diff --git a/lib/common/src/bvh.rs b/lib/common/src/bvh.rs index 5e047a6..e82d44f 100644 --- a/lib/common/src/bvh.rs +++ b/lib/common/src/bvh.rs @@ -1,3 +1,5 @@ +use std::collections::BTreeMap; + use crate::{aabb::Aabb,integer::Planar64Vec3}; //da algaritum @@ -57,18 +59,29 @@ impl<L> BvhNode<L>{ }, } } - pub fn sample_ray<C:SampleRayContext>(&self,ray:&Ray,context:&mut C){ + fn populate_nodes<T>(&self,ray:&Ray,start_time:T,nodes:&mut BTreeMap<T,&BvhNode<L>>){ + // Am I an upcoming superstar? + if let Some(t)=self.aabb.intersect_ray(ray){ + if start_time<t{ + nodes.insert(t,self); + } + } match &self.content{ - RecursiveContent::Leaf(model)=>context.sample(model), - RecursiveContent::Branch(children)=>{ - if self.aabb.contains(ray.origin){ - for child in children{ - child.sample_ray(aabb,f); - } + RecursiveContent::Leaf(_)=>(), + RecursiveContent::Branch(children)=>for child in children{ + if child.aabb.contains(point){ + child.populate_nodes(point,f); + }else{ + // check if child will } }, } } + pub fn sample_ray<F:FnMut(&L)>(&self,ray:&Ray,f:&mut F){ + let mut nodes=BTreeMap::new(); + // perform a normal sample aabb at point ray.origin + self.populate_nodes(point,f); + } pub fn into_inner(self)->(RecursiveContent<BvhNode<L>,L>,Aabb){ (self.content,self.aabb) }