6 sides quad
This commit is contained in:
parent
f16eab798d
commit
c733c0519f
2 changed files with 108 additions and 59 deletions
|
@ -11,7 +11,7 @@ pub struct Cube{
|
||||||
pub tex_coord: vertex::Vec2
|
pub tex_coord: vertex::Vec2
|
||||||
}
|
}
|
||||||
|
|
||||||
const cube_size: f32 = 0.48;
|
const cube_size: f32 = 0.5;
|
||||||
|
|
||||||
impl Drawable for Cube {
|
impl Drawable for Cube {
|
||||||
fn draw(& self, topology: &vk::PrimitiveTopology, start_index: usize, scene: &mut Scene) {
|
fn draw(& self, topology: &vk::PrimitiveTopology, start_index: usize, scene: &mut Scene) {
|
||||||
|
|
165
src/scene.rs
165
src/scene.rs
|
@ -5,6 +5,7 @@ use anyhow::Result;
|
||||||
use cgmath::{vec2, vec3, Vector3};
|
use cgmath::{vec2, vec3, Vector3};
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
use std::intrinsics::size_of;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
@ -651,22 +652,22 @@ struct EmptyVolume {
|
||||||
|
|
||||||
pub position: Vector3<usize>,
|
pub position: Vector3<usize>,
|
||||||
|
|
||||||
pub color_front: Vec<Vector3<u8>>,
|
pub color_left_rn: Vec<Vector3<u8>>,
|
||||||
pub color_back: Vec<Vector3<u8>>,
|
pub color_right_rn: Vec<Vector3<u8>>,
|
||||||
pub color_top: Vec<Vector3<u8>>,
|
pub color_top: Vec<Vector3<u8>>,
|
||||||
pub color_bottom: Vec<Vector3<u8>>,
|
pub color_bottom: Vec<Vector3<u8>>,
|
||||||
pub color_back_rn: Vec<Vector3<u8>>,
|
pub color_back_rn: Vec<Vector3<u8>>,
|
||||||
pub color_front_rn: Vec<Vector3<u8>>,
|
pub color_front_rn: Vec<Vector3<u8>>,
|
||||||
|
|
||||||
pub roughness_front: Vec<Vector3<u8>>,
|
pub roughness_left_rn: Vec<Vector3<u8>>,
|
||||||
pub roughness_back: Vec<Vector3<u8>>,
|
pub roughness_right_rn: Vec<Vector3<u8>>,
|
||||||
pub roughness_top: Vec<Vector3<u8>>,
|
pub roughness_top: Vec<Vector3<u8>>,
|
||||||
pub roughness_bottom: Vec<Vector3<u8>>,
|
pub roughness_bottom: Vec<Vector3<u8>>,
|
||||||
pub roughness_back_rn: Vec<Vector3<u8>>,
|
pub roughness_back_rn: Vec<Vector3<u8>>,
|
||||||
pub roughness_front_rn: Vec<Vector3<u8>>,
|
pub roughness_front_rn: Vec<Vector3<u8>>,
|
||||||
|
|
||||||
pub neighbor_front: Vec<Option<Rc<RefCell<Self>>>>,
|
pub neighbor_left_rn: Vec<Option<Rc<RefCell<Self>>>>,
|
||||||
pub neighbor_back: Vec<Option<Rc<RefCell<Self>>>>,
|
pub neighbor_right_rn: Vec<Option<Rc<RefCell<Self>>>>,
|
||||||
pub neighbor_top: Vec<Option<Rc<RefCell<Self>>>>,
|
pub neighbor_top: Vec<Option<Rc<RefCell<Self>>>>,
|
||||||
pub neighbor_bottom: Vec<Option<Rc<RefCell<Self>>>>,
|
pub neighbor_bottom: Vec<Option<Rc<RefCell<Self>>>>,
|
||||||
pub neighbor_back_rn: Vec<Option<Rc<RefCell<Self>>>>,
|
pub neighbor_back_rn: Vec<Option<Rc<RefCell<Self>>>>,
|
||||||
|
@ -772,20 +773,20 @@ impl EmptyVolume {
|
||||||
size_y: y_size + 1,
|
size_y: y_size + 1,
|
||||||
size_z: z_size + 1,
|
size_z: z_size + 1,
|
||||||
position: Vector3{x: x_index, y: y_index, z: z_index},
|
position: Vector3{x: x_index, y: y_index, z: z_index},
|
||||||
color_front: vec![],
|
color_left_rn: vec![],
|
||||||
color_back: vec![],
|
color_right_rn: vec![],
|
||||||
color_top: vec![],
|
color_top: vec![],
|
||||||
color_bottom: vec![],
|
color_bottom: vec![],
|
||||||
color_back_rn: vec![],
|
color_back_rn: vec![],
|
||||||
color_front_rn: vec![],
|
color_front_rn: vec![],
|
||||||
roughness_front: vec![],
|
roughness_left_rn: vec![],
|
||||||
roughness_back: vec![],
|
roughness_right_rn: vec![],
|
||||||
roughness_top: vec![],
|
roughness_top: vec![],
|
||||||
roughness_bottom: vec![],
|
roughness_bottom: vec![],
|
||||||
roughness_back_rn: vec![],
|
roughness_back_rn: vec![],
|
||||||
roughness_front_rn: vec![],
|
roughness_front_rn: vec![],
|
||||||
neighbor_front: vec![],
|
neighbor_left_rn: vec![],
|
||||||
neighbor_back: vec![],
|
neighbor_right_rn: vec![],
|
||||||
neighbor_top: vec![],
|
neighbor_top: vec![],
|
||||||
neighbor_bottom: vec![],
|
neighbor_bottom: vec![],
|
||||||
neighbor_back_rn: vec![],
|
neighbor_back_rn: vec![],
|
||||||
|
@ -940,57 +941,57 @@ impl EmptyVolume {
|
||||||
}
|
}
|
||||||
|
|
||||||
// front face of the volume
|
// front face of the volume
|
||||||
let mut front_colors = vec![];
|
let mut left_colors_rn = vec![];
|
||||||
let mut front_roughness = vec![];
|
let mut left_roughness_rn = vec![];
|
||||||
let mut front_elements_num = 0;
|
let mut left_elements_num_rn = 0;
|
||||||
for y in 0..y_size+1 {
|
for y in 0..y_size+1 {
|
||||||
for z in 0..z_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) {
|
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};
|
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);
|
left_colors_rn.push(u8_color);
|
||||||
front_roughness.push(Vector3 {x: 128, y: 128, z: 128});
|
left_roughness_rn.push(Vector3 {x: 128, y: 128, z: 128});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
front_colors.push(Vector3 { x: 255, y: 255, z: 255 });
|
left_colors_rn.push(Vector3 { x: 255, y: 255, z: 255 });
|
||||||
front_roughness.push(Vector3 {x: 255, y: 255, z: 255});
|
left_roughness_rn.push(Vector3 {x: 255, y: 255, z: 255});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if front_elements_num > 0 {
|
if left_elements_num_rn > 0 {
|
||||||
reference.borrow_mut().color_front = front_colors;
|
reference.borrow_mut().color_left_rn = left_colors_rn;
|
||||||
reference.borrow_mut().roughness_front = front_roughness;
|
reference.borrow_mut().roughness_left_rn = left_roughness_rn;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
reference.borrow_mut().color_front= vec![];
|
reference.borrow_mut().color_left_rn= vec![];
|
||||||
reference.borrow_mut().roughness_front= vec![];
|
reference.borrow_mut().roughness_left_rn= vec![];
|
||||||
}
|
}
|
||||||
|
|
||||||
// back face of the volume
|
// back face of the volume
|
||||||
let mut back_colors = vec![];
|
let mut right_colors_rn = vec![];
|
||||||
let mut back_roughness = vec![];
|
let mut right_roughness_rn = vec![];
|
||||||
let mut back_elements_num = 0;
|
let mut right_elements_num_rn = 0;
|
||||||
for y in 0..y_size+1 {
|
for y in 0..y_size+1 {
|
||||||
for z in 0..z_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) {
|
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};
|
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);
|
right_colors_rn.push(u8_color);
|
||||||
back_roughness.push(Vector3 {x: 128, y: 128, z: 128});
|
right_roughness_rn.push(Vector3 {x: 128, y: 128, z: 128});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
back_colors.push(Vector3 { x: 255, y: 255, z: 255 });
|
right_colors_rn.push(Vector3 { x: 255, y: 255, z: 255 });
|
||||||
back_roughness.push(Vector3 {x: 255, y: 255, z: 255});
|
right_roughness_rn.push(Vector3 {x: 255, y: 255, z: 255});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if back_elements_num > 0 {
|
if right_elements_num_rn > 0 {
|
||||||
reference.borrow_mut().color_back = back_colors;
|
reference.borrow_mut().color_right_rn = right_colors_rn;
|
||||||
reference.borrow_mut().roughness_back = back_roughness;
|
reference.borrow_mut().roughness_right_rn = right_roughness_rn;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
reference.borrow_mut().color_back= vec![];
|
reference.borrow_mut().color_right_rn= vec![];
|
||||||
reference.borrow_mut().roughness_back= vec![];
|
reference.borrow_mut().roughness_right_rn= vec![];
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("new volume done");
|
println!("new volume done");
|
||||||
|
@ -1073,7 +1074,7 @@ impl EmptyVolume {
|
||||||
reference.borrow_mut().neighbor_top = vec![None];
|
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_neighbors_rn = vec![];
|
||||||
let mut back_elements_num_rn = 0;
|
let mut back_elements_num_rn = 0;
|
||||||
for x in 0..reference.borrow().size_x {
|
for x in 0..reference.borrow().size_x {
|
||||||
|
@ -1094,7 +1095,7 @@ impl EmptyVolume {
|
||||||
reference.borrow_mut().neighbor_back_rn = vec![None];
|
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_neighbors_rn = vec![];
|
||||||
let mut front_elements_num_rn = 0;
|
let mut front_elements_num_rn = 0;
|
||||||
if y_min_pos != 0{
|
if y_min_pos != 0{
|
||||||
|
@ -1117,48 +1118,48 @@ impl EmptyVolume {
|
||||||
reference.borrow_mut().neighbor_front_rn = vec![None];
|
reference.borrow_mut().neighbor_front_rn = vec![None];
|
||||||
}
|
}
|
||||||
|
|
||||||
// front face of the volume
|
// left face of the volume
|
||||||
let mut front_neighbors = vec![];
|
let mut left_neighbors_rn = vec![];
|
||||||
let mut front_elements_num = 0;
|
let mut left_elements_num_rn = 0;
|
||||||
if x_min_pos != 0 {
|
if x_min_pos != 0 {
|
||||||
for y in 0..reference.borrow().size_y {
|
for y in 0..reference.borrow().size_y {
|
||||||
for z in 0..reference.borrow().size_z {
|
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) {
|
if let Some(c) = neighbors.get_element(x_min_pos, reference.borrow().position.y + y, reference.borrow().position.z + z) {
|
||||||
front_elements_num += 1;
|
left_elements_num_rn += 1;
|
||||||
front_neighbors.push(Some(c.clone()));
|
left_neighbors_rn.push(Some(c.clone()));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
front_neighbors.push(None);
|
left_neighbors_rn.push(None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if front_elements_num > 0 {
|
if left_elements_num_rn > 0 {
|
||||||
reference.borrow_mut().neighbor_front = front_neighbors;
|
reference.borrow_mut().neighbor_left_rn = left_neighbors_rn;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
reference.borrow_mut().neighbor_front = vec![None];
|
reference.borrow_mut().neighbor_left_rn = vec![None];
|
||||||
}
|
}
|
||||||
|
|
||||||
// back face of the volume
|
// right face of the volume
|
||||||
let mut back_neighbors = vec![];
|
let mut right_neighbors_rn = vec![];
|
||||||
let mut back_elements_num = 0;
|
let mut right_elements_num_rn = 0;
|
||||||
for y in 0..reference.borrow().size_y {
|
for y in 0..reference.borrow().size_y {
|
||||||
for z in 0..reference.borrow().size_z {
|
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) {
|
if let Some(c) = neighbors.get_element(x_max_pos, reference.borrow().position.y + y, reference.borrow().position.z + z) {
|
||||||
back_elements_num += 1;
|
right_elements_num_rn += 1;
|
||||||
back_neighbors.push(Some(c.clone()));
|
right_neighbors_rn.push(Some(c.clone()));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
back_neighbors.push(None);
|
right_neighbors_rn.push(None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if back_elements_num > 0 {
|
if right_elements_num_rn > 0 {
|
||||||
reference.borrow_mut().neighbor_back = back_neighbors;
|
reference.borrow_mut().neighbor_right_rn = right_neighbors_rn;
|
||||||
}
|
}
|
||||||
else {
|
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);
|
println!("volume creation took {} s", start_time.elapsed().as_millis() as f32 / 1000.0);
|
||||||
|
@ -1262,6 +1263,54 @@ impl EmptyVolume {
|
||||||
quads.push(quad);
|
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
|
quads
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue