diff --git a/src/primitives/cube.rs b/src/primitives/cube.rs index fd27a1e..bf439ad 100644 --- a/src/primitives/cube.rs +++ b/src/primitives/cube.rs @@ -11,7 +11,7 @@ pub struct Cube{ pub tex_coord: vertex::Vec2 } -const cube_size: f32 = 0.48; +const cube_size: f32 = 0.5; impl Drawable for Cube { fn draw(& self, topology: &vk::PrimitiveTopology, start_index: usize, scene: &mut Scene) { diff --git a/src/scene.rs b/src/scene.rs index 2b12710..b9b317e 100644 --- a/src/scene.rs +++ b/src/scene.rs @@ -5,6 +5,7 @@ use anyhow::Result; use cgmath::{vec2, vec3, Vector3}; use std::cell::RefCell; +use std::intrinsics::size_of; use std::rc::Rc; use std::time::Instant; @@ -651,22 +652,22 @@ struct EmptyVolume { pub position: Vector3, - pub color_front: Vec>, - pub color_back: Vec>, + pub color_left_rn: Vec>, + pub color_right_rn: Vec>, pub color_top: Vec>, pub color_bottom: Vec>, pub color_back_rn: Vec>, pub color_front_rn: Vec>, - pub roughness_front: Vec>, - pub roughness_back: Vec>, + pub roughness_left_rn: Vec>, + pub roughness_right_rn: Vec>, pub roughness_top: Vec>, pub roughness_bottom: Vec>, pub roughness_back_rn: Vec>, pub roughness_front_rn: Vec>, - pub neighbor_front: Vec>>>, - pub neighbor_back: Vec>>>, + pub neighbor_left_rn: Vec>>>, + pub neighbor_right_rn: Vec>>>, pub neighbor_top: Vec>>>, pub neighbor_bottom: Vec>>>, pub neighbor_back_rn: Vec>>>, @@ -772,20 +773,20 @@ impl EmptyVolume { size_y: y_size + 1, size_z: z_size + 1, position: Vector3{x: x_index, y: y_index, z: z_index}, - color_front: vec![], - color_back: vec![], + color_left_rn: vec![], + color_right_rn: vec![], color_top: vec![], color_bottom: vec![], color_back_rn: vec![], color_front_rn: vec![], - roughness_front: vec![], - roughness_back: vec![], + roughness_left_rn: vec![], + roughness_right_rn: vec![], roughness_top: vec![], roughness_bottom: vec![], roughness_back_rn: vec![], roughness_front_rn: vec![], - neighbor_front: vec![], - neighbor_back: vec![], + neighbor_left_rn: vec![], + neighbor_right_rn: vec![], neighbor_top: vec![], neighbor_bottom: vec![], neighbor_back_rn: vec![], @@ -940,57 +941,57 @@ impl EmptyVolume { } // front face of the volume - let mut front_colors = vec![]; - let mut front_roughness = vec![]; - let mut front_elements_num = 0; + let mut left_colors_rn = vec![]; + let mut left_roughness_rn = vec![]; + let mut left_elements_num_rn = 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) { - front_elements_num += 1; + left_elements_num_rn += 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(Vector3 {x: 128, y: 128, z: 128}); + left_colors_rn.push(u8_color); + left_roughness_rn.push(Vector3 {x: 128, y: 128, z: 128}); } else { - front_colors.push(Vector3 { x: 255, y: 255, z: 255 }); - front_roughness.push(Vector3 {x: 255, y: 255, z: 255}); + left_colors_rn.push(Vector3 { x: 255, y: 255, z: 255 }); + left_roughness_rn.push(Vector3 {x: 255, y: 255, z: 255}); } } } - if front_elements_num > 0 { - reference.borrow_mut().color_front = front_colors; - reference.borrow_mut().roughness_front = front_roughness; + if left_elements_num_rn > 0 { + reference.borrow_mut().color_left_rn = left_colors_rn; + reference.borrow_mut().roughness_left_rn = left_roughness_rn; } else { - reference.borrow_mut().color_front= vec![]; - reference.borrow_mut().roughness_front= vec![]; + reference.borrow_mut().color_left_rn= vec![]; + reference.borrow_mut().roughness_left_rn= vec![]; } // back face of the volume - let mut back_colors = vec![]; - let mut back_roughness = vec![]; - let mut back_elements_num = 0; + let mut right_colors_rn = vec![]; + let mut right_roughness_rn = vec![]; + let mut right_elements_num_rn = 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) { - back_elements_num += 1; + right_elements_num_rn += 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(Vector3 {x: 128, y: 128, z: 128}); + right_colors_rn.push(u8_color); + right_roughness_rn.push(Vector3 {x: 128, y: 128, z: 128}); } else { - back_colors.push(Vector3 { x: 255, y: 255, z: 255 }); - back_roughness.push(Vector3 {x: 255, y: 255, z: 255}); + right_colors_rn.push(Vector3 { x: 255, y: 255, z: 255 }); + right_roughness_rn.push(Vector3 {x: 255, y: 255, z: 255}); } } } - if back_elements_num > 0 { - reference.borrow_mut().color_back = back_colors; - reference.borrow_mut().roughness_back = back_roughness; + if right_elements_num_rn > 0 { + reference.borrow_mut().color_right_rn = right_colors_rn; + reference.borrow_mut().roughness_right_rn = right_roughness_rn; } else { - reference.borrow_mut().color_back= vec![]; - reference.borrow_mut().roughness_back= vec![]; + reference.borrow_mut().color_right_rn= vec![]; + reference.borrow_mut().roughness_right_rn= vec![]; } println!("new volume done"); @@ -1073,7 +1074,7 @@ impl EmptyVolume { reference.borrow_mut().neighbor_top = vec![None]; } - // left face of the volume + // back face of the volume let mut back_neighbors_rn = vec![]; let mut back_elements_num_rn = 0; for x in 0..reference.borrow().size_x { @@ -1094,7 +1095,7 @@ impl EmptyVolume { reference.borrow_mut().neighbor_back_rn = vec![None]; } - // right face of the volume + // front face of the volume let mut front_neighbors_rn = vec![]; let mut front_elements_num_rn = 0; if y_min_pos != 0{ @@ -1117,48 +1118,48 @@ impl EmptyVolume { reference.borrow_mut().neighbor_front_rn = vec![None]; } - // front face of the volume - let mut front_neighbors = vec![]; - let mut front_elements_num = 0; + // left face of the volume + let mut left_neighbors_rn = vec![]; + let mut left_elements_num_rn = 0; 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) { - front_elements_num += 1; - front_neighbors.push(Some(c.clone())); + left_elements_num_rn += 1; + left_neighbors_rn.push(Some(c.clone())); } else { - front_neighbors.push(None); + left_neighbors_rn.push(None); } } } } - if front_elements_num > 0 { - reference.borrow_mut().neighbor_front = front_neighbors; + if left_elements_num_rn > 0 { + reference.borrow_mut().neighbor_left_rn = left_neighbors_rn; } else { - reference.borrow_mut().neighbor_front = vec![None]; + reference.borrow_mut().neighbor_left_rn = vec![None]; } - // back face of the volume - let mut back_neighbors = vec![]; - let mut back_elements_num = 0; + // right face of the volume + let mut right_neighbors_rn = vec![]; + let mut right_elements_num_rn = 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_max_pos, reference.borrow().position.y + y, reference.borrow().position.z + z) { - back_elements_num += 1; - back_neighbors.push(Some(c.clone())); + right_elements_num_rn += 1; + right_neighbors_rn.push(Some(c.clone())); } else { - back_neighbors.push(None); + right_neighbors_rn.push(None); } } } - if back_elements_num > 0 { - reference.borrow_mut().neighbor_back = back_neighbors; + if right_elements_num_rn > 0 { + reference.borrow_mut().neighbor_right_rn = right_neighbors_rn; } else { - reference.borrow_mut().neighbor_back = vec![None]; + reference.borrow_mut().neighbor_right_rn = vec![None]; } } println!("volume creation took {} s", start_time.elapsed().as_millis() as f32 / 1000.0); @@ -1262,6 +1263,54 @@ impl EmptyVolume { quads.push(quad); } } + + //left sides of the volumes, right side of the block + for y in 0..self.size_y { + for z in 0..self.size_z { + let index = y * self.size_z + z; + if self.color_left_rn.len() == 0 { + continue; + } + if self.neighbor_left_rn.len() > index { + if let Some(_) = self.neighbor_left_rn[index] { + continue; + } + } + 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 }, + pos2: float_pos + Vector3 { x: -0.5 + 0.0 as f32, y: y as f32 + 0.5, z: z as f32 + 0.5 }, + pos3: float_pos + Vector3 { x: -0.5 + 0.0 as f32, y: y as f32 + 0.5, z: z as f32 - 0.5 }, + raster_pos: cgmath::Vector2 { x: y as u32, y: z as u32 }, + volume_index: 0 + }; + quads.push(quad); + } + } + + //right sides of the volumes, left side of the block + for y in 0..self.size_y { + for z in 0..self.size_z { + let index = y * self.size_z + z; + if self.color_right_rn.len() == 0 { + continue; + } + if self.neighbor_right_rn.len() > index { + if let Some(_) = self.neighbor_right_rn[index] { + continue; + } + } + 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 }, + pos3: float_pos + Vector3 { x: -0.5 + self.size_x as f32, y: y as f32 + 0.5, z: z as f32 + 0.5 }, + pos2: float_pos + Vector3 { x: -0.5 + self.size_x as f32, y: y as f32 + 0.5, z: z as f32 - 0.5 }, + raster_pos: cgmath::Vector2 { x: y as u32, y: z as u32 }, + volume_index: 0 + }; + quads.push(quad); + } + } quads } }