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

Toggle Light visuals #1387

Merged
merged 10 commits into from
Mar 18, 2022
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
1 change: 1 addition & 0 deletions examples/worlds/lights.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<quadratic>0.01</quadratic>
</attenuation>
<cast_shadows>false</cast_shadows>
<visualize>false</visualize>
</light>

<light type="spot" name="spot">
Expand Down
41 changes: 35 additions & 6 deletions src/Conversions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -569,12 +569,23 @@ msgs::Light ignition::gazebo::convert(const sdf::Light &_in)
out.set_spot_outer_angle(_in.SpotOuterAngle().Radian());
out.set_spot_falloff(_in.SpotFalloff());

// todo(ahcorde) Use the field is_light_off in light.proto from
// Garden on.
auto header = out.mutable_header()->add_data();
header->set_key("isLightOn");
std::string *value = header->add_value();
*value = std::to_string(_in.LightOn());
{
// todo(ahcorde) Use the field is_light_off in light.proto from
// Garden on.
auto header = out.mutable_header()->add_data();
header->set_key("isLightOn");
std::string *value = header->add_value();
*value = std::to_string(_in.LightOn());
}

{
// todo(ahcorde) Use the field visualize_visual in light.proto from
// Garden on.
auto header = out.mutable_header()->add_data();
header->set_key("visualizeVisual");
std::string *value = header->add_value();
*value = std::to_string(_in.Visualize());
}

if (_in.Type() == sdf::LightType::POINT)
out.set_type(msgs::Light_LightType_POINT);
Expand Down Expand Up @@ -606,6 +617,24 @@ sdf::Light ignition::gazebo::convert(const msgs::Light &_in)
out.SetSpotOuterAngle(math::Angle(_in.spot_outer_angle()));
out.SetSpotFalloff(_in.spot_falloff());

// todo(ahcorde) Use the field is_light_off in light.proto from
// Garden on.
bool visualizeVisual = true;
for (int i = 0; i < _in.header().data_size(); ++i)
{
for (int j = 0;
j < _in.header().data(i).value_size(); ++j)
{
if (_in.header().data(i).key() ==
"visualizeVisual")
{
visualizeVisual = ignition::math::parseInt(
_in.header().data(i).value(0));
}
}
}
out.SetVisualize(visualizeVisual);

// todo(ahcorde) Use the field is_light_off in light.proto from
// Garden on.
bool isLightOn = true;
Expand Down
43 changes: 34 additions & 9 deletions src/gui/plugins/component_inspector/ComponentInspector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,21 @@ void ignition::gazebo::setData(QStandardItem *_item, const msgs::Light &_data)
lightType = 2;
}

bool visualizeVisual = true;
for (int i = 0; i < _data.header().data_size(); ++i)
{
for (int j = 0;
j < _data.header().data(i).value_size(); ++j)
{
if (_data.header().data(i).key() ==
"visualizeVisual")
{
visualizeVisual = ignition::math::parseInt(
_data.header().data(i).value(0));
}
}
}

bool isLightOn = true;
for (int i = 0; i < _data.header().data_size(); ++i)
{
Expand Down Expand Up @@ -192,7 +207,8 @@ void ignition::gazebo::setData(QStandardItem *_item, const msgs::Light &_data)
QVariant(_data.spot_falloff()),
QVariant(_data.intensity()),
QVariant(lightType),
QVariant(isLightOn)
QVariant(isLightOn),
QVariant(visualizeVisual)
}), ComponentsModel::RoleNames().key("data"));
}

