diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index f509289b3..50ea60b91 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -442,15 +442,17 @@ namespace Assimp { void FBXConverter::GetUniqueName(const std::string &name, std::string &uniqueName) { uniqueName = name; - int i = 0; - while (mNodeNames.find(uniqueName) != mNodeNames.end()) + auto it_pair = mNodeNameInstances.insert({ name, 0 }); // duplicate node name instance count + unsigned int& i = it_pair.first->second; + auto uniqueIt_pair = mNodeNames.insert(uniqueName); + while (!uniqueIt_pair.second) { i++; std::stringstream ext; ext << name << std::setfill('0') << std::setw(3) << i; uniqueName = ext.str(); + uniqueIt_pair = mNodeNames.insert(uniqueName); } - mNodeNames.insert(uniqueName); } const char* FBXConverter::NameTransformationComp(TransformationComp comp) { diff --git a/code/FBXConverter.h b/code/FBXConverter.h index 1bdf9ac9f..f5de99ae3 100644 --- a/code/FBXConverter.h +++ b/code/FBXConverter.h @@ -461,6 +461,10 @@ private: using NodeAnimBitMap = std::map ; NodeAnimBitMap node_anim_chain_bits; + // number of nodes with the same name + using NodeAnimNameMap = std::unordered_map; + NodeAnimNameMap mNodeNameInstances; + using NodeNameCache = std::unordered_set; NodeNameCache mNodeNames; diff --git a/test/unit/utFBXImporterExporter.cpp b/test/unit/utFBXImporterExporter.cpp index a678357ff..188f7cf22 100644 --- a/test/unit/utFBXImporterExporter.cpp +++ b/test/unit/utFBXImporterExporter.cpp @@ -166,7 +166,7 @@ TEST_F(utFBXImporterExporter, importCubesComplexTransform) { ASSERT_STREQ(child1->mName.C_Str(), "Cube3"); auto parent = child1; - constexpr size_t chain_length = 8u; + const size_t chain_length = 8u; const char* chainStr[chain_length] = { "Cube1001_$AssimpFbx$_Translation", "Cube1001_$AssimpFbx$_RotationPivot",