Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3 ➡️ 4 Forward port Scene3D mesh material fixes #192

Merged
merged 2 commits into from
Mar 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 34 additions & 13 deletions src/plugins/scene3d/Scene3D.cc
Original file line number Diff line number Diff line change
Expand Up @@ -603,11 +603,7 @@ rendering::VisualPtr SceneManager::LoadVisual(const msgs::Visual &_msg)
// Don't set a default material for meshes because they
// may have their own
// TODO(anyone) support overriding mesh material
else if (_msg.geometry().has_mesh())
{
material = geom->Material();
}
else
else if (!_msg.geometry().has_mesh())
{
// create default material
material = this->scene->Material("ign-grey");
Expand All @@ -621,15 +617,40 @@ rendering::VisualPtr SceneManager::LoadVisual(const msgs::Visual &_msg)
material->SetMetalness(1.0f);
}
}
else
{
// meshes created by mesh loader may have their own materials
// update/override their properties based on input sdf element values
auto mesh = std::dynamic_pointer_cast<rendering::Mesh>(geom);
for (unsigned int i = 0; i < mesh->SubMeshCount(); ++i)
{
auto submesh = mesh->SubMeshByIndex(i);
auto submeshMat = submesh->Material();
if (submeshMat)
{
double productAlpha = (1.0-_msg.transparency()) *
(1.0 - submeshMat->Transparency());
submeshMat->SetTransparency(1 - productAlpha);
submeshMat->SetCastShadows(_msg.cast_shadows());
}
}
}

material->SetTransparency(_msg.transparency());

// TODO(anyone) Get roughness and metalness from message instead
// of giving a default value.
material->SetRoughness(0.3f);
material->SetMetalness(0.3f);

geom->SetMaterial(material);
if (material)
{
// set transparency
material->SetTransparency(_msg.transparency());

// cast shadows
material->SetCastShadows(_msg.cast_shadows());

geom->SetMaterial(material);
// todo(anyone) SetMaterial function clones the input material.
// but does not take ownership of it so we need to destroy it here.
// This is not ideal. We should let ign-rendering handle the lifetime
// of this material
this->scene->DestroyMaterial(material);
}
}
else
{
Expand Down