@wheen/terrain
v0.1.3
Published
wheen chunked heightfield terrain — height cache, stamps, ChunkManager + Rapier physics LOD for R3F
Maintainers
Readme
@wheen/terrain
Chunked heightfield terrain for wheen — one stamp store, one height cache, one focus authority.
Install (workspace)
"@wheen/terrain": "*"API
Core — @wheen/terrain
| Export | Role |
|--------|------|
| TERRAIN | world law (segments visual, physicsSegments Rapier LOD) |
| sampleHeight(x,z) | deterministic height (fbm + bay pad + stamps) |
| getChunkHeights / clearHeightCache | shared Float32 cache |
| buildChunk / buildChunkGeometry / buildChunkPhysics | mesh + Rapier arrays |
| upsertFlattenStamp / flattenStampFromBox3 | pads under placed props |
| layoutIsland / applyIslandLayout / RESERVED_LOTS | lot grammar: catalog pads + +Z door ribbon. Not a cube city |
| setTerrainFocus / getTerrainFocus | spatial hash focus (mutate from useFrame only) |
React — @wheen/terrain/react
| Export | Role |
|--------|------|
| ChunkManager | streams visual chunks; queue ≤buildsPerFrame; dispose on unload |
| TerrainPhysics | Rapier heightfields at physicsSegments; stable keys; stamp-local remount |
Law
- Never put continuous player XZ in React state —
setTerrainFocusonly. - Mesh and physics must share
sampleHeight/ cache (no ghost floors). - App code must not fork this package under
app/src/lib/terrain.
Drive vs make
- Make:
ChunkManager follow="camera"→ writes focus from camera. - Drive: vehicle
useFrame→setTerrainFocus(currPos);ChunkManager follow="focus";<TerrainPhysics />.
