Skip to content

Commit

Permalink
gltfpack: Filter duplicate nodes after merging node lists
Browse files Browse the repository at this point in the history
This almost never comes up in practice, but occasionally scenes might
have the same geometry attached to the same nodes. This results in
counterintuitive results because we create node lists with duplicate
nodes for this, which never happened before, and end up producing more
quantization sub-nodes than necessary.

For now we can just filter these attachments out to avoid redundancy.
  • Loading branch information
zeux committed Oct 16, 2024
1 parent 98c9b1a commit 288bd2e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions gltf/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,16 @@ void dedupMeshes(std::vector<Mesh>& meshes)
mesh.instances.clear();
}
}

for (size_t i = 0; i < meshes.size(); ++i)
{
Mesh& target = meshes[i];
if (target.nodes.size() <= 1)
continue;

std::sort(target.nodes.begin(), target.nodes.end());
target.nodes.erase(std::unique(target.nodes.begin(), target.nodes.end()), target.nodes.end());
}
}

void mergeMeshInstances(Mesh& mesh)
Expand Down

0 comments on commit 288bd2e

Please sign in to comment.