diff --git a/include/sdf/Light.hh b/include/sdf/Light.hh
index 11e5dceb8..210026aca 100644
--- a/include/sdf/Light.hh
+++ b/include/sdf/Light.hh
@@ -126,6 +126,14 @@ namespace sdf
/// \param[in] _cast True to indicate that the light casts shadows.
public: void SetCastShadows(const bool _cast);
+ /// \brief Get if the light is on
+ /// \return True if the light is on.
+ public: bool LightOn() const;
+
+ /// \brief Set if the light is ON/OFF
+ /// \param[in] _cast True to indicate that the light is on, False otherwise.
+ public: void SetLightOn(const bool _isLightOn);
+
/// \brief Get the light intensity
/// \return The light intensity
public: double Intensity() const;
diff --git a/sdf/1.8/light.sdf b/sdf/1.8/light.sdf
index c9e1f237b..a6939ac48 100644
--- a/sdf/1.8/light.sdf
+++ b/sdf/1.8/light.sdf
@@ -14,6 +14,10 @@
When true, the light will cast shadows.
+
+ When true, the light is on.
+
+
Scale factor to set the relative power of a light.
diff --git a/src/Light.cc b/src/Light.cc
index 692a925b9..c35850e78 100644
--- a/src/Light.cc
+++ b/src/Light.cc
@@ -83,6 +83,9 @@ class sdf::Light::Implementation
/// \brief Spot light falloff.
public: double spotFalloff = 0.0;
+
+ /// \brief Is light on ?
+ public: bool isLightOn = true;
};
/////////////////////////////////////////////////
@@ -141,6 +144,9 @@ Errors Light::Load(ElementPtr _sdf)
// Load the pose. Ignore the return value since the light pose is optional.
loadPose(_sdf, this->dataPtr->pose, this->dataPtr->poseRelativeTo);
+ this->dataPtr->isLightOn = _sdf->Get("light_on",
+ this->dataPtr->isLightOn).first;
+
this->dataPtr->castShadows = _sdf->Get("cast_shadows",
this->dataPtr->castShadows).first;
@@ -316,6 +322,18 @@ void Light::SetCastShadows(const bool _cast)
this->dataPtr->castShadows = _cast;
}
+/////////////////////////////////////////////////
+bool Light::LightOn() const
+{
+ return this->dataPtr->isLightOn;
+}
+
+/////////////////////////////////////////////////
+void Light::SetLightOn(const bool _isLightOn)
+{
+ this->dataPtr->isLightOn = _isLightOn;
+}
+
/////////////////////////////////////////////////
ignition::math::Color Light::Diffuse() const
{
diff --git a/src/Light_TEST.cc b/src/Light_TEST.cc
index 758cf7955..5ac8ed77a 100644
--- a/src/Light_TEST.cc
+++ b/src/Light_TEST.cc
@@ -55,6 +55,10 @@ TEST(DOMLight, DefaultConstruction)
EXPECT_FALSE(semanticPose.Resolve(pose).empty());
}
+ EXPECT_TRUE(light.LightOn());
+ light.SetLightOn(false);
+ EXPECT_FALSE(light.LightOn());
+
EXPECT_FALSE(light.CastShadows());
light.SetCastShadows(true);
EXPECT_TRUE(light.CastShadows());
@@ -113,6 +117,7 @@ TEST(DOMLight, CopyConstructor)
light.SetRawPose({3, 2, 1, 0, IGN_PI, 0});
light.SetPoseRelativeTo("ground_plane");
light.SetCastShadows(true);
+ light.SetLightOn(false);
light.SetDiffuse(ignition::math::Color(0.4f, 0.5f, 0.6f, 1.0));
light.SetSpecular(ignition::math::Color(0.8f, 0.9f, 0.1f, 1.0));
light.SetAttenuationRange(3.2);
@@ -131,6 +136,7 @@ TEST(DOMLight, CopyConstructor)
EXPECT_EQ(ignition::math::Pose3d(3, 2, 1, 0, IGN_PI, 0), light2.RawPose());
EXPECT_EQ("ground_plane", light2.PoseRelativeTo());
EXPECT_TRUE(light2.CastShadows());
+ EXPECT_FALSE(light2.LightOn());
EXPECT_EQ(ignition::math::Color(0.4f, 0.5f, 0.6f, 1), light2.Diffuse());
EXPECT_EQ(ignition::math::Color(0.8f, 0.9f, 0.1f, 1), light2.Specular());
EXPECT_DOUBLE_EQ(3.2, light2.AttenuationRange());
@@ -153,6 +159,7 @@ TEST(DOMLight, CopyAssignmentOperator)
light.SetRawPose({3, 2, 1, 0, IGN_PI, 0});
light.SetPoseRelativeTo("ground_plane");
light.SetCastShadows(true);
+ light.SetLightOn(false);
light.SetDiffuse(ignition::math::Color(0.4f, 0.5f, 0.6f, 1.0));
light.SetSpecular(ignition::math::Color(0.8f, 0.9f, 0.1f, 1.0));
light.SetAttenuationRange(3.2);
@@ -172,6 +179,7 @@ TEST(DOMLight, CopyAssignmentOperator)
EXPECT_EQ(ignition::math::Pose3d(3, 2, 1, 0, IGN_PI, 0), light2.RawPose());
EXPECT_EQ("ground_plane", light2.PoseRelativeTo());
EXPECT_TRUE(light2.CastShadows());
+ EXPECT_FALSE(light2.LightOn());
EXPECT_EQ(ignition::math::Color(0.4f, 0.5f, 0.6f, 1), light2.Diffuse());
EXPECT_EQ(ignition::math::Color(0.8f, 0.9f, 0.1f, 1), light2.Specular());
EXPECT_DOUBLE_EQ(3.2, light2.AttenuationRange());
@@ -194,6 +202,7 @@ TEST(DOMLight, MoveConstructor)
light.SetRawPose({3, 2, 1, 0, IGN_PI, 0});
light.SetPoseRelativeTo("ground_plane");
light.SetCastShadows(true);
+ light.SetLightOn(false);
light.SetDiffuse(ignition::math::Color(0.4f, 0.5f, 0.6f, 1.0));
light.SetSpecular(ignition::math::Color(0.8f, 0.9f, 0.1f, 1.0));
light.SetAttenuationRange(3.2);
@@ -212,6 +221,7 @@ TEST(DOMLight, MoveConstructor)
EXPECT_EQ(ignition::math::Pose3d(3, 2, 1, 0, IGN_PI, 0), light2.RawPose());
EXPECT_EQ("ground_plane", light2.PoseRelativeTo());
EXPECT_TRUE(light2.CastShadows());
+ EXPECT_FALSE(light2.LightOn());
EXPECT_EQ(ignition::math::Color(0.4f, 0.5f, 0.6f, 1), light2.Diffuse());
EXPECT_EQ(ignition::math::Color(0.8f, 0.9f, 0.1f, 1), light2.Specular());
EXPECT_DOUBLE_EQ(3.2, light2.AttenuationRange());
@@ -234,6 +244,7 @@ TEST(DOMLight, MoveAssignment)
light.SetRawPose({3, 2, 1, 0, IGN_PI, 0});
light.SetPoseRelativeTo("ground_plane");
light.SetCastShadows(true);
+ light.SetLightOn(false);
light.SetDiffuse(ignition::math::Color(0.4f, 0.5f, 0.6f, 1.0));
light.SetSpecular(ignition::math::Color(0.8f, 0.9f, 0.1f, 1.0));
light.SetAttenuationRange(3.2);
@@ -253,6 +264,7 @@ TEST(DOMLight, MoveAssignment)
EXPECT_EQ(ignition::math::Pose3d(3, 2, 1, 0, IGN_PI, 0), light2.RawPose());
EXPECT_EQ("ground_plane", light2.PoseRelativeTo());
EXPECT_TRUE(light2.CastShadows());
+ EXPECT_FALSE(light2.LightOn());
EXPECT_EQ(ignition::math::Color(0.4f, 0.5f, 0.6f, 1), light2.Diffuse());
EXPECT_EQ(ignition::math::Color(0.8f, 0.9f, 0.1f, 1), light2.Specular());
EXPECT_DOUBLE_EQ(3.2, light2.AttenuationRange());