mirror of
https://github.com/eliasstepanik/voxel-simulation.git
synced 2026-01-11 05:48:29 +00:00
Mark neighbor chunks dirty on LOD change
This commit is contained in:
parent
957c9cffa7
commit
5fa3af97db
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user