Mark neighbor chunks dirty on LOD change

This commit is contained in:
Elias Stepanik 2025-06-09 13:31:34 +02:00
parent 957c9cffa7
commit 5fa3af97db
2 changed files with 17 additions and 1 deletions

View File

@ -34,5 +34,6 @@ pub fn update_chunk_lods(
for key in changed {
tree.dirty_chunks.insert(key);
tree.mark_neighbors_dirty_from_key(key);
}
}

View File

@ -6,7 +6,7 @@ use bevy::prelude::*;
use bevy::render::mesh::{Indices, PrimitiveTopology, VertexAttributeValues};
use bevy::render::render_asset::RenderAssetUsages;
use crate::plugins::environment::systems::voxels::helper::chunk_key_from_world;
use crate::plugins::environment::systems::voxels::structure::{DirtyVoxel, OctreeNode, Ray, SparseVoxelOctree, Voxel, AABB, NEIGHBOR_OFFSETS};
use crate::plugins::environment::systems::voxels::structure::{DirtyVoxel, OctreeNode, Ray, SparseVoxelOctree, Voxel, AABB, NEIGHBOR_OFFSETS, CHUNK_SIZE, ChunkKey};
impl SparseVoxelOctree {
/// Creates a new octree with the specified max depth, size, and wireframe visibility.
@ -142,6 +142,21 @@ impl SparseVoxelOctree {
}
}
/// Mark all six neighbor chunks of the given key as dirty if they exist.
pub fn mark_neighbors_dirty_from_key(&mut self, key: ChunkKey) {
let offsets = [
(-1, 0, 0), (1, 0, 0),
(0, -1, 0), (0, 1, 0),
(0, 0, -1), (0, 0, 1),
];
for (dx, dy, dz) in offsets {
let neighbor = ChunkKey(key.0 + dx, key.1 + dy, key.2 + dz);
if self.occupied_chunks.contains(&neighbor) {
self.dirty_chunks.insert(neighbor);
}
}
}
fn remove_recursive(
node: &mut OctreeNode,
x: f32,