diff --git a/src/adj.rs b/src/adj.rs index 4f4a75f..699e04a 100644 --- a/src/adj.rs +++ b/src/adj.rs @@ -32,36 +32,74 @@ pub fn introduce_adjacent_chunks( } } update_mesh(main_mesh, main_md, reg); - - if let Some(pbs) = main_md.pbs { - for index in iter_faces_of_chunk(dims, connection_side) { - if main_md - .vivi - .get_quad_index(connection_side, index) - .is_some() - { - let adj_voxel_index = get_neigbhor_across_chunk(dims, index, connection_side); - let mut closest_voxels = [false; 6]; - for i in 0..6 { - let tmp_face = Face::from(i); - if let Some(neighbor) = get_neighbor(adj_voxel_index, tmp_face, dims) { - closest_voxels[i] = - reg.is_covering(&adjacent_chunk_grid[neighbor], tmp_face.opposite()); - } - } - if closest_voxels != [false; 6] { - apply_pbs_quad( - main_mesh, - &main_md.vivi, - index, - connection_side, - closest_voxels, - pbs, - reg.get_voxel_dimensions(), - dims, - ) - } - } - } - } } + +// if let Some(pbs) = main_md.pbs { +// for index in iter_faces_of_chunk(dims, connection_side) { +// if main_md +// .vivi +// .get_quad_index(connection_side, index) +// .is_some() +// { +// let adj_voxel_index = get_neigbhor_across_chunk(dims, index, connection_side); +// let mut closest_voxels = [false; 6]; +// closest_voxels[connection_side.opposite() as usize] = true; +// for i in 0..6 { +// let tmp_face = Face::from(i); +// if let Some(neighbor) = get_neighbor(adj_voxel_index, tmp_face, dims) { +// closest_voxels[i] = +// reg.is_covering(&adjacent_chunk_grid[neighbor], tmp_face.opposite()); +// } +// } +// if closest_voxels != [false; 6] { +// apply_pbs_quad( +// main_mesh, +// &main_md.vivi, +// index, +// connection_side, +// closest_voxels, +// pbs, +// voxel_dims, +// dims, +// ) +// } +// } else if main_md.vivi.vivi[index].is_empty() { +// let adj_voxel_index = get_neigbhor_across_chunk(dims, index, connection_side); +// let mut closest_voxels = [false; 6]; +// let adj_voxel = adjacent_chunk_grid[adj_voxel_index]; +// if reg.is_covering(&adj_voxel, connection_side.opposite()) { +// for i in 0..6 { +// let face = Face::from(i); +// if let Some(neighbor) = get_neighbor(index, face, dims) { +// closest_voxels[i] = !main_md.vivi.vivi[neighbor].is_empty(); +// } +// } +// closest_voxels[connection_side as usize] = true; +// +// for j in 0..6 { +// let face = Face::from(j); +// if let Some(neighbor) = get_neighbor(index, face, dims) { +// if +// /* !main_md.vivi.vivi[neighbor].is_empty() */ +// main_md +// .vivi +// .get_quad_index(face.opposite(), neighbor) +// .is_some() +// { +// apply_pbs_quad( +// main_mesh, +// &main_md.vivi, +// neighbor, +// face.opposite(), +// closest_voxels, +// pbs, +// voxel_dims, +// dims, +// ) +// } +// } +// } +// } +// } +// } +// } diff --git a/src/face.rs b/src/face.rs index 3c2ce7f..ce910eb 100644 --- a/src/face.rs +++ b/src/face.rs @@ -1,4 +1,4 @@ -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug)] /// This enum represents all the faces of a cubic voxel. pub enum Face { Top, diff --git a/src/pbs.rs b/src/pbs.rs index 2a2399b..cf5ad7f 100644 --- a/src/pbs.rs +++ b/src/pbs.rs @@ -122,10 +122,10 @@ pub(crate) fn apply_pbs( let face = face_from_u32(q & REVERSE_OFFSET_CONST); let mut count = 0; if let Some(neigbhor) = get_neighbor(i, face, dims) { - for i in 0..6 { - if let Some(tmp) = get_neighbor(neigbhor, Face::from(i), dims) { + for j in 0..6 { + if let Some(tmp) = get_neighbor(neigbhor, Face::from(j), dims) { if !vivi.vivi[tmp].is_empty() { - close_voxels[i] = true; + close_voxels[j] = true; count += 1; } } diff --git a/src/util/mod.rs b/src/util/mod.rs index 1163c94..dbe1492 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -119,45 +119,35 @@ pub fn extract_indices_data(mesh: &Mesh) -> Vec<[u32; 3]> { } pub fn iter_faces_of_chunk(dims: Dimensions, face: Face) -> impl Iterator { - let all = 0..(dims.0 * dims.1 * dims.2); - let m = [dims.1 - 1, 0, dims.0 - 1, 0, dims.2 - 1, 0]; - let i = match face { - Top | Bottom => 1, - Right | Left => 0, - Forward | Back => 2, - }; - let all = all.filter(move |x| three_d_cords_arr(*x, dims)[i] == m[face as usize]); - all + (0..(dims.0 * dims.1 * dims.2)) + .into_iter() + .filter(move |x| is_block_on_edge(dims, *x, face)) } -pub fn is_block_on_edge(dims: Dimensions, index: usize) -> Vec { +pub fn block_edges(dims: Dimensions, index: usize) -> Vec { let mut to_return = vec![]; - let m = [dims.1 - 1, 0, dims.0 - 1, 0, dims.2 - 1, 0]; for i in 0..6 { let face = Face::from(i); - let j = match face { - Top | Bottom => 1, - Right | Left => 0, - Forward | Back => 2, - }; - if three_d_cords_arr(index, dims)[j] == m[face as usize] { + if get_neighbor(index, face, dims).is_none() { to_return.push(face); } } to_return } +pub fn is_block_on_edge(dims: Dimensions, index: usize, face: Face) -> bool { + get_neighbor(index, face, dims).is_none() +} + pub fn get_neigbhor_across_chunk(dims: Dimensions, index: usize, face: Face) -> usize { - for f in is_block_on_edge(dims, index) { - if f as usize == face as usize { - return match face { - Right => index - dims.0 + 1, - Left => index + dims.0 - 1, - Back => index - dims.0 * (dims.2 - 1), - Forward => index + dims.0 * (dims.2 - 1), - _ => panic!("Shouldn't happen"), - }; - } + if is_block_on_edge(dims, index, face) { + return match face { + Right => index - dims.0 + 1, + Left => index + dims.0 - 1, + Back => index - dims.0 * (dims.2 - 1), + Forward => index + dims.0 * (dims.2 - 1), + _ => panic!("Shouldn't happen"), + }; } panic!("`get_neigbhor_across_chunk` was called on a block that wasn't on the edge of a chunk"); } @@ -180,7 +170,7 @@ pub fn get_neighbor(voxel: usize, face: Face, dims: Dimensions) -> Option } pub fn get_neigbhors_from_across_chunks(dims: Dimensions, index: usize) -> Vec<(Face, usize)> { - let edges = is_block_on_edge(dims, index); + let edges = block_edges(dims, index); if edges.is_empty() { return vec![]; }