Jondolf / avian

ECS-driven 2D and 3D physics engine for the Bevy game engine.
https://crates.io/crates/avian3d
Apache License 2.0
1.4k stars 112 forks source link

Add debug rendering for `shape_intersections` #426

Open MeGaGiGaGon opened 2 months ago

MeGaGiGaGon commented 2 months ago

As the title says, it looks like currently no debug rendering is done for the colliders in SpatialQuery::shape_intersections. From what I could tell reading the debug rendering code, it only renders Colliders findable through a query, and the ones used in shape_intersections aren't part of that. Currently I do have a workaround in our code by mirroring the signature, but it would be nice to have present natively. Thanks.

Code we are currently using ```rust use bevy::color::palettes::css; use bevy::prelude::*; use avian2d::prelude::*; use bevy_ecs::system::SystemParam; #[derive(SystemParam)] pub struct ShapeIntersections<'w, 's> { pub spatial_query: SpatialQuery<'w, 's>, pub gizmos: Gizmos<'w, 's>, } impl ShapeIntersections<'_, '_> { pub fn shape_intersections( &mut self, shape: &Collider, shape_position: avian2d::math::Vector, shape_rotation: avian2d::math::Scalar, query_filter: SpatialQueryFilter, ) -> Vec { if let Some(cuboid) = shape.shape().downcast_ref::() { self.gizmos.primitive_2d(&Rectangle { half_size: cuboid.half_extents.into()}, shape_position, shape_rotation, css::YELLOW) }; self.spatial_query.shape_intersections(shape, shape_position, shape_rotation, query_filter) } } ```