fixes double neighbor assignement and cubes inside of empty volumes after skipping to grow
This commit is contained in:
parent
5353f28acd
commit
457d3e2d6b
7 changed files with 165 additions and 105 deletions
src/scene
|
@ -105,30 +105,38 @@ impl EmptyVolume {
|
|||
continue;
|
||||
}
|
||||
println!("new starting pos: {}, {}, {}", x_index, y_index, z_index);
|
||||
println!("start growing volume x");
|
||||
// MARK: Start new Volume
|
||||
let mut x_size = 0;
|
||||
let mut y_size = 0;
|
||||
let mut z_size = 0;
|
||||
if query_result.1 > 1 {
|
||||
|
||||
let neighbor_result = neighbors.test_element(x_index, y_index, z_index);
|
||||
|
||||
if query_result.1 > 1 && query_result.2.0 >= neighbor_result.2.0 && query_result.2.1 >= neighbor_result.2.1 && query_result.2.2 >= neighbor_result.2.2 && query_result.1 <= neighbor_result.1 {
|
||||
x_size = query_result.1 - 1 - (x_index - query_result.2.0);
|
||||
y_size = query_result.1 - 1 - (y_index - query_result.2.1);
|
||||
z_size = query_result.1 - 1 - (z_index - query_result.2.2);
|
||||
println!("enhanced starting size: {}, {}, {}", x_size+1, y_size+1, z_size+1);
|
||||
}
|
||||
println!("start growing volume x");
|
||||
let mut grow = true;
|
||||
while grow {
|
||||
grow &= (x_index + x_size + 1) < tree.borrow().size;
|
||||
if grow {
|
||||
let mut z = 0;
|
||||
let mut y = 0;
|
||||
while z < z_size.max(1) && y < y_size.max(1) {
|
||||
while z < z_size + 1 && y < y_size + 1 {
|
||||
let query_result = tree.borrow().test_element(x_index + x_size + 1, y_index + y, z_index + z);
|
||||
let neighbor_result = neighbors.test_element(x_index + x_size + 1, y_index + y, z_index + z);
|
||||
check_its += 1;
|
||||
grow &= ((!query_result.0 && !transparent) || (transparent && EmptyVolume::check_transparent(query_result.3, &transparent_color, &tranparent_roughness))) &&
|
||||
neighbors.get_element(x_index + x_size + 1, y_index + y, z_index + z).is_none();
|
||||
!neighbor_result.0;
|
||||
|
||||
if !grow {
|
||||
break;
|
||||
}
|
||||
|
||||
if query_result.1 > 1 {
|
||||
if query_result.1 > 1 && query_result.2.1 >= neighbor_result.2.1 && query_result.2.2 >= neighbor_result.2.2 && query_result.1 <= neighbor_result.1 {
|
||||
let start_x = query_result.2.0;
|
||||
let start_y = query_result.2.1;
|
||||
let start_z = query_result.2.2;
|
||||
|
@ -137,22 +145,20 @@ impl EmptyVolume {
|
|||
let end_y = query_result.2.1 + query_result.1;
|
||||
let end_z = query_result.2.2 + query_result.1;
|
||||
|
||||
if start_z <= z && z_index + z_size <= end_z {
|
||||
if start_z <= z_index + z && z_index + z_size <= end_z {
|
||||
// we can skip iterating z
|
||||
z = end_z;
|
||||
if start_y <= y && y_index + y_size <= end_y {
|
||||
z = end_z - z_index;
|
||||
if start_y <= y_index + y && y_index + y_size <= end_y && start_z <= z_index {
|
||||
// we can skip iterating y
|
||||
y = end_y;
|
||||
y = end_y - y_index;
|
||||
z = 0;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !grow {
|
||||
break;
|
||||
}
|
||||
|
||||
z += 1;
|
||||
if z >= z_size {
|
||||
if z >= z_size + 1 {
|
||||
z = 0;
|
||||
y += 1;
|
||||
}
|
||||
|
@ -169,13 +175,18 @@ impl EmptyVolume {
|
|||
if grow {
|
||||
let mut z = 0;
|
||||
let mut x = 0;
|
||||
while z < z_size.max(1) && x < x_size.max(1) {
|
||||
while z < z_size + 1 && x < x_size + 1 {
|
||||
let query_result = tree.borrow().test_element(x_index + x, y_index + y_size + 1, z_index + z);
|
||||
let neighbor_result = neighbors.test_element(x_index + x, y_index + y_size + 1, z_index + z);
|
||||
check_its += 1;
|
||||
grow &= ((!query_result.0 && !transparent) || (transparent && EmptyVolume::check_transparent(query_result.3, &transparent_color, &tranparent_roughness))) &&
|
||||
neighbors.get_element(x_index + x, y_index + y_size + 1, z_index + z).is_none();
|
||||
|
||||
if query_result.1 > 1 {
|
||||
!neighbor_result.0;
|
||||
|
||||
if !grow {
|
||||
break;
|
||||
}
|
||||
|
||||
if query_result.1 > 1 && query_result.2.0 >= neighbor_result.2.0 && query_result.2.2 >= neighbor_result.2.2 && query_result.1 <= neighbor_result.1 {
|
||||
let start_x = query_result.2.0;
|
||||
let start_y = query_result.2.1;
|
||||
let start_z = query_result.2.2;
|
||||
|
@ -184,22 +195,20 @@ impl EmptyVolume {
|
|||
let end_y = query_result.2.1 + query_result.1;
|
||||
let end_z = query_result.2.2 + query_result.1;
|
||||
|
||||
if start_z <= z && z_index + z_size <= end_z {
|
||||
if start_z <= z_index + z && z_index + z_size <= end_z {
|
||||
// we can skip iterating z
|
||||
z = end_z;
|
||||
if start_x <= x && x_index + x_size <= end_x {
|
||||
z = end_z - z_index;
|
||||
if start_x <= x_index + x && x_index + x_size <= end_x && start_z <= z_index {
|
||||
// we can skip iterating x
|
||||
x = end_x;
|
||||
x = end_x - x_index;
|
||||
z = 0;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !grow {
|
||||
break;
|
||||
}
|
||||
|
||||
z += 1;
|
||||
if z >= z_size {
|
||||
if z >= z_size + 1 {
|
||||
z = 0;
|
||||
x += 1;
|
||||
}
|
||||
|
@ -217,13 +226,18 @@ impl EmptyVolume {
|
|||
if grow {
|
||||
let mut y = 0;
|
||||
let mut x = 0;
|
||||
while y < y_size.max(1) && x < x_size.max(1) {
|
||||
while y < y_size + 1 && x < x_size + 1 {
|
||||
let query_result = tree.borrow().test_element(x_index + x, y_index + y, z_index + z_size + 1);
|
||||
let neighbor_result = neighbors.test_element(x_index + x, y_index + y, z_index + z_size + 1);
|
||||
check_its += 1;
|
||||
grow &= ((!query_result.0 && !transparent) || (transparent && EmptyVolume::check_transparent(query_result.3, &transparent_color, &tranparent_roughness))) &&
|
||||
neighbors.get_element(x_index + x, y_index + y, z_index + z_size + 1).is_none();
|
||||
!neighbor_result.0;
|
||||
|
||||
if !grow {
|
||||
break;
|
||||
}
|
||||
|
||||
if query_result.1 > 1 {
|
||||
if query_result.1 > 1 && query_result.2.1 >= neighbor_result.2.1 && query_result.2.0 >= neighbor_result.2.0 && query_result.1 <= neighbor_result.1 {
|
||||
let start_x = query_result.2.0;
|
||||
let start_y = query_result.2.1;
|
||||
let start_z = query_result.2.2;
|
||||
|
@ -232,22 +246,20 @@ impl EmptyVolume {
|
|||
let end_y = query_result.2.1 + query_result.1;
|
||||
let end_z = query_result.2.2 + query_result.1;
|
||||
|
||||
if start_x <= x && x_index + x_size <= end_x {
|
||||
if start_x <= x_index + x && x_index + x_size <= end_x {
|
||||
// we can skip iterating x
|
||||
x = end_x;
|
||||
if start_y <= y && y_index + y_size <= end_y {
|
||||
x = end_x - x_index;
|
||||
if start_y <= y_index + y && y_index + y_size <= end_y && start_x <= x_index {
|
||||
// we can skip iterating y
|
||||
y = end_y;
|
||||
y = end_y - y_index;
|
||||
x = 0;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !grow {
|
||||
break;
|
||||
}
|
||||
|
||||
x += 1;
|
||||
if x >= x_size {
|
||||
if x >= x_size + 1 {
|
||||
x = 0;
|
||||
y += 1;
|
||||
}
|
||||
|
@ -509,7 +521,7 @@ impl EmptyVolume {
|
|||
x_min_pos = 0;
|
||||
}
|
||||
else {
|
||||
x_min_pos = reference.borrow().position.x -1;
|
||||
x_min_pos = reference.borrow().position.x - 1;
|
||||
}
|
||||
let y_min_pos;
|
||||
if reference.borrow().position.y == 0 {
|
||||
|
@ -517,7 +529,7 @@ impl EmptyVolume {
|
|||
y_min_pos = 0;
|
||||
}
|
||||
else {
|
||||
y_min_pos = reference.borrow().position.y -1;
|
||||
y_min_pos = reference.borrow().position.y - 1;
|
||||
}
|
||||
let z_min_pos;
|
||||
if reference.borrow().position.z == 0 {
|
||||
|
@ -525,7 +537,7 @@ impl EmptyVolume {
|
|||
z_min_pos = 0;
|
||||
}
|
||||
else {
|
||||
z_min_pos = reference.borrow().position.z -1;
|
||||
z_min_pos = reference.borrow().position.z - 1;
|
||||
}
|
||||
let x_max_pos = reference.borrow().position.x + reference.borrow().size_x;
|
||||
let y_max_pos = reference.borrow().position.y + reference.borrow().size_y;
|
||||
|
@ -534,18 +546,16 @@ impl EmptyVolume {
|
|||
let mut bottom_neighbors = vec![];
|
||||
let mut bottom_elements_num = 0;
|
||||
let mut all_same = true;
|
||||
if z_min_pos != 0 {
|
||||
for x in 0..reference.borrow().size_x {
|
||||
for y in 0..reference.borrow().size_y {
|
||||
if let Some(c) = neighbors.get_element(reference.borrow().position.x + x, reference.borrow().position.y + y, z_min_pos) {
|
||||
bottom_elements_num += 1;
|
||||
bottom_neighbors.push(Some(c.clone()));
|
||||
all_same = all_same && (bottom_neighbors[0] == Some(c));
|
||||
}
|
||||
else {
|
||||
bottom_neighbors.push(None);
|
||||
all_same = all_same && (bottom_neighbors[0] == None);
|
||||
}
|
||||
for x in 0..reference.borrow().size_x {
|
||||
for y in 0..reference.borrow().size_y {
|
||||
if let Some(c) = neighbors.get_element(reference.borrow().position.x + x, reference.borrow().position.y + y, z_min_pos) {
|
||||
bottom_elements_num += 1;
|
||||
bottom_neighbors.push(Some(c.clone()));
|
||||
all_same = all_same && (bottom_neighbors[0] == Some(c));
|
||||
}
|
||||
else {
|
||||
bottom_neighbors.push(None);
|
||||
all_same = all_same && (bottom_neighbors[0] == None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -622,18 +632,16 @@ impl EmptyVolume {
|
|||
let mut front_neighbors = vec![];
|
||||
let mut front_elements_num = 0;
|
||||
let mut all_same = true;
|
||||
if y_min_pos != 0{
|
||||
for x in 0..reference.borrow().size_x {
|
||||
for z in 0..reference.borrow().size_z {
|
||||
if let Some(c) = neighbors.get_element(reference.borrow().position.x + x, y_min_pos, reference.borrow().position.z + z) {
|
||||
front_elements_num += 1;
|
||||
front_neighbors.push(Some(c.clone()));
|
||||
all_same = all_same && (front_neighbors[0] == Some(c));
|
||||
}
|
||||
else {
|
||||
front_neighbors.push(None);
|
||||
all_same = all_same && (front_neighbors[0] == None);
|
||||
}
|
||||
for x in 0..reference.borrow().size_x {
|
||||
for z in 0..reference.borrow().size_z {
|
||||
if let Some(c) = neighbors.get_element(reference.borrow().position.x + x, y_min_pos, reference.borrow().position.z + z) {
|
||||
front_elements_num += 1;
|
||||
front_neighbors.push(Some(c.clone()));
|
||||
all_same = all_same && (front_neighbors[0] == Some(c));
|
||||
}
|
||||
else {
|
||||
front_neighbors.push(None);
|
||||
all_same = all_same && (front_neighbors[0] == None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -653,18 +661,16 @@ impl EmptyVolume {
|
|||
let mut left_neighbors = vec![];
|
||||
let mut left_elements_num = 0;
|
||||
let mut all_same = true;
|
||||
if x_min_pos != 0 {
|
||||
for y in 0..reference.borrow().size_y {
|
||||
for z in 0..reference.borrow().size_z {
|
||||
if let Some(c) = neighbors.get_element(x_min_pos, reference.borrow().position.y + y, reference.borrow().position.z + z) {
|
||||
left_elements_num += 1;
|
||||
left_neighbors.push(Some(c.clone()));
|
||||
all_same = all_same && (left_neighbors[0] == Some(c));
|
||||
}
|
||||
else {
|
||||
left_neighbors.push(None);
|
||||
all_same = all_same && (left_neighbors[0] == None);
|
||||
}
|
||||
for y in 0..reference.borrow().size_y {
|
||||
for z in 0..reference.borrow().size_z {
|
||||
if let Some(c) = neighbors.get_element(x_min_pos, reference.borrow().position.y + y, reference.borrow().position.z + z) {
|
||||
left_elements_num += 1;
|
||||
left_neighbors.push(Some(c.clone()));
|
||||
all_same = all_same && (left_neighbors[0] == Some(c));
|
||||
}
|
||||
else {
|
||||
left_neighbors.push(None);
|
||||
all_same = all_same && (left_neighbors[0] == None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -723,13 +729,20 @@ impl EmptyVolume {
|
|||
if self.color_bottom.len() <= index {
|
||||
continue;
|
||||
}
|
||||
if self.neighbor_bottom.len() > index {
|
||||
if let Some(_) = self.neighbor_bottom[index] {
|
||||
if self.neighbor_bottom.len() > index || self.neighbor_bottom.len() == 1 {
|
||||
if let Some(_) = self.neighbor_bottom[index.min(self.neighbor_bottom.len() - 1)] {
|
||||
if self.color_bottom[index] == (Vector3 {x: 0, y: 0, z: 0}) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if self.color_bottom[index] == (Vector3 {x: 0, y: 0, z: 0}) {
|
||||
println!("No neighbor reference, but no color! x: {}, y: {}, z: {}", self.position.x + x, self.position.y + y, self.position.z);
|
||||
if self.neighbor_bottom.len() == 1 {
|
||||
println!("neighbor length is one!");
|
||||
}
|
||||
}
|
||||
|
||||
let quad = Quad {
|
||||
pos1: float_pos + Vector3 { x: -0.5 + x as f32, y: -0.5 + y as f32, z: -0.5 },
|
||||
pos4: float_pos + Vector3 { x: 0.5 + x as f32, y: -0.5 + y as f32, z: -0.5 },
|
||||
|
@ -749,13 +762,21 @@ impl EmptyVolume {
|
|||
if self.color_top.len() <= 0 {
|
||||
continue;
|
||||
}
|
||||
if self.neighbor_top.len() > index {
|
||||
if let Some(_) = self.neighbor_top[index] {
|
||||
if self.neighbor_top.len() > index || self.neighbor_top.len() == 1 {
|
||||
if let Some(_) = self.neighbor_top[index.min(self.neighbor_top.len() - 1)] {
|
||||
if self.color_top[index] == (Vector3 {x: 0, y: 0, z: 0}) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if self.color_top[index] == (Vector3 {x: 0, y: 0, z: 0}) {
|
||||
println!("No neighbor reference, but no color! x: {}, y: {}, z: {}", self.position.x + x, self.position.y + y, self.position.z + self.size_z);
|
||||
|
||||
if self.neighbor_top.len() == 1 {
|
||||
println!("neighbor length is one!");
|
||||
}
|
||||
}
|
||||
let quad = Quad {
|
||||
pos4: float_pos + Vector3 { x: -0.5 + x as f32, y: -0.5 + y as f32, z: self.size_z as f32 - 0.5 },
|
||||
pos1: float_pos + Vector3 { x: 0.5 + x as f32, y: -0.5 + y as f32, z: self.size_z as f32 - 0.5 },
|
||||
|
@ -776,13 +797,20 @@ impl EmptyVolume {
|
|||
if self.color_front.len() <= 0 {
|
||||
continue;
|
||||
}
|
||||
if self.neighbor_front.len() > index {
|
||||
if let Some(_) = self.neighbor_front[index] {
|
||||
if self.neighbor_front.len() > index || self.neighbor_front.len() == 1 {
|
||||
if let Some(_) = self.neighbor_front[index.min(self.neighbor_front.len() - 1)] {
|
||||
if self.color_front[index] == (Vector3 {x: 0, y: 0, z: 0}) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if self.color_front[index] == (Vector3 {x: 0, y: 0, z: 0}) {
|
||||
println!("No neighbor reference, but no color! x: {}, y: {}, z: {}", self.position.x + x, self.position.y, self.position.z + z);
|
||||
if self.neighbor_front.len() == 1 {
|
||||
println!("neighbor length is one!");
|
||||
}
|
||||
}
|
||||
let quad = Quad {
|
||||
pos1: float_pos + Vector3 { x: -0.5 + x as f32, y: -0.5 + 0 as f32, z: z as f32 - 0.5 },
|
||||
pos4: float_pos + Vector3 { x: -0.5 + x as f32, y: -0.5 + 0 as f32, z: z as f32 + 0.5 },
|
||||
|
@ -803,13 +831,20 @@ impl EmptyVolume {
|
|||
if self.color_back.len() <= 0 {
|
||||
continue;
|
||||
}
|
||||
if self.neighbor_back.len() > index {
|
||||
if let Some(_) = self.neighbor_back[index] {
|
||||
if self.neighbor_back.len() > index || self.neighbor_back.len() == 1 {
|
||||
if let Some(_) = self.neighbor_back[index.min(self.neighbor_back.len() - 1)] {
|
||||
if self.color_back[index] == (Vector3 {x: 0, y: 0, z: 0}) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if self.color_back[index] == (Vector3 {x: 0, y: 0, z: 0}) {
|
||||
println!("No neighbor reference, but no color! x: {}, y: {}, z: {}", self.position.x + x, self.position.y + self.size_y, self.position.z + z);
|
||||
if self.neighbor_back.len() == 1 {
|
||||
println!("neighbor length is one!");
|
||||
}
|
||||
}
|
||||
let quad = Quad {
|
||||
pos4: float_pos + Vector3 { x: -0.5 + x as f32, y: -0.5 + self.size_y as f32, z: z as f32 - 0.5 },
|
||||
pos1: float_pos + Vector3 { x: -0.5 + x as f32, y: -0.5 + self.size_y as f32, z: z as f32 + 0.5 },
|
||||
|
@ -830,13 +865,20 @@ impl EmptyVolume {
|
|||
if self.color_left.len() <= 0 {
|
||||
continue;
|
||||
}
|
||||
if self.neighbor_left.len() > index {
|
||||
if let Some(_) = self.neighbor_left[index] {
|
||||
if self.neighbor_left.len() > index || self.neighbor_left.len() == 1 {
|
||||
if let Some(_) = self.neighbor_left[index.min(self.neighbor_left.len() - 1)] {
|
||||
if self.color_left[index] == (Vector3 {x: 0, y: 0, z: 0}) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if self.color_left[index] == (Vector3 {x: 0, y: 0, z: 0}) {
|
||||
println!("No neighbor reference, but no color! x: {}, y: {}, z: {}", self.position.x, self.position.y + y, self.position.z + z);
|
||||
if self.neighbor_left.len() == 1 {
|
||||
println!("neighbor length is one!");
|
||||
}
|
||||
}
|
||||
let quad = Quad {
|
||||
pos4: float_pos + Vector3 { x: -0.5 + 0.0 as f32, y: y as f32 - 0.5, z: z as f32 - 0.5 },
|
||||
pos1: float_pos + Vector3 { x: -0.5 + 0.0 as f32, y: y as f32 - 0.5, z: z as f32 + 0.5 },
|
||||
|
@ -857,13 +899,20 @@ impl EmptyVolume {
|
|||
if self.color_right.len() <= 0 {
|
||||
continue;
|
||||
}
|
||||
if self.neighbor_right.len() > index {
|
||||
if let Some(_) = self.neighbor_right[index] {
|
||||
if self.neighbor_right.len() > index || self.neighbor_right.len() == 1 {
|
||||
if let Some(_) = self.neighbor_right[index.min(self.neighbor_right.len() - 1)] {
|
||||
if self.color_right[index] == (Vector3 {x: 0, y: 0, z: 0}) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if self.color_right[index] == (Vector3 {x: 0, y: 0, z: 0}) {
|
||||
println!("No neighbor reference, but no color! x: {}, y: {}, z: {}", self.position.x + self.size_x, self.position.y + y, self.position.z + z);
|
||||
if self.neighbor_right.len() == 1 {
|
||||
println!("neighbor length is one!");
|
||||
}
|
||||
}
|
||||
let quad = Quad {
|
||||
pos1: float_pos + Vector3 { x: -0.5 + self.size_x as f32, y: y as f32 - 0.5, z: z as f32 - 0.5 },
|
||||
pos4: float_pos + Vector3 { x: -0.5 + self.size_x as f32, y: y as f32 - 0.5, z: z as f32 + 0.5 },
|
||||
|
@ -1238,7 +1287,7 @@ impl Memorizable for EmptyVolume {
|
|||
mem_index += 2;
|
||||
|
||||
//color and roughness
|
||||
//check which endian should be used in conjun´ction of the graphicscard (might already be handled by vulkan)
|
||||
//check which endian should be used in conjunction of the graphics card (might already be handled by vulkan)
|
||||
if self.color_top.len() > 0 {
|
||||
for index in 0..self.color_top.len() {
|
||||
let value = &self.color_top[index];
|
||||
|
@ -1419,7 +1468,7 @@ impl Memorizable for EmptyVolume {
|
|||
v[mem_index] = 0;
|
||||
mem_index += 1;
|
||||
}
|
||||
println!("last memory index of volume was {}, equivalent to {}kB", mem_index, mem_index * 32 / 8 / 1024);
|
||||
//println!("last memory index of volume was {}, equivalent to {}kB", mem_index, mem_index * 32 / 8 / 1024);
|
||||
v
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue