Prompt specification
Build or customize the Three.js 3D scene "Skill Tokens and Task Socket 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: Skill Tokens and Task Socket Board
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/skill-tokens-and-task-socket-board-x3277
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows volunteer skills, assignments, and availability. Build a board with three task sockets requiring distinct skill symbols and time blocks. A token fits only when both requirements match, making the rule observable. Low-poly.
Working Three.js Starter (skill-tokens-and-task-socket-board-x3277):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Common Ground — Volunteer Match Board</title>
<style>
:root {
--ink: #183b36;
--muted: #6f7d76;
--paper: #f5f1e7;
--panel: #fffdf8;
--line: #ddd9cd;
--repair: #3f806e;
--care: #d86362;
--learning: #4b78b7;
--morning: #e8b84a;
--afternoon: #ee8b5d;
--evening: #7568a8;
--success: #34745d;
--error: #b44f49;
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
color: var(--ink);
background: var(--paper);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button { font: inherit; }
#app {
height: 100%;
display: grid;
grid-template-rows: 76px minmax(0, 1fr);
}
.topbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 0 26px;
background: rgba(255, 253, 248, 0.96);
border-bottom: 1px solid var(--line);
z-index: 5;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
width: 42px;
height: 42px;
border-radius: 13px;
display: grid;
grid-template-columns: repeat(2, 7px);
grid-template-rows: repeat(2, 7px);
place-content: center;
gap: 4px;
background: var(--ink);
transform: rotate(-3deg);
box-shadow: 0 6px 16px rgba(24, 59, 54, 0.18);
}
.brand-mark i {
display: block;
width: 7px;
height: 7px;
border-radius: 2px;
background: #f4cf6c;
}
.brand-mark i:nth-child(2) { background: #ef8b68; }
.brand-mark i:nth-child(3) { background: #77b9a5; }
.brand-mark i:nth-child(4) { background: #f8f5eb; }
.brand-copy { min-width: 0; }
.eyebrow {
margin: 0 0 3px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.brand h1 {
margin: 0;
font-size: 18px;
line-height: 1;
letter-spacing: -0.02em;
}
.top-actions {
display: flex;
align-items: center;
gap: 16px;
}
.board-meta {
text-align: right;
color: var(--muted);
font-size: 12px;
line-height: 1.35;
}
.board-meta strong {
display: block;
color: var(--ink);
font-size: 13px;
}
.reset-button {
border: 1px solid #cfcabd;
background: transparent;
color: var(--ink);
padding: 10px 15px;
border-radius: 10px;
cursor: pointer;
font-weight: 750;
font-size: 12px;
transition: 160ms ease;
}
.reset-button:hover {
background: var(--ink);
color: white;
border-color: var(--ink);
}
main {
min-height: 0;
display: grid;
grid-template-columns: 350px minmax(0, 1fr);
}
aside {
min-height: 0;
overflow-y: auto;
padding: 27px 24px 24px;
background: var(--panel);
border-right: 1px solid var(--line);
scrollbar-width: thin;
scrollbar-color: #c8c4b9 transparent;
}
.intro h2 {
margin: 0 0 10px;
font-size: 29px;
line-height: 1.04;
letter-spacing: -0.045em;
}
.intro p {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.6;
}
.rule-card {
margin: 20px 0 23px;
padding: 14px;
border: 1px solid #ded9cb;
border-radius: 15px;
background:
linear-gradient(135deg, rgba(231, 184, 74, 0.09), transparent 48%),
#faf7ef;
}
.rule-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.rule-title span:last-child {
color: var(--muted);
font-size: 9px;
letter-spacing: 0.13em;
}
.rule-row {
display: grid;
grid-template-columns: 1fr 22px 1fr 22px 1fr;
align-items: center;
gap: 5px;
}
.rule-chip {
min-height: 48px;
display: flex;
align-items: center;
justify-content: center;
gap: 7px;
border-radius: 10px;
border: 1px solid #ded9cd;
background: white;
font-size: 10px;
font-weight: 800;
text-transform: uppercase;
letter-spacing: 0.04em;
}
.rule-chip.skill {
color: var(--repair);
border-color: rgba(63, 128, 110, 0.25);
}
.rule-chip.time {
color: #9b652f;
border-color: rgba(232, 184, 74, 0.42);
background: #fffaf0;
}
.rule-chip.result {
color: var(--success);
border-color: rgba(52, 116, 93, 0.24);
background: #f1f8f4;
}
.rule-symbol {
font-size: 19px;
font-weight: 500;
color: #8d978f;
text-align: center;
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin: 0 0 11px;
font-size: 12px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.section-heading span:last-child {
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
.roster {
display: grid;
gap: 8px;
}
.volunteer {
width: 100%;
display: grid;
grid-template-columns: 38px minmax(0, 1fr) auto;
align-items: center;
gap: 10px;
padding: 10px;
border: 1px solid #e3dfd4;
border-radius: 13px;
background: white;
color: var(--ink);
text-align: left;
cursor: pointer;
transition: 150ms ease;
}
.volunteer:hover {
transform: translateY(-1px);
border-color: #bfc8bf;
box-shadow: 0 5px 14px rgba(39, 53, 45, 0.06);
}
.volunteer.selected {
border-color: #5b8f79;
box-shadow: 0 0 0 2px rgba(91, 143, 121, 0.13);
background: #f8fcf8;
}
.volunteer.assigned {
background: #f7fbf8;
}
.avatar {
width: 38px;
height: 38px;
display: grid;
place-items: center;
border-radius: 11px;
color: white;
font-size: 12px;
font-weight: 850;
letter-spacing: 0.03em;
}
.person-copy { min-width: 0; }
.person-copy strong {
display: block;
margin-bottom: 3px;
font-size: 13px;
}
.person-copy span {
display: flex;
align-items: center;
gap: 5px;
color: var(--muted);
font-size: 10px;
white-space: nowrap;
}
.person-copy svg {
width: 13px;
height: 13px;
flex: 0 0 auto;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #d4d0c5;
box-shadow: 0 0 0 3px #f3f1eb;
}
.assigned .status-dot {
background: #52a27f;
box-shadow: 0 0 0 3px #e5f3ec;
}
.selection-panel {
margin-top: 23px;
padding-top: 19px;
border-top: 1px solid var(--line);
}
.selection-empty {
padding: 14px;
border-radius: 12px;
background: #f4f1e8;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.selected-card {
padding: 13px;
border-radius: 13px;
border: 1px solid #ddd8cb;
background: #faf8f1;
}
.selected-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 11px;
}
.selected-name {
font-size: 14px;
font-weight: 850;
}
.selected-meta {
color: var(--muted);
font-size: 10px;
margin-top: 2px;
}
.return-button {
border: 0;
border-radius: 8px;
padding: 7px 9px;
background: #efece4;
color: var(--ink);
font-size: 10px;
font-weight: 800;
cursor: pointer;
}
.socket-label {
margin: 13px 0 8px;
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.socket-choices {
display: grid;
gap: 7px;
}
.socket-choice {
width: 100%;
display: grid;
grid-template-columns: 31px minmax(0, 1fr) auto;
align-items: center;
gap: 9px;
padding: 8px 9px;
border: 1px solid #dfdbd0;
border-radius: 10px;
background: white;
color: var(--ink);
text-align: left;
cursor: pointer;
transition: 140ms ease;
}
.socket-choice:hover {
border-color: #8ba697;
transform: translateX(2px);
}
.socket-icon {
width: 31px;
height: 31px;
display: grid;
place-items: center;
border-radius: 9px;
color: white;
}
.socket-icon svg { width: 17px; height: 17px; }
.socket-copy strong {
display: block;
font-size: 11px;
margin-bottom: 2px;
}
.socket-copy span {
color: var(--muted);
font-size: 9px;
}
.time-pill {
padding: 4px 6px;
border-radius: 999px;
color: #433d31;
font-size: 8px;
font-weight: 850;
white-space: nowrap;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #f2eee4;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
cursor: grab;
}
.stage-hud {
position: absolute;
top: 22px;
left: 24px;
right: 24px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 18px;
pointer-events: none;
}
.hud-title {
color: var(--muted);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.hud-title strong {
display: block;
margin-top: 5px;
color: var(--ink);
font-size: 16px;
letter-spacing: -0.01em;
}
.hud-actions {
display: flex;
align-items: center;
gap: 8px;
pointer-events: auto;
}
.hud-badge {
display: flex;
align-items: center;
gap: 8px;
padding: 9px 11px;
border: 1px solid rgba(117, 112, 96, 0.18);
border-radius: 10px;
background: rgba(255, 253, 248, 0.82);
backdrop-filter: blur(9px);
color: var(--muted);
font-size: 10px;
font-weight: 750;
}
.hud-badge strong {
color: var(--ink);
font-size: 12px;
}
.view-button {
border: 1px solid rgba(117, 112, 96, 0.2);
border-radius: 10px;
padding: 9px 11px;
background: rgba(255, 253, 248, 0.82);
color: var(--ink);
font-size: 10px;
font-weight: 800;
cursor: pointer;
}
.stage-help {
position: absolute;
left: 24px;
bottom: 20px;
display: flex;
align-items: center;
gap: 9px;
padding: 9px 12px;
border: 1px solid rgba(117, 112, 96, 0.14);
border-radius: 999px;
background: rgba(255, 253, 248, 0.78);
backdrop-filter: blur(8px);
color: var(--muted);
font-size: 10px;
pointer-events: none;
}
.stage-help b { color: var(--ink); }
.feedback {
position: absolute;
left: 50%;
bottom: 67px;
width: min(520px, calc(100% - 48px));
padding: 13px 16px;
border-radius: 13px;
background: #fffdf8;
border: 1px solid #d9d5c9;
box-shadow: 0 12px 35px rgba(38, 49, 42, 0.15);
opacity: 0;
transform: translate(-50%, 12px);
transition: 180ms ease;
pointer-events: none;
}
.feedback.show {
opacity: 1;
transform: translate(-50%, 0);
}
.feedback.success { border-left: 5px solid var(--success); }
.feedback.error { border-left: 5px solid var(--error); }
.feedback.info { border-left: 5px solid #c7923e; }
.feedback strong {
display: block;
margin-bottom: 4px;
font-size: 12px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.feedback span {
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
@media (max-width: 900px) {
html, body { overflow: auto; }
#app { min-height: 100%; height: auto; }
main { grid-template-columns: 300px minmax(520px, 1fr); }
.board-meta { display: none; }
}
@media (max-width: 680px) {
#app { grid-template-rows: 66px auto; }
.topbar { padding: 0 15px; }
.brand h1 { font-size: 15px; }
.reset-button { padding: 9px 11px; }
main { display: block; }
aside { max-height: none; border-right: 0; }
#stage { height: 620px; border-top: 1px solid var(--line); }
.stage-hud { top: 15px; left: 15px; right: 15px; }
.hud-badge { display: none; }
.stage-help { left: 15px; }
}
</style>
</head>
<body>
<div id="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i><i></i>
</div>
<div class="brand-copy">
<p class="eyebrow">Volunteer operations</p>
<h1>Common Ground</h1>
</div>
</div>
<div class="top-actions">
<div class="board-meta">
<strong>Community Center</strong>
Board 04 · Live session
</div>
<button class="reset-button" id="resetButton">Reset board</button>
</div>
</header>
<main>
<aside>
<section class="intro">
<p class="eyebrow">Match day</p>
<h2>Make the right match.</h2>
<p>
A volunteer token settles into a task socket only when both the
required skill and the availability block match.
</p>
</section>
<section class="rule-card" aria-label="Matching rule">
<div class="rule-title">
<span>The fitting rule</span>
<span>Both required</span>
</div>
<div class="rule-row">
<div class="rule-chip skill">⌁ Skill</div>
<div class="rule-symbol">+</div>
<div class="rule-chip time">◷ Time</div>
<div class="rule-symbol">=</div>
<div class="rule-chip result">✓ Fits</div>
</div>
</section>
<div class="section-heading">
<span>Volunteer bench</span>
<span id="rosterCount">6 ready</span>
</div>
<div class="roster" id="roster"></div>
<section class="selection-panel" id="selectionPanel"></section>
</aside>
<section id="stage" aria-label="Interactive 3D volunteer assignment board">
<div class="stage-hud">
<div class="hud-title">
Live matching board
<strong>Community task sockets</strong>
</div>
<div class="hud-actions">
<div class="hud-badge">
Tasks covered <strong id="coverage">0 / 3</strong>
</div>
<button class="view-button" id="viewButton">Reset view</button>
</div>
</div>
<div class="feedback" id="feedback" role="status" aria-live="polite">
<strong id="feedbackTitle"></strong>
<span id="feedbackText"></span>
</div>
<div class="stage-help">
<b>Click</b> a token, then a socket · <b>Drag</b> empty space to orbit · <b>Scroll</b> to zoom
</div>
</section>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const rosterElement = document.getElementById("roster");
const selectionPanel = document.getElementById("selectionPanel");
const feedback = document.getElementById("feedback");
const feedbackTitle = document.getElementById("feedbackTitle");
const feedbackText = document.getElementById("feedbackText");
const coverageElement = document.getElementById("coverage");
const skills = {
repair: {
label: "Repair",
color: "#3f806e",
dark: "#285e50"
},
care: {
label: "Care",
color: "#d86362",
dark: "#a94749"
},
learning: {
label: "Learning",
color: "#4b78b7",
dark: "#345b91"
}
};
const times = {
morning: {
label: "Morning",
range: "09–11",
color: "#e8b84a",
dark: "#9b7423"
},
afternoon: {
label: "Afternoon",
range: "13–15",
color: "#ee8b5d",
dark: "#a85531"
},
evening: {
label: "Evening",
range: "17–19",
color: "#7568a8",
dark: "#51477b"
}
};
const volunteers = [
{
id: "maya",
name: "Maya",
initials: "MY",
skill: "repair",
time: "morning",
home: [-4.95, 0.33, -1.75]
},
{
id: "luis",
name: "Luis",
initials: "LU",
skill: "repair",
time: "afternoon",
home: [-3.48, 0.33, -1.75]
},
{
id: "priya",
name: "Priya",
initials: "PR",
skill: "care",
time: "afternoon",
home: [-4.95, 0.33, 0]
},
{
id: "ana",
name: "Ana",
initials: "AN",
skill: "care",
time: "morning",
home: [-3.48, 0.33, 0]
},
{
id: "noor",
name: "Noor",
initials: "NO",
skill: "learning",
time: "evening",
home: [-4.95, 0.33, 1.75]
},
{
id: "theo",
name: "Theo",
initials: "TH",
skill: "learning",
time: "afternoon",
home: [-3.48, 0.33, 1.75]
}
];
const sockets = [
{
id: "garden",
title: "Garden setup",
short: "Garden",
skill: "repair",
time: "morning",
position: [0.55, 0.41, 0]
},
{
id: "aid",
title: "First aid",
short: "First aid",
skill: "care",
time: "afternoon",
position: [3.15, 0.41, 0]
},
{
id: "homework",
title: "Homework club",
short: "Homework",
skill: "learning",
time: "evening",
position: [5.75, 0.41, 0]
}
];
let selectedVolunteerId = null;
let hoveredObject = null;
let feedbackTimer = 0;
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.domElement.setAttribute("aria-label", "3D matching board");
stage.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf2eee4);
scene.fog = new THREE.Fog(0xf2eee4, 21, 38);
const camera = new THREE.OrthographicCamera(-8, 8, 5, -5, 0.1, 100);
const cameraTarget = new THREE.Vector3(0.25, 0, 0);
let cameraYaw = 0.66;
let cameraPitch = 0.69;
let cameraZoom = 1;
const hemisphere = new THREE.HemisphereLight(0xfff9e9, 0x8b9b8e, 2.05);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff3d6, 3.2);
sun.position.set(-5, 11, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d8d2, 0.75);
fill.position.set(9, 5, -8);
scene.add(fill);
const interactiveMeshes = [];
const tokenObjects = new Map();
const socketObjects = new Map();
const animations = [];
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function drawSkill(ctx, skill, cx, cy, scale = 1, color = "#ffffff") {
ctx.save();
ctx.translate(cx, cy);
ctx.scale(scale, scale);
ctx.strokeStyle = color;
ctx.fillStyle = color;
ctx.lineCap = "round";
ctx.lineJoin = "round";
if (skill === "repair") {
ctx.lineWidth = 21;
ctx.beginPath();
ctx.moveTo(-56, 64);
ctx.lineTo(31, -23);
ctx.stroke();
ctx.beginPath();
ctx.arc(40, -35, 30, 0.35, Math.PI * 1.7);
ctx.stroke();
ctx.beginPath();
ctx.arc(-57, 65, 10, 0, Math.PI * 2);
ctx.stroke();
} else if (skill === "care") {
ctx.beginPath();
ctx.moveTo(0, 75);
ctx.bezierCurveTo(-95, 10, -70, -70, 0, -30);
ctx.bezierCurveTo(70, -70, 95, 10, 0, 75);
ctx.closePath();
ctx.fill();
} else {
ctx.lineWidth = 15;
ctx.beginPath();
ctx.moveTo(-76, -54);
ctx.quadraticCurveTo(-38, -62, -5, -39);
ctx.lineTo(-5, 66);
ctx.quadraticCurveTo(-42, 40, -76, 47);
ctx.closePath();
ctx.stroke();
ctx.beginPath();
ctx.moveTo(76, -54);
ctx.quadraticCurveTo(38, -62, 5, -39);
ctx.lineTo(5, 66);
ctx.quadraticCurveTo(42, 40, 76, 47);
ctx.closePath();
ctx.stroke();
ctx.lineWidth = 9;
ctx.beginPath();
ctx.moveTo(0, -36);
ctx.lineTo(0, 64);
ctx.stroke();
}
ctx.restore();
}
function canvasTexture(draw, width = 512, height = 512) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
draw(ctx, width, height);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function skillSvg(skill) {
const paths = {
repair: `
<path d="M14.2 5.1a5.4 5.4 0 0 0-5.7 7.1L3.7 17a2.1 2.1 0 0 0 3 3l4.8-4.8a5.4 5.4 0 0 0 7.1-5.7l-3.2 3.2-3-3 3.2-3.2a5.4 5.4 0 0 0-1.4-.4Z"
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>`,
care: `
<path d="M12 20.2 4.7 13A5.1 5.1 0 0 1 12 5.7 5.1 5.1 0 0 1 19.3 13L12 20.2Z"
fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/>`,
learning: `
<path d="M3.5 5.2c3.5-.6 6.2-.1 8.5 1.5v12c-2.3-1.6-5-2.1-8.5-1.5v-12Zm17 0c-3.5-.6-6.2-.1-8.5 1.5v12c2.3-1.6 5-2.1 8.5-1.5v-12Z"
fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round"/>`
};
return `<svg viewBox="0 0 24 24" aria-hidden="true">${paths[skill]}</svg>`;
}
function makeStandardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.82,
metalness: options.metalness ?? 0,
flatShading: options.flatShading ?? true,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
side: options.side ?? THREE.FrontSide
});
}
function addBox(parent, width, height, depth, color, x, y, z, options = {}) {
const geometry = new THREE.BoxGeometry(width, height, depth);
const material = makeStandardMaterial(color, options);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
parent.add(mesh);
return mesh;
}
function addCylinder(parent, radiusTop, radiusBottom, height, segments, color, x, y, z, options = {}) {
const geometry = new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments);
const material = makeStandardMaterial(color, options);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
parent.add(mesh);
return mesh;
}
function addHorizontalText(text, subtitle, x, z, width, height, background, foreground) {
const texture = canvasTexture((ctx, w, h) => {
ctx.clearRect(0, 0, w, h);
roundedRect(ctx, 8, 8, w - 16, h - 16, 24);
ctx.fillStyle = background;
ctx.fill();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = foreground;
ctx.font = "800 42px system-ui, sans-serif";
ctx.fillText(text, w / 2, h * 0.43);
if (subtitle) {
ctx.globalAlpha = 0.65;
ctx.font = "700 23px system-ui, sans-serif";
ctx.fillText(subtitle, w / 2, h * 0.72);
ctx.globalAlpha = 1;
}
}, 1024, 240);
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide
});
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(width, height), material);
mesh.rotation.x = -Math.PI / 2;
mesh.position.set(x, 0.29, z);
scene.add(mesh);
return mesh;
}
// Ground and low-poly environment.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
makeStandardMaterial(0xe9e4d8, { roughness: 1, castShadow: false })
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.22;
ground.receiveShadow = true;
scene.add(ground);
// Small faceted stones around the diorama.
const stoneMaterial = makeStandardMaterial(0xc9c4b6);
[
[-7.4, -1.02, -2.9, 0.42],
[-7.0, -1.03, 2.5, 0.32],
[7.9, -1.03, -2.1, 0.38],
[8.2, -1.03, 2.6, 0.28],
[-0.2, -1.03, 3.8, 0.34]
].forEach(([x, y, z, size]) => {
const stone = new THREE.Mesh(new THREE.DodecahedronGeometry(size, 0), stoneMaterial);
stone.position.set(x, y, z);
stone.rotation.set(0.2, x, 0.1);
stone.castShadow = true;
stone.receiveShadow = true;
scene.add(stone);
});
// Volunteer bench.
const bench = new THREE.Group();
scene.add(bench);
addBox(bench, 4.4, 0.38, 6.6, 0xbfcdbb, -4.35, -0.05, 0);
addBox(bench, 4.18, 0.11, 6.36, 0xd8e0d1, -4.35, 0.19, 0);
[
[-5.95, -0.72, -2.65],
[-2.75, -0.72, -2.65],
[-5.95, -0.72, 2.65],
[-2.75, -0.72, 2.65]
].forEach(([x, y, z]) => addBox(bench, 0.28, 1.15, 0.28, 0x789184, x, y, z));
// Main board.
const board = new THREE.Group();
scene.add(board);
addBox(board, 8.2, 0.48, 6.6, 0x244c43, 3.15, 0, 0);
addBox(board, 8.05, 0.08, 6.43, 0x315c52, 3.15, 0.27, 0);
[
[-0.35, -0.72, -2.65],
[6.65, -0.72, -2.65],
[-0.35, -0.72, 2.65],
[6.65, -0.72, 2.65]
].forEach(([x, y, z]) => addBox(board, 0.31, 1.15, 0.31, 0x173b34, x, y, z));
// Board dividers.
[1.85, 4.45].forEach(x => {
addBox(board, 0.035, 0.026, 4.65, 0x66877d, x, 0.325, -0.05, {
castShadow: false
});
});
// Corner bolts.
[
[-0.62, -2.92], [6.92, -2.92], [-0.62, 2.92], [6.92, 2.92]
].forEach(([x, z]) => {
addCylinder(board, 0.075, 0.075, 0.045, 8, 0xa8b8a8, x, 0.35, z);
});
addHorizontalText("VOLUNTEER BENCH", "6 tokens", -4.35, -2.82, 3.4, 0.5, "#e8eee2", "#35594d");
addHorizontalText("COMMUNITY MATCH BOARD", "3 task sockets", 3.15, -2.82, 4.55, 0.5, "#315c52", "#f7f1df");
function createToken(volunteer) {
const group = new THREE.Group();
group.position.set(...volunteer.home);
group.userData.kind = "token";
group.userData.id = volunteer.id;
scene.add(group);
const bodyMaterial = makeStandardMaterial(skills[volunteer.skill].color);
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.67, 0.72, 0.23, 6),
bodyMaterial
);
body.castShadow = true;
body.receiveShadow = true;
body.userData = { kind: "token", id: volunteer.id };
group.add(body);
interactiveMeshes.push(body);
const lowerBand = new THREE.Mesh(
new THREE.CylinderGeometry(0.72, 0.72, 0.065, 6),
makeStandardMaterial(skills[volunteer.skill].dark)
);
lowerBand.position.y = -0.07;
lowerBand.castShadow = true;
lowerBand.userData = { kind: "token", id: volunteer.id };
group.add(lowerBand);
interactiveMeshes.push(lowerBand);
const topTexture = canvasTexture((ctx, w, h) => {
ctx.clearRect(0, 0, w, h);
ctx.beginPath();
ctx.arc(w / 2, h / 2, w / 2 - 7, 0, Math.PI * 2);
ctx.fillStyle = skills[volunteer.skill].color;
ctx.fill();
ctx.strokeStyle = "rgba(255,255,255,0.38)";
ctx.lineWidth = 9;
ctx.stroke();
drawSkill(ctx, volunteer.skill, 256, 190, 1.18, "#ffffff");
roundedRect(ctx, 105, 365, 302, 76, 30);
ctx.fillStyle = times[volunteer.time].color;
ctx.fill();
ctx.fillStyle = "#3f3a31";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "900 44px system-ui, sans-serif";
ctx.fillText(times[volunteer.time].range, 256, 404);
});
const top = new THREE.Mesh(
new THREE.CircleGeometry(0.65, 32),
new THREE.MeshBasicMaterial({ map: topTexture, transparent: true })
);
top.rotation.x = -Math.PI / 2;
top.position.y = 0.122;
top.userData = { kind: "token", id: volunteer.id };
group.add(top);
interactiveMeshes.push(top);
const rim = new THREE.Mesh(
new THREE.TorusGeometry(0.65, 0.035, 4, 6),
makeStandardMaterial(0xf4efe0)
);
rim.rotation.x = Math.PI / 2;
rim.position.y = 0.125;
rim.userData = { kind: "token", id: volunteer.id };
group.add(rim);
interactiveMeshes.push(rim);
const halo = new THREE.Mesh(
new THREE.TorusGeometry(0.82, 0.035, 4, 24),
new THREE.MeshBasicMaterial({
color: 0xf4c965,
transparent: true,
opacity: 0.9,
depthWrite: false
})
);
halo.rotation.x = Math.PI / 2;
halo.position.y = -0.03;
halo.visible = false;
group.add(halo);
tokenObjects.set(volunteer.id, {
group,
body,
bodyMaterial,
halo,
volunteer,
assignedSocketId: null,
shakeStart: 0
});
}
volunteers.forEach(createToken);
function createSocket(socket) {
const [x, y, z] = socket.position;
const base = new THREE.Mesh(
new THREE.CylinderGeometry(1.03, 1.08, 0.23, 8),
makeStandardMaterial(0x173b35)
);
base.position.set(x, y, z);
base.castShadow = true;
base.receiveShadow = true;
base.userData = { kind: "socket", id: socket.id };
scene.add(base);
interactiveMeshes.push(base);
const inner = new THREE.Mesh(
new THREE.CylinderGeometry(0.88, 0.9, 0.055, 32),
makeStandardMaterial(0xf1eadb)
);
inner.position.set(x, y + 0.14, z);
inner.castShadow = false;
inner.receiveShadow = true;
inner.userData = { kind: "socket", id: socket.id };
scene.add(inner);
interactiveMeshes.push(inner);
const ringMaterial = makeStandardMaterial(times[socket.time].color, {
emissive: 0x000000,
emissiveIntensity: 0,
roughness: 0.64
});
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.91, 0.075, 5, 24),
ringMaterial
);
ring.rotation.x = Math.PI / 2;
ring.position.set(x, y + 0.19, z);
ring.castShadow = true;
ring.userData = { kind: "socket", id: socket.id };
scene.add(ring);
interactiveMeshes.push(ring);
const indicatorMaterial = makeStandardMaterial(0x7b8b83, {
emissive: 0x000000,
emissiveIntensity: 0
});
const indicator = new THREE.Mesh(
new THREE.CylinderGeometry(0.1, 0.1, 0.07, 8),
indicatorMaterial
);
indicator.position.set(x, y + 0.21, z - 1.42);
indicator.userData = { kind: "socket", id: socket.id };
scene.add(indicator);
interactiveMeshes.push(indicator);
// Upright requirement sign.
const signGroup = new THREE.Group();
signGroup.position.set(x, 0.32, z - 1.23);
scene.add(signGroup);
const signTexture = canvasTexture((ctx, w, h) => {
ctx.clearRect(0, 0, w, h);
roundedRect(ctx, 18, 18, w - 36, h - 36, 28);
ctx.fillStyle = "#fffaf0";
ctx.fill();
ctx.strokeStyle = skills[socket.skill].color;
ctx.lineWidth = 12;
ctx.stroke();
ctx.fillStyle = skills[socket.skill].color;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "900 32px system-ui, sans-serif";
ctx.fillText("REQUIRED", w / 2, 65);
drawSkill(ctx, socket.skill, 112, 190, 0.78, skills[socket.skill].color);
ctx.textAlign = "left";
ctx.fillStyle = "#183b36";
ctx.font = "850 40px system-ui, sans-serif";
ctx.fillText(skills[socket.skill].label, 205, 162);
roundedRect(ctx, 205, 202, 325, 66, 24);
ctx.fillStyle = times[socket.time].color;
ctx.fill();
ctx.fillStyle = "#403b32";
ctx.textAlign = "center";
ctx.font = "900 34px system-ui, sans-serif";
ctx.fillText(`${times[socket.time].range} ${times[socket.time].label.toUpperCase()}`, 367, 236);
}, 640, 330);
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(1.82, 0.94),
new THREE.MeshBasicMaterial({ map: signTexture, transparent: true, side: THREE.DoubleSide })
);
sign.position.y = 0.84;
signGroup.add(sign);
addBox(signGroup, 0.065, 0.62, 0.065, 0x527167, -0.58, 0.3, 0);
addBox(signGroup, 0.065, 0.62, 0.065, 0x527167, 0.58, 0.3, 0);
const titleTexture = canvasTexture((ctx, w, h) => {
ctx.clearRect(0, 0, w, h);
roundedRect(ctx, 5, 5, w - 10, h - 10, 20);
ctx.fillStyle = "#f7f2e6";
ctx.fill();
ctx.fillStyle = "#183b36";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "900 39px system-ui, sans-serif";
ctx.fillText(socket.title.toUpperCase(), w / 2, h * 0.45);
ctx.fillStyle = times[socket.time].dark;
ctx.font = "750 24px system-ui, sans-serif";
ctx.fillText(`${times[socket.time].range} · ${times[socket.time].label}`, w / 2, h * 0.76);
}, 900, 220);
const title = new THREE.Mesh(
new THREE.PlaneGeometry(2.28, 0.56),
new THREE.MeshBasicMaterial({ map: titleTexture, transparent: true, depthWrite: false })
);
title.rotation.x = -Math.PI / 2;
title.position.set(x, 0.34, 1.85);
scene.add(title);
socketObjects.set(socket.id, {
socket,
base,
ring,
ringMaterial,
indicator,
indicatorMaterial,
signGroup,
flashUntil: 0
});
}
sockets.forEach(createSocket);
function updateCamera() {
const radius = 17;
const horizontal = radius * Math.cos(cameraPitch);
camera.position.set(
cameraTarget.x + horizontal * Math.sin(cameraYaw),
cameraTarget.y + radius * Math.sin(cameraPitch),
cameraTarget.z + horizontal * Math.cos(cameraYaw)
);
camera.lookAt(cameraTarget);
for (const item of socketObjects.values()) {
item.signGroup.rotation.y = cameraYaw;
}
}
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
if (!width || !height) return;
renderer.setSize(width, height, false);
const aspect = width / height;
const viewHeight = Math.max(9.65, 15.7 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
updateCamera();
}
new ResizeObserver(resize).observe(stage);
resize();
updateCamera();
function refreshTokenStyles() {
for (const token of tokenObjects.values()) {
const selected = token.volunteer.id === selectedVolunteerId;
const hovered = hoveredObject?.kind === "token" && hoveredObject.id === token.volunteer.id;
token.halo.visible = selected;
if (selected) {
token.bodyMaterial.emissive.setHex(0x527a49);
token.bodyMaterial.emissiveIntensity = 0.42;
} else if (hovered) {
token.bodyMaterial.emissive.setHex(0xd2a946);
token.bodyMaterial.emissiveIntensity = 0.23;
} else {
token.bodyMaterial.emissive.setHex(0x000000);
token.bodyMaterial.emissiveIntensity = 0;
}
}
for (const socket of socketObjects.values()) {
const hovered = hoveredObject?.kind === "socket" && hoveredObject.id === socket.socket.id;
socket.ringMaterial.emissive.setHex(hovered ? 0x7f6e38 : 0x000000);
socket.ringMaterial.emissiveIntensity = hovered ? 0.36 : 0;
}
}
function showFeedback(type, title, text) {
clearTimeout(feedbackTimer);
feedback.className = `feedback ${type} show`;
feedbackTitle.textContent = title;
feedbackText.textContent = text;
feedbackTimer = window.setTimeout(() => {
feedback.classList.remove("show");
}, 5200);
}
function renderRoster() {
rosterElement.innerHTML = volunteers.map(volunteer => {
const token = tokenObjects.get(volunteer.id);
const assignedSocket = token.assignedSocketId
? sockets.find(socket => socket.id === token.assignedSocketId)
: null;
const status = assignedSocket ? "Assigned" : "Ready";
const skill = skills[volunteer.skill];
const time = times[volunteer.time];
return `
<button class="volunteer ${selectedVolunteerId === volunteer.id ? "selected" : ""} ${assignedSocket ? "assigned" : ""}"
data-id="${volunteer.id}" aria-pressed="${selectedVolunteerId === volunteer.id}">
<span class="avatar" style="background:${skill.color}">${volunteer.initials}</span>
<span class="person-copy">
<strong>${volunteer.name}</strong>
<span style="color:${skill.color}">${skillSvg(volunteer.skill)}</span>
<span>${skill.label} · ${time.range}</span>
</span>
<span class="status-dot" title="${status}"></span>
</button>
`;
}).join("");
const ready = volunteers.filter(v => !tokenObjects.get(v.id).assignedSocketId).length;
document.getElementById("rosterCount").textContent = `${ready} ready`;
const covered = sockets.filter(socket =>
[...tokenObjects.values()].some(token => token.assignedSocketId === socket.id)
).length;
coverageElement.textContent = `${covered} / ${sockets.length}`;
}
function renderSelection() {
if (!selectedVolunteerId) {
selectionPanel.innerHTML = `
<div class="selection-empty">
Select a volunteer token to inspect its skill and availability.
Then choose the matching task socket on the board.
</div>
`;
return;
}
const token = tokenObjects.get(selectedVolunteerId);
const volunteer = token.volunteer;
const skill = skills[volunteer.skill];
const time = times[volunteer.time];
const assignedSocket = token.assignedSocketId
? sockets.find(socket => socket.id === token.assignedSocketId)
: null;
selectionPanel.innerHTML = `
<div class="selected-card">
<div class="selected-head">
<div>
<div class="selected-name">${volunteer.name}</div>
<div class="selected-meta">${skill.label} · ${time.label} · ${time.range}</div>
</div>
${assignedSocket ? `<button class="return-button" id="returnButton">Return to bench</button>` : ""}
</div>
<div class="socket-label">Choose a task socket</div>
<div class="socket-choices">
${sockets.map(socket => {
const occupied = [...tokenObjects.values()].some(
other => other.assignedSocketId === socket.id && other.volunteer.id !== volunteer.id
);
const ownSocket = assignedSocket?.id === socket.id;
return `
<button class="socket-choice" data-socket="${socket.id}" ${ownSocket ? 'disabled style="opacity:.58"' : ""}>
<span class="socket-icon" style="background:${skills[socket.skill].color}">
${skillSvg(socket.skill)}
</span>
<span class="socket-copy">
<strong>${socket.title}${occupied ? " · filled" : ""}</strong>
<span>Needs ${skills[socket.skill].label} · ${times[socket.time].range}</span>
</span>
<span class="time-pill" style="background:${times[socket.time].color}">${times[socket.time].range}</span>
</button>
`;
}).join("")}
</div>
</div>
`;
const returnButton = document.getElementById("returnButton");
if (returnButton) returnButton.addEventListener("click", () => returnToBench(volunteer.id));
}
function selectVolunteer(id) {
selectedVolunteerId = id;
refreshTokenStyles();
renderRoster();
renderSelection();
const token = tokenObjects.get(id);
if (token && !token.assignedSocketId) {
showFeedback(
"info",
`${token.volunteer.name} selected`,
`Skill: ${skills[token.volunteer.skill].label}. Availability: ${times[token.volunteer.time].label}, ${times[token.volunteer.time].range}. Choose a socket.`
);
}
}
function animateToken(token, endPosition, onComplete, duration = 720) {
animations.push({
token,
start: token.group.position.clone(),
end: endPosition.clone(),
startTime: performance.now(),
duration,
onComplete
});
}
function assignVolunteer(volunteerId, socketId) {
const token = tokenObjects.get(volunteerId);
const socket = socketObjects.get(socketId).socket;
if (!token) return;
if (token.assignedSocketId) {
if (token.assignedSocketId === socketId) {
showFeedback("info", "Already assigned", `${token.volunteer.name} is already working on ${socket.title}.`);
} else {
showFeedback(
"info",
"Token already assigned",
`Return ${token.volunteer.name} to the bench before moving the token to another socket.`
);
}
return;
}
const occupied = [...tokenObjects.values()].find(other => other.assignedSocketId === socketId);
if (occupied) {
showFeedback(
"error",
"Socket occupied",
`${socket.title} is already covered by ${occupied.volunteer.name}. Return that token before assigning another.`
);
return;
}
const skillMatches = token.volunteer.skill === socket.skill;
const timeMatches = token.volunteer.time === socket.time;
if (!skillMatches || !timeMatches) {
const socketObject = socketObjects.get(socketId);
socketObject.flashUntil = performance.now() + 950;
token.shakeStart = performance.now();
const skillText = skillMatches
? `Skill ✓ ${skills[token.volunteer.skill].label}`
: `Skill ✕ ${skills[token.volunteer.skill].label} ≠ ${skills[socket.skill].label}`;
const timeText = timeMatches
? `Time ✓ ${times[token.volunteer.time].label}`
: `Time ✕ ${times[token.volunteer.time].label} ≠ ${times[socket.time].label}`;
showFeedback(
"error",
"Not a fit — both conditions must match",
`${token.volunteer.name} → ${socket.title}: ${skillText}; ${timeText}. The token stays on the bench.`
);
return;
}
token.assignedSocketId = socketId;
const socketObject = socketObjects.get(socketId);
socketObject.indicatorMaterial.color.setHex(0x56a37e);
socketObject.indicatorMaterial.emissive.setHex(0x285f49);
socketObject.indicatorMaterial.emissiveIntensity = 0.25;
animateToken(
token,
new THREE.Vector3(socket.position[0], 0.64, socket.position[2]),
() => {
renderRoster();
renderSelection();
}
);
showFeedback(
"success",
"Match found",
`${token.volunteer.name} fits ${socket.title}: ${skills[socket.skill].label} and ${times[socket.time].label} both match.`
);
renderRoster();
renderSelection();
}
function returnToBench(volunteerId) {
const token = tokenObjects.get(volunteerId);
if (!token || !token.assignedSocketId) return;
const oldSocketId = token.assignedSocketId;
token.assignedSocketId = null;
const socketObject = socketObjects.get(oldSocketId);
socketObject.indicatorMaterial.color.setHex(0x7b8b83);
socketObject.indicatorMaterial.emissive.setHex(0x000000);
socketObject.indicatorMaterial.emissiveIntensity = 0;
animateToken(token, new THREE.Vector3(...token.volunteer.home));
showFeedback(
"info",
"Token returned",
`${token.volunteer.name} is back on the volunteer bench.`
);
renderRoster();
renderSelection();
}
function handleObjectHit(hit) {
if (!hit) return;
if (hit.kind === "token") {
selectVolunteer(hit.id);
} else if (hit.kind === "socket") {
if (!selectedVolunteerId) {
showFeedback("info", "Select a volunteer first", "Choose a token from the bench, then select its task socket.");
} else {
assignVolunteer(selectedVolunteerId, hit.id);
}
}
}
rosterElement.addEventListener("click", event => {
const button = event.target.closest("[data-id]");
if (button) selectVolunteer(button.dataset.id);
});
selectionPanel.addEventListener("click", event => {
const button = event.target.closest("[data-socket]");
if (!button) return;
if (!selectedVolunteerId) {
showFeedback("info", "Select a volunteer first", "Choose a token from the bench before choosing a task socket.");
return;
}
assignVolunteer(selectedVolunteerId, button.dataset.socket);
});
document.getElementById("resetButton").addEventListener("click", () => {
selectedVolunteerId = null;
for (const token of tokenObjects.values()) {
token.assignedSocketId = null;
token.group.position.set(...token.volunteer.home);
token.group.rotation.set(0, 0, 0);
}
for (const socket of socketObjects.values()) {
socket.indicatorMaterial.color.setHex(0x7b8b83);
socket.indicatorMaterial.emissive.setHex(0x000000);
socket.indicatorMaterial.emissiveIntensity = 0;
socket.flashUntil = 0;
}
refreshTokenStyles();
renderRoster();
renderSelection();
showFeedback("info", "Board reset", "All six tokens are back on the bench and all three sockets are open.");
});
document.getElementById("viewButton").addEventListener("click", () => {
cameraYaw = 0.66;
cameraPitch = 0.69;
cameraZoom = 1;
resize();
});
// Direct raycasting and custom camera controls.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const pointerState = {
down: false,
moved: false,
startX: 0,
startY: 0,
lastX: 0,
lastY: 0,
hit: null,
mode: null
};
function updatePointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function getHit(event) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(interactiveMeshes, false);
return intersections.length ? intersections[0].object.userData : null;
}
renderer.domElement.addEventListener("pointerdown", event => {
pointerState.down = true;
pointerState.moved = false;
pointerState.startX = pointerState.lastX = event.clientX;
pointerState.startY = pointerState.lastY = event.clientY;
pointerState.hit = getHit(event);
pointerState.mode = pointerState.hit ? "interactive" : "orbit";
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (pointerState.down) {
const dx = event.clientX - pointerState.lastX;
const dy = event.clientY - pointerState.lastY;
const totalDistance = Math.hypot(
event.clientX - pointerState.startX,
event.clientY - pointerState.startY
);
if (totalDistance > 5) pointerState.moved = true;
if (pointerState.mode === "orbit" && pointerState.moved) {
cameraYaw -= dx * 0.006;
cameraPitch = THREE.MathUtils.clamp(cameraPitch + dy * 0.0045, 0.48, 1.03);
updateCamera();
renderer.domElement.style.cursor = "grabbing";
}
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
return;
}
const nextHover = getHit(event);
const changed =
(nextHover?.kind !== hoveredObject?.kind) ||
(nextHover?.id !== hoveredObject?.id);
hoveredObject = nextHover;
renderer.domElement.style.cursor = nextHover ? "pointer" : "grab";
if (changed) refreshTokenStyles();
});
renderer.domElement.addEventListener("pointerup", event => {
if (pointerState.down && !pointerState.moved && pointerState.hit) {
handleObjectHit(pointerState.hit);
}
pointerState.down = false;
pointerState.mode = null;
renderer.domElement.style.cursor = hoveredObject ? "pointer" : "grab";
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerState.down = false;
pointerState.mode = null;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(cameraZoom * (1 - event.deltaY * 0.001), 0.72, 1.65);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
}, { passive: false });
function animate(now) {
requestAnimationFrame(animate);
for (let i = animations.length - 1; i >= 0; i--) {
const animation = animations[i];
const raw = Math.min(1, (now - animation.startTime) / animation.duration);
const eased = raw < 0.5
? 4 * raw * raw * raw
: 1 - Math.pow(-2 * raw + 2, 3) / 2;
animation.token.group.position.lerpVectors(animation.start, animation.end, eased);
animation.token.group.position.y += Math.sin(Math.PI * raw) * 0.78;
animation.token.group.rotation.y = Math.sin(Math.PI * raw) * 0.18;
if (raw >= 1) {
animation.token.group.position.copy(animation.end);
animation.token.group.rotation.set(0, 0, 0);
animations.splice(i, 1);
if (animation.onComplete) animation.onComplete();
}
}
for (const token of tokenObjects.values()) {
if (token.shakeStart) {
const elapsed = now - token.shakeStart;
if (elapsed < 480) {
const amount = (1 - elapsed / 480) * 0.13;
token.group.rotation.z = Math.sin(elapsed * 0.055) * amount;
} else {
token.group.rotation.z = 0;
token.shakeStart = 0;
}
}
if (token.halo.visible) {
const pulse = 1 + Math.sin(now * 0.006) * 0.055;
token.halo.scale.setScalar(pulse);
}
}
for (const socket of socketObjects.values()) {
if (socket.flashUntil > now) {
socket.ringMaterial.color.setHex(0xc5534e);
socket.ringMaterial.emissive.setHex(0x8c2724);
socket.ringMaterial.emissiveIntensity = 0.45;
} else {
socket.ringMaterial.color.setHex(new THREE.Color(times[socket.socket.time].color).getHex());
const hovered = hoveredObject?.kind === "socket" && hoveredObject.id === socket.socket.id;
socket.ringMaterial.emissive.setHex(hovered ? 0x7f6e38 : 0x000000);
socket.ringMaterial.emissiveIntensity = hovered ? 0.36 : 0;
}
}
renderer.render(scene, camera);
}
renderRoster();
renderSelection();
refreshTokenStyles();
requestAnimationFrame(animate);
</script>
</body>
</html>
```