Prompt specification
Build or customize the Three.js 3D scene "Bucket and public water trough" 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 and public water trough
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/bucket-and-public-water-trough-x2357
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing an early modern town's bucket relay for firefighting. Place a wooden bucket beside a stone water trough and a short chain of carrying positions. Make the water source and transfer direction visually clear. Voxel style.
Working Three.js Starter (bucket-and-public-water-trough-x2357):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Early Modern Bucket Relay</title>
<style>
:root {
color-scheme: dark;
--ink: #f5ead3;
--panel: rgba(28, 25, 22, 0.86);
--water: #62c7df;
--gold: #f1b84b;
--fire: #ef6847;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #aeb9ad;
font-family: Georgia, "Times New Roman", serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 5;
color: var(--ink);
background: var(--panel);
border: 1px solid rgba(255, 232, 189, 0.22);
box-shadow: 0 10px 30px rgba(20, 16, 12, 0.24);
backdrop-filter: blur(8px);
}
#title {
top: 20px;
left: 20px;
max-width: min(430px, calc(100vw - 40px));
padding: 16px 19px 15px;
border-radius: 5px;
}
#title h1 {
margin: 0;
font-size: clamp(23px, 3vw, 34px);
line-height: 1;
letter-spacing: 0.035em;
text-transform: uppercase;
}
#title p {
margin: 8px 0 0;
color: #d7c8aa;
font-family: system-ui, sans-serif;
font-size: 12px;
letter-spacing: 0.11em;
text-transform: uppercase;
}
#controls {
top: 20px;
right: 20px;
padding: 11px 13px;
border-radius: 5px;
font-family: system-ui, sans-serif;
font-size: 12px;
line-height: 1.55;
}
#controls strong {
color: #fff1d1;
}
#reset {
display: block;
width: 100%;
margin-top: 9px;
padding: 8px 12px;
color: #f7e8ca;
background: #675233;
border: 1px solid #a88951;
border-radius: 3px;
font: 700 11px system-ui, sans-serif;
letter-spacing: 0.1em;
text-transform: uppercase;
cursor: pointer;
}
#reset:hover {
background: #7c623c;
}
#legend {
left: 50%;
bottom: 18px;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 17px;
padding: 11px 16px;
border-radius: 5px;
white-space: nowrap;
font-family: system-ui, sans-serif;
font-size: 12px;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 13px;
height: 13px;
display: inline-block;
border-radius: 2px;
box-shadow: inset 0 0 0 1px rgba(255,255,255,0.28);
}
.swatch.water {
background: var(--water);
}
.swatch.gold {
background: var(--gold);
}
.swatch.fire {
background: var(--fire);
}
.arrow-text {
color: var(--gold);
font-size: 18px;
line-height: 1;
}
@media (max-width: 720px) {
#title {
top: 10px;
left: 10px;
padding: 12px 14px;
}
#title p {
font-size: 10px;
}
#controls {
top: auto;
right: 10px;
bottom: 70px;
padding: 8px 10px;
font-size: 10px;
}
#controls .desktop-help {
display: none;
}
#reset {
margin-top: 6px;
}
#legend {
bottom: 10px;
width: calc(100vw - 20px);
justify-content: center;
gap: 10px;
padding: 9px 8px;
font-size: 10px;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive voxel scene of an early modern bucket relay"></div>
<section id="title" class="panel">
<h1>Bucket Relay</h1>
<p>Early modern town firefighting · fill, carry, pass</p>
</section>
<section id="controls" class="panel">
<div class="desktop-help">
<strong>Drag</strong> to orbit<br />
<strong>Shift-drag / right-drag</strong> to pan<br />
<strong>Wheel / pinch</strong> to zoom
</div>
<button id="reset" type="button">Reset View</button>
</section>
<section id="legend" class="panel" aria-label="Scene legend">
<span class="legend-item"><i class="swatch water"></i> Water source</span>
<span class="arrow-text">→</span>
<span class="legend-item"><i class="swatch gold"></i> Pass buckets</span>
<span class="arrow-text">→</span>
<span class="legend-item"><i class="swatch fire"></i> Fire</span>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const host = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({ antialias: true });
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.15;
host.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xaeb9ad);
scene.fog = new THREE.Fog(0xaeb9ad, 23, 42);
const camera = new THREE.OrthographicCamera(-10, 10, 7, -7, 0.1, 100);
const hemisphere = new THREE.HemisphereLight(0xdce9ee, 0x6c6048, 2.05);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffedcb, 3.1);
sun.position.set(-7, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -16;
sun.shadow.camera.right = 16;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 38;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fillLight = new THREE.DirectionalLight(0x91b8d0, 0.55);
fillLight.position.set(9, 7, -8);
scene.add(fillLight);
// -------------------------------------------------------------------------
// Materials and reusable geometry helpers
// -------------------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.9,
metalness: 0,
flatShading: true,
...options
});
const M = {
grass: material(0x7f8d67),
grassDark: material(0x687553),
soil: material(0x615b49),
cobbleBase: material(0x777267),
path: material(0x9b8968),
plaster: material(0xd9c7a3),
plasterWarm: material(0xc9ae87),
plasterPale: material(0xe1d3b5),
timber: material(0x4b3528),
timberLight: material(0x6b4931),
roof: material(0x8b4635),
roofDark: material(0x66352e),
stone: material(0x85857d),
stoneLight: material(0xa3a198),
stoneDark: material(0x656760),
wood: material(0xa76b35),
woodLight: material(0xc78a48),
woodDark: material(0x704321),
iron: material(0x3f4240, { metalness: 0.48, roughness: 0.58 }),
water: material(0x3ca9c6, {
transparent: true,
opacity: 0.88,
roughness: 0.28,
metalness: 0.04
}),
waterLight: material(0x83d9e7, {
transparent: true,
opacity: 0.76,
roughness: 0.3
}),
gold: material(0xf0b53e, {
emissive: 0x7a4b08,
emissiveIntensity: 0.22,
roughness: 0.65
}),
red: material(0xb94737),
orange: material(0xef7b2e),
yellow: material(0xffc544),
smoke: material(0x777b79, {
transparent: true,
opacity: 0.55,
depthWrite: false
}),
skin: material(0xc9956f),
black: material(0x252725),
white: material(0xf4e8cf)
};
const shadowCasters = [];
function box(w, h, d, mat, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(radiusTop, radiusBottom, height, mat, x, y, z, parent = scene, segments = 8) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function beam2D(a, b, thickness, depth, mat, parent, plane = "front") {
const dx = b.x - a.x;
const dy = b.y - a.y;
const length = Math.hypot(dx, dy);
const mesh = box(length, thickness, depth, mat, 0, 0, 0, parent);
mesh.position.x = (a.x + b.x) * 0.5;
mesh.position.y = (a.y + b.y) * 0.5;
mesh.rotation.z = Math.atan2(dy, dx);
return mesh;
}
function makeLabel(text, background = "#253d45", width = 2.4, number = false) {
const canvas = document.createElement("canvas");
const ctx = canvas.getContext("2d");
if (number) {
canvas.width = 96;
canvas.height = 96;
} else {
canvas.width = 512;
canvas.height = 112;
}
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (number) {
ctx.fillStyle = background;
ctx.beginPath();
ctx.arc(48, 48, 39, 0, Math.PI * 2);
ctx.fill();
ctx.strokeStyle = "rgba(255,255,255,0.7)";
ctx.lineWidth = 4;
ctx.stroke();
ctx.fillStyle = "#fff4db";
ctx.font = "bold 46px Georgia";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 48, 50);
} else {
ctx.fillStyle = "rgba(20,24,24,0.88)";
ctx.beginPath();
ctx.roundRect(4, 5, canvas.width - 8, canvas.height - 10, 16);
ctx.fill();
ctx.strokeStyle = background;
ctx.lineWidth = 7;
ctx.stroke();
ctx.fillStyle = "#fff3d8";
ctx.font = "bold 39px Georgia";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const spriteMaterial = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(spriteMaterial);
const height = number ? width : width * 112 / 512;
sprite.scale.set(width, height, 1);
sprite.renderOrder = 20;
return sprite;
}
// -------------------------------------------------------------------------
// Ground and cobbled town square
// -------------------------------------------------------------------------
box(32, 0.35, 25, M.grass, 0, -0.42, 0);
box(22.5, 0.20, 14.2, M.cobbleBase, -0.3, -0.12, 0.3);
const stoneGeometry = new THREE.BoxGeometry(0.62, 0.13, 0.54);
const cobbles = new THREE.InstancedMesh(stoneGeometry, material(0xffffff), 790);
cobbles.receiveShadow = true;
const dummy = new THREE.Object3D();
const color = new THREE.Color();
let stoneIndex = 0;
for (let z = 0; z < 23; z++) {
for (let x = 0; x < 34; x++) {
const rowOffset = z % 2 ? 0.31 : 0;
const px = -11.05 + x * 0.65 + rowOffset;
const pz = -6.25 + z * 0.58;
dummy.position.set(px, 0.005 + Math.random() * 0.035, pz);
dummy.rotation.y = (Math.random() - 0.5) * 0.035;
dummy.scale.set(
0.88 + Math.random() * 0.13,
0.8 + Math.random() * 0.25,
0.88 + Math.random() * 0.12
);
dummy.updateMatrix();
cobbles.setMatrixAt(stoneIndex, dummy.matrix);
const shade = 0.48 + Math.random() * 0.18;
color.setHSL(0.105, 0.075, shade);
cobbles.setColorAt(stoneIndex, color);
stoneIndex++;
}
}
cobbles.instanceMatrix.needsUpdate = true;
cobbles.instanceColor.needsUpdate = true;
scene.add(cobbles);
// A clear ochre carrying lane from the source to the fire.
box(14.6, 0.045, 1.65, M.path, -0.55, 0.085, 0.42);
box(14.65, 0.055, 0.10, M.stoneLight, -0.55, 0.105, -0.39);
box(14.65, 0.055, 0.10, M.stoneLight, -0.55, 0.105, 1.23);
// -------------------------------------------------------------------------
// Direction arrows, built from rectangular voxel-like pieces
// -------------------------------------------------------------------------
function directionArrow(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.14, z);
group.scale.setScalar(scale);
box(0.78, 0.045, 0.15, M.gold, -0.16, 0, 0, group);
// Stepped triangular head pointing toward +X.
box(0.17, 0.047, 0.16, M.gold, 0.48, 0, 0, group);
box(0.18, 0.047, 0.39, M.gold, 0.32, 0, 0, group);
box(0.19, 0.047, 0.61, M.gold, 0.15, 0, 0, group);
scene.add(group);
return group;
}
[-5.4, -3.0, -0.8, 1.3, 3.5, 4.65].forEach((x, index) => {
directionArrow(x, 0.42, index === 5 ? 0.9 : 0.82);
});
// -------------------------------------------------------------------------
// Wooden bucket
// -------------------------------------------------------------------------
function makeBucket(scale = 1) {
const group = new THREE.Group();
group.scale.setScalar(scale);
// Dark interior makes the hollow bucket read clearly.
box(0.47, 0.08, 0.47, M.woodDark, 0, 0.11, 0, group);
for (let level = 0; level < 3; level++) {
const width = 0.49 + level * 0.105;
const depth = 0.49 + level * 0.105;
const y = 0.19 + level * 0.205;
const plank = level === 1 ? M.woodLight : M.wood;
box(width, 0.185, 0.065, plank, 0, y, depth / 2, group);
box(width, 0.185, 0.065, plank, 0, y, -depth / 2, group);
box(0.065, 0.185, depth, plank, width / 2, y, 0, group);
box(0.065, 0.185, depth, plank, -width / 2, y, 0, group);
}
// Iron hoops.
for (const y of [0.22, 0.56]) {
const width = y < 0.3 ? 0.55 : 0.72;
box(width + 0.055, 0.055, 0.07, M.iron, 0, y, width / 2, group);
box(width + 0.055, 0.055, 0.07, M.iron, 0, y, -width / 2, group);
box(0.07, 0.055, width + 0.055, M.iron, width / 2, y, 0, group);
box(0.07, 0.055, width + 0.055, M.iron, -width / 2, y, 0, group);
}
// Angular wooden handle.
box(0.07, 0.39, 0.08, M.woodDark, -0.31, 0.86, 0, group);
box(0.07, 0.39, 0.08, M.woodDark, 0.31, 0.86, 0, group);
box(0.69, 0.08, 0.08, M.woodDark, 0, 1.055, 0, group);
box(0.10, 0.10, 0.12, M.iron, -0.31, 0.68, 0, group);
box(0.10, 0.10, 0.12, M.iron, 0.31, 0.68, 0, group);
scene.add(group);
return group;
}
// -------------------------------------------------------------------------
// Stone water trough and source
// -------------------------------------------------------------------------
const trough = new THREE.Group();
trough.position.set(-6.45, 0, 0.35);
scene.add(trough);
box(2.7, 0.30, 1.62, M.stoneDark, 0, 0.17, 0, trough);
// Individual stone blocks form the basin walls.
for (const z of [-0.70, 0.70]) {
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 4; col++) {
const stone = box(
0.61, 0.29, 0.28,
(row + col) % 3 === 0 ? M.stoneLight : M.stone,
-0.93 + col * 0.62,
0.43 + row * 0.28,
z,
trough
);
stone.rotation.y = ((col + row) % 2 ? 1 : -1) * 0.018;
}
}
}
for (const x of [-1.20, 1.20]) {
for (let row = 0; row < 2; row++) {
box(
0.29, 0.29, 1.12,
row ? M.stoneLight : M.stone,
x,
0.43 + row * 0.28,
0,
trough
);
}
}
box(2.05, 0.075, 1.05, M.water, 0, 0.64, 0, trough);
box(0.86, 0.018, 0.075, M.waterLight, -0.25, 0.687, -0.18, trough);
box(0.58, 0.018, 0.055, M.waterLight, 0.38, 0.687, 0.16, trough);
// A raised stone spring edge behind the trough emphasizes where water begins.
for (let i = 0; i < 5; i++) {
box(
0.43, 0.32, 0.38,
i % 2 ? M.stone : M.stoneLight,
-8.25 + i * 0.42,
0.25,
-0.75,
scene
);
}
box(1.75, 0.07, 0.28, M.water, -7.45, 0.43, -0.75);
// The required wooden bucket beside the trough.
const bucketBesideTrough = makeBucket(1.02);
bucketBesideTrough.position.set(-4.92, 0.06, 1.57);
bucketBesideTrough.rotation.y = -0.18;
const sourceLabel = makeLabel("WATER SOURCE", "#347f99", 2.55);
sourceLabel.position.set(-6.55, 2.55, 0.35);
scene.add(sourceLabel);
// -------------------------------------------------------------------------
// Half-timbered early modern town buildings
// -------------------------------------------------------------------------
function createBuilding(x, z, w, h, d, plasterMat, roofMat, detailed = true) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
box(w, h, d, plasterMat, 0, h / 2, 0, group);
// Corner posts and horizontal beams.
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
box(
0.19, h + 0.08, 0.19,
M.timber,
sx * (w / 2 - 0.04),
h / 2,
sz * (d / 2 - 0.02),
group
);
}
}
for (const y of [0.22, h * 0.52, h - 0.12]) {
box(w + 0.05, 0.16, 0.16, M.timber, 0, y, d / 2 + 0.015, group);
box(w + 0.05, 0.16, 0.16, M.timber, 0, y, -d / 2 - 0.015, group);
box(0.16, 0.16, d + 0.05, M.timber, w / 2 + 0.015, y, 0, group);
box(0.16, 0.16, d + 0.05, M.timber, -w / 2 - 0.015, y, 0, group);
}
if (detailed) {
// Diagonal half-timbering on the front.
beam2D(
{ x: -w * 0.36, y: 0.35 },
{ x: -w * 0.03, y: h * 0.47 },
0.15, 0.12, M.timber, group
);
beam2D(
{ x: w * 0.36, y: 0.35 },
{ x: w * 0.04, y: h * 0.47 },
0.15, 0.12, M.timber, group
);
beam2D(
{ x: -w * 0.30, y: h * 0.56 },
{ x: w * 0.28, y: h - 0.22 },
0.14, 0.12, M.timber, group
);
}
// Stepped voxel roof.
for (let i = 0; i < 5; i++) {
box(
w + 0.85 - i * 0.16,
0.18,
d + 0.72 - i * 0.13,
i % 2 ? roofMat : M.roofDark,
0,
h + 0.11 + i * 0.17,
0,
group
);
}
// Door and windows.
box(0.72, 1.35, 0.09, M.timber, -w * 0.22, 0.70, d / 2 + 0.06, group);
box(0.62, 0.69, 0.08, M.woodDark, -w * 0.22, 1.15, d / 2 + 0.115, group);
for (const wx of [-w * 0.28, w * 0.29]) {
box(0.63, 0.64, 0.09, M.timber, wx, h * 0.63, d / 2 + 0.065, group);
box(0.48, 0.49, 0.10, M.waterLight, wx, h * 0.63, d / 2 + 0.12, group);
box(0.055, 0.52, 0.12, M.timber, wx, h * 0.63, d / 2 + 0.14, group);
box(0.52, 0.055, 0.12, M.timber, wx, h * 0.63, d / 2 + 0.14, group);
}
// Chimney.
box(0.48, 1.35, 0.50, M.stoneDark, w * 0.27, h + 0.75, -d * 0.18, group);
box(0.62, 0.18, 0.62, M.stone, w * 0.27, h + 1.43, -d * 0.18, group);
return group;
}
createBuilding(-4.3, -5.65, 3.5, 2.65, 2.35, M.plaster, M.roof, true);
createBuilding(0.15, -6.0, 4.1, 3.0, 2.55, M.plasterWarm, M.roofDark, true);
createBuilding(4.8, -5.55, 3.4, 2.55, 2.3, M.plasterPale, M.roof, true);
createBuilding(-9.0, -4.9, 2.7, 2.25, 2.1, M.plasterWarm, M.roofDark, false);
const fireBuilding = createBuilding(
6.15, -1.40, 2.8, 2.75, 2.35,
M.plasterWarm, M.roofDark, true
);
// -------------------------------------------------------------------------
// Carrying positions and period-dress figures
// -------------------------------------------------------------------------
const carrierColors = [
material(0x8a4639),
material(0x526d78),
material(0x776443),
material(0x624f6e)
];
function makeCarrier(x, z, coat, index) {
const group = new THREE.Group();
group.position.set(x, 0.10, z);
group.rotation.y = 0.12;
scene.add(group);
// Shoes and legs.
box(0.25, 0.18, 0.27, M.black, -0.14, 0.09, 0.10, group);
box(0.25, 0.18, 0.27, M.black, -0.14, 0.09, -0.12, group);
box(0.18, 0.47, 0.20, M.black, -0.14, 0.40, 0.10, group);
box(0.18, 0.47, 0.20, M.black, -0.14, 0.40, -0.12, group);
// Coat, belt, collar.
box(0.56, 0.72, 0.47, coat, 0, 1.00, 0, group);
box(0.59, 0.08, 0.49, M.timber, 0, 0.76, 0, group);
box(0.39, 0.12, 0.40, M.plasterPale, 0, 1.40, 0, group);
// Head, nose, hat.
box(0.35, 0.36, 0.35, M.skin, 0.03, 1.60, 0, group);
box(0.12, 0.11, 0.13, M.skin, 0.25, 1.59, 0, group);
box(0.53, 0.07, 0.49, M.timber, 0.02, 1.80, 0, group);
box(0.34, 0.23, 0.32, M.timberDark ?? M.timber, 0.01, 1.93, 0, group);
// Arms extend toward the next carrier.
const armA = box(0.58, 0.17, 0.17, coat, 0.35, 1.20, 0.12, group);
const armB = box(0.55, 0.17, 0.17, coat, 0.34, 1.04, -0.12, group);
armA.rotation.z = -0.12;
armB.rotation.z = 0.17;
// Small held bucket.
const heldBucket = makeBucket(0.58);
heldBucket.position.set(0.68, 0.72, 0);
heldBucket.rotation.y = Math.PI / 2;
// Pale stone pads mark each carrying position.
for (const dz of [-0.38, 0.38]) {
box(0.95, 0.075, 0.48, M.stoneLight, 0, 0.02, dz, group);
}
const number = makeLabel(String(index), "#8b6534", 0.46, true);
number.position.set(x, 2.45, z);
scene.add(number);
return group;
}
const stationXs = [-3.75, -1.75, 0.25, 2.25];
stationXs.forEach((x, i) => {
makeCarrier(x, 1.28, carrierColors[i], i + 1);
});
const relayLabel = makeLabel("BUCKET RELAY", "#a1712f", 2.25);
relayLabel.position.set(-0.75, 3.45, 1.25);
scene.add(relayLabel);
// -------------------------------------------------------------------------
// Fire at the receiving end
// -------------------------------------------------------------------------
const fire = new THREE.Group();
fire.position.set(6.0, 0.1, 0.43);
scene.add(fire);
box(1.45, 0.24, 0.92, M.stoneDark, 0, 0.12, 0, fire);
box(1.16, 0.16, 0.67, M.woodDark, 0, 0.28, 0, fire);
const flameMeshes = [];
for (let i = 0; i < 11; i++) {
const flameMat = i % 3 === 0 ? M.yellow : (i % 2 ? M.orange : M.red);
const flame = box(
0.28 + Math.random() * 0.23,
0.55 + Math.random() * 0.82,
0.28 + Math.random() * 0.23,
flameMat,
(Math.random() - 0.5) * 0.82,
0.55 + Math.random() * 0.42,
(Math.random() - 0.5) * 0.38,
fire
);
flame.userData.baseY = flame.position.y;
flame.userData.phase = Math.random() * Math.PI * 2;
flame.userData.baseScaleY = flame.scale.y;
flameMeshes.push(flame);
}
const smokeMeshes = [];
for (let i = 0; i < 6; i++) {
const smoke = box(
0.48 + i * 0.035,
0.48 + i * 0.035,
0.48 + i * 0.035,
M.smoke,
6.0 + i * 0.10,
2.1 + i * 0.52,
0.25 - i * 0.045,
scene
);
smoke.castShadow = false;
smoke.userData.offset = i * 0.52;
smokeMeshes.push(smoke);
}
const fireLabel = makeLabel("TO THE FIRE", "#a63e2f", 2.35);
fireLabel.position.set(6.0, 3.55, 0.35);
scene.add(fireLabel);
// -------------------------------------------------------------------------
// Animated bucket showing the handoff direction
// -------------------------------------------------------------------------
const movingBucket = makeBucket(0.68);
const relayCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-4.85, 1.03, 1.48),
new THREE.Vector3(-3.75, 1.08, 1.28),
new THREE.Vector3(-1.75, 1.08, 1.28),
new THREE.Vector3(0.25, 1.08, 1.28),
new THREE.Vector3(2.25, 1.08, 1.28),
new THREE.Vector3(4.40, 0.92, 0.76),
new THREE.Vector3(5.50, 0.90, 0.45)
]);
// A gold square follows the moving bucket as a position indicator.
const handoffMarker = new THREE.Group();
box(0.84, 0.035, 0.055, M.gold, 0, 0, -0.39, handoffMarker);
box(0.84, 0.035, 0.055, M.gold, 0, 0, 0.39, handoffMarker);
box(0.055, 0.035, 0.72, M.gold, -0.39, 0, 0, handoffMarker);
box(0.055, 0.035, 0.72, M.gold, 0.39, 0, 0, handoffMarker);
scene.add(handoffMarker);
// -------------------------------------------------------------------------
// Simple voxel trees and props
// -------------------------------------------------------------------------
function makeTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
box(0.55, 2.4, 0.55, M.woodDark, 0, 1.15, 0, group);
box(2.0, 1.2, 1.8, M.grassDark, 0, 2.55, 0, group);
box(1.55, 1.0, 1.55, material(0x71845d), 0.22, 3.25, 0.08, group);
box(1.25, 0.85, 1.35, material(0x82936a), -0.35, 3.85, -0.12, group);
}
makeTree(-10.0, 4.2, 1.15);
makeTree(9.2, 4.7, 1.0);
makeTree(1.7, 5.8, 0.78);
// Wooden sign at the source.
box(0.17, 1.55, 0.17, M.woodDark, -8.65, 0.76, 1.75);
box(1.55, 0.52, 0.16, M.wood, -8.20, 1.32, 1.75);
const signLabel = makeLabel("FILL", "#347f99", 1.15);
signLabel.position.set(-8.20, 1.34, 1.87);
scene.add(signLabel);
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, reset
// -------------------------------------------------------------------------
const view = {
target: new THREE.Vector3(-0.55, 0.65, 0.25),
yaw: 0.48,
pitch: 0.67,
radius: 19.2
};
const initialView = {
target: view.target.clone(),
yaw: view.yaw,
pitch: view.pitch,
radius: view.radius
};
function updateCamera() {
const cp = Math.cos(view.pitch);
camera.position.set(
view.target.x + view.radius * Math.sin(view.yaw) * cp,
view.target.y + view.radius * Math.sin(view.pitch),
view.target.z + view.radius * Math.cos(view.yaw) * cp
);
camera.lookAt(view.target);
camera.updateProjectionMatrix();
}
function resetView() {
view.target.copy(initialView.target);
view.yaw = initialView.yaw;
view.pitch = initialView.pitch;
view.radius = initialView.radius;
updateCamera();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(10.8, 19.4 / aspect);
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
document.getElementById("reset").addEventListener("click", resetView);
const canvas = renderer.domElement;
const pointers = new Map();
let previous = null;
let previousPinchDistance = 0;
let panMode = false;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
previous = { x: event.clientX, y: event.clientY };
panMode = event.button === 2 || event.shiftKey;
if (pointers.size === 2) {
previousPinchDistance = pointerDistance();
}
});
canvas.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
const distance = pointerDistance();
if (previousPinchDistance > 0 && distance > 0) {
view.radius = THREE.MathUtils.clamp(
view.radius * previousPinchDistance / distance,
9,
29
);
updateCamera();
}
previousPinchDistance = distance;
return;
}
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
previous = { x: event.clientX, y: event.clientY };
if (panMode) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3(
-forward.z,
0,
forward.x
);
const scale = (view.radius / renderer.domElement.clientHeight) * 1.35;
view.target.addScaledVector(right, -dx * scale);
view.target.addScaledVector(forward, -dy * scale);
} else {
view.yaw -= dx * 0.0055;
view.pitch = THREE.MathUtils.clamp(
view.pitch + dy * 0.0045,
0.28,
1.30
);
}
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
previous = null;
panMode = false;
previousPinchDistance = pointers.size === 2 ? pointerDistance() : 0;
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("pointerleave", event => {
if (!pointers.has(event.pointerId)) return;
endPointer(event);
});
canvas.addEventListener("wheel", event => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius * Math.exp(event.deltaY * 0.001),
9,
29
);
updateCamera();
}, { passive: false });
canvas.addEventListener("dblclick", resetView);
resize();
updateCamera();
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
// Moving relay bucket.
const cycle = (elapsed % 10) / 10;
const eased = cycle < 0.08
? THREE.MathUtils.smoothstep(cycle, 0, 0.08)
: (cycle > 0.94
? 1 - THREE.MathUtils.smoothstep(cycle, 0.94, 1)
: 1);
const pathT = THREE.MathUtils.clamp(eased, 0, 1);
const bucketPosition = relayCurve.getPointAt(pathT);
movingBucket.position.copy(bucketPosition);
movingBucket.position.y += Math.sin(elapsed * 5.0) * 0.025;
movingBucket.rotation.y = Math.PI / 2 + Math.sin(elapsed * 3.0) * 0.08;
handoffMarker.position.set(
bucketPosition.x,
0.18,
bucketPosition.z
);
// Flame flicker.
flameMeshes.forEach((flame, index) => {
const pulse = 1 + Math.sin(elapsed * 8 + flame.userData.phase) * 0.18;
flame.scale.y = pulse;
flame.position.y =
flame.userData.baseY +
Math.sin(elapsed * 5.5 + flame.userData.phase) * 0.075;
flame.rotation.z = Math.sin(elapsed * 4 + index) * 0.045;
});
// Rising smoke blocks.
smokeMeshes.forEach((smoke, index) => {
const localTime = (elapsed * 0.34 + smoke.userData.offset) % 3.6;
smoke.position.y = 1.65 + localTime;
smoke.position.x = 6.0 + localTime * 0.13 + Math.sin(elapsed + index) * 0.06;
smoke.position.z = 0.28 - localTime * 0.055;
const fade = Math.max(0, 1 - localTime / 3.6);
smoke.material.opacity = 0.50 * fade;
smoke.scale.setScalar(0.8 + localTime * 0.10);
});
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```