volume creation improvement 1
This commit is contained in:
parent
9b618b0e3f
commit
886f92470c
4 changed files with 402 additions and 306 deletions
src
|
@ -8,7 +8,8 @@ use crate::primitives::drawable::Drawable;
|
|||
pub struct Cube{
|
||||
pub pos: vertex::Vec3,
|
||||
pub color: vertex::Vec3,
|
||||
pub tex_coord: vertex::Vec2
|
||||
pub tex_coord: vertex::Vec2,
|
||||
pub transparent: bool,
|
||||
}
|
||||
|
||||
const cube_size: f32 = 0.48;
|
||||
|
|
|
@ -61,13 +61,9 @@ impl EmptyVolume {
|
|||
for y_index in 0..tree.size {
|
||||
for z_index in 0..tree.size {
|
||||
// check if there is a block at that position
|
||||
let query_result = tree.get_element(x_index, y_index, z_index);
|
||||
let query_result = tree.test_element(x_index, y_index, z_index);
|
||||
|
||||
match query_result {
|
||||
Some(cube) => {
|
||||
//if so do nothing
|
||||
},
|
||||
None => {
|
||||
if !query_result.0 {
|
||||
//if not check that it is not already inside of a volume
|
||||
let mut contained = false;
|
||||
for volume in &volumes {
|
||||
|
@ -372,7 +368,6 @@ impl EmptyVolume {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("add the neighbor linkage for all the volumes of the oct tree");
|
||||
// MARK: Neighbor Linkage
|
||||
for reference in volumes.iter_mut() {
|
||||
|
|
|
@ -72,7 +72,8 @@ impl Scene {
|
|||
let cube = Cube {
|
||||
pos: vec3(x_index as f32, y_index as f32, 5.0),
|
||||
color: vec3(shade, 1.0, shade),
|
||||
tex_coord: vec2(0.0, 0.0)
|
||||
tex_coord: vec2(0.0, 0.0),
|
||||
transparent: false,
|
||||
};
|
||||
|
||||
oct_tree.set_cube(cube.clone());
|
||||
|
@ -83,7 +84,8 @@ impl Scene {
|
|||
let cube = Cube {
|
||||
pos: vec3(10.0, 10.0, 10.0),
|
||||
color: vec3(1.0, 1.0, 0.0),
|
||||
tex_coord: vec2(0.0, 0.0)
|
||||
tex_coord: vec2(0.0, 0.0),
|
||||
transparent: true,
|
||||
};
|
||||
|
||||
oct_tree.set_cube(cube.clone());
|
||||
|
@ -167,7 +169,7 @@ impl Scene {
|
|||
for light in &self.point_lights {
|
||||
volume_vec = light.insert_into_memory(volume_vec);
|
||||
}
|
||||
println!("volume_vec print {:?}", volume_vec);
|
||||
//println!("volume_vec print {:?}", volume_vec);
|
||||
|
||||
self.rt_memory = volume_vec;
|
||||
data.scene_rt_memory_size = (self.rt_memory.len() * 4) as u64; // size of the needed buffer size in bytes
|
||||
|
|
|
@ -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