volume creation improvement 1
This commit is contained in:
parent
9b618b0e3f
commit
886f92470c
4 changed files with 402 additions and 306 deletions
src/scene
|
@ -61,314 +61,309 @@ 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 not check that it is not already inside of a volume
|
||||
let mut contained = false;
|
||||
for volume in &volumes {
|
||||
if volume.borrow().contains(&Vector3{x: x_index, y: y_index, z: z_index}) {
|
||||
contained = true;
|
||||
break;
|
||||
}
|
||||
if !query_result.0 {
|
||||
//if not check that it is not already inside of a volume
|
||||
let mut contained = false;
|
||||
for volume in &volumes {
|
||||
if volume.borrow().contains(&Vector3{x: x_index, y: y_index, z: z_index}) {
|
||||
contained = true;
|
||||
break;
|
||||
}
|
||||
if contained {
|
||||
// abort if it is already covered
|
||||
continue;
|
||||
}
|
||||
if contained {
|
||||
// abort if it is already covered
|
||||
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 grow = true;
|
||||
while grow {
|
||||
grow = tree.get_element(x_index + x_size + 1, y_index, z_index).is_none() && neighbors.get_element(x_index + x_size + 1, y_index, z_index).is_none();
|
||||
grow &= (x_index + x_size + 1) < tree.size;
|
||||
if grow {
|
||||
x_size += 1;
|
||||
}
|
||||
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 grow = true;
|
||||
while grow {
|
||||
grow = tree.get_element(x_index + x_size + 1, y_index, z_index).is_none() && neighbors.get_element(x_index + x_size + 1, y_index, z_index).is_none();
|
||||
grow &= (x_index + x_size + 1) < tree.size;
|
||||
if grow {
|
||||
x_size += 1;
|
||||
}
|
||||
}
|
||||
println!("start growing volume y");
|
||||
let mut y_size = 0;
|
||||
grow = true;
|
||||
while grow {
|
||||
grow &= (y_index + y_size + 1) < tree.size;
|
||||
if grow {
|
||||
for x in 0..x_size {
|
||||
grow &= tree.get_element(x_index + x, y_index + y_size + 1, z_index).is_none() &&
|
||||
neighbors.get_element(x_index + x, y_index + y_size + 1, z_index).is_none();
|
||||
|
||||
if !grow {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if grow {
|
||||
y_size += 1;
|
||||
}
|
||||
}
|
||||
println!("start growing volume z");
|
||||
let mut z_size = 0;
|
||||
grow = true;
|
||||
while grow {
|
||||
grow &= (z_index + z_size + 1) < tree.size;
|
||||
if grow {
|
||||
for x in 0..x_size {
|
||||
for y in 0..y_size {
|
||||
grow &= tree.get_element(x_index + x, y_index + y, z_index + z_size + 1).is_none() &&
|
||||
neighbors.get_element(x_index + x, y_index + y, z_index + z_size + 1).is_none();
|
||||
if !grow {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if !grow {
|
||||
break;
|
||||
}
|
||||
}
|
||||
println!("start growing volume y");
|
||||
let mut y_size = 0;
|
||||
grow = true;
|
||||
while grow {
|
||||
grow &= (y_index + y_size + 1) < tree.size;
|
||||
if grow {
|
||||
for x in 0..x_size {
|
||||
grow &= tree.get_element(x_index + x, y_index + y_size + 1, z_index).is_none() &&
|
||||
neighbors.get_element(x_index + x, y_index + y_size + 1, z_index).is_none();
|
||||
|
||||
if !grow {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if grow {
|
||||
z_size += 1;
|
||||
}
|
||||
}
|
||||
println!("final size: {}, {}, {}", x_size+1, y_size+1, z_size+1);
|
||||
// create new empty volume
|
||||
let new_volume = EmptyVolume {
|
||||
memory_start: 0,
|
||||
size_x: x_size + 1,
|
||||
size_y: y_size + 1,
|
||||
size_z: z_size + 1,
|
||||
position: Vector3{x: x_index, y: y_index, z: z_index},
|
||||
color_left: vec![],
|
||||
color_right: vec![],
|
||||
color_top: vec![],
|
||||
color_bottom: vec![],
|
||||
color_back: vec![],
|
||||
color_front: vec![],
|
||||
roughness_left: vec![],
|
||||
roughness_right: vec![],
|
||||
roughness_top: vec![],
|
||||
roughness_bottom: vec![],
|
||||
roughness_back: vec![],
|
||||
roughness_front: vec![],
|
||||
neighbor_left: vec![],
|
||||
neighbor_right: vec![],
|
||||
neighbor_top: vec![],
|
||||
neighbor_bottom: vec![],
|
||||
neighbor_back: vec![],
|
||||
neighbor_front: vec![],
|
||||
};
|
||||
println!("adding neighbor references");
|
||||
// MARK: fill in info in the neighbor octtree
|
||||
let reference = Rc::new(RefCell::new(new_volume));
|
||||
for x in 0..x_size+1 {
|
||||
for y in 0..y_size+1 {
|
||||
for z in 0..z_size+1 {
|
||||
neighbors.set_element(reference.clone(), reference.borrow().position.x + x, reference.borrow().position.y + y, reference.borrow().position.z + z);
|
||||
// fill only the edges
|
||||
/*if x == 0 || x == x_size || y == 0 || y == y_size || z==0 || z == z_size {
|
||||
neighbors.set_element(reference.clone(), reference.borrow().position.x + x, reference.borrow().position.y + y, reference.borrow().position.z + z)
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("add the border information for color and roughness");
|
||||
let x_min_pos;
|
||||
if reference.borrow().position.x == 0 {
|
||||
// will result in an empty color and roughness map.
|
||||
x_min_pos = 0;
|
||||
}
|
||||
else {
|
||||
x_min_pos = reference.borrow().position.x -1;
|
||||
}
|
||||
let y_min_pos;
|
||||
if reference.borrow().position.y == 0 {
|
||||
// will result in an empty color and roughness map.
|
||||
y_min_pos = 0;
|
||||
}
|
||||
else {
|
||||
y_min_pos = reference.borrow().position.y -1;
|
||||
}
|
||||
let z_min_pos;
|
||||
if reference.borrow().position.z == 0 {
|
||||
// will result in an empty color and roughness map.
|
||||
z_min_pos = 0;
|
||||
}
|
||||
else {
|
||||
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;
|
||||
let z_max_pos = reference.borrow().position.z + reference.borrow().size_z;
|
||||
// MARK: bottom face of the volume
|
||||
let mut bottom_colors = vec![];
|
||||
let mut bottom_roughness = vec![];
|
||||
let mut bottom_elements_num = 0;
|
||||
for x in 0..x_size+1 {
|
||||
for y in 0..y_size+1 {
|
||||
if let Some(c) = tree.get_element(reference.borrow().position.x + x, reference.borrow().position.y + y, z_min_pos) {
|
||||
bottom_elements_num += 1;
|
||||
let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
|
||||
bottom_colors.push(u8_color);
|
||||
bottom_roughness.push(128);
|
||||
}
|
||||
else {
|
||||
bottom_colors.push(Vector3 { x: 0, y: 0, z: 0 });
|
||||
bottom_roughness.push(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if bottom_elements_num > 0 {
|
||||
reference.borrow_mut().color_bottom = bottom_colors;
|
||||
reference.borrow_mut().roughness_bottom = bottom_roughness;
|
||||
}
|
||||
else {
|
||||
reference.borrow_mut().color_bottom= vec![];
|
||||
reference.borrow_mut().roughness_bottom= vec![];
|
||||
}
|
||||
// MARK: top face of the volume
|
||||
let mut top_colors = vec![];
|
||||
let mut top_roughness = vec![];
|
||||
let mut top_elements_num = 0;
|
||||
for x in 0..x_size+1 {
|
||||
for y in 0..y_size+1 {
|
||||
if let Some(c) = tree.get_element(reference.borrow().position.x + x, reference.borrow().position.y + y, z_max_pos) {
|
||||
top_elements_num += 1;
|
||||
let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
|
||||
top_colors.push(u8_color);
|
||||
top_roughness.push(128);
|
||||
}
|
||||
else {
|
||||
top_colors.push(Vector3 { x: 0, y: 0, z: 0 });
|
||||
top_roughness.push(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if top_elements_num > 0 {
|
||||
reference.borrow_mut().color_top = top_colors;
|
||||
reference.borrow_mut().roughness_top = top_roughness;
|
||||
}
|
||||
else {
|
||||
reference.borrow_mut().color_top= vec![];
|
||||
reference.borrow_mut().roughness_top= vec![];
|
||||
}
|
||||
|
||||
// MARK: back face of the volume
|
||||
let mut back_colors = vec![];
|
||||
let mut back_roughness = vec![];
|
||||
let mut back_elements_num = 0;
|
||||
for x in 0..x_size+1 {
|
||||
for z in 0..z_size+1 {
|
||||
if let Some(c) = tree.get_element(reference.borrow().position.x + x, y_max_pos, reference.borrow().position.z + z) {
|
||||
back_elements_num += 1;
|
||||
let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
|
||||
back_colors.push(u8_color);
|
||||
back_roughness.push(128);
|
||||
}
|
||||
else {
|
||||
back_colors.push(Vector3 { x: 0, y: 0, z: 0 });
|
||||
back_roughness.push(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if back_elements_num > 0 {
|
||||
reference.borrow_mut().color_back = back_colors;
|
||||
reference.borrow_mut().roughness_back = back_roughness;
|
||||
}
|
||||
else {
|
||||
reference.borrow_mut().color_back= vec![];
|
||||
reference.borrow_mut().roughness_back= vec![];
|
||||
}
|
||||
|
||||
// MARK: front face of the volume
|
||||
let mut front_colors = vec![];
|
||||
let mut front_roughness = vec![];
|
||||
let mut front_elements_num = 0;
|
||||
for x in 0..x_size+1 {
|
||||
for z in 0..z_size+1 {
|
||||
if let Some(c) = tree.get_element(reference.borrow().position.x + x, y_min_pos, reference.borrow().position.z + z) {
|
||||
front_elements_num += 1;
|
||||
let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
|
||||
front_colors.push(u8_color);
|
||||
front_roughness.push(128);
|
||||
}
|
||||
else {
|
||||
front_colors.push(Vector3 { x: 0, y: 0, z: 0 });
|
||||
front_roughness.push(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if front_elements_num > 0 {
|
||||
reference.borrow_mut().color_front = front_colors;
|
||||
reference.borrow_mut().roughness_front = front_roughness;
|
||||
}
|
||||
else {
|
||||
reference.borrow_mut().color_front= vec![];
|
||||
reference.borrow_mut().roughness_front= vec![];
|
||||
}
|
||||
|
||||
// MARK: left face of the volume
|
||||
let mut left_colors = vec![];
|
||||
let mut left_roughness = vec![];
|
||||
let mut left_elements_num = 0;
|
||||
for y in 0..y_size+1 {
|
||||
for z in 0..z_size+1 {
|
||||
if let Some(c) = tree.get_element(x_min_pos, reference.borrow().position.y + y, reference.borrow().position.z + z) {
|
||||
left_elements_num += 1;
|
||||
let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
|
||||
left_colors.push(u8_color);
|
||||
left_roughness.push(128);
|
||||
}
|
||||
else {
|
||||
left_colors.push(Vector3 { x: 0, y: 0, z: 0 });
|
||||
left_roughness.push(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if left_elements_num > 0 {
|
||||
reference.borrow_mut().color_left = left_colors;
|
||||
reference.borrow_mut().roughness_left = left_roughness;
|
||||
}
|
||||
else {
|
||||
reference.borrow_mut().color_left= vec![];
|
||||
reference.borrow_mut().roughness_left= vec![];
|
||||
}
|
||||
|
||||
// MARK: right face of the volume
|
||||
let mut right_colors = vec![];
|
||||
let mut right_roughness = vec![];
|
||||
let mut right_elements_num = 0;
|
||||
for y in 0..y_size+1 {
|
||||
for z in 0..z_size+1 {
|
||||
if let Some(c) = tree.get_element(x_max_pos, reference.borrow().position.y + y, reference.borrow().position.z + z) {
|
||||
right_elements_num += 1;
|
||||
let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
|
||||
right_colors.push(u8_color);
|
||||
right_roughness.push(128);
|
||||
}
|
||||
else {
|
||||
right_colors.push(Vector3 { x: 0, y: 0, z: 0 });
|
||||
right_roughness.push(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if right_elements_num > 0 {
|
||||
reference.borrow_mut().color_right = right_colors;
|
||||
reference.borrow_mut().roughness_right = right_roughness;
|
||||
}
|
||||
else {
|
||||
reference.borrow_mut().color_right= vec![];
|
||||
reference.borrow_mut().roughness_right= vec![];
|
||||
}
|
||||
}
|
||||
|
||||
println!("new volume done");
|
||||
//push to the list
|
||||
volumes.push(reference);
|
||||
if grow {
|
||||
y_size += 1;
|
||||
}
|
||||
}
|
||||
println!("start growing volume z");
|
||||
let mut z_size = 0;
|
||||
grow = true;
|
||||
while grow {
|
||||
grow &= (z_index + z_size + 1) < tree.size;
|
||||
if grow {
|
||||
for x in 0..x_size {
|
||||
for y in 0..y_size {
|
||||
grow &= tree.get_element(x_index + x, y_index + y, z_index + z_size + 1).is_none() &&
|
||||
neighbors.get_element(x_index + x, y_index + y, z_index + z_size + 1).is_none();
|
||||
if !grow {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if !grow {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if grow {
|
||||
z_size += 1;
|
||||
}
|
||||
}
|
||||
println!("final size: {}, {}, {}", x_size+1, y_size+1, z_size+1);
|
||||
// create new empty volume
|
||||
let new_volume = EmptyVolume {
|
||||
memory_start: 0,
|
||||
size_x: x_size + 1,
|
||||
size_y: y_size + 1,
|
||||
size_z: z_size + 1,
|
||||
position: Vector3{x: x_index, y: y_index, z: z_index},
|
||||
color_left: vec![],
|
||||
color_right: vec![],
|
||||
color_top: vec![],
|
||||
color_bottom: vec![],
|
||||
color_back: vec![],
|
||||
color_front: vec![],
|
||||
roughness_left: vec![],
|
||||
roughness_right: vec![],
|
||||
roughness_top: vec![],
|
||||
roughness_bottom: vec![],
|
||||
roughness_back: vec![],
|
||||
roughness_front: vec![],
|
||||
neighbor_left: vec![],
|
||||
neighbor_right: vec![],
|
||||
neighbor_top: vec![],
|
||||
neighbor_bottom: vec![],
|
||||
neighbor_back: vec![],
|
||||
neighbor_front: vec![],
|
||||
};
|
||||
println!("adding neighbor references");
|
||||
// MARK: fill in info in the neighbor octtree
|
||||
let reference = Rc::new(RefCell::new(new_volume));
|
||||
for x in 0..x_size+1 {
|
||||
for y in 0..y_size+1 {
|
||||
for z in 0..z_size+1 {
|
||||
neighbors.set_element(reference.clone(), reference.borrow().position.x + x, reference.borrow().position.y + y, reference.borrow().position.z + z);
|
||||
// fill only the edges
|
||||
/*if x == 0 || x == x_size || y == 0 || y == y_size || z==0 || z == z_size {
|
||||
neighbors.set_element(reference.clone(), reference.borrow().position.x + x, reference.borrow().position.y + y, reference.borrow().position.z + z)
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("add the border information for color and roughness");
|
||||
let x_min_pos;
|
||||
if reference.borrow().position.x == 0 {
|
||||
// will result in an empty color and roughness map.
|
||||
x_min_pos = 0;
|
||||
}
|
||||
else {
|
||||
x_min_pos = reference.borrow().position.x -1;
|
||||
}
|
||||
let y_min_pos;
|
||||
if reference.borrow().position.y == 0 {
|
||||
// will result in an empty color and roughness map.
|
||||
y_min_pos = 0;
|
||||
}
|
||||
else {
|
||||
y_min_pos = reference.borrow().position.y -1;
|
||||
}
|
||||
let z_min_pos;
|
||||
if reference.borrow().position.z == 0 {
|
||||
// will result in an empty color and roughness map.
|
||||
z_min_pos = 0;
|
||||
}
|
||||
else {
|
||||
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;
|
||||
let z_max_pos = reference.borrow().position.z + reference.borrow().size_z;
|
||||
// MARK: bottom face of the volume
|
||||
let mut bottom_colors = vec![];
|
||||
let mut bottom_roughness = vec![];
|
||||
let mut bottom_elements_num = 0;
|
||||
for x in 0..x_size+1 {
|
||||
for y in 0..y_size+1 {
|
||||
if let Some(c) = tree.get_element(reference.borrow().position.x + x, reference.borrow().position.y + y, z_min_pos) {
|
||||
bottom_elements_num += 1;
|
||||
let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
|
||||
bottom_colors.push(u8_color);
|
||||
bottom_roughness.push(128);
|
||||
}
|
||||
else {
|
||||
bottom_colors.push(Vector3 { x: 0, y: 0, z: 0 });
|
||||
bottom_roughness.push(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if bottom_elements_num > 0 {
|
||||
reference.borrow_mut().color_bottom = bottom_colors;
|
||||
reference.borrow_mut().roughness_bottom = bottom_roughness;
|
||||
}
|
||||
else {
|
||||
reference.borrow_mut().color_bottom= vec![];
|
||||
reference.borrow_mut().roughness_bottom= vec![];
|
||||
}
|
||||
// MARK: top face of the volume
|
||||
let mut top_colors = vec![];
|
||||
let mut top_roughness = vec![];
|
||||
let mut top_elements_num = 0;
|
||||
for x in 0..x_size+1 {
|
||||
for y in 0..y_size+1 {
|
||||
if let Some(c) = tree.get_element(reference.borrow().position.x + x, reference.borrow().position.y + y, z_max_pos) {
|
||||
top_elements_num += 1;
|
||||
let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
|
||||
top_colors.push(u8_color);
|
||||
top_roughness.push(128);
|
||||
}
|
||||
else {
|
||||
top_colors.push(Vector3 { x: 0, y: 0, z: 0 });
|
||||
top_roughness.push(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if top_elements_num > 0 {
|
||||
reference.borrow_mut().color_top = top_colors;
|
||||
reference.borrow_mut().roughness_top = top_roughness;
|
||||
}
|
||||
else {
|
||||
reference.borrow_mut().color_top= vec![];
|
||||
reference.borrow_mut().roughness_top= vec![];
|
||||
}
|
||||
|
||||
// MARK: back face of the volume
|
||||
let mut back_colors = vec![];
|
||||
let mut back_roughness = vec![];
|
||||
let mut back_elements_num = 0;
|
||||
for x in 0..x_size+1 {
|
||||
for z in 0..z_size+1 {
|
||||
if let Some(c) = tree.get_element(reference.borrow().position.x + x, y_max_pos, reference.borrow().position.z + z) {
|
||||
back_elements_num += 1;
|
||||
let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
|
||||
back_colors.push(u8_color);
|
||||
back_roughness.push(128);
|
||||
}
|
||||
else {
|
||||
back_colors.push(Vector3 { x: 0, y: 0, z: 0 });
|
||||
back_roughness.push(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if back_elements_num > 0 {
|
||||
reference.borrow_mut().color_back = back_colors;
|
||||
reference.borrow_mut().roughness_back = back_roughness;
|
||||
}
|
||||
else {
|
||||
reference.borrow_mut().color_back= vec![];
|
||||
reference.borrow_mut().roughness_back= vec![];
|
||||
}
|
||||
|
||||
// MARK: front face of the volume
|
||||
let mut front_colors = vec![];
|
||||
let mut front_roughness = vec![];
|
||||
let mut front_elements_num = 0;
|
||||
for x in 0..x_size+1 {
|
||||
for z in 0..z_size+1 {
|
||||
if let Some(c) = tree.get_element(reference.borrow().position.x + x, y_min_pos, reference.borrow().position.z + z) {
|
||||
front_elements_num += 1;
|
||||
let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
|
||||
front_colors.push(u8_color);
|
||||
front_roughness.push(128);
|
||||
}
|
||||
else {
|
||||
front_colors.push(Vector3 { x: 0, y: 0, z: 0 });
|
||||
front_roughness.push(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if front_elements_num > 0 {
|
||||
reference.borrow_mut().color_front = front_colors;
|
||||
reference.borrow_mut().roughness_front = front_roughness;
|
||||
}
|
||||
else {
|
||||
reference.borrow_mut().color_front= vec![];
|
||||
reference.borrow_mut().roughness_front= vec![];
|
||||
}
|
||||
|
||||
// MARK: left face of the volume
|
||||
let mut left_colors = vec![];
|
||||
let mut left_roughness = vec![];
|
||||
let mut left_elements_num = 0;
|
||||
for y in 0..y_size+1 {
|
||||
for z in 0..z_size+1 {
|
||||
if let Some(c) = tree.get_element(x_min_pos, reference.borrow().position.y + y, reference.borrow().position.z + z) {
|
||||
left_elements_num += 1;
|
||||
let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
|
||||
left_colors.push(u8_color);
|
||||
left_roughness.push(128);
|
||||
}
|
||||
else {
|
||||
left_colors.push(Vector3 { x: 0, y: 0, z: 0 });
|
||||
left_roughness.push(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if left_elements_num > 0 {
|
||||
reference.borrow_mut().color_left = left_colors;
|
||||
reference.borrow_mut().roughness_left = left_roughness;
|
||||
}
|
||||
else {
|
||||
reference.borrow_mut().color_left= vec![];
|
||||
reference.borrow_mut().roughness_left= vec![];
|
||||
}
|
||||
|
||||
// MARK: right face of the volume
|
||||
let mut right_colors = vec![];
|
||||
let mut right_roughness = vec![];
|
||||
let mut right_elements_num = 0;
|
||||
for y in 0..y_size+1 {
|
||||
for z in 0..z_size+1 {
|
||||
if let Some(c) = tree.get_element(x_max_pos, reference.borrow().position.y + y, reference.borrow().position.z + z) {
|
||||
right_elements_num += 1;
|
||||
let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
|
||||
right_colors.push(u8_color);
|
||||
right_roughness.push(128);
|
||||
}
|
||||
else {
|
||||
right_colors.push(Vector3 { x: 0, y: 0, z: 0 });
|
||||
right_roughness.push(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if right_elements_num > 0 {
|
||||
reference.borrow_mut().color_right = right_colors;
|
||||
reference.borrow_mut().roughness_right = right_roughness;
|
||||
}
|
||||
else {
|
||||
reference.borrow_mut().color_right= vec![];
|
||||
reference.borrow_mut().roughness_right= vec![];
|
||||
}
|
||||
|
||||
println!("new volume done");
|
||||
//push to the list
|
||||
volumes.push(reference);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue