BabylonJS/Babylon.js · error

No mesh provided to create physics shape.

Error message

No mesh provided to create physics shape.

What it means

When creating a MESH or CONVEX_HULL PhysicsShape, HavokPlugin needs a source mesh in the shape options to extract vertex positions and triangle indices for the Havok collider. If the relevant options field holds no mesh, it cannot build the collider and throws. The plugin requires actual geometry, not just a shape-type declaration.

Source

Thrown at packages/dev/core/src/Physics/v2/Plugins/havokPlugin.ts:1841

                        const includeChildMeshes = !!options.includeChildMeshes;
                        const needIndices = type != PhysicsShapeType.CONVEX_HULL;
                        const accum = new MeshAccumulator(mesh, needIndices, mesh?.getScene());
                        accum.addNodeMeshes(mesh, includeChildMeshes);

                        const positions = accum.getVertices(this._hknp);
                        const numVec3s = positions.numObjects / 3;

                        if (type == PhysicsShapeType.CONVEX_HULL) {
                            shape._pluginData = this._hknp.HP_Shape_CreateConvexHull(positions.offset, numVec3s)[1];
                        } else {
                            const triangles = accum.getTriangles(this._hknp);
                            const numTriangles = triangles.numObjects / 3;
                            shape._pluginData = this._hknp.HP_Shape_CreateMesh(positions.offset, numVec3s, triangles.offset, numTriangles)[1];
                            accum.freeBuffer(this._hknp, triangles);
                        }
                        accum.freeBuffer(this._hknp, positions);
                    } else {
                        throw new Error("No mesh provided to create physics shape.");
                    }
                }
                break;
            case PhysicsShapeType.HEIGHTFIELD:
                {
                    if (options.groundMesh) {
                        // update options with datas from groundMesh
                        this._createOptionsFromGroundMesh(options);
                    }
                    if (options.numHeightFieldSamplesX && options.numHeightFieldSamplesZ && options.heightFieldSizeX && options.heightFieldSizeZ && options.heightFieldData) {
                        const totalNumHeights = options.numHeightFieldSamplesX * options.numHeightFieldSamplesZ;
                        const numBytes = totalNumHeights * 4;
                        const bufferBegin = this._hknp._malloc(numBytes);

                        const heightBuffer = new Float32Array(this._hknp.HEAPU8.buffer, bufferBegin, totalNumHeights);
                        for (let x = 0; x < options.numHeightFieldSamplesX; x++) {
                            for (let z = 0; z < options.numHeightFieldSamplesZ; z++) {
                                const hkBufferIndex = z * options.numHeightFieldSamplesX + x;

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Pass the source mesh explicitly: new PhysicsShapeMesh(parent, mesh, scene) or ensure options.mesh is set.
  2. Await mesh/asset loading and ensure geometry exists before creating the shape (mesh.getTotalVertices() > 0).
  3. For a shape around the node itself, use new PhysicsAggregate(node, PhysicsShapeType.MESH, {mesh: node as Mesh}, scene).

Example fix

// before
const shape = new PhysicsShapeMesh(parent, undefined, scene);
// after
if (!mesh || mesh.getTotalVertices() === 0) throw new Error("need a mesh with geometry");
const shape = new PhysicsShapeMesh(parent, mesh, scene);
Defensive patterns

Strategy: validation

Validate before calling

if (!mesh || mesh.getTotalVertices() === 0) {
  throw new Error("mesh must be loaded with vertex data before creating a physics shape");
}

Type guard

function isUsableMesh(m: unknown): m is Mesh {
  return m instanceof Mesh && m.getTotalVertices() > 0;
}

Prevention

When it happens

Trigger: new PhysicsShapeMesh(parent, mesh, scene) with a null/undefined mesh argument; or new PhysicsShape({type: PhysicsShapeType.MESH}) without passing a mesh via the mesh parameter/options, reaching havokPlugin.ts:1841.

Common situations: Creating a physics shape before the mesh finishes loading (async asset load not awaited); passing a thin wrapper like AbstractMesh with no vertex data; forgetting the mesh parameter when using the generic PhysicsShape constructor.

Related errors


AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30). Data as JSON: /api/errors/55ed64dee08083b4. Report an issue: GitHub.