Skip to main content

SpriteModel

Struct SpriteModel 

Source
pub struct SpriteModel {
    pub dims: [u32; 3],
    pub occ_words_per_col: u32,
    pub pivot: [f32; 3],
    pub occupancy: Vec<u32>,
    pub colors: Vec<u32>,
    pub color_offsets: Vec<u32>,
    pub voxel_world_size: f32,
}
Expand description

CPU-built voxel volume for one KV6 model.

Fields§

§dims: [u32; 3]

Voxel extent (mx, my, mz).

§occ_words_per_col: u32

ceil(mz / 32) — u32 words of occupancy per (x, y) column.

§pivot: [f32; 3]

KV6 pivot in model-local voxel space.

§occupancy: Vec<u32>

Per-column occupancy bitmask, mx * my * occ_words_per_col.

§colors: Vec<u32>

Voxel colours, ascending z within each column.

§color_offsets: Vec<u32>

Prefix sums: color_offsets[col] is the first colour index of column col; length mx * my + 1.

§voxel_world_size: f32

World-space size of one voxel of this model (GPU.10.4 LOD): 1.0 at mip-0, doubling each SpriteModel::downsample. The shader divides the local ray by this so a coarse voxel spans the right world extent and the march t stays in world units.

Implementations§

Source§

impl SpriteModel

Source

pub fn recolor(&mut self, f: impl Fn(u32) -> u32)

Recolour every voxel via f(old_rgba) -> new_rgba. Structure (occupancy / offsets) is untouched, so this is a cheap in-place edit — handy on a SpriteModelRegistry::fork to make a tinted variant. For structural edits, mutate the public occupancy / colours / dims directly (via model_mut) then rebuild the LOD.

Source

pub fn set_voxel(&mut self, x: u32, y: u32, z: u32, color: Option<u32>) -> bool

GPU.12 — structural edit of a single voxel within the model’s existing bounds. Some(rgba) sets/replaces the voxel at (x, y, z); None clears it. Maintains the ascending-z colour invariant by inserting/removing at the voxel’s popcount rank and shifting the affected columns’ color_offsets. Returns true if the model changed. Out-of-bounds coordinates are ignored (returns false) — growing dims is a separate concern.

After editing, call SpriteModelRegistry::rebuild_lod to refresh coarser mips, then re-upload via set_sprite_instances.

Source

pub fn bound_radius(&self) -> f32

Radius of a bounding sphere centred at the instance position (the pivot maps there): the farthest bbox corner from the pivot. Used for frustum culling. Assumes a unit basis; scaled instances would multiply this by their max basis length.

Source

pub fn downsample(&self) -> SpriteModel

GPU.10.4 — 2× voxel downsample for the next LOD level. A coarse voxel is solid if any of its 2×2×2 fine voxels is, coloured by their per-channel average. Dims/pivot halve and voxel_world_size doubles, so the coarse model occupies the same world box at half the resolution (origin-corner aligned).

Trait Implementations§

Source§

impl Clone for SpriteModel

Source§

fn clone(&self) -> SpriteModel

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 SpriteModel

Source§

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

Formats the value using the given formatter. 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,