Prompt specification
Build or customize the Three.js 3D scene "Factory town linked to housing and railway" 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: Factory town linked to housing and railway
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/factory-town-linked-to-housing-and-railway-x2595
Scene Description Prompt:
A voxel historical factory town linking housing, station, workplace, and public services through everyday routes. Create one HTML file with Three.js from cdnjs.
Working Three.js Starter (factory-town-linked-to-housing-and-railway-x2595):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Millbrook — A Working Town, 1908</title>
<style>
:root {
--ink: #302d27;
--muted: #716b5f;
--paper: rgba(248, 243, 224, 0.94);
--line: rgba(70, 61, 45, 0.22);
--amber: #b97835;
--green: #58735a;
--blue: #506f82;
--rose: #a05d57;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8d1bd;
color: var(--ink);
font-family: Arial, Helvetica, sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
button { font: inherit; }
.panel {
position: fixed;
z-index: 10;
background: var(--paper);
border: 1px solid var(--line);
box-shadow: 0 10px 30px rgba(55, 46, 32, 0.14);
backdrop-filter: blur(8px);
}
#masthead {
top: 22px;
left: 22px;
width: min(365px, calc(100vw - 44px));
padding: 20px 22px 18px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: var(--amber);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.23em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 4vw, 48px);
font-weight: 500;
line-height: 0.95;
letter-spacing: -0.045em;
}
.subtitle {
margin: 10px 0 0;
color: var(--muted);
font-family: Georgia, "Times New Roman", serif;
font-size: 14px;
font-style: italic;
line-height: 1.45;
}
.rule {
width: 42px;
height: 3px;
margin: 15px 0 12px;
background: var(--amber);
}
.masthead-copy {
margin: 0;
color: #615b51;
font-size: 12px;
line-height: 1.55;
}
#detail {
top: 22px;
right: 22px;
width: min(310px, calc(100vw - 44px));
padding: 18px 19px;
transition: opacity 180ms ease;
}
#detail h2 {
margin: 0 0 6px;
font-family: Georgia, "Times New Roman", serif;
font-size: 22px;
font-weight: 500;
}
#detail .meta {
margin-bottom: 12px;
color: var(--amber);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
#detail p {
margin: 0;
color: #5f594f;
font-family: Georgia, "Times New Roman", serif;
font-size: 13px;
line-height: 1.55;
}
#detail .routes {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 13px;
}
.route-chip {
padding: 5px 8px;
border: 1px solid rgba(70, 61, 45, 0.16);
background: rgba(255, 255, 255, 0.35);
color: #5f594f;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
#controls {
left: 22px;
bottom: 22px;
display: flex;
gap: 7px;
padding: 8px;
}
.control {
min-height: 36px;
padding: 0 12px;
border: 1px solid rgba(70, 61, 45, 0.2);
background: rgba(255, 255, 255, 0.38);
color: #514c43;
cursor: pointer;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: background 140ms ease, color 140ms ease;
}
.control:hover,
.control.active {
background: var(--ink);
color: #f8f1db;
}
#legend {
right: 22px;
bottom: 22px;
padding: 13px 15px;
}
.legend-title {
margin-bottom: 9px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
margin-top: 6px;
color: #5f594f;
font-size: 10px;
}
.swatch {
width: 18px;
height: 3px;
background: var(--amber);
}
.swatch.blue { background: var(--blue); }
.swatch.green { background: var(--green); }
.swatch.rose { background: var(--rose); }
#hint {
position: fixed;
z-index: 9;
left: 50%;
bottom: 25px;
transform: translateX(-50%);
color: rgba(61, 55, 45, 0.65);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
pointer-events: none;
white-space: nowrap;
}
#loading {
position: fixed;
inset: 0;
z-index: 50;
display: grid;
place-items: center;
background: #d8d1bd;
color: #625b4e;
font-family: Georgia, "Times New Roman", serif;
font-size: 18px;
transition: opacity 400ms ease;
}
#loading.hidden { opacity: 0; pointer-events: none; }
@media (max-width: 760px) {
#masthead {
top: 12px;
left: 12px;
width: 235px;
padding: 14px 16px;
}
#masthead h1 { font-size: 30px; }
.subtitle { font-size: 12px; }
.masthead-copy { display: none; }
.rule { margin-bottom: 0; }
#detail {
top: auto;
right: 12px;
bottom: 64px;
width: 235px;
padding: 13px 15px;
}
#detail p { display: none; }
#detail .routes { margin-top: 8px; }
#controls {
left: 12px;
bottom: 12px;
flex-wrap: wrap;
max-width: calc(100vw - 24px);
}
.control {
padding: 0 9px;
font-size: 9px;
}
#legend { display: none; }
#hint { display: none; }
}
</style>
</head>
<body>
<div id="loading">Building Millbrook…</div>
<section id="masthead" class="panel">
<div class="eyebrow">A living historical diorama · 1908</div>
<h1>Millbrook</h1>
<div class="rule"></div>
<p class="subtitle">One town, carried by the daily journey.</p>
<p class="masthead-copy">
Follow workers from the station to the Lantern Works, from workers’ rows to
school, clinic, market and civic life.
</p>
</section>
<aside id="detail" class="panel">
<h2 id="detail-title">A town in motion</h2>
<div id="detail-meta" class="meta">Select a landmark</div>
<p id="detail-text">
Click a building to discover how Millbrook’s homes, railway and public
services supported the working day.
</p>
<div id="detail-routes" class="routes"></div>
</aside>
<nav id="controls" class="panel" aria-label="Scene controls">
<button id="routes-button" class="control active">Commute Routes</button>
<button id="labels-button" class="control active">Labels</button>
<button id="time-button" class="control">Evening</button>
<button id="reset-button" class="control">Reset View</button>
</nav>
<aside id="legend" class="panel">
<div class="legend-title">Everyday journeys</div>
<div class="legend-row"><span class="swatch"></span> Factory shift</div>
<div class="legend-row"><span class="swatch blue"></span> Station & housing</div>
<div class="legend-row"><span class="swatch green"></span> Civic services</div>
<div class="legend-row"><span class="swatch rose"></span> School & errands</div>
</aside>
<div id="hint">Drag to orbit · Shift-drag to pan · Scroll to zoom · Click to inspect</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const loading = document.getElementById("loading");
const detailTitle = document.getElementById("detail-title");
const detailMeta = document.getElementById("detail-meta");
const detailText = document.getElementById("detail-text");
const detailRoutes = document.getElementById("detail-routes");
const routesButton = document.getElementById("routes-button");
const labelsButton = document.getElementById("labels-button");
const timeButton = document.getElementById("time-button");
const resetButton = document.getElementById("reset-button");
const scene = new THREE.Scene();
const dayColor = new THREE.Color("#d8d1bd");
const duskColor = new THREE.Color("#8c806f");
scene.background = dayColor.clone();
scene.fog = new THREE.Fog(dayColor.clone(), 72, 145);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.body.prepend(renderer.domElement);
const world = new THREE.Group();
const routeLayer = new THREE.Group();
const labelLayer = new THREE.Group();
world.add(routeLayer, labelLayer);
scene.add(world);
const camera = new THREE.OrthographicCamera(-40, 40, 30, -30, 0.1, 250);
const cameraState = {
azimuth: 0.62,
polar: 0.78,
viewSize: 51,
target: new THREE.Vector3(0, 0, -1)
};
const hemisphere = new THREE.HemisphereLight(0xfff3d4, 0x756e61, 2.2);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe2af, 3.2);
sun.position.set(-24, 38, 27);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -48;
sun.shadow.camera.right = 48;
sun.shadow.camera.top = 42;
sun.shadow.camera.bottom = -42;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 110;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9fb4c4, 0.55);
fill.position.set(30, 18, -25);
scene.add(fill);
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
const palette = {
earth: new THREE.MeshStandardMaterial({ color: 0x9b9a79, roughness: 1 }),
earthDark: new THREE.MeshStandardMaterial({ color: 0x85866b, roughness: 1 }),
soil: new THREE.MeshStandardMaterial({ color: 0xb9aa85, roughness: 1 }),
brick: new THREE.MeshStandardMaterial({ color: 0x9d5541, roughness: 0.93 }),
brickDark: new THREE.MeshStandardMaterial({ color: 0x7d4437, roughness: 0.95 }),
plaster: new THREE.MeshStandardMaterial({ color: 0xd5c5a3, roughness: 0.92 }),
cream: new THREE.MeshStandardMaterial({ color: 0xe3d7b7, roughness: 0.9 }),
stone: new THREE.MeshStandardMaterial({ color: 0xa39b88, roughness: 0.98 }),
roofRed: new THREE.MeshStandardMaterial({ color: 0x8e4738, roughness: 0.9 }),
roofDark: new THREE.MeshStandardMaterial({ color: 0x40504b, roughness: 0.88 }),
roofBlue: new THREE.MeshStandardMaterial({ color: 0x465d66, roughness: 0.87 }),
wood: new THREE.MeshStandardMaterial({ color: 0x74543a, roughness: 1 }),
woodLight: new THREE.MeshStandardMaterial({ color: 0xa27b4e, roughness: 0.95 }),
iron: new THREE.MeshStandardMaterial({ color: 0x3d4240, roughness: 0.65, metalness: 0.38 }),
rail: new THREE.MeshStandardMaterial({ color: 0x5e615d, roughness: 0.45, metalness: 0.6 }),
road: new THREE.MeshStandardMaterial({ color: 0xa69c84, roughness: 1 }),
roadEdge: new THREE.MeshStandardMaterial({ color: 0xc1b596, roughness: 1 }),
cobbleA: new THREE.MeshStandardMaterial({ color: 0x918977, roughness: 1 }),
cobbleB: new THREE.MeshStandardMaterial({ color: 0xb0a58f, roughness: 1 }),
glass: new THREE.MeshStandardMaterial({
color: 0x394e57,
emissive: 0xffb85c,
emissiveIntensity: 0.03,
roughness: 0.28,
metalness: 0.12
}),
lamp: new THREE.MeshStandardMaterial({
color: 0xffe2a1,
emissive: 0xffa83b,
emissiveIntensity: 0.05,
roughness: 0.4
}),
red: new THREE.MeshStandardMaterial({ color: 0xa5483d, roughness: 0.8 }),
green: new THREE.MeshStandardMaterial({ color: 0x536e52, roughness: 1 }),
leafA: new THREE.MeshStandardMaterial({ color: 0x60734a, roughness: 1 }),
leafB: new THREE.MeshStandardMaterial({ color: 0x788154, roughness: 1 }),
leafC: new THREE.MeshStandardMaterial({ color: 0x4d6648, roughness: 1 }),
water: new THREE.MeshStandardMaterial({
color: 0x698b8d,
roughness: 0.42,
metalness: 0.08
}),
black: new THREE.MeshStandardMaterial({ color: 0x272b29, roughness: 0.75 }),
white: new THREE.MeshStandardMaterial({ color: 0xf0e7cf, roughness: 0.85 }),
canvasA: new THREE.MeshStandardMaterial({ color: 0xcb7956, roughness: 1 }),
canvasB: new THREE.MeshStandardMaterial({ color: 0xdfc69c, roughness: 1 })
};
function box(parent, w, h, d, x, y, z, material, castShadow = true) {
const mesh = new THREE.Mesh(cubeGeometry, material);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
let randomSeed = 417;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
function label(text, parent, x, y, z, color = "#f4e8c8", background = "#403c34") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 112;
const context = canvas.getContext("2d");
context.fillStyle = background;
context.beginPath();
context.roundRect(4, 4, 504, 104, 18);
context.fill();
context.strokeStyle = "rgba(255,255,255,.18)";
context.lineWidth = 3;
context.stroke();
context.fillStyle = color;
context.textAlign = "center";
context.textBaseline = "middle";
context.font = "700 35px Arial";
context.fillText(text.toUpperCase(), 256, 58);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
}));
sprite.position.set(x, y, z);
sprite.scale.set(9.4, 2.05, 1);
sprite.userData.isLabel = true;
labelLayer.add(sprite);
return sprite;
}
const poiData = {
station: {
title: "Ashwick Station",
meta: "Great Western branch line · opened 1876",
text: "Millbrook’s railway brought coal, timber, machinery and news. Thousands of workers crossed this platform each morning on their way to the Lantern Works.",
routes: ["Factory shift", "Housing to station"]
},
housing: {
title: "Workers’ Row",
meta: "Company housing · two terraces",
text: "Rows of modest brick homes stood close to the works. Residents walked to the station, the clinic, school and market, forming the daily rhythm of the town.",
routes: ["Commuter loop", "School journey", "Market errands"]
},
factory: {
title: "The Lantern Works",
meta: "Engineering works · established 1848",
text: "The largest employer in Millbrook produced industrial lamps and precision fittings. Steam rises from its brick chimney while shift workers arrive on foot and by train.",
routes: ["Factory shift", "Market deliveries"]
},
market: {
title: "Market Square",
meta: "Open market · Tuesdays and Fridays",
text: "The square connected the railway, works and surrounding homes. Fruit sellers, grocers and drapers served daily needs in the center of town.",
routes: ["Civic services", "Market errands"]
},
school: {
title: "Board School",
meta: "Elementary school · founded 1864",
text: "Children from the workers’ rows attended the board school in the morning and again at the end of the working day, taking the short route through the center.",
routes: ["School journey", "Housing to station"]
},
clinic: {
title: "District Clinic",
meta: "Public health service · opened 1891",
text: "The clinic provided inexpensive treatment to mill and factory workers. Its location near the market made it accessible to most of Millbrook on foot.",
routes: ["Civic services", "Factory shift"]
},
townhall: {
title: "Millbrook Town Hall",
meta: "Civic center · built 1887",
text: "Rates, notices, meetings and public announcements were handled here. The town hall stood beside the route between the station, homes and market square.",
routes: ["Civic services", "Station to housing"]
}
};
function showPOI(key) {
const data = poiData[key];
if (!data) return;
detailTitle.textContent = data.title;
detailMeta.textContent = data.meta;
detailText.textContent = data.text;
detailRoutes.innerHTML = "";
data.routes.forEach(route => {
const chip = document.createElement("span");
chip.className = "route-chip";
chip.textContent = route;
detailRoutes.appendChild(chip);
});
}
// Voxel terrain.
box(world, 68, 1, 50, 0, -0.68, 0, palette.earth, false);
const tileCount = 33 * 21;
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1
});
const tiles = new THREE.InstancedMesh(cubeGeometry, tileMaterial, tileCount);
tiles.receiveShadow = true;
const dummy = new THREE.Object3D();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let z = -20; z <= 20; z += 2) {
for (let x = -32; x <= 32; x += 2) {
dummy.position.set(x, -0.16, z);
dummy.scale.set(1.97, 0.42, 1.97);
dummy.updateMatrix();
tiles.setMatrixAt(tileIndex, dummy.matrix);
const shade = random();
if (shade < 0.18) tileColor.setHex(0x9a9a79);
else if (shade < 0.44) tileColor.setHex(0xa7a181);
else if (shade < 0.7) tileColor.setHex(0xb0a582);
else tileColor.setHex(0x999b7a);
tiles.setColorAt(tileIndex++, tileColor);
}
}
tiles.instanceMatrix.needsUpdate = true;
if (tiles.instanceColor) tiles.instanceColor.needsUpdate = true;
world.add(tiles);
// Canal and embankments.
box(world, 65, 0.35, 3.1, 0, -0.08, -22, palette.water, false);
box(world, 65, 0.55, 0.55, 0, 0.08, -20.45, palette.stone, false);
box(world, 65, 0.55, 0.55, 0, 0.08, -23.55, palette.stone, false);
box(world, 5.2, 0.45, 4.3, -10, 0.34, -22, palette.woodLight, false);
box(world, 0.25, 1.2, 4.2, -12.45, 0.95, -22, palette.wood);
box(world, 0.25, 1.2, 4.2, -7.55, 0.95, -22, palette.wood);
const waterRipples = [];
for (let i = 0; i < 26; i++) {
const ripple = box(
world, 0.7 + random() * 1.5, 0.035, 0.08,
-30 + random() * 60, 0.115, -23 + random() * 2,
palette.white, false
);
ripple.material = palette.white.clone();
ripple.material.transparent = true;
ripple.material.opacity = 0.2;
waterRipples.push({ mesh: ripple, offset: random() * 10 });
}
// Road graph.
const edgeDefinitions = [
{
name: "Station to housing", category: "blue", color: 0x506f82, width: 2.5,
path: [[-22, 14], [-22, 2], [-18, 2], [-18, -10]]
},
{
name: "Station to civic center", category: "green", color: 0x58735a, width: 2.35,
path: [[-22, 14], [-14, 14], [-11, 9], [-7, 5]]
},
{
name: "Station to factory", category: "amber", color: 0xb97835, width: 3.25,
path: [[-22, 14], [-9, 15], [4, 15], [14, 12], [18, 6], [18, -1]]
},
{
name: "Housing to school", category: "rose", color: 0xa05d57, width: 2.3,
path: [[-18, -10], [-12, -9], [-5, -10]]
},
{
name: "Housing to market", category: "rose", color: 0xa05d57, width: 2.15,
path: [[-18, -10], [-14, -4], [-7, -2], [1, 1]]
},
{
name: "School to factory", category: "amber", color: 0xb97835, width: 2.35,
path: [[-5, -10], [3, -9], [7, -5], [18, -1]]
},
{
name: "Market to factory", category: "amber", color: 0xb97835, width: 2.8,
path: [[1, 1], [8, 1], [13, 0], [18, -1]]
},
{
name: "Town hall to market", category: "green", color: 0x58735a, width: 2.4,
path: [[-7, 5], [-5, 4], [1, 1]]
},
{
name: "Market to school", category: "rose", color: 0xa05d57, width: 2.1,
path: [[1, 1], [-2, -4], [-5, -10]]
},
{
name: "Town hall to clinic", category: "green", color: 0x58735a, width: 2.25,
path: [[-7, 5], [0, 8], [6, 7], [11, 2]]
},
{
name: "Clinic to factory", category: "amber", color: 0xb97835, width: 2.2,
path: [[11, 2], [15, 1], [18, -1]]
}
];
function roadSegment(a, b, width, main = false) {
const dx = b[0] - a[0];
const dz = b[1] - a[1];
const length = Math.hypot(dx, dz);
const angle = -Math.atan2(dz, dx);
const centerX = (a[0] + b[0]) / 2;
const centerZ = (a[1] + b[1]) / 2;
const road = box(
world, length + 0.22, 0.13, width,
centerX, 0.16, centerZ, palette.road, false
);
road.rotation.y = angle;
const curbA = box(
world, length + 0.18, 0.12, 0.28,
centerX, 0.2, centerZ, palette.roadEdge, false
);
curbA.rotation.y = angle;
curbA.translateZ(width / 2 + 0.12);
const curbB = box(
world, length + 0.18, 0.12, 0.28,
centerX, 0.2, centerZ, palette.roadEdge, false
);
curbB.rotation.y = angle;
curbB.translateZ(-width / 2 - 0.12);
const stoneCount = Math.max(1, Math.floor(length / 0.78));
for (let i = 0; i < stoneCount; i++) {
const t = (i + 0.5) / stoneCount;
const px = a[0] + dx * t;
const pz = a[1] + dz * t;
const stone = box(
world, 0.28 + random() * 0.22, 0.035, width * 0.52,
px, 0.245, pz,
random() > 0.5 ? palette.cobbleA : palette.cobbleB,
false
);
stone.rotation.y = angle + (random() - 0.5) * 0.08;
}
}
function pathLength(path) {
let length = 0;
for (let i = 1; i < path.length; i++) {
length += Math.hypot(path[i][0] - path[i - 1][0], path[i][1] - path[i - 1][1]);
}
return length;
}
function samplePath(path, t) {
const length = pathLength(path);
let distance = ((t % 1) + 1) % 1 * length;
for (let i = 1; i < path.length; i++) {
const a = path[i - 1];
const b = path[i];
const segmentLength = Math.hypot(b[0] - a[0], b[1] - a[1]);
if (distance <= segmentLength) {
const u = segmentLength === 0 ? 0 : distance / segmentLength;
const x = a[0] + (b[0] - a[0]) * u;
const z = a[1] + (b[1] - a[1]) * u;
return { x, z, angle: Math.atan2(b[0] - a[0], b[1] - a[1]) };
}
distance -= segmentLength;
}
const last = path[path.length - 1];
return { x: last[0], z: last[1], angle: 0 };
}
const edges = edgeDefinitions.map(definition => {
for (let i = 1; i < definition.path.length; i++) {
roadSegment(definition.path[i - 1], definition.path[i], definition.width, definition.width > 3);
}
const points = definition.path.map(([x, z]) => new THREE.Vector3(x, 0.34, z));
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const lineMaterial = new THREE.LineDashedMaterial({
color: definition.color,
dashSize: 0.85,
gapSize: 0.58,
transparent: true,
opacity: 0.72
});
const line = new THREE.Line(geometry, lineMaterial);
line.computeLineDistances();
routeLayer.add(line);
const particleMaterial = new THREE.MeshStandardMaterial({
color: definition.color,
emissive: definition.color,
emissiveIntensity: 0.45,
roughness: 0.55
});
const particles = [];
for (let i = 0; i < 2; i++) {
const particle = box(routeLayer, 0.26, 0.16, 0.26, 0, 0.48, 0, particleMaterial, false);
particles.push({ mesh: particle, offset: i * 0.5 + random() * 0.12 });
}
return { ...definition, particles, length: pathLength(definition.path) };
});
function makeBuilding({
x, z, w, d, h, wall, roof, poi, sign,
roofStyle = "stepped", windowColumns = null
}) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.userData.poi = poi;
world.add(group);
box(group, w + 0.45, 0.45, d + 0.45, 0, 0.36, 0, palette.stone);
box(group, w, h, d, 0, 0.58 + h / 2, 0, wall);
if (roofStyle === "stepped") {
for (let i = 0; i < 4; i++) {
box(
group,
w + 1.15 - i * 0.72,
0.42,
d + 1 - i * 0.45,
0,
h + 0.78 + i * 0.4,
0,
roof
);
}
} else if (roofStyle === "flat") {
box(group, w + 0.5, 0.38, d + 0.5, 0, h + 0.77, 0, roof);
box(group, w + 0.2, 0.65, 0.3, 0, h + 1.25, d / 2, wall);
box(group, 0.3, 0.65, d + 0.2, -w / 2, h + 1.25, 0, wall);
box(group, 0.3, 0.65, d + 0.2, w / 2, h + 1.25, 0, wall);
} else if (roofStyle === "factory") {
const count = Math.max(3, Math.floor(w / 3.4));
for (let i = 0; i < count; i++) {
const rx = -w / 2 + (i + 0.5) * w / count;
box(group, w / count - 0.28, 0.55, d - 0.8, rx, h + 0.9, -0.2, roof);
box(group, w / count - 0.72, 1.25, 0.13, rx, h + 1.45, d / 2 - 0.45, palette.glass, false);
}
}
const columns = windowColumns ?? Math.max(2, Math.floor(w / 2.2));
for (let i = 0; i < columns; i++) {
const wx = -w / 2 + (i + 0.5) * w / columns;
box(group, 0.95, 1.18, 0.13, wx, h * 0.57 + 0.5, d / 2 + 0.08, palette.glass, false);
box(group, 0.1, 1.23, 0.08, wx, h * 0.57 + 0.5, d / 2 + 0.17, palette.woodLight, false);
box(group, 0.98, 0.1, 0.08, wx, h * 0.57 + 0.5, d / 2 + 0.17, palette.woodLight, false);
}
box(group, 1.35, 2.15, 0.16, 0, 1.57, d / 2 + 0.12, palette.wood);
box(group, 0.08, 0.08, 0.08, 0.43, 1.55, d / 2 + 0.23, palette.lamp);
const labelY = h + (roofStyle === "factory" ? 3.0 : 3.3);
label(sign, group, 0, labelY, 0);
return group;
}
// Station and railway.
const station = makeBuilding({
x: -21, z: 16.2, w: 12, d: 5.5, h: 4.4,
wall: palette.brick, roof: palette.roofDark, poi: "station",
sign: "Ashwick Station", windowColumns: 6
});
box(station, 2.5, 6.3, 2.7, 0, 3.75, -1.8, palette.brickDark);
box(station, 3.1, 0.42, 3.2, 0, 7.1, -1.8, palette.roofDark);
box(station, 1.55, 1.55, 0.12, 0, 6.1, -0.39, palette.cream);
box(station, 0.09, 0.72, 0.06, 0, 6.25, -0.29, palette.black, false);
box(station, 0.52, 0.09, 0.06, 0.16, 6.05, -0.28, palette.black, false);
box(world, 15, 0.35, 2.4, -21, 0.24, 19.65, palette.stone, false);
for (let x = -31; x <= 31; x += 1.25) {
box(world, 0.32, 0.12, 2.5, x, 0.16, 21.15, palette.wood, false);
}
box(world, 64, 0.16, 0.13, 0, 0.32, 20.44, palette.rail, false);
box(world, 64, 0.16, 0.13, 0, 0.32, 21.86, palette.rail, false);
for (let x = -30; x <= 30; x += 8) {
box(world, 0.18, 4.3, 0.18, x, 2.3, 23.1, palette.wood);
box(world, 2.4, 0.14, 0.14, x, 4.25, 23.1, palette.wood);
box(world, 0.12, 0.7, 0.12, x - 1, 3.85, 23.1, palette.iron);
box(world, 0.12, 0.7, 0.12, x + 1, 3.85, 23.1, palette.iron);
}
// Workers' housing.
const housingGroup = new THREE.Group();
housingGroup.userData.poi = "housing";
world.add(housingGroup);
function cottage(x, z, wallColor, roofColor) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.userData.poi = "housing";
world.add(group);
box(group, 4.4, 0.35, 4.4, 0, 0.32, 0, palette.stone);
box(group, 4, 3.5, 4, 0, 2.25, 0, wallColor);
for (let i = 0; i < 4; i++) {
box(group, 5 - i * 0.62, 0.34, 4.85 - i * 0.35, 0, 4.18 + i * 0.32, 0, roofColor);
}
box(group, 1.05, 1.85, 0.14, 0, 1.42, 2.07, palette.wood);
box(group, 0.75, 0.95, 0.12, -1.15, 2.25, 2.08, palette.glass, false);
box(group, 0.75, 0.95, 0.12, 1.15, 2.25, 2.08, palette.glass, false);
box(group, 0.55, 1.6, 0.58, 1.35, 4.75, -0.5, palette.brickDark);
return group;
}
cottage(-27, -16, palette.brick, palette.roofRed);
cottage(-19.5, -16, palette.plaster, palette.roofRed);
cottage(-12, -16, palette.brick, palette.roofDark);
cottage(-27, -7, palette.plaster, palette.roofRed);
cottage(-9.5, -7.5, palette.brick, palette.roofRed);
label("Workers’ Row", housingGroup, -19, 6.8, -13.7);
// Fences and washing lines.
for (let x = -29; x <= -8; x += 2.5) {
box(world, 0.13, 1.4, 0.13, x, 0.9, -12.8, palette.wood);
}
box(world, 21.5, 0.12, 0.12, -18.5, 1.25, -12.8, palette.wood);
box(world, 21.5, 0.12, 0.12, -18.5, 0.7, -12.8, palette.wood);
// Factory.
const factory = makeBuilding({
x: 18, z: -8, w: 14, d: 12, h: 7.3,
wall: palette.brick, roof: palette.iron, poi: "factory",
sign: "The Lantern Works", roofStyle: "factory", windowColumns: 5
});
box(factory, 2.35, 14.3, 2.35, 6, 7.4, -3.1, palette.brickDark);
box(factory, 2.8, 0.5, 2.8, 6, 14.65, -3.1, palette.stone);
box(factory, 4.1, 4.4, 0.3, 0.2, 2.7, 6.18, palette.wood);
box(factory, 3.4, 3.6, 0.12, -3.2, 2.25, 6.18, palette.glass, false);
box(factory, 0.16, 3.6, 0.14, -3.2, 2.25, 6.27, palette.iron, false);
box(factory, 3.4, 0.14, 0.14, -3.2, 2.25, 6.27, palette.iron, false);
const smokeOrigin = new THREE.Vector3(24, 15, -11.1);
const smokePuffs = [];
for (let i = 0; i < 12; i++) {
const material = new THREE.MeshStandardMaterial({
color: 0x7d7d76,
transparent: true,
opacity: 0.45,
roughness: 1,
depthWrite: false
});
const puff = box(world, 1, 1, 1, 0, 0, 0, material, false);
smokePuffs.push({ mesh: puff, phase: i / 12, offset: random() * 4 });
}
// Water tower.
const waterTower = new THREE.Group();
waterTower.position.set(25.8, 0, 5.5);
world.add(waterTower);
for (const x of [-1.6, 1.6]) {
for (const z of [-1.6, 1.6]) {
box(waterTower, 0.25, 6.3, 0.25, x, 3.15, z, palette.iron);
}
}
box(waterTower, 4, 2.4, 4, 0, 6.5, 0, palette.wood);
box(waterTower, 4.6, 0.22, 4.6, 0, 7.8, 0, palette.roofDark);
box(waterTower, 0.18, 5.4, 0.18, 0, 3.2, 2.2, palette.iron);
label("Water Tower", waterTower, 0, 9.5, 0);
// School.
const school = makeBuilding({
x: -5, z: -15, w: 8, d: 6, h: 4.6,
wall: palette.cream, roof: palette.roofRed, poi: "school",
sign: "Board School", windowColumns: 5
});
box(school, 1.6, 2.1, 1.6, 0, 7, -0.5, palette.brick);
box(school, 2, 0.35, 2, 0, 8.15, -0.5, palette.roofDark);
// Town hall.
const townhall = makeBuilding({
x: -7, z: 10, w: 9, d: 7, h: 6.2,
wall: palette.plaster, roof: palette.roofBlue, poi: "townhall",
sign: "Town Hall", windowColumns: 5
});
box(townhall, 6.8, 0.4, 2.2, 0, 4.15, 4.25, palette.stone);
for (const x of [-2.9, -1.45, 0, 1.45, 2.9]) {
box(townhall, 0.42, 3.8, 0.42, x, 2.35, 4.65, palette.white);
}
box(townhall, 7.7, 0.45, 1.25, 0, 4.45, 4.65, palette.stone);
box(townhall, 0.16, 7.5, 0.16, -4.9, 3.75, 2.8, palette.iron);
box(townhall, 2.1, 1.25, 0.08, -3.85, 6.9, 2.8, palette.cream);
// Clinic.
const clinic = makeBuilding({
x: 11, z: 7, w: 7, d: 6, h: 5.4,
wall: palette.cream, roof: palette.roofRed, poi: "clinic",
sign: "District Clinic", windowColumns: 4
});
box(clinic, 0.55, 2.2, 0.15, 0, 5.2, 3.12, palette.red, false);
box(clinic, 2.2, 0.55, 0.15, 0, 5.2, 3.13, palette.red, false);
// Market square.
const market = new THREE.Group();
market.userData.poi = "market";
world.add(market);
function marketStall(x, z, rotation = 0) {
const stall = new THREE.Group();
stall.position.set(x, 0, z);
stall.rotation.y = rotation;
stall.userData.poi = "market";
world.add(stall);
for (const sx of [-1.25, 1.25]) {
for (const sz of [-0.85, 0.85]) {
box(stall, 0.12, 2.45, 0.12, sx, 1.3, sz, palette.wood);
}
}
for (let i = 0; i < 6; i++) {
box(stall, 0.48, 0.2, 2.45, -1.2 + i * 0.48, 2.65, 0,
i % 2 ? palette.canvasA : palette.canvasB);
}
box(stall, 2.65, 0.65, 1.25, 0, 0.65, 0, palette.woodLight);
box(stall, 0.65, 0.55, 0.6, -0.55, 1.2, 0, palette.roofRed);
box(stall, 0.55, 0.5, 0.6, 0.35, 1.15, 0.15, palette.green);
}
marketStall(-2.3, 2.2, 0.12);
marketStall(4.4, 3.5, -0.15);
marketStall(-1.6, -1.8, Math.PI / 2);
marketStall(4.3, -1.4, Math.PI / 2);
box(market, 3.1, 0.32, 3.1, 1, 0.35, 1, palette.stone, false);
box(market, 0.55, 1.5, 0.55, 1, 1.15, 1, palette.cream);
box(market, 1.35, 0.3, 1.35, 1, 1.95, 1, palette.stone);
label("Market Square", market, 1, 5.1, 1);
// Trees, lamps and benches.
function tree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
world.add(group);
box(group, 0.55, 2.6, 0.55, 0, 1.3, 0, palette.wood);
box(group, 2.6, 1.5, 2.6, 0, 3.1, 0, palette.leafA);
box(group, 1.8, 1.35, 1.8, -0.8, 3.9, 0.2, palette.leafB);
box(group, 1.65, 1.2, 1.65, 0.85, 3.65, -0.35, palette.leafC);
box(group, 1.4, 0.95, 1.4, 0.05, 4.65, 0, palette.leafB);
}
[
[-29, 10], [-28, 2], [-25, -2], [-15, 19], [-8, 18],
[7, 18], [15, 18], [27, 12], [28, 2], [28, -15],
[7, -16], [2, -18], [-16, -18], [-31, -16]
].forEach(([x, z], index) => tree(x, z, 0.8 + (index % 3) * 0.12));
function lamp(x, z) {
const group = new THREE.Group();
group.position.set(x, 0, z);
world.add(group);
box(group, 0.13, 3.3, 0.13, 0, 1.65, 0, palette.iron);
box(group, 0.55, 0.16, 0.55, 0, 3.35, 0, palette.iron);
box(group, 0.38, 0.48, 0.38, 0, 3.05, 0, palette.lamp, false);
box(group, 0.52, 0.13, 0.52, 0, 2.78, 0, palette.iron);
}
[
[-20, 12.8], [-12.5, 12.8], [-8, 6], [-17.5, -8.5],
[-7.2, -8.8], [-3, 3], [3.3, 2.7], [8, 2.8],
[10, 1], [16.5, 0.8], [-4.5, 14.2], [5, 14.2]
].forEach(([x, z]) => lamp(x, z));
function bench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
world.add(group);
box(group, 2.5, 0.18, 0.65, 0, 0.8, 0, palette.woodLight);
box(group, 2.5, 0.65, 0.16, 0, 1.25, -0.28, palette.woodLight);
box(group, 0.16, 0.65, 0.55, -0.95, 0.5, 0, palette.iron);
box(group, 0.16, 0.65, 0.55, 0.95, 0.5, 0, palette.iron);
}
bench(-1.8, 4.2, 0);
bench(3.7, 4.1, Math.PI);
bench(-7.8, 4.8, 0);
bench(10.4, 3.4, Math.PI);
const squareLight = new THREE.PointLight(0xffb45e, 0, 18, 2);
squareLight.position.set(1, 5, 1);
scene.add(squareLight);
// Voxel pedestrians.
const people = [];
const peoplePalette = [
palette.roofRed, palette.roofBlue, palette.green,
palette.wood, palette.black, palette.cream
];
function makePerson(edgeIndex, offset, speed, color, hatColor = palette.black) {
const group = new THREE.Group();
routeLayer.add(group);
const bodyMaterial = color;
box(group, 0.38, 0.63, 0.28, 0, 0.83, 0, bodyMaterial);
box(group, 0.31, 0.31, 0.31, 0, 1.31, 0, palette.cream);
box(group, 0.36, 0.12, 0.36, 0, 1.52, 0, hatColor);
box(group, 0.13, 0.45, 0.15, -0.1, 0.32, 0, palette.black);
box(group, 0.13, 0.45, 0.15, 0.1, 0.32, 0, palette.black);
people.push({ group, edgeIndex, offset, speed, phase: random() * 6 });
}
[
[2, 0.08, 0.028], [2, 0.34, 0.025], [2, 0.71, 0.030],
[0, 0.21, 0.025], [0, 0.66, 0.023], [3, 0.33, 0.027],
[4, 0.12, 0.023], [5, 0.51, 0.026], [6, 0.72, 0.025],
[7, 0.41, 0.024], [8, 0.18, 0.023], [9, 0.63, 0.025],
[10, 0.37, 0.026], [1, 0.79, 0.023]
].forEach((data, index) => {
makePerson(
data[0], data[1], data[2],
peoplePalette[index % peoplePalette.length],
index % 4 === 0 ? palette.cream : palette.black
);
});
// Horse-drawn delivery cart.
const cart = new THREE.Group();
routeLayer.add(cart);
box(cart, 2.2, 0.8, 1.25, -1, 0.85, 0, palette.wood);
box(cart, 2.35, 0.18, 1.4, -1, 1.3, 0, palette.woodLight);
box(cart, 1.8, 0.75, 1.05, -1, 1.75, 0, palette.canvasA);
box(cart, 0.12, 1.4, 0.12, 0.15, 1.1, 0, palette.wood);
box(cart, 1.55, 0.75, 0.65, 1.55, 1.0, 0, palette.wood);
box(cart, 0.55, 0.75, 0.5, 2.5, 1.3, 0, palette.wood);
box(cart, 0.12, 0.95, 0.12, 0.75, 1.45, 0, palette.wood);
for (const x of [-1.75, -0.25]) {
box(cart, 0.65, 0.65, 0.18, x, 0.45, 0.73, palette.black);
box(cart, 0.65, 0.65, 0.18, x, 0.45, -0.73, palette.black);
}
// Steam train.
const train = new THREE.Group();
train.position.set(-43, 0, 21.15);
world.add(train);
box(train, 4.4, 1.8, 2.1, 0, 1.55, 0, palette.black);
box(train, 1.6, 2.2, 1.7, -0.75, 2.85, 0, palette.brickDark);
box(train, 0.8, 1.05, 0.12, -0.75, 3.05, 0.9, palette.glass, false);
box(train, 0.62, 1.5, 0.62, 1.45, 2.8, 0, palette.iron);
box(train, 0.85, 0.25, 0.85, 1.45, 3.65, 0, palette.black);
for (const x of [-1.45, -0.2, 1.25]) {
box(train, 0.7, 0.7, 2.35, x, 0.55, 0, palette.black);
}
for (let i = 1; i <= 2; i++) {
const carX = -i * 5.3;
box(train, 4.4, 2.1, 2.15, carX, 1.75, 0, palette.brickDark);
box(train, 4.7, 0.25, 2.4, carX, 2.95, 0, palette.roofDark);
for (const x of [-1.3, 0, 1.3]) {
box(train, 0.7, 0.75, 0.12, carX + x, 2.05, 1.11, palette.glass, false);
}
for (const wx of [-1.4, 1.4]) {
box(train, 0.65, 0.65, 2.3, carX + wx, 0.55, 0, palette.black);
}
}
// Ambient details: laundry, carts, crates and notices.
function laundryLine(x1, z1, x2, z2) {
box(world, Math.abs(x2 - x1), 0.035, 0.035, (x1 + x2) / 2, 2.4, (z1 + z2) / 2, palette.black, false);
for (let i = 0; i < 4; i++) {
const t = (i + 0.5) / 4;
box(world, 0.5, 0.7, 0.06, x1 + (x2 - x1) * t, 2.02, z1, i % 2 ? palette.white : palette.canvasB, false);
}
}
laundryLine(-24, -11.6, -19, -11.6);
laundryLine(-16, -11.6, -12, -11.6);
for (let i = 0; i < 8; i++) {
box(
world, 0.75, 0.65, 0.75,
5.6 + (i % 3) * 0.85, 0.55 + Math.floor(i / 3) * 0.65, -2.4,
palette.woodLight
);
}
const noticeBoard = new THREE.Group();
noticeBoard.position.set(-4.7, 0, 6.1);
world.add(noticeBoard);
box(noticeBoard, 2.1, 1.4, 0.15, 0, 2.1, 0, palette.wood);
box(noticeBoard, 1.75, 1.0, 0.05, 0, 2.1, 0.1, palette.cream, false);
box(noticeBoard, 0.12, 2.3, 0.12, -0.75, 1.2, 0, palette.wood);
box(noticeBoard, 0.12, 2.3, 0.12, 0.75, 1.2, 0, palette.wood);
// Custom orthographic camera controls.
function updateCamera() {
const aspect = window.innerWidth / window.innerHeight;
const effectiveSize = Math.max(cameraState.viewSize, 70 / aspect);
camera.left = -effectiveSize * aspect / 2;
camera.right = effectiveSize * aspect / 2;
camera.top = effectiveSize / 2;
camera.bottom = -effectiveSize / 2;
camera.updateProjectionMatrix();
const radius = 72;
const horizontal = Math.sin(cameraState.polar) * radius;
camera.position.set(
cameraState.target.x + horizontal * Math.sin(cameraState.azimuth),
cameraState.target.y + Math.cos(cameraState.polar) * radius,
cameraState.target.z + horizontal * Math.cos(cameraState.azimuth)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.azimuth = 0.62;
cameraState.polar = 0.78;
cameraState.viewSize = 51;
cameraState.target.set(0, 0, -1);
updateCamera();
}
let pointerDown = false;
let moved = false;
let lastX = 0;
let lastY = 0;
let panning = false;
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("pointerdown", event => {
pointerDown = true;
moved = false;
panning = event.button === 2 || event.shiftKey;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointerDown) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (Math.abs(dx) + Math.abs(dy) > 1) moved = true;
if (panning) {
const scale = cameraState.viewSize / window.innerHeight * 1.6;
const right = new THREE.Vector3(Math.cos(cameraState.azimuth), 0, -Math.sin(cameraState.azimuth));
const forward = new THREE.Vector3(-Math.sin(cameraState.azimuth), 0, -Math.cos(cameraState.azimuth));
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(forward, -dy * scale);
} else {
cameraState.azimuth -= dx * 0.006;
cameraState.polar = THREE.MathUtils.clamp(cameraState.polar - dy * 0.005, 0.34, 1.23);
}
updateCamera();
});
renderer.domElement.addEventListener("pointerup", event => {
pointerDown = false;
if (!moved && event.button === 0) {
pointer.x = event.clientX / window.innerWidth * 2 - 1;
pointer.y = -(event.clientY / window.innerHeight) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(world.children, true);
for (const hit of hits) {
if (hit.object.userData.isLabel) continue;
let object = hit.object;
while (object && !object.userData.poi) object = object.parent;
if (object?.userData.poi) {
showPOI(object.userData.poi);
break;
}
}
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.viewSize = THREE.MathUtils.clamp(
cameraState.viewSize + event.deltaY * 0.035,
27,
76
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("resize", () => {
renderer.setSize(window.innerWidth, window.innerHeight);
updateCamera();
});
routesButton.addEventListener("click", () => {
routeLayer.visible = !routeLayer.visible;
routesButton.classList.toggle("active", routeLayer.visible);
});
labelsButton.addEventListener("click", () => {
labelLayer.visible = !labelLayer.visible;
labelsButton.classList.toggle("active", labelLayer.visible);
});
let evening = false;
let duskMix = 0;
timeButton.addEventListener("click", () => {
evening = !evening;
timeButton.textContent = evening ? "Morning" : "Evening";
timeButton.classList.toggle("active", evening);
});
resetButton.addEventListener("click", resetCamera);
updateCamera();
// Animation.
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
duskMix += ((evening ? 1 : 0) - duskMix) * Math.min(1, delta * 2.4);
scene.background.copy(dayColor).lerp(duskColor, duskMix);
scene.fog.color.copy(scene.background);
sun.intensity = THREE.MathUtils.lerp(3.2, 0.48, duskMix);
hemisphere.intensity = THREE.MathUtils.lerp(2.2, 0.85, duskMix);
fill.intensity = THREE.MathUtils.lerp(0.55, 0.22, duskMix);
squareLight.intensity = duskMix * 85;
palette.glass.emissiveIntensity = THREE.MathUtils.lerp(0.03, 1.45, duskMix);
palette.lamp.emissiveIntensity = THREE.MathUtils.lerp(0.05, 2.2, duskMix);
edges.forEach((edge, edgeIndex) => {
edge.particles.forEach((particle, particleIndex) => {
const t = (elapsed * (0.065 + edgeIndex * 0.001) + particle.offset) % 1;
const point = samplePath(edge.path, t);
particle.mesh.position.set(point.x, 0.47, point.z);
particle.mesh.rotation.y = point.angle;
particle.mesh.scale.setScalar(0.75 + Math.sin(elapsed * 5 + particleIndex) * 0.12);
});
});
people.forEach(person => {
const edge = edges[person.edgeIndex];
const t = (elapsed * person.speed + person.offset) % 1;
const point = samplePath(edge.path, t);
person.group.position.set(point.x, 0.22 + Math.abs(Math.sin(elapsed * 7 + person.phase)) * 0.045, point.z);
person.group.rotation.y = point.angle;
person.group.rotation.z = Math.sin(elapsed * 7 + person.phase) * 0.025;
});
const cartPoint = samplePath(edges[2].path, (elapsed * 0.018) % 1);
cart.position.set(cartPoint.x, 0.2, cartPoint.z);
cart.rotation.y = cartPoint.angle;
smokePuffs.forEach((puff, index) => {
const life = (elapsed * 0.095 + puff.phase) % 1;
const scale = 0.55 + life * 2.2;
puff.mesh.position.set(
smokeOrigin.x + life * 3.4 + Math.sin(life * 6 + puff.offset) * 0.55,
smokeOrigin.y + life * 7.5,
smokeOrigin.z + life * 1.4 + Math.cos(life * 5 + puff.offset) * 0.45
);
puff.mesh.scale.set(scale, scale * 0.82, scale);
puff.mesh.rotation.set(life * 0.4, life * 0.7, life * 0.25);
puff.mesh.material.opacity = (1 - life) * 0.43;
});
waterRipples.forEach(ripple => {
ripple.mesh.position.x += delta * (0.28 + ripple.offset * 0.015);
if (ripple.mesh.position.x > 32) ripple.mesh.position.x = -32;
ripple.mesh.material.opacity = 0.13 + Math.sin(elapsed * 1.8 + ripple.offset) * 0.08;
});
train.position.x += delta * 1.65;
if (train.position.x > 47) train.position.x = -47;
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 450);
});
</script>
</body>
</html>
```