浏览代码

Merge pull request #1603 from Matter-and-Form/fix/gltf-node-name-conflict

[gltf2] node name conflict fix
Kim Kulling 7 年之前
父节点
当前提交
9d224f6ac5
共有 3 个文件被更改,包括 13 次插入1 次删除
  1. 3 1
      code/glTF2Importer.cpp
  2. 二进制
      test/models/glTF2/2CylinderEngine-glTF-Binary/2CylinderEngine.glb
  3. 10 0
      test/unit/utglTF2ImportExport.cpp

+ 3 - 1
code/glTF2Importer.cpp

@@ -516,7 +516,9 @@ aiNode* ImportNode(aiScene* pScene, glTF2::Asset& r, std::vector<unsigned int>&
 {
 {
     Node& node = *ptr;
     Node& node = *ptr;
 
 
-    aiNode* ainode = new aiNode(node.name);
+    std::string nameOrId = node.name.empty() ? node.id : node.name;
+
+    aiNode* ainode = new aiNode(nameOrId);
 
 
     if (!node.children.empty()) {
     if (!node.children.empty()) {
         ainode->mNumChildren = unsigned(node.children.size());
         ainode->mNumChildren = unsigned(node.children.size());

二进制
test/models/glTF2/2CylinderEngine-glTF-Binary/2CylinderEngine.glb


+ 10 - 0
test/unit/utglTF2ImportExport.cpp

@@ -56,6 +56,12 @@ public:
         return nullptr != scene;
         return nullptr != scene;
     }
     }
 
 
+    virtual bool binaryImporterTest() {
+        Assimp::Importer importer;
+        const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/glTF2/2CylinderEngine-glTF-Binary/2CylinderEngine.glb", aiProcess_ValidateDataStructure);
+        return nullptr != scene;
+    }
+
 #ifndef ASSIMP_BUILD_NO_EXPORT
 #ifndef ASSIMP_BUILD_NO_EXPORT
     virtual bool exporterTest() {
     virtual bool exporterTest() {
         Assimp::Importer importer;
         Assimp::Importer importer;
@@ -74,6 +80,10 @@ TEST_F( utglTF2ImportExport, importglTF2FromFileTest ) {
     EXPECT_TRUE( importerTest() );
     EXPECT_TRUE( importerTest() );
 }
 }
 
 
+TEST_F( utglTF2ImportExport, importBinaryglTF2FromFileTest ) {
+    EXPECT_TRUE( binaryImporterTest() );
+}
+
 #ifndef ASSIMP_BUILD_NO_EXPORT
 #ifndef ASSIMP_BUILD_NO_EXPORT
 TEST_F( utglTF2ImportExport, exportglTF2FromFileTest ) {
 TEST_F( utglTF2ImportExport, exportglTF2FromFileTest ) {
     EXPECT_TRUE( exporterTest() );
     EXPECT_TRUE( exporterTest() );