Shape & ShapeStore
Shapes are collider geometry. Build one with a Shape.* helper (returns a plain descriptor) and pass it to createBody. For the guide, see Shapes.
Builders
Section titled “Builders”import { Shape } from "jolt-ts";
Shape.sphere(radius); // or ({ radius })Shape.box(halfExtents); // or ({ halfExtents, convexRadius? })Shape.capsule({ halfHeight, radius }); // Y-alignedShape.cylinder({ halfHeight, radius, convexRadius? }); // Y-alignedShape.convexHull({ points, maxConvexRadius? });Shape.mesh({ vertices, indices }); // static triangle meshShape.compound(children, { mutable? });Shape.offsetCenterOfMass(shape, offset);Descriptor fields
Section titled “Descriptor fields”| Kind | Fields |
|---|---|
sphere | radius |
box | halfExtents, convexRadius? (default 0.05) |
capsule | halfHeight, radius |
cylinder | halfHeight, radius, convexRadius? |
convexHull | points (Vector3[] or flat Float32Array), maxConvexRadius? |
mesh | vertices (flat [x,y,z,…]), indices (triangle list) |
compound | children: { shape, position?, rotation?, userData? }[], mutable? |
offsetCenterOfMass | shape, offset |
A ShapeInput — accepted anywhere a shape is — is either one of these descriptors or a ShapeResource.
ShapeResource
Section titled “ShapeResource”A built, reference-counted collider you can reuse across bodies. Created through the store (below) or implicitly retained when you pass the same resource to multiple bodies.
resource.raw; // the raw Jolt shaperesource.disposed; // booleanresource.dispose(); // release (also done by world/store disposal)ShapeStore
Section titled “ShapeStore”world.shapes is a ShapeStore — build a shape once and reuse it, optionally under a name.
// Named: retained by the store, retrievable, replaced if the name is reused.const crate = world.shapes.create("crate", Shape.box({ halfExtents: [0.5, 0.5, 0.5] }));world.shapes.get("crate"); // ShapeResource | undefined
// Unnamed: returns a resource you own.const gem = world.shapes.create(Shape.convexHull({ points }));
world.shapes.dispose(); // release all named shapes (also called by world.dispose())Reusing a resource across many bodies avoids rebuilding the collider each time — worthwhile for shapes used in bulk (crates, projectiles, tiles).