wip
This commit is contained in:
parent
bc9599eef0
commit
019c7b3887
60
src/bvh.rs
60
src/bvh.rs
@ -1,14 +1,10 @@
|
|||||||
use crate::aabb::Aabb;
|
use crate::aabb::Aabb;
|
||||||
|
|
||||||
//da algaritum
|
//bvh 2
|
||||||
//lista boxens
|
//sort {x,y,z}_{min,max} (6 sets)
|
||||||
//sort by {minx,maxx,miny,maxy,minz,maxz} (6 lists)
|
//octree partitioning
|
||||||
//find the sets that minimizes the sum of surface areas
|
//for each axis, minimize the sum of the lower and upper partition world width
|
||||||
//splitting is done when the minimum split sum of surface areas is larger than the node's own surface area
|
//effectively, find the biggest gap
|
||||||
|
|
||||||
//start with bisection into octrees because a bad bvh is still 1000x better than no bvh
|
|
||||||
//sort the centerpoints on each axis (3 lists)
|
|
||||||
//bv is put into octant based on whether it is upper or lower in each list
|
|
||||||
|
|
||||||
pub enum RecursiveContent<R,T>{
|
pub enum RecursiveContent<R,T>{
|
||||||
Branch(Vec<R>),
|
Branch(Vec<R>),
|
||||||
@ -121,18 +117,40 @@ fn generate_bvh_node<T>(boxen:Vec<(T,Aabb)>,force:bool)->BvhNode<T>{
|
|||||||
aabb,
|
aabb,
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
let mut sort_x=Vec::with_capacity(n);
|
let mut sort_x_min=boxen.iter()
|
||||||
let mut sort_y=Vec::with_capacity(n);
|
.enumerate()
|
||||||
let mut sort_z=Vec::with_capacity(n);
|
.map(|(i,(_,aabb))|(i,aabb))
|
||||||
for (i,(_,aabb)) in boxen.iter().enumerate(){
|
.collect::<Vec<(usize,&Aabb)>>();
|
||||||
let center=aabb.center();
|
let mut sort_x_max=sort_x_min.clone();
|
||||||
sort_x.push((i,center.x()));
|
let mut sort_y_min=sort_x_min.clone();
|
||||||
sort_y.push((i,center.y()));
|
let mut sort_y_max=sort_x_min.clone();
|
||||||
sort_z.push((i,center.z()));
|
let mut sort_z_min=sort_x_min.clone();
|
||||||
}
|
let mut sort_z_max=sort_x_min.clone();
|
||||||
sort_x.sort_by(|tup0,tup1|tup0.1.cmp(&tup1.1));
|
//sort by x_min, but if x_min is equal, then sort by x_max reverse instead
|
||||||
sort_y.sort_by(|tup0,tup1|tup0.1.cmp(&tup1.1));
|
sort_x_min.sort_by(|&(_,aabb0),&(_,aabb1)|
|
||||||
sort_z.sort_by(|tup0,tup1|tup0.1.cmp(&tup1.1));
|
aabb0.min().x().cmp(&aabb1.min().x())
|
||||||
|
.then(aabb0.max().x().cmp(&aabb1.max().x()).reverse())
|
||||||
|
);
|
||||||
|
sort_x_max.sort_by(|&(_,aabb0),&(_,aabb1)|
|
||||||
|
aabb0.max().x().cmp(&aabb1.max().x())
|
||||||
|
.then(aabb0.min().x().cmp(&aabb1.min().x()).reverse())
|
||||||
|
);
|
||||||
|
sort_y_min.sort_by(|&(_,aabb0),&(_,aabb1)|
|
||||||
|
aabb0.min().y().cmp(&aabb1.min().y())
|
||||||
|
.then(aabb0.max().y().cmp(&aabb1.max().y()).reverse())
|
||||||
|
);
|
||||||
|
sort_y_max.sort_by(|&(_,aabb0),&(_,aabb1)|
|
||||||
|
aabb0.max().y().cmp(&aabb1.max().y())
|
||||||
|
.then(aabb0.min().y().cmp(&aabb1.min().y()).reverse())
|
||||||
|
);
|
||||||
|
sort_z_min.sort_by(|&(_,aabb0),&(_,aabb1)|
|
||||||
|
aabb0.min().z().cmp(&aabb1.min().z())
|
||||||
|
.then(aabb0.max().z().cmp(&aabb1.max().z()).reverse())
|
||||||
|
);
|
||||||
|
sort_z_max.sort_by(|&(_,aabb0),&(_,aabb1)|
|
||||||
|
aabb0.max().z().cmp(&aabb1.max().z())
|
||||||
|
.then(aabb0.min().z().cmp(&aabb1.min().z()).reverse())
|
||||||
|
);
|
||||||
let h=n/2;
|
let h=n/2;
|
||||||
let median_x=sort_x[h].1;
|
let median_x=sort_x[h].1;
|
||||||
let median_y=sort_y[h].1;
|
let median_y=sort_y[h].1;
|
||||||
|
Loading…
Reference in New Issue
Block a user