Skip to main content

ChunkedMeshCache

Struct ChunkedMeshCache 

Source
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

Source

pub fn new(config: ChunkedCacheConfig) -> Self

Create a new chunked mesh cache.

Source

pub fn get_chunk(&self, coord: &ChunkCoord) -> Option<Arc<Mesh>>

Get the chunk mesh at the given coordinate, if cached and valid.

Source

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.

Source

pub fn invalidate_all(&self)

Mark all chunks as dirty (e.g. the SDF changed globally).

Source

pub fn invalidate_region(&self, min: Vec3, max: Vec3)

Mark chunks overlapping a world-space bounding box as dirty.

Source

pub fn dirty_chunks(&self) -> Vec<ChunkCoord>

Get the coordinates of all currently dirty chunks.

Source

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).

Source

pub fn cached_chunks(&self) -> Vec<ChunkCoord>

Get all cached chunk coordinates.

Source

pub fn chunk_count(&self) -> usize

Number of cached chunks.

Source

pub fn memory_usage(&self) -> usize

Total approximate memory usage of all cached chunk meshes (bytes).

Source

pub fn world_to_chunk(&self, pos: Vec3) -> ChunkCoord

Convert a world-space position to its containing chunk coordinate.

Source

pub fn chunk_bounds(&self, coord: &ChunkCoord) -> (Vec3, Vec3)

Get the axis-aligned bounding box (min, max) for a chunk coordinate.

Source

pub fn chunks_in_bounds(&self, min: Vec3, max: Vec3) -> Vec<ChunkCoord>

Compute all chunk coordinates required to cover the given bounding box.

Source

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.

Source

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.

Source

pub fn clear(&self)

Clear all cached chunks.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.