Prompt specification
Build or customize the Three.js 3D scene "Community recycling courtyard" 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: Community recycling courtyard
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/community-recycling-courtyard-x0056
Scene Description Prompt:
A low-poly courtyard recycling station where users sort modeled items into material streams and accepted items update fill levels. One HTML file, Three.js from cdnjs.
Working Three.js Starter (community-recycling-courtyard-x0056):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#dfe8df" />
<title>Circular Courtyard — Recycling Station</title>
<style>
:root {
--ink: #24342e;
--muted: #6f7b74;
--paper: rgba(250, 249, 244, 0.92);
--paper-solid: #faf9f4;
--line: rgba(36, 52, 46, 0.12);
--shadow: 0 18px 50px rgba(48, 63, 55, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dfe8df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.texture {
position: fixed;
inset: 0;
pointer-events: none;
opacity: 0.13;
background:
radial-gradient(circle at 15% 15%, rgba(255,255,255,.8), transparent 28%),
radial-gradient(circle at 80% 70%, rgba(60,80,65,.14), transparent 30%);
mix-blend-mode: soft-light;
}
header {
position: fixed;
z-index: 10;
top: 22px;
left: 24px;
right: 24px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20px;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
pointer-events: auto;
}
.brand-mark {
width: 48px;
height: 48px;
display: grid;
place-items: center;
flex: 0 0 auto;
border-radius: 15px;
background: var(--ink);
color: white;
box-shadow: var(--shadow);
}
.brand-mark svg {
width: 27px;
height: 27px;
}
.brand-copy {
padding-top: 1px;
text-shadow: 0 1px 12px rgba(255,255,255,.65);
}
.eyebrow {
margin: 0 0 3px;
color: #65766c;
font-size: 10px;
font-weight: 800;
letter-spacing: .18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 34px);
line-height: 1;
letter-spacing: -.04em;
}
.brand-copy > p:last-child {
margin: 7px 0 0;
color: #5f6d65;
font-size: 13px;
}
.top-actions {
display: flex;
gap: 8px;
pointer-events: auto;
}
.soft-button {
min-height: 42px;
padding: 0 15px;
border: 1px solid rgba(36, 52, 46, .12);
border-radius: 13px;
background: var(--paper);
color: var(--ink);
box-shadow: 0 8px 26px rgba(45, 61, 53, .09);
backdrop-filter: blur(14px);
cursor: pointer;
font-size: 12px;
font-weight: 750;
transition: transform .18s ease, background .18s ease;
}
.soft-button:hover {
transform: translateY(-2px);
background: white;
}
.panel {
position: fixed;
z-index: 10;
bottom: 24px;
width: 306px;
padding: 17px;
border: 1px solid rgba(255,255,255,.55);
border-radius: 21px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
}
.tray {
left: 24px;
}
.streams {
right: 24px;
width: 318px;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin: 0 2px 13px;
}
.panel-heading h2 {
margin: 0;
font-size: 13px;
letter-spacing: -.01em;
}
.counter {
min-width: 29px;
height: 24px;
padding: 0 8px;
display: grid;
place-items: center;
border-radius: 999px;
background: rgba(36, 52, 46, .08);
color: #67736c;
font-size: 10px;
font-weight: 800;
}
.item-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 7px;
}
.item-button {
position: relative;
min-width: 0;
min-height: 58px;
display: flex;
align-items: center;
gap: 9px;
padding: 9px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255,255,255,.48);
color: var(--ink);
text-align: left;
cursor: pointer;
transition: transform .16s ease, border-color .16s ease,
background .16s ease, opacity .16s ease;
}
.item-button:hover:not(:disabled) {
transform: translateY(-2px);
border-color: rgba(36, 52, 46, .24);
background: white;
}
.item-button.selected {
border-color: #344b40;
background: #344b40;
color: white;
box-shadow: 0 8px 18px rgba(36, 52, 46, .18);
}
.item-button.sorted {
opacity: .48;
cursor: default;
}
.item-button.sorted::after {
content: "✓";
position: absolute;
right: 8px;
top: 6px;
color: #4f8c63;
font-size: 12px;
font-weight: 900;
}
.item-button:disabled {
cursor: default;
}
.item-icon {
width: 34px;
height: 34px;
flex: 0 0 auto;
display: grid;
place-items: center;
border-radius: 10px;
background: #eeeae0;
color: #405049;
}
.item-button.selected .item-icon {
background: rgba(255,255,255,.13);
color: white;
}
.item-icon svg {
width: 24px;
height: 24px;
overflow: visible;
}
.item-name {
min-width: 0;
overflow: hidden;
font-size: 11px;
font-weight: 800;
line-height: 1.18;
}
.item-material {
margin-top: 3px;
color: #7a837e;
font-size: 9px;
font-weight: 650;
text-transform: capitalize;
}
.item-button.selected .item-material {
color: rgba(255,255,255,.65);
}
.stream-list {
display: grid;
gap: 8px;
}
.stream-button {
width: 100%;
padding: 11px 12px 10px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(255,255,255,.48);
color: var(--ink);
text-align: left;
cursor: pointer;
transition: transform .16s ease, border-color .16s ease,
box-shadow .16s ease, background .16s ease;
}
.stream-button:hover {
transform: translateY(-2px);
background: white;
border-color: rgba(36,52,46,.23);
}
.stream-button.recommended {
border-color: var(--stream-color);
box-shadow: 0 0 0 2px color-mix(in srgb, var(--stream-color) 18%, transparent);
}
.stream-button.reject {
animation: reject .34s ease;
}
@keyframes reject {
0%, 100% { transform: translateX(0); }
25% { transform: translateX(-6px); }
55% { transform: translateX(5px); }
80% { transform: translateX(-3px); }
}
.stream-head {
display: grid;
grid-template-columns: 30px 1fr auto;
align-items: center;
gap: 9px;
}
.stream-code {
width: 30px;
height: 30px;
display: grid;
place-items: center;
border-radius: 9px;
background: var(--stream-color);
color: white;
font-size: 9px;
font-weight: 900;
letter-spacing: .05em;
}
.stream-title {
font-size: 12px;
font-weight: 850;
}
.stream-subtitle {
margin-top: 2px;
color: #7a837e;
font-size: 9px;
}
.stream-count {
color: #647168;
font-size: 10px;
font-weight: 850;
}
.meter {
height: 6px;
margin: 9px 0 6px;
overflow: hidden;
border-radius: 99px;
background: rgba(36,52,46,.09);
}
.meter i {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: var(--stream-color);
transition: width .55s cubic-bezier(.2,.8,.2,1);
}
.stream-foot {
display: flex;
justify-content: space-between;
color: #8a928d;
font-size: 8px;
font-weight: 700;
}
.hint {
position: fixed;
z-index: 8;
left: 50%;
bottom: 28px;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 8px;
padding: 10px 14px;
border: 1px solid rgba(255,255,255,.58);
border-radius: 999px;
background: rgba(250,249,244,.84);
box-shadow: 0 10px 30px rgba(44,61,52,.1);
backdrop-filter: blur(14px);
color: #59675f;
font-size: 10px;
font-weight: 700;
white-space: nowrap;
pointer-events: none;
}
.hint b {
color: var(--ink);
font-weight: 850;
}
.hint-separator {
width: 3px;
height: 3px;
border-radius: 50%;
background: #99a39d;
}
.toast {
position: fixed;
z-index: 30;
top: 93px;
left: 50%;
max-width: min(440px, calc(100vw - 32px));
transform: translate(-50%, -15px);
padding: 12px 17px;
border: 1px solid rgba(255,255,255,.7);
border-radius: 13px;
background: #263a31;
box-shadow: var(--shadow);
color: white;
font-size: 12px;
font-weight: 750;
opacity: 0;
pointer-events: none;
transition: opacity .22s ease, transform .22s ease;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
.toast.error {
background: #9b493e;
}
.toast.success {
background: #326d4e;
}
#loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
background: #e2e9e1;
transition: opacity .45s ease, visibility .45s ease;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
.loader-card {
display: flex;
align-items: center;
gap: 13px;
color: #415148;
font-size: 12px;
font-weight: 800;
}
.spinner {
width: 29px;
height: 29px;
border: 3px solid rgba(65,81,72,.15);
border-top-color: #415148;
border-radius: 50%;
animation: spin .8s linear infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
@media (max-width: 850px) {
header {
top: 14px;
left: 14px;
right: 14px;
}
.brand-copy > p:last-child,
.eyebrow {
display: none;
}
.brand-mark {
width: 43px;
height: 43px;
border-radius: 13px;
}
.top-actions {
gap: 5px;
}
.soft-button {
min-height: 39px;
padding: 0 11px;
font-size: 10px;
}
.panel {
bottom: 14px;
padding: 12px;
border-radius: 17px;
}
.tray {
left: 14px;
width: min(300px, 47vw);
}
.streams {
right: 14px;
width: min(300px, 47vw);
}
.item-grid {
gap: 5px;
}
.item-button {
min-height: 48px;
padding: 6px;
gap: 6px;
}
.item-icon {
width: 29px;
height: 29px;
}
.item-icon svg {
width: 21px;
height: 21px;
}
.item-name {
font-size: 9px;
}
.item-material,
.stream-subtitle,
.stream-foot span:last-child {
display: none;
}
.stream-button {
padding: 9px;
}
.hint {
display: none;
}
}
@media (max-width: 560px) {
h1 {
max-width: 130px;
font-size: 19px;
}
.brand {
gap: 8px;
}
.brand-mark {
width: 37px;
height: 37px;
}
.top-actions {
flex-direction: column;
}
.soft-button {
min-height: 33px;
padding: 0 9px;
}
.panel {
width: calc(50vw - 19px);
}
.tray {
left: 10px;
}
.streams {
right: 10px;
}
.panel-heading {
margin-bottom: 8px;
}
.panel-heading h2 {
font-size: 11px;
}
.counter {
min-width: 23px;
height: 20px;
font-size: 8px;
}
.item-grid {
grid-template-columns: 1fr;
max-height: 172px;
overflow: auto;
}
.item-button {
min-height: 43px;
}
.stream-list {
gap: 6px;
}
.stream-code {
width: 25px;
height: 25px;
}
.stream-head {
grid-template-columns: 25px 1fr auto;
gap: 6px;
}
.stream-title {
font-size: 10px;
}
.stream-count {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="texture"></div>
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<svg viewBox="0 0 32 32" fill="none">
<path d="M16 4.5 20.2 12H16.8l-1.1-2.1-2.7 4.7"
stroke="currentColor" stroke-width="2.4"
stroke-linecap="round" stroke-linejoin="round"/>
<path d="m27 13-7.4 4.3 2.1 3.6 3.2-1.8"
stroke="currentColor" stroke-width="2.4"
stroke-linecap="round" stroke-linejoin="round"/>
<path d="m21 27-7.4-4.2-2.1 3.6 3.2 1.9"
stroke="currentColor" stroke-width="2.4"
stroke-linecap="round" stroke-linejoin="round"/>
<path d="M9 27 5 20.7l-3.2 1.9"
stroke="currentColor" stroke-width="2.4"
stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</div>
<div class="brand-copy">
<p class="eyebrow">Courtyard 04 · Waste station</p>
<h1>Circular Courtyard</h1>
<p>Sort every object into the right material stream.</p>
</div>
</div>
<div class="top-actions">
<button class="soft-button" id="resetView">Reset view</button>
<button class="soft-button" id="resetStation">Reset station</button>
</div>
</header>
<aside class="panel tray">
<div class="panel-heading">
<h2>Object tray</h2>
<span class="counter" id="itemCounter">6 left</span>
</div>
<div class="item-grid" id="itemList"></div>
</aside>
<aside class="panel streams">
<div class="panel-heading">
<h2>Material streams</h2>
<span class="counter">3 × 3</span>
</div>
<div class="stream-list" id="streamList"></div>
</aside>
<div class="hint">
<b>Drag</b> an object into a bin
<span class="hint-separator"></span>
<b>Tap</b> an object, then a stream
<span class="hint-separator"></span>
<b>Scroll</b> to zoom
</div>
<div class="toast" id="toast" role="status" aria-live="polite"></div>
<div id="loading">
<div class="loader-card">
<div class="spinner"></div>
Preparing the courtyard…
</div>
</div>
<script type="module">
let THREE;
try {
THREE = await import(
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js"
);
} catch (error) {
document.getElementById("loading").innerHTML =
'<div class="loader-card">Unable to load Three.js.</div>';
throw error;
}
// -------------------------------------------------------------------------
// Core setup
// -------------------------------------------------------------------------
const sceneHost = document.getElementById("scene");
const loading = document.getElementById("loading");
const toastElement = document.getElementById("toast");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdfe8df);
scene.fog = new THREE.Fog(0xdfe8df, 21, 39);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute("aria-label", "Interactive recycling courtyard");
sceneHost.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
70
);
const cameraTarget = new THREE.Vector3(0, 1.05, 0);
const initialCameraPosition = new THREE.Vector3(8.2, 7.4, 12.8);
const initialSpherical = new THREE.Spherical().setFromVector3(
initialCameraPosition.clone().sub(cameraTarget)
);
const cameraGoal = {
theta: initialSpherical.theta,
phi: initialSpherical.phi,
radius: initialSpherical.radius
};
const cameraCurrent = { ...cameraGoal };
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
flatShading: true,
...options
});
}
function addMesh(geometry, mat, parent = scene) {
const mesh = new THREE.Mesh(geometry, mat);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function box(w, h, d, mat, x, y, z, parent = scene) {
const mesh = addMesh(new THREE.BoxGeometry(w, h, d), mat, parent);
mesh.position.set(x, y, z);
return mesh;
}
function cylinder(rt, rb, h, segments, mat, x, y, z, parent = scene) {
const mesh = addMesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
mat,
parent
);
mesh.position.set(x, y, z);
return mesh;
}
// -------------------------------------------------------------------------
// Lighting and courtyard
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xfff8e8, 0x7e9183, 2.3);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d2, 3.1);
sun.position.set(-7, 13, 8);
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 = 35;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fillLight = new THREE.DirectionalLight(0xbcd9df, 0.7);
fillLight.position.set(8, 6, -5);
scene.add(fillLight);
const groundMaterial = material(0xd9d5c9);
const groutMaterial = material(0xc9c6bb);
const wallMaterial = material(0xeee8db);
const wallAccentMaterial = material(0xbac9b9);
const darkMetalMaterial = material(0x394a43, { metalness: 0.35 });
box(30, 0.12, 25, groundMaterial, 0, -0.12, 0);
for (let x = -12; x <= 12; x += 3) {
box(0.025, 0.012, 23, groutMaterial, x, -0.052, 0);
}
for (let z = -10; z <= 10; z += 3) {
box(28, 0.012, 0.025, groutMaterial, 0, -0.051, z);
}
const platformMaterial = material(0xc8c5b9);
box(10.9, 0.15, 4.45, platformMaterial, 0, 0.015, -1.45);
const platformEdgeMaterial = material(0x9da99f);
box(11.0, 0.065, 0.08, platformEdgeMaterial, 0, 0.11, -3.68);
box(0.08, 0.065, 4.45, platformEdgeMaterial, -5.46, 0.11, -1.45);
box(0.08, 0.065, 4.45, platformEdgeMaterial, 5.46, 0.11, -1.45);
// Back wall and architectural details.
box(24, 4.6, 0.4, wallMaterial, 0, 2.2, -6.35);
box(24, 0.65, 0.45, wallAccentMaterial, 0, 0.23, -6.32);
box(24, 0.12, 0.48, material(0x93aa99), 0, 3.82, -6.29);
const windowMaterial = material(0x6f9696, {
roughness: 0.35,
metalness: 0.08
});
const windowFrameMaterial = material(0xd3cabb);
for (const x of [-8.7, -6.5, 6.4, 8.6]) {
box(1.55, 1.45, 0.11, windowFrameMaterial, x, 2.55, -6.08);
box(1.32, 1.22, 0.12, windowMaterial, x, 2.55, -7.0);
box(0.07, 1.25, 0.14, windowFrameMaterial, x, 2.55, -7.0);
}
function createWallSign() {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#f4f0e4";
ctx.fillRect(0, 0, 1024, 256);
ctx.fillStyle = "#344b40";
ctx.fillRect(0, 0, 34, 256);
ctx.fillStyle = "#344b40";
ctx.font = "800 76px Arial";
ctx.fillText("CIRCULAR COURT", 86, 112);
ctx.fillStyle = "#77847b";
ctx.font = "600 30px Arial";
ctx.fillText("SORT · RECOVER · REUSE", 90, 172);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
const sign = addMesh(
new THREE.PlaneGeometry(7.6, 1.9),
new THREE.MeshBasicMaterial({ map: texture })
);
sign.position.set(0, 2.65, -6.08);
sign.castShadow = false;
}
createWallSign();
// Planters and faceted shrubs.
function createPlanter(x, z, shrubColor) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
box(1.9, 0.65, 1.5, material(0x9c8d76), 0, 0.31, 0, group);
box(1.62, 0.08, 1.24, material(0x665c49), 0, 0.65, 0, group);
const shrubMaterial = material(shrubColor);
const shrubPositions = [
[-0.42, 1.05, 0.1, 0.72],
[0.33, 1.18, -0.08, 0.82],
[0.03, 1.55, 0.06, 0.74]
];
for (const [px, py, pz, scale] of shrubPositions) {
const shrub = addMesh(
new THREE.IcosahedronGeometry(scale, 0),
shrubMaterial,
group
);
shrub.position.set(px, py, pz);
shrub.rotation.set(px, py * 2, pz);
}
}
createPlanter(-7.6, -4.6, 0x6f916f);
createPlanter(7.55, -4.5, 0x78966e);
// Bench.
const bench = new THREE.Group();
bench.position.set(7.2, 0, 0.7);
bench.rotation.y = -0.12;
scene.add(bench);
const benchWood = material(0xb78355);
box(2.8, 0.16, 0.7, benchWood, 0, 0.7, 0, bench);
box(2.8, 0.52, 0.13, benchWood, 0, 1.08, -0.31, bench);
box(0.16, 0.7, 0.58, darkMetalMaterial, -1.05, 0.34, 0, bench);
box(0.16, 0.7, 0.58, darkMetalMaterial, 1.05, 0.34, 0, bench);
// -------------------------------------------------------------------------
// Material streams and bins
// -------------------------------------------------------------------------
const streams = [
{
id: "paper",
label: "Paper",
subtitle: "Paper & cardboard",
code: "01",
color: 0x4b8cab,
css: "#4b8cab"
},
{
id: "plastic",
label: "Plastic",
subtitle: "Bottles & containers",
code: "02",
color: 0xdda543,
css: "#dda543"
},
{
id: "metal",
label: "Metal",
subtitle: "Cans & tins",
code: "03",
color: 0xc9664e,
css: "#c9664e"
}
];
const capacity = 3;
const bins = [];
const binsById = {};
function makeStreamTexture(stream) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#f8f5eb";
ctx.fillRect(0, 0, 768, 256);
ctx.fillStyle = stream.css;
ctx.fillRect(0, 0, 20, 256);
ctx.fillStyle = "#344b40";
ctx.font = "800 32px Arial";
ctx.fillText(`STREAM ${stream.code}`, 66, 62);
ctx.font = "900 79px Arial";
ctx.fillText(stream.label.toUpperCase(), 62, 155);
ctx.fillStyle = "#7b857f";
ctx.font = "600 26px Arial";
ctx.fillText(stream.subtitle.toUpperCase(), 65, 207);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function createBin(stream, x) {
const group = new THREE.Group();
group.position.set(x, 0, -1.45);
scene.add(group);
const color = new THREE.Color(stream.color);
const sideColor = color.clone().multiplyScalar(0.77);
const rimColor = color.clone().lerp(new THREE.Color(0xffffff), 0.12);
const wallMat = material(stream.color);
const sideMat = material(sideColor);
const rimMat = material(rimColor);
const innerMat = material(0x26352f);
box(2.18, 0.18, 1.55, sideMat, 0, 0.19, 0, group);
box(0.18, 1.32, 1.55, sideMat, -1.0, 0.94, 0, group);
box(0.18, 1.32, 1.55, sideMat, 1.0, 0.94, 0, group);
box(2.0, 1.32, 0.17, sideMat, 0, 0.94, -0.69, group);
box(2.0, 1.08, 0.17, wallMat, 0, 0.82, 0.69, group);
box(1.83, 0.08, 1.22, innerMat, 0, 0.31, 0, group);
// Open-top rim.
box(2.18, 0.11, 0.14, rimMat, 0, 1.64, 0.70, group);
box(2.18, 0.11, 0.14, rimMat, 0, 1.64, -0.70, group);
box(0.14, 0.11, 1.42, rimMat, -1.02, 1.64, 0, group);
box(0.14, 0.11, 1.42, rimMat, 1.02, 1.64, 0, group);
const fillMaterial = material(color.clone().multiplyScalar(0.72));
const fill = box(1.83, 1, 1.22, fillMaterial, 0, 0.35, 0, group);
fill.scale.y = 0.001;
fill.visible = false;
const signTexture = makeStreamTexture(stream);
const sign = addMesh(
new THREE.PlaneGeometry(1.72, 0.57),
new THREE.MeshBasicMaterial({ map: signTexture }),
group
);
sign.position.set(0, 0.89, 0.79);
sign.castShadow = false;
const bin = {
stream,
group,
fill,
count: 0,
capacity
};
bins.push(bin);
binsById[stream.id] = bin;
return bin;
}
createBin(streams[0], -3.15);
createBin(streams[1], 0);
createBin(streams[2], 3.15);
// -------------------------------------------------------------------------
// Modeled recyclable objects
// -------------------------------------------------------------------------
const paperMaterial = material(0xf1ecde);
const newsLineMaterial = material(0x78817d);
const cartonMaterial = material(0xd9b681);
const blueLabelMaterial = material(0x6d9eae);
const plasticMaterial = material(0xb9d9d7, {
transparent: true,
opacity: 0.82,
roughness: 0.28
});
const orangeLabelMaterial = material(0xe6934f);
const capMaterial = material(0x557c69);
const silverMaterial = material(0xaeb7b3, {
metalness: 0.68,
roughness: 0.36
});
const redLabelMaterial = material(0xc65e4c);
const tinMaterial = material(0xb9b7ad, { metalness: 0.45, roughness: 0.5 });
function makeNewspaper() {
const group = new THREE.Group();
for (let i = 0; i < 4; i++) {
const sheet = box(
0.82,
0.035,
0.58,
paperMaterial,
(i % 2) * 0.035,
0.055 + i * 0.043,
(i % 2) * 0.025,
group
);
sheet.rotation.y = (i - 1.5) * 0.025;
}
for (let i = 0; i < 5; i++) {
const line = box(
0.47 - (i % 2) * 0.08,
0.008,
0.018,
newsLineMaterial,
-0.09,
0.215,
-0.16 + i * 0.075,
group
);
line.castShadow = false;
}
return group;
}
function makeCarton() {
const group = new THREE.Group();
box(0.72, 0.84, 0.5, cartonMaterial, 0, 0.43, 0, group);
box(0.74, 0.13, 0.51, blueLabelMaterial, 0, 0.43, 0, group);
const flapA = box(
0.36,
0.035,
0.5,
cartonMaterial,
-0.18,
0.88,
0,
group
);
flapA.rotation.z = 0.35;
const flapB = box(
0.36,
0.035,
0.5,
cartonMaterial,
0.18,
0.88,
0,
group
);
flapB.rotation.z = -0.35;
return group;
}
function makeBottle() {
const group = new THREE.Group();
cylinder(0.27, 0.31, 0.76, 8, plasticMaterial, 0, 0.42, 0, group);
cylinder(0.13, 0.27, 0.18, 8, plasticMaterial, 0, 0.89, 0, group);
cylinder(0.12, 0.12, 0.19, 8, plasticMaterial, 0, 1.065, 0, group);
cylinder(0.145, 0.145, 0.12, 8, capMaterial, 0, 1.19, 0, group);
cylinder(0.315, 0.315, 0.25, 8, orangeLabelMaterial, 0, 0.43, 0, group);
return group;
}
function makeJug() {
const group = new THREE.Group();
box(0.62, 0.69, 0.5, plasticMaterial, -0.04, 0.37, 0, group);
box(0.55, 0.17, 0.45, plasticMaterial, -0.04, 0.79, 0, group);
cylinder(0.13, 0.16, 0.2, 8, plasticMaterial, -0.12, 0.965, 0, group);
cylinder(0.145, 0.145, 0.11, 8, orangeLabelMaterial, -0.12, 1.09, 0, group);
const handle = addMesh(
new THREE.TorusGeometry(0.22, 0.065, 5, 9, Math.PI * 1.55),
plasticMaterial,
group
);
handle.position.set(0.36, 0.52, 0);
handle.rotation.z = -0.18;
box(0.47, 0.17, 0.51, orangeLabelMaterial, -0.06, 0.42, 0, group);
return group;
}
function makeCan() {
const group = new THREE.Group();
cylinder(0.29, 0.29, 0.72, 10, silverMaterial, 0, 0.39, 0, group);
cylinder(0.305, 0.305, 0.04, 10, silverMaterial, 0, 0.77, 0, group);
cylinder(0.305, 0.305, 0.04, 10, silverMaterial, 0, 0.02, 0, group);
cylinder(0.297, 0.297, 0.24, 10, redLabelMaterial, 0, 0.4, 0, group);
return group;
}
function makeFoodTin() {
const group = new THREE.Group();
cylinder(0.32, 0.35, 0.56, 8, tinMaterial, 0, 0.3, 0, group);
cylinder(0.36, 0.36, 0.05, 8, silverMaterial, 0, 0.6, 0, group);
cylinder(0.36, 0.36, 0.05, 8, silverMaterial, 0, 0.025, 0, group);
cylinder(0.355, 0.355, 0.24, 8, blueLabelMaterial, 0, 0.31, 0, group);
const pullTab = addMesh(
new THREE.TorusGeometry(0.065, 0.015, 4, 8),
darkMetalMaterial,
group
);
pullTab.position.set(0.07, 0.635, 0);
pullTab.rotation.x = Math.PI / 2;
return group;
}
const itemSpecs = [
{
id: "news",
name: "Folded news",
material: "paper",
icon: "paper",
home: [-4.9, 0, 3.75],
maker: makeNewspaper
},
{
id: "carton",
name: "Milk carton",
material: "paper",
icon: "carton",
home: [-2.55, 0, 4.35],
maker: makeCarton
},
{
id: "bottle",
name: "Water bottle",
material: "plastic",
icon: "bottle",
home: [-0.1, 0, 4.75],
maker: makeBottle
},
{
id: "jug",
name: "Soap jug",
material: "plastic",
icon: "jug",
home: [2.35, 0, 4.45],
maker: makeJug
},
{
id: "can",
name: "Soda can",
material: "metal",
icon: "can",
home: [4.75, 0, 3.8],
maker: makeCan
},
{
id: "tin",
name: "Food tin",
material: "metal",
icon: "tin",
home: [-5.15, 0, 1.65],
maker: makeFoodTin
}
];
const items = [];
const itemsById = {};
const interactiveMeshes = [];
itemSpecs.forEach((spec, index) => {
const group = spec.maker();
group.position.set(...spec.home);
group.rotation.y = (index % 2 ? 1 : -1) * (0.12 + index * 0.035);
scene.add(group);
const item = {
...spec,
group,
home: new THREE.Vector3(...spec.home),
homeRotationY: group.rotation.y,
accepted: false,
tween: null
};
group.traverse((child) => {
if (child.isMesh) {
child.userData.item = item;
interactiveMeshes.push(child);
}
});
items.push(item);
itemsById[item.id] = item;
});
// -------------------------------------------------------------------------
// UI
// -------------------------------------------------------------------------
function itemIcon(type) {
const icons = {
paper: `
<svg viewBox="0 0 24 24" fill="none">
<path d="M5 3.5h12l2 2V20H5z" fill="currentColor" opacity=".18"/>
<path d="M7 3.5h10v16H7z" fill="currentColor" opacity=".36"/>
<path d="M9 7h6M9 10h6M9 13h4" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
</svg>`,
carton: `
<svg viewBox="0 0 24 24" fill="none">
<path d="m5 7 7-3 7 3v11l-7 3-7-3z" fill="currentColor" opacity=".25"/>
<path d="m5 7 7 3 7-3M12 10v11" stroke="currentColor" stroke-width="1.4" stroke-linejoin="round"/>
<path d="M8 5.2 12 7l4-1.8" stroke="currentColor" stroke-width="1.4"/>
</svg>`,
bottle: `
<svg viewBox="0 0 24 24" fill="none">
<path d="M9 2h6v4l2 3v11H7V9l2-3z" fill="currentColor" opacity=".27"/>
<path d="M9 2h6v4l2 3v11H7V9l2-3zM7 12h10" stroke="currentColor" stroke-width="1.4" stroke-linejoin="round"/>
<path d="M9 2h6" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
</svg>`,
jug: `
<svg viewBox="0 0 24 24" fill="none">
<path d="M6 5h8v4l3 3v9H6z" fill="currentColor" opacity=".26"/>
<path d="M6 5h8v4l3 3v9H6zM14 10h3c3 0 3 5 0 5h-3" stroke="currentColor" stroke-width="1.4" stroke-linejoin="round"/>
<path d="M9 3h4v2H9z" fill="currentColor"/>
</svg>`,
can: `
<svg viewBox="0 0 24 24" fill="none">
<ellipse cx="12" cy="5" rx="6" ry="2.5" fill="currentColor" opacity=".45"/>
<path d="M6 5v14c0 1.4 2.7 2.5 6 2.5s6-1.1 6-2.5V5" fill="currentColor" opacity=".22"/>
<ellipse cx="12" cy="5" rx="6" ry="2.5" stroke="currentColor" stroke-width="1.3"/>
<path d="M6 19c0 1.4 2.7 2.5 6 2.5s6-1.1 6-2.5" stroke="currentColor" stroke-width="1.3"/>
<path d="M6 10c1.3 1.2 3.2 1.7 6 1.7s4.7-.5 6-1.7" stroke="currentColor" stroke-width="1.3"/>
</svg>`,
tin: `
<svg viewBox="0 0 24 24" fill="none">
<ellipse cx="12" cy="6" rx="7" ry="3" fill="currentColor" opacity=".48"/>
<path d="M5 6v12c0 1.7 3.1 3 7 3s7-1.3 7-3V6" fill="currentColor" opacity=".22"/>
<path d="M5 6v12c0 1.7 3.1 3 7 3s7-1.3 7-3V6" stroke="currentColor" stroke-width="1.3"/>
<path d="M10 6c0-1.2 1-2 2-2s2 .8 2 2" stroke="currentColor" stroke-width="1.3"/>
</svg>`
};
return icons[type] || icons.paper;
}
const itemListElement = document.getElementById("itemList");
const streamListElement = document.getElementById("streamList");
const itemCounterElement = document.getElementById("itemCounter");
items.forEach((item) => {
const button = document.createElement("button");
button.className = "item-button";
button.type = "button";
button.innerHTML = `
<span class="item-icon">${itemIcon(item.icon)}</span>
<span>
<span class="item-name">${item.name}</span>
<span class="item-material">${item.material}</span>
</span>
`;
button.addEventListener("click", () => {
if (item.accepted) return;
selectedItemId = selectedItemId === item.id ? null : item.id;
updateSelectionUI();
});
item.ui = { button };
itemListElement.appendChild(button);
});
streams.forEach((stream) => {
const button = document.createElement("button");
button.className = "stream-button";
button.type = "button";
button.style.setProperty("--stream-color", stream.css);
button.innerHTML = `
<div class="stream-head">
<span class="stream-code">${stream.code}</span>
<span>
<span class="stream-title">${stream.label}</span>
<span class="stream-subtitle">${stream.subtitle}</span>
</span>
<span class="stream-count">0 / ${capacity}</span>
</div>
<div class="meter"><i></i></div>
<div class="stream-foot">
<span>Empty</span>
<span>Tap to place selected</span>
</div>
`;
button.addEventListener("click", () => {
if (!selectedItemId) {
showToast("Choose an object from the tray first.");
return;
}
attemptSort(itemsById[selectedItemId], stream);
});
stream.ui = {
button,
fill: button.querySelector(".meter i"),
count: button.querySelector(".stream-count"),
status: button.querySelector(".stream-foot span")
};
streamListElement.appendChild(button);
});
let selectedItemId = null;
let toastTimer;
function showToast(message, type = "") {
clearTimeout(toastTimer);
toastElement.textContent = message;
toastElement.className = `toast show ${type}`;
toastTimer = setTimeout(() => {
toastElement.className = "toast";
}, 2300);
}
function updateSelectionUI() {
const selectedItem = selectedItemId ? itemsById[selectedItemId] : null;
items.forEach((item) => {
item.ui.button.classList.toggle("selected", item.id === selectedItemId);
item.ui.button.classList.toggle("sorted", item.accepted);
item.ui.button.disabled = item.accepted;
});
streams.forEach((stream) => {
stream.ui.button.classList.toggle(
"recommended",
!!selectedItem && selectedItem.material === stream.id
);
});
const remaining = items.filter((item) => !item.accepted).length;
itemCounterElement.textContent = `${remaining} left`;
}
function updateBinFill(bin) {
const ratio = bin.count / bin.capacity;
const fillHeight = Math.max(0.001, ratio * 1.18);
bin.fill.visible = bin.count > 0;
bin.fill.scale.y = fillHeight;
bin.fill.position.y = 0.31 + fillHeight / 2;
const stream = bin.stream;
stream.ui.fill.style.width = `${ratio * 100}%`;
stream.ui.count.textContent = `${bin.count} / ${bin.capacity}`;
stream.ui.status.textContent =
bin.count === 0 ? "Empty" :
bin.count === bin.capacity ? "Full" :
bin.count >= bin.capacity - 1 ? "Nearly full" : "Filling";
}
// Tag every bin mesh for raycasting.
bins.forEach((bin) => {
bin.group.traverse((child) => {
if (child.isMesh) {
child.userData.bin = bin;
interactiveMeshes.push(child);
}
});
});
// -------------------------------------------------------------------------
// Selection, dragging, and sorting
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointerNdc = new THREE.Vector2();
const dragPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), -0.35);
const dragPoint = new THREE.Vector3();
let pointerState = null;
function setPointerFromEvent(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointerNdc.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNdc.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNdc, camera);
}
function getHits(event) {
setPointerFromEvent(event);
return raycaster.intersectObjects(interactiveMeshes, false);
}
function selectItem(id) {
if (!id || itemsById[id].accepted) return;
selectedItemId = id;
updateSelectionUI();
}
function returnItemHome(item) {
item.tween = {
from: item.group.position.clone(),
to: item.home.clone(),
fromScale: item.group.scale.clone(),
toScale: new THREE.Vector3(1, 1, 1),
start: performance.now(),
duration: 480,
onComplete: null
};
}
function findNearestBin(position) {
let nearest = null;
let nearestDistance = Infinity;
for (const bin of bins) {
const dx = position.x - bin.group.position.x;
const dz = position.z - bin.group.position.z;
const distance = Math.hypot(dx, dz);
if (distance < nearestDistance) {
nearestDistance = distance;
nearest = bin;
}
}
return nearestDistance < 1.58 ? nearest : null;
}
function attemptSort(item, stream) {
if (!item || item.accepted) return false;
if (item.material !== stream.id) {
showToast(
`${item.name} belongs in the ${item.material} stream.`,
"error"
);
stream.ui.button.classList.remove("reject");
void stream.ui.button.offsetWidth;
stream.ui.button.classList.add("reject");
item.rejectUntil = performance.now() + 360;
return false;
}
selectedItemId = null;
updateSelectionUI();
const bin = binsById[stream.id];
const target = new THREE.Vector3(
bin.group.position.x,
1.85,
bin.group.position.z + 0.03
);
item.tween = {
from: item.group.position.clone(),
to: target,
fromScale: item.group.scale.clone(),
toScale: new THREE.Vector3(0.08, 0.08, 0.08),
start: performance.now(),
duration: 720,
onComplete: () => {
item.accepted = true;
item.group.visible = false;
item.group.scale.set(1, 1, 1);
bin.count = Math.min(bin.capacity, bin.count + 1);
updateBinFill(bin);
updateSelectionUI();
spawnConfetti(bin);
showToast(`${stream.label} accepted. Nice sorting!`, "success");
}
};
return true;
}
// Pointer interaction: drag objects, select them, and orbit the camera.
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
const hits = getHits(event);
const itemHit = hits.find((hit) => hit.object.userData.item);
const binHit = hits.find((hit) => hit.object.userData.bin);
if (event.button === 0 && itemHit) {
const item = itemHit.object.userData.item;
if (item.accepted) return;
selectItem(item.id);
const planeHit = raycaster.ray.intersectPlane(dragPlane, dragPoint);
const offset = new THREE.Vector3();
if (planeHit) {
offset.copy(item.group.position).sub(planeHit);
}
pointerState = {
mode: "item",
item,
startX: event.clientX,
startY: event.clientY,
lastX: event.clientX,
lastY: event.clientY,
moved: false,
offset
};
renderer.domElement.setPointerCapture(event.pointerId);
return;
}
if (event.button === 0 && binHit) {
const bin = binHit.object.userData.bin;
if (selectedItemId) {
attemptSort(itemsById[selectedItemId], bin.stream);
} else {
showToast(`Choose an object for the ${bin.stream.label.toLowerCase()} stream.`);
}
return;
}
pointerState = {
mode: "orbit",
lastX: event.clientX,
lastY: event.clientY
};
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerState) {
const hits = getHits(event);
const overItem = hits.some((hit) => hit.object.userData.item);
const overBin = hits.some((hit) => hit.object.userData.bin);
renderer.domElement.style.cursor =
overItem ? "grab" : overBin ? "pointer" : "default";
return;
}
if (pointerState.mode === "orbit") {
const dx = event.clientX - pointerState.lastX;
const dy = event.clientY - pointerState.lastY;
cameraGoal.theta = THREE.MathUtils.clamp(
cameraGoal.theta - dx * 0.0055,
-1.16,
1.16
);
cameraGoal.phi = THREE.MathUtils.clamp(
cameraGoal.phi - dy * 0.004,
0.58,
1.34
);
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
return;
}
if (pointerState.mode === "item") {
const totalDistance = Math.hypot(
event.clientX - pointerState.startX,
event.clientY - pointerState.startY
);
if (totalDistance > 5) pointerState.moved = true;
if (pointerState.moved) {
setPointerFromEvent(event);
if (raycaster.ray.intersectPlane(dragPlane, dragPoint)) {
pointerState.item.group.position.set(
dragPoint.x + pointerState.offset.x,
0.38,
dragPoint.z + pointerState.offset.z
);
}
renderer.domElement.style.cursor = "grabbing";
}
}
});
function finishPointerInteraction(event) {
if (!pointerState) return;
const state = pointerState;
pointerState = null;
renderer.domElement.style.cursor = "default";
if (state.mode === "item") {
if (state.moved) {
const nearestBin = findNearestBin(state.item.group.position);
if (nearestBin) {
attemptSort(state.item, nearestBin.stream);
} else {
returnItemHome(state.item);
showToast("Drop the object into one of the three bins.");
}
}
}
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", finishPointerInteraction);
renderer.domElement.addEventListener("pointercancel", finishPointerInteraction);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraGoal.radius = THREE.MathUtils.clamp(
cameraGoal.radius * Math.exp(event.deltaY * 0.001),
8.5,
22
);
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Selection indicator and celebratory particles
// -------------------------------------------------------------------------
const selectionRing = new THREE.Mesh(
new THREE.TorusGeometry(0.55, 0.025, 5, 36),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.88,
depthWrite: false
})
);
selectionRing.rotation.x = -Math.PI / 2;
selectionRing.visible = false;
scene.add(selectionRing);
const particles = [];
function spawnConfetti(bin) {
for (let i = 0; i < 13; i++) {
const mesh = addMesh(
new THREE.BoxGeometry(0.075, 0.035, 0.12),
material(bin.stream.color)
);
mesh.position.set(
bin.group.position.x + (Math.random() - 0.5) * 0.9,
1.55 + Math.random() * 0.25,
bin.group.position.z + (Math.random() - 0.5) * 0.6
);
particles.push({
mesh,
velocity: new THREE.Vector3(
(Math.random() - 0.5) * 1.6,
1.3 + Math.random() * 1.6,
(Math.random() - 0.5) * 1.1
),
spin: new THREE.Vector3(
Math.random() * 5,
Math.random() * 5,
Math.random() * 5
),
life: 1.25
});
}
}
// -------------------------------------------------------------------------
// Reset controls and keyboard shortcuts
// -------------------------------------------------------------------------
document.getElementById("resetView").addEventListener("click", () => {
cameraGoal.theta = initialSpherical.theta;
cameraGoal.phi = initialSpherical.phi;
cameraGoal.radius = initialSpherical.radius;
showToast("Camera reset.");
});
document.getElementById("resetStation").addEventListener("click", () => {
selectedItemId = null;
bins.forEach((bin) => {
bin.count = 0;
updateBinFill(bin);
});
items.forEach((item) => {
item.accepted = false;
item.tween = null;
item.group.visible = true;
item.group.position.copy(item.home);
item.group.scale.set(1, 1, 1);
item.group.rotation.y = item.homeRotationY;
});
updateSelectionUI();
showToast("The sorting station has been reset.");
});
window.addEventListener("keydown", (event) => {
if (event.key === "Escape") {
selectedItemId = null;
updateSelectionUI();
}
if (["1", "2", "3"].includes(event.key) && selectedItemId) {
const stream = streams[Number(event.key) - 1];
attemptSort(itemsById[selectedItemId], stream);
}
});
// -------------------------------------------------------------------------
// Animation loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const now = performance.now();
const damping = 1 - Math.exp(-7 * dt);
cameraCurrent.theta +=
(cameraGoal.theta - cameraCurrent.theta) * damping;
cameraCurrent.phi +=
(cameraGoal.phi - cameraCurrent.phi) * damping;
cameraCurrent.radius +=
(cameraGoal.radius - cameraCurrent.radius) * damping;
const cameraSpherical = new THREE.Spherical(
cameraCurrent.radius,
cameraCurrent.phi,
cameraCurrent.theta
);
camera.position.setFromSpherical(cameraSpherical).add(cameraTarget);
camera.lookAt(cameraTarget);
items.forEach((item) => {
if (item.tween) {
const tween = item.tween;
const t = Math.min(1, (now - tween.start) / tween.duration);
const eased = 1 - Math.pow(1 - t, 3);
item.group.position.lerpVectors(tween.from, tween.to, eased);
item.group.scale.lerpVectors(
tween.fromScale,
tween.toScale,
eased
);
if (t >= 1) {
item.tween = null;
if (tween.onComplete) tween.onComplete();
}
} else if (
item.id === selectedItemId &&
!item.accepted &&
!(pointerState && pointerState.mode === "item")
) {
const targetY = 0.24 + Math.sin(now * 0.004) * 0.055;
item.group.position.y +=
(targetY - item.group.position.y) * 0.15;
item.group.position.x +=
(item.home.x - item.group.position.x) * 0.09;
item.group.position.z +=
(item.home.z - item.group.position.z) * 0.09;
}
if (
item.rejectUntil &&
now < item.rejectUntil &&
item.id === selectedItemId
) {
item.group.position.x =
item.home.x + Math.sin(now * 0.055) * 0.09;
}
});
const selectedItem = selectedItemId ? itemsById[selectedItemId] : null;
selectionRing.visible = !!selectedItem && !selectedItem.accepted;
if (selectedItem) {
selectionRing.position.set(
selectedItem.group.position.x,
0.13,
selectedItem.group.position.z
);
const pulse = 1 + Math.sin(now * 0.005) * 0.07;
selectionRing.scale.setScalar(pulse);
selectionRing.material.opacity = 0.65 + Math.sin(now * 0.005) * 0.2;
}
for (let i = particles.length - 1; i >= 0; i--) {
const particle = particles[i];
particle.life -= dt;
particle.velocity.y -= 3.7 * dt;
particle.mesh.position.addScaledVector(particle.velocity, dt);
particle.mesh.rotation.x += particle.spin.x * dt;
particle.mesh.rotation.y += particle.spin.y * dt;
particle.mesh.rotation.z += particle.spin.z * dt;
if (particle.life <= 0) {
scene.remove(particle.mesh);
particle.mesh.geometry.dispose();
particles.splice(i, 1);
}
}
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
updateSelectionUI();
bins.forEach(updateBinFill);
animate();
requestAnimationFrame(() => {
requestAnimationFrame(() => loading.classList.add("hidden"));
});
</script>
</body>
</html>
```