Skip to main content

Destructible 3D

Destructible3DBehavior fractures render meshes using @dgreenheck/three-pinata (FractureOptions, DestructibleMesh) and produces fragment collider/body definitions for the WASM stage. Use it on breakable props, crates, and walls where visual shards should match physics debris.

Minimal example​

website/snippets/behaviors/catalog/destructible-3d.ts:

import { Destructible3DBehavior } from '@zylem/game-lib/behavior';

const destructible = crate.use(Destructible3DBehavior, {
fragmentPhysics: {
mode: 'independent',
outwardVelocity: 4,
},
});

crate.onCollision(() => {
if (!destructible.isFractured()) {
destructible.fracture();
}
});

Options​

FieldRole
fractureOptionsVoronoi/chip settings passed to pinata.
innerMaterialInterior material after fracture.
colliderFragment shape (convexHull, cuboid, trimesh), sensor, groups.
fragmentPhysicsCompound vs independent bodies, inherited velocity, outward impulse.
prebakeWorkerUrlOptional worker URL for async Voronoi prebake.

Handle​

  • fracture(), prebake(), prebakeAsync(), repair(), isFractured(), getFragments().

Host code attaches fragment entities to the simulation using the plain-data definitions the behavior emits.

Pitfalls​

  • Target entities need destructible geometry; simple boxes may need mesh setup compatible with pinata.
  • Prebake reduces hitch on first break but requires worker bundle deployment.
  • repair() restores visuals; re-sync colliders if fragments were spawned into the world.

API reference​