Skip to content

Commit

Permalink
Merge branch 'sdf9' into jennuine/parse_inf
Browse files Browse the repository at this point in the history
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
  • Loading branch information
jennuine committed Aug 4, 2021
2 parents 650b544 + 89be29b commit 808253c
Show file tree
Hide file tree
Showing 14 changed files with 204 additions and 16 deletions.
15 changes: 15 additions & 0 deletions include/sdf/Pbr.hh
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,21 @@ namespace sdf
/// \param[in] _map Filename of the emissive map.
public: void SetEmissiveMap(const std::string &_map);

/// \brief Get the light map filename. This will be an empty string
/// if an light map has not been set.
/// \return Filename of the light map, or empty string if a light
/// map has not been specified.
public: std::string LightMap() const;

/// \brief Set the light map filename.
/// \param[in] _map Filename of the light map.
/// \param[in] _uvSet Index of the light map texture coordinate set
public: void SetLightMap(const std::string &_map, unsigned int _uvSet = 0u);

/// \brief Get the light map texture coordinate set.
/// \return Index of the texture coordinate set
public: unsigned int LightMapTexCoordSet() const;

/// \brief Get the metalness value of the material for metal workflow
/// \return metalness value of the material
public: double Metalness() const;
Expand Down
15 changes: 15 additions & 0 deletions sdf/1.7/material.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@
<element name="emissive_map" type="string" default="" required="0">
<description>Filename of the emissive map.</description>
</element>

<element name="light_map" type="string" default="" required="0">
<attribute name="uv_set" type="unsigned int" default="0" required="0">
<description>Index of the texture coordinate set to use.</description>
</attribute>
<description>Filename of the light map. The light map is a prebaked light texture that is applied over the albedo map</description>
</element>

</element>

<element name="specular" required="0">
Expand Down Expand Up @@ -135,6 +143,13 @@
<element name="emissive_map" type="string" default="" required="0">
<description>Filename of the emissive map.</description>
</element>

<element name="light_map" type="string" default="" required="0">
<attribute name="uv_set" type="unsigned int" default="0" required="0">
<description>Index of the texture coordinate set to use.</description>
</attribute>
<description>Filename of the light map. The light map is a prebaked light texture that is applied over the albedo map</description>
</element>
</element>

</element>
Expand Down
34 changes: 34 additions & 0 deletions src/Pbr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ class sdf::PbrWorkflowPrivate
/// \brief Emissive map
public: std::string emissiveMap = "";

/// \brief Light map
public: std::string lightMapFilename;

/// \brief Light map texture coordinate set
public: unsigned int lightMapUvSet = 0u;

/// \brief Roughness value (metal workflow only)
public: double roughness = 0.5;

Expand Down Expand Up @@ -140,6 +146,7 @@ bool PbrWorkflow::operator==(const PbrWorkflow &_workflow) const
&& (this->dataPtr->glossinessMap == _workflow.dataPtr->glossinessMap)
&& (this->dataPtr->environmentMap == _workflow.dataPtr->environmentMap)
&& (this->dataPtr->emissiveMap == _workflow.dataPtr->emissiveMap)
&& (this->dataPtr->lightMapFilename == _workflow.dataPtr->lightMapFilename)
&& (this->dataPtr->ambientOcclusionMap ==
_workflow.dataPtr->ambientOcclusionMap)
&& (ignition::math::equal(
Expand Down Expand Up @@ -212,6 +219,14 @@ Errors PbrWorkflow::Load(sdf::ElementPtr _sdf)
this->dataPtr->emissiveMap = _sdf->Get<std::string>("emissive_map",
this->dataPtr->emissiveMap).first;

if (_sdf->HasElement("light_map"))
{
sdf::ElementPtr lightMapElem = _sdf->GetElement("light_map");
this->dataPtr->lightMapFilename = lightMapElem->Get<std::string>();
this->dataPtr->lightMapUvSet = lightMapElem->Get<unsigned int>("uv_set",
this->dataPtr->lightMapUvSet).first;
}

return errors;
}

Expand Down Expand Up @@ -366,6 +381,25 @@ void PbrWorkflow::SetEmissiveMap(const std::string &_map)
this->dataPtr->emissiveMap = _map;
}

