Prompt specification
Build or customize the Three.js 3D scene "Community Workshop Reservation System" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Community Workshop Reservation System
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/community-workshop-reservation-system-x3263
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a voxel community workshop with a simple reservation system. Include a shared workbench, a drill station, a storage wall, and a small noticeboard beside the entrance. Give each station its own availability timeline and mark one interval as a maintenance closure. Users can place booking blocks on the timelines and inspect rejected requests: an overlap, a closed station, or insufficient available time should produce a specific reason. Keep the workshop arrangement fixed while the schedule changes. Accepted bookings should highlight the corresponding physical station so the timetable remains connected to the scene.
Working Three.js Starter (community-workshop-reservation-system-x3263):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Block & Bench — Community Workshop Reservations</title>
<style>
:root {
--ink: #17252a;
--muted: #66777b;
--paper: #f5f1e6;
--paper-deep: #e9e3d4;
--line: #d4cdbd;
--green: #167a65;
--green-bright: #47c9a7;
--orange: #e87942;
--orange-bright: #f6b94f;
--purple: #7358b8;
--red: #bd3f4d;
--red-soft: #f8dfe1;
--blue: #377b93;
--shadow: 0 14px 35px rgba(28, 42, 45, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: #dce3de;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
select {
font: inherit;
}
button {
cursor: pointer;
}
.app {
height: 100vh;
min-height: 680px;
display: grid;
grid-template-rows: 74px minmax(0, 1fr);
overflow: hidden;
}
.topbar {
z-index: 20;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 0 22px;
color: #f9f6ed;
background: #193239;
border-bottom: 4px solid #f0ae49;
box-shadow: 0 5px 18px rgba(12, 28, 32, 0.18);
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
position: relative;
width: 40px;
height: 40px;
flex: 0 0 auto;
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
width: 19px;
height: 19px;
border: 3px solid #f5bb58;
box-shadow: inset 0 0 0 3px #193239;
}
.brand-mark::before {
left: 2px;
top: 3px;
}
.brand-mark::after {
right: 2px;
bottom: 3px;
border-color: #54c9a8;
}
.brand h1 {
margin: 0;
font-size: 19px;
letter-spacing: 0.02em;
}
.brand p {
margin: 3px 0 0;
color: #b9c8c7;
font: 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.header-meta {
display: flex;
align-items: center;
gap: 10px;
flex-wrap: wrap;
justify-content: flex-end;
}
.header-chip {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 4px;
color: #d8e4e1;
background: rgba(255, 255, 255, 0.05);
font: 11px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.live-dot {
width: 7px;
height: 7px;
background: #54d2a9;
border-radius: 50%;
box-shadow: 0 0 0 3px rgba(84, 210, 169, 0.15);
}
.workspace {
min-height: 0;
display: grid;
grid-template-columns: minmax(520px, 1.45fr) minmax(440px, 0.9fr);
gap: 12px;
padding: 12px;
}
.scene-card,
.panel-card,
.timeline-card {
border: 1px solid rgba(73, 87, 82, 0.15);
background: var(--paper);
box-shadow: var(--shadow);
}
.scene-card {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
border-radius: 8px;
background: #d9e3dd;
}
#viewport {
position: absolute;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.scene-top {
position: absolute;
z-index: 4;
top: 16px;
left: 16px;
right: 16px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
pointer-events: none;
}
.scene-title {
max-width: 390px;
padding: 12px 14px;
border: 1px solid rgba(34, 55, 55, 0.12);
border-radius: 6px;
background: rgba(249, 246, 237, 0.92);
backdrop-filter: blur(8px);
box-shadow: 0 8px 22px rgba(36, 50, 51, 0.12);
}
.eyebrow {
margin: 0 0 5px;
color: var(--green);
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.scene-title h2 {
margin: 0;
font-size: 18px;
}
.scene-title p {
margin: 5px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.scene-actions {
pointer-events: auto;
display: flex;
gap: 7px;
}
.small-button,
.ghost-button {
padding: 8px 10px;
border: 1px solid rgba(41, 58, 60, 0.2);
border-radius: 4px;
color: var(--ink);
background: rgba(250, 248, 241, 0.94);
font: 11px ui-monospace, SFMono-Regular, Menlo, monospace;
font-weight: 800;
letter-spacing: 0.03em;
text-transform: uppercase;
box-shadow: 0 5px 12px rgba(32, 44, 45, 0.1);
}
.small-button:hover,
.ghost-button:hover {
background: white;
transform: translateY(-1px);
}
.scene-labels {
position: absolute;
z-index: 3;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.station-label {
position: absolute;
display: flex;
align-items: center;
gap: 8px;
min-width: 144px;
padding: 7px 9px;
border: 1px solid rgba(28, 49, 52, 0.18);
border-radius: 5px;
color: var(--ink);
background: rgba(250, 248, 240, 0.93);
box-shadow: 0 6px 16px rgba(28, 43, 44, 0.14);
transform: translate(-50%, -100%);
pointer-events: auto;
text-align: left;
transition: background 140ms ease, border-color 140ms ease;
}
.station-label:hover,
.station-label.selected {
border-color: var(--green);
background: #fffdf6;
}
.label-dot {
width: 10px;
height: 10px;
flex: 0 0 auto;
border-radius: 2px;
background: var(--label-color);
box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.45);
}
.station-label b {
display: block;
font-size: 11px;
}
.station-label small {
display: block;
margin-top: 2px;
color: var(--muted);
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.scene-bottom {
position: absolute;
z-index: 4;
right: 14px;
bottom: 14px;
left: 14px;
display: flex;
justify-content: space-between;
align-items: flex-end;
gap: 10px;
pointer-events: none;
}
.scene-help,
.scene-selection {
padding: 8px 10px;
border: 1px solid rgba(30, 50, 52, 0.14);
border-radius: 4px;
color: #4f6264;
background: rgba(248, 246, 238, 0.88);
backdrop-filter: blur(6px);
font: 10px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.scene-selection {
color: var(--ink);
font-weight: 800;
}
.schedule-panel {
min-width: 0;
min-height: 0;
overflow-y: auto;
padding-right: 3px;
scrollbar-width: thin;
scrollbar-color: #aeb8b2 transparent;
}
.panel-card {
margin-bottom: 11px;
padding: 14px;
border-radius: 7px;
}
.panel-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.panel-heading h3 {
margin: 0;
font-size: 15px;
}
.panel-heading p {
margin: 4px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.control-grid {
display: grid;
grid-template-columns: 1fr auto;
gap: 10px;
align-items: end;
}
.field-label {
display: block;
margin-bottom: 6px;
color: #59696b;
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
select {
width: 100%;
padding: 9px 31px 9px 10px;
border: 1px solid #cfc7b7;
border-radius: 4px;
color: var(--ink);
background: #fffdf7;
font-size: 12px;
font-weight: 700;
}
.interaction-note {
margin: 10px 0 0;
padding: 8px 10px;
border-left: 3px solid var(--green);
color: #536566;
background: #e9eee8;
font-size: 11px;
line-height: 1.45;
}
.demo-row {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 11px;
}
.demo-button {
padding: 7px 8px;
border: 1px solid #d4cbbb;
border-radius: 3px;
color: #5c4b3f;
background: #efe8da;
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
font-weight: 800;
}
.demo-button:hover {
background: #fff9ec;
}
.timeline-list {
display: grid;
gap: 10px;
}
.timeline-card {
padding: 12px;
border-radius: 7px;
transition: border-color 140ms ease, box-shadow 140ms ease;
}
.timeline-card.selected {
border-color: var(--station-color);
box-shadow:
0 10px 24px rgba(28, 42, 45, 0.12),
inset 3px 0 0 var(--station-color);
}
.timeline-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 9px;
}
.station-select {
display: flex;
align-items: center;
gap: 8px;
padding: 0;
border: 0;
color: var(--ink);
background: transparent;
text-align: left;
}
.station-index {
display: grid;
width: 24px;
height: 24px;
place-items: center;
border-radius: 3px;
color: white;
background: var(--station-color);
font: 800 11px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.station-select b {
display: block;
font-size: 12px;
}
.station-select small {
display: block;
margin-top: 2px;
color: var(--muted);
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.maintenance-chip {
padding: 5px 6px;
border-radius: 3px;
color: #87452f;
background: #f6dfce;
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
font-weight: 800;
white-space: nowrap;
}
.timeline-wrap {
position: relative;
}
.timeline-track {
position: relative;
height: 62px;
overflow: hidden;
border: 1px solid #c9c1b1;
border-radius: 4px;
background-color: #ece8dc;
background-image:
repeating-linear-gradient(
to right,
rgba(92, 107, 106, 0.14) 0,
rgba(92, 107, 106, 0.14) 1px,
transparent 1px,
transparent 5.5555%
),
repeating-linear-gradient(
to right,
transparent 0,
transparent 2.7777%,
rgba(92, 107, 106, 0.07) 2.7777%,
rgba(92, 107, 106, 0.07) calc(2.7777% + 1px)
);
cursor: crosshair;
touch-action: none;
}
.off-hours {
position: absolute;
z-index: 1;
top: 0;
bottom: 0;
background:
repeating-linear-gradient(
135deg,
rgba(61, 75, 77, 0.17) 0,
rgba(61, 75, 77, 0.17) 5px,
rgba(61, 75, 77, 0.08) 5px,
rgba(61, 75, 77, 0.08) 10px
);
pointer-events: none;
}
.closure-block {
position: absolute;
z-index: 2;
top: 0;
bottom: 0;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
color: #783d2c;
border-left: 1px solid #cf7450;
border-right: 1px solid #cf7450;
background:
repeating-linear-gradient(
135deg,
rgba(222, 103, 61, 0.42) 0,
rgba(222, 103, 61, 0.42) 7px,
rgba(255, 226, 205, 0.68) 7px,
rgba(255, 226, 205, 0.68) 14px
);
font: 800 9px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.06em;
pointer-events: none;
}
.booking-block,
.request-block {
position: absolute;
z-index: 3;
left: 0;
display: flex;
align-items: center;
min-width: 3px;
overflow: hidden;
padding: 0 6px;
border: 1px solid rgba(20, 43, 45, 0.32);
border-radius: 3px;
color: #15332f;
box-shadow: 0 3px 7px rgba(22, 35, 36, 0.15);
font: 800 9px ui-monospace, SFMono-Regular, Menlo, monospace;
text-overflow: ellipsis;
white-space: nowrap;
}
.booking-block {
top: 20px;
height: 32px;
}
.booking-block:hover,
.request-block:hover {
filter: brightness(1.05);
box-shadow: 0 5px 11px rgba(22, 35, 36, 0.2);
}
.request-block {
z-index: 5;
top: 5px;
height: 19px;
color: #7c1f2c;
border-color: #a92e3d;
background:
repeating-linear-gradient(
135deg,
rgba(189, 63, 77, 0.22) 0,
rgba(189, 63, 77, 0.22) 5px,
rgba(255, 255, 255, 0.36) 5px,
rgba(255, 255, 255, 0.36) 10px
),
#f5c7cc;
}
.drag-preview {
position: absolute;
z-index: 8;
top: 3px;
height: 54px;
border: 2px dashed var(--green);
border-radius: 4px;
color: var(--green);
background: rgba(71, 201, 160, 0.17);
font: 800 9px ui-monospace, SFMono-Regular, Menlo, monospace;
pointer-events: none;
}
.ruler {
display: flex;
justify-content: space-between;
margin-top: 5px;
color: #7b8583;
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin-top: 11px;
color: var(--muted);
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 5px;
}
.legend-swatch {
width: 13px;
height: 9px;
border-radius: 2px;
border: 1px solid rgba(40, 57, 58, 0.2);
}
.inspector {
min-height: 126px;
}
.empty-inspector {
display: grid;
min-height: 96px;
place-items: center;
padding: 12px;
border: 1px dashed #c8c0b1;
border-radius: 5px;
color: var(--muted);
text-align: center;
font-size: 11px;
line-height: 1.5;
}
.detail-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.detail-top h3 {
margin: 0;
font-size: 15px;
}
.detail-top p {
margin: 4px 0 0;
color: var(--muted);
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.status-pill {
padding: 5px 7px;
border-radius: 3px;
color: #145e50;
background: #d4eee4;
font: 800 9px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.status-pill.rejected {
color: #8a2331;
background: #f5d3d7;
}
.reason-box {
margin-top: 11px;
padding: 10px;
border-left: 4px solid var(--green);
color: #455a59;
background: #e8eee8;
font-size: 12px;
line-height: 1.5;
}
.reason-box.rejected {
border-left-color: var(--red);
color: #783740;
background: var(--red-soft);
}
.detail-actions {
display: flex;
justify-content: flex-end;
margin-top: 10px;
}
.danger-button {
padding: 7px 9px;
border: 1px solid #d5a3aa;
border-radius: 3px;
color: #8a2634;
background: #fff1f2;
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
font-weight: 800;
}
.request-log {
max-height: 210px;
overflow-y: auto;
scrollbar-width: thin;
}
.log-list {
display: grid;
gap: 5px;
}
.log-row {
display: grid;
grid-template-columns: 9px minmax(0, 1fr) auto;
gap: 8px;
align-items: center;
width: 100%;
padding: 8px;
border: 1px solid #ddd6c7;
border-radius: 4px;
color: var(--ink);
background: #fbf8f0;
text-align: left;
}
.log-row:hover,
.log-row.selected {
border-color: #aebbb3;
background: #fffdf6;
}
.log-dot {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--green);
}
.log-dot.rejected {
background: var(--red);
}
.log-copy {
min-width: 0;
}
.log-copy b,
.log-copy small {
display: block;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.log-copy b {
font-size: 11px;
}
.log-copy small {
margin-top: 2px;
color: var(--muted);
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.log-time {
color: #6d7a78;
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.toast {
position: fixed;
z-index: 100;
bottom: 22px;
left: 50%;
max-width: min(520px, calc(100vw - 32px));
padding: 11px 15px;
border: 1px solid #8db9ad;
border-radius: 5px;
color: #174f45;
background: #effaf5;
box-shadow: 0 12px 32px rgba(25, 47, 46, 0.2);
font: 11px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
font-weight: 800;
opacity: 0;
pointer-events: none;
transform: translate(-50%, 12px);
transition: opacity 170ms ease, transform 170ms ease;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
.toast.rejected {
border-color: #d99ba3;
color: #812837;
background: #fff0f2;
}
@media (max-width: 980px) {
.app {
height: auto;
min-height: 100vh;
overflow: visible;
}
.workspace {
grid-template-columns: 1fr;
}
.scene-card {
height: 62vh;
min-height: 490px;
}
.schedule-panel {
overflow: visible;
}
}
@media (max-width: 640px) {
.app {
grid-template-rows: auto auto;
}
.topbar {
align-items: flex-start;
flex-direction: column;
gap: 10px;
padding: 13px;
}
.header-meta {
justify-content: flex-start;
}
.workspace {
padding: 7px;
}
.scene-card {
height: 56vh;
min-height: 410px;
}
.scene-top {
flex-direction: column;
}
.scene-title {
max-width: none;
}
.scene-actions {
align-self: flex-end;
}
.scene-bottom {
align-items: stretch;
flex-direction: column;
}
.control-grid {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<h1>Block & Bench</h1>
<p>Community workshop · reservation desk</p>
</div>
</div>
<div class="header-meta">
<span class="header-chip"><span class="live-dot"></span> Schedule live</span>
<span class="header-chip">Fixed floor plan</span>
<span class="header-chip">Today · 09:00–18:00</span>
</div>
</header>
<main class="workspace">
<section class="scene-card" aria-label="Interactive voxel workshop scene">
<div id="viewport"></div>
<div class="scene-top">
<div class="scene-title">
<p class="eyebrow">Workshop overview</p>
<h2>A small place for big projects</h2>
<p>
Select a station in the room or on the timetable.
Accepted reservations light up the matching physical station.
</p>
</div>
<div class="scene-actions">
<button id="resetView" class="small-button" type="button">Reset view</button>
</div>
</div>
<div id="stationLabels" class="scene-labels"></div>
<div class="scene-bottom">
<div class="scene-help">
Drag to orbit · Scroll to zoom · Click a station to select
</div>
<div id="sceneSelection" class="scene-selection">Selected: Shared workbench</div>
</div>
</section>
<aside class="schedule-panel" aria-label="Workshop reservation schedule">
<section class="panel-card">
<div class="panel-heading">
<div>
<p class="eyebrow">Reservation desk</p>
<h3>Place a booking</h3>
<p>The room stays fixed; only the timetable changes.</p>
</div>
<button id="resetSchedule" class="ghost-button" type="button">Reset</button>
</div>
<div class="control-grid">
<label>
<span class="field-label">Booking length</span>
<select id="duration">
<option value="30">30 minutes</option>
<option value="60" selected>60 minutes</option>
<option value="90">90 minutes</option>
<option value="120">120 minutes</option>
</select>
</label>
<div>
<span class="field-label">Selected station</span>
<strong id="selectedStationName">Shared workbench</strong>
</div>
</div>
<p class="interaction-note">
<strong>Click</strong> a timeline to place a booking using the selected length.
<strong>Drag</strong> across a timeline to choose a custom range.
Times snap to 15-minute increments.
</p>
<div class="demo-row" aria-label="Example rejection buttons">
<button class="demo-button" type="button" data-demo="overlap">Try overlap</button>
<button class="demo-button" type="button" data-demo="closure">Try closure</button>
<button class="demo-button" type="button" data-demo="insufficient">Try insufficient time</button>
</div>
</section>
<section class="panel-card">
<div class="panel-heading">
<div>
<p class="eyebrow">Station availability</p>
<h3>Daily timetables</h3>
<p>Click any accepted or rejected block to inspect its decision.</p>
</div>
</div>
<div id="timelines" class="timeline-list"></div>
<div class="legend">
<span class="legend-item">
<span class="legend-swatch" style="background:#54c9a8"></span> Accepted
</span>
<span class="legend-item">
<span class="legend-swatch" style="background:#f1c3c8"></span> Rejected
</span>
<span class="legend-item">
<span class="legend-swatch" style="background:#efb08f"></span> Maintenance
</span>
</div>
</section>
<section id="inspector" class="panel-card inspector" aria-live="polite"></section>
<section class="panel-card">
<div class="panel-heading">
<div>
<p class="eyebrow">Request history</p>
<h3>Decision log</h3>
</div>
</div>
<div id="requestLog" class="request-log"></div>
</section>
</aside>
</main>
</div>
<div id="toast" class="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";
/* ------------------------------------------------------------------
Schedule data
------------------------------------------------------------------ */
const DAY_START = 9 * 60;
const DAY_END = 18 * 60;
const DAY_SPAN = DAY_END - DAY_START;
const STATION_KEYS = ["bench", "drill", "storage"];
const stations = [
{
id: "bench",
name: "Shared workbench",
short: "Workbench",
index: "01",
open: 9 * 60,
close: 17 * 60,
closure: { start: 12 * 60, end: 13 * 60 },
color: 0xf0b247,
css: "#e4a536",
anchor: new THREE.Vector3(0, 4.25, 0.1),
pip: [2.65, 0.12, 1.18]
},
{
id: "drill",
name: "Drill station",
short: "Drill station",
index: "02",
open: 9 * 60,
close: 16 * 60,
closure: { start: 10 * 60, end: 11 * 60 },
color: 0x48bda3,
css: "#3aa98f",
anchor: new THREE.Vector3(-5.2, 4.35, -3.25),
pip: [1.55, 0.12, 1.0]
},
{
id: "storage",
name: "Storage wall",
short: "Storage wall",
index: "03",
open: 10 * 60,
close: 18 * 60,
closure: { start: 14 * 60 + 30, end: 15 * 60 + 30 },
color: 0x8267bd,
css: "#7557af",
anchor: new THREE.Vector3(5.1, 4.75, -5.35),
pip: [2.32, 0.12, 0.94]
}
];
const stationById = Object.fromEntries(stations.map((station) => [station.id, station]));
const seedBookings = [
{
id: "booking-seed-1",
stationId: "bench",
start: 9 * 60,
end: 10 * 60,
title: "Morning repair",
locked: true
},
{
id: "booking-seed-2",
stationId: "bench",
start: 14 * 60,
end: 15 * 60,
title: "Ceramics group",
locked: true
},
{
id: "booking-seed-3",
stationId: "drill",
start: 11 * 60 + 30,
end: 12 * 60 + 30,
title: "Bike maintenance",
locked: true
},
{
id: "booking-seed-4",
stationId: "storage",
start: 15 * 60 + 30,
end: 16 * 60 + 30,
title: "Material pickup",
locked: true
}
];
let bookings = seedBookings.map((booking) => ({ ...booking }));
let rejectedRequests = [];
let requestLog = seedBookings.map((booking) => ({
id: `log-${booking.id}`,
stationId: booking.stationId,
start: booking.start,
end: booking.end,
status: "accepted",
title: booking.title,
reason: "Community booking confirmed.",
detailType: "booking",
detailId: booking.id
}));
let selectedStationId = "bench";
let selectedDetail = null;
let dragState = null;
let toastTimer = null;
let sequence = 100;
const highlightUntil = new Map();
const viewport = document.querySelector("#viewport");
const timelinesElement = document.querySelector("#timelines");
const inspectorElement = document.querySelector("#inspector");
const requestLogElement = document.querySelector("#requestLog");
const selectedStationName = document.querySelector("#selectedStationName");
const sceneSelection = document.querySelector("#sceneSelection");
const durationSelect = document.querySelector("#duration");
const stationLabelsElement = document.querySelector("#stationLabels");
const toastElement = document.querySelector("#toast");
function formatTime(minutes) {
const normalized = ((Math.round(minutes) % 1440) + 1440) % 1440;
const hours = Math.floor(normalized / 60);
const mins = normalized % 60;
return `${String(hours).padStart(2, "0")}:${String(mins).padStart(2, "0")}`;
}
function formatRange(start, end) {
return `${formatTime(start)}–${formatTime(end)}`;
}
function formatDuration(minutes) {
return `${minutes} minute${minutes === 1 ? "" : "s"}`;
}
function percent(minutes) {
return ((minutes - DAY_START) / DAY_SPAN) * 100;
}
function escapeHTML(value) {
return String(value)
.replaceAll("&", "&")
.replaceAll("<", "<")
.replaceAll(">", ">")
.replaceAll('"', """)
.replaceAll("'", "'");
}
function showToast(message, rejected = false) {
window.clearTimeout(toastTimer);
toastElement.textContent = message;
toastElement.classList.toggle("rejected", rejected);
toastElement.classList.add("show");
toastTimer = window.setTimeout(() => {
toastElement.classList.remove("show");
}, 4200);
}
/* ------------------------------------------------------------------
Three.js scene
------------------------------------------------------------------ */
let renderer;
let scene;
let camera;
let cameraTarget = new THREE.Vector3(0, 1.45, -0.45);
let cameraYaw = 0.69;
let cameraPitch = 0.78;
let cameraZoom = 1;
let orbitPointer = null;
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const stationObjects = {};
const stationSigns = {};
const labelElements = {};
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.84,
metalness: options.metalness ?? 0,
flatShading: true,
...options
});
}
function block(parent, size, color, position, options = {}) {
const geometry = new THREE.BoxGeometry(size[0], size[1], size[2]);
const mat = options.material || material(color, options);
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function buildRenderer() {
renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
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.05;
viewport.appendChild(renderer.domElement);
scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8e3dd);
scene.fog = new THREE.Fog(0xd8e3dd, 29, 54);
camera = new THREE.OrthographicCamera(-10, 10, 8, -8, 0.1, 100);
const hemisphere = new THREE.HemisphereLight(0xfff8e9, 0x526a70, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0d6, 3.2);
sun.position.set(-8, 17, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -16;
sun.shadow.camera.right = 16;
sun.shadow.camera.top = 16;
sun.shadow.camera.bottom = -16;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.0005;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d9df, 0.8);
fill.position.set(11, 8, -8);
scene.add(fill);
}
function buildFloor() {
const floorMaterials = [
material(0xded8c8),
material(0xe8e1d2),
material(0xd4d3c6),
material(0xdcd9cb)
];
block(scene, [18.5, 0.42, 13.5], 0x8d9990, [0, -0.28, 0], {
castShadow: false
});
for (let x = 0; x < 18; x++) {
for (let z = 0; z < 13; z++) {
const value = Math.abs(Math.sin(x * 12.9898 + z * 78.233) * 43758.5453) % 1;
const tileMaterial = floorMaterials[Math.floor(value * floorMaterials.length)];
block(
scene,
[0.965, 0.1, 0.965],
0xffffff,
[-8.5 + x, -0.03, -6 + z],
{ material: tileMaterial, castShadow: false }
);
}
}
}
function buildWalls() {
const wallColors = [0xe8e2d4, 0xdfd9ca, 0xeee7d8];
for (let x = 0; x < 18; x++) {
for (let y = 0; y < 5; y++) {
const color = wallColors[(x + y * 2) % wallColors.length];
block(
scene,
[0.96, 0.96, 0.38],
color,
[-8.5 + x, 0.5 + y, -6.62],
{ roughness: 0.95 }
);
}
}
for (let z = 0; z < 13; z++) {
for (let y = 0; y < 5; y++) {
const color = wallColors[(z + y) % wallColors.length];
block(
scene,
[0.38, 0.96, 0.96],
color,
[-9.18, 0.5 + y, -6 + z],
{ roughness: 0.95 }
);
}
}
// Window.
block(scene, [4.25, 0.25, 0.2], 0x4b5e60, [0.3, 3.65, -6.36]);
block(scene, [0.24, 2.5, 0.2], 0x4b5e60, [0.3, 2.45, -6.36]);
block(scene, [4, 2.35, 0.08], 0x87b8c1, [0.3, 2.45, -6.48], {
roughness: 0.35
});
block(scene, [0.13, 2.35, 0.1], 0x4b5e60, [0.3, 2.45, -6.38]);
block(scene, [4, 0.13, 0.1], 0x4b5e60, [0.3, 2.45, -6.38]);
block(scene, [4.65, 0.2, 0.55], 0xb78b62, [0.3, 1.16, -6.25]);
// A small pegboard and shelf on the back wall.
block(scene, [3.6, 2.1, 0.15], 0xb48b62, [-5.6, 3.0, -6.34]);
for (let i = 0; i < 7; i++) {
block(scene, [0.13, 0.72, 0.13], 0x54696d, [-7.05 + i * 0.48, 3.15, -6.18]);
block(scene, [0.29, 0.25, 0.14], i % 2 ? 0xdda85d : 0x5ca58e, [-7.05 + i * 0.48, 3.66, -6.18]);
}
}
function registerStation(id, group, width, depth) {
group.userData.stationId = id;
scene.add(group);
const halo = new THREE.Mesh(
new THREE.PlaneGeometry(width, depth),
new THREE.MeshBasicMaterial({
color: stationById[id].color,
transparent: true,
opacity: 0.16,
depthWrite: false,
side: THREE.DoubleSide
})
);
halo.rotation.x = -Math.PI / 2;
halo.position.y = 0.035;
halo.renderOrder = 2;
group.add(halo);
const pips = new THREE.Group();
group.add(pips);
stationObjects[id] = {
group,
halo,
pips,
materials: []
};
return group;
}
function buildWorkbench() {
const group = new THREE.Group();
group.position.set(0, 0, 0.2);
registerStation("bench", group, 6.35, 3.6);
// Lower shelf.
block(group, [4.65, 0.22, 1.65], 0xa86f45, [0, 0.73, 0]);
// Legs.
for (const x of [-2.15, 2.15]) {
for (const z of [-0.82, 0.82]) {
block(group, [0.34, 2.0, 0.34], 0x546469, [x, 1.05, z]);
}
}
// Top and edge.
block(group, [5.45, 0.42, 2.35], 0xc78950, [0, 2.22, 0]);
block(group, [5.55, 0.14, 2.45], 0xe0aa68, [0, 2.47, 0]);
// Bench vise.
block(group, [0.82, 0.38, 0.55], 0x425d63, [1.65, 2.65, -0.05]);
block(group, [0.36, 0.52, 0.74], 0x536e73, [1.43, 2.73, -0.05]);
block(group, [0.13, 0.62, 0.13], 0xc9d0ca, [1.92, 2.65, -0.05]);
// Project pieces.
block(group, [1.15, 0.22, 0.55], 0xe1c75c, [-1.55, 2.69, 0.2], {
rotation: 0
});
block(group, [0.75, 0.45, 0.75], 0x699b91, [-0.15, 2.73, -0.35]);
block(group, [0.62, 0.15, 0.42], 0xe57852, [0.35, 2.65, 0.4]);
// Lower-shelf boxes.
block(group, [1.05, 0.55, 0.8], 0x5b8c83, [-1.4, 1.12, 0]);
block(group, [0.85, 0.65, 0.72], 0xd19b51, [1.1, 1.16, 0.05]);
// A stool.
block(group, [0.78, 0.18, 0.78], 0x9c6446, [-1.75, 1.12, 1.45]);
for (const x of [-2.02, -1.48]) {
for (const z of [1.2, 1.7]) {
block(group, [0.12, 1.0, 0.12], 0x53676b, [x, 0.54, z]);
}
}
}
function buildDrillStation() {
const group = new THREE.Group();
group.position.set(-5.2, 0, -3.25);
registerStation("drill", group, 4.55, 3.5);
// Cabinet and feet.
block(group, [2.6, 1.35, 1.75], 0x497a74, [0, 0.88, 0]);
block(group, [2.72, 0.18, 1.86], 0x355d5a, [0, 1.62, 0]);
for (const x of [-0.95, 0.95]) {
block(group, [0.28, 0.28, 1.45], 0x33494d, [x, 0.17, 0]);
}
// Drawer details.
for (let i = 0; i < 3; i++) {
block(group, [2.25, 0.27, 0.08], 0x74a49a, [0, 0.46 + i * 0.38, 0.92]);
block(group, [0.62, 0.08, 0.12], 0xd7d0bd, [0, 0.46 + i * 0.38, 0.99]);
}
// Drill press.
block(group, [2.25, 0.26, 1.5], 0x3b5157, [0.2, 1.83, 0]);
block(group, [0.38, 3.25, 0.48], 0x596e72, [-0.65, 2.43, -0.48]);
block(group, [1.28, 0.38, 0.64], 0x5b7074, [0, 3.83, -0.34]);
block(group, [0.7, 0.72, 0.66], 0xd99d42, [0.15, 3.4, 0.08]);
block(group, [0.42, 0.35, 0.42], 0x33464b, [0.15, 2.88, 0.08]);
block(group, [0.1, 0.72, 0.1], 0xcbd2ce, [0.15, 2.35, 0.08]);
block(group, [0.12, 0.1, 0.95], 0x4a5b5d, [0.15, 3.1, 0.45]);
// Safety and controls.
block(group, [0.2, 0.2, 0.13], 0xbf3f43, [-0.72, 3.4, -0.03]);
block(group, [0.46, 0.12, 0.12], 0x232f32, [0.87, 3.38, 0.06]);
// Tool tray.
block(group, [1.2, 0.18, 0.55], 0xd7a25a, [1.3, 1.92, 0.4]);
block(group, [0.12, 0.55, 0.12], 0xcbd2ca, [1.15, 2.18, 0.4]);
block(group, [0.15, 0.4, 0.15], 0x527d78, [1.47, 2.12, 0.4]);
}
function buildStorageWall() {
const group = new THREE.Group();
group.position.set(5.1, 0, -5.35);
registerStation("storage", group, 5.6, 2.75);
// Shelf frame.
for (const x of [-2.35, 2.35]) {
block(group, [0.22, 4.25, 0.25], 0x5e6263, [x, 2.15, 0]);
}
const shelfColors = [0x6c716e, 0x77726a, 0x666d69];
for (let i = 0; i < 4; i++) {
block(group, [4.95, 0.2, 1.35], shelfColors[i % 3], [0, 0.42 + i * 1.12, 0]);
}
// Colorful storage bins.
const binColors = [0xd9954f, 0x5e9e8e, 0x7285ac, 0xc76856, 0xb49b62];
for (let row = 0; row < 3; row++) {
for (let col = 0; col < 4; col++) {
const x = -1.75 + col * 1.15;
const y = 0.84 + row * 1.12;
const color = binColors[(row + col) % binColors.length];
block(group, [0.86, 0.63, 0.93], color, [x, y, 0]);
block(group, [0.32, 0.12, 0.08], 0xf1e8d5, [x, y + 0.05, 0.52]);
block(group, [0.12, 0.12, 0.11], 0x3e4b4e, [x, y + 0.14, 0.58]);
}
}
// Long timber and tools.
block(group, [3.9, 0.18, 0.2], 0xc89861, [0, 4.02, 0.34]);
for (let i = 0; i < 4; i++) {
block(group, [0.12, 0.72, 0.13], 0x536b6d, [-1.45 + i * 0.55, 3.62, 0.37]);
}
// Reserve shelf labels.
block(group, [0.75, 0.32, 0.08], 0xf2e6c9, [-1.2, 1.67, 0.75]);
block(group, [0.75, 0.32, 0.08], 0xf2e6c9, [1.1, 2.79, 0.75]);
}
function makePlate(parent, width, height, position) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 192;
const context = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({ map: texture })
);
mesh.position.set(position[0], position[1], position[2]);
parent.add(mesh);
return { canvas, context, texture, mesh };
}
function drawStationSign(station) {
const plate = stationSigns[station.id];
if (!plate) return;
const { context: ctx, texture } = plate;
const stationBookings = bookings
.filter((booking) => booking.stationId === station.id)
.sort((a, b) => a.start - b.start);
ctx.clearRect(0, 0, 512, 192);
ctx.fillStyle = "#f7f1df";
ctx.fillRect(0, 0, 512, 192);
ctx.fillStyle = station.css;
ctx.fillRect(0, 0, 18, 192);
ctx.fillStyle = "#1b3033";
ctx.font = "800 30px monospace";
ctx.fillText(station.short.toUpperCase(), 38, 43);
ctx.fillStyle = "#536669";
ctx.font = "700 22px monospace";
const nextText = stationBookings.length
? `NEXT ${formatTime(stationBookings[0].start)} · ${stationBookings.length} BOOKING${stationBookings.length === 1 ? "" : "S"}`
: "NO BOOKINGS · OPEN TODAY";
ctx.fillText(nextText, 38, 89);
ctx.fillStyle = "#a95035";
ctx.font = "800 21px monospace";
ctx.fillText(
`MAINT ${formatTime(station.closure.start)}-${formatTime(station.closure.end)}`,
38,
142
);
ctx.fillStyle = "#c5bda9";
ctx.fillRect(38, 163, 430, 3);
texture.needsUpdate = true;
}
function buildSigns() {
stationSigns.bench = makePlate(
stationObjects.bench.group,
4.15,
1.25,
[0, 3.6, -1.28]
);
stationSigns.drill = makePlate(
stationObjects.drill.group,
3.55,
1.1,
[-0.1, 4.35, -0.92]
);
stationSigns.storage = makePlate(
stationObjects.storage.group,
4.45,
1.3,
[0, 4.65, 0.79]
);
stations.forEach(drawStationSign);
}
function buildNoticeboardAndEntrance() {
// Small noticeboard beside the entrance.
const board = new THREE.Group();
board.position.set(4.7, 0, 5.45);
scene.add(board);
for (const x of [-0.75, 0.75]) {
block(board, [0.16, 2.2, 0.16], 0x59676a, [x, 1.1, 0]);
block(board, [0.55, 0.12, 0.75], 0x455659, [x, 0.08, 0]);
}
block(board, [2.15, 1.55, 0.2], 0x9c744f, [0, 2.15, 0]);
block(board, [1.93, 1.34, 0.08], 0xc7aa7b, [0, 2.15, 0.14]);
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 384;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#c7aa7b";
ctx.fillRect(0, 0, 512, 384);
ctx.fillStyle = "#263c3f";
ctx.font = "800 34px monospace";
ctx.fillText("COMMUNITY BOARD", 30, 54);
const notes = [
{ x: 35, y: 88, color: "#e6bf64", text: "SHARE TOOLS" },
{ x: 275, y: 88, color: "#df9a72", text: "CLEAN UP" },
{ x: 35, y: 224, color: "#70ad98", text: "NEW MEMBERS" }
];
notes.forEach((note) => {
ctx.fillStyle = note.color;
ctx.fillRect(note.x, note.y, 195, 105);
ctx.fillStyle = "rgba(38,60,63,0.25)";
for (let line = 0; line < 4; line++) {
ctx.fillRect(note.x + 16, note.y + 31 + line * 15, 155 - line * 18, 4);
}
ctx.fillStyle = "#263c3f";
ctx.font = "800 15px monospace";
ctx.fillText(note.text, note.x + 13, note.y + 22);
});
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const notice = new THREE.Mesh(
new THREE.PlaneGeometry(1.87, 1.28),
new THREE.MeshBasicMaterial({ map: texture })
);
notice.position.set(0, 2.15, 0.19);
board.add(notice);
// Entrance portal.
const entrance = new THREE.Group();
entrance.position.set(7.25, 0, 6.12);
scene.add(entrance);
block(entrance, [0.32, 3.25, 0.38], 0x526c6e, [-0.85, 1.62, 0]);
block(entrance, [0.32, 3.25, 0.38], 0x526c6e, [0.85, 1.62, 0]);
block(entrance, [2.1, 0.34, 0.42], 0xe1a64d, [0, 3.2, 0]);
block(entrance, [1.55, 0.42, 0.12], 0xf1e7ce, [0, 2.84, 0.24]);
block(entrance, [0.17, 0.58, 0.1], 0x667d7d, [0, 2.84, 0.32]);
block(entrance, [0.17, 0.58, 0.1], 0x667d7d, [0, 2.84, 0.32]);
// Threshold mat.
block(entrance, [1.65, 0.06, 0.8], 0x607574, [0, 0.05, -0.6], {
castShadow: false
});
}
function addVoxelPerson(x, z, shirtColor, hairColor, rotation = 0) {
const person = new THREE.Group();
person.position.set(x, 0, z);
person.rotation.y = rotation;
scene.add(person);
// Shoes and trousers.
block(person, [0.35, 0.18, 0.58], 0x34464a, [-0.25, 0.12, 0.03]);
block(person, [0.35, 0.18, 0.58], 0x34464a, [0.25, 0.12, -0.04]);
block(person, [0.34, 0.8, 0.36], 0x3d5961, [-0.25, 0.57, 0]);
block(person, [0.34, 0.8, 0.36], 0x3d5961, [0.25, 0.57, 0]);
// Torso and arms.
block(person, [0.92, 0.9, 0.46], shirtColor, [0, 1.42, 0]);
block(person, [0.26, 0.83, 0.3], shirtColor, [-0.62, 1.38, 0]);
block(person, [0.26, 0.83, 0.3], shirtColor, [0.62, 1.38, 0]);
block(person, [0.24, 0.22, 0.26], 0xd5a078, [-0.62, 0.92, 0]);
block(person, [0.24, 0.22, 0.26], 0xd5a078, [0.62, 0.92, 0]);
// Head and hair.
block(person, [0.65, 0.65, 0.62], 0xd6a27e, [0, 2.2, 0]);
block(person, [0.71, 0.2, 0.66], hairColor, [0, 2.54, -0.01]);
block(person, [0.2, 0.37, 0.64], hairColor, [-0.26, 2.28, 0]);
block(person, [0.2, 0.37, 0.64], hairColor, [0.26, 2.28, 0]);
}
function buildDecor() {
addVoxelPerson(2.65, 1.85, 0xc57b55, 0x4a3933, -0.65);
addVoxelPerson(-6.75, -1.8, 0x507f91, 0x6a4937, 0.8);
// Toolbox.
block(scene, [0.85, 0.48, 0.55], 0xb95f4f, [-3.0, 0.27, 3.35]);
block(scene, [0.42, 0.08, 0.12], 0xe0c6a1, [-3.0, 0.55, 3.35]);
block(scene, [0.08, 0.22, 0.08], 0x394b4d, [-3.0, 0.65, 3.35]);
// Voxel plant.
const plant = new THREE.Group();
plant.position.set(8.1, 0, -5.35);
scene.add(plant);
block(plant, [0.72, 0.72, 0.72], 0xc27a52, [0, 0.38, 0]);
block(plant, [0.13, 1.35, 0.13], 0x47735c, [0, 1.2, 0]);
block(plant, [0.85, 0.42, 0.5], 0x5b966d, [0, 1.55, 0]);
block(plant, [0.55, 0.48, 0.75], 0x73a87a, [0, 1.95, 0]);
block(plant, [0.9, 0.35, 0.45], 0x477f5f, [0, 2.25, 0]);
}
function buildStationLabels() {
stationLabelsElement.innerHTML = stations
.map(
(station) => `
<button
class="station-label"
type="button"
data-station="${station.id}"
style="--label-color:${station.css}"
>
<span class="label-dot"></span>
<span>
<b>${escapeHTML(station.short)}</b>
<small data-label-info="${station.id}"></small>
</span>
</button>
`
)
.join("");
stations.forEach((station) => {
const element = stationLabelsElement.querySelector(`[data-station="${station.id}"]`);
labelElements[station.id] = element;
element.addEventListener("click", (event) => {
event.stopPropagation();
selectStation(station.id, true);
});
});
updateLabelStates();
}
function updateLabelStates() {
stations.forEach((station) => {
const element = labelElements[station.id];
if (!element) return;
element.classList.toggle("selected", station.id === selectedStationId);
const count = bookings.filter((booking) => booking.stationId === station.id).length;
const info = element.querySelector("[data-label-info]");
info.textContent = `${formatTime(station.open)}–${formatTime(station.close)} · ${count} booking${count === 1 ? "" : "s"}`;
});
}
function finalizeStationMaterials() {
stations.forEach((station) => {
const object = stationObjects[station.id];
object.group.traverse((child) => {
if (child.isMesh && child.material?.isMeshStandardMaterial) {
object.materials.push(child.material);
}
});
});
}
function updateStationPips() {
stations.forEach((station) => {
const object = stationObjects[station.id];
const pips = object.pips;
while (pips.children.length) {
const child = pips.children[0];
pips.remove(child);
child.geometry?.dispose();
if (Array.isArray(child.material)) {
child.material.forEach((mat) => mat.dispose());
} else {
child.material?.dispose();
}
}
const stationBookings = bookings
.filter((booking) => booking.stationId === station.id)
.sort((a, b) => a.start - b.start)
.slice(0, 6);
stationBookings.forEach((booking, index) => {
block(
pips,
[0.16, 0.16, 0.16],
station.color,
[
station.pip[0] + index * 0.23,
station.pip[1],
station.pip[2]
],
{ castShadow: false }
);
});
});
}
function updateStationVisuals(now) {
stations.forEach((station) => {
const object = stationObjects[station.id];
const selected = station.id === selectedStationId;
const recent = (highlightUntil.get(station.id) || 0) > now;
object.materials.forEach((mat) => {
mat.emissive.setHex(selected || recent ? station.color : 0x000000);
mat.emissiveIntensity = recent ? 0.27 : selected ? 0.075 : 0;
});
object.halo.visible = selected || recent;
object.halo.material.color.setHex(station.color);
object.halo.material.opacity = recent
? 0.16 + (Math.sin(now * 0.009) + 1) * 0.055
: 0.115;
});
}
function buildScene() {
buildRenderer();
buildFloor();
buildWalls();
buildWorkbench();
buildDrillStation();
buildStorageWall();
buildSigns();
buildNoticeboardAndEntrance();
buildDecor();
buildStationLabels();
finalizeStationMaterials();
updateStationPips();
renderer.domElement.addEventListener("pointerdown", onOrbitPointerDown);
renderer.domElement.addEventListener("pointermove", onOrbitPointerMove);
renderer.domElement.addEventListener("pointerup", onOrbitPointerUp);
renderer.domElement.addEventListener("pointercancel", onOrbitPointerUp);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * (event.deltaY > 0 ? 0.92 : 1.08),
0.72,
1.45
);
updateCamera();
},
{ passive: false }
);
document.querySelector("#resetView").addEventListener("click", resetCamera);
const resizeObserver = new ResizeObserver(resizeScene);
resizeObserver.observe(viewport);
resizeScene();
}
function updateCamera() {
const aspect = Math.max(viewport.clientWidth / Math.max(viewport.clientHeight, 1), 0.2);
let frustumHeight = 14.7 / cameraZoom;
if (frustumHeight * aspect < 21.5) {
frustumHeight = 21.5 / aspect;
}
camera.left = (-frustumHeight * aspect) / 2;
camera.right = (frustumHeight * aspect) / 2;
camera.top = frustumHeight / 2;
camera.bottom = -frustumHeight / 2;
const radius = 27;
camera.position.set(
cameraTarget.x + radius * Math.sin(cameraPitch) * Math.sin(cameraYaw),
cameraTarget.y + radius * Math.cos(cameraPitch),
cameraTarget.z + radius * Math.sin(cameraPitch) * Math.cos(cameraYaw)
);
camera.lookAt(cameraTarget);
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resizeScene() {
if (!renderer || !camera) return;
const width = Math.max(viewport.clientWidth, 1);
const height = Math.max(viewport.clientHeight, 1);
renderer.setSize(width, height, false);
updateCamera();
}
function resetCamera() {
cameraYaw = 0.69;
cameraPitch = 0.78;
cameraZoom = 1;
updateCamera();
}
function onOrbitPointerDown(event) {
if (event.button !== 0) return;
orbitPointer = {
id: event.pointerId,
startX: event.clientX,
startY: event.clientY,
lastX: event.clientX,
lastY: event.clientY,
moved: false
};
renderer.domElement.setPointerCapture(event.pointerId);
}
function onOrbitPointerMove(event) {
if (!orbitPointer || orbitPointer.id !== event.pointerId) return;
const totalDistance = Math.hypot(
event.clientX - orbitPointer.startX,
event.clientY - orbitPointer.startY
);
if (totalDistance > 5) orbitPointer.moved = true;
const deltaX = event.clientX - orbitPointer.lastX;
const deltaY = event.clientY - orbitPointer.lastY;
cameraYaw -= deltaX * 0.006;
cameraPitch = THREE.MathUtils.clamp(cameraPitch + deltaY * 0.005, 0.43, 1.13);
orbitPointer.lastX = event.clientX;
orbitPointer.lastY = event.clientY;
updateCamera();
}
function onOrbitPointerUp(event) {
if (!orbitPointer || orbitPointer.id !== event.pointerId) return;
if (!orbitPointer.moved) {
pickStation(event);
}
orbitPointer = null;
}
function pickStation(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;
raycaster.setFromCamera(pointer, camera);
const roots = stations.map((station) => stationObjects[station.id].group);
const hits = raycaster.intersectObjects(roots, true);
if (!hits.length) return;
let object = hits[0].object;
while (object && !object.userData.stationId) {
object = object.parent;
}
if (object?.userData.stationId) {
selectStation(object.userData.stationId, true);
}
}
function updateProjectedLabels() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
stations.forEach((station) => {
const element = labelElements[station.id];
if (!element) return;
const projected = station.anchor.clone().project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.opacity = projected.z > 1 ? "0" : "1";
});
}
/* ------------------------------------------------------------------
Reservation logic
------------------------------------------------------------------ */
function selectStation(stationId, refresh = true) {
if (!stationById[stationId]) return;
selectedStationId = stationId;
selectedStationName.textContent = stationById[stationId].name;
sceneSelection.textContent = `Selected: ${stationById[stationId].name}`;
updateLabelStates();
updateStationVisuals(performance.now());
if (refresh) {
renderTimelines();
renderInspector();
}
}
function validateRequest(station, start, end) {
if (
start < station.closure.end &&
end > station.closure.start
) {
return {
status: "rejected",
reason:
`Closed station — ${station.name} is under maintenance from ` +
`${formatTime(station.closure.start)} to ${formatTime(station.closure.end)}.`
};
}
const overlap = bookings.find(
(booking) =>
booking.stationId === station.id &&
start < booking.end &&
end > booking.start
);
if (overlap) {
return {
status: "rejected",
reason:
`Overlap — the request conflicts with “${overlap.title}” ` +
`(${formatRange(overlap.start, overlap.end)}).`
};
}
if (start < station.open || end > station.close) {
return {
status: "rejected",
reason:
`Insufficient available time — ${station.name} is open ` +
`${formatTime(station.open)}–${formatTime(station.close)}; ` +
`${formatDuration(end - start)} from ${formatTime(start)} would end ` +
`at ${formatTime(end)}.`
};
}
return {
status: "accepted",
reason:
`Available — ${formatDuration(end - start)} reserved from ` +
`${formatTime(start)} to ${formatTime(end)}.`
};
}
function placeRequest(stationId, start, end, source = "timeline") {
const station = stationById[stationId];
if (!station) return;
start = Math.round(start / 15) * 15;
end = Math.round(end / 15) * 15;
const decision = validateRequest(station, start, end);
const requestId = `request-${Date.now()}-${sequence++}`;
if (decision.status === "accepted") {
const booking = {
id: `booking-${Date.now()}-${sequence++}`,
stationId,
start,
end,
title: "Your booking",
locked: false
};
bookings.push(booking);
requestLog.unshift({
id: `log-${requestId}`,
stationId,
start,
end,
status: "accepted",
title: booking.title,
reason: decision.reason,
detailType: "booking",
detailId: booking.id
});
selectedDetail = { type: "booking", id: booking.id };
highlightUntil.set(stationId, performance.now() + 8000);
showToast(
`Accepted: ${station.name}, ${formatRange(start, end)}. The station is highlighted.`
);
} else {
const request = {
id: requestId,
stationId,
start,
end,
title: "Your request",
reason: decision.reason,
source
};
rejectedRequests.push(request);
requestLog.unshift({
id: `log-${requestId}`,
stationId,
start,
end,
status: "rejected",
title: request.title,
reason: decision.reason,
detailType: "request",
detailId: request.id
});
selectedDetail = { type: "request", id: request.id };
highlightUntil.set(stationId, performance.now() + 3500);
showToast(decision.reason, true);
}
selectStation(stationId, false);
renderAll();
}
function releaseBooking(bookingId) {
const booking = bookings.find((item) => item.id === bookingId);
if (!booking || booking.locked) return;
bookings = bookings.filter((item) => item.id !== bookingId);
selectedDetail = null;
showToast(`Released ${stationById[booking.stationId].name} at ${formatTime(booking.start)}.`);
renderAll();
}
function selectDetail(type, id) {
selectedDetail = { type, id };
if (type === "booking") {
const booking = bookings.find((item) => item.id === id);
if (booking) {
selectStation(booking.stationId, false);
highlightUntil.set(booking.stationId, performance.now() + 10000);
}
} else {
const request = rejectedRequests.find((item) => item.id === id);
if (request) {
selectStation(request.stationId, false);
highlightUntil.set(request.stationId, performance.now() + 5000);
}
}
renderInspector();
renderRequestLog();
}
/* ------------------------------------------------------------------
Timetable rendering
------------------------------------------------------------------ */
function renderTimelines() {
timelinesElement.innerHTML = stations
.map((station) => {
const stationBookings = bookings
.filter((booking) => booking.stationId === station.id)
.sort((a, b) => a.start - b.start);
const stationRequests = rejectedRequests
.filter((request) => request.stationId === station.id)
.sort((a, b) => a.start - b.start);
const bookingBlocks = stationBookings
.map((booking) => {
const left = percent(booking.start);
const width = percent(booking.end) - left;
return `
<button
class="booking-block"
type="button"
data-booking="${booking.id}"
style="left:${left}%;width:${width}%;background:${station.css}"
title="${escapeHTML(booking.title)} · ${formatRange(booking.start, booking.end)}"
>
${escapeHTML(booking.title)}
</button>
`;
})
.join("");
const requestBlocks = stationRequests
.map((request) => {
const left = percent(request.start);
const width = percent(request.end) - left;
return `
<button
class="request-block"
type="button"
data-request="${request.id}"
style="left:${left}%;width:${width}%"
title="${escapeHTML(request.reason)}"
>
REJECTED
</button>
`;
})
.join("");
const beforeOpen =
station.open > DAY_START
? `<div class="off-hours" style="left:0;width:${percent(station.open)}%"></div>`
: "";
const afterClose =
station.close < DAY_END
? `<div class="off-hours" style="left:${percent(station.close)}%;right:0"></div>`
: "";
const closureLeft = percent(station.closure.start);
const closureWidth = percent(station.closure.end) - closureLeft;
return `
<article
class="timeline-card ${station.id === selectedStationId ? "selected" : ""}"
style="--station-color:${station.css}"
>
<div class="timeline-head">
<button class="station-select" type="button" data-select-station="${station.id}">
<span class="station-index">${station.index}</span>
<span>
<b>${escapeHTML(station.name)}</b>
<small>Open ${formatTime(station.open)}–${formatTime(station.close)}</small>
</span>
</button>
<span class="maintenance-chip">
MAINT ${formatTime(station.closure.start)}–${formatTime(station.closure.end)}
</span>
</div>
<div class="timeline-wrap">
<div class="timeline-track" data-track="${station.id}">
${beforeOpen}
${afterClose}
<div
class="closure-block"
style="left:${closureLeft}%;width:${closureWidth}%"
title="Maintenance closure"
>
CLOSED
</div>
${bookingBlocks}
${requestBlocks}
</div>
<div class="ruler">
${["09", "10", "11", "12", "13", "14", "15", "16", "17", "18"]
.map((hour) => `<span>${hour}</span>`)
.join("")}
</div>
</div>
</article>
`;
})
.join("");
timelinesElement.querySelectorAll("[data-select-station]").forEach((button) => {
button.addEventListener("click", () => {
selectStation(button.dataset.selectStation, true);
});
});
timelinesElement.querySelectorAll("[data-booking]").forEach((button) => {
button.addEventListener("click", (event) => {
event.stopPropagation();
selectDetail("booking", button.dataset.booking);
});
});
timelinesElement.querySelectorAll("[data-request]").forEach((button) => {
button.addEventListener("click", (event) => {
event.stopPropagation();
selectDetail("request", button.dataset.request);
});
});
timelinesElement.querySelectorAll("[data-track]").forEach((track) => {
track.addEventListener("pointerdown", onTimelinePointerDown);
track.addEventListener("pointermove", onTimelinePointerMove);
track.addEventListener("pointerup", onTimelinePointerUp);
track.addEventListener("pointercancel", onTimelinePointerUp);
});
}
function timelineMinuteAt(track, clientX) {
const rect = track.getBoundingClientRect();
const ratio = THREE.MathUtils.clamp((clientX - rect.left) / rect.width, 0, 1);
const raw = DAY_START + ratio * DAY_SPAN;
return Math.round(raw / 15) * 15;
}
function onTimelinePointerDown(event) {
if (event.button !== 0) return;
if (event.target.closest(".booking-block, .request-block")) return;
const track = event.currentTarget;
const stationId = track.dataset.track;
selectStation(stationId, false);
const start = timelineMinuteAt(track, event.clientX);
const preview = document.createElement("div");
preview.className = "drag-preview";
preview.style.left = `${percent(start)}%`;
preview.style.width = "0%";
preview.textContent = formatTime(start);
track.appendChild(preview);
dragState = {
stationId,
track,
start,
current: start,
pointerId: event.pointerId,
moved: false,
preview
};
track.setPointerCapture(event.pointerId);
}
function onTimelinePointerMove(event) {
if (!dragState || dragState.pointerId !== event.pointerId) return;
dragState.current = timelineMinuteAt(dragState.track, event.clientX);
const distance = Math.abs(dragState.current - dragState.start);
if (distance >= 7) dragState.moved = true;
const end = Math.max(dragState.start, dragState.current);
dragState.preview.style.left = `${percent(dragState.start)}%`;
dragState.preview.style.width = `${percent(end) - percent(dragState.start)}%`;
dragState.preview.textContent = `${formatTime(dragState.start)} → ${formatTime(end)}`;
}
function onTimelinePointerUp(event) {
if (!dragState || dragState.pointerId !== event.pointerId) return;
const state = dragState;
dragState = null;
state.preview.remove();
let end;
if (state.moved) {
end = Math.max(state.start + 30, state.current);
} else {
end = state.start + Number(durationSelect.value);
}
placeRequest(state.stationId, state.start, end);
}
/* ------------------------------------------------------------------
Inspector and decision log
------------------------------------------------------------------ */
function renderInspector() {
if (!selectedDetail) {
inspectorElement.innerHTML = `
<div class="panel-heading">
<div>
<p class="eyebrow">Request inspector</p>
<h3>Inspect a booking</h3>
</div>
</div>
<div class="empty-inspector">
Click a booking, rejected block, or decision-log entry to see the exact result.
</div>
`;
return;
}
let item = null;
let type = selectedDetail.type;
if (type === "booking") {
item = bookings.find((booking) => booking.id === selectedDetail.id);
} else {
item = rejectedRequests.find((request) => request.id === selectedDetail.id);
}
if (!item) {
selectedDetail = null;
renderInspector();
return;
}
const station = stationById[item.stationId];
const accepted = type === "booking";
const canRelease = accepted && !item.locked;
inspectorElement.innerHTML = `
<div class="panel-heading">
<div>
<p class="eyebrow">Request inspector</p>
<h3>${accepted ? "Accepted booking" : "Rejected request"}</h3>
</div>
<span class="status-pill ${accepted ? "" : "rejected"}">
${accepted ? "Accepted" : "Rejected"}
</span>
</div>
<div class="detail-top">
<div>
<h3>${escapeHTML(station.name)}</h3>
<p>${formatRange(item.start, item.end)} · ${formatDuration(item.end - item.start)}</p>
</div>
</div>
<div class="reason-box ${accepted ? "" : "rejected"}">
${escapeHTML(item.reason)}
</div>
${
canRelease
? `
<div class="detail-actions">
<button class="danger-button" type="button" data-release="${item.id}">
Release booking
</button>
</div>
`
: ""
}
`;
const releaseButton = inspectorElement.querySelector("[data-release]");
if (releaseButton) {
releaseButton.addEventListener("click", () => releaseBooking(releaseButton.dataset.release));
}
}
function renderRequestLog() {
if (!requestLog.length) {
requestLogElement.innerHTML = `<p class="empty-inspector">No requests yet.</p>`;
return;
}
requestLogElement.innerHTML = `
<div class="log-list">
${requestLog
.slice(0, 30)
.map((entry) => {
const station = stationById[entry.stationId];
const selected =
selectedDetail &&
selectedDetail.type === entry.detailType &&
selectedDetail.id === entry.detailId;
return `
<button
class="log-row ${selected ? "selected" : ""}"
type="button"
data-log="${entry.id}"
>
<span class="log-dot ${entry.status === "rejected" ? "rejected" : ""}"></span>
<span class="log-copy">
<b>${escapeHTML(station.short)} · ${escapeHTML(entry.title)}</b>
<small>${escapeHTML(entry.reason)}</small>
</span>
<span class="log-time">${formatRange(entry.start, entry.end)}</span>
</button>
`;
})
.join("")}
</div>
`;
requestLogElement.querySelectorAll("[data-log]").forEach((button) => {
button.addEventListener("click", () => {
const entry = requestLog.find((item) => item.id === button.dataset.log);
if (!entry) return;
selectDetail(entry.detailType, entry.detailId);
});
});
}
function renderAll() {
renderTimelines();
renderInspector();
renderRequestLog();
updateStationPips();
stations.forEach(drawStationSign);
updateLabelStates();
}
function resetSchedule() {
bookings = seedBookings.map((booking) => ({ ...booking }));
rejectedRequests = [];
requestLog = seedBookings.map((booking) => ({
id: `log-${booking.id}`,
stationId: booking.stationId,
start: booking.start,
end: booking.end,
status: "accepted",
title: booking.title,
reason: "Community booking confirmed.",
detailType: "booking",
detailId: booking.id
}));
selectedDetail = null;
highlightUntil.clear();
showToast("Schedule reset to the original community timetable.");
renderAll();
}
/* ------------------------------------------------------------------
Demo controls and startup
------------------------------------------------------------------ */
document.querySelectorAll("[data-demo]").forEach((button) => {
button.addEventListener("click", () => {
const demo = button.dataset.demo;
if (demo === "overlap") {
// Matches the seeded bike-maintenance booking at the drill.
placeRequest("drill", 11 * 60 + 30, 12 * 60 + 30, "demo");
} else if (demo === "closure") {
// Falls inside the workbench maintenance closure.
placeRequest("bench", 12 * 60, 13 * 60, "demo");
} else if (demo === "insufficient") {
// The workbench closes at 17:00, so this 90-minute request cannot fit.
placeRequest("bench", 16 * 60 + 30, 18 * 60, "demo");
}
});
});
document.querySelector("#resetSchedule").addEventListener("click", resetSchedule);
durationSelect.addEventListener("change", () => {
showToast(
`Click a timeline to place a ${durationSelect.value}-minute booking, or drag for a custom range.`
);
});
buildScene();
renderAll();
selectStation("bench", true);
function animate(now) {
requestAnimationFrame(animate);
updateStationVisuals(now);
updateProjectedLabels();
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```