Prompt specification
Build or customize the Three.js 3D scene "Community Fridge Stock Board" 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 Fridge Stock Board
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/community-fridge-stock-board-x3267
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing shared information about tasks and supplies. Create a neighborhood pantry with shelves, donation arrivals, and an update board. Display how outdated stock information causes failed pickups while avoiding personal identifying details. Voxel style.
Working Three.js Starter (community-fridge-stock-board-x3267):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Block & Basket — Neighborhood Pantry</title>
<style>
:root {
--ink: #203248;
--muted: #667487;
--cream: #fffaf0;
--paper: rgba(255, 252, 244, 0.94);
--mint: #79c9aa;
--mint-dark: #277d63;
--gold: #f2bb55;
--coral: #ef795f;
--navy: #314a67;
--line: rgba(32, 50, 72, 0.13);
--shadow: 0 14px 35px rgba(40, 53, 70, 0.14);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
background: #dce8e4;
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%;
touch-action: none;
outline: none;
}
.topbar {
position: fixed;
z-index: 20;
top: 14px;
left: 14px;
right: 14px;
min-height: 68px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
padding: 11px 14px 11px 16px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 17px;
background: rgba(255, 250, 240, 0.92);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}
.brand-mark {
width: 42px;
height: 42px;
position: relative;
flex: 0 0 auto;
}
.brand-mark i {
position: absolute;
width: 19px;
height: 19px;
border-radius: 4px;
box-shadow: inset -3px -3px rgba(0, 0, 0, 0.09);
}
.brand-mark i:nth-child(1) {
left: 1px; top: 3px;
background: var(--gold);
}
.brand-mark i:nth-child(2) {
right: 1px; top: 3px;
background: var(--mint);
}
.brand-mark i:nth-child(3) {
left: 11px; bottom: 2px;
background: var(--coral);
}
.brand h1 {
margin: 0;
font-size: 18px;
line-height: 1.1;
letter-spacing: -0.03em;
white-space: nowrap;
}
.brand p {
margin: 4px 0 0;
color: var(--muted);
font-size: 12px;
white-space: nowrap;
}
.top-actions {
display: flex;
align-items: center;
gap: 10px;
flex-wrap: wrap;
justify-content: flex-end;
}
.status-chip {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 8px 11px;
border-radius: 999px;
color: #8b3c2d;
background: #ffe0d8;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.06em;
white-space: nowrap;
}
.status-chip::before {
content: "";
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--coral);
box-shadow: 0 0 0 4px rgba(239, 121, 95, 0.16);
}
.status-chip.safe {
color: #236a53;
background: #daf3e8;
}
.status-chip.safe::before {
background: var(--mint-dark);
box-shadow: 0 0 0 4px rgba(39, 125, 99, 0.14);
}
.small-button,
.primary-button,
.secondary-button {
border: 0;
border-radius: 10px;
padding: 10px 13px;
cursor: pointer;
font-weight: 800;
transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}
.small-button {
color: var(--ink);
background: #e9eee9;
font-size: 12px;
}
.small-button:hover,
.primary-button:hover,
.secondary-button:hover {
transform: translateY(-1px);
}
.small-button:disabled,
.primary-button:disabled,
.secondary-button:disabled {
opacity: 0.45;
cursor: not-allowed;
transform: none;
}
.panel {
position: fixed;
z-index: 15;
top: 96px;
width: 306px;
max-height: calc(100vh - 118px);
overflow: auto;
padding: 16px;
border: 1px solid rgba(255, 255, 255, 0.85);
border-radius: 17px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
scrollbar-width: thin;
}
#taskPanel { left: 14px; }
#ledgerPanel { right: 14px; width: 332px; }
.eyebrow {
margin: 0 0 5px;
color: var(--mint-dark);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.panel h2 {
margin: 0;
font-size: 20px;
letter-spacing: -0.035em;
}
.panel-intro {
margin: 7px 0 14px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.task-card,
.stock-card {
width: 100%;
display: block;
text-align: left;
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.68);
border-radius: 12px;
padding: 11px;
color: var(--ink);
cursor: pointer;
transition: border-color 0.15s ease, transform 0.15s ease, background 0.15s ease;
}
.task-card + .task-card,
.stock-card + .stock-card {
margin-top: 8px;
}
.task-card:hover,
.stock-card:hover {
transform: translateX(2px);
background: #fff;
}
.task-card.selected,
.stock-card.selected {
border-color: rgba(239, 121, 95, 0.65);
background: #fff6ef;
}
.task-row,
.stock-row,
.metric-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.task-code {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
font-weight: 900;
}
.task-title {
margin-top: 6px;
font-size: 14px;
font-weight: 850;
}
.task-meta {
margin-top: 3px;
color: var(--muted);
font-size: 11px;
}
.pill {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 5px 7px;
border-radius: 999px;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.05em;
white-space: nowrap;
color: #276d57;
background: #dff3e9;
}
.pill.risk {
color: #9a4434;
background: #ffe0d8;
}
.pill.done {
color: #43566c;
background: #e8edf1;
}
.privacy {
margin-top: 14px;
padding: 11px;
border-radius: 11px;
background: #e9f4ee;
border: 1px solid #cfe6da;
color: #436154;
font-size: 11px;
line-height: 1.45;
}
.privacy strong {
display: block;
margin-bottom: 3px;
color: #28654f;
font-size: 10px;
letter-spacing: 0.09em;
}
.primary-button {
width: 100%;
margin-top: 13px;
color: white;
background: var(--navy);
box-shadow: 0 6px 14px rgba(49, 74, 103, 0.19);
font-size: 12px;
}
.secondary-button {
color: var(--ink);
background: #e7eee9;
font-size: 11px;
}
.divider {
height: 1px;
margin: 16px 0;
background: var(--line);
}
.detail-card {
margin-top: 13px;
padding: 13px;
border-radius: 13px;
background: #f1f5f1;
border: 1px solid var(--line);
}
.detail-title {
display: flex;
align-items: center;
gap: 9px;
font-size: 15px;
font-weight: 900;
}
.swatch {
width: 13px;
height: 13px;
flex: 0 0 auto;
border-radius: 4px;
box-shadow: inset -2px -2px rgba(0, 0, 0, 0.13);
}
.metric-row {
margin-top: 10px;
padding-top: 9px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 11px;
}
.metric-row b {
color: var(--ink);
font-size: 13px;
}
.warning {
margin-top: 11px;
padding: 10px;
border-radius: 10px;
color: #8c4335;
background: #ffe1d9;
font-size: 11px;
line-height: 1.45;
}
.verified {
margin-top: 11px;
padding: 10px;
border-radius: 10px;
color: #286a53;
background: #daf3e8;
font-size: 11px;
line-height: 1.45;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 10px;
}
.log {
margin-top: 10px;
display: grid;
gap: 8px;
}
.log-entry {
display: grid;
grid-template-columns: 46px 1fr;
gap: 8px;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.log-entry time {
color: var(--ink);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-weight: 800;
}
.log-entry.alert .log-message { color: #9a4434; }
.log-entry.success .log-message { color: #286a53; }
#result {
position: fixed;
z-index: 30;
left: 50%;
bottom: 22px;
width: min(430px, calc(100vw - 28px));
transform: translate(-50%, 130%);
opacity: 0;
padding: 15px;
border: 1px solid rgba(255, 255, 255, 0.9);
border-radius: 15px;
background: rgba(255, 250, 240, 0.97);
box-shadow: 0 18px 45px rgba(31, 48, 66, 0.24);
transition: transform 0.28s ease, opacity 0.28s ease;
pointer-events: none;
}
#result.show {
transform: translate(-50%, 0);
opacity: 1;
pointer-events: auto;
}
.result-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.result-heading h3 {
margin: 0;
font-size: 17px;
}
.result-body {
margin: 7px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.close-result {
border: 0;
background: #e9eee9;
color: var(--ink);
border-radius: 8px;
width: 28px;
height: 28px;
cursor: pointer;
font-weight: 900;
}
.scene-hint {
position: fixed;
z-index: 10;
left: 50%;
bottom: 16px;
transform: translateX(-50%);
padding: 7px 11px;
border-radius: 999px;
color: rgba(32, 50, 72, 0.76);
background: rgba(255, 255, 255, 0.58);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.02em;
pointer-events: none;
}
#loading {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
background: #dce8e4;
color: var(--ink);
font-weight: 800;
}
#loading.hidden { display: none; }
@media (max-width: 1050px) {
.panel { width: 275px; }
#ledgerPanel { width: 292px; }
.brand p { display: none; }
}
@media (max-width: 760px) {
.topbar {
top: 8px;
left: 8px;
right: 8px;
min-height: 58px;
padding: 8px 10px;
}
.brand-mark { width: 34px; height: 34px; transform: scale(0.8); transform-origin: left center; }
.brand h1 { font-size: 15px; }
.status-chip { display: none; }
#taskPanel {
top: 78px;
left: 8px;
width: calc(100% - 16px);
max-height: 27vh;
padding: 12px;
}
#ledgerPanel {
top: auto;
right: 8px;
bottom: 8px;
width: calc(100% - 16px);
max-height: 38vh;
padding: 12px;
}
.panel-intro { margin-bottom: 10px; }
.scene-hint { display: none; }
#result { bottom: 10px; }
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"><i></i><i></i><i></i></div>
<div>
<h1>Block & Basket</h1>
<p>Neighborhood pantry · shared operations board</p>
</div>
</div>
<div class="top-actions">
<div id="riskChip" class="status-chip">1 PICKUP AT RISK</div>
<button id="resetButton" class="small-button" type="button">Reset scenario</button>
</div>
</header>
<aside id="taskPanel" class="panel" aria-label="Shared pickup tasks">
<p class="eyebrow">Shared queue</p>
<h2>Today’s pickup tasks</h2>
<p class="panel-intro">
Tasks use anonymous pickup codes. The board reflects the last published shelf count.
</p>
<div id="taskList"></div>
<button id="attemptButton" class="primary-button" type="button">
Attempt pickup P-204
</button>
<div class="privacy">
<strong>PRIVACY BY DESIGN</strong>
Pickup codes, shelf IDs, and aggregate counts only. No names, phone numbers,
addresses, or personal notes are collected or displayed.
</div>
</aside>
<aside id="ledgerPanel" class="panel" aria-label="Shared supply ledger">
<p class="eyebrow">Supply ledger</p>
<h2>Shared stock counts</h2>
<p class="panel-intro">
Select an item to inspect the difference between the published count and the shelf.
</p>
<div id="stockList"></div>
<div id="selectedDetails" class="detail-card"></div>
<div class="button-row">
<button id="locateButton" class="secondary-button" type="button">Locate in pantry</button>
<button id="publishButton" class="secondary-button" type="button">Publish verified count</button>
</div>
<button id="receiveButton" class="primary-button" type="button">
Receive 8 rice units + sync
</button>
<div class="divider"></div>
<p class="eyebrow">Activity log</p>
<div id="eventLog" class="log" aria-live="polite"></div>
</aside>
<section id="result" role="status" aria-live="assertive">
<div class="result-heading">
<h3 id="resultTitle"></h3>
<button id="closeResult" class="close-result" type="button" aria-label="Close">×</button>
</div>
<p id="resultBody" class="result-body"></p>
</section>
<div class="scene-hint">Drag to orbit · wheel to zoom · shift-drag to pan</div>
<div id="loading">Building the neighborhood pantry…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const sceneHost = document.getElementById("scene");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8e4);
scene.fog = new THREE.Fog(0xdce8e4, 29, 57);
const renderer = new THREE.WebGLRenderer({ antialias: true });
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;
sceneHost.appendChild(renderer.domElement);
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel neighborhood pantry with shelves, donation arrivals, and an update board"
);
const camera = new THREE.OrthographicCamera(-10, 10, 10, -10, 0.1, 100);
const cameraState = {
yaw: 0.72,
pitch: 0.72,
zoom: 1,
target: new THREE.Vector3(0, 2, -0.35),
targetGoal: new THREE.Vector3(0, 2, -0.35)
};
const hemisphere = new THREE.HemisphereLight(0xf8fff7, 0x8d7766, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff2d5, 3.2);
sun.position.set(8, 14, 10);
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 = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 38;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xccecff, 1.0);
fill.position.set(-10, 8, 4);
scene.add(fill);
const COLORS = {
cream: 0xf4ead4,
wall: 0xf0dfc3,
wallDark: 0xd9c4a3,
floorA: 0xe8dfca,
floorB: 0xf1e9d7,
navy: 0x314a67,
ink: 0x203248,
mint: 0x79c9aa,
mintDark: 0x3b8f74,
gold: 0xf2bb55,
coral: 0xef795f,
wood: 0xb87845,
woodDark: 0x835236,
metal: 0x9aa9aa,
white: 0xfffdf7,
green: 0x6f9f62
};
const clickableMeshes = [];
const commodityGroups = {};
const animations = [];
function material(color, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
flatShading: true,
...extra
});
}
function box(parent, w, h, d, x, y, z, color, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
material(color, options.material || {})
);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function textureFromCanvas(canvas) {
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function makeLabel(width, height, lines, options = {}) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = Math.max(160, Math.round(1024 * height / width));
const ctx = canvas.getContext("2d");
const texture = textureFromCanvas(canvas);
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
side: THREE.DoubleSide
})
);
function redraw(nextLines = lines, nextOptions = options) {
const bg = nextOptions.bg || "#fffaf0";
const fg = nextOptions.fg || "#203248";
const accent = nextOptions.accent || "#ef795f";
const border = nextOptions.border || 10;
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = bg;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = accent;
ctx.lineWidth = border;
ctx.strokeRect(border / 2, border / 2, canvas.width - border, canvas.height - border);
const rowHeight = (canvas.height - border * 2) / nextLines.length;
nextLines.forEach((line, index) => {
const isFirst = index === 0;
ctx.fillStyle = isFirst ? accent : fg;
ctx.font = `${isFirst ? 900 : 800} ${Math.floor(rowHeight * (isFirst ? 0.46 : 0.39))}px ui-monospace, monospace`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(
line,
canvas.width / 2,
border + rowHeight * (index + 0.5),
canvas.width - border * 3
);
});
texture.needsUpdate = true;
}
redraw();
return { mesh, canvas, texture, redraw };
}
function addLabel(parent, width, height, position, lines, options) {
const label = makeLabel(width, height, lines, options);
label.mesh.position.set(position[0], position[1], position[2]);
parent.add(label.mesh);
return label;
}
// -------------------------------------------------------------------------
// Shared, anonymous operational state
// -------------------------------------------------------------------------
const state = {
now: "10:42",
receiving: false,
selected: "rice",
completed: new Set(),
supplies: {
rice: {
id: "rice",
name: "Rice 1 kg",
shortName: "RICE",
shelf: "C-2",
actual: 3,
listed: 8,
last: "08:10",
stale: true,
request: 6,
code: "P-204",
color: "#f2bb55"
},
beans: {
id: "beans",
name: "Canned beans",
shortName: "BEANS",
shelf: "C-1",
actual: 10,
listed: 10,
last: "09:55",
stale: false,
request: 4,
code: "P-118",
color: "#79c9aa"
},
soup: {
id: "soup",
name: "Vegetable soup",
shortName: "SOUP",
shelf: "C-3",
actual: 6,
listed: 6,
last: "09:50",
stale: false,
request: 2,
code: "P-091",
color: "#ef795f"
},
hygiene: {
id: "hygiene",
name: "Hygiene kits",
shortName: "KITS",
shelf: "D-1",
actual: 8,
listed: 8,
last: "09:40",
stale: false,
request: 1,
code: "P-143",
color: "#8d9bc5"
}
},
log: [
{ time: "08:10", message: "Shelf C-2 count published.", type: "" },
{ time: "09:55", message: "Shelves C-1 and C-3 verified.", type: "success" },
{ time: "10:12", message: "Donation arrival logged: 8 rice units.", type: "" },
{ time: "10:42", message: "P-204 confirmed using the shared count sheet.", type: "alert" }
]
};
function addLog(message, type = "") {
state.log.push({ time: state.now, message, type });
if (state.log.length > 14) state.log.shift();
renderLog();
}
// -------------------------------------------------------------------------
// Voxel pantry architecture
// -------------------------------------------------------------------------
const pantry = new THREE.Group();
scene.add(pantry);
// Floor base and tiled surface.
box(pantry, 17.6, 0.28, 12, 0, -0.2, 0, 0xcbb99c);
const tileColors = [COLORS.floorA, COLORS.floorB];
for (let ix = 0; ix < 12; ix++) {
for (let iz = 0; iz < 8; iz++) {
const x = -7.65 + ix * 1.4;
const z = -4.9 + iz * 1.4;
box(
pantry,
1.34,
0.12,
1.34,
x,
-0.02,
z,
tileColors[(ix + iz) % 2],
{ castShadow: false }
);
}
}
// Cutaway back and left walls.
box(pantry, 17.6, 8.2, 0.36, 0, 4.0, -5.75, COLORS.wall);
box(pantry, 0.36, 8.2, 12, -8.68, 4.0, 0, COLORS.wall);
// Voxel brick seams.
for (let y = 0.9; y < 7.8; y += 0.8) {
box(pantry, 17.2, 0.035, 0.04, 0, y, -5.55, COLORS.wallDark, {
castShadow: false
});
box(pantry, 0.04, 0.035, 11.7, -8.48, y, 0, COLORS.wallDark, {
castShadow: false
});
}
// Baseboards.
box(pantry, 17.2, 0.34, 0.15, 0, 0.18, -5.49, COLORS.navy);
box(pantry, 0.15, 0.34, 11.7, -8.43, 0.18, 0, COLORS.navy);
// Rear shelf.
const rearShelf = new THREE.Group();
rearShelf.position.set(-4.25, 0, -4.6);
pantry.add(rearShelf);
const shelfLevels = [0.58, 1.78, 2.98, 4.18];
for (const x of [-3.0, 3.0]) {
box(rearShelf, 0.19, 4.8, 1.28, x, 2.48, 0, COLORS.navy);
}
for (const y of shelfLevels) {
box(rearShelf, 6.18, 0.16, 1.28, 0, y, 0, COLORS.wood);
box(rearShelf, 6.18, 0.18, 0.12, 0, y, 0.66, COLORS.woodDark);
}
box(rearShelf, 6.25, 0.18, 1.4, 0, 4.83, 0, COLORS.navy);
// Back shelf header.
addLabel(
rearShelf,
4.4,
0.55,
[0, 5.28, 0.08],
["SHARED SHELVES", "COUNTS UPDATED 09:55"],
{ bg: "#314a67", fg: "#fffaf0", accent: "#f2bb55" }
);
function registerCommodity(id, group) {
commodityGroups[id] = group;
group.traverse((object) => {
if (object.isMesh) {
object.userData.supplyId = id;
clickableMeshes.push(object);
}
});
}
// Rice: only three units are physically present at the start.
const riceGroup = new THREE.Group();
rearShelf.add(riceGroup);
registerCommodity("rice", riceGroup);
const riceTargetPositions = [];
for (let i = 0; i < 11; i++) {
const row = Math.floor(i / 6);
const col = i % 6;
riceTargetPositions.push(
new THREE.Vector3(-2.25 + col * 0.85, 0.86, row === 0 ? 0.32 : -0.12)
);
}
for (let i = 0; i < 3; i++) {
const rice = box(
riceGroup,
0.46,
0.43,
0.42,
riceTargetPositions[i].x,
riceTargetPositions[i].y,
riceTargetPositions[i].z,
COLORS.gold
);
rice.userData.supplyId = "rice";
clickableMeshes.push(rice);
box(riceGroup, 0.28, 0.05, 0.43, 0, 0.02, 0, COLORS.woodDark, {
castShadow: false
});
}
const riceShelfLabel = addLabel(
rearShelf,
2.2,
0.38,
[1.82, 0.83, 0.7],
["SHELF C-2", "RICE: 3 HERE / 8 LISTED"],
{ bg: "#fff4cf", fg: "#6e4a14", accent: "#ef795f" }
);
// Beans.
const beansGroup = new THREE.Group();
rearShelf.add(beansGroup);
registerCommodity("beans", beansGroup);
for (let i = 0; i < 10; i++) {
const x = -2.25 + i * 0.5;
const tin = box(beansGroup, 0.32, 0.43, 0.32, x, 2.04, 0.1, COLORS.mint);
tin.userData.supplyId = "beans";
clickableMeshes.push(tin);
box(beansGroup, 0.23, 0.05, 0.33, x, 2.05, 0.1, COLORS.mintDark, {
castShadow: false
});
}
addLabel(
rearShelf,
1.9,
0.34,
[2.02, 2.05, 0.7],
["SHELF C-1", "BEANS: 10 VERIFIED"],
{ bg: "#e4f4ec", fg: "#285d4c", accent: "#3b8f74" }
);
// Soup.
const soupGroup = new THREE.Group();
rearShelf.add(soupGroup);
registerCommodity("soup", soupGroup);
for (let i = 0; i < 6; i++) {
const x = -1.9 + i * 0.72;
const tin = box(soupGroup, 0.43, 0.46, 0.36, x, 3.24, 0.12, COLORS.coral);
tin.userData.supplyId = "soup";
clickableMeshes.push(tin);
box(soupGroup, 0.34, 0.05, 0.37, x, 3.25, 0.12, 0xf6b096, {
castShadow: false
});
}
addLabel(
rearShelf,
1.9,
0.34,
[2.02, 3.25, 0.7],
["SHELF C-3", "SOUP: 6 VERIFIED"],
{ bg: "#fff0e9", fg: "#7f4438", accent: "#ef795f" }
);
// Hygiene kits.
const hygieneGroup = new THREE.Group();
rearShelf.add(hygieneGroup);
registerCommodity("hygiene", hygieneGroup);
for (let i = 0; i < 8; i++) {
const x = -2.2 + i * 0.62;
const kit = box(hygieneGroup, 0.43, 0.35, 0.45, x, 4.43, 0.08, 0x8d9bc5);
kit.userData.supplyId = "hygiene";
clickableMeshes.push(kit);
box(hygieneGroup, 0.29, 0.05, 0.46, x, 4.45, 0.08, 0xc7d0e8, {
castShadow: false
});
}
addLabel(
rearShelf,
1.9,
0.34,
[2.02, 4.43, 0.7],
["SHELF D-1", "KITS: 8 VERIFIED"],
{ bg: "#eef0fb", fg: "#4b587e", accent: "#8d9bc5" }
);
// Side shelf, rotated into the cutaway.
const sideShelf = new THREE.Group();
sideShelf.position.set(7.1, 0, -1.15);
sideShelf.rotation.y = Math.PI / 2;
pantry.add(sideShelf);
for (const x of [-2.25, 2.25]) {
box(sideShelf, 0.16, 4.4, 1.1, x, 2.25, 0, COLORS.navy);
}
for (const y of [0.55, 1.65, 2.75, 3.85]) {
box(sideShelf, 4.7, 0.14, 1.1, 0, y, 0, COLORS.wood);
box(sideShelf, 4.7, 0.15, 0.1, 0, y, 0.58, COLORS.woodDark);
}
const sideBoxColors = [COLORS.gold, COLORS.mint, COLORS.coral, 0x8d9bc5];
for (let row = 0; row < 4; row++) {
for (let col = 0; col < 5; col++) {
box(
sideShelf,
0.42,
0.38,
0.42,
-1.8 + col * 0.85,
0.82 + row * 1.1,
0.06,
sideBoxColors[row]
);
}
}
addLabel(
sideShelf,
2.6,
0.42,
[0, 4.48, 0.15],
["DAILY RESERVE", "ROTA / SHARED STOCK"],
{ bg: "#314a67", fg: "#fffaf0", accent: "#f2bb55" }
);
// -------------------------------------------------------------------------
// Physical update board
// -------------------------------------------------------------------------
const boardCanvas = document.createElement("canvas");
boardCanvas.width = 1024;
boardCanvas.height = 640;
const boardContext = boardCanvas.getContext("2d");
const boardTexture = textureFromCanvas(boardCanvas);
const boardMesh = new THREE.Mesh(
new THREE.PlaneGeometry(4.7, 2.94),
new THREE.MeshBasicMaterial({ map: boardTexture })
);
boardMesh.position.set(0.15, 3.55, -5.52);
pantry.add(boardMesh);
box(pantry, 4.95, 3.18, 0.12, 0.15, 3.55, -5.59, COLORS.woodDark);
function drawBoard() {
const ctx = boardContext;
const w = boardCanvas.width;
const h = boardCanvas.height;
ctx.fillStyle = "#fffaf0";
ctx.fillRect(0, 0, w, h);
ctx.fillStyle = "#314a67";
ctx.fillRect(0, 0, w, 102);
ctx.fillStyle = "#f2bb55";
ctx.fillRect(0, 0, 24, 102);
ctx.fillStyle = "#fffaf0";
ctx.font = "900 42px ui-monospace, monospace";
ctx.textBaseline = "middle";
ctx.fillText("PANTRY UPDATE BOARD", 52, 51);
ctx.fillStyle = "#9fdac4";
ctx.font = "800 20px ui-monospace, monospace";
ctx.fillText("SHARED TASKS • AGGREGATE COUNTS", 54, 128);
const taskRows = [
["10:30", "P-204", "RICE x6", "C-2", state.completed.has("P-204") ? "COMPLETE" : state.supplies.rice.stale ? "COUNT STALE" : "CHECK STOCK"],
["11:00", "P-118", "BEANS x4", "C-1", "READY"],
["11:30", "P-091", "SOUP x2", "C-3", "READY"]
];
taskRows.forEach((row, index) => {
const y = 170 + index * 96;
const risk = row[4] === "COUNT STALE";
const done = row[4] === "COMPLETE";
ctx.fillStyle = done ? "#e6ece8" : risk ? "#ffe0d8" : "#edf4ef";
ctx.fillRect(35, y, w - 70, 76);
ctx.fillStyle = risk ? "#ef795f" : done ? "#839087" : "#79c9aa";
ctx.fillRect(35, y, 12, 76);
ctx.fillStyle = "#203248";
ctx.font = "900 25px ui-monospace, monospace";
ctx.fillText(row[0], 70, y + 38);
ctx.fillText(row[1], 175, y + 38);
ctx.fillText(row[2], 310, y + 38);
ctx.fillText(row[3], 560, y + 38);
ctx.fillStyle = risk ? "#a34837" : done ? "#617069" : "#2d705a";
ctx.font = "900 21px ui-monospace, monospace";
ctx.fillText(row[4], 685, y + 38);
});
ctx.fillStyle = "#dfe9e4";
ctx.fillRect(35, 475, w - 70, 112);
ctx.fillStyle = "#314a67";
ctx.font = "900 25px ui-monospace, monospace";
ctx.fillText("SHARE COUNTS, NOT IDENTITIES", 67, 514);
ctx.fillStyle = "#607064";
ctx.font = "800 20px ui-monospace, monospace";
ctx.fillText("PICKUP CODE + SHELF + QUANTITY ONLY", 67, 551);
ctx.fillStyle = "#277d63";
ctx.fillRect(w - 280, 495, 210, 64);
ctx.fillStyle = "#fffaf0";
ctx.font = "900 20px ui-monospace, monospace";
ctx.fillText("NO NAMES / NO NOTES", w - 257, 527);
boardTexture.needsUpdate = true;
}
drawBoard();
// -------------------------------------------------------------------------
// Donation arrivals
// -------------------------------------------------------------------------
const donationGroup = new THREE.Group();
donationGroup.position.set(4.7, 0, -3.75);
pantry.add(donationGroup);
box(donationGroup, 3.45, 0.2, 1.75, 0, 1.16, 0, COLORS.wood);
box(donationGroup, 3.5, 0.13, 1.82, 0, 1.28, 0, COLORS.woodDark);
for (const x of [-1.45, 1.45]) {
for (const z of [-0.62, 0.62]) {
box(donationGroup, 0.18, 1.15, 0.18, x, 0.57, z, COLORS.navy);
}
}
// Two open voxel crates.
for (const crateX of [-0.85, 0.85]) {
box(donationGroup, 1.35, 0.12, 1.12, crateX, 1.39, 0, COLORS.woodDark);
box(donationGroup, 1.35, 0.55, 0.1, crateX, 1.62, -0.52, COLORS.wood);
box(donationGroup, 0.1, 0.55, 1.12, crateX - 0.62, 1.62, 0, COLORS.wood);
box(donationGroup, 0.1, 0.55, 1.12, crateX + 0.62, 1.62, 0, COLORS.wood);
}
const incomingBoxes = [];
const incomingHomes = [];
for (let i = 0; i < 8; i++) {
const home = new THREE.Vector3(
-1.13 + (i % 4) * 0.35,
1.68,
i < 4 ? -0.23 : 0.23
);
incomingHomes.push(home.clone());
const incoming = box(
donationGroup,
0.3,
0.36,
0.34,
home.x,
home.y,
home.z,
COLORS.gold
);
incoming.userData.supplyId = "rice";
clickableMeshes.push(incoming);
incomingBoxes.push(incoming);
}
const donationLabel = addLabel(
donationGroup,
3.35,
0.65,
[0, 2.45, 0.18],
["DONATION ARRIVAL", "8 RICE UNITS / COUNT PENDING"],
{ bg: "#fff4cf", fg: "#684a18", accent: "#f2bb55" }
);
// A stacked second arrival, visually distinct but not yet in the ledger.
box(donationGroup, 0.86, 0.68, 0.78, 2.25, 1.75, -0.2, COLORS.mint);
box(donationGroup, 0.92, 0.08, 0.84, 2.25, 2.12, -0.2, COLORS.mintDark);
addLabel(
donationGroup,
1.15,
0.3,
[2.25, 1.79, 0.23],
["CANNED GOODS"],
{ bg: "#e4f4ec", fg: "#285d4c", accent: "#3b8f74" }
);
// -------------------------------------------------------------------------
// Pickup counter and floor route
// -------------------------------------------------------------------------
const counter = new THREE.Group();
counter.position.set(4.2, 0, 1.7);
pantry.add(counter);
box(counter, 4.15, 1.45, 1.55, 0, 0.73, 0, COLORS.navy);
box(counter, 4.4, 0.18, 1.75, 0, 1.54, 0, COLORS.wood);
box(counter, 4.42, 0.08, 1.77, 0, 1.65, 0, COLORS.woodDark);
// Counter panels.
for (let i = 0; i < 5; i++) {
box(counter, 0.64, 0.85, 0.06, -1.45 + i * 0.72, 0.75, 0.81, COLORS.cream);
}
addLabel(
counter,
2.8,
0.48,
[0, 2.28, -0.2],
["PICKUP WINDOW", "CODE ONLY / NO NAMES"],
{ bg: "#314a67", fg: "#fffaf0", accent: "#79c9aa" }
);
const pickupCodeLabel = addLabel(
counter,
2.1,
0.5,
[-0.55, 1.98, 0.2],
["P-204", "RICE x6 / SHELF C-2"],
{ bg: "#fffaf0", fg: "#203248", accent: "#ef795f" }
);
// Blocky code token on the counter.
box(counter, 0.52, 0.72, 0.12, 1.45, 1.99, 0.08, COLORS.gold);
box(counter, 0.32, 0.09, 0.14, 1.45, 2.1, 0.16, COLORS.ink, {
castShadow: false
});
// Gold floor markers indicating the shared pickup route.
for (let i = 0; i < 7; i++) {
box(pantry, 0.42, 0.06, 0.42, -0.8 + i * 0.72, 0.08, 2.0, COLORS.gold, {
castShadow: false
});
}
// Voxel plant in a corner.
box(pantry, 0.72, 0.75, 0.72, -7.1, 0.38, 2.8, COLORS.coral);
box(pantry, 0.54, 0.16, 0.54, -7.1, 0.82, 2.8, 0x9f4e40);
box(pantry, 0.24, 1.25, 0.24, -7.1, 1.42, 2.8, 0x557a48);
box(pantry, 0.82, 0.24, 0.3, -7.18, 1.72, 2.8, COLORS.green);
box(pantry, 0.3, 0.24, 0.82, -7.1, 2.02, 2.78, COLORS.green);
// Voxel clock on the wall.
box(pantry, 0.95, 0.95, 0.12, -6.55, 6.35, -5.45, COLORS.navy);
box(pantry, 0.72, 0.72, 0.13, -6.55, 6.35, -5.36, COLORS.cream);
box(pantry, 0.07, 0.28, 0.05, -6.55, 6.48, -5.27, COLORS.ink, {
castShadow: false
});
box(pantry, 0.23, 0.06, 0.05, -6.45, 6.35, -5.27, COLORS.ink, {
castShadow: false
});
// -------------------------------------------------------------------------
// Selection outline
// -------------------------------------------------------------------------
let selectionOutline = null;
function updateSelectionOutline() {
if (selectionOutline) {
scene.remove(selectionOutline);
selectionOutline.geometry.dispose();
selectionOutline.material.dispose();
selectionOutline = null;
}
const group = commodityGroups[state.selected];
if (!group) return;
selectionOutline = new THREE.BoxHelper(group, 0xef795f);
selectionOutline.material.transparent = true;
selectionOutline.material.opacity = 0.9;
selectionOutline.material.depthTest = false;
selectionOutline.renderOrder = 20;
scene.add(selectionOutline);
}
updateSelectionOutline();
// -------------------------------------------------------------------------
// UI rendering
// -------------------------------------------------------------------------
const taskList = document.getElementById("taskList");
const stockList = document.getElementById("stockList");
const selectedDetails = document.getElementById("selectedDetails");
const eventLog = document.getElementById("eventLog");
const riskChip = document.getElementById("riskChip");
const publishButton = document.getElementById("publishButton");
const receiveButton = document.getElementById("receiveButton");
const resetButton = document.getElementById("resetButton");
function renderTasks() {
const tasks = [
{ code: "P-204", id: "rice", time: "10:30", quantity: 6 },
{ code: "P-118", id: "beans", time: "11:00", quantity: 4 },
{ code: "P-091", id: "soup", time: "11:30", quantity: 2 }
];
taskList.innerHTML = tasks.map((task) => {
const supply = state.supplies[task.id];
const completed = state.completed.has(task.code);
const risk = supply.stale && !completed;
const status = completed ? "COMPLETE" : risk ? "COUNT STALE" : "READY";
const statusClass = completed ? "done" : risk ? "risk" : "";
return `
<button class="task-card ${state.selected === task.id ? "selected" : ""}"
data-task="${task.id}" type="button">
<span class="task-row">
<span class="task-code">${task.code}</span>
<span class="pill ${statusClass}">${status}</span>
</span>
<span class="task-title">${supply.name} × ${task.quantity}</span>
<span class="task-meta">${task.time} · Shelf ${supply.shelf} · code only</span>
</button>
`;
}).join("");
}
function renderStock() {
stockList.innerHTML = Object.values(state.supplies).map((supply) => {
const risk = supply.stale;
return `
<button class="stock-card ${state.selected === supply.id ? "selected" : ""}"
data-stock="${supply.id}" type="button">
<span class="stock-row">
<span class="detail-title">
<span class="swatch" style="background:${supply.color}"></span>
${supply.shortName}
</span>
<span class="pill ${risk ? "risk" : ""}">${risk ? "STALE" : "VERIFIED"}</span>
</span>
<span class="task-meta">Shelf ${supply.shelf} · listed ${supply.listed} · verified ${supply.last}</span>
</button>
`;
}).join("");
}
function renderDetails() {
const supply = state.supplies[state.selected];
const difference = supply.listed - supply.actual;
selectedDetails.innerHTML = `
<div class="detail-title">
<span class="swatch" style="background:${supply.color}"></span>
${supply.name}
</div>
<div class="metric-row">
<span>Published count</span>
<b>${supply.listed}</b>
</div>
<div class="metric-row">
<span>Units visible at shelf</span>
<b>${supply.actual}</b>
</div>
<div class="metric-row">
<span>Last verified</span>
<b>${supply.last}</b>
</div>
${supply.stale ? `
<div class="warning">
<strong>Count discrepancy: ${difference > 0 ? "+" : ""}${difference}.</strong><br>
The shared sheet can confirm a pickup even when the physical shelf no longer
matches. Publish a verified count before confirming more tasks.
</div>
` : `
<div class="verified">
<strong>Counts agree.</strong><br>
This item has a current shared count and no displayed stock discrepancy.
</div>
`}
`;
publishButton.disabled = supply.id !== "rice" || !supply.stale || state.receiving;
receiveButton.disabled = supply.id !== "rice" || state.receiving;
receiveButton.textContent = state.receiving
? "Receiving donation…"
: "Receive 8 rice units + sync";
}
function renderLog() {
eventLog.innerHTML = state.log.slice().reverse().map((entry) => `
<div class="log-entry ${entry.type}">
<time>${entry.time}</time>
<span class="log-message">${entry.message}</span>
</div>
`).join("");
}
function renderRiskChip() {
const risky = Object.values(state.supplies).filter((supply) => supply.stale).length;
riskChip.textContent = risky ? `${risky} STOCK COUNT AT RISK` : "ALL COUNTS VERIFIED";
riskChip.classList.toggle("safe", risky === 0);
}
function renderUI() {
renderTasks();
renderStock();
renderDetails();
renderLog();
renderRiskChip();
resetButton.disabled = state.receiving;
drawBoard();
}
taskList.addEventListener("click", (event) => {
const button = event.target.closest("[data-task]");
if (!button) return;
selectSupply(button.dataset.task);
});
stockList.addEventListener("click", (event) => {
const button = event.target.closest("[data-stock]");
if (!button) return;
selectSupply(button.dataset.stock);
});
function selectSupply(id) {
state.selected = id;
updateSelectionOutline();
renderUI();
}
// -------------------------------------------------------------------------
// Operational actions
// -------------------------------------------------------------------------
let resultTimer = null;
function showResult(title, body, tone = "info") {
const result = document.getElementById("result");
document.getElementById("resultTitle").textContent = title;
document.getElementById("resultBody").textContent = body;
result.style.borderLeft = `7px solid ${tone === "success" ? "#3b8f74" : tone === "alert" ? "#ef795f" : "#f2bb55"}`;
result.classList.add("show");
clearTimeout(resultTimer);
resultTimer = setTimeout(() => result.classList.remove("show"), 6500);
}
document.getElementById("closeResult").addEventListener("click", () => {
document.getElementById("result").classList.remove("show");
});
document.getElementById("attemptButton").addEventListener("click", () => {
const rice = state.supplies.rice;
if (state.completed.has(rice.code)) {
showResult(
"Pickup already completed",
"P-204 is complete. The shared board records the anonymous task and aggregate quantity only.",
"success"
);
return;
}
const insufficient = rice.actual < rice.request;
const staleConfirmation = rice.stale && rice.listed >= rice.request && insufficient;
if (insufficient) {
const title = staleConfirmation
? "Pickup failed — outdated stock information"
: "Pickup failed — shelf quantity was insufficient";
const explanation = staleConfirmation
? `The shared count sheet showed ${rice.listed} rice units, so P-204 was confirmed for ${rice.request}. Only ${rice.actual} units were actually visible at shelf ${rice.shelf}. The outdated count made the task appear ready when the stock was not there.`
: `The shelf count is current, but only ${rice.actual} units are available at shelf ${rice.shelf}. The request is ${rice.request} units.`;
addLog(
staleConfirmation
? "P-204 failed at C-2: published count and shelf quantity differed."
: "P-204 failed at C-2: verified quantity was insufficient.",
"alert"
);
showResult(
title,
`${explanation} Resolve the task by logging the donation or publishing a verified count before confirming future pickups.`,
"alert"
);
} else {
state.completed.add(rice.code);
addLog("P-204 completed using a verified shelf count.", "success");
showResult(
"Pickup completed",
`P-204 found ${rice.actual} rice units at shelf ${rice.shelf}, enough for the ${rice.request}-unit task. The task is complete and no personal details were recorded.`,
"success"
);
}
renderUI();
});
publishButton.addEventListener("click", () => {
const rice = state.supplies.rice;
if (!rice.stale) return;
rice.listed = rice.actual;
rice.last = state.now;
rice.stale = false;
addLog(`Shelf C-2 verified and published at ${rice.listed} rice units.`, "success");
riceShelfLabel.redraw(
["SHELF C-2", `RICE: ${rice.actual} HERE / ${rice.listed} LISTED`],
{ bg: "#fff4cf", fg: "#6e4a14", accent: "#3b8f74" }
);
renderUI();
updateSelectionOutline();
showResult(
"Verified count published",
`The shared sheet now matches the shelf: ${rice.actual} rice units. A subsequent pickup will no longer fail because of stale information, although it will still be short if ${rice.request} units are requested.`,
"info"
);
});
document.getElementById("locateButton").addEventListener("click", () => {
const group = commodityGroups[state.selected];
if (!group) return;
const world = new THREE.Vector3();
group.getWorldPosition(world);
cameraState.targetGoal.set(world.x, 1.8, world.z);
});
function easeInOutCubic(t) {
return t < 0.5
? 4 * t * t * t
: 1 - Math.pow(-2 * t + 2, 3) / 2;
}
function moveDonationBox(boxMesh, index) {
return new Promise((resolve) => {
const from = boxMesh.position.clone();
const targetLocal = riceTargetPositions[index + 3].clone();
const worldTarget = rearShelf.localToWorld(targetLocal.clone());
const to = donationGroup.worldToLocal(worldTarget.clone());
animations.push({
mesh: boxMesh,
from,
to,
start: performance.now() + index * 65,
duration: 850,
resolve
});
});
}
receiveButton.addEventListener("click", async () => {
if (state.receiving) return;
state.receiving = true;
renderDetails();
resetButton.disabled = true;
donationLabel.redraw(
["DONATION ARRIVAL", "MOVING 8 UNITS TO SHELF C-2"],
{ bg: "#fff4cf", fg: "#684a18", accent: "#f2bb55" }
);
addLog("Donation arrival started: 8 rice units moving to shelf C-2.");
await Promise.all(incomingBoxes.map(moveDonationBox));
const rice = state.supplies.rice;
rice.actual = 11;
rice.listed = 11;
rice.last = state.now;
rice.stale = false;
state.receiving = false;
donationLabel.redraw(
["DONATION RECEIVED", "8 RICE UNITS / COUNT VERIFIED"],
{ bg: "#e4f4ec", fg: "#285d4c", accent: "#3b8f74" }
);
riceShelfLabel.redraw(
["SHELF C-2", `RICE: ${rice.actual} HERE / ${rice.listed} LISTED`],
{ bg: "#e4f4ec", fg: "#285d4c", accent: "#3b8f74" }
);
addLog("Shelf C-2 updated and published at 11 rice units.", "success");
renderUI();
updateSelectionOutline();
showResult(
"Donation received and counts synchronized",
"Eight rice units were moved to shelf C-2. The shared sheet and physical shelf now agree at 11 units. P-204 can be fulfilled without a stale-count failure.",
"success"
);
});
resetButton.addEventListener("click", () => {
// Return the donation boxes to their arrival positions.
incomingBoxes.forEach((boxMesh, index) => {
donationGroup.attach(boxMesh);
boxMesh.position.copy(incomingHomes[index]);
boxMesh.rotation.set(0, 0, 0);
});
state.now = "10:42";
state.receiving = false;
state.selected = "rice";
state.completed.clear();
Object.assign(state.supplies.rice, {
actual: 3,
listed: 8,
last: "08:10",
stale: true
});
state.log = [
{ time: "08:10", message: "Shelf C-2 count published.", type: "" },
{ time: "09:55", message: "Shelves C-1 and C-3 verified.", type: "success" },
{ time: "10:12", message: "Donation arrival logged: 8 rice units.", type: "" },
{ time: "10:42", message: "P-204 confirmed using the shared count sheet.", type: "alert" }
];
donationLabel.redraw(
["DONATION ARRIVAL", "8 RICE UNITS / COUNT PENDING"],
{ bg: "#fff4cf", fg: "#684a18", accent: "#f2bb55" }
);
riceShelfLabel.redraw(
["SHELF C-2", "RICE: 3 HERE / 8 LISTED"],
{ bg: "#fff4cf", fg: "#6e4a14", accent: "#ef795f" }
);
pickupCodeLabel.redraw(
["P-204", "RICE x6 / SHELF C-2"],
{ bg: "#fffaf0", fg: "#203248", accent: "#ef795f" }
);
cameraState.targetGoal.set(0, 2, -0.35);
cameraState.yaw = 0.72;
cameraState.pitch = 0.72;
cameraState.zoom = 1;
camera.zoom = 1;
camera.updateProjectionMatrix();
renderUI();
updateSelectionOutline();
showResult(
"Scenario reset",
"The pantry is back to its initial state: the sheet lists 8 rice units, while only 3 are visible at shelf C-2.",
"info"
);
});
renderUI();
// -------------------------------------------------------------------------
// Custom camera controls — no add-ons
// -------------------------------------------------------------------------
const pointer = {
down: false,
moved: false,
x: 0,
y: 0,
lastX: 0,
lastY: 0,
button: 0
};
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
function setPointerNDC(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;
}
function pickSupply(event) {
setPointerNDC(event);
raycaster.setFromCamera(pointerNDC, camera);
const hit = raycaster.intersectObjects(clickableMeshes, false)[0];
if (hit?.object?.userData?.supplyId) {
selectSupply(hit.object.userData.supplyId);
}
}
renderer.domElement.addEventListener("pointerdown", (event) => {
pointer.down = true;
pointer.moved = false;
pointer.x = event.clientX;
pointer.y = event.clientY;
pointer.lastX = event.clientX;
pointer.lastY = event.clientY;
pointer.button = event.button;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (pointer.down) {
const dx = event.clientX - pointer.lastX;
const dy = event.clientY - pointer.lastY;
if (Math.abs(event.clientX - pointer.x) + Math.abs(event.clientY - pointer.y) > 4) {
pointer.moved = true;
}
if (event.shiftKey || pointer.button === 2) {
const right = new THREE.Vector3(
Math.cos(cameraState.yaw),
0,
-Math.sin(cameraState.yaw)
);
cameraState.targetGoal.addScaledVector(right, -dx * 0.018);
cameraState.targetGoal.y = THREE.MathUtils.clamp(
cameraState.targetGoal.y + dy * 0.012,
0.5,
4.5
);
} else {
cameraState.yaw -= dx * 0.007;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.006,
0.42,
1.2
);
}
} else {
setPointerNDC(event);
raycaster.setFromCamera(pointerNDC, camera);
const hit = raycaster.intersectObjects(clickableMeshes, false)[0];
renderer.domElement.style.cursor = hit ? "pointer" : "grab";
}
pointer.lastX = event.clientX;
pointer.lastY = event.clientY;
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (pointer.down && !pointer.moved) {
pickSupply(event);
}
pointer.down = false;
renderer.domElement.releasePointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointercancel", () => {
pointer.down = false;
});
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
1.75
);
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => {
cameraState.yaw = 0.72;
cameraState.pitch = 0.72;
cameraState.zoom = 1;
cameraState.targetGoal.set(0, 2, -0.35);
camera.zoom = 1;
camera.updateProjectionMatrix();
});
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const halfHeight = Math.max(10.5, 10.2 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
function updateCamera() {
const distance = 23;
const horizontal = Math.cos(cameraState.pitch) * distance;
cameraState.target.lerp(cameraState.targetGoal, 0.075);
camera.position.set(
cameraState.target.x + Math.sin(cameraState.yaw) * horizontal,
cameraState.target.y + Math.sin(cameraState.pitch) * distance,
cameraState.target.z + Math.cos(cameraState.yaw) * horizontal
);
camera.lookAt(cameraState.target);
camera.zoom += (cameraState.zoom - camera.zoom) * 0.12;
camera.updateProjectionMatrix();
}
function updateAnimations(now) {
for (let i = animations.length - 1; i >= 0; i--) {
const animation = animations[i];
if (now < animation.start) continue;
const raw = THREE.MathUtils.clamp(
(now - animation.start) / animation.duration,
0,
1
);
const eased = easeInOutCubic(raw);
animation.mesh.position.lerpVectors(animation.from, animation.to, eased);
animation.mesh.position.y += Math.sin(raw * Math.PI) * 1.25;
animation.mesh.rotation.y = Math.sin(raw * Math.PI) * 0.18;
if (raw >= 1) {
rearShelf.attach(animation.mesh);
animation.mesh.position.copy(riceTargetPositions[i + 3]);
animation.mesh.rotation.set(0, 0, 0);
animation.resolve();
animations.splice(i, 1);
}
}
}
const clock = new THREE.Clock();
function animate(now) {
requestAnimationFrame(animate);
const delta = clock.getDelta();
updateCamera();
updateAnimations(now);
if (selectionOutline) {
selectionOutline.update();
selectionOutline.material.opacity = 0.72 + Math.sin(now * 0.005) * 0.18;
}
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
loading.classList.add("hidden");
</script>
</body>
</html>
```