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 moreSource§impl Debug for SpriteModelRegistry
impl Debug for SpriteModelRegistry
Source§impl Default for SpriteModelRegistry
impl Default for SpriteModelRegistry
Source§fn default() -> SpriteModelRegistry
fn default() -> SpriteModelRegistry
Auto Trait Implementations§
impl Freeze for SpriteModelRegistry
impl RefUnwindSafe for SpriteModelRegistry
impl Send for SpriteModelRegistry
impl Sync for SpriteModelRegistry
impl Unpin for SpriteModelRegistry
impl UnsafeUnpin for SpriteModelRegistry
impl UnwindSafe for SpriteModelRegistry
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.