Skip to content

Commit

Permalink
Fix shape modification not updating graphics in testbed
Browse files Browse the repository at this point in the history
  • Loading branch information
agarret7 committed Aug 4, 2024
1 parent 617428e commit cd5daae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion examples3d/debug_shape_modification3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn init_world(testbed: &mut Testbed) {
let mut step = 0;
let snapped_frame = 51;

testbed.add_callback(move |_, physics, _, _| {
testbed.add_callback(move |mut gfx, physics, _, _| {
step += 1;

// Snap the ball velocity or restore it.
Expand All @@ -62,6 +62,10 @@ pub fn init_world(testbed: &mut Testbed) {

let ball_coll = physics.colliders.get_mut(ball_coll_handle).unwrap();
ball_coll.set_shape(SharedShape::ball(ball_rad * step as f32 * 2.0));
if let Some(gfx) = &mut gfx {
gfx.remove_collider(ball_coll_handle, &physics.colliders);
gfx.add_collider(ball_coll_handle, &physics.colliders);
}
});

/*
Expand Down
8 changes: 6 additions & 2 deletions src_testbed/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,18 @@ impl GraphicsManager {
collider: ColliderHandle,
) {
let body = body.unwrap_or(RigidBodyHandle::invalid());
if let Some(sns) = self.b2sn.get_mut(&body) {
for sn in sns.iter_mut() {
if let Some(sns) = self.b2sn.remove(&body) {
let mut new_sn = 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_sn.push(sn);
}
}
}
self.b2sn.insert(body, new_sn);
}
}

Expand Down

0 comments on commit cd5daae

Please sign in to comment.