Skip to main content

SoftBodyBuilder

Struct SoftBodyBuilder 

Source
pub struct SoftBodyBuilder {
Show 26 fields pub positions: Vec<Vector>, pub masses: Vec<f32>, pub particle_mass: f32, pub pinned: Vec<u32>, pub edges: Vec<[u32; 2]>, pub bend_edges: Vec<[u32; 2]>, pub tension_only_edges: Vec<u32>, pub edge_softness: Vec<(u32, SpringCoefficients<f32>)>, pub edge_tear_resistance: Vec<(u32, f32)>, pub dihedrals: Vec<[u32; 4]>, pub cells: Vec<[u32; 4]>, pub surface: Vec<[u32; 3]>, pub material: SoftBodyMaterial, pub cell_model: SoftBodyCellModel, pub volume_preservation: bool, pub volume_factor: f32, pub shape_matching: bool, pub self_contacts: bool, pub oriented: Option<bool>, pub particle_radius: f32, pub collider_template: Option<ColliderBuilder>, pub skin: Option<(Vec<Vector>, Vec<[u32; 3]>)>, pub wire: Vec<[u32; 2]>, pub skin_collision: bool, pub particle_settings: SoftBodyParticleSettings, pub user_data: u128,
}
Expand description

A builder for crate::dynamics::SoftBodys: particles are given in world space and elements reference particles by index. The generators (Self::rope, plus cloth/cuboid/sphere in 3D and polygon/disk/grid in 2D) make complete bodies; the setters build any body.

Fields§

§positions: Vec<Vector>

World-space particle positions.

§masses: Vec<f32>

Per-particle masses (empty = uniform particle_mass).

§particle_mass: f32

Uniform particle mass, used when masses is empty.

§pinned: Vec<u32>

Indices of the pinned particles.

§edges: Vec<[u32; 2]>

Structural edges (particle index pairs).

§bend_edges: Vec<[u32; 2]>

Bending edges (particle index pairs).

§tension_only_edges: Vec<u32>

Edges that only resist stretching, never compression (indices into the concatenation of edges then bend_edges).

§edge_softness: Vec<(u32, SpringCoefficients<f32>)>

Per-edge softness overrides (indices into the concatenation of edges then bend_edges); the material’s softness applies to the others.

§edge_tear_resistance: Vec<(u32, f32)>

Per-edge tear-threshold multipliers (indices into the concatenation of edges then bend_edges, see crate::dynamics::SoftBodyEdge::tear_resistance); 1.0 for the others.

§dihedrals: Vec<[u32; 4]>

Dihedral bending constraints: shared edge then the two opposite vertices.

§cells: Vec<[u32; 4]>

Simplex cells (triangles in 2D, tetrahedra in 3D).

§surface: Vec<[u32; 3]>

Boundary elements (segments in 2D, triangles in 3D), oriented outward. Derived from the cells when empty.

§material: SoftBodyMaterial

The material.

§cell_model: SoftBodyCellModel

The constitutive model of the cells.

§volume_preservation: bool

Whether area/volume preservation is enabled (one constraint per piece of material enclosed by a closed surface).

§volume_factor: f32

Target volume multiplier (> 1 inflates the body).

§shape_matching: bool

Whether shape matching is enabled.

§self_contacts: bool

Whether the body’s surface collides with itself.

§oriented: Option<bool>

Whether the default collision surface’s shape is built with parry’s ORIENTED flag (see Self::oriented); None: when the surface is closed.

§particle_radius: f32

Thickness of the particles: the contact skin of the body’s surface collider.

§collider_template: Option<ColliderBuilder>

Template of the colliders of the body’s collision meshes (their shape is the mesh’s own); None disables collisions.

§skin: Option<(Vec<Vector>, Vec<[u32; 3]>)>

Mesh held by the cells, if any: (vertices, elements) in world space, bound to the cells at build time.

§wire: Vec<[u32; 2]>

The segments the body collides through when it has no surface: a rope or a wire (3D only; in 2D the surface is already made of segments).

