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
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>
Convert
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>
Convert
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)
Convert
&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)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.