Skip to main content

DeformableBody

Struct DeformableBody 

Source
pub struct DeformableBody {
    pub positions: Vec<Vec3Fix>,
    pub velocities: Vec<Vec3Fix>,
    pub inv_masses: Vec<Fix128>,
    pub tetrahedra: Vec<[usize; 4]>,
    pub surface_triangles: Vec<[usize; 3]>,
    pub config: DeformableConfig,
    /* private fields */
}
Expand description

Deformable body simulation

Fields§

§positions: Vec<Vec3Fix>

Particle positions

§velocities: Vec<Vec3Fix>

Velocities

§inv_masses: Vec<Fix128>

Inverse mass per particle

§tetrahedra: Vec<[usize; 4]>

Tetrahedra (4 vertex indices each)

§surface_triangles: Vec<[usize; 3]>

Surface triangles (for rendering/collision)

§config: DeformableConfig

Configuration

Implementations§

Source§

impl DeformableBody

Source

pub fn new( positions: Vec<Vec3Fix>, tetrahedra: &[[usize; 4]], surface_triangles: Vec<[usize; 3]>, mass_per_particle: Fix128, ) -> Self

Create from particle positions and tetrahedra

Source

pub fn new_cube(center: Vec3Fix, half_extent: Fix128, mass: Fix128) -> Self

Create a simple cube deformable (for testing)

Source

pub fn particle_count(&self) -> usize

Number of particles

Source

pub fn step(&mut self, dt: Fix128)

Step simulation

Source

pub fn step_with_sdf(&mut self, dt: Fix128, sdf_colliders: &[SdfCollider])

Step with SDF collision

Source

pub fn center_of_mass(&self) -> Vec3Fix

Centroid of the particle positions. Every constructor gives all particles the same mass, for which this is the centre of mass; it is not mass weighted if inv_masses are edited to differ. Zero for a body without particles.

Source

pub fn resolve_rigid_body_collisions( &mut self, rigid_bodies: &mut [RigidBody], body_radii: &[Fix128], dt: Fix128, )

Resolve collisions between deformable body particles and rigid bodies

Treats each rigid body as a sphere with given radius for simplicity. Applies two-way coupling: deformable particles are pushed out, and rigid bodies receive reaction impulses.

The correction and the (perfectly inelastic) normal impulse are shared by inverse mass, w_p / (w_p + w_b) to the particle and w_b / (w_p + w_b) to the body; a body with zero inverse mass (static, kinematic) takes none, so a particle pressed into it ends exactly on its surface with zero approach speed. A particle exactly at the centre of a body has no push direction and is left untouched; pinned particles (zero inverse mass) are skipped. dt only gates the call (zero is a no-op).

Trait Implementations§

Source§

impl Debug for DeformableBody

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.