{"record":{"id":"55ed64dee08083b4","repo":"BabylonJS/Babylon.js","slug":"no-mesh-provided-to-create-physics-shape","errorCode":null,"errorMessage":"No mesh provided to create physics shape.","messagePattern":"No mesh provided to create physics shape\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Physics/v2/Plugins/havokPlugin.ts","lineNumber":1841,"sourceCode":"                        const includeChildMeshes = !!options.includeChildMeshes;\r\n                        const needIndices = type != PhysicsShapeType.CONVEX_HULL;\r\n                        const accum = new MeshAccumulator(mesh, needIndices, mesh?.getScene());\r\n                        accum.addNodeMeshes(mesh, includeChildMeshes);\r\n\r\n                        const positions = accum.getVertices(this._hknp);\r\n                        const numVec3s = positions.numObjects / 3;\r\n\r\n                        if (type == PhysicsShapeType.CONVEX_HULL) {\r\n                            shape._pluginData = this._hknp.HP_Shape_CreateConvexHull(positions.offset, numVec3s)[1];\r\n                        } else {\r\n                            const triangles = accum.getTriangles(this._hknp);\r\n                            const numTriangles = triangles.numObjects / 3;\r\n                            shape._pluginData = this._hknp.HP_Shape_CreateMesh(positions.offset, numVec3s, triangles.offset, numTriangles)[1];\r\n                            accum.freeBuffer(this._hknp, triangles);\r\n                        }\r\n                        accum.freeBuffer(this._hknp, positions);\r\n                    } else {\r\n                        throw new Error(\"No mesh provided to create physics shape.\");\r\n                    }\r\n                }\r\n                break;\r\n            case PhysicsShapeType.HEIGHTFIELD:\r\n                {\r\n                    if (options.groundMesh) {\r\n                        // update options with datas from groundMesh\r\n                        this._createOptionsFromGroundMesh(options);\r\n                    }\r\n                    if (options.numHeightFieldSamplesX && options.numHeightFieldSamplesZ && options.heightFieldSizeX && options.heightFieldSizeZ && options.heightFieldData) {\r\n                        const totalNumHeights = options.numHeightFieldSamplesX * options.numHeightFieldSamplesZ;\r\n                        const numBytes = totalNumHeights * 4;\r\n                        const bufferBegin = this._hknp._malloc(numBytes);\r\n\r\n                        const heightBuffer = new Float32Array(this._hknp.HEAPU8.buffer, bufferBegin, totalNumHeights);\r\n                        for (let x = 0; x < options.numHeightFieldSamplesX; x++) {\r\n                            for (let z = 0; z < options.numHeightFieldSamplesZ; z++) {\r\n                                const hkBufferIndex = z * options.numHeightFieldSamplesX + x;\r","sourceCodeStart":1823,"sourceCodeEnd":1859,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Physics/v2/Plugins/havokPlugin.ts#L1823-L1859","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass the source mesh explicitly: new PhysicsShapeMesh(parent, mesh, scene) or ensure options.mesh is set.","Await mesh/asset loading and ensure geometry exists before creating the shape (mesh.getTotalVertices() > 0).","For a shape around the node itself, use new PhysicsAggregate(node, PhysicsShapeType.MESH, {mesh: node as Mesh}, scene)."],"exampleFix":"// before\nconst shape = new PhysicsShapeMesh(parent, undefined, scene);\n// after\nif (!mesh || mesh.getTotalVertices() === 0) throw new Error(\"need a mesh with geometry\");\nconst shape = new PhysicsShapeMesh(parent, mesh, scene);","handlingStrategy":"validation","validationCode":"if (!mesh || mesh.getTotalVertices() === 0) {\n  throw new Error(\"mesh must be loaded with vertex data before creating a physics shape\");\n}","typeGuard":"function isUsableMesh(m: unknown): m is Mesh {\n  return m instanceof Mesh && m.getTotalVertices() > 0;\n}","tryCatchPattern":null,"preventionTips":["Await mesh/asset imports before building physics shapes from them.","Pass the mesh explicitly via the shape constructor or options instead of relying on inference.","Check getTotalVertices() > 0 as a preflight in physics setup code."],"tags":["physics","havok","mesh","missing-parameter"],"backgroundTag":"missing-mesh-parameter","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}