From ca08c4a20948c5fa96be43015edbf726c81b6d12 Mon Sep 17 00:00:00 2001 From: Matias Date: Wed, 27 Mar 2019 11:20:16 +0100 Subject: [PATCH] FBX: Fix for loading taking a very long time on models with many duplicate names (issue_2390) --- code/FBXConverter.cpp | 9 +++++---- code/FBXConverter.h | 8 +++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index a61ae4006..692f081da 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -410,16 +410,17 @@ namespace Assimp { void FBXConverter::GetUniqueName(const std::string &name, std::string &uniqueName) { - int i = 0; uniqueName = name; - while (mNodeNames.find(uniqueName) != mNodeNames.end()) + int i = 0; + auto it = mNodeNameInstances.find(uniqueName); + if (it != mNodeNameInstances.end()) { - ++i; + i = it->second + 1; std::stringstream ext; ext << name << std::setfill('0') << std::setw(3) << i; uniqueName = ext.str(); } - mNodeNames.insert(uniqueName); + mNodeNameInstances[name] = i; } diff --git a/code/FBXConverter.h b/code/FBXConverter.h index 398baa445..1ed88406e 100644 --- a/code/FBXConverter.h +++ b/code/FBXConverter.h @@ -58,6 +58,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include struct aiScene; struct aiNode; @@ -74,8 +75,6 @@ namespace FBX { class Document; -using NodeNameCache = std::set; - /** * Convert a FBX #Document to #aiScene * @param out Empty scene to be populated @@ -444,7 +443,10 @@ private: typedef std::map NodeAnimBitMap; NodeAnimBitMap node_anim_chain_bits; - NodeNameCache mNodeNames; + // number of nodes with the same name + typedef std::unordered_map NodeNameMap; + NodeNameMap mNodeNameInstances; + double anim_fps; aiScene* const out;