Skip to content

Commit

Permalink
Add directional light to scene_system (#762)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
scpeters authored Mar 12, 2021
1 parent f7762b9 commit 0187e3a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/backend/scene_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ namespace delphyne {
template <class T>
using ProtobufIterator = google::protobuf::internal::RepeatedPtrIterator<T>;

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<ignition::msgs::Model_V>()).get_index();
Expand Down Expand Up @@ -83,8 +87,18 @@ void SceneSystem::CalcSceneMessage(const drake::systems::Context<double>& 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
11 changes: 11 additions & 0 deletions src/backend/scene_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include <drake/systems/framework/leaf_system.h>

#include <ignition/math/Color.hh>
#include <ignition/math/Vector3.hh>
#include <ignition/msgs.hh>

namespace delphyne {
Expand Down Expand Up @@ -44,6 +46,15 @@ class SceneSystem : public drake::systems::LeafSystem<double> {
// updated poses of mobile elements.
void CalcSceneMessage(const drake::systems::Context<double>& 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_{};
};
Expand Down

0 comments on commit 0187e3a

Please sign in to comment.