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: u32ceil(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: f32World-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
impl SpriteModel
Sourcepub fn recolor(&mut self, f: impl Fn(u32) -> u32)
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.
Sourcepub fn set_voxel(&mut self, x: u32, y: u32, z: u32, color: Option<u32>) -> bool
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.
Sourcepub fn bound_radius(&self) -> f32
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.
Sourcepub fn downsample(&self) -> SpriteModel
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
impl Clone for SpriteModel
Source§fn clone(&self) -> SpriteModel
fn clone(&self) -> SpriteModel
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for SpriteModel
impl RefUnwindSafe for SpriteModel
impl Send for SpriteModel
impl Sync for SpriteModel
impl Unpin for SpriteModel
impl UnsafeUnpin for SpriteModel
impl UnwindSafe for SpriteModel
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.