bvh reduce badness
This commit is contained in:
parent
2ddb546f73
commit
43aa079d89
23
src/bvh.rs
23
src/bvh.rs
@ -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)
|
||||||
|
}else{
|
||||||
|
BvhNode{
|
||||||
|
content:BvhNodeContent::Branch(
|
||||||
|
list_list.into_iter().map(|b|{
|
||||||
|
let node=generate_bvh_node(b,false);
|
||||||
aabb.join(&node.aabb);
|
aabb.join(&node.aabb);
|
||||||
node
|
node
|
||||||
}).collect();
|
}).collect()
|
||||||
BvhNode{
|
),
|
||||||
content:BvhNodeContent::Branch(children),
|
|
||||||
aabb,
|
aabb,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user