API

Creating Ground From a Height Map

Ground From a Height Map

When the ground is created using groundFromHeightMap, the surface of the ground can be perturbed by a grayscale image file called a height map. Lighter areas are displayed higher than darker areas. This is a way to create hills and valleys on your ground.

MeshBuilder

Usage:

import { MeshBuilder } from "@babylonjs/core/Meshes/meshBuilder";
const ground = MeshBuilder.CreateGroundFromHeightMap("gdhm", url_to_height_map, options, scene); //scene is optional and defaults to the current scene
optionvaluedefault value
width
(number) size of the map width
10
height
(number) size of the map height
10
subdivisions
(number) number of map subdivisions
1
minHeight
(number) minimum altitude
0
maxHeight
(number) maximum altitude
1
onReady
(function) a JavaScript callback function that is called and passed the newly built mesh
(mesh) => {return;}
updatable
(boolean) true if the mesh is updatable
false

Examples

The following image is used for the height map in the first examples.

height map
Low subdivisions: Create Ground From A HeightMap - Low Subdivisions High subdivisions: Create Ground From A HeightMap - High Subdivisions

Flat world: Create Ground From A HeightMap

Mesh

Usage :

import { Mesh } from "@babylonjs/core/Meshes/mesh";
var ground = Mesh.CreateGroundFromHeightMap("ground", heightMapPath, width, height, subdivisions, minHeight, maxHeight, scene, updatable, onReadyCallback);