From 680d79777d5c1437e225c38c9e144734fab83285 Mon Sep 17 00:00:00 2001 From: Luca Della Vedova Date: Thu, 14 Dec 2023 22:44:56 +0800 Subject: [PATCH] Backwards compatible assimp texture name fix (#565) * Backwards compatible assimp texture name fix Signed-off-by: Luca Della Vedova * Fix test Signed-off-by: Luca Della Vedova --------- Signed-off-by: Luca Della Vedova --- graphics/src/AssimpLoader.cc | 7 ++++++- graphics/src/AssimpLoader_TEST.cc | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/graphics/src/AssimpLoader.cc b/graphics/src/AssimpLoader.cc index 2eda1248..9e49046e 100644 --- a/graphics/src/AssimpLoader.cc +++ b/graphics/src/AssimpLoader.cc @@ -584,7 +584,12 @@ ImagePtr AssimpLoader::Implementation::LoadEmbeddedTexture( std::string AssimpLoader::Implementation::GenerateTextureName( const aiScene* _scene, aiMaterial* _mat, const std::string& _type) const { - return ToString(_scene->mRootNode->mName) + "_" + ToString(_mat->GetName()) + +#ifdef GZ_ASSIMP_PRE_5_2_0 + auto rootName = _scene->mRootNode->mName; +#else + auto rootName = _scene->mName; +#endif + return ToString(rootName) + "_" + ToString(_mat->GetName()) + "_" + _type; } diff --git a/graphics/src/AssimpLoader_TEST.cc b/graphics/src/AssimpLoader_TEST.cc index 5df30d0f..5407a595 100644 --- a/graphics/src/AssimpLoader_TEST.cc +++ b/graphics/src/AssimpLoader_TEST.cc @@ -673,7 +673,13 @@ TEST_F(AssimpLoader, LoadGlTF2BoxWithJPEGTexture) EXPECT_EQ(math::Color(0.4f, 0.4f, 0.4f, 1.0f), mat->Ambient()); EXPECT_EQ(math::Color(1.0f, 1.0f, 1.0f, 1.0f), mat->Diffuse()); EXPECT_EQ(math::Color(0.0f, 0.0f, 0.0f, 1.0f), mat->Specular()); + // Assimp 5.2.0 and above uses the scene name for its texture names, + // older version use the root node instead. +#ifdef GZ_ASSIMP_PRE_5_2_0 EXPECT_EQ("Cube_Material_Diffuse", mat->TextureImage()); +#else + EXPECT_EQ("Scene_Material_Diffuse", mat->TextureImage()); +#endif EXPECT_NE(nullptr, mat->TextureData()); }