Large convex hulls produce incorrect contact manifolds
- Dominant language
- Rust
- Stars
- 867
- Forks
- 157
- Avg merge
- 7d 13h
- Merged PRs (30d)
- 2
Description
Hi! I'm having an issue in my physics engine bevy_xpbd where convex hulls with large faces can return invalid contact manifolds, which produces very buggy and explosive behavior. This also impacts rapier and bevy_rapier, so it is most likely an issue in parry.
bevy_xpbd:
https://github.com/dimforge/parry/assets/57632562/e3862026-a45d-4065-914c-1d4bc3c59820
bevy_rapier:
https://github.com/dimforge/parry/assets/57632562/d306f8d9-4eee-4e9e-87ce-7761096fd650
In these examples, the ground is a 20,000 x 20,000 convex hull, but even 500 x 500 has issues. However, smaller convex hulls like 30 x 30 don't really have any problems. Using f64 precision also helps. Other collider types like trimeshes also don't have issues even at much bigger scales.
When a faulty collision occurs, the contact normal is often flipped and the contact points are almost inverted (contact that should be at the bottom of the cube is at the top). This causes very large penetration depths and explosions.
I tried to track down where the issue is, and based on logs it looks like it often happens when [this line](https://github.com/dimforge/parry/blob/aefe2a661efbe602a33714b32e337acc49df92b4/src/query/contact/contact_support_map_support_map.rs#L64) returns `GJKResult::ClosestPoints`. Changing `exact_dist` to false helps a bit, but it causes other issues, and I think it only helps because it makes gjk return early (I think). I also logged normals, and the incorrect normals seem to be computed in `gjk::closest_points`, but I don't know the reason for those incorrect normals. Maybe the support map for the convex hull is wrong?
I can try to set up a repro specifically for parry if I can, but it's easiest to reproduce in e.g. bevy_rapier by just spawning some cubes onto a large flat convex hull and moving them around.
Contributor guide
Assessment
This issue has not been assessed yet.