Exemplo n.º 1
0
        public static Object3D readObj(StreamReader sr)
        {
            Object3D obj = new Object3D();

            String[] s, s1;
            Face     f;
            String   line = sr.ReadLine();

            while (line != null)
            {
                s = line.Split(' ');
                //add vertex
                if (s[0].Equals("v"))
                {
                    obj.addOriginals(new Vertex(Convert.ToDouble(s[1].Replace(".", ",")), Convert.ToDouble(s[2].Replace(".", ",")), Convert.ToDouble(s[3].Replace(".", ","))));
                }

                //add face
                else if (s[0].Equals("f"))
                {
                    f = new Face();
                    if (s[s.Length - 1] == "")
                    {
                        Array.Resize(ref s, 3);
                    }
                    for (int i = 1; i < s.Length; i++)
                    {
                        s1 = s[i].Split('/');

                        f.addVertex(Convert.ToInt32(s1[0]) - 1);
                    }
                    obj.addFaces(f);
                }
                //add texture
                //else if ()

                line = sr.ReadLine();
            }
            obj.setActuals(obj.getOriginals());
            obj.setNFaces();

            return(obj);
        }