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§

kdtree
implementations to use kd_tree trees as a spatial datastructure in bevy_spatial.
point
The different point Traits and Types used by bevy_spatial

Structs§

AutomaticUpdate
Plugin struct for setting up a spatial datastructure with automatic updating.
SpatialSet
Default set for spatial datastructure updates. Can be overridden using AutomaticUpdate::with_set()
TimestepLength
Resource used for fixed timestep without repeats in the same frame (builtin timestep may run the system multiple times per frame).

Enums§

SpatialStructure
Enum containing the different types of spatial datastructure compatible with AutomaticUpdate
TransformMode
Select which Transform to use when automatically updating the Spatial Datastructure.

Traits§

SpatialAccess
Trait for accessing point-based spatial datastructures.
TComp
automatically implemented trait for all components which can be used as markers for automatic updates?