# Ground height map from UInt8Array corrupted points

**URL:** <https://forum.babylonjs.com/t/ground-height-map-from-uint8array-corrupted-points/61456>\
**Category:** Questions\
**Tags:** mesh, heightmap\
**Created:** [November 17, 2025, 6:33pm UTC](https://forum.babylonjs.com/t/ground-height-map-from-uint8array-corrupted-points/61456 "2025-11-17T18:33:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Khanon](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/khanon/32/14980_2.png) [@Khanon](https://forum.babylonjs.com/u/Khanon)\
**Post date:** [November 17, 2025, 6:33pm UTC](https://forum.babylonjs.com/t/ground-height-map-from-uint8array-corrupted-points/61456/1 "2025-11-17T18:33:49Z")

</div>

I’m experimenting with `BABYLON.MeshBuilder.CreateGroundFromHeightMap` and I have a question and an issue.

* * *

Question: I don’t have clear what `minHeight` and `maxHeight` are doing exactly. For what I’ve been testing, those two parameters refer to the mimumn and maximum values the ground will have after being created, regardless the actual height map values I’m sending to `CreateGroundFromHeightMap` . It will adjust the mesh vertices to that range (0 minimum and 1 maximum by default).

Is that correct?

* * *

Issue (more important): Depending on the amplitude of the height points I’m sending to `CreateGroundFromHeightMap` , if some of them are lower than a threshold, the vertex is corrupted or whatever, and it appears upside into the air.

Here is an example working fine:

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

Then, if I increment the amplitude of the height map, one of the vertices appear in the sky. I believe this is the vertex with lowest value (if I’m not wrong by some tests I’ve done).

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

Incrementing more the amplitude, more and more vertices are corrupted.

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

Some idea what’s coming on here?

---

<div class="post-metadata">

**Author:** ![Leonardo\_Villalobos](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/leonardo_villalobos/32/9628_2.png) [@Leonardo\_Villalobos](https://forum.babylonjs.com/u/Leonardo_Villalobos)\
**Post date:** [November 17, 2025, 8:54pm UTC](https://forum.babylonjs.com/t/ground-height-map-from-uint8array-corrupted-points/61456/2 "2025-11-17T20:54:52Z")

</div>

I would try “Uint8ClampedArray” in “data” definition, if it does not disturb data visualization (flat point).

```auto
const data = new Uint8ClampedArray(mapWidth * mapHeight * 4);

```

If you check the numbers in “value”, at least 6 calculations of “value” are out of the Uint8Array definition (are \< = -1), and therefore, they are not assigned (consistent with numbers of points gone). So “value” is set to whatever JS gives, instead an error, not related to calculation. Set to Uint8ClampedArray, since you can’t assign values less than -1, by definition, Or use an heightOffset higher [from 21 (still gives some negatives but are \> -1 and \< 0) or more to whatever you consider], to assure all calculations of “value” are considered.

```auto
    let value = noise2D(x, y) * amplitude + heightOffset + 1; by the way, if you change the last term (…+1)

```

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/6/b/6b664740ee7318b744f1a25b3fa52f0c5c6b84bf.png)

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/4/4/4499a098df67de85c617bed660f41f091879ff1e.png)

---

<div class="post-metadata">

**Author:** ![Khanon](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/khanon/32/14980_2.png) [@Khanon](https://forum.babylonjs.com/u/Khanon)\
**Post date:** [November 18, 2025, 9:02am UTC](https://forum.babylonjs.com/t/ground-height-map-from-uint8array-corrupted-points/61456/3 "2025-11-18T09:02:36Z")

</div>

You are absolutelly right, that’s why it is `unsigned int` 😅

Thanks for the explanation!
