diff --git a/src/plugins/spatial_query/mod.rs b/src/plugins/spatial_query/mod.rs index 1ca5913b..a964760a 100644 --- a/src/plugins/spatial_query/mod.rs +++ b/src/plugins/spatial_query/mod.rs @@ -25,8 +25,8 @@ //! in the [`RayHits`] component every frame. It uses local coordinates, so it will automatically follow the entity //! it's attached to or its parent. //! 2. When you need more control or don't want to cast every frame, use the raycasting methods provided by -//! [`SpatialQuery`], like [`cast_ray`](SpatialQuery::cast_ray), [`ray_hits`](SpatialQuery::ray_hits) or -//! [`ray_hits_callback`](SpatialQuery::ray_hits_callback). +//! [`SpatialQuery`], like [`raycast`](SpatialQuery::raycast), [`raycast_many`](SpatialQuery::raycast_many) or +//! [`raycast_callback`](SpatialQuery::raycast_callback). //! //! See the documentation of the components and methods for more information. //! @@ -80,8 +80,8 @@ //! in the [`ShapeHits`] component every frame. It uses local coordinates, so it will automatically follow the entity //! it's attached to or its parent. //! 2. When you need more control or don't want to cast every frame, use the shapecasting methods provided by -//! [`SpatialQuery`], like [`cast_shape`](SpatialQuery::cast_shape), [`shape_hits`](SpatialQuery::shape_hits) or -//! [`shape_hits_callback`](SpatialQuery::shape_hits_callback). +//! [`SpatialQuery`], like [`shapecast`](SpatialQuery::shapecast), [`shapecast_many`](SpatialQuery::shapecast_many) or +//! [`shapecast_callback`](SpatialQuery::shapecast_callback). //! //! See the documentation of the components and methods for more information. //! diff --git a/src/plugins/spatial_query/pipeline.rs b/src/plugins/spatial_query/pipeline.rs index 36f39095..c2ea2fcf 100644 --- a/src/plugins/spatial_query/pipeline.rs +++ b/src/plugins/spatial_query/pipeline.rs @@ -145,8 +145,8 @@ impl SpatialQueryPipeline { /// Otherwise, the collider will be treated as hollow, and the hit point will be at the collider's boundary. /// - `query_filter`: A [`SpatialQueryFilter`] that determines which colliders are taken into account in the query. /// - /// See also: [`SpatialQuery::cast_ray`] - pub fn cast_ray( + /// See also: [`SpatialQuery::raycast`] + pub fn raycast( &self, origin: Vector, direction: Vector, @@ -187,8 +187,8 @@ impl SpatialQueryPipeline { /// Otherwise, the collider will be treated as hollow, and the hit point will be at the collider's boundary. /// - `query_filter`: A [`SpatialQueryFilter`] that determines which colliders are taken into account in the query. /// - /// See also: [`SpatialQuery::ray_hits`] - pub fn ray_hits( + /// See also: [`SpatialQuery::raycast_many`] + pub fn raycast_many( &self, origin: Vector, direction: Vector, @@ -198,7 +198,7 @@ impl SpatialQueryPipeline { query_filter: SpatialQueryFilter, ) -> Vec { let mut hits = Vec::with_capacity(10); - self.ray_hits_callback( + self.raycast_callback( origin, direction, max_time_of_impact, @@ -227,8 +227,8 @@ impl SpatialQueryPipeline { /// - `query_filter`: A [`SpatialQueryFilter`] that determines which colliders are taken into account in the query. /// - `callback`: A callback function called for each hit. /// - /// See also: [`SpatialQuery::ray_hits_callback`] - pub fn ray_hits_callback( + /// See also: [`SpatialQuery::raycast_callback`] + pub fn raycast_callback( &self, origin: Vector, direction: Vector, @@ -286,9 +286,9 @@ impl SpatialQueryPipeline { /// hit will be returned. /// - `query_filter`: A [`SpatialQueryFilter`] that determines which colliders are taken into account in the query. /// - /// See also: [`SpatialQuery::cast_shape`] + /// See also: [`SpatialQuery::shapecast`] #[allow(clippy::too_many_arguments)] - pub fn cast_shape( + pub fn shapecast( &self, shape: &Collider, origin: Vector, @@ -350,9 +350,9 @@ impl SpatialQueryPipeline { /// - `query_filter`: A [`SpatialQueryFilter`] that determines which colliders are taken into account in the query. /// - `callback`: A callback function called for each hit. /// - /// See also: [`SpatialQuery::shape_hits`] + /// See also: [`SpatialQuery::shapecast_many`] #[allow(clippy::too_many_arguments)] - pub fn shape_hits( + pub fn shapecast_many( &self, shape: &Collider, origin: Vector, @@ -364,7 +364,7 @@ impl SpatialQueryPipeline { query_filter: SpatialQueryFilter, ) -> Vec { let mut hits = Vec::with_capacity(10); - self.shape_hits_callback( + self.shapecast_callback( shape, origin, shape_rotation, @@ -397,9 +397,9 @@ impl SpatialQueryPipeline { /// - `query_filter`: A [`SpatialQueryFilter`] that determines which colliders are taken into account in the query. /// - `callback`: A callback function called for each hit. /// - /// See also: [`SpatialQuery::shape_hits_callback`] + /// See also: [`SpatialQuery::shapecast_callback`] #[allow(clippy::too_many_arguments)] - pub fn shape_hits_callback( + pub fn shapecast_callback( &self, shape: &Collider, origin: Vector, diff --git a/src/plugins/spatial_query/system_param.rs b/src/plugins/spatial_query/system_param.rs index cd7ac3c6..23debf35 100644 --- a/src/plugins/spatial_query/system_param.rs +++ b/src/plugins/spatial_query/system_param.rs @@ -5,10 +5,10 @@ use bevy::{ecs::system::SystemParam, prelude::*}; /// /// ## Methods /// -/// - [Raycasting](spatial_query#raycasting): [`cast_ray`](SpatialQuery::cast_ray), -/// [`ray_hits`](SpatialQuery::ray_hits), [`ray_hits_callback`](SpatialQuery::ray_hits_callback) -/// - [Shapecasting](spatial_query#shapecasting): [`cast_shape`](SpatialQuery::cast_shape), -/// [`shape_hits`](SpatialQuery::shape_hits), [`shape_hits_callback`](SpatialQuery::shape_hits_callback) +/// - [Raycasting](spatial_query#raycasting): [`raycast`](SpatialQuery::raycast), +/// [`raycast_many`](SpatialQuery::raycast_many), [`raycast_callback`](SpatialQuery::raycast_callback) +/// - [Shapecasting](spatial_query#shapecasting): [`shapecast`](SpatialQuery::shapecast), +/// [`shapecast_many`](SpatialQuery::shapecast_many), [`shapecast_callback`](SpatialQuery::shapecast_callback) /// - [Point projection](spatial_query#point-projection): [`project_point`](SpatialQuery::project_point) /// - [Intersection tests](spatial_query#intersection-tests) /// - Point intersections: [`point_intersections`](SpatialQuery::point_intersections), @@ -33,7 +33,7 @@ use bevy::{ecs::system::SystemParam, prelude::*}; /// # #[cfg(all(feature = "3d", feature = "f32"))] /// fn print_hits(spatial_query: SpatialQuery) { /// // Cast ray and print first hit -/// if let Some(first_hit) = spatial_query.cast_ray( +/// if let Some(first_hit) = spatial_query.raycast( /// Vec3::ZERO, // Origin /// Vec3::X, // Direction /// 100.0, // Maximum time of impact (travel distance) @@ -44,7 +44,7 @@ use bevy::{ecs::system::SystemParam, prelude::*}; /// } /// /// // Cast ray and get up to 20 hits -/// let hits = spatial_query.ray_hits( +/// let hits = spatial_query.raycast_many( /// Vec3::ZERO, // Origin /// Vec3::X, // Direction /// 100.0, // Maximum time of impact (travel distance) @@ -110,7 +110,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// # #[cfg(all(feature = "3d", feature = "f32"))] /// fn print_hits(spatial_query: SpatialQuery) { /// // Cast ray and print first hit - /// if let Some(first_hit) = spatial_query.cast_ray( + /// if let Some(first_hit) = spatial_query.raycast( /// Vec3::ZERO, // Origin /// Vec3::X, // Direction /// 100.0, // Maximum time of impact (travel distance) @@ -121,7 +121,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// } /// } /// ``` - pub fn cast_ray( + pub fn raycast( &self, origin: Vector, direction: Vector, @@ -130,7 +130,20 @@ impl<'w, 's> SpatialQuery<'w, 's> { query_filter: SpatialQueryFilter, ) -> Option { self.query_pipeline - .cast_ray(origin, direction, max_time_of_impact, solid, query_filter) + .raycast(origin, direction, max_time_of_impact, solid, query_filter) + } + + /// Deprecated, use [`SpatialQuery::raycast()`] instead. + #[deprecated(since = "0.4.0", note = "renamed, please use `raycast` instead")] + pub fn cast_ray( + &self, + origin: Vector, + direction: Vector, + max_time_of_impact: Scalar, + solid: bool, + query_filter: SpatialQueryFilter, + ) -> Option { + self.raycast(origin, direction, max_time_of_impact, solid, query_filter) } /// Casts a [ray](spatial_query#raycasting) and computes all [hits](RayHitData) until `max_hits` is reached. @@ -160,7 +173,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// # #[cfg(all(feature = "3d", feature = "f32"))] /// fn print_hits(spatial_query: SpatialQuery) { /// // Cast ray and get hits - /// let hits = spatial_query.ray_hits( + /// let hits = spatial_query.raycast_many( /// Vec3::ZERO, // Origin /// Vec3::X, // Direction /// 100.0, // Maximum time of impact (travel distance) @@ -175,6 +188,27 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// } /// } /// ``` + pub fn raycast_many( + &self, + origin: Vector, + direction: Vector, + max_time_of_impact: Scalar, + max_hits: u32, + solid: bool, + query_filter: SpatialQueryFilter, + ) -> Vec { + self.query_pipeline.raycast_many( + origin, + direction, + max_time_of_impact, + max_hits, + solid, + query_filter, + ) + } + + /// Deprecated, use [`SpatialQuery::raycast_many()`] instead. + #[deprecated(since = "0.4.0", note = "renamed, please use `raycast_many` instead")] pub fn ray_hits( &self, origin: Vector, @@ -184,7 +218,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { solid: bool, query_filter: SpatialQueryFilter, ) -> Vec { - self.query_pipeline.ray_hits( + self.raycast_many( origin, direction, max_time_of_impact, @@ -223,7 +257,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// let mut hits = vec![]; /// /// // Cast ray and get all hits - /// spatial_query.ray_hits_callback( + /// spatial_query.raycast_callback( /// Vec3::ZERO, // Origin /// Vec3::X, // Direction /// 100.0, // Maximum time of impact (travel distance) @@ -241,6 +275,30 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// } /// } /// ``` + pub fn raycast_callback( + &self, + origin: Vector, + direction: Vector, + max_time_of_impact: Scalar, + solid: bool, + query_filter: SpatialQueryFilter, + callback: impl FnMut(RayHitData) -> bool, + ) { + self.query_pipeline.raycast_callback( + origin, + direction, + max_time_of_impact, + solid, + query_filter, + callback, + ) + } + + /// Deprecated, use [`SpatialQuery::raycast_many()`] instead. + #[deprecated( + since = "0.4.0", + note = "renamed, please use `raycast_callback` instead" + )] pub fn ray_hits_callback( &self, origin: Vector, @@ -250,7 +308,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { query_filter: SpatialQueryFilter, callback: impl FnMut(RayHitData) -> bool, ) { - self.query_pipeline.ray_hits_callback( + self.raycast_callback( origin, direction, max_time_of_impact, @@ -289,7 +347,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// # #[cfg(all(feature = "3d", feature = "f32"))] /// fn print_hits(spatial_query: SpatialQuery) { /// // Cast ray and print first hit - /// if let Some(first_hit) = spatial_query.cast_shape( + /// if let Some(first_hit) = spatial_query.shapecast( /// &Collider::ball(0.5), // Shape /// Vec3::ZERO, // Origin /// Quat::default(), // Shape rotation @@ -303,6 +361,30 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// } /// ``` #[allow(clippy::too_many_arguments)] + pub fn shapecast( + &self, + shape: &Collider, + origin: Vector, + shape_rotation: RotationValue, + direction: Vector, + max_time_of_impact: Scalar, + ignore_origin_penetration: bool, + query_filter: SpatialQueryFilter, + ) -> Option { + self.query_pipeline.shapecast( + shape, + origin, + shape_rotation, + direction, + max_time_of_impact, + ignore_origin_penetration, + query_filter, + ) + } + + /// Deprecated, use [`SpatialQuery::shapecast()`] instead. + #[deprecated(since = "0.4.0", note = "renamed, please use `shapecast` instead")] + #[allow(clippy::too_many_arguments)] pub fn cast_shape( &self, shape: &Collider, @@ -313,7 +395,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { ignore_origin_penetration: bool, query_filter: SpatialQueryFilter, ) -> Option { - self.query_pipeline.cast_shape( + self.query_pipeline.shapecast( shape, origin, shape_rotation, @@ -353,7 +435,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// # #[cfg(all(feature = "3d", feature = "f32"))] /// fn print_hits(spatial_query: SpatialQuery) { /// // Cast shape and get all hits - /// let hits = spatial_query.shape_hits( + /// let hits = spatial_query.shapecast_many( /// &Collider::ball(0.5), // Shape /// Vec3::ZERO, // Origin /// Quat::default(), // Shape rotation @@ -371,6 +453,32 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// } /// ``` #[allow(clippy::too_many_arguments)] + pub fn shapecast_many( + &self, + shape: &Collider, + origin: Vector, + shape_rotation: RotationValue, + direction: Vector, + max_time_of_impact: Scalar, + max_hits: u32, + ignore_origin_penetration: bool, + query_filter: SpatialQueryFilter, + ) -> Vec { + self.query_pipeline.shapecast_many( + shape, + origin, + shape_rotation, + direction, + max_time_of_impact, + max_hits, + ignore_origin_penetration, + query_filter, + ) + } + + /// Deprecated, use [`SpatialQuery::shapecast_many()`] instead. + #[deprecated(since = "0.4.0", note = "renamed, please use `shapecast_many` instead")] + #[allow(clippy::too_many_arguments)] pub fn shape_hits( &self, shape: &Collider, @@ -382,7 +490,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { ignore_origin_penetration: bool, query_filter: SpatialQueryFilter, ) -> Vec { - self.query_pipeline.shape_hits( + self.query_pipeline.shapecast_many( shape, origin, shape_rotation, @@ -425,7 +533,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// let mut hits = vec![]; /// /// // Cast shape and get all hits - /// spatial_query.shape_hits_callback( + /// spatial_query.shapecast_callback( /// &Collider::ball(0.5), // Shape /// Vec3::ZERO, // Origin /// Quat::default(), // Shape rotation @@ -446,6 +554,35 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// } /// ``` #[allow(clippy::too_many_arguments)] + pub fn shapecast_callback( + &self, + shape: &Collider, + origin: Vector, + shape_rotation: RotationValue, + direction: Vector, + max_time_of_impact: Scalar, + ignore_origin_penetration: bool, + query_filter: SpatialQueryFilter, + callback: impl FnMut(ShapeHitData) -> bool, + ) { + self.query_pipeline.shapecast_callback( + shape, + origin, + shape_rotation, + direction, + max_time_of_impact, + ignore_origin_penetration, + query_filter, + callback, + ) + } + + /// Deprecated, use [`SpatialQuery::shapecast_callback()`] instead. + #[deprecated( + since = "0.4.0", + note = "renamed, please use `shapecast_callback` instead" + )] + #[allow(clippy::too_many_arguments)] pub fn shape_hits_callback( &self, shape: &Collider, @@ -457,7 +594,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { query_filter: SpatialQueryFilter, callback: impl FnMut(ShapeHitData) -> bool, ) { - self.query_pipeline.shape_hits_callback( + self.query_pipeline.shapecast_callback( shape, origin, shape_rotation,