§skin_collision: bool

Whether the body meets the world through its skin rather than through its cells’ boundary (off by default, and no effect without a skin).

§particle_settings: SoftBodyParticleSettings

Dynamics settings of the particles.

§user_data: u128

User data of the soft body.

Implementations§

Source§

impl SoftBodyBuilder

Source

pub fn particle_positions(&self) -> &[Vector] ⓘ

The particle positions set so far.

Source

pub fn positions(self, positions: Vec<Vector>) -> Self

Sets the world-space positions of the particles.

Source

pub fn particle_mass(self, mass: f32) -> Self

Sets the mass of every particle.

Source

pub fn mass(self, mass: f32) -> Self

Sets the total mass of the soft body (split uniformly across the particles).

Source

pub fn masses(self, masses: Vec<f32>) -> Self

Sets per-particle masses.

Source

pub fn pinned_particles(self, pinned: impl IntoIterator<Item = u32>) -> Self

Pins the given particles (infinite mass, moved kinematically: see crate::dynamics::SoftBody::set_particle_kinematic_target).

Source

pub fn edges(self, edges: Vec<[u32; 2]>) -> Self

Sets the structural edges.

Source

pub fn add_edges(self, edges: impl IntoIterator<Item = [u32; 2]>) -> Self

Adds structural edges (seams between two appended pieces, extra springs…); their rest length is the current distance of their particles.

Source

pub fn append(self, other: SoftBodyBuilder) -> Self

Appends the particles and elements of other (its indices shifted past this builder’s particles): the two pieces become one soft body, to be sewn together with Self::add_edges. This builder’s material, model and settings are kept.

Source

pub fn bend_edges(self, edges: Vec<[u32; 2]>) -> Self

Sets the bending edges.

Source

pub fn tension_only(self) -> Self

Makes every edge (structural and bending) only resist stretching, never compression.

Source

pub fn dihedrals(self, dihedrals: Vec<[u32; 4]>) -> Self

Sets the dihedral bending constraints (shared edge then the two opposite vertices).

Source

pub fn cells(self, cells: Vec<[u32; 4]>) -> Self

Sets the simplex cells (triangles in 2D, tetrahedra in 3D). Structural edges along the cell edges are added at build time if none were given.

Source

pub fn translated(self, translation: Vector) -> Self

Moves everything the builder holds in world space: the particles and the skin.

Useful to drop copies of a meshed body at several places without meshing it again; moving the particles alone would leave the skin behind.

Source

pub fn skin(self, vertices: Vec<Vector>, indices: Vec<[u32; 3]>) -> Self

Sets the mesh the cells hold: the body’s default collision mesh is then that mesh, bound to the cells (crate::dynamics::SoftMeshMapping::Skinned) instead of the cells’ boundary. The vertices are in world space in the cells’ build pose, each bound to the closest cell.

Source

pub fn skin_collision(self, enabled: bool) -> Self

Whether the body’s skin is its collision mesh rather than its cells’ boundary (off by default, and no effect without a skin); on, a contact is resolved through the particles of the cell holding the touched part of the skin, which must be at least as fine as the cells.

Source

pub fn wire(self, segments: Vec<[u32; 2]>) -> Self

Sets the segments the body collides through: a rope or a wire, whose collision mesh is a polyline rather than a surface (3D only; in 2D Self::surface already takes segments). A wire encloses nothing, so its contacts are two-sided and it never expels anything.

Source

pub fn surface(self, surface: Vec<[u32; 3]>) -> Self

Sets the computational mesh’s boundary elements (segments in 2D, triangles in 3D), oriented outward: what the volume constraint integrates over, and the geometry of the default collision mesh.

Source

pub fn material(self, material: SoftBodyMaterial) -> Self

Sets the material.

Source

pub fn softness(self, softness: SpringCoefficients<f32>) -> Self

Sets the same softness for every constraint family.

Source

pub fn tear_strain(self, strain: f32) -> Self

Sets the material’s tear strain (see SoftBodyMaterial::tear_strain).

