Crate bevy_spatial
source ·Expand description
A bevy plugin to track your entities in spatial indices and query them.
Quickstart using the kdtree
feature:
use bevy_spatial::{AutomaticUpdate, KDTree3, TransformMode, SpatialAccess};
#[derive(Component, Default)]
struct TrackedByKDTree;
fn main() {
App::new()
.add_plugin(AutomaticUpdate::<TrackedByKDTree>::new()
.with_frequency(Duration::from_secs_f32(0.3))
.with_transform(TransformMode::GlobalTransform))
.add_system(use_neighbour);
// ...
}
type NNTree = KDTree3<TrackedByKDTree>; // type alias for later
// spawn some entities with the TrackedByKDTree component
fn use_neighbour(tree: Res<NNTree>){
if let Some((pos, entity)) = tree.nearest_neighbour(Vec3::ZERO) {
// pos: Vec3
// do something with the nearest entity here
}
}
For more details see Examples
Modules§
- implementations to use
kd_tree
trees as a spatial datastructure inbevy_spatial
. - The different point Traits and Types used by
bevy_spatial
Structs§
- Plugin struct for setting up a spatial datastructure with automatic updating.
- Default set for spatial datastructure updates. Can be overridden using
AutomaticUpdate::with_set()
- Resource used for fixed timestep without repeats in the same frame (builtin timestep may run the system multiple times per frame).
Enums§
- Enum containing the different types of spatial datastructure compatible with
AutomaticUpdate
- Select which Transform to use when automatically updating the Spatial Datastructure.
Traits§
- Trait for accessing point-based spatial datastructures.
- automatically implemented trait for all components which can be used as markers for automatic updates?