diff --git a/src/render/mod.rs b/src/render/mod.rs index 73c4b8b0..14aa8ba9 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -112,8 +112,7 @@ impl Plugin for RapierDebugRenderPlugin { struct BevyLinesRenderBackend<'world, 'state, 'a, 'b> { physics_scale: f32, custom_colors: Query<'world, 'state, &'a ColliderDebugColor>, - global: bool, - visible: Query<'world, 'state, &'a ColliderDebug>, + visible_colliders: Option>, context: &'b RapierContext, gizmos: Gizmos<'state>, } @@ -134,16 +133,16 @@ impl<'world, 'state, 'a, 'b> BevyLinesRenderBackend<'world, 'state, 'a, 'b> { } fn drawing_enabled(&self, object: DebugRenderObject) -> bool { - match object { - DebugRenderObject::Collider(h, ..) => self - .context - .colliders - .get(h) - .map(|co| { - let entity = Entity::from_bits(co.user_data as u64); - self.global || self.visible.contains(entity) - }) - .unwrap_or(false), + match (object, &self.visible_colliders) { + (DebugRenderObject::Collider(h, ..), Some(visible_colliders)) => { + let collider = self.context.colliders.get(h); + collider + .map(|co| { + let entity = Entity::from_bits(co.user_data as u64); + visible_colliders.contains(entity) + }) + .unwrap_or(false) + } _ => true, } } @@ -198,17 +197,16 @@ fn debug_render_scene<'a>( mut render_context: ResMut, gizmos: Gizmos, custom_colors: Query<&'a ColliderDebugColor>, - visible: Query<&'a ColliderDebug>, + visible_colliders: Query<&'a ColliderDebug>, ) { if !render_context.enabled { return; } let mut backend = BevyLinesRenderBackend { - global: render_context.global, physics_scale: rapier_context.physics_scale, custom_colors, - visible, + visible_colliders: render_context.global.then(|| visible_colliders), context: &rapier_context, gizmos, };