Source

pub fn tear_force(self, force: f32) -> Self

Sets the material’s tear force (see SoftBodyMaterial::tear_force).

Source

pub fn min_piece(self, elements: u32) -> Self

Sets the smallest piece, in measure elements, a tear may split off (see SoftBodyMaterial::min_piece).

Source

pub fn tear_smoothing(self, seconds: f32) -> Self

Sets the material’s tear smoothing time constant (see SoftBodyMaterial::tear_smoothing).

Source

pub fn interior_strength(self, strength: f32) -> Self

Sets the material’s interior strength (see SoftBodyMaterial::interior_strength).

Source

pub fn edge_tear_resistance( self, edges: impl IntoIterator<Item = (u32, f32)>, ) -> Self

Sets the tear-threshold multiplier of some edges, as (edge index, resistance) pairs indexing the concatenation of the structural then the bending edges (see crate::dynamics::SoftBodyEdge::tear_resistance).

Source

pub fn cell_model(self, model: SoftBodyCellModel) -> Self

Sets the constitutive model of the cells.

Source

pub fn volume_preservation(self, enabled: bool) -> Self

Enables area/volume preservation: one constraint per piece of material enclosed by a closed surface (see crate::dynamics::SoftBody::volume_pieces).

Source

pub fn volume_factor(self, factor: f32) -> Self

Sets the target volume multiplier (> 1 inflates the body).

Source

pub fn shape_matching(self, enabled: bool) -> Self

Enables shape matching.

Source

pub fn self_contacts(self, enabled: bool) -> Self

Enables self contacts between the body’s surface vertices/edges and its own surface.

Source

pub fn oriented(self, oriented: bool) -> Self

Whether the shape of the body’s default collision surface is built with parry’s ORIENTED flag, like a rigid polyline or mesh. Left unset, it is whenever the surface is closed, which is what a solid body wants: an oriented closed surface encloses matter, so nothing is held inside it. Set it to false for a shell, whose inner side holds the bodies inside it. After insertion the collider’s shape is the authority: change its flags there, like for any collider. Independent of the material inside (cells, pressure).

Source

pub fn particle_radius(self, radius: f32) -> Self

Sets the thickness of the particles (the contact skin of the body’s surface collider).

Source

pub fn surface_collider(self, collider: ColliderBuilder) -> Self

Configures the collider of the body’s default collision mesh (its cells’ boundary, or its skin under Self::skin_collision): friction, restitution, groups, events. The shape is the mesh’s own; the density is ignored (mass from Self::mass or Self::masses).

Source

pub fn no_surface_collider(self) -> Self

Gives the body no default collision mesh collider: it collides through the meshes added after insertion, if any.

Source

pub fn particle_settings(self, settings: SoftBodyParticleSettings) -> Self

Sets the dynamics settings of the particles (damping, gravity scale, sleeping…).

Source

pub fn linear_damping(self, damping: f32) -> Self

Sets the linear damping of the particles.

Source

pub fn gravity_scale(self, scale: f32) -> Self

Sets the gravity scale of the particles.

Source

pub fn additional_solver_iterations(self, iterations: usize) -> Self

Requests extra solver substeps for the particles (and everything they touch).

Source

pub fn additional_pgs_iterations(self, iterations: usize) -> Self

Requests extra internal PGS iterations per substep for the particles (and everything they touch); see SoftBodyParticleSettings::additional_pgs_iterations.

Source

pub fn can_sleep(self, can_sleep: bool) -> Self

Whether the particles may fall asleep.

Source

pub fn user_data(self, data: u128) -> Self

Sets the user data of the soft body.

Source

pub fn surface_edges(&self) -> Vec<[u32; 2]>

The unique edges of the surface elements.

Source

pub fn cell_edges(&self) -> Vec<[u32; 2]>

The unique edges of the cells.

Source

pub fn surface_dihedrals(&self) -> Vec<[u32; 4]>

The dihedral constraints across every interior edge of the triangle surface (3D only).

Source§

