Physics · class

ClothBody

Explained in Your first game, Rigid bodies.

class ClothBody
import { ClothBody } from '@driftengine/physics';

Constructor

new

constructor(positions: Float32Array, links: Int32Array, bendLinks: Int32Array, options?: ClothOptions)
ParameterTypeDescription
positionsFloat32Array
linksInt32Array
bendLinksInt32Array
options?ClothOptions

Properties

NameTypeDescription
positionreadonlyFloat32Arrayxyz-packed particle positions.
velocityreadonlyFloat32Arrayxyz-packed velocities.
invMassreadonlyFloat32ArrayInverse mass per particle. Zero pins it.
countreadonlynumber
iterationsreadonlynumber
dampingreadonlynumber
thicknessreadonlynumber
couplingreadonlynumberSee ClothOptions.coupling. 0 is one-way, which is the default.
particleMassreadonlynumberSee ClothOptions.particleMass. Kilograms, read only by the coupling.
selfDistancereadonlynumberSee ClothOptions.selfDistance. 0 is off, which is the default.
gravityXnumber
gravityYnumber
gravityZnumber

Methods

pin

pin(index: number, pinned?: boolean): void

Pin a particle where it is, or release it.

ParameterTypeDescription
indexnumber
pinned?boolean

step

step(world: PhysicsWorld | null, dt: number): void

Advance one fixed tick.

ParameterTypeDescription
worldPhysicsWorld | null
dtnumber
More

Integrate, project every constraint iterations times, then derive velocity from how far each particle actually moved — which is what makes it position-based: a constraint that moves a particle also, by construction, changes its velocity, so nothing has to reconcile the two.