Skip to content

Commit

Permalink
Merge pull request #3069 from ms-maxvollmer/GLTF2_guarantee_rootnode_fix
Browse files Browse the repository at this point in the history
GLTF2: Fixed behavior of glTF2Importer::ImportNodes
  • Loading branch information
kimkulling committed Mar 26, 2020
2 parents 16725cc + ef20cdc commit da8b174
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
6 changes: 4 additions & 2 deletions code/glTF2/glTF2Importer.cpp
Expand Up @@ -952,8 +952,8 @@ aiNode *ImportNode(aiScene *pScene, glTF2::Asset &r, std::vector<unsigned int> &

void glTF2Importer::ImportNodes(glTF2::Asset &r) {
if (!r.scene) {
return;
}
throw DeadlyImportError("GLTF: No scene");
}

std::vector<Ref<Node>> rootNodes = r.scene->nodes;

Expand All @@ -970,6 +970,8 @@ void glTF2Importer::ImportNodes(glTF2::Asset &r) {
root->mChildren[root->mNumChildren++] = node;
}
mScene->mRootNode = root;
} else {
mScene->mRootNode = new aiNode("ROOT");
}
}

Expand Down
6 changes: 6 additions & 0 deletions test/models/glTF2/TestNoRootNode/NoScene.gltf
@@ -0,0 +1,6 @@
{
"asset": {
"version": "2.0"
},
"scene": 0
}
10 changes: 10 additions & 0 deletions test/models/glTF2/TestNoRootNode/SceneWithoutNodes.gltf
@@ -0,0 +1,10 @@
{
"asset": {
"version": "2.0"
},
"scene": 0,
"scenes": [
{
}
]
}
13 changes: 13 additions & 0 deletions test/unit/utglTF2ImportExport.cpp
Expand Up @@ -490,3 +490,16 @@ TEST_F(utglTF2ImportExport, texcoords) {
EXPECT_EQ(aiGetMaterialInteger(material, AI_MATKEY_GLTF_TEXTURE_TEXCOORD(aiTextureType_UNKNOWN, 0), &uvIndex), aiReturn_SUCCESS);
EXPECT_EQ(uvIndex, 1);
}

TEST_F(utglTF2ImportExport, norootnode_noscene) {
Assimp::Importer importer;
const aiScene* scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/TestNoRootNode/NoScene.gltf", aiProcess_ValidateDataStructure);
ASSERT_EQ(scene, nullptr);
}

TEST_F(utglTF2ImportExport, norootnode_scenewithoutnodes) {
Assimp::Importer importer;
const aiScene* scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/TestNoRootNode/SceneWithoutNodes.gltf", aiProcess_ValidateDataStructure);
ASSERT_NE(scene, nullptr);
ASSERT_NE(scene->mRootNode, nullptr);
}

0 comments on commit da8b174

Please sign in to comment.