impl SoftBodyBuilder

Source

pub fn new(positions: Vec<Vector>) -> Self

A builder over the given world-space particle positions, with no element.

Source

pub fn trimesh(vertices: Vec<Vector>, indices: Vec<[u32; 3]>) -> Option<Self>

A triangle-mesh soft body without volumetric cells (None if empty): vertices are particles, edges are structural and shape matching holds the shape. 3D: the triangles are the surface (dihedral bending across interior edges); 2D: the boundary is the surface.

Source

pub fn rope(start: Vector, end: Vector, num_particles: usize) -> Self

A rope of num_particles particles from start to end: structural edges between neighbors, bending edges between second neighbors; in 2D the segments are also the surface. The particle radius (the rope’s thickness) defaults to half the segment length.

Source

pub fn cloth( origin: Vector, du: Vector, dv: Vector, nu: usize, nv: usize, ) -> Self

A rectangular cloth of nu × nv particles (3D only): origin + i * du + j * dv, with structural, shear and bending edges, and a triangle surface for rendering. The particle radius defaults to half the smallest edge length so the particles tile the surface.

Source

pub fn cloth_tube( origin: Vector, axis: Vector, radius_start: f32, radius_end: f32, num_around: usize, num_along: usize, ) -> Self

A cloth tube: num_along rings of num_around particles around the segment origin to origin + axis, radius linear from radius_start to radius_end; edges and surface of Self::cloth closed around the axis. Ring-major particles: ring 0 is 0..num_around.

Source

pub fn cloth_anisotropic( origin: Vector, du: Vector, dv: Vector, nu: usize, nv: usize, warp: SpringCoefficients<f32>, weft: SpringCoefficients<f32>, shear: SpringCoefficients<f32>, ) -> Self

Self::cloth with anisotropic stiffness: the edges along du (warp), along dv (weft) and the diagonals (shear) get their own softness (the material’s bend_softness still applies to the bending edges).

Source

pub fn cuboid( center: Vector, half_extents: Vector, nx: usize, ny: usize, nz: usize, ) -> Self

A solid box tetrahedralized on a nx × ny × nz particle grid (3D only), with structural edges along the tetrahedra edges and the boundary triangles as surface.

The particle radius defaults to half the smallest cell size.

Source

pub fn volumetric( vertices: &[Vector], indices: &[[u32; 3]], cell_size: f32, ) -> Option<Self>

A volumetric body filling a closed, outward-oriented mesh (triangles in 3D, segments in 2D) with cells of size cell_size; the surface is their boundary. Particle radius defaults to half the mean cell edge; None if the mesh is empty, open or encloses nothing at that size.

Source

pub fn volumetric_with( vertices: &[Vector], indices: &[[u32; 3]], params: &VolumeMeshParameters, ) -> Option<Self>

The same as Self::volumetric, with the meshing parameters spelled out: element size, the cover’s smoothing, guard and subdivision, and whether the surface alone is covered (the crust).

Source

pub fn volumetric_skinned( vertices: &[Vector], indices: &[[u32; 3]], cell_size: f32, ) -> Option<Self>

The same as Self::volumetric, keeping the boundary mesh as the body’s skin: the cells hold it and the body is drawn as it, so thin features survive a cell size that cannot resolve them; it still collides through its cells, so contacts are as coarse as they are.

Source

pub fn sphere(center: Vector, radius: f32, subdivisions: usize) -> Self

A hollow sphere (3D only): an icosphere surface with subdivisions refinement levels, structural edges along the triangle edges, dihedral bending constraints across them, and volume preservation. The particle radius defaults to half the mean edge length.

Trait Implementations§

Source§

impl Clone for SoftBodyBuilder

Source§

fn clone(&self) -> SoftBodyBuilder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SoftBodyBuilder

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for SoftBodyBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<SoftBodyBuilder> for SoftBody

Source§

fn from(builder: SoftBodyBuilder) -> Self

Converts to this type from the input type.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &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)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

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

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
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> MaybeSync for T
where T: Sync + ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.