pub struct Sprite {
pub kv6: Kv6,
pub p: [f32; 3],
pub s: [f32; 3],
pub h: [f32; 3],
pub f: [f32; 3],
pub flags: u32,
pub material: u8,
pub alpha_mul: u8,
pub material_map: Vec<(u32, u8)>,
}Expand description
A KV6 voxel sprite positioned in world space.
Mirror of voxlap’s vx5sprite for the kv6 case
(flags & SPRITE_FLAG_KFA == 0; see SPRITE_FLAG_KFA).
Owns its Kv6 by value. p / s / h / f are voxlap’s
per-axis world-space basis: s is the kv6.xsiz direction,
h the ysiz direction, f the zsiz direction. For an
axis-aligned sprite, s = [1,0,0], h = [0,1,0],
f = [0,0,1].
Fields§
§kv6: Kv6Voxel data + bounding-box pivots. Loaded from a .kv6
file via crate::kv6::parse or built procedurally.
p: [f32; 3]World-space position of the sprite’s pivot (xpiv, ypiv, zpiv inside the kv6 maps to this point).
s: [f32; 3]World-space basis vector for the kv6’s local +x. Length
scales the sprite along that axis (typically 1.0 for
unit-scale).
h: [f32; 3]World-space basis vector for the kv6’s local +y.
f: [f32; 3]World-space basis vector for the kv6’s local +z.
flags: u32Voxlap-style flags bitfield. See SPRITE_FLAG_NO_SHADING,
SPRITE_FLAG_KFA, SPRITE_FLAG_INVISIBLE,
SPRITE_FLAG_NO_Z.
material: u8Voxel-material id (TV stage) applied uniformly to this sprite’s
voxels — indexes the renderer’s global
MaterialTable for opacity + blend
mode. 0 (the default) is opaque, so an un-set sprite renders exactly
as before. See PORTING-TRANSPARENCY.md.
alpha_mul: u8Per-instance opacity multiplier (TV stage), 0..=255 (255 =
unscaled, the default). Scales the material’s alpha so an effect can
fade out by cheap per-frame updates without re-uploading its volume.
material_map: Vec<(u32, u8)>Per-voxel material colour map (TV.3): (rgb, material_id) pairs that
classify this model’s voxels into materials by colour — a mixed model
(opaque frame + glass, bottle + potion). Empty (the default) means
the whole sprite uses material uniformly (the TV.1
path). See crate::material::material_for_color.
Implementations§
Source§impl Sprite
impl Sprite
Sourcepub fn axis_aligned(kv6: Kv6, pos: [f32; 3]) -> Sprite
pub fn axis_aligned(kv6: Kv6, pos: [f32; 3]) -> Sprite
Convenience constructor for an axis-aligned sprite at
world position pos. Basis is identity, flags = 0
(kv6 + normal shading + visible + z-tested).
§Examples
use roxlap_formats::kv6::Kv6;
use roxlap_formats::sprite::Sprite;
// ... after `let kv6 = kv6::parse(&bytes)?;` or similar:
let sprite = Sprite::axis_aligned(kv6, [1024.0, 1024.0, 100.0]);
assert_eq!(sprite.flags, 0);
assert_eq!(sprite.s, [1.0, 0.0, 0.0]);Sourcepub fn casts_shadow(&self) -> bool
pub fn casts_shadow(&self) -> bool
XS.4 — whether this sprite casts a hard shadow (the dynamic-lighting
stage decides it darkens terrain / other
sprites). true unless SPRITE_FLAG_NO_SHADOW_CAST is set.
Sourcepub fn receives_shadow(&self) -> bool
pub fn receives_shadow(&self) -> bool
XS.4 — whether this sprite receives hard shadows (is darkened by
occluders). true unless SPRITE_FLAG_NO_SHADOW_RECEIVE is set.
Sourcepub fn with_casts_shadow(self, casts: bool) -> Sprite
pub fn with_casts_shadow(self, casts: bool) -> Sprite
XS.4 — set whether this sprite casts a hard shadow (clears/sets
SPRITE_FLAG_NO_SHADOW_CAST). Returns self for chaining.
Sourcepub fn with_receives_shadow(self, receives: bool) -> Sprite
pub fn with_receives_shadow(self, receives: bool) -> Sprite
XS.4 — set whether this sprite receives hard shadows (clears/sets
SPRITE_FLAG_NO_SHADOW_RECEIVE). Returns self for chaining.
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 sprite’s voxel model, controlling
the colour of the interior the cut exposes. Thin delegate to
Kv6::carve_sphere_with_colfunc — centre / radius,
solid, and colfunc are all in kv6-local voxel
coordinates (the sprite pose p/s/h/f is untouched). See
that method for why the solid occupancy predicate is required.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Sprite
impl RefUnwindSafe for Sprite
impl Send for Sprite
impl Sync for Sprite
impl Unpin for Sprite
impl UnsafeUnpin for Sprite
impl UnwindSafe for Sprite
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