Skip to content

Commit

Permalink
Backwards compatible assimp texture name fix (#565)
Browse files Browse the repository at this point in the history
* Backwards compatible assimp texture name fix

Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>

* Fix test

Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>

---------

Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
  • Loading branch information
luca-della-vedova authored Dec 14, 2023
1 parent 983a1eb commit 680d797
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion graphics/src/AssimpLoader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 6 additions & 0 deletions graphics/src/AssimpLoader_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down

0 comments on commit 680d797

Please sign in to comment.