Browse Source

issue 2390: FBXConverter::GetUniqueName now uses a map for keeping track of duplicate node name count and a set for registering names that have been taken.This is required because the model might contain a several nodes called "nodename" and another one called "nodename001". In that case we can't add "001" to the second node called "nodename".

Matias 6 năm trước cách đây
mục cha
commit
0505dd7266
2 tập tin đã thay đổi với 16 bổ sung8 xóa
  1. 10 6
      code/FBXConverter.cpp
  2. 6 2
      code/FBXConverter.h

+ 10 - 6
code/FBXConverter.cpp

@@ -412,18 +412,22 @@ namespace Assimp {
         {
             uniqueName = name;
             int i = 0;
-            auto it = mNodeNameInstances.find(uniqueName);
+            auto it = mNodeNameInstances.find(name); // duplicate node name instance count
             if (it != mNodeNameInstances.end())
             {
-                i = it->second + 1;
-                std::stringstream ext;
-                ext << name << std::setfill('0') << std::setw(3) << i;
-                uniqueName = ext.str();
+                i = it->second;
+                while (mNodeNames.find(uniqueName) != mNodeNames.end())
+                {
+                    i++;
+                    std::stringstream ext;
+                    ext << name << std::setfill('0') << std::setw(3) << i;
+                    uniqueName = ext.str();
+                }
             }
             mNodeNameInstances[name] = i;
+            mNodeNames.insert(uniqueName);
         }
 
-
         const char* FBXConverter::NameTransformationComp(TransformationComp comp) {
             switch (comp) {
             case TransformationComp_Translation:

+ 6 - 2
code/FBXConverter.h

@@ -59,6 +59,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <assimp/camera.h>
 #include <assimp/StringComparison.h>
 #include <unordered_map>
+#include <unordered_set>
 
 struct aiScene;
 struct aiNode;
@@ -442,8 +443,11 @@ private:
     NodeAnimBitMap node_anim_chain_bits;
 
     // number of nodes with the same name
-    using NodeNameMap = std::unordered_map<std::string, unsigned int> ;
-    NodeNameMap mNodeNameInstances;
+    typedef std::unordered_map<std::string, unsigned int> NodeAnimNameMap;
+    NodeAnimNameMap mNodeNameInstances;
+
+    typedef std::unordered_set<std::string> NodeNameCache;
+    NodeNameCache mNodeNames;
 
     double anim_fps;