Prompt specification
Build or customize the Three.js 3D scene "Neighbor explains a garden route" 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: Neighbor explains a garden route
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/neighbor-explains-a-garden-route-x3866
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts handover of community garden responsibilities. Animate one gardener pointing to labeled planters while another checks corresponding cards; the receiving person then follows the same route independently through the beds. Low-poly.
Working Three.js Starter (neighbor-explains-a-garden-route-x3866):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Community Garden Responsibility Handover</title>
<style>
:root {
color-scheme: light;
--ink: #173b32;
--paper: rgba(249, 247, 235, 0.93);
--accent: #d96f45;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
background: #dce9d2;
}
#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: 10;
color: var(--ink);
background: var(--paper);
border: 1px solid rgba(23, 59, 50, 0.13);
box-shadow: 0 12px 36px rgba(30, 61, 48, 0.13);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#intro {
top: 22px;
left: 22px;
width: min(430px, calc(100vw - 44px));
padding: 18px 20px 16px;
border-radius: 18px;
}
.eyebrow {
margin: 0 0 7px;
color: #658071;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(21px, 3vw, 30px);
line-height: 1.08;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 14px;
color: #50685d;
font-size: 13px;
line-height: 1.45;
}
.status-row {
display: flex;
align-items: center;
gap: 9px;
min-height: 26px;
}
#phase {
padding: 6px 9px;
border-radius: 999px;
color: #fff;
background: var(--ink);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.09em;
white-space: nowrap;
}
#detail {
color: #3f5b4d;
font-size: 12px;
line-height: 1.35;
}
.progress-track {
height: 4px;
margin-top: 13px;
overflow: hidden;
border-radius: 999px;
background: rgba(23, 59, 50, 0.1);
}
#progress {
width: 0%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #d96f45, #e5ae4f, #5b8d65);
transition: width 80ms linear;
}
#legend {
left: 22px;
bottom: 22px;
width: min(430px, calc(100vw - 44px));
padding: 14px 16px;
border-radius: 16px;
}
.legend-heading {
margin-bottom: 10px;
color: #698075;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.people {
display: flex;
flex-wrap: wrap;
gap: 8px 15px;
margin-bottom: 12px;
}
.person {
display: flex;
align-items: center;
gap: 7px;
font-size: 12px;
font-weight: 700;
}
.dot {
width: 10px;
height: 10px;
border-radius: 50%;
box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.65);
}
.cards {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 6px;
}
.card-chip {
min-width: 0;
padding: 8px 5px 7px;
overflow: hidden;
border: 1px solid rgba(23, 59, 50, 0.1);
border-radius: 10px;
background: rgba(255, 255, 255, 0.5);
text-align: center;
transition:
transform 180ms ease,
background 180ms ease,
box-shadow 180ms ease;
}
.card-chip::before {
display: block;
width: 18px;
height: 4px;
margin: 0 auto 5px;
border-radius: 99px;
background: var(--c);
content: "";
}
.card-chip strong,
.card-chip small {
display: block;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.card-chip strong {
font-size: 10px;
}
.card-chip small {
margin-top: 2px;
color: #71847a;
font-size: 9px;
}
.card-chip.active {
z-index: 1;
transform: translateY(-3px);
background: #fff;
box-shadow: 0 7px 18px rgba(37, 66, 53, 0.13);
}
#controls {
right: 22px;
bottom: 22px;
display: flex;
align-items: center;
gap: 8px;
padding: 9px;
border-radius: 14px;
}
button {
appearance: none;
border: 0;
border-radius: 10px;
padding: 9px 12px;
color: #fff;
background: var(--ink);
cursor: pointer;
font: inherit;
font-size: 12px;
font-weight: 750;
}
button:hover {
background: #285447;
}
button.secondary {
color: var(--ink);
background: rgba(23, 59, 50, 0.09);
}
button.secondary:hover {
background: rgba(23, 59, 50, 0.15);
}
.hint {
padding: 0 8px 0 3px;
color: #657b70;
font-size: 11px;
white-space: nowrap;
}
@media (max-width: 720px) {
#intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 15px;
}
.subtitle {
display: none;
}
#legend {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
padding: 11px 12px;
}
#controls {
right: 12px;
top: 12px;
bottom: auto;
}
.hint {
display: none;
}
.cards {
gap: 4px;
}
.card-chip {
padding-inline: 2px;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Animated community garden responsibility handover"></main>
<section id="intro" class="panel">
<p class="eyebrow">Community stewardship</p>
<h1>Responsibility handover</h1>
<p class="subtitle">
A garden guide reviews each planter with a new steward. The new steward
then repeats the route independently, confirming each care card.
</p>
<div class="status-row">
<span id="phase">PREPARING</span>
<span id="detail">The route and garden records are ready.</span>
</div>
<div class="progress-track"><div id="progress"></div></div>
</section>
<section id="legend" class="panel">
<div class="legend-heading">People</div>
<div class="people">
<div class="person">
<span class="dot" style="background:#d96f45"></span>
Garden guide
</div>
<div class="person">
<span class="dot" style="background:#4d8194"></span>
New steward
</div>
</div>
<div class="legend-heading">Care cards</div>
<div class="cards">
<div class="card-chip" style="--c:#e76f51">
<strong>01</strong><small>Tomatoes</small>
</div>
<div class="card-chip" style="--c:#58a66f">
<strong>02</strong><small>Herbs</small>
</div>
<div class="card-chip" style="--c:#e9c46a">
<strong>03</strong><small>Pollinators</small>
</div>
<div class="card-chip" style="--c:#8d6e63">
<strong>04</strong><small>Compost</small>
</div>
</div>
</section>
<section id="controls" class="panel">
<button id="replay" type="button">Replay</button>
<button id="pause" class="secondary" type="button">Pause</button>
<span class="hint">Drag to orbit · Scroll to zoom</span>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, lighting, and custom camera controls
// -------------------------------------------------------------------------
const host = document.querySelector("#scene");
const phaseEl = document.querySelector("#phase");
const detailEl = document.querySelector("#detail");
const progressEl = document.querySelector("#progress");
const replayButton = document.querySelector("#replay");
const pauseButton = document.querySelector("#pause");
const cardChips = [...document.querySelectorAll(".card-chip")];
const scene = new THREE.Scene();
scene.background = new THREE.Color("#dce9d2");
scene.fog = new THREE.Fog("#dce9d2", 27, 48);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 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;
host.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-10, 10, 10, -10, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0.3, 0.2);
let cameraYaw = 0.72;
let cameraPitch = 0.61;
let cameraZoom = 1;
function updateCamera() {
const radius = 24;
const horizontal = Math.cos(cameraPitch) * radius;
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * horizontal,
cameraTarget.y + Math.sin(cameraPitch) * radius,
cameraTarget.z + Math.cos(cameraYaw) * horizontal
);
camera.lookAt(cameraTarget);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
}
updateCamera();
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousPointerX;
const dy = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
cameraYaw -= dx * 0.006;
cameraPitch = THREE.MathUtils.clamp(cameraPitch + dy * 0.004, 0.32, 1.08);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * Math.exp(-event.deltaY * 0.001),
0.65,
1.65
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraYaw = 0.72;
cameraPitch = 0.61;
cameraZoom = 1;
updateCamera();
});
const hemisphere = new THREE.HemisphereLight("#f5f1d4", "#66846b", 2.05);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff0c4", 3.25);
sun.position.set(-8, 16, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 38;
sun.shadow.bias = -0.0005;
scene.add(sun);
const fill = new THREE.DirectionalLight("#c5ddff", 0.8);
fill.position.set(10, 8, -12);
scene.add(fill);
// -------------------------------------------------------------------------
// Reusable low-poly helpers
// -------------------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
flatShading: true,
...options
});
const materials = {
ground: material("#9fbe79"),
groundEdge: material("#76985f"),
soil: material("#5d4030"),
wood: material("#9a6940"),
woodLight: material("#b47d4d"),
woodDark: material("#74492f"),
stem: material("#426b3d"),
leaf: material("#4e8b4f"),
leafLight: material("#78aa5f"),
leafDark: material("#315c39"),
tomato: material("#e85d42"),
flowerYellow: material("#f1c75b"),
flowerPink: material("#db7f9b"),
flowerBlue: material("#648fc1"),
fence: material("#d5b782"),
bench: material("#9a633e"),
metal: material("#486b67"),
cream: material("#f2ead5")
};
function addMesh(parent, geometry, mat, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBox(parent, width, height, depth, mat, x = 0, y = 0, z = 0) {
return addMesh(
parent,
new THREE.BoxGeometry(width, height, depth),
mat,
x,
y,
z
);
}
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function makeLabelTexture(title, code, color) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 220;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 8, 8, 752, 204, 30);
ctx.fillStyle = "rgba(22, 52, 43, 0.94)";
ctx.fill();
roundedRect(ctx, 25, 28, 18, 164, 9);
ctx.fillStyle = color;
ctx.fill();
ctx.fillStyle = "#fff8e9";
ctx.font = "800 60px system-ui, sans-serif";
ctx.textBaseline = "middle";
ctx.fillText(title, 70, 86);
ctx.fillStyle = color;
ctx.font = "800 31px system-ui, sans-serif";
ctx.fillText(code, 71, 155);
ctx.fillStyle = "#d0dfd2";
ctx.font = "500 25px system-ui, sans-serif";
ctx.fillText("CARE PLANTER", 225, 156);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function makeTagTexture(text, color) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 112;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 5, 5, 502, 102, 26);
ctx.fillStyle = "rgba(247, 244, 228, 0.93)";
ctx.fill();
ctx.strokeStyle = color;
ctx.lineWidth = 6;
ctx.stroke();
ctx.fillStyle = color;
ctx.font = "850 39px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 57);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
function makeCardTexture(number, name, color) {
const canvas = document.createElement("canvas");
canvas.width = 160;
canvas.height = 190;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 5, 5, 150, 180, 17);
ctx.fillStyle = "#fffdf2";
ctx.fill();
roundedRect(ctx, 5, 5, 150, 61, 17);
ctx.fillStyle = color;
ctx.fill();
ctx.fillStyle = "#173b32";
ctx.font = "850 39px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.fillText(number, 80, 47);
ctx.font = "800 17px system-ui, sans-serif";
ctx.fillText(name.toUpperCase(), 80, 91);
ctx.strokeStyle = "#b9c6ba";
ctx.lineWidth = 5;
ctx.lineCap = "round";
ctx.beginPath();
ctx.moveTo(29, 121);
ctx.lineTo(131, 121);
ctx.moveTo(29, 143);
ctx.lineTo(108, 143);
ctx.stroke();
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
// -------------------------------------------------------------------------
// Ground and the shared inspection route
// -------------------------------------------------------------------------
addBox(scene, 22, 0.38, 16, materials.groundEdge, 0, -0.23, 0);
addBox(scene, 21.8, 0.12, 15.8, materials.ground, 0, -0.02, 0);
const routePoints = [
new THREE.Vector3(-8.0, 0.055, 1.6),
new THREE.Vector3(-5.2, 0.055, 0.1),
new THREE.Vector3(-1.0, 0.055, 0.1),
new THREE.Vector3(3.0, 0.055, 0.1),
new THREE.Vector3(4.0, 0.055, 3.4),
new THREE.Vector3(-0.4, 0.055, 5.5)
];
const routeCurve = new THREE.CatmullRomCurve3(
routePoints,
false,
"catmullrom",
0.22
);
function createRibbon(points, width, color, heightOffset) {
const positions = [];
const indices = [];
const samples = 90;
for (let i = 0; i <= samples; i++) {
const t = i / samples;
const point = points.getPoint(t);
const tangent = points.getTangent(t).normalize();
const side = new THREE.Vector3(-tangent.z, 0, tangent.x).multiplyScalar(
width / 2
);
positions.push(
point.x + side.x,
point.y + heightOffset,
point.z + side.z,
point.x - side.x,
point.y + heightOffset,
point.z - side.z
);
if (i < samples) {
const a = i * 2;
indices.push(a, a + 2, a + 1, a + 1, a + 2, a + 3);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material(color));
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
createRibbon(routeCurve, 1.58, "#bba779", 0.012);
createRibbon(routeCurve, 1.28, "#ddcba4", 0.025);
const dottedPositions = [];
for (let i = 0; i <= 120; i++) {
const point = routeCurve.getPoint(i / 120);
dottedPositions.push(point.x, point.y + 0.055, point.z);
}
const dottedGeometry = new THREE.BufferGeometry();
dottedGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(dottedPositions, 3)
);
const dottedLine = new THREE.Line(
dottedGeometry,
new THREE.LineDashedMaterial({
color: "#f7bd59",
dashSize: 0.23,
gapSize: 0.16,
transparent: true,
opacity: 0.95
})
);
dottedLine.computeLineDistances();
scene.add(dottedLine);
// -------------------------------------------------------------------------
// Planters, crops, labels, and care-card colors
// -------------------------------------------------------------------------
let randomSeed = 23;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
const planterDefinitions = [
{
name: "Tomatoes",
code: "PLANTER 01",
color: "#e76f51",
x: -5,
z: -3,
width: 4,
depth: 2,
kind: "tomato"
},
{
name: "Herbs",
code: "PLANTER 02",
color: "#58a66f",
x: -1,
z: -3,
width: 3.4,
depth: 2,
kind: "herbs"
},
{
name: "Pollinators",
code: "PLANTER 03",
color: "#e9c46a",
x: 4,
z: -2.3,
width: 3.4,
depth: 2.4,
kind: "flowers"
},
{
name: "Compost",
code: "PLANTER 04",
color: "#8d6e63",
x: 2.7,
z: 3.4,
width: 3.3,
depth: 2.3,
kind: "compost"
}
];
function addPlant(group, kind, x, z, index) {
const plant = new THREE.Group();
plant.position.set(x, 0.61, z);
plant.rotation.y = random() * Math.PI;
group.add(plant);
if (kind === "tomato") {
addMesh(
plant,
new THREE.CylinderGeometry(0.035, 0.055, 0.58, 5),
materials.stem,
0,
0.29,
0
);
for (let leaf = 0; leaf < 4; leaf++) {
const leafMesh = addMesh(
plant,
new THREE.IcosahedronGeometry(0.18, 0),
leaf % 2 ? materials.leaf : materials.leafLight,
(leaf % 2 ? 1 : -1) * 0.12,
0.22 + leaf * 0.09,
(leaf % 3 - 1) * 0.04
);
leafMesh.scale.set(1.35, 0.55, 0.8);
leafMesh.rotation.z = leaf % 2 ? 0.45 : -0.45;
}
for (let fruit = 0; fruit < 3; fruit++) {
addMesh(
plant,
new THREE.IcosahedronGeometry(0.09, 0),
materials.tomato,
(random() - 0.5) * 0.28,
0.22 + random() * 0.3,
0.1 + random() * 0.08
);
}
} else if (kind === "herbs") {
addMesh(
plant,
new THREE.CylinderGeometry(0.025, 0.04, 0.32, 5),
materials.stem,
0,
0.16,
0
);
for (let leaf = 0; leaf < 5; leaf++) {
const angle = (leaf / 5) * Math.PI * 2;
const leafMesh = addMesh(
plant,
new THREE.IcosahedronGeometry(0.16, 0),
leaf % 2 ? materials.leafLight : materials.leaf,
Math.cos(angle) * 0.1,
0.27 + (leaf % 2) * 0.06,
Math.sin(angle) * 0.1
);
leafMesh.scale.set(1.3, 0.7, 0.8);
leafMesh.rotation.y = angle;
}
} else if (kind === "flowers") {
addMesh(
plant,
new THREE.CylinderGeometry(0.025, 0.04, 0.48, 5),
materials.stem,
0,
0.24,
0
);
const petalMaterial = [
materials.flowerYellow,
materials.flowerPink,
materials.flowerBlue
][index % 3];
const petals = new THREE.Group();
petals.position.y = 0.48;
plant.add(petals);
for (let petal = 0; petal < 5; petal++) {
const angle = (petal / 5) * Math.PI * 2;
const petalMesh = addMesh(
petals,
new THREE.IcosahedronGeometry(0.095, 0),
petalMaterial,
Math.cos(angle) * 0.11,
0,
Math.sin(angle) * 0.11
);
petalMesh.scale.set(1.3, 0.55, 0.8);
petalMesh.rotation.y = -angle;
}
addMesh(
petals,
new THREE.IcosahedronGeometry(0.075, 0),
materials.cream,
0,
0.015,
0
);
} else {
const mound = addMesh(
plant,
new THREE.IcosahedronGeometry(0.28, 0),
materials.soil,
0,
0.09,
0
);
mound.scale.set(1.2, 0.55, 1);
for (let scrap = 0; scrap < 3; scrap++) {
const scrapMesh = addMesh(
plant,
new THREE.BoxGeometry(0.24, 0.035, 0.08),
scrap % 2 ? materials.leafDark : materials.leaf,
(random() - 0.5) * 0.35,
0.23,
(random() - 0.5) * 0.35
);
scrapMesh.rotation.y = random() * Math.PI;
scrapMesh.rotation.z = (random() - 0.5) * 0.4;
}
}
}
function addPlanter(definition, index) {
const group = new THREE.Group();
group.position.set(definition.x, 0, definition.z);
scene.add(group);
addBox(
group,
definition.width,
0.55,
definition.depth,
materials.wood,
0,
0.275,
0
);
addBox(
group,
definition.width - 0.2,
0.08,
definition.depth - 0.2,
materials.soil,
0,
0.58,
0
);
for (const side of [-1, 1]) {
addBox(
group,
definition.width + 0.04,
0.12,
0.09,
materials.woodLight,
0,
0.48,
side * (definition.depth / 2 + 0.015)
);
addBox(
group,
0.09,
0.12,
definition.depth + 0.04,
materials.woodLight,
side * (definition.width / 2 + 0.015),
0.48,
0
);
}
for (const x of [-1, 1]) {
for (const z of [-1, 1]) {
addBox(
group,
0.13,
0.68,
0.13,
materials.woodDark,
x * (definition.width / 2 - 0.08),
0.34,
z * (definition.depth / 2 - 0.08)
);
}
}
const plantCount = definition.kind === "herbs" ? 8 : 6;
for (let i = 0; i < plantCount; i++) {
const columns = definition.kind === "herbs" ? 4 : 3;
const x = ((i % columns) / (columns - 1) - 0.5) *
(definition.width - 0.7);
const z = (Math.floor(i / columns) / 1.5 - 0.5) *
(definition.depth - 0.65);
addPlant(group, definition.kind, x, z, i);
}
addBox(
group,
0.09,
1.08,
0.09,
materials.woodDark,
0,
1.05,
0
);
const labelTexture = makeLabelTexture(
definition.name,
definition.code,
definition.color
);
const label = new THREE.Sprite(
new THREE.SpriteMaterial({
map: labelTexture,
transparent: true,
depthTest: false,
depthWrite: false,
fog: false,
toneMapped: false
})
);
label.position.set(0, 1.82, 0);
label.scale.set(3.05, 0.87, 1);
label.renderOrder = 30;
group.add(label);
const halo = new THREE.Mesh(
new THREE.RingGeometry(0.54, 0.64, 32),
new THREE.MeshBasicMaterial({
color: definition.color,
transparent: true,
opacity: 0,
side: THREE.DoubleSide,
depthWrite: false
})
);
halo.rotation.x = -Math.PI / 2;
halo.position.y = 0.655;
halo.renderOrder = 5;
group.add(halo);
return {
...definition,
group,
label,
halo,
index
};
}
const planters = planterDefinitions.map(addPlanter);
// -------------------------------------------------------------------------
// Garden dressing: fence, trees, bench, barrel, and notice board
// -------------------------------------------------------------------------
for (let x = -10; x <= 10; x += 2) {
for (const z of [-7.45, 7.45]) {
addBox(scene, 0.16, 1.1, 0.16, materials.fence, x, 0.5, z);
}
}
for (const x of [-10, 10]) {
for (let z = -6; z <= 6; z += 2) {
addBox(scene, 0.16, 1.1, 0.16, materials.fence, x, 0.5, z);
}
}
for (const z of [-7.45, 7.45]) {
addBox(scene, 20, 0.12, 0.12, materials.fence, 0, 0.43, z);
addBox(scene, 20, 0.12, 0.12, materials.fence, 0, 0.78, z);
}
for (const x of [-10, 10]) {
addBox(scene, 0.12, 0.12, 12, materials.fence, x, 0.43, 0);
addBox(scene, 0.12, 0.12, 12, materials.fence, x, 0.78, 0);
}
function addTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
scene.add(tree);
addMesh(
tree,
new THREE.CylinderGeometry(0.2, 0.29, 1.65, 6),
materials.woodDark,
0,
0.82,
0
);
const crown = addMesh(
tree,
new THREE.IcosahedronGeometry(0.92, 1),
materials.leafDark,
0,
1.85,
0
);
crown.scale.set(1.05, 1.2, 0.95);
const crown2 = addMesh(
tree,
new THREE.IcosahedronGeometry(0.65, 0),
materials.leaf,
0.42,
1.75,
0.12
);
crown2.scale.set(1, 0.9, 1);
}
addTree(-9, -6, 1.05);
addTree(8.5, -6, 1.2);
addTree(-9, 5.8, 0.9);
addTree(8.7, 5.9, 1.05);
const bench = new THREE.Group();
bench.position.set(-7.2, 0, 4.6);
bench.rotation.y = -0.15;
scene.add(bench);
for (const x of [-0.85, 0.85]) {
addBox(bench, 0.14, 0.65, 0.15, materials.metal, x, 0.33, 0.25);
addBox(bench, 0.14, 0.65, 0.15, materials.metal, x, 0.33, -0.25);
}
for (const z of [-0.24, 0, 0.24]) {
addBox(bench, 2.1, 0.11, 0.2, materials.bench, 0, 0.64, z);
}
for (const y of [0.95, 1.25]) {
addBox(bench, 2.1, 0.16, 0.1, materials.bench, 0, y, -0.34);
}
const barrel = new THREE.Group();
barrel.position.set(8.1, 0, 4.6);
scene.add(barrel);
addMesh(
barrel,
new THREE.CylinderGeometry(0.62, 0.57, 1.3, 10),
materials.metal,
0,
0.65,
0
);
addMesh(
barrel,
new THREE.CylinderGeometry(0.66, 0.66, 0.09, 10),
materials.cream,
0,
1.31,
0
);
for (const y of [0.25, 1.05]) {
addMesh(
barrel,
new THREE.TorusGeometry(0.61, 0.035, 5, 12),
materials.woodDark,
0,
y,
0
).rotation.x = Math.PI / 2;
}
const noticeCanvas = document.createElement("canvas");
noticeCanvas.width = 1024;
noticeCanvas.height = 280;
const noticeContext = noticeCanvas.getContext("2d");
roundedRect(noticeContext, 8, 8, 1008, 264, 30);
noticeContext.fillStyle = "rgba(31, 66, 53, 0.94)";
noticeContext.fill();
noticeContext.fillStyle = "#fff2cf";
noticeContext.textAlign = "center";
noticeContext.font = "850 62px system-ui, sans-serif";
noticeContext.fillText("COMMUNITY GARDEN", 512, 98);
noticeContext.fillStyle = "#a8d69d";
noticeContext.font = "700 34px system-ui, sans-serif";
noticeContext.fillText("SHARED CARE · SHARED HARVEST", 512, 165);
noticeContext.fillStyle = "#f3bf63";
noticeContext.font = "700 27px system-ui, sans-serif";
noticeContext.fillText("RESPONSIBILITY HANDOVER", 512, 220);
const noticeTexture = new THREE.CanvasTexture(noticeCanvas);
noticeTexture.colorSpace = THREE.SRGBColorSpace;
const noticeSprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: noticeTexture,
transparent: true,
depthTest: false,
depthWrite: false,
fog: false,
toneMapped: false
})
);
noticeSprite.position.set(0, 2, -6.65);
noticeSprite.scale.set(4.6, 1.25, 1);
noticeSprite.renderOrder = 25;
scene.add(noticeSprite);
for (const x of [-1.7, 1.7]) {
addBox(scene, 0.12, 1.5, 0.12, materials.woodDark, x, 0.72, -6.68);
}
// -------------------------------------------------------------------------
// Low-poly gardeners
// -------------------------------------------------------------------------
function createCharacter(options) {
const root = new THREE.Group();
scene.add(root);
const shirt = material(options.shirt);
const trousers = material(options.trousers);
const skin = material(options.skin);
const hair = material(options.hair);
const shoes = material("#33443d");
const eyeMaterial = material("#17221f");
const body = addMesh(
root,
new THREE.CylinderGeometry(0.29, 0.36, 0.65, 7),
shirt,
0,
0.98,
0
);
body.rotation.y = 0.12;
if (options.apron) {
addBox(root, 0.48, 0.47, 0.07, options.apron, 0, 0.95, 0.29);
addBox(root, 0.08, 0.36, 0.075, options.apron, -0.15, 1.27, 0.29);
addBox(root, 0.08, 0.36, 0.075, options.apron, 0.15, 1.27, 0.29);
} else {
addBox(root, 0.44, 0.4, 0.065, trousers, 0, 1.08, 0.29);
addBox(root, 0.09, 0.39, 0.07, trousers, -0.15, 1.25, 0.29);
addBox(root, 0.09, 0.39, 0.07, trousers, 0.15, 1.25, 0.29);
}
const headPivot = new THREE.Group();
headPivot.position.set(0, 1.37, 0);
root.add(headPivot);
addMesh(
headPivot,
new THREE.IcosahedronGeometry(0.235, 1),
skin,
0,
0.22,
0
);
const hairCap = addMesh(
headPivot,
new THREE.SphereGeometry(0.238, 8, 4, 0, Math.PI * 2, 0, Math.PI * 0.56),
hair,
0,
0.24,
-0.005
);
hairCap.scale.y = 0.85;
for (const x of [-0.072, 0.072]) {
addMesh(
headPivot,
new THREE.IcosahedronGeometry(0.025, 0),
eyeMaterial,
x,
0.25,
0.218
);
}
const nose = addMesh(
headPivot,
new THREE.ConeGeometry(0.045, 0.12, 4),
skin,
0,
0.19,
0.25
);
nose.rotation.x = Math.PI / 2;
if (options.hat) {
addMesh(
root,
new THREE.CylinderGeometry(0.34, 0.34, 0.055, 9),
options.hat,
0,
1.79,
0
);
addMesh(
root,
new THREE.CylinderGeometry(0.22, 0.25, 0.24, 8),
options.hat,
0,
1.92,
0
);
}
const legs = [];
for (const side of [-1, 1]) {
const legPivot = new THREE.Group();
legPivot.position.set(side * 0.15, 0.62, 0);
root.add(legPivot);
addMesh(
legPivot,
new THREE.CylinderGeometry(0.105, 0.115, 0.46, 6),
trousers,
0,
-0.23,
0
);
addBox(legPivot, 0.21, 0.18, 0.34, shoes, 0, -0.52, 0.055);
legs.push(legPivot);
}
function createArm(side) {
const shoulder = new THREE.Group();
shoulder.position.set(side * 0.39, 1.19, 0);
root.add(shoulder);
addMesh(
shoulder,
new THREE.CylinderGeometry(0.085, 0.095, 0.32, 6),
shirt,
0,
-0.16,
0
);
const elbow = new THREE.Group();
elbow.position.set(0, -0.32, 0);
shoulder.add(elbow);
addMesh(
elbow,
new THREE.CylinderGeometry(0.07, 0.085, 0.3, 6),
skin,
0,
-0.15,
0
);
const hand = addMesh(
elbow,
new THREE.IcosahedronGeometry(0.09, 0),
skin,
0,
-0.33,
0
);
hand.scale.set(0.9, 1.05, 0.85);
return { shoulder, elbow, hand };
}
const leftArm = createArm(-1);
const rightArm = createArm(1);
const tag = new THREE.Sprite(
new THREE.SpriteMaterial({
map: makeTagTexture(options.tag, options.tagColor),
transparent: true,
depthTest: false,
depthWrite: false,
fog: false,
toneMapped: false
})
);
tag.position.set(0, 2.28, 0);
tag.scale.set(1.55, 0.39, 1);
tag.renderOrder = 31;
root.add(tag);
return {
root,
body,
headPivot,
legs,
leftArm,
rightArm,
tag
};
}
const guide = createCharacter({
shirt: "#d96f45",
trousers: "#52675a",
skin: "#b97852",
hair: "#3b2d28",
apron: material("#416a4d"),
hat: material("#e3bd6f"),
tag: "GARDEN GUIDE",
tagColor: "#d96f45"
});
guide.root.position.set(-6.45, 0, 1.2);
guide.root.rotation.y = 2.7;
const steward = createCharacter({
shirt: "#4d8194",
trousers: "#345467",
skin: "#e0a06e",
hair: "#59443b",
tag: "NEW STEWARD",
tagColor: "#4d8194"
});
steward.root.position.copy(routePoints[0]);
steward.root.rotation.y = 0.45;
// The card board follows the steward and stays readable from any camera angle.
const cardBoard = new THREE.Group();
scene.add(cardBoard);
addBox(cardBoard, 0.7, 0.82, 0.07, material("#345447"));
const cardRecords = [];
const cardPositions = [
[-0.16, 0.19],
[0.16, 0.19],
[-0.16, -0.19],
[0.16, -0.19]
];
for (let i = 0; i < 4; i++) {
const cardGroup = new THREE.Group();
cardGroup.position.set(cardPositions[i][0], cardPositions[i][1], 0.055);
cardBoard.add(cardGroup);
const card = new THREE.Mesh(
new THREE.PlaneGeometry(0.27, 0.32),
new THREE.MeshBasicMaterial({
map: makeCardTexture(
String(i + 1).padStart(2, "0"),
planters[i].name,
planters[i].color
),
side: THREE.DoubleSide,
toneMapped: false
})
);
cardGroup.add(card);
const checkGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-0.065, -0.025, 0.012),
new THREE.Vector3(-0.015, -0.068, 0.012),
new THREE.Vector3(0.075, 0.055, 0.012)
]);
const check = new THREE.Line(
checkGeometry,
new THREE.LineBasicMaterial({
color: "#173b32",
linewidth: 2
})
);
check.visible = false;
cardGroup.add(check);
cardRecords.push({
group: cardGroup,
card,
check,
baseY: cardPositions[i][1]
});
}
// -------------------------------------------------------------------------
// Pointing guide line and route markers
// -------------------------------------------------------------------------
const guideGeometry = new THREE.BufferGeometry();
guideGeometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(24 * 3), 3)
);
const guideLine = new THREE.Line(
guideGeometry,
new THREE.LineBasicMaterial({
color: "#ffd166",
transparent: true,
opacity: 0,
depthTest: false
})
);
guideLine.renderOrder = 40;
scene.add(guideLine);
const guideArrow = new THREE.Mesh(
new THREE.ConeGeometry(0.11, 0.3, 5),
new THREE.MeshBasicMaterial({
color: "#ffd166",
transparent: true,
opacity: 0,
depthTest: false
})
);
guideArrow.renderOrder = 41;
scene.add(guideArrow);
for (let i = 1; i <= 4; i++) {
const point = routePoints[i];
const marker = new THREE.Mesh(
new THREE.CylinderGeometry(0.19, 0.19, 0.055, 12),
material(planters[i - 1].color)
);
marker.position.set(point.x, 0.1, point.z);
marker.receiveShadow = true;
scene.add(marker);
}
// -------------------------------------------------------------------------
// Animation timeline
// -------------------------------------------------------------------------
const HANDOVER_START = 0.8;
const STAGE_DURATION = 2.25;
const HANDOVER_END = HANDOVER_START + STAGE_DURATION * 4;
const JOURNEY_START = 10.4;
const END_TIME = 24;
const journeyKeys = [
{ time: 10.4, position: routePoints[0], kind: "start" },
{ time: 12.0, position: routePoints[1], kind: "walk" },
{ time: 13.0, position: routePoints[1], kind: "check", card: 0 },
{ time: 14.4, position: routePoints[2], kind: "walk" },
{ time: 15.4, position: routePoints[2], kind: "check", card: 1 },
{ time: 16.8, position: routePoints[3], kind: "walk" },
{ time: 17.8, position: routePoints[3], kind: "check", card: 2 },
{ time: 19.2, position: routePoints[4], kind: "walk" },
{ time: 20.2, position: routePoints[4], kind: "check", card: 3 },
{ time: 21.8, position: routePoints[5], kind: "walk" },
{ time: 24.0, position: routePoints[5], kind: "wave" }
];
let animationTime = 0;
let paused = false;
function smoothstep(min, max, value) {
return THREE.MathUtils.smoothstep(value, min, max);
}
function dampAngle(current, target, lambda, delta) {
const difference = Math.atan2(
Math.sin(target - current),
Math.cos(target - current)
);
return current + difference * (1 - Math.exp(-lambda * delta));
}
function setActiveCard(activeIndex) {
cardRecords.forEach((record, index) => {
const active = index === activeIndex;
record.group.position.z = active ? 0.13 : 0.055;
record.group.position.y = record.baseY + (active ? 0.035 : 0);
record.group.scale.setScalar(active ? 1.09 : 1);
record.check.visible = active;
});
cardChips.forEach((chip, index) => {
chip.classList.toggle("active", index === activeIndex);
});
}
function setCharacterLook(character, target, lambda, delta) {
const dx = target.x - character.root.position.x;
const dz = target.z - character.root.position.z;
const desiredAngle = Math.atan2(dx, dz);
character.root.rotation.y = dampAngle(
character.root.rotation.y,
desiredAngle,
lambda,
delta
);
}
function updatePointGuide(target, strength) {
guide.root.updateMatrixWorld(true);
guide.rightArm.hand.getWorldPosition(guideStart);
const positions = guideGeometry.attributes.position;
for (let i = 0; i < 24; i++) {
const t = i / 23;
const point = guideStart.clone().lerp(target, t);
point.y += Math.sin(t * Math.PI) * 0.22;
positions.setXYZ(i, point.x, point.y, point.z);
}
positions.needsUpdate = true;
guideGeometry.computeBoundingSphere();
guideLine.material.opacity = strength * 0.78;
guideArrow.material.opacity = strength * 0.95;
guideLine.visible = strength > 0.01;
guideArrow.visible = strength > 0.01;
const direction = target.clone().sub(guideStart).normalize();
guideArrow.position.copy(target);
guideArrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction
);
}
const guideStart = new THREE.Vector3();
function updateAnimation(time, delta) {
let activeCard = -1;
let phase = "PREPARING";
let detail = "The route and garden records are ready.";
// Reset neutral poses.
guide.leftArm.shoulder.rotation.set(0.05, 0, -0.04);
guide.leftArm.elbow.rotation.set(-0.08, 0, 0);
guide.rightArm.shoulder.rotation.set(0.05, 0, 0.04);
guide.rightArm.elbow.rotation.set(-0.05, 0, 0);
guide.legs.forEach((leg) => (leg.rotation.x = 0));
guide.root.position.y = 0;
steward.leftArm.shoulder.rotation.set(0.05, 0, -0.04);
steward.leftArm.elbow.rotation.set(-0.08, 0, 0);
steward.rightArm.shoulder.rotation.set(0.05, 0, 0.04);
steward.rightArm.elbow.rotation.set(-0.05, 0, 0);
steward.legs.forEach((leg) => (leg.rotation.x = 0));
steward.root.position.y = 0;
if (time < HANDOVER_START) {
guide.headPivot.rotation.x = 0.04;
steward.headPivot.rotation.x = 0.22;
setCharacterLook(
guide,
planters[0].group.position,
4,
delta
);
} else if (time < JOURNEY_START) {
const stage = THREE.MathUtils.clamp(
Math.floor((time - HANDOVER_START) / STAGE_DURATION),
0,
3
);
const localTime =
(time - HANDOVER_START) % STAGE_DURATION;
const localPhase = localTime / STAGE_DURATION;
const pointStrength =
smoothstep(0, 0.18, localPhase) *
(1 - smoothstep(0.82, 1, localPhase));
activeCard = stage;
const planter = planters[stage];
const target = planter.group.position.clone();
target.y = 1.65;
setCharacterLook(guide, target, 8, delta);
guide.headPivot.rotation.x = 0.06;
guide.rightArm.shoulder.rotation.x = THREE.MathUtils.lerp(
0.05,
-1.18,
pointStrength
);
guide.rightArm.elbow.rotation.x = THREE.MathUtils.lerp(
-0.05,
-0.33,
pointStrength
);
steward.headPivot.rotation.x = 0.48;
steward.leftArm.shoulder.rotation.x = -0.48;
steward.leftArm.elbow.rotation.x = -0.62;
steward.rightArm.shoulder.rotation.x = -0.4;
steward.rightArm.elbow.rotation.x = -0.68;
updatePointGuide(target, pointStrength);
phase = "GUIDED HANDOVER";
detail =
`Guide points to ${planter.name.toLowerCase()} · ` +
`steward verifies card ${stage + 1}`;
} else if (time < END_TIME) {
let keyIndex = 0;
while (
keyIndex < journeyKeys.length - 1 &&
time >= journeyKeys[keyIndex + 1].time
) {
keyIndex++;
}
const from = journeyKeys[keyIndex];
const to = journeyKeys[Math.min(keyIndex + 1, journeyKeys.length - 1)];
const moving = to.kind === "walk";
const checking = to.kind === "check";
const segmentProgress = THREE.MathUtils.clamp(
(time - from.time) / Math.max(0.001, to.time - from.time),
0,
1
);
if (moving) {
const eased = THREE.MathUtils.smoothstep(
segmentProgress,
0,
1
);
steward.root.position.lerpVectors(
from.position,
to.position,
eased
);
const direction = to.position.clone().sub(from.position);
if (direction.lengthSq() > 0.001) {
const desiredAngle = Math.atan2(direction.x, direction.z);
steward.root.rotation.y = dampAngle(
steward.root.rotation.y,
desiredAngle,
8,
delta
);
}
const stride = time * 8.5;
steward.legs[0].rotation.x = Math.sin(stride) * 0.55;
steward.legs[1].rotation.x = -Math.sin(stride) * 0.55;
steward.leftArm.shoulder.rotation.x = -Math.sin(stride) * 0.38;
steward.rightArm.shoulder.rotation.x = Math.sin(stride) * 0.38;
steward.root.position.y = Math.abs(Math.sin(stride)) * 0.035;
steward.headPivot.rotation.x = 0.08;
phase = "INDEPENDENT ROUTE";
detail = "The new steward follows the marked route independently.";
} else if (checking) {
activeCard = to.card;
steward.root.position.copy(to.position);
setCharacterLook(
steward,
planters[to.card].group.position,
8,
delta
);
steward.headPivot.rotation.x = 0.48;
steward.leftArm.shoulder.rotation.x = -0.48;
steward.leftArm.elbow.rotation.x = -0.62;
steward.rightArm.shoulder.rotation.x = -0.4;
steward.rightArm.elbow.rotation.x = -0.68;
phase = "INDEPENDENT ROUTE";
detail =
`At ${planters[to.card].name.toLowerCase()}: ` +
`card ${to.card + 1} confirmed`;
} else {
steward.root.position.copy(routePoints[5]);
steward.root.rotation.y = dampAngle(
steward.root.rotation.y,
Math.atan2(
camera.position.x - cameraTarget.x,
camera.position.z - cameraTarget.z
),
5,
delta
);
steward.headPivot.rotation.x = -0.08;
steward.rightArm.shoulder.rotation.z = 2.2;
steward.rightArm.elbow.rotation.x = -0.18;
guide.leftArm.shoulder.rotation.z = -2.1;
phase = "HANDOVER COMPLETE";
detail = "The route is understood; gardening duties are now shared.";
}
guide.rightArm.shoulder.rotation.x = 0.05;
guide.rightArm.elbow.rotation.x = -0.05;
guide.headPivot.rotation.x = 0.03;
updatePointGuide(guide.root.position, 0);
} else {
activeCard = -1;
phase = "HANDOVER COMPLETE";
detail = "Responsibility for the community garden is now shared.";
steward.root.position.copy(routePoints[5]);
steward.rightArm.shoulder.rotation.z = 2.2;
guide.leftArm.shoulder.rotation.z = -2.1;
updatePointGuide(guide.root.position, 0);
}
// Keep the care-card board in front of the steward and readable.
const cameraFlatDirection = new THREE.Vector3(
camera.position.x - cameraTarget.x,
0,
camera.position.z - cameraTarget.z
).normalize();
cardBoard.position.copy(steward.root.position);
cardBoard.position.addScaledVector(cameraFlatDirection, 0.61);
cardBoard.position.y += 1.02;
cardBoard.quaternion.copy(camera.quaternion);
setActiveCard(activeCard);
// Planter highlights.
planters.forEach((planter, index) => {
const active = index === activeCard;
const pulse = active ? 1 + Math.sin(time * 4) * 0.06 : 1;
planter.label.scale.x = THREE.MathUtils.lerp(
planter.label.scale.x,
active ? 3.43 : 3.05,
1 - Math.exp(-8 * delta)
);
planter.label.scale.y = THREE.MathUtils.lerp(
planter.label.scale.y,
active ? 0.98 : 0.87,
1 - Math.exp(-8 * delta)
);
planter.halo.material.opacity = THREE.MathUtils.lerp(
planter.halo.material.opacity,
active ? 0.76 : 0,
1 - Math.exp(-8 * delta)
);
planter.halo.scale.setScalar(pulse);
});
phaseEl.textContent = phase;
detailEl.textContent = detail;
progressEl.style.width =
`${Math.min(100, (time / END_TIME) * 100).toFixed(2)}%`;
}
// -------------------------------------------------------------------------
// Controls, resize, and render loop
// -------------------------------------------------------------------------
replayButton.addEventListener("click", () => {
animationTime = 0;
paused = false;
pauseButton.textContent = "Pause";
});
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Play" : "Pause";
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
pauseButton.click();
}
if (event.code === "KeyR") {
replayButton.click();
}
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const halfHeight = Math.max(9.4, 13.8 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
let previousTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (!paused) {
animationTime = Math.min(animationTime + delta, END_TIME);
}
updateAnimation(animationTime, paused ? 0 : delta);
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```