From 98a9aaf9322f0dc2592d8c8679863e9b8e753f66 Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Fri, 1 Mar 2024 22:51:51 +0000 Subject: [PATCH 1/3] parse transmission, add test Signed-off-by: Ian Chen --- graphics/src/AssimpLoader.cc | 21 +++++++++++++++++++-- graphics/src/AssimpLoader_TEST.cc | 22 ++++++++++++++++++++++ test/data/box_transmission.glb | Bin 0 -> 2140 bytes 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 test/data/box_transmission.glb diff --git a/graphics/src/AssimpLoader.cc b/graphics/src/AssimpLoader.cc index 9e49046e..d664352f 100644 --- a/graphics/src/AssimpLoader.cc +++ b/graphics/src/AssimpLoader.cc @@ -357,8 +357,24 @@ MaterialPtr AssimpLoader::Implementation::CreateMaterial( } float opacity = 1.0; ret = assimpMat->Get(AI_MATKEY_OPACITY, opacity); - mat->SetTransparency(1.0 - opacity); - mat->SetBlendFactors(opacity, 1.0 - opacity); + if (ret == AI_SUCCESS) + { + mat->SetTransparency(1.0 - opacity); + mat->SetBlendFactors(opacity, 1.0 - opacity); + } + + // basic support for transmission - currently just overrides opacity + // \todo(iche033) The transmission factor can be used with volume + // material extension to simulate effects like refraction + // so consider also extending support for other properties like + // AI_MATKEY_VOLUME_THICKNESS_FACTOR + float transmission = 0.0; + ret = assimpMat->Get(AI_MATKEY_TRANSMISSION_FACTOR, transmission); + if (ret == AI_SUCCESS) + { + mat->SetTransparency(transmission); + } + // TODO(luca) more than one texture, Gazebo assumes UV index 0 Pbr pbr; aiString texturePath(_path.c_str()); @@ -593,6 +609,7 @@ std::string AssimpLoader::Implementation::GenerateTextureName( "_" + _type; } +////////////////////////////////////////////////// SubMesh AssimpLoader::Implementation::CreateSubMesh( const aiMesh* _assimpMesh, const math::Matrix4d& _transform) const { diff --git a/graphics/src/AssimpLoader_TEST.cc b/graphics/src/AssimpLoader_TEST.cc index 40a99f7f..4627ca93 100644 --- a/graphics/src/AssimpLoader_TEST.cc +++ b/graphics/src/AssimpLoader_TEST.cc @@ -665,6 +665,28 @@ TEST_F(AssimpLoader, LoadGlTF2BoxExternalTexture) delete mesh; } +///////////////////////////////////////////////// +// Open a gltf mesh with transmission extension +TEST_F(AssimpLoader, LoadGlTF2BoxTransmission) +{ + common::AssimpLoader loader; + common::Mesh *mesh = loader.Load( + common::testing::TestFile("data", "box_transmission.glb")); + + EXPECT_STREQ("unknown", mesh->Name().c_str()); + + // Make sure we can read the submesh name + EXPECT_STREQ("Cube", mesh->SubMeshByIndex(0).lock()->Name().c_str()); + + EXPECT_EQ(mesh->MaterialCount(), 1u); + + const common::MaterialPtr mat = mesh->MaterialByIndex(0u); + ASSERT_TRUE(mat.get()); + // transmission currently modeled as transparency + EXPECT_FLOAT_EQ(0.1, mat->Transparency()); + delete mesh; +} + ///////////////////////////////////////////////// // This test loads a box glb mesh with embedded compressed jpeg texture TEST_F(AssimpLoader, LoadGlTF2BoxWithJPEGTexture) diff --git a/test/data/box_transmission.glb b/test/data/box_transmission.glb new file mode 100644 index 0000000000000000000000000000000000000000..adc74d3881100ce746497fd1d1aeacf809f2eb54 GIT binary patch literal 2140 zcmb7ETT|0O6g~nfC|(fM*UUc0nxywWh)`juK;yKPaRwPk+il5An=qRcVLF}ZKhvM( zqvve1r43N(!tU8~`_9>Kw`q53y9)sDa~a_862RB0UG6g{2zbZ}eb(k47f$F4R$%+* z!uR|@Yh#MG-Qix73$66g)-IEYOv1`Con3MfxW0$MR>EKdo$;%Xdt?f}2fWD&$83ME za@uu5E?lP*oQA^jg036LEIsCQvFwS?f(ACh3P!XG5T(yNr;9dLl|G$$ev^~KI2mAu z()z5+gL9c0#TR>Z&M0Kuf<$Zjy?TdN-6r)IiXNZroOqbgHF_scvFkJ>T}Hw*M#D_y z4b#k+7V`R&`|Jc6Di#XG`KSqw3Y- z*1=XqKKC1PCdraS)vrT-z`b^eKNKsM(-|4;R!e>X@a98DwCQ7zOyx6pC5noNb0yfk z+4w}KE2pz`kU48-W6AgvnodsAQyq~I5ioJ;T#6o)rtK{PY?sRTH5_h6^Y;UL@~fEp z_L~zJ_w5x1`S02*8_8LF<)0-tqka?)>G8eNN#3zXisT?44dM%ik(35nM!95HLt#mM zsH``6bK_t=8A}j|qxy)~l5W*o)T@e-Ihd=4>@5~UK2>MjTP)@l4%X9f!X5I@r;$A_ zDSn8)xTH9;$0fymj_^sI;RKu%M>?RK)HSpXagwBQM!Lc!8}5}3@CaVQ2Cf_M6rRBo sSjTl8-osmX1FN{M!Yg Date: Fri, 1 Mar 2024 23:56:59 +0000 Subject: [PATCH 2/3] check assimp ver Signed-off-by: Ian Chen --- graphics/src/AssimpLoader.cc | 2 ++ graphics/src/AssimpLoader_TEST.cc | 2 ++ graphics/src/CMakeLists.txt | 10 ++++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/graphics/src/AssimpLoader.cc b/graphics/src/AssimpLoader.cc index d664352f..24b2f2fa 100644 --- a/graphics/src/AssimpLoader.cc +++ b/graphics/src/AssimpLoader.cc @@ -363,6 +363,7 @@ MaterialPtr AssimpLoader::Implementation::CreateMaterial( mat->SetBlendFactors(opacity, 1.0 - opacity); } +#ifndef GZ_ASSIMP_PRE_5_1_0 // basic support for transmission - currently just overrides opacity // \todo(iche033) The transmission factor can be used with volume // material extension to simulate effects like refraction @@ -374,6 +375,7 @@ MaterialPtr AssimpLoader::Implementation::CreateMaterial( { mat->SetTransparency(transmission); } +#endif // TODO(luca) more than one texture, Gazebo assumes UV index 0 Pbr pbr; diff --git a/graphics/src/AssimpLoader_TEST.cc b/graphics/src/AssimpLoader_TEST.cc index 4627ca93..3a42c0fc 100644 --- a/graphics/src/AssimpLoader_TEST.cc +++ b/graphics/src/AssimpLoader_TEST.cc @@ -669,6 +669,7 @@ TEST_F(AssimpLoader, LoadGlTF2BoxExternalTexture) // Open a gltf mesh with transmission extension TEST_F(AssimpLoader, LoadGlTF2BoxTransmission) { +#ifdef GZ_ASSIMP_PRE_5_1_0 common::AssimpLoader loader; common::Mesh *mesh = loader.Load( common::testing::TestFile("data", "box_transmission.glb")); @@ -685,6 +686,7 @@ TEST_F(AssimpLoader, LoadGlTF2BoxTransmission) // transmission currently modeled as transparency EXPECT_FLOAT_EQ(0.1, mat->Transparency()); delete mesh; +#endif } ///////////////////////////////////////////////// diff --git a/graphics/src/CMakeLists.txt b/graphics/src/CMakeLists.txt index aa832387..b153bf67 100644 --- a/graphics/src/CMakeLists.txt +++ b/graphics/src/CMakeLists.txt @@ -29,16 +29,22 @@ gz_build_tests( ) # Assimp doesn't offer preprocessor version, use cmake to set a compatibility -# mode for versions below 5.2.0 +# mode for versions below 5.2.0 and 5.1.0 if(${GzAssimp_VERSION} STRLESS "5.2.0") message("Warning, assimp below 5.2.0 detected, setting compatibility mode") target_compile_definitions(${graphics_target} PRIVATE GZ_ASSIMP_PRE_5_2_0) if(TARGET UNIT_AssimpLoader_TEST) target_compile_definitions(UNIT_AssimpLoader_TEST PRIVATE GZ_ASSIMP_PRE_5_2_0) endif() + if(${GzAssimp_VERSION} STRLESS "5.1.0") + message("Warning, assimp below 5.1.0 detected, setting compatibility mode") + target_compile_definitions(${graphics_target} PRIVATE GZ_ASSIMP_PRE_5_1_0) + if(TARGET UNIT_AssimpLoader_TEST) + target_compile_definitions(UNIT_AssimpLoader_TEST PRIVATE GZ_ASSIMP_PRE_5_1_0) + endif() + endif() endif() - if(USE_EXTERNAL_TINYXML2) # If we are using an external copy of tinyxml2, add its imported target From 8ea66e1336b5e0164b24769bc6adb8f3d0e34b3d Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Sat, 2 Mar 2024 00:27:46 +0000 Subject: [PATCH 3/3] fix test for focal Signed-off-by: Ian Chen --- graphics/src/AssimpLoader_TEST.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphics/src/AssimpLoader_TEST.cc b/graphics/src/AssimpLoader_TEST.cc index 3a42c0fc..6be2e579 100644 --- a/graphics/src/AssimpLoader_TEST.cc +++ b/graphics/src/AssimpLoader_TEST.cc @@ -669,7 +669,7 @@ TEST_F(AssimpLoader, LoadGlTF2BoxExternalTexture) // Open a gltf mesh with transmission extension TEST_F(AssimpLoader, LoadGlTF2BoxTransmission) { -#ifdef GZ_ASSIMP_PRE_5_1_0 +#ifndef GZ_ASSIMP_PRE_5_1_0 common::AssimpLoader loader; common::Mesh *mesh = loader.Load( common::testing::TestFile("data", "box_transmission.glb"));