Giter VIP home page Giter VIP logo

bevy-spatial's Introduction

bevy_spatial

A bevy plugin to track your entities in spatial indices and query them.

crates.io

NOTE: You will need to enable at least one of the features.

Currently implemented features:

Feature Description
kdtree KD-Tree for spatial lookups which is fully recreated. This is ideal for cases where most entities are moving.
rstar R*-Tree for spatial lookups which is updated or recreated based on a threshold of changed entities. Ideal when most entities are static.

Quickstart using the kdtree feature:

use bevy_spatial::{KDTreeAccess2D, KDTreePlugin2D, SpatialAccess};

#[derive(Component)]
struct TrackedByKDTree;

fn main() {
   App::new()
       .add_plugin(KDTreePlugin2D::<TrackedByKDTree> { ..default() })
       .add_system(use_neighbour);
   // ...
}

type NNTree = KDTreeAccess2D<TrackedByKDTree>; // type alias for brevity

fn use_neighbour(tree: Res<NNTree>){
    if let Some((pos, entity)) = tree.nearest_neighbour(Vec2::ZERO) {
        // pos: Vec3
        // do something with the nearest entity here, most likley you will want a `query.get(entity)` call
    }
}

For more details on usage see Examples

compatible bevy versions

bevy bevy_spatial
0.9 0.4.0
0.8 0.3.0
0.8 0.2.1
0.7 0.1

wasm caveats: the rayon acceleration for kdtree is disabled on wasm, making it a bit slower.

TODOs and Ideas

  • benchmarks

  • documentation

  • Versions of the SpatialAccess functions which return Iterators instead of Vecs

  • a feature for linfa_nn to use their abstractions over kdtree/balltree linear search

  • a feature for https://github.com/InstantDomain/instant-distance

bevy-spatial's People

Contributors

cbournhonesque avatar laundmo avatar pinkponk avatar sirhall avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.