volume creation improvement 1
This commit is contained in:
parent
9b618b0e3f
commit
886f92470c
4 changed files with 402 additions and 306 deletions
src/scene
|
@ -377,6 +377,104 @@ impl<T: Clone> OctTree<T> {
|
|||
self.blocks[z * MIN_CHUNK_SIZE * MIN_CHUNK_SIZE + y * MIN_CHUNK_SIZE + x].clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn test_element(&self, x: usize, y: usize, z: usize) -> (bool, usize, (usize, usize, usize)) {
|
||||
self.test_element_internal(x, y, z, 0, 0, 0)
|
||||
}
|
||||
|
||||
fn test_element_internal(&self, x: usize, y: usize, z: usize, node_start_x: usize, node_start_y: usize, node_start_z: usize) -> (bool, usize, (usize, usize, usize)) {
|
||||
if x >= self.size || y >= self.size || z >= self.size {
|
||||
return (false, 0, (0, 0, 0))
|
||||
}
|
||||
|
||||
if self.size > MIN_CHUNK_SIZE {
|
||||
let mid_point = self.size / 2;
|
||||
if x >= mid_point {
|
||||
if y >= mid_point {
|
||||
if z >= mid_point {
|
||||
match &self.child_XYZ {
|
||||
Some(child) => {
|
||||
child.borrow().test_element_internal(x - mid_point, y - mid_point, z - mid_point, node_start_x + mid_point, node_start_y + mid_point, node_start_z + mid_point)
|
||||
},
|
||||
None => (false, mid_point, (node_start_x + mid_point, node_start_y + mid_point, node_start_z + mid_point))
|
||||
}
|
||||
}
|
||||
else {
|
||||
match &self.child_XYz {
|
||||
Some(child) => {
|
||||
child.borrow().test_element_internal( x - mid_point, y - mid_point, z, node_start_x + mid_point, node_start_y + mid_point, node_start_z)
|
||||
},
|
||||
None => (false, mid_point, (node_start_x + mid_point, node_start_y + mid_point, node_start_z))
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if z >= mid_point {
|
||||
match &self.child_XyZ {
|
||||
Some(child) => {
|
||||
child.borrow().test_element_internal(x - mid_point, y, z - mid_point, node_start_x + mid_point, node_start_y, node_start_z + mid_point)
|
||||
},
|
||||
None => (false, mid_point, (node_start_x + mid_point, node_start_y, node_start_z + mid_point))
|
||||
}
|
||||
}
|
||||
else {
|
||||
match &self.child_Xyz {
|
||||
Some(child) => {
|
||||
child.borrow().test_element_internal(x - mid_point, y, z, node_start_x + mid_point, node_start_y, node_start_z)
|
||||
},
|
||||
None => (false, mid_point, (node_start_x + mid_point, node_start_y, node_start_z))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if y >= mid_point {
|
||||
if z >= mid_point {
|
||||
match &self.child_xYZ {
|
||||
Some(child) => {
|
||||
child.borrow().test_element_internal(x, y - mid_point, z - mid_point, node_start_x, node_start_y + mid_point, node_start_z + mid_point)
|
||||
},
|
||||
None => (false, mid_point, (node_start_x, node_start_y + mid_point, node_start_z + mid_point))
|
||||
}
|
||||
}
|
||||
else {
|
||||
match &self.child_xYz {
|
||||
Some(child) => {
|
||||
child.borrow().test_element_internal(x, y - mid_point, z, node_start_x, node_start_y + mid_point, node_start_z)
|
||||
},
|
||||
None => (false, mid_point, (node_start_x, node_start_y + mid_point, node_start_z))
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if z >= mid_point {
|
||||
match &self.child_xyZ {
|
||||
Some(child) => {
|
||||
child.borrow().test_element_internal(x, y, z - mid_point, node_start_x, node_start_y, node_start_z + mid_point)
|
||||
},
|
||||
None => (false, mid_point, (node_start_x, node_start_y, node_start_z + mid_point))
|
||||
}
|
||||
}
|
||||
else {
|
||||
match &self.child_xyz {
|
||||
Some(child) => {
|
||||
child.borrow().test_element_internal(x, y, z, node_start_x, node_start_y, node_start_z)
|
||||
},
|
||||
None => (false, mid_point, (node_start_x , node_start_y, node_start_z))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if let Some(_) = self.blocks[z * MIN_CHUNK_SIZE * MIN_CHUNK_SIZE + y * MIN_CHUNK_SIZE + x] {
|
||||
(true, 1, (x, y, z))
|
||||
}
|
||||
else {
|
||||
(false, 1, (x, y, z))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct OctTreeIter<'a> {
|
||||
|
@ -503,7 +601,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_oct_tree(){
|
||||
let mut test_tree: OctTree<Cube> = OctTree::create(512).unwrap();
|
||||
let test_cube = Cube{color: Vector3 { x: 1.0, y: 0.0, z: 0.0 }, pos: Vector3 { x: 5.0, y: 2.0, z: 10.0 }, tex_coord: Vector2{x: 0.0, y: 0.0}};
|
||||
let test_cube = Cube{color: Vector3 { x: 1.0, y: 0.0, z: 0.0 }, pos: Vector3 { x: 5.0, y: 2.0, z: 10.0 }, tex_coord: Vector2{x: 0.0, y: 0.0}, transparent: false};
|
||||
|
||||
test_tree.set_cube(test_cube.clone());
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue