Beispiel #1
0
        public static OffMesh ReadFile(string path)
        {
            FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            //BufferedStream bs = new BufferedStream(fs);
            StreamReader sr = new StreamReader(fs);

            int    nbVertices, nbFaces, nbEdges;
            string line;

            if (sr.ReadLine() != "OFF")
            {
                Debug.LogError("File does not start with \"OFF\" line !");
                return(null);
            }

            string s = sr.ReadLine();

            string[] parameters = s.Split(' ');
            if (parameters.Length != 3)
            {
                Debug.LogError("Wrong parameters format line 2");
                return(null);
            }

            nbVertices = int.Parse(parameters[0]);
            nbFaces    = int.Parse(parameters[1]);
            nbEdges    = int.Parse(parameters[2]);

            OffMesh mesh = new OffMesh();


            for (int i = 0; i < nbVertices; i++)
            {
                line = sr.ReadLine();
                float[] pos = ParseVertex(line);
                mesh.vertices.Add(new Vector3(pos[0], pos[1], pos[2]));
            }

            for (int i = 0; i < nbFaces; i++)
            {
                line = sr.ReadLine();
                OffFace face = ParseFace(line);
                mesh.faces.Add(face);
            }

            //int[] edge = ParseEdge(line);
            //mesh.edges.Add(new Vector2(edge[0], edge[1]));
            return(mesh);
        }
Beispiel #2
0
        private static OffFace ParseFace(string line)
        {
            try
            {
                string[] data  = line.Split(' ');
                int      nbVtx = int.Parse(data[0]);
                OffFace  face  = new OffFace(nbVtx);

                for (int i = 0; i < nbVtx; i++)
                {
                    face.verticesIndex[i] = int.Parse(data[i + 1]);
                }
                return(face);
            }
            catch (Exception ex)
            {
                Debug.LogError(string.Format($"Can't find face data in line : {0}. ERROR : {1}", line, ex));
                return(null);
            }
        }