Prompt specification
Build or customize the Three.js 3D scene "Courtyard cleanup cooperation" 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: Courtyard cleanup cooperation
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/courtyard-cleanup-cooperation-x0024
Scene Description Prompt:
Courtyard cleanup cooperation. Place two stylized helpers around a courtyard with leaves and sorting bins; coordinate sweeping and collection so neither helper blocks the other's working path. Please build this with Three.js from cdnjs in one self-contained HTML file, using low-poly forms.
Working Three.js Starter (courtyard-cleanup-cooperation-x0024):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Courtyard Cleanup Co-op</title>
<style>
:root {
color-scheme: light;
--ink: #193238;
--muted: #607477;
--paper: rgba(255, 252, 242, 0.9);
--mint: #2a9d8f;
--gold: #f4a261;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c9ddd7;
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:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
background: var(--paper);
border: 1px solid rgba(25, 50, 56, 0.12);
box-shadow: 0 16px 40px rgba(35, 60, 62, 0.14);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#intro {
top: 20px;
left: 20px;
width: min(360px, calc(100vw - 40px));
border-radius: 18px;
padding: 18px 19px 16px;
pointer-events: none;
}
.eyebrow {
margin: 0 0 5px;
color: #658078;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 4vw, 34px);
line-height: 1.05;
letter-spacing: -0.04em;
}
.subtitle {
margin: 9px 0 14px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.legend {
display: grid;
gap: 8px;
}
.legend-row {
display: grid;
grid-template-columns: 10px 1fr auto;
align-items: center;
gap: 9px;
font-size: 12px;
font-weight: 650;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 50%;
}
.swatch.mint {
background: var(--mint);
}
.swatch.gold {
background: var(--gold);
}
.lane {
color: #6b7c7f;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
#status {
display: flex;
align-items: center;
gap: 8px;
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid rgba(25, 50, 56, 0.1);
color: #52706b;
font-size: 11px;
font-weight: 700;
}
#status::before {
content: "";
width: 8px;
height: 8px;
border-radius: 50%;
background: #49b879;
box-shadow: 0 0 0 4px rgba(73, 184, 121, 0.14);
}
#controls {
right: 20px;
bottom: 20px;
display: flex;
align-items: center;
gap: 8px;
border-radius: 14px;
padding: 9px;
}
button {
appearance: none;
border: 0;
border-radius: 10px;
padding: 9px 12px;
background: #24474b;
color: #fffdf5;
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition: transform 150ms ease, background 150ms ease;
}
button:hover {
background: #2f5b5f;
transform: translateY(-1px);
}
button.secondary {
background: #e8eee8;
color: #315155;
}
.hint {
padding: 0 7px 0 3px;
color: #66787a;
font-size: 11px;
white-space: nowrap;
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #d6e5df;
color: #35585a;
font-size: 13px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 640px) {
#intro {
top: 12px;
left: 12px;
width: min(330px, calc(100vw - 24px));
padding: 14px;
}
.subtitle {
margin-bottom: 10px;
}
#controls {
right: 12px;
bottom: 12px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="app"></div>
<section id="intro" class="panel">
<p class="eyebrow">Shared chore · separated routes</p>
<h1>Courtyard Cleanup</h1>
<p class="subtitle">
Two helpers work independent lanes: leaves stay on the west side,
while litter is collected and sorted on the east.
</p>
<div class="legend">
<div class="legend-row">
<span class="swatch mint"></span>
<span>Helper 1 · Sweeper</span>
<span class="lane">West → Compost</span>
</div>
<div class="legend-row">
<span class="swatch gold"></span>
<span>Helper 2 · Collector</span>
<span class="lane">East → Sorting</span>
</div>
</div>
<div id="status">Both lanes active · no path overlap</div>
</section>
<nav id="controls" class="panel" aria-label="Scene controls">
<span class="hint">Drag to orbit · wheel/pinch to zoom</span>
<button id="pause" class="secondary">Pause</button>
<button id="reset">Reset view</button>
</nav>
<div id="loading">Preparing the courtyard…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const app = document.getElementById("app");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc9ddd7);
scene.fog = new THREE.Fog(0xc9ddd7, 25, 43);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
app.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xfff9e8, 0x668074, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1cf, 3.1);
sun.position.set(8, 13, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x91b9c7, 0.65);
fill.position.set(-9, 7, 4);
scene.add(fill);
// -------------------------------------------------------------------------
// Materials and geometry helpers
// -------------------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.0,
flatShading: true,
...options
});
const M = {
base: material(0xb9aa91),
grout: material(0x9f927d),
wall: material(0xf0dfbd),
wallTrim: material(0xc87958),
wood: material(0xa96f45),
woodDark: material(0x744d36),
soil: material(0x59493a),
leaf: material(0x4e8b5c),
leafLight: material(0x76a85d),
trunk: material(0x79533a),
mint: material(0x2a9d8f),
mintDark: material(0x20766f),
gold: material(0xf4a261),
goldDark: material(0xb96b3f),
skin: material(0xd99b73),
skinDark: material(0xa9674e),
hair: material(0x493a34),
pants: material(0x344c55),
boots: material(0x29383b),
cream: material(0xfff4d9),
blue: material(0x3b82a5),
blueDark: material(0x235d7b),
brown: material(0x8a6042),
brownDark: material(0x5b3e2c),
gray: material(0x7b8988),
grayDark: material(0x4d5c5d),
white: material(0xf7f5e9),
orange: material(0xe98546)
};
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, w, h, d, mat, x = 0, y = 0, z = 0) {
return addMesh(parent, new THREE.BoxGeometry(w, h, d), mat, x, y, z);
}
function addCylinder(
parent,
topRadius,
bottomRadius,
height,
segments,
mat,
x = 0,
y = 0,
z = 0
) {
return addMesh(
parent,
new THREE.CylinderGeometry(
topRadius,
bottomRadius,
height,
segments
),
mat,
x,
y,
z
);
}
function labelTexture(title, subtitle, accent) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#fffaf0";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = accent;
ctx.fillRect(0, 0, canvas.width, 20);
ctx.fillRect(0, 0, 20, canvas.height);
ctx.strokeStyle = "rgba(30,55,58,.18)";
ctx.lineWidth = 8;
ctx.strokeRect(4, 4, canvas.width - 8, canvas.height - 8);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#243e42";
ctx.font = "800 53px system-ui, sans-serif";
ctx.fillText(title, canvas.width / 2, 108);
ctx.fillStyle = "#6a7c7c";
ctx.font = "700 26px system-ui, sans-serif";
ctx.fillText(subtitle, canvas.width / 2, 174);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function makeLabel(title, subtitle, accent, width = 1.15, height = 0.58) {
const mat = new THREE.MeshBasicMaterial({
map: labelTexture(title, subtitle, accent),
toneMapped: false
});
return addMesh(scene, new THREE.PlaneGeometry(width, height), mat);
}
function makeBadge(number, color) {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.beginPath();
ctx.arc(64, 64, 55, 0, Math.PI * 2);
ctx.fillStyle = color;
ctx.fill();
ctx.lineWidth = 8;
ctx.strokeStyle = "#fff9e9";
ctx.stroke();
ctx.fillStyle = "#ffffff";
ctx.font = "900 66px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(String(number), 64, 68);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
toneMapped: false
})
);
sprite.scale.setScalar(0.48);
return sprite;
}
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
const ease = (x) => {
x = clamp(x, 0, 1);
return x * x * (3 - 2 * x);
};
// -------------------------------------------------------------------------
// Courtyard floor, walls, and landscaping
// -------------------------------------------------------------------------
addBox(scene, 18, 0.34, 14, M.base, 0, -0.02, 0);
const tileGeometry = new THREE.BoxGeometry(1.08, 0.07, 1.04);
const tileMaterials = [
material(0xd7c8a9),
material(0xcdbf9f),
material(0xe0d2b4),
material(0xc9bda2),
material(0xd8ccb0)
];
for (let row = 0; row < 11; row++) {
for (let col = 0; col < 15; col++) {
const x = (col - 7) * 1.12;
const z = (row - 5) * 1.08;
const paletteIndex =
(row * 3 + col * 5 + Math.floor(Math.sin(col * row) * 2) + 12) % 5;
const tile = addMesh(
scene,
tileGeometry,
tileMaterials[paletteIndex],
x,
0.18,
z
);
tile.castShadow = false;
}
}
// Colored work zones make the non-overlapping routes explicit.
const westLane = addMesh(
scene,
new THREE.BoxGeometry(3.75, 0.014, 8.4),
new THREE.MeshBasicMaterial({
color: 0x2a9d8f,
transparent: true,
opacity: 0.12,
depthWrite: false
}),
-5.0,
0.224,
-0.05
);
westLane.castShadow = false;
westLane.receiveShadow = false;
const eastLane = addMesh(
scene,
new THREE.BoxGeometry(5.0, 0.014, 8.4),
new THREE.MeshBasicMaterial({
color: 0xf4a261,
transparent: true,
opacity: 0.13,
depthWrite: false
}),
4.8,
0.224,
-0.05
);
eastLane.castShadow = false;
eastLane.receiveShadow = false;
// Back and side courtyard walls.
addBox(scene, 17.7, 1.45, 0.38, M.wall, 0, 0.94, -6.48);
addBox(scene, 17.9, 0.18, 0.54, M.wallTrim, 0, 1.70, -6.48);
addBox(scene, 0.38, 1.1, 10.9, M.wall, -8.72, 0.77, -0.95);
addBox(scene, 0.38, 0.72, 4.2, M.wall, 8.72, 0.58, -4.2);
addBox(scene, 0.55, 0.16, 10.95, M.wallTrim, -8.72, 1.35, -0.95);
// Central sign above the courtyard.
const courtyardSign = makeLabel(
"COURTYARD CO-OP",
"CLEAN • SORT • SHARE",
"#2a9d8f",
3.4,
0.78
);
courtyardSign.position.set(0, 3.65, -6.27);
function makeTree(parent, x, z, scale = 1, planterType = "round") {
const group = new THREE.Group();
group.position.set(x, 0.23, z);
group.scale.setScalar(scale);
parent.add(group);
if (planterType === "round") {
addCylinder(group, 0.74, 0.60, 0.52, 8, M.wallTrim, 0, 0.26, 0);
addCylinder(group, 0.66, 0.66, 0.06, 8, M.soil, 0, 0.53, 0);
} else {
addBox(group, 1.35, 0.52, 1.35, M.wallTrim, 0, 0.26, 0);
addBox(group, 1.19, 0.06, 1.19, M.soil, 0, 0.54, 0);
}
addCylinder(group, 0.13, 0.19, 1.75, 6, M.trunk, 0, 1.38, 0);
const branch1 = addCylinder(
group,
0.08,
0.11,
0.9,
5,
M.trunk,
-0.28,
2.0,
0.05
);
branch1.rotation.z = -0.62;
const branch2 = addCylinder(
group,
0.08,
0.11,
0.82,
5,
M.trunk,
0.25,
2.1,
-0.05
);
branch2.rotation.z = 0.58;
const canopyGeometry = new THREE.IcosahedronGeometry(0.9, 0);
const canopyA = addMesh(
group,
canopyGeometry,
M.leaf,
0,
2.65,
0
);
canopyA.scale.set(1.2, 0.95, 1.05);
const canopyB = addMesh(
group,
canopyGeometry,
M.leafLight,
-0.62,
2.35,
0.12
);
canopyB.scale.set(0.85, 0.78, 0.85);
const canopyC = addMesh(
group,
canopyGeometry,
M.leaf,
0.65,
2.42,
-0.1
);
canopyC.scale.set(0.9, 0.8, 0.92);
return group;
}
makeTree(scene, 0, 0.25, 0.95, "round");
makeTree(scene, -7.55, 4.85, 0.78, "square");
makeTree(scene, 7.55, 4.85, 0.78, "square");
function makeBench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0.23, z);
group.rotation.y = rotation;
scene.add(group);
for (let i = 0; i < 3; i++) {
addBox(group, 2.2, 0.10, 0.17, M.wood, 0, 0.62, -0.25 + i * 0.24);
addBox(group, 2.2, 0.10, 0.17, M.wood, 0, 1.08, -0.39);
}
addBox(group, 0.12, 0.72, 0.55, M.woodDark, -0.85, 0.36, 0);
addBox(group, 0.12, 0.72, 0.55, M.woodDark, 0.85, 0.36, 0);
addBox(group, 0.12, 0.95, 0.12, M.woodDark, -0.85, 0.8, -0.35);
addBox(group, 0.12, 0.95, 0.12, M.woodDark, 0.85, 0.8, -0.35);
}
makeBench(-7.55, 0.8, Math.PI / 2);
makeBench(7.55, 1.25, -Math.PI / 2);
// Flat floor arrows point toward the sorting area.
const arrowShape = new THREE.Shape();
arrowShape.moveTo(0, 0.52);
arrowShape.lineTo(0.32, 0.10);
arrowShape.lineTo(0.12, 0.10);
arrowShape.lineTo(0.12, -0.5);
arrowShape.lineTo(-0.12, -0.5);
arrowShape.lineTo(-0.12, 0.10);
arrowShape.lineTo(-0.32, 0.10);
arrowShape.closePath();
const arrowGeometry = new THREE.ShapeGeometry(arrowShape);
function floorArrow(x, z, color) {
const arrow = addMesh(
scene,
arrowGeometry,
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.8,
side: THREE.DoubleSide
}),
x,
0.242,
z
);
arrow.rotation.x = -Math.PI / 2;
arrow.castShadow = false;
arrow.receiveShadow = false;
}
[-2.5, 0, 2.5].forEach((z) => {
floorArrow(-5.05, z, 0x2a9d8f);
floorArrow(4.8, z, 0xe68a4f);
});
// -------------------------------------------------------------------------
// Sorting bins
// -------------------------------------------------------------------------
const binDefinitions = {
compost: { x: -6.35, z: -4.78, color: M.brown, accent: "#8a6042" },
recycle: { x: 5.35, z: -4.78, color: M.blue, accent: "#3b82a5" },
trash: { x: 7.25, z: -4.78, color: M.gray, accent: "#71817f" }
};
function makeBin(type, definition, title, subtitle) {
const group = new THREE.Group();
group.position.set(definition.x, 0.23, definition.z);
scene.add(group);
addBox(group, 1.16, 1.25, 0.9, definition.color, 0, 0.67, 0);
addBox(group, 1.05, 0.07, 0.79, M.grayDark, 0, 1.32, 0);
// Angled side flaps give the bins a simple low-poly silhouette.
const flapA = addBox(
group,
0.14,
0.42,
0.83,
definition.color,
-0.58,
1.47,
0
);
flapA.rotation.z = -0.28;
const flapB = addBox(
group,
0.14,
0.42,
0.83,
definition.color,
0.58,
1.47,
0
);
flapB.rotation.z = 0.28;
const wheelA = addCylinder(
group,
0.13,
0.13,
0.10,
8,
M.grayDark,
-0.47,
0.15,
0.26
);
wheelA.rotation.z = Math.PI / 2;
const wheelB = wheelA.clone();
wheelB.position.x = 0.47;
group.add(wheelB);
const label = makeLabel(title, subtitle, definition.accent, 0.95, 0.48);
label.position.set(definition.x, 0.98, definition.z + 0.456);
// Simple front icon geometry.
if (type === "compost") {
const icon = addMesh(
group,
new THREE.CircleGeometry(0.16, 5),
M.leafLight,
0,
0.36,
0.456
);
icon.rotation.x = Math.PI / 2;
icon.rotation.z = 0.5;
} else if (type === "recycle") {
for (let i = 0; i < 3; i++) {
const arrow = addBox(
group,
0.22,
0.07,
0.06,
M.cream,
0,
0.36,
0.47
);
arrow.rotation.z = (i * Math.PI * 2) / 3;
}
} else {
addBox(group, 0.28, 0.3, 0.05, M.cream, 0, 0.37, 0.465);
addBox(group, 0.32, 0.06, 0.06, M.cream, 0, 0.55, 0.47);
}
return group;
}
makeBin("compost", binDefinitions.compost, "COMPOST", "ORGANICS");
makeBin("recycle", binDefinitions.recycle, "RECYCLE", "CANS + BOTTLES");
makeBin("trash", binDefinitions.trash, "LANDFILL", "WRAPPERS + CUPS");
// -------------------------------------------------------------------------
// Helpers
// -------------------------------------------------------------------------
function makeHelper({
shirt,
shirtDark,
skin,
hair,
badgeNumber,
badgeColor,
capColor = M.cream
}) {
const root = new THREE.Group();
scene.add(root);
const upper = new THREE.Group();
upper.position.y = 0.8;
root.add(upper);
addCylinder(upper, 0.34, 0.43, 0.72, 8, shirt, 0, 0.36, 0);
addBox(upper, 0.66, 0.09, 0.49, shirtDark, 0, 0.08, 0.015);
addCylinder(upper, 0.12, 0.13, 0.18, 8, skin, 0, 0.78, 0);
addMesh(upper, new THREE.SphereGeometry(0.27, 10, 6), skin, 0, 0.99, 0);
// Hair cap and simple face.
const hairCap = addMesh(
upper,
new THREE.SphereGeometry(0.275, 10, 6),
hair,
0,
1.055,
-0.035
);
hairCap.scale.set(1, 0.58, 1);
addMesh(
upper,
new THREE.SphereGeometry(0.027, 6, 4),
M.grayDark,
-0.09,
1.0,
0.242
);
addMesh(
upper,
new THREE.SphereGeometry(0.027, 6, 4),
M.grayDark,
0.09,
1.0,
0.242
);
const nose = addMesh(
upper,
new THREE.ConeGeometry(0.055, 0.12, 4),
skin,
0,
0.955,
0.29
);
nose.rotation.x = Math.PI / 2;
addCylinder(upper, 0.275, 0.28, 0.12, 10, capColor, 0, 1.19, 0);
addBox(upper, 0.40, 0.055, 0.27, capColor, 0, 1.145, 0.22);
const arms = [];
for (const side of [-1, 1]) {
const arm = new THREE.Group();
arm.position.set(side * 0.39, 0.62, 0);
upper.add(arm);
addCylinder(arm, 0.105, 0.12, 0.52, 7, shirt, 0, -0.25, 0);
addMesh(
arm,
new THREE.SphereGeometry(0.12, 8, 5),
skin,
0,
-0.54,
0
);
arm.rotation.x = -0.38;
arms.push(arm);
}
const legs = [];
for (const side of [-1, 1]) {
const leg = new THREE.Group();
leg.position.set(side * 0.17, 0.76, 0);
root.add(leg);
addCylinder(leg, 0.135, 0.15, 0.60, 7, M.pants, 0, -0.30, 0);
addBox(leg, 0.25, 0.16, 0.39, M.boots, 0, -0.65, 0.08);
legs.push(leg);
}
const badge = makeBadge(badgeNumber, badgeColor);
badge.position.set(0, 2.34, 0);
root.add(badge);
return { root, upper, arms, legs, badge };
}
const sweeper = makeHelper({
shirt: M.mint,
shirtDark: M.mintDark,
skin: M.skin,
hair: M.hair,
badgeNumber: 1,
badgeColor: "#2a9d8f"
});
const collector = makeHelper({
shirt: M.gold,
shirtDark: M.goldDark,
skin: M.skinDark,
hair: M.hair,
badgeNumber: 2,
badgeColor: "#f4a261",
capColor: M.blueDark
});
// Sweeper's broom.
const broomPivot = new THREE.Group();
broomPivot.position.set(0.34, 1.16, 0.42);
sweeper.root.add(broomPivot);
const broomStart = new THREE.Vector3(0, 0, 0);
const broomEnd = new THREE.Vector3(0, -1.02, 0.72);
const broomDirection = broomEnd.clone().sub(broomStart);
const broomHandle = addCylinder(
broomPivot,
0.045,
0.055,
broomDirection.length(),
7,
M.woodDark,
0,
0,
0
);
broomHandle.position.copy(broomStart).add(broomEnd).multiplyScalar(0.5);
broomHandle.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
broomDirection.clone().normalize()
);
addBox(broomPivot, 0.66, 0.11, 0.25, M.wood, 0, -1.02, 0.72);
for (let i = 0; i < 6; i++) {
addBox(
broomPivot,
0.065,
0.20,
0.24,
M.gold,
-0.27 + i * 0.108,
-1.13,
0.72
);
}
// Collector's rear sorting basket.
const basket = new THREE.Group();
basket.position.set(0, 0.38, -0.42);
collector.upper.add(basket);
addBox(basket, 0.65, 0.48, 0.30, M.blueDark, 0, 0, 0);
addBox(basket, 0.52, 0.08, 0.33, M.gold, 0, 0.22, 0);
addBox(basket, 0.08, 0.55, 0.33, M.goldDark, -0.26, 0.02, 0);
addBox(basket, 0.08, 0.55, 0.33, M.goldDark, 0.26, 0.02, 0);
const basketItems = [];
for (let i = 0; i < 4; i++) {
const item = addBox(
basket,
0.14,
0.16,
0.12,
i % 2 ? M.cream : M.blue,
-0.18 + (i % 2) * 0.36,
0.16,
i < 2 ? -0.08 : 0.08
);
item.rotation.y = i * 0.45;
item.visible = false;
basketItems.push(item);
}
// -------------------------------------------------------------------------
// Leaves in the west work lane
// -------------------------------------------------------------------------
const leafGeometry = new THREE.CircleGeometry(0.14, 5);
const leafColors = [
material(0xd98735),
material(0xe3aa3f),
material(0xb85e35),
material(0xd3b43b)
];
const leaves = [];
const leafStarts = [
[-4.55, 2.00],
[-5.35, 1.55],
[-4.05, 1.05],
[-5.70, 0.75],
[-4.90, 0.25],
[-5.25, -0.35],
[-4.35, -0.95],
[-5.75, -1.35],
[-4.80, -1.85],
[-5.55, -2.25]
];
leafStarts.forEach(([x, z], index) => {
const group = new THREE.Group();
scene.add(group);
const leaf = addMesh(group, leafGeometry, leafColors[index % 4]);
leaf.rotation.x = -Math.PI / 2;
leaf.scale.set(1, 0.62, 1);
leaf.castShadow = false;
addBox(group, 0.022, 0.012, 0.16, M.leaf, 0, 0.01, 0.13);
group.position.set(x, 0.27, z);
group.rotation.y = index * 1.37;
leaves.push({
group,
start: new THREE.Vector3(x, 0.27, z),
offsetX: ((index % 3) - 1) * 0.28,
phase: index * 0.83
});
});
// -------------------------------------------------------------------------
// Litter in the east work lane
// -------------------------------------------------------------------------
const litterItems = [];
function makeLitter(type, kind, x, z) {
const group = new THREE.Group();
group.position.set(x, 0.23, z);
scene.add(group);
if (kind === "can") {
addCylinder(group, 0.11, 0.11, 0.36, 8, M.cream, 0, 0.18, 0);
addCylinder(group, 0.115, 0.115, 0.035, 8, M.blue, 0, 0.25, 0);
addCylinder(group, 0.115, 0.115, 0.035, 8, M.blue, 0, 0.10, 0);
} else if (kind === "bottle") {
addCylinder(group, 0.12, 0.14, 0.32, 7, M.leafLight, 0, 0.16, 0);
addCylinder(group, 0.065, 0.065, 0.16, 7, M.leafLight, 0, 0.39, 0);
addCylinder(group, 0.07, 0.07, 0.06, 7, M.cream, 0, 0.49, 0);
} else if (kind === "cup") {
addCylinder(group, 0.13, 0.095, 0.30, 7, M.cream, 0, 0.15, 0);
addCylinder(group, 0.14, 0.14, 0.035, 7, M.orange, 0, 0.32, 0);
} else {
const wrapper = addBox(group, 0.31, 0.05, 0.21, M.orange, 0, 0.03, 0);
wrapper.rotation.y = 0.45;
addBox(group, 0.19, 0.055, 0.08, M.cream, 0.02, 0.035, 0);
}
litterItems.push({
group,
position: new THREE.Vector3(x, 0.23, z),
type,
kind,
taken: false
});
}
makeLitter("recycle", "can", 2.35, 2.00);
makeLitter("recycle", "bottle", 5.55, 1.65);
makeLitter("trash", "wrapper", 3.20, 1.10);
makeLitter("recycle", "can", 6.10, 0.70);
makeLitter("trash", "cup", 4.60, -0.10);
makeLitter("trash", "wrapper", 2.65, -0.85);
makeLitter("recycle", "bottle", 5.70, -1.55);
makeLitter("trash", "wrapper", 3.90, -2.25);
// -------------------------------------------------------------------------
// Animation helpers
// -------------------------------------------------------------------------
function dampAngle(current, target, amount, dt) {
const difference = Math.atan2(
Math.sin(target - current),
Math.cos(target - current)
);
return current + difference * amount;
}
function faceToward(helper, x, z, dt, speed = 10) {
const desired = Math.atan2(x - helper.root.position.x, z - helper.root.position.z);
helper.root.rotation.y = dampAngle(
helper.root.rotation.y,
desired,
1 - Math.exp(-speed * dt),
dt
);
}
function animateHelper(helper, dt, walking, phase, bend = 0) {
helper.root.position.y =
0.23 + (walking ? Math.abs(Math.sin(phase)) * 0.028 : 0);
const stride = walking ? Math.sin(phase) * 0.48 : 0;
helper.legs[0].rotation.x = stride;
helper.legs[1].rotation.x = -stride;
helper.upper.rotation.x = bend;
helper.arms[0].rotation.x = -0.38 - bend * 0.25;
helper.arms[1].rotation.x = -0.38 - bend * 0.25;
}
function moveHelperToward(helper, target, speed, dt) {
const dx = target.x - helper.root.position.x;
const dz = target.z - helper.root.position.z;
const distance = Math.hypot(dx, dz);
if (distance > 0.001) {
const step = Math.min(distance, speed * dt);
helper.root.position.x += (dx / distance) * step;
helper.root.position.z += (dz / distance) * step;
faceToward(helper, target.x, target.z, dt);
}
return distance;
}
// -------------------------------------------------------------------------
// Sweeper animation
// -------------------------------------------------------------------------
const sweepCycle = 12.8;
function updateSweeper(elapsed, dt) {
const cycleTime = elapsed % sweepCycle;
const moveProgress = clamp(cycleTime / 8.3, 0, 1);
const s = ease(moveProgress);
const x = -4.55 - 1.5 * s + 0.3 * Math.sin(Math.PI * s);
const z = 2.55 - 6.05 * s;
sweeper.root.position.x = x;
sweeper.root.position.z = z;
const s2 = ease(Math.min(moveProgress + 0.012, 1));
const x2 = -4.55 - 1.5 * s2 + 0.3 * Math.sin(Math.PI * s2);
const z2 = 2.55 - 6.05 * s2;
faceToward(sweeper, x2, z2, dt, 8);
const walking = cycleTime < 8.3;
animateHelper(sweeper, dt, walking, elapsed * 7.2, 0);
broomPivot.rotation.y = Math.sin(elapsed * 7.5) * 0.16;
broomPivot.rotation.x = Math.sin(elapsed * 3.8) * 0.025;
for (const leaf of leaves) {
if (cycleTime < 8.3) {
// A leaf joins the broom's path after the broom reaches it.
const engagement = clamp(
(leaf.start.z + 0.7 - z) / 0.85,
0,
1
);
const targetX = x + leaf.offsetX;
const targetZ = z - 0.70;
leaf.group.position.x = lerp(
leaf.start.x,
targetX,
engagement
);
leaf.group.position.z = lerp(
leaf.start.z,
targetZ,
engagement
);
leaf.group.position.y =
0.27 + Math.sin(elapsed * 4 + leaf.phase) * 0.012;
leaf.group.scale.setScalar(1);
leaf.group.rotation.y += dt * 0.18;
} else {
// Deposit the gathered leaves into the compost opening.
const deposit = ease((cycleTime - 8.3) / 1.9);
const baseX = -6.05 + leaf.offsetX * 0.35;
const baseZ = -3.98;
leaf.group.position.x = lerp(baseX, -6.35 + leaf.offsetX * 0.12, deposit);
leaf.group.position.z = lerp(baseZ, -4.78, deposit);
leaf.group.position.y = lerp(0.27, 1.52, deposit);
leaf.group.scale.setScalar(1 - deposit * 0.78);
leaf.group.rotation.y += dt * (1.5 + deposit * 4);
}
}
}
// -------------------------------------------------------------------------
// Collector animation and sorting state machine
// -------------------------------------------------------------------------
const collectorStart = new THREE.Vector3(1.65, 0.23, 2.85);
const binDrops = {
recycle: new THREE.Vector3(5.35, 0.23, -3.62),
trash: new THREE.Vector3(7.25, 0.23, -3.62)
};
collector.root.position.set(collectorStart.x, 0.23, collectorStart.z);
let collectorState = "item";
let collectorIndex = 0;
let collectorTimer = 0;
let carried = [];
let binQueue = [];
let binIndex = 0;
let currentSortType = "recycle";
let sortedThisStop = false;
function resetCollectorItems() {
for (const item of litterItems) {
item.taken = false;
item.group.visible = true;
}
collectorIndex = 0;
carried = [];
binQueue = [];
binIndex = 0;
}
function updateCollector(elapsed, dt) {
let walking = false;
let bend = 0;
if (collectorState === "item") {
const item = litterItems[collectorIndex];
const distance = moveHelperToward(
collector,
item.position,
1.48,
dt
);
walking = distance > 0.02;
if (distance < 0.055) {
collectorState = "pick";
collectorTimer = 0;
}
} else if (collectorState === "pick") {
collectorTimer += dt;
bend = Math.sin(clamp(collectorTimer / 0.72, 0, 1) * Math.PI) * 0.42;
const item = litterItems[collectorIndex];
if (collectorTimer > 0.43 && !item.taken) {
item.taken = true;
item.group.visible = false;
carried.push(item.type);
}
if (collectorTimer > 0.72) {
if (carried.length >= 4) {
binQueue = [...new Set(carried)];
binIndex = 0;
collectorState = "bins";
} else {
collectorIndex += 1;
collectorState =
collectorIndex >= litterItems.length ? "bins" : "item";
if (collectorState === "bins") {
binQueue = [...new Set(carried)];
binIndex = 0;
}
}
}
} else if (collectorState === "bins") {
if (binIndex >= binQueue.length) {
carried = [];
binQueue = [];
binIndex = 0;
collectorState =
collectorIndex >= litterItems.length ? "return" : "item";
} else {
currentSortType = binQueue[binIndex];
const distance = moveHelperToward(
collector,
binDrops[currentSortType],
1.55,
dt
);
walking = distance > 0.02;
if (distance < 0.055) {
collectorState = "sort";
collectorTimer = 0;
sortedThisStop = false;
}
}
} else if (collectorState === "sort") {
collectorTimer += dt;
bend = Math.sin(clamp(collectorTimer / 1.1, 0, 1) * Math.PI) * 0.43;
if (collectorTimer > 0.62 && !sortedThisStop) {
const carriedIndex = carried.indexOf(currentSortType);
if (carriedIndex !== -1) carried.splice(carriedIndex, 1);
sortedThisStop = true;
}
if (collectorTimer > 1.1) {
binIndex += 1;
collectorState = "bins";
}
} else if (collectorState === "return") {
const distance = moveHelperToward(
collector,
collectorStart,
1.45,
dt
);
walking = distance > 0.02;
if (distance < 0.06) {
resetCollectorItems();
collectorState = "item";
}
}
basketItems.forEach((item, index) => {
item.visible = index < carried.length;
});
animateHelper(
collector,
dt,
walking,
elapsed * 7.4 + 1.2,
bend
);
}
// -------------------------------------------------------------------------
// Custom orbit camera controls; no external examples or addons
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 0.65, -0.25);
const defaultCamera = {
yaw: 0.72,
pitch: 0.81,
radius: 19.2
};
let cameraYaw = defaultCamera.yaw;
let cameraPitch = defaultCamera.pitch;
let cameraRadius = defaultCamera.radius;
function updateCamera() {
const horizontal = Math.sin(cameraPitch) * cameraRadius;
camera.position.set(
cameraTarget.x + horizontal * Math.sin(cameraYaw),
cameraTarget.y + Math.cos(cameraPitch) * cameraRadius,
cameraTarget.z + horizontal * Math.cos(cameraYaw)
);
camera.lookAt(cameraTarget);
}
const pointers = new Map();
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const previousPositions = [...pointers.values()];
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
cameraYaw -= dx * 0.006;
cameraPitch = clamp(cameraPitch + dy * 0.005, 0.45, 1.18);
} else if (pointers.size === 2) {
const currentPositions = [...pointers.values()];
const previousDistance = Math.hypot(
previousPositions[0].x - previousPositions[1].x,
previousPositions[0].y - previousPositions[1].y
);
const currentDistance = Math.hypot(
currentPositions[0].x - currentPositions[1].x,
currentPositions[0].y - currentPositions[1].y
);
if (previousDistance > 0 && currentDistance > 0) {
cameraRadius = clamp(
cameraRadius * (previousDistance / currentDistance),
12,
28
);
}
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("lostpointercapture", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
12,
28
);
},
{ passive: false }
);
document.getElementById("reset").addEventListener("click", () => {
cameraYaw = defaultCamera.yaw;
cameraPitch = defaultCamera.pitch;
cameraRadius = defaultCamera.radius;
});
let paused = false;
const pauseButton = document.getElementById("pause");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
pauseButton.setAttribute("aria-pressed", String(paused));
});
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
let elapsed = 0;
let previousTime = performance.now();
function render(now) {
requestAnimationFrame(render);
const dt = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (!paused) {
elapsed += dt;
updateSweeper(elapsed, dt);
updateCollector(elapsed, dt);
}
updateCamera();
renderer.render(scene, camera);
}
updateCamera();
renderer.render(scene, camera);
document.getElementById("loading").classList.add("hidden");
requestAnimationFrame(render);
</script>
</body>
</html>
```