pub struct MeshRayCast<'w, 's> { /* private fields */ }Expand description
Add this ray casting SystemParam to your system to cast rays into the world with an
immediate-mode API. Call cast_ray to immediately perform a ray cast and get a result.
Under the hood, this is a collection of regular bevy queries, resources, and local parameters that are added to your system.
§Usage
The following system casts a ray into the world with the ray positioned at the origin, pointing in the X-direction, and returns a list of intersections:
fn ray_cast_system(mut ray_cast: MeshRayCast) {
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
let hits = ray_cast.cast_ray(ray, &MeshRayCastSettings::default());
}§Configuration
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.
fn ray_cast_system(mut ray_cast: MeshRayCast, foo_query: Query<(), With<Foo>>) {
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
// Only ray cast against entities with the `Foo` component.
let filter = |entity| foo_query.contains(entity);
// Never early-exit. Note that you can change behavior per-entity.
let early_exit_test = |_entity| false;
// Ignore the visibility of entities. This allows ray casting hidden entities.
let visibility = RayCastVisibility::Any;
let settings = MeshRayCastSettings::default()
.with_filter(&filter)
.with_early_exit_test(&early_exit_test)
.with_visibility(visibility);
// Cast the ray with the settings, returning a list of intersections.
let hits = ray_cast.cast_ray(ray, &settings);
}Implementations§
Source§impl<'w, 's> MeshRayCast<'w, 's>
impl<'w, 's> MeshRayCast<'w, 's>
Sourcepub fn cast_ray(
&mut self,
ray: Ray3d,
settings: &MeshRayCastSettings<'_>,
) -> &[(Entity, RayMeshHit)]
pub fn cast_ray( &mut self, ray: Ray3d, settings: &MeshRayCastSettings<'_>, ) -> &[(Entity, RayMeshHit)]
Casts the ray into the world and returns a sorted list of intersections, nearest first.
Trait Implementations§
Source§impl SystemParam for MeshRayCast<'_, '_>
impl SystemParam for MeshRayCast<'_, '_>
Source§type Item<'w, 's> = MeshRayCast<'w, 's>
type Item<'w, 's> = MeshRayCast<'w, 's>
The item type returned when constructing this system param.
The value of this associated type should be
Self, instantiated with new lifetimes. Read moreSource§fn init_state(
world: &mut World,
system_meta: &mut SystemMeta,
) -> <MeshRayCast<'_, '_> as SystemParam>::State
fn init_state( world: &mut World, system_meta: &mut SystemMeta, ) -> <MeshRayCast<'_, '_> as SystemParam>::State
Registers any
World access used by this SystemParam
and creates a new instance of this param’s State.Source§unsafe fn new_archetype(
state: &mut <MeshRayCast<'_, '_> as SystemParam>::State,
archetype: &Archetype,
system_meta: &mut SystemMeta,
)
unsafe fn new_archetype( state: &mut <MeshRayCast<'_, '_> as SystemParam>::State, archetype: &Archetype, system_meta: &mut SystemMeta, )
For the specified
Archetype, registers the components accessed by this SystemParam (if applicable).a Read moreSource§fn apply(
state: &mut <MeshRayCast<'_, '_> as SystemParam>::State,
system_meta: &SystemMeta,
world: &mut World,
)
fn apply( state: &mut <MeshRayCast<'_, '_> as SystemParam>::State, system_meta: &SystemMeta, world: &mut World, )
Applies any deferred mutations stored in this
SystemParam’s state.
This is used to apply Commands during ApplyDeferred.Source§fn queue(
state: &mut <MeshRayCast<'_, '_> as SystemParam>::State,
system_meta: &SystemMeta,
world: DeferredWorld<'_>,
)
fn queue( state: &mut <MeshRayCast<'_, '_> as SystemParam>::State, system_meta: &SystemMeta, world: DeferredWorld<'_>, )
Queues any deferred mutations to be applied at the next
ApplyDeferred.Source§unsafe fn validate_param<'w, 's>(
state: &'s <MeshRayCast<'_, '_> as SystemParam>::State,
_system_meta: &SystemMeta,
_world: UnsafeWorldCell<'w>,
) -> Result<(), SystemParamValidationError>
unsafe fn validate_param<'w, 's>( state: &'s <MeshRayCast<'_, '_> as SystemParam>::State, _system_meta: &SystemMeta, _world: UnsafeWorldCell<'w>, ) -> Result<(), SystemParamValidationError>
Source§unsafe fn get_param<'w, 's>(
state: &'s mut <MeshRayCast<'_, '_> as SystemParam>::State,
system_meta: &SystemMeta,
world: UnsafeWorldCell<'w>,
change_tick: Tick,
) -> <MeshRayCast<'_, '_> as SystemParam>::Item<'w, 's>
unsafe fn get_param<'w, 's>( state: &'s mut <MeshRayCast<'_, '_> as SystemParam>::State, system_meta: &SystemMeta, world: UnsafeWorldCell<'w>, change_tick: Tick, ) -> <MeshRayCast<'_, '_> as SystemParam>::Item<'w, 's>
Creates a parameter to be passed into a
SystemParamFunction. Read moreimpl<'w, 's> ReadOnlySystemParam for MeshRayCast<'w, 's>where
Res<'w, Assets<Mesh>>: ReadOnlySystemParam,
Local<'s, Vec<(FloatOrd, (Entity, RayMeshHit))>>: ReadOnlySystemParam,
Local<'s, Vec<(Entity, RayMeshHit)>>: ReadOnlySystemParam,
Local<'s, Vec<(FloatOrd, Entity)>>: ReadOnlySystemParam,
Query<'w, 's, (&'static InheritedVisibility, &'static ViewVisibility, &'static Aabb, &'static GlobalTransform, Entity), Or<(With<Mesh3d>, With<Mesh2d>, With<SimplifiedMesh>)>>: ReadOnlySystemParam,
Query<'w, 's, (Option<&'static Mesh2d>, Option<&'static Mesh3d>, Option<&'static SimplifiedMesh>, Has<RayCastBackfaces>, &'static GlobalTransform), Or<(With<Mesh3d>, With<Mesh2d>, With<SimplifiedMesh>)>>: ReadOnlySystemParam,
Auto Trait Implementations§
impl<'w, 's> Freeze for MeshRayCast<'w, 's>
impl<'w, 's> !RefUnwindSafe for MeshRayCast<'w, 's>
impl<'w, 's> Send for MeshRayCast<'w, 's>
impl<'w, 's> Sync for MeshRayCast<'w, 's>
impl<'w, 's> Unpin for MeshRayCast<'w, 's>
impl<'w, 's> !UnwindSafe for MeshRayCast<'w, 's>
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
Return the
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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)
Converts
&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)
Converts
&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<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
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>
Converts
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>
Converts
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 more