pub struct MetaballEntity {
pub sources: Vec<FieldSource>,
pub threshold: f32,
pub hp_ratio: f32,
pub grid_resolution: u32,
pub breath_phase: f32,
pub breath_frequency: f32,
pub center: Vec3,
pub rotation: Vec3,
pub scale: f32,
pub bounds_half: Vec3,
pub dirty: bool,
pub name: String,
}Expand description
An entity defined by a scalar field from metaball sources.
The visible body is the isosurface at threshold. HP modulates all source
strengths, so damage physically reshapes the body. Crits destroy individual
sources, punching permanent holes.
Fields§
§sources: Vec<FieldSource>All field sources making up this entity.
threshold: f32Isosurface threshold. Surface exists where field(p) >= threshold.
hp_ratio: f32Current HP ratio (0.0 = dead, 1.0 = full HP).
grid_resolution: u32Grid resolution for marching cubes extraction. 32 for normal entities, 64 for bosses.
breath_phase: f32Current breathing animation phase.
breath_frequency: f32Breathing animation frequency (Hz).
center: Vec3Entity center in world space.
rotation: Vec3Entity rotation (euler angles for simplicity).
scale: f32Entity scale.
bounds_half: Vec3Bounding box half-extents (auto-computed from sources).
dirty: boolWhether the mesh needs re-extraction this frame.
name: StringName for debugging.
Implementations§
Source§impl MetaballEntity
impl MetaballEntity
pub fn new(threshold: f32, resolution: u32) -> Self
pub fn with_name(self, name: impl Into<String>) -> Self
Sourcepub fn add_source(&mut self, source: FieldSource) -> usize
pub fn add_source(&mut self, source: FieldSource) -> usize
Add a field source.
Sourcepub fn nearest_source(&self, point: Vec3) -> Option<usize>
pub fn nearest_source(&self, point: Vec3) -> Option<usize>
Find the source nearest to a world-space point.
Sourcepub fn find_source(&self, tag: &str) -> Option<usize>
pub fn find_source(&self, tag: &str) -> Option<usize>
Find a source by tag.
Sourcepub fn update(&mut self, dt: f32, time: f32)
pub fn update(&mut self, dt: f32, time: f32)
Update the entity for a new frame.
- Advances breathing animation
- Updates source positions from breathing offsets
- Decays damage reductions (spring-back)
- Marks as dirty if anything changed
Sourcepub fn evaluate_full(&self, point: Vec3) -> (f32, Vec4, f32)
pub fn evaluate_full(&self, point: Vec3) -> (f32, Vec4, f32)
Evaluate the scalar field and compute color/emission at a point.
Sourcepub fn gradient(&self, point: Vec3) -> Vec3
pub fn gradient(&self, point: Vec3) -> Vec3
Compute the gradient (normal direction) at a point via central differences.
Sourcepub fn normal_at(&self, point: Vec3) -> Vec3
pub fn normal_at(&self, point: Vec3) -> Vec3
Normal at a point on the isosurface (normalized gradient, pointing outward).
Sourcepub fn set_center(&mut self, center: Vec3)
pub fn set_center(&mut self, center: Vec3)
Move the entity center. Updates all source positions.
Sourcepub fn recompute_bounds(&mut self)
pub fn recompute_bounds(&mut self)
Recompute bounding box from source positions and radii.
Sourcepub fn active_source_count(&self) -> usize
pub fn active_source_count(&self) -> usize
Number of active (non-destroyed) sources.
Sourcepub fn source_count(&self) -> usize
pub fn source_count(&self) -> usize
Total active source count.
Sourcepub fn take_dirty(&mut self) -> bool
pub fn take_dirty(&mut self) -> bool
Consume the dirty flag.
Trait Implementations§
Source§impl Clone for MetaballEntity
impl Clone for MetaballEntity
Source§impl Debug for MetaballEntity
impl Debug for MetaballEntity
Auto Trait Implementations§
impl Freeze for MetaballEntity
impl RefUnwindSafe for MetaballEntity
impl Send for MetaballEntity
impl Sync for MetaballEntity
impl Unpin for MetaballEntity
impl UnsafeUnpin for MetaballEntity
impl UnwindSafe for MetaballEntity
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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.