pub struct Kv6 {
pub xsiz: u32,
pub ysiz: u32,
pub zsiz: u32,
pub xpiv: f32,
pub ypiv: f32,
pub zpiv: f32,
pub voxels: Vec<Voxel>,
pub xlen: Vec<u32>,
pub ylen: Vec<Vec<u16>>,
pub palette: Option<[Rgb6; 256]>,
}Fields§
§xsiz: u32§ysiz: u32§zsiz: u32§xpiv: f32§ypiv: f32§zpiv: f32§voxels: Vec<Voxel>Voxel records in file order (numvoxs == voxels.len() as u32).
xlen: Vec<u32>xlen[x] is the number of voxels in the x-th slice.
xlen.len() == xsiz. xlen.iter().sum() == numvoxs.
ylen: Vec<Vec<u16>>ylen[x][y] is the number of voxels in column (x, y).
Outer length xsiz, inner ysiz.
palette: Option<[Rgb6; 256]>Optional trailing 256-entry palette ("SPal" section).
Implementations§
Source§impl Kv6
impl Kv6
Sourcepub fn from_fn<F>(xsiz: u32, ysiz: u32, zsiz: u32, fill: F) -> Kv6
pub fn from_fn<F>(xsiz: u32, ysiz: u32, zsiz: u32, fill: F) -> Kv6
Build a Kv6 procedurally from a dense occupancy + colour
closure: fill(x, y, z) returns Some(col) for a solid voxel,
None for air. col is voxlap-packed 0x80RRGGBB — the high
byte is brightness, not alpha, so 0x00… renders black; use
0x80… for a flat-lit mid value.
Only surface voxels are emitted (a voxel with at least one
of its six neighbours air or out of bounds), matching how a
.kv6 stores a hull and how crate::sprite::Sprite expects to
be drawn; fully-enclosed interior voxels are skipped. Emitted
voxels get vis = 63 (all faces) and dir = 0, mirroring
roxlap_core::meltsphere’s flat output — adequate for procedural
models that don’t need per-face normals. The pivot is the
geometric centre.
Voxels are emitted in the canonical x-major, then y, then
ascending-z order the format requires, with matching xlen /
ylen run tables.
Sourcepub fn from_fn_shaded<F>(xsiz: u32, ysiz: u32, zsiz: u32, fill: F) -> Kv6
pub fn from_fn_shaded<F>(xsiz: u32, ysiz: u32, zsiz: u32, fill: F) -> Kv6
Like Kv6::from_fn, but fills real per-voxel surface
normals (Voxel::dir) and face visibility (Voxel::vis)
instead of the flat dir = 0, vis = 63. The CPU sprite
rasteriser shades each voxel by dir (kv6colmul[dir]), so a
from_fn-built model shades flat while a from_fn_shaded one
gets proper directional gradient shading — the difference an
authored .kv6 shows.
dir is the nearest voxlap direction
(crate::equivec::nearest_dir) to the voxel’s outward surface
normal, estimated as the occupancy gradient over the 3³
neighbourhood (pointing toward empty space). vis is the bitmask
of the six exposed faces.
Sourcepub fn recompute_surface(&mut self, occupied: impl Fn(i32, i32, i32) -> bool)
pub fn recompute_surface(&mut self, occupied: impl Fn(i32, i32, i32) -> bool)
Recompute every stored voxel’s Voxel::vis + Voxel::dir
from occupied (a predicate over the full solid in this
kv6’s local coordinates; out-of-range / air ⇒ false). Use this
after editing a model’s voxels to refresh its shading + face
visibility — the editor counterpart to building with
Kv6::from_fn_shaded. Geometry (positions, run tables) is left
untouched; only vis/dir change.
Sourcepub fn carve_sphere_with_colfunc<S, C>(
&mut self,
centre: [i32; 3],
radius: u32,
solid: S,
colfunc: C,
)
pub fn carve_sphere_with_colfunc<S, C>( &mut self, centre: [i32; 3], radius: u32, solid: S, colfunc: C, )
Carve a sphere out of this model and control the colour of the
interior the cut exposes — the sprite counterpart of
roxlap_scene::Grid::set_sphere_with_colfunc /
crate::edit::set_sphere_with_colfunc.
Why a solid predicate is required. A .kv6 stores only
its surface hull — fully-enclosed interior voxels are not
recorded (see Kv6::from_fn). A carve must therefore know the
model’s full occupancy to expose meaningful interior walls,
which the data alone can’t provide. The caller supplies it via
solid(x, y, z) -> bool in kv6-local voxel coords (e.g. the
same predicate used to build the model with
Kv6::from_fn_shaded). solid must report true for at
least every stored surface voxel.
Behaviour:
- Voxels inside the sphere (
dx²+dy²+dz² <= r², matchingcrate::edit::set_sphere) become air. - Voxels the cut newly exposes get their colour from
colfunc(x, y, z)(kv6-local coords, voxlap-packed0x80RRGGBB). Pass|_, _, _| colfor a flat crater colour. - Voxels that were already on the surface keep their stored colour.
centre / radius are in kv6-local voxel units. Dimensions,
pivot, and palette are preserved; the model is re-extracted with
real per-voxel normals + face visibility (as
Kv6::from_fn_shaded).
Sourcepub fn solid_box(xsiz: u32, ysiz: u32, zsiz: u32, col: u32) -> Kv6
pub fn solid_box(xsiz: u32, ysiz: u32, zsiz: u32, col: u32) -> Kv6
A solid axis-aligned box of a single colour (voxlap-packed
0x80RRGGBB). Convenience over Kv6::from_fn.
Sourcepub fn solid_cube(n: u32, col: u32) -> Kv6
pub fn solid_cube(n: u32, col: u32) -> Kv6
A solid n³ cube of a single colour.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Kv6
impl RefUnwindSafe for Kv6
impl Send for Kv6
impl Sync for Kv6
impl Unpin for Kv6
impl UnsafeUnpin for Kv6
impl UnwindSafe for Kv6
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.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more