Exemplo n.º 1
0
        /// <summary>
        /// Return the f line string (i.e. 1/1/1 2/2/2 3/3/3)
        /// </summary>
        /// <param name="vertIndexes"></param>
        /// <param name="indexesObj"></param>
        /// <returns></returns>
        private static string GetDataF(VertIndexesObj vertIndexes, LocalIndexesObj indexesObj)
        {
            const string strSpace = " ";

            string[] strIndexesF = new string[vertIndexes.VertIndexList.Count];
            int      i           = 0;

            foreach (VertIndexObj vertIndex in vertIndexes.VertIndexList)
            {
                int?V  = vertIndex.V;
                int?Vt = vertIndex.Vt;
                int?Vn = vertIndex.Vn;
                if (V != null)
                {
                    V = V + 1 + indexesObj.vIndex;
                }
                if (Vt != null)
                {
                    Vt = Vt + 1 + indexesObj.vtIndex;
                }
                if (Vn != null)
                {
                    Vn = Vn + 1 + indexesObj.vnIndex;
                }

                strIndexesF[i] = GetIndexesF(V, Vt, Vn); // Add the 1/1/1
                i++;
            }
            return(string.Join(strSpace, strIndexesF));
        }
Exemplo n.º 2
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);
        }