Ejemplo n.º 1
0
        /// <summary>
        /// Store the f, v, vt and vn lines into the object
        /// </summary>
        /// <param name="value"></param>
        /// <param name="objectObj"></param>
        /// <param name="allVertices"></param>
        /// <param name="indexesObj"></param>
        private static void VerticeData(string value, ObjectObj objectObj, AllVerticesDataObj allVertices, LocalIndexesObj indexesObj)
        {
            VertIndexesObj vertIndexes = new VertIndexesObj();

            foreach (string indexes in ObjUtils.SplitVertData(value))
            {
                VertIndexObj vertIndex = new VertIndexObj();

                string[] indexList = ObjUtils.SplitIndexes(indexes);

                int length = indexList.Length;

                for (int i = 0; i < length; i++)
                {
                    int index = 0;
                    if (indexList[i] != "")                                 // the vt line can be empty
                    {
                        if (Int32.TryParse(indexList[i], out int tmpIndex)) // Get the index
                        {
                            index = tmpIndex;
                        }
                    }

                    if (i == 0) // v
                    {
                        if (index != 0)
                        {
                            vertIndex.V = indexesObj.vIndex;
                            string vLine = allVertices.GetVIndex(index - 1); // Obj index start at 1
                            if (vLine != null)
                            {
                                objectObj.VerticesList.Add(new Point(vLine));
                                indexesObj.vIndex++;
                            }
                        }
                    }
                    else if (i == 1) // vt
                    {
                        if (index != 0)
                        {
                            vertIndex.Vt = indexesObj.vtIndex;
                            string vtLine = allVertices.GetVtIndex(index - 1); // Obj index start at 1
                            if (vtLine != null)
                            {
                                objectObj.UVsList.Add(new UVCoordinates(vtLine));
                                indexesObj.vtIndex++;
                            }
                        }
                    }
                    else if (i == 2) // vn
                    {
                        if (index != 0)
                        {
                            vertIndex.Vn = indexesObj.vnIndex;
                            string vnLine = allVertices.GetVnIndex(index - 1); // Obj index start at 1
                            if (vnLine != null)
                            {
                                objectObj.NormalsList.Add(new Vector(vnLine));
                                indexesObj.vnIndex++;
                            }
                        }
                    }
                }
                vertIndexes.VertIndexList.Add(vertIndex);
            }
            objectObj.VertIndexesList.Add(vertIndexes);
        }