rapier icon indicating copy to clipboard operation
rapier copied to clipboard

Fix shape modification not updating graphics in testbed

Open agarret7 opened this issue 1 year ago • 2 comments

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:

before

debug_shape_modification3 after:

after

agarret7 avatar Aug 04 '24 04:08 agarret7

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 :)

ThierryBerger avatar Aug 09 '24 13:08 ThierryBerger

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.

agarret7 avatar Aug 10 '24 03:08 agarret7

Thanks!

sebcrozet avatar Jan 08 '25 17:01 sebcrozet