pub struct ChunkedMeshCache { /* private fields */ }Expand description
Thread-safe chunked incremental mesh cache.
Divides the SDF evaluation space into a uniform grid of chunks. Each chunk is independently cached and can be marked dirty when the underlying SDF changes — either globally or within a specific region.
Implementations§
Source§impl ChunkedMeshCache
impl ChunkedMeshCache
Sourcepub fn new(config: ChunkedCacheConfig) -> Self
pub fn new(config: ChunkedCacheConfig) -> Self
Create a new chunked mesh cache.
Sourcepub fn get_chunk(&self, coord: &ChunkCoord) -> Option<Arc<Mesh>>
pub fn get_chunk(&self, coord: &ChunkCoord) -> Option<Arc<Mesh>>
Get the chunk mesh at the given coordinate, if cached and valid.
Sourcepub fn set_chunk(&self, coord: ChunkCoord, mesh: Mesh, sdf_hash: u64)
pub fn set_chunk(&self, coord: ChunkCoord, mesh: Mesh, sdf_hash: u64)
Insert or update a chunk mesh.
Uses FIFO eviction: when at capacity, the oldest-inserted chunk is removed first — deterministic and cache-friendly compared to random.
Sourcepub fn invalidate_all(&self)
pub fn invalidate_all(&self)
Mark all chunks as dirty (e.g. the SDF changed globally).
Sourcepub fn invalidate_region(&self, min: Vec3, max: Vec3)
pub fn invalidate_region(&self, min: Vec3, max: Vec3)
Mark chunks overlapping a world-space bounding box as dirty.
Sourcepub fn dirty_chunks(&self) -> Vec<ChunkCoord>
pub fn dirty_chunks(&self) -> Vec<ChunkCoord>
Get the coordinates of all currently dirty chunks.
Sourcepub fn update_sdf_hash(&self, new_hash: u64) -> Vec<ChunkCoord>
pub fn update_sdf_hash(&self, new_hash: u64) -> Vec<ChunkCoord>
Update the global SDF hash. Returns the list of chunks that were
invalidated (those whose stored hash differs from new_hash).
Sourcepub fn cached_chunks(&self) -> Vec<ChunkCoord>
pub fn cached_chunks(&self) -> Vec<ChunkCoord>
Get all cached chunk coordinates.
Sourcepub fn chunk_count(&self) -> usize
pub fn chunk_count(&self) -> usize
Number of cached chunks.
Sourcepub fn memory_usage(&self) -> usize
pub fn memory_usage(&self) -> usize
Total approximate memory usage of all cached chunk meshes (bytes).
Sourcepub fn world_to_chunk(&self, pos: Vec3) -> ChunkCoord
pub fn world_to_chunk(&self, pos: Vec3) -> ChunkCoord
Convert a world-space position to its containing chunk coordinate.
Sourcepub fn chunk_bounds(&self, coord: &ChunkCoord) -> (Vec3, Vec3)
pub fn chunk_bounds(&self, coord: &ChunkCoord) -> (Vec3, Vec3)
Get the axis-aligned bounding box (min, max) for a chunk coordinate.
Sourcepub fn chunks_in_bounds(&self, min: Vec3, max: Vec3) -> Vec<ChunkCoord>
pub fn chunks_in_bounds(&self, min: Vec3, max: Vec3) -> Vec<ChunkCoord>
Compute all chunk coordinates required to cover the given bounding box.
Sourcepub fn persist_dirty(&self) -> Result<usize, IoError>
pub fn persist_dirty(&self) -> Result<usize, IoError>
Persist all dirty chunks to disk as individual .abm files.
Requires cache_dir to be set in the configuration. Returns the
number of chunks written.
Sourcepub fn load_chunk(
&self,
coord: &ChunkCoord,
) -> Result<Option<Arc<Mesh>>, IoError>
pub fn load_chunk( &self, coord: &ChunkCoord, ) -> Result<Option<Arc<Mesh>>, IoError>
Load a single chunk from the disk cache. Returns None if the file
does not exist. A chunk that is not cached yet is added at the back of
the FIFO order, evicting the oldest chunk when the cache is full.
Sourcepub fn merge_all(&self) -> Mesh
pub fn merge_all(&self) -> Mesh
Merge all cached chunk meshes into a single combined Mesh.
Vertex positions are preserved in world space. Index offsets are adjusted so the resulting mesh is self-consistent.
Chunks are concatenated in ascending (x, y, z) order of their
ChunkCoord, so the same set of chunks always gives the same vertex
and index order, whatever the insertion order and from one run to the
next (until 5.0.0 the order was that of the internal HashMap, which
changes between runs).
Auto Trait Implementations§
impl !Freeze for ChunkedMeshCache
impl RefUnwindSafe for ChunkedMeshCache
impl Send for ChunkedMeshCache
impl Sync for ChunkedMeshCache
impl Unpin for ChunkedMeshCache
impl UnsafeUnpin for ChunkedMeshCache
impl UnwindSafe for ChunkedMeshCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more