HeightField

The heightField() function creates a height-mapped plane from a grid of values. Provide the edge size, grid resolution, and an array of heights.

const size = [100, 100];
const divisions = [1, 1];
const heights = [50, -50, -50, 50];
const colors = [
    "red",
    "green",
    "blue",
    "cyan"
];

heightField(size, divisions, heights)
    .color(colors);

orbit({ autoRotate: 1 });

Returns the HeightField object:


HeightField

Example usage:
// Sets height at vertex index 0 to 1.5 units
heightField.setHeight(0, 1.5);
field
mesh: THREE.Mesh<THREE.PlaneGeometry>
The THREE.Mesh instance representing this object.
Example
heightField.mesh.rotation.y = Math.PI / 8;
method
pos(position: Vec3): HeightField
Set the position of the object.
param position
A vector-like object representing the position.
Example
heightField.pos([0, 1, 0]);
method
color(color: HeightFieldColor): HeightField
Sets the color of the height field.
param color
A single color or an array of colors for each vertex.
Example
heightField.color("forestgreen");
method
material(material: THREE.Material): HeightField
Set the material of the object.
param material
A THREE.Material instance.
Example
heightField.material(new THREE.MeshStandardMaterial());
method
shaded(): HeightField
Configures the object to use a shaded material.
Example
heightField.shaded();
field
pointCount: number
Gets the number of vertices in the height field.
returns
Number of vertices.
Example
const count = heightField.pointCount;
method
getHeight(index: number): number
Gets the height of a specific vertex.
param index
Index of the vertex to get the height for.
returns
Height of the specified vertex.
Example
const peak = heightField.getHeight(0);
method
setHeight(index: number, height: number): void
Sets the height of a specific vertex.
param index
Index of the vertex to set the height for.
param height
New height for the vertex.
Example
heightField.setHeight(0, 2);
method
getColor(index: number): THREE.Color
Gets the color of a specific vertex.
param index
Index of the vertex to get the color for.
returns
Color of the specified vertex.
Example
const tint = heightField.getColor(0);
method
setColor(index: number, color: THREE.ColorRepresentation): void
Sets the color of a specific vertex.
param index
Index of the vertex to set the color for.
param color
New color for the vertex.
Example
heightField.setColor(0, "gold");