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

Added render_order to material #446

Merged
merged 5 commits into from
Dec 28, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions include/sdf/Material.hh
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ namespace sdf
/// \param[in] _color Emissive color.
public: void SetEmissive(const ignition::math::Color &_color) const;

/// \brief Get render order
/// \return Render order
public: float RenderOrder() const;

/// \brief Set render order
/// \param[in] _renderOrder render order
public: void SetRenderOrder(const float _renderOrder);

/// \brief Get whether dynamic lighting is enabled. The default
/// value is true.
/// \return False if dynamic lighting should be disabled.
Expand Down
4 changes: 4 additions & 0 deletions sdf/1.7/material.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
</element>
</element>

<element name="render_order" type="double" default="0.0" required="0">
chapulina marked this conversation as resolved.
Show resolved Hide resolved
<description>Set render order for coplanar polygons. The higher value will be rendered on top of the other coplanar polygons</description>
</element>

<element name="lighting" type="bool" default="true" required="0">
<description>If false, dynamic lighting will be disabled</description>
</element>
Expand Down
19 changes: 19 additions & 0 deletions src/Material.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class sdf::MaterialPrivate
/// \brief Emissive color
public: ignition::math::Color emissive {0, 0, 0, 1};

/// \brief Render order
public: float renderOrder = 0;

/// \brief Physically Based Rendering (PBR) properties
public: std::unique_ptr<Pbr> pbr;

Expand Down Expand Up @@ -89,6 +92,7 @@ Material::Material(const Material &_material)
this->dataPtr->shader = _material.dataPtr->shader;
this->dataPtr->normalMap = _material.dataPtr->normalMap;
this->dataPtr->lighting = _material.dataPtr->lighting;
this->dataPtr->renderOrder = _material.dataPtr->renderOrder;
this->dataPtr->doubleSided = _material.dataPtr->doubleSided;
this->dataPtr->ambient = _material.dataPtr->ambient;
this->dataPtr->diffuse = _material.dataPtr->diffuse;
Expand Down Expand Up @@ -207,6 +211,9 @@ Errors Material::Load(sdf::ElementPtr _sdf)
}
}

this->dataPtr->renderOrder = _sdf->Get<float>("render_order",
this->dataPtr->renderOrder).first;

this->dataPtr->ambient = _sdf->Get<ignition::math::Color>("ambient",
this->dataPtr->ambient).first;

Expand Down Expand Up @@ -284,6 +291,18 @@ void Material::SetEmissive(const ignition::math::Color &_color) const
this->dataPtr->emissive = _color;
}

//////////////////////////////////////////////////
float Material::RenderOrder() const
{
return this->dataPtr->renderOrder;
}

//////////////////////////////////////////////////
void Material::SetRenderOrder(const float _renderOrder)
{
this->dataPtr->renderOrder = _renderOrder;
}

