Expand description
This module provides a simple interface for implementing a picking backend.
Don’t be dissuaded by terminology like “backend”; the idea is dead simple. bevy_picking
will tell you where pointers are, all you have to do is send an event if the pointers are
hitting something. That’s it. The rest of this documentation explains the requirements in more
detail.
Because bevy_picking
is very loosely coupled with its backends, you can mix and match as
many backends as you want. For example, You could use the rapier
backend to raycast against
physics objects, a picking shader backend to pick non-physics meshes, and the bevy_ui
backend
for your UI. The PointerHits
s produced by these various backends will be combined, sorted,
and used as a homogeneous input for the picking systems that consume these events.
§Implementation
-
A picking backend only has one job: read
PointerLocation
components and producePointerHits
events. In plain English, a backend is provided the location of pointers, and is asked to provide a list of entities under those pointers. -
The
PointerHits
events produced by a backend do not need to be sorted or filtered, all that is needed is an unordered list of entities and theirHitData
. -
Backends do not need to consider the
PickingBehavior
component, though they may use it for optimization purposes. For example, a backend that traverses a spatial hierarchy may want to early exit if it intersects an entity that blocks lower entities from being picked.
§Raycasting Backends
Backends that require a ray to cast into the scene should use ray::RayMap
. This
automatically constructs rays in world space for all cameras and pointers, handling details like
viewports and DPI for you.
Modules§
- prelude
- The picking backend prelude.
- ray
- Types and systems for constructing rays from cameras and pointers.
Structs§
- HitData
- Holds data from a successful pointer hit test. See
HitData::depth
for important details. - Pointer
Hits - An event produced by a picking backend after it has run its hit tests, describing the entities under a pointer.