|
@@ -800,9 +800,33 @@ void glTF2Exporter::MergeMeshes()
|
|
|
for (unsigned int m = nMeshes - 1; m >= 1; --m) {
|
|
|
Ref<Mesh> mesh = node->meshes.at(m);
|
|
|
|
|
|
- firstMesh->primitives.insert(firstMesh->primitives.end(), mesh->primitives.begin(), mesh->primitives.end());
|
|
|
-
|
|
|
- node->meshes.erase(node->meshes.begin() + m);
|
|
|
+ //append this mesh's primitives to the first mesh's primitives
|
|
|
+ firstMesh->primitives.insert(
|
|
|
+ firstMesh->primitives.end(),
|
|
|
+ mesh->primitives.begin(),
|
|
|
+ mesh->primitives.end()
|
|
|
+ );
|
|
|
+
|
|
|
+ //remove the mesh from the list of meshes
|
|
|
+ unsigned int removedIndex = mAsset->meshes.Remove(mesh->id.c_str());
|
|
|
+
|
|
|
+ //find the presence of the removed mesh in other nodes
|
|
|
+ for (unsigned int nn = 0; nn < mAsset->nodes.Size(); ++nn) {
|
|
|
+ Ref<Node> node = mAsset->nodes.Get(nn);
|
|
|
+
|
|
|
+ for (unsigned int mm = 0; mm < node->meshes.size(); ++mm) {
|
|
|
+ Ref<Mesh>& meshRef = node->meshes.at(mm);
|
|
|
+ unsigned int meshIndex = meshRef.GetIndex();
|
|
|
+
|
|
|
+ if (meshIndex == removedIndex) {
|
|
|
+ node->meshes.erase(node->meshes.begin() + mm);
|
|
|
+ } else if (meshIndex > removedIndex) {
|
|
|
+ Ref<Mesh> newMeshRef = mAsset->meshes.Get(meshIndex - 1);
|
|
|
+
|
|
|
+ meshRef = newMeshRef;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//since we were looping backwards, reverse the order of merged primitives to their original order
|