private void ReadFace() { var parts = SplitLine(); if (parts.Length < 4) { ThrowInvalidModelFormatException("Too few parameters for face"); } var vertexIndices = new List <int>(3); var textureCoordIndices = new List <int>(3); var normalIndices = new List <int>(3); foreach (var part in parts.Skip(1)) { ParseFaceIndexBundle(part, vertexIndices, textureCoordIndices, normalIndices); } ValidateTextureCoordIndices(textureCoordIndices, vertexIndices); ValidateNormalIndices(normalIndices, vertexIndices); _model.AddFace(new Face { VertexIndices = vertexIndices.ToArray(), NormalIndices = normalIndices.ToArray(), TextureCoordIndices = textureCoordIndices.ToArray(), }); }
private IModel InternalRead(Stream input, CancellationToken token, IProgress <double> progress) { _input = input ?? throw new ArgumentNullException(nameof(input)); if (!_input.CanRead) { throw new ArgumentException("Input stream must be readable"); } _model = new Model.Model(); using (var br = new BinaryReader(input)) { br.ReadBytes(80); var faceNum = br.ReadUInt32(); _lastReportedProgress = 0; for (var i = 0; i < faceNum; i++) { ReportProgress(progress); if (token.IsCancellationRequested) { break; } var normal = ReadVector(br); var vertexIdx = _model.Vertices.Count; _model.AddVertex((Vertex)ReadVector(br)); _model.AddVertex((Vertex)ReadVector(br)); _model.AddVertex((Vertex)ReadVector(br)); br.ReadInt16(); var face = new Face { Normal = normal, VertexIndices = new[] { vertexIdx, vertexIdx + 1, vertexIdx + 2 } }; _model.AddFace(face); } } return(_model); }