Skip to content

DavidPeicho/tinybvh-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

trinybvh-rs

Rust wrapper for tinybvh.

Features

Provides BVH (Bounding Volume Hierarchy) construction and intersection:

  • Construction: [BVH], [BVH4], [CWBVH]
  • Intersection

For more information about each layout: tinybvh.

Examples

BVH Wald

use tinybvh_rs::{BVH, Intersector, Ray};

let primitives = vec![
    [-2.0, 1.0, -1.0, 0.0],    //
    [-1.0, 1.0, -1.0, 0.0],    // Left triangle
    [-2.0, 0.0, -1.0, 0.0],    //

    [2.0, 1.0, -1.0, 0.0],     //
    [2.0, 0.0, -1.0, 0.0],     // Right triangle
    [1.0, 0.0, -1.0, 0.0],     //
];

let bvh = BVH::new(&primitives);

// No intersection, ray pass between the primitives
let mut ray = Ray::new([0.0, 0.0, 0.0], [0.0, 0.0, -1.0]);
bvh.intersect(&mut ray);
println!("Hit distance: {}", ray.hit.t); // 1e30

// Intersects left primitive
let mut ray = Ray::new([-1.5, 0.5, 0.0], [0.0, 0.0, -1.0]);
bvh.intersect(&mut ray);
println!("Hit distance & primtive: {} / {}", ray.hit.t, ray.hit.prim); // 1.0 / 0

// Intersects right primitive
let mut ray = Ray::new([1.5, 0.45, 0.0], [0.0, 0.0, -1.0]);
bvh.intersect(&mut ray);
println!("Hit distance & primtive: {} / {}", ray.hit.t, ray.hit.prim); // 1.0 / 1

TODO

  • build() should return Result
    • Check for node coutn in CWBVH
    • Check for primitives % 3

About

Rust wrapper for the tinybvh libary

Resources

License

Stars

Watchers

Forks

Packages

No packages published