Prompt specification
Build or customize the Three.js 3D scene "Public Space Stewardship Puzzle" 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: Public Space Stewardship Puzzle
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/public-space-stewardship-puzzle-x3272
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows care and etiquette in shared public space. Create a small square after a community event with displaced chairs and litter. Players restore access and seating according to visible spatial constraints, with deterministic completion checks. Low-poly.
Working Three.js Starter (public-space-stewardship-puzzle-x3272):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Common Ground — A Public Space Etiquette Game</title>
<style>
:root {
--ink: #173a35;
--muted: #607772;
--paper: rgba(250, 252, 248, 0.94);
--line: rgba(23, 58, 53, 0.13);
--green: #238a72;
--mint: #b9e8d9;
--blue: #3d87c9;
--compost: #42a66e;
--landfill: #d66f58;
--shadow: 0 14px 45px rgba(31, 69, 62, 0.16);
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: #dce9e3;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#world {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.panel {
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.75);
box-shadow: var(--shadow);
backdrop-filter: blur(15px);
-webkit-backdrop-filter: blur(15px);
}
#brief {
position: fixed;
top: 18px;
left: 18px;
width: min(420px, calc(100vw - 36px));
padding: 17px 18px 15px;
border-radius: 20px;
pointer-events: none;
z-index: 5;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
color: var(--green);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 4px rgba(35, 138, 114, 0.12);
}
h1 {
margin: 0;
font-size: clamp(22px, 2.3vw, 31px);
line-height: 1.05;
letter-spacing: -0.035em;
}
#brief p {
margin: 9px 0 12px;
max-width: 365px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.brief-actions {
display: flex;
align-items: center;
gap: 9px;
pointer-events: auto;
}
button {
border: 0;
font: inherit;
cursor: pointer;
}
.reset-button {
padding: 8px 12px;
border-radius: 10px;
background: var(--ink);
color: white;
font-size: 12px;
font-weight: 750;
transition: transform 0.15s, background 0.15s;
}
.reset-button:hover {
transform: translateY(-1px);
background: #25564e;
}
.microcopy {
color: var(--muted);
font-size: 10px;
font-weight: 650;
}
#checklist {
position: fixed;
top: 18px;
right: 18px;
width: 285px;
padding: 16px;
border-radius: 20px;
z-index: 5;
pointer-events: none;
}
.checklist-heading {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 12px;
}
.checklist-heading strong {
font-size: 13px;
letter-spacing: 0.02em;
}
#overall {
color: var(--green);
font-size: 11px;
font-weight: 850;
}
.progress-track {
height: 5px;
overflow: hidden;
margin-bottom: 14px;
border-radius: 10px;
background: #e6ece8;
}
#progress-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #48ad8e, #8ed4b7);
transition: width 0.35s ease;
}
.task {
display: grid;
grid-template-columns: 22px 1fr auto;
align-items: center;
gap: 9px;
min-height: 46px;
border-top: 1px solid var(--line);
}
.task:first-of-type { border-top: 0; }
.task-dot {
width: 18px;
height: 18px;
border: 2px solid #b9c6c1;
border-radius: 50%;
background: #fff;
transition: 0.2s;
}
.task.done .task-dot {
border-color: var(--green);
background: var(--green);
box-shadow: inset 0 0 0 4px white;
}
.task-title {
font-size: 12px;
font-weight: 800;
}
.task-subtitle {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9.5px;
font-weight: 550;
}
.task-value {
color: var(--muted);
font-size: 10px;
font-weight: 850;
white-space: nowrap;
}
.task.done .task-value { color: var(--green); }
.legend {
display: flex;
gap: 6px;
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid var(--line);
}
.legend span {
flex: 1;
padding: 6px 4px;
border-radius: 8px;
color: white;
text-align: center;
font-size: 8px;
font-weight: 900;
letter-spacing: 0.07em;
}
.legend .recycle { background: var(--blue); }
.legend .compost { background: var(--compost); }
.legend .landfill { background: var(--landfill); }
#guide {
position: fixed;
left: 18px;
bottom: 18px;
max-width: 445px;
padding: 13px 15px;
border-radius: 17px;
z-index: 5;
pointer-events: none;
}
.guide-title {
margin-bottom: 6px;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.04em;
text-transform: uppercase;
}
#guide p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
#camera-tools {
position: fixed;
right: 18px;
bottom: 18px;
display: flex;
gap: 6px;
padding: 7px;
border-radius: 15px;
z-index: 6;
}
#camera-tools button {
min-width: 36px;
height: 34px;
padding: 0 10px;
border-radius: 9px;
background: #edf2ef;
color: var(--ink);
font-size: 13px;
font-weight: 850;
transition: background 0.15s, transform 0.15s;
}
#camera-tools button:hover {
background: #dceae4;
transform: translateY(-1px);
}
#toast {
position: fixed;
left: 50%;
bottom: 104px;
max-width: min(470px, calc(100vw - 32px));
padding: 11px 16px;
border-radius: 12px;
background: rgba(20, 48, 43, 0.93);
color: white;
box-shadow: var(--shadow);
font-size: 12px;
font-weight: 700;
text-align: center;
opacity: 0;
transform: translate(-50%, 12px);
transition: opacity 0.2s, transform 0.2s;
pointer-events: none;
z-index: 20;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#toast.error { background: rgba(153, 67, 49, 0.95); }
#toast.success { background: rgba(27, 116, 87, 0.96); }
#success {
position: fixed;
inset: 0;
display: grid;
place-items: center;
padding: 20px;
background: rgba(19, 47, 42, 0.28);
backdrop-filter: blur(5px);
opacity: 0;
visibility: hidden;
transition: opacity 0.35s, visibility 0.35s;
z-index: 30;
}
#success.show {
opacity: 1;
visibility: visible;
}
.success-card {
width: min(440px, 100%);
padding: 30px;
border-radius: 25px;
background: #fbfcf8;
box-shadow: 0 25px 80px rgba(20, 52, 46, 0.3);
text-align: center;
transform: translateY(15px) scale(0.98);
transition: transform 0.35s;
}
#success.show .success-card {
transform: translateY(0) scale(1);
}
.success-mark {
display: grid;
place-items: center;
width: 60px;
height: 60px;
margin: 0 auto 16px;
border-radius: 50%;
background: var(--mint);
color: var(--green);
font-size: 30px;
font-weight: 900;
}
.success-card h2 {
margin: 0;
font-size: 29px;
letter-spacing: -0.035em;
}
.success-card p {
margin: 12px auto 22px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.success-stats {
display: flex;
justify-content: center;
gap: 18px;
margin-bottom: 22px;
color: var(--green);
font-size: 11px;
font-weight: 850;
}
#continue-button {
padding: 11px 20px;
border-radius: 11px;
background: var(--green);
color: white;
font-weight: 800;
}
@media (max-width: 760px) {
#brief {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 13px 14px;
}
#brief p { display: none; }
.eyebrow { margin-bottom: 5px; }
#checklist {
top: 106px;
right: 10px;
width: 225px;
padding: 12px;
}
.task { min-height: 38px; }
.task-subtitle { display: none; }
.legend { margin-top: 8px; padding-top: 8px; }
#guide {
left: 10px;
right: 10px;
bottom: 66px;
max-width: none;
padding: 10px 12px;
}
#guide p { font-size: 10px; }
#camera-tools { right: 10px; bottom: 10px; }
#toast { bottom: 150px; }
}
</style>
</head>
<body>
<main id="world" aria-label="Interactive low-poly public square"></main>
<section id="brief" class="panel">
<div class="eyebrow">Common Ground / Etiquette Simulation</div>
<h1>Leave the square ready.</h1>
<p>
The community event is over, but chairs have shifted and litter remains.
Restore the seating, keep the access route clear, and sort the litter
before the next person arrives.
</p>
<div class="brief-actions">
<button id="reset-button" class="reset-button">Reset square</button>
<span class="microcopy">Drag items to move them</span>
</div>
</section>
<aside id="checklist" class="panel" aria-label="Completion checklist">
<div class="checklist-heading">
<strong>Ready for the next event</strong>
<span id="overall">0 / 3</span>
</div>
<div class="progress-track"><div id="progress-fill"></div></div>
<div id="task-seat" class="task">
<span class="task-dot"></span>
<span>
<span class="task-title">Restore the seating</span>
<span class="task-subtitle">Eight marked bays, all facing the stage</span>
</span>
<span id="seat-value" class="task-value">0 / 8</span>
</div>
<div id="task-access" class="task">
<span class="task-dot"></span>
<span>
<span class="task-title">Keep access clear</span>
<span class="task-subtitle">The mint route from gate to stage</span>
</span>
<span id="access-value" class="task-value">BLOCKED</span>
</div>
<div id="task-litter" class="task">
<span class="task-dot"></span>
<span>
<span class="task-title">Sort the remaining litter</span>
<span class="task-subtitle">Match each colored tag to its bin</span>
</span>
<span id="litter-value" class="task-value">0 / 9</span>
</div>
<div class="legend" aria-label="Litter sorting legend">
<span class="recycle">RECYCLE</span>
<span class="compost">COMPOST</span>
<span class="landfill">LANDFILL</span>
</div>
</aside>
<section id="guide" class="panel">
<div class="guide-title">How to care for the space</div>
<p>
Drag each chair into a mint bay; the chair back should face away from you
toward the stage. Drag litter to the bin matching its colored tag.
Nothing may remain in the 2.4 m mint access lane.
</p>
</section>
<div id="camera-tools" class="panel" aria-label="Camera controls">
<button id="zoom-out" title="Zoom out">−</button>
<button id="rotate-left" title="Rotate left">↶</button>
<button id="rotate-right" title="Rotate right">↷</button>
<button id="zoom-in" title="Zoom in">+</button>
<button id="reset-camera" title="Reset camera">⌂</button>
</div>
<div id="toast" role="status" aria-live="polite"></div>
<div id="success" role="dialog" aria-modal="true" aria-labelledby="success-title">
<div class="success-card">
<div class="success-mark">✓</div>
<h2 id="success-title">A considerate close.</h2>
<p>
The seating is aligned, the access route is open, and every piece of
litter has been sorted. The square is ready for the next community.
</p>
<div class="success-stats">
<span>8 CHAIRS</span>
<span>9 ITEMS SORTED</span>
<span>ACCESS CLEAR</span>
</div>
<button id="continue-button">Keep enjoying the square</button>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const world = document.getElementById("world");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce9e3);
scene.fog = new THREE.Fog(0xdce9e3, 31, 58);
const renderer = new THREE.WebGLRenderer({ antialias: true });
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;
renderer.domElement.setAttribute("aria-label", "Drag chairs and litter to restore the public square");
world.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-16, 16, 10, -10, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0, 0.25);
let cameraYaw = 0.66;
let cameraPitch = 0.82;
let cameraZoom = 0.98;
const hemisphere = new THREE.HemisphereLight(0xf7fff9, 0x738a7f, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff3d9, 3.2);
sun.position.set(-9, 17, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9dfff, 0.65);
fill.position.set(11, 8, -10);
scene.add(fill);
const categoryInfo = {
recycle: { label: "RECYCLE", color: 0x3d87c9, css: "#3d87c9" },
compost: { label: "COMPOST", color: 0x42a66e, css: "#42a66e" },
landfill: { label: "LANDFILL", color: 0xd66f58, css: "#d66f58" }
};
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0.0,
flatShading: true,
...options
});
}
function addBox(width, height, depth, mat, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(width, height, depth), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(radiusTop, radiusBottom, height, mat, x, y, z, parent = scene, segments = 8) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
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 panelTexture(lines, options = {}) {
const canvas = document.createElement("canvas");
canvas.width = options.width || 768;
canvas.height = options.height || 256;
const ctx = canvas.getContext("2d");
const linesArray = Array.isArray(lines) ? lines : [lines];
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (options.bg) {
ctx.fillStyle = options.bg;
roundedRect(
ctx,
8,
8,
canvas.width - 16,
canvas.height - 16,
options.radius || 34
);
ctx.fill();
}
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = options.fg || "#173a35";
ctx.font = `850 ${options.fontSize || (linesArray.length > 1 ? 54 : 66)}px system-ui, sans-serif`;
const startY = canvas.height / 2 - ((linesArray.length - 1) * 62) / 2;
linesArray.forEach((line, index) => {
ctx.fillText(line, canvas.width / 2, startY + index * 62);
});
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function groundText(text, x, z, width = 2, height = 0.45, color = "#176d5d") {
const texture = panelTexture(text, {
fg: color,
bg: null,
fontSize: 58,
width: 768,
height: 192
});
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide
})
);
mesh.rotation.x = -Math.PI / 2;
mesh.position.set(x, 0.052, z);
scene.add(mesh);
return mesh;
}
function spriteLabel(text, x, y, z, width = 2.1, height = 0.7, fg = "#ffffff", bg = "#173a35") {
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: panelTexture(text, { fg, bg, fontSize: 61 }),
transparent: true,
depthWrite: false
})
);
sprite.position.set(x, y, z);
sprite.scale.set(width, height, 1);
scene.add(sprite);
return sprite;
}
// Plaza
const pavingMat = material(0xcbd6cd);
const pavingAccentMat = material(0xd5ddd5);
addBox(18, 0.36, 18, pavingMat, 0, -0.18, 0);
const grid = new THREE.GridHelper(18, 18, 0x9eaea4, 0xaebbb2);
grid.position.y = 0.008;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
// Access route
const routeMat = new THREE.MeshStandardMaterial({
color: 0x70c8aa,
emissive: 0x173f35,
emissiveIntensity: 0.07,
roughness: 1,
transparent: true,
opacity: 0.58,
depthWrite: false
});
addBox(2.4, 0.025, 11.65, routeMat, 0, 0.025, 1.625);
const routeEdgeMat = new THREE.MeshBasicMaterial({
color: 0xeffff8,
transparent: true,
opacity: 0.85
});
addBox(0.045, 0.035, 11.65, routeEdgeMat, -1.2, 0.045, 1.625);
addBox(0.045, 0.035, 11.65, routeEdgeMat, 1.2, 0.045, 1.625);
const arrowShape = new THREE.Shape();
arrowShape.moveTo(0, 0.68);
arrowShape.lineTo(0.38, 0.14);
arrowShape.lineTo(0.14, 0.14);
arrowShape.lineTo(0.14, -0.62);
arrowShape.lineTo(-0.14, -0.62);
arrowShape.lineTo(-0.14, 0.14);
arrowShape.lineTo(-0.38, 0.14);
arrowShape.closePath();
const arrowGeometry = new THREE.ShapeGeometry(arrowShape);
const arrowMaterial = new THREE.MeshBasicMaterial({
color: 0xf4fff8,
transparent: true,
opacity: 0.86,
side: THREE.DoubleSide
});
[5.65, 2.75, -0.15, -3.05].forEach((z) => {
const arrow = new THREE.Mesh(arrowGeometry, arrowMaterial);
arrow.rotation.x = -Math.PI / 2;
arrow.position.set(0, 0.06, z);
scene.add(arrow);
});
groundText("2.4 m CLEAR ROUTE", 0, 6.65, 2.12, 0.4, "#ffffff");
groundText("FACE STAGE", 5.85, -0.65, 1.65, 0.38, "#2d7568");
// Stage and community-event backdrop
const stageMat = material(0x9b7257);
const stageTopMat = material(0xc99b74);
addBox(8.2, 0.42, 3.1, stageMat, 0, 0.21, -6.25);
addBox(8.25, 0.08, 3.15, stageTopMat, 0, 0.46, -6.25);
addBox(2.4, 0.18, 0.72, stageMat, 0, 0.09, -4.42);
const backdropMat = material(0xf3e6cc);
addBox(7.7, 2.65, 0.2, backdropMat, 0, 1.83, -7.48);
const eventSign = new THREE.Mesh(
new THREE.PlaneGeometry(7.25, 2.18),
new THREE.MeshBasicMaterial({
map: panelTexture(
["COMMON GROUND", "COMMUNITY EVENT"],
{ fg: "#24584c", bg: "#f3e6cc", fontSize: 59 }
),
side: THREE.DoubleSide
})
);
eventSign.position.set(0, 1.88, -7.365);
scene.add(eventSign);
const postMat = material(0x456d63);
[-3.65, 3.65].forEach((x) => {
addCylinder(0.09, 0.11, 3.25, postMat, x, 1.62, -4.65);
});
// Low-poly bunting
const stringMat = material(0x55716a);
const string = addCylinder(0.025, 0.025, 7.4, stringMat, 0, 3.0, -4.65);
string.rotation.z = Math.PI / 2;
const flagColors = [0xe36c56, 0xf0b54c, 0x4b9a80, 0x4f87b5, 0xe58d76];
for (let i = 0; i < 10; i++) {
const x = -3.25 + i * 0.72;
const y = 2.82 - Math.abs(i - 4.5) * 0.055;
const flagGeometry = new THREE.BufferGeometry();
flagGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
-0.22, 0, 0,
0.22, 0, 0,
0, -0.45, 0
], 3)
);
flagGeometry.computeVertexNormals();
const flag = new THREE.Mesh(flagGeometry, material(flagColors[i % flagColors.length], { side: THREE.DoubleSide }));
flag.position.set(x, y, -4.63);
flag.castShadow = true;
scene.add(flag);
}
// Gate posts
const gateMat = material(0x355b53);
[-1.5, 1.5].forEach((x) => {
addCylinder(0.13, 0.16, 1.2, gateMat, x, 0.6, 7.62);
addCylinder(0.18, 0.18, 0.12, material(0xe5bd5c), x, 1.24, 7.62);
});
// Planters and angular trees
function addTree(x, z, canopyColor) {
const planterMat = material(0xb6a087);
const planter = addBox(1.8, 0.55, 1.8, planterMat, x, 0.275, z);
planter.rotation.y = Math.PI / 4;
addCylinder(0.14, 0.19, 1.65, material(0x795b43), x, 1.25, z, scene, 7);
const canopy = new THREE.Mesh(
new THREE.IcosahedronGeometry(1.15, 0),
material(canopyColor)
);
canopy.position.set(x, 2.48, z);
canopy.scale.set(1, 1.12, 0.95);
canopy.castShadow = true;
canopy.receiveShadow = true;
scene.add(canopy);
}
addTree(-7.0, 6.4, 0x4e9b75);
addTree(7.0, 6.55, 0x6d9f65);
addTree(-7.25, -6.85, 0x619877);
// Chair bays
const slotDefinitions = [
{ id: "L1", x: -2.7, z: -1.65 },
{ id: "L2", x: -4.7, z: -1.65 },
{ id: "L3", x: -2.7, z: 0.85 },
{ id: "L4", x: -4.7, z: 0.85 },
{ id: "R1", x: 2.7, z: -1.65 },
{ id: "R2", x: 4.7, z: -1.65 },
{ id: "R3", x: 2.7, z: 0.85 },
{ id: "R4", x: 4.7, z: 0.85 }
];
const slots = slotDefinitions.map((definition) => {
const markerMaterial = new THREE.MeshStandardMaterial({
color: 0x4fb99b,
emissive: 0x000000,
roughness: 0.9,
transparent: true,
opacity: 0.63
});
const outline = new THREE.Group();
outline.position.set(definition.x, 0, definition.z);
scene.add(outline);
addBox(1.43, 0.035, 0.055, markerMaterial, 0, 0.045, 0.69, outline);
addBox(1.43, 0.035, 0.055, markerMaterial, 0, 0.045, -0.69, outline);
addBox(0.055, 0.035, 1.43, markerMaterial, 0.69, 0.045, 0, outline);
addBox(0.055, 0.035, 1.43, markerMaterial, -0.69, 0.045, 0, outline);
groundText(definition.id, definition.x, definition.z + 0.93, 0.48, 0.22, "#287b69");
return {
...definition,
rotation: 0,
markerMaterial,
occupant: null
};
});
const chairs = [];
const litter = [];
const draggableRoots = [];
function makeChair(color, x, z, rotation) {
const group = new THREE.Group();
const seatMaterial = material(color);
const frameMaterial = material(0x294b49);
addBox(0.94, 0.14, 0.86, seatMaterial, 0, 0.72, 0, group);
addBox(0.94, 0.64, 0.14, seatMaterial, 0, 1.12, 0.39, group);
[-0.37, 0.37].forEach((legX) => {
[-0.31, 0.31].forEach((legZ) => {
addBox(0.09, 0.7, 0.09, frameMaterial, legX, 0.35, legZ, group);
});
addBox(0.08, 0.72, 0.08, frameMaterial, legX, 1.02, 0.36, group);
});
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
const chair = {
id: `chair-${chairs.length + 1}`,
type: "chair",
group,
baseY: 0,
start: { x, z, rotation },
slotIndex: null
};
group.userData.entity = chair;
chairs.push(chair);
draggableRoots.push(group);
return chair;
}
const chairStarts = [
[-6.45, 2.55, 0.48],
[5.75, -1.85, -0.68],
[-0.55, 2.45, 1.38],
[3.2, 4.35, 0.28],
[-6.05, -2.55, -0.42],
[0.65, 5.55, 2.18],
[6.1, 3.4, 0.7],
[-3.6, -3.75, 1.12]
];
const chairColors = [0xe56f52, 0xf0b74e, 0x477d9b, 0xe56f52, 0xf0b74e, 0x477d9b, 0xe56f52, 0xf0b74e];
chairStarts.forEach((start, index) => makeChair(chairColors[index], ...start));
// Sorting station
addBox(1.65, 0.1, 6.65, material(0xbac9bf), 7.12, 0.05, 1.65);
spriteLabel("SORT LITTER", 7.12, 2.75, 4.85, 2.45, 0.72, "#ffffff", "#315b52");
const bins = [];
function addBin(category, z) {
const color = categoryInfo[category].color;
const bodyMaterial = material(color);
const darkMaterial = material(0x263b37);
const x = 7.12;
addBox(1.05, 1.12, 1.05, bodyMaterial, x, 0.61, z);
addBox(0.82, 0.07, 0.82, darkMaterial, x, 1.20, z);
const ringMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.28,
side: THREE.DoubleSide,
depthWrite: false
});
const ring = new THREE.Mesh(new THREE.RingGeometry(0.64, 0.77, 24), ringMaterial);
ring.rotation.x = -Math.PI / 2;
ring.position.set(x, 0.12, z);
scene.add(ring);
spriteLabel(categoryInfo[category].label, x, 1.72, z, 1.95, 0.65, "#ffffff", `#${color.toString(16).padStart(6, "0")}`);
const bin = { category, x, z, ringMaterial, count: 0 };
bins.push(bin);
return bin;
}
addBin("recycle", 4.12);
addBin("compost", 1.65);
addBin("landfill", -0.82);
function addLitterModel(group, type, category) {
const tagMaterial = new THREE.MeshBasicMaterial({
color: categoryInfo[category].color,
transparent: true,
opacity: 0.76,
side: THREE.DoubleSide,
depthWrite: false
});
const tag = new THREE.Mesh(new THREE.RingGeometry(0.3, 0.37, 16), tagMaterial);
tag.rotation.x = -Math.PI / 2;
tag.position.y = 0.015;
group.add(tag);
if (type === "can") {
addCylinder(0.17, 0.17, 0.54, material(0xc9d7db), 0, 0.3, 0, group, 10);
addCylinder(0.18, 0.18, 0.08, material(0x3d87c9), 0, 0.47, 0, group, 10);
addCylinder(0.15, 0.15, 0.05, material(0xaab9b9), 0, 0.59, 0, group, 10);
} else if (type === "bottle") {
addCylinder(0.15, 0.19, 0.55, material(0x7eb8a6, { transparent: true, opacity: 0.88 }), 0, 0.31, 0, group, 8);
addCylinder(0.08, 0.13, 0.2, material(0x7eb8a6), 0, 0.66, 0, group, 8);
addCylinder(0.09, 0.09, 0.1, material(0x3d87c9), 0, 0.8, 0, group, 8);
} else if (type === "carton") {
addBox(0.32, 0.48, 0.28, material(0xe4c18b), 0, 0.27, 0, group);
addBox(0.22, 0.03, 0.2, material(0x3d87c9), 0, 0.52, 0, group);
} else if (type === "banana") {
const banana = new THREE.Mesh(
new THREE.TorusGeometry(0.26, 0.075, 5, 10, Math.PI * 1.35),
material(0xf1c84b)
);
banana.rotation.x = Math.PI / 2;
banana.rotation.z = -0.4;
banana.position.y = 0.13;
banana.castShadow = true;
group.add(banana);
} else if (type === "food") {
const food = new THREE.Mesh(new THREE.IcosahedronGeometry(0.25, 0), material(0xd99443));
food.position.y = 0.22;
food.scale.set(1.15, 0.7, 0.9);
food.castShadow = true;
group.add(food);
} else if (type === "apple") {
const apple = new THREE.Mesh(new THREE.IcosahedronGeometry(0.23, 0), material(0xbe5e4b));
apple.position.y = 0.21;
apple.scale.set(0.9, 1, 0.9);
apple.castShadow = true;
group.add(apple);
addCylinder(0.025, 0.035, 0.18, material(0x795b43), 0, 0.4, 0, group, 6);
} else if (type === "tissue") {
const tissue = new THREE.Mesh(new THREE.IcosahedronGeometry(0.27, 0), material(0xf4eee5));
tissue.position.y = 0.2;
tissue.scale.set(1.2, 0.65, 0.95);
tissue.castShadow = true;
group.add(tissue);
} else if (type === "wrapper") {
const wrapper = addBox(0.48, 0.035, 0.31, material(0xe58c74), 0, 0.07, 0, group);
wrapper.rotation.y = 0.3;
} else if (type === "cup") {
addCylinder(0.17, 0.11, 0.46, material(0xd8c8b6), 0, 0.27, 0, group, 8);
addCylinder(0.18, 0.18, 0.045, material(0xd66f58), 0, 0.51, 0, group, 8);
}
}
const litterStarts = [
{ type: "can", category: "recycle", x: -0.35, z: 3.2 },
{ type: "bottle", category: "recycle", x: -5.7, z: 2.7 },
{ type: "carton", category: "recycle", x: 3.2, z: -2.35 },
{ type: "banana", category: "compost", x: 0.55, z: 5.25 },
{ type: "food", category: "compost", x: -4.8, z: -3.1 },
{ type: "apple", category: "compost", x: 5.8, z: 5.55 },
{ type: "tissue", category: "landfill", x: -0.45, z: -2.2 },
{ type: "wrapper", category: "landfill", x: 2.8, z: 5.8 },
{ type: "cup", category: "landfill", x: -6.3, z: 5.4 }
];
litterStarts.forEach((start) => {
const group = new THREE.Group();
addLitterModel(group, start.type, start.category);
group.position.set(start.x, 0.02, start.z);
group.rotation.y = (start.x + start.z) * 0.37;
scene.add(group);
const item = {
id: `litter-${litter.length + 1}`,
type: "litter",
category: start.category,
itemType: start.type,
group,
baseY: 0.02,
start: { x: start.x, z: start.z, rotation: group.rotation.y },
collected: false
};
group.userData.entity = item;
litter.push(item);
draggableRoots.push(group);
});
// Camera implementation: no external controls addon.
function updateCamera() {
const distance = 26;
const horizontal = Math.cos(cameraPitch) * distance;
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * horizontal,
cameraTarget.y + Math.sin(cameraPitch) * distance,
cameraTarget.z + Math.cos(cameraYaw) * horizontal
);
camera.lookAt(cameraTarget);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const halfHeight = Math.max(9.5, 11 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
updateCamera();
}
window.addEventListener("resize", resize);
resize();
// Interaction
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const groundPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), 0);
const groundHit = new THREE.Vector3();
let drag = null;
let cameraDrag = null;
let hoveredEntity = null;
let completionActive = false;
let toastTimer = 0;
const toast = document.getElementById("toast");
const successOverlay = document.getElementById("success");
function showToast(message, type = "") {
toast.textContent = message;
toast.className = `show ${type}`;
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
toast.className = "";
}, 2600);
}
function updatePointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function entityFromObject(object) {
let current = object;
while (current) {
if (current.userData.entity) return current.userData.entity;
current = current.parent;
}
return null;
}
function pickEntity(event) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(draggableRoots, true);
for (const hit of hits) {
const entity = entityFromObject(hit.object);
if (!entity) continue;
if (entity.collected) continue;
if (entity.group.visible === false) continue;
return entity;
}
return null;
}
function setHovered(entity) {
if (hoveredEntity === entity) return;
if (hoveredEntity && hoveredEntity !== drag?.entity) {
hoveredEntity.group.scale.setScalar(1);
}
hoveredEntity = entity;
if (hoveredEntity && hoveredEntity !== drag?.entity) {
hoveredEntity.group.scale.setScalar(1.045);
}
renderer.domElement.style.cursor = hoveredEntity ? "grab" : "default";
}
function clearSlotHighlights() {
slots.forEach((slot) => {
slot.markerMaterial.color.setHex(0x4fb99b);
slot.markerMaterial.emissive.setHex(0x000000);
slot.markerMaterial.opacity = 0.63;
});
}
function clearBinHighlights() {
bins.forEach((bin) => {
bin.ringMaterial.color.setHex(categoryInfo[bin.category].color);
bin.ringMaterial.opacity = 0.28;
});
}
function findNearestSlot(position, entity, maxDistance = 1.0) {
let nearest = null;
let nearestDistance = maxDistance;
slots.forEach((slot, index) => {
if (slot.occupant && slot.occupant !== entity) return;
const distance = Math.hypot(position.x - slot.x, position.z - slot.z);
if (distance < nearestDistance) {
nearest = slot;
nearestDistance = distance;
nearest.index = index;
}
});
return nearest;
}
function findNearestBin(position, maxDistance = 1.35) {
let nearest = null;
let nearestDistance = maxDistance;
bins.forEach((bin) => {
const distance = Math.hypot(position.x - bin.x, position.z - bin.z);
if (distance < nearestDistance) {
nearest = bin;
nearestDistance = distance;
}
});
return nearest;
}
function updateDragPreview(entity) {
clearSlotHighlights();
clearBinHighlights();
if (entity.type === "chair") {
const slot = findNearestSlot(entity.group.position, entity, 1.05);
if (slot) {
slot.markerMaterial.color.setHex(0x83efd0);
slot.markerMaterial.emissive.setHex(0x1d6f5c);
slot.markerMaterial.opacity = 0.95;
}
} else {
const bin = findNearestBin(entity.group.position, 1.45);
if (bin) {
bin.ringMaterial.color.setHex(
bin.category === entity.category ? 0xffffff : 0xff5f48
);
bin.ringMaterial.opacity = 0.9;
}
}
}
function releaseChairSlot(chair) {
if (chair.slotIndex === null) return;
slots[chair.slotIndex].occupant = null;
chair.slotIndex = null;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
if (event.button === 2) {
cameraDrag = { mode: "orbit", x: event.clientX, y: event.clientY };
event.preventDefault();
return;
}
if (event.button === 1) {
cameraDrag = { mode: "pan", x: event.clientX, y: event.clientY };
event.preventDefault();
return;
}
if (event.button !== 0) return;
const entity = pickEntity(event);
if (!entity) return;
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
if (!raycaster.ray.intersectPlane(groundPlane, groundHit)) return;
drag = {
entity,
startX: event.clientX,
startY: event.clientY,
moved: false,
offsetX: entity.group.position.x - groundHit.x,
offsetZ: entity.group.position.z - groundHit.z,
previousSlotIndex: entity.type === "chair" ? entity.slotIndex : null,
slotReleased: false
};
entity.group.scale.setScalar(1.065);
renderer.domElement.style.cursor = "grabbing";
event.preventDefault();
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (cameraDrag) {
const dx = event.clientX - cameraDrag.x;
const dy = event.clientY - cameraDrag.y;
cameraDrag.x = event.clientX;
cameraDrag.y = event.clientY;
if (cameraDrag.mode === "orbit") {
cameraYaw -= dx * 0.006;
cameraPitch = THREE.MathUtils.clamp(cameraPitch + dy * 0.005, 0.43, 1.32);
} else {
const units = (camera.top - camera.bottom) / camera.zoom / renderer.domElement.clientHeight;
cameraTarget.x = THREE.MathUtils.clamp(cameraTarget.x + dx * units, -4.5, 4.5);
cameraTarget.z = THREE.MathUtils.clamp(cameraTarget.z + dy * units, -4.5, 4.5);
}
updateCamera();
return;
}
if (drag) {
const distance = Math.hypot(
event.clientX - drag.startX,
event.clientY - drag.startY
);
if (distance > 4) drag.moved = true;
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
if (raycaster.ray.intersectPlane(groundPlane, groundHit)) {
drag.entity.group.position.x = groundHit.x + drag.offsetX;
drag.entity.group.position.z = groundHit.z + drag.offsetZ;
drag.entity.group.position.y = drag.entity.baseY + 0.28;
if (
drag.entity.type === "chair" &&
drag.moved &&
!drag.slotReleased
) {
releaseChairSlot(drag.entity);
drag.slotReleased = true;
}
updateDragPreview(drag.entity);
}
return;
}
const entity = pickEntity(event);
setHovered(entity);
});
function finishDrag(event) {
if (!drag) return;
const entity = drag.entity;
if (entity.type === "chair") {
if (!drag.moved && drag.previousSlotIndex !== null) {
const slot = slots[drag.previousSlotIndex];
entity.slotIndex = drag.previousSlotIndex;
slot.occupant = entity;
entity.group.position.set(slot.x, entity.baseY, slot.z);
entity.group.rotation.y = slot.rotation;
showToast("Chair returned to its marked bay.", "success");
} else {
const slot = findNearestSlot(entity.group.position, entity, 1.0);
if (slot) {
if (slot.occupant && slot.occupant !== entity) {
showToast("That bay is already occupied. Try the empty outline.", "error");
} else {
slot.occupant = entity;
entity.slotIndex = slot.index;
entity.group.position.set(slot.x, entity.baseY, slot.z);
entity.group.rotation.y = slot.rotation;
showToast(`${slot.id} is aligned and facing the stage.`, "success");
}
} else {
showToast("Place the chair fully inside an empty mint bay.", "error");
}
}
} else if (entity.type === "litter") {
const bin = findNearestBin(entity.group.position, 1.35);
if (bin) {
if (bin.category === entity.category) {
entity.collected = true;
entity.group.visible = false;
entity.group.position.set(bin.x, entity.baseY, bin.z);
bin.count += 1;
showToast(
`${entity.itemType.toUpperCase()} sorted into ${categoryInfo[entity.category].label}.`,
"success"
);
} else {
entity.group.position.set(entity.start.x, entity.baseY, entity.start.z);
entity.group.rotation.y = entity.start.rotation;
showToast(
`That item belongs in ${categoryInfo[entity.category].label}. Match its colored tag.`,
"error"
);
}
} else if (!drag.moved) {
showToast("Drag this item to the bin with the matching colored label.");
}
}
entity.group.position.y = entity.baseY;
entity.group.scale.setScalar(1);
drag = null;
clearSlotHighlights();
clearBinHighlights();
renderer.domElement.style.cursor = "grab";
evaluateState();
}
renderer.domElement.addEventListener("pointerup", finishDrag);
renderer.domElement.addEventListener("pointercancel", (event) => {
if (cameraDrag) {
cameraDrag = null;
return;
}
if (drag) {
drag.entity.group.position.y = drag.entity.baseY;
drag.entity.group.scale.setScalar(1);
drag = null;
clearSlotHighlights();
clearBinHighlights();
}
});
renderer.domElement.addEventListener("pointerleave", () => {
if (!drag) setHovered(null);
});
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * (event.deltaY > 0 ? 0.9 : 1.1),
0.65,
1.7
);
updateCamera();
},
{ passive: false }
);
// Deterministic completion checks
function overlapsAccessLane(x, z, margin) {
return (
Math.abs(x) < 1.2 + margin &&
z > -4.3 - margin &&
z < 7.45 + margin
);
}
function evaluateState() {
const seated = slots.filter((slot) => slot.occupant !== null).length;
const sorted = litter.filter((item) => item.collected).length;
let accessBlockers = 0;
chairs.forEach((chair) => {
if (overlapsAccessLane(chair.group.position.x, chair.group.position.z, 0.48)) {
accessBlockers += 1;
}
});
litter.forEach((item) => {
if (
!item.collected &&
overlapsAccessLane(item.group.position.x, item.group.position.z, 0.08)
) {
accessBlockers += 1;
}
});
const seatComplete = seated === slots.length;
const accessComplete = accessBlockers === 0;
const litterComplete = sorted === litter.length;
document.getElementById("seat-value").textContent = `${seated} / ${slots.length}`;
document.getElementById("litter-value").textContent = `${sorted} / ${litter.length}`;
document.getElementById("access-value").textContent = accessComplete
? "CLEAR"
: `${accessBlockers} BLOCKER${accessBlockers === 1 ? "" : "S"}`;
document.getElementById("task-seat").classList.toggle("done", seatComplete);
document.getElementById("task-access").classList.toggle("done", accessComplete);
document.getElementById("task-litter").classList.toggle("done", litterComplete);
const completedTasks = [seatComplete, accessComplete, litterComplete].filter(Boolean).length;
document.getElementById("overall").textContent = `${completedTasks} / 3`;
document.getElementById("progress-fill").style.width = `${(completedTasks / 3) * 100}%`;
if (seatComplete && accessComplete && litterComplete && !completionActive) {
completionActive = true;
successOverlay.classList.add("show");
launchConfetti();
showToast("The square is ready for the next person.", "success");
}
}
// Fixed, deterministic celebratory confetti
const confetti = [];
const confettiColors = [0xe56f52, 0xf0b74e, 0x4b9a80, 0x4f87b5, 0xe58d76];
function launchConfetti() {
for (let i = 0; i < 36; i++) {
const mesh = addBox(
0.12,
0.035,
0.25,
material(confettiColors[i % confettiColors.length]),
-6 + (i % 12) * 1.08,
4.3 + (i % 3) * 0.55,
-4.5 + Math.floor(i / 12) * 0.9
);
mesh.castShadow = false;
confetti.push({
mesh,
velocityX: ((i % 5) - 2) * 0.36,
velocityY: 0.25 + (i % 4) * 0.08,
velocityZ: ((i % 3) - 1) * 0.27,
spin: 0.025 + (i % 4) * 0.008
});
}
}
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
for (const piece of confetti) {
piece.mesh.position.x += piece.velocityX * delta;
piece.mesh.position.y -= piece.velocityY * delta;
piece.mesh.position.z += piece.velocityZ * delta;
piece.mesh.rotation.x += piece.spin * delta;
piece.mesh.rotation.z += piece.spin * 0.7 * delta;
if (piece.mesh.position.y < 0.1) {
piece.mesh.visible = false;
}
}
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
// UI controls
document.getElementById("reset-button").addEventListener("click", () => {
location.reload();
});
document.getElementById("continue-button").addEventListener("click", () => {
successOverlay.classList.remove("show");
});
document.getElementById("zoom-in").addEventListener("click", () => {
cameraZoom = THREE.MathUtils.clamp(cameraZoom * 1.12, 0.65, 1.7);
updateCamera();
});
document.getElementById("zoom-out").addEventListener("click", () => {
cameraZoom = THREE.MathUtils.clamp(cameraZoom * 0.89, 0.65, 1.7);
updateCamera();
});
document.getElementById("rotate-left").addEventListener("click", () => {
cameraYaw -= 0.16;
updateCamera();
});
document.getElementById("rotate-right").addEventListener("click", () => {
cameraYaw += 0.16;
updateCamera();
});
document.getElementById("reset-camera").addEventListener("click", () => {
cameraYaw = 0.66;
cameraPitch = 0.82;
cameraZoom = 0.98;
cameraTarget.set(0, 0, 0.25);
updateCamera();
});
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLButtonElement) return;
if (event.key === "ArrowLeft") {
cameraYaw -= 0.08;
updateCamera();
} else if (event.key === "ArrowRight") {
cameraYaw += 0.08;
updateCamera();
} else if (event.key === "ArrowUp") {
cameraPitch = THREE.MathUtils.clamp(cameraPitch + 0.05, 0.43, 1.32);
updateCamera();
} else if (event.key === "ArrowDown") {
cameraPitch = THREE.MathUtils.clamp(cameraPitch - 0.05, 0.43, 1.32);
updateCamera();
} else if (event.key === "+" || event.key === "=") {
cameraZoom = THREE.MathUtils.clamp(cameraZoom * 1.1, 0.65, 1.7);
updateCamera();
} else if (event.key === "-") {
cameraZoom = THREE.MathUtils.clamp(cameraZoom * 0.9, 0.65, 1.7);
updateCamera();
} else if (event.key.toLowerCase() === "r") {
cameraYaw = 0.66;
cameraPitch = 0.82;
cameraZoom = 0.98;
cameraTarget.set(0, 0, 0.25);
updateCamera();
}
});
evaluateState();
</script>
</body>
</html>
```