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: f32Uniform 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: SoftBodyMaterialThe material.
cell_model: SoftBodyCellModelThe constitutive model of the cells.
volume_preservation: boolWhether area/volume preservation is enabled (one constraint per piece of material enclosed by a closed surface).
volume_factor: f32Target volume multiplier (> 1 inflates the body).
shape_matching: boolWhether shape matching is enabled.
self_contacts: boolWhether 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: f32Thickness 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: boolWhether 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: SoftBodyParticleSettingsDynamics settings of the particles.
user_data: u128User data of the soft body.
Implementations§
Source§impl SoftBodyBuilder
impl SoftBodyBuilder
Sourcepub fn particle_positions(&self) -> &[Vector] ⓘ
pub fn particle_positions(&self) -> &[Vector] ⓘ
The particle positions set so far.
Sourcepub fn positions(self, positions: Vec<Vector>) -> Self
pub fn positions(self, positions: Vec<Vector>) -> Self
Sets the world-space positions of the particles.
Sourcepub fn particle_mass(self, mass: f32) -> Self
pub fn particle_mass(self, mass: f32) -> Self
Sets the mass of every particle.
Sourcepub fn mass(self, mass: f32) -> Self
pub fn mass(self, mass: f32) -> Self
Sets the total mass of the soft body (split uniformly across the particles).
Sourcepub fn pinned_particles(self, pinned: impl IntoIterator<Item = u32>) -> Self
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).
Sourcepub fn add_edges(self, edges: impl IntoIterator<Item = [u32; 2]>) -> Self
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.
Sourcepub fn append(self, other: SoftBodyBuilder) -> Self
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.
Sourcepub fn bend_edges(self, edges: Vec<[u32; 2]>) -> Self
pub fn bend_edges(self, edges: Vec<[u32; 2]>) -> Self
Sets the bending edges.
Sourcepub fn tension_only(self) -> Self
pub fn tension_only(self) -> Self
Makes every edge (structural and bending) only resist stretching, never compression.
Sourcepub fn dihedrals(self, dihedrals: Vec<[u32; 4]>) -> Self
pub fn dihedrals(self, dihedrals: Vec<[u32; 4]>) -> Self
Sets the dihedral bending constraints (shared edge then the two opposite vertices).
Sourcepub fn cells(self, cells: Vec<[u32; 4]>) -> Self
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.
Sourcepub fn translated(self, translation: Vector) -> Self
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.
Sourcepub fn skin(self, vertices: Vec<Vector>, indices: Vec<[u32; 3]>) -> Self
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.
Sourcepub fn skin_collision(self, enabled: bool) -> Self
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.
Sourcepub fn wire(self, segments: Vec<[u32; 2]>) -> Self
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.
Sourcepub fn surface(self, surface: Vec<[u32; 3]>) -> Self
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.
Sourcepub fn material(self, material: SoftBodyMaterial) -> Self
pub fn material(self, material: SoftBodyMaterial) -> Self
Sets the material.
Sourcepub fn softness(self, softness: SpringCoefficients<f32>) -> Self
pub fn softness(self, softness: SpringCoefficients<f32>) -> Self
Sets the same softness for every constraint family.
Sourcepub fn tear_strain(self, strain: f32) -> Self
pub fn tear_strain(self, strain: f32) -> Self
Sets the material’s tear strain (see SoftBodyMaterial::tear_strain).
Sourcepub fn tear_force(self, force: f32) -> Self
pub fn tear_force(self, force: f32) -> Self
Sets the material’s tear force (see SoftBodyMaterial::tear_force).
Sourcepub fn min_piece(self, elements: u32) -> Self
pub fn min_piece(self, elements: u32) -> Self
Sets the smallest piece, in measure elements, a tear may split off (see
SoftBodyMaterial::min_piece).
Sourcepub fn tear_smoothing(self, seconds: f32) -> Self
pub fn tear_smoothing(self, seconds: f32) -> Self
Sets the material’s tear smoothing time constant (see
SoftBodyMaterial::tear_smoothing).
Sourcepub fn interior_strength(self, strength: f32) -> Self
pub fn interior_strength(self, strength: f32) -> Self
Sets the material’s interior strength (see SoftBodyMaterial::interior_strength).
Sourcepub fn edge_tear_resistance(
self,
edges: impl IntoIterator<Item = (u32, f32)>,
) -> Self
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).
Sourcepub fn cell_model(self, model: SoftBodyCellModel) -> Self
pub fn cell_model(self, model: SoftBodyCellModel) -> Self
Sets the constitutive model of the cells.
Sourcepub fn volume_preservation(self, enabled: bool) -> Self
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).
Sourcepub fn volume_factor(self, factor: f32) -> Self
pub fn volume_factor(self, factor: f32) -> Self
Sets the target volume multiplier (> 1 inflates the body).
Sourcepub fn shape_matching(self, enabled: bool) -> Self
pub fn shape_matching(self, enabled: bool) -> Self
Enables shape matching.
Sourcepub fn self_contacts(self, enabled: bool) -> Self
pub fn self_contacts(self, enabled: bool) -> Self
Enables self contacts between the body’s surface vertices/edges and its own surface.
Sourcepub fn oriented(self, oriented: bool) -> Self
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).
Sourcepub fn particle_radius(self, radius: f32) -> Self
pub fn particle_radius(self, radius: f32) -> Self
Sets the thickness of the particles (the contact skin of the body’s surface collider).
Sourcepub fn surface_collider(self, collider: ColliderBuilder) -> Self
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).
Sourcepub fn no_surface_collider(self) -> Self
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.
Sourcepub fn particle_settings(self, settings: SoftBodyParticleSettings) -> Self
pub fn particle_settings(self, settings: SoftBodyParticleSettings) -> Self
Sets the dynamics settings of the particles (damping, gravity scale, sleeping…).
Sourcepub fn linear_damping(self, damping: f32) -> Self
pub fn linear_damping(self, damping: f32) -> Self
Sets the linear damping of the particles.
Sourcepub fn gravity_scale(self, scale: f32) -> Self
pub fn gravity_scale(self, scale: f32) -> Self
Sets the gravity scale of the particles.
Sourcepub fn additional_solver_iterations(self, iterations: usize) -> Self
pub fn additional_solver_iterations(self, iterations: usize) -> Self
Requests extra solver substeps for the particles (and everything they touch).
Sourcepub fn additional_pgs_iterations(self, iterations: usize) -> Self
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.
Sourcepub fn surface_edges(&self) -> Vec<[u32; 2]>
pub fn surface_edges(&self) -> Vec<[u32; 2]>
The unique edges of the surface elements.
Sourcepub fn cell_edges(&self) -> Vec<[u32; 2]>
pub fn cell_edges(&self) -> Vec<[u32; 2]>
The unique edges of the cells.
Sourcepub fn surface_dihedrals(&self) -> Vec<[u32; 4]>
pub fn surface_dihedrals(&self) -> Vec<[u32; 4]>
The dihedral constraints across every interior edge of the triangle surface (3D only).
Source§impl SoftBodyBuilder
impl SoftBodyBuilder
Sourcepub fn new(positions: Vec<Vector>) -> Self
pub fn new(positions: Vec<Vector>) -> Self
A builder over the given world-space particle positions, with no element.
Sourcepub fn trimesh(vertices: Vec<Vector>, indices: Vec<[u32; 3]>) -> Option<Self>
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.
Sourcepub fn rope(start: Vector, end: Vector, num_particles: usize) -> Self
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.
Sourcepub fn cloth(
origin: Vector,
du: Vector,
dv: Vector,
nu: usize,
nv: usize,
) -> Self
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.
Sourcepub fn cloth_tube(
origin: Vector,
axis: Vector,
radius_start: f32,
radius_end: f32,
num_around: usize,
num_along: usize,
) -> Self
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.
Sourcepub fn cloth_anisotropic(
origin: Vector,
du: Vector,
dv: Vector,
nu: usize,
nv: usize,
warp: SpringCoefficients<f32>,
weft: SpringCoefficients<f32>,
shear: SpringCoefficients<f32>,
) -> Self
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).
Sourcepub fn cuboid(
center: Vector,
half_extents: Vector,
nx: usize,
ny: usize,
nz: usize,
) -> Self
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.
Sourcepub fn volumetric(
vertices: &[Vector],
indices: &[[u32; 3]],
cell_size: f32,
) -> Option<Self>
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.
Sourcepub fn volumetric_with(
vertices: &[Vector],
indices: &[[u32; 3]],
params: &VolumeMeshParameters,
) -> Option<Self>
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).
Sourcepub fn volumetric_skinned(
vertices: &[Vector],
indices: &[[u32; 3]],
cell_size: f32,
) -> Option<Self>
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.
Sourcepub fn sphere(center: Vector, radius: f32, subdivisions: usize) -> Self
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
impl Clone for SoftBodyBuilder
Source§fn clone(&self) -> SoftBodyBuilder
fn clone(&self) -> SoftBodyBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SoftBodyBuilder
impl Debug for SoftBodyBuilder
Source§impl Default for SoftBodyBuilder
impl Default for SoftBodyBuilder
Source§impl From<SoftBodyBuilder> for SoftBody
impl From<SoftBodyBuilder> for SoftBody
Source§fn from(builder: SoftBodyBuilder) -> Self
fn from(builder: SoftBodyBuilder) -> Self
Auto Trait Implementations§
impl !RefUnwindSafe for SoftBodyBuilder
impl !UnwindSafe for SoftBodyBuilder
impl Freeze for SoftBodyBuilder
impl Send for SoftBodyBuilder
impl Sync for SoftBodyBuilder
impl Unpin for SoftBodyBuilder
impl UnsafeUnpin for SoftBodyBuilder
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> 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>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
&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
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
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 moreimpl<T> MaybeSync for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.