pub struct SpriteModelRegistry { /* private fields */ }Expand description
A registry of sprite models. Instances reference a model by
model_id, which is a LOD chain id: each chain holds one or
more concrete mip levels (finest first; GPU.10.4), and the renderer
picks the level per instance by distance. Identical KV6s are added
once and shared by many instances. Copy-on-modify:
Self::fork deep-copies a chain so edits to the fork leave the
parent (and its instances) intact.
Implementations§
Source§impl SpriteModelRegistry
impl SpriteModelRegistry
pub fn new() -> Self
Sourcepub fn add(&mut self, model: SpriteModel) -> u32
pub fn add(&mut self, model: SpriteModel) -> u32
Register a single-level (no-LOD) model; returns its model_id.
Sourcepub fn add_lod(&mut self, model: SpriteModel, max_levels: u32) -> u32
pub fn add_lod(&mut self, model: SpriteModel, max_levels: u32) -> u32
Register a model with up to max_levels LOD mips (each a 2×
SpriteModel::downsample of the previous; stops early once a
level collapses to 1³). Returns its model_id.
Sourcepub fn fork(&mut self, parent: u32) -> u32
pub fn fork(&mut self, parent: u32) -> u32
Copy-on-modify: deep-copy every level of chain parent into new
entries + a new chain, and return its model_id. The fork owns
independent voxel data, so mutating it does not affect the
parent or any instance still pointing at it.
§Panics
If parent is not a registered model_id.
Sourcepub fn model(&self, id: u32) -> &SpriteModel
pub fn model(&self, id: u32) -> &SpriteModel
The finest (mip-0) model of chain id.
Sourcepub fn model_checked(&self, id: u32) -> Option<&SpriteModel>
pub fn model_checked(&self, id: u32) -> Option<&SpriteModel>
Like Self::model but returns None for an out-of-range or
tombstoned (emptied) chain instead of panicking — the guarded form
for public primitives handed an arbitrary chain_id.
Sourcepub fn model_mut(&mut self, id: u32) -> &mut SpriteModel
pub fn model_mut(&mut self, id: u32) -> &mut SpriteModel
Mutable access to the finest (mip-0) model for editing — the
copy-on-modify entry point (typically on a Self::fork).
After a structural edit (occupancy/dims), call
Self::rebuild_lod so the coarser mips match; a pure recolour
can use Self::recolor_chain instead.
Sourcepub fn recolor_chain(&mut self, id: u32, f: impl Fn(u32) -> u32 + Copy)
pub fn recolor_chain(&mut self, id: u32, f: impl Fn(u32) -> u32 + Copy)
Recolour every LOD level of chain id (so a forked tint shows
at all distances).
Sourcepub fn rebuild_lod(&mut self, id: u32)
pub fn rebuild_lod(&mut self, id: u32)
Regenerate chain id’s coarser mip levels from its (possibly
just-edited) mip-0. Run after a structural edit via
Self::model_mut so the LOD ladder stays consistent. No-op
for a single-level (no-LOD) chain.
Sourcepub fn remove(&mut self, chain_id: u32)
pub fn remove(&mut self, chain_id: u32)
Free chain chain_id’s voxel data in place: replace each of
its LOD entries with SpriteModel::empty and clear the chain.
Entry ids and every other model_id are preserved (the chain
becomes empty, its entries become placeholders), so no id remap is
needed and the resident registry’s entry alignment stays intact.
This is safe to pair with the resident side because
SpriteRegistryResident::remove_model tombstones the same
entries (dead[e]) and compact
reads only live entries — so the resident never touches the empty
placeholders left here. Call remove_model (resident) before
this so those tombstones are set. No-op if chain_id is out of
range or already removed.
Sourcepub fn is_live(&self, chain_id: u32) -> bool
pub fn is_live(&self, chain_id: u32) -> bool
Whether chain_id is a live (registered, not removed)
model. false for an out-of-range id or a tombstoned chain.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of LOD chains (distinct model_ids). Counts tombstoned
(removed) chains too — ids are never reused, so this is also the
next id that Self::add / Self::add_lod will mint.
pub fn is_empty(&self) -> bool
Trait Implementations§
Source§impl Clone for SpriteModelRegistry
impl Clone for SpriteModelRegistry
Source§fn clone(&self) -> SpriteModelRegistry
fn clone(&self) -> SpriteModelRegistry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more