예제 #1
0
        public static ObjModel Load(string filePath)
        {
            ObjModel result = new ObjModel();

            string[] content = File.ReadAllLines(filePath);

            foreach (string line in content)
            {
                string[] splits = line.Split(' ', StringSplitOptions.RemoveEmptyEntries);
                if (splits.Length == 0)
                {
                    continue;
                }

                foreach (var parser in Parsers)
                {
                    if (parser.Keyword == splits[0])
                    {
                        parser.Parse(result, splits.Skip(1).ToArray());
                    }
                }
            }

            return(result);
        }
예제 #2
0
        public void Parse(ObjModel model, string[] content)
        {
            Vector2 textureCoordinate = new Vector2();

            for (int i = 0; i < content.Length; i++)
            {
                textureCoordinate[i] = float.Parse(content[i], CultureInfo.InvariantCulture);
            }
            model.TextureCoordinates.Add(textureCoordinate);
        }
예제 #3
0
        public void Parse(ObjModel model, string[] content)
        {
            Vector3 normal = new Vector3();

            for (int i = 0; i < content.Length; i++)
            {
                normal[i] = float.Parse(content[i], CultureInfo.InvariantCulture);
            }
            model.Normals.Add(normal);
        }
예제 #4
0
        public void Parse(ObjModel model, string[] content)
        {
            Vector3 position = new Vector3();

            for (int i = 0; i < content.Length; i++)
            {
                position[i] = float.Parse(content[i], CultureInfo.InvariantCulture);
            }
            model.Positions.Add(position);
        }
예제 #5
0
        public void Parse(ObjModel model, string[] content)
        {
            List <Vector3i> polygon = new List <Vector3i>();

            for (int i = 0; i < content.Length; i++)
            {
                string[] vertex  = content[i].Split('/');
                Vector3i indices = new Vector3i();

                for (int j = 0; j < vertex.Length; j++)
                {
                    indices[j] = vertex[j] == string.Empty ? 0 : int.Parse(vertex[j]);
                }
                polygon.Add(indices);
            }
            model.CurrentMesh.Indices.AddRange(polygon);
        }