Constructor
new HeightMap(heights, sizeopt, heightopt, colorsopt)
Create a height map from an array or an image
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
heights | Array.<Array.<number>> | | |||
size | Vector2 | <optional> | World size along X and Z | |
height | number | <optional> | 1 | World height of a full value |
colors | Array.<Array.<Color>> | | <optional> |
- Source
const terrain = new HeightMap(heightImage, vec2(100, 100), 10, colorImage);
new EngineObject3D(vec3(), terrain.buildMesh());
const y = terrain.getHeight(x, z); // stand things on itMembers
colors :Array.<Array.<Color>>|undefined
- Array.<Array.<Color>> |
undefined
| Type | Description |
|---|---|
| Array.<Array.<Color>> | | Vertex colors as [row][column], undefined for white |
- Source
columns
Number of columns, along X
- Source
height
Properties| Type | Description |
|---|---|
| number | World height of a full value |
- Source
heights
Properties| Type | Description |
|---|---|
| Array.<Array.<number>> | Heights 0-1 as [row][column], rows along Z |
- Source
rows
Number of rows, along Z
- Source
size
Properties| Type | Description |
|---|---|
| Vector2 | World size along X and Z |
- Source
Methods
buildMesh(smoothopt) → {Mesh}
Build the terrain mesh, one vertex per sample, centered on the origin
| Name | Type | Attributes | Description |
|---|---|---|---|
smooth | boolean | <optional> | Defaults to render3D.smoothShading |
- Source
- Type:
- Mesh
getColor(x, zopt) → {Color}
Color of the nearest sample to a position, white when there are no colors
| Name | Type | Attributes | Description |
|---|---|---|---|
x | number | | X, or a position to take X and Z from | |
z | number | <optional> |
- Source
- Type:
- Color
getHeight(x, zopt) → {number}
World height at a position, exactly the height of the mesh buildMesh draws there, clamped at the edges
| Name | Type | Attributes | Description |
|---|---|---|---|
x | number | | X, or a position to take X and Z from | |
z | number | <optional> |
- Source
- Type:
- number
getNormal(x, zopt) → {Vector3}
Surface normal at a position, from the slope across a sample
| Name | Type | Attributes | Description |
|---|---|---|---|
x | number | | X, or a position to take X and Z from | |
z | number | <optional> |
- Source
- Type:
- Vector3
raycast(ray) → {number|undefined}
Distance along a ray to where it crosses the terrain surface, or undefined for a miss
- Steps along the ray half a cell at a time, then narrows in on the exact spot
- A ray that starts under the ground crosses on its way out, so the hit is still on the surface
| Name | Type | Description |
|---|---|---|
ray | Ray3D | From screenToRay, or any ray |
- Source
- Type:
- number |
undefined