Prompt specification
Build or customize the Three.js 3D scene "Footbridge crossing an alpine tributary" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Footbridge crossing an alpine tributary
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/footbridge-crossing-an-alpine-tributary-x3098
Scene Description Prompt:
Create a stylized cutaway of a New Zealand alpine footbridge spanning a rocky tributary beside a mountain path. Three.js from cdnjs, standalone HTML.
Working Three.js Starter (footbridge-crossing-an-alpine-tributary-x3098):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Kea Crossing — New Zealand Alpine Footbridge</title>
<style>
:root {
--ink: #183238;
--paper: #f4f0df;
--accent: #d85d3f;
--line: rgba(24, 50, 56, 0.25);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 40%, rgba(255, 255, 255, 0.72), transparent 42%),
linear-gradient(180deg, #b9d6dc 0%, #dbe6df 64%, #bfc4ae 100%);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
}
.interface {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 10;
}
.masthead {
position: absolute;
top: 30px;
left: 34px;
max-width: 430px;
text-shadow: 0 1px 16px rgba(255, 255, 255, 0.45);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 8px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.21em;
text-transform: uppercase;
}
.flag {
width: 27px;
height: 14px;
position: relative;
border: 1px solid rgba(24, 50, 56, 0.28);
background:
linear-gradient(90deg, #17324a 0 42%, transparent 42%),
linear-gradient(0deg, transparent 57%, #d74a38 57% 71%, transparent 71%);
}
.flag::after {
content: "";
position: absolute;
width: 5px;
height: 5px;
border: 2px solid #d74a38;
left: 9px;
top: 2.5px;
border-radius: 50%;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(42px, 6vw, 78px);
font-weight: 500;
line-height: 0.92;
letter-spacing: -0.055em;
}
.subtitle {
max-width: 350px;
margin: 14px 0 0;
font-size: 12px;
line-height: 1.55;
font-weight: 600;
letter-spacing: 0.025em;
}
.coordinates {
position: absolute;
top: 34px;
left: 50%;
transform: translateX(-50%);
padding: 8px 13px;
border: 1px solid rgba(24, 50, 56, 0.25);
border-radius: 999px;
background: rgba(244, 240, 223, 0.62);
backdrop-filter: blur(10px);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
white-space: nowrap;
}
.controls {
position: absolute;
top: 28px;
right: 30px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
border: 1px solid rgba(24, 50, 56, 0.25);
border-radius: 999px;
padding: 10px 14px;
color: var(--ink);
background: rgba(244, 240, 223, 0.78);
backdrop-filter: blur(10px);
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
cursor: pointer;
transition: transform 160ms ease, background 160ms ease;
}
button:hover {
transform: translateY(-2px);
background: rgba(255, 252, 240, 0.96);
}
button[aria-pressed="true"] {
color: var(--paper);
background: var(--ink);
}
.legend {
position: absolute;
left: 32px;
bottom: 30px;
width: 248px;
padding: 18px 19px;
border: 1px solid rgba(24, 50, 56, 0.22);
border-radius: 4px;
background: rgba(244, 240, 223, 0.76);
backdrop-filter: blur(12px);
box-shadow: 0 14px 50px rgba(44, 57, 48, 0.08);
}
.legend-title {
margin-bottom: 13px;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 12px 1fr;
gap: 10px;
align-items: center;
margin-top: 9px;
font-size: 10px;
font-weight: 650;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 50%;
box-shadow: inset 0 0 0 1px rgba(24, 50, 56, 0.12);
}
.swatch.rock { background: #8b765b; }
.swatch.moss { background: #78805d; }
.swatch.water { background: #76aeb2; }
.swatch.timber { background: #805438; }
.hint {
position: absolute;
right: 32px;
bottom: 31px;
padding: 10px 13px;
border: 1px solid rgba(24, 50, 56, 0.18);
border-radius: 999px;
background: rgba(244, 240, 223, 0.62);
backdrop-filter: blur(10px);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.hint span {
color: var(--accent);
margin-right: 6px;
}
#leaders {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 8;
}
.leader {
stroke: rgba(24, 50, 56, 0.56);
stroke-width: 1;
stroke-dasharray: 3 4;
}
.callout {
position: fixed;
z-index: 12;
display: flex;
align-items: center;
gap: 8px;
padding: 7px 10px;
border: 1px solid rgba(24, 50, 56, 0.24);
border-radius: 3px;
background: rgba(246, 242, 226, 0.88);
backdrop-filter: blur(8px);
box-shadow: 0 7px 25px rgba(25, 43, 42, 0.08);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
transition: opacity 160ms ease;
}
.callout::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--accent);
}
.callout.hidden,
.leader.hidden {
opacity: 0;
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #dbe6df;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 450ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
.masthead {
top: 20px;
left: 20px;
}
h1 {
font-size: 43px;
}
.subtitle {
max-width: 260px;
font-size: 10px;
}
.coordinates,
.legend {
display: none;
}
.controls {
top: 20px;
right: 16px;
flex-direction: column;
}
button {
padding: 9px 11px;
font-size: 8px;
}
.hint {
right: 14px;
bottom: 14px;
font-size: 8px;
}
.callout {
font-size: 7px;
padding: 5px 7px;
}
}
</style>
</head>
<body>
<div id="loading">Surveying the alpine crossing…</div>
<svg id="leaders" aria-hidden="true"></svg>
<div class="interface">
<header class="masthead">
<div class="eyebrow">
<span class="flag" aria-hidden="true"></span>
Alpine infrastructure / Field note 07
</div>
<h1>Kea<br />Crossing</h1>
<p class="subtitle">
A stylized cutaway of an alpine suspension footbridge above a braided
schist tributary, Aotearoa New Zealand.
</p>
</header>
<div class="coordinates">South Island · 46° S · Alpine trail</div>
<div class="controls">
<button id="resetView" type="button" aria-label="Reset camera view">Reset view</button>
<button id="toggleLabels" type="button" aria-pressed="true">Labels on</button>
</div>
<section class="legend" aria-label="Scene legend">
<div class="legend-title">Material key</div>
<div class="legend-row"><i class="swatch rock"></i> Weathered schist</div>
<div class="legend-row"><i class="swatch moss"></i> Alpine tussock</div>
<div class="legend-row"><i class="swatch water"></i> Glacial tributary</div>
<div class="legend-row"><i class="swatch timber"></i> Silver beech / timber</div>
</section>
<div class="hint"><span>↔</span> Drag to orbit · scroll to zoom</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Utilities
// ------------------------------------------------------------
const TAU = Math.PI * 2;
const WORLD_W = 14;
const WORLD_D = 12;
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
function smoothstep(edge0, edge1, value) {
const t = clamp((value - edge0) / (edge1 - edge0), 0, 1);
return t * t * (3 - 2 * t);
}
function seededRandom(seed) {
return function () {
seed |= 0;
seed = (seed + 0x6D2B79F5) | 0;
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = seededRandom(481516);
function riverCenter(z) {
return 0.43 * Math.sin(z * 0.48) + 0.1 * Math.sin(z * 1.1 + 0.4);
}
function terrainHeight(x, z) {
const distance = Math.abs(x - riverCenter(z));
const channel = 1 - smoothstep(0.85, 1.9, distance);
const texture =
Math.sin(x * 1.72 + z * 0.54) * 0.055 +
Math.sin(z * 2.13 - x * 0.47) * 0.045;
const outerRise = 0.28 * smoothstep(2.4, 6.7, Math.abs(x));
const backRise = 0.24 * smoothstep(2.5, 6.0, -z);
return (
0.26 -
channel * 3.05 +
texture * (1 - channel * 0.75) +
outerRise +
backRise
);
}
function addShadowedMesh(parent, geometry, material, position) {
const mesh = new THREE.Mesh(geometry, material);
if (position) mesh.position.copy(position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function beamBetween(a, b, radius, material, parent, radialSegments = 6) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments,
1
);
const mesh = addShadowedMesh(parent, geometry, material);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
// ------------------------------------------------------------
// Renderer, camera and lighting
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xc4d9d9, 20, 47);
const camera = new THREE.PerspectiveCamera(
36,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional cutaway of a New Zealand alpine footbridge"
);
renderer.domElement.tabIndex = 0;
document.body.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xe6f5f3, 0x66523e, 2.2);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d3, 3.4);
sun.position.set(-8, 14, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8bc4d0, 1.1);
fill.position.set(10, 5, -9);
scene.add(fill);
const world = new THREE.Group();
scene.add(world);
// ------------------------------------------------------------
// Terrain surface
// ------------------------------------------------------------
function createTerrain() {
const nx = 108;
const nz = 90;
const positions = [];
const colors = [];
const indices = [];
const mossDark = new THREE.Color(0x5f6d50);
const mossLight = new THREE.Color(0x8a8e61);
const earth = new THREE.Color(0x9a8060);
const rock = new THREE.Color(0x73756e);
const color = new THREE.Color();
for (let iz = 0; iz <= nz; iz++) {
const z = -WORLD_D / 2 + (iz / nz) * WORLD_D;
for (let ix = 0; ix <= nx; ix++) {
const x = -WORLD_W / 2 + (ix / nx) * WORLD_W;
const y = terrainHeight(x, z);
positions.push(x, y, z);
const distance = Math.abs(x - riverCenter(z));
const variation =
0.5 +
0.25 * Math.sin(x * 1.38 + z * 0.71) +
0.25 * Math.sin(z * 1.74 - x * 0.32);
if (distance < 1.35) {
color.copy(rock).lerp(earth, variation * 0.38);
} else {
color.copy(mossDark).lerp(mossLight, variation);
color.lerp(earth, smoothstep(4.6, 6.8, Math.abs(x)) * 0.26);
}
colors.push(color.r, color.g, color.b);
}
}
for (let iz = 0; iz < nz; iz++) {
for (let ix = 0; ix < nx; ix++) {
const a = iz * (nx + 1) + ix;
const b = a + 1;
const c = a + nx + 1;
const d = c + 1;
indices.push(a, c, b, b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.96,
metalness: 0
});
const terrain = new THREE.Mesh(geometry, material);
terrain.receiveShadow = true;
world.add(terrain);
}
createTerrain();
// ------------------------------------------------------------
// Exposed cutaway walls and geological strata
// ------------------------------------------------------------
function pushQuad(positionArray, colorArray, a, b, c, d, color) {
positionArray.push(...a, ...b, ...c, ...a, ...c, ...d);
for (let i = 0; i < 6; i++) {
colorArray.push(color.r, color.g, color.b);
}
}
function createCutaway() {
const positions = [];
const colors = [];
const faceColor = new THREE.Color();
const bedrock = new THREE.Color(0x655244);
const middle = new THREE.Color(0x9b704e);
const upper = new THREE.Color(0x79664d);
const sideRock = new THREE.Color(0x80694f);
const steps = 150;
const z = WORLD_D / 2 + 0.018;
for (let i = 0; i < steps; i++) {
const x0 = -WORLD_W / 2 + (i / steps) * WORLD_W;
const x1 = -WORLD_W / 2 + ((i + 1) / steps) * WORLD_W;
const h0 = terrainHeight(x0, WORLD_D / 2);
const h1 = terrainHeight(x1, WORLD_D / 2);
// Deepest bedrock remains beneath the incised stream.
pushQuad(
positions,
colors,
[x0, -4.6, z],
[x1, -4.6, z],
[x1, -3.12, z],
[x0, -3.12, z],
bedrock
);
if (h0 > -3.12 || h1 > -3.12) {
const top0 = Math.min(h0, -1.5);
const top1 = Math.min(h1, -1.5);
pushQuad(
positions,
colors,
[x0, -3.12, z],
[x1, -3.12, z],
[x1, top1, z],
[x0, top0, z],
middle
);
}
if (h0 > -1.5 || h1 > -1.5) {
pushQuad(
positions,
colors,
[x0, -1.5, z],
[x1, -1.5, z],
[x1, h1, z],
[x0, h0, z],
upper
);
}
}
// Right and left boundary walls.
for (const side of [-1, 1]) {
const x = side * (WORLD_W / 2 + 0.018);
const segments = 90;
for (let i = 0; i < segments; i++) {
const z0 = -WORLD_D / 2 + (i / segments) * WORLD_D;
const z1 = -WORLD_D / 2 + ((i + 1) / segments) * WORLD_D;
const h0 = terrainHeight(x, z0);
const h1 = terrainHeight(x, z1);
faceColor.copy(sideRock).offsetHSL(0, 0, Math.sin(i * 0.7) * 0.035);
pushQuad(
positions,
colors,
[x, -4.6, z0],
[x, -4.6, z1],
[x, h1, z1],
[x, h0, z0],
faceColor
);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
const wall = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 1,
side: THREE.DoubleSide
})
);
wall.receiveShadow = true;
world.add(wall);
const plinth = addShadowedMesh(
world,
new THREE.BoxGeometry(WORLD_W + 0.35, 0.42, WORLD_D + 0.35),
new THREE.MeshStandardMaterial({
color: 0x3e3b35,
roughness: 0.92
}),
new THREE.Vector3(0, -4.81, 0)
);
plinth.castShadow = false;
}
createCutaway();
// ------------------------------------------------------------
// Alpine paths
// ------------------------------------------------------------
function createPathRibbon(curve, width, colorValue) {
const segments = 100;
const positions = [];
const uvs = [];
const indices = [];
const points = curve.getPoints(segments);
for (let i = 0; i <= segments; i++) {
const t = i / segments;
const point = points[i];
const tangent = curve.getTangent(t);
const perpendicular = new THREE.Vector3(-tangent.z, 0, tangent.x).normalize();
const left = point.clone().addScaledVector(perpendicular, width / 2);
const right = point.clone().addScaledVector(perpendicular, -width / 2);
left.y = terrainHeight(left.x, left.z) + 0.045;
right.y = terrainHeight(right.x, right.z) + 0.045;
positions.push(left.x, left.y, left.z);
positions.push(right.x, right.y, right.z);
uvs.push(0, t, 1, t);
if (i < segments) {
const a = i * 2;
indices.push(a, a + 2, a + 1, a + 1, a + 2, a + 3);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
geometry.setIndex(indices);
geometry.computeVertexNormals();
const path = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
color: colorValue,
roughness: 1,
side: THREE.DoubleSide
})
);
path.receiveShadow = true;
world.add(path);
return points;
}
const westPathCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-4.8, 0, -5.5),
new THREE.Vector3(-3.5, 0, -4.1),
new THREE.Vector3(-3.25, 0, -2.9),
new THREE.Vector3(-4.25, 0, -1.45),
new THREE.Vector3(-3.55, 0, 0)
]);
const eastPathCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(3.5, 0, 0.1),
new THREE.Vector3(4.35, 0, 1.35),
new THREE.Vector3(3.8, 0, 2.75),
new THREE.Vector3(4.8, 0, 4.4),
new THREE.Vector3(4.25, 0, 5.65)
]);
createPathRibbon(westPathCurve, 0.86, 0xb39a73);
createPathRibbon(eastPathCurve, 0.78, 0xaa8f68);
// ------------------------------------------------------------
// Glacial stream
// ------------------------------------------------------------
function createWater() {
const segments = 130;
const positions = [];
const uvs = [];
const indices = [];
for (let i = 0; i <= segments; i++) {
const z = -WORLD_D / 2 + (i / segments) * WORLD_D;
const center = riverCenter(z);
const width = 0.94 + Math.sin(z * 1.3) * 0.07;
positions.push(center - width, -2.55, z);
positions.push(center + width, -2.55, z);
uvs.push(0, i / segments, 1, i / segments);
if (i < segments) {
const a = i * 2;
indices.push(a, a + 2, a + 1, a + 1, a + 2, a + 3);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
geometry.setIndex(indices);
geometry.computeVertexNormals();
const water = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
color: 0x74b1b6,
emissive: 0x173e43,
emissiveIntensity: 0.18,
roughness: 0.24,
metalness: 0.05,
transparent: true,
opacity: 0.88,
side: THREE.DoubleSide
})
);
water.receiveShadow = true;
world.add(water);
// Thin pale current traces in the braided channel.
const currentMaterial = new THREE.MeshBasicMaterial({
color: 0xdceeed,
transparent: true,
opacity: 0.58
});
for (let i = 0; i < 15; i++) {
const z = -5.5 + i * 0.75;
const center = riverCenter(z);
const points = [];
for (let j = 0; j < 12; j++) {
const t = j / 11;
const zz = z - 0.34 + t * 0.68;
const xx = riverCenter(zz) + Math.sin(t * Math.PI * 2 + i) * 0.17;
points.push(new THREE.Vector3(xx, -2.525, zz));
}
const curve = new THREE.CatmullRomCurve3(points);
const current = new THREE.Mesh(
new THREE.TubeGeometry(curve, 18, 0.012, 4, false),
currentMaterial
);
world.add(current);
}
}
createWater();
// ------------------------------------------------------------
// Rocks and whitewater
// ------------------------------------------------------------
const rockGeometry = new THREE.DodecahedronGeometry(1, 0);
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.97,
flatShading: true
});
const rockCount = 118;
const rocks = new THREE.InstancedMesh(
rockGeometry,
rockMaterial,
rockCount
);
rocks.castShadow = true;
rocks.receiveShadow = true;
const dummy = new THREE.Object3D();
const rockColors = [
new THREE.Color(0x686c67),
new THREE.Color(0x77766d),
new THREE.Color(0x555e5b),
new THREE.Color(0x8b8878),
new THREE.Color(0xa18c6f)
];
for (let i = 0; i < rockCount; i++) {
const z = -5.7 + random() * 11.4;
const side = random() < 0.5 ? -1 : 1;
const distance = 0.08 + random() * 1.18;
const x = riverCenter(z) + side * distance;
const scale = 0.18 + Math.pow(random(), 1.7) * 0.72;
const y = terrainHeight(x, z) + scale * 0.24;
dummy.position.set(x, y, z);
dummy.rotation.set(random() * 1.2, random() * TAU, random() * 0.8);
dummy.scale.set(
scale * (0.8 + random() * 0.65),
scale * (0.48 + random() * 0.42),
scale * (0.8 + random() * 0.65)
);
dummy.updateMatrix();
rocks.setMatrixAt(i, dummy.matrix);
rocks.setColorAt(
i,
rockColors[Math.floor(random() * rockColors.length)]
);
}
rocks.instanceMatrix.needsUpdate = true;
rocks.instanceColor.needsUpdate = true;
world.add(rocks);
// Pale foam arcs around selected channel rocks.
const foamGeometry = new THREE.TorusGeometry(0.3, 0.017, 4, 22, Math.PI * 1.4);
const foamMaterial = new THREE.MeshBasicMaterial({
color: 0xf1f5ed,
transparent: true,
opacity: 0.8
});
for (let i = 0; i < 20; i++) {
const z = -5.3 + random() * 10.6;
const x = riverCenter(z) + (random() - 0.5) * 0.9;
const foam = new THREE.Mesh(foamGeometry, foamMaterial);
foam.rotation.set(Math.PI / 2, 0, random() * TAU);
foam.position.set(x, -2.515, z);
foam.scale.setScalar(0.55 + random() * 1.1);
world.add(foam);
}
// ------------------------------------------------------------
// Tussock grass
// ------------------------------------------------------------
const bladeGeometry = new THREE.BufferGeometry();
bladeGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[-0.024, 0, 0, 0.024, 0, 0, 0.008, 0.42, 0],
3
)
);
bladeGeometry.computeVertexNormals();
const bladeMaterial = new THREE.MeshStandardMaterial({
color: 0x8f8b53,
roughness: 1,
side: THREE.DoubleSide
});
const bladesPerTuft = 5;
const tuftCount = 74;
const tussock = new THREE.InstancedMesh(
bladeGeometry,
bladeMaterial,
tuftCount * bladesPerTuft
);
tussock.castShadow = true;
let bladeIndex = 0;
for (let i = 0; i < tuftCount; i++) {
const z = -5.6 + random() * 11.2;
const side = random() < 0.5 ? -1 : 1;
const x = riverCenter(z) + side * (1.7 + random() * 4.6);
if (Math.abs(z) < 0.72 && Math.abs(x) < 3.8) continue;
const y = terrainHeight(x, z) + 0.01;
const size = 0.72 + random() * 0.75;
for (let j = 0; j < bladesPerTuft; j++) {
dummy.position.set(x, y, z);
dummy.rotation.set(
(random() - 0.5) * 0.22,
random() * TAU,
(random() - 0.5) * 0.24
);
dummy.scale.set(size, size, size);
dummy.updateMatrix();
tussock.setMatrixAt(bladeIndex++, dummy.matrix);
}
}
tussock.count = bladeIndex;
tussock.instanceMatrix.needsUpdate = true;
world.add(tussock);
// ------------------------------------------------------------
// Stylized silver beech trees
// ------------------------------------------------------------
const barkMaterial = new THREE.MeshStandardMaterial({
color: 0x655044,
roughness: 1,
flatShading: true
});
const foliageMaterials = [
new THREE.MeshStandardMaterial({
color: 0x738575,
roughness: 0.92,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x899687,
roughness: 0.92,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x5e7569,
roughness: 0.92,
flatShading: true
})
];
function createTree(x, z, size) {
const tree = new THREE.Group();
tree.position.set(x, terrainHeight(x, z), z);
tree.rotation.y = random() * TAU;
const trunkHeight = size * 1.45;
const trunk = addShadowedMesh(
tree,
new THREE.CylinderGeometry(
size * 0.045,
size * 0.085,
trunkHeight,
7
),
barkMaterial,
new THREE.Vector3(0, trunkHeight / 2, 0)
);
trunk.rotation.z = (random() - 0.5) * 0.1;
for (let branch = 0; branch < 4; branch++) {
const angle = (branch / 4) * TAU + random() * 0.5;
const start = new THREE.Vector3(
0,
trunkHeight * (0.5 + branch * 0.08),
0
);
const end = new THREE.Vector3(
Math.cos(angle) * size * 0.48,
trunkHeight * (0.76 + random() * 0.16),
Math.sin(angle) * size * 0.48
);
beamBetween(start, end, size * 0.027, barkMaterial, tree, 5);
}
const clusterCount = 5;
for (let i = 0; i < clusterCount; i++) {
const angle = (i / clusterCount) * TAU + random() * 0.4;
const foliage = addShadowedMesh(
tree,
new THREE.IcosahedronGeometry(size * (0.34 + random() * 0.11), 1),
foliageMaterials[i % foliageMaterials.length],
new THREE.Vector3(
Math.cos(angle) * size * 0.33,
trunkHeight * (0.8 + random() * 0.19),
Math.sin(angle) * size * 0.33
)
);
foliage.scale.set(1.15, 0.66, 1);
}
world.add(tree);
}
createTree(-5.3, -3.55, 1.65);
createTree(-4.8, -1.95, 1.35);
createTree(-5.55, 2.75, 1.75);
createTree(5.15, -3.55, 1.6);
createTree(5.5, 0.45, 1.4);
createTree(5.2, 3.45, 1.72);
// ------------------------------------------------------------
// Suspension footbridge
// ------------------------------------------------------------
function createBridge() {
const bridge = new THREE.Group();
world.add(bridge);
const timber = new THREE.MeshStandardMaterial({
color: 0x805438,
roughness: 0.88
});
const darkTimber = new THREE.MeshStandardMaterial({
color: 0x553d31,
roughness: 0.92
});
const cableMaterial = new THREE.MeshStandardMaterial({
color: 0x354347,
roughness: 0.46,
metalness: 0.58
});
// Deck planks.
const plankCount = 25;
for (let i = 0; i < plankCount; i++) {
const x = -3.36 + i * 0.28;
const plank = addShadowedMesh(
bridge,
new THREE.BoxGeometry(0.245, 0.115, 1.3),
i % 4 === 0 ? darkTimber : timber,
new THREE.Vector3(x, 1.0 + Math.sin(i * 1.9) * 0.008, 0)
);
plank.rotation.y = (random() - 0.5) * 0.015;
}
// Longitudinal bearers.
for (const z of [-0.46, 0.46]) {
addShadowedMesh(
bridge,
new THREE.BoxGeometry(7.05, 0.17, 0.15),
darkTimber,
new THREE.Vector3(0, 0.84, z)
);
}
// Tower frames at each abutment.
for (const x of [-3.2, 3.2]) {
for (const z of [-0.69, 0.69]) {
addShadowedMesh(
bridge,
new THREE.BoxGeometry(0.17, 2.2, 0.17),
darkTimber,
new THREE.Vector3(x, 2.13, z)
);
}
addShadowedMesh(
bridge,
new THREE.BoxGeometry(0.19, 0.18, 1.58),
darkTimber,
new THREE.Vector3(x, 3.17, 0)
);
const braceA = new THREE.Vector3(x - 0.4, 2.0, -0.69);
const braceB = new THREE.Vector3(x + 0.4, 2.95, -0.69);
beamBetween(braceA, braceB, 0.036, cableMaterial, bridge);
}
// Main suspension cables.
for (const z of [-0.69, 0.69]) {
const points = [
new THREE.Vector3(-3.2, 3.2, z),
new THREE.Vector3(-2.45, 2.78, z),
new THREE.Vector3(-1.25, 2.12, z),
new THREE.Vector3(0, 1.76, z),
new THREE.Vector3(1.25, 2.12, z),
new THREE.Vector3(2.45, 2.78, z),
new THREE.Vector3(3.2, 3.2, z)
];
const curve = new THREE.CatmullRomCurve3(points);
const cable = new THREE.Mesh(
new THREE.TubeGeometry(curve, 72, 0.044, 7, false),
cableMaterial
);
cable.castShadow = true;
bridge.add(cable);
// Vertical hangers.
for (let i = -6; i <= 6; i++) {
if (i === 0) continue;
const x = i * 0.5;
const cableY = 1.76 + 1.44 * Math.pow(x / 3.2, 2);
beamBetween(
new THREE.Vector3(x, 1.07, z),
new THREE.Vector3(x, cableY, z),
0.015,
cableMaterial,
bridge,
5
);
}
}
// Handrails and uprights.
for (const z of [-0.64, 0.64]) {
const railCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-3.2, 1.62, z),
new THREE.Vector3(-1.6, 1.55, z),
new THREE.Vector3(0, 1.52, z),
new THREE.Vector3(1.6, 1.55, z),
new THREE.Vector3(3.2, 1.62, z)
]);
const rail = new THREE.Mesh(
new THREE.TubeGeometry(railCurve, 45, 0.023, 6, false),
cableMaterial
);
rail.castShadow = true;
bridge.add(rail);
for (let x = -3.2; x <= 3.21; x += 0.8) {
addShadowedMesh(
bridge,
new THREE.BoxGeometry(0.075, 0.62, 0.075),
darkTimber,
new THREE.Vector3(x, 1.34, z)
);
}
}
// Stone approach steps, supported down to the terrain.
const stepHeights = [0.78, 0.59, 0.41, 0.29];
for (const side of [-1, 1]) {
for (let i = 0; i < stepHeights.length; i++) {
const x = side * (3.66 + i * 0.34);
const ground = terrainHeight(x, 0);
const top = stepHeights[i];
const height = Math.max(0.1, top - ground);
addShadowedMesh(
bridge,
new THREE.BoxGeometry(0.43, height, 1.38),
new THREE.MeshStandardMaterial({
color: i % 2 ? 0x8e8068 : 0x9a8b70,
roughness: 1
}),
new THREE.Vector3(x, top - height / 2, 0)
);
}
}
}
createBridge();
// ------------------------------------------------------------
// Trail sign and a small kea
// ------------------------------------------------------------
function createSign() {
const signCanvas = document.createElement("canvas");
signCanvas.width = 512;
signCanvas.height = 220;
const context = signCanvas.getContext("2d");
context.fillStyle = "#e9dfc2";
context.fillRect(0, 0, 512, 220);
context.strokeStyle = "#273c3b";
context.lineWidth = 12;
context.strokeRect(10, 10, 492, 200);
context.fillStyle = "#273c3b";
context.textAlign = "center";
context.font = "bold 52px Georgia";
context.fillText("KEA CROSSING", 256, 92);
context.font = "bold 25px sans-serif";
context.fillText("TRACK • 3.2 KM", 256, 147);
const texture = new THREE.CanvasTexture(signCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const post = addShadowedMesh(
world,
new THREE.BoxGeometry(0.09, 1.2, 0.09),
barkMaterial,
new THREE.Vector3(-4.25, 0.72, -1.28)
);
const board = addShadowedMesh(
world,
new THREE.BoxGeometry(1.16, 0.5, 0.07),
[
barkMaterial,
barkMaterial,
barkMaterial,
barkMaterial,
new THREE.MeshStandardMaterial({ map: texture, roughness: 0.88 }),
barkMaterial
],
new THREE.Vector3(-4.25, 1.28, -1.24)
);
// A stylized kea perched above the sign.
const kea = new THREE.Group();
kea.position.set(-4.27, 1.62, -1.1);
const keaMaterial = new THREE.MeshStandardMaterial({
color: 0x626a45,
roughness: 0.94,
flatShading: true
});
const body = addShadowedMesh(
kea,
new THREE.IcosahedronGeometry(0.19, 1),
keaMaterial,
new THREE.Vector3(0, 0, 0)
);
body.scale.set(0.8, 0.95, 1.22);
addShadowedMesh(
kea,
new THREE.IcosahedronGeometry(0.13, 1),
keaMaterial,
new THREE.Vector3(0.16, 0.12, 0)
);
const beak = addShadowedMesh(
kea,
new THREE.ConeGeometry(0.055, 0.19, 6),
new THREE.MeshStandardMaterial({ color: 0xb75e3e, roughness: 0.7 }),
new THREE.Vector3(0.31, 0.11, 0)
);
beak.rotation.z = -Math.PI / 2;
const tail = addShadowedMesh(
kea,
new THREE.BoxGeometry(0.33, 0.055, 0.11),
keaMaterial,
new THREE.Vector3(-0.23, -0.02, 0)
);
tail.rotation.y = 0.22;
world.add(kea);
}
createSign();
// ------------------------------------------------------------
// Distant South Island alpine peaks
// ------------------------------------------------------------
function createMountain(x, z, radius, height, colorValue, snowValue) {
const mountainGeometry = new THREE.ConeGeometry(radius, height, 7, 2);
const position = mountainGeometry.attributes.position;
for (let i = 0; i < position.count; i++) {
const px = position.getX(i);
const pz = position.getZ(i);
const variation = 1 + Math.sin(i * 2.37) * 0.09;
position.setX(i, px * variation);
position.setZ(i, pz * (2 - variation));
}
mountainGeometry.computeVertexNormals();
const baseY = -4.3;
const mountain = new THREE.Mesh(
mountainGeometry,
new THREE.MeshStandardMaterial({
color: colorValue,
roughness: 1,
flatShading: true
})
);
mountain.position.set(x, baseY + height / 2, z);
mountain.rotation.y = random() * TAU;
world.add(mountain);
const capHeight = height * 0.27;
const cap = new THREE.Mesh(
new THREE.ConeGeometry(radius * 0.27, capHeight, 7),
new THREE.MeshStandardMaterial({
color: snowValue,
roughness: 1,
flatShading: true
})
);
cap.position.set(
x,
baseY + height - capHeight / 2,
z
);
cap.rotation.y = mountain.rotation.y;
world.add(cap);
}
createMountain(-8.5, -16, 5.3, 11.5, 0x68787b, 0xe8eeea);
createMountain(-0.5, -19, 6.6, 13.5, 0x778588, 0xf2f2e9);
createMountain(7.8, -16.5, 5.0, 10.2, 0x647477, 0xe3ebe7);
createMountain(12.5, -23, 7.4, 15.5, 0x849193, 0xf2f2e8);
// Wispy distant cloud forms.
const cloudMaterial = new THREE.MeshStandardMaterial({
color: 0xf3f4ed,
roughness: 1,
transparent: true,
opacity: 0.65,
flatShading: true
});
for (const cloud of [
[-9, 8, -23, 1.4],
[3, 9.2, -26, 1.7],
[10, 7.5, -24, 1.2]
]) {
const group = new THREE.Group();
group.position.set(cloud[0], cloud[1], cloud[2]);
for (let i = 0; i < 4; i++) {
const puff = new THREE.Mesh(
new THREE.IcosahedronGeometry(cloud[3] * (0.65 + random() * 0.4), 1),
cloudMaterial
);
puff.position.set((i - 1.5) * cloud[3], Math.sin(i) * 0.2, random() * 0.6);
puff.scale.set(1.35, 0.55, 0.75);
group.add(puff);
}
world.add(group);
}
// ------------------------------------------------------------
// Projected callouts
// ------------------------------------------------------------
const calloutDefinitions = [
{
label: "01 · Suspension span",
anchor: new THREE.Vector3(0.1, 2.1, 0),
offset: [110, -62]
},
{
label: "02 · Glacial tributary",
anchor: new THREE.Vector3(0.1, -2.35, 3.4),
offset: [115, 18]
},
{
label: "03 · Schist cutaway",
anchor: new THREE.Vector3(4.9, -1.65, 6.02),
offset: [95, 22]
},
{
label: "04 · Silver beech",
anchor: new THREE.Vector3(-5.25, 2.25, -3.4),
offset: [-175, -28]
}
];
const svg = document.getElementById("leaders");
const callouts = calloutDefinitions.map((definition) => {
const element = document.createElement("div");
element.className = "callout";
element.textContent = definition.label;
document.body.appendChild(element);
const line = document.createElementNS(
"http://www.w3.org/2000/svg",
"line"
);
line.setAttribute("class", "leader");
svg.appendChild(line);
return { ...definition, element, line };
});
let labelsVisible = true;
function updateCallouts() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const callout of callouts) {
const projected = callout.anchor.clone().project(camera);
const visible =
labelsVisible &&
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.3 &&
Math.abs(projected.y) < 1.3;
callout.element.classList.toggle("hidden", !visible);
callout.line.classList.toggle("hidden", !visible);
if (!visible) continue;
const px = (projected.x * 0.5 + 0.5) * width;
const py = (-projected.y * 0.5 + 0.5) * height;
const labelX = px + callout.offset[0];
const labelY = py + callout.offset[1];
callout.element.style.left = `${labelX}px`;
callout.element.style.top = `${labelY}px`;
const lineEndX =
callout.offset[0] < 0
? labelX + callout.element.offsetWidth
: labelX;
const lineEndY = labelY + callout.element.offsetHeight / 2;
callout.line.setAttribute("x1", px);
callout.line.setAttribute("y1", py);
callout.line.setAttribute("x2", lineEndX);
callout.line.setAttribute("y2", lineEndY);
}
}
// ------------------------------------------------------------
// Direct camera controls — no external controls module
// ------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, -0.25, 0);
const spherical = new THREE.Spherical(22.5, 1.08, 0.66);
const cameraOffset = new THREE.Vector3();
function updateCamera() {
cameraOffset.setFromSpherical(spherical);
camera.position.copy(cameraTarget).add(cameraOffset);
camera.lookAt(cameraTarget);
}
function resetView() {
cameraTarget.set(0, -0.25, 0);
spherical.set(22.5, 1.08, 0.66);
updateCamera();
}
updateCamera();
let dragging = false;
let pointerId = null;
let lastX = 0;
let lastY = 0;
const activePointers = new Map();
let pinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 1) {
dragging = true;
pointerId = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
} else if (activePointers.size === 2) {
const points = [...activePointers.values()];
pinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!activePointers.has(event.pointerId)) return;
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 2) {
const points = [...activePointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (pinchDistance > 0) {
spherical.radius = clamp(
spherical.radius * (pinchDistance / distance),
12,
32
);
updateCamera();
}
pinchDistance = distance;
return;
}
if (!dragging || event.pointerId !== pointerId) return;
const deltaX = event.clientX - lastX;
const deltaY = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
spherical.theta -= deltaX * 0.006;
spherical.phi = clamp(
spherical.phi + deltaY * 0.005,
0.48,
1.38
);
updateCamera();
});
function releasePointer(event) {
activePointers.delete(event.pointerId);
if (event.pointerId === pointerId) {
dragging = false;
pointerId = null;
}
if (activePointers.size < 2) pinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
spherical.radius = clamp(
spherical.radius * Math.exp(event.deltaY * 0.001),
12,
32
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetView();
if (event.key === "ArrowLeft") {
spherical.theta -= 0.1;
updateCamera();
}
if (event.key === "ArrowRight") {
spherical.theta += 0.1;
updateCamera();
}
if (event.key === "ArrowUp") {
spherical.phi = clamp(spherical.phi - 0.08, 0.48, 1.38);
updateCamera();
}
if (event.key === "ArrowDown") {
spherical.phi = clamp(spherical.phi + 0.08, 0.48, 1.38);
updateCamera();
}
});
document.getElementById("resetView").addEventListener("click", resetView);
const labelButton = document.getElementById("toggleLabels");
labelButton.addEventListener("click", () => {
labelsVisible = !labelsVisible;
labelButton.setAttribute("aria-pressed", String(labelsVisible));
labelButton.textContent = labelsVisible ? "Labels on" : "Labels off";
});
// ------------------------------------------------------------
// Responsive rendering and animation
// ------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
// Barely perceptible current shimmer.
const time = clock.getElapsedTime();
world.children.forEach((child) => {
if (child.material && child.material.emissive) {
if (child.material.color.getHex() === 0x74b1b6) {
child.material.emissiveIntensity = 0.17 + Math.sin(time * 0.7) * 0.025;
}
}
});
renderer.render(scene, camera);
updateCallouts();
}
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```