diff --git a/src/backend/scene_system.cc b/src/backend/scene_system.cc index 36b19104d..26a4f1cb6 100644 --- a/src/backend/scene_system.cc +++ b/src/backend/scene_system.cc @@ -13,6 +13,10 @@ namespace delphyne { template using ProtobufIterator = google::protobuf::internal::RepeatedPtrIterator; +const ignition::math::Color SceneSystem::kLightColor{0.9, 0.9, 0.9}; + +const ignition::math::Vector3d SceneSystem::kLightDirection{-0.5, -0.5, -1}; + SceneSystem::SceneSystem() { geometry_models_input_port_index_ = DeclareAbstractInputPort(drake::systems::kUseDefaultName, drake::Value()).get_index(); @@ -83,8 +87,18 @@ void SceneSystem::CalcSceneMessage(const drake::systems::Context& contex } } - // TODO(caguero): Populate the rest of the scene fields, such as lights. - // See https://github.com/ToyotaResearchInstitute/delphyne/issues/204 + // Add a directional light to the scene + { + const ignition::msgs::Color kLightColorMsg = ignition::msgs::Convert(kLightColor); + ignition::msgs::Light directionalLight; + directionalLight.set_name("directional_light"); + directionalLight.set_type(ignition::msgs::Light_LightType_DIRECTIONAL); + directionalLight.mutable_diffuse()->CopyFrom(kLightColorMsg); + directionalLight.mutable_specular()->CopyFrom(kLightColorMsg); + directionalLight.mutable_direction()->CopyFrom(ignition::msgs::Convert(kLightDirection)); + directionalLight.set_cast_shadows(kCastShadowsByDefault); + scene_message->add_light()->CopyFrom(directionalLight); + } } } // namespace delphyne diff --git a/src/backend/scene_system.h b/src/backend/scene_system.h index 1f63627cd..f83ed9462 100644 --- a/src/backend/scene_system.h +++ b/src/backend/scene_system.h @@ -8,6 +8,8 @@ #include +#include +#include #include namespace delphyne { @@ -44,6 +46,15 @@ class SceneSystem : public drake::systems::LeafSystem { // updated poses of mobile elements. void CalcSceneMessage(const drake::systems::Context& context, ignition::msgs::Scene* scene_message) const; + // This is the color used by the directional light added to each scene. + static const ignition::math::Color kLightColor; + + // This is the direction of the directional light added to each scene. + static const ignition::math::Vector3d kLightDirection; + + // Cast shadows by default. + static const bool kCastShadowsByDefault{true}; + int geometry_models_input_port_index_{}; int updated_pose_models_input_port_index_{}; };