//////////////////////////////////////////////////
std::string PbrWorkflow::LightMap() const
{
return this->dataPtr->lightMapFilename;
}

//////////////////////////////////////////////////
void PbrWorkflow::SetLightMap(const std::string &_map, unsigned int _uvSet)
{
this->dataPtr->lightMapFilename = _map;
this->dataPtr->lightMapUvSet = _uvSet;
}

//////////////////////////////////////////////////
unsigned int PbrWorkflow::LightMapTexCoordSet() const
{
return this->dataPtr->lightMapUvSet;
}

//////////////////////////////////////////////////
sdf::ElementPtr PbrWorkflow::Element() const
{
Expand Down
34 changes: 34 additions & 0 deletions src/Pbr_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ TEST(DOMPbr, Construction)
EXPECT_EQ(std::string(), workflow.RoughnessMap());
EXPECT_EQ(std::string(), workflow.MetalnessMap());
EXPECT_EQ(std::string(), workflow.EmissiveMap());
EXPECT_EQ(std::string(), workflow.LightMap());
EXPECT_EQ(0u, workflow.LightMapTexCoordSet());
EXPECT_DOUBLE_EQ(0.5, workflow.Roughness());
EXPECT_DOUBLE_EQ(0.5, workflow.Metalness());
EXPECT_EQ(std::string(), workflow.SpecularMap());
Expand Down Expand Up @@ -70,6 +72,7 @@ TEST(DOMPbr, MoveConstructor)
workflow.SetEnvironmentMap("metal_env_map.png");
workflow.SetAmbientOcclusionMap("metal_ambient_occlusion_map.png");
workflow.SetEmissiveMap("metal_emissive_map.png");
workflow.SetLightMap("metal_light_map.png", 1u);
workflow.SetRoughnessMap("roughness_map.png");
workflow.SetMetalnessMap("metalness_map.png");
workflow.SetRoughness(0.8);
Expand All @@ -84,6 +87,8 @@ TEST(DOMPbr, MoveConstructor)
EXPECT_EQ("metal_ambient_occlusion_map.png",
workflow2.AmbientOcclusionMap());
EXPECT_EQ("metal_emissive_map.png", workflow2.EmissiveMap());
EXPECT_EQ("metal_light_map.png", workflow2.LightMap());
EXPECT_EQ(1u, workflow2.LightMapTexCoordSet());
EXPECT_EQ("roughness_map.png", workflow2.RoughnessMap());
EXPECT_EQ("metalness_map.png", workflow2.MetalnessMap());
EXPECT_DOUBLE_EQ(0.8, workflow2.Roughness());
Expand All @@ -104,6 +109,7 @@ TEST(DOMPbr, MoveConstructor)
workflow.SetEnvironmentMap("specular_env_map.png");
workflow.SetAmbientOcclusionMap("specular_ambient_occlusion_map.png");
workflow.SetEmissiveMap("specular_emissive_map.png");
workflow.SetLightMap("specular_light_map.png", 2u);
workflow.SetGlossinessMap("glossiness_map.png");
workflow.SetSpecularMap("specular_map.png");
workflow.SetGlossiness(0.1);
Expand All @@ -117,6 +123,8 @@ TEST(DOMPbr, MoveConstructor)
EXPECT_EQ("specular_ambient_occlusion_map.png",
workflow2.AmbientOcclusionMap());
EXPECT_EQ("specular_emissive_map.png", workflow2.EmissiveMap());
EXPECT_EQ("specular_light_map.png", workflow2.LightMap());
EXPECT_EQ(2u, workflow2.LightMapTexCoordSet());
EXPECT_EQ("specular_map.png", workflow2.SpecularMap());
EXPECT_EQ("glossiness_map.png", workflow2.GlossinessMap());
EXPECT_DOUBLE_EQ(0.1, workflow2.Glossiness());
Expand Down Expand Up @@ -155,6 +163,7 @@ TEST(DOMPbr, MoveAssignmentOperator)
workflow.SetEnvironmentMap("metal_env_map.png");
workflow.SetAmbientOcclusionMap("metal_ambient_occlusion_map.png");
workflow.SetEmissiveMap("metal_emissive_map.png");
workflow.SetLightMap("metal_light_map.png", 3u);
workflow.SetRoughnessMap("roughness_map.png");
workflow.SetMetalnessMap("metalness_map.png");
workflow.SetRoughness(0.8);
Expand All @@ -170,6 +179,8 @@ TEST(DOMPbr, MoveAssignmentOperator)
EXPECT_EQ("metal_ambient_occlusion_map.png",
workflow2.AmbientOcclusionMap());
EXPECT_EQ("metal_emissive_map.png", workflow2.EmissiveMap());
EXPECT_EQ("metal_light_map.png", workflow2.LightMap());
EXPECT_EQ(3u, workflow2.LightMapTexCoordSet());
EXPECT_EQ("roughness_map.png", workflow2.RoughnessMap());
EXPECT_EQ("metalness_map.png", workflow2.MetalnessMap());
EXPECT_DOUBLE_EQ(0.8, workflow2.Roughness());
Expand All @@ -190,6 +201,7 @@ TEST(DOMPbr, MoveAssignmentOperator)
workflow.SetEnvironmentMap("specular_env_map.png");
workflow.SetAmbientOcclusionMap("specular_ambient_occlusion_map.png");
workflow.SetEmissiveMap("specular_emissive_map.png");
workflow.SetLightMap("specular_light_map.png", 1u);
workflow.SetGlossinessMap("glossiness_map.png");
workflow.SetSpecularMap("specular_map.png");
workflow.SetGlossiness(0.1);
Expand All @@ -204,6 +216,8 @@ TEST(DOMPbr, MoveAssignmentOperator)
EXPECT_EQ("specular_ambient_occlusion_map.png",
workflow2.AmbientOcclusionMap());
EXPECT_EQ("specular_emissive_map.png", workflow2.EmissiveMap());
EXPECT_EQ("specular_light_map.png", workflow2.LightMap());
EXPECT_EQ(1u, workflow2.LightMapTexCoordSet());
EXPECT_EQ("specular_map.png", workflow2.SpecularMap());
EXPECT_EQ("glossiness_map.png", workflow2.GlossinessMap());
EXPECT_DOUBLE_EQ(0.1, workflow2.Glossiness());
Expand Down Expand Up @@ -241,6 +255,7 @@ TEST(DOMPbr, CopyConstructor)
workflow.SetEnvironmentMap("metal_env_map.png");
workflow.SetAmbientOcclusionMap("metal_ambient_occlusion_map.png");
workflow.SetEmissiveMap("metal_emissive_map.png");
workflow.SetLightMap("metal_light_map.png", 2u);
workflow.SetRoughnessMap("roughness_map.png");
workflow.SetMetalnessMap("metalness_map.png");
workflow.SetRoughness(0.8);
Expand All @@ -255,6 +270,8 @@ TEST(DOMPbr, CopyConstructor)
EXPECT_EQ("metal_ambient_occlusion_map.png",
workflow2.AmbientOcclusionMap());
EXPECT_EQ("metal_emissive_map.png", workflow2.EmissiveMap());
EXPECT_EQ("metal_light_map.png", workflow2.LightMap());
EXPECT_EQ(2u, workflow2.LightMapTexCoordSet());
EXPECT_EQ("roughness_map.png", workflow2.RoughnessMap());
EXPECT_EQ("metalness_map.png", workflow2.MetalnessMap());
EXPECT_DOUBLE_EQ(0.8, workflow2.Roughness());
Expand All @@ -274,6 +291,7 @@ TEST(DOMPbr, CopyConstructor)
workflow.SetEnvironmentMap("specular_env_map.png");
workflow.SetAmbientOcclusionMap("specular_ambient_occlusion_map.png");
workflow.SetEmissiveMap("specular_emissive_map.png");
workflow.SetLightMap("specular_light_map.png", 1u);
workflow.SetGlossinessMap("glossiness_map.png");
workflow.SetSpecularMap("specular_map.png");
workflow.SetGlossiness(0.1);
Expand All @@ -287,6 +305,8 @@ TEST(DOMPbr, CopyConstructor)
EXPECT_EQ("specular_ambient_occlusion_map.png",
workflow2.AmbientOcclusionMap());
EXPECT_EQ("specular_emissive_map.png", workflow2.EmissiveMap());
EXPECT_EQ("specular_light_map.png", workflow2.LightMap());
EXPECT_EQ(1u, workflow2.LightMapTexCoordSet());
EXPECT_EQ("specular_map.png", workflow2.SpecularMap());
EXPECT_EQ("glossiness_map.png", workflow2.GlossinessMap());
EXPECT_DOUBLE_EQ(0.1, workflow2.Glossiness());
Expand Down Expand Up @@ -325,6 +345,7 @@ TEST(DOMPbr, AssignmentOperator)
workflow.SetEnvironmentMap("metal_env_map.png");
workflow.SetAmbientOcclusionMap("metal_ambient_occlusion_map.png");
workflow.SetEmissiveMap("metal_emissive_map.png");
workflow.SetLightMap("metal_light_map.png", 1u);
workflow.SetRoughnessMap("roughness_map.png");
workflow.SetMetalnessMap("metalness_map.png");
workflow.SetRoughness(0.8);
Expand All @@ -339,6 +360,8 @@ TEST(DOMPbr, AssignmentOperator)
EXPECT_EQ("metal_ambient_occlusion_map.png",
workflow2.AmbientOcclusionMap());
EXPECT_EQ("metal_emissive_map.png", workflow2.EmissiveMap());
EXPECT_EQ("metal_light_map.png", workflow2.LightMap());
EXPECT_EQ(1u, workflow2.LightMapTexCoordSet());
EXPECT_EQ("roughness_map.png", workflow2.RoughnessMap());
EXPECT_EQ("metalness_map.png", workflow2.MetalnessMap());
EXPECT_DOUBLE_EQ(0.8, workflow2.Roughness());
Expand All @@ -358,6 +381,7 @@ TEST(DOMPbr, AssignmentOperator)
workflow.SetEnvironmentMap("specular_env_map.png");
workflow.SetAmbientOcclusionMap("specular_ambient_occlusion_map.png");
workflow.SetEmissiveMap("specular_emissive_map.png");
workflow.SetLightMap("specular_light_map.png", 2u);
workflow.SetGlossinessMap("glossiness_map.png");
workflow.SetSpecularMap("specular_map.png");
workflow.SetGlossiness(0.1);
Expand All @@ -370,6 +394,8 @@ TEST(DOMPbr, AssignmentOperator)
EXPECT_EQ("specular_ambient_occlusion_map.png",
workflow2.AmbientOcclusionMap());
EXPECT_EQ("specular_emissive_map.png", workflow2.EmissiveMap());
EXPECT_EQ("specular_light_map.png", workflow2.LightMap());
EXPECT_EQ(2u, workflow2.LightMapTexCoordSet());
EXPECT_EQ("specular_map.png", workflow2.SpecularMap());
EXPECT_EQ("glossiness_map.png", workflow2.GlossinessMap());
EXPECT_DOUBLE_EQ(0.1, workflow2.Glossiness());
Expand Down Expand Up @@ -443,6 +469,10 @@ TEST(DOMPbr, Set)
workflow.SetEmissiveMap("metal_emissive_map.png");
EXPECT_EQ("metal_emissive_map.png", workflow.EmissiveMap());

workflow.SetLightMap("metal_light_map.png", 1u);
EXPECT_EQ("metal_light_map.png", workflow.LightMap());
EXPECT_EQ(1u, workflow.LightMapTexCoordSet());

workflow.SetRoughnessMap("roughness_map.png");
EXPECT_EQ("roughness_map.png", workflow.RoughnessMap());

Expand Down Expand Up @@ -491,6 +521,10 @@ TEST(DOMPbr, Set)
workflow.SetEmissiveMap("specular_emissive_map.png");
EXPECT_EQ("specular_emissive_map.png", workflow.EmissiveMap());

workflow.SetLightMap("specular_light_map.png", 1u);
EXPECT_EQ("specular_light_map.png", workflow.LightMap());
EXPECT_EQ(1u, workflow.LightMapTexCoordSet());

workflow.SetGlossinessMap("glossiness_map.png");
EXPECT_EQ("glossiness_map.png", workflow.GlossinessMap());

Expand Down
2 changes: 2 additions & 0 deletions src/SDFExtension.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ SDFExtension::SDFExtension()
this->visual_blobs.clear();
this->collision_blobs.clear();
this->setStaticFlag = false;
this->isGravity = false;
this->gravity = true;
this->isDampingFactor = false;
this->isMaxContacts = false;
Expand Down Expand Up @@ -74,6 +75,7 @@ SDFExtension::SDFExtension(const SDFExtension &_ge)
this->visual_blobs = _ge.visual_blobs;
this->collision_blobs = _ge.collision_blobs;
this->setStaticFlag = _ge.setStaticFlag;
this->isGravity = _ge.isGravity;
this->gravity = _ge.gravity;
this->isDampingFactor = _ge.isDampingFactor;
this->isMaxContacts = _ge.isMaxContacts;
Expand Down
1 change: 1 addition & 0 deletions src/SDFExtension.hh
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ namespace sdf

// body, default off
public: bool setStaticFlag;
public: bool isGravity;
public: bool gravity;
public: bool isDampingFactor;
public: double dampingFactor;
Expand Down
13 changes: 5 additions & 8 deletions src/parser_urdf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,7 @@ void URDF2SDF::ParseSDFExtension(TiXmlDocument &_urdfXml)
else if (childElem->ValueStr() == "turnGravityOff")
{
std::string valueStr = GetKeyValueAsString(childElem);
sdf->isGravity = true;

// default of gravity is true
if (lowerStr(valueStr) == "false" || lowerStr(valueStr) == "no" ||
Expand Down Expand Up @@ -2069,26 +2070,22 @@ void InsertSDFExtensionLink(TiXmlElement *_elem, const std::string &_linkName)
sdfIt->second.begin(); ge != sdfIt->second.end(); ++ge)
{
// insert gravity
if ((*ge)->gravity)
if ((*ge)->isGravity)
{
AddKeyValue(_elem, "gravity", "true");
}
else
{
AddKeyValue(_elem, "gravity", "false");
AddKeyValue(_elem, "gravity", (*ge)->gravity ? "true" : "false");
}

// damping factor
TiXmlElement *velocityDecay = new TiXmlElement("velocity_decay");
if ((*ge)->isDampingFactor)
{
TiXmlElement *velocityDecay = new TiXmlElement("velocity_decay");
/// @todo separate linear and angular velocity decay
AddKeyValue(velocityDecay, "linear",
Values2str(1, &(*ge)->dampingFactor));
AddKeyValue(velocityDecay, "angular",
Values2str(1, &(*ge)->dampingFactor));
_elem->LinkEndChild(velocityDecay);
}
_elem->LinkEndChild(velocityDecay);
// selfCollide tag
if ((*ge)->isSelfCollide)
{
Expand Down
4 changes: 4 additions & 0 deletions test/integration/fixed_joint_reduction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ void FixedJointReductionCollisionVisualExtension(const std::string &_urdfFile,
for (sdf::ElementPtr link = urdfModel->GetElement("link"); link;
link = link->GetNextElement("link"))
{
EXPECT_FALSE(link->HasElement("gravity"));
EXPECT_FALSE(link->HasElement("self_collide"));
EXPECT_FALSE(link->HasElement("velocity_decay"));
for (sdf::ElementPtr col = link->GetElement("collision"); col;
col = col->GetNextElement("collision"))
{
Expand Down Expand Up @@ -184,7 +186,9 @@ void FixedJointReductionCollisionVisualExtension(const std::string &_urdfFile,
for (sdf::ElementPtr link = sdfModel->GetElement("link"); link;
link = link->GetNextElement("link"))
{
EXPECT_FALSE(link->HasElement("gravity"));
EXPECT_FALSE(link->HasElement("self_collide"));
EXPECT_FALSE(link->HasElement("velocity_decay"));
for (sdf::ElementPtr col = link->GetElement("collision"); col;
col = col->GetNextElement("collision"))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
</script>
</material>
</visual>
<gravity>1</gravity>
<velocity_decay/>
<self_collide>0</self_collide>
</link>
</model>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@
</script>
</material>
</visual>
<velocity_decay/>
<velocity_decay/>
<gravity>1</gravity>
<velocity_decay/>
</link>
</model>
</sdf>
Loading

0 comments on commit 808253c

Please sign in to comment.