SImplify mesh merging code
My assumption that primitives of different types (modes) can’t be in the same mesh was incorrect.pull/1446/head
parent
2efd2cdef8
commit
8743d28ec5
|
@ -755,31 +755,18 @@ void glTF2Exporter::MergeMeshes()
|
||||||
//skip if it's 1 or less meshes per node
|
//skip if it's 1 or less meshes per node
|
||||||
if (nMeshes > 1) {
|
if (nMeshes > 1) {
|
||||||
Ref<Mesh> firstMesh = node->meshes.at(0);
|
Ref<Mesh> firstMesh = node->meshes.at(0);
|
||||||
Mesh::Primitive firstPrimitive = firstMesh->primitives.at(0);
|
|
||||||
|
|
||||||
//loop backwards to allow easy removal of a mesh from a node once it's merged
|
//loop backwards to allow easy removal of a mesh from a node once it's merged
|
||||||
for (unsigned int m = nMeshes - 1; m >= 1; --m) {
|
for (unsigned int m = nMeshes - 1; m >= 1; --m) {
|
||||||
Ref<Mesh> mesh = node->meshes.at(m);
|
Ref<Mesh> mesh = node->meshes.at(m);
|
||||||
bool primitivesPushed = false;
|
|
||||||
|
|
||||||
for (unsigned int p = 0; p < mesh->primitives.size(); ++p) {
|
firstMesh->primitives.insert(firstMesh->primitives.end(), mesh->primitives.begin(), mesh->primitives.end());
|
||||||
Mesh::Primitive primitive = mesh->primitives.at(p);
|
|
||||||
|
|
||||||
if (firstPrimitive.mode == primitive.mode) {
|
node->meshes.erase(node->meshes.begin() + m);
|
||||||
firstMesh->primitives.push_back(primitive);
|
|
||||||
primitivesPushed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (primitivesPushed) {
|
|
||||||
//remove the merged meshes from the node
|
|
||||||
node->meshes.erase(node->meshes.begin() + m);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//since we were looping backwards, reverse the order of merged primitives to their original order
|
//since we were looping backwards, reverse the order of merged primitives to their original order
|
||||||
std::reverse(firstMesh->primitives.begin() + 1, firstMesh->primitives.end());
|
std::reverse(firstMesh->primitives.begin() + 1, firstMesh->primitives.end());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue