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 of creating hills and valleys on your ground.
MeshBuilder
Usage:
javascript
const ground = BABYLON.MeshBuilder.CreateGroundFromHeightMap("gdhm", url_to_height_map, options, scene); //scene is optional and defaults to the current scene
option | value | default value |
---|---|---|
option width | value (number) size of the map width | default value 10 |
option height | value (number) size of the map height | default value 10 |
option subdivisions | value (number) number of map subdivisions | default value 1 |
option minHeight | value (number) minimum altitude | default value 0 |
option maxHeight | value (number) maximum altitude | default value 1 |
option onReady | value (function) a callback js function that is called and passed the just built mesh | default value (mesh) => {return;} |
option updatable | value (boolean) true if the mesh is updatable | default value false |
Examples
The following image is used for the height map in the first examples
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 :
javascript
var ground = BABYLON.Mesh.CreateGroundFromHeightMap("ground", heightMapPath, width, height, subdivisions, minHeight, maxHeight, scene, updatable, onReadyCallback);