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())); }
private void ParseVertices(LineReader lineReader) { byte[] buffer = new byte[_dataStore.Header.Size.Length * sizeof(float)]; for (int i = 0; i < _dataStore.Header.Points; i++) { if (lineReader.Read(buffer, 0, buffer.Length) != buffer.Length) { throw new IOException(); } _vertexParser.Parse(buffer); } }