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

Heightmap triangulation pattern differs between ODE and OGRE #2838

Open
scpeters opened this issue Sep 2, 2020 · 6 comments
Open

Heightmap triangulation pattern differs between ODE and OGRE #2838

scpeters opened this issue Sep 2, 2020 · 6 comments

Comments

@scpeters
Copy link
Member

scpeters commented Sep 2, 2020

Heightmaps are a 2.5D surface defined by a Cartesian grid of points in 2 axes (X and Y for SDFormat / Gazebo) with heights specified for the 3rd axis (Z for SDFormat / Gazebo). To create a surface from these points, each square formed by 4 nearby points is divided into triangles along one of the diagonals. It turns out that the triangulation pattern is different between OGRE (rendering) and ODE (default physics engine). This may not be very noticeable for heightmaps with fine resolution, but it may be a confounding issue when trying to debug heightmap contact behavior.

OGRE uses a zig-zag pattern with the diagonals alternating direction (see OgreTerrain.cpp):

ogre_heightmap_triangulation

ODE, by contrast, uses the same direction for diagonals everywhere (see heightfield.cpp).

Bullet uses the ODE approach by default but actually has a flag to match the OGRE approach (see setUseZigzagSubdivision in btHeightfieldTerrainShape.h and its use in btHeightfieldTerrainShape.cpp and bullet issue 625).

Update: it looks like when DART uses bullet for collision detection, the zig-zag flag is enabled, so that it will match OGRE:

scpeters added a commit to scpeters/gazebo that referenced this issue Sep 9, 2020
This adds a python script to the media/materials/textures
folder that can be used to generate a png file with a
square grayscale gradient that corresponds to a pyramid
heightmap.

Due to gazebosim#2838, the triangulation pattern differs between
OGRE and ODE, so some contact behavior can look wrong
in the places where this visualization differs.

Signed-off-by: Steve Peters <[email protected]>
@scpeters
Copy link
Member Author

scpeters commented Sep 9, 2020

To help visualize this, I made a script for generating a png image with square gradients for use as a pyramid heightmap in scpeters@9fd36f8.

heightmap_pyramid_65x65

I've also added a demo world with a few spheres and some CPU LIDAR sensors, since they use the physics engine for collision detection.

Since ODE always uses the same diagonal direction for its triangulation, the lines where each pyramid face meet will have different triangulation. The following image shows how the 8 triangles at the top of the pyramid are constructed for ODE:

heightmap_pyramid_triangulation_ode

When the triangulation diagonal is parallel to line where faces meet, it models the pyramid shape quite well. In the following screenshot, you can see from the LIDAR scan that ODE treats that edge like a smooth line, in contrast to the wireframe rendered by OGRE, which is quite bumpy.

Screenshot from 2020-09-09 15-05-55

When the triangulation diagonal is perpendicular to the line where faces meet, ODE models the surface with a stair-step pattern, which differs from the OGRE surface model.

Screenshot from 2020-09-09 14-57-16

@scpeters
Copy link
Member Author

scpeters commented Sep 9, 2020

This shows the behavior of some spheres added near the top of the pyramid. The spheres on the left are above the jagged edge of the heightmap, one of which falls and rests on one of the stair-steps and the other bounces down the steps. The spheres on the right are above the smooth edge, each one offset to x or y, and they roll smoothly down the side to which they are offset.

heightmap_pyramid_top_large_spheres

@scpeters
Copy link
Member Author

scpeters commented Oct 5, 2020

I've noticed some strange behavior with spheres falling into a heightmap and disappearing when they fall directly on a sharp ridge. The following animation shows the unit_medium_sphere_smooth_falls_through red sphere added in scpeters@e953586 that falls through the sharp edge of the pyramid

heightmap_pyramid_sphere_disappear

@scpeters
Copy link
Member Author

scpeters commented Oct 5, 2020

@scpeters
Copy link
Member Author

bug about spheres falling through heightmap reported upstream at https://bitbucket.org/odedevs/ode/issues/71/small-spheres-fall-through-convex-edges-of

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

No branches or pull requests

1 participant