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 all commits
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
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.
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

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