pub struct SpatialQueryPipeline { /* private fields */ }Expand description
A resource for the spatial query pipeline.
The pipeline maintains a quaternary bounding volume hierarchy Bvh of the world’s colliders
as an acceleration structure for spatial queries.
Implementations§
Source§impl SpatialQueryPipeline
impl SpatialQueryPipeline
Sourcepub fn new() -> SpatialQueryPipeline
pub fn new() -> SpatialQueryPipeline
Creates a new SpatialQueryPipeline.
Sourcepub fn as_composite_shape<'a>(
&'a self,
query_filter: &'a SpatialQueryFilter,
) -> impl TypedCompositeShape
pub fn as_composite_shape<'a>( &'a self, query_filter: &'a SpatialQueryFilter, ) -> impl TypedCompositeShape
Creates a parry TypedCompositeShape for this pipeline.
Can be used to implement custom spatial queries
Sourcepub fn as_composite_shape_with_predicate<'a>(
&'a self,
query_filter: &'a SpatialQueryFilter,
predicate: &'a dyn Fn(Entity) -> bool,
) -> impl TypedCompositeShape
pub fn as_composite_shape_with_predicate<'a>( &'a self, query_filter: &'a SpatialQueryFilter, predicate: &'a dyn Fn(Entity) -> bool, ) -> impl TypedCompositeShape
Creates a parry TypedCompositeShape for this pipeline, with a predicate.
Can be used to implement custom spatial queries
Sourcepub fn update<'a>(
&mut self,
colliders: impl Iterator<Item = (Entity, &'a Position, &'a Rotation, &'a Collider, &'a CollisionLayers)>,
)
pub fn update<'a>( &mut self, colliders: impl Iterator<Item = (Entity, &'a Position, &'a Rotation, &'a Collider, &'a CollisionLayers)>, )
Updates the associated acceleration structures with a new set of entities.
Sourcepub fn entity(&self, index: usize) -> Entity
pub fn entity(&self, index: usize) -> Entity
Get the entity corresponding to a given index in the pipeline
Sourcepub fn dispatcher_ref(&self) -> &dyn QueryDispatcher
pub fn dispatcher_ref(&self) -> &dyn QueryDispatcher
Get a dyn reference to the query dispatcher used in this pipeline
Sourcepub fn cast_ray(
&self,
origin: Vector,
direction: Dir2,
max_distance: Scalar,
solid: bool,
filter: &SpatialQueryFilter,
) -> Option<RayHitData>
pub fn cast_ray( &self, origin: Vector, direction: Dir2, max_distance: Scalar, solid: bool, filter: &SpatialQueryFilter, ) -> Option<RayHitData>
Casts a ray and computes the closest hit with a collider.
If there are no hits, None is returned.
§Arguments
origin: Where the ray is cast from.direction: What direction the ray is cast in.max_distance: The maximum distance the ray can travel.solid: If true and the ray origin is inside of a collider, the hit point will be the ray origin itself. Otherwise, the collider will be treated as hollow, and the hit point will be at its boundary.filter: ASpatialQueryFilterthat determines which colliders are taken into account in the query.
§Related Methods
Sourcepub fn cast_ray_predicate(
&self,
origin: Vector,
direction: Dir2,
max_distance: Scalar,
solid: bool,
filter: &SpatialQueryFilter,
predicate: &dyn Fn(Entity) -> bool,
) -> Option<RayHitData>
pub fn cast_ray_predicate( &self, origin: Vector, direction: Dir2, max_distance: Scalar, solid: bool, filter: &SpatialQueryFilter, predicate: &dyn Fn(Entity) -> bool, ) -> Option<RayHitData>
Casts a ray and computes the closest hit with a collider.
If there are no hits, None is returned.
§Arguments
origin: Where the ray is cast from.direction: What direction the ray is cast in.max_distance: The maximum distance the ray can travel.solid: If true and the ray origin is inside of a collider, the hit point will be the ray origin itself. Otherwise, the collider will be treated as hollow, and the hit point will be at its boundary.predicate: A function called on each entity hit by the ray. The ray keeps travelling until the predicate returnstrue.filter: ASpatialQueryFilterthat determines which colliders are taken into account in the query.
§Related Methods
Sourcepub fn ray_hits(
&self,
origin: Vector,
direction: Dir2,
max_distance: Scalar,
max_hits: u32,
solid: bool,
filter: &SpatialQueryFilter,
) -> Vec<RayHitData>
pub fn ray_hits( &self, origin: Vector, direction: Dir2, max_distance: Scalar, max_hits: u32, solid: bool, filter: &SpatialQueryFilter, ) -> Vec<RayHitData>
Casts a ray and computes all hits until max_hits is reached.
Note that the order of the results is not guaranteed, and if there are more hits than max_hits,
some hits will be missed.
§Arguments
origin: Where the ray is cast from.direction: What direction the ray is cast in.max_distance: The maximum distance the ray can travel.max_hits: The maximum number of hits. Additional hits will be missed.solid: If true and the ray origin is inside of a collider, the hit point will be the ray origin itself. Otherwise, the collider will be treated as hollow, and the hit point will be at its boundary.filter: ASpatialQueryFilterthat determines which colliders are taken into account in the query.
§Related Methods
Sourcepub fn ray_hits_callback(
&self,
origin: Vector,
direction: Dir2,
max_distance: Scalar,
solid: bool,
filter: &SpatialQueryFilter,
callback: impl FnMut(RayHitData) -> bool,
)
pub fn ray_hits_callback( &self, origin: Vector, direction: Dir2, max_distance: Scalar, solid: bool, filter: &SpatialQueryFilter, callback: impl FnMut(RayHitData) -> bool, )
Casts a ray and computes all hits, calling the given callback
for each hit. The raycast stops when callback returns false or all hits have been found.
Note that the order of the results is not guaranteed.
§Arguments
origin: Where the ray is cast from.direction: What direction the ray is cast in.max_distance: The maximum distance the ray can travel.solid: If true and the ray origin is inside of a collider, the hit point will be the ray origin itself. Otherwise, the collider will be treated as hollow, and the hit point will be at its boundary.filter: ASpatialQueryFilterthat determines which colliders are taken into account in the query.callback: A callback function called for each hit.
§Related Methods
Sourcepub fn cast_shape(
&self,
shape: &Collider,
origin: Vector,
shape_rotation: Scalar,
direction: Dir2,
config: &ShapeCastConfig,
filter: &SpatialQueryFilter,
) -> Option<ShapeHitData>
pub fn cast_shape( &self, shape: &Collider, origin: Vector, shape_rotation: Scalar, direction: Dir2, config: &ShapeCastConfig, filter: &SpatialQueryFilter, ) -> Option<ShapeHitData>
Casts a shape with a given rotation and computes the closest hit
with a collider. If there are no hits, None is returned.
For a more ECS-based approach, consider using the ShapeCaster component instead.
§Arguments
shape: The shape being cast represented as aCollider.origin: Where the shape is cast from.shape_rotation: The rotation of the shape being cast.direction: What direction the shape is cast in.config: AShapeCastConfigthat determines the behavior of the cast.filter: ASpatialQueryFilterthat determines which colliders are taken into account in the query.
§Related Methods
Sourcepub fn cast_shape_predicate(
&self,
shape: &Collider,
origin: Vector,
shape_rotation: Scalar,
direction: Dir2,
config: &ShapeCastConfig,
filter: &SpatialQueryFilter,
predicate: &dyn Fn(Entity) -> bool,
) -> Option<ShapeHitData>
pub fn cast_shape_predicate( &self, shape: &Collider, origin: Vector, shape_rotation: Scalar, direction: Dir2, config: &ShapeCastConfig, filter: &SpatialQueryFilter, predicate: &dyn Fn(Entity) -> bool, ) -> Option<ShapeHitData>
Casts a shape with a given rotation and computes the closest hit
with a collider. If there are no hits, None is returned.
For a more ECS-based approach, consider using the ShapeCaster component instead.
§Arguments
shape: The shape being cast represented as aCollider.origin: Where the shape is cast from.shape_rotation: The rotation of the shape being cast.direction: What direction the shape is cast in.config: AShapeCastConfigthat determines the behavior of the cast.filter: ASpatialQueryFilterthat determines which colliders are taken into account in the query.predicate: A function called on each entity hit by the shape. The shape keeps travelling until the predicate returnstrue.
§Related Methods
Sourcepub fn shape_hits(
&self,
shape: &Collider,
origin: Vector,
shape_rotation: Scalar,
direction: Dir2,
max_hits: u32,
config: &ShapeCastConfig,
filter: &SpatialQueryFilter,
) -> Vec<ShapeHitData>
pub fn shape_hits( &self, shape: &Collider, origin: Vector, shape_rotation: Scalar, direction: Dir2, max_hits: u32, config: &ShapeCastConfig, filter: &SpatialQueryFilter, ) -> Vec<ShapeHitData>
Casts a shape with a given rotation and computes computes all hits
in the order of distance until max_hits is reached.
§Arguments
shape: The shape being cast represented as aCollider.origin: Where the shape is cast from.shape_rotation: The rotation of the shape being cast.direction: What direction the shape is cast in.max_hits: The maximum number of hits. Additional hits will be missed.config: AShapeCastConfigthat determines the behavior of the cast.filter: ASpatialQueryFilterthat determines which colliders are taken into account in the query.
§Related Methods
Sourcepub fn shape_hits_callback(
&self,
shape: &Collider,
origin: Vector,
shape_rotation: Scalar,
direction: Dir2,
config: &ShapeCastConfig,
filter: &SpatialQueryFilter,
callback: impl FnMut(ShapeHitData) -> bool,
)
pub fn shape_hits_callback( &self, shape: &Collider, origin: Vector, shape_rotation: Scalar, direction: Dir2, config: &ShapeCastConfig, filter: &SpatialQueryFilter, callback: impl FnMut(ShapeHitData) -> bool, )
Casts a shape with a given rotation and computes computes all hits
in the order of distance, calling the given callback for each hit. The shapecast stops when
callback returns false or all hits have been found.
§Arguments
shape: The shape being cast represented as aCollider.origin: Where the shape is cast from.shape_rotation: The rotation of the shape being cast.direction: What direction the shape is cast in.config: AShapeCastConfigthat determines the behavior of the cast.filter: ASpatialQueryFilterthat determines which colliders are taken into account in the query.callback: A callback function called for each hit.
§Related Methods
Sourcepub fn project_point(
&self,
point: Vector,
solid: bool,
filter: &SpatialQueryFilter,
) -> Option<PointProjection>
pub fn project_point( &self, point: Vector, solid: bool, filter: &SpatialQueryFilter, ) -> Option<PointProjection>
Finds the projection of a given point on the closest collider.
If one isn’t found, None is returned.
§Arguments
point: The point that should be projected.solid: If true and the point is inside of a collider, the projection will be at the point. Otherwise, the collider will be treated as hollow, and the projection will be at the collider’s boundary.filter: ASpatialQueryFilterthat determines which colliders are taken into account in the query.
§Related Methods
Sourcepub fn project_point_predicate(
&self,
point: Vector,
solid: bool,
filter: &SpatialQueryFilter,
predicate: &dyn Fn(Entity) -> bool,
) -> Option<PointProjection>
pub fn project_point_predicate( &self, point: Vector, solid: bool, filter: &SpatialQueryFilter, predicate: &dyn Fn(Entity) -> bool, ) -> Option<PointProjection>
Finds the projection of a given point on the closest collider.
If one isn’t found, None is returned.
§Arguments
point: The point that should be projected.solid: If true and the point is inside of a collider, the projection will be at the point. Otherwise, the collider will be treated as hollow, and the projection will be at the collider’s boundary.filter: ASpatialQueryFilterthat determines which colliders are taken into account in the query.predicate: A function for filtering which entities are considered in the query. The projection will be on the closest collider for which thepredicatereturnstrue
§Related Methods
Sourcepub fn point_intersections(
&self,
point: Vector,
filter: &SpatialQueryFilter,
) -> Vec<Entity>
pub fn point_intersections( &self, point: Vector, filter: &SpatialQueryFilter, ) -> Vec<Entity>
An intersection test that finds all entities with a collider that contains the given point.
§Arguments
point: The point that intersections are tested against.filter: ASpatialQueryFilterthat determines which colliders are taken into account in the query.
§Related Methods
Sourcepub fn point_intersections_callback(
&self,
point: Vector,
filter: &SpatialQueryFilter,
callback: impl FnMut(Entity) -> bool,
)
pub fn point_intersections_callback( &self, point: Vector, filter: &SpatialQueryFilter, callback: impl FnMut(Entity) -> bool, )
An intersection test that finds all entities with a collider
that contains the given point, calling the given callback for each intersection.
The search stops when callback returns false or all intersections have been found.
§Arguments
point: The point that intersections are tested against.filter: ASpatialQueryFilterthat determines which colliders are taken into account in the query.callback: A callback function called for each intersection.
§Related Methods
Sourcepub fn aabb_intersections_with_aabb(&self, aabb: ColliderAabb) -> Vec<Entity>
pub fn aabb_intersections_with_aabb(&self, aabb: ColliderAabb) -> Vec<Entity>
An intersection test that finds all entities with a ColliderAabb
that is intersecting the given aabb.
§Related Methods
Sourcepub fn aabb_intersections_with_aabb_callback(
&self,
aabb: ColliderAabb,
callback: impl FnMut(Entity) -> bool,
)
pub fn aabb_intersections_with_aabb_callback( &self, aabb: ColliderAabb, callback: impl FnMut(Entity) -> bool, )
An intersection test that finds all entities with a ColliderAabb
that is intersecting the given aabb, calling callback for each intersection.
The search stops when callback returns false or all intersections have been found.
§Related Methods
Sourcepub fn shape_intersections(
&self,
shape: &Collider,
shape_position: Vector,
shape_rotation: Scalar,
filter: &SpatialQueryFilter,
) -> Vec<Entity>
pub fn shape_intersections( &self, shape: &Collider, shape_position: Vector, shape_rotation: Scalar, filter: &SpatialQueryFilter, ) -> Vec<Entity>
An intersection test that finds all entities with a Collider
that is intersecting the given shape with a given position and rotation.
§Arguments
shape: The shape that intersections are tested against represented as aCollider.shape_position: The position of the shape.shape_rotation: The rotation of the shape.filter: ASpatialQueryFilterthat determines which colliders are taken into account in the query.
§Related Methods
Sourcepub fn shape_intersections_callback(
&self,
shape: &Collider,
shape_position: Vector,
shape_rotation: Scalar,
filter: &SpatialQueryFilter,
callback: impl FnMut(Entity) -> bool,
)
pub fn shape_intersections_callback( &self, shape: &Collider, shape_position: Vector, shape_rotation: Scalar, filter: &SpatialQueryFilter, callback: impl FnMut(Entity) -> bool, )
An intersection test that finds all entities with a Collider
that is intersecting the given shape with a given position and rotation, calling callback for each
intersection. The search stops when callback returns false or all intersections have been found.
§Arguments
shape: The shape that intersections are tested against represented as aCollider.shape_position: The position of the shape.shape_rotation: The rotation of the shape.filter: ASpatialQueryFilterthat determines which colliders are taken into account in the query.callback: A callback function called for each intersection.
§Related Methods
Trait Implementations§
Source§impl Clone for SpatialQueryPipeline
impl Clone for SpatialQueryPipeline
Source§fn clone(&self) -> SpatialQueryPipeline
fn clone(&self) -> SpatialQueryPipeline
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Default for SpatialQueryPipeline
impl Default for SpatialQueryPipeline
impl Resource for SpatialQueryPipeline
Auto Trait Implementations§
impl Freeze for SpatialQueryPipeline
impl !RefUnwindSafe for SpatialQueryPipeline
impl Send for SpatialQueryPipeline
impl Sync for SpatialQueryPipeline
impl Unpin for SpatialQueryPipeline
impl !UnwindSafe for SpatialQueryPipeline
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T ShaderType for self. When used in AsBindGroup
derives, it is safe to assume that all images in self exist.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
Source§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.