Fix shape modification not updating graphics in testbed#708
Fix shape modification not updating graphics in testbed#708sebcrozet merged 4 commits intodimforge:masterfrom
Conversation
| if let Some(sns) = self.b2sn.remove(&body) { | ||
| let mut new_sns = vec![]; | ||
| for sn in sns.into_iter() { | ||
| if let Some(sn_c) = sn.collider { | ||
| if sn_c == collider { | ||
| commands.entity(sn.entity).despawn(); | ||
| } else { | ||
| new_sns.push(sn); | ||
| } | ||
| } | ||
| } | ||
| self.b2sn.insert(body, new_sns); |
There was a problem hiding this comment.
| if let Some(sns) = self.b2sn.remove(&body) { | |
| let mut new_sns = vec![]; | |
| for sn in sns.into_iter() { | |
| if let Some(sn_c) = sn.collider { | |
| if sn_c == collider { | |
| commands.entity(sn.entity).despawn(); | |
| } else { | |
| new_sns.push(sn); | |
| } | |
| } | |
| } | |
| self.b2sn.insert(body, new_sns); | |
| if let Some(mut sns) = self.b2sn.remove(&body) { | |
| sns = sns | |
| .into_iter() | |
| .filter(|sn| { | |
| let Some(sn_c) = sn.collider else { | |
| return false; | |
| }; | |
| if sn_c == collider { | |
| commands.entity(sn.entity).despawn(); | |
| return false; | |
| } else { | |
| return true; | |
| } | |
| }) | |
| .collect(); | |
| self.b2sn.insert(body, sns); | |
| } |
Small nitpick, I did that just to help me understand the change, not sure if which is better, don´t worry about it I'll merge one or the other after discussion with seb.
There was a problem hiding this comment.
This can be simplified further with Vec::retain:
if let Some(sns) = self.b2sn.get_mut(&body) {
sns.retain(|sn| {
if let Some(sn_c) = sn.collider {
if sn_c == collider {
commands.entity(sn.entity).despawn();
return false;
}
}
true
});
}this also fixes the case where we the scene node doesn’t have a collider attached, in which case we don’t want this method to remove it from the list.
|
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:
rapier/src_testbed/objects/node.rs Lines 82 to 85 in eba44e7
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 rapier/src/geometry/collider.rs Lines 445 to 449 in eba44e7 It seems like monitoring those changes from the testbed requires a new function like |
|
Thanks! |
This PR is for a fix for the
GraphicsManager::remove_collider_nodesfunction in the testbed. The problem was that the entity was despawned but not removed fromGraphicsManager::b2sn, creating an invalid state. See this thread for the discussion.TestbedApp::add_callbackstill requires a manual refresh withgfx.add_colliderif the user wants to see the 3D entity update correctly.debug_shape_modification3before:debug_shape_modification3after: