Installation
How to install Hello Terrain in your project
Prerequisites
Hello Terrain requires three.js as a peer dependency. Make sure you have it installed in your project.
Supported versions
| Package | Supported range |
|---|---|
three | >=0.183.0 |
@react-three/fiber (for @hello-terrain/react) | 8, 9, or 10 (including the 10 alpha) |
react / react-dom | 18 or 19 |
three.js 0.183.0 is the minimum because earlier releases drop the array layer when sampling array textures in WGSL, which breaks the array-texture terrain-field backend (used when maxNodes fits within the device's maxTextureArrayLayers, 256 by default).
React Three Fiber 10 itself requires three.js 0.185.0 or newer.
Packages
Hello Terrain provides two packages depending on your setup:
| Package | Description |
|---|---|
@hello-terrain/three | Core terrain system for vanilla three.js projects |
@hello-terrain/react | React bindings for react-three/fiber projects |
Installing for Three.js
If you're using vanilla three.js, install the core package:
# npm
npm install @hello-terrain/three three
# pnpm
pnpm add @hello-terrain/three three
# yarn
yarn add @hello-terrain/three threeBasic Usage
import * as THREE from "three";
import { TerrainGeometry } from "@hello-terrain/three";
const geometry = new TerrainGeometry(16, true);
const material = new THREE.MeshStandardMaterial();
const mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);Installing for React Three Fiber
If you're using react-three/fiber, install the React package along with its peer dependencies:
# npm
npm install @hello-terrain/react @react-three/fiber three react react-dom
# pnpm
pnpm add @hello-terrain/react @react-three/fiber three react react-dom
# yarn
yarn add @hello-terrain/react @react-three/fiber three react react-domThe @hello-terrain/react package includes @hello-terrain/three as a dependency, so you can use both packages in your React project.
Basic Usage (React Three Fiber 10)
React Three Fiber 10 renders every Canvas from @react-three/fiber with WebGPURenderer and initializes it for you, so no renderer setup is needed. Pass renderer options (antialias, logarithmicDepthBuffer, shadows, …) through the renderer prop:
import { Terrain } from "@hello-terrain/react";
import { Canvas } from "@react-three/fiber";
import { float } from "three/tsl";
const elevation = () => float(0);
function App() {
return (
<Canvas renderer={{ antialias: true }}>
<Terrain rootSize={128} maxLevel={10} elevation={elevation}>
{({ positionNode }) => (
<meshStandardNodeMaterial positionNode={positionNode} />
)}
</Terrain>
</Canvas>
);
}Use the default @react-three/fiber import. The @react-three/fiber/webgpu entry is deprecated as of 10.0.0-alpha.6, and the gl prop throws on a WebGPU canvas. @react-three/fiber/legacy is WebGL-only, so Hello Terrain cannot render there.
Basic Usage (React Three Fiber 8 / 9)
React Three Fiber 8 and 9 default to WebGLRenderer, so create and initialize a WebGPURenderer in an async gl factory:
import { Terrain } from "@hello-terrain/react";
import { Canvas } from "@react-three/fiber";
import type { WebGPURendererParameters } from "three/src/renderers/webgpu/WebGPURenderer.js";
import { float } from "three/tsl";
import * as THREE from "three/webgpu";
const elevation = () => float(0);
function App() {
return (
<Canvas
gl={async (props) => {
const renderer = new THREE.WebGPURenderer(
props as WebGPURendererParameters,
);
await renderer.init();
return renderer;
}}
>
<Terrain rootSize={128} maxLevel={10} elevation={elevation}>
{({ positionNode }) => (
<meshStandardNodeMaterial positionNode={positionNode} />
)}
</Terrain>
</Canvas>
);
}@hello-terrain/react expects a WebGPU renderer and a node material that accepts the positionNode provided by the terrain render prop.
TypeScript Support
Both packages ship with TypeScript definitions out of the box. No additional @types packages are required.
Next Steps
Once installed, start with the React overview for the React bindings, or jump to the Terrain Geometry docs if you're using the lower-level Three.js API directly.