Prompt specification
Build or customize the Three.js 3D scene "After-party cleanup corner" 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: After-party cleanup corner
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/after-party-cleanup-corner-x0023
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows a voxel living-room corner after a small party. A sofa, two chairs, a low table, streamers, and empty cups frame an open strip of floor. Place a broom and dustpan beside scattered paper scraps. Animate the broom pushing a few scraps into a pile, then collecting them in the pan; the visible count should move between floor, pile, and pan rather than disappear. Keep the chairs and larger objects stationary throughout the cleanup. Use a warm room palette with brighter paper pieces, and frame the floor low enough that the sweep direction and collection point are easy to follow.
Verify the behavior against the actual geometry and data in each relevant state. Use schematic labels for deliberately synthetic elements.
Technical checks: Render the room and cleanup objects in a visible WebGL canvas. Show paper moving from the floor to a pile and then into the dustpan.
Return one complete HTML document. The file must run in a sandbox allowing inline scripts and the cdnjs Three.js r160 module. Construct procedural assets, use local event handlers and avoid remote assets, runtime network requests besides Three.js, pointer lock and native form submission. Keep the main requested geometry visible in the initial view.
Working Three.js Starter (after-party-cleanup-corner-x0023):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel After-Party Cleanup</title>
<style>
:root {
color-scheme: light;
--ink: #263c43;
--paper: #fff8e9;
--line: rgba(55, 69, 68, 0.2);
--floor: #e45e5e;
--pile: #d89a22;
--pan: #238b82;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8c3a5;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#app, #app canvas {
width: 100%;
height: 100%;
display: block;
}
#app canvas {
touch-action: none;
cursor: grab;
}
#app canvas.dragging { cursor: grabbing; }
.panel {
position: fixed;
z-index: 10;
background: rgba(255, 248, 233, 0.92);
border: 1px solid rgba(66, 75, 68, 0.2);
border-radius: 16px;
box-shadow: 0 14px 40px rgba(55, 39, 25, 0.16);
backdrop-filter: blur(10px);
}
#ledger {
top: 18px;
left: 18px;
width: min(390px, calc(100vw - 36px));
padding: 16px 17px 14px;
}
.eyebrow {
margin: 0 0 4px;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
color: #65716d;
}
h1 {
margin: 0;
font-size: clamp(19px, 2.3vw, 27px);
line-height: 1.08;
letter-spacing: -0.025em;
}
.subtitle {
margin: 7px 0 13px;
color: #66736e;
font-size: 12px;
line-height: 1.4;
}
.counts {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.count {
position: relative;
overflow: hidden;
min-width: 0;
padding: 10px 10px 9px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.42);
}
.count::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 4px;
background: var(--accent);
}
.count span {
display: block;
color: #65716d;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.13em;
}
.count strong {
display: block;
margin-top: 2px;
font-size: 26px;
line-height: 1;
font-variant-numeric: tabular-nums;
}
.count small {
display: block;
margin-top: 4px;
color: #78817d;
font-size: 9px;
}
#floorCount { --accent: var(--floor); }
#pileCount { --accent: var(--pile); }
#panCount { --accent: var(--pan); }
.audit {
display: flex;
justify-content: space-between;
gap: 10px;
margin-top: 10px;
color: #586661;
font-size: 10px;
font-weight: 750;
}
.audit .ok { color: #19776f; }
#status {
margin-top: 10px;
padding-top: 10px;
border-top: 1px solid var(--line);
font-size: 12px;
font-weight: 780;
min-height: 32px;
}
.progress {
height: 5px;
margin-top: 8px;
overflow: hidden;
border-radius: 999px;
background: rgba(57, 76, 71, 0.12);
}
#progressBar {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #e45e5e, #efb63e, #238b82);
transition: width 120ms linear;
}
#controls {
top: 18px;
right: 18px;
display: flex;
gap: 8px;
padding: 8px;
}
button {
appearance: none;
border: 1px solid rgba(45, 67, 63, 0.22);
border-radius: 10px;
padding: 10px 13px;
background: #fffaf0;
color: #314743;
font: inherit;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.025em;
cursor: pointer;
box-shadow: 0 3px 0 rgba(49, 61, 56, 0.12);
}
button:hover { background: #fff; transform: translateY(-1px); }
button:active { transform: translateY(1px); box-shadow: none; }
button:focus-visible { outline: 3px solid rgba(35, 139, 130, 0.35); outline-offset: 2px; }
#hint {
right: 18px;
bottom: 18px;
max-width: 340px;
padding: 10px 13px;
color: #596963;
font-size: 10px;
line-height: 1.45;
}
#hint b { color: #334b46; }
#boot {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #d8c3a5;
color: #314743;
font-size: 13px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 300ms ease, visibility 300ms ease;
}
#boot.hidden {
opacity: 0;
visibility: hidden;
}
@media (max-width: 700px) {
#ledger {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 12px;
}
.subtitle { display: none; }
.counts { margin-top: 10px; }
.count strong { font-size: 22px; }
#controls {
top: auto;
right: 10px;
bottom: 54px;
}
#hint {
right: 10px;
bottom: 10px;
max-width: calc(100vw - 20px);
}
}
</style>
</head>
<body>
<div id="app" aria-label="Interactive Three.js voxel living room"></div>
<section id="ledger" class="panel" aria-live="polite">
<p class="eyebrow">Schematic cleanup study</p>
<h1>Voxel After-Party</h1>
<p class="subtitle">One conserved set of 14 paper meshes moves visibly: floor → pile → dustpan.</p>
<div class="counts">
<div id="floorCount" class="count">
<span>FLOOR</span>
<strong id="floorNumber">14</strong>
<small id="floorMeshes">14 actual meshes</small>
</div>
<div id="pileCount" class="count">
<span>PILE</span>
<strong id="pileNumber">0</strong>
<small id="pileMeshes">0 actual meshes</small>
</div>
<div id="panCount" class="count">
<span>PAN</span>
<strong id="panNumber">0</strong>
<small id="panMeshes">0 actual meshes</small>
</div>
</div>
<div class="audit">
<span id="meshAudit">MESH AUDIT: 14 / 14 VISIBLE</span>
<span class="ok" id="totalAudit">TOTAL: 14 / 14</span>
</div>
<div id="status">Preparing the cleanup lane…</div>
<div class="progress"><div id="progressBar"></div></div>
</section>
<nav id="controls" class="panel" aria-label="Animation controls">
<button id="pauseButton" type="button">PAUSE</button>
<button id="replayButton" type="button">REPLAY CLEANUP</button>
</nav>
<aside id="hint" class="panel">
<b>Camera:</b> drag to orbit, wheel to zoom, double-click to reset.
<br><b>Scene:</b> furniture stays fixed; only the broom, dustpan, and paper move.
</aside>
<div id="boot">Building WebGL room…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.getElementById("app");
const boot = document.getElementById("boot");
const floorNumber = document.getElementById("floorNumber");
const pileNumber = document.getElementById("pileNumber");
const panNumber = document.getElementById("panNumber");
const floorMeshes = document.getElementById("floorMeshes");
const pileMeshes = document.getElementById("pileMeshes");
const panMeshes = document.getElementById("panMeshes");
const meshAudit = document.getElementById("meshAudit");
const totalAudit = document.getElementById("totalAudit");
const statusLine = document.getElementById("status");
const progressBar = document.getElementById("progressBar");
const pauseButton = document.getElementById("pauseButton");
const replayButton = document.getElementById("replayButton");
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
} catch (error) {
boot.textContent = "WebGL could not be initialized on this device.";
console.error(error);
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8c3a5);
scene.fog = new THREE.Fog(0xd8c3a5, 19, 29);
const camera = new THREE.PerspectiveCamera(
48,
window.innerWidth / window.innerHeight,
0.1,
60
);
const cameraTarget = new THREE.Vector3(0, 0.65, -0.45);
const defaultCamera = { yaw: 0.68, elevation: 0.39, radius: 14.2 };
let cameraYaw = defaultCamera.yaw;
let cameraElevation = defaultCamera.elevation;
let cameraRadius = defaultCamera.radius;
function updateCamera() {
const horizontal = Math.cos(cameraElevation) * cameraRadius;
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * horizontal,
cameraTarget.y + Math.sin(cameraElevation) * cameraRadius,
cameraTarget.z + Math.cos(cameraYaw) * horizontal
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xffedcf, 0x6e776d, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe1ad, 3.15);
sun.position.set(-5, 9, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -9;
sun.shadow.camera.right = 9;
sun.shadow.camera.top = 9;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 25;
sun.shadow.bias = -0.00025;
scene.add(sun);
const warmFill = new THREE.PointLight(0xffa76f, 16, 14, 2);
warmFill.position.set(4.2, 3.2, 1.8);
scene.add(warmFill);
const mat = {
floor: new THREE.MeshStandardMaterial({ color: 0xc99b70, roughness: 0.94 }),
floorLine: new THREE.MeshBasicMaterial({ color: 0xb4865e, transparent: true, opacity: 0.28 }),
wall: new THREE.MeshStandardMaterial({ color: 0xefd3ad, roughness: 0.96 }),
wallSide: new THREE.MeshStandardMaterial({ color: 0xe4c39d, roughness: 0.96 }),
trim: new THREE.MeshStandardMaterial({ color: 0xf7e6c9, roughness: 0.88 }),
rug: new THREE.MeshStandardMaterial({ color: 0x718983, roughness: 1 }),
rugEdge: new THREE.MeshStandardMaterial({ color: 0x9ca69b, roughness: 1 }),
sofa: new THREE.MeshStandardMaterial({ color: 0xb95f47, roughness: 0.9 }),
cushion: new THREE.MeshStandardMaterial({ color: 0xd9815f, roughness: 0.95 }),
sofaDark: new THREE.MeshStandardMaterial({ color: 0x8f4939, roughness: 0.92 }),
mustard: new THREE.MeshStandardMaterial({ color: 0xd6a13b, roughness: 0.9 }),
sage: new THREE.MeshStandardMaterial({ color: 0x78937c, roughness: 0.92 }),
pillow: new THREE.MeshStandardMaterial({ color: 0xefb34f, roughness: 0.95 }),
wood: new THREE.MeshStandardMaterial({ color: 0x77503a, roughness: 0.86 }),
table: new THREE.MeshStandardMaterial({ color: 0xaa7147, roughness: 0.84 }),
dark: new THREE.MeshStandardMaterial({ color: 0x3c4c49, roughness: 0.86 }),
broomHead: new THREE.MeshStandardMaterial({ color: 0xe0a12c, roughness: 0.86 }),
bristles: new THREE.MeshStandardMaterial({ color: 0xd8bd79, roughness: 1 }),
pan: new THREE.MeshStandardMaterial({ color: 0xe45e5e, roughness: 0.78 }),
panDark: new THREE.MeshStandardMaterial({ color: 0xa84242, roughness: 0.84 }),
cup: new THREE.MeshStandardMaterial({ color: 0xfff7df, roughness: 0.72, side: THREE.DoubleSide }),
marker: new THREE.MeshBasicMaterial({ color: 0xf3bd42, transparent: true, opacity: 0.85 }),
ring: new THREE.MeshBasicMaterial({ color: 0x36a095, transparent: true, opacity: 0.7 })
};
function box(parent, w, h, d, x, y, z, material) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderBetween(parent, a, b, radius, material, segments = 10) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, segments),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Room shell and tiled voxel floor.
box(scene, 11.4, 0.18, 8.2, 0, -0.09, 0, mat.floor);
box(scene, 11.4, 3.45, 0.18, 0, 1.725, -4.05, mat.wall);
box(scene, 0.18, 3.45, 2.65, -5.61, 1.725, -2.72, mat.wallSide);
box(scene, 11.3, 0.22, 0.13, 0, 0.11, -3.91, mat.trim);
box(scene, 0.13, 0.22, 2.6, -5.47, 0.11, -2.72, mat.trim);
for (let x = -5; x <= 5; x += 1) {
box(scene, 0.018, 0.008, 8.0, x, 0.005, 0, mat.floorLine);
}
for (let z = -3; z <= 3; z += 1) {
box(scene, 11.1, 0.008, 0.018, 0, 0.005, z, mat.floorLine);
}
// Rug sits behind the cleanup lane.
box(scene, 7.8, 0.035, 3.1, 0.7, 0.023, -2.03, mat.rug);
box(scene, 7.45, 0.038, 2.76, 0.7, 0.041, -2.03, mat.rugEdge);
// Sofa.
const sofa = new THREE.Group();
sofa.position.set(-2.35, 0, -2.78);
scene.add(sofa);
for (const x of [-1.45, 1.45]) {
for (const z of [-0.48, 0.48]) {
box(sofa, 0.16, 0.36, 0.16, x, 0.18, z, mat.wood);
}
}
box(sofa, 3.55, 0.48, 1.36, 0, 0.49, 0, mat.sofaDark);
box(sofa, 3.38, 1.34, 0.34, 0, 1.33, -0.52, mat.sofa);
box(sofa, 0.34, 0.92, 1.38, -1.72, 0.84, 0, mat.sofa);
box(sofa, 0.34, 0.92, 1.38, 1.72, 0.84, 0, mat.sofa);
const sofaCushions = [-1.08, 0, 1.08];
sofaCushions.forEach((x) => {
box(sofa, 1.02, 0.24, 1.03, x, 0.77, 0.08, mat.cushion);
box(sofa, 1.01, 0.82, 0.22, x, 1.28, -0.31, mat.cushion);
});
const pillowA = box(sofa, 0.54, 0.53, 0.18, -1.0, 1.19, 0.02, mat.pillow);
pillowA.rotation.z = 0.11;
const pillowB = box(sofa, 0.50, 0.48, 0.18, 1.08, 1.16, 0.01, mat.mustard);
pillowB.rotation.z = -0.12;
function makeChair(x, z, upholstery, rotation) {
const chair = new THREE.Group();
chair.position.set(x, 0, z);
chair.rotation.y = rotation;
scene.add(chair);
for (const lx of [-0.46, 0.46]) {
for (const lz of [-0.39, 0.39]) {
box(chair, 0.14, 0.52, 0.14, lx, 0.26, lz, mat.wood);
}
}
box(chair, 1.18, 0.28, 1.08, 0, 0.60, 0, upholstery);
box(chair, 1.16, 1.02, 0.24, 0, 1.10, -0.43, upholstery);
box(chair, 0.18, 0.63, 1.08, -0.57, 0.89, 0, upholstery);
box(chair, 0.18, 0.63, 1.08, 0.57, 0.89, 0, upholstery);
return chair;
}
makeChair(2.25, -2.55, mat.mustard, -0.12);
makeChair(4.25, -1.93, mat.sage, -0.34);
// Low table.
const table = new THREE.Group();
table.position.set(0.0, 0, -1.74);
scene.add(table);
box(table, 2.1, 0.18, 1.08, 0, 0.55, 0, mat.table);
for (const x of [-0.82, 0.82]) {
for (const z of [-0.37, 0.37]) {
box(table, 0.13, 0.48, 0.13, x, 0.24, z, mat.wood);
}
}
// Empty cups: open cylinders with visible rims and no liquid surface.
function makeCup(x, y, z, tipped = false) {
const cup = new THREE.Group();
cup.position.set(x, y, z);
if (tipped) {
cup.rotation.z = Math.PI * 0.5;
cup.rotation.y = 0.35;
}
scene.add(cup);
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.145, 0.115, 0.34, 18, 1, true),
mat.cup
);
body.position.y = 0.17;
body.castShadow = true;
body.receiveShadow = true;
cup.add(body);
const rim = new THREE.Mesh(
new THREE.TorusGeometry(0.145, 0.018, 7, 20),
mat.cup
);
rim.rotation.x = Math.PI * 0.5;
rim.position.y = 0.34;
rim.castShadow = true;
cup.add(rim);
const bottom = new THREE.Mesh(
new THREE.CircleGeometry(0.112, 18),
new THREE.MeshStandardMaterial({ color: 0xd9cbb6, roughness: 0.9 })
);
bottom.rotation.x = -Math.PI * 0.5;
bottom.position.y = 0.012;
cup.add(bottom);
return cup;
}
makeCup(-0.46, 0.645, -1.72);
makeCup(0.45, 0.645, -1.83);
makeCup(4.35, 0.02, 0.42, true);
makeCup(-4.25, 0.0, 0.25);
// Procedural party streamers on the back wall.
function addStreamer(points, color) {
const curve = new THREE.CatmullRomCurve3(points);
const geometry = new THREE.TubeGeometry(curve, 44, 0.027, 7, false);
const material = new THREE.MeshStandardMaterial({ color, roughness: 0.65 });
const streamer = new THREE.Mesh(geometry, material);
streamer.castShadow = true;
scene.add(streamer);
}
addStreamer([
new THREE.Vector3(-4.7, 2.92, -3.91),
new THREE.Vector3(-4.1, 2.58, -3.85),
new THREE.Vector3(-3.55, 2.76, -3.88),
new THREE.Vector3(-3.08, 2.34, -3.83),
new THREE.Vector3(-2.55, 2.48, -3.87)
], 0xe95d62);
addStreamer([
new THREE.Vector3(-2.2, 3.05, -3.9),
new THREE.Vector3(-1.7, 2.64, -3.84),
new THREE.Vector3(-1.25, 2.83, -3.88),
new THREE.Vector3(-0.75, 2.37, -3.82),
new THREE.Vector3(-0.2, 2.55, -3.87)
], 0x36a9a0);
addStreamer([
new THREE.Vector3(0.3, 3.08, -3.9),
new THREE.Vector3(0.8, 2.71, -3.84),
new THREE.Vector3(1.25, 2.86, -3.88),
new THREE.Vector3(1.76, 2.43, -3.82),
new THREE.Vector3(2.22, 2.66, -3.87)
], 0xf0b83d);
addStreamer([
new THREE.Vector3(2.7, 3.02, -3.9),
new THREE.Vector3(3.15, 2.58, -3.84),
new THREE.Vector3(3.64, 2.79, -3.88),
new THREE.Vector3(4.08, 2.39, -3.83)
], 0xd887bd);
// Broom: head, bristles, and an angled handle. It translates along +X only.
const broom = new THREE.Group();
broom.position.set(-3.35, 0, 1.52);
scene.add(broom);
box(broom, 0.24, 0.27, 1.18, 0, 0.34, 0, mat.broomHead);
for (let i = 0; i < 15; i++) {
const z = -0.54 + i * (1.08 / 14);
box(broom, 0.29, 0.25, 0.052, 0.025, 0.135, z, mat.bristles);
}
cylinderBetween(
broom,
new THREE.Vector3(-0.02, 0.43, 0.22),
new THREE.Vector3(-0.22, 1.82, 1.12),
0.045,
mat.wood,
10
);
cylinderBetween(
broom,
new THREE.Vector3(-0.02, 0.43, 0.22),
new THREE.Vector3(-0.10, 0.72, 0.38),
0.065,
mat.broomHead,
10
);
// Dustpan: an open tray facing -X, with a long handle toward +X.
const dustpan = new THREE.Group();
dustpan.position.set(3.45, 0, 1.52);
scene.add(dustpan);
box(dustpan, 1.02, 0.07, 0.80, 0, 0.035, 0, mat.pan);
box(dustpan, 0.09, 0.16, 0.80, 0.465, 0.115, 0, mat.panDark);
box(dustpan, 1.02, 0.16, 0.075, 0, 0.115, -0.365, mat.panDark);
box(dustpan, 1.02, 0.16, 0.075, 0, 0.115, 0.365, mat.panDark);
box(dustpan, 1.15, 0.10, 0.15, 1.02, 0.115, 0, mat.panDark);
box(dustpan, 0.48, 0.15, 0.22, 1.65, 0.115, 0, mat.pan);
// Schematic floor markers.
const pileCenter = new THREE.Vector3(1.52, 0, 1.52);
const collectionRing = new THREE.Mesh(
new THREE.TorusGeometry(0.48, 0.026, 8, 48),
mat.ring
);
collectionRing.rotation.x = Math.PI * 0.5;
collectionRing.position.set(pileCenter.x, 0.025, pileCenter.z);
scene.add(collectionRing);
box(scene, 2.8, 0.025, 0.075, -1.05, 0.025, 2.87, mat.marker);
const arrowHead = new THREE.Mesh(
new THREE.ConeGeometry(0.19, 0.43, 3),
mat.marker
);
arrowHead.rotation.z = -Math.PI * 0.5;
arrowHead.position.set(0.64, 0.04, 2.87);
scene.add(arrowHead);
function makeLabel(text, width, x, y, z, background = "#344c49") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = background;
ctx.globalAlpha = 0.92;
ctx.beginPath();
ctx.roundRect(8, 16, 496, 96, 22);
ctx.fill();
ctx.globalAlpha = 1;
ctx.strokeStyle = "rgba(255,255,255,0.58)";
ctx.lineWidth = 4;
ctx.stroke();
ctx.fillStyle = "#fff9e9";
ctx.font = "800 40px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 65);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(width, width * 0.25, 1);
sprite.position.set(x, y, z);
sprite.renderOrder = 20;
scene.add(sprite);
return sprite;
}
makeLabel("OPEN SWEEP LANE", 2.65, -1.15, 0.43, 2.55);
makeLabel("PILE ZONE", 1.65, 1.50, 0.42, 2.47, "#9b6b20");
makeLabel("DUSTPAN", 1.45, 2.78, 0.45, 2.42, "#a84242");
makeLabel("SWEEP DIRECTION +X", 2.75, -1.05, 0.36, 3.22, "#8a6a25");
// Exactly 14 physical paper meshes. Their state is the source of truth for the HUD.
const paperColors = [
0xff4f70, 0xffca3a, 0x35d2bd, 0x4f9cff,
0xf582d7, 0xfff0cf, 0xff7a45, 0x5ad36e,
0xeb5eb5, 0x38c6d9, 0xffdf3d, 0x7b7cff,
0xff785b, 0xffffff
];
const basePositions = [
[-2.78, 1.17], [-2.42, 1.91], [-2.08, 1.34], [-1.77, 1.82],
[-1.42, 1.18], [-1.10, 1.96], [-0.76, 1.48], [-0.43, 1.13],
[-0.14, 1.89], [0.14, 1.49], [0.43, 1.10], [0.61, 1.88],
[0.87, 1.49], [-0.52, 2.08]
];
const papers = [];
const paperGeometry = new THREE.BoxGeometry(0.24, 0.018, 0.16);
basePositions.forEach(([x, z], index) => {
const material = new THREE.MeshStandardMaterial({
color: paperColors[index],
roughness: 0.86,
metalness: 0
});
const mesh = new THREE.Mesh(paperGeometry, material);
mesh.position.set(x, 0.026, z);
mesh.rotation.y = (index * 1.73) % Math.PI;
mesh.scale.set(
0.88 + (index % 4) * 0.055,
1,
0.90 + (index % 3) * 0.06
);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.visible = true;
scene.add(mesh);
papers.push({
mesh,
state: "floor",
base: mesh.position.clone(),
baseRotation: mesh.rotation.y,
triggered: false,
motion: null
});
});
function actualCounts() {
return papers.reduce((counts, paper) => {
counts[paper.state] += 1;
return counts;
}, { floor: 0, pile: 0, pan: 0 });
}
function pileTarget(index) {
const column = index % 5;
const row = Math.floor(index / 5) % 3;
const layer = Math.floor(index / 15);
return new THREE.Vector3(
pileCenter.x + (column - 2) * 0.13,
0.048 + layer * 0.025,
pileCenter.z + (row - 1) * 0.13
);
}
function panTarget(index) {
const column = index % 4;
const row = Math.floor(index / 4) % 4;
const layer = Math.floor(index / 16);
return new THREE.Vector3(
dustpan.position.x + (column - 1.5) * 0.13,
0.093 + layer * 0.02,
dustpan.position.z + (row - 1.5) * 0.115
);
}
function beginTransfer(paper, destinationState, target, duration = 0.72) {
paper.motion = {
from: paper.mesh.position.clone(),
to: target.clone(),
fromRotation: paper.mesh.rotation.y,
toRotation: paper.mesh.rotation.y + (destinationState === "pan" ? 0.32 : 0.18),
t: 0,
duration,
destinationState
};
}
function updateMotions(dt) {
for (const paper of papers) {
if (!paper.motion) continue;
const motion = paper.motion;
motion.t += dt;
const raw = THREE.MathUtils.clamp(motion.t / motion.duration, 0, 1);
const eased = raw * raw * (3 - 2 * raw);
paper.mesh.position.lerpVectors(motion.from, motion.to, eased);
paper.mesh.position.y += Math.sin(raw * Math.PI) * 0.13;
paper.mesh.rotation.y = THREE.MathUtils.lerp(
motion.fromRotation,
motion.toRotation,
eased
);
if (raw >= 1) {
paper.state = motion.destinationState;
paper.mesh.position.copy(motion.to);
paper.mesh.visible = true;
paper.motion = null;
updateLedger();
}
}
}
function noTransfersRunning() {
return papers.every((paper) => paper.motion === null);
}
let phase = "ready";
let phaseTime = 0;
let paused = false;
let collectIndex = 0;
let collectTimer = 0;
function updateLedger() {
const counts = actualCounts();
floorNumber.textContent = counts.floor;
pileNumber.textContent = counts.pile;
panNumber.textContent = counts.pan;
floorMeshes.textContent = `${counts.floor} actual meshes`;
pileMeshes.textContent = `${counts.pile} actual meshes`;
panMeshes.textContent = `${counts.pan} actual meshes`;
const visible = papers.filter((paper) => paper.mesh.visible).length;
meshAudit.textContent = `MESH AUDIT: ${visible} / ${papers.length} VISIBLE`;
totalAudit.textContent = `TOTAL: ${counts.floor + counts.pile + counts.pan} / ${papers.length}`;
const descriptions = {
ready: "Ready — 14 bright scraps are visible on the open floor.",
sweep: `Broom sweeping: ${counts.floor} floor, ${counts.pile} pile, ${counts.pan} pan.`,
settle: "The pile is formed; the dustpan is moving toward the collection point.",
approach: "Dustpan aligned with the pile. Paper counts remain unchanged during approach.",
collect: `Collecting visibly: ${counts.floor} floor, ${counts.pile} pile, ${counts.pan} pan.`,
done: `Complete — all ${papers.length} visible paper meshes are in the dustpan.`
};
statusLine.textContent = descriptions[phase];
}
function resetCleanup(startImmediately = false) {
papers.forEach((paper, index) => {
paper.state = "floor";
paper.triggered = false;
paper.motion = null;
paper.mesh.visible = true;
paper.mesh.position.copy(paper.base);
paper.mesh.rotation.set(0, paper.baseRotation, 0);
});
broom.position.x = -3.35;
dustpan.position.x = 3.45;
collectIndex = 0;
collectTimer = 0;
phaseTime = 0;
phase = startImmediately ? "sweep" : "ready";
updateLedger();
}
function updateCleanup(dt) {
if (paused) return;
phaseTime += dt;
if (phase === "ready") {
if (phaseTime >= 0.9) {
phase = "sweep";
phaseTime = 0;
updateLedger();
}
} else if (phase === "sweep") {
const t = THREE.MathUtils.clamp(phaseTime / 6.8, 0, 1);
broom.position.x = THREE.MathUtils.lerp(-3.35, 1.14, t);
for (const paper of papers) {
if (!paper.triggered && broom.position.x >= paper.base.x - 0.18) {
paper.triggered = true;
const index = papers.indexOf(paper);
beginTransfer(paper, "pile", pileTarget(index), 0.72);
}
}
if (phaseTime >= 6.8 && papers.every((paper) => paper.triggered) && noTransfersRunning()) {
phase = "settle";
phaseTime = 0;
updateLedger();
}
} else if (phase === "settle") {
if (phaseTime >= 0.45) {
phase = "approach";
phaseTime = 0;
updateLedger();
}
} else if (phase === "approach") {
const t = THREE.MathUtils.clamp(phaseTime / 1.25, 0, 1);
const eased = t * t * (3 - 2 * t);
dustpan.position.x = THREE.MathUtils.lerp(3.45, 2.13, eased);
if (t >= 1) {
phase = "collect";
phaseTime = 0;
collectIndex = 0;
collectTimer = 0;
updateLedger();
}
} else if (phase === "collect") {
collectTimer += dt;
if (collectIndex < papers.length && collectTimer >= 0.235) {
collectTimer -= 0.235;
const paper = papers[collectIndex];
if (paper.state === "pile") {
beginTransfer(paper, "pan", panTarget(collectIndex), 0.42);
}
collectIndex += 1;
}
if (collectIndex >= papers.length && noTransfersRunning() &&
papers.every((paper) => paper.state === "pan")) {
phase = "done";
phaseTime = 0;
updateLedger();
}
}
updateMotions(dt);
updateLedger();
}
function cleanupProgress() {
if (phase === "ready") return 0.025;
if (phase === "sweep") return 0.05 + 0.50 * THREE.MathUtils.clamp(phaseTime / 6.8, 0, 1);
if (phase === "settle") return 0.56;
if (phase === "approach") return 0.59 + 0.11 * THREE.MathUtils.clamp(phaseTime / 1.25, 0, 1);
if (phase === "collect") return 0.70 + 0.29 * THREE.MathUtils.clamp(collectIndex / papers.length, 0, 1);
return 1;
}
replayButton.addEventListener("click", () => {
resetCleanup(true);
});
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "RESUME" : "PAUSE";
pauseButton.setAttribute("aria-pressed", String(paused));
});
// Small custom orbit implementation; no examples/addons are used.
let dragging = false;
let dragX = 0;
let dragY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
dragX = event.clientX;
dragY = event.clientY;
renderer.domElement.classList.add("dragging");
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
cameraYaw -= (event.clientX - dragX) * 0.006;
cameraElevation = THREE.MathUtils.clamp(
cameraElevation + (event.clientY - dragY) * 0.0045,
0.18,
0.78
);
dragX = event.clientX;
dragY = event.clientY;
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
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 + event.deltaY * 0.01, 9.5, 18.5);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => {
cameraYaw = defaultCamera.yaw;
cameraElevation = defaultCamera.elevation;
cameraRadius = defaultCamera.radius;
updateCamera();
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
resetCleanup(false);
updateLedger();
let previousTime = 0;
let firstFrame = true;
renderer.setAnimationLoop((time) => {
const dt = previousTime ? Math.min((time - previousTime) / 1000, 0.05) : 0;
previousTime = time;
updateCleanup(dt);
progressBar.style.width = `${(cleanupProgress() * 100).toFixed(1)}%`;
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
boot.classList.add("hidden");
}
});
</script>
</body>
</html>
```