bevy_xpbd
bevy_xpbd copied to clipboard
Add debug rendering for `shape_intersections`
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 Collider
s 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
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<Entity> {
if let Some(cuboid) = shape.shape().downcast_ref::<avian2d::parry::shape::Cuboid>() {
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)
}
}