예제 #1
0
        public WavefrontObject LoadFromFile(string filename)
        {
            _logger.Debug("Loading Obj file from {0}", filename);
            using var file = File.OpenText(filename);

            var vertices = new List <Vector3>();
            var normals  = new List <Vector3>();
            var textures = new List <Vector2>();
            var faces    = new List <Face>();

            while (TryParse(file, out var objLine))
            {
                switch (objLine.Type)
                {
                case ObjTypes.Vertex: vertices.Add(_vertexParser.Parse(objLine.Value)); break;

                case ObjTypes.Normal: normals.Add(_normalParser.Parse(objLine.Value)); break;

                case ObjTypes.Texture: textures.Add(_textureParser.Parse(objLine.Value)); break;

                case ObjTypes.Face: faces.Add(new Face(_faceParser.Parse(objLine.Value))); break;

                //TODO: Add support for Objects, Groups, Materials, Lights
                default:
                    _logger.Debug("Unknown type: {0} value: {1}", objLine.Type, objLine.Value);
                    break;
                }
            }
            _logger.Debug("Finished loading model. Vertices: {0}, Textures: {1}, Normals: {2}, Faces: {3}", vertices.Count, textures.Count, normals.Count, faces.Count);
            return(new WavefrontObject(vertices.ToArray(), normals.ToArray(), textures.ToArray(), faces.ToArray()));
        }
        public CubeTexture Parse()
        {
            ITexture leftTexture  = leftParser.Parse();
            ITexture rightTexture = rightParser.Parse();
            ITexture upTexture    = upParser.Parse();
            ITexture downTexture  = downParser.Parse();
            ITexture frontTexture = frontParser.Parse();
            ITexture backTexture  = backParser.Parse();

            return(new CubeTexture(
                       leftTexture,
                       rightTexture,
                       upTexture,
                       downTexture,
                       frontTexture,
                       backTexture));
        }