Skip to main content

Kv6

Struct Kv6 

Source
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]>,
}
Expand description

Parsed .kv6 model. Round-trips byte-equally via parse + serialize.

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

Source

pub fn from_fn<F>(xsiz: u32, ysiz: u32, zsiz: u32, fill: F) -> Kv6
where F: Fn(u32, u32, u32) -> Option<u32>,

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.

Source

pub fn from_fn_shaded<F>(xsiz: u32, ysiz: u32, zsiz: u32, fill: F) -> Kv6
where F: Fn(u32, u32, u32) -> Option<u32>,

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.

Source

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.

Source

pub fn carve_sphere_with_colfunc<S, C>( &mut self, centre: [i32; 3], radius: u32, solid: S, colfunc: C, )
where S: Fn(i32, i32, i32) -> bool, C: Fn(i32, i32, i32) -> u32,

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², matching crate::edit::set_sphere) become air.
  • Voxels the cut newly exposes get their colour from colfunc(x, y, z) (kv6-local coords, voxlap-packed 0x80RRGGBB). Pass |_, _, _| col for 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).

Source

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.

Source

pub fn solid_cube(n: u32, col: u32) -> Kv6

A solid cube of a single colour.

Trait Implementations§

Source§

impl Clone for Kv6

Source§

fn clone(&self) -> Kv6

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 Kv6

Source§

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

Formats the value using the given formatter. Read more

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

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

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

Convert &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)

Convert &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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more