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

Add directional light to scene_system #762

Merged
merged 2 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 12 additions & 2 deletions src/backend/scene_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,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 @@ -39,6 +41,15 @@ class SceneSystem : public drake::systems::LeafSystem<double> {

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you make these three variables static?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 247ad17

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.
Expand Down