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 00000000..adc74d38 Binary files /dev/null and b/test/data/box_transmission.glb differ