Create a height map from an array or an image, it draws itself and joins the level's collision
heights Array<Array<number>>|HTMLImageElement|HTMLCanvasElement|OffscreenCanvas|TextureInfomapSize Vector2 optionalWorld size along X and Z
height number optional, default 1World height of a full value
colors Array<Array<Color>>|HTMLImageElement|HTMLCanvasElement|OffscreenCanvas|TextureInfo optionalpos3D Vector3 optionalCenter of the map
smooth boolean optionalDefaults to render3D.smoothShading
const terrain = new HeightMap(heightImage, vec2(100, 100), 10, colorImage);
const y = terrain.getHeight(x, z); // stand things on it, or give them collideLevel
Vertex colors as [row][column], undefined for white
Number of columns, along X
World height of a full value
Heights 0-1 as [row][column], rows along Z, rebuild() after changing them
Smooth shading, rebuild() after changing it
Build the terrain mesh, one vertex per sample, centered on the map's own origin
smooth boolean optionalDefaults to render3D.smoothShading
Destroy the map, it leaves the level's collision
immediate boolean optional
Color of the nearest sample to a position, white when there are no colors
x number|Vector3X, or a position to take X and Z from
z number optional
World height at a position, exactly the height of the mesh buildMesh draws there, clamped at the edges
x number|Vector3X, or a position to take X and Z from
z number optional
Surface normal at a position, from the slope across a sample
x number|Vector3X, or a position to take X and Z from
z number optional
Distance along a ray to where it crosses the terrain surface, or undefined for a miss
- Exact: the ground is flat inside each triangle, so the ray is checked between each grid line and
cell diagonal it crosses, and a hill it only grazes is still hit
- A ray that starts under the ground crosses on its way out, so the hit is still on the surface
ray Ray3DFrom screenToRay, or any ray
Make the mesh again from the heights and colors, after changing them or smooth
Keeps an eye on its placement, called automatically each frame