diff --git a/code/AssetLib/glTF2/glTF2Asset.h b/code/AssetLib/glTF2/glTF2Asset.h index 39f09bef2..e08632c85 100644 --- a/code/AssetLib/glTF2/glTF2Asset.h +++ b/code/AssetLib/glTF2/glTF2Asset.h @@ -1267,6 +1267,7 @@ private: size_t mBodyOffset; size_t mBodyLength; IdMap mUsedIds; + std::map> mUsedNamesMap; Ref mBodyBuffer; }; diff --git a/code/AssetLib/glTF2/glTF2Asset.inl b/code/AssetLib/glTF2/glTF2Asset.inl index 56e15205e..78455039f 100644 --- a/code/AssetLib/glTF2/glTF2Asset.inl +++ b/code/AssetLib/glTF2/glTF2Asset.inl @@ -2195,8 +2195,10 @@ inline std::string Asset::FindUniqueID(const std::string &str, const char *suffi std::string id = str; if (!id.empty()) { - if (mUsedIds.find(id) == mUsedIds.end()) + if (mUsedIds.find(id) == mUsedIds.end()){ + mUsedNamesMap[id] = 0; return id; + } id += "_"; } @@ -2205,17 +2207,13 @@ inline std::string Asset::FindUniqueID(const std::string &str, const char *suffi Asset::IdMap::iterator it = mUsedIds.find(id); if (it == mUsedIds.end()) { + mUsedNamesMap[id] = 0; return id; } - std::vector buffer; - buffer.resize(id.size() + 16); - int offset = ai_snprintf(buffer.data(), buffer.size(), "%s_", id.c_str()); - for (int i = 0; it != mUsedIds.end(); ++i) { - ai_snprintf(buffer.data() + offset, buffer.size() - offset, "%d", i); - id = buffer.data(); - it = mUsedIds.find(id); - } + auto key = id; + id += "_" + std::to_string(mUsedNamesMap[key]); + mUsedNamesMap[key] = mUsedNamesMap[key] + 1; return id; } diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index c78b5fd7f..382f28110 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -1499,6 +1499,10 @@ unsigned int glTF2Exporter::ExportNodeHierarchy(const aiNode *n) { Ref node = mAsset->nodes.Create(mAsset->FindUniqueID(n->mName.C_Str(), "node")); node->name = n->mName.C_Str(); + if(n->mNumChildren > 0) + node->children.reserve(n->mNumChildren); + if(n->mNumMeshes > 0) + node->meshes.reserve(n->mNumMeshes); if (!n->mTransformation.IsIdentity(configEpsilon)) { node->matrix.isPresent = true; @@ -1527,6 +1531,10 @@ unsigned int glTF2Exporter::ExportNode(const aiNode *n, Ref &parent) { node->parent = parent; node->name = name; + if(n->mNumChildren > 0) + node->children.reserve(n->mNumChildren); + if(n->mNumMeshes > 0) + node->meshes.reserve(n->mNumMeshes); ExportNodeExtras(n->mMetaData, node->extras);