diff --git a/examples/worlds/lights.sdf b/examples/worlds/lights.sdf index f1910f0ac7..61d2d92fd1 100644 --- a/examples/worlds/lights.sdf +++ b/examples/worlds/lights.sdf @@ -52,6 +52,7 @@ 0.01 false + false diff --git a/src/Conversions.cc b/src/Conversions.cc index aafd9213f7..fa72327900 100644 --- a/src/Conversions.cc +++ b/src/Conversions.cc @@ -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); @@ -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; diff --git a/src/gui/plugins/component_inspector/ComponentInspector.cc b/src/gui/plugins/component_inspector/ComponentInspector.cc index f16712ce73..4deed41829 100644 --- a/src/gui/plugins/component_inspector/ComponentInspector.cc +++ b/src/gui/plugins/component_inspector/ComponentInspector.cc @@ -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) { @@ -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")); } @@ -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 cb = [](const ignition::msgs::Boolean &/*_rep*/, const bool _result) @@ -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); diff --git a/src/gui/plugins/component_inspector/ComponentInspector.hh b/src/gui/plugins/component_inspector/ComponentInspector.hh index 0590aa31c7..54a6659a70 100644 --- a/src/gui/plugins/component_inspector/ComponentInspector.hh +++ b/src/gui/plugins/component_inspector/ComponentInspector.hh @@ -253,6 +253,7 @@ 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, @@ -260,7 +261,8 @@ namespace gazebo 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 diff --git a/src/gui/plugins/component_inspector/ComponentInspector.qml b/src/gui/plugins/component_inspector/ComponentInspector.qml index c9f68bd1e4..9e94025b16 100644 --- a/src/gui/plugins/component_inspector/ComponentInspector.qml +++ b/src/gui/plugins/component_inspector/ComponentInspector.qml @@ -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) } /* diff --git a/src/gui/plugins/component_inspector/Light.qml b/src/gui/plugins/component_inspector/Light.qml index f051feb2b3..b32da765a3 100644 --- a/src/gui/plugins/component_inspector/Light.qml +++ b/src/gui/plugins/component_inspector/Light.qml @@ -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++ @@ -127,7 +130,8 @@ Rectangle { falloffItem.value, intensityItem.value, model.data[20], - isLightOnItem.checked + isLightOnItem.checked, + visualizeVisualItem.checked ); } @@ -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 { + id: visualizeVisualLoader + anchors.fill: parent + property double numberValue: model.data[22] + sourceComponent: ignSwitch + onLoaded: { + visualizeVisualItem = visualizeVisualLoader.item + } + } + } + } + RowLayout { Rectangle { color: "transparent" diff --git a/src/rendering/RenderUtil.cc b/src/rendering/RenderUtil.cc index 15e7bdfd43..4954674668 100644 --- a/src/rendering/RenderUtil.cc +++ b/src/rendering/RenderUtil.cc @@ -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() && @@ -2131,6 +2132,29 @@ void RenderUtilPrivate::UpdateLights( auto l = std::dynamic_pointer_cast(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; diff --git a/src/rendering/SceneManager.cc b/src/rendering/SceneManager.cc index fe334bad2a..79893983f2 100644 --- a/src/rendering/SceneManager.cc +++ b/src/rendering/SceneManager.cc @@ -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( lightVisual); lightVis->SetUserData("gazebo-entity", static_cast(_id)); diff --git a/src/systems/user_commands/UserCommands.cc b/src/systems/user_commands/UserCommands.cc index 1bd29a7d96..2b56e369c9 100644 --- a/src/systems/user_commands/UserCommands.cc +++ b/src/systems/user_commands/UserCommands.cc @@ -159,6 +159,27 @@ class LightCommand : public UserCommandBase public: std::function 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 @@ -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() &&