//////////////////////////////////////////////////
bool Material::Lighting() const
{
Expand Down
14 changes: 14 additions & 0 deletions src/Material_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ TEST(DOMMaterial, Construction)
EXPECT_EQ(ignition::math::Color(0, 0, 0, 1), material.Specular());
EXPECT_EQ(ignition::math::Color(0, 0, 0, 1), material.Emissive());
EXPECT_TRUE(material.Lighting());
EXPECT_EQ(0, material.RenderOrder());
chapulina marked this conversation as resolved.
Show resolved Hide resolved
EXPECT_FALSE(material.DoubleSided());
EXPECT_EQ(nullptr, material.Element());
EXPECT_EQ("", material.ScriptUri());
Expand All @@ -49,6 +50,7 @@ TEST(DOMMaterial, MoveConstructor)
material.SetSpecular(ignition::math::Color(0.3f, 0.4f, 0.5f, 0.7f));
material.SetEmissive(ignition::math::Color(0.4f, 0.5f, 0.6f, 0.8f));
material.SetLighting(false);
material.SetRenderOrder(2);
material.SetDoubleSided(true);
material.SetScriptUri("banana");
material.SetScriptName("orange");
Expand All @@ -65,6 +67,7 @@ TEST(DOMMaterial, MoveConstructor)
material2.Emissive());
EXPECT_FALSE(material2.Lighting());
EXPECT_TRUE(material2.DoubleSided());
EXPECT_EQ(2, material2.RenderOrder());
EXPECT_EQ("banana", material2.ScriptUri());
EXPECT_EQ("orange", material2.ScriptName());
EXPECT_EQ(sdf::ShaderType::VERTEX, material2.Shader());
Expand All @@ -82,6 +85,7 @@ TEST(DOMMaterial, CopyConstructor)
material.SetSpecular(ignition::math::Color(0.3f, 0.4f, 0.5f, 0.7f));
material.SetEmissive(ignition::math::Color(0.4f, 0.5f, 0.6f, 0.8f));
material.SetLighting(false);
material.SetRenderOrder(4);
material.SetDoubleSided(true);
material.SetScriptUri("banana");
material.SetScriptName("orange");
Expand All @@ -98,6 +102,7 @@ TEST(DOMMaterial, CopyConstructor)
material2.Emissive());
EXPECT_FALSE(material2.Lighting());
EXPECT_TRUE(material2.DoubleSided());
EXPECT_EQ(4, material2.RenderOrder());
EXPECT_EQ("banana", material2.ScriptUri());
EXPECT_EQ("orange", material2.ScriptName());
EXPECT_EQ(sdf::ShaderType::VERTEX, material2.Shader());
Expand All @@ -115,6 +120,7 @@ TEST(DOMMaterial, AssignmentOperator)
material.SetSpecular(ignition::math::Color(0.3f, 0.4f, 0.5f, 0.7f));
material.SetEmissive(ignition::math::Color(0.4f, 0.5f, 0.6f, 0.8f));
material.SetLighting(false);
material.SetRenderOrder(4);
material.SetDoubleSided(true);
material.SetScriptUri("banana");
material.SetScriptName("orange");
Expand All @@ -132,6 +138,7 @@ TEST(DOMMaterial, AssignmentOperator)
material2.Emissive());
EXPECT_FALSE(material2.Lighting());
EXPECT_TRUE(material2.DoubleSided());
EXPECT_EQ(4, material2.RenderOrder());
EXPECT_EQ("banana", material2.ScriptUri());
EXPECT_EQ("orange", material2.ScriptName());
EXPECT_EQ(sdf::ShaderType::VERTEX, material2.Shader());
Expand All @@ -149,6 +156,7 @@ TEST(DOMMaterial, MoveAssignmentOperator)
material.SetSpecular(ignition::math::Color(0.3f, 0.4f, 0.5f, 0.7f));
material.SetEmissive(ignition::math::Color(0.4f, 0.5f, 0.6f, 0.8f));
material.SetLighting(false);
material.SetRenderOrder(4);
material.SetDoubleSided(true);
material.SetScriptUri("banana");
material.SetScriptName("orange");
Expand All @@ -165,6 +173,7 @@ TEST(DOMMaterial, MoveAssignmentOperator)
material2.Emissive());
EXPECT_FALSE(material2.Lighting());
EXPECT_TRUE(material2.DoubleSided());
EXPECT_EQ(4, material2.RenderOrder());
EXPECT_EQ("banana", material2.ScriptUri());
EXPECT_EQ("orange", material2.ScriptName());
EXPECT_EQ(sdf::ShaderType::VERTEX, material2.Shader());
Expand Down Expand Up @@ -215,6 +224,10 @@ TEST(DOMMaterial, Set)
material.SetLighting(false);
EXPECT_FALSE(material.Lighting());

EXPECT_EQ(0, material.RenderOrder());
material.SetRenderOrder(5);
EXPECT_EQ(5, material.RenderOrder());

EXPECT_FALSE(material.DoubleSided());
material.SetDoubleSided(true);
EXPECT_TRUE(material.DoubleSided());
Expand Down Expand Up @@ -256,6 +269,7 @@ TEST(DOMMaterial, Set)
EXPECT_EQ(ignition::math::Color(0.3f, 0.4f, 0.5f, 0.7f), moved.Specular());
EXPECT_EQ(ignition::math::Color(0.4f, 0.5f, 0.6f, 0.8f), moved.Emissive());
EXPECT_FALSE(moved.Lighting());
EXPECT_EQ(5, moved.RenderOrder());
EXPECT_TRUE(moved.DoubleSided());
EXPECT_EQ("uri", moved.ScriptUri());
EXPECT_EQ("name", moved.ScriptName());
Expand Down
1 change: 1 addition & 0 deletions test/integration/visual_dom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ TEST(DOMVisual, Material)
EXPECT_EQ(ignition::math::Color(1.0f, 0.0f, 0.2f, 1.0f), mat->Emissive());
EXPECT_FALSE(mat->Lighting());
EXPECT_TRUE(mat->DoubleSided());
EXPECT_FLOAT_EQ(5.1, mat->RenderOrder());
EXPECT_EQ(sdf::ShaderType::VERTEX, mat->Shader());
EXPECT_EQ("myuri", mat->ScriptUri());
EXPECT_EQ("myname", mat->ScriptName());
Expand Down
3 changes: 2 additions & 1 deletion test/sdf/material.sdf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" ?>
<sdf version="1.6">
<sdf version="1.7">
<model name="model">
<link name="link">
<visual name="visual1">
Expand All @@ -9,6 +9,7 @@
<specular>0.7 0.3 0.5 0.9</specular>
<emissive>1.0 0.0 0.2 1.0</emissive>
<lighting>false</lighting>
<render_order>5.1</render_order>
<double_sided>true</double_sided>
<shader type="vertex">
</shader>
Expand Down