Prompt specification
Build or customize the Three.js 3D scene "Shared lift traffic planning" 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: Shared lift traffic planning
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/shared-lift-traffic-planning-x0432
Scene Description Prompt:
Build a three-floor public building with a small lift and destination requests; users schedule trips while boarding order, capacity markers, and waiting positions remain visible. Use Three.js from cdnjs in a single HTML file, with low-poly forms.
Acceptance criteria: Make adding a floor request a local button action in the gallery, then validate that boarding, queue order, and served floor update.
Technical checks: Use a local button to add a floor request. Verify that the wait positions, boarding order, served floor, and served count update together.
Return one complete HTML document. The file must run in a sandbox allowing inline scripts and the cdnjs Three.js r160 module. Construct procedural assets, use local event handlers and avoid remote assets, runtime network requests besides Three.js, pointer lock and native form submission. Keep the main requested geometry visible in the initial view.
Working Three.js Starter (shared-lift-traffic-planning-x0432):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#08111f">
<title>Vertical Commons — Public Building Lift</title>
<style>
:root {
color-scheme: dark;
--bg: #08111f;
--panel: #0d1828;
--panel-2: #111f32;
--line: #23364c;
--text: #edf5fb;
--muted: #8da2b8;
--mint: #66e2c4;
--amber: #ffbf69;
--blue: #7eb9ff;
--danger: #ff7f86;
--shadow: 0 18px 60px rgba(0, 0, 0, .28);
}
* {
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 {
font: inherit;
}
button:focus-visible {
outline: 2px solid var(--mint);
outline-offset: 3px;
}
.app-shell {
width: 100%;
height: 100%;
display: grid;
grid-template-rows: 68px minmax(0, 1fr);
}
.topbar {
position: relative;
z-index: 20;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 0 24px;
border-bottom: 1px solid var(--line);
background: rgba(8, 17, 31, .96);
}
.brand {
display: flex;
align-items: center;
min-width: 0;
gap: 13px;
}
.brand-mark {
position: relative;
width: 36px;
height: 36px;
flex: 0 0 auto;
border: 1px solid rgba(102, 226, 196, .5);
border-radius: 10px;
background: linear-gradient(145deg, rgba(102, 226, 196, .18), rgba(126, 185, 255, .04));
overflow: hidden;
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
left: 10px;
width: 0;
height: 0;
border-left: 8px solid transparent;
border-right: 8px solid transparent;
}
.brand-mark::before {
top: 8px;
border-bottom: 8px solid var(--mint);
}
.brand-mark::after {
bottom: 8px;
border-top: 8px solid var(--mint);
}
.brand-copy {
min-width: 0;
}
.brand-copy strong {
display: block;
font-size: 14px;
letter-spacing: .14em;
text-transform: uppercase;
white-space: nowrap;
}
.brand-copy span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 11px;
letter-spacing: .08em;
white-space: nowrap;
}
.top-meta {
display: flex;
align-items: center;
gap: 9px;
}
.top-pill {
display: inline-flex;
align-items: center;
gap: 7px;
height: 30px;
padding: 0 11px;
border: 1px solid var(--line);
border-radius: 999px;
color: #b9c9d9;
font-size: 10px;
font-weight: 800;
letter-spacing: .1em;
text-transform: uppercase;
white-space: nowrap;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--mint);
box-shadow: 0 0 0 4px rgba(102, 226, 196, .1), 0 0 14px rgba(102, 226, 196, .65);
}
.main-layout {
min-height: 0;
display: grid;
grid-template-columns: 370px minmax(0, 1fr);
}
.sidebar {
position: relative;
z-index: 10;
min-height: 0;
overflow-y: auto;
padding: 18px;
border-right: 1px solid var(--line);
background:
radial-gradient(circle at 20% 0%, rgba(102, 226, 196, .055), transparent 34%),
var(--panel);
scrollbar-width: thin;
scrollbar-color: #31465d transparent;
}
.panel {
margin-bottom: 13px;
padding: 16px;
border: 1px solid var(--line);
border-radius: 16px;
background: linear-gradient(145deg, rgba(18, 32, 50, .97), rgba(11, 23, 38, .97));
box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
}
.panel-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 14px;
}
.eyebrow {
margin: 0 0 5px;
color: var(--mint);
font-size: 9px;
font-weight: 900;
letter-spacing: .18em;
text-transform: uppercase;
}
h1,
h2,
p {
margin-top: 0;
}
h1 {
margin-bottom: 5px;
font-size: 21px;
line-height: 1.12;
letter-spacing: -.02em;
}
h2 {
margin-bottom: 0;
font-size: 14px;
letter-spacing: .02em;
}
.micro-copy {
margin-bottom: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.local-badge {
flex: 0 0 auto;
padding: 5px 7px;
border: 1px solid rgba(102, 226, 196, .28);
border-radius: 6px;
color: var(--mint);
background: rgba(102, 226, 196, .06);
font-size: 8px;
font-weight: 900;
letter-spacing: .12em;
text-transform: uppercase;
}
.control-label {
display: flex;
align-items: center;
justify-content: space-between;
margin: 12px 0 7px;
color: #c5d2df;
font-size: 9px;
font-weight: 850;
letter-spacing: .14em;
text-transform: uppercase;
}
.control-label span:last-child {
color: #657d94;
font-weight: 700;
letter-spacing: .05em;
}
.segmented {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
}
.segmented button {
min-height: 35px;
padding: 7px 8px;
border: 1px solid #2a3d53;
border-radius: 9px;
color: #9fb2c6;
background: #0c1726;
cursor: pointer;
font-size: 11px;
font-weight: 800;
transition: border-color .18s ease, background .18s ease, color .18s ease,
transform .18s ease;
}
.segmented button:hover {
transform: translateY(-1px);
border-color: #45617e;
color: var(--text);
}
.segmented button.selected {
border-color: var(--mint);
color: #071912;
background: var(--mint);
box-shadow: 0 0 0 3px rgba(102, 226, 196, .08);
}
.segmented.destination button.selected {
border-color: var(--amber);
color: #211406;
background: var(--amber);
box-shadow: 0 0 0 3px rgba(255, 191, 105, .08);
}
.primary-action {
width: 100%;
min-height: 44px;
margin-top: 14px;
border: 0;
border-radius: 11px;
color: #071912;
background: linear-gradient(135deg, #79efd0, #53cdae);
box-shadow: 0 10px 24px rgba(45, 190, 153, .16);
cursor: pointer;
font-size: 12px;
font-weight: 900;
letter-spacing: .04em;
transition: transform .18s ease, filter .18s ease;
}
.primary-action:hover {
transform: translateY(-2px);
filter: brightness(1.06);
}
.primary-action:active {
transform: translateY(0);
}
.request-message {
min-height: 30px;
margin: 9px 2px 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.request-message.error {
color: var(--danger);
}
.request-message.success {
color: var(--mint);
}
.gallery-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin: 15px 0 8px;
}
.gallery-title strong {
font-size: 10px;
letter-spacing: .13em;
text-transform: uppercase;
}
.gallery-title span {
color: #657d94;
font-size: 9px;
}
.floor-gallery {
display: grid;
gap: 7px;
}
.floor-card {
display: grid;
grid-template-columns: 43px minmax(0, 1fr) 70px;
align-items: center;
gap: 9px;
min-height: 60px;
padding: 8px;
border: 1px solid #26394f;
border-radius: 11px;
background: rgba(8, 18, 31, .66);
transition: border-color .18s ease, background .18s ease;
}
.floor-card:hover {
border-color: #3d566f;
background: rgba(11, 25, 42, .9);
}
.floor-number {
display: grid;
place-items: center;
width: 43px;
height: 43px;
border-radius: 10px;
color: var(--mint);
background: rgba(102, 226, 196, .08);
font-size: 11px;
font-weight: 900;
letter-spacing: .06em;
}
.floor-card:nth-child(2) .floor-number {
color: var(--blue);
background: rgba(126, 185, 255, .08);
}
.floor-card:nth-child(3) .floor-number {
color: var(--amber);
background: rgba(255, 191, 105, .08);
}
.floor-summary {
min-width: 0;
}
.floor-summary strong {
display: block;
overflow: hidden;
color: #dbe7f1;
font-size: 10px;
text-overflow: ellipsis;
white-space: nowrap;
}
.floor-summary span {
display: block;
margin-top: 4px;
overflow: hidden;
color: #71889e;
font-size: 9px;
text-overflow: ellipsis;
white-space: nowrap;
}
.quick-add {
min-height: 33px;
padding: 0 8px;
border: 1px solid #35506a;
border-radius: 8px;
color: #b8cadb;
background: #122236;
cursor: pointer;
font-size: 9px;
font-weight: 850;
transition: color .18s ease, border-color .18s ease, background .18s ease;
}
.quick-add:hover {
border-color: var(--mint);
color: var(--mint);
background: rgba(102, 226, 196, .08);
}
.live-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.live-heading .live-dot {
flex: 0 0 auto;
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.metric {
min-height: 66px;
padding: 10px 11px;
border: 1px solid #293d53;
border-radius: 11px;
background: rgba(7, 16, 28, .66);
}
.metric-label {
display: block;
margin-bottom: 7px;
color: #71889e;
font-size: 8px;
font-weight: 900;
letter-spacing: .12em;
text-transform: uppercase;
}
.metric-value {
display: block;
font-size: 20px;
font-weight: 850;
letter-spacing: -.02em;
}
.metric-value.pulse {
animation: metricPulse .45s ease;
}
@keyframes metricPulse {
50% {
color: var(--mint);
transform: scale(1.04);
}
}
.capacity-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-top: 11px;
padding: 9px 10px;
border: 1px solid #293d53;
border-radius: 10px;
background: rgba(7, 16, 28, .52);
}
.capacity-row span:first-child {
color: #8fa4b9;
font-size: 9px;
font-weight: 800;
letter-spacing: .09em;
text-transform: uppercase;
}
.capacity-pips {
display: flex;
gap: 5px;
}
.capacity-pip {
width: 10px;
height: 10px;
border: 1px solid #47617b;
border-radius: 50%;
background: #17263a;
transition: background .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.capacity-pip.active {
border-color: var(--amber);
background: var(--amber);
box-shadow: 0 0 9px rgba(255, 191, 105, .5);
}
.lift-status {
min-height: 32px;
margin: 9px 1px 12px;
color: #91a7bb;
font-size: 10px;
line-height: 1.45;
}
.section-minihead {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin: 3px 0 8px;
}
.section-minihead strong {
font-size: 9px;
letter-spacing: .13em;
text-transform: uppercase;
}
.section-minihead span {
color: #657d94;
font-size: 9px;
}
.boarding-list {
display: grid;
gap: 5px;
margin: 0;
padding: 0;
list-style: none;
}
.boarding-row {
display: grid;
grid-template-columns: 23px minmax(0, 1fr) auto;
align-items: center;
gap: 8px;
min-height: 32px;
padding: 5px 8px;
border: 1px solid rgba(42, 61, 83, .8);
border-radius: 8px;
background: rgba(7, 16, 28, .52);
}
.boarding-row .rank {
color: #617991;
font-size: 9px;
font-weight: 900;
text-align: center;
}
.boarding-row .passenger {
min-width: 0;
color: #dbe7f1;
font-size: 10px;
font-weight: 800;
white-space: nowrap;
}
.boarding-row .route {
display: block;
margin-top: 2px;
color: #71889e;
font-size: 8px;
font-weight: 600;
}
.boarding-row .state {
padding: 3px 5px;
border-radius: 5px;
color: var(--blue);
background: rgba(126, 185, 255, .08);
font-size: 7px;
font-weight: 900;
letter-spacing: .08em;
text-transform: uppercase;
}
.boarding-row.onboard .state {
color: var(--mint);
background: rgba(102, 226, 196, .08);
}
.validation-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.validation-cell {
min-width: 0;
padding: 9px;
border: 1px solid #293d53;
border-radius: 9px;
background: rgba(7, 16, 28, .56);
}
.validation-cell span {
display: block;
margin-bottom: 5px;
color: #6f879d;
font-size: 7px;
font-weight: 900;
letter-spacing: .1em;
text-transform: uppercase;
}
.validation-cell b {
display: block;
overflow: hidden;
color: #dce8f2;
font-size: 10px;
text-overflow: ellipsis;
white-space: nowrap;
}
.activity-list {
display: grid;
gap: 5px;
margin-top: 9px;
}
.activity-item {
display: flex;
align-items: flex-start;
gap: 8px;
color: #8197ab;
font-size: 9px;
line-height: 1.4;
}
.activity-item::before {
content: "";
width: 5px;
height: 5px;
flex: 0 0 auto;
margin-top: 4px;
border-radius: 50%;
background: #527089;
}
.activity-item:first-child {
color: #c8d7e4;
}
.activity-item:first-child::before {
background: var(--mint);
box-shadow: 0 0 8px rgba(102, 226, 196, .5);
}
.viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #08111f;
}
.viewport canvas {
position: absolute;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
.viewport canvas:active {
cursor: grabbing;
}
.scene-overlay {
position: absolute;
z-index: 4;
pointer-events: none;
}
.scene-title {
top: 20px;
left: 22px;
}
.scene-title strong {
display: block;
color: #dce8f2;
font-size: 10px;
letter-spacing: .16em;
text-transform: uppercase;
}
.scene-title span {
display: block;
margin-top: 6px;
color: #71889e;
font-size: 9px;
letter-spacing: .08em;
}
.scene-tools {
right: 18px;
bottom: 18px;
display: flex;
align-items: center;
gap: 8px;
pointer-events: auto;
}
.camera-help {
padding: 8px 10px;
border: 1px solid rgba(49, 70, 93, .7);
border-radius: 8px;
color: #71889e;
background: rgba(8, 17, 31, .74);
backdrop-filter: blur(8px);
font-size: 9px;
}
.reset-view {
min-height: 31px;
padding: 0 10px;
border: 1px solid #38536d;
border-radius: 8px;
color: #b3c5d6;
background: rgba(12, 25, 41, .88);
cursor: pointer;
font-size: 9px;
font-weight: 800;
}
.legend {
left: 20px;
bottom: 18px;
display: flex;
align-items: center;
gap: 13px;
padding: 8px 10px;
border: 1px solid rgba(49, 70, 93, .7);
border-radius: 8px;
color: #71889e;
background: rgba(8, 17, 31, .72);
backdrop-filter: blur(8px);
font-size: 9px;
}
.legend-item {
display: flex;
align-items: center;
gap: 5px;
}
.legend-swatch {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--mint);
}
.legend-swatch.waiting {
background: var(--blue);
}
.legend-swatch.served {
background: var(--amber);
}
.toast {
position: absolute;
z-index: 8;
left: 50%;
top: 18px;
max-width: min(430px, calc(100% - 36px));
padding: 10px 14px;
border: 1px solid rgba(102, 226, 196, .38);
border-radius: 10px;
color: #dffbf4;
background: rgba(10, 30, 38, .92);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
font-size: 10px;
font-weight: 750;
line-height: 1.4;
opacity: 0;
pointer-events: none;
transform: translate(-50%, -12px);
transition: opacity .22s ease, transform .22s ease;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 980px) {
.main-layout {
grid-template-columns: 330px minmax(0, 1fr);
}
.sidebar {
padding: 13px;
}
.panel {
padding: 13px;
}
.top-pill:nth-child(2) {
display: none;
}
}
@media (max-width: 720px) {
html,
body {
overflow: auto;
}
.app-shell {
min-height: 100%;
height: auto;
grid-template-rows: 58px auto;
}
.topbar {
padding: 0 14px;
}
.brand-copy span,
.top-pill {
display: none;
}
.main-layout {
min-height: calc(100vh - 58px);
grid-template-columns: 1fr;
grid-template-rows: auto 58vh;
}
.sidebar {
max-height: none;
overflow: visible;
border-right: 0;
border-bottom: 1px solid var(--line);
}
.viewport {
min-height: 58vh;
}
.scene-title {
top: 14px;
left: 14px;
}
.legend {
left: 12px;
bottom: 12px;
gap: 8px;
}
.camera-help {
display: none;
}
}
</style>
</head>
<body>
<div class="app-shell">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div class="brand-copy">
<strong>Vertical Commons</strong>
<span>Public building · lift request study</span>
</div>
</div>
<div class="top-meta" aria-label="Building information">
<span class="top-pill">3 public floors</span>
<span class="top-pill">4-person lift</span>
<span class="top-pill"><i class="live-dot"></i>Live dispatch</span>
</div>
</header>
<main class="main-layout">
<aside class="sidebar" aria-label="Lift request controls and live status">
<section class="panel">
<div class="panel-heading">
<div>
<p class="eyebrow">Local request gallery</p>
<h1>Schedule a trip</h1>
<p class="micro-copy">Choose a pickup and destination, then add the request locally.</p>
</div>
<span class="local-badge">No form</span>
</div>
<div class="control-label">
<span>Pickup floor</span>
<span id="pickupHint">L01</span>
</div>
<div class="segmented" id="pickupControls" aria-label="Pickup floor">
<button type="button" class="selected" data-pickup="0" aria-pressed="true">L01</button>
<button type="button" data-pickup="1" aria-pressed="false">L02</button>
<button type="button" data-pickup="2" aria-pressed="false">L03</button>
</div>
<div class="control-label">
<span>Destination floor</span>
<span id="destinationHint">L02</span>
</div>
<div class="segmented destination" id="destinationControls" aria-label="Destination floor">
<button type="button" data-destination="0" aria-pressed="false">L01</button>
<button type="button" class="selected" data-destination="1" aria-pressed="true">L02</button>
<button type="button" data-destination="2" aria-pressed="false">L03</button>
</div>
<button type="button" class="primary-action" id="addRequestBtn">+ Add floor request</button>
<p class="request-message" id="requestMessage" role="status">Ready — add a request to update the floor queue.</p>
<div class="gallery-title">
<strong>Floor request gallery</strong>
<span>Click + to queue</span>
</div>
<div class="floor-gallery" id="floorGallery">
<article class="floor-card">
<div class="floor-number">L01</div>
<div class="floor-summary">
<strong id="floorCount0">1 waiting</strong>
<span id="miniQueue0">A03 → L03</span>
</div>
<button type="button" class="quick-add" data-add-floor="0">+ Add floor</button>
</article>
<article class="floor-card">
<div class="floor-number">L02</div>
<div class="floor-summary">
<strong id="floorCount1">1 waiting</strong>
<span id="miniQueue1">A04 → L03</span>
</div>
<button type="button" class="quick-add" data-add-floor="1">+ Add floor</button>
</article>
<article class="floor-card">
<div class="floor-number">L03</div>
<div class="floor-summary">
<strong id="floorCount2">1 waiting</strong>
<span id="miniQueue2">A05 → L01</span>
</div>
<button type="button" class="quick-add" data-add-floor="2">+ Add floor</button>
</article>
</div>
</section>
<section class="panel">
<div class="live-heading">
<div>
<p class="eyebrow">Lift 01</p>
<h2>Live capacity & boarding</h2>
</div>
<i class="live-dot" aria-hidden="true"></i>
</div>
<div class="metric-grid">
<div class="metric">
<span class="metric-label">Capacity</span>
<strong class="metric-value" id="occupancyValue">2 / 4</strong>
</div>
<div class="metric">
<span class="metric-label">Served floor</span>
<strong class="metric-value" id="servedFloorValue">L01</strong>
</div>
</div>
<div class="capacity-row">
<span>Capacity markers</span>
<div class="capacity-pips" aria-label="Two of four lift places occupied">
<i class="capacity-pip active"></i>
<i class="capacity-pip active"></i>
<i class="capacity-pip"></i>
<i class="capacity-pip"></i>
</div>
</div>
<p class="lift-status" id="currentStatus">Ready for local requests · L01</p>
<div class="section-minihead">
<strong>Boarding order</strong>
<span id="boardingTotal">2 onboard · 3 waiting</span>
</div>
<ol class="boarding-list" id="boardingList"></ol>
</section>
<section class="panel">
<div class="section-minihead">
<strong>Request validation</strong>
<span>Live state</span>
</div>
<div class="validation-grid">
<div class="validation-cell">
<span>Queue order</span>
<b id="queueValidation">L01 · #1</b>
</div>
<div class="validation-cell">
<span>Boarding</span>
<b id="boardingValidation">A01 · A02</b>
</div>
<div class="validation-cell">
<span>Served floor</span>
<b id="servedValidation">L01</b>
</div>
</div>
<div class="activity-list" id="activityList" aria-label="Recent lift activity"></div>
</section>
</aside>
<section class="viewport" id="viewport" aria-label="Interactive three-dimensional cutaway of a public building">
<div class="scene-overlay scene-title">
<strong>Cutaway model / floor stack</strong>
<span>Procedural low-poly building · custom orbit camera</span>
</div>
<div class="scene-overlay legend" aria-hidden="true">
<span class="legend-item"><i class="legend-swatch"></i>Onboard</span>
<span class="legend-item"><i class="legend-swatch waiting"></i>Waiting</span>
<span class="legend-item"><i class="legend-swatch served"></i>Served floor</span>
</div>
<div class="scene-overlay scene-tools">
<span class="camera-help">Drag to orbit · scroll to zoom · double-click to reset</span>
<button type="button" class="reset-view" id="resetView">Reset view</button>
</div>
<div class="toast" id="toast" role="status" aria-live="polite"></div>
</section>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const FLOOR_COUNT = 3;
const FLOOR_HEIGHT = 4.4;
const CAPACITY = 4;
const viewport = document.getElementById("viewport");
const floorName = (floor) => `L${String(floor + 1).padStart(2, "0")}`;
const passengerColors = [0x66e2c4, 0x7eb9ff, 0xffbf69, 0xd19cff, 0xff8f9d, 0x85e070];
const state = {
selectedPickup: 0,
selectedDestination: 1,
carFloor: 0,
visualFloor: 0,
servedFloor: 0,
targetFloor: null,
travelFrom: 0,
tripPurpose: null,
phase: "idle",
phaseTime: 0,
doorAmount: 0,
nextId: 6,
sequence: 0,
lastAddedId: null,
queues: [
[
{ id: "A03", pickup: 0, destination: 2, color: passengerColors[2], sequence: 3 }
],
[
{ id: "A04", pickup: 1, destination: 2, color: passengerColors[3], sequence: 4 }
],
[
{ id: "A05", pickup: 2, destination: 0, color: passengerColors[4], sequence: 5 }
]
],
occupants: [
{ id: "A01", pickup: 0, destination: 1, color: passengerColors[0], sequence: 1 },
{ id: "A02", pickup: 0, destination: 2, color: passengerColors[1], sequence: 2 }
],
activity: [
"Dispatch ready at L01 with 2 passengers onboard",
"2 of 4 capacity markers are occupied",
"3 requests are waiting across the public floors"
]
};
const ui = {
pickupControls: document.getElementById("pickupControls"),
destinationControls: document.getElementById("destinationControls"),
pickupHint: document.getElementById("pickupHint"),
destinationHint: document.getElementById("destinationHint"),
addRequestBtn: document.getElementById("addRequestBtn"),
requestMessage: document.getElementById("requestMessage"),
floorGallery: document.getElementById("floorGallery"),
occupancyValue: document.getElementById("occupancyValue"),
servedFloorValue: document.getElementById("servedFloorValue"),
currentStatus: document.getElementById("currentStatus"),
boardingList: document.getElementById("boardingList"),
boardingTotal: document.getElementById("boardingTotal"),
queueValidation: document.getElementById("queueValidation"),
boardingValidation: document.getElementById("boardingValidation"),
servedValidation: document.getElementById("servedValidation"),
activityList: document.getElementById("activityList"),
toast: document.getElementById("toast"),
resetView: document.getElementById("resetView")
};
let toastTimer = 0;
function showToast(message) {
ui.toast.textContent = message;
ui.toast.classList.add("show");
window.clearTimeout(toastTimer);
toastTimer = window.setTimeout(() => ui.toast.classList.remove("show"), 2400);
}
function addActivity(message) {
state.activity.unshift(message);
state.activity = state.activity.slice(0, 4);
renderActivity();
}
function renderActivity() {
ui.activityList.replaceChildren();
state.activity.forEach((message) => {
const item = document.createElement("div");
item.className = "activity-item";
item.textContent = message;
ui.activityList.appendChild(item);
});
}
function makeMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.76,
metalness: 0.06,
flatShading: true,
...options
});
}
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x08111f);
scene.fog = new THREE.Fog(0x08111f, 34, 70);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 120);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute("aria-label", "Three-dimensional cutaway public building with lift queues");
viewport.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xc7e9ff, 0x152033, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0d4, 3.25);
sun.position.set(12, 23, 15);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.bias = -0.0004;
scene.add(sun);
const coolFill = new THREE.PointLight(0x64d9ff, 24, 24, 2);
coolFill.position.set(-8, 8, 7);
scene.add(coolFill);
const warmFill = new THREE.PointLight(0xffb86a, 18, 20, 2);
warmFill.position.set(8, 11, 2);
scene.add(warmFill);
const building = new THREE.Group();
scene.add(building);
const slabMaterial = makeMaterial(0x27384a);
const edgeMaterial = makeMaterial(0x3d566c);
const structureMaterial = makeMaterial(0x18293a);
const rearMaterial = makeMaterial(0x142638);
const sideMaterial = makeMaterial(0x7db6cf, {
transparent: true,
opacity: 0.11,
depthWrite: false,
roughness: 0.4
});
const floorAccents = [0x66e2c4, 0x7eb9ff, 0xffbf69];
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(...size), material);
mesh.position.set(...position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(parent, radiusTop, radiusBottom, height, position, material, segments = 8) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
material
);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function makeTextSprite(text, options = {}) {
const {
width = 512,
height = 160,
background = "rgba(8, 20, 34, 0.88)",
border = "#38536d",
color = "#e9f3fa",
accent = "#66e2c4",
fontSize = 54,
scale = [2.25, 0.7],
depthTest = false
} = options;
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, width, height);
roundedRect(ctx, 8, 8, width - 16, height - 16, 22);
ctx.fillStyle = background;
ctx.fill();
ctx.strokeStyle = border;
ctx.lineWidth = 5;
ctx.stroke();
ctx.fillStyle = accent;
roundedRect(ctx, 8, 8, 13, height - 16, 7);
ctx.fill();
ctx.fillStyle = color;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = `800 ${fontSize}px system-ui, sans-serif`;
ctx.fillText(text, width / 2 + 8, height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(scale[0], scale[1], 1);
sprite.renderOrder = 8;
return sprite;
}
const groundMaterial = makeMaterial(0x0b1725);
const ground = new THREE.Mesh(new THREE.PlaneGeometry(70, 70), groundMaterial);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.53;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(60, 30, 0x28465d, 0x172b3e);
grid.position.y = -0.505;
grid.material.transparent = true;
grid.material.opacity = 0.46;
scene.add(grid);
const floorHalos = [];
for (let floor = 0; floor < FLOOR_COUNT; floor += 1) {
const y = floor * FLOOR_HEIGHT;
addBox(building, [8.4, 0.28, 10], [-5.8, y - 0.14, 0], slabMaterial);
addBox(building, [8.4, 0.28, 10], [5.8, y - 0.14, 0], slabMaterial);
addBox(building, [3.2, 0.28, 5.2], [0, y - 0.14, 2.6], slabMaterial);
addBox(building, [3.2, 0.28, 1.8], [0, y - 0.14, -4.1], slabMaterial);
addBox(building, [19.8, 0.07, 0.06], [0, y + 0.02, 5.02], edgeMaterial, false);
addBox(building, [19.8, 0.07, 0.06], [0, y + 0.02, -4.96], edgeMaterial, false);
addBox(
building,
[3.1, 0.07, 0.06],
[0, y + 0.02, 5.02],
makeMaterial(floorAccents[floor], { emissive: floorAccents[floor], emissiveIntensity: 0.3 }),
false
);
addBox(building, [20, 4.05, 0.22], [0, y + 2.02, -5.06], rearMaterial);
addBox(building, [0.16, 4.05, 10], [10.02, y + 2.02, 0], sideMaterial, false);
addBox(building, [0.16, 4.05, 10], [-10.02, y + 2.02, 0], sideMaterial, false);
addBox(
building,
[19.5, 0.045, 0.05],
[0, y + 1.08, -4.93],
makeMaterial(floorAccents[floor], { emissive: floorAccents[floor], emissiveIntensity: 0.18 }),
false
);
for (let x = -9; x <= 9; x += 3) {
addBox(building, [0.08, 3.8, 0.08], [x, y + 2.02, -4.9], edgeMaterial, false);
}
const sign = makeTextSprite(`FLOOR ${floorName(floor)}`, {
background: "rgba(8, 20, 34, 0.9)",
border: "#35536c",
accent: `#${floorAccents[floor].toString(16).padStart(6, "0")}`,
scale: [2.25, 0.7],
fontSize: 46
});
sign.position.set(-7.6, y + 0.66, 4.55);
building.add(sign);
const halo = new THREE.Mesh(
new THREE.TorusGeometry(0.72, 0.055, 6, 28),
makeMaterial(0x345269, {
emissive: 0xffbf69,
emissiveIntensity: 0,
transparent: true,
opacity: 0.6
})
);
halo.rotation.x = Math.PI / 2;
halo.position.set(-7.6, y + 0.055, 4.55);
building.add(halo);
floorHalos.push(halo);
const benchMaterial = makeMaterial(0x536b7a);
const benchDark = makeMaterial(0x24384a);
addBox(building, [2.5, 0.18, 0.72], [-5.8, y + 0.55, 1.3], benchMaterial);
addBox(building, [2.5, 0.62, 0.14], [-5.8, y + 0.88, 0.98], benchDark);
addBox(building, [0.18, 0.5, 0.55], [-6.8, y + 0.25, 1.3], benchDark);
addBox(building, [0.18, 0.5, 0.55], [-4.8, y + 0.25, 1.3], benchDark);
const planterMaterial = makeMaterial(0x4f6570);
const leafMaterial = makeMaterial(0x4e8a6a);
addCylinder(building, 0.35, 0.28, 0.62, [8.4, y + 0.31, 2.7], planterMaterial, 7);
const shrub = new THREE.Mesh(new THREE.IcosahedronGeometry(0.58, 0), leafMaterial);
shrub.position.set(8.4, y + 0.95, 2.7);
shrub.castShadow = true;
building.add(shrub);
for (let position = 0; position < 4; position += 1) {
const marker = new THREE.Mesh(
new THREE.RingGeometry(0.25, 0.33, 12),
new THREE.MeshBasicMaterial({
color: floorAccents[floor],
transparent: true,
opacity: 0.32,
side: THREE.DoubleSide,
depthWrite: false
})
);
marker.rotation.x = -Math.PI / 2;
marker.position.set(2.25, y + 0.025, 0.98 + position * 0.7);
building.add(marker);
}
}
const columnHeight = FLOOR_HEIGHT * FLOOR_COUNT + 0.3;
for (const x of [-9.75, 9.75]) {
for (const z of [-4.78, 4.78]) {
addBox(
building,
[0.34, columnHeight, 0.34],
[x, columnHeight / 2 - 0.2, z],
structureMaterial
);
}
}
for (let floor = 0; floor < FLOOR_COUNT; floor += 1) {
const y = floor * FLOOR_HEIGHT;
addBox(building, [19.8, 0.18, 0.2], [0, y + 4.1, -4.78], edgeMaterial);
}
const shaftFrameMaterial = makeMaterial(0x294359, {
roughness: 0.48,
metalness: 0.48
});
const shaftGlassMaterial = makeMaterial(0x87b9d2, {
transparent: true,
opacity: 0.075,
depthWrite: false,
roughness: 0.32
});
for (const x of [-1.72, 1.72]) {
for (const z of [-3.08, 0.38]) {
addBox(
building,
[0.16, columnHeight, 0.16],
[x, columnHeight / 2 - 0.2, z],
shaftFrameMaterial
);
}
}
addBox(
building,
[3.45, columnHeight, 0.05],
[0, columnHeight / 2 - 0.2, -3.1],
shaftGlassMaterial,
false
);
addBox(
building,
[0.05, columnHeight, 3.45],
[-1.73, columnHeight / 2 - 0.2, -1.36],
shaftGlassMaterial,
false
);
addBox(
building,
[0.05, columnHeight, 3.45],
[1.73, columnHeight / 2 - 0.2, -1.36],
shaftGlassMaterial,
false
);
const shaftLightMaterial = makeMaterial(0x66e2c4, {
emissive: 0x66e2c4,
emissiveIntensity: 1.1
});
addBox(
building,
[0.055, columnHeight - 0.8, 0.055],
[-1.65, columnHeight / 2 - 0.2, 0.41],
shaftLightMaterial,
false
);
const liftSign = makeTextSprite("LIFT 01 / 4 PERSON", {
width: 640,
height: 150,
background: "rgba(8, 20, 34, 0.92)",
border: "#4d718a",
accent: "#ffbf69",
fontSize: 39,
scale: [3.5, 0.82]
});
liftSign.position.set(0, columnHeight - 0.05, 0.55);
building.add(liftSign);
const car = new THREE.Group();
car.position.z = -1.36;
scene.add(car);
const carFrameMaterial = makeMaterial(0x5fc9bd, {
roughness: 0.42,
metalness: 0.32
});
const carDarkMaterial = makeMaterial(0x183043);
const carGlassMaterial = makeMaterial(0x9ad7e1, {
transparent: true,
opacity: 0.26,
depthWrite: false,
roughness: 0.24
});
const doorMaterial = makeMaterial(0xa3c9cb, {
transparent: true,
opacity: 0.74,
depthWrite: false,
roughness: 0.38
});
addBox(car, [2.95, 0.17, 2.95], [0, 0.08, 0], carFrameMaterial);
addBox(car, [2.95, 0.17, 2.95], [0, 3.25, 0], carDarkMaterial);
addBox(car, [2.95, 3.15, 0.08], [0, 1.66, -1.45], carGlassMaterial, false);
addBox(car, [0.08, 3.15, 2.9], [-1.45, 1.66, 0], carGlassMaterial, false);
addBox(car, [0.08, 3.15, 2.9], [1.45, 1.66, 0], carGlassMaterial, false);
const leftDoor = addBox(car, [1.37, 2.92, 0.09], [-0.69, 1.57, 1.47], doorMaterial, false);
const rightDoor = addBox(car, [1.37, 2.92, 0.09], [0.69, 1.57, 1.47], doorMaterial, false);
addBox(car, [0.045, 3.05, 0.06], [0, 1.57, 1.53], shaftFrameMaterial, false);
const capacityLights = [];
for (let index = 0; index < CAPACITY; index += 1) {
const lightMaterial = makeMaterial(index < state.occupants.length ? 0xffbf69 : 0x294258, {
emissive: index < state.occupants.length ? 0xffbf69 : 0x000000,
emissiveIntensity: index < state.occupants.length ? 1.4 : 0,
roughness: 0.35
});
const light = new THREE.Mesh(new THREE.SphereGeometry(0.105, 8, 6), lightMaterial);
light.position.set(-0.75 + index * 0.5, 1.78, -1.35);
car.add(light);
capacityLights.push(light);
}
const carPassengerLayer = new THREE.Group();
car.add(carPassengerLayer);
function createPerson(passenger, options = {}) {
const group = new THREE.Group();
const { withLabel = true, scale = 1 } = options;
const clothing = makeMaterial(passenger.color, {
roughness: 0.86,
metalness: 0
});
const skin = makeMaterial(0xe5b895);
const dark = makeMaterial(0x233448);
addCylinder(group, 0.19, 0.26, 0.7, [0, 0.66, 0], clothing, 6);
const head = new THREE.Mesh(new THREE.SphereGeometry(0.19, 8, 6), skin);
head.position.y = 1.18;
head.castShadow = true;
group.add(head);
addCylinder(group, 0.075, 0.085, 0.38, [-0.105, 0.22, 0], dark, 6);
addCylinder(group, 0.075, 0.085, 0.38, [0.105, 0.22, 0], dark, 6);
addCylinder(group, 0.065, 0.07, 0.5, [-0.24, 0.65, 0], clothing, 6);
addCylinder(group, 0.065, 0.07, 0.5, [0.24, 0.65, 0], clothing, 6);
const positionRing = new THREE.Mesh(
new THREE.RingGeometry(0.29, 0.36, 12),
new THREE.MeshBasicMaterial({
color: passenger.color,
transparent: true,
opacity: 0.52,
side: THREE.DoubleSide,
depthWrite: false
})
);
positionRing.rotation.x = -Math.PI / 2;
positionRing.position.y = 0.025;
group.add(positionRing);
if (withLabel) {
const label = makeTextSprite(`${passenger.id} → ${floorName(passenger.destination)}`, {
width: 420,
height: 135,
background: "rgba(7, 18, 31, 0.82)",
border: "#45627b",
accent: `#${passenger.color.toString(16).padStart(6, "0")}`,
color: "#eef7fc",
fontSize: 39,
scale: [1.45, 0.47],
depthTest: true
});
label.position.y = 1.62;
group.add(label);
}
group.scale.setScalar(scale);
return group;
}
function rebuildCarPassengers() {
while (carPassengerLayer.children.length) {
const child = carPassengerLayer.children[0];
carPassengerLayer.remove(child);
}
state.occupants.forEach((passenger, index) => {
const visual = createPerson(passenger, { withLabel: false, scale: 0.82 });
visual.position.set(-0.72 + index * 0.48, 0.18, 0.38);
carPassengerLayer.add(visual);
});
capacityLights.forEach((light, index) => {
const occupied = index < state.occupants.length;
light.material.color.setHex(occupied ? 0xffbf69 : 0x294258);
light.material.emissive.setHex(occupied ? 0xffbf69 : 0x000000);
light.material.emissiveIntensity = occupied ? 1.4 : 0;
});
}
function repositionWaitingPeople() {
state.queues.forEach((queue, floor) => {
queue.forEach((passenger, index) => {
if (!passenger.visual) return;
passenger.visual.position.set(2.25, floor * FLOOR_HEIGHT + 0.035, 0.98 + index * 0.7);
});
});
}
function createWaitingVisuals() {
state.queues.forEach((queue) => {
queue.forEach((passenger) => {
passenger.visual = createPerson(passenger);
building.add(passenger.visual);
});
});
repositionWaitingPeople();
}
function removeWaitingVisual(passenger) {
if (!passenger.visual) return;
passenger.visual.parent?.remove(passenger.visual);
passenger.visual = null;
}
createWaitingVisuals();
rebuildCarPassengers();
const orbit = {
theta: 0.64,
phi: 1.08,
radius: 29,
target: new THREE.Vector3(0.8, 5.2, 0)
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
function resetCamera() {
orbit.theta = 0.64;
orbit.phi = 1.08;
orbit.radius = 29;
orbit.target.set(0.8, 5.2, 0);
updateCamera();
}
updateCamera();
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
orbit.theta -= deltaX * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi - deltaY * 0.005, 0.58, 1.43);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(orbit.radius * Math.exp(event.deltaY * 0.001), 19, 43);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
ui.resetView.addEventListener("click", resetCamera);
function resizeRenderer() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resizeRenderer);
resizeObserver.observe(viewport);
resizeRenderer();
function renderBoardingList() {
const waiting = state.queues
.flat()
.sort((a, b) => a.sequence - b.sequence);
const rows = [
...state.occupants.map((passenger) => ({ ...passenger, onboard: true })),
...waiting.map((passenger) => ({ ...passenger, onboard: false }))
];
ui.boardingList.replaceChildren();
rows.forEach((passenger, index) => {
const item = document.createElement("li");
item.className = `boarding-row${passenger.onboard ? " onboard" : ""}`;
const rank = document.createElement("span");
rank.className = "rank";
rank.textContent = String(index + 1).padStart(2, "0");
const details = document.createElement("span");
details.className = "passenger";
details.textContent = passenger.id;
const route = document.createElement("span");
route.className = "route";
route.textContent = `${floorName(passenger.pickup)} → ${floorName(passenger.destination)}`;
details.appendChild(route);
const badge = document.createElement("span");
badge.className = "state";
badge.textContent = passenger.onboard ? "Onboard" : "Waiting";
item.append(rank, details, badge);
ui.boardingList.appendChild(item);
});
ui.boardingTotal.textContent = `${state.occupants.length} onboard · ${waiting.length} waiting`;
}
function renderFloorCards() {
state.queues.forEach((queue, floor) => {
const count = document.getElementById(`floorCount${floor}`);
const miniQueue = document.getElementById(`miniQueue${floor}`);
count.textContent = `${queue.length} waiting`;
if (queue.length === 0) {
miniQueue.textContent = "No one waiting";
} else {
const visible = queue.slice(0, 2).map((passenger) =>
`${passenger.id} → ${floorName(passenger.destination)}`
).join(" · ");
miniQueue.textContent = queue.length > 2
? `${visible} +${queue.length - 2}`
: visible;
}
});
}
function renderMetrics() {
const occupancy = `${state.occupants.length} / ${CAPACITY}`;
ui.occupancyValue.textContent = occupancy;
ui.servedFloorValue.textContent = floorName(state.servedFloor);
ui.servedValidation.textContent = floorName(state.servedFloor);
const pips = document.querySelectorAll(".capacity-pip");
pips.forEach((pip, index) => pip.classList.toggle("active", index < state.occupants.length));
document.querySelector(".capacity-pips").setAttribute(
"aria-label",
`${state.occupants.length} of ${CAPACITY} lift places occupied`
);
floorHalos.forEach((halo, floor) => {
const active = floor === state.servedFloor;
halo.material.color.setHex(active ? 0xffbf69 : 0x345269);
halo.material.emissive.setHex(active ? 0xffbf69 : 0x000000);
halo.material.emissiveIntensity = active ? 1.2 : 0;
halo.material.opacity = active ? 0.9 : 0.28;
});
}
function renderValidation() {
if (!state.lastAddedId) {
const firstWaiting = state.queues.flat().sort((a, b) => a.sequence - b.sequence)[0];
ui.queueValidation.textContent = firstWaiting
? `${floorName(firstWaiting.pickup)} · #1`
: "No queue";
ui.boardingValidation.textContent = state.occupants.map((passenger) => passenger.id).join(" · ");
return;
}
const allWaiting = state.queues.flat().sort((a, b) => a.sequence - b.sequence);
const passenger = allWaiting.find((item) => item.id === state.lastAddedId);
const onboardPassenger = state.occupants.find((item) => item.id === state.lastAddedId);
if (passenger) {
const floorQueue = state.queues[passenger.pickup];
const queuePosition = floorQueue.findIndex((item) => item.id === passenger.id) + 1;
const boardingPosition = allWaiting.findIndex((item) => item.id === passenger.id) + 1;
ui.queueValidation.textContent = `${floorName(passenger.pickup)} · #${queuePosition}`;
ui.boardingValidation.textContent = `Slot ${boardingPosition} · ${passenger.id}`;
} else if (onboardPassenger) {
ui.queueValidation.textContent = `${onboardPassenger.id} boarded`;
ui.boardingValidation.textContent = `Onboard · ${onboardPassenger.id}`;
}
}
function syncUI() {
renderMetrics();
renderBoardingList();
renderFloorCards();
renderValidation();
}
function setStatus(message) {
if (ui.currentStatus.textContent !== message) {
ui.currentStatus.textContent = message;
}
}
function pulseServedFloor() {
ui.servedFloorValue.classList.remove("pulse");
void ui.servedFloorValue.offsetWidth;
ui.servedFloorValue.classList.add("pulse");
}
function syncSelection() {
ui.pickupHint.textContent = floorName(state.selectedPickup);
ui.destinationHint.textContent = floorName(state.selectedDestination);
ui.pickupControls.querySelectorAll("[data-pickup]").forEach((button) => {
const selected = Number(button.dataset.pickup) === state.selectedPickup;
button.classList.toggle("selected", selected);
button.setAttribute("aria-pressed", String(selected));
});
ui.destinationControls.querySelectorAll("[data-destination]").forEach((button) => {
const selected = Number(button.dataset.destination) === state.selectedDestination;
button.classList.toggle("selected", selected);
button.setAttribute("aria-pressed", String(selected));
});
}
function chooseDifferentDestination(pickup) {
if (state.selectedDestination === pickup) {
state.selectedDestination = pickup === 0 ? 1 : 0;
}
syncSelection();
}
function addRequest(pickup, destination) {
if (!Number.isInteger(pickup) || !Number.isInteger(destination)) {
ui.requestMessage.textContent = "Choose a valid pickup and destination floor.";
ui.requestMessage.className = "request-message error";
return;
}
if (pickup === destination) {
ui.requestMessage.textContent = "Pickup and destination must be different floors.";
ui.requestMessage.className = "request-message error";
showToast("Choose two different floors for this trip.");
return;
}
const id = `A${String(state.nextId).padStart(2, "0")}`;
state.nextId += 1;
state.sequence += 1;
const passenger = {
id,
pickup,
destination,
color: passengerColors[state.sequence % passengerColors.length],
sequence: state.sequence
};
state.queues[pickup].push(passenger);
passenger.visual = createPerson(passenger);
building.add(passenger.visual);
repositionWaitingPeople();
state.lastAddedId = id;
const queuePosition = state.queues[pickup].length;
const boardingPosition = state.queues.flat().sort((a, b) => a.sequence - b.sequence)
.findIndex((item) => item.id === id) + 1;
ui.requestMessage.textContent =
`${id} added locally to ${floorName(pickup)} · queue position ${queuePosition}.`;
ui.requestMessage.className = "request-message success";
addActivity(`${id} added to ${floorName(pickup)} queue · position ${queuePosition}`);
showToast(`${id} queued · boarding slot ${boardingPosition}`);
if (state.phase === "idle") {
if (pickup === state.carFloor) {
beginTravel(pickup, "pickup");
} else if (state.occupants.length) {
beginTravel(nearestOccupantDestination(), "destination");
} else {
beginTravel(pickup, "pickup");
}
}
syncUI();
}
function nearestOccupantDestination() {
const destinations = [...new Set(state.occupants.map((passenger) => passenger.destination))];
destinations.sort((a, b) => {
const distanceA = Math.abs(a - state.carFloor);
const distanceB = Math.abs(b - state.carFloor);
return distanceA === distanceB ? a - b : distanceA - distanceB;
});
return destinations[0] ?? state.carFloor;
}
function beginTravel(target, purpose) {
state.travelFrom = state.visualFloor;
state.targetFloor = target;
state.tripPurpose = purpose;
state.phase = "travel";
state.phaseTime = 0;
setStatus(
purpose === "pickup"
? `Collecting passengers · ${floorName(target)}`
: `Moving to destination · ${floorName(target)}`
);
}
function setPhase(phase) {
state.phase = phase;
state.phaseTime = 0;
if (phase === "open") {
setStatus(`Doors open · ${floorName(state.carFloor)}`);
} else if (phase === "boarding") {
setStatus(`Boarding in order · ${state.occupants.length} of ${CAPACITY}`);
} else if (phase === "closing") {
setStatus(`Doors closing · ${floorName(state.carFloor)}`);
} else if (phase === "idle") {
setStatus(`Ready for local requests · ${floorName(state.carFloor)}`);
}
}
function unloadAtCurrentFloor() {
const leaving = state.occupants.filter((passenger) => passenger.destination === state.carFloor);
if (!leaving.length) return;
state.occupants = state.occupants.filter(
(passenger) => passenger.destination !== state.carFloor
);
rebuildCarPassengers();
leaving.forEach((passenger) => {
addActivity(`${passenger.id} served at ${floorName(state.carFloor)}`);
});
}
function dispatchNextRequest() {
const next = state.queues.flat().sort((a, b) => a.sequence - b.sequence)[0];
if (!next) {
state.targetFloor = null;
setPhase("idle");
return;
}
beginTravel(next.pickup, "pickup");
}
function updateSimulation(delta) {
state.phaseTime += delta;
if (state.phase === "travel") {
const duration = Math.max(0.01, Math.abs(state.targetFloor - state.travelFrom) * 1.35);
const progress = THREE.MathUtils.clamp(state.phaseTime / duration, 0, 1);
const eased = progress * progress * (3 - 2 * progress);
state.visualFloor = THREE.MathUtils.lerp(state.travelFrom, state.targetFloor, eased);
if (progress >= 1) {
state.carFloor = state.targetFloor;
state.visualFloor = state.targetFloor;
state.servedFloor = state.targetFloor;
pulseServedFloor();
addActivity(`Lift reached ${floorName(state.carFloor)} · served floor updated`);
setPhase("open");
syncUI();
}
} else if (state.phase === "open") {
if (state.phaseTime >= 0.56) {
unloadAtCurrentFloor();
const hasWaiting = state.queues[state.carFloor].length > 0;
if (hasWaiting && state.occupants.length < CAPACITY) {
setPhase("boarding");
} else {
setPhase("closing");
}
syncUI();
}
} else if (state.phase === "boarding") {
const nextBoardAt = 0.26 + state.occupants.length * 0.02;
if (state.phaseTime >= nextBoardAt && state.queues[state.carFloor].length) {
const passenger = state.queues[state.carFloor].shift();
state.occupants.push(passenger);
removeWaitingVisual(passenger);
rebuildCarPassengers();
repositionWaitingPeople();
addActivity(`${passenger.id} boarded · capacity ${state.occupants.length} of ${CAPACITY}`);
syncUI();
}
if (state.phaseTime > 0.78 && (
state.occupants.length >= CAPACITY || state.queues[state.carFloor].length === 0
)) {
setPhase("closing");
}
} else if (state.phase === "closing") {
if (state.phaseTime >= 0.56) {
if (state.occupants.length) {
beginTravel(nearestOccupantDestination(), "destination");
} else {
dispatchNextRequest();
}
}
}
let doorTarget = 0;
if (state.phase === "open" || state.phase === "boarding") {
doorTarget = 1;
} else if (state.phase === "closing") {
doorTarget = Math.max(0, 1 - state.phaseTime / 0.55);
}
state.doorAmount = THREE.MathUtils.damp(state.doorAmount, doorTarget, 9, delta);
}
ui.pickupControls.addEventListener("click", (event) => {
const button = event.target.closest("[data-pickup]");
if (!button) return;
state.selectedPickup = Number(button.dataset.pickup);
syncSelection();
});
ui.destinationControls.addEventListener("click", (event) => {
const button = event.target.closest("[data-destination]");
if (!button) return;
state.selectedDestination = Number(button.dataset.destination);
syncSelection();
});
ui.addRequestBtn.addEventListener("click", () => {
addRequest(state.selectedPickup, state.selectedDestination);
});
ui.floorGallery.addEventListener("click", (event) => {
const button = event.target.closest("[data-add-floor]");
if (!button) return;
const pickup = Number(button.dataset.addFloor);
state.selectedPickup = pickup;
chooseDifferentDestination(pickup);
addRequest(pickup, state.selectedDestination);
});
syncSelection();
syncUI();
renderActivity();
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
updateSimulation(delta);
car.position.y = state.visualFloor * FLOOR_HEIGHT + 0.02;
leftDoor.position.x = -0.69 - state.doorAmount * 0.66;
rightDoor.position.x = 0.69 + state.doorAmount * 0.66;
const pulse = 1 + Math.sin(performance.now() * 0.003) * 0.045;
const servedHalo = floorHalos[state.servedFloor];
servedHalo.scale.setScalar(pulse);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```