Prompt specification
Build or customize the Three.js 3D scene "Broom sweep into pan" 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: Broom sweep into pan
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/broom-sweep-into-pan-x0022
Scene Description Prompt:
Use Three.js from cdnjs to animate a small broom pushing dry crumbs across a tiled patch into a stationary dustpan; crumbs stop inside instead of passing through its back wall. Deliver one self-contained HTML file with low-poly forms.
Working Three.js Starter (broom-sweep-into-pan-x0022):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Broom & Dustpan</title>
<style>
html, body { margin:0; padding:0; height:100%; overflow:hidden; background:#c9d6df; }
#app { position:fixed; inset:0; }
canvas { display:block; }
#hud {
position:fixed; left:16px; top:16px; z-index:10;
background:rgba(18,22,26,.82); color:#eef2f5; border:1px solid rgba(255,255,255,.14);
border-radius:12px; padding:14px 16px; font:13px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;
box-shadow:0 8px 26px rgba(0,0,0,.35); max-width:280px; user-select:none;
}
#hud h1 { margin:0 0 6px; font-size:15px; letter-spacing:.4px; }
#hud p { margin:2px 0; color:#a9b6c0; }
#hud .bar { height:8px; border-radius:5px; background:rgba(255,255,255,.12); margin:10px 0 8px; overflow:hidden; }
#hud .bar i { display:block; height:100%; width:0%; background:linear-gradient(90deg,#d9a441,#e8c877); transition:width .2s; }
#hud .count { font-size:20px; color:#f0c977; }
#hud button {
margin:10px 6px 0 0; padding:6px 10px; border-radius:8px; cursor:pointer;
background:#2b3views; color:#eef2f5; border:1px solid rgba(255,255,255,.2);
background:#2c343c; font:inherit; cursor:pointer;
}
#hud button:hover { background:#3a454f; }
</style>
</head>
<body>
<div id="app"></div>
<div id="hud">
<h1>Broom & Dustpan</h1>
<p>drag = orbit · wheel = zoom · shift-drag = pan</p>
<div class="count"><span id="inPan">0</span> / <span id="total">0</span> crumbs collected</div>
<div class="bar"><i id="bar"></i></div>
<button id="reset">Rescatter crumbs</button><button id="toggle">Pause</button>
</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
/* ------------------------------------------------------------------ */
/* Renderer / scene / lights */
/* ------------------------------------------------------------------ */
const app = document.getElementById('app');
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc9d6df);
scene.fog = new THREE.Fog(0xc9d6df, 18, 46);
const camera = new THREE.PerspectiveCamera(48, innerWidth / innerHeight, 0.1, 200);
scene.add(new THREE.HemisphereLight(0xdfefff, 0x6d6a56, 0.85));
const sun = new THREE.DirectionalLight(0xfff1d6, 1.15);
sun.position.set(6, 11, 5);
sun.castShadow = true;
sun.shadow.mapSize.set(1024, 1024);
sun.shadow.camera.left = -9; sun.shadow.camera.right = 9;
sun.shadow.camera.top = 9; sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 1; sun.shadow.camera.far = 32;
sun.shadow.bias = -0.0012;
scene.add(sun);
/* ------------------------------------------------------------------ */
/* World constants */
/* ------------------------------------------------------------------ */
const PAN = { front: 2.55, back: 4.10, halfW: 1.20, floorY: 0.04 }; // dustpan interior
const BRM = { front: 0.18, halfW: 1.00, startX: -4.05, endX: 2.27 }; // broom head
const NUM_CRUMBS = 58;
const FRICTION = 3.2; // dry crumbs stop quickly
const GROUND = 0.0;
/* ------------------------------------------------------------------ */
/* Tiled floor patch (instanced, low-poly boxes) */
/* ------------------------------------------------------------------ */
const COLS = 12, ROWS = 5, PITCH = 0.85, TILE = 0.80;
const tileGeo = new THREE.BoxGeometry(TILE, 0.06, TILE);
const tileMat = new THREE.MeshLambertMaterial({ color: 0xffffff, flatShading: true });
const tiles = new THREE.InstancedMesh(tileGeo, tileMat, COLS * ROWS);
tiles.receiveShadow = true;
const dummy = new THREE.Object3D();
const palette = [0xf3ece0, 0xe8e0d0, 0xd8d1c1, 0xefe7da, 0xcdc6b6];
let ti = 0;
for (let cx = 0; cx < COLS; cx++) {
for (let cz = 0; cz < ROWS; cz++) {
dummy.position.set(-4.40 + cx * PITCH, -0.03, -1.70 + cz * PITCH);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
tiles.setMatrixAt(ti, dummy.matrix);
const c = new THREE.Color(palette[(cx * 3 + cz * 5) % palette.length]);
c.offsetHSL(0, 0, (Math.random() - 0.5) * 0.06);
tiles.setColorAt(ti, c);
ti++;
}
}
tiles.instanceColor.needsUpdate = true;
scene.add(tiles);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(70, 70),
new THREE.MeshLambertMaterial({ color: 0x8e99a1 })
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.062;
ground.receiveShadow = true;
scene.add(ground);
/* ------------------------------------------------------------------ */
/* Dustpan (stationary, low-poly) */
/* ------------------------------------------------------------------ */
const panGroup = new THREE.Group();
const panMat = new THREE.MeshLambertMaterial({ color: 0xd8402f, flatShading: true });
const panDark = new THREE.MeshLambertMaterial({ color: 0xa92f22, flatShading: true });
// floor of the pan
const panFloor = new THREE.Mesh(new THREE.BoxGeometry(PAN.back - PAN.front, 0.04, PAN.halfW * 2), panDark);
panFloor.position.set((PAN.front + PAN.back) / 2, PAN.floorY / 2, 0);
panFloor.receiveShadow = true;
panGroup.add(panFloor);
// back wall (tall) — crumbs stop here instead of passing through
const backWall = new THREE.Mesh(new THREE.BoxGeometry(0.12, 0.55, PAN.halfW * 2 + 0.2), panMat);
backWall.position.set(PAN.back + 0.06, 0.275, 0);
backWall.castShadow = true; backWall.receiveShadow = true;
panGroup.add(backWall);
// sloping side walls (extruded low-poly profile)
const sideShape = new THREE.Shape();
sideShape.moveTo(PAN.front, 0);
sideShape.lineTo(PAN.back, 0);
sideShape.lineTo(PAN.back, 0.55);
sideShape.lineTo(3.35, 0.30);
sideShape.lineTo(PAN.front, 0.12);
sideShape.closePath();
const sideGeo = new THREE.ExtrudeGeometry(sideShape, { depth: 0.09, bevelEnabled: false });
const sidePlus = new THREE.Mesh(sideGeo, panMat);
sidePlus.position.z = PAN.halfW - 0.09;
const sideMinus = new THREE.Mesh(sideGeo, panMat);
sideMinus.position.z = -PAN.halfW;
sidePlus.castShadow = sideMinus.castShadow = true;
panGroup.add(sidePlus, sideMinus);
// low front lip
const lip = new THREE.Mesh(new THREE.BoxGeometry(0.07, 0.07, PAN.halfW * 2), panDark);
lip.position.set(PAN.front, PAN.floorY + 0.035, 0);
lip.castShadow = true;
panGroup.add(lip);
// handle sticking up at the back
const handlePivot = new THREE.Group();
handlePivot.position.set(PAN.back + 0.10, 0.52, 0);
handlePivot.rotation.z = -0.62;
const stick = new THREE.Mesh(new THREE.CylinderGeometry(0.045, 0.05, 1.45, 6), panDark);
stick.position.y = 0.72; stick.castShadow = true;
const grip = new THREE.Mesh(new THREE.CylinderGeometry(0.065, 0.065, 0.34, 6),
new THREE.MeshLambertMaterial({ color: 0x2f3338, flatShading: true }));
grip.position.y = 1.36;
handlePivot.add(stick, grip);
panGroup.add(handlePivot);
scene.add(panGroup);
/* ------------------------------------------------------------------ */
/* Broom (low-poly, animated) */
/* ------------------------------------------------------------------ */
const broom = new THREE.Group();
const woodMat = new THREE.MeshLambertMaterial({ color: 0xb07a3e, flatShading: true });
const strawMat = new THREE.MeshLambertMaterial({ color: 0xffffff, flatShading: true });
const head = new THREE.Mesh(new THREE.BoxGeometry(0.36, 0.14, BRM.halfW * 2), woodMat);
head.position.y = 0.31;
head.castShadow = true; head.receiveShadow = true;
broom.add(head);
// bristle fringe (instanced tufts)
const BR_ROWS = 2, BR_COLS = 18;
const bristleGeo = new THREE.BoxGeometry(0.26, 0.24, 0.075);
const bristles = new THREE.InstancedMesh(bristleGeo, strawMat, BR_ROWS * BR_COLS);
bristles.castShadow = true;
let bi = 0;
for (let r = 0; r < BR_ROWS; r++) {
for (let c = 0; c < BR_COLS; c++) {
dummy.position.set(r === 0 ? -0.075 : 0.075, 0.12 + (Math.random() - 0.5) * 0.02,
-0.94 + c * (1.88 / (BR_COLS - 1)));
dummy.rotation.set((Math.random() - 0.5) * 0.16, (Math.random() - 0.5) * 0.10,
(Math.random() - 0.5) * 0.16);
dummy.scale.set(1, 0.85 + Math.random() * 0.3, 1);
dummy.updateMatrix();
bristles.setMatrixAt(bi, dummy.matrix);
const col = new THREE.Color(0xd9b267).offsetHSL(0, (Math.random() - 0.5) * 0.06, (Math.random() - 0.5) * 0.10);
bristles.setColorAt(bi, col);
bi++;
}
}
bristles.instanceColor.needsUpdate = true;
broom.add(bristles);
// shaft + grip
const shaftPivot = new THREE.Group();
shaftPivot.position.set(-0.11, 0.37, 0);
shaftPivot.rotation.z = 0.46;
const shaft = new THREE.Mesh(new THREE.CylinderGeometry(0.042, 0.05, 2.55, 6), woodMat);
shaft.position.y = 1.28; shaft.castShadow = true;
const shaftGrip = new THREE.Mesh(new THREE.CylinderGeometry(0.058, 0.058, 0.42, 6),
new THREE.MeshLambertMaterial({ color: 0x35506b, flatShading: true }));
shaftGrip.position.y = 2.28;
shaftPivot.add(shaft, shaftGrip);
broom.add(shaftPivot);
scene.add(broom);
/* ------------------------------------------------------------------ */
/* Crumbs */
/* ------------------------------------------------------------------ */
const crumbs = [];
const crumbGeoCache = [];
function crumbGeometry(r) {
const key = r.toFixed(3);
let g = crumbGeoCache.find(c => c.key === key);
if (!g) { g = { key, geo: new THREE.IcosahedronGeometry(r, 0) }; crumbGeoCache.push(g); }
return g.geo;
}
function scatterCrumbs() {
for (const c of crumbs) { scene.remove(c.mesh); c.mesh.material.dispose(); }
crumbs.length = 0;
for (let i = 0; i < NUM_CRUMBS; i++) {
const r = 0.055 + Math.random() * 0.032;
const mat = new THREE.MeshLambertMaterial({
color: new THREE.Color().setHSL(0.075 + Math.random() * 0.045,
0.32 + Math.random() * 0.28,
0.44 + Math.random() * 0.24),
flatShading: true
});
const mesh = new THREE.Mesh(crumbGeometry(r), mat);
mesh.scale.set(1, 0.8, 1);
mesh.castShadow = true;
const pos = new THREE.Vector3(
-3.65 + Math.random() * 5.35,
GROUND + r * 0.8,
-0.92 + Math.random() * 1.84
);
mesh.position.copy(pos);
mesh.rotation.set(Math.random() * 6, Math.random() * 6, Math.random() * 6);
scene.add(mesh);
crumbs.push({ mesh, pos, vel: new THREE.Vector3(), r });
}
document.getElementById('total').textContent = NUM_CRUMBS;
}
scatterCrumbs();
/* ------------------------------------------------------------------ */
/* Dust puffs */
/* ------------------------------------------------------------------ */
const puffGeo = new THREE.TetrahedronGeometry(0.055);
const puffs = [];
for (let i = 0; i < 48; i++) {
const m = new THREE.MeshLambertMaterial({ color: 0xe9dcbe, transparent: true, opacity: 0, flatShading: true, depthWrite: false });
const mesh = new THREE.Mesh(puffGeo, m);
mesh.visible = false;
scene.add(mesh);
puffs.push({ mesh, life: 0, max: 1, vel: new THREE.Vector3() });
}
let puffCur = 0;
function spawnPuff(x, y, z, s = 1) {
const p = puffs[puffCur]; puffCur = (puffCur + 1) % puffs.length;
p.max = p.life = 0.45 + Math.random() * 0.45;
p.mesh.position.set(x, y, z);
p.vel.set((Math.random() - 0.5) * 0.7 * s, (0.35 + Math.random() * 0.5) * s, (Math.random() - 0.5) * 0.7 * s);
p.mesh.rotation.set(Math.random() * 6, Math.random() * 6, Math.random() * 6);
p.mesh.scale.setScalar(0.5 + Math.random() * 0.8);
p.mesh.material.opacity = 0.5;
p.mesh.visible = true;
}
function updatePuffs(dt) {
for (const p of puffs) {
if (p.life <= 0) continue;
p.life -= dt;
p.mesh.position.addScaledVector(p.vel, dt);
p.vel.y -= 0.35 * dt;
p.mesh.rotation.x += dt * 3.5; p.mesh.rotation.y += dt * 2.5;
p.mesh.scale.multiplyScalar(1 + dt * 1.1);
p.mesh.material.opacity = 0.5 * Math.max(0, p.life / p.max);
if (p.life <= 0) p.mesh.visible = false;
}
}
/* ------------------------------------------------------------------ */
/* Broom timeline */
/* ------------------------------------------------------------------ */
const PHASES = [
{ name: 'push', dur: 3.20 },
{ name: 'hold', dur: 0.55 },
{ name: 'back', dur: 2.50 },
{ name: 'rest', dur: 0.80 }
];
let phaseIdx = 0, phaseTime = 0, prevPhaseIdx = -1;
let broomX = BRM.startX, prevBroomX = BRM.startX, broomSpeed = 0, broomLift = 0;
function smooth(t) { return t * t * (3 - 2 * t); }
function trapezoid(t, T, a) { // distance travelled, accel/decel ramp
const D = BRM.endX - BRM.startX, vmax = D / (T - a);
if (t < a) return 0.5 * vmax * t * t / a;
if (t < T - a) return 0.5 * vmax * a + vmax * (t - a);
const td = t - (T - a);
return 0.5 * vmax * a + vmax * (T - 2 * a) + vmax * td - 0.5 * vmax * td * td / a;
}
function flick() { // final push that throws crumbs over the lip into the pan
for (const c of crumbs) {
if (c.pos.x > 1.4 && c.pos.x < PAN.front + 0.05) {
c.vel.x = Math.max(c.vel.x, 3.2 + Math.random() * 2.6);
c.vel.z += (Math.random() - 0.5) * 1.3;
}
}
}
function updateBroom(dt) {
phaseTime += dt;
if (phaseTime >= PHASES[phaseIdx].dur) {
phaseTime -= PHASES[phaseIdx].dur;
prevPhaseIdx = phaseIdx;
phaseIdx = (phaseIdx + 1) % PHASES.length;
if (prevPhaseIdx === 0 && phaseIdx === 1) flick();
}
const ph = PHASES[phaseIdx];
if (ph.name === 'push') {
broomX = BRM.startX + trapezoid(phaseTime, ph.dur, 0.55);
broomLift = 0;
} else if (ph.name === 'hold') {
broomX = BRM.endX; broomLift = 0;
} else if (ph.name === 'back') {
broomX = BRM.endX - trapezoid(phaseTime, ph.dur, 0.55);
broomLift = 0.55 * smooth(Math.min(1, phaseTime / 0.35));
} else {
broomX = BRM.startX;
broomLift = 0.55 * (1 - smooth(Math.min(1, phaseTime / 0.45)));
}
broomSpeed = (broomX - prevBroomX) / Math.max(dt, 1e-4);
prevBroomX = broomX;
broom.position.set(broomX, broomLift, 0);
}
/* ------------------------------------------------------------------ */
/* Broom pushing the crumbs */
/* ------------------------------------------------------------------ */
let puffTimer = 0;
function broomPush(dt) {
if (broomSpeed <= 0.05 || broomLift > 0.05) return; // only push while sweeping forward
const front = broomX + BRM.front;
for (const c of crumbs) {
if (c.pos.x > PAN.front - 0.02) continue; // already inside the pan
if (Math.abs(c.pos.z) > BRM.halfW + c.r * 0.5) continue; // outside the broom width
if (c.pos.x < broomX - 0.12) continue; // behind the broom
const target = front + c.r;
if (c.pos.x < target) {
c.pos.x = target;
c.vel.x = Math.max(c.vel.x, broomSpeed * 1.15);
c.vel.z += (Math.random() - 0.5) * 0.05;
}
}
puffTimer -= dt;
if (puffTimer <= 0) {
puffTimer = 0.06;
spawnPuff(broomX + BRM.front * 0.6, 0.08, (Math.random() - 0.5) * 1.9, 0.7);
}
}
/* ------------------------------------------------------------------ */
/* Crumb physics + dustpan collision (crumbs STOP inside) */
/* ------------------------------------------------------------------ */
function clampToPan(c) {
if (c.pos.x <= PAN.front - 0.02) return; // not in the pan yet
if (Math.abs(c.pos.z) > PAN.halfW + 0.3) return;
// back wall — clamp and kill forward velocity: crumbs stop, never pass through
if (c.pos.x > PAN.back - c.r) {
if (c.pos.x !== PAN.back - c.r) spawnPuff(PAN.back - c.r - 0.03, 0.10, c.pos.z, 0.45);
c.pos.x = PAN.back - c.r;
c.vel.x = 0;
}
// side walls
if (c.pos.z > PAN.halfW - c.r) { c.pos.z = PAN.halfW - c.r; c.vel.z = 0; }
if (c.pos.z < -PAN.halfW + c.r) { c.pos.z = -PAN.halfW + c.r; c.vel.z = 0; }
// low front lip keeps collected crumbs from sliding back out
if (c.pos.x < PAN.front + 0.02 && c.vel.x < 0) { c.pos.x = PAN.front + 0.02; c.vel.x = 0; }
}
function updateCrumbs(dt) {
const damp = Math.exp(-FRICTION * dt);
for (const c of crumbs) {
c.vel.x *= damp; c.vel.z *= damp;
if (Math.abs(c.vel.x) < 0.008) c.vel.x = 0;
if (Math.abs(c.vel.z) < 0.008) c.vel.z = 0;
c.pos.x += c.vel.x * dt;
c.pos.z += c.vel.z * dt;
}
// crumb vs crumb
for (let i = 0; i < crumbs.length; i++) {
for (let j = i + 1; j < crumbs.length; j++) {
const a = crumbs[i], b = crumbs[j];
const dx = b.pos.x - a.pos.x, dz = b.pos.z - a.pos.z;
const d2 = dx * dx + dz * dz, min = a.r + b.r;
if (d2 < min * min && d2 > 1e-9) {
const d = Math.sqrt(d2), nx = dx / d, nz = dz / d, ov = min - d;
a.pos.x -= nx * ov * 0.5; a.pos.z -= nz * ov * 0.5;
b.pos.x += nx * ov * 0.5; b.pos.z += nz * ov * 0.5;
const rvx = b.vel.x - a.vel.x, rvz = b.vel.z - a.vel.z;
const vn = rvx * nx + rvz * nz;
if (vn < 0) {
const imp = -vn * 0.55;
a.vel.x -= nx * imp; a.vel.z -= nz * imp;
b.vel.x += nx * imp; b.vel.z += nz * imp;
}
}
}
}
for (const c of crumbs) {
clampToPan(c);
const base = c.pos.x > PAN.front ? PAN.floorY : GROUND;
c.pos.y = base + c.r * 0.8;
c.mesh.position.copy(c.pos);
c.mesh.rotation.x += c.vel.z * dt * 4;
c.mesh.rotation.z -= c.vel.x * dt * 4;
}
}
/* ------------------------------------------------------------------ */
/* Camera controls (hand-rolled orbit / zoom / pan) */
/* ------------------------------------------------------------------ */
const cam = { theta: 0.62, phi: 0.92, radius: 10.5, target: new THREE.Vector3(0.6, 0.18, 0) };
let dragging = false, panning = false, lx = 0, ly = 0;
const dom = renderer.domElement;
dom.addEventListener('pointerdown', e => {
dragging = true; panning = (e.button === 2) || e.shiftKey;
lx = e.clientX; ly = e.clientY;
dom.setPointerCapture(e.pointerId);
});
window.addEventListener('pointermove', e => {
if (!dragging) return;
const dx = e.clientX - lx, dy = e.clientY - ly;
lx = e.clientX; ly = e.clientY;
if (panning) {
const fwd = new THREE.Vector3().subVectors(cam.target, camera.position); fwd.y = 0; fwd.normalize();
const right = new THREE.Vector3(fwd.z, 0, -fwd.x);
const s = cam.radius * 0.0016;
cam.target.addScaledVector(right, -dx * s).addScaledVector(fwd, dy * s);
cam.target.x = THREE.MathUtils.clamp(cam.target.x, -6, 7);
cam.target.z = THREE.MathUtils.clamp(cam.target.z, -6, 6);
} else {
cam.theta -= dx * 0.006;
cam.phi = THREE.MathUtils.clamp(cam.phi - dy * 0.005, 0.12, 1.42);
}
});
window.addEventListener('pointerup', () => { dragging = false; });
dom.addEventListener('contextmenu', e => e.preventDefault());
dom.addEventListener('wheel', e => {
e.preventDefault();
cam.radius = THREE.MathUtils.clamp(cam.radius * (1 + Math.sign(e.deltaY) * 0.09), 3.2, 26);
}, { passive: false });
function updateCamera() {
const { theta, phi, radius, target } = cam;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
}
/* ------------------------------------------------------------------ */
/* HUD */
/* ------------------------------------------------------------------ */
const inPanEl = document.getElementById('inPan');
const barEl = document.getElementById('bar');
let hudTick = 0;
function updateHUD() {
let n = 0;
for (const c of crumbs) if (c.pos.x > PAN.front && Math.abs(c.pos.z) < PAN.halfW) n++;
inPanEl.textContent = n;
barEl.style.width = (100 * n / NUM_CRUMBS) + '%';
}
document.getElementById('reset').addEventListener('click', () => {
scatterCrumbs(); phaseIdx = 0; phaseTime = 0; broomX = prevBroomX = BRM.startX;
});
let paused = false;
const toggleBtn = document.getElementById('toggle');
toggleBtn.addEventListener('click', () => {
paused = !paused;
toggleBtn.textContent = paused ? 'Play' : 'Pause';
});
/* ------------------------------------------------------------------ */
/* Loop */
/* ------------------------------------------------------------------ */
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
if (!paused) {
updateBroom(dt);
broomPush(dt);
updateCrumbs(dt);
updatePuffs(dt);
if (++hudTick % 5 === 0) updateHUD();
}
updateCamera();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
window.addEventListener('resize', () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
});
</script>
</body>
</html>
```