The description of a soft body to create.

Start from one of the generators (SoftBodyDesc.rope, cloth, cuboid, sphere, trimesh, volumetric in 3D; rope, polygon, disk, grid, polyline, volumetric in 2D) or from raw particle positions, then tune it with the chainable setters. The description holds no WASM memory: it is applied when the soft body is created.

Constructors

  • A description over raw world-space particle positions (flattened), with no element: add edges, cells and a surface with the setters.

    Parameters

    • Optional positions: number[] | Float32Array

    Returns SoftBodyDesc

Properties

additionalPgsIterations: number

Extra internal PGS iterations per substep for the body and everything it touches.

additionalSolverIterations: number

Extra solver substeps requested for the body and everything it touches.

canSleep: boolean

Whether the body may fall asleep.

The constitutive model of the cells.

dominanceGroup: number

The dominance group of the body.

generator: any
gravityScale: number

Gravity scale of the particles.

linearDamping: number

Linear damping of the particles.

mass: number

The total mass of the body, spread over its particles, or null to use particleMass.

masses: Float32Array

Per-particle masses, or null for uniform masses.

The material of the soft body, or null to keep the default one (with softness applied on top when set).

oriented: boolean

Whether the shape of the body's collision surface is built with the ORIENTED flag (null: whenever the surface is closed).

particleMass: number

The uniform mass of the particles (ignored when masses is set).

particleRadius: number

The thickness of the particles (null: what the generator chose).

pinnedParticles: Uint32Array

The indices of the pinned particles.

selfContacts: boolean

Whether the body's surface collides with itself.

setters: any
shapeMatching: boolean

Whether shape matching holds the body's shape (null: what the generator chose, off for raw positions).

skinCollision: boolean

Whether the body collides through its skin rather than through its cells' boundary.

A uniform softness applied to every constraint of the material, or null.

The solver holding the cells together.

surfaceCollider: ColliderDesc

The template of the body's colliders (their shape is replaced by the body's deformable surface), or null for a body without collisions.

translation: Vector

A translation applied to every particle.

userData?: unknown

An arbitrary user-defined object associated with the soft body.

volumeFactor: number

The target volume multiplier of the volume preservation (> 1 inflates the body).

volumePreservation: boolean

Whether the area/volume enclosed by the body's closed surfaces is preserved (null: what the generator chose, off for raw positions).

withGenerator: any

