diff --git a/code/glTF2/glTF2Importer.cpp b/code/glTF2/glTF2Importer.cpp index e05c97264..caff630dc 100644 --- a/code/glTF2/glTF2Importer.cpp +++ b/code/glTF2/glTF2Importer.cpp @@ -952,8 +952,8 @@ aiNode *ImportNode(aiScene *pScene, glTF2::Asset &r, std::vector & void glTF2Importer::ImportNodes(glTF2::Asset &r) { if (!r.scene) { - return; - } + throw DeadlyImportError("GLTF: No scene"); + } std::vector> rootNodes = r.scene->nodes; @@ -970,6 +970,8 @@ void glTF2Importer::ImportNodes(glTF2::Asset &r) { root->mChildren[root->mNumChildren++] = node; } mScene->mRootNode = root; + } else { + mScene->mRootNode = new aiNode("ROOT"); } } diff --git a/test/models/glTF2/TestNoRootNode/NoScene.gltf b/test/models/glTF2/TestNoRootNode/NoScene.gltf new file mode 100644 index 000000000..6cad71ed4 --- /dev/null +++ b/test/models/glTF2/TestNoRootNode/NoScene.gltf @@ -0,0 +1,6 @@ +{ + "asset": { + "version": "2.0" + }, + "scene": 0 +} diff --git a/test/models/glTF2/TestNoRootNode/SceneWithoutNodes.gltf b/test/models/glTF2/TestNoRootNode/SceneWithoutNodes.gltf new file mode 100644 index 000000000..d426ca569 --- /dev/null +++ b/test/models/glTF2/TestNoRootNode/SceneWithoutNodes.gltf @@ -0,0 +1,10 @@ +{ + "asset": { + "version": "2.0" + }, + "scene": 0, + "scenes": [ + { + } + ] +} diff --git a/test/unit/utglTF2ImportExport.cpp b/test/unit/utglTF2ImportExport.cpp index 739d844e5..55cd2ef6a 100644 --- a/test/unit/utglTF2ImportExport.cpp +++ b/test/unit/utglTF2ImportExport.cpp @@ -496,3 +496,16 @@ TEST_F(utglTF2ImportExport, recursive_nodes) { const aiScene* scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/RecursiveNodes/RecursiveNodes.gltf", aiProcess_ValidateDataStructure); EXPECT_EQ(nullptr, scene); } + +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); +}