THREE.JS / FOUNDATIONS 205

The mesh and collider must agree.

This route turns Rapier's heightfield boundary into a terrain laboratory: one sampled function drives the visible grid and the physics matrix, profile edits rebuild the fixed collider, and falling bodies make the contact result visible.

Initializing Preparing renderer

Preparing the sampled terrain, heightfield body, and dynamic test bodies...

physics
-
samples
-
bodies
-
terrain
-
profile
-
height
-
selected
-
fps
-
Heightfield controlsbody 1

Select a body to inspect its shared terrain height and physics lifecycle.

Heightfield contractofficial API boundary
generateHeight(...)sample one terrain function
BufferGeometry.positionwrite visible row-major grid
physics.addHeightfield(...)register fixed collider
Float32Array[column * n + row]write Rapier column-major matrix
physics.addMesh(...)register falling bodies
physics.removeMesh(...)remove dynamic body
world.removeRigidBody(...)replace terrain body
new RapierHelper(world)inspect collider topology

The visible grid indexes samples as row then column. Rapier's 3D heightfield expects the same samples as a column-major matrix, so the lab writes both views from one function and makes profile rebuilds replace the fixed body.

Selected bodyactive
shape-
position-
terrain height-
lifecycle-

Rapier is loading. The fixed heightfield and dynamic body map become available after WASM initialization.

Based on the official Rapier terrain example, RapierPhysics docs, and heightfield collider API. The CPU fallback approximates terrain contact and does not claim full heightfield parity.

THREE.JS FOUNDATIONS LAB