From ce96f51e8a0dd0fb6d65e3645a8d3d63b71e2154 Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Tue, 9 Mar 2021 12:08:22 -0800 Subject: [PATCH 1/2] Add directional light to scene_system Use hard-coded light parameters copied from visualizer0. The visualizer0 render_widget will need to be updated in order to parse this portion of the scene message. --- src/backend/scene_system.cc | 14 ++++++++++++-- src/backend/scene_system.h | 11 +++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/backend/scene_system.cc b/src/backend/scene_system.cc index 36b19104d..e7e3c74b0 100644 --- a/src/backend/scene_system.cc +++ b/src/backend/scene_system.cc @@ -83,8 +83,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..e71bce3b0 100644 --- a/src/backend/scene_system.h +++ b/src/backend/scene_system.h @@ -8,6 +8,8 @@ #include +#include +#include #include namespace delphyne { @@ -39,6 +41,15 @@ class SceneSystem : public drake::systems::LeafSystem { int get_updated_pose_models_input_port_index() const { return updated_pose_models_input_port_index_; } + // This is the color used by the directional light added to each scene. + const ignition::math::Color kLightColor{0.9, 0.9, 0.9}; + + // This is the direction of the directional light added to each scene. + const ignition::math::Vector3d kLightDirection{-0.5, -0.5, -1}; + + // Cast shadows by default. + bool kCastShadowsByDefault{true}; + private: // Calculates a new scene message from the geometry description and the // updated poses of mobile elements. From 247ad1791059a07eddd7e7747409e76703a6699c Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Thu, 11 Mar 2021 10:32:24 -0800 Subject: [PATCH 2/2] Use static private variables --- src/backend/scene_system.cc | 4 ++++ src/backend/scene_system.h | 16 ++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/backend/scene_system.cc b/src/backend/scene_system.cc index e7e3c74b0..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(); diff --git a/src/backend/scene_system.h b/src/backend/scene_system.h index e71bce3b0..f83ed9462 100644 --- a/src/backend/scene_system.h +++ b/src/backend/scene_system.h @@ -41,19 +41,19 @@ class SceneSystem : public drake::systems::LeafSystem { int get_updated_pose_models_input_port_index() const { return updated_pose_models_input_port_index_; } + private: + // Calculates a new scene message from the geometry description and the + // 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. - const ignition::math::Color kLightColor{0.9, 0.9, 0.9}; + static const ignition::math::Color kLightColor; // This is the direction of the directional light added to each scene. - const ignition::math::Vector3d kLightDirection{-0.5, -0.5, -1}; + static const ignition::math::Vector3d kLightDirection; // Cast shadows by default. - bool kCastShadowsByDefault{true}; - - private: - // Calculates a new scene message from the geometry description and the - // updated poses of mobile elements. - void CalcSceneMessage(const drake::systems::Context& context, ignition::msgs::Scene* scene_message) const; + static const bool kCastShadowsByDefault{true}; int geometry_models_input_port_index_{}; int updated_pose_models_input_port_index_{};