mirror of
https://github.com/eliasstepanik/voxel-simulation.git
synced 2026-01-11 05:48:29 +00:00
fix lod distance calculation
This commit is contained in:
parent
4e1597aaa8
commit
ba5ccb8fb7
@ -1,6 +1,6 @@
|
||||
use bevy::prelude::*;
|
||||
use crate::plugins::environment::systems::voxels::helper::chunk_center_world;
|
||||
use crate::plugins::environment::systems::voxels::structure::{Chunk, ChunkLod, ChunkCullingCfg, SparseVoxelOctree};
|
||||
use crate::plugins::environment::systems::voxels::structure::{Chunk, ChunkLod, ChunkCullingCfg, SparseVoxelOctree, CHUNK_SIZE};
|
||||
|
||||
/// Update each chunk's LOD level based on its distance from the camera.
|
||||
/// Chunks farther away get a higher LOD value (coarser mesh).
|
||||
@ -11,20 +11,19 @@ pub fn update_chunk_lods(
|
||||
cfg: Res<ChunkCullingCfg>,
|
||||
) {
|
||||
let cam_pos = cam_q.single().translation();
|
||||
let max_depth;
|
||||
let range_step;
|
||||
let (max_depth, range_step, chunk_size);
|
||||
{
|
||||
let tree = tree_q.single();
|
||||
max_depth = tree.max_depth;
|
||||
range_step = cfg.view_distance_chunks as f32 / max_depth as f32;
|
||||
chunk_size = CHUNK_SIZE as f32 * tree.get_spacing_at_depth(max_depth);
|
||||
}
|
||||
|
||||
let mut changed = Vec::new();
|
||||
for (chunk, mut lod) in chunks.iter_mut() {
|
||||
let tree = tree_q.single();
|
||||
let center = chunk_center_world(&tree, chunk.key);
|
||||
let dist_chunks = cam_pos.distance(center)
|
||||
/ (cfg.view_distance_chunks as f32);
|
||||
let dist_chunks = cam_pos.distance(center) / chunk_size;
|
||||
let mut level = (dist_chunks / range_step).floor() as u32;
|
||||
if level > max_depth { level = max_depth; }
|
||||
if lod.0 != level {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user