From: Daniel Hritzkiv Date: Sun, 17 Sep 2017 21:00:57 +0000 (-0400) Subject: Merge multiple meshes in a node into one mesh with many primtives; write out only... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=28523232cf735a28ec794a557af48163d84174c0;p=platform%2Fupstream%2Fassimp.git 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 --- diff --git a/code/glTF2AssetWriter.inl b/code/glTF2AssetWriter.inl index dd90ec5..df28cb6 100644 --- a/code/glTF2AssetWriter.inl +++ b/code/glTF2AssetWriter.inl @@ -417,7 +417,9 @@ namespace glTF2 { AddRefsVector(obj, "children", n.children, w.mAl); - AddRefsVector(obj, "meshes", n.meshes, w.mAl); + if (!n.meshes.empty()) { + obj.AddMember("mesh", n.meshes[0]->index, w.mAl); + } AddRefsVector(obj, "skeletons", n.skeletons, w.mAl); diff --git a/code/glTF2Exporter.cpp b/code/glTF2Exporter.cpp index 56932db..f63c8e8 100644 --- a/code/glTF2Exporter.cpp +++ b/code/glTF2Exporter.cpp @@ -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 = mAsset->nodes.Get(n); + + unsigned int nMeshes = node->meshes.size(); + + if (nMeshes) { + Ref firstMesh = node->meshes.at(0); + + for (unsigned int m = 1; m < nMeshes; ++m) { + Ref 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. diff --git a/code/glTF2Exporter.h b/code/glTF2Exporter.h index 420c2af..3aed35a 100644 --- a/code/glTF2Exporter.h +++ b/code/glTF2Exporter.h @@ -120,6 +120,7 @@ namespace Assimp void ExportMetadata(); void ExportMaterials(); void ExportMeshes(); + void MergeMeshes(); unsigned int ExportNodeHierarchy(const aiNode* n); unsigned int ExportNode(const aiNode* node, glTF2::Ref& parent); void ExportScene();