This commit is contained in:
Quaternions 2025-02-06 12:11:24 -08:00
parent 5123573822
commit aceae11d42

@ -59,28 +59,31 @@ impl<L> BvhNode<L>{
}, },
} }
} }
fn populate_nodes<T>(&self,ray:&Ray,start_time:T,nodes:&mut BTreeMap<T,&BvhNode<L>>){ fn populate_nodes<T:Ord>(&self,nodes:&mut BTreeMap<T,&BvhNode<L>>,ray:&Ray,start_time:T,f:&F)->Option<(T,&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{ match &self.content{
RecursiveContent::Leaf(_)=>(), RecursiveContent::Leaf(leaf)=>Some((f(leaf),leaf)),
RecursiveContent::Branch(children)=>for child in children{ RecursiveContent::Branch(children)=>for child in children{
if child.aabb.contains(point){ let mut collector=InstructionCollector::new(time_limit);
child.populate_nodes(point,f); if child.aabb.contains(ray.origin){
collector.collect(child.populate_nodes(nodes,ray,start_time,f));
}else{ }else{
// check if child will // Am I an upcoming superstar?
if let Some(t)=child.aabb.intersect_ray(ray){
if start_time<t{
nodes.insert(t,child);
}
}
} }
collector.take()
}, },
} }
} }
pub fn sample_ray<F:FnMut(&L)>(&self,ray:&Ray,f:&mut F){ pub fn sample_ray<T:Ord,F:Fn(&L)->T>(&self,ray:&Ray,start_time:T,mut time_limit:Option<T>,f:&F)->Option<(T,&L)>{
let mut nodes=BTreeMap::new(); let mut nodes=BTreeMap::new();
// perform a normal sample aabb at point ray.origin // perform a normal sample aabb at point ray.origin
self.populate_nodes(point,f); self.populate_nodes(&mut nodes,ray,start_time);
// swim through nodes one at a time
} }
pub fn into_inner(self)->(RecursiveContent<BvhNode<L>,L>,Aabb){ pub fn into_inner(self)->(RecursiveContent<BvhNode<L>,L>,Aabb){
(self.content,self.aabb) (self.content,self.aabb)