Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/ign-gazebo6' into ahcorde/6_to_7…
Browse files Browse the repository at this point in the history
…/11_29_2022
  • Loading branch information
ahcorde committed Nov 29, 2022
2 parents 0e950b9 + 678b985 commit fde6ec6
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 142 deletions.
13 changes: 13 additions & 0 deletions src/SdfEntityCreator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,19 @@ Entity SdfEntityCreator::CreateEntities(const sdf::Light *_light)
this->dataPtr->ecm->CreateComponent(lightEntity,
components::LightType(convert(_light->Type())));

// Light Visual
Entity lightVisualEntity = this->dataPtr->ecm->CreateEntity();
this->dataPtr->ecm->CreateComponent(lightVisualEntity, components::Visual());
this->dataPtr->ecm->CreateComponent(lightVisualEntity,
components::Pose());
this->dataPtr->ecm->CreateComponent(lightVisualEntity,
components::Name(_light->Name() + "Visual"));
this->dataPtr->ecm->CreateComponent(lightVisualEntity,
components::CastShadows(false));
this->dataPtr->ecm->CreateComponent(lightVisualEntity,
components::Transparency(false));
this->SetParent(lightVisualEntity, lightEntity);

return lightEntity;
}

Expand Down
23 changes: 23 additions & 0 deletions src/gui/plugins/view_angle/ViewAngle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ namespace gz::sim
/// \brief View Control service name
public: std::string viewControlService;

/// \brief View Control reference visual service name
public: std::string viewControlRefVisualService;

/// \brief gui camera pose
public: math::Pose3d camPose;

Expand Down Expand Up @@ -121,6 +124,9 @@ void ViewAngle::LoadConfig(const tinyxml2::XMLElement *)
// view control requests
this->dataPtr->viewControlService = "/gui/camera/view_control";

// view control reference visual requests
this->dataPtr->viewControlRefVisualService = "/gui/camera/reference_visual";

// Subscribe to camera pose
std::string topic = "/gui/camera/pose";
this->dataPtr->node.Subscribe(
Expand Down Expand Up @@ -204,6 +210,23 @@ void ViewAngle::OnViewControl(const QString &_controller)
this->dataPtr->node.Request(this->dataPtr->viewControlService, req, cb);
}

/////////////////////////////////////////////////
void ViewAngle::OnViewControlReferenceVisual(bool _enable)
{
std::function<void(const msgs::Boolean &, const bool)> cb =
[](const msgs::Boolean &/*_rep*/, const bool _result)
{
if (!_result)
ignerr << "Error setting view controller reference visual" << std::endl;
};

msgs::Boolean req;
req.set_data(_enable);

this->dataPtr->node.Request(
this->dataPtr->viewControlRefVisualService, req, cb);
}

/////////////////////////////////////////////////
QList<double> ViewAngle::CamPose() const
{
Expand Down
6 changes: 6 additions & 0 deletions src/gui/plugins/view_angle/ViewAngle.hh
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ namespace sim
/// \param[in] _mode New camera view controller
public slots: void OnViewControl(const QString &_controller);

/// \brief Callback in Qt thread when camera view reference visual state
/// changes.
/// \param[in] _enable True to enable camera view control reference visual,
/// false to hide it
public slots: void OnViewControlReferenceVisual(bool _enable);

/// \brief Get the current gui camera pose.
public: Q_INVOKABLE QList<double> CamPose() const;

Expand Down
13 changes: 13 additions & 0 deletions src/gui/plugins/view_angle/ViewAngle.qml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,19 @@ ColumnLayout {
}
}

// toggle view control reference visual
CheckBox {
Layout.alignment: Qt.AlignHCenter
id: displayVisual
Layout.columnSpan: 6
Layout.fillWidth: true
text: qsTr("Display View Control Reference Visual")
checked: true
onClicked: {
ViewAngle.OnViewControlReferenceVisual(checked)
}
}

// Set camera pose
Text {
text: "Camera Pose"
Expand Down
39 changes: 19 additions & 20 deletions src/rendering/RenderUtil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1201,27 +1201,26 @@ void RenderUtil::Update()

for (const auto &light : newLights)
{
this->dataPtr->sceneManager.CreateLight(std::get<0>(light),
std::get<1>(light), std::get<2>(light), std::get<3>(light));

// TODO(anyone) This needs to be updated for when sensors and GUI use
// the same scene
// create a new id for the light visual, if we're not loading sensors
if (!this->dataPtr->enableSensors)
auto newLightRendering = this->dataPtr->sceneManager.CreateLight(
std::get<0>(light),
std::get<1>(light),
std::get<2>(light),
std::get<3>(light));

if (newLightRendering)
{
rendering::VisualPtr lightVisual =
this->dataPtr->sceneManager.CreateLightVisual(
std::get<0>(light) + 1,
std::get<1>(light),
std::get<2>(light),
std::get<0>(light));
this->dataPtr->matchLightWithVisuals[std::get<0>(light)] =
std::get<0>(light) + 1;
}
else
{
auto attempts = 100000u;
for (auto i = 0u; i < attempts; ++i)
{
Entity id = std::numeric_limits<uint64_t>::min() + i;
if (!this->dataPtr->sceneManager.HasEntity(id))
{
rendering::VisualPtr lightVisual =
this->dataPtr->sceneManager.CreateLightVisual(
id, std::get<1>(light), std::get<2>(light), std::get<0>(light));
this->dataPtr->matchLightWithVisuals[std::get<0>(light)] = id;
break;
}
}
ignerr << "Failed to create light" << std::endl;
}
}

Expand Down
16 changes: 15 additions & 1 deletion src/rendering/SceneManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,13 @@ rendering::LightPtr SceneManager::CreateLight(Entity _id,
if (!this->dataPtr->scene)
return rendering::LightPtr();

if (this->HasEntity(_id))
{
ignerr << "Light with Id: [" << _id << "] can not be create there is "
"another entity with the same entity number" << std::endl;
return nullptr;
}

if (this->dataPtr->lights.find(_id) != this->dataPtr->lights.end())
{
gzerr << "Light with Id: [" << _id << "] already exists in the scene"
Expand Down Expand Up @@ -2275,7 +2282,14 @@ SceneManager::LoadAnimations(const sdf::Actor &_actor)
}
}
if (addAnim)
meshSkel->AddBvhAnimation(animFilename, animScale);
{
if (!meshSkel->AddBvhAnimation(animFilename, animScale))
{
ignerr << "Bvh animation in file " << animFilename
<< " failed to load during actor creation" << std::endl;
continue;
}
}
mapAnimNameId[animName] = numAnims++;
}
else if (extension == "dae")
Expand Down
Loading

0 comments on commit fde6ec6

Please sign in to comment.