Fix shape modification not updating graphics in testbed
This PR is for a fix for the GraphicsManager::remove_collider_nodes function in the testbed. The problem was that the entity was despawned but not removed from GraphicsManager::b2sn, creating an invalid state. See this thread for the discussion.
TestbedApp::add_callback still requires a manual refresh with gfx.add_collider if the user wants to see the 3D entity update correctly.
if let Some(gfx) = &mut gfx {
gfx.remove_collider(ball_coll_handle, &physics.colliders);
gfx.add_collider(ball_coll_handle, &physics.colliders);
}
debug_shape_modification3 before:
debug_shape_modification3 after:
For the record, I think the best solution is to monitor changes over the shapes, and then modify the mesh handle:
In practice, running these snippets of code:
- recompute the mesh:
https://github.com/dimforge/rapier/blob/eba44e71f8cee93a835bdc690dd6ea7d8053909a/src_testbed/objects/node.rs#L82-L85
- Then reapply the mesh handle on the entity.
But as we're in testbed, I think this solution is good enough :)
I had thought that it might be good to factor these sorts of updates into the testbed loop, but wasn't sure how to track incremental computation of the state. Especially since I noticed you have a vector of flags already tracking collider updates in ColliderSet::changes private to the rapier3d crate and that collider.set_shape uses this internally:
https://github.com/dimforge/rapier/blob/eba44e71f8cee93a835bdc690dd6ea7d8053909a/src/geometry/collider.rs#L445-L449
It seems like monitoring those changes from the testbed requires a new function like pub fn get_changes() -> &ColliderChanges? From what I could tell the ColliderChanges otherwise cannot be seen outside the main crate and thus wasn't sure how you might select meshes to be recomputed.
Thanks!