pub struct SpringSystem {
pub rest_positions: Vec<[f32; 3]>,
pub positions: Vec<[f32; 3]>,
pub velocities: Vec<[f32; 3]>,
pub springs: Vec<(usize, usize, f32)>,
pub fixed: Vec<bool>,
pub params: SpringParams,
}Expand description
A spring-mass system attached to mesh vertices for soft-body simulation.
Fields§
§rest_positions: Vec<[f32; 3]>Rest positions (used to reset).
positions: Vec<[f32; 3]>Current positions.
velocities: Vec<[f32; 3]>Current velocities.
springs: Vec<(usize, usize, f32)>Springs: (vertex_a, vertex_b, rest_length).
fixed: Vec<bool>Fixed (pinned) vertices that do not move.
params: SpringParamsSimulation parameters.
Implementations§
Source§impl SpringSystem
impl SpringSystem
Sourcepub fn from_mesh(mesh: &MeshBuffers, params: SpringParams) -> Self
pub fn from_mesh(mesh: &MeshBuffers, params: SpringParams) -> Self
Construct from a mesh and simulation parameters.
Sourcepub fn vertex_count(&self) -> usize
pub fn vertex_count(&self) -> usize
Number of vertices in the system.
Sourcepub fn spring_count(&self) -> usize
pub fn spring_count(&self) -> usize
Number of springs in the system.
Sourcepub fn kinetic_energy(&self) -> f32
pub fn kinetic_energy(&self) -> f32
Total kinetic energy: sum of 0.5 * mass * |v|^2 over all vertices.
Sourcepub fn is_settled(&self, threshold: f32) -> bool
pub fn is_settled(&self, threshold: f32) -> bool
Returns true when the kinetic energy is below threshold.
Sourcepub fn apply_impulse(&mut self, vertex: usize, force: [f32; 3])
pub fn apply_impulse(&mut self, vertex: usize, force: [f32; 3])
Apply an instantaneous velocity impulse to a vertex.
Sourcepub fn apply_gravity_impulse(&mut self, dt: f32)
pub fn apply_gravity_impulse(&mut self, dt: f32)
Accumulate gravity into all non-fixed vertex velocities.
Sourcepub fn step(&mut self, dt: f32)
pub fn step(&mut self, dt: f32)
Advance the simulation by dt seconds (uses params.substeps substeps).
Sourcepub fn step_n(&mut self, dt: f32, n: usize)
pub fn step_n(&mut self, dt: f32, n: usize)
Advance the simulation by n steps of dt seconds each.
Sourcepub fn to_mesh(&self, template: &MeshBuffers) -> MeshBuffers
pub fn to_mesh(&self, template: &MeshBuffers) -> MeshBuffers
Build a new MeshBuffers from the template, with positions replaced by
the current simulated positions, and normals recomputed.
Auto Trait Implementations§
impl Freeze for SpringSystem
impl RefUnwindSafe for SpringSystem
impl Send for SpringSystem
impl Sync for SpringSystem
impl Unpin for SpringSystem
impl UnsafeUnpin for SpringSystem
impl UnwindSafe for SpringSystem
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> 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