From 1cc4d1e8ac547ea884b889f9ae2124afb41b0fcb Mon Sep 17 00:00:00 2001 From: Joona Aalto Date: Tue, 10 Dec 2024 05:27:42 +0200 Subject: [PATCH] Rename `RayCastSettings` to `MeshRayCastSettings` (#16703) # Objective The `RayCastSettings` type is only used in the context of ray casts with the `MeshRayCast` system parameter. The current name is somewhat inconsistent with other existing types, like `MeshRayCast` and `MeshPickingSettings`, but more importantly, it easily conflicts with physics, and forces those crates to opt for some other name like `RayCastConfig` or `RayCastOptions`. We should rename `RayCastSettings` to `MeshRayCastSettings` to avoid naming conflicts and improve consistency. ## Solution Rename `RayCastSettings` to `MeshRayCastSettings`. --- ## Migration Guide `RayCastSettings` has been renamed to `MeshRayCastSettings` to avoid naming conflicts with other ray casting backends and types. --- crates/bevy_picking/src/lib.rs | 2 +- crates/bevy_picking/src/mesh_picking/mod.rs | 4 ++-- .../src/mesh_picking/ray_cast/mod.rs | 18 +++++++++++------- examples/3d/mesh_ray_cast.rs | 5 ++++- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/crates/bevy_picking/src/lib.rs b/crates/bevy_picking/src/lib.rs index 3dd24c6a674f3..9a04220ba26cf 100644 --- a/crates/bevy_picking/src/lib.rs +++ b/crates/bevy_picking/src/lib.rs @@ -172,7 +172,7 @@ pub mod prelude { #[cfg(feature = "bevy_mesh_picking_backend")] #[doc(hidden)] pub use crate::mesh_picking::{ - ray_cast::{MeshRayCast, RayCastBackfaces, RayCastSettings, RayCastVisibility}, + ray_cast::{MeshRayCast, MeshRayCastSettings, RayCastBackfaces, RayCastVisibility}, MeshPickingPlugin, MeshPickingSettings, RayCastPickable, }; #[doc(hidden)] diff --git a/crates/bevy_picking/src/mesh_picking/mod.rs b/crates/bevy_picking/src/mesh_picking/mod.rs index 62060540be692..a848097a6854f 100644 --- a/crates/bevy_picking/src/mesh_picking/mod.rs +++ b/crates/bevy_picking/src/mesh_picking/mod.rs @@ -19,7 +19,7 @@ use bevy_app::prelude::*; use bevy_ecs::prelude::*; use bevy_reflect::prelude::*; use bevy_render::{prelude::*, view::RenderLayers}; -use ray_cast::{MeshRayCast, RayCastSettings, RayCastVisibility, SimplifiedMesh}; +use ray_cast::{MeshRayCast, MeshRayCastSettings, RayCastVisibility, SimplifiedMesh}; /// Runtime settings for the [`MeshPickingPlugin`]. #[derive(Resource, Reflect)] @@ -89,7 +89,7 @@ pub fn update_hits( let cam_layers = cam_layers.to_owned().unwrap_or_default(); - let settings = RayCastSettings { + let settings = MeshRayCastSettings { visibility: backend_settings.ray_cast_visibility, filter: &|entity| { let marker_requirement = diff --git a/crates/bevy_picking/src/mesh_picking/ray_cast/mod.rs b/crates/bevy_picking/src/mesh_picking/ray_cast/mod.rs index e6c405bbb3677..2ba76f79606f6 100644 --- a/crates/bevy_picking/src/mesh_picking/ray_cast/mod.rs +++ b/crates/bevy_picking/src/mesh_picking/ray_cast/mod.rs @@ -34,7 +34,7 @@ pub enum RayCastVisibility { /// Settings for a ray cast. #[derive(Clone)] -pub struct RayCastSettings<'a> { +pub struct MeshRayCastSettings<'a> { /// Determines how ray casting should consider [`Visibility`]. pub visibility: RayCastVisibility, /// A predicate that is applied for every entity that ray casts are performed against. @@ -45,7 +45,7 @@ pub struct RayCastSettings<'a> { pub early_exit_test: &'a dyn Fn(Entity) -> bool, } -impl<'a> RayCastSettings<'a> { +impl<'a> MeshRayCastSettings<'a> { /// Set the filter to apply to the ray cast. pub fn with_filter(mut self, filter: &'a impl Fn(Entity) -> bool) -> Self { self.filter = filter; @@ -75,7 +75,7 @@ impl<'a> RayCastSettings<'a> { } } -impl<'a> Default for RayCastSettings<'a> { +impl<'a> Default for MeshRayCastSettings<'a> { fn default() -> Self { Self { visibility: RayCastVisibility::VisibleInView, @@ -128,13 +128,13 @@ type MeshFilter = Or<(With, With, With)>; /// # use bevy_picking::prelude::*; /// fn ray_cast_system(mut ray_cast: MeshRayCast) { /// let ray = Ray3d::new(Vec3::ZERO, Dir3::X); -/// let hits = ray_cast.cast_ray(ray, &RayCastSettings::default()); +/// let hits = ray_cast.cast_ray(ray, &MeshRayCastSettings::default()); /// } /// ``` /// /// ## Configuration /// -/// You can specify the behavior of the ray cast using [`RayCastSettings`]. This allows you to filter out +/// You can specify the behavior of the ray cast using [`MeshRayCastSettings`]. This allows you to filter out /// entities, configure early-out behavior, and set whether the [`Visibility`] of an entity should be /// considered. /// @@ -156,7 +156,7 @@ type MeshFilter = Or<(With, With, With)>; /// // Ignore the visibility of entities. This allows ray casting hidden entities. /// let visibility = RayCastVisibility::Any; /// -/// let settings = RayCastSettings::default() +/// let settings = MeshRayCastSettings::default() /// .with_filter(&filter) /// .with_early_exit_test(&early_exit_test) /// .with_visibility(visibility); @@ -205,7 +205,11 @@ pub struct MeshRayCast<'w, 's> { impl<'w, 's> MeshRayCast<'w, 's> { /// Casts the `ray` into the world and returns a sorted list of intersections, nearest first. - pub fn cast_ray(&mut self, ray: Ray3d, settings: &RayCastSettings) -> &[(Entity, RayMeshHit)] { + pub fn cast_ray( + &mut self, + ray: Ray3d, + settings: &MeshRayCastSettings, + ) -> &[(Entity, RayMeshHit)] { let ray_cull = info_span!("ray culling"); let ray_cull_guard = ray_cull.enter(); diff --git a/examples/3d/mesh_ray_cast.rs b/examples/3d/mesh_ray_cast.rs index 3c691ccc164dc..85985f75a900a 100644 --- a/examples/3d/mesh_ray_cast.rs +++ b/examples/3d/mesh_ray_cast.rs @@ -51,7 +51,10 @@ fn bounce_ray(mut ray: Ray3d, ray_cast: &mut MeshRayCast, gizmos: &mut Gizmos, c for i in 0..MAX_BOUNCES { // Cast the ray and get the first hit - let Some((_, hit)) = ray_cast.cast_ray(ray, &RayCastSettings::default()).first() else { + let Some((_, hit)) = ray_cast + .cast_ray(ray, &MeshRayCastSettings::default()) + .first() + else { break; };