Skip to content

Commit

Permalink
Unused materials are now discarded
Browse files Browse the repository at this point in the history
  • Loading branch information
HeDo88TH committed May 25, 2022
1 parent f35043d commit 56da2fc
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Obj2Tiles.Library/Geometry/MeshT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -942,11 +942,14 @@ private void RemoveUnusedVerticesAndUvs()

var newVertexes = new Dictionary<Vertex3, int>(_vertices.Count);
var newUvs = new Dictionary<Vertex2, int>(_textureVertices.Count);
var newMaterials = new Dictionary<Material, int>(_materials.Count);

for (var f = 0; f < _faces.Count; f++)
{
var face = _faces[f];

// Vertices

var vA = _vertices[face.IndexA];
var vB = _vertices[face.IndexB];
var vC = _vertices[face.IndexC];
Expand All @@ -966,6 +969,8 @@ private void RemoveUnusedVerticesAndUvs()

face.IndexC = newVC;

// Texture vertices

var uvA = _textureVertices[face.TextureIndexA];
var uvB = _textureVertices[face.TextureIndexB];
var uvC = _textureVertices[face.TextureIndexC];
Expand All @@ -985,10 +990,20 @@ private void RemoveUnusedVerticesAndUvs()

face.TextureIndexC = newUvC;

// Materials

var material = _materials[face.MaterialIndex];

if (!newMaterials.TryGetValue(material, out var newMaterial))
newMaterial = newMaterials.AddIndex(material);

face.MaterialIndex = newMaterial;

}

_vertices = newVertexes.Keys.ToList();
_textureVertices = newUvs.Keys.ToList();
_materials = newMaterials.Keys.ToList();

}

Expand Down

0 comments on commit 56da2fc

Please sign in to comment.