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

Fix pose of plane visual with non-default normal vector #574

Merged
merged 4 commits into from
Feb 12, 2021

Conversation

azeey
Copy link
Contributor

@azeey azeey commented Jan 20, 2021

Trying to verify my comment led me to this bug. It looks like the rotation due to a plane's normal vector is accounted for during the creation of the visual but not in pose update. The creation is in: https://github.com/ignitionrobotics/ign-gazebo/blob/ddd7fcda563b1f8c47c92610181a2d5f797c80bc/src/rendering/SceneManager.cc#L261-L267 and the pose update is done in: https://github.com/ignitionrobotics/ign-gazebo/blob/ddd7fcda563b1f8c47c92610181a2d5f797c80bc/src/rendering/RenderUtil.cc#L860 https://github.com/ignitionrobotics/ign-gazebo/blob/ddd7fcda563b1f8c47c92610181a2d5f797c80bc/src/rendering/RenderUtil.cc#L425

To test this, run the shapes.sdf example and set the plane visual's normal to 1 0 0.

diff --git a/examples/worlds/shapes.sdf b/examples/worlds/shapes.sdf
index 5dec565b..2136df07 100644
--- a/examples/worlds/shapes.sdf
+++ b/examples/worlds/shapes.sdf
@@ -35,3 +35,3 @@ Try moving a model:
             <plane>
-              <normal>0 0 1</normal>
+              <normal>1 0 0</normal>
             </plane>
@@ -42,3 +42,3 @@ Try moving a model:
             <plane>
-              <normal>0 0 1</normal>
+              <normal>1 0 0</normal>
               <size>100 100</size>

The plane should intersect with the shapes like so
image

Without this patch, the plane is not affected
image

I believe this fixes #26.

@azeey azeey requested review from iche033 and chapulina January 20, 2021 22:18
@github-actions github-actions bot added the 🏰 citadel Ignition Citadel label Jan 20, 2021
@iche033
Copy link
Contributor

iche033 commented Jan 21, 2021

looks good to me. I think the removal of user data should be fine as well since we don't expect the geometry pose to change at run time. Approving once builds turn green

@chapulina chapulina added the rendering Involves Ignition Rendering label Jan 21, 2021
@@ -258,16 +258,11 @@ rendering::VisualPtr SceneManager::CreateVisual(Entity _id,
/// In general, this can be used to store any local transforms between the
/// parent Visual and geometry.
rendering::VisualPtr geomVis;
if (localPose != math::Pose3d::Zero)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most visuals don't have a local pose. I think only the planes do. So removing this check is essentially duplicating the number of visuals in the scene by nesting an extra visual inside every visual. It may be worth it looking into performance impacts.

Another thing to keep in mind is that there may be code assuming that the visual with the entity ID has a geometry, as opposed to having a child visual. So I think this has the potential to break existing plugins and other user code.

Copy link
Contributor

@iche033 iche033 Jan 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just ran into an issue with this new node structure. This unfortunately broke thermal cameras which rely on the entity ID stored in the geometry to point to the parent visual but now it's pointing to a geometry visual.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, would it be better to add a local pose member to rendering::Geometry? Do we have other alternatives?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm how about we do this for the ground plane as special case? i.e.

    if (localPose != math::Pose3d::Zero)
    {
      rendering::VisualPtr geomVis = this->dataPtr->scene->CreateVisual(name + "_geom");
      geomVis->SetLocalPose(localPose);
      geomVis->AddGeometry(geom);
      visualVis->AddChild(geomVis);
    }
    else
    {
      visualVis->AddGeometry(geom);
    }
    visualVis->SetLocalScale(scale);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm how about we do this for the ground plane as special case? i.e.

Yup, I can do that, but it would affect all plane shapes, not just the ground plane. This could still break existing code though if, as @chapulina said, the code assumes that the visual with the entity ID always has a geometry, as opposed to having a child visual.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in d3c0732

Copy link
Contributor

@iche033 iche033 Jan 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could still break existing code though

yeah.. I can't think of a good workaround for now. Adding localPose to Geometry in ign-rendering also means internally we'll be creating a node to store the geometry and apply transformation to this parent node.

One approach I'm thinking of is to transform the vertices of the plane that gets created in ign-rendering based on its normal. Alternatively add an Transform function ign-common's Mesh class to we can rotate it before feeding the mesh data to ign-rendering.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried the current fix and it didn't seem to break any GUI functionality, like selection, highlight and collision visualization. So at least our plugins seem to be ok with the change. There's a small chance that this breaks downstream plugins, but I think the chance is small enough that the benefits outweigh it. Let's get this in!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏰 citadel Ignition Citadel rendering Involves Ignition Rendering
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants