Пример #1
0
        private string[] ConvertToObj(List <Polygon> polygons)
        {
            ObjFile file = new ObjFile()
            {
                ObjectName = "ConvertedObject"
            };

            foreach (var polygon in polygons)
            {
                ObjFile.Face face = new ObjFile.Face();
                foreach (var vertex in polygon.Vertexes)
                {
                    var foundVertex = file.Vertexes.Find(v => v.Equals(vertex));
                    int number;
                    if (foundVertex == null)
                    {
                        file.Vertexes.Add(vertex);
                        number = file.Vertexes.Count;
                    }
                    else
                    {
                        number = file.Vertexes.IndexOf(foundVertex);
                    }
                    face.AddComponent(new ObjFile.Face.Component(number, 0));
                }
                file.AddFace(face);
            }
            return(file.Write());
        }
Пример #2
0
        public ObjFile Read(string[] lines)
        {
            ObjFile data = new ObjFile();

            foreach (var line in lines)
            {
                string syntax = line.Substring(0, 2).Trim();
                if (syntax.Equals(FileSyntax.Obj.VERTEX))
                {
                    data.Vertexes.Add(V3d.Parse(line.Substring(1), T3D_NUMBER_SEPARATOR));
                }
                if (syntax.Equals(FileSyntax.Obj.FACE))
                {
                    data.AddFace(ObjFile.Face.Parse(line.Substring(1)));
                }
            }
            return(data);
        }