Methods

  • Adds structural edges (flattened particle pairs).

    Parameters

    • edges: number[] | Uint32Array

    Returns SoftBodyDesc

  • Appends the particles and elements of another description to this one.

    Parameters

    Returns SoftBodyDesc

  • Internal

    Builds the WASM-side builder this description stands for. The result must be freed.

    Returns RawSoftBodyBuilder

  • The number of particles the description currently generates.

    Returns number

  • The flattened world-space positions of the particles the description generates.

    Returns Float32Array

  • Sets the extra internal PGS iterations per substep for the body and everything it touches (default: 3).

    Parameters

    • iterations: number

    Returns SoftBodyDesc

  • Sets the extra solver substeps requested for the body and everything it touches.

    Parameters

    • iterations: number

    Returns SoftBodyDesc

  • Replaces the bending edges (flattened particle pairs).

    Parameters

    • edges: number[] | Uint32Array

    Returns SoftBodyDesc

  • Sets whether the body may fall asleep.

    Parameters

    • canSleep: boolean

    Returns SoftBodyDesc

  • Replaces the cells (flattened triangles in 2D, tetrahedra in 3D).

    Parameters

    • cells: number[] | Uint32Array

    Returns SoftBodyDesc

  • Sets the dominance group of the body.

    Parameters

    • group: number

    Returns SoftBodyDesc

  • Overrides the softness of the given edges.

    Parameters

    Returns SoftBodyDesc

  • Multiplies the tear thresholds of the given edges.

    Parameters

    • edges: number[] | Uint32Array
    • resistances: number[] | Float32Array

    Returns SoftBodyDesc

  • Replaces the structural edges (flattened particle pairs).

    Parameters

    • edges: number[] | Uint32Array

    Returns SoftBodyDesc

  • Sets the gravity scale of the particles.

    Parameters

    • scale: number

    Returns SoftBodyDesc

  • Sets the linear damping of the particles.

    Parameters

    • damping: number

    Returns SoftBodyDesc

  • Sets the total mass of the body, spread over its particles.

    Parameters

    • mass: number

    Returns SoftBodyDesc

  • Sets per-particle masses.

    Parameters

    • masses: number[] | Float32Array

    Returns SoftBodyDesc

  • Removes the body's colliders: it will not collide with anything.

    Returns SoftBodyDesc

  • Sets whether the shape of the body's collision surface is built with the ORIENTED flag, like a 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.

    Parameters

    • oriented: boolean

    Returns SoftBodyDesc

  • Sets the uniform mass of the particles.

    Parameters

    • mass: number

    Returns SoftBodyDesc

  • Sets the thickness of the particles.

    Parameters

    • radius: number

    Returns SoftBodyDesc

  • Pins the given particles in place.

    Parameters

    • pinned: number[] | Uint32Array

    Returns SoftBodyDesc

  • Makes the body's surface collide with itself.

    Parameters

    • enabled: boolean

    Returns SoftBodyDesc

  • Holds the body's shape by shape matching.

    Parameters

    • enabled: boolean

    Returns SoftBodyDesc

  • Sets a skin: a finer mesh (flattened world-space vertices and elements) embedded in the cells, which follows them.

    Parameters

    • vertices: number[] | Float32Array
    • indices: number[] | Uint32Array

    Returns SoftBodyDesc

  • Makes the body collide through its skin rather than through its cells' boundary.

    Parameters

    • enabled: boolean

    Returns SoftBodyDesc

  • Sets a uniform softness for every constraint of the material.

    Parameters

    • naturalFrequency: number
    • dampingRatio: number

    Returns SoftBodyDesc

  • Sets the solver holding the cells together (SoftBodySolver.Fem needs cells).

    Parameters

    Returns SoftBodyDesc

  • Replaces the boundary elements (flattened segments in 2D, triangles in 3D), oriented outward.

    Parameters

    • surface: number[] | Uint32Array

    Returns SoftBodyDesc

  • Sets the template of the body's colliders: its friction, restitution, groups, events and other settings are kept, its shape is replaced by the body's deformable surface.

    Parameters

    Returns SoftBodyDesc

  • Makes every edge resist stretching only (a rope or a net that folds freely).

    Returns SoftBodyDesc

  • Translates every particle.

    Parameters

    Returns SoftBodyDesc

  • Sets the user data associated with the soft body.

    Parameters

    • data: unknown

    Returns SoftBodyDesc

  • Sets the target volume multiplier (> 1 inflates the body); this also enables the volume preservation.

    Parameters

    • factor: number

    Returns SoftBodyDesc

  • Enables the preservation of the area/volume enclosed by the body's closed surfaces.

    Parameters

    • enabled: boolean

    Returns SoftBodyDesc

  • A disk: a ring of numParticles particles holding its area (a pressurized blob).

    Parameters

    • center: Vector
    • radius: number
    • numParticles: number

    Returns SoftBodyDesc

  • A grid of nx by ny particles filled with triangle cells.

    Parameters

    Returns SoftBodyDesc

  • A closed polygon of particles (flattened points) holding its area.

    Parameters

    • points: number[] | Float32Array

    Returns SoftBodyDesc

  • A polyline body: the vertices are particles linked by the segments (a line strip when indices is not given). Returns null if the polyline is empty.

    Parameters

    • vertices: Float32Array
    • Optional indices: Uint32Array

    Returns SoftBodyDesc

  • A rope of numParticles particles from start to end.

    Parameters

    Returns SoftBodyDesc

  • A body filling the closed surface (segments in 2D, triangles in 3D) with cells of the given size; skinned keeps the surface as a skin embedded in the cells. Returns null if the surface cannot be meshed.

    Parameters

    • vertices: Float32Array

      The flattened world-space vertices of the surface.

    • indices: Uint32Array

      The flattened elements of the surface.

    • cellSize: number
    • Optional skinned: boolean

    Returns SoftBodyDesc