Exemple #1
0
        public static void parseTexCord(FVLMesh mesh, String[] args)
        {
            Vector2 texCord = new Vector2();

            texCord.X = float.Parse(args[1], System.Globalization.NumberStyles.Float, new System.Globalization.CultureInfo("en-US"));
            texCord.Y = float.Parse(args[2], System.Globalization.NumberStyles.Float, new System.Globalization.CultureInfo("en-US"));
            mesh.AddTexCord(texCord);
        }
Exemple #2
0
        public static List <FVLMesh> parseFile(String objFileName, String mtlFileName)
        {
            List <FVLMesh> listaMeshes = new List <FVLMesh>();
            FVLMesh        mesh        = new FVLMesh();
            //Lista de todos los f, v, vn y vt del obj
            List <Vector3> vertexList       = new List <Vector3>();
            List <Vector2> texCordList      = new List <Vector2>();
            List <Vector3> vertexNormalList = new List <Vector3>();

            //Parseo el archivo de materiales
            List <MatConTextura> listaMateriales = MtlFileParser.parseFile(mtlFileName);

            String line;

            String[] lineSplit;

            StreamReader file = new StreamReader(objFileName);

            line = file.ReadLine();
            while (line != null)
            {
                line = line.Trim();                                   //Saco espacios en blanco.
                if ((line.Length != 0) && (!line[0].Equals(COMMENT))) //Si no es comentario
                {
                    lineSplit = line.Split(SEPARATORS, StringSplitOptions.RemoveEmptyEntries);
                    if (lineSplit[0].Equals(VERTEX))
                    {
                        parseVertex(mesh, lineSplit, vertexList);
                    }
                    else if (lineSplit[0].Equals(NORMAL))
                    {
                        parseNormal(mesh, lineSplit, vertexNormalList);
                    }

                    else if (lineSplit[0].Equals(FACE))
                    {
                        parseFace(mesh, line);//HERE!!
                    }

                    else if (lineSplit[0].Equals(TEXCORD))
                    {
                        parseTexCord(mesh, lineSplit, texCordList);
                    }

                    else if (lineSplit[0].Equals(USEMTL))
                    {
                        parseMtl(mesh, lineSplit, listaMateriales);
                    }
                    else if (lineSplit[0].Equals(O))
                    {
                        mesh = new FVLMesh();
                        mesh.NombreObjeto = lineSplit[1];
                        //Agrego todos los v, vn y vt a la lista del subobjeto (para que no se desacomoden los indices en el build)
                        foreach (Vector3 vertex in vertexList)
                        {
                            mesh.AddVertex(vertex);
                        }
                        foreach (Vector3 vertexNormal in vertexNormalList)
                        {
                            mesh.AddVertexNormal(vertexNormal);
                        }
                        foreach (Vector2 texCoord in texCordList)
                        {
                            mesh.AddTexCord(texCoord);
                        }

                        listaMeshes.Add(mesh);
                    }
                }
                line = file.ReadLine();
            }
            file.Close();
            return(listaMeshes);
        }