2 unstable releases

0.1.0 Mar 6, 2024
0.0.1 Nov 16, 2023

#412 in Game dev

Download history 22/week @ 2024-02-19 18/week @ 2024-02-26 125/week @ 2024-03-04 72/week @ 2024-03-11 29/week @ 2024-04-01

106 downloads per month

MIT/Apache

23KB
507 lines

ploc-bhv

A Bounding Volume Hierarchy based on PLOC. Inspired by a series of articles by Arsène Pérard-Gayot

Getting started

Creating and traversing the BVH is all done using Iterators.

In this example we create AABBs for a few boxes, and use their index as the key:

use ploc_bvh::prelude::*;
use bevy_math::Vec3;

...

let boxes: Vec<(Vec3, Vec3)> = generate_boxes();
let bvh = Bvh3d::new(
    boxes.len(),
    boxes.iter().enumerate().map(|(i, aabb)| (i as u32, *aabb)),
);

Next we can simply iterate over the BVH using one of the provided methods:

let mut stack = bvh.create_stack();

let origin = Vec3::ZERO;
let direction = Vec3::Y;
let max_time_of_impact = 1.;
for index in bvh.cast_ray(&mut stack, origin, direction, max_time_of_impact) {
    println!("We hit box {}: {:?}", index, boxes[index]);
}

It's recommended to reuse the stack where possible to avoid unnecessary allocations.

Future work

  • Actually support the parallelization

Licensing

All code in this repository is dual-licensed under either:

at your option.

Dependencies

~3MB
~93K SLoC