Merge multiple meshes in a node into one mesh with many primtives; write out only one mesh per node

To do:
- clean up MergeMeshes
- see if there’s a way to do this earlier in the flow
This commit is contained in:
Daniel Hritzkiv
2017-09-17 17:00:57 -04:00
parent 5147acfe65
commit 28523232cf
3 changed files with 26 additions and 1 deletions

View File

@@ -110,6 +110,7 @@ glTF2Exporter::glTF2Exporter(const char* filename, IOSystem* pIOSystem, const ai
}
ExportMeshes();
MergeMeshes();
ExportScene();
@@ -743,6 +744,27 @@ void glTF2Exporter::ExportMeshes()
}
}
void glTF2Exporter::MergeMeshes()
{
for (unsigned int n = 0; n < mAsset->nodes.Size(); ++n) {
Ref<Node> node = mAsset->nodes.Get(n);
unsigned int nMeshes = node->meshes.size();
if (nMeshes) {
Ref<Mesh> firstMesh = node->meshes.at(0);
for (unsigned int m = 1; m < nMeshes; ++m) {
Ref<Mesh> mesh = node->meshes.at(m);
Mesh::Primitive primitive = mesh->primitives.at(0);
firstMesh->primitives.push_back(primitive);
}
node->meshes.erase(node->meshes.begin() + 1, node->meshes.end());
}
}
}
/*
* Export the root node of the node hierarchy.
* Calls ExportNode for all children.