public void WriteToOBJ(TextWriter writer, int lodNumber, int firstVertexNumber, int firstNormalNumber, int firstCoordNumber, Dictionary <string, int?> materialNames, Stream unknownData) { unknownData.Write(unknown); unknownData.WriteByte(unknown2); unknownData.WriteByte(unknown3); double scaleFactor = ConvertScale(Scale); writer.WriteLine($"g lod{lodNumber}/scale={scaleFactor}"); writer.WriteLine("# vertices"); Vertices.ForEach(vertex => vertex.WriteToOBJ(writer, scaleFactor)); writer.WriteLine("# normals"); Normals.ForEach(normal => normal.WriteToOBJ(writer)); List <UVCoordinate> coords = GetAllUVCoords(); writer.WriteLine("# UV coords"); coords.ForEach(coord => coord.WriteToOBJ(writer)); writer.WriteLine("# triangles"); Triangles.ForEach(polygon => polygon.WriteToOBJ(writer, false, Vertices, Normals, firstVertexNumber, firstNormalNumber, materialNames)); writer.WriteLine("# quads"); Quads.ForEach(polygon => polygon.WriteToOBJ(writer, true, Vertices, Normals, firstVertexNumber, firstNormalNumber, materialNames)); writer.WriteLine("# UV triangles"); UVTriangles.ForEach(polygon => polygon.WriteToOBJ(writer, false, Vertices, Normals, firstVertexNumber, firstNormalNumber, coords, firstCoordNumber, materialNames)); writer.WriteLine("# UV quads"); UVQuads.ForEach(polygon => polygon.WriteToOBJ(writer, true, Vertices, Normals, firstVertexNumber, firstNormalNumber, coords, firstCoordNumber, materialNames)); }
public List <UVCoordinate> GetAllUVCoords() => UVTriangles.SelectMany(polygon => new UVCoordinate[] { polygon.Vertex0UV, polygon.Vertex1UV, polygon.Vertex2UV }) .Concat(UVQuads.SelectMany(polygon => new UVCoordinate[] { polygon.Vertex0UV, polygon.Vertex1UV, polygon.Vertex2UV, polygon.Vertex3UV })).ToList();