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

Scene: support deletion of Heightmap Visuals #3171

Merged
merged 4 commits into from
Feb 11, 2022

Conversation

scpeters
Copy link
Member

As noted in #3159, removing a model containing a heightmap causes its collision shape to be remove from the physics subsystem in gzserver, but the heightmap visual remains in gzclient. This pull request fixes that so that height map visuals should now disappear from gzclient when a heightmap model is deleted. The sequence of commits is described below:

  • 1445ab1: This was my first simple attempt to support removing the visual by storing the visual Id associated with the heightmap / terrain and adding logic in Scene::RemoveVisual to delete the terrain object when a visual matching terrainVisualId is removed. This didn't actually work.
  • e497d4d: This includes two fixes needed to allow removal of the heightmap visual: using a proper parent visual and adding the visual to the dataPtr::visuals vector. This code was already present elsewhere in ProcessVisualMsg, so I duplicated it to apply to the heightmap codepath. I didn't like this code duplication, so I worked to eliminate that in the following two commits.
  • f3eaaee: This changes the Heightmap visual loading to use Visual::LoadFromMsg for consistency with the latter parts of ProcessVisualMsg. It requires construction of an extra boost::shared_ptr but I think the consistency is worth it.
  • 77bbc8c: This deduplicates the code by moving much of the heightmap processing code to the end of ProcessVisualMsg so it can share the existing portions that it had duplicated. This commit has a net reduction of 25 lines.

A Heightmap visual still appears in gzclient even when its
corresponding Visual is removed using Scene::RemoveVisual,
as reported in Issue #3159.

This attempts to delete the ScenePrivate::terrain object
when its corresponding Visual is passed to RemoveVisual
by storing the corresponding Visual Id. It doesn't seem
to work though.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
Copy code from elsewhere in Scene::ProcessVisualMsg
to fix removal of heightmap visual.

* Try to find parent visual for heightmap instead
  of only using the world visual
* Add heightmap visual to the visuals vector so
  it can be removed in RemoveVisual

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
The Heightmap visual loading code in Scene::ProcessVisualMsg
was not using the same Visual::LoadFromMsg method as the
other visuals. This changes it to be more consistent.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
Refactor code in Scene::ProcessVisualMsg so that
a Visual containing a heightmap uses more of the
same code path as other visuals. This also allows
removing duplicated code.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
@scpeters
Copy link
Member Author

The heightmap will never be visited because it isn't part of visuals.

it should be fixed by e497d4d

Copy link
Contributor

@WilliamLewww WilliamLewww left a comment

Choose a reason for hiding this comment

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

Test failures irrelevant to changes.

@scpeters scpeters merged commit d4dbf98 into gazebo11 Feb 11, 2022
@scpeters scpeters deleted the scpeters/rm_heightmap_visual branch February 11, 2022 20:28
@tekfr34k
Copy link

Thank you for fixing this as it's a functionality I need for a project. I might've spotted a bug however:
When using ROS for:

  • spawning an SDF model to add a heightmap into the scene
  • deleting the heightmap from the scene again
  • creating a new heightmap image
  • spawning the SDF model again with the new heightmap (same name, no changes in config) into the scene

For some reason it uses the old visual representation (of the old heightmap) but the collisions work as intended (they're based on the new heightmap).
A dirty work around that I'm using now is just to spawn the same new heightmap, delete it, then spawn it again, so that "buffer"-like anomaly disappears.

@tekfr34k
Copy link

Seems my previously described issue was caused by the cache problems with heightmaps similar to the comments in #2604. Deleting the ~/.gazebo/paging/MODELNAME folder within my script, each time I spawn a new heightmap fixed the problem without needing the workaround of double spawning (which didn't work that great after further testing).

@scpeters
Copy link
Member Author

@tekfr34k can you open an issue describing how to reproduce the problem?

thanks!

@tekfr34k
Copy link

@scpeters I couldn't narrow down what exactly the problem is yet. The issue is very inconsistent, depending on if I start Gazebo from my launch scripts or just without any configuration at all it behaves differently. Maybe it has something to do with defining multiple model paths (even if the models are named differently in the SDF/config). Adding a model path in the "Insert" tab which contains the heightmap SDF gives an issue of not showing the model in the overview. Maybe that's something to start with...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants