use crate::prelude::*;
use bevy::prelude::*;
pub fn introduce_adjacent_chunks<T: std::fmt::Debug + Sized + Copy>(
reg: &impl VoxelRegistry<Voxel = T>,
main_mesh: &mut Mesh,
main_md: &mut MeshMD<T>,
connection_side: Face,
adjacent_chunk_grid: &[T],
) {
assert_eq!(
adjacent_chunk_grid.len(),
main_md.vivi.vivi.len(),
"Cannot introduce chunks with different sizes to each other"
);
let dims = main_md.dims;
for index in iter_faces_of_chunk(dims, connection_side) {
let adj_voxel_index = get_neigbhor_across_chunk_safe(dims, index, connection_side);
let adj_voxel_index = if adj_voxel_index.is_some() {
adj_voxel_index.unwrap()
} else {
continue;
};
let adj_voxel = adjacent_chunk_grid[adj_voxel_index];
if reg.is_covering(&adj_voxel, connection_side.opposite()) {
let mut tmp = [None; 6];
tmp[connection_side as usize] = Some(adj_voxel);
main_md.log(VoxelChange::CullFaces, index, adj_voxel, tmp)
}
}
update_mesh(main_mesh, main_md, reg);
}