Prompt specification
Build or customize the Three.js 3D scene "Community garden volunteer changeover" 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: Community garden volunteer changeover
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/community-garden-volunteer-changeover-x3867
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: community garden volunteer changeover. Build garden beds, tool shed, noticeboard, and seating; an outgoing volunteer hands over tasks and tools before new helpers begin their assigned activities. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (community-garden-volunteer-changeover-x3867):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Community Garden Volunteer Changeover</title>
<style>
:root {
color-scheme: light;
--ink: #18372f;
--muted: #60756e;
--panel: rgba(250, 249, 240, 0.92);
--line: rgba(24, 55, 47, 0.16);
--green: #3e7656;
--orange: #d8793f;
--blue: #447d9d;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9d9d2;
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
color: var(--ink);
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.panel {
background: var(--panel);
border: 1px solid var(--line);
box-shadow: 0 12px 32px rgba(26, 58, 49, 0.16);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#title-card {
position: fixed;
top: 18px;
left: 18px;
width: min(410px, calc(100vw - 36px));
padding: 15px 17px 14px;
border-radius: 14px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 5px;
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(17px, 2.3vw, 24px);
line-height: 1.15;
letter-spacing: -0.04em;
}
#subtitle {
margin-top: 8px;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
#status-panel {
position: fixed;
top: 18px;
right: 18px;
max-width: min(350px, calc(100vw - 36px));
padding: 11px 14px;
border-radius: 12px;
pointer-events: none;
}
#status-label {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
#status-text {
margin-top: 5px;
font-size: 12px;
font-weight: 700;
line-height: 1.4;
}
#timeline-panel {
position: fixed;
left: 50%;
bottom: 18px;
width: min(760px, calc(100vw - 36px));
transform: translateX(-50%);
padding: 12px 14px 11px;
border-radius: 14px;
}
.timeline-row {
display: grid;
grid-template-columns: auto 1fr auto;
align-items: center;
gap: 12px;
}
button {
border: 1px solid var(--line);
border-radius: 9px;
background: #fffdf4;
color: var(--ink);
font: inherit;
cursor: pointer;
transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}
button:hover {
transform: translateY(-1px);
border-color: rgba(24, 55, 47, 0.35);
}
button:active { transform: translateY(0); }
#play {
width: 42px;
height: 34px;
padding: 0;
font-size: 14px;
font-weight: 900;
}
#timeline {
width: 100%;
height: 6px;
margin: 0;
appearance: none;
-webkit-appearance: none;
border-radius: 99px;
background:
linear-gradient(90deg,
var(--green) 0%,
var(--green) 33.333%,
var(--orange) 33.333%,
var(--orange) 66.666%,
var(--blue) 66.666%,
var(--blue) 100%);
cursor: pointer;
outline: none;
}
#timeline::-webkit-slider-thumb {
width: 17px;
height: 17px;
appearance: none;
-webkit-appearance: none;
border: 3px solid #fffdf4;
border-radius: 50%;
background: var(--ink);
box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
#timeline::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid #fffdf4;
border-radius: 50%;
background: var(--ink);
}
#time {
min-width: 48px;
color: var(--muted);
font-size: 11px;
text-align: right;
}
.phase-buttons {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 10px;
}
.phase-buttons button {
padding: 7px 8px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: .04em;
}
.phase-buttons button.active {
border-color: var(--green);
background: #e5efe4;
color: var(--green);
}
#view-controls {
position: fixed;
right: 18px;
bottom: 104px;
display: flex;
gap: 6px;
}
#view-controls button {
width: 36px;
height: 34px;
padding: 0;
font-size: 15px;
font-weight: 900;
box-shadow: 0 7px 20px rgba(26, 58, 49, 0.12);
}
#help {
position: fixed;
left: 18px;
bottom: 102px;
padding: 8px 10px;
border-radius: 9px;
color: var(--muted);
font-size: 9px;
line-height: 1.45;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
display: grid;
place-items: center;
background: #b9d9d2;
color: var(--ink);
font-size: 13px;
font-weight: 800;
letter-spacing: .08em;
text-transform: uppercase;
z-index: 20;
}
@media (max-width: 700px) {
#title-card { top: 10px; left: 10px; width: calc(100vw - 20px); }
#status-panel { top: auto; right: 10px; bottom: 111px; max-width: 220px; }
#timeline-panel { bottom: 10px; width: calc(100vw - 20px); }
#help { display: none; }
#view-controls { right: 10px; bottom: 160px; }
#subtitle { font-size: 10px; }
}
</style>
</head>
<body>
<div id="loading">Building the community garden…</div>
<section id="title-card" class="panel">
<div class="eyebrow">Neighborhood Garden · Shift 02</div>
<h1>Volunteer Changeover</h1>
<div id="subtitle">One gardener closes the shift. The next team receives the task list, tools, and encouragement.</div>
</section>
<section id="status-panel" class="panel">
<div id="status-label">Current moment</div>
<div id="status-text">Preparing tools</div>
</section>
<div id="help" class="panel">Drag to orbit · Wheel to zoom · Space to pause</div>
<div id="view-controls">
<button id="zoom-out" title="Zoom out" aria-label="Zoom out">−</button>
<button id="zoom-in" title="Zoom in" aria-label="Zoom in">+</button>
<button id="reset-view" title="Reset camera" aria-label="Reset camera">⌂</button>
</div>
<section id="timeline-panel" class="panel">
<div class="timeline-row">
<button id="play" aria-label="Pause animation">Ⅱ</button>
<input id="timeline" type="range" min="0" max="30" step="0.01" value="0" aria-label="Changeover timeline">
<div id="time">00:00</div>
</div>
<div class="phase-buttons">
<button data-time="2" class="active">1 · Prepare</button>
<button data-time="11">2 · Hand over</button>
<button data-time="28">3 · New shift</button>
</div>
</section>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
// -------------------------------------------------------------------------
// Scene and renderer
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb9d9d2);
scene.fog = new THREE.Fog(0xb9d9d2, 30, 58);
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.08;
document.body.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(38, window.innerWidth / window.innerHeight, 0.1, 100);
const hemisphere = new THREE.HemisphereLight(0xeaf8ef, 0x667552, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1cb, 3.0);
sun.position.set(-9, 17, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -20;
sun.shadow.camera.right = 20;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 50;
sun.shadow.bias = -0.00045;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9dc9d3, 0.65);
fill.position.set(12, 8, -10);
scene.add(fill);
// -------------------------------------------------------------------------
// Small voxel construction helpers
// -------------------------------------------------------------------------
const materialCache = new Map();
function material(color) {
if (color && color.isMaterial) return color;
if (!materialCache.has(color)) {
materialCache.set(color, new THREE.MeshStandardMaterial({
color,
roughness: 0.94,
metalness: 0
}));
}
return materialCache.get(color);
}
function box(parent, w, h, d, x, y, z, color, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function group(parent, x = 0, y = 0, z = 0) {
const g = new THREE.Group();
g.position.set(x, y, z);
parent.add(g);
return g;
}
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function makeSprite(text, {
width = 3.4,
background = '#203d35',
foreground = '#fffdf2',
border = null,
fontSize = 34
} = {}) {
const canvas = document.createElement('canvas');
canvas.width = 768;
canvas.height = 160;
const ctx = canvas.getContext('2d');
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const mat = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(mat);
sprite.scale.set(width, width * 160 / 768, 1);
sprite.renderOrder = 20;
sprite.userData.setText = (value, bg = background, fg = foreground, fs = fontSize) => {
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 8, 10, canvas.width - 16, canvas.height - 20, 24);
ctx.fillStyle = bg;
ctx.fill();
if (border) {
ctx.strokeStyle = border;
ctx.lineWidth = 7;
ctx.stroke();
}
ctx.fillStyle = fg;
ctx.font = `800 ${fs}px ui-monospace, monospace`;
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(value, canvas.width / 2, canvas.height / 2 + 2, canvas.width - 50);
texture.needsUpdate = true;
};
sprite.userData.setText(text);
return sprite;
}
function makeTextPlane(text, width, height, {
background = '#28483d',
foreground = '#fff9e8',
subtitle = ''
} = {}) {
const canvas = document.createElement('canvas');
canvas.width = 1024;
canvas.height = 512;
const ctx = canvas.getContext('2d');
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = 'rgba(255,255,255,.16)';
ctx.lineWidth = 12;
ctx.strokeRect(18, 18, canvas.width - 36, canvas.height - 36);
ctx.fillStyle = foreground;
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.font = '900 76px ui-monospace, monospace';
ctx.fillText(text, 512, subtitle ? 205 : 256, 940);
if (subtitle) {
ctx.font = '700 42px ui-monospace, monospace';
ctx.fillText(subtitle, 512, 335, 900);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({ map: texture })
);
return mesh;
}
function clamp01(v) { return Math.max(0, Math.min(1, v)); }
function ease(v) { v = clamp01(v); return v * v * (3 - 2 * v); }
function lerp(a, b, t) { return THREE.MathUtils.lerp(a, b, t); }
function segment(t, a, b) { return clamp01((t - a) / (b - a)); }
// -------------------------------------------------------------------------
// Garden landscape
// -------------------------------------------------------------------------
const garden = group(scene);
box(garden, 26, 0.65, 18, 0, -0.37, 0, '#61784e', false);
box(garden, 25.7, 0.09, 17.7, 0, -0.005, 0, '#6f8756', false);
// Winding gravel paths.
box(garden, 21.5, 0.08, 2.0, 0.5, 0.055, 1.55, '#c9bb91', false);
box(garden, 2.0, 0.08, 8.0, -7.0, 0.06, -1.0, '#c9bb91', false);
box(garden, 2.0, 0.08, 7.0, 9.7, 0.06, 1.5, '#c9bb91', false);
box(garden, 1.8, 0.08, 6.0, 3.6, 0.06, -1.3, '#c9bb91', false);
box(garden, 1.7, 0.08, 4.2, 0, 0.06, 4.7, '#c9bb91', false);
// A few individual path stones.
for (let i = 0; i < 10; i++) {
box(garden, 0.8, 0.09, 0.48, -6.3 + i * 1.55, 0.11, 1.45 + (i % 2) * 0.28, '#d9cca5', false);
}
// Rear and side fence.
for (let x = -12; x <= 12; x += 2) {
box(garden, 0.18, 1.45, 0.18, x, 0.72, -8.55, '#8a6c45');
}
box(garden, 25, 0.16, 0.16, 0, 0.68, -8.55, '#a98757');
box(garden, 25, 0.16, 0.16, 0, 1.24, -8.55, '#a98757');
for (const x of [-12.6, 12.6]) {
for (let z = -6.5; z <= 7; z += 2.3) {
box(garden, 0.18, 1.45, 0.18, x, 0.72, z, '#8a6c45');
}
box(garden, 0.16, 0.16, 16, x, 0.68, 0, '#a98757');
box(garden, 0.16, 0.16, 16, x, 1.24, 0, '#a98757');
}
// Voxel trees.
function makeTree(x, z, scale = 1) {
const tree = group(garden, x, 0, z);
tree.scale.setScalar(scale);
box(tree, 0.65, 2.8, 0.65, 0, 1.4, 0, '#795b3f');
box(tree, 2.4, 1.5, 2.4, 0, 3.05, 0, '#477b45');
box(tree, 1.8, 1.25, 1.8, -0.45, 4.05, 0.1, '#5b914c');
box(tree, 1.65, 1.1, 1.65, 0.8, 3.65, -0.35, '#386e40');
}
makeTree(-11.0, 6.4, 0.9);
makeTree(11.0, -6.8, 0.95);
makeTree(-11.1, -6.9, 0.72);
// Raised garden beds.
const plantGroups = [];
function makePlant(x, y, z, parent, variant = 0) {
const p = group(parent, x, y, z);
box(p, 0.13, 0.55, 0.13, 0, 0.28, 0, '#397344');
if (variant % 3 === 0) {
box(p, 0.55, 0.4, 0.55, 0, 0.58, 0, '#73a84d');
box(p, 0.35, 0.35, 0.35, 0.15, 0.82, 0.06, '#8fbd55');
} else if (variant % 3 === 1) {
box(p, 0.72, 0.2, 0.28, 0, 0.52, 0, '#4e9147');
box(p, 0.28, 0.2, 0.68, 0, 0.7, 0, '#6ca64d');
} else {
box(p, 0.35, 0.48, 0.38, 0, 0.62, 0, '#9c7846');
box(p, 0.42, 0.15, 0.42, 0, 0.9, 0, '#d7b064');
}
p.userData.phase = variant * 0.71;
plantGroups.push(p);
return p;
}
function makeBed(cx, cz, w, d, cropOffset = 0) {
const bed = group(garden, cx, 0, cz);
box(bed, w, 0.35, d, 0, 0.18, 0, '#654734');
const border = 0.22;
box(bed, w + border, 0.42, border, 0, 0.25, -d / 2, '#9b7449');
box(bed, w + border, 0.42, border, 0, 0.25, d / 2, '#9b7449');
box(bed, border, 0.42, d, -w / 2, 0.25, 0, '#9b7449');
box(bed, border, 0.42, d, w / 2, 0.25, 0, '#9b7449');
let index = cropOffset;
for (let row = 0; row < 3; row++) {
for (let col = 0; col < 6; col++) {
if ((row === 1 && col === 4) || (row === 2 && col === 1)) continue;
const x = -w / 2 + 0.62 + col * ((w - 1.2) / 5);
const z = -d / 2 + 0.72 + row * ((d - 1.4) / 2);
makePlant(x, 0.36, z, bed, index++);
}
}
return bed;
}
makeBed(4.0, -2.0, 5.0, 3.7, 0);
makeBed(6.5, 4.0, 5.0, 3.7, 4);
// Tool shed.
const shed = group(garden, -8, 0, -4.8);
box(shed, 4.8, 0.18, 3.9, 0, 0.09, 0, '#a89169');
box(shed, 4.4, 3.0, 0.22, 0, 1.6, -1.78, '#4f7656');
box(shed, 0.22, 3.0, 3.6, -2.1, 1.6, 0, '#507c58');
box(shed, 0.22, 3.0, 3.6, 2.1, 1.6, 0, '#5b875e');
box(shed, 5.0, 0.35, 4.25, 0, 3.28, 0, '#385f49');
box(shed, 4.5, 0.28, 0.28, 0, 2.78, 1.75, '#426b50');
box(shed, 0.28, 2.9, 0.28, -2.03, 1.5, 1.75, '#6f8c5e');
box(shed, 0.28, 2.9, 0.28, 2.03, 1.5, 1.75, '#6f8c5e');
// Workbench and hanging tools inside the shed.
box(shed, 2.4, 0.18, 0.85, 0, 1.05, 0.55, '#9d7146');
box(shed, 0.18, 0.9, 0.65, -0.9, 0.55, 0.55, '#73513a');
box(shed, 0.18, 0.9, 0.65, 0.9, 0.55, 0.55, '#73513a');
box(shed, 0.12, 1.0, 0.12, -0.75, 1.75, -1.58, '#bb8a52');
box(shed, 0.42, 0.55, 0.12, -0.75, 1.25, -1.57, '#71818a');
box(shed, 0.12, 0.95, 0.12, 0.05, 1.8, -1.57, '#c39b61');
box(shed, 0.28, 0.35, 0.12, 0.05, 1.25, -1.56, '#b66a43');
const shedSign = makeTextPlane('TOOL SHED', 2.1, 0.82, {
background: '#355846',
foreground: '#fff1c8'
});
shedSign.position.set(0, 2.68, 1.91);
shed.add(shedSign);
// Noticeboard.
const noticeboard = group(garden, -2.8, 0, -6.7);
box(noticeboard, 0.2, 3.0, 0.2, -1.45, 1.5, 0, '#745339');
box(noticeboard, 0.2, 3.0, 0.2, 1.45, 1.5, 0, '#745339');
box(noticeboard, 3.7, 2.3, 0.28, 0, 2.15, 0, '#815d3c');
const taskBoard = document.createElement('canvas');
taskBoard.width = 1024;
taskBoard.height = 640;
const taskCtx = taskBoard.getContext('2d');
taskCtx.fillStyle = '#d8c89a';
taskCtx.fillRect(0, 0, 1024, 640);
taskCtx.fillStyle = '#2d4c3f';
taskCtx.font = '900 67px ui-monospace, monospace';
taskCtx.textAlign = 'center';
taskCtx.fillText("TODAY'S TASKS", 512, 92);
taskCtx.textAlign = 'left';
taskCtx.font = '800 46px ui-monospace, monospace';
taskCtx.fillStyle = '#487b50';
taskCtx.fillText('■ PLANT ROWS', 105, 245);
taskCtx.fillStyle = '#477d9d';
taskCtx.fillText('■ WATER BEDS', 105, 375);
taskCtx.fillStyle = '#b46b3d';
taskCtx.fillText('■ TURN COMPOST', 105, 505);
const taskTexture = new THREE.CanvasTexture(taskBoard);
taskTexture.colorSpace = THREE.SRGBColorSpace;
const taskPlane = new THREE.Mesh(
new THREE.PlaneGeometry(3.15, 1.85),
new THREE.MeshBasicMaterial({ map: taskTexture })
);
taskPlane.position.set(0, 2.15, 0.151);
noticeboard.add(taskPlane);
const noticeLabel = makeSprite('NOTICE BOARD', {
width: 3.0,
background: '#f2dfad',
foreground: '#315046'
});
noticeLabel.position.set(-2.8, 3.95, -6.65);
scene.add(noticeLabel);
// Seating area.
function makeBench(x, z, rotation = 0) {
const bench = group(garden, x, 0, z);
bench.rotation.y = rotation;
for (let i = 0; i < 3; i++) {
box(bench, 3.7, 0.16, 0.48, 0, 1.05, -0.55 + i * 0.55, '#a77948');
}
box(bench, 3.7, 0.65, 0.16, 0, 1.65, -0.92, '#9b6d43');
box(bench, 0.28, 1.05, 1.25, -1.35, 0.55, 0, '#6d533b');
box(bench, 0.28, 1.05, 1.25, 1.35, 0.55, 0, '#6d533b');
box(bench, 0.22, 0.65, 0.22, -1.45, 1.7, -0.88, '#6d533b');
box(bench, 0.22, 0.65, 0.22, 1.45, 1.7, -0.88, '#6d533b');
return bench;
}
makeBench(-7.0, 5.4);
makeBench(-4.8, 6.3, Math.PI / 2);
const seatingLabel = makeSprite('COMMUNITY SEATING', {
width: 3.6,
background: '#e7d7a6',
foreground: '#3a594b'
});
seatingLabel.position.set(-7.0, 2.9, 5.4);
scene.add(seatingLabel);
// Compost bin.
const compost = group(garden, 0, 0, 5.35);
for (let i = 0; i < 4; i++) {
box(compost, 2.0, 0.18, 0.18, 0, 0.3 + i * 0.38, -0.75, '#87623e');
box(compost, 2.0, 0.18, 0.18, 0, 0.3 + i * 0.38, 0.75, '#87623e');
box(compost, 0.18, 0.18, 1.5, -0.9, 0.3 + i * 0.38, 0, '#87623e');
box(compost, 0.18, 0.18, 1.5, 0.9, 0.3 + i * 0.38, 0, '#87623e');
}
box(compost, 1.8, 0.35, 1.3, 0, 0.65, 0, '#5a4930');
box(compost, 1.8, 0.2, 1.3, 0, 1.4, 0, '#6b5437');
// Rain barrel.
const barrel = group(garden, 9.8, 0, -4.3);
box(barrel, 1.0, 1.55, 1.0, 0, 0.78, 0, '#4b7f8d');
box(barrel, 1.08, 0.16, 1.08, 0, 1.5, 0, '#3d6977');
box(barrel, 0.25, 0.18, 0.25, 0, 0.35, 0.58, '#9c7c50');
// Low voxel clouds.
function makeCloud(x, y, z, scale) {
const cloud = group(scene, x, y, z);
cloud.scale.setScalar(scale);
box(cloud, 2.3, 0.75, 1.0, 0, 0, 0, '#edf5eb', false);
box(cloud, 1.3, 1.0, 0.9, -0.55, 0.35, 0, '#f7faef', false);
box(cloud, 1.35, 1.15, 0.9, 0.65, 0.3, 0, '#f7faef', false);
}
makeCloud(-9, 10.5, -17, 1.2);
makeCloud(6, 12.3, -20, 1.45);
makeCloud(16, 9.5, -15, 0.9);
// -------------------------------------------------------------------------
// Handover trolley and task items
// -------------------------------------------------------------------------
const handoverCart = group(scene, -0.2, 0, 0.35);
box(handoverCart, 2.1, 0.18, 1.0, 0, 1.05, 0, '#b5814d');
box(handoverCart, 1.8, 0.12, 0.8, 0, 0.45, 0, '#93623e');
for (const x of [-0.82, 0.82]) {
for (const z of [-0.34, 0.34]) {
box(handoverCart, 0.16, 1.05, 0.16, x, 0.52, z, '#6e5138');
}
}
box(handoverCart, 0.2, 0.7, 0.2, -0.95, 1.45, -0.38, '#6e5138');
box(handoverCart, 0.2, 0.7, 0.2, 0.95, 1.45, -0.38, '#6e5138');
box(handoverCart, 2.0, 0.16, 0.16, 0, 1.78, -0.38, '#6e5138');
const handoverLabel = makeSprite('HANDOVER', {
width: 2.6,
background: '#f0ba58',
foreground: '#294238'
});
handoverLabel.position.set(-0.2, 3.75, 0.35);
scene.add(handoverLabel);
function makeTrowel() {
const g = group(scene);
box(g, 0.13, 0.68, 0.13, 0, 0.23, 0, '#c38d4f');
box(g, 0.42, 0.4, 0.11, 0, -0.28, 0, '#768991');
box(g, 0.12, 0.1, 0.13, 0, 0.63, 0, '#d8ad69');
return g;
}
function makeWateringCan() {
const g = group(scene);
box(g, 0.65, 0.58, 0.48, 0, 0, 0, '#477f9a');
box(g, 0.12, 0.12, 0.85, 0, 0.08, 0.52, '#477f9a');
box(g, 0.28, 0.24, 0.22, 0, 0.08, 0.98, '#5d98af');
box(g, 0.12, 0.62, 0.12, -0.28, 0.28, 0, '#477f9a');
box(g, 0.12, 0.62, 0.12, 0.28, 0.28, 0, '#477f9a');
box(g, 0.65, 0.12, 0.12, 0, 0.56, 0, '#477f9a');
return g;
}
function makeFork() {
const g = group(scene);
box(g, 0.13, 0.9, 0.13, 0, 0.1, 0, '#bd8950');
box(g, 0.56, 0.14, 0.12, 0, -0.38, 0, '#718087');
for (const x of [-0.21, 0, 0.21]) {
box(g, 0.09, 0.34, 0.1, x, -0.58, 0, '#718087');
}
return g;
}
function makeClipboard(color = '#d6bd6d') {
const g = group(scene);
box(g, 0.65, 0.84, 0.08, 0, 0, 0, color);
box(g, 0.54, 0.67, 0.03, 0, -0.03, 0.055, '#f7f0d5');
box(g, 0.24, 0.12, 0.07, 0, 0.43, 0.07, '#8b7457');
for (let i = 0; i < 3; i++) {
box(g, 0.37, 0.035, 0.02, 0, 0.14 - i * 0.16, 0.078, '#95a39a', false);
}
return g;
}
function makeTaskCard(color) {
const g = group(scene);
box(g, 0.5, 0.64, 0.065, 0, 0, 0, color);
box(g, 0.35, 0.4, 0.02, 0, -0.03, 0.043, '#f7f1dc');
box(g, 0.25, 0.035, 0.02, 0, 0.06, 0.058, '#87978d', false);
box(g, 0.18, 0.035, 0.02, 0, -0.06, 0.058, '#87978d', false);
return g;
}
const cartClipboard = makeClipboard('#d0a658');
cartClipboard.position.set(-0.65, 1.18, 0.04);
cartClipboard.rotation.x = -Math.PI / 2;
cartClipboard.scale.setScalar(0.7);
handoverCart.add(cartClipboard);
const cartTrowel = makeTrowel();
cartTrowel.position.set(-0.15, 1.2, 0.06);
cartTrowel.rotation.x = -Math.PI / 2;
cartTrowel.scale.setScalar(0.72);
handoverCart.add(cartTrowel);
const cartCan = makeWateringCan();
cartCan.position.set(0.45, 1.36, 0.02);
cartCan.scale.setScalar(0.68);
handoverCart.add(cartCan);
const cartFork = makeFork();
cartFork.position.set(0.73, 1.2, -0.18);
cartFork.rotation.x = -Math.PI / 2;
cartFork.scale.setScalar(0.65);
handoverCart.add(cartFork);
const cartPlantCard = makeTaskCard('#6d9e58');
cartPlantCard.position.set(-0.72, 1.2, 0.23);
cartPlantCard.rotation.x = -Math.PI / 2;
cartPlantCard.scale.setScalar(0.65);
handoverCart.add(cartPlantCard);
const cartWaterCard = makeTaskCard('#5b91ab');
cartWaterCard.position.set(-0.1, 1.2, 0.23);
cartWaterCard.rotation.x = -Math.PI / 2;
cartWaterCard.scale.setScalar(0.65);
handoverCart.add(cartWaterCard);
const cartCompostCard = makeTaskCard('#c77a48');
cartCompostCard.position.set(0.52, 1.2, 0.23);
cartCompostCard.rotation.x = -Math.PI / 2;
cartCompostCard.scale.setScalar(0.65);
handoverCart.add(cartCompostCard);
// -------------------------------------------------------------------------
// Voxel volunteers
// -------------------------------------------------------------------------
function makeVolunteer({
shirt,
trousers,
skin,
hair,
hat = null,
vest = null,
badge = '#f0c85b'
}) {
const root = group(scene);
const shadowMat = new THREE.MeshBasicMaterial({
color: 0x304637,
transparent: true,
opacity: 0.16,
depthWrite: false
});
const shadow = new THREE.Mesh(new THREE.BoxGeometry(0.95, 0.025, 0.72), shadowMat);
shadow.position.y = 0.02;
root.add(shadow);
const leftLeg = group(root, -0.24, 1.02, 0);
const rightLeg = group(root, 0.24, 1.02, 0);
box(leftLeg, 0.38, 0.88, 0.42, 0, -0.42, 0, trousers);
box(rightLeg, 0.38, 0.88, 0.42, 0, -0.42, 0, trousers);
box(leftLeg, 0.42, 0.2, 0.58, 0, -0.88, 0.08, '#303b36');
box(rightLeg, 0.42, 0.2, 0.58, 0, -0.88, 0.08, '#303b36');
box(root, 0.94, 1.05, 0.52, 0, 1.56, 0, shirt);
box(root, 0.98, 0.18, 0.56, 0, 1.27, 0, trousers);
box(root, 0.3, 0.32, 0.04, 0.2, 1.65, 0.285, badge, false);
if (vest) {
box(root, 1.02, 0.78, 0.56, 0, 1.6, 0, vest);
box(root, 0.12, 0.74, 0.59, -0.29, 1.61, 0, '#f2e8b8');
box(root, 0.12, 0.74, 0.59, 0.29, 1.61, 0, '#f2e8b8');
}
box(root, 0.68, 0.68, 0.64, 0, 2.39, 0, skin);
box(root, 0.72, 0.23, 0.68, 0, 2.73, -0.02, hair);
box(root, 0.12, 0.42, 0.68, -0.31, 2.5, -0.02, hair);
box(root, 0.12, 0.15, 0.08, -0.15, 2.45, 0.335, '#26332d', false);
box(root, 0.12, 0.15, 0.08, 0.15, 2.45, 0.335, '#26332d', false);
box(root, 0.15, 0.14, 0.12, 0, 2.3, 0.36, skin, false);
if (hat) {
box(root, 0.82, 0.18, 0.78, 0, 2.9, 0, hat);
box(root, 0.72, 0.32, 0.65, 0, 3.08, -0.02, hat);
}
const leftArm = group(root, -0.61, 1.98, 0);
const rightArm = group(root, 0.61, 1.98, 0);
box(leftArm, 0.3, 0.76, 0.34, 0, -0.36, 0, shirt);
box(rightArm, 0.3, 0.76, 0.34, 0, -0.36, 0, shirt);
box(leftArm, 0.32, 0.2, 0.36, 0, -0.79, 0, skin);
box(rightArm, 0.32, 0.2, 0.36, 0, -0.79, 0, skin);
const leftHand = group(leftArm, 0, -0.83, 0.1);
const rightHand = group(rightArm, 0, -0.83, 0.1);
return {
root, leftLeg, rightLeg, leftArm, rightArm, leftHand, rightHand,
tool: null, card: null
};
}
const outgoing = makeVolunteer({
shirt: '#527f55',
trousers: '#40585a',
skin: '#b97853',
hair: '#3c302b',
hat: '#e1b85e',
vest: '#e8aa42'
});
const maya = makeVolunteer({
shirt: '#d66f47',
trousers: '#435767',
skin: '#d39a72',
hair: '#2f2928',
hat: '#e48c5e'
});
const theo = makeVolunteer({
shirt: '#4b83a0',
trousers: '#4e5c51',
skin: '#8d5b42',
hair: '#241f1d',
hat: '#69a6bd'
});
const iris = makeVolunteer({
shirt: '#9d6a9d',
trousers: '#63536a',
skin: '#e0ad87',
hair: '#a56836',
hat: '#b782aa'
});
// Held tools and task cards.
const mayaTool = makeTrowel();
mayaTool.scale.setScalar(0.82);
maya.rightHand.add(mayaTool);
maya.tool = mayaTool;
const theoTool = makeWateringCan();
theoTool.scale.setScalar(0.78);
theo.rightHand.add(theoTool);
theo.tool = theoTool;
const irisTool = makeFork();
irisTool.scale.setScalar(0.8);
iris.rightHand.add(irisTool);
iris.tool = irisTool;
const mayaCard = makeTaskCard('#6d9e58');
mayaCard.scale.setScalar(0.72);
maya.leftHand.add(mayaCard);
maya.card = mayaCard;
const theoCard = makeTaskCard('#5b91ab');
theoCard.scale.setScalar(0.72);
theo.leftHand.add(theoCard);
theo.card = theoCard;
const irisCard = makeTaskCard('#c77a48');
irisCard.scale.setScalar(0.72);
iris.leftHand.add(irisCard);
iris.card = irisCard;
// The outgoing volunteer carries the task folder and spare tools.
const outgoingBundle = group(outgoing.root, 0.67, 1.15, 0.5);
const bundleClipboard = makeClipboard('#c79e4f');
bundleClipboard.scale.setScalar(0.64);
bundleClipboard.rotation.y = -0.25;
outgoingBundle.add(bundleClipboard);
const bundleTool = makeTrowel();
bundleTool.scale.setScalar(0.62);
bundleTool.position.set(0.3, -0.08, 0.12);
bundleTool.rotation.z = -0.35;
outgoingBundle.add(bundleTool);
// Overhead assignment labels.
const mayaLabel = makeSprite('MAYA · PLANT', {
width: 2.6, background: '#4f784e', foreground: '#fff6d8', fontSize: 29
});
mayaLabel.position.set(0, 3.42, 0);
maya.root.add(mayaLabel);
const theoLabel = makeSprite('THEO · WATER', {
width: 2.6, background: '#426f89', foreground: '#fff6d8', fontSize: 29
});
theoLabel.position.set(0, 3.42, 0);
theo.root.add(theoLabel);
const irisLabel = makeSprite('IRIS · COMPOST', {
width: 2.9, background: '#855a83', foreground: '#fff6d8', fontSize: 27
});
irisLabel.position.set(0, 3.42, 0);
iris.root.add(irisLabel);
// Animated activity details.
const mayaSoilDrops = group(maya.root);
for (let i = 0; i < 6; i++) {
const drop = box(mayaSoilDrops, 0.12, 0.12, 0.12,
(i % 3 - 1) * 0.16, 0.7, 0.85 + Math.floor(i / 3) * 0.45,
'#5b3b29', false);
drop.userData.offset = i * 0.17;
}
const theoWaterDrops = group(theo.root);
for (let i = 0; i < 12; i++) {
const drop = box(theoWaterDrops, 0.08, 0.14, 0.08,
(i % 3 - 1) * 0.12, 0.7, 0.85 + Math.floor(i / 3) * 0.28,
'#69b6d0', false);
drop.userData.offset = i * 0.11;
}
const irisCompostBits = group(iris.root);
for (let i = 0; i < 7; i++) {
const bit = box(irisCompostBits, 0.12, 0.12, 0.12,
(i % 4 - 1.5) * 0.13, 0.9 + (i % 2) * 0.15, 0.85 + Math.floor(i / 4) * 0.3,
i % 2 ? '#6e5535' : '#88704b', false);
bit.userData.offset = i * 0.13;
}
// A changing speech bubble above the handover cart.
const speech = makeSprite('', {
width: 4.8,
background: '#fff3c7',
foreground: '#29483d',
border: '#d69a49',
fontSize: 30
});
speech.position.set(-0.2, 3.0, 0.35);
scene.add(speech);
// -------------------------------------------------------------------------
// Timeline animation
// -------------------------------------------------------------------------
let timeline = 0;
let playing = true;
let lastStatus = '';
let lastPhase = -1;
const playButton = document.getElementById('play');
const timelineInput = document.getElementById('timeline');
const timeLabel = document.getElementById('time');
const statusText = document.getElementById('status-text');
const phaseButtons = [...document.querySelectorAll('.phase-buttons button')];
function positionOnPath(v, points, t) {
// points is an array of [time, x, z, yaw].
let current = points[0];
let next = points[points.length - 1];
for (let i = 0; i < points.length - 1; i++) {
if (t >= points[i][0] && t <= points[i + 1][0]) {
current = points[i];
next = points[i + 1];
break;
}
}
if (t <= points[0][0]) return points[0];
if (t >= points[points.length - 1][0]) return points[points.length - 1];
const u = ease((t - current[0]) / (next[0] - current[0]));
v.root.position.x = lerp(current[1], next[1], u);
v.root.position.z = lerp(current[2], next[2], u);
let yaw = lerp(current[3], next[3], u);
const dx = next[1] - current[1];
const dz = next[2] - current[2];
const movingYaw = Math.atan2(dx, dz);
const turnWeight = Math.sin(u * Math.PI);
yaw = lerp(yaw, movingYaw, turnWeight);
v.root.rotation.y = yaw;
return u;
}
function setPose(v, walking, t, baseLeft = 0, baseRight = 0) {
const swing = walking ? Math.sin(t * 8.2) * 0.62 : 0;
v.leftLeg.rotation.x = walking ? -swing : 0;
v.rightLeg.rotation.x = walking ? swing : 0;
v.leftArm.rotation.x = baseLeft + (walking ? swing : 0);
v.rightArm.rotation.x = baseRight + (walking ? -swing : 0);
v.leftArm.rotation.z = 0;
v.rightArm.rotation.z = 0;
v.root.position.y = walking ? Math.abs(Math.sin(t * 8.2)) * 0.035 : 0;
}
function updateTimeline(t) {
// Outgoing volunteer: shed -> handover -> shed.
const outgoingPath = [
[0, -8.0, -2.45, 0],
[4, -8.0, -2.45, 0],
[9, -2.0, 0.2, Math.PI / 2],
[15, -2.0, 0.2, Math.PI / 2],
[25, -8.0, -2.45, -Math.PI / 2],
[30, -8.0, -2.45, 0]
];
const outgoingMove = positionOnPath(outgoing, outgoingPath, t);
const outgoingWalking = (t > 4 && t < 9) || (t > 15 && t < 25);
const outgoingHandover = t >= 9 && t < 15;
setPose(
outgoing,
outgoingWalking,
t,
outgoingHandover ? -0.72 : 0,
outgoingHandover ? -0.82 : 0
);
if (t >= 25 && t < 30) {
outgoing.rightArm.rotation.x = -0.2;
outgoing.rightArm.rotation.z = 1.05 + Math.sin(t * 5) * 0.12;
}
outgoingBundle.visible = t < 10.25;
// New helpers wait at the gate until their assigned handover.
const mayaPath = [
[0, 11.8, 6.9, -2.0],
[9, 11.8, 6.9, -2.0],
[14, 1.45, 1.2, -1.82],
[20, 1.45, 1.2, -1.82],
[27, 4.0, 0.72, Math.PI],
[30, 4.0, 0.72, Math.PI]
];
const mayaMove = positionOnPath(maya, mayaPath, t);
const mayaWalking = (t > 9 && t < 14) || (t > 20 && t < 27);
const mayaReceiving = t >= 12.5 && t < 20;
setPose(maya, mayaWalking, t, mayaReceiving ? -0.55 : 0, mayaReceiving ? -0.85 : 0);
const theoPath = [
[0, 12.2, 6.1, -1.9],
[12, 12.2, 6.1, -1.9],
[17, 1.8, 2.8, -1.55],
[20, 1.8, 2.8, -1.55],
[28, 9.35, 4.0, -Math.PI / 2],
[30, 9.35, 4.0, -Math.PI / 2]
];
const theoMove = positionOnPath(theo, theoPath, t);
const theoWalking = (t > 12 && t < 17) || (t > 20 && t < 28);
const theoReceiving = t >= 15.5 && t < 20;
setPose(theo, theoWalking, t, theoReceiving ? -0.55 : 0, theoReceiving ? -0.82 : 0);
const irisPath = [
[0, 12.1, -4.6, -1.25],
[14, 12.1, -4.6, -1.25],
[19, 1.45, -1.25, -1.55],
[20, 1.45, -1.25, -1.55],
[27, 0, 3.78, 0],
[30, 0, 3.78, 0]
];
const irisMove = positionOnPath(iris, irisPath, t);
const irisWalking = (t > 14 && t < 19) || (t > 20 && t < 27);
const irisReceiving = t >= 17.5 && t < 20;
setPose(iris, irisWalking, t, irisReceiving ? -0.55 : 0, irisReceiving ? -0.82 : 0);
// The outgoing volunteer places the bundle on the trolley.
const putDown = ease(segment(t, 9.2, 10.2));
cartClipboard.visible = t >= 9.2;
cartClipboard.scale.setScalar(0.7 * Math.max(0.001, putDown));
cartPlantCard.visible = t >= 9.2 && t < 13;
cartPlantCard.scale.setScalar(0.65 * Math.max(0.001, putDown));
cartTrowel.visible = t >= 9.2 && t < 13;
cartTrowel.scale.setScalar(0.72 * Math.max(0.001, putDown));
cartWaterCard.visible = t >= 10.4 && t < 16;
cartWaterCard.scale.setScalar(0.65 * Math.max(0.001, ease(segment(t, 10.4, 11.2))));
cartCan.visible = t >= 10.4 && t < 16;
cartCan.scale.setScalar(0.68 * Math.max(0.001, ease(segment(t, 10.4, 11.2))));
cartCompostCard.visible = t >= 11.7 && t < 18;
cartCompostCard.scale.setScalar(0.65 * Math.max(0.001, ease(segment(t, 11.7, 12.5))));
cartFork.visible = t >= 11.7 && t < 18;
cartFork.scale.setScalar(0.65 * Math.max(0.001, ease(segment(t, 11.7, 12.5))));
// Helpers visibly receive their tool and task card before moving away.
mayaTool.visible = t >= 13;
mayaCard.visible = t >= 13;
theoTool.visible = t >= 16;
theoCard.visible = t >= 16;
irisTool.visible = t >= 18;
irisCard.visible = t >= 18;
mayaLabel.visible = t >= 13;
theoLabel.visible = t >= 16;
irisLabel.visible = t >= 18;
// Assigned work starts only after the full handover has finished.
if (t >= 27) {
maya.rightArm.rotation.x = -0.95 + Math.sin(t * 5.2) * 0.22;
maya.leftArm.rotation.x = -0.55 + Math.cos(t * 4.8) * 0.12;
maya.root.position.y = Math.abs(Math.sin(t * 5.2)) * 0.035;
}
if (t >= 28) {
theo.rightArm.rotation.x = -0.52 + Math.sin(t * 3.8) * 0.08;
theo.leftArm.rotation.x = -0.45;
}
if (t >= 26.5) {
iris.rightArm.rotation.x = -0.72 + Math.sin(t * 4.5) * 0.22;
iris.leftArm.rotation.x = -0.48;
}
mayaSoilDrops.visible = t >= 27;
theoWaterDrops.visible = t >= 28;
irisCompostBits.visible = t >= 26.5;
for (const drop of mayaSoilDrops.children) {
const phase = (t * 1.8 + drop.userData.offset) % 1;
drop.position.y = 0.95 - phase * 0.45;
}
for (const drop of theoWaterDrops.children) {
const phase = (t * 2.1 + drop.userData.offset) % 1;
drop.position.y = 0.85 - phase * 0.55;
}
for (const bit of irisCompostBits.children) {
const phase = (t * 1.5 + bit.userData.offset) % 1;
bit.position.y = 1.0 - phase * 0.35;
}
// Gentle, deterministic plant movement.
for (const plant of plantGroups) {
plant.rotation.z = Math.sin(t * 0.75 + plant.userData.phase) * 0.018;
}
// Speech bubble content.
speech.visible = t >= 5 && t < 21;
let message = '';
if (t < 9) message = 'Shift handover';
else if (t < 13) message = "Here are today's tasks + tools";
else if (t < 16) message = 'Maya: planting rows';
else if (t < 18) message = 'Theo: watering beds';
else if (t < 20) message = 'Iris: turning compost';
else message = 'You are all set — enjoy the shift!';
if (speech.userData.currentText !== message) {
speech.userData.setText(message);
speech.userData.currentText = message;
}
updateUI(t);
}
function updateUI(t) {
timelineInput.value = t.toFixed(2);
const seconds = Math.floor(t);
timeLabel.textContent = `00:${String(seconds).padStart(2, '0')}`;
let status;
if (t < 4) status = 'Outgoing volunteer checks and gathers the tools';
else if (t < 9) status = 'Outgoing volunteer walks to the handover station';
else if (t < 13) status = 'Task cards and tools are placed on the trolley';
else if (t < 20) status = 'New helpers receive their assignments one by one';
else if (t < 27) status = 'Handover complete — helpers walk to their stations';
else status = 'New shift underway: planting, watering, and compost turning';
if (status !== lastStatus) {
statusText.textContent = status;
lastStatus = status;
}
const phase = t < 4 ? 0 : t < 20 ? 1 : 2;
if (phase !== lastPhase) {
phaseButtons.forEach((button, index) => button.classList.toggle('active', index === phase));
lastPhase = phase;
}
}
function togglePlay() {
if (timeline >= 30) timeline = 0;
playing = !playing;
playButton.textContent = playing ? 'Ⅱ' : '▶';
playButton.setAttribute('aria-label', playing ? 'Pause animation' : 'Play animation');
}
playButton.addEventListener('click', togglePlay);
timelineInput.addEventListener('input', (event) => {
timeline = Number(event.target.value);
updateTimeline(timeline);
});
phaseButtons.forEach((button) => {
button.addEventListener('click', () => {
timeline = Number(button.dataset.time);
updateTimeline(timeline);
});
});
window.addEventListener('keydown', (event) => {
if (event.code === 'Space' && event.target.tagName !== 'INPUT' && event.target.tagName !== 'BUTTON') {
event.preventDefault();
togglePlay();
}
if (event.code === 'ArrowRight') {
timeline = Math.min(30, timeline + 0.5);
updateTimeline(timeline);
}
if (event.code === 'ArrowLeft') {
timeline = Math.max(0, timeline - 0.5);
updateTimeline(timeline);
}
});
// -------------------------------------------------------------------------
// Custom orbit camera controls — no external controls addon
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 0.7, -0.1);
let cameraRadius = 28;
let cameraTheta = 0.83;
let cameraPhi = 0.87;
let dragging = false;
let pointerX = 0;
let pointerY = 0;
function updateCamera() {
const spherical = new THREE.Spherical(cameraRadius, cameraPhi, cameraTheta);
const offset = new THREE.Vector3().setFromSpherical(spherical);
camera.position.copy(cameraTarget).add(offset);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraRadius = 28;
cameraTheta = 0.83;
cameraPhi = 0.87;
cameraTarget.set(0, 0.7, -0.1);
updateCamera();
}
renderer.domElement.addEventListener('pointerdown', (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener('pointermove', (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(cameraPhi - dy * 0.005, 0.42, 1.28);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener('pointerup', endDrag);
renderer.domElement.addEventListener('pointercancel', endDrag);
renderer.domElement.addEventListener('wheel', (event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(cameraRadius * Math.exp(event.deltaY * 0.001), 16, 42);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener('dblclick', resetCamera);
document.getElementById('zoom-in').addEventListener('click', () => {
cameraRadius = Math.max(16, cameraRadius - 2);
updateCamera();
});
document.getElementById('zoom-out').addEventListener('click', () => {
cameraRadius = Math.min(42, cameraRadius + 2);
updateCamera();
});
document.getElementById('reset-view').addEventListener('click', resetCamera);
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
resetCamera();
updateTimeline(0);
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) {
timeline = Math.min(30, timeline + delta);
if (timeline >= 30) {
playing = false;
playButton.textContent = '▶';
playButton.setAttribute('aria-label', 'Replay animation');
}
}
updateTimeline(timeline);
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
document.getElementById('loading')?.remove();
}
}
animate();
</script>
</body>
</html>
```