pub struct SpringNetwork {
pub positions: Vec<Vec3>,
pub velocities: Vec<Vec3>,
pub masses: Vec<f32>,
pub edges: Vec<(usize, usize, f32, f32)>,
pub gravity: Vec3,
pub damping: f32,
pub iterations: usize,
}Expand description
A general graph of nodes connected by spring edges.
Each node is a mass-point; edges are distance constraints. Useful for soft body shapes, molecules, and amorphous entities.
Fields§
§positions: Vec<Vec3>§velocities: Vec<Vec3>§masses: Vec<f32>§edges: Vec<(usize, usize, f32, f32)>Edges: (node_a, node_b, rest_length, stiffness).
gravity: Vec3§damping: f32§iterations: usizeImplementations§
Source§impl SpringNetwork
impl SpringNetwork
pub fn new() -> Self
pub fn add_node(&mut self, pos: Vec3, mass: f32) -> usize
Sourcepub fn add_edge(&mut self, a: usize, b: usize, stiffness: f32)
pub fn add_edge(&mut self, a: usize, b: usize, stiffness: f32)
Add an edge between two nodes. Automatically computes rest length from current positions.
pub fn add_edge_with_length( &mut self, a: usize, b: usize, rest_length: f32, stiffness: f32, )
pub fn tick(&mut self, dt: f32)
pub fn apply_impulse(&mut self, node: usize, impulse: Vec3)
Sourcepub fn explode(&mut self, center: Vec3, strength: f32, radius: f32)
pub fn explode(&mut self, center: Vec3, strength: f32, radius: f32)
Apply a radial explosion impulse from center.
pub fn node_count(&self) -> usize
pub fn edge_count(&self) -> usize
Trait Implementations§
Source§impl Clone for SpringNetwork
impl Clone for SpringNetwork
Source§fn clone(&self) -> SpringNetwork
fn clone(&self) -> SpringNetwork
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SpringNetwork
impl Debug for SpringNetwork
Auto Trait Implementations§
impl Freeze for SpringNetwork
impl RefUnwindSafe for SpringNetwork
impl Send for SpringNetwork
impl Sync for SpringNetwork
impl Unpin for SpringNetwork
impl UnsafeUnpin for SpringNetwork
impl UnwindSafe for SpringNetwork
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
Mutably borrows from an owned value. Read more