do not try to use hole mask if holes enabled flag is off

This commit is contained in:
Dmitry Stepanov
2026-03-09 18:33:05 +03:00
parent bc413859a4
commit 66586d9bba
+18 -16
View File
@@ -738,23 +738,25 @@ fn make_heightfield(terrain: &Terrain) -> Option<SharedShape> {
)),
Vector3::new(x_scale, 1.0, z_scale),
);
hf.cells_statuses_mut()
.fill(HeightFieldCellStatus::CELL_REMOVED);
let hole_mask_size = terrain.hole_mask_size();
for chunk in terrain.chunks_ref() {
let texture = chunk.hole_mask().map(|t| t.data_ref());
let hole_mask = texture.as_ref().map(|t| t.data_of_type::<u8>().unwrap());
let pos = (chunk.grid_position() - chunk_min).map(|x| x as u32);
let (ox, oy) = (pos.x * chunk_size.x, pos.y * chunk_size.y);
if terrain.holes_enabled() {
hf.cells_statuses_mut()
.fill(HeightFieldCellStatus::CELL_REMOVED);
let hole_mask_size = terrain.hole_mask_size();
for chunk in terrain.chunks_ref() {
let texture = chunk.hole_mask().map(|t| t.data_ref());
let hole_mask = texture.as_ref().map(|t| t.data_of_type::<u8>().unwrap());
let pos = (chunk.grid_position() - chunk_min).map(|x| x as u32);
let (ox, oy) = (pos.x * chunk_size.x, pos.y * chunk_size.y);
for iy in 0..hole_mask_size.y {
for ix in 0..hole_mask_size.x {
let is_hole = hole_mask
.map(|m| m[(iy * hole_mask_size.x + ix) as usize] < 128)
.unwrap_or_default();
let (x, y) = (ox + ix, oy + iy);
if !is_hole {
hf.set_cell_status(y as usize, x as usize, HeightFieldCellStatus::empty());
for iy in 0..hole_mask_size.y {
for ix in 0..hole_mask_size.x {
let is_hole = hole_mask
.map(|m| m[(iy * hole_mask_size.x + ix) as usize] < 128)
.unwrap_or_default();
let (x, y) = (ox + ix, oy + iy);
if !is_hole {
hf.set_cell_status(y as usize, x as usize, HeightFieldCellStatus::empty());
}
}
}
}