Prompt specification
Build or customize the Three.js 3D scene "Abandoned railway verge succession" 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: Abandoned railway verge succession
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/abandoned-railway-verge-succession-x0731
Scene Description Prompt:
Advance a stylized abandoned railway verge from grasses through shrubs to seedlings while tracks remain visible. Build standalone HTML with Three.js from cdnjs.
Working Three.js Starter (abandoned-railway-verge-succession-x0731):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>The Quiet Line — Rewilded Railway</title>
<style>
:root {
color-scheme: dark;
--ink: #f1eee3;
--muted: #c2c5b7;
--panel: rgba(29, 35, 29, 0.72);
--line: rgba(235, 237, 216, 0.18);
--accent: #c7d88d;
--warm: #d8b77d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #aeb8aa;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
linear-gradient(180deg, rgba(17, 24, 19, 0.22), transparent 26%),
radial-gradient(circle at 52% 45%, transparent 48%, rgba(20, 25, 20, 0.3) 110%);
z-index: 2;
}
.panel {
position: fixed;
z-index: 5;
border: 1px solid var(--line);
background: var(--panel);
box-shadow: 0 18px 60px rgba(16, 23, 18, 0.18);
backdrop-filter: blur(16px) saturate(115%);
-webkit-backdrop-filter: blur(16px) saturate(115%);
}
#masthead {
top: 24px;
left: 24px;
width: min(380px, calc(100vw - 48px));
padding: 20px 22px 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
color: var(--accent);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.eyebrow::before {
width: 22px;
height: 1px;
content: "";
background: currentColor;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(31px, 4vw, 49px);
font-weight: 400;
line-height: 0.95;
letter-spacing: -0.035em;
}
.masthead p {
max-width: 310px;
margin: 13px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
#survey {
top: 24px;
right: 24px;
width: 230px;
padding: 15px 17px;
}
.survey-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
padding: 8px 0;
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.survey-row:last-child {
border-bottom: 0;
}
.survey-row span {
color: var(--muted);
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.survey-row strong {
font-family: Georgia, "Times New Roman", serif;
font-size: 19px;
font-weight: 400;
}
#story {
left: 24px;
bottom: 24px;
width: min(390px, calc(100vw - 48px));
padding: 19px 22px 20px;
}
#story.pulse {
animation: story-pulse 700ms ease-out;
}
@keyframes story-pulse {
0% {
transform: translateY(7px);
opacity: 0.5;
}
100% {
transform: translateY(0);
opacity: 1;
}
}
#story h2 {
margin: 0 0 8px;
font-family: Georgia, "Times New Roman", serif;
font-size: 28px;
font-weight: 400;
letter-spacing: -0.02em;
}
#story p {
min-height: 54px;
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
#controls {
right: 24px;
bottom: 24px;
width: min(360px, calc(100vw - 48px));
padding: 16px 17px 15px;
}
.button-row {
display: flex;
gap: 8px;
margin-bottom: 13px;
}
button {
min-height: 36px;
border: 1px solid var(--line);
border-radius: 0;
color: var(--ink);
background: rgba(255, 255, 255, 0.045);
font: inherit;
cursor: pointer;
transition: background 160ms ease, border-color 160ms ease;
}
button:hover {
border-color: rgba(235, 237, 216, 0.38);
background: rgba(255, 255, 255, 0.1);
}
button:focus-visible,
input:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 3px;
}
#play {
flex: 1;
color: #20291f;
border-color: var(--accent);
background: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
#reset {
width: 86px;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
input[type="range"] {
width: 100%;
height: 20px;
margin: 0;
appearance: none;
background: transparent;
cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
height: 2px;
background: linear-gradient(
to right,
var(--accent) 0%,
var(--accent) var(--progress, 0%),
rgba(255, 255, 255, 0.19) var(--progress, 0%),
rgba(255, 255, 255, 0.19) 100%
);
}
input[type="range"]::-moz-range-track {
height: 2px;
background: rgba(255, 255, 255, 0.19);
}
input[type="range"]::-moz-range-progress {
height: 2px;
background: var(--accent);
}
input[type="range"]::-webkit-slider-thumb {
width: 13px;
height: 13px;
margin-top: -5.5px;
appearance: none;
border: 2px solid #293126;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 1px var(--accent);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 2px solid #293126;
border-radius: 50%;
background: var(--accent);
}
.timeline-labels {
display: flex;
justify-content: space-between;
margin-top: 7px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.chapters {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
margin-top: 13px;
}
.chapter {
padding: 9px 6px;
color: #9fa596;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.chapter.active {
color: var(--accent);
border-color: rgba(199, 216, 141, 0.52);
background: rgba(199, 216, 141, 0.08);
}
#hint {
position: fixed;
z-index: 4;
right: 50%;
bottom: 27px;
transform: translateX(50%);
color: rgba(241, 238, 227, 0.72);
font-size: 9px;
letter-spacing: 0.14em;
text-transform: uppercase;
pointer-events: none;
text-shadow: 0 1px 8px rgba(0, 0, 0, 0.6);
}
@media (max-width: 850px) {
#masthead {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 17px;
}
#masthead p {
display: none;
}
#survey {
display: none;
}
#story {
left: 12px;
bottom: 188px;
width: calc(100vw - 24px);
padding: 15px 17px;
}
#story p {
min-height: 0;
}
#controls {
right: 12px;
bottom: 12px;
width: calc(100vw - 24px);
}
#hint {
display: none;
}
}
@media (max-height: 650px) {
#story p {
display: none;
}
#story {
bottom: 12px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="vignette"></div>
<header id="masthead" class="panel">
<div class="eyebrow">Railway ecology / field study 04</div>
<h1>The Quiet Line</h1>
<p>
An abandoned railway returns to life. The camera remains low and close
enough to keep the rails and sleepers legible as the verge develops.
</p>
</header>
<aside id="survey" class="panel" aria-label="Current survey">
<div class="survey-row">
<span>Phase</span>
<strong id="phase-value">01</strong>
</div>
<div class="survey-row">
<span>Regrowth</span>
<strong id="progress-value">0%</strong>
</div>
<div class="survey-row">
<span>Rail corridor</span>
<strong>Visible</strong>
</div>
</aside>
<section id="story" class="panel" aria-live="polite">
<div id="story-kicker" class="eyebrow">01 — Grasses</div>
<h2 id="story-title">First green</h2>
<p id="story-text">
Fine grasses root in the cool ballast shoulders, while the rails remain exposed.
</p>
</section>
<section id="controls" class="panel" aria-label="Growth controls">
<div class="button-row">
<button id="play" type="button">Pause growth</button>
<button id="reset" type="button">Reset</button>
</div>
<input
id="timeline"
type="range"
min="0"
max="1000"
value="0"
aria-label="Vegetation growth timeline"
/>
<div class="timeline-labels">
<span>Grasses</span>
<span>Shrubs</span>
<span>Seedlings</span>
</div>
<div class="chapters">
<button class="chapter active" type="button" data-progress="0.04">01 Grasses</button>
<button class="chapter" type="button" data-progress="0.46">02 Shrubs</button>
<button class="chapter" type="button" data-progress="0.86">03 Seedlings</button>
</div>
</section>
<div id="hint">Drag to orbit · Scroll to zoom</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const container = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb5c0b2);
scene.fog = new THREE.Fog(0xb5c0b2, 34, 118);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
180
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 0.95;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
container.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xe4ead9, 0x655d49, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffdfad, 3.25);
sun.position.set(-25, 38, 22);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -43;
sun.shadow.camera.right = 43;
sun.shadow.camera.top = 43;
sun.shadow.camera.bottom = -43;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 115;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbdced2, 0.55);
fill.position.set(20, 12, -30);
scene.add(fill);
// -------------------------------------------------------------------------
// Deterministic helpers
// -------------------------------------------------------------------------
let seed = 71429;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function rand(min, max) {
return min + (max - min) * random();
}
function clamp01(value) {
return THREE.MathUtils.clamp(value, 0, 1);
}
function smoothstep(min, max, value) {
return THREE.MathUtils.smoothstep(value, min, max);
}
function vergeHeight(x, z) {
const outer = smoothstep(4, 22, Math.abs(x));
return (
-0.14 +
outer *
(0.22 * Math.sin(x * 0.23 + z * 0.09) +
0.13 * Math.sin(z * 0.31 - x * 0.15) +
0.1)
);
}
function surfaceHeight(x, z) {
const distance = Math.abs(x);
if (distance < 2.68) return 0.04;
if (distance < 4.0) return 0.035;
return vergeHeight(x, z);
}
// -------------------------------------------------------------------------
// Terrain
// -------------------------------------------------------------------------
const terrainGeometry = new THREE.PlaneGeometry(70, 150, 42, 84);
terrainGeometry.rotateX(-Math.PI / 2);
const terrainPositions = terrainGeometry.attributes.position;
const terrainColors = new Float32Array(terrainPositions.count * 3);
const soilColor = new THREE.Color(0x68684f);
const grassColor = new THREE.Color(0x72785a);
const dryColor = new THREE.Color(0x8d8461);
const tempColor = new THREE.Color();
for (let i = 0; i < terrainPositions.count; i++) {
const x = terrainPositions.getX(i);
const z = terrainPositions.getZ(i);
const y = vergeHeight(x, z);
terrainPositions.setY(i, y);
const variation = 0.5 + 0.5 * Math.sin(x * 0.61 + z * 0.37);
tempColor.copy(soilColor).lerp(grassColor, variation * 0.7);
tempColor.lerp(dryColor, random() * 0.12);
terrainColors[i * 3] = tempColor.r;
terrainColors[i * 3 + 1] = tempColor.g;
terrainColors[i * 3 + 2] = tempColor.b;
}
terrainGeometry.setAttribute(
"color",
new THREE.BufferAttribute(terrainColors, 3)
);
terrainGeometry.computeVertexNormals();
const terrain = new THREE.Mesh(
terrainGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 1,
metalness: 0
})
);
terrain.receiveShadow = true;
scene.add(terrain);
const ballastGeometry = new THREE.PlaneGeometry(5.35, 145);
ballastGeometry.rotateX(-Math.PI / 2);
const ballast = new THREE.Mesh(
ballastGeometry,
new THREE.MeshStandardMaterial({
color: 0x77766e,
roughness: 1
})
);
ballast.position.y = 0.035;
ballast.receiveShadow = true;
scene.add(ballast);
const shoulderMaterial = new THREE.MeshStandardMaterial({
color: 0x77735d,
roughness: 1
});
for (const side of [-1, 1]) {
const shoulder = new THREE.Mesh(
new THREE.BoxGeometry(1.45, 0.12, 145),
shoulderMaterial
);
shoulder.position.set(side * 3.3, -0.025, 0);
shoulder.receiveShadow = true;
scene.add(shoulder);
}
// -------------------------------------------------------------------------
// Track: sleepers, rails, fasteners, and ballast stones
// -------------------------------------------------------------------------
const sleeperCount = 94;
const sleeperSpacing = 1.45;
const sleeperGeometry = new THREE.BoxGeometry(3.25, 0.18, 0.34);
const sleeperMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.94
});
const sleepers = new THREE.InstancedMesh(
sleeperGeometry,
sleeperMaterial,
sleeperCount
);
sleepers.castShadow = true;
sleepers.receiveShadow = true;
const dummy = new THREE.Object3D();
const woodColors = [0x5f4935, 0x6e533a, 0x4e4033, 0x755b40];
for (let i = 0; i < sleeperCount; i++) {
const z = (i - (sleeperCount - 1) / 2) * sleeperSpacing;
dummy.position.set(rand(-0.055, 0.055), 0.125, z);
dummy.rotation.set(rand(-0.025, 0.025), rand(-0.018, 0.018), rand(-0.018, 0.018));
dummy.scale.set(rand(0.96, 1.02), rand(0.92, 1.05), rand(0.94, 1.03));
dummy.updateMatrix();
sleepers.setMatrixAt(i, dummy.matrix);
sleepers.setColorAt(
i,
new THREE.Color(woodColors[Math.floor(random() * woodColors.length)])
);
}
scene.add(sleepers);
const railHeadMaterial = new THREE.MeshStandardMaterial({
color: 0x969a91,
metalness: 0.72,
roughness: 0.36
});
const railRustMaterial = new THREE.MeshStandardMaterial({
color: 0x685548,
metalness: 0.45,
roughness: 0.72
});
for (const side of [-1, 1]) {
const railX = side * 1.22;
const head = new THREE.Mesh(
new THREE.BoxGeometry(0.14, 0.1, 145),
railHeadMaterial
);
head.position.set(railX, 0.355, 0);
head.castShadow = true;
head.receiveShadow = true;
scene.add(head);
const web = new THREE.Mesh(
new THREE.BoxGeometry(0.065, 0.18, 145),
railRustMaterial
);
web.position.set(railX, 0.235, 0);
web.castShadow = true;
scene.add(web);
const foot = new THREE.Mesh(
new THREE.BoxGeometry(0.22, 0.055, 145),
railRustMaterial
);
foot.position.set(railX, 0.12, 0);
foot.castShadow = true;
scene.add(foot);
}
const fastenerCount = sleeperCount * 2;
const fasteners = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.34, 0.035, 0.38),
new THREE.MeshStandardMaterial({
color: 0x51483f,
metalness: 0.52,
roughness: 0.74
}),
fastenerCount
);
let fastenerIndex = 0;
for (let i = 0; i < sleeperCount; i++) {
const z = (i - (sleeperCount - 1) / 2) * sleeperSpacing;
for (const side of [-1, 1]) {
dummy.position.set(side * 1.22, 0.225, z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
fasteners.setMatrixAt(fastenerIndex++, dummy.matrix);
}
}
fasteners.castShadow = true;
scene.add(fasteners);
const stoneCount = 560;
const stones = new THREE.InstancedMesh(
new THREE.DodecahedronGeometry(0.14, 0),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1
}),
stoneCount
);
stones.receiveShadow = true;
const stoneColors = [0x85837a, 0x696a63, 0x989185, 0x77766c, 0xa09683];
for (let i = 0; i < stoneCount; i++) {
const x = rand(-2.62, 2.62);
const z = rand(-71, 71);
const scale = rand(0.48, 1.5);
dummy.position.set(x, rand(0.045, 0.105), z);
dummy.rotation.set(rand(0, Math.PI), rand(0, Math.PI), rand(0, Math.PI));
dummy.scale.set(scale, scale * rand(0.45, 0.8), scale);
dummy.updateMatrix();
stones.setMatrixAt(i, dummy.matrix);
stones.setColorAt(
i,
new THREE.Color(stoneColors[Math.floor(random() * stoneColors.length)])
);
}
scene.add(stones);
// -------------------------------------------------------------------------
// Grasses: low crossed-blade geometry, rendered as instanced meshes
// -------------------------------------------------------------------------
const bladeVertices = [];
for (let i = 0; i < 5; i++) {
const angle = (i / 5) * Math.PI;
const directionX = Math.cos(angle);
const directionZ = Math.sin(angle);
const perpendicularX = -Math.sin(angle) * 0.105;
const perpendicularZ = Math.cos(angle) * 0.105;
bladeVertices.push(
-perpendicularX, 0, -perpendicularZ,
perpendicularX, 0, perpendicularZ,
directionX * 0.055, 1, directionZ * 0.055
);
}
const bladeGeometry = new THREE.BufferGeometry();
bladeGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(bladeVertices, 3)
);
bladeGeometry.computeVertexNormals();
const grassCount = 620;
const grasses = new THREE.InstancedMesh(
bladeGeometry,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
side: THREE.DoubleSide
}),
grassCount
);
grasses.receiveShadow = true;
grasses.castShadow = true;
const grassData = [];
for (let i = 0; i < grassCount; i++) {
const side = random() > 0.5 ? 1 : -1;
const x = side * rand(2.68, 19);
const z = rand(-58, 55);
const width = rand(0.55, 1.18);
const height = rand(0.36, 0.88);
const rotation = rand(0, Math.PI * 2);
const phase = rand(0, Math.PI * 2);
grassData.push({
x,
z,
width,
height,
rotation,
phase
});
const color = new THREE.Color().setHSL(
rand(0.17, 0.24),
rand(0.25, 0.46),
rand(0.39, 0.61)
);
grasses.setColorAt(i, color);
}
scene.add(grasses);
// -------------------------------------------------------------------------
// Shrubs: low-poly clusters outside the track clearance zone
// -------------------------------------------------------------------------
const shrubGeometry = new THREE.IcosahedronGeometry(1, 1);
const shrubMaterials = [
new THREE.MeshStandardMaterial({ color: 0x596a45, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0x6d7c4f, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0x485b3b, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0x7c8455, roughness: 1 })
];
const shrubs = [];
function makeShrub(x, z, size, delay) {
const group = new THREE.Group();
group.position.set(x, surfaceHeight(x, z), z);
group.rotation.y = rand(0, Math.PI * 2);
const clusterCount = 4 + Math.floor(random() * 3);
for (let i = 0; i < clusterCount; i++) {
const leaf = new THREE.Mesh(
shrubGeometry,
shrubMaterials[Math.floor(random() * shrubMaterials.length)]
);
const angle = rand(0, Math.PI * 2);
const radius = rand(0.05, 0.58);
const height = rand(0.45, 1.55);
leaf.position.set(
Math.cos(angle) * radius,
height,
Math.sin(angle) * radius
);
leaf.scale.set(
rand(0.52, 0.93),
rand(0.65, 1.18),
rand(0.52, 0.95)
);
leaf.castShadow = true;
leaf.receiveShadow = true;
group.add(leaf);
}
const twig = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.09, 1.4, 5),
new THREE.MeshStandardMaterial({ color: 0x594738, roughness: 1 })
);
twig.position.y = 0.65;
twig.castShadow = true;
group.add(twig);
scene.add(group);
shrubs.push({
group,
size,
delay,
phase: rand(0, Math.PI * 2)
});
}
for (let i = 0; i < 27; i++) {
const side = random() > 0.5 ? 1 : -1;
const x = side * rand(6.2, 18.5);
const z = rand(-55, 48);
makeShrub(x, z, rand(0.7, 1.24), rand(0, 0.11));
}
// -------------------------------------------------------------------------
// Seedlings: small plants close to the rails, but never over the rail heads
// -------------------------------------------------------------------------
const stemMaterial = new THREE.MeshStandardMaterial({
color: 0x617b43,
roughness: 0.92
});
const leafMaterial = new THREE.MeshStandardMaterial({
color: 0x7f9a52,
roughness: 0.9
});
const youngLeafMaterial = new THREE.MeshStandardMaterial({
color: 0x9caf65,
roughness: 0.88
});
const stemGeometry = new THREE.CylinderGeometry(0.025, 0.045, 0.46, 5);
const seedlingLeafGeometry = new THREE.SphereGeometry(1, 6, 3);
const seedlings = [];
function makeSeedling(x, z, delay) {
const group = new THREE.Group();
group.position.set(x, surfaceHeight(x, z), z);
const stem = new THREE.Mesh(stemGeometry, stemMaterial);
stem.position.y = 0.23;
stem.castShadow = true;
group.add(stem);
for (const side of [-1, 1]) {
const leaf = new THREE.Mesh(
seedlingLeafGeometry,
random() > 0.62 ? youngLeafMaterial : leafMaterial
);
leaf.position.set(side * 0.105, 0.39 + random() * 0.05, 0);
leaf.rotation.z = side * rand(0.45, 0.72);
leaf.rotation.y = rand(-0.3, 0.3);
leaf.scale.set(0.17, 0.038, 0.075);
leaf.castShadow = true;
group.add(leaf);
}
const bud = new THREE.Mesh(
new THREE.SphereGeometry(0.055, 5, 3),
youngLeafMaterial
);
bud.position.y = 0.49;
bud.scale.y = 1.3;
group.add(bud);
scene.add(group);
seedlings.push({
group,
delay,
phase: rand(0, Math.PI * 2)
});
}
for (let i = 0; i < 44; i++) {
const side = random() > 0.5 ? 1 : -1;
// The closest edge is 1.55, outside the 1.29-wide rail heads.
const x = side * rand(1.55, 2.55);
const z = rand(-49, 47);
makeSeedling(x, z, rand(0, 0.12));
}
// -------------------------------------------------------------------------
// Abandoned railway details
// -------------------------------------------------------------------------
const postMaterial = new THREE.MeshStandardMaterial({
color: 0x61503c,
roughness: 0.9,
metalness: 0.08
});
const signPost = new THREE.Mesh(
new THREE.CylinderGeometry(0.075, 0.095, 3.6, 7),
postMaterial
);
signPost.position.set(-4.65, 1.72, -8.5);
signPost.rotation.z = 0.035;
signPost.castShadow = true;
scene.add(signPost);
const signCanvas = document.createElement("canvas");
signCanvas.width = 512;
signCanvas.height = 256;
const signContext = signCanvas.getContext("2d");
signContext.fillStyle = "#c8b993";
signContext.fillRect(0, 0, 512, 256);
signContext.strokeStyle = "#554a38";
signContext.lineWidth = 12;
signContext.strokeRect(14, 14, 484, 228);
signContext.fillStyle = "#554a38";
signContext.textAlign = "center";
signContext.font = "bold 52px Georgia";
signContext.fillText("NO PASSING", 256, 115);
signContext.font = "27px Georgia";
signContext.fillText("BEYOND THIS POINT", 256, 166);
const signTexture = new THREE.CanvasTexture(signCanvas);
signTexture.colorSpace = THREE.SRGBColorSpace;
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(1.9, 0.95),
new THREE.MeshStandardMaterial({
map: signTexture,
roughness: 0.9,
side: THREE.DoubleSide
})
);
sign.position.set(-4.61, 3.0, -8.43);
sign.rotation.z = -0.035;
sign.castShadow = true;
scene.add(sign);
const signalGroup = new THREE.Group();
signalGroup.position.set(4.55, 0, -17.5);
signalGroup.rotation.z = -0.025;
const signalPost = new THREE.Mesh(
new THREE.CylinderGeometry(0.09, 0.13, 3.7, 8),
postMaterial
);
signalPost.position.y = 1.85;
signalPost.castShadow = true;
signalGroup.add(signalPost);
const signalCase = new THREE.Mesh(
new THREE.BoxGeometry(0.62, 1.05, 0.5),
new THREE.MeshStandardMaterial({
color: 0x3d493e,
roughness: 0.78,
metalness: 0.35
})
);
signalCase.position.y = 3.25;
signalCase.castShadow = true;
signalGroup.add(signalCase);
const lens = new THREE.Mesh(
new THREE.CircleGeometry(0.17, 16),
new THREE.MeshStandardMaterial({
color: 0x8b3028,
emissive: 0x240603,
roughness: 0.48
})
);
lens.position.set(0, 3.36, 0.256);
signalGroup.add(lens);
scene.add(signalGroup);
// Broken boards beside the line.
for (let i = 0; i < 4; i++) {
const plank = new THREE.Mesh(
new THREE.BoxGeometry(rand(1.8, 3.3), 0.08, rand(0.18, 0.32)),
new THREE.MeshStandardMaterial({
color: i % 2 ? 0x594633 : 0x6e5840,
roughness: 1
})
);
plank.position.set(rand(-6.6, -5.2), 0.08 + i * 0.045, rand(6, 10));
plank.rotation.set(rand(-0.04, 0.04), rand(-0.35, 0.35), rand(-0.05, 0.05));
plank.castShadow = true;
plank.receiveShadow = true;
scene.add(plank);
}
// A small pile of discarded sleepers.
for (let i = 0; i < 3; i++) {
const oldSleeper = new THREE.Mesh(
new THREE.BoxGeometry(2.7, 0.18, 0.3),
new THREE.MeshStandardMaterial({
color: 0x554333,
roughness: 1
})
);
oldSleeper.position.set(7.4 + i * 0.08, 0.11 + i * 0.18, 13);
oldSleeper.rotation.y = -0.2 + i * 0.08;
oldSleeper.castShadow = true;
oldSleeper.receiveShadow = true;
scene.add(oldSleeper);
}
// -------------------------------------------------------------------------
// Growth animation
// -------------------------------------------------------------------------
function updateVegetation(progress, elapsed) {
const grassGrowth = 0.18 + 0.82 * smoothstep(0, 0.29, progress);
for (let i = 0; i < grassData.length; i++) {
const item = grassData[i];
const wind =
Math.sin(elapsed * 1.15 + item.phase + item.z * 0.08) * 0.025 *
(0.25 + grassGrowth);
dummy.position.set(
item.x,
surfaceHeight(item.x, item.z),
item.z
);
dummy.rotation.set(wind, item.rotation, wind * 0.7);
dummy.scale.set(
item.width,
item.height * grassGrowth,
item.width
);
dummy.updateMatrix();
grasses.setMatrixAt(i, dummy.matrix);
}
grasses.instanceMatrix.needsUpdate = true;
for (const shrub of shrubs) {
const growth = smoothstep(
0.27 + shrub.delay,
0.62 + shrub.delay,
progress
);
const sway = Math.sin(elapsed * 0.75 + shrub.phase) * 0.012 * growth;
shrub.group.scale.set(
shrub.size * growth,
shrub.size * growth,
shrub.size * growth
);
shrub.group.rotation.z = sway;
shrub.group.visible = growth > 0.005;
}
for (const seedling of seedlings) {
const growth = smoothstep(
0.62 + seedling.delay,
0.94 + seedling.delay,
progress
);
const sway = Math.sin(elapsed * 1.45 + seedling.phase) * 0.035 * growth;
seedling.group.scale.setScalar(growth);
seedling.group.rotation.z = sway;
seedling.group.visible = growth > 0.005;
}
}
// -------------------------------------------------------------------------
// Custom camera controls — no Three.js addons
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 0.85, -5);
const cameraState = {
yaw: 0.48,
pitch: 0.31,
distance: 31
};
const desiredCamera = {
yaw: cameraState.yaw,
pitch: cameraState.pitch,
distance: cameraState.distance
};
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
desiredCamera.yaw = THREE.MathUtils.clamp(
desiredCamera.yaw - deltaX * 0.005,
-1.02,
1.02
);
desiredCamera.pitch = THREE.MathUtils.clamp(
desiredCamera.pitch + deltaY * 0.0035,
0.21,
0.72
);
});
function endPointer(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredCamera.distance = THREE.MathUtils.clamp(
desiredCamera.distance + event.deltaY * 0.018,
22,
46
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
desiredCamera.yaw = 0.48;
desiredCamera.pitch = 0.31;
desiredCamera.distance = 31;
});
function updateCamera(dt) {
const smoothing = 1 - Math.exp(-dt * 7);
cameraState.yaw +=
(desiredCamera.yaw - cameraState.yaw) * smoothing;
cameraState.pitch +=
(desiredCamera.pitch - cameraState.pitch) * smoothing;
cameraState.distance +=
(desiredCamera.distance - cameraState.distance) * smoothing;
const horizontal =
Math.cos(cameraState.pitch) * cameraState.distance;
camera.position.set(
cameraTarget.x + Math.sin(cameraState.yaw) * horizontal,
cameraTarget.y + Math.sin(cameraState.pitch) * cameraState.distance,
cameraTarget.z + Math.cos(cameraState.yaw) * horizontal
);
camera.lookAt(cameraTarget);
}
// -------------------------------------------------------------------------
// Timeline and story interface
// -------------------------------------------------------------------------
const playButton = document.getElementById("play");
const resetButton = document.getElementById("reset");
const timeline = document.getElementById("timeline");
const progressValue = document.getElementById("progress-value");
const phaseValue = document.getElementById("phase-value");
const story = document.getElementById("story");
const storyKicker = document.getElementById("story-kicker");
const storyTitle = document.getElementById("story-title");
const storyText = document.getElementById("story-text");
const chapterButtons = [...document.querySelectorAll(".chapter")];
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
const chapters = [
{
threshold: 0,
kicker: "01 — Grasses",
title: "First green",
text: "Fine grasses root in the cool ballast shoulders, while the rails remain exposed."
},
{
threshold: 0.3,
kicker: "02 — Shrubs",
title: "Scrub takes hold",
text: "Low shrubs gather beyond the sleepers, loosening the edges of the old embankment."
},
{
threshold: 0.66,
kicker: "03 — Seedlings",
title: "A younger generation",
text: "Fresh seedlings appear between the stones: small signs that the line is becoming habitat."
}
];
let desiredProgress = reducedMotion ? 0.84 : 0;
let visualProgress = desiredProgress;
let playing = !reducedMotion;
let activeChapter = -1;
function setPlaying(value) {
playing = value;
playButton.textContent = playing ? "Pause growth" : "Resume growth";
}
function updatePlayButton() {
playButton.textContent = playing ? "Pause growth" : "Resume growth";
}
playButton.addEventListener("click", () => {
if (!playing && desiredProgress >= 0.999) {
desiredProgress = 0;
visualProgress = 0;
}
setPlaying(!playing);
});
resetButton.addEventListener("click", () => {
desiredProgress = 0;
visualProgress = 0;
setPlaying(false);
});
timeline.addEventListener("input", () => {
desiredProgress = Number(timeline.value) / 1000;
setPlaying(false);
});
chapterButtons.forEach((button) => {
button.addEventListener("click", () => {
desiredProgress = Number(button.dataset.progress);
setPlaying(false);
});
});
function updateInterface(progress) {
const percentage = Math.round(progress * 100);
progressValue.textContent = `${percentage}%`;
timeline.value = Math.round(progress * 1000);
timeline.style.setProperty("--progress", `${percentage}%`);
let chapterIndex = 0;
if (progress >= chapters[2].threshold) {
chapterIndex = 2;
} else if (progress >= chapters[1].threshold) {
chapterIndex = 1;
}
if (chapterIndex !== activeChapter) {
activeChapter = chapterIndex;
const chapter = chapters[chapterIndex];
storyKicker.textContent = chapter.kicker;
storyTitle.textContent = chapter.title;
storyText.textContent = chapter.text;
phaseValue.textContent = `0${chapterIndex + 1}`;
chapterButtons.forEach((button, index) => {
button.classList.toggle("active", index === chapterIndex);
});
story.classList.remove("pulse");
void story.offsetWidth;
story.classList.add("pulse");
}
}
updatePlayButton();
// -------------------------------------------------------------------------
// Resize and animation loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
if (playing) {
desiredProgress = Math.min(1, desiredProgress + dt / 24);
if (desiredProgress >= 1) {
setPlaying(false);
}
}
visualProgress +=
(desiredProgress - visualProgress) * (1 - Math.exp(-dt * 5.5));
updateVegetation(visualProgress, elapsed);
updateInterface(visualProgress);
updateCamera(dt);
renderer.render(scene, camera);
}
updateVegetation(visualProgress, 0);
updateInterface(visualProgress);
animate();
</script>
</body>
</html>
```