Skip to main content

SoftBodyBuilder

Struct SoftBodyBuilder 

Source
pub struct SoftBodyBuilder {
Show 24 fields pub positions: Vec<Vec2>, 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 cells: Vec<[u32; 3]>, pub surface: Vec<[u32; 2]>, 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<Vec2>, 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<Vec2>

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.

§cells: Vec<[u32; 3]>

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

§surface: Vec<[u32; 2]>

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<Vec2>, Vec<[u32; 2]>)>

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

§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) -> &[Vec2]

The particle positions set so far.

Source

pub fn positions(self, positions: Vec<Vec2>) -> SoftBodyBuilder

Sets the world-space positions of the particles.

Source

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

Sets the mass of every particle.

Source

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

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

Source

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

Sets per-particle masses.

Source

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

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]>) -> SoftBodyBuilder

Sets the structural edges.

Source

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

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) -> SoftBodyBuilder

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]>) -> SoftBodyBuilder

Sets the bending edges.

Source

pub fn tension_only(self) -> SoftBodyBuilder

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

Source

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

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: Vec2) -> SoftBodyBuilder

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<Vec2>, indices: Vec<[u32; 2]>, ) -> SoftBodyBuilder

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) -> SoftBodyBuilder

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 surface(self, surface: Vec<[u32; 2]>) -> SoftBodyBuilder

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) -> SoftBodyBuilder

Sets the material.

Source

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

Sets the same softness for every constraint family.

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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) -> SoftBodyBuilder

Sets the constitutive model of the cells.

Source

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

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) -> SoftBodyBuilder

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

Source

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

Enables shape matching.

Source

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

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

Source

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

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) -> SoftBodyBuilder

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

Source

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

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) -> SoftBodyBuilder

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, ) -> SoftBodyBuilder

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

Source

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

Sets the linear damping of the particles.

Source

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

Sets the gravity scale of the particles.

Source

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

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

Source

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

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) -> SoftBodyBuilder

Whether the particles may fall asleep.

Source

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

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§

impl SoftBodyBuilder

Source

pub fn new(positions: Vec<Vec2>) -> SoftBodyBuilder

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

Source

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

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 polyline( vertices: Vec<Vec2>, indices: Option<Vec<[u32; 2]>>, ) -> Option<SoftBodyBuilder>

A soft body from a polyline (2D only): particles at the vertices, structural edges and the surface on the segments, bending edges at two-segment vertices, shape matching, an inside (Self::volume_preservation) if closed counter-clockwise; None for an empty polyline.

Source

pub fn rope(start: Vec2, end: Vec2, num_particles: usize) -> SoftBodyBuilder

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 volumetric( vertices: &[Vec2], indices: &[[u32; 2]], cell_size: f32, ) -> Option<SoftBodyBuilder>

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: &[Vec2], indices: &[[u32; 2]], params: &VolumeMeshParameters, ) -> Option<SoftBodyBuilder>

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: &[Vec2], indices: &[[u32; 2]], cell_size: f32, ) -> Option<SoftBodyBuilder>

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 polygon(points: Vec<Vec2>) -> SoftBodyBuilder

A closed polygon (counter-clockwise points): structural edges along the boundary, bending edges between second neighbors, and area preservation (2D only).

The particle radius defaults to half the mean edge length.

Source

pub fn disk(center: Vec2, radius: f32, num_particles: usize) -> SoftBodyBuilder

A regular polygon with num_particles boundary particles (see Self::polygon, 2D only).

Source

pub fn grid( center: Vec2, half_extents: Vec2, nx: usize, ny: usize, ) -> SoftBodyBuilder

A solid rectangle triangulated on a nx × ny particle grid (2D only), with structural edges along the triangle edges and the boundary segments as surface.

The particle radius defaults to half the smallest cell size.

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<(), Error>

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

impl Default for SoftBodyBuilder

Source§

fn default() -> SoftBodyBuilder

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

impl From<SoftBodyBuilder> for SoftBody

Source§

fn from(builder: SoftBodyBuilder) -> SoftBody

Converts to this type from the input type.
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, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

Source§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U

Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist.
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> ConditionalSend for T
where T: Send,

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> FromTemplate for T
where T: Clone + Default + Unpin,

Source§

type Template = T

The Template for this type.
Source§

impl<T> FromWorld for T
where T: Default,

Source§

fn from_world(_world: &mut World) -> T

Creates Self using default().

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoResult<T> for T

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

impl<A> Is for A
where A: Any,

Source§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
Source§

impl<T> MaybeSync for T
where T: Sync + ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Settings for T
where T: 'static + Send + Sync,

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> Template for T
where T: Clone + Unpin,

Source§

type Output = T

The type of value produced by this Template.
Source§

fn build_template( &self, _context: &mut TemplateContext<'_, '_>, ) -> Result<<T as Template>::Output, BevyError>

Uses this template and the given entity context to produce a Template::Output.
Source§

fn clone_template(&self) -> T

Clones this template. See Clone.
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.
Source§

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

fn clone_type_data(&self) -> Box<dyn TypeData>

Creates a type-erased clone of self.
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more