Prompt specification
Build or customize the Three.js 3D scene "Festival Setup Volunteer Roster" 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: Festival Setup Volunteer Roster
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/festival-setup-volunteer-roster-x3278
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows volunteer skills, assignments, and availability. Show volunteers with different availability intervals setting up tables, signs, and lighting. Assign tasks without overlapping one person's time or treating all skills as interchangeable. Stylized solid forms.
Working Three.js Starter (festival-setup-volunteer-roster-x3278):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Setup Crew — Volunteer Planning Board</title>
<style>
:root {
--ink: #19342f;
--muted: #6b7b76;
--green: #276f5e;
--green-dark: #173f38;
--paper: #fffdf8;
--canvas: #edf0eb;
--line: #dde4de;
--tables: #e97955;
--signs: #5578c2;
--lighting: #dca72f;
--power: #9065b2;
--logistics: #31917b;
--danger: #bf4d43;
--shadow: 0 10px 30px rgba(25, 52, 47, 0.09);
}
* { box-sizing: border-box; }
html, body {
margin: 0;
min-height: 100%;
background: var(--canvas);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, select, input { font: inherit; }
button { color: inherit; }
header {
height: 72px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 0 24px;
color: #fff;
background: var(--green-dark);
border-bottom: 1px solid rgba(255,255,255,.12);
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
width: 38px;
height: 38px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 4px;
transform: rotate(-4deg);
}
.brand-mark span {
display: block;
border-radius: 5px;
background: #f1c75b;
}
.brand-mark span:nth-child(2) { background: #ef8354; }
.brand-mark span:nth-child(3) { background: #82b8a9; }
.brand-mark span:nth-child(4) { background: #f7f1dc; }
.brand h1 {
margin: 0;
font-size: 19px;
line-height: 1.05;
letter-spacing: -.02em;
}
.brand p {
margin: 5px 0 0;
color: #bdd0ca;
font-size: 12px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.event-meta {
display: flex;
align-items: center;
gap: 22px;
color: #d4e1dd;
font-size: 12px;
text-align: right;
}
.event-meta strong {
display: block;
margin-top: 2px;
color: #fff;
font-size: 13px;
}
.app {
display: grid;
grid-template-columns: 280px minmax(0, 1fr) 330px;
height: calc(100vh - 72px);
min-height: 640px;
}
.panel {
min-width: 0;
background: var(--paper);
overflow: hidden;
}
.left-panel {
border-right: 1px solid var(--line);
display: flex;
flex-direction: column;
}
.right-panel {
border-left: 1px solid var(--line);
overflow-y: auto;
}
.panel-section {
padding: 20px;
border-bottom: 1px solid var(--line);
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 14px;
}
.section-heading h2,
.section-heading h3 {
margin: 0;
font-size: 14px;
letter-spacing: -.01em;
}
.count {
display: inline-grid;
place-items: center;
min-width: 24px;
height: 24px;
padding: 0 7px;
border-radius: 20px;
color: var(--green);
background: #e6f0ec;
font-size: 11px;
font-weight: 800;
}
.subtle {
margin: 5px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.roster {
flex: 1;
min-height: 0;
overflow-y: auto;
padding: 14px;
}
.volunteer-card {
width: 100%;
display: block;
text-align: left;
border: 1px solid var(--line);
border-radius: 14px;
padding: 13px;
margin-bottom: 10px;
background: #fff;
cursor: pointer;
transition: border-color .16s, transform .16s, box-shadow .16s;
}
.volunteer-card:hover {
transform: translateY(-1px);
border-color: #a9beb6;
box-shadow: 0 6px 16px rgba(25, 52, 47, .07);
}
.volunteer-card.selected {
border-color: var(--green);
box-shadow: 0 0 0 2px rgba(39, 111, 94, .11);
}
.volunteer-top {
display: flex;
align-items: center;
gap: 10px;
}
.avatar {
position: relative;
flex: 0 0 auto;
width: 38px;
height: 38px;
display: grid;
place-items: center;
color: #fff;
border-radius: 12px;
font-size: 11px;
font-weight: 800;
letter-spacing: .02em;
}
.avatar.on-site::after {
content: "";
position: absolute;
right: -3px;
bottom: -3px;
width: 10px;
height: 10px;
border-radius: 50%;
border: 2px solid #fff;
background: #45a37f;
}
.volunteer-name {
min-width: 0;
flex: 1;
}
.volunteer-name strong {
display: block;
font-size: 13px;
}
.volunteer-name span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
.availability {
margin: 10px 0 9px;
color: #415a53;
font-size: 11px;
font-weight: 650;
}
.split-label {
margin-left: 4px;
color: #9a6b28;
font-size: 9px;
font-weight: 800;
text-transform: uppercase;
letter-spacing: .04em;
}
.chips {
display: flex;
flex-wrap: wrap;
gap: 5px;
}
.chip {
display: inline-flex;
align-items: center;
gap: 5px;
border-radius: 20px;
padding: 4px 7px;
background: #f0f3ef;
color: #536660;
font-size: 9px;
font-weight: 800;
letter-spacing: .025em;
text-transform: uppercase;
}
.chip::before {
content: "";
width: 6px;
height: 6px;
border-radius: 2px;
background: var(--skill-color, #8aa099);
}
.skill-tables { --skill-color: var(--tables); }
.skill-signs { --skill-color: var(--signs); }
.skill-lighting { --skill-color: var(--lighting); }
.skill-power { --skill-color: var(--power); }
.skill-logistics { --skill-color: var(--logistics); }
.scene-panel {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background:
radial-gradient(circle at 52% 38%, rgba(255,255,255,.92), rgba(255,255,255,0) 44%),
linear-gradient(180deg, #eef2ed, #e6ebe6);
}
#scene {
position: absolute;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.scene-top {
position: absolute;
z-index: 3;
top: 16px;
left: 16px;
right: 16px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
pointer-events: none;
}
.stats {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.stat {
min-width: 104px;
padding: 10px 12px;
border: 1px solid rgba(255,255,255,.82);
border-radius: 13px;
background: rgba(255,253,248,.88);
box-shadow: 0 7px 22px rgba(25,52,47,.07);
backdrop-filter: blur(8px);
}
.stat span {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 800;
text-transform: uppercase;
letter-spacing: .07em;
}
.stat strong {
display: block;
margin-top: 3px;
font-size: 17px;
letter-spacing: -.02em;
}
.reset-view {
pointer-events: auto;
border: 1px solid rgba(255,255,255,.82);
border-radius: 12px;
padding: 10px 13px;
background: rgba(255,253,248,.9);
box-shadow: 0 7px 22px rgba(25,52,47,.07);
cursor: pointer;
font-size: 11px;
font-weight: 750;
}
.scene-bottom {
position: absolute;
z-index: 3;
left: 16px;
right: 16px;
bottom: 15px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 14px;
pointer-events: none;
}
.time-panel,
.legend-panel {
border: 1px solid rgba(255,255,255,.82);
border-radius: 14px;
background: rgba(255,253,248,.9);
box-shadow: 0 8px 26px rgba(25,52,47,.08);
backdrop-filter: blur(9px);
pointer-events: auto;
}
.time-panel {
width: min(410px, 55%);
padding: 10px 12px;
}
.time-row {
display: flex;
align-items: center;
gap: 10px;
}
#playButton {
flex: 0 0 auto;
width: 30px;
height: 30px;
border: 0;
border-radius: 9px;
color: #fff;
background: var(--green);
cursor: pointer;
font-size: 11px;
}
#timeSlider {
flex: 1;
min-width: 80px;
accent-color: var(--green);
cursor: pointer;
}
#timeOutput {
flex: 0 0 auto;
min-width: 48px;
color: var(--ink);
font-size: 12px;
font-weight: 800;
}
.legend-panel {
max-width: 300px;
padding: 10px 12px;
}
.legend-title {
margin-bottom: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: .07em;
text-transform: uppercase;
}
.legend-items {
display: flex;
flex-wrap: wrap;
gap: 9px 12px;
}
.legend-item {
display: flex;
align-items: center;
gap: 5px;
color: #51635d;
font-size: 10px;
font-weight: 700;
}
.legend-dot {
width: 8px;
height: 8px;
border-radius: 3px;
background: var(--dot);
}
.scene-help {
position: absolute;
z-index: 2;
left: 18px;
top: 102px;
color: #708079;
font-size: 10px;
pointer-events: none;
}
.tooltip {
position: absolute;
z-index: 8;
display: none;
max-width: 230px;
padding: 9px 11px;
border-radius: 10px;
color: #fff;
background: rgba(23,63,56,.96);
box-shadow: 0 8px 24px rgba(23,63,56,.2);
font-size: 11px;
line-height: 1.4;
pointer-events: none;
}
.tooltip strong { display: block; margin-bottom: 2px; }
.assignment-list {
display: grid;
gap: 8px;
}
.assignment-card {
position: relative;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 12px;
padding: 11px 34px 11px 13px;
background: #fff;
cursor: pointer;
transition: border-color .15s, transform .15s;
}
.assignment-card:hover {
transform: translateX(-2px);
border-color: #b6c7c0;
}
.assignment-card.selected {
border-color: var(--green);
box-shadow: 0 0 0 2px rgba(39,111,94,.09);
}
.assignment-card::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 4px;
background: var(--task-color);
}
.assignment-card.open-task {
background: #fafbf8;
border-style: dashed;
}
.assignment-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.assignment-title strong {
font-size: 12px;
line-height: 1.25;
}
.assignment-meta {
margin-top: 5px;
color: var(--muted);
font-size: 10px;
}
.remove-assignment {
position: absolute;
top: 8px;
right: 8px;
width: 22px;
height: 22px;
display: grid;
place-items: center;
border: 0;
border-radius: 7px;
color: #8a9792;
background: transparent;
cursor: pointer;
font-size: 15px;
}
.remove-assignment:hover {
color: var(--danger);
background: #f9e9e6;
}
.open-badge {
color: #8b6c2f;
background: #fff3d8;
}
.form-grid {
display: grid;
gap: 12px;
}
.field label {
display: block;
margin-bottom: 6px;
color: #51645d;
font-size: 10px;
font-weight: 800;
letter-spacing: .035em;
text-transform: uppercase;
}
select {
width: 100%;
height: 39px;
padding: 0 32px 0 10px;
border: 1px solid #d7e0da;
border-radius: 9px;
color: var(--ink);
background: #fff;
font-size: 12px;
cursor: pointer;
}
select:focus,
input:focus,
button:focus-visible {
outline: 3px solid rgba(39,111,94,.18);
outline-offset: 1px;
}
.duration-note {
margin-top: 7px;
color: var(--muted);
font-size: 10px;
}
.checks {
display: grid;
gap: 6px;
margin-top: 12px;
}
.check {
display: flex;
align-items: flex-start;
gap: 8px;
color: #65766f;
font-size: 10px;
line-height: 1.35;
}
.check-icon {
flex: 0 0 auto;
width: 16px;
height: 16px;
display: grid;
place-items: center;
border-radius: 50%;
background: #eef1ee;
color: #8a9892;
font-size: 9px;
font-weight: 900;
}
.check.ok { color: #376d5e; }
.check.ok .check-icon { color: #fff; background: #3f8d76; }
.check.bad { color: #9b4e46; }
.check.bad .check-icon { color: #fff; background: #c65d53; }
.primary-button {
width: 100%;
min-height: 40px;
border: 0;
border-radius: 10px;
color: #fff;
background: var(--green);
box-shadow: 0 5px 13px rgba(39,111,94,.18);
cursor: pointer;
font-size: 12px;
font-weight: 800;
}
.primary-button:hover { background: #205f50; }
.primary-button:disabled { opacity: .45; cursor: default; }
.secondary-button {
min-height: 34px;
padding: 0 12px;
border: 1px solid #d5dfd9;
border-radius: 9px;
background: #fff;
cursor: pointer;
font-size: 10px;
font-weight: 800;
}
.secondary-button:hover { border-color: #9eb5ac; }
.rules {
display: grid;
gap: 9px;
margin-top: 16px;
}
.rule {
display: flex;
gap: 9px;
align-items: flex-start;
color: #5d7069;
font-size: 10px;
line-height: 1.4;
}
.rule-icon {
flex: 0 0 auto;
width: 22px;
height: 22px;
display: grid;
place-items: center;
border-radius: 7px;
color: var(--green);
background: #e7f0ec;
font-size: 11px;
font-weight: 900;
}
.toast {
position: fixed;
z-index: 50;
left: 50%;
bottom: 24px;
max-width: min(430px, calc(100vw - 30px));
padding: 12px 16px;
border-radius: 12px;
color: #fff;
background: rgba(23,63,56,.97);
box-shadow: 0 14px 38px rgba(23,63,56,.26);
transform: translate(-50%, 20px);
opacity: 0;
pointer-events: none;
transition: opacity .2s, transform .2s;
font-size: 12px;
text-align: center;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
.toast.error { background: rgba(157,64,56,.97); }
.progress {
height: 6px;
overflow: hidden;
margin-top: 12px;
border-radius: 20px;
background: #e7ece8;
}
.progress > div {
height: 100%;
width: 0;
border-radius: inherit;
background: linear-gradient(90deg, #3d8d76, #72ae9c);
transition: width .3s;
}
@media (max-width: 1180px) {
.app { grid-template-columns: 250px minmax(0, 1fr) 300px; }
.panel-section { padding: 16px; }
.roster { padding: 10px; }
.event-meta { display: none; }
}
@media (max-width: 960px) {
.app {
grid-template-columns: 250px minmax(0, 1fr);
height: auto;
}
.scene-panel { min-height: 650px; }
.right-panel {
grid-column: 1 / -1;
border-left: 0;
border-top: 1px solid var(--line);
overflow: visible;
}
.right-panel { display: grid; grid-template-columns: 1fr 1fr; }
.right-panel .panel-section { border-right: 1px solid var(--line); }
}
@media (max-width: 700px) {
header { height: 64px; padding: 0 15px; }
.brand p { display: none; }
.app { display: flex; flex-direction: column; }
.scene-panel { order: 1; min-height: 580px; }
.left-panel { order: 2; border-right: 0; }
.right-panel { order: 3; display: block; }
.roster { max-height: 430px; }
.legend-panel { display: none; }
.time-panel { width: calc(100% - 32px); }
.scene-help { display: none; }
}
</style>
</head>
<body>
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<span></span><span></span><span></span><span></span>
</div>
<div>
<h1>Setup Crew</h1>
<p>Outdoor arts festival · volunteer skills and schedule</p>
</div>
</div>
<div class="event-meta">
<div>WORK WINDOW<strong>08:00–18:00</strong></div>
<div>EVENT<strong>Community Arts Market</strong></div>
<div>PLAN STATUS<strong id="headerStatus">Live</strong></div>
</div>
</header>
<main class="app">
<aside class="panel left-panel">
<section class="panel-section">
<div class="section-heading">
<h2>Volunteers</h2>
<span class="count" id="volunteerCount">6</span>
</div>
<p class="subtle">Availability is shown as one or more work intervals. Select a volunteer to focus their lane.</p>
</section>
<div class="roster" id="roster"></div>
</aside>
<section class="scene-panel" aria-label="Interactive three-dimensional volunteer schedule">
<div id="scene"></div>
<div class="scene-top">
<div class="stats">
<div class="stat">
<span>Task coverage</span>
<strong id="coverageStat">10 / 11</strong>
</div>
<div class="stat">
<span>On site now</span>
<strong id="siteStat">3 people</strong>
</div>
<div class="stat">
<span>Conflicts</span>
<strong id="conflictStat">0</strong>
</div>
</div>
<button class="reset-view" id="resetView" type="button">Reset view</button>
</div>
<div class="scene-help">Drag to orbit · Scroll to zoom · Shift-drag to pan · Click a lane or task</div>
<div class="scene-bottom">
<div class="time-panel">
<div class="time-row">
<button id="playButton" type="button" aria-label="Play schedule clock">▶</button>
<input id="timeSlider" type="range" min="480" max="1080" step="30" value="840" aria-label="Current time">
<output id="timeOutput">14:00</output>
</div>
</div>
<div class="legend-panel">
<div class="legend-title">Required skill</div>
<div class="legend-items">
<span class="legend-item"><i class="legend-dot" style="--dot:#e97955"></i>Tables</span>
<span class="legend-item"><i class="legend-dot" style="--dot:#5578c2"></i>Signs</span>
<span class="legend-item"><i class="legend-dot" style="--dot:#dca72f"></i>Lighting</span>
<span class="legend-item"><i class="legend-dot" style="--dot:#9065b2"></i>Power</span>
<span class="legend-item"><i class="legend-dot" style="--dot:#31917b"></i>Logistics</span>
</div>
</div>
</div>
<div class="tooltip" id="tooltip"></div>
</section>
<aside class="panel right-panel">
<section class="panel-section">
<div class="section-heading">
<h2>Assignments</h2>
<div style="display:flex;gap:7px;align-items:center">
<span class="count" id="assignmentCount">10</span>
<button class="secondary-button" id="autoPlan" type="button">Plan open</button>
</div>
</div>
<p class="subtle">Tasks use their exact required skill. Lighting, power and logistics remain separate.</p>
<div class="progress"><div id="coverageProgress"></div></div>
</section>
<section class="panel-section">
<div class="section-heading">
<h3>Assign a task</h3>
</div>
<div class="form-grid">
<div class="field">
<label for="taskSelect">Task</label>
<select id="taskSelect"></select>
<div class="duration-note" id="durationNote"></div>
</div>
<div class="field">
<label for="volunteerSelect">Volunteer</label>
<select id="volunteerSelect"></select>
</div>
<div class="field">
<label for="startSelect">Start time</label>
<select id="startSelect"></select>
</div>
<div class="checks" id="assignmentChecks" aria-live="polite"></div>
<button class="primary-button" id="assignButton" type="button">Assign task</button>
</div>
<div class="rules">
<div class="rule">
<span class="rule-icon">S</span>
<span><strong>Exact skill match.</strong> A lighting task cannot be given to a sign or power specialist.</span>
</div>
<div class="rule">
<span class="rule-icon">T</span>
<span><strong>Full interval.</strong> The complete task must fit inside one availability interval.</span>
</div>
<div class="rule">
<span class="rule-icon">≠</span>
<span><strong>No overlap.</strong> One volunteer cannot be scheduled in two places at once.</span>
</div>
</div>
</section>
<section class="panel-section" style="border-bottom:0">
<div class="section-heading">
<h3>Task board</h3>
</div>
<div class="assignment-list" id="assignmentList"></div>
</section>
</aside>
</main>
<div class="toast" id="toast" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const DAY_START = 8 * 60;
const DAY_END = 18 * 60;
const BOARD = { left: -7.2, right: 7.2 };
const skillColors = {
tables: "#e97955",
signs: "#5578c2",
lighting: "#dca72f",
power: "#9065b2",
logistics: "#31917b"
};
const skillNames = {
tables: "Tables",
signs: "Signs",
lighting: "Lighting",
power: "Power",
logistics: "Logistics"
};
const volunteers = [
{
id: "maya", name: "Maya Chen", initials: "MC", color: "#e97955",
skills: ["tables", "signs"], intervals: [[540, 900]]
},
{
id: "sofia", name: "Sofia Reyes", initials: "SR", color: "#d4a62f",
skills: ["tables", "signs"], intervals: [[510, 810]]
},
{
id: "iris", name: "Iris Patel", initials: "IP", color: "#2f8f79",
skills: ["tables", "logistics"], intervals: [[540, 750], [810, 960]]
},
{
id: "noah", name: "Noah Williams", initials: "NW", color: "#9065b2",
skills: ["signs", "lighting"], intervals: [[660, 990]]
},
{
id: "eli", name: "Eli Carter", initials: "EC", color: "#3e8da7",
skills: ["tables", "lighting"], intervals: [[720, 1050]]
},
{
id: "theo", name: "Theo Brooks", initials: "TB", color: "#6577b8",
skills: ["lighting", "power"], intervals: [[600, 1080]]
}
];
const tasks = [
{ id: "early", name: "Early check-in table", short: "Early check-in", skill: "tables", duration: 60, preferred: 510 },
{ id: "registration", name: "Registration tables", short: "Registration", skill: "tables", duration: 90, preferred: 540 },
{ id: "info", name: "Information table", short: "Info desk", skill: "tables", duration: 60, preferred: 630 },
{ id: "direction", name: "Directional sign cluster", short: "Wayfinding", skill: "signs", duration: 60, preferred: 660 },
{ id: "welcome", name: "Welcome sign", short: "Welcome sign", skill: "signs", duration: 45, preferred: 720 },
{ id: "water", name: "Water station", short: "Water station", skill: "tables", duration: 60, preferred: 690 },
{ id: "sponsor", name: "Sponsor board", short: "Sponsor board", skill: "signs", duration: 60, preferred: 840 },
{ id: "supply", name: "Supply staging", short: "Supply staging", skill: "logistics", duration: 60, preferred: 810 },
{ id: "courtyard", name: "Courtyard lighting", short: "Courtyard lights", skill: "lighting", duration: 120, preferred: 780 },
{ id: "stage", name: "Stage lighting", short: "Stage lights", skill: "lighting", duration: 60, preferred: 930 },
{ id: "power", name: "Power and cable run", short: "Power run", skill: "power", duration: 60, preferred: 990 }
];
let assignments = [
{ id: "a1", taskId: "early", volunteerId: "sofia", start: 510 },
{ id: "a2", taskId: "registration", volunteerId: "maya", start: 540 },
{ id: "a3", taskId: "info", volunteerId: "iris", start: 630 },
{ id: "a4", taskId: "direction", volunteerId: "noah", start: 660 },
{ id: "a5", taskId: "welcome", volunteerId: "noah", start: 720 },
{ id: "a6", taskId: "sponsor", volunteerId: "maya", start: 840 },
{ id: "a7", taskId: "supply", volunteerId: "iris", start: 810 },
{ id: "a8", taskId: "courtyard", volunteerId: "eli", start: 780 },
{ id: "a9", taskId: "stage", volunteerId: "noah", start: 930 },
{ id: "a10", taskId: "power", volunteerId: "theo", start: 990 }
];
const state = {
selectedVolunteerId: "maya",
selectedTaskId: "water",
currentTime: 840,
playing: false,
form: { taskId: "water", volunteerId: "maya", start: 690 }
};
const taskById = id => tasks.find(t => t.id === id);
const volunteerById = id => volunteers.find(v => v.id === id);
const assignmentForTask = taskId => assignments.find(a => a.taskId === taskId);
function formatTime(minutes) {
const h = Math.floor(minutes / 60);
const m = minutes % 60;
return `${String(h).padStart(2, "0")}:${String(m).padStart(2, "0")}`;
}
function intervalText(intervals) {
return intervals.map(([a, b]) => `${formatTime(a)}–${formatTime(b)}`).join(", ");
}
function showToast(message, error = false) {
const toast = document.getElementById("toast");
toast.textContent = message;
toast.classList.toggle("error", error);
toast.classList.add("show");
clearTimeout(showToast.timer);
showToast.timer = setTimeout(() => toast.classList.remove("show"), 3000);
}
function isOnSite(volunteerId, at = state.currentTime) {
return assignments.some(a => {
if (a.volunteerId !== volunteerId) return false;
const task = taskById(a.taskId);
return at >= a.start && at < a.start + task.duration;
});
}
function candidateChecks(task, volunteerId, start) {
const volunteer = volunteerById(volunteerId);
const end = start + task.duration;
const skill = !!volunteer && volunteer.skills.includes(task.skill);
const availability = !!volunteer && volunteer.intervals.some(
([a, b]) => start >= a && end <= b
);
const overlap = assignments.some(a => {
if (a.taskId === task.id || a.volunteerId !== volunteerId) return false;
const other = taskById(a.taskId);
return start < a.start + other.duration && end > a.start;
});
const insideDay = start >= DAY_START && end <= DAY_END;
return { skill, availability, overlap, insideDay };
}
function conflictCount() {
return assignments.filter(a => {
const task = taskById(a.taskId);
const checks = candidateChecks(task, a.volunteerId, a.start);
return !checks.skill || !checks.availability || checks.overlap || !checks.insideDay;
}).length;
}
function renderRoster() {
const roster = document.getElementById("roster");
roster.innerHTML = volunteers.map(v => {
const onSite = isOnSite(v.id);
const active = assignments.filter(a => a.volunteerId === v.id).length;
return `
<button class="volunteer-card ${state.selectedVolunteerId === v.id ? "selected" : ""}"
data-volunteer="${v.id}" type="button">
<div class="volunteer-top">
<span class="avatar ${onSite ? "on-site" : ""}" style="background:${v.color}">${v.initials}</span>
<span class="volunteer-name">
<strong>${v.name}</strong>
<span>${active} assignment${active === 1 ? "" : "s"}${onSite ? " · on site" : ""}</span>
</span>
</div>
<div class="availability">
${intervalText(v.intervals)}
${v.intervals.length > 1 ? '<span class="split-label">split shift</span>' : ""}
</div>
<div class="chips">
${v.skills.map(s => `<span class="chip skill-${s}">${skillNames[s]}</span>`).join("")}
</div>
</button>`;
}).join("");
roster.querySelectorAll("[data-volunteer]").forEach(card => {
card.addEventListener("click", () => {
const id = card.dataset.volunteer;
state.selectedVolunteerId = id;
const task = taskById(state.form.taskId);
const volunteer = volunteerById(id);
if (volunteer.skills.includes(task.skill)) {
state.form.volunteerId = id;
}
renderRoster();
renderForm();
rebuildDynamicScene();
});
});
}
function renderAssignments() {
const list = document.getElementById("assignmentList");
const sorted = [...tasks].sort((a, b) => {
const aa = assignmentForTask(a.id);
const bb = assignmentForTask(b.id);
return (aa?.start ?? a.preferred) - (bb?.start ?? b.preferred);
});
list.innerHTML = sorted.map(task => {
const assignment = assignmentForTask(task.id);
const color = skillColors[task.skill];
if (!assignment) {
return `
<div class="assignment-card open-task ${state.selectedTaskId === task.id ? "selected" : ""}"
data-task="${task.id}">
<div class="assignment-title">
<strong>${task.name}</strong>
<span class="count open-badge">Open</span>
</div>
<div class="assignment-meta">
${formatTime(task.preferred)} · ${task.duration} min · Requires ${skillNames[task.skill].toLowerCase()}
</div>
</div>`;
}
const volunteer = volunteerById(assignment.volunteerId);
return `
<div class="assignment-card ${state.selectedTaskId === task.id ? "selected" : ""}"
data-task="${task.id}" style="--task-color:${color}">
<button class="remove-assignment" data-remove="${assignment.id}" type="button"
aria-label="Remove ${task.name}">×</button>
<div class="assignment-title">
<strong>${task.name}</strong>
<span class="chip skill-${task.skill}">${skillNames[task.skill]}</span>
</div>
<div class="assignment-meta">
${volunteer.name} · ${formatTime(assignment.start)}–${formatTime(assignment.start + task.duration)}
</div>
</div>`;
}).join("");
list.querySelectorAll("[data-task]").forEach(card => {
card.addEventListener("click", event => {
if (event.target.closest("[data-remove]")) return;
focusTask(card.dataset.task);
});
});
list.querySelectorAll("[data-remove]").forEach(button => {
button.addEventListener("click", event => {
event.stopPropagation();
assignments = assignments.filter(a => a.id !== button.dataset.remove);
renderAll();
showToast("Assignment removed. The task is open again.");
});
});
}
function renderStats() {
const assigned = assignments.length;
const onSite = new Set(
assignments.filter(a => {
const t = taskById(a.taskId);
return state.currentTime >= a.start && state.currentTime < a.start + t.duration;
}).map(a => a.volunteerId)
).size;
const conflicts = conflictCount();
document.getElementById("coverageStat").textContent = `${assigned} / ${tasks.length}`;
document.getElementById("siteStat").textContent = `${onSite} ${onSite === 1 ? "person" : "people"}`;
document.getElementById("conflictStat").textContent = conflicts;
document.getElementById("assignmentCount").textContent = assigned;
document.getElementById("volunteerCount").textContent = volunteers.length;
document.getElementById("coverageProgress").style.width = `${assigned / tasks.length * 100}%`;
document.getElementById("headerStatus").textContent = conflicts ? "Needs attention" : "Live";
document.getElementById("autoPlan").disabled = assigned === tasks.length;
}
function renderForm() {
const task = taskById(state.form.taskId);
const taskSelect = document.getElementById("taskSelect");
const volunteerSelect = document.getElementById("volunteerSelect");
const startSelect = document.getElementById("startSelect");
taskSelect.innerHTML = tasks.map(t =>
`<option value="${t.id}">${t.name} · ${skillNames[t.skill]}</option>`
).join("");
taskSelect.value = task.id;
const eligible = volunteers.filter(v => v.skills.includes(task.skill));
if (!eligible.some(v => v.id === state.form.volunteerId)) {
state.form.volunteerId = eligible[0]?.id ?? "";
state.selectedVolunteerId = state.form.volunteerId;
}
volunteerSelect.innerHTML = volunteers.map(v => {
const disabled = !v.skills.includes(task.skill);
const skillText = v.skills.map(s => skillNames[s]).join(" + ");
return `
<option value="${v.id}" ${disabled ? "disabled" : ""}>
${v.name} · ${skillText}${disabled ? " — wrong skill" : ""}
</option>`;
}).join("");
volunteerSelect.value = state.form.volunteerId;
const latestStart = DAY_END - task.duration;
const starts = [];
for (let t = DAY_START; t <= latestStart; t += 30) starts.push(t);
if (!starts.includes(state.form.start)) {
state.form.start = starts.includes(task.preferred) ? task.preferred : starts[0];
}
startSelect.innerHTML = starts.map(t =>
`<option value="${t}">${formatTime(t)}</option>`
).join("");
startSelect.value = state.form.start;
document.getElementById("durationNote").textContent =
`${task.duration} minutes · exact skill required: ${skillNames[task.skill]}`;
const existing = assignmentForTask(task.id);
document.getElementById("assignButton").textContent = existing ? "Update assignment" : "Assign task";
renderChecks();
}
function renderChecks() {
const task = taskById(state.form.taskId);
const checks = candidateChecks(task, state.form.volunteerId, state.form.start);
const rows = [
{
ok: checks.skill,
title: "Exact skill match",
detail: checks.skill ? `${skillNames[task.skill]} is in this volunteer's skill set.` : "This volunteer does not have the required skill."
},
{
ok: checks.availability,
title: "Inside availability",
detail: checks.availability ? "The whole task fits in one work interval." : "The task extends outside an available interval."
},
{
ok: !checks.overlap,
title: "No time overlap",
detail: !checks.overlap ? "This volunteer is free for the full task." : "This volunteer already has an assignment during this time."
},
{
ok: checks.insideDay,
title: "Inside event window",
detail: checks.insideDay ? "The task finishes by 18:00." : "The task extends outside the event window."
}
];
document.getElementById("assignmentChecks").innerHTML = rows.map(row => `
<div class="check ${row.ok ? "ok" : "bad"}">
<span class="check-icon">${row.ok ? "✓" : "!"}</span>
<span><strong>${row.title}.</strong> ${row.detail}</span>
</div>
`).join("");
}
function focusTask(taskId) {
const task = taskById(taskId);
const assignment = assignmentForTask(taskId);
state.selectedTaskId = taskId;
state.form.taskId = taskId;
state.form.start = assignment?.start ?? task.preferred;
state.form.volunteerId = assignment?.volunteerId ??
volunteers.find(v => v.skills.includes(task.skill))?.id;
state.selectedVolunteerId = state.form.volunteerId;
renderRoster();
renderAssignments();
renderForm();
rebuildDynamicScene();
}
function renderAll() {
renderRoster();
renderAssignments();
renderStats();
renderForm();
rebuildDynamicScene();
}
document.getElementById("taskSelect").addEventListener("change", event => {
focusTask(event.target.value);
});
document.getElementById("volunteerSelect").addEventListener("change", event => {
state.form.volunteerId = event.target.value;
state.selectedVolunteerId = event.target.value;
renderRoster();
renderChecks();
rebuildDynamicScene();
});
document.getElementById("startSelect").addEventListener("change", event => {
state.form.start = Number(event.target.value);
renderChecks();
});
document.getElementById("assignButton").addEventListener("click", () => {
const task = taskById(state.form.taskId);
const checks = candidateChecks(task, state.form.volunteerId, state.form.start);
if (!checks.skill) return showToast(`This task requires ${skillNames[task.skill].toLowerCase()}.`, true);
if (!checks.availability) return showToast("That assignment does not fit inside the volunteer's availability.", true);
if (checks.overlap) return showToast("That time overlaps another assignment for this volunteer.", true);
if (!checks.insideDay) return showToast("That assignment extends beyond the 08:00–18:00 event window.", true);
const existing = assignmentForTask(task.id);
if (existing) {
assignments = assignments.filter(a => a.id !== existing.id);
}
assignments.push({
id: existing?.id ?? `a${Date.now()}`,
taskId: task.id,
volunteerId: state.form.volunteerId,
start: state.form.start
});
state.selectedVolunteerId = state.form.volunteerId;
state.selectedTaskId = task.id;
renderAll();
showToast(`${task.name} assigned to ${volunteerById(state.form.volunteerId).name}.`);
});
document.getElementById("autoPlan").addEventListener("click", () => {
const openTasks = tasks.filter(t => !assignmentForTask(t.id));
let planned = 0;
for (const task of openTasks) {
const candidates = volunteers
.filter(v => v.skills.includes(task.skill))
.sort((a, b) =>
assignments.filter(x => x.volunteerId === a.id).length -
assignments.filter(x => x.volunteerId === b.id).length
);
let placed = false;
for (const volunteer of candidates) {
const possible = [];
for (let start = DAY_START; start <= DAY_END - task.duration; start += 30) {
possible.push(start);
}
possible.sort((a, b) => Math.abs(a - task.preferred) - Math.abs(b - task.preferred));
for (const start of possible) {
const checks = candidateChecks(task, volunteer.id, start);
if (checks.skill && checks.availability && !checks.overlap && checks.insideDay) {
assignments.push({
id: `auto${Date.now()}${planned}`,
taskId: task.id,
volunteerId: volunteer.id,
start
});
state.selectedTaskId = task.id;
state.selectedVolunteerId = volunteer.id;
state.form = { taskId: task.id, volunteerId: volunteer.id, start };
planned++;
placed = true;
break;
}
}
if (placed) break;
}
}
renderAll();
showToast(planned ? `Planned ${planned} open task${planned === 1 ? "" : "s"} without conflicts.` :
"No open task has a valid skill-and-time match.", !planned);
});
// ---------- Three.js scene ----------
const sceneHost = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#e9eee9");
scene.fog = new THREE.Fog("#e9eee9", 24, 52);
const camera = new THREE.PerspectiveCamera(37, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.prepend(renderer.domElement);
renderer.domElement.setAttribute("aria-label", "3D volunteer assignment timeline");
renderer.domElement.tabIndex = 0;
const hemisphere = new THREE.HemisphereLight("#ffffff", "#aab7ae", 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff8e8", 3.2);
sun.position.set(8, 15, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.0003;
scene.add(sun);
const boardGroup = new THREE.Group();
const dynamicGroup = new THREE.Group();
scene.add(boardGroup, dynamicGroup);
function solid(geometry, color, options = {}) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
flatShading: true,
...options
});
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + w - r, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
ctx.lineTo(x + w, y + h - r);
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
ctx.lineTo(x + r, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function textSprite(text, {
background = "#fffdf8",
foreground = "#19342f",
accent = null,
width = 2,
height = 0.42,
depthTest = true
} = {}) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 160;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 4, 4, 760, 152, 28);
ctx.fillStyle = background;
ctx.fill();
if (accent) {
roundedRect(ctx, 18, 18, 12, 124, 6);
ctx.fillStyle = accent;
ctx.fill();
}
const maxWidth = accent ? 685 : 710;
let fontSize = 45;
do {
ctx.font = `700 ${fontSize}px Inter, system-ui, sans-serif`;
fontSize -= 2;
} while (ctx.measureText(text).width > maxWidth && fontSize > 20);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = foreground;
ctx.fillText(text, accent ? 402 : 384, 81);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, height, 1);
sprite.renderOrder = 5;
return sprite;
}
function timeToX(minutes) {
return BOARD.left + (minutes - DAY_START) / (DAY_END - DAY_START) * (BOARD.right - BOARD.left);
}
function rowZ(index) {
return -3.55 + index * 1.34;
}
function makeGrid() {
const base = solid(new THREE.BoxGeometry(16.8, 0.44, 9.6), "#d7dfd8");
base.position.y = -0.23;
boardGroup.add(base);
const top = solid(new THREE.BoxGeometry(16.42, 0.08, 9.22), "#f8f6ed");
top.position.y = -0.01;
boardGroup.add(top);
const frontEdge = solid(new THREE.BoxGeometry(16.3, 0.08, 0.09), "#367b68");
frontEdge.position.set(0, 0.05, 4.72);
boardGroup.add(frontEdge);
const gridMaterial = new THREE.MeshBasicMaterial({ color: "#cfd8d1", transparent: true, opacity: 0.8 });
for (let h = DAY_START; h <= DAY_END; h += 60) {
const x = timeToX(h);
const line = new THREE.Mesh(new THREE.BoxGeometry(0.012, 0.014, 8.6), gridMaterial);
line.position.set(x, 0.045, 0);
boardGroup.add(line);
const label = textSprite(formatTime(h), {
background: "#f3f5ef",
foreground: "#687971",
width: 0.88,
height: 0.31,
depthTest: false
});
label.position.set(x, 0.18, 4.38);
boardGroup.add(label);
}
for (let i = 0; i < volunteers.length; i++) {
const z = rowZ(i);
const line = new THREE.Mesh(
new THREE.BoxGeometry(14.45, 0.012, 0.012),
new THREE.MeshBasicMaterial({ color: "#d4ddd6", transparent: true, opacity: 0.85 })
);
line.position.set(0, 0.045, z + 0.58);
boardGroup.add(line);
}
const title = textSprite("SETUP TIMELINE · 08:00–18:00", {
background: "#173f38",
foreground: "#ffffff",
accent: "#f1c75b",
width: 4.2,
height: 0.48,
depthTest: false
});
title.position.set(-4.6, 0.25, -4.25);
boardGroup.add(title);
}
makeGrid();
const ground = solid(new THREE.PlaneGeometry(80, 80), "#dfe6df", { roughness: 1 });
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.48;
ground.receiveShadow = true;
ground.castShadow = false;
scene.add(ground);
function makeAvailabilityStrip(volunteer, interval, z) {
const [start, end] = interval;
const width = timeToX(end) - timeToX(start);
const strip = solid(
new THREE.BoxGeometry(width, 0.025, 0.11),
"#6cb59d",
{ transparent: true, opacity: 0.6, roughness: 1 }
);
strip.position.set((timeToX(start) + timeToX(end)) / 2, 0.065, z + 0.39);
strip.castShadow = false;
return strip;
}
function makeAvatar(volunteer, z) {
const group = new THREE.Group();
group.position.set(-8.02, 0.04, z);
const skin = solid(new THREE.SphereGeometry(0.17, 16, 12), "#e3aa84");
skin.position.y = 0.82;
group.add(skin);
const body = solid(new THREE.CylinderGeometry(0.17, 0.22, 0.43, 12), volunteer.color);
body.position.y = 0.49;
group.add(body);
const legMaterial = solid(new THREE.CylinderGeometry(0.055, 0.065, 0.28, 8), "#314a43");
for (const x of [-0.08, 0.08]) {
const leg = legMaterial.clone();
leg.position.set(x, 0.14, 0);
group.add(leg);
}
const armMaterial = solid(new THREE.CylinderGeometry(0.045, 0.05, 0.37, 8), volunteer.color);
for (const x of [-0.22, 0.22]) {
const arm = armMaterial.clone();
arm.position.set(x, 0.47, 0);
arm.rotation.z = x < 0 ? -0.18 : 0.18;
group.add(arm);
}
if (state.selectedVolunteerId === volunteer.id) {
const ring = solid(
new THREE.TorusGeometry(0.31, 0.035, 8, 24),
"#f1c75b",
{ emissive: "#6d5612", emissiveIntensity: 0.18 }
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.035;
group.add(ring);
}
const label = textSprite(volunteer.name, {
background: "#173f38",
foreground: "#ffffff",
accent: volunteer.color,
width: 1.9,
height: 0.42,
depthTest: false
});
label.position.set(-8.02, 1.42, z);
group.add(label);
group.traverse(object => {
if (object.isMesh || object.isSprite) {
object.userData.pick = { type: "volunteer", id: volunteer.id };
}
});
return group;
}
function makeTaskProp(skill) {
const group = new THREE.Group();
if (skill === "tables") {
const top = solid(new THREE.BoxGeometry(0.58, 0.07, 0.34), "#f2d3b8");
top.position.y = 0.29;
group.add(top);
const legMaterial = solid(new THREE.BoxGeometry(0.055, 0.28, 0.055), "#72594d");
for (const x of [-0.21, 0.21]) {
for (const z of [-0.10, 0.10]) {
const leg = legMaterial.clone();
leg.position.set(x, 0.14, z);
group.add(leg);
}
}
} else if (skill === "signs") {
const board = solid(new THREE.BoxGeometry(0.55, 0.34, 0.07), "#f4ead5");
board.position.y = 0.37;
group.add(board);
const stripe = solid(new THREE.BoxGeometry(0.42, 0.055, 0.015), skillColors.signs);
stripe.position.set(0, 0.40, 0.044);
group.add(stripe);
const legMaterial = solid(new THREE.BoxGeometry(0.04, 0.27, 0.04), "#52675e");
for (const x of [-0.20, 0.20]) {
const leg = legMaterial.clone();
leg.position.set(x, 0.14, 0);
group.add(leg);
}
} else if (skill === "lighting") {
const pole = solid(new THREE.CylinderGeometry(0.025, 0.035, 0.45, 8), "#455852");
pole.position.y = 0.23;
group.add(pole);
const fixture = solid(new THREE.BoxGeometry(0.22, 0.13, 0.18), "#ffe394", {
emissive: "#d99e16", emissiveIntensity: 0.22
});
fixture.position.set(0, 0.48, 0);
group.add(fixture);
const lens = solid(new THREE.CylinderGeometry(0.07, 0.07, 0.025, 12), "#fff4bd");
lens.rotation.x = Math.PI / 2;
lens.position.set(0, 0.48, 0.10);
group.add(lens);
} else if (skill === "power") {
const box = solid(new THREE.BoxGeometry(0.28, 0.19, 0.2), "#d7c2e5");
box.position.y = 0.13;
group.add(box);
for (const x of [-0.07, 0.07]) {
const socket = solid(new THREE.CylinderGeometry(0.035, 0.035, 0.025, 10), "#4d4055");
socket.rotation.x = Math.PI / 2;
socket.position.set(x, 0.13, 0.11);
group.add(socket);
}
const cable = solid(new THREE.TorusGeometry(0.17, 0.025, 7, 16, Math.PI * 1.5), "#e37d55");
cable.rotation.x = Math.PI / 2;
cable.position.set(0.12, 0.04, 0.02);
group.add(cable);
} else {
const crate = solid(new THREE.BoxGeometry(0.42, 0.29, 0.34), "#d4b889");
crate.position.y = 0.15;
group.add(crate);
const strap = solid(new THREE.BoxGeometry(0.055, 0.31, 0.36), "#547f6c");
strap.position.y = 0.15;
group.add(strap);
}
return group;
}
function makeAssignmentBlock(assignment) {
const task = taskById(assignment.taskId);
const volunteer = volunteerById(assignment.volunteerId);
const index = volunteers.findIndex(v => v.id === volunteer.id);
const z = rowZ(index);
const x1 = timeToX(assignment.start);
const x2 = timeToX(assignment.start + task.duration);
const width = x2 - x1;
const center = (x1 + x2) / 2;
const selected = state.selectedTaskId === task.id;
const group = new THREE.Group();
const block = solid(
new THREE.BoxGeometry(width, 0.48, 0.58),
skillColors[task.skill],
{
roughness: 0.7,
emissive: selected ? "#253d37" : "#000000",
emissiveIntensity: selected ? 0.13 : 0
}
);
block.position.set(center, 0.26, z);
group.add(block);
if (selected) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(block.geometry),
new THREE.LineBasicMaterial({ color: "#fff5c7" })
);
edges.position.copy(block.position);
edges.scale.setScalar(1.015);
edges.renderOrder = 4;
group.add(edges);
}
const prop = makeTaskProp(task.skill);
prop.position.set(center, 0.5, z);
group.add(prop);
const label = textSprite(task.short, {
background: "#fffdf8",
foreground: "#213d36",
accent: skillColors[task.skill],
width: Math.min(Math.max(width * 0.88, 1.2), 2.55),
height: 0.38,
depthTest: true
});
label.position.set(center, 0.94, z);
group.add(label);
group.traverse(object => {
if (object.isMesh || object.isSprite) {
object.userData.pick = { type: "task", id: task.id };
}
});
return group;
}
function disposeObject(object) {
object.traverse(child => {
if (child.geometry) child.geometry.dispose();
if (child.material) {
const materials = Array.isArray(child.material) ? child.material : [child.material];
materials.forEach(material => {
if (material.map) material.map.dispose();
material.dispose();
});
}
});
}
function rebuildDynamicScene() {
while (dynamicGroup.children.length) {
const child = dynamicGroup.children[0];
disposeObject(child);
dynamicGroup.remove(child);
}
volunteers.forEach((volunteer, index) => {
const z = rowZ(index);
volunteer.intervals.forEach(interval => {
dynamicGroup.add(makeAvailabilityStrip(volunteer, interval, z));
});
dynamicGroup.add(makeAvatar(volunteer, z));
});
assignments.forEach(assignment => {
dynamicGroup.add(makeAssignmentBlock(assignment));
});
}
rebuildDynamicScene();
// Current-time marker.
const currentMarker = new THREE.Group();
const markerLine = new THREE.Mesh(
new THREE.BoxGeometry(0.035, 2.7, 0.035),
new THREE.MeshBasicMaterial({
color: "#ef8354",
transparent: true,
opacity: 0.78,
depthTest: false
})
);
markerLine.position.y = 1.35;
markerLine.renderOrder = 8;
currentMarker.add(markerLine);
const markerTip = new THREE.Mesh(
new THREE.ConeGeometry(0.12, 0.26, 12),
new THREE.MeshBasicMaterial({ color: "#ef8354", depthTest: false })
);
markerTip.position.y = 2.82;
markerTip.renderOrder = 8;
currentMarker.add(markerTip);
scene.add(currentMarker);
function updateCurrentMarker() {
currentMarker.position.x = timeToX(state.currentTime);
}
updateCurrentMarker();
// Custom orbit, pan and zoom controls; no addons are used.
const orbit = {
theta: 0,
phi: 0.91,
radius: 18.7,
target: new THREE.Vector3(0, 0, 0),
desiredTheta: 0,
desiredPhi: 0.91,
desiredRadius: 18.7,
desiredTarget: new THREE.Vector3(0, 0, 0)
};
function applyCamera() {
orbit.theta += (orbit.desiredTheta - orbit.theta) * 0.12;
orbit.phi += (orbit.desiredPhi - orbit.phi) * 0.12;
orbit.radius += (orbit.desiredRadius - orbit.radius) * 0.12;
orbit.target.lerp(orbit.desiredTarget, 0.12);
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
applyCamera();
function resetView() {
orbit.desiredTheta = 0;
orbit.desiredPhi = 0.91;
orbit.desiredRadius = 18.7;
orbit.desiredTarget.set(0, 0, 0);
}
document.getElementById("resetView").addEventListener("click", resetView);
const canvas = renderer.domElement;
const tooltip = document.getElementById("tooltip");
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = null;
let dragging = false;
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 pickAt(event) {
pointerToNDC(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(dynamicGroup.children, true);
for (const hit of hits) {
if (hit.object.userData.pick) return hit.object.userData.pick;
}
return null;
}
canvas.addEventListener("pointerdown", event => {
pointerDown = { x: event.clientX, y: event.clientY, button: event.button };
dragging = false;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (pointerDown) {
const dx = event.clientX - pointerDown.x;
const dy = event.clientY - pointerDown.y;
if (Math.abs(dx) + Math.abs(dy) > 4) dragging = true;
if (pointerDown.button === 2 || event.shiftKey) {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const amount = orbit.radius * 0.0015;
orbit.desiredTarget.addScaledVector(right, -dx * amount);
orbit.desiredTarget.addScaledVector(up, dy * amount);
orbit.desiredTarget.x = THREE.MathUtils.clamp(orbit.desiredTarget.x, -8, 8);
orbit.desiredTarget.z = THREE.MathUtils.clamp(orbit.desiredTarget.z, -5, 5);
} else {
orbit.desiredTheta -= dx * 0.006;
orbit.desiredPhi = THREE.MathUtils.clamp(orbit.desiredPhi - dy * 0.005, 0.35, 1.35);
}
pointerDown.x = event.clientX;
pointerDown.y = event.clientY;
tooltip.style.display = "none";
return;
}
const pick = pickAt(event);
if (pick) {
canvas.style.cursor = "pointer";
const rect = sceneHost.getBoundingClientRect();
tooltip.style.left = `${event.clientX - rect.left + 14}px`;
tooltip.style.top = `${event.clientY - rect.top + 14}px`;
if (pick.type === "volunteer") {
const v = volunteerById(pick.id);
tooltip.innerHTML = `<strong>${v.name}</strong>${v.skills.map(s => skillNames[s]).join(" + ")}<br>${intervalText(v.intervals)}`;
} else {
const task = taskById(pick.id);
const a = assignmentForTask(task.id);
tooltip.innerHTML = `<strong>${task.name}</strong>${skillNames[task.skill]} · ${task.duration} min` +
(a ? `<br>${volunteerById(a.volunteerId).name} · ${formatTime(a.start)}–${formatTime(a.start + task.duration)}` : "");
}
tooltip.style.display = "block";
} else {
canvas.style.cursor = "grab";
tooltip.style.display = "none";
}
});
canvas.addEventListener("pointerup", event => {
if (pointerDown && !dragging && pointerDown.button === 0) {
const pick = pickAt(event);
if (pick?.type === "task") {
focusTask(pick.id);
} else if (pick?.type === "volunteer") {
const card = document.querySelector(`[data-volunteer="${pick.id}"]`);
card?.click();
}
}
pointerDown = null;
});
canvas.addEventListener("pointercancel", () => {
pointerDown = null;
dragging = false;
});
canvas.addEventListener("pointerleave", () => {
tooltip.style.display = "none";
});
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("wheel", event => {
event.preventDefault();
orbit.desiredRadius = THREE.MathUtils.clamp(
orbit.desiredRadius * Math.exp(event.deltaY * 0.001),
9,
29
);
}, { passive: false });
canvas.addEventListener("dblclick", resetView);
// Clock controls.
const timeSlider = document.getElementById("timeSlider");
const timeOutput = document.getElementById("timeOutput");
const playButton = document.getElementById("playButton");
let playTimer = null;
function setCurrentTime(value) {
state.currentTime = Number(value);
timeOutput.value = formatTime(state.currentTime);
timeSlider.value = state.currentTime;
updateCurrentMarker();
renderStats();
renderRoster();
}
timeSlider.addEventListener("input", event => setCurrentTime(event.target.value));
playButton.addEventListener("click", () => {
state.playing = !state.playing;
playButton.textContent = state.playing ? "Ⅱ" : "▶";
clearInterval(playTimer);
if (state.playing) {
playTimer = setInterval(() => {
let next = state.currentTime + 30;
if (next > DAY_END) next = DAY_START;
setCurrentTime(next);
}, 700);
}
});
function resize() {
const width = sceneHost.clientWidth;
const height = sceneHost.clientHeight;
if (!width || !height) return;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
new ResizeObserver(resize).observe(sceneHost);
resize();
function animate() {
requestAnimationFrame(animate);
applyCamera();
renderer.render(scene, camera);
}
animate();
renderAll();
setCurrentTime(840);
</script>
</body>
</html>
```