pub struct SoftBody<const P: usize, const S: usize> {
pub particles: Vec<Particle, P>,
pub springs: Vec<Spring, S>,
pub gravity: Vector3<f32>,
pub damping: f32,
pub pressure_config: PressureConfig,
pub ground_plane: Option<f32>,
pub ground_restitution: f32,
pub ground_friction: f32,
}Expand description
A soft body made of particles connected by springs.
Generic parameters:
P- Maximum number of particlesS- Maximum number of springs
Fields§
§particles: Vec<Particle, P>Particles in the soft body
springs: Vec<Spring, S>Spring constraints between particles
gravity: Vector3<f32>Gravity acceleration applied to all particles
damping: f32Global damping factor (0.0 = no damping, 1.0 = full damping)
pressure_config: PressureConfigPressure/volume preservation configuration
ground_plane: Option<f32>Ground plane height (particles bounce off this)
ground_restitution: f32Ground restitution (bounciness of ground collisions)
ground_friction: f32Ground friction coefficient
Implementations§
Source§impl<const P: usize, const S: usize> SoftBody<P, S>
impl<const P: usize, const S: usize> SoftBody<P, S>
Sourcepub fn add_particle(&mut self, particle: Particle) -> Result<usize, ()>
pub fn add_particle(&mut self, particle: Particle) -> Result<usize, ()>
Add a particle to the soft body.
Sourcepub fn add_spring(
&mut self,
particle_a: usize,
particle_b: usize,
rest_length: f32,
stiffness: f32,
damping: f32,
) -> Result<(), ()>
pub fn add_spring( &mut self, particle_a: usize, particle_b: usize, rest_length: f32, stiffness: f32, damping: f32, ) -> Result<(), ()>
Add a spring constraint between two particles.
Sourcepub fn get_particle(&self, index: usize) -> Option<&Particle>
pub fn get_particle(&self, index: usize) -> Option<&Particle>
Get a particle by index.
Sourcepub fn get_particle_mut(&mut self, index: usize) -> Option<&mut Particle>
pub fn get_particle_mut(&mut self, index: usize) -> Option<&mut Particle>
Get a mutable reference to a particle by index.
Sourcepub fn set_gravity(&mut self, gravity: Vector3<f32>)
pub fn set_gravity(&mut self, gravity: Vector3<f32>)
Set the gravity vector for all particles.
Sourcepub fn step(&mut self, dt: f32)
pub fn step(&mut self, dt: f32)
Advance the soft body simulation by one timestep.
Uses semi-implicit Euler integration with spring forces.
Sourcepub fn get_vertex_positions(&self, output: &mut [[f32; 3]]) -> usize
pub fn get_vertex_positions(&self, output: &mut [[f32; 3]]) -> usize
Get vertex positions for rendering.
Converts particle positions to vertex array format.
Sourcepub fn clear_forces(&mut self)
pub fn clear_forces(&mut self)
Reset all forces on particles.
Sourcepub fn apply_global_force(&mut self, force: Vector3<f32>)
pub fn apply_global_force(&mut self, force: Vector3<f32>)
Apply an external force to all particles.
Source§impl<const P: usize, const S: usize> SoftBody<P, S>
Helper functions for creating common soft body shapes.
impl<const P: usize, const S: usize> SoftBody<P, S>
Helper functions for creating common soft body shapes.
Sourcepub fn create_cloth(
width: usize,
height: usize,
spacing: f32,
stiffness: f32,
damping: f32,
) -> Result<Self, ()>
pub fn create_cloth( width: usize, height: usize, spacing: f32, stiffness: f32, damping: f32, ) -> Result<Self, ()>
Create a cloth grid suspended from the top edge.
§Arguments
width- Number of particles along X axisheight- Number of particles along Y axisspacing- Distance between particlesstiffness- Spring stiffnessdamping- Spring damping
Returns the soft body with structural and shear springs, or an error if capacity exceeded.
Trait Implementations§
Auto Trait Implementations§
impl<const P: usize, const S: usize> Freeze for SoftBody<P, S>
impl<const P: usize, const S: usize> RefUnwindSafe for SoftBody<P, S>
impl<const P: usize, const S: usize> Send for SoftBody<P, S>
impl<const P: usize, const S: usize> Sync for SoftBody<P, S>
impl<const P: usize, const S: usize> Unpin for SoftBody<P, S>
impl<const P: usize, const S: usize> UnsafeUnpin for SoftBody<P, S>
impl<const P: usize, const S: usize> UnwindSafe for SoftBody<P, S>
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> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.