Skip to content

Commit

Permalink
parse transmission, add test
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Chen <[email protected]>
  • Loading branch information
iche033 committed Mar 1, 2024
1 parent 3374a3b commit 98a9aaf
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
21 changes: 19 additions & 2 deletions graphics/src/AssimpLoader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -593,6 +609,7 @@ std::string AssimpLoader::Implementation::GenerateTextureName(
"_" + _type;
}

//////////////////////////////////////////////////
SubMesh AssimpLoader::Implementation::CreateSubMesh(
const aiMesh* _assimpMesh, const math::Matrix4d& _transform) const
{
Expand Down
22 changes: 22 additions & 0 deletions graphics/src/AssimpLoader_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Binary file added test/data/box_transmission.glb
Binary file not shown.

0 comments on commit 98a9aaf

Please sign in to comment.