pub struct SoftBody {
pub nodes: Vec<SoftNode>,
pub springs: Vec<Spring>,
pub damping: f32,
pub restitution: f32,
pub iterations: usize,
pub label: String,
}Expand description
A mass-spring soft body.
Fields§
§nodes: Vec<SoftNode>§springs: Vec<Spring>§damping: f32Global friction / air drag coefficient.
restitution: f32Contact restitution (for floor/ceiling collisions).
iterations: usizeIteration count for constraint projection.
label: StringUser label.
Implementations§
Source§impl SoftBody
impl SoftBody
pub fn new() -> Self
Sourcepub fn rope(n: usize, length: f32, mass_per_node: f32, stiffness: f32) -> Self
pub fn rope(n: usize, length: f32, mass_per_node: f32, stiffness: f32) -> Self
Create a 1D rope of n nodes spanning length.
Sourcepub fn grid(cols: usize, rows: usize, cell_size: f32) -> Self
pub fn grid(cols: usize, rows: usize, cell_size: f32) -> Self
Create a 2D cloth grid of cols × rows nodes, spaced cell_size.
Sourcepub fn grid_with_params(
cols: usize,
rows: usize,
cell_size: f32,
mass: f32,
stiffness: f32,
) -> Self
pub fn grid_with_params( cols: usize, rows: usize, cell_size: f32, mass: f32, stiffness: f32, ) -> Self
Create a cloth grid with custom mass and stiffness.
Sourcepub fn blob(n: usize, radius: f32, mass: f32, stiffness: f32) -> Self
pub fn blob(n: usize, radius: f32, mass: f32, stiffness: f32) -> Self
Create a circular blob of n nodes with internal cross-springs.
Sourcepub fn add_node(&mut self, position: Vec2, mass: f32) -> usize
pub fn add_node(&mut self, position: Vec2, mass: f32) -> usize
Add a node and return its index.
Sourcepub fn add_spring(&mut self, a: usize, b: usize, stiffness: f32) -> usize
pub fn add_spring(&mut self, a: usize, b: usize, stiffness: f32) -> usize
Add a spring between two nodes and return its index.
Sourcepub fn apply_impulse(&mut self, node: usize, impulse: Vec2)
pub fn apply_impulse(&mut self, node: usize, impulse: Vec2)
Apply an impulse to a node.
Sourcepub fn apply_force_radius(&mut self, origin: Vec2, radius: f32, force: Vec2)
pub fn apply_force_radius(&mut self, origin: Vec2, radius: f32, force: Vec2)
Apply force to all nodes in a radius.
Sourcepub fn resolve_floor(&mut self, floor_y: f32)
pub fn resolve_floor(&mut self, floor_y: f32)
Resolve simple floor collision (y >= floor_y, normal = up).
Sourcepub fn resolve_ceiling(&mut self, ceiling_y: f32)
pub fn resolve_ceiling(&mut self, ceiling_y: f32)
Resolve ceiling collision.
Sourcepub fn resolve_wall_left(&mut self, x: f32)
pub fn resolve_wall_left(&mut self, x: f32)
Resolve left wall.
Sourcepub fn resolve_wall_right(&mut self, x: f32)
pub fn resolve_wall_right(&mut self, x: f32)
Resolve right wall.
Sourcepub fn resolve_circle_obstacle(&mut self, center: Vec2, radius: f32)
pub fn resolve_circle_obstacle(&mut self, center: Vec2, radius: f32)
Push nodes out of a circle.
Sourcepub fn kinetic_energy(&self) -> f32
pub fn kinetic_energy(&self) -> f32
Total kinetic energy.
Sourcepub fn spring_potential_energy(&self) -> f32
pub fn spring_potential_energy(&self) -> f32
Total potential energy from spring stretch.
Sourcepub fn active_spring_count(&self) -> usize
pub fn active_spring_count(&self) -> usize
Number of active (non-broken) springs.
Sourcepub fn positions(&self) -> Vec<Vec2>
pub fn positions(&self) -> Vec<Vec2>
Collect all edge node positions (ring periphery for convex hulls or rendering).
Sourcepub fn nearest_node(&self, point: Vec2) -> Option<usize>
pub fn nearest_node(&self, point: Vec2) -> Option<usize>
Closest node index to a world position.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SoftBody
impl RefUnwindSafe for SoftBody
impl Send for SoftBody
impl Sync for SoftBody
impl Unpin for SoftBody
impl UnsafeUnpin for SoftBody
impl UnwindSafe for SoftBody
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.