# Physics with height map?

**URL:** <https://forum.babylonjs.com/t/physics-with-height-map/59039>\
**Category:** Questions\
**Tags:** physics\
**Created:** [June 19, 2025, 3:37am UTC](https://forum.babylonjs.com/t/physics-with-height-map/59039 "2025-06-19T03:37:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alekop](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/alekop/32/4380_2.png) [@alekop](https://forum.babylonjs.com/u/alekop)\
**Post date:** [June 19, 2025, 3:37am UTC](https://forum.babylonjs.com/t/physics-with-height-map/59039/1 "2025-06-19T03:37:33Z")

</div>

Trying to add a physics aggregate to a height map, but failing with `No valid mesh was provided for mesh or convex hull shape parameter. Please provide a mesh with valid geometry (number of vertices greater than 0).`

If I comment out the aggregate creation, the heightmap renders.

> **[Babylon.js Playground](https://playground.babylonjs.com/#LQ4LI1%23725)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL and WebGPU 3D scenes

I found some working examples that use the deprecated `BABYLON.Mesh.CreateGroundFromHeightMap`. That one uses a callback, but the MeshBuilder version seems to by sync?

---

<div class="post-metadata">

**Author:** ![regna](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/regna/32/23915_2.png) [@regna](https://forum.babylonjs.com/u/regna)\
**Post date:** [June 19, 2025, 4:19am UTC](https://forum.babylonjs.com/t/physics-with-height-map/59039/2 "2025-06-19T04:19:00Z")

</div>

I believe something like this should work:

> **[Babylon.js Playground](https://playground.babylonjs.com/#LQ4LI1%23728)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL and WebGPU 3D scenes

```ts
const ground = BABYLON.MeshBuilder.CreateGroundFromHeightMap("gdhm", "textures/heightMap.png", {
    width: 5,
    height: 5,
    subdivisions: 10,
    maxHeight: 1,

    onReady: (mesh, heightBuffer) => {
        const aggregate = new BABYLON.PhysicsAggregate(mesh, BABYLON.PhysicsShapeType.MESH);
        console.log('aggregate:', aggregate);
    },

    // passHeightBufferInCallback: true // if you need to use `heightBuffer` in the callback above
});

```

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [June 19, 2025, 7:53am UTC](https://forum.babylonjs.com/t/physics-with-height-map/59039/3 "2025-06-19T07:53:56Z")

</div>

PG from the documentation : [https://playground.babylonjs.com/#I37D8G#18](https://playground.babylonjs.com/#I37D8G#18)

---

<div class="post-metadata">

**Author:** ![alekop](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/alekop/32/4380_2.png) [@alekop](https://forum.babylonjs.com/u/alekop)\
**Post date:** [June 19, 2025, 2:49pm UTC](https://forum.babylonjs.com/t/physics-with-height-map/59039/4 "2025-06-19T14:49:12Z")

</div>

I missed that one. Google keeps bringing up the `Mesh` PGs.

Strange API… It returns the mesh immediately, but it’s not ready. IMHO, it should return a promise instead of the onReady callback.
