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

Support for Gazebo materials #2269

Merged
merged 21 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
28 changes: 17 additions & 11 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,9 @@ gz_msgs_generate_messages_impl(
DEPENDENCY_DESCRIPTIONS ${msgs_desc_file}
)

set(network_sources
network/NetworkConfig.cc
network/NetworkManager.cc
network/NetworkManagerPrimary.cc
network/NetworkManagerSecondary.cc
network/PeerInfo.cc
network/PeerTracker.cc
set(cli_sources
gz.cc
cmd/ModelCommandAPI.cc
)

set(comms_sources
Expand All @@ -55,9 +51,18 @@ set(gui_sources
PARENT_SCOPE
)

set(cli_sources
gz.cc
cmd/ModelCommandAPI.cc
set(material_sources
rendering/MaterialParser/MaterialParser.cc
rendering/MaterialParser/ConfigLoader.cc
)

set(network_sources
azeey marked this conversation as resolved.
Show resolved Hide resolved
network/NetworkConfig.cc
network/NetworkManager.cc
network/NetworkManagerPrimary.cc
network/NetworkManagerSecondary.cc
network/PeerInfo.cc
network/PeerTracker.cc
)

set (sources
Expand Down Expand Up @@ -89,9 +94,10 @@ set (sources
Util.cc
View.cc
World.cc
${network_sources}
${comms_sources}
${msgs_sources}
${network_sources}
${material_sources}
)

set (gtest_sources
Expand Down
29 changes: 28 additions & 1 deletion src/SdfEntityCreator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
#include "gz/sim/components/WindMode.hh"
#include "gz/sim/components/World.hh"

#include "rendering/MaterialParser/MaterialParser.hh"

class gz::sim::SdfEntityCreatorPrivate
{
/// \brief Pointer to entity component manager. We don't assume ownership.
Expand Down Expand Up @@ -788,8 +790,33 @@ Entity SdfEntityCreator::CreateEntities(const sdf::Visual *_visual)
// \todo(louise) Populate with default material if undefined
if (_visual->Material())
{
sdf::Material visualMaterial = *_visual->Material();
if (!_visual->Material()->ScriptUri().empty())
{
std::string scriptUri = visualMaterial.ScriptUri();
if (scriptUri != "file://media/materials/scripts/gazebo.material") {
gzwarn << "Custom material scripts are not supported."
<< std::endl;
}
}
if (!_visual->Material()->ScriptName().empty())
{
std::string scriptName = visualMaterial.ScriptName();

if((scriptName.find("Gazebo/") != std::string::npos)) {
quarkytale marked this conversation as resolved.
Show resolved Hide resolved
gzwarn << "Using internal gazebo.material to parse " << scriptName
<< std::endl;
MaterialParser* materialParser = new MaterialParser();
quarkytale marked this conversation as resolved.
Show resolved Hide resolved
materialParser->Load();
std::vector<std::vector<float>> parsed = materialParser->GetMaterialValues(scriptName);

visualMaterial.SetAmbient(gz::math::Color(parsed[0][0],parsed[0][1], parsed[0][2]));
quarkytale marked this conversation as resolved.
Show resolved Hide resolved
visualMaterial.SetDiffuse(gz::math::Color(parsed[1][0],parsed[1][1], parsed[1][2]));
visualMaterial.SetSpecular(gz::math::Color(parsed[2][0],parsed[2][1], parsed[2][2], parsed[2][3]));
}
}
this->dataPtr->ecm->CreateComponent(visualEntity,
components::Material(*_visual->Material()));
components::Material(visualMaterial));
}

// store the plugin in a component
Expand Down
Loading
Loading