Prompt specification
Build or customize the Three.js 3D scene "Bucket relay across a narrow lane" 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: Bucket relay across a narrow lane
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/bucket-relay-across-a-narrow-lane-x2358
Scene Description Prompt:
Please make a cutaway Three.js scene in one standalone HTML file using cdnjs. Create a historically informed bucket relay between a water point and small non-graphic roof fire. Animate handoffs with filled and returning empty buckets separated.
Working Three.js Starter (bucket-relay-across-a-narrow-lane-x2358):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>The Bucket Relay — Three.js Cutaway</title>
<style>
:root {
--ink: #253139;
--paper: #f5f0e3;
--water: #2d91ad;
--empty: #b86d45;
--line: rgba(37, 49, 57, 0.2);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8e2df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 5;
pointer-events: none;
}
.title-card {
top: 26px;
left: 28px;
max-width: min(390px, calc(100vw - 56px));
padding: 18px 20px 16px;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 16px;
background: rgba(247, 243, 232, 0.87);
box-shadow: 0 14px 40px rgba(30, 47, 50, 0.13);
backdrop-filter: blur(12px);
}
.eyebrow {
margin-bottom: 5px;
color: #65736e;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(29px, 4vw, 43px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
margin: 10px 0 14px;
color: #596863;
font-size: 12px;
line-height: 1.45;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 14px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: #3f4e4a;
font-size: 11px;
font-weight: 700;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 12px;
height: 12px;
border-radius: 50%;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}
.swatch.full {
background: var(--water);
}
.swatch.empty {
background: var(--empty);
}
.note {
top: 26px;
right: 28px;
width: 220px;
padding: 13px 15px;
border: 1px solid rgba(255, 255, 255, 0.48);
border-radius: 13px;
background: rgba(247, 243, 232, 0.77);
color: #53615d;
font-size: 10px;
line-height: 1.45;
box-shadow: 0 10px 30px rgba(30, 47, 50, 0.09);
backdrop-filter: blur(10px);
}
.note strong {
display: block;
margin-bottom: 3px;
color: #34433f;
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.controls {
right: 28px;
bottom: 26px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
appearance: none;
padding: 10px 13px;
border: 1px solid rgba(37, 49, 57, 0.16);
border-radius: 10px;
background: rgba(248, 245, 235, 0.9);
color: var(--ink);
font: 700 11px/1 Inter, ui-sans-serif, system-ui, sans-serif;
cursor: pointer;
box-shadow: 0 6px 20px rgba(30, 47, 50, 0.09);
backdrop-filter: blur(10px);
transition: transform 150ms ease, background 150ms ease;
}
button:hover {
transform: translateY(-1px);
background: #fffdf5;
}
button:active {
transform: translateY(0);
}
.hint {
left: 28px;
bottom: 28px;
padding: 9px 12px;
border-radius: 10px;
background: rgba(247, 243, 232, 0.73);
color: #596863;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.025em;
backdrop-filter: blur(8px);
}
.hint span {
color: #2d3a3a;
}
@media (max-width: 720px) {
.title-card {
top: 14px;
left: 14px;
padding: 14px 15px;
}
.subtitle {
margin-bottom: 10px;
}
.note {
display: none;
}
.controls {
right: 14px;
bottom: 14px;
}
.hint {
left: 14px;
bottom: 62px;
max-width: calc(100vw - 28px);
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive cutaway of a historical bucket fire relay"></canvas>
<section class="panel title-card">
<div class="eyebrow">Water-to-roof firefighting</div>
<h1>The Bucket Relay</h1>
<p class="subtitle">
A historically informed cutaway of a hand-bucket brigade moving water
from an open cistern to a small roof fire.
</p>
<div class="legend">
<div class="legend-item">
<span class="swatch full"></span>
Filled buckets — outbound
</div>
<div class="legend-item">
<span class="swatch empty"></span>
Empty buckets — return
</div>
</div>
</section>
<aside class="panel note">
<strong>How the relay works</strong>
Filled wooden buckets travel toward the building. After their contents
are used, empty buckets return along a visibly separate lane.
</aside>
<div class="panel hint">
<span>Drag</span> to orbit · <span>Right-drag / Shift-drag</span> to pan ·
<span>Scroll</span> to zoom
</div>
<div class="panel controls">
<button id="pause" type="button">Pause motion</button>
<button id="reset" type="button">Reset view</button>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const pauseButton = document.querySelector("#pause");
const resetButton = document.querySelector("#reset");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
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.05;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8e2df);
scene.fog = new THREE.Fog(0xd8e2df, 39, 72);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
120
);
const hemisphere = new THREE.HemisphereLight(0xeaf6f2, 0x6b654c, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0ce, 3.3);
sun.position.set(-9, 19, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -22;
sun.shadow.camera.right = 22;
sun.shadow.camera.top = 19;
sun.shadow.camera.bottom = -17;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fillLight = new THREE.DirectionalLight(0xbad7e0, 0.85);
fillLight.position.set(15, 8, -14);
scene.add(fillLight);
const standard = (color, roughness = 0.8, metalness = 0) =>
new THREE.MeshStandardMaterial({ color, roughness, metalness });
const materials = {
ground: standard(0x8e9b78),
earth: standard(0x766b52),
base: standard(0x59584d),
stone: standard(0x817e70),
stoneLight: standard(0x9b9787),
timber: standard(0x5d402e),
timberLight: standard(0x98704a),
beam: standard(0x4b3527),
plaster: standard(0xd4c39e),
plasterEdge: standard(0xe7d7b3),
floor: standard(0x9c7048),
roof: standard(0x914b3d),
roofDark: standard(0x713c35),
blue: standard(0x287f9d, 0.24, 0.05),
blueLight: standard(0x55b9cd, 0.18, 0.05),
bucketWood: standard(0xa66f39),
bucketDark: standard(0x664328),
iron: standard(0x3b4140, 0.48, 0.65),
clay: standard(0xb66c45),
cream: standard(0xe9dfc8),
skin: standard(0xc58f68),
black: standard(0x293034),
window: standard(0x789da3, 0.3, 0.05),
leaf: standard(0x687c55),
leafLight: standard(0x829064)
};
function addMesh(geometry, material, parent = scene) {
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBox(parent, w, h, d, x, y, z, material) {
const mesh = addMesh(new THREE.BoxGeometry(w, h, d), material, parent);
mesh.position.set(x, y, z);
return mesh;
}
function addCylinder(
parent,
topRadius,
bottomRadius,
height,
x,
y,
z,
material,
segments = 12
) {
const mesh = addMesh(
new THREE.CylinderGeometry(
topRadius,
bottomRadius,
height,
segments
),
material,
parent
);
mesh.position.set(x, y, z);
return mesh;
}
function addSphere(parent, radius, x, y, z, material) {
const mesh = addMesh(
new THREE.SphereGeometry(radius, 12, 8),
material,
parent
);
mesh.position.set(x, y, z);
return mesh;
}
function addBeam(parent, a, b, width, depth, material) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const beam = addMesh(
new THREE.BoxGeometry(width, length, depth),
material,
parent
);
beam.position.copy(start).add(end).multiplyScalar(0.5);
beam.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return beam;
}
function addQuad(parent, points, material) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(points.flat(), 3)
);
geometry.setIndex([0, 1, 2, 0, 2, 3]);
geometry.computeVertexNormals();
const sideMaterial = material.clone();
sideMaterial.side = THREE.DoubleSide;
return addMesh(geometry, sideMaterial, parent);
}
function makeLabel(text, accent = "#2d91ad", width = 4) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 640;
labelCanvas.height = 144;
const context = labelCanvas.getContext("2d");
context.clearRect(0, 0, 640, 144);
context.fillStyle = "rgba(249, 246, 236, 0.93)";
context.strokeStyle = "rgba(44, 57, 57, 0.18)";
context.lineWidth = 4;
const x = 8;
const y = 8;
const w = 624;
const h = 128;
const radius = 24;
context.beginPath();
context.moveTo(x + radius, y);
context.lineTo(x + w - radius, y);
context.quadraticCurveTo(x + w, y, x + w, y + radius);
context.lineTo(x + w, y + h - radius);
context.quadraticCurveTo(x + w, y + h, x + w - radius, y + h);
context.lineTo(x + radius, y + h);
context.quadraticCurveTo(x, y + h, x, y + h - radius);
context.lineTo(x, y + radius);
context.quadraticCurveTo(x, y, x + radius, y);
context.closePath();
context.fill();
context.stroke();
context.fillStyle = accent;
context.fillRect(25, 31, 10, 82);
context.fillStyle = "#2b393a";
context.font = "700 47px Georgia, serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 332, 74);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
sprite.scale.set(width, width * 0.225, 1);
return sprite;
}
// ---------------------------------------------------------------------
// Ground, paths, and the cutaway landscape
// ---------------------------------------------------------------------
addBox(scene, 31, 0.7, 17, 0, -0.48, 0, materials.base);
addBox(scene, 30.5, 0.13, 16.5, 0, -0.075, 0, materials.ground);
// Two pale earth lanes make the outbound and return routes readable.
addBox(scene, 19.5, 0.025, 1.05, -3.2, 0.01, -0.6, materials.earth);
addBox(scene, 19.5, 0.025, 1.05, -3.2, 0.01, 1.65, materials.earth);
for (let x = -9.5; x < 4.4; x += 1.25) {
addBox(scene, 0.68, 0.035, 0.12, x, 0.04, -1.05, materials.blue);
addBox(scene, 0.68, 0.035, 0.12, x, 0.04, 1.2, materials.clay);
}
// Small deterministic paving details.
const pavingGeometry = new THREE.BoxGeometry(0.5, 0.07, 0.34);
const paving = new THREE.InstancedMesh(
pavingGeometry,
materials.stoneLight,
110
);
paving.castShadow = true;
paving.receiveShadow = true;
const pavingDummy = new THREE.Object3D();
let pavingIndex = 0;
for (let i = 0; i < 110; i++) {
const row = Math.floor(i / 11);
const column = i % 11;
pavingDummy.position.set(
-10 + column * 1.05 + (row % 2) * 0.22,
0.055,
-1.55 + row * 0.48
);
pavingDummy.rotation.y = ((i * 13) % 7 - 3) * 0.025;
pavingDummy.updateMatrix();
paving.setMatrixAt(pavingIndex++, pavingDummy.matrix);
}
scene.add(paving);
// Low planting beds.
const plantingPositions = [
[-13, 5.8], [-11.8, 6.2], [12.8, 5.9], [14, 4.8], [13.7, -6.1]
];
for (const [x, z] of plantingPositions) {
addCylinder(scene, 0.75, 0.85, 0.18, x, 0.09, z, materials.earth);
for (let i = 0; i < 5; i++) {
const bush = addSphere(
scene,
0.38 + (i % 2) * 0.09,
x + Math.sin(i * 2.1) * 0.38,
0.34 + (i % 2) * 0.08,
z + Math.cos(i * 1.8) * 0.3,
i % 2 ? materials.leaf : materials.leafLight
);
bush.scale.y = 0.72;
}
}
// ---------------------------------------------------------------------
// Open stone cistern and timber hoist
// ---------------------------------------------------------------------
const cistern = new THREE.Group();
cistern.position.set(-10, 0, -1.4);
scene.add(cistern);
addCylinder(cistern, 1.78, 1.88, 0.2, 0, 0.08, 0, materials.stone, 32);
addCylinder(cistern, 1.48, 1.48, 0.075, 0, 0.205, 0, materials.blue, 32);
for (let i = 0; i < 18; i++) {
const angle = (i / 18) * Math.PI * 2;
const block = addBox(
cistern,
0.68,
0.5 + (i % 3) * 0.035,
0.42,
Math.cos(angle) * 1.7,
0.43,
Math.sin(angle) * 1.7,
i % 3 === 0 ? materials.stoneLight : materials.stone
);
block.rotation.y = -angle + Math.PI / 2;
}
addBox(cistern, 0.18, 2.9, 0.18, -1.35, 1.5, 0, materials.timber);
addBox(cistern, 0.18, 2.9, 0.18, 1.35, 1.5, 0, materials.timber);
addBox(cistern, 3.0, 0.2, 0.2, 0, 2.95, 0, materials.timberLight);
addBeam(
cistern,
[-1.25, 2.9, 0],
[0, 3.28, 0],
0.12,
0.12,
materials.timber
);
addBeam(
cistern,
[1.25, 2.9, 0],
[0, 3.28, 0],
0.12,
0.12,
materials.timber
);
const pulley = addMesh(
new THREE.TorusGeometry(0.32, 0.065, 8, 20),
materials.iron,
cistern
);
pulley.position.set(0, 3.05, 0.04);
addCylinder(
cistern,
0.018,
0.018,
2.4,
0,
1.82,
0.04,
materials.beam,
6
);
const waterLabel = makeLabel("OPEN WATER", "#287f9d", 3.8);
waterLabel.position.set(-10, 3.95, -1.25);
scene.add(waterLabel);
// ---------------------------------------------------------------------
// Cutaway timber-framed house
// ---------------------------------------------------------------------
const house = new THREE.Group();
scene.add(house);
addBox(house, 7.7, 0.42, 6.35, 8, 0.16, -0.25, materials.stone);
addBox(house, 7.35, 0.14, 6.0, 8, 0.43, -0.25, materials.floor);
// Floor boards.
for (let x = 4.45; x < 11.7; x += 0.58) {
addBox(house, 0.025, 0.018, 5.9, x, 0.515, -0.25, materials.timberLight);
}
// Rear and far walls. The front and near walls are omitted to expose
// the interior, giving the scene a true dollhouse-like cutaway.
addBox(house, 7.4, 3.55, 0.24, 8, 2.25, -3.05, materials.plaster);
addBox(house, 0.24, 3.55, 6.05, 4.35, 2.25, -0.25, materials.plaster);
addBox(house, 7.45, 0.22, 0.3, 8, 4.05, -3.05, materials.timber);
// Pale cut edges emphasize the removed wall.
addBox(house, 0.3, 3.7, 0.3, 4.35, 2.28, 2.7, materials.plasterEdge);
addBox(house, 0.3, 3.7, 0.3, 11.65, 2.28, 2.7, materials.plasterEdge);
addBox(house, 7.45, 0.18, 0.3, 8, 4.08, 2.7, materials.timber);
// Exposed posts and braces.
for (const x of [4.35, 7.9, 11.65]) {
addBox(house, 0.2, 3.65, 0.22, x, 2.28, 2.7, materials.timber);
}
addBeam(
house,
[4.35, 0.65, 2.72],
[7.85, 3.85, 2.72],
0.14,
0.14,
materials.timber
);
// Window and simple interior furnishings.
addBox(house, 1.55, 1.35, 0.08, 7.6, 2.7, -2.88, materials.window);
addBox(house, 0.08, 1.4, 0.11, 7.6, 2.7, -2.81, materials.timberLight);
addBox(house, 1.62, 0.08, 0.11, 7.6, 2.7, -2.81, materials.timberLight);
addBox(house, 1.5, 0.12, 0.55, 9.45, 1.25, 0.75, materials.timberLight);
for (const x of [8.85, 10.05]) {
addBox(house, 0.12, 0.78, 0.12, x, 0.86, 0.75, materials.timber);
}
addCylinder(house, 0.3, 0.34, 0.12, 10.0, 0.64, 1.65, materials.timber, 10);
addBox(house, 2.0, 0.13, 0.5, 8.2, 2.0, -2.65, materials.timberLight);
addBox(house, 2.0, 0.13, 0.5, 8.2, 2.55, -2.65, materials.timberLight);
for (const x of [7.35, 9.05]) {
addBox(house, 0.12, 0.9, 0.12, x, 1.6, -2.65, materials.timber);
}
for (let i = 0; i < 5; i++) {
addBox(
house,
0.25,
0.4,
0.24,
7.65 + i * 0.34,
2.25,
-2.62,
i % 2 ? materials.clay : materials.cream
);
}
// The left roof slope remains; most of the right slope is removed.
addQuad(
house,
[
[4.35, 3.85, -3.15],
[8.0, 5.35, -3.15],
[8.0, 5.35, 2.7],
[4.35, 3.85, 2.7]
],
materials.roof
);
addQuad(
house,
[
[8.0, 5.35, -3.15],
[11.65, 3.85, -3.15],
[11.65, 3.85, -1.78],
[8.0, 5.35, -1.78]
],
materials.roofDark
);
// Roof courses on the retained slope.
for (let z = -3.05; z <= 2.6; z += 0.48) {
addBeam(
house,
[4.38, 3.87, z],
[8.0, 5.37, z],
0.035,
0.035,
materials.roofDark
);
}
// Ridge and exposed rafters over the cutaway room.
addBox(house, 0.2, 0.2, 6.1, 8, 5.35, -0.2, materials.timber);
for (const z of [-0.9, 0.45, 1.8, 2.6]) {
addBeam(
house,
[8, 5.3, z],
[11.65, 3.85, z],
0.15,
0.15,
materials.timber
);
}
addBox(house, 7.4, 0.16, 0.18, 8, 3.86, 2.72, materials.timber);
// Ladder to the roof-side working area.
addBeam(
house,
[4.2, 0.15, 1.0],
[4.55, 3.85, -0.25],
0.09,
0.09,
materials.timberLight
);
addBeam(
house,
[4.75, 0.15, 1.0],
[5.1, 3.85, -0.25],
0.09,
0.09,
materials.timberLight
);
for (let i = 0; i < 8; i++) {
const t = (i + 0.5) / 8;
const x = 4.2 + t * 0.35;
const y = 0.15 + t * 3.7;
const z = 1.0 - t * 1.25;
addBeam(
house,
[x, y, z],
[x + 0.55, y, z],
0.07,
0.07,
materials.timberLight
);
}
// ---------------------------------------------------------------------
// Stylized workers
// ---------------------------------------------------------------------
const workers = [];
const coatColors = [
0x465d69, 0x765146, 0x5f664d, 0x574e63, 0x765b38, 0x425b52
];
function createWorker(x, z, direction, color, baseY = 0, scale = 1) {
const group = new THREE.Group();
group.position.set(x, baseY, z);
group.rotation.y = direction;
group.scale.setScalar(scale);
scene.add(group);
const coatMaterial = standard(color);
const trouserMaterial = standard(0x353b3b);
addBox(group, 0.19, 0.14, 0.38, -0.17, 0.1, 0.08, materials.black);
addBox(group, 0.19, 0.14, 0.38, 0.17, 0.1, 0.08, materials.black);
addCylinder(group, 0.12, 0.14, 0.72, -0.17, 0.52, 0, trouserMaterial, 8);
addCylinder(group, 0.12, 0.14, 0.72, 0.17, 0.52, 0, trouserMaterial, 8);
addCylinder(group, 0.29, 0.4, 0.88, 0, 1.13, 0, coatMaterial, 10);
addBox(group, 0.2, 0.55, 0.035, 0, 1.18, 0.31, materials.cream);
addCylinder(group, 0.12, 0.12, 0.11, 0, 1.63, 0, materials.skin, 10);
addSphere(group, 0.22, 0, 1.82, 0, materials.skin);
addSphere(group, 0.055, 0, 1.8, 0.205, materials.skin);
addCylinder(group, 0.23, 0.24, 0.12, 0, 2.01, 0, coatMaterial, 12);
addCylinder(group, 0.31, 0.31, 0.035, 0, 1.96, 0.02, coatMaterial, 12);
const armLeft = new THREE.Group();
const armRight = new THREE.Group();
armLeft.position.set(-0.31, 1.47, 0);
armRight.position.set(0.31, 1.47, 0);
group.add(armLeft, armRight);
addCylinder(armLeft, 0.075, 0.09, 0.53, 0, -0.24, 0, coatMaterial, 8);
addCylinder(armRight, 0.075, 0.09, 0.53, 0, -0.24, 0, coatMaterial, 8);
addSphere(armLeft, 0.09, 0, -0.52, 0, materials.skin);
addSphere(armRight, 0.09, 0, -0.52, 0, materials.skin);
const worker = {
group,
armLeft,
armRight,
lane: null,
stationX: x,
pulse: 0
};
workers.push(worker);
return worker;
}
const outboundStations = [-8.3, -5.8, -3.3, -0.8, 1.7, 4.0];
outboundStations.forEach((station, index) => {
createWorker(
station - 0.4,
-1.17,
Math.PI / 2,
coatColors[index % coatColors.length]
);
const worker = workers[workers.length - 1];
worker.lane = "full";
worker.stationX = station;
});
const returnStations = [4.0, 1.7, -0.8, -3.3, -5.8, -8.3];
returnStations.forEach((station, index) => {
createWorker(
station + 0.4,
2.22,
-Math.PI / 2,
coatColors[(index + 2) % coatColors.length]
);
const worker = workers[workers.length - 1];
worker.lane = "empty";
worker.stationX = station;
});
// Water-point attendant.
createWorker(-11.65, -1.28, Math.PI / 2, 0x465d69);
// A smaller roof attendant, standing on the sloping roof.
const roofY = (x) =>
3.85 + ((x - 4.35) / (8.0 - 4.35)) * (5.35 - 3.85);
createWorker(
6.65,
-1.55,
-Math.PI / 2,
0x765146,
roofY(6.65),
0.73
);
// ---------------------------------------------------------------------
// Small, non-graphic roof fire
// ---------------------------------------------------------------------
const flameMaterial = standard(0xf06a2d, 0.48);
const innerFlameMaterial = standard(0xffd05b, 0.38);
const flameGroup = new THREE.Group();
scene.add(flameGroup);
const flames = [];
for (let i = 0; i < 9; i++) {
const x = 5.05 + (i % 3) * 0.48 + Math.sin(i * 2.4) * 0.08;
const z = -2.25 + Math.floor(i / 3) * 0.72;
const y = roofY(x) + 0.08;
const flame = new THREE.Group();
flame.position.set(x, y, z);
flameGroup.add(flame);
const outer = addMesh(
new THREE.ConeGeometry(0.24 + (i % 2) * 0.055, 1.05, 7),
flameMaterial,
flame
);
outer.position.y = 0.48;
const inner = addMesh(
new THREE.ConeGeometry(0.12, 0.64, 7),
innerFlameMaterial,
flame
);
inner.position.y = 0.31;
flames.push({ flame, outer, inner, phase: i * 0.83 });
}
const smokeMaterial = new THREE.MeshBasicMaterial({
color: 0x8d9692,
transparent: true,
opacity: 0.13,
depthWrite: false
});
const smoke = [];
for (let i = 0; i < 8; i++) {
const puff = addMesh(
new THREE.SphereGeometry(0.3, 10, 7),
smokeMaterial.clone(),
scene
);
puff.castShadow = false;
puff.receiveShadow = false;
smoke.push({
puff,
x: 5.65 + (i % 3) * 0.18,
y: 5.15,
z: -1.9 + (i % 2) * 0.24,
offset: i / 8
});
}
const fireLight = new THREE.PointLight(0xff7b32, 17, 11, 2);
fireLight.position.set(5.65, 5.25, -1.65);
scene.add(fireLight);
const fireLabel = makeLabel("ROOF FIRE", "#b85a32", 3.5);
fireLabel.position.set(6.15, 6.65, -1.8);
scene.add(fireLabel);
// ---------------------------------------------------------------------
// Wooden buckets
// ---------------------------------------------------------------------
function createBucket() {
const group = new THREE.Group();
scene.add(group);
addCylinder(
group,
0.35,
0.27,
0.55,
0,
0.275,
0,
materials.bucketWood,
14
);
addCylinder(group, 0.26, 0.26, 0.035, 0, 0.05, 0, materials.bucketDark, 14);
for (const y of [0.12, 0.46]) {
const hoop = addMesh(
new THREE.TorusGeometry(y < 0.2 ? 0.278 : 0.337, 0.022, 6, 18),
materials.iron,
group
);
hoop.rotation.x = Math.PI / 2;
hoop.position.y = y;
}
const handle = addMesh(
new THREE.TorusGeometry(0.34, 0.024, 6, 18, Math.PI),
materials.iron,
group
);
handle.position.y = 0.53;
const water = addCylinder(
group,
0.303,
0.303,
0.022,
0,
0.44,
0,
materials.blueLight,
18
);
water.castShadow = false;
// Subtle stave seams.
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
const seam = addBox(
group,
0.018,
0.47,
0.018,
Math.cos(angle) * 0.31,
0.275,
Math.sin(angle) * 0.31,
materials.bucketDark
);
seam.rotation.y = -angle;
}
return {
group,
water,
wasFull: null,
phase: 0
};
}
const buckets = [];
for (let i = 0; i < 10; i++) {
buckets.push(createBucket());
}
// ---------------------------------------------------------------------
// Route keyframes and animation
// ---------------------------------------------------------------------
const sourcePoint = new THREE.Vector3(-10.35, 0.34, -0.6);
const roofPoint = new THREE.Vector3(5.72, 4.12, -1.25);
const outboundKeys = [
{ t: 0.00, p: sourcePoint },
{ t: 0.07, p: new THREE.Vector3(-8.3, 0.79, -0.6) },
{ t: 0.11, p: new THREE.Vector3(-8.3, 0.79, -0.6) },
{ t: 0.24, p: new THREE.Vector3(-5.8, 0.79, -0.6) },
{ t: 0.28, p: new THREE.Vector3(-5.8, 0.79, -0.6) },
{ t: 0.41, p: new THREE.Vector3(-3.3, 0.79, -0.6) },
{ t: 0.45, p: new THREE.Vector3(-3.3, 0.79, -0.6) },
{ t: 0.58, p: new THREE.Vector3(-0.8, 0.79, -0.6) },
{ t: 0.62, p: new THREE.Vector3(-0.8, 0.79, -0.6) },
{ t: 0.75, p: new THREE.Vector3(1.7, 0.79, -0.6) },
{ t: 0.79, p: new THREE.Vector3(1.7, 0.79, -0.6) },
{ t: 0.90, p: new THREE.Vector3(4.0, 0.79, -0.6) },
{ t: 0.94, p: new THREE.Vector3(4.0, 0.79, -0.6) },
{ t: 1.00, p: roofPoint }
];
const returnKeys = [
{ t: 0.00, p: roofPoint },
{ t: 0.08, p: new THREE.Vector3(4.0, 0.79, 1.65) },
{ t: 0.12, p: new THREE.Vector3(4.0, 0.79, 1.65) },
{ t: 0.24, p: new THREE.Vector3(1.7, 0.79, 1.65) },
{ t: 0.28, p: new THREE.Vector3(1.7, 0.79, 1.65) },
{ t: 0.40, p: new THREE.Vector3(-0.8, 0.79, 1.65) },
{ t: 0.44, p: new THREE.Vector3(-0.8, 0.79, 1.65) },
{ t: 0.56, p: new THREE.Vector3(-3.3, 0.79, 1.65) },
{ t: 0.60, p: new THREE.Vector3(-3.3, 0.79, 1.65) },
{ t: 0.72, p: new THREE.Vector3(-5.8, 0.79, 1.65) },
{ t: 0.76, p: new THREE.Vector3(-5.8, 0.79, 1.65) },
{ t: 0.88, p: new THREE.Vector3(-8.3, 0.79, 1.65) },
{ t: 0.92, p: new THREE.Vector3(-8.3, 0.79, 1.65) },
{ t: 1.00, p: sourcePoint }
];
function sampleKeys(keys, progress) {
progress = THREE.MathUtils.clamp(progress, 0, 1);
for (let i = 0; i < keys.length - 1; i++) {
const a = keys[i];
const b = keys[i + 1];
if (progress <= b.t) {
const span = b.t - a.t;
const raw = span > 0 ? (progress - a.t) / span : 1;
const eased = raw * raw * (3 - 2 * raw);
return a.p.clone().lerp(b.p, eased);
}
}
return keys[keys.length - 1].p.clone();
}
const FULL_DURATION = 11.2;
const EMPTY_DURATION = 9.4;
const REFILL_DURATION = 1.6;
const TOTAL_DURATION = FULL_DURATION + EMPTY_DURATION + REFILL_DURATION;
const droplets = [];
const dropletGeometry = new THREE.SphereGeometry(0.045, 6, 4);
const dropletMaterial = new THREE.MeshStandardMaterial({
color: 0x58c3d4,
roughness: 0.2,
metalness: 0.05,
transparent: true,
opacity: 0.9
});
function spawnSplash(position) {
for (let i = 0; i < 7; i++) {
const droplet = new THREE.Mesh(dropletGeometry, dropletMaterial);
droplet.position.copy(position);
droplet.position.y += 0.42;
droplet.position.x += (Math.random() - 0.5) * 0.3;
droplet.position.z += (Math.random() - 0.5) * 0.3;
scene.add(droplet);
droplets.push({
mesh: droplet,
velocity: new THREE.Vector3(
(Math.random() - 0.5) * 0.75,
0.65 + Math.random() * 0.65,
(Math.random() - 0.5) * 0.65
),
life: 0.8 + Math.random() * 0.35
});
}
}
const fullLabel = makeLabel("FILLED →", "#287f9d", 4.1);
fullLabel.position.set(-1.2, 0.8, -2.05);
scene.add(fullLabel);
const emptyLabel = makeLabel("← EMPTY", "#b66c45", 4.1);
emptyLabel.position.set(-1.2, 0.8, 2.85);
scene.add(emptyLabel);
let elapsed = 0;
let paused = false;
let previousTime = performance.now();
function updateBuckets(time, delta) {
for (let i = 0; i < buckets.length; i++) {
const bucket = buckets[i];
const offset = (i / buckets.length) * TOTAL_DURATION;
const cycle = (time + offset) % TOTAL_DURATION;
let position;
let isFull = false;
if (cycle < FULL_DURATION) {
position = sampleKeys(outboundKeys, cycle / FULL_DURATION);
isFull = true;
} else if (cycle < FULL_DURATION + EMPTY_DURATION) {
position = sampleKeys(
returnKeys,
(cycle - FULL_DURATION) / EMPTY_DURATION
);
} else {
position = sourcePoint.clone();
position.y = 0.3;
}
bucket.group.position.copy(position);
bucket.group.rotation.z =
Math.sin(time * 4.2 + i * 1.7) * 0.025;
bucket.group.rotation.y =
Math.sin(time * 2.1 + i) * 0.04;
if (isFull) {
bucket.water.visible = true;
bucket.water.scale.set(1, 1, 1);
} else if (cycle >= FULL_DURATION + EMPTY_DURATION) {
const fill = THREE.MathUtils.clamp(
(cycle - FULL_DURATION - EMPTY_DURATION) / REFILL_DURATION,
0,
1
);
bucket.water.visible = true;
bucket.water.scale.set(1, Math.max(0.001, fill), 1);
} else {
bucket.water.visible = false;
bucket.water.scale.set(1, 0.001, 1);
}
if (
bucket.wasFull === true &&
!isFull &&
cycle >= FULL_DURATION
) {
spawnSplash(position);
}
bucket.wasFull = isFull;
bucket.phase = cycle;
}
for (let i = droplets.length - 1; i >= 0; i--) {
const droplet = droplets[i];
droplet.life -= delta;
droplet.velocity.y -= 2.6 * delta;
droplet.mesh.position.addScaledVector(droplet.velocity, delta);
droplet.mesh.material.opacity = Math.max(0, droplet.life * 1.2);
if (droplet.life <= 0) {
scene.remove(droplet.mesh);
droplets.splice(i, 1);
}
}
}
function updateWorkers() {
for (const worker of workers) {
if (!worker.lane) {
worker.armLeft.rotation.x = 0.12;
worker.armRight.rotation.x = 0.12;
continue;
}
let pulse = 0;
for (const bucket of buckets) {
const isFull = bucket.phase < FULL_DURATION;
if ((worker.lane === "full") !== isFull) continue;
const xDistance = Math.abs(
bucket.group.position.x - worker.stationX
);
const yDistance = Math.abs(bucket.group.position.y - 0.79);
const zDistance = Math.abs(
bucket.group.position.z -
(worker.lane === "full" ? -0.6 : 1.65)
);
if (xDistance < 0.72 && yDistance < 0.5 && zDistance < 0.45) {
pulse = Math.max(pulse, 1 - xDistance / 0.72);
}
}
worker.pulse = pulse;
const flutter = Math.sin(elapsed * 10 + worker.stationX) * 0.025;
worker.armLeft.rotation.x = 0.12 - pulse * 1.2 + flutter;
worker.armRight.rotation.x = 0.12 - pulse * 1.08 - flutter;
worker.group.rotation.z = Math.sin(elapsed * 1.8) * 0.012;
}
}
function updateFire(time) {
for (const item of flames) {
const flicker =
1 +
Math.sin(time * 7.2 + item.phase) * 0.12 +
Math.sin(time * 11.4 + item.phase * 1.7) * 0.06;
item.flame.scale.set(
0.9 + Math.sin(time * 5 + item.phase) * 0.08,
flicker,
0.9 + Math.cos(time * 6 + item.phase) * 0.08
);
item.flame.rotation.y = time * 0.5 + item.phase;
item.inner.scale.y = 0.88 + flicker * 0.16;
}
for (const item of smoke) {
const progress = (time * 0.12 + item.offset) % 1;
item.puff.position.set(
item.x + Math.sin(progress * 5 + item.offset) * 0.42,
item.y + progress * 4.4,
item.z + progress * 0.48
);
const size = 0.55 + progress * 1.1;
item.puff.scale.setScalar(size);
item.puff.material.opacity = Math.sin(progress * Math.PI) * 0.14;
}
fireLight.intensity =
16 + Math.sin(time * 9.1) * 2.4 + Math.sin(time * 14.7) * 1.2;
}
// ---------------------------------------------------------------------
// Direct camera controls: orbit, pan, and wheel zoom
// ---------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 2.0, -0.2),
yaw: 0.64,
pitch: 0.43,
radius: 30
};
const defaultCamera = {
target: cameraState.target.clone(),
yaw: cameraState.yaw,
pitch: cameraState.pitch,
radius: cameraState.radius
};
function updateCamera() {
const { target, yaw, pitch, radius } = cameraState;
camera.position.set(
target.x + radius * Math.sin(yaw) * Math.cos(pitch),
target.y + radius * Math.sin(pitch),
target.z + radius * Math.cos(yaw) * Math.cos(pitch)
);
camera.lookAt(target);
}
let dragging = false;
let draggingButton = 0;
let previousPointerX = 0;
let previousPointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
draggingButton = event.button;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousPointerX;
const dy = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
const wantsPan = draggingButton === 2 || event.shiftKey;
if (wantsPan) {
const right = new THREE.Vector3();
const up = new THREE.Vector3();
camera.matrixWorld.extractBasis(right, up, new THREE.Vector3());
const panScale = cameraState.radius * 0.0014;
cameraState.target.addScaledVector(right, -dx * panScale);
cameraState.target.addScaledVector(up, dy * panScale);
} else {
cameraState.yaw -= dx * 0.005;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.004,
0.16,
1.02
);
}
updateCamera();
});
function stopDragging(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.018,
16,
48
);
updateCamera();
},
{ passive: false }
);
resetButton.addEventListener("click", () => {
cameraState.target.copy(defaultCamera.target);
cameraState.yaw = defaultCamera.yaw;
cameraState.pitch = defaultCamera.pitch;
cameraState.radius = defaultCamera.radius;
updateCamera();
});
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume motion" : "Pause motion";
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
pauseButton.click();
}
if (event.key.toLowerCase() === "r") {
resetButton.click();
}
});
window.addEventListener("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);
});
// ---------------------------------------------------------------------
// Render loop
// ---------------------------------------------------------------------
updateCamera();
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (!paused) {
elapsed += delta;
updateBuckets(elapsed, delta);
updateWorkers();
updateFire(elapsed);
}
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```