Skip to content

Commit

Permalink
added CreateCollision function to SceneManager
Browse files Browse the repository at this point in the history
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
  • Loading branch information
jennuine committed Jan 12, 2021
1 parent 4a1cba6 commit 704af0d
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 27 deletions.
10 changes: 9 additions & 1 deletion include/ignition/gazebo/rendering/SceneManager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,18 @@ inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
public: rendering::VisualPtr CreateVisual(Entity _id,
const sdf::Visual &_visual, Entity _parentId = 0);

/// \brief Create a collision visual
/// \param[in] _id Unique visual id
/// \param[in] _collision Collision sdf dom
/// \param[in] _parentId Parent id
/// \return Visual (collision) object created from the sdf dom
public: rendering::VisualPtr CreateCollision(Entity _id,
const sdf::Collision &_collision, Entity _parentId = 0);

/// \brief Retrieve visual
/// \param[in] _id Unique visual (entity) id
/// \return Pointer to requested visual
public: rendering::VisualPtr GetVisual(Entity _id);
public: rendering::VisualPtr VisualById(Entity _id);

/// \brief Create an actor
/// \param[in] _id Unique actor id
Expand Down
2 changes: 1 addition & 1 deletion src/gui/plugins/modules/EntityContextMenu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void EntityContextMenu::OnRequest(const QString &_request, const QString &_data)
req.set_data(_data.toStdString());
this->dataPtr->node.Request(this->dataPtr->followService, req, cb);
}
else if (request == "viewCollisions")
else if (request == "view_collisions")
{
ignition::msgs::StringMsg req;
req.set_data(_data.toStdString());
Expand Down
13 changes: 12 additions & 1 deletion src/gui/plugins/modules/EntityContextMenu.qml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ Item {
text: "Remove"
onTriggered: context.OnRemove(context.entity, context.type)
}
// // cascading submenu only works in Qt 5.10+ on focal
// Menu {
// id: viewSubmenu
// title: "View"
// MenuItem {
// id: viewCollisionsMenu
// text: "Collisions"
// onTriggered: context.OnRequest("view_collisions", context.entity)
// }
// }
// workaround for getting submenu's to work on bionic (< Qt 5.10)
MenuItem {
id: viewSubmenu
text: "View >"
Expand All @@ -57,7 +68,7 @@ Item {
text: "Collisions"
onTriggered: {
menu.close()
context.OnRequest("viewCollisions", context.entity)
context.OnRequest("view_collisions", context.entity)
}
}
}
Expand Down
11 changes: 0 additions & 11 deletions src/gui/plugins/scene3d/Scene3D.cc
Original file line number Diff line number Diff line change
Expand Up @@ -817,17 +817,6 @@ void IgnRenderer::Render()
rendering::NodePtr targetNode =
scene->NodeByName(this->dataPtr->viewCollisionsTarget);

if (!targetNode)
{
// workaround for selecting collision
size_t found = this->dataPtr->viewCollisionsTarget.find_last_of("::");
if (found != std::string::npos)
{
targetNode = scene->NodeByName(
this->dataPtr->viewCollisionsTarget.substr(0, found-1));
}
}

if (targetNode)
{
Entity targetEntity =
Expand Down
15 changes: 3 additions & 12 deletions src/rendering/RenderUtil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -535,17 +535,8 @@ void RenderUtil::Update()
{
if (!this->dataPtr->sceneManager.HasEntity(colEntity))
{
sdf::Collision collision = this->dataPtr->entityCollisions[colEntity];

sdf::Material material;
material.SetAmbient(math::Color(1, 0.5088, 0.0468, 1));
material.SetDiffuse(math::Color(1, 0.5088, 0.0468, 1));
material.SetSpecular(math::Color(0.5, 0.5, 0.5, 1));

sdf::Visual visual;
visual.SetGeom(*collision.Geom());
visual.SetMaterial(material);
this->dataPtr->sceneManager.CreateVisual(colEntity, visual, link);
this->dataPtr->sceneManager.CreateCollision(colEntity,
this->dataPtr->entityCollisions[colEntity], link);
this->dataPtr->viewingCollisions[colEntity] = true;
}
}
Expand Down Expand Up @@ -1493,7 +1484,7 @@ void RenderUtil::ViewCollisions(const Entity &_entity)
}

rendering::VisualPtr colVisual =
this->dataPtr->sceneManager.GetVisual(colEntity);
this->dataPtr->sceneManager.VisualById(colEntity);
if (colVisual == nullptr)
{
ignerr << "Could not find collision visual for entity [" << colEntity
Expand Down
18 changes: 17 additions & 1 deletion src/rendering/SceneManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <map>

#include <sdf/Box.hh>
#include <sdf/Collision.hh>
#include <sdf/Cylinder.hh>
#include <sdf/Mesh.hh>
#include <sdf/Pbr.hh>
Expand Down Expand Up @@ -342,7 +343,7 @@ rendering::VisualPtr SceneManager::CreateVisual(Entity _id,
}

/////////////////////////////////////////////////
rendering::VisualPtr SceneManager::GetVisual(Entity _id)
rendering::VisualPtr SceneManager::VisualById(Entity _id)
{
if (this->dataPtr->visuals.find(_id) == this->dataPtr->visuals.end())
{
Expand All @@ -352,6 +353,21 @@ rendering::VisualPtr SceneManager::GetVisual(Entity _id)
return this->dataPtr->visuals[_id];
}

/////////////////////////////////////////////////
rendering::VisualPtr SceneManager::CreateCollision(Entity _id,
const sdf::Collision &_collision, Entity _parentId)
{
sdf::Material material;
material.SetAmbient(math::Color(1, 0.5088, 0.0468, 0.7));
material.SetDiffuse(math::Color(1, 0.5088, 0.0468, 0.7));

sdf::Visual visual;
visual.SetGeom(*_collision.Geom());
visual.SetMaterial(material);
visual.SetCastShadows(false);
rendering::VisualPtr collisionVis = CreateVisual(_id, visual, _parentId);
return collisionVis;
}
/////////////////////////////////////////////////
rendering::GeometryPtr SceneManager::LoadGeometry(const sdf::Geometry &_geom,
math::Vector3d &_scale, math::Pose3d &_localPose)
Expand Down

0 comments on commit 704af0d

Please sign in to comment.