Crate bevy_mod_spatial_query

Source
Expand description

Spatially aware Queries for the Bevy game engine

fn change_color_on_hover(
     mouse: Single<&Mouse>,
     mut circles: SpatialQuery<&mut Circle>,
 ) {
    for mut circle in circles.in_radius(mouse.position, 10.) {
        // Do something with the circle..
    }
}

This crate aims to provide an ergonomic and fast way of performing spatial queries, i.e. “nearby entities” -type queries. “Spatial” here refers purely to the GlobalPosition of an entity, and does not consider things like meshes or collision shapes.

By default, this crate uses a naive lookup algorithm as it outperforms more advanced algorithms for simple (less than 1 000 000 entities) scenes with few (less than 100) queries. A BVH-based algorithm is also provided, but it is only useful for scenes with many (100 000 000+) entities or very many queries (10 000+). Users can implement their own lookup algorithms by implementing the SpatialLookupAlgorithm trait, and inserting the SpatialLookupState resource like so:

app.insert_resource(SpatialLookupState::with_algorithm(YourAwesomeAlgorithm));

Modules§

algorithms
Spatial lookup algorithms
prelude

Structs§

PrepareSpatialLookup
System set for systems used to set up the spatial lookup.
SpatialLookupState
Resource which holds the configured SpatialLookupAlgorithm and relevant state.
SpatialQueriesPlugin
Adds SpatialQuery support to bevy.

Traits§

SpatialLookupAlgorithm
Trait for defining Spatial Lookup Algorithms to be used with SpatialQuery<_>.

Functions§

draw_spatial_lookup_gizmos
prepare_spatial_lookup
Prepares the configured spatial lookup algorithm.