Prompt specification
Build or customize the Three.js 3D scene "Community workshop capacity game" 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 workshop capacity game
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/community-workshop-capacity-game-x0224
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows shared table space. Create a workshop with a finite tabletop area and several activity kits; users allocate space and tool access so every participant can complete one visible operation. Low-poly.
Working Three.js Starter (community-workshop-capacity-game-x0224):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shared Table Workshop</title>
<style>
:root {
--ink: #17232b;
--muted: #66727a;
--paper: rgba(251, 248, 239, 0.94);
--line: rgba(32, 49, 58, 0.13);
--accent: #ff6b57;
--green: #218a72;
--shadow: 0 18px 55px rgba(31, 38, 41, 0.18);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
color: var(--ink);
background: #d8d4c7;
}
button, select { font: inherit; }
button {
cursor: pointer;
border: 0;
}
button:disabled {
cursor: not-allowed;
opacity: 0.48;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.topbar {
position: fixed;
z-index: 10;
top: 18px;
left: 18px;
right: 18px;
min-height: 70px;
display: flex;
align-items: center;
gap: 22px;
padding: 12px 14px 12px 18px;
border: 1px solid rgba(255,255,255,.58);
border-radius: 18px;
background: rgba(251, 248, 239, 0.92);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 250px;
}
.brand-mark {
position: relative;
width: 42px;
height: 42px;
border-radius: 13px;
background: var(--ink);
overflow: hidden;
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
border-radius: 4px;
background: #f7c657;
transform: rotate(-12deg);
}
.brand-mark::before {
width: 29px;
height: 10px;
left: 5px;
top: 9px;
}
.brand-mark::after {
width: 19px;
height: 10px;
right: 4px;
bottom: 8px;
background: #ff735f;
}
.eyebrow {
margin: 0 0 3px;
font-size: 10px;
font-weight: 800;
letter-spacing: .16em;
text-transform: uppercase;
color: var(--muted);
}
h1 {
margin: 0;
font-size: 17px;
line-height: 1.1;
letter-spacing: -.02em;
}
.metrics {
display: flex;
align-items: stretch;
gap: 8px;
margin-left: auto;
}
.metric {
min-width: 86px;
padding: 7px 11px;
border-left: 1px solid var(--line);
}
.metric strong {
display: block;
font-size: 19px;
line-height: 1.1;
}
.metric span {
display: block;
margin-top: 4px;
font-size: 9px;
font-weight: 800;
letter-spacing: .12em;
text-transform: uppercase;
color: var(--muted);
}
.top-actions {
display: flex;
gap: 8px;
}
.button {
min-height: 42px;
padding: 0 15px;
border-radius: 11px;
border: 1px solid var(--line);
background: #fffef9;
color: var(--ink);
font-size: 12px;
font-weight: 750;
transition: transform .16s ease, box-shadow .16s ease, background .16s ease;
}
.button:hover:not(:disabled) {
transform: translateY(-1px);
box-shadow: 0 6px 18px rgba(23,35,43,.12);
}
.button.primary {
border-color: var(--ink);
background: var(--ink);
color: #fffaf0;
}
.button.soft {
background: #ece7da;
}
.panel {
position: fixed;
z-index: 9;
top: 106px;
bottom: 62px;
border: 1px solid rgba(255,255,255,.62);
border-radius: 18px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
overflow: hidden;
}
.roster {
left: 18px;
width: 280px;
display: flex;
flex-direction: column;
}
.inspector {
right: 18px;
width: 320px;
overflow-y: auto;
padding-bottom: 16px;
}
.panel-heading {
padding: 18px 18px 14px;
border-bottom: 1px solid var(--line);
}
.panel-heading h2 {
margin: 0;
font-size: 15px;
letter-spacing: -.02em;
}
.panel-heading p {
margin: 7px 0 0;
font-size: 11px;
line-height: 1.5;
color: var(--muted);
}
#participantList {
flex: 1;
padding: 10px;
overflow-y: auto;
}
.person-card {
width: 100%;
display: grid;
grid-template-columns: 37px 1fr auto;
align-items: center;
gap: 10px;
margin: 4px 0;
padding: 11px 10px;
border: 1px solid transparent;
border-radius: 13px;
background: transparent;
color: var(--ink);
text-align: left;
transition: background .15s ease, border-color .15s ease, transform .15s ease;
}
.person-card:hover {
background: rgba(255,255,255,.65);
transform: translateX(2px);
}
.person-card.selected {
border-color: var(--line);
background: #fffdf6;
box-shadow: 0 5px 16px rgba(23,35,43,.07);
}
.avatar {
position: relative;
width: 34px;
height: 34px;
border-radius: 11px;
background: var(--person);
box-shadow: inset 0 -8px 0 rgba(0,0,0,.08);
}
.avatar::after {
content: "";
position: absolute;
left: 10px;
top: 7px;
width: 14px;
height: 14px;
border-radius: 50%;
background: #f5d8bd;
box-shadow: 0 8px 0 -3px var(--person);
}
.person-name {
font-size: 12px;
font-weight: 800;
}
.person-detail {
margin-top: 3px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
font-size: 10px;
color: var(--muted);
}
.status-pill {
padding: 5px 7px;
border-radius: 999px;
background: #ece8dd;
color: #657078;
font-size: 8px;
font-weight: 850;
letter-spacing: .06em;
text-transform: uppercase;
white-space: nowrap;
}
.status-pill.ready {
color: #176c59;
background: #dcefe7;
}
.status-pill.working {
color: #815500;
background: #fff0bf;
}
.status-pill.complete {
color: #fff;
background: var(--green);
}
.mini-progress {
grid-column: 2 / 4;
display: block;
height: 3px;
margin-top: 2px;
overflow: hidden;
border-radius: 3px;
background: #e5e1d7;
}
.mini-progress i {
display: block;
height: 100%;
width: 0;
border-radius: inherit;
background: var(--person);
transition: width .1s linear;
}
.roster-footer {
display: flex;
gap: 8px;
padding: 11px;
border-top: 1px solid var(--line);
}
.roster-footer .button { flex: 1; }
.selected-header {
display: flex;
align-items: center;
gap: 12px;
padding: 18px;
border-bottom: 1px solid var(--line);
}
.selected-avatar {
width: 42px;
height: 42px;
border-radius: 13px;
background: var(--person);
box-shadow: inset 0 -10px 0 rgba(0,0,0,.08);
flex: none;
}
.selected-header h2 {
margin: 0;
font-size: 17px;
}
.selected-header p {
margin: 4px 0 0;
font-size: 10px;
color: var(--muted);
}
.steps {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
padding: 14px 18px 0;
}
.step {
position: relative;
padding-top: 16px;
color: #9a9e9e;
font-size: 9px;
font-weight: 800;
text-align: center;
}
.step::before {
content: "";
position: absolute;
z-index: 0;
top: 4px;
left: 0;
width: 100%;
height: 2px;
background: #dedbd1;
}
.step.done { color: var(--green); }
.step.done::before { background: var(--green); }
.section {
padding: 16px 18px 0;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 9px;
}
.section-title strong {
font-size: 10px;
font-weight: 850;
letter-spacing: .12em;
text-transform: uppercase;
}
.section-title span {
font-size: 10px;
color: var(--muted);
}
.space-row {
display: flex;
align-items: center;
gap: 10px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255,255,255,.55);
}
.bay-badge {
display: grid;
place-items: center;
width: 38px;
height: 38px;
flex: none;
border-radius: 10px;
background: var(--ink);
color: white;
font-size: 12px;
font-weight: 850;
}
.space-copy {
flex: 1;
min-width: 0;
}
.space-copy b {
display: block;
font-size: 11px;
}
.space-copy small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
}
.mini-button {
padding: 7px 9px;
border: 1px solid var(--line);
border-radius: 8px;
background: #fffef9;
color: var(--ink);
font-size: 9px;
font-weight: 800;
}
.kit-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.kit-option {
min-height: 78px;
padding: 10px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255,255,255,.58);
color: var(--ink);
text-align: left;
transition: transform .14s ease, border-color .14s ease, background .14s ease;
}
.kit-option:hover:not(:disabled) {
transform: translateY(-2px);
border-color: rgba(23,35,43,.28);
background: #fffef9;
}
.kit-option.selected {
border-color: var(--person);
background: color-mix(in srgb, var(--person) 13%, white);
box-shadow: inset 0 0 0 1px var(--person);
}
.kit-icon {
display: grid;
place-items: center;
width: 27px;
height: 27px;
margin-bottom: 7px;
border-radius: 8px;
color: white;
background: var(--kit);
font-size: 17px;
font-weight: 800;
}
.kit-option b {
display: block;
font-size: 10px;
line-height: 1.15;
}
.kit-option small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 8px;
line-height: 1.25;
}
.tool-card {
padding: 12px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255,255,255,.55);
}
.tool-top {
display: flex;
align-items: center;
gap: 9px;
}
.tool-symbol {
display: grid;
place-items: center;
width: 33px;
height: 33px;
border-radius: 9px;
background: #e7e2d5;
font-size: 18px;
}
.tool-copy { flex: 1; }
.tool-copy b { display: block; font-size: 10px; }
.tool-copy small { display: block; margin-top: 3px; color: var(--muted); font-size: 9px; }
#grantTool {
width: 100%;
margin-top: 11px;
}
.secondary-actions {
display: flex;
gap: 7px;
padding: 10px 18px 0;
}
.secondary-actions .button { flex: 1; padding: 0 8px; font-size: 9px; }
.ready-note {
margin: 16px 18px 0;
padding: 12px;
border-radius: 12px;
background: #e1eee7;
color: #26624f;
font-size: 10px;
line-height: 1.45;
}
.ready-note.blocked {
background: #eee9dd;
color: #6c6458;
}
.scene-hint {
position: fixed;
z-index: 8;
left: 50%;
bottom: 17px;
transform: translateX(-50%);
padding: 9px 14px;
border: 1px solid rgba(255,255,255,.52);
border-radius: 999px;
background: rgba(23,35,43,.83);
color: rgba(255,255,255,.88);
box-shadow: 0 8px 24px rgba(23,35,43,.18);
font-size: 9px;
font-weight: 700;
letter-spacing: .03em;
pointer-events: none;
white-space: nowrap;
}
#tooltip {
position: fixed;
z-index: 20;
display: none;
pointer-events: none;
padding: 7px 10px;
border-radius: 8px;
background: rgba(23,35,43,.92);
color: white;
font-size: 10px;
font-weight: 700;
box-shadow: 0 8px 20px rgba(0,0,0,.18);
transform: translate(12px, 12px);
}
#toast {
position: fixed;
z-index: 30;
left: 50%;
top: 104px;
max-width: 360px;
padding: 11px 16px;
border-radius: 11px;
background: var(--ink);
color: white;
box-shadow: 0 10px 30px rgba(23,35,43,.23);
font-size: 11px;
font-weight: 700;
opacity: 0;
transform: translate(-50%, -12px);
transition: opacity .2s ease, transform .2s ease;
pointer-events: none;
text-align: center;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#completionBanner {
position: fixed;
z-index: 15;
left: 50%;
top: 106px;
padding: 10px 16px;
border-radius: 999px;
background: #218a72;
color: white;
box-shadow: 0 10px 30px rgba(33,138,114,.25);
font-size: 10px;
font-weight: 850;
letter-spacing: .05em;
text-transform: uppercase;
opacity: 0;
transform: translate(-50%, -8px) scale(.96);
transition: .25s ease;
pointer-events: none;
}
#completionBanner.show {
opacity: 1;
transform: translate(-50%, 0) scale(1);
}
::-webkit-scrollbar { width: 7px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { border-radius: 8px; background: #c9c5ba; }
@media (max-width: 1050px) {
.brand { min-width: 190px; }
.metric { min-width: 70px; }
.roster { width: 240px; }
.inspector { width: 290px; }
}
@media (max-width: 780px) {
.topbar {
top: 10px;
left: 10px;
right: 10px;
min-height: 60px;
gap: 8px;
padding: 9px 10px;
}
.brand { min-width: 0; }
.brand .eyebrow, .brand h1 { display: none; }
.metrics { gap: 2px; }
.metric { min-width: 48px; padding: 5px 7px; }
.metric strong { font-size: 15px; }
.metric span { font-size: 7px; }
.top-actions .button:first-child { display: none; }
.panel {
top: auto;
bottom: 52px;
max-height: 42vh;
}
.roster { left: 10px; width: 43vw; border-radius: 15px; }
.inspector { right: 10px; width: 52vw; border-radius: 15px; }
.panel-heading p, .roster-footer { display: none; }
.panel-heading { padding: 12px; }
#participantList { padding: 5px; }
.person-card { grid-template-columns: 30px 1fr; padding: 8px; }
.avatar { width: 29px; height: 29px; }
.status-pill { display: none; }
.mini-progress { grid-column: 2; }
.selected-header, .section { padding-left: 12px; padding-right: 12px; }
.secondary-actions, .ready-note { margin-left: 12px; margin-right: 12px; }
.scene-hint { display: none; }
#completionBanner { top: 78px; }
#toast { top: 78px; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive 3D shared workshop table"></canvas>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<p class="eyebrow">Community workshop · table 04</p>
<h1>Shared Table Planner</h1>
</div>
</div>
<div class="metrics">
<div class="metric"><strong id="spaceMetric">0/4</strong><span>Spaces</span></div>
<div class="metric"><strong id="kitMetric">0/4</strong><span>Kits</span></div>
<div class="metric"><strong id="toolMetric">0/4</strong><span>Tools</span></div>
</div>
<div class="top-actions">
<button id="clearPlan" class="button soft">Clear plan</button>
<button id="startWorkshop" class="button primary">Run workshop</button>
</div>
</header>
<aside class="panel roster">
<div class="panel-heading">
<p class="eyebrow">People</p>
<h2>Workshop roster</h2>
<p>Select a participant, then allocate a table bay, kit, and shared tool.</p>
</div>
<div id="participantList"></div>
<div class="roster-footer">
<button id="restoreSample" class="button soft">Restore sample</button>
</div>
</aside>
<aside class="panel inspector">
<div id="selectedHeader" class="selected-header"></div>
<div class="steps">
<div id="stepSpace" class="step">Space</div>
<div id="stepKit" class="step">Kit</div>
<div id="stepTool" class="step">Tool</div>
</div>
<section class="section">
<div class="section-title">
<strong>01 · Table space</strong>
<span>12 finite bays</span>
</div>
<div class="space-row">
<div id="bayBadge" class="bay-badge">—</div>
<div class="space-copy">
<b id="spaceTitle">No bay allocated</b>
<small id="spaceSubtitle">Click a bay on the 3D table</small>
</div>
<button id="clearSpace" class="mini-button">Clear</button>
</div>
</section>
<section class="section">
<div class="section-title">
<strong>02 · Activity kit</strong>
<span>One kit each</span>
</div>
<div id="kitGrid" class="kit-grid"></div>
</section>
<section class="section">
<div class="section-title">
<strong>03 · Tool access</strong>
<span>Shared inventory</span>
</div>
<div id="toolCard" class="tool-card"></div>
<button id="grantTool" class="button primary">Grant access</button>
</section>
<div class="secondary-actions">
<button id="clearKit" class="button soft">Remove kit</button>
<button id="focusBay" class="button soft">Center bay</button>
</div>
<div id="readyNote" class="ready-note blocked"></div>
</aside>
<div class="scene-hint">Drag to orbit · Shift-drag to pan · Scroll to zoom · Click a bay to allocate</div>
<div id="tooltip"></div>
<div id="toast"></div>
<div id="completionBanner">All four operations complete</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
// ------------------------------------------------------------
// State
// ------------------------------------------------------------
const participants = [
{ id: 0, name: 'Ada', color: '#ff6b57', cell: 0, kit: 'circuit', tool: false, progress: 0 },
{ id: 1, name: 'Bo', color: '#2a9d8f', cell: 1, kit: 'weave', tool: true, progress: 0 },
{ id: 2, name: 'Cleo', color: '#f0ad3d', cell: 2, kit: 'origami', tool: false, progress: 0 },
{ id: 3, name: 'Dev', color: '#6c63ff', cell: 3, kit: 'wood', tool: false, progress: 0 }
];
const kits = {
circuit: { name: 'Circuit board', short: 'Solder a micro-circuit', icon: '⌁', color: '#24796c', tool: 'Soldering iron', toolIcon: '⌁' },
weave: { name: 'Weaving frame', short: 'Stitch a woven strip', icon: '≡', color: '#cf6658', tool: 'Needle & thread', toolIcon: '↝' },
origami: { name: 'Paper folding', short: 'Fold an origami form', icon: '◇', color: '#e3a532', tool: 'Bone folder', toolIcon: '◇' },
wood: { name: 'Wood shaping', short: 'File a wooden block', icon: '▱', color: '#6959a8', tool: 'Hand file', toolIcon: '▱' }
};
const COLS = 4;
const ROWS = 3;
const TABLE_TOP_Y = 1.72;
const TABLE_WIDTH = 11;
const TABLE_DEPTH = 8.4;
const CELL_W = 2.42;
const CELL_D = 2.42;
let selectedId = 0;
let phase = 'planning';
let runStart = 0;
let hoveredCell = -1;
let toastTimer;
let uiTick = 0;
let cameraGoal = null;
const cellPosition = (index) => {
const row = Math.floor(index / COLS);
const col = index % COLS;
return {
x: (col - (COLS - 1) / 2) * CELL_W,
z: (row - (ROWS - 1) / 2) * CELL_D,
label: `${String.fromCharCode(65 + col)}${row + 1}`
};
};
const selectedParticipant = () => participants[selectedId];
function stateFor(p) {
if (phase === 'running') return 'working';
if (phase === 'complete' && p.progress >= 1) return 'complete';
if (p.cell === null) return 'space';
if (!p.kit) return 'kit';
if (!p.tool) return 'tool';
return 'ready';
}
const stateLabels = {
space: 'Needs space',
kit: 'Needs kit',
tool: 'Needs tool',
ready: 'Ready',
working: 'Working',
complete: 'Complete'
};
// ------------------------------------------------------------
// Renderer, scene, and camera
// ------------------------------------------------------------
const canvas = document.getElementById('scene');
const renderer = new THREE.WebGLRenderer({ canvas, 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;
const scene = new THREE.Scene();
scene.background = new THREE.Color('#d8d4c7');
scene.fog = new THREE.Fog('#d8d4c7', 25, 47);
const camera = new THREE.PerspectiveCamera(43, window.innerWidth / window.innerHeight, 0.1, 80);
const cameraState = {
theta: 0.61,
phi: 0.92,
radius: 18.4,
target: new THREE.Vector3(0, 1.35, 0)
};
const hemi = new THREE.HemisphereLight('#fff7df', '#66736e', 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight('#fff0cf', 3.2);
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 = 38;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight('#b9d9ff', 1.15);
fill.position.set(9, 7, -7);
scene.add(fill);
const kitRoot = new THREE.Group();
const confettiRoot = new THREE.Group();
scene.add(kitRoot, confettiRoot);
const cellMeshes = [];
const cellLabels = [];
const kitGroups = new Map();
const personGroups = new Map();
const standard = (color, extra = {}) => new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.02,
flatShading: true,
...extra
});
const materials = {
floor: standard('#bfc0b5'),
wall: standard('#ded8c8'),
wallSide: standard('#d2cdbd'),
trim: standard('#32434a'),
wood: standard('#b9824f'),
woodDark: standard('#71472f'),
woodLight: standard('#d4a66c'),
metal: standard('#45545a', { metalness: 0.35 }),
cream: standard('#f3ead7'),
black: standard('#263137'),
green: standard('#286f5e'),
red: standard('#d94d42'),
yellow: standard('#e4ad32'),
blue: standard('#5c6ea7')
};
function addBox(parent, w, h, d, material, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(parent, rTop, rBottom, h, segments, material, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(new THREE.CylinderGeometry(rTop, rBottom, h, segments), material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addSphere(parent, radius, segments, material, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(new THREE.SphereGeometry(radius, segments, Math.max(3, segments - 2)), material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
function makeTextSprite(text, color = '#17232b', background = 'rgba(255,255,255,0.92)', width = 1.3, height = .34, alwaysVisible = false) {
const c = document.createElement('canvas');
c.width = 384;
c.height = 96;
const ctx = c.getContext('2d');
ctx.clearRect(0, 0, c.width, c.height);
ctx.fillStyle = background;
ctx.beginPath();
ctx.roundRect(4, 8, 376, 80, 24);
ctx.fill();
ctx.fillStyle = color;
ctx.font = '800 32px system-ui, sans-serif';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(text, 192, 49);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: !alwaysVisible,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, height, 1);
sprite.renderOrder = alwaysVisible ? 10 : 2;
return sprite;
}
// ------------------------------------------------------------
// Low-poly workshop environment
// ------------------------------------------------------------
function buildRoom() {
addBox(scene, 28, .3, 22, materials.floor, 0, -.2, 0);
addBox(scene, 28, 9, .25, materials.wall, 0, 4.45, -8.2);
addBox(scene, .25, 9, 20, materials.wallSide, -12, 4.45, 0);
addBox(scene, 28, .16, .18, materials.trim, 0, 1.05, -8.02);
addBox(scene, .18, .16, 20, materials.trim, -11.82, 1.05, 0);
// Painted floor bands.
const floorBand = standard('#c9c7ba');
for (let z = -8; z <= 8; z += 4) {
addBox(scene, 24, .012, .035, floorBand, 0, -.04, z);
}
// Back-wall windows.
function windowUnit(x, w, h) {
const group = new THREE.Group();
group.position.set(x, 4.8, -8.02);
const frame = standard('#39494e');
const pane = standard('#b8d7dc', { emissive: '#8ebbc2', emissiveIntensity: .22, roughness: .35 });
addBox(group, w + .18, h + .18, .14, frame, 0, 0, 0);
addBox(group, w, h, .16, pane, 0, 0, .02);
addBox(group, .09, h, .18, frame, 0, 0, .04);
addBox(group, w, .09, .18, frame, 0, 0, .04);
scene.add(group);
}
windowUnit(-5.3, 4.3, 2.8);
windowUnit(.4, 3.4, 2.8);
// Pegboard and hanging hand tools.
const pegboard = new THREE.Group();
pegboard.position.set(7.25, 4.3, -7.95);
addBox(pegboard, 4.6, 3.4, .18, standard('#9b7654'), 0, 0, 0);
const holeMat = standard('#70533d');
for (let x = -2; x <= 2; x += .4) {
for (let y = -1.3; y <= 1.3; y += .4) {
const hole = addCylinder(pegboard, .035, .035, .025, 6, holeMat, x, y, .105);
hole.rotation.x = Math.PI / 2;
}
}
const toolDark = standard('#36464b', { metalness: .45 });
for (let i = 0; i < 5; i++) {
const x = -1.55 + i * .78;
addBox(pegboard, .11, 1.2 + (i % 2) * .3, .11, toolDark, x, .1, .18);
const ring = new THREE.Mesh(new THREE.TorusGeometry(.19, .055, 5, 9), toolDark);
ring.position.set(x, .85, .19);
ring.castShadow = true;
pegboard.add(ring);
}
scene.add(pegboard);
// Shelf and storage boxes.
addBox(scene, 5.2, .18, .85, materials.woodDark, -7.25, 3.2, -7.45);
const storage = [standard('#d67a58'), standard('#668b80'), standard('#d0a954')];
for (let i = 0; i < 3; i++) {
addBox(scene, 1.15, .85, .65, storage[i], -8.7 + i * 1.45, 3.72, -7.42);
addBox(scene, .28, .08, .04, materials.cream, -8.7 + i * 1.45, 3.85, -7.08);
}
// Pendant lights.
[-3.5, 3.5].forEach((x) => {
addCylinder(scene, .035, .035, 2.5, 6, materials.black, x, 7.0, -.4);
const shade = new THREE.Mesh(new THREE.ConeGeometry(.72, .55, 10, 1, true), standard('#34464b'));
shade.position.set(x, 5.62, -.4);
shade.rotation.x = Math.PI;
shade.castShadow = true;
scene.add(shade);
const bulb = addSphere(scene, .13, 8, standard('#fff4c5', { emissive: '#ffd76a', emissiveIntensity: 2 }), x, 5.47, -.4);
bulb.castShadow = false;
});
// Plant.
const pot = addCylinder(scene, .48, .36, .72, 8, standard('#b5654e'), -10.45, .36, -6.8);
pot.castShadow = true;
const leafMat = standard('#477c5e');
for (let i = 0; i < 6; i++) {
const leaf = addSphere(scene, .32, 6, leafMat, -10.45 + Math.cos(i * 1.1) * .25, 1.05 + (i % 2) * .25, -6.8 + Math.sin(i * 1.1) * .25);
leaf.scale.set(.55, 1.4, .45);
leaf.rotation.z = Math.cos(i) * .4;
}
}
function buildTable() {
addBox(scene, TABLE_WIDTH + .22, .3, TABLE_DEPTH + .22, materials.woodDark, 0, 1.49, 0);
addBox(scene, TABLE_WIDTH, .22, TABLE_DEPTH, materials.wood, 0, 1.62, 0);
addBox(scene, TABLE_WIDTH - .15, .025, TABLE_DEPTH - .15, materials.woodLight, 0, 1.735, 0);
const legPositions = [
[-4.65, -3.35], [4.65, -3.35], [-4.65, 3.35], [4.65, 3.35]
];
legPositions.forEach(([x, z]) => {
addBox(scene, .36, 1.35, .36, materials.trim, x, .69, z);
addBox(scene, .45, .08, .45, materials.black, x, .07, z);
});
addBox(scene, 9.65, .28, .22, materials.woodDark, 0, 1.18, -3.55);
addBox(scene, 9.65, .28, .22, materials.woodDark, 0, 1.18, 3.55);
// Grid bays.
for (let i = 0; i < COLS * ROWS; i++) {
const { x, z, label } = cellPosition(i);
const material = standard(i % 2 ? '#e8dfcc' : '#f2ead9');
const cell = addBox(scene, CELL_W - .07, .035, CELL_D - .07, material, x, TABLE_TOP_Y, z);
cell.userData.cellIndex = i;
cellMeshes.push(cell);
const labelSprite = makeTextSprite(label, '#857e70', 'rgba(255,255,255,0.62)', .46, .22);
labelSprite.position.set(x + CELL_W / 2 - .28, TABLE_TOP_Y + .045, z + CELL_D / 2 - .24);
scene.add(labelSprite);
cellLabels.push(labelSprite);
}
}
function buildStools() {
const seatColors = [standard('#c56852'), standard('#578b82'), standard('#c3994f'), standard('#7568a4')];
[-4, -2, 0, 2, 4].forEach((x, i) => {
const group = new THREE.Group();
group.position.set(x, 0, 5.35);
addCylinder(group, .47, .47, .18, 8, seatColors[i % seatColors.length], 0, .95, 0);
addCylinder(group, .08, .1, .78, 6, materials.metal, 0, .45, 0);
addCylinder(group, .34, .38, .08, 8, materials.metal, 0, .06, 0);
scene.add(group);
});
}
function buildPeople() {
const skinColors = ['#d99c72', '#9d684e', '#e2b38e', '#7f513d'];
const xs = [-4.35, -1.45, 1.45, 4.35];
participants.forEach((p, i) => {
const group = new THREE.Group();
group.position.set(xs[i], 0, -5.65);
const shirt = standard(p.color);
const pants = standard('#35444b');
const skin = standard(skinColors[i]);
const shoe = standard('#263137');
addBox(group, .24, .72, .27, pants, -.2, .43, 0);
addBox(group, .24, .72, .27, pants, .2, .43, 0);
addBox(group, .3, .16, .48, shoe, -.2, .08, .09);
addBox(group, .3, .16, .48, shoe, .2, .08, .09);
addCylinder(group, .37, .43, .83, 7, shirt, 0, 1.18, 0);
addBox(group, .48, .48, .08, standard('#f0e4cd'), 0, 1.12, .38);
const head = addSphere(group, .29, 8, skin, 0, 1.88, 0);
head.scale.set(.92, 1.05, .9);
addBox(group, .49, .13, .42, standard(i % 2 ? '#3f302c' : '#6a4937'), 0, 2.08, -.02);
const leftArm = addCylinder(group, .1, .12, .74, 6, shirt, -.49, 1.2, .03);
leftArm.rotation.z = -.22;
const rightArm = addCylinder(group, .1, .12, .74, 6, shirt, .49, 1.2, .03);
rightArm.rotation.z = .22;
addSphere(group, .11, 6, skin, -.58, .84, .05);
addSphere(group, .11, 6, skin, .58, .84, .05);
const name = makeTextSprite(p.name, '#17232b', 'rgba(255,253,246,.96)', 1.05, .3, true);
name.position.set(0, 2.48, 0);
group.add(name);
group.userData.rightArm = rightArm;
group.userData.leftArm = leftArm;
scene.add(group);
personGroups.set(p.id, group);
});
}
// ------------------------------------------------------------
// Activity kits and visible operations
// ------------------------------------------------------------
function clearKitRoot() {
kitRoot.traverse((obj) => {
if (obj.geometry) obj.geometry.dispose();
if (obj.material) {
const mats = Array.isArray(obj.material) ? obj.material : [obj.material];
mats.forEach(m => {
if (m.map) m.map.dispose();
m.dispose();
});
}
});
kitRoot.clear();
kitGroups.clear();
}
function createKit(kitId, participant) {
const group = new THREE.Group();
const pos = cellPosition(participant.cell);
group.position.set(pos.x, TABLE_TOP_Y + .02, pos.z);
group.userData.kitId = kitId;
group.userData.participantId = participant.id;
// Participant color token at the front of the bay.
const tokenMat = standard(participant.color);
const token = addCylinder(group, .24, .24, .065, 10, tokenMat, 0, .055, .92);
token.castShadow = true;
if (kitId === 'circuit') {
addBox(group, 1.35, .09, .86, standard('#286f5e'), 0, .12, 0);
addBox(group, .46, .08, .34, standard('#202c31'), -.25, .21, -.08);
addBox(group, .26, .08, .2, standard('#d8b35c'), .28, .2, .08);
for (let i = 0; i < 4; i++) {
addCylinder(group, .055, .055, .045, 8, standard('#c9c2aa'), -.46 + i * .3, .19, -.25);
}
const wireMat = standard('#dfb949');
addBox(group, .65, .025, .035, wireMat, .1, .19, .28);
const iron = new THREE.Group();
addBox(iron, .22, .2, .54, standard('#c94e43'), 0, .03, .28);
addCylinder(iron, .045, .08, .4, 6, materials.metal, 0, .01, -.2).rotation.x = Math.PI / 2;
iron.position.set(-.46, .3, .12);
group.add(iron);
const sparkMat = standard('#ffd45b', { emissive: '#ff9d23', emissiveIntensity: 2.5 });
const sparks = new THREE.Group();
for (let i = 0; i < 8; i++) {
const spark = addSphere(sparks, .028, 5, sparkMat, Math.cos(i * 2.4) * .16, Math.sin(i * 1.7) * .1, Math.sin(i * 2.4) * .14);
spark.castShadow = false;
}
sparks.position.set(.12, .27, -.08);
group.add(sparks);
group.userData.anim = { type: 'circuit', iron, sparks };
}
if (kitId === 'weave') {
const frameMat = standard('#b47a45');
addBox(group, .12, 1.05, .12, frameMat, -.62, .58, -.47);
addBox(group, .12, 1.05, .12, frameMat, .62, .58, -.47);
addBox(group, .12, 1.05, .12, frameMat, -.62, .58, .47);
addBox(group, .12, 1.05, .12, frameMat, .62, .58, .47);
addBox(group, 1.35, .12, .12, frameMat, 0, 1.08, -.47);
addBox(group, 1.35, .12, .12, frameMat, 0, 1.08, .47);
const warpMat = standard('#e7d7b8');
for (let i = 0; i < 7; i++) {
addBox(group, .035, .72, .035, warpMat, -.48 + i * .16, .57, -.42);
}
const yarnA = standard('#d26355');
const yarnB = standard('#4c9285');
for (let i = 0; i < 4; i++) {
addBox(group, .97, .07, .09, i % 2 ? yarnA : yarnB, 0, .3 + i * .16, -.39);
}
const needle = new THREE.Group();
const shaft = addCylinder(needle, .018, .018, .72, 6, materials.metal, 0, 0, 0);
shaft.rotation.z = Math.PI / 2;
const eye = new THREE.Mesh(new THREE.TorusGeometry(.06, .018, 5, 8), materials.metal);
eye.position.x = .35;
needle.add(eye);
needle.position.set(-.35, .67, .1);
group.add(needle);
group.userData.anim = { type: 'weave', needle };
}
if (kitId === 'origami') {
addBox(group, 1.16, .035, .92, standard('#f7eedc'), 0, .06, 0);
const fold = new THREE.Mesh(new THREE.ConeGeometry(.62, .36, 4), standard('#f0b847'));
fold.position.set(0, .3, 0);
fold.rotation.y = Math.PI / 4;
fold.castShadow = true;
group.add(fold);
const crease = addBox(group, .78, .018, .045, standard('#d49d35'), 0, .51, 0);
crease.rotation.y = Math.PI / 4;
group.userData.anim = { type: 'origami', fold, crease };
}
if (kitId === 'wood') {
addBox(group, 1.22, .47, .82, standard('#bd824c'), 0, .33, -.02);
addBox(group, .92, .018, .52, standard('#d8a66a'), 0, .58, -.02);
const file = new THREE.Group();
addBox(file, .18, .11, .84, materials.metal, 0, 0, 0);
addBox(file, .24, .14, .3, standard('#34444a'), 0, .02, .53);
file.position.set(0, .7, -.28);
group.add(file);
const shavingMat = standard('#dfb374');
for (let i = 0; i < 5; i++) {
const shaving = addBox(group, .22, .025, .09, shavingMat, -.46 + i * .22, .11, .62);
shaving.rotation.y = i * .8;
}
group.userData.anim = { type: 'wood', file };
}
// Small low-poly gloves suggest a participant actively working.
const gloveMat = standard('#e1ae83');
const leftGlove = addSphere(group, .15, 6, gloveMat, -.48, .28, .56);
const rightGlove = addSphere(group, .15, 6, gloveMat, .48, .28, .56);
leftGlove.scale.set(.9, .55, 1.25);
rightGlove.scale.set(.9, .55, 1.25);
group.userData.leftGlove = leftGlove;
group.userData.rightGlove = rightGlove;
const label = makeTextSprite(`${participant.name} · ${kits[kitId].name}`, '#17232b', 'rgba(255,253,246,.96)', 1.9, .37, true);
label.position.set(0, 1.56, 0);
group.add(label);
return group;
}
function syncScene() {
clearKitRoot();
participants.forEach(p => {
if (p.cell !== null && p.kit) {
const group = createKit(p.kit, p);
kitRoot.add(group);
kitGroups.set(p.id, group);
}
});
updateCellVisuals();
}
function updateCellVisuals() {
const selected = selectedParticipant();
cellMeshes.forEach((mesh, index) => {
const occupant = participants.find(p => p.cell === index);
const base = new THREE.Color(index % 2 ? '#e8dfcc' : '#f2ead9');
if (occupant) {
base.lerp(new THREE.Color(occupant.color), .28);
}
mesh.material.color.copy(base);
mesh.material.emissive.set('#000000');
if (occupant && occupant.id === selected.id) {
mesh.material.emissive.set(occupant.color);
mesh.material.emissiveIntensity = .18;
} else if (index === hoveredCell) {
mesh.material.emissive.set('#fff8dd');
mesh.material.emissiveIntensity = .35;
}
});
}
function animateKits(now) {
participants.forEach(p => {
const group = kitGroups.get(p.id);
if (!group) return;
const a = group.userData.anim;
const t = THREE.MathUtils.clamp(p.progress, 0, 1);
const eased = t * t * (3 - 2 * t);
const active = phase === 'running' || phase === 'complete';
if (a.type === 'circuit') {
a.iron.position.x = THREE.MathUtils.lerp(-.46, .43, eased);
a.iron.position.z = .12 - Math.sin(t * Math.PI) * .2;
a.sparks.visible = active && t > .08 && t < .92 && Math.sin(now * .035) > -.2;
a.sparks.rotation.y = now * .002;
}
if (a.type === 'weave') {
a.needle.position.x = THREE.MathUtils.lerp(-.38, .38, eased);
a.needle.position.z = .1 + Math.sin(t * Math.PI * 4) * .09;
a.needle.rotation.z = Math.sin(t * Math.PI * 4) * .22;
}
if (a.type === 'origami') {
const s = active ? .12 + eased * .88 : .12;
a.fold.scale.set(s, s, s);
a.fold.rotation.y = Math.PI / 4 + eased * Math.PI / 2;
a.fold.position.y = .1 + eased * .2;
a.crease.scale.x = eased;
}
if (a.type === 'wood') {
a.file.position.z = THREE.MathUtils.lerp(-.28, .28, eased);
a.file.position.x = Math.sin(t * Math.PI * 6) * .13;
a.file.rotation.y = Math.sin(t * Math.PI * 6) * .08;
}
const gloveMotion = active ? Math.sin(t * Math.PI * 8) * .055 : 0;
group.userData.leftGlove.position.x = -.48 - gloveMotion;
group.userData.rightGlove.position.x = .48 + gloveMotion;
});
}
// ------------------------------------------------------------
// UI
// ------------------------------------------------------------
const participantList = document.getElementById('participantList');
const selectedHeader = document.getElementById('selectedHeader');
const kitGrid = document.getElementById('kitGrid');
const toolCard = document.getElementById('toolCard');
const readyNote = document.getElementById('readyNote');
const startButton = document.getElementById('startWorkshop');
function renderUI() {
const selected = selectedParticipant();
const allocatedSpaces = participants.filter(p => p.cell !== null).length;
const allocatedKits = participants.filter(p => p.kit).length;
const grantedTools = participants.filter(p => p.tool).length;
document.getElementById('spaceMetric').textContent = `${allocatedSpaces}/4`;
document.getElementById('kitMetric').textContent = `${allocatedKits}/4`;
document.getElementById('toolMetric').textContent = `${grantedTools}/4`;
participantList.innerHTML = participants.map(p => {
const state = stateFor(p);
const kitName = p.kit ? kits[p.kit].name : 'No kit';
const bay = p.cell !== null ? cellPosition(p.cell).label : 'No bay';
return `
<button class="person-card ${p.id === selected.id ? 'selected' : ''}"
data-person="${p.id}" style="--person:${p.color}">
<span class="avatar" aria-hidden="true"></span>
<span>
<span class="person-name">${p.name}</span>
<span class="person-detail">${bay} · ${kitName}${p.tool ? ' · tool ready' : ''}</span>
</span>
<span class="status-pill ${state}">${stateLabels[state]}</span>
<span class="mini-progress"><i style="width:${Math.round(p.progress * 100)}%"></i></span>
</button>`;
}).join('');
selectedHeader.style.setProperty('--person', selected.color);
selectedHeader.innerHTML = `
<div class="selected-avatar"></div>
<div>
<p class="eyebrow">Selected participant</p>
<h2>${selected.name}</h2>
<p>${stateFor(selected) === 'ready' ? 'Allocation complete — ready to work.' : 'Complete the three allocation steps.'}</p>
</div>`;
document.getElementById('stepSpace').classList.toggle('done', selected.cell !== null);
document.getElementById('stepKit').classList.toggle('done', !!selected.kit);
document.getElementById('stepTool').classList.toggle('done', !!selected.tool);
const pos = selected.cell !== null ? cellPosition(selected.cell) : null;
document.getElementById('bayBadge').textContent = pos ? pos.label : '—';
document.getElementById('spaceTitle').textContent = pos ? `Bay ${pos.label} allocated` : 'No bay allocated';
document.getElementById('spaceSubtitle').textContent = pos ? 'Click another bay to move' : 'Click a bay on the 3D table';
document.getElementById('clearSpace').disabled = selected.cell === null || phase === 'running';
document.getElementById('focusBay').disabled = selected.cell === null || phase === 'running';
kitGrid.innerHTML = Object.entries(kits).map(([id, kit]) => {
const owner = participants.find(p => p.kit === id && p.id !== selected.id);
const selectedKit = selected.kit === id;
return `
<button class="kit-option ${selectedKit ? 'selected' : ''}"
data-kit="${id}" style="--kit:${kit.color};--person:${selected.color}"
${phase === 'running' ? 'disabled' : ''}>
<span class="kit-icon">${kit.icon}</span>
<b>${kit.name}</b>
<small>${owner ? `Currently with ${owner.name}` : selectedKit ? 'Assigned to ' + selected.name : 'Available'}</small>
</button>`;
}).join('');
const clearKitButton = document.getElementById('clearKit');
clearKitButton.disabled = !selected.kit || phase === 'running';
const grantButton = document.getElementById('grantTool');
if (!selected.kit) {
toolCard.innerHTML = `
<div class="tool-top">
<div class="tool-symbol">?</div>
<div class="tool-copy"><b>No tool required yet</b><small>Choose an activity kit first.</small></div>
</div>`;
grantButton.textContent = 'Grant access';
grantButton.disabled = true;
} else {
const kit = kits[selected.kit];
const holder = participants.find(p => p.id !== selected.id && p.tool === selected.kit);
toolCard.innerHTML = `
<div class="tool-top">
<div class="tool-symbol">${kit.toolIcon}</div>
<div class="tool-copy">
<b>${kit.tool}</b>
<small>${selected.tool ? `Access granted to ${selected.name}.` : holder ? `Currently held by ${holder.name}.` : 'Available · 1 shared tool'}</small>
</div>
</div>`;
grantButton.textContent = selected.tool ? 'Revoke access' : holder ? `Transfer from ${holder.name}` : 'Grant access';
grantButton.disabled = phase === 'running';
}
const allReady = participants.every(p => p.cell !== null && p.kit && p.tool);
const missing = {
space: participants.filter(p => p.cell === null).length,
kit: participants.filter(p => !p.kit).length,
tool: participants.filter(p => !p.tool).length
};
readyNote.classList.toggle('blocked', !allReady);
if (allReady) {
readyNote.textContent = 'Everything is allocated. Every participant has a bay, kit, and tool for one visible operation.';
} else {
const parts = [];
if (missing.space) parts.push(`${missing.space} space${missing.space > 1 ? 's' : ''}`);
if (missing.kit) parts.push(`${missing.kit} kit${missing.kit > 1 ? 's' : ''}`);
if (missing.tool) parts.push(`${missing.tool} tool${missing.tool > 1 ? 's' : ''}`);
readyNote.textContent = `Still needed: ${parts.join(', ')}.`;
}
startButton.disabled = !allReady || phase === 'running';
startButton.textContent = phase === 'running' ? 'Workshop running…' : phase === 'complete' ? 'Run again' : 'Run workshop';
startButton.title = allReady ? 'Start all four visible operations' : 'Complete all allocations first';
document.getElementById('clearPlan').disabled = phase === 'running';
document.getElementById('restoreSample').disabled = phase === 'running';
updateCellVisuals();
}
function showToast(message) {
const toast = document.getElementById('toast');
toast.textContent = message;
toast.classList.add('show');
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove('show'), 2600);
}
function commitChange() {
phase = 'planning';
participants.forEach(p => p.progress = 0);
document.getElementById('completionBanner').classList.remove('show');
renderUI();
syncScene();
}
participantList.addEventListener('click', (event) => {
const card = event.target.closest('[data-person]');
if (!card) return;
selectedId = Number(card.dataset.person);
renderUI();
});
kitGrid.addEventListener('click', (event) => {
const button = event.target.closest('[data-kit]');
if (!button || phase === 'running') return;
const selected = selectedParticipant();
const kitId = button.dataset.kit;
if (selected.kit === kitId) return;
const previousOwner = participants.find(p => p.id !== selected.id && p.kit === kitId);
if (previousOwner) {
previousOwner.kit = null;
previousOwner.tool = false;
}
selected.kit = kitId;
selected.tool = false;
commitChange();
showToast(previousOwner
? `${kits[kitId].name} moved from ${previousOwner.name} to ${selected.name}.`
: `${kits[kitId].name} assigned to ${selected.name}.`);
});
document.getElementById('clearSpace').addEventListener('click', () => {
if (phase === 'running') return;
selectedParticipant().cell = null;
commitChange();
showToast(`${selectedParticipant().name}'s table bay was released.`);
});
document.getElementById('clearKit').addEventListener('click', () => {
if (phase === 'running') return;
const p = selectedParticipant();
p.kit = null;
p.tool = false;
commitChange();
showToast(`${p.name}'s kit was removed.`);
});
document.getElementById('grantTool').addEventListener('click', () => {
if (phase === 'running') return;
const p = selectedParticipant();
if (!p.kit) return;
if (p.tool) {
p.tool = false;
commitChange();
showToast(`${kits[p.kit].tool} access revoked from ${p.name}.`);
return;
}
const previousHolder = participants.find(other => other.id !== p.id && other.tool === p.kit);
if (previousHolder) previousHolder.tool = false;
p.tool = true;
commitChange();
showToast(previousHolder
? `${kits[p.kit].tool} transferred from ${previousHolder.name} to ${p.name}.`
: `${kits[p.kit].tool} access granted to ${p.name}.`);
});
document.getElementById('focusBay').addEventListener('click', () => {
const p = selectedParticipant();
if (p.cell === null) return;
const pos = cellPosition(p.cell);
cameraGoal = new THREE.Vector3(pos.x, 1.45, pos.z);
cameraState.radius = 15.8;
showToast(`Camera centered on bay ${pos.label}.`);
});
document.getElementById('clearPlan').addEventListener('click', () => {
if (phase === 'running') return;
participants.forEach(p => {
p.cell = null;
p.kit = null;
p.tool = false;
p.progress = 0;
});
phase = 'planning';
commitChange();
showToast('The allocation plan was cleared.');
});
function restoreSample() {
const sample = [
{ cell: 0, kit: 'circuit', tool: false },
{ cell: 1, kit: 'weave', tool: true },
{ cell: 2, kit: 'origami', tool: false },
{ cell: 3, kit: 'wood', tool: false }
];
participants.forEach((p, i) => Object.assign(p, sample[i], { progress: 0 }));
phase = 'planning';
commitChange();
showToast('Sample allocation restored.');
}
document.getElementById('restoreSample').addEventListener('click', restoreSample);
startButton.addEventListener('click', () => {
const allReady = participants.every(p => p.cell !== null && p.kit && p.tool);
if (!allReady || phase === 'running') return;
phase = 'running';
runStart = performance.now();
participants.forEach(p => p.progress = 0);
document.getElementById('completionBanner').classList.remove('show');
renderUI();
showToast('Workshop started — watch the tools complete each operation.');
});
// ------------------------------------------------------------
// Direct camera controls and bay picking
// ------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const tooltip = document.getElementById('tooltip');
let dragging = false;
let dragMoved = 0;
let pointerStart = { x: 0, y: 0 };
let lastPointer = { x: 0, y: 0 };
function pointerToNdc(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pickCell(event) {
pointerToNdc(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(cellMeshes, false);
return hits.length ? hits[0].object.userData.cellIndex : -1;
}
canvas.addEventListener('pointerdown', (event) => {
dragging = true;
dragMoved = 0;
pointerStart = { x: event.clientX, y: event.clientY };
lastPointer = { x: event.clientX, y: event.clientY };
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = 'grabbing';
});
canvas.addEventListener('pointermove', (event) => {
if (dragging) {
const dx = event.clientX - lastPointer.x;
const dy = event.clientY - lastPointer.y;
dragMoved += Math.abs(dx) + Math.abs(dy);
lastPointer = { x: event.clientX, y: event.clientY };
if (event.shiftKey || event.buttons === 2) {
const scale = cameraState.radius * 0.0015;
const right = new THREE.Vector3(Math.cos(cameraState.theta), 0, -Math.sin(cameraState.theta));
const forward = new THREE.Vector3(-Math.sin(cameraState.theta), 0, -Math.cos(cameraState.theta));
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(forward, -dy * scale);
cameraState.target.x = THREE.MathUtils.clamp(cameraState.target.x, -7, 7);
cameraState.target.z = THREE.MathUtils.clamp(cameraState.target.z, -6, 6);
cameraGoal = null;
} else {
cameraState.theta -= dx * .0055;
cameraState.phi = THREE.MathUtils.clamp(cameraState.phi + dy * .0045, .42, 1.36);
cameraGoal = null;
}
return;
}
const hit = pickCell(event);
if (hit !== hoveredCell) {
hoveredCell = hit;
updateCellVisuals();
}
if (hit >= 0) {
const pos = cellPosition(hit);
const occupant = participants.find(p => p.cell === hit);
tooltip.textContent = occupant
? `Bay ${pos.label} · ${occupant.name}${occupant.id === selectedId ? ' (selected)' : ''}`
: `Bay ${pos.label} · click to allocate`;
tooltip.style.display = 'block';
tooltip.style.left = `${event.clientX}px`;
tooltip.style.top = `${event.clientY}px`;
canvas.style.cursor = 'pointer';
} else {
tooltip.style.display = 'none';
canvas.style.cursor = 'grab';
}
});
canvas.addEventListener('pointerup', (event) => {
dragging = false;
canvas.style.cursor = 'grab';
if (dragMoved < 7 && phase !== 'running') {
const index = pickCell(event);
if (index >= 0) {
const p = selectedParticipant();
if (p.cell === index) {
showToast(`${p.name} is already assigned to bay ${cellPosition(index).label}.`);
} else {
const occupant = participants.find(other => other.cell === index);
if (occupant) {
showToast(`Bay ${cellPosition(index).label} is already assigned to ${occupant.name}.`);
} else {
p.cell = index;
commitChange();
showToast(`${p.name} allocated to bay ${cellPosition(index).label}.`);
}
}
}
}
});
canvas.addEventListener('pointercancel', () => {
dragging = false;
canvas.style.cursor = 'grab';
});
canvas.addEventListener('pointerleave', () => {
if (!dragging) {
hoveredCell = -1;
tooltip.style.display = 'none';
updateCellVisuals();
}
});
canvas.addEventListener('wheel', (event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(cameraState.radius * Math.exp(event.deltaY * .001), 10, 28);
cameraGoal = null;
}, { passive: false });
canvas.addEventListener('contextmenu', event => event.preventDefault());
// ------------------------------------------------------------
// Celebration particles
// ------------------------------------------------------------
const confetti = [];
function startConfetti() {
confettiRoot.clear();
confetti.length = 0;
const colors = participants.map(p => new THREE.Color(p.color));
for (let i = 0; i < 42; i++) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(.08, .025, .16),
new THREE.MeshBasicMaterial({ color: colors[i % colors.length] })
);
mesh.position.set((Math.random() - .5) * 7, 3.4 + Math.random() * 2, (Math.random() - .5) * 5);
mesh.rotation.set(Math.random() * 3, Math.random() * 3, Math.random() * 3);
confettiRoot.add(mesh);
confetti.push({
mesh,
velocity: new THREE.Vector3((Math.random() - .5) * .7, .3 + Math.random() * .7, (Math.random() - .5) * .7),
spin: new THREE.Vector3(Math.random() * 5, Math.random() * 5, Math.random() * 5)
});
}
}
function updateConfetti(dt) {
if (!confetti.length) return;
let alive = false;
confetti.forEach(c => {
c.velocity.y -= dt * 1.35;
c.mesh.position.addScaledVector(c.velocity, dt);
c.mesh.rotation.x += c.spin.x * dt;
c.mesh.rotation.y += c.spin.y * dt;
c.mesh.rotation.z += c.spin.z * dt;
if (c.mesh.position.y > .75) alive = true;
});
if (!alive) {
confettiRoot.clear();
confetti.length = 0;
}
}
// ------------------------------------------------------------
// Main loop
// ------------------------------------------------------------
function updateCamera(dt) {
if (cameraGoal) {
cameraState.target.lerp(cameraGoal, 1 - Math.pow(.001, dt));
if (cameraState.target.distanceTo(cameraGoal) < .025) cameraGoal = null;
}
const sinPhi = Math.sin(cameraState.phi);
const offset = new THREE.Vector3(
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.radius * Math.cos(cameraState.phi),
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.position.copy(cameraState.target).add(offset);
camera.lookAt(cameraState.target);
}
function updateWorkshop(now) {
if (phase !== 'running') return;
const elapsed = (now - runStart) / 1000;
let allDone = true;
participants.forEach((p, i) => {
const local = elapsed - i * .34;
p.progress = THREE.MathUtils.clamp(local / 3.1, 0, 1);
if (p.progress < 1) allDone = false;
});
if (allDone) {
phase = 'complete';
participants.forEach(p => p.progress = 1);
document.getElementById('completionBanner').classList.add('show');
startConfetti();
renderUI();
showToast('Workshop complete — every participant finished one operation.');
}
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener('resize', resize);
buildRoom();
buildTable();
buildStools();
buildPeople();
syncScene();
renderUI();
let previousTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const dt = Math.min((now - previousTime) / 1000, .05);
previousTime = now;
updateWorkshop(now);
animateKits(now);
updateConfetti(dt);
updateCamera(dt);
// Subtle participant movement while an operation is active.
participants.forEach(p => {
const person = personGroups.get(p.id);
if (!person) return;
const working = phase === 'running' && p.progress > 0 && p.progress < 1;
const target = working ? Math.sin(now * .012 + p.id) * .22 : 0;
person.userData.rightArm.rotation.z = .22 + target;
person.userData.leftArm.rotation.z = -.22 - target * .65;
});
if (now - uiTick > 110 && phase === 'running') {
uiTick = now;
renderUI();
}
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```