bvh reduce badness

This commit is contained in:
Quaternions 2024-02-08 22:58:52 -08:00
parent 2ddb546f73
commit 43aa079d89

View File

@ -42,9 +42,13 @@ impl<T:Copy+Eq+std::hash::Hash> BvhNode<T>{
} }
} }
pub fn generate_bvh_node<T:Copy+Eq+std::hash::Hash>(boxen:Vec<(T,Aabb)>)->BvhNode<T>{ pub fn generate_bvh<T:Copy+Eq+std::hash::Hash>(boxen:Vec<(T,Aabb)>)->BvhNode<T>{
generate_bvh_node(boxen,false)
}
fn generate_bvh_node<T:Copy+Eq+std::hash::Hash>(boxen:Vec<(T,Aabb)>,force:bool)->BvhNode<T>{
let n=boxen.len(); let n=boxen.len();
if n<20{ if force||n<20{
let mut aabb=Aabb::default(); let mut aabb=Aabb::default();
let nodes=boxen.into_iter().map(|b|{ let nodes=boxen.into_iter().map(|b|{
aabb.join(&b.1); aabb.join(&b.1);
@ -107,14 +111,19 @@ pub fn generate_bvh_node<T:Copy+Eq+std::hash::Hash>(boxen:Vec<(T,Aabb)>)->BvhNod
list_list[list_id].push((i,aabb)); list_list[list_id].push((i,aabb));
} }
let mut aabb=Aabb::default(); let mut aabb=Aabb::default();
let children=list_list.into_iter().map(|b|{ if list_list.len()==1{
let node=generate_bvh_node(b); generate_bvh_node(list_list.remove(0),true)
aabb.join(&node.aabb); }else{
node BvhNode{
}).collect(); content:BvhNodeContent::Branch(
BvhNode{ list_list.into_iter().map(|b|{
content:BvhNodeContent::Branch(children), let node=generate_bvh_node(b,false);
aabb, aabb.join(&node.aabb);
node
}).collect()
),
aabb,
}
} }
} }
} }