progress
This commit is contained in:
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>>){
|
||||
// Am I an upcoming superstar?
|
||||
if let Some(t)=self.aabb.intersect_ray(ray){
|
||||
if start_time<t{
|
||||
nodes.insert(t,self);
|
||||
}
|
||||
}
|
||||
fn populate_nodes<T:Ord>(&self,nodes:&mut BTreeMap<T,&BvhNode<L>>,ray:&Ray,start_time:T,f:&F)->Option<(T,&L)>{
|
||||
match &self.content{
|
||||
RecursiveContent::Leaf(_)=>(),
|
||||
RecursiveContent::Leaf(leaf)=>Some((f(leaf),leaf)),
|
||||
RecursiveContent::Branch(children)=>for child in children{
|
||||
if child.aabb.contains(point){
|
||||
child.populate_nodes(point,f);
|
||||
let mut collector=InstructionCollector::new(time_limit);
|
||||
if child.aabb.contains(ray.origin){
|
||||
collector.collect(child.populate_nodes(nodes,ray,start_time,f));
|
||||
}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();
|
||||
// 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){
|
||||
(self.content,self.aabb)
|
||||
|
Loading…
x
Reference in New Issue
Block a user