Prompt specification
Build or customize the Three.js 3D scene "Schedule a fictional constrained-space transfer sequence" 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: Schedule a fictional constrained-space transfer sequence
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/schedule-a-fictional-constrained-space-transfer-sequen-x2432
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing the 2010 Chilean mine rescue. Let users order illustrative capsule trips with capacity and handover constraints. Focus on coordination and explicitly separate the teaching exercise from real emergency procedures or historical timing. Low-poly.
Working Three.js Starter (schedule-a-fictional-constrained-space-transfer-sequen-x2432):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>2010 Chilean Mine Rescue — Teaching Coordination Exercise</title>
<style>
:root {
--bg: #07131f;
--panel: rgba(10, 25, 38, 0.91);
--panel-2: rgba(18, 40, 56, 0.82);
--line: rgba(155, 200, 219, 0.18);
--text: #edf7fb;
--muted: #9db5c2;
--cyan: #65d8ff;
--orange: #ff9b45;
--green: #63e6a7;
--yellow: #ffd166;
--red: #ff6b6b;
--shadow: 0 16px 50px rgba(0, 0, 0, 0.35);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input,
select {
font: inherit;
}
button,
select,
input[type="number"] {
color: var(--text);
background: #102b3c;
border: 1px solid rgba(137, 201, 224, 0.22);
border-radius: 9px;
}
button {
cursor: pointer;
transition:
background 140ms ease,
border-color 140ms ease,
transform 100ms ease;
}
button:hover:not(:disabled) {
background: #183d51;
border-color: rgba(101, 216, 255, 0.55);
}
button:active:not(:disabled) {
transform: translateY(1px);
}
button:disabled {
cursor: not-allowed;
opacity: 0.38;
}
button.primary {
color: #05202d;
background: var(--cyan);
border-color: transparent;
font-weight: 800;
}
button.primary:hover:not(:disabled) {
background: #91e6ff;
}
button.warning {
color: #251505;
background: var(--orange);
border-color: transparent;
font-weight: 800;
}
button.danger {
color: #ffd7d7;
border-color: rgba(255, 107, 107, 0.35);
}
button.small {
padding: 6px 9px;
font-size: 12px;
}
select,
input[type="number"] {
min-height: 38px;
padding: 7px 9px;
outline: none;
}
select:focus,
input:focus {
border-color: var(--cyan);
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.topbar {
position: fixed;
z-index: 10;
top: 14px;
left: 14px;
right: 14px;
min-height: 64px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
padding: 11px 14px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(7, 19, 31, 0.86);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.brand {
min-width: 0;
}
.eyebrow {
margin-bottom: 3px;
color: var(--cyan);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
overflow: hidden;
font-size: clamp(16px, 2vw, 24px);
line-height: 1.1;
text-overflow: ellipsis;
white-space: nowrap;
}
.subtitle {
margin-top: 5px;
color: var(--muted);
font-size: 12px;
}
.toolbar {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: flex-end;
gap: 7px;
}
.toolbar button,
.toolbar select {
min-height: 37px;
padding: 7px 10px;
font-size: 12px;
}
.panel {
position: fixed;
z-index: 9;
top: 92px;
bottom: 18px;
width: 350px;
padding: 14px;
overflow: auto;
border: 1px solid var(--line);
border-radius: 15px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
scrollbar-width: thin;
scrollbar-color: #31566b transparent;
}
#planner {
left: 14px;
}
#monitor {
right: 14px;
width: 310px;
}
.panel h2 {
margin: 0 0 10px;
font-size: 15px;
letter-spacing: 0.01em;
}
.panel h3 {
margin: 16px 0 8px;
color: #cce3ec;
font-size: 12px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.section {
padding-bottom: 14px;
border-bottom: 1px solid var(--line);
}
.section:last-child {
padding-bottom: 0;
border-bottom: 0;
}
.notice {
margin-bottom: 12px;
padding: 10px 11px;
border: 1px solid rgba(255, 155, 69, 0.28);
border-radius: 10px;
color: #ffe0bd;
background: rgba(255, 155, 69, 0.08);
font-size: 12px;
line-height: 1.45;
}
.notice strong {
color: var(--orange);
}
.control-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.field {
display: flex;
flex-direction: column;
gap: 5px;
}
.field label {
color: var(--muted);
font-size: 11px;
font-weight: 700;
}
.full {
grid-column: 1 / -1;
}
.queue-summary {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 9px;
}
.queue-summary span {
color: var(--muted);
font-size: 12px;
}
.queue {
display: flex;
flex-direction: column;
gap: 9px;
}
.order {
padding: 10px;
border: 1px solid var(--line);
border-left: 3px solid #567487;
border-radius: 10px;
background: rgba(20, 48, 65, 0.56);
}
.order.ready {
border-left-color: var(--green);
}
.order.active {
border-left-color: var(--cyan);
background: rgba(35, 94, 118, 0.42);
}
.order.complete {
opacity: 0.62;
border-left-color: #4d6876;
}
.order-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 8px;
}
.order-id {
font-size: 13px;
font-weight: 850;
}
.order-count {
margin-left: 6px;
color: var(--muted);
font-size: 12px;
font-weight: 500;
}
.pill {
display: inline-flex;
align-items: center;
padding: 3px 7px;
border: 1px solid var(--line);
border-radius: 999px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.pill.ready {
color: var(--green);
border-color: rgba(99, 230, 167, 0.35);
}
.pill.active {
color: var(--cyan);
border-color: rgba(101, 216, 255, 0.35);
}
.checks {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 6px;
margin-bottom: 8px;
}
.check {
display: flex;
align-items: center;
gap: 6px;
padding: 6px 7px;
border: 1px solid var(--line);
border-radius: 8px;
color: var(--muted);
background: rgba(2, 14, 23, 0.22);
font-size: 11px;
cursor: pointer;
}
.check input {
width: 14px;
height: 14px;
margin: 0;
accent-color: var(--green);
}
.check.checked {
color: #c9ffe6;
border-color: rgba(99, 230, 167, 0.35);
background: rgba(99, 230, 167, 0.08);
}
.order-actions {
display: flex;
justify-content: flex-end;
gap: 5px;
}
.order-actions button {
min-width: 30px;
padding: 4px 8px;
font-size: 11px;
}
.empty {
padding: 18px 10px;
border: 1px dashed var(--line);
border-radius: 10px;
color: var(--muted);
font-size: 12px;
text-align: center;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.metric {
padding: 10px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(22, 52, 70, 0.55);
}
.metric-value {
color: var(--cyan);
font-size: 22px;
font-weight: 850;
line-height: 1;
}
.metric-label {
margin-top: 5px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.state-card {
padding: 11px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(12, 35, 49, 0.76);
}
.state-row {
display: flex;
justify-content: space-between;
gap: 10px;
margin-bottom: 5px;
font-size: 12px;
}
.state-row strong {
color: var(--cyan);
text-align: right;
}
.progress {
height: 7px;
margin-top: 10px;
overflow: hidden;
border-radius: 999px;
background: #071721;
}
.progress > div {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--cyan), var(--green));
transition: width 80ms linear;
}
.stage-strip {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 4px;
margin-top: 10px;
}
.stage {
padding: 5px 2px;
border: 1px solid var(--line);
border-radius: 6px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
text-align: center;
text-transform: uppercase;
}
.stage.on {
color: #062331;
background: var(--cyan);
border-color: var(--cyan);
}
.constraint {
display: flex;
gap: 8px;
margin: 7px 0;
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
.constraint::before {
flex: 0 0 auto;
width: 7px;
height: 7px;
margin-top: 4px;
border-radius: 50%;
background: var(--cyan);
content: "";
}
.handoff-status {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.team {
padding: 9px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(17, 40, 54, 0.62);
}
.team-name {
color: var(--muted);
font-size: 10px;
font-weight: 800;
text-transform: uppercase;
}
.team-state {
margin-top: 4px;
color: var(--red);
font-size: 12px;
font-weight: 850;
}
.team.ready .team-state {
color: var(--green);
}
.reason {
margin-top: 10px;
padding: 9px;
border-radius: 8px;
color: #ffe3b8;
background: rgba(255, 209, 102, 0.08);
font-size: 11px;
line-height: 1.45;
}
.camera-buttons {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 5px;
}
.camera-buttons button {
padding: 6px 4px;
font-size: 10px;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 12px;
color: var(--muted);
font-size: 10px;
}
.legend span {
display: flex;
align-items: center;
gap: 5px;
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
}
.bottom-note {
position: fixed;
z-index: 8;
left: 50%;
bottom: 16px;
transform: translateX(-50%);
max-width: calc(100vw - 720px);
padding: 8px 12px;
border: 1px solid rgba(255, 155, 69, 0.25);
border-radius: 999px;
color: #e8c39f;
background: rgba(7, 19, 31, 0.78);
font-size: 10px;
text-align: center;
pointer-events: none;
}
#toast {
position: fixed;
z-index: 40;
left: 50%;
top: 88px;
max-width: 420px;
transform: translate(-50%, -12px);
padding: 10px 14px;
border: 1px solid rgba(101, 216, 255, 0.35);
border-radius: 9px;
color: var(--text);
background: rgba(12, 39, 54, 0.96);
box-shadow: var(--shadow);
font-size: 12px;
opacity: 0;
pointer-events: none;
transition:
opacity 160ms ease,
transform 160ms ease;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#about {
position: fixed;
z-index: 50;
inset: 0;
display: none;
align-items: center;
justify-content: center;
padding: 20px;
background: rgba(2, 9, 15, 0.72);
backdrop-filter: blur(7px);
}
#about.open {
display: flex;
}
.modal {
width: min(640px, 100%);
max-height: 85vh;
overflow: auto;
padding: 22px;
border: 1px solid rgba(101, 216, 255, 0.28);
border-radius: 16px;
background: #0b2030;
box-shadow: var(--shadow);
}
.modal-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20px;
}
.modal h2 {
margin: 3px 0 14px;
font-size: 21px;
}
.modal p,
.modal li {
color: #c3d8e1;
font-size: 13px;
line-height: 1.65;
}
.modal ul {
padding-left: 20px;
}
.warning-box {
margin: 16px 0;
padding: 13px;
border: 1px solid rgba(255, 155, 69, 0.35);
border-radius: 10px;
background: rgba(255, 155, 69, 0.08);
}
@media (max-width: 1050px) {
#monitor {
width: 280px;
}
.bottom-note {
display: none;
}
}
@media (max-width: 850px) {
.topbar {
align-items: flex-start;
flex-direction: column;
}
.toolbar {
justify-content: flex-start;
}
.panel {
top: 132px;
}
#monitor {
display: none;
}
#planner {
right: 14px;
width: auto;
}
}
@media (max-width: 520px) {
.topbar {
top: 8px;
left: 8px;
right: 8px;
}
.subtitle {
font-size: 10px;
}
.toolbar button,
.toolbar select {
min-height: 32px;
padding: 5px 7px;
font-size: 10px;
}
.panel {
top: 125px;
bottom: 8px;
left: 8px;
right: 8px;
width: auto;
padding: 11px;
}
.checks,
.handoff-status {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive low-poly mine rescue teaching scene"></div>
<header class="topbar">
<div class="brand">
<div class="eyebrow">Teaching exercise · fictional coordination model</div>
<h1>2010 Chilean Mine Rescue</h1>
<div class="subtitle">
Order batches, confirm shared handovers, and observe one-capsule dispatch.
</div>
</div>
<div class="toolbar">
<button id="runBtn" class="primary">Start</button>
<button id="stepBtn">Step 1s</button>
<select id="speedSelect" aria-label="Simulation speed">
<option value="1">1× speed</option>
<option value="2">2× speed</option>
<option value="4">4× speed</option>
</select>
<button id="restartBtn" title="Restart the run while keeping the current order plan">
Restart run
</button>
<button id="aboutBtn">Model notes</button>
</div>
</header>
<aside id="planner" class="panel" aria-label="Trip order planner">
<div class="section">
<h2>Trip-order planner</h2>
<div class="notice">
<strong>Not a historical reconstruction.</strong>
This is a fictional batching exercise with a four-person capacity.
Model seconds are not historical rescue times or real procedures.
</div>
<div class="control-row">
<div class="field">
<label for="capacitySelect">Illustrative capacity</label>
<select id="capacitySelect">
<option value="1">1 passenger</option>
<option value="2">2 passengers</option>
<option value="3">3 passengers</option>
<option value="4" selected>4 passengers</option>
</select>
</div>
<div class="field">
<label for="passengerCount">Passengers per order</label>
<input
id="passengerCount"
type="number"
min="1"
max="4"
step="1"
value="1"
>
</div>
<button id="addOrderBtn" class="primary full">Add trip order</button>
</div>
</div>
<div class="section">
<div class="queue-summary">
<span>FIFO queue</span>
<span id="queueSummaryText">0 orders</span>
</div>
<div id="orderList" class="queue"></div>
<div class="order-actions" style="margin-top: 10px">
<button id="clearQueuedBtn" class="small danger">Clear queued</button>
<button id="clearCompletedBtn" class="small">Clear completed</button>
</div>
</div>
<div class="section">
<h3>Exercise rules</h3>
<div class="constraint">
The first unfinished order blocks every later order.
</div>
<div class="constraint">
Each order needs both pit and surface handoff confirmation.
</div>
<div class="constraint">
A batch cannot exceed the selected capacity.
</div>
<div class="constraint">
One shared capsule permits only one active order.
</div>
</div>
</aside>
<aside id="monitor" class="panel" aria-label="Exercise monitor">
<div class="section">
<h2>Exercise monitor</h2>
<div class="metrics">
<div class="metric">
<div id="deliveredMetric" class="metric-value">0</div>
<div class="metric-label">Completed trips</div>
</div>
<div class="metric">
<div id="surfaceMetric" class="metric-value">0</div>
<div class="metric-label">At surface</div>
</div>
<div class="metric">
<div id="queueMetric" class="metric-value">0</div>
<div class="metric-label">Queued batches</div>
</div>
<div class="metric">
<div id="freeMetric" class="metric-value">33</div>
<div class="metric-label">Unallocated people</div>
</div>
</div>
</div>
<div class="section">
<h3>Capsule state</h3>
<div class="state-card">
<div class="state-row">
<span>State</span>
<strong id="stateText">Paused</strong>
</div>
<div class="state-row">
<span>Active order</span>
<strong id="activeOrderText">None</strong>
</div>
<div class="state-row">
<span>Model clock</span>
<strong id="clockText">0.0 s</strong>
</div>
<div class="progress"><div id="progressFill"></div></div>
<div class="stage-strip">
<div class="stage" data-stage="loading">Load</div>
<div class="stage" data-stage="ascent">Ascend</div>
<div class="stage" data-stage="unloading">Handoff</div>
<div class="stage" data-stage="reset">Reset</div>
</div>
</div>
<div id="handoffReason" class="reason">
The front order needs both handover confirmations.
</div>
</div>
<div class="section">
<h3>Shared handover teams</h3>
<div class="handoff-status">
<div id="pitTeam" class="team">
<div class="team-name">Pit handoff</div>
<div id="pitTeamState" class="team-state">Waiting</div>
</div>
<div id="surfaceTeam" class="team">
<div class="team-name">Surface handoff</div>
<div id="surfaceTeamState" class="team-state">Waiting</div>
</div>
</div>
</div>
<div class="section">
<h3>Camera</h3>
<div class="camera-buttons">
<button data-camera="overview">Overview</button>
<button data-camera="surface">Surface</button>
<button data-camera="cavern">Cavern</button>
</div>
<p style="margin: 11px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45">
Drag the scene to orbit. Use the mouse wheel to zoom.
</p>
</div>
<div class="section">
<h3>Scene legend</h3>
<div class="legend">
<span><i class="dot" style="background: #ff9b45"></i> Teaching capsule</span>
<span><i class="dot" style="background: #ffd166"></i> Waiting cohort</span>
<span><i class="dot" style="background: #63e6a7"></i> Confirmed handoff</span>
<span><i class="dot" style="background: #65d8ff"></i> Surface cohort</span>
</div>
</div>
</aside>
<div class="bottom-note">
Fictional teaching exercise — not emergency guidance, a Fénix reconstruction,
or a source of historical timing.
</div>
<div id="toast" role="status" aria-live="polite"></div>
<div id="about" role="dialog" aria-modal="true" aria-labelledby="aboutTitle">
<div class="modal">
<div class="modal-head">
<div>
<div class="eyebrow">Read before using</div>
<h2 id="aboutTitle">Historical context and model boundaries</h2>
</div>
<button id="closeAboutBtn" class="small">Close</button>
</div>
<p>
In 2010, 33 miners trapped underground at the Copiapó mine were ultimately
brought to the surface. This page uses that event only as a neutral teaching
context for coordination, queueing, capacity, and shared-resource decisions.
</p>
<div class="warning-box">
<strong>Explicit separation:</strong> the capsule, four-person capacity,
timing, sequence, animations, and handover workflow are fictional. They do
not reconstruct the Fénix capsule or the actual rescue. In reality, the
Fénix capsule carried one miner at a time.
</div>
<p>
The model omits drilling, shaft engineering, communications, medical
assessment, rope and winch procedures, rescue-team roles, casualty handling,
and every other real emergency requirement. It must not be used to plan,
conduct, evaluate, or improvise an actual mine rescue.
</p>
<h3>What the exercise teaches</h3>
<ul>
<li>How a finite capacity turns a group of people into ordered batches.</li>
<li>How a FIFO queue can become blocked by an uncleared front order.</li>
<li>How shared handover resources require explicit readiness.</li>
<li>How one capsule serializes loading, ascent, unloading, and reset.</li>
</ul>
<p>
All displayed seconds are model seconds. They are intentionally unrelated
to historical minutes, drilling time, ascent time, or the duration of the
2010 rescue.
</p>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Exercise state
// -------------------------------------------------------------------------
const TOTAL_MINERS = 33;
const PHASE_DURATION = {
loading: 8,
ascent: 26,
unloading: 8,
reset: 18
};
const PHASE_LABEL = {
idle: "Waiting",
loading: "Loading at pit",
ascent: "Ascending",
unloading: "Surface handoff",
reset: "Returning empty"
};
const STATUS_LABEL = {
queued: "Queued",
loading: "Loading",
ascent: "Ascending",
unloading: "Unloading",
returning: "Returning",
complete: "Complete"
};
let capacity = 4;
let orders = [];
let nextOrderNumber = 1;
let running = false;
let simulationSpeed = 1;
let exerciseClock = 0;
let phase = "idle";
let phaseTime = 0;
let phaseDuration = 1;
let activeOrder = null;
let deliveredCount = 0;
let surfaceCount = 0;
let loadingAssignment = [];
let loadingHidden = 0;
let unloadingShown = 0;
let uiDirty = true;
let toastTimer = 0;
const orderList = document.getElementById("orderList");
const passengerInput = document.getElementById("passengerCount");
const capacitySelect = document.getElementById("capacitySelect");
const runButton = document.getElementById("runBtn");
function seedPlan() {
orders = [
{
id: nextOrderNumber++,
count: 4,
pit: true,
surface: false,
status: "queued"
},
{
id: nextOrderNumber++,
count: 4,
pit: false,
surface: false,
status: "queued"
}
];
uiDirty = true;
}
function reservedCount() {
return orders
.filter((order) => order.status !== "complete")
.reduce((total, order) => total + order.count, 0);
}
function unallocatedCount() {
return TOTAL_MINERS - deliveredCount - reservedCount();
}
function nextQueuedOrder() {
return orders.find((order) => order.status === "queued");
}
function showToast(message) {
const toast = document.getElementById("toast");
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2600);
}
function addOrder() {
const count = Number.parseInt(passengerInput.value, 10);
if (!Number.isFinite(count) || count < 1) {
showToast("Enter a passenger count of at least one.");
return;
}
if (count > capacity) {
showToast(`This order exceeds the ${capacity}-person illustrative capacity.`);
return;
}
if (count > unallocatedCount()) {
showToast(
`Only ${unallocatedCount()} people remain unallocated in this 33-person exercise.`
);
return;
}
orders.push({
id: nextOrderNumber++,
count,
pit: false,
surface: false,
status: "queued"
});
passengerInput.value = "1";
uiDirty = true;
showToast(`Trip T-${String(nextOrderNumber - 1).padStart(2, "0")} added.`);
}
function moveOrder(id, direction) {
const queued = orders.filter((order) => order.status === "queued");
const queuedIndex = queued.findIndex((order) => order.id === id);
if (queuedIndex < 0) return;
const targetIndex = queuedIndex + direction;
if (targetIndex < 0 || targetIndex >= queued.length) return;
const currentGlobalIndex = orders.indexOf(queued[queuedIndex]);
const targetGlobalIndex = orders.indexOf(queued[targetIndex]);
[orders[currentGlobalIndex], orders[targetGlobalIndex]] = [
orders[targetGlobalIndex],
orders[currentGlobalIndex]
];
uiDirty = true;
}
function setHandoff(id, field, value) {
const order = orders.find((item) => item.id === id);
if (!order || order.status !== "queued") return;
order[field] = value;
uiDirty = true;
}
function clearQueuedOrders() {
const removed = orders.filter((order) => order.status === "queued").length;
orders = orders.filter((order) => order.status !== "queued");
uiDirty = true;
showToast(`${removed} queued order${removed === 1 ? "" : "s"} removed.`);
}
function clearCompletedOrders() {
const removed = orders.filter((order) => order.status === "complete").length;
orders = orders.filter((order) => order.status !== "complete");
uiDirty = true;
showToast(`${removed} completed order${removed === 1 ? "" : "s"} removed.`);
}
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const sceneHost = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071521);
scene.fog = new THREE.Fog(0x071521, 68, 145);
const camera = new THREE.PerspectiveCamera(
46,
window.innerWidth / window.innerHeight,
0.1,
220
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
sceneHost.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xc9efff, 0x15202b, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffefd5, 3.0);
sun.position.set(25, 42, 28);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -45;
sun.shadow.camera.right = 45;
sun.shadow.camera.top = 45;
sun.shadow.camera.bottom = -45;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 120;
scene.add(sun);
const undergroundLight = new THREE.PointLight(0xff9a54, 34, 34, 1.8);
undergroundLight.position.set(-11, -20, 4);
scene.add(undergroundLight);
const shaftLight = new THREE.PointLight(0x65d8ff, 20, 24, 1.8);
shaftLight.position.set(0, -12, 2);
scene.add(shaftLight);
const surfaceLight = new THREE.PointLight(0xb9ecff, 22, 26, 1.7);
surfaceLight.position.set(5, 7, 4);
scene.add(surfaceLight);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02,
flatShading: true,
...options
});
}
const groundMaterial = material(0x41634f);
const sideMaterial = material(0x293d45);
const platformMaterial = material(0x53636b);
const darkMaterial = material(0x111d26);
const rockMaterial = material(0x34434a);
const rockLightMaterial = material(0x47575a);
const orangeMaterial = material(0xff873c, {
emissive: 0x4d1600,
emissiveIntensity: 0.32
});
const cyanMaterial = material(0x65d8ff, {
emissive: 0x0c3e4d,
emissiveIntensity: 0.55
});
const greenMaterial = material(0x63e6a7, {
emissive: 0x0b4d31,
emissiveIntensity: 0.6
});
function addBox(width, height, depth, mat, x, y, z, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function cylinderBetween(a, b, radius, mat, radialSegments = 6) {
const direction = b.clone().sub(a);
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radius,
radius,
direction.length(),
radialSegments
),
mat
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
scene.add(mesh);
return mesh;
}
function addRock(x, y, z, sx, sy, sz, mat = rockMaterial) {
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(1, 0),
mat
);
rock.position.set(x, y, z);
rock.scale.set(sx, sy, sz);
rock.rotation.set(
Math.random() * 0.4,
Math.random() * Math.PI,
Math.random() * 0.3
);
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
return rock;
}
// Ground slab with a square opening around the shaft.
const groundShape = new THREE.Shape();
groundShape.moveTo(-26, -17);
groundShape.lineTo(26, -17);
groundShape.lineTo(26, 17);
groundShape.lineTo(-26, 17);
groundShape.closePath();
const shaftHole = new THREE.Path();
shaftHole.moveTo(-3.2, -3.2);
shaftHole.lineTo(-3.2, 3.2);
shaftHole.lineTo(3.2, 3.2);
shaftHole.lineTo(3.2, -3.2);
shaftHole.closePath();
groundShape.holes.push(shaftHole);
const groundGeometry = new THREE.ExtrudeGeometry(groundShape, {
depth: 1.2,
bevelEnabled: false
});
groundGeometry.rotateX(-Math.PI / 2);
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
ground.position.y = -1.2;
ground.receiveShadow = true;
scene.add(ground);
// Surface landing pads around the shaft.
addBox(13, 0.28, 6.4, platformMaterial, -9.6, 0.14, 0);
addBox(13, 0.28, 6.4, platformMaterial, 9.6, 0.14, 0);
addBox(6.4, 0.28, 13.2, platformMaterial, 0, 0.14, -9.8);
addBox(6.4, 0.28, 13.2, platformMaterial, 0, 0.14, 9.8);
// Low-poly shaft rails and rear wall.
for (const x of [-1.9, 1.9]) {
for (const z of [-1.9, 1.9]) {
cylinderBetween(
new THREE.Vector3(x, -25, z),
new THREE.Vector3(x, 12, z),
0.085,
darkMaterial,
6
);
}
}
const shaftBack = new THREE.Mesh(
new THREE.PlaneGeometry(5.2, 37),
new THREE.MeshStandardMaterial({
color: 0x152b36,
roughness: 0.9,
transparent: true,
opacity: 0.38,
side: THREE.DoubleSide,
flatShading: true
})
);
shaftBack.position.set(0, -12.5, -2.15);
scene.add(shaftBack);
// Headframe.
const frameMaterial = material(0xe0a23c);
const framePoints = [
[new THREE.Vector3(-3.0, 0.4, -2.0), new THREE.Vector3(-1.35, 11.3, -1.0)],
[new THREE.Vector3(3.0, 0.4, -2.0), new THREE.Vector3(1.35, 11.3, -1.0)],
[new THREE.Vector3(-3.0, 0.4, 2.0), new THREE.Vector3(-1.35, 11.3, 1.0)],
[new THREE.Vector3(3.0, 0.4, 2.0), new THREE.Vector3(1.35, 11.3, 1.0)]
];
for (const [a, b] of framePoints) {
cylinderBetween(a, b, 0.15, frameMaterial, 6);
}
addBox(4.0, 0.35, 2.8, frameMaterial, 0, 11.4, 0);
addBox(4.8, 0.28, 0.35, frameMaterial, 0, 6.4, -1.65);
addBox(4.8, 0.28, 0.35, frameMaterial, 0, 6.4, 1.65);
const pulley = new THREE.Mesh(
new THREE.CylinderGeometry(0.95, 0.95, 0.65, 12),
darkMaterial
);
pulley.rotation.z = Math.PI / 2;
pulley.position.set(0, 10.8, 0);
pulley.castShadow = true;
scene.add(pulley);
const winch = new THREE.Mesh(
new THREE.CylinderGeometry(0.7, 0.7, 1.8, 10),
material(0x657983, { metalness: 0.35 })
);
winch.rotation.z = Math.PI / 2;
winch.position.set(2.8, 4.4, -2.9);
winch.castShadow = true;
scene.add(winch);
// Cavern floor, tunnel, and faceted rock shell.
addBox(15, 0.65, 12.2, sideMaterial, -11.2, -25.35, 0);
addBox(7.0, 0.7, 4.6, platformMaterial, -2.4, -25.05, 0);
const tunnel = new THREE.Mesh(
new THREE.CylinderGeometry(1.75, 1.75, 6.4, 8, 1, true),
new THREE.MeshStandardMaterial({
color: 0x23333b,
roughness: 1,
side: THREE.DoubleSide,
flatShading: true
})
);
tunnel.rotation.z = Math.PI / 2;
tunnel.position.set(-2.9, -23.45, 0);
scene.add(tunnel);
addRock(-14, -20.8, -5.5, 5.4, 4.2, 2.1);
addRock(-7.3, -20.5, -4.6, 3.8, 3.5, 2.1, rockLightMaterial);
addRock(-18, -23.0, -3.3, 2.5, 2.3, 2.3);
addRock(-17.4, -18.6, 1.0, 2.3, 3.2, 2.6, rockLightMaterial);
addRock(-5.5, -18.7, -3.0, 2.1, 3.0, 2.0);
addRock(-17.6, -24.3, 4.8, 2.5, 1.4, 1.5, rockLightMaterial);
addRock(-6.0, -24.0, 4.5, 2.1, 1.2, 1.3);
// Generic low-poly teaching capsule, not a Fénix reconstruction.
const capsule = new THREE.Group();
const capsuleBody = new THREE.Mesh(
new THREE.CylinderGeometry(1.12, 1.12, 3.1, 8),
orangeMaterial
);
capsuleBody.castShadow = true;
capsule.add(capsuleBody);
const capsuleTop = new THREE.Mesh(
new THREE.ConeGeometry(1.12, 0.85, 8),
orangeMaterial
);
capsuleTop.position.y = 1.98;
capsuleTop.castShadow = true;
capsule.add(capsuleTop);
const capsuleBottom = new THREE.Mesh(
new THREE.ConeGeometry(1.12, 0.85, 8),
orangeMaterial
);
capsuleBottom.position.y = -1.98;
capsuleBottom.rotation.z = Math.PI;
capsuleBottom.castShadow = true;
capsule.add(capsuleBottom);
const windowMaterial = material(0x183946, {
emissive: 0x0c3140,
emissiveIntensity: 0.6,
metalness: 0.15
});
const frontWindow = addBox(1.25, 0.82, 0.10, windowMaterial, 0, 0.3, 1.06);
const sideWindow = addBox(0.10, 0.82, 1.18, windowMaterial, 1.06, 0.3, 0);
// Reparent the two window meshes to the capsule group.
capsule.attach(frontWindow);
capsule.attach(sideWindow);
const capsuleBand = new THREE.Mesh(
new THREE.TorusGeometry(1.16, 0.09, 5, 8),
cyanMaterial
);
capsuleBand.rotation.x = Math.PI / 2;
capsuleBand.position.y = -0.85;
capsule.add(capsuleBand);
capsule.position.set(0, -22.2, 0);
scene.add(capsule);
// Cable from the headframe to the capsule.
const cableGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 10.7, 0),
new THREE.Vector3(0, -19.7, 0)
]);
const cable = new THREE.Line(
cableGeometry,
new THREE.LineBasicMaterial({ color: 0x9ab1b9 })
);
scene.add(cable);
// Handoff rings.
const pitRingMaterial = greenMaterial.clone();
const surfaceRingMaterial = greenMaterial.clone();
const pitRing = new THREE.Mesh(
new THREE.TorusGeometry(1.05, 0.10, 6, 12),
pitRingMaterial
);
pitRing.rotation.x = Math.PI / 2;
pitRing.position.set(-3.9, -24.82, 1.1);
scene.add(pitRing);
const surfaceRing = new THREE.Mesh(
new THREE.TorusGeometry(1.05, 0.10, 6, 12),
surfaceRingMaterial
);
surfaceRing.rotation.x = Math.PI / 2;
surfaceRing.position.set(4.0, 0.34, 1.3);
scene.add(surfaceRing);
function makeMiner(bodyColor) {
const group = new THREE.Group();
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.25, 0.32, 0.70, 6),
material(bodyColor)
);
body.position.y = 0.46;
body.castShadow = true;
group.add(body);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.22, 8, 6),
material(0xd9a47d)
);
head.position.y = 1.02;
head.castShadow = true;
group.add(head);
const helmet = new THREE.Mesh(
new THREE.CylinderGeometry(0.25, 0.29, 0.15, 8),
material(0xffcf45)
);
helmet.position.y = 1.20;
helmet.castShadow = true;
group.add(helmet);
const lamp = new THREE.Mesh(
new THREE.SphereGeometry(0.075, 6, 4),
cyanMaterial
);
lamp.position.set(0, 1.20, 0.25);
group.add(lamp);
return group;
}
const waitingMiners = [];
const surfacePeople = [];
const minerColors = [0x3e78a5, 0x7d5aa6, 0x447d68, 0x9c664e];
for (let i = 0; i < TOTAL_MINERS; i++) {
const column = i % 6;
const row = Math.floor(i / 6);
const miner = makeMiner(minerColors[i % minerColors.length]);
miner.position.set(
-15.0 + column * 1.28,
-24.98,
-4.0 + row * 1.38
);
miner.rotation.y = Math.PI * 0.08;
scene.add(miner);
waitingMiners.push(miner);
const person = makeMiner(minerColors[(i + 1) % minerColors.length]);
person.position.set(
8.0 + column * 1.32,
0.32,
-4.0 + row * 1.38
);
person.rotation.y = Math.PI;
person.visible = false;
scene.add(person);
surfacePeople.push(person);
}
// Surface base camp decorations.
const tentMaterial = material(0xc96e43);
const tent = new THREE.Mesh(
new THREE.ConeGeometry(2.0, 2.7, 4),
tentMaterial
);
tent.position.set(-11, 1.4, 6.5);
tent.rotation.y = Math.PI / 4;
tent.castShadow = true;
scene.add(tent);
addBox(3.4, 2.2, 2.8, material(0x637984), -18, 1.1, -5.5);
addBox(3.8, 0.18, 3.1, material(0x93a7ac), -18, 2.28, -5.5);
for (const x of [-21, -19.5, -17.7]) {
cylinderBetween(
new THREE.Vector3(x, 0, 10),
new THREE.Vector3(x, 3.3, 10),
0.09,
material(0x604a35),
5
);
const tree = new THREE.Mesh(
new THREE.ConeGeometry(1.15, 3.2, 6),
material(0x2d604a)
);
tree.position.set(x, 2.1, 10);
tree.castShadow = true;
scene.add(tree);
}
// Distant faceted hills.
addRock(-28, 0.6, -14, 9, 4, 7, material(0x253d40));
addRock(24, 1.0, -16, 10, 5, 8, material(0x2d4646));
addRock(29, 0.4, 5, 7, 3.5, 6, material(0x263c3c));
function makeLabel(text, color = "#dff8ff") {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 128;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(5, 18, 28, 0.78)";
context.fillRect(0, 20, canvas.width, 88);
context.strokeStyle = color;
context.lineWidth = 4;
context.strokeRect(4, 24, canvas.width - 8, 80);
context.fillStyle = color;
context.font = "bold 38px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvas.width / 2, 65);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(11, 2.2, 1);
return sprite;
}
const surfaceLabel = makeLabel("SURFACE HANDOFF", "#65d8ff");
surfaceLabel.position.set(12, 4.7, 0);
scene.add(surfaceLabel);
const pitLabel = makeLabel("UNDERGROUND HANDOFF", "#ffb05c");
pitLabel.position.set(-4.0, -20.6, 2.0);
scene.add(pitLabel);
const cohortLabel = makeLabel("33-PERSON TEACHING COHORT", "#ffd166");
cohortLabel.position.set(-12.5, -18.6, 4.0);
scene.add(cohortLabel);
const capsuleLabel = makeLabel("FICTIONAL TEACHING CAPSULE", "#ff9b45");
capsuleLabel.position.set(0, 13.7, 0);
scene.add(capsuleLabel);
// -------------------------------------------------------------------------
// Direct camera controls: orbit, zoom, keyboard shortcuts, and presets
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(-4, -10.5, 0);
let cameraYaw = 0.64;
let cameraPitch = 0.27;
let cameraRadius = 68;
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
function applyCamera() {
cameraPitch = THREE.MathUtils.clamp(cameraPitch, -0.04, 1.08);
cameraRadius = THREE.MathUtils.clamp(cameraRadius, 23, 105);
camera.position.set(
cameraTarget.x + cameraRadius * Math.cos(cameraPitch) * Math.sin(cameraYaw),
cameraTarget.y + cameraRadius * Math.sin(cameraPitch),
cameraTarget.z + cameraRadius * Math.cos(cameraPitch) * Math.cos(cameraYaw)
);
camera.lookAt(cameraTarget);
}
function setCameraPreset(name) {
if (name === "surface") {
cameraTarget.set(3, 1.5, 0);
cameraYaw = 0.62;
cameraPitch = 0.48;
cameraRadius = 39;
} else if (name === "cavern") {
cameraTarget.set(-10, -22.2, 0);
cameraYaw = 0.46;
cameraPitch = 0.13;
cameraRadius = 35;
} else {
cameraTarget.set(-4, -10.5, 0);
cameraYaw = 0.64;
cameraPitch = 0.27;
cameraRadius = 68;
}
applyCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
cameraYaw -= deltaX * 0.005;
cameraPitch += deltaY * 0.004;
applyCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius *= Math.exp(event.deltaY * 0.001);
applyCamera();
},
{ passive: false }
);
document.querySelectorAll("[data-camera]").forEach((button) => {
button.addEventListener("click", () => {
setCameraPreset(button.dataset.camera);
});
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// -------------------------------------------------------------------------
// Simulation
// -------------------------------------------------------------------------
function beginLoading(order) {
const available = waitingMiners.filter((miner) => miner.visible);
if (available.length < order.count) {
showToast("Not enough unallocated people remain for this order.");
return false;
}
activeOrder = order;
order.status = "loading";
phase = "loading";
phaseTime = 0;
phaseDuration = PHASE_DURATION.loading;
loadingAssignment = available.slice(0, order.count);
loadingHidden = 0;
unloadingShown = 0;
uiDirty = true;
return true;
}
function tryBeginNextOrder() {
if (activeOrder) return false;
const next = nextQueuedOrder();
if (!next) return false;
if (next.count > capacity) {
return false;
}
if (!next.pit || !next.surface) {
return false;
}
return beginLoading(next);
}
function advanceSimulation(deltaSeconds) {
exerciseClock += deltaSeconds;
if (phase === "idle") {
tryBeginNextOrder();
return;
}
phaseTime += deltaSeconds;
if (phase === "loading") {
const targetHidden = Math.min(
activeOrder.count,
Math.floor((phaseTime / phaseDuration) * activeOrder.count)
);
while (loadingHidden < targetHidden) {
loadingAssignment[loadingHidden].visible = false;
loadingHidden++;
}
if (phaseTime >= phaseDuration) {
while (loadingHidden < loadingAssignment.length) {
loadingAssignment[loadingHidden].visible = false;
loadingHidden++;
}
activeOrder.status = "ascent";
phase = "ascent";
phaseTime = 0;
phaseDuration = PHASE_DURATION.ascent;
uiDirty = true;
}
} else if (phase === "ascent") {
if (phaseTime >= phaseDuration) {
activeOrder.status = "unloading";
phase = "unloading";
phaseTime = 0;
phaseDuration = PHASE_DURATION.unloading;
unloadingShown = 0;
uiDirty = true;
}
} else if (phase === "unloading") {
const targetShown = Math.min(
activeOrder.count,
Math.floor((phaseTime / phaseDuration) * activeOrder.count)
);
while (unloadingShown < targetShown) {
surfacePeople[surfaceCount + unloadingShown].visible = true;
unloadingShown++;
}
if (phaseTime >= phaseDuration) {
while (unloadingShown < activeOrder.count) {
surfacePeople[surfaceCount + unloadingShown].visible = true;
unloadingShown++;
}
surfaceCount += activeOrder.count;
activeOrder.status = "returning";
phase = "reset";
phaseTime = 0;
phaseDuration = PHASE_DURATION.reset;
uiDirty = true;
}
} else if (phase === "reset") {
if (phaseTime >= phaseDuration) {
activeOrder.status = "complete";
deliveredCount += activeOrder.count;
activeOrder = null;
phase = "idle";
phaseTime = 0;
uiDirty = true;
}
}
}
function stepSimulation() {
running = false;
updateRunButton();
if (phase === "idle") {
tryBeginNextOrder();
}
advanceSimulation(1);
renderMonitor();
}
function toggleRunning() {
if (phase === "idle" && !tryBeginNextOrder()) {
const next = nextQueuedOrder();
if (!next) {
showToast("The queue is clear. Add another trip order to continue.");
} else if (!next.pit) {
showToast(`T-${String(next.id).padStart(2, "0")} needs pit-handoff confirmation.`);
} else if (!next.surface) {
showToast(`T-${String(next.id).padStart(2, "0")} needs surface-handoff confirmation.`);
}
return;
}
running = !running;
updateRunButton();
}
function updateRunButton() {
runButton.textContent = running ? "Pause" : "Start";
}
function restartRun() {
running = false;
phase = "idle";
phaseTime = 0;
activeOrder = null;
deliveredCount = 0;
surfaceCount = 0;
exerciseClock = 0;
loadingAssignment = [];
loadingHidden = 0;
unloadingShown = 0;
orders.forEach((order) => {
if (order.status !== "complete") order.status = "queued";
});
waitingMiners.forEach((miner) => {
miner.visible = true;
});
surfacePeople.forEach((person) => {
person.visible = false;
});
capsule.position.y = -22.2;
updateRunButton();
uiDirty = true;
showToast("Run restarted. The order plan and handover confirmations were kept.");
}
// -------------------------------------------------------------------------
// UI rendering
// -------------------------------------------------------------------------
function renderOrders() {
if (!uiDirty) return;
uiDirty = false;
if (!orders.length) {
orderList.innerHTML =
'<div class="empty">No trip orders. Add a batch above to begin planning.</div>';
} else {
const queuedOrders = orders.filter((order) => order.status === "queued");
orderList.innerHTML = orders
.map((order) => {
const id = String(order.id).padStart(2, "0");
const ready = order.pit && order.surface && order.status === "queued";
const active = ["loading", "ascent", "unloading", "returning"].includes(
order.status
);
const complete = order.status === "complete";
const queueIndex = queuedOrders.findIndex((item) => item.id === order.id);
const editable = order.status === "queued";
const statusClass = ready
? "ready"
: active
? "active"
: complete
? "complete"
: "";
const pillClass = ready
? "ready"
: active
? "active"
: "";
return `
<article class="order ${statusClass}">
<div class="order-top">
<div>
<span class="order-id">T-${id}</span>
<span class="order-count">${order.count} passenger${
order.count === 1 ? "" : "s"
}</span>
</div>
<span class="pill ${pillClass}">${STATUS_LABEL[order.status]}</span>
</div>
<div class="checks">
<label class="check ${order.pit ? "checked" : ""}">
<input
type="checkbox"
data-id="${order.id}"
data-field="pit"
${order.pit ? "checked" : ""}
${editable ? "" : "disabled"}
>
Pit handoff
</label>
<label class="check ${order.surface ? "checked" : ""}">
<input
type="checkbox"
data-id="${order.id}"
data-field="surface"
${order.surface ? "checked" : ""}
${editable ? "" : "disabled"}
>
Surface handoff
</label>
</div>
<div class="order-actions">
<button
class="small"
data-action="up"
data-id="${order.id}"
${editable && queueIndex > 0 ? "" : "disabled"}
title="Move earlier"
>↑</button>
<button
class="small"
data-action="down"
data-id="${order.id}"
${editable && queueIndex >= 0 && queueIndex < queuedOrders.length - 1 ? "" : "disabled"}
title="Move later"
>↓</button>
</div>
</article>
`;
})
.join("");
}
const queuedCount = orders.filter((order) => order.status === "queued").length;
document.getElementById("queueSummaryText").textContent =
`${queuedCount} order${queuedCount === 1 ? "" : "s"}`;
}
function blockReason() {
if (activeOrder) {
return `T-${String(activeOrder.id).padStart(2, "0")} is active. Later orders remain blocked until this batch finishes its reset cycle.`;
}
const next = nextQueuedOrder();
if (!next) {
return "Queue clear. Add another order or restart the run.";
}
if (next.count > capacity) {
return `T-${String(next.id).padStart(2, "0")} exceeds the selected capacity.`;
}
if (!next.pit) {
return `T-${String(next.id).padStart(2, "0")} is blocked: confirm the pit handoff.`;
}
if (!next.surface) {
return `T-${String(next.id).padStart(2, "0")} is blocked: confirm the surface handoff.`;
}
return `T-${String(next.id).padStart(2, "0")} is ready. Start or step the exercise to load it.`;
}
function renderMonitor() {
const queuedCount = orders.filter((order) => order.status === "queued").length;
const next = nextQueuedOrder();
document.getElementById("deliveredMetric").textContent = deliveredCount;
document.getElementById("surfaceMetric").textContent = surfaceCount;
document.getElementById("queueMetric").textContent = queuedCount;
document.getElementById("freeMetric").textContent = unallocatedCount();
document.getElementById("stateText").textContent = running
? PHASE_LABEL[phase]
: phase === "idle"
? "Paused"
: `${PHASE_LABEL[phase]} · paused`;
document.getElementById("activeOrderText").textContent = activeOrder
? `T-${String(activeOrder.id).padStart(2, "0")} · ${activeOrder.count}`
: "None";
document.getElementById("clockText").textContent = `${exerciseClock.toFixed(1)} s`;
const progress = phase === "idle" ? 0 : Math.min(1, phaseTime / phaseDuration);
document.getElementById("progressFill").style.width = `${progress * 100}%`;
document.querySelectorAll("[data-stage]").forEach((stage) => {
stage.classList.toggle("on", stage.dataset.stage === phase);
});
document.getElementById("handoffReason").textContent = blockReason();
const pitReady = Boolean(activeOrder?.pit || next?.pit);
const surfaceReady = Boolean(activeOrder?.surface || next?.surface);
const pitTeam = document.getElementById("pitTeam");
const surfaceTeam = document.getElementById("surfaceTeam");
pitTeam.classList.toggle("ready", pitReady);
surfaceTeam.classList.toggle("ready", surfaceReady);
document.getElementById("pitTeamState").textContent = pitReady
? "Confirmed"
: "Waiting";
document.getElementById("surfaceTeamState").textContent = surfaceReady
? "Confirmed"
: "Waiting";
pitRingMaterial.color.setHex(pitReady ? 0x63e6a7 : 0x8b4656);
pitRingMaterial.emissive.setHex(pitReady ? 0x0b4d31 : 0x2c1017);
surfaceRingMaterial.color.setHex(surfaceReady ? 0x63e6a7 : 0x8b4656);
surfaceRingMaterial.emissive.setHex(surfaceReady ? 0x0b4d31 : 0x2c1017);
}
// -------------------------------------------------------------------------
// Input wiring
// -------------------------------------------------------------------------
document.getElementById("addOrderBtn").addEventListener("click", addOrder);
passengerInput.addEventListener("keydown", (event) => {
if (event.key === "Enter") addOrder();
});
capacitySelect.addEventListener("change", () => {
const proposedCapacity = Number(capacitySelect.value);
const invalidOrder = orders.find(
(order) =>
order.status === "queued" &&
order.count > proposedCapacity
);
if (invalidOrder) {
capacitySelect.value = String(capacity);
showToast(
`T-${String(invalidOrder.id).padStart(2, "0")} has ${invalidOrder.count} passengers. Change or remove it first.`
);
return;
}
capacity = proposedCapacity;
passengerInput.max = String(capacity);
uiDirty = true;
showToast(`Illustrative capacity set to ${capacity} passengers.`);
});
orderList.addEventListener("change", (event) => {
const input = event.target.closest("input[data-field]");
if (!input) return;
setHandoff(
Number(input.dataset.id),
input.dataset.field,
input.checked
);
});
orderList.addEventListener("click", (event) => {
const button = event.target.closest("button[data-action]");
if (!button) return;
const id = Number(button.dataset.id);
if (button.dataset.action === "up") moveOrder(id, -1);
if (button.dataset.action === "down") moveOrder(id, 1);
});
runButton.addEventListener("click", toggleRunning);
document.getElementById("stepBtn").addEventListener("click", stepSimulation);
document.getElementById("restartBtn").addEventListener("click", restartRun);
document.getElementById("clearQueuedBtn").addEventListener("click", clearQueuedOrders);
document.getElementById("clearCompletedBtn").addEventListener("click", clearCompletedOrders);
document.getElementById("speedSelect").addEventListener("change", (event) => {
simulationSpeed = Number(event.target.value);
});
const aboutDialog = document.getElementById("about");
document.getElementById("aboutBtn").addEventListener("click", () => {
aboutDialog.classList.add("open");
});
document.getElementById("closeAboutBtn").addEventListener("click", () => {
aboutDialog.classList.remove("open");
});
aboutDialog.addEventListener("click", (event) => {
if (event.target === aboutDialog) aboutDialog.classList.remove("open");
});
window.addEventListener("keydown", (event) => {
const tag = document.activeElement?.tagName;
if (tag === "INPUT" || tag === "SELECT" || tag === "TEXTAREA") return;
if (event.code === "Space") {
event.preventDefault();
toggleRunning();
}
if (event.key.toLowerCase() === "s") {
stepSimulation();
}
if (event.key === "Escape") {
aboutDialog.classList.remove("open");
}
});
// -------------------------------------------------------------------------
// Animation loop
// -------------------------------------------------------------------------
const BOTTOM_Y = -22.2;
const TOP_Y = 4.4;
function updateCapsuleVisuals() {
if (phase === "ascent") {
const t = THREE.MathUtils.clamp(phaseTime / phaseDuration, 0, 1);
const eased = t * t * (3 - 2 * t);
capsule.position.y = THREE.MathUtils.lerp(BOTTOM_Y, TOP_Y, eased);
} else if (phase === "reset") {
const t = THREE.MathUtils.clamp(phaseTime / phaseDuration, 0, 1);
const eased = t * t * (3 - 2 * t);
capsule.position.y = THREE.MathUtils.lerp(TOP_Y, BOTTOM_Y, eased);
} else if (phase === "loading" || phase === "idle") {
capsule.position.y = BOTTOM_Y;
} else if (phase === "unloading") {
capsule.position.y = TOP_Y;
}
const cablePositions = cableGeometry.attributes.position.array;
cablePositions[1] = capsule.position.y + 2.55;
cablePositions[4] = capsule.position.y + 2.55;
cableGeometry.attributes.position.needsUpdate = true;
cableGeometry.computeBoundingSphere();
}
let previousTime = performance.now();
let monitorTimer = 0;
function animate(now) {
const delta = Math.min(0.05, (now - previousTime) / 1000);
previousTime = now;
if (running) {
advanceSimulation(delta * simulationSpeed);
}
updateCapsuleVisuals();
monitorTimer += delta;
if (monitorTimer >= 0.1) {
monitorTimer = 0;
renderOrders();
renderMonitor();
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
// Initialize.
seedPlan();
passengerInput.max = String(capacity);
applyCamera();
renderOrders();
renderMonitor();
updateRunButton();
requestAnimationFrame(animate);
</script>
</body>
</html>
```