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