Expand Down Expand Up @@ -1006,7 +1022,7 @@ void ComponentInspector::OnLight(
double _attQuadratic, bool _castShadows, double _directionX,
double _directionY, double _directionZ, double _innerAngle,
double _outerAngle, double _falloff, double _intensity, int _type,
bool _isLightOn)
bool _isLightOn, bool _visualizeVisual)
{
std::function<void(const ignition::msgs::Boolean &, const bool)> cb =
[](const ignition::msgs::Boolean &/*_rep*/, const bool _result)
Expand All @@ -1016,13 +1032,22 @@ void ComponentInspector::OnLight(
};

ignition::msgs::Light req;

// todo(ahcorde) Use the field is_light_off in light.proto from
// Garden on.
auto header = req.mutable_header()->add_data();
header->set_key("isLightOn");
std::string *value = header->add_value();
*value = std::to_string(_isLightOn);
{
// todo(ahcorde) Use the field is_light_off in light.proto from
// Garden on.
auto header = req.mutable_header()->add_data();
header->set_key("isLightOn");
std::string *value = header->add_value();
*value = std::to_string(_isLightOn);
}
{
// todo(ahcorde) Use the field visualize_visual in light.proto from
// Garden on.
auto header = req.mutable_header()->add_data();
header->set_key("visualizeVisual");
std::string *value = header->add_value();
*value = std::to_string(_visualizeVisual);
}

req.set_name(this->dataPtr->entityName);
req.set_id(this->dataPtr->entity);
Expand Down
4 changes: 3 additions & 1 deletion src/gui/plugins/component_inspector/ComponentInspector.hh
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,16 @@ namespace gazebo
/// \param[in] _intensity Intensity of the light
/// \param[in] _type light type
/// \param[in] _isLightOn is light on
/// \param[in] _visualizeVisual is visual enabled
public: Q_INVOKABLE void OnLight(
double _rSpecular, double _gSpecular, double _bSpecular,
double _aSpecular, double _rDiffuse, double _gDiffuse,
double _bDiffuse, double _aDiffuse, double _attRange,
double _attLinear, double _attConstant, double _attQuadratic,
bool _castShadows, double _directionX, double _directionY,
double _directionZ, double _innerAngle, double _outerAngle,
double _falloff, double _intensity, int _type, bool _isLightOn);
double _falloff, double _intensity, int _type, bool _isLightOn,
bool _visualizeVisual);

/// \brief Callback in Qt thread when physics' properties change.
/// \param[in] _stepSize step size
Expand Down
4 changes: 2 additions & 2 deletions src/gui/plugins/component_inspector/ComponentInspector.qml
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ Rectangle {
_attRange, _attLinear, _attConstant, _attQuadratic,
_castShadows, _directionX, _directionY, _directionZ,
_innerAngle, _outerAngle, _falloff, _intensity, _type,
_isLightOn) {
_isLightOn, _visualizeVisual) {
ComponentInspector.OnLight(_rSpecular, _gSpecular, _bSpecular, _aSpecular,
_rDiffuse, _gDiffuse, _bDiffuse, _aDiffuse,
_attRange, _attLinear, _attConstant, _attQuadratic,
_castShadows, _directionX, _directionY, _directionZ,
_innerAngle, _outerAngle, _falloff, _intensity, _type,
_isLightOn)
_isLightOn, _visualizeVisual)
}

/*
Expand Down
37 changes: 36 additions & 1 deletion src/gui/plugins/component_inspector/Light.qml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ Rectangle {
// Loaded item for isLightOn
property var isLightOnItem: {}

// Loaded item for visualizeVisuals
property var visualizeVisualItem: {}

// Send new light data to C++
function sendLight() {
// TODO(anyone) There's a loss of precision when these values get to C++
Expand All @@ -127,7 +130,8 @@ Rectangle {
falloffItem.value,
intensityItem.value,
model.data[20],
isLightOnItem.checked
isLightOnItem.checked,
visualizeVisualItem.checked
);
}

Expand Down Expand Up @@ -289,6 +293,37 @@ Rectangle {
id: grid
width: parent.width

RowLayout {
Rectangle {
color: "transparent"
height: 40
Layout.preferredWidth: visualizeVisualText.width + indentation*3

Text {
id : visualizeVisualText
text: ' View gizmo'
leftPadding: 5
color: Material.theme == Material.Light ? "#444444" : "#bbbbbb"
font.pointSize: 12
anchors.centerIn: parent
}
}
Item {
Layout.fillWidth: true
height: 40

Loader {
chapulina marked this conversation as resolved.
Show resolved Hide resolved
id: visualizeVisualLoader
anchors.fill: parent
property double numberValue: model.data[22]
sourceComponent: ignSwitch
onLoaded: {
visualizeVisualItem = visualizeVisualLoader.item
}
}
}
}

RowLayout {
Rectangle {
color: "transparent"
Expand Down
24 changes: 24 additions & 0 deletions src/rendering/RenderUtil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ class ignition::gazebo::RenderUtilPrivate
lightEql { [](const sdf::Light &_a, const sdf::Light &_b)
{
return
_a.Visualize() == _b.Visualize() &&
_a.Type() == _b.Type() &&
_a.Name() == _b.Name() &&
_a.Diffuse() == _b.Diffuse() &&
Expand Down Expand Up @@ -2131,6 +2132,29 @@ void RenderUtilPrivate::UpdateLights(
auto l = std::dynamic_pointer_cast<rendering::Light>(node);
if (l)
{
// todo(ahcorde) Use the field visualize_visual in light.proto from
// Garden on.
bool visualizeVisual = true;
for (int i = 0; i < light.second.header().data_size(); ++i)
{
for (int j = 0;
j < light.second.header().data(i).value_size(); ++j)
{
if (light.second.header().data(i).key() ==
"visualizeVisual")
{
visualizeVisual = ignition::math::parseInt(
light.second.header().data(i).value(0));
}
}
}

rendering::VisualPtr lightVisual =
this->sceneManager.VisualById(
this->matchLightWithVisuals[light.first]);
if (lightVisual)
lightVisual->SetVisible(visualizeVisual);

// todo(ahcorde) Use the field is_light_off in light.proto from
// Garden on.
bool isLightOn = true;
Expand Down
3 changes: 3 additions & 0 deletions src/rendering/SceneManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,9 @@ rendering::VisualPtr SceneManager::CreateLightVisual(Entity _id,
lightVisual->SetInnerAngle(_light.SpotInnerAngle().Radian());
lightVisual->SetOuterAngle(_light.SpotOuterAngle().Radian());
}

lightVisual->SetVisible(_light.Visualize());

rendering::VisualPtr lightVis = std::dynamic_pointer_cast<rendering::Visual>(
lightVisual);
lightVis->SetUserData("gazebo-entity", static_cast<int>(_id));
Expand Down
22 changes: 22 additions & 0 deletions src/systems/user_commands/UserCommands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,27 @@ class LightCommand : public UserCommandBase
public: std::function<bool(const msgs::Light &, const msgs::Light &)>
lightEql { [](const msgs::Light &_a, const msgs::Light &_b)
{
// todo(ahcorde) Use the field is_light_off in light.proto from
// Garden on.
auto getVisualizeVisual = [](const msgs::Light &_light) -> bool
{
bool visualizeVisual = true;
for (int i = 0; i < _light.header().data_size(); ++i)
{
for (int j = 0;
j < _light.header().data(i).value_size(); ++j)
{
if (_light.header().data(i).key() ==
"visualizeVisual")
{
visualizeVisual = ignition::math::parseInt(
_light.header().data(i).value(0));
}
}
}
return visualizeVisual;
};

// todo(ahcorde) Use the field is_light_off in light.proto from
// Garden on.
auto getIsLightOn = [](const msgs::Light &_light) -> bool
Expand All @@ -180,6 +201,7 @@ class LightCommand : public UserCommandBase
return isLightOn;
};
return
getVisualizeVisual(_a) == getVisualizeVisual(_b) &&
getIsLightOn(_a) == getIsLightOn(_b) &&
_a.type() == _b.type() &&
_a.name() == _b.name() &&
Expand Down