Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Dharini Dutia <[email protected]>
  • Loading branch information
quarkytale committed Jan 6, 2024
1 parent 26c61ca commit eacd18f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
21 changes: 12 additions & 9 deletions src/SdfEntityCreator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -817,17 +817,20 @@ Entity SdfEntityCreator::CreateEntities(const sdf::Visual *_visual)
std::optional<MaterialParser::MaterialValues> parsed =
this->dataPtr->materialParser.GetMaterialValues(scriptName);

if(!parsed.has_value()) {
if(parsed.has_value())
{
visualMaterial.SetAmbient
(parsed->ambient.value_or(visualMaterial.Ambient()));
visualMaterial.SetDiffuse
(parsed->diffuse.value_or(visualMaterial.Diffuse()));
visualMaterial.SetSpecular
(parsed->specular.value_or(visualMaterial.Specular()));
}
else
{
gzwarn << "Material " << scriptName <<
" not recognized, using default." << std::endl;
" not recognized or supported, using default." << std::endl;
}

visualMaterial.SetAmbient
(parsed->ambient.value_or(visualMaterial.Ambient()));
visualMaterial.SetDiffuse
(parsed->diffuse.value_or(visualMaterial.Diffuse()));
visualMaterial.SetSpecular
(parsed->specular.value_or(visualMaterial.Specular()));
}
}
this->dataPtr->ecm->CreateComponent(visualEntity,
Expand Down
19 changes: 7 additions & 12 deletions src/rendering/MaterialParser/MaterialParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void MaterialParser::Load()
std::optional<MaterialParser::MaterialValues> MaterialParser::GetMaterialValues(
const std::string& material)
{
MaterialValues values;
std::optional<MaterialValues> values;
std::map<std::string, ConfigNode *> scripts =
this->configLoader.getAllConfigScripts();

Expand All @@ -57,25 +57,20 @@ std::optional<MaterialParser::MaterialValues> MaterialParser::GetMaterialValues(
if (techniqueNode) {
ConfigNode * passNode = techniqueNode->findChild("pass");
if (passNode) {
std::size_t index = name.rfind(" ");
if (index != std::string::npos) {
name = name.substr(index + 1);
}

ConfigNode * ambientNode = passNode->findChild("ambient");
if (ambientNode) {
std::vector<float> ambientValues;
ambientNode->getValuesInFloat(ambientValues);
values.ambient = gz::math::Color(ambientValues[0],
ambientValues[1], ambientValues[2]);
values->ambient.emplace(gz::math::Color(ambientValues[0],
ambientValues[1], ambientValues[2]));
}

ConfigNode * diffuseNode = passNode->findChild("diffuse");
if (diffuseNode) {
std::vector<float> diffuseValues;
diffuseNode->getValuesInFloat(diffuseValues);
values.diffuse = gz::math::Color(diffuseValues[0],
diffuseValues[1], diffuseValues[2]);
values->diffuse.emplace(gz::math::Color(diffuseValues[0],
diffuseValues[1], diffuseValues[2]));
}

ConfigNode * specularNode = passNode->findChild("specular");
Expand All @@ -84,8 +79,8 @@ std::optional<MaterialParser::MaterialValues> MaterialParser::GetMaterialValues(
specularNode->getValuesInFloat(specularValues);
// Using first four values for specular as
// Gazebo doesn't support shininess
values.specular = gz::math::Color(specularValues[0],
specularValues[1], specularValues[2], specularValues[3]);
values->specular.emplace(gz::math::Color(specularValues[0],
specularValues[1], specularValues[2], specularValues[3]));
}
}
}
Expand Down

0 comments on commit eacd18f

Please sign in to comment.