Skip to main content

SpriteModelRegistry

Struct SpriteModelRegistry 

Source
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

Source

pub fn new() -> Self

Source

pub fn add(&mut self, model: SpriteModel) -> u32

Register a single-level (no-LOD) model; returns its model_id.

Source

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.

Source

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.

Source

pub fn model(&self, id: u32) -> &SpriteModel

The finest (mip-0) model of chain id.

Source

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.

Source

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

Source

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.

Source

pub fn len(&self) -> usize

Number of LOD chains (distinct model_ids).

Source

pub fn is_empty(&self) -> bool

Trait Implementations§

Source§

impl Clone for SpriteModelRegistry

Source§

fn clone(&self) -> SpriteModelRegistry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SpriteModelRegistry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SpriteModelRegistry

Source§

fn default() -> SpriteModelRegistry

Returns the “default value” for a type. Read more

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,