diff --git a/src/spatial_query/pipeline.rs b/src/spatial_query/pipeline.rs index 81f8b995d..d0e0760df 100644 --- a/src/spatial_query/pipeline.rs +++ b/src/spatial_query/pipeline.rs @@ -51,7 +51,7 @@ impl SpatialQueryPipeline { SpatialQueryPipeline::default() } - pub(crate) fn as_composite_shape<'a>( + pub(crate) fn as_composite_shape_internal<'a>( &'a self, query_filter: &'a SpatialQueryFilter, ) -> QueryPipelineAsCompositeShape<'a> { @@ -61,7 +61,16 @@ impl SpatialQueryPipeline { } } - pub(crate) fn as_composite_shape_with_predicate<'a: 'b, 'b>( + /// Creates a parry [`TypedCompositeShape`] for this pipeline. + /// Can be used to implement custom spatial queries + pub fn as_composite_shape<'a>( + &'a self, + query_filter: &'a SpatialQueryFilter, + ) -> impl TypedCompositeShape { + self.as_composite_shape_internal(query_filter) + } + + pub(crate) fn as_composite_shape_with_predicate_internal<'a: 'b, 'b>( &'a self, query_filter: &'a SpatialQueryFilter, predicate: &'a dyn Fn(Entity) -> bool, @@ -73,6 +82,16 @@ impl SpatialQueryPipeline { } } + /// Creates a parry [`TypedCompositeShape`] for this pipeline, with a predicate. + /// Can be used to implement custom spatial queries + pub fn as_composite_shape_with_predicate<'a>( + &'a self, + query_filter: &'a SpatialQueryFilter, + predicate: &'a dyn Fn(Entity) -> bool, + ) -> impl TypedCompositeShape { + self.as_composite_shape_with_predicate_internal(query_filter, predicate) + } + /// Updates the associated acceleration structures with a new set of entities. pub fn update<'a>( &mut self, @@ -113,6 +132,16 @@ impl SpatialQueryPipeline { self.bvh = Bvh::from_iter(BvhBuildStrategy::Binned, aabbs); } + /// Get the entity corresponding to a given index in the pipeline + pub fn entity(&self, index: usize) -> Entity { + self.proxies[index].entity + } + + /// Get a dyn reference to the query dispatcher used in this pipeline + pub fn dispatcher_ref(&self) -> &dyn QueryDispatcher { + self.dispatcher.as_ref() + } + /// Casts a [ray](spatial_query#raycasting) and computes the closest [hit](RayHitData) with a collider. /// If there are no hits, `None` is returned. /// @@ -493,7 +522,7 @@ impl SpatialQueryPipeline { let shape_direction = direction.adjust_precision().into(); loop { - let composite = self.as_composite_shape(&query_filter); + let composite = self.as_composite_shape_internal(&query_filter); let pipeline_shape = CompositeShapeRef(&composite); let hit = pipeline_shape diff --git a/src/spatial_query/shape_caster.rs b/src/spatial_query/shape_caster.rs index 613881795..b56a601e1 100644 --- a/src/spatial_query/shape_caster.rs +++ b/src/spatial_query/shape_caster.rs @@ -370,7 +370,7 @@ impl ShapeCaster { let shape_direction = self.global_direction().adjust_precision().into(); while hits.len() < self.max_hits as usize { - let composite = query_pipeline.as_composite_shape(&query_filter); + let composite = query_pipeline.as_composite_shape_internal(&query_filter); let pipeline_shape = CompositeShapeRef(&composite); let hit = pipeline_shape