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 more