Skip to content

Commit 9888685

Browse files
committed
Fix enlarged AABB init
1 parent 2187f79 commit 9888685

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/collider_tree/update.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,22 @@ impl<C: AnyCollider> Plugin for ColliderTreeUpdatePlugin<C> {
7878
&Rotation,
7979
Option<&CollisionMargin>,
8080
&mut ColliderAabb,
81+
&mut EnlargedAabb,
8182
)>,
8283
narrow_phase_config: Res<NarrowPhaseConfig>,
8384
length_unit: Res<PhysicsLengthUnit>,
8485
collider_context: StaticSystemParam<C::Context>| {
8586
let contact_tolerance = length_unit.0 * narrow_phase_config.contact_tolerance;
8687
let aabb_context = AabbContext::new(trigger.entity, &*collider_context);
8788

88-
if let Ok((collider, pos, rot, collision_margin, mut aabb)) =
89+
if let Ok((collider, pos, rot, collision_margin, mut aabb, mut enlarged_aabb)) =
8990
query.get_mut(trigger.entity)
9091
{
9192
let collision_margin = collision_margin.map_or(0.0, |m| m.0);
9293
*aabb = collider
9394
.aabb_with_context(pos.0, *rot, aabb_context)
9495
.grow(Vector::splat(contact_tolerance + collision_margin));
96+
enlarged_aabb.update(&aabb, 0.0);
9597
}
9698
},
9799
);
@@ -113,9 +115,7 @@ impl<C: AnyCollider> Plugin for ColliderTreeUpdatePlugin<C> {
113115
app.add_observer(add_to_tree_on::<Insert, (C, ColliderOf), Without<ColliderDisabled>>);
114116

115117
// Case 2
116-
app.add_observer(
117-
remove_from_tree_on::<Remove, C, (Without<Disabled>, Without<ColliderDisabled>)>,
118-
);
118+
app.add_observer(remove_from_tree_on::<Remove, C, Without<ColliderDisabled>>);
119119

120120
// Case 3
121121
app.add_observer(
@@ -816,6 +816,7 @@ fn update_static_aabbs<C: AnyCollider>(
816816
&Position,
817817
&Rotation,
818818
&mut ColliderAabb,
819+
&mut EnlargedAabb,
819820
&C,
820821
Option<&CollisionMargin>,
821822
&ColliderTreeProxyKey,
@@ -841,13 +842,15 @@ fn update_static_aabbs<C: AnyCollider>(
841842
.init_primitives_to_nodes_if_uninit();
842843

843844
// TODO: Parallelize this and/or avoid iterating over all static bodies.
845+
// TODO: Enlarged AABBs are not really needed for static colliders.
844846
for body_colliders in &static_bodies {
845847
let mut iter = colliders.iter_many_mut(body_colliders.iter());
846848
while let Some((
847849
entity,
848850
collider_pos,
849851
collider_rot,
850852
mut aabb,
853+
mut enlarged_aabb,
851854
collider,
852855
margin,
853856
proxy_key,
@@ -861,6 +864,7 @@ fn update_static_aabbs<C: AnyCollider>(
861864
*aabb = collider
862865
.aabb_with_context(collider_pos.0, *collider_rot, context)
863866
.grow(Vector::splat(contact_tolerance + margin));
867+
enlarged_aabb.update(&aabb, 0.0);
864868

865869
// Reinsert the proxy into the BVH.
866870
collider_trees
@@ -880,6 +884,7 @@ fn update_standalone_aabbs<C: AnyCollider>(
880884
&Position,
881885
&Rotation,
882886
&mut ColliderAabb,
887+
&mut EnlargedAabb,
883888
&C,
884889
Option<&CollisionMargin>,
885890
&ColliderTreeProxyKey,
@@ -905,8 +910,16 @@ fn update_standalone_aabbs<C: AnyCollider>(
905910
.bvh
906911
.init_primitives_to_nodes_if_uninit();
907912

908-
for (entity, collider_pos, collider_rot, mut aabb, collider, margin, proxy_key) in
909-
&mut colliders
913+
for (
914+
entity,
915+
collider_pos,
916+
collider_rot,
917+
mut aabb,
918+
mut enlarged_aabb,
919+
collider,
920+
margin,
921+
proxy_key,
922+
) in &mut colliders
910923
{
911924
let margin = margin.map_or(0.0, |margin| margin.0);
912925

@@ -916,6 +929,7 @@ fn update_standalone_aabbs<C: AnyCollider>(
916929
*aabb = collider
917930
.aabb_with_context(collider_pos.0, *collider_rot, context)
918931
.grow(Vector::splat(contact_tolerance + margin));
932+
enlarged_aabb.update(&aabb, 0.0);
919933

920934
// Reinsert the proxy into the BVH.
921935
collider_trees

0 commit comments

Comments
 (0)