Prompt specification
Build or customize the Three.js 3D scene "Compare queue layouts with the same voter arrivals" 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: Compare queue layouts with the same voter arrivals
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/compare-queue-layouts-with-the-same-voter-arrivals-x2472
Scene Description Prompt:
Create a standalone voxel scene in one HTML file using Three.js from cdnjs. Let users adjust a fictional polling-room layout under stated service-time assumptions. Show waiting and privacy tradeoffs while keeping the simulation separate from actual 1994 election statistics.
Working Three.js Starter (compare-queue-layouts-with-the-same-voter-arrivals-x2472):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Polling Room Lab — Illustrative Planning Sandbox</title>
<style>
:root {
--ink: #172331;
--muted: #647180;
--paper: #ffffff;
--line: #dce3e8;
--navy: #193b56;
--teal: #167d83;
--teal-soft: #dff3f1;
--amber: #d78324;
--amber-soft: #fff0d8;
--red: #bd3c42;
--red-soft: #fbe7e8;
--shadow: 0 18px 50px rgba(31, 49, 66, 0.10);
}
* { box-sizing: border-box; }
html, body {
margin: 0;
min-height: 100%;
background: #edf1f3;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
.topbar {
min-height: 76px;
padding: 14px 22px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
background: #f9fbfc;
border-bottom: 1px solid var(--line);
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
width: 42px;
height: 42px;
flex: 0 0 auto;
display: grid;
place-items: center;
border-radius: 11px;
background: var(--navy);
box-shadow: 0 7px 18px rgba(25, 59, 86, 0.20);
}
.brand-mark svg {
width: 25px;
height: 25px;
fill: none;
stroke: #fff;
stroke-width: 1.8;
stroke-linecap: round;
stroke-linejoin: round;
}
.brand h1 {
margin: 0;
font-size: 18px;
line-height: 1.2;
letter-spacing: -0.02em;
}
.brand p {
margin: 4px 0 0;
color: var(--muted);
font-size: 12px;
}
.historical-warning {
max-width: 570px;
padding: 9px 12px;
border: 1px solid #e4c992;
border-radius: 9px;
background: #fff8e9;
color: #735321;
font-size: 12px;
line-height: 1.4;
}
.workspace {
width: min(1840px, 100%);
min-height: calc(100vh - 76px);
margin: 0 auto;
padding: 16px;
display: grid;
grid-template-columns: 292px minmax(460px, 1fr) 306px;
gap: 14px;
}
.panel,
.stage-card {
min-width: 0;
border: 1px solid var(--line);
border-radius: 15px;
background: var(--paper);
box-shadow: var(--shadow);
}
.controls-panel,
.analysis-panel {
max-height: calc(100vh - 108px);
min-height: 700px;
overflow: auto;
scrollbar-width: thin;
}
.panel-heading {
padding: 18px 18px 14px;
border-bottom: 1px solid var(--line);
}
.eyebrow {
margin: 0 0 5px;
color: var(--teal);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.panel-heading h2 {
margin: 0;
font-size: 17px;
letter-spacing: -0.015em;
}
.panel-heading p {
margin: 7px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.control-section {
padding: 16px 18px;
border-bottom: 1px solid var(--line);
}
.section-title {
margin: 0 0 14px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
color: #506071;
}
.control {
margin: 0 0 18px;
}
.control:last-child { margin-bottom: 0; }
.control-head {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
margin-bottom: 8px;
}
.control label {
font-size: 12px;
font-weight: 650;
}
.control output {
color: var(--navy);
font-size: 12px;
font-weight: 800;
white-space: nowrap;
}
.control small {
display: block;
margin-top: 6px;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 5px 0;
appearance: none;
border-radius: 10px;
background: linear-gradient(
to right,
var(--teal) 0%,
var(--teal) var(--fill, 50%),
#dbe3e8 var(--fill, 50%),
#dbe3e8 100%
);
outline: none;
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
appearance: none;
border: 3px solid #fff;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 1px 6px rgba(18, 82, 88, 0.35);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #fff;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 1px 6px rgba(18, 82, 88, 0.35);
}
select {
width: 100%;
padding: 9px 10px;
border: 1px solid #cfd9df;
border-radius: 8px;
outline: none;
background: #f8fafb;
color: var(--ink);
font-size: 12px;
}
select:focus {
border-color: var(--teal);
box-shadow: 0 0 0 3px rgba(22, 125, 131, 0.10);
}
.preset-buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.preset-buttons button,
.reset-button {
padding: 9px 8px;
border: 1px solid #cfd9df;
border-radius: 8px;
background: #f7f9fa;
color: #334558;
font-size: 11px;
font-weight: 700;
}
.preset-buttons button:hover,
.reset-button:hover {
border-color: var(--teal);
color: var(--teal);
background: var(--teal-soft);
}
.reset-button {
width: 100%;
margin-top: 9px;
}
.stage-card {
min-height: 700px;
overflow: hidden;
display: grid;
grid-template-rows: auto minmax(520px, 1fr) auto;
}
.stage-header {
padding: 15px 17px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
border-bottom: 1px solid var(--line);
}
.stage-title h2 {
margin: 0;
font-size: 15px;
}
.stage-title p {
margin: 4px 0 0;
color: var(--muted);
font-size: 11px;
}
.stage-tools {
display: flex;
align-items: center;
gap: 8px;
}
.status-pill {
padding: 6px 9px;
border-radius: 999px;
background: var(--teal-soft);
color: #14686d;
font-size: 10px;
font-weight: 800;
white-space: nowrap;
}
.status-pill.warn {
color: #875415;
background: var(--amber-soft);
}
.status-pill.bad {
color: #9b3036;
background: var(--red-soft);
}
.icon-button {
width: 31px;
height: 31px;
border: 1px solid #d1dce2;
border-radius: 8px;
background: #f8fafb;
color: #42586b;
font-size: 17px;
}
#viewport {
position: relative;
min-height: 520px;
overflow: hidden;
background: #dfe8ec;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#viewport canvas:active { cursor: grabbing; }
.scene-chip {
position: absolute;
z-index: 2;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 8px;
background: rgba(255, 255, 255, 0.82);
backdrop-filter: blur(8px);
color: #405466;
font-size: 10px;
font-weight: 700;
pointer-events: none;
}
.scene-chip.top-left { top: 13px; left: 13px; }
.scene-chip.bottom-left { bottom: 13px; left: 13px; }
.camera-help {
position: absolute;
right: 13px;
bottom: 13px;
z-index: 2;
color: #536777;
font-size: 10px;
pointer-events: none;
text-align: right;
}
.stage-summary {
display: grid;
grid-template-columns: repeat(4, 1fr);
border-top: 1px solid var(--line);
background: #fbfcfd;
}
.stage-summary div {
padding: 12px 14px;
border-right: 1px solid var(--line);
}
.stage-summary div:last-child { border-right: 0; }
.stage-summary span {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.stage-summary strong {
display: block;
margin-top: 4px;
font-size: 13px;
}
.analysis-panel { padding-bottom: 14px; }
.metric-grid {
padding: 15px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
border-bottom: 1px solid var(--line);
}
.metric {
min-height: 88px;
padding: 12px;
border: 1px solid #e0e6ea;
border-radius: 11px;
background: #fbfcfd;
}
.metric .label {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric .value {
margin-top: 8px;
font-size: 21px;
font-weight: 800;
letter-spacing: -0.03em;
}
.metric .sub {
margin-top: 3px;
color: var(--muted);
font-size: 9px;
line-height: 1.3;
}
.metric.alert {
border-color: #e3b7ba;
background: #fff8f8;
}
.metric.alert .value { color: var(--red); }
.analysis-section {
padding: 16px 17px;
border-bottom: 1px solid var(--line);
}
.analysis-section h3 {
margin: 0 0 12px;
font-size: 12px;
}
.plot {
position: relative;
height: 190px;
margin-top: 6px;
border: 1px solid #d9e2e7;
border-radius: 10px;
background:
linear-gradient(to right, transparent 49.7%, #e4eaee 50%, transparent 50.3%),
linear-gradient(to top, transparent 49.7%, #e4eaee 50%, transparent 50.3%),
#f8fafb;
overflow: hidden;
}
.plot-label {
position: absolute;
z-index: 1;
color: #788692;
font-size: 9px;
pointer-events: none;
}
.plot-label.x {
right: 8px;
bottom: 7px;
}
.plot-label.y {
left: 7px;
top: 7px;
writing-mode: vertical-rl;
transform: rotate(180deg);
}
.plot-quadrant {
position: absolute;
color: #a0abb4;
font-size: 8px;
font-weight: 750;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.plot-quadrant.fast-private {
top: 10px;
right: 10px;
}
.plot-quadrant.fast-exposed {
top: 10px;
left: 10px;
}
.plot-quadrant.slow-private {
bottom: 25px;
right: 10px;
}
.plot-quadrant.slow-exposed {
bottom: 25px;
left: 10px;
}
#plotMarker {
position: absolute;
z-index: 3;
width: 15px;
height: 15px;
border: 3px solid #fff;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 3px 10px rgba(15, 63, 70, 0.35);
transform: translate(-50%, 50%);
transition: left 180ms ease, bottom 180ms ease;
}
.plot-values {
display: flex;
justify-content: space-between;
margin-top: 8px;
color: var(--muted);
font-size: 10px;
}
.anatomy-row {
display: grid;
grid-template-columns: 1fr auto;
gap: 10px;
padding: 7px 0;
border-bottom: 1px solid #edf1f3;
font-size: 11px;
}
.anatomy-row:last-child { border-bottom: 0; }
.anatomy-row strong {
color: var(--teal);
font-size: 11px;
}
.anatomy-row strong.negative { color: var(--red); }
.insight-card {
margin: 0 17px 15px;
padding: 13px;
border: 1px solid #cfe4e2;
border-radius: 10px;
background: #f0f9f7;
}
.insight-card h3 {
margin: 0 0 6px;
color: #145f62;
font-size: 12px;
}
.insight-card p {
margin: 0;
color: #456361;
font-size: 11px;
line-height: 1.5;
}
details {
margin: 0 17px 15px;
border: 1px solid #dce4e9;
border-radius: 10px;
background: #fafcfd;
}
summary {
padding: 12px;
color: #3e5264;
font-size: 11px;
font-weight: 800;
cursor: pointer;
}
.assumption-list {
margin: 0;
padding: 0 14px 13px 28px;
color: #5e6c78;
font-size: 10px;
line-height: 1.55;
}
.assumption-list li { margin-bottom: 6px; }
.boundary-note {
margin: 0 17px;
padding: 11px;
border-radius: 9px;
background: #fff6e5;
color: #755726;
font-size: 10px;
line-height: 1.5;
}
@media (max-width: 1160px) {
.workspace {
grid-template-columns: 280px minmax(460px, 1fr);
}
.analysis-panel {
grid-column: 1 / -1;
max-height: none;
min-height: 0;
display: grid;
grid-template-columns: 1fr 1fr;
}
.analysis-panel .panel-heading,
.analysis-panel .metric-grid,
.analysis-panel .boundary-note {
grid-column: 1 / -1;
}
.analysis-panel details { align-self: start; }
}
@media (max-width: 760px) {
.topbar {
align-items: flex-start;
flex-direction: column;
}
.historical-warning { max-width: none; }
.workspace {
grid-template-columns: 1fr;
padding: 9px;
}
.controls-panel,
.analysis-panel {
max-height: none;
min-height: 0;
}
.analysis-panel { grid-column: auto; display: block; }
.stage-card {
min-height: 610px;
grid-template-rows: auto 510px auto;
}
.stage-summary {
grid-template-columns: 1fr 1fr;
}
.stage-summary div:nth-child(2) { border-right: 0; }
.stage-summary div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
}
</style>
</head>
<body>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<svg viewBox="0 0 32 32">
<path d="M7 5h18v22H7z"></path>
<path d="M11 10h10M11 15h10M11 20h6"></path>
<path d="m19 23 2 2 4-5"></path>
</svg>
</div>
<div>
<h1>Polling Room Lab</h1>
<p>Fictional service-design sandbox · voxel layout</p>
</div>
</div>
<div class="historical-warning">
<strong>Historical boundary:</strong> this is an imagined planning exercise,
not a reconstruction of any polling place. It uses no actual 1994 election
turnout, geography, party, precinct, or outcome statistics.
</div>
</header>
<main class="workspace">
<aside class="panel controls-panel" aria-label="Scenario controls">
<div class="panel-heading">
<p class="eyebrow">Scenario controls</p>
<h2>Shape the fictional room</h2>
<p>Adjust arrivals, service speed, and physical privacy. The model updates instantly.</p>
</div>
<section class="control-section">
<h3 class="section-title">Demand & service assumptions</h3>
<div class="control">
<div class="control-head">
<label for="arrivals">Voter arrivals</label>
<output id="arrivalsOut" for="arrivals"></output>
</div>
<input id="arrivals" type="range" min="60" max="900" step="30" value="210">
<small>Poisson arrivals, shown per hour.</small>
</div>
<div class="control">
<div class="control-head">
<label for="intakeDesks">Check-in desks</label>
<output id="intakeDesksOut" for="intakeDesks"></output>
</div>
<input id="intakeDesks" type="range" min="1" max="4" step="1" value="3">
</div>
<div class="control">
<div class="control-head">
<label for="checkinTime">Mean check-in time</label>
<output id="checkinTimeOut" for="checkinTime"></output>
</div>
<input id="checkinTime" type="range" min="15" max="120" step="5" value="45">
<small>Fixed mean, before any accessibility accommodation.</small>
</div>
<div class="control">
<div class="control-head">
<label for="booths">Voting stations</label>
<output id="boothsOut" for="booths"></output>
</div>
<input id="booths" type="range" min="2" max="12" step="1" value="6">
</div>
<div class="control">
<div class="control-head">
<label for="ballotTime">Mean ballot service time</label>
<output id="ballotTimeOut" for="ballotTime"></output>
</div>
<input id="ballotTime" type="range" min="45" max="180" step="5" value="90">
<small>Assumed service only; walking time is excluded.</small>
</div>
</section>
<section class="control-section">
<h3 class="section-title">Physical layout</h3>
<div class="control">
<div class="control-head">
<label for="screenStyle">Voting screen style</label>
</div>
<select id="screenStyle">
<option value="open">Open frames</option>
<option value="partial" selected>Partial screens</option>
<option value="full">Full-height screens</option>
</select>
</div>
<div class="control">
<div class="control-head">
<label for="spacing">Station spacing</label>
</div>
<select id="spacing">
<option value="compact">Compact</option>
<option value="standard" selected>Standard</option>
<option value="spacious">Spacious</option>
</select>
</div>
<div class="control">
<div class="control-head">
<label for="queueStyle">Waiting-line treatment</label>
</div>
<select id="queueStyle">
<option value="open">Open waiting area</option>
<option value="marked" selected>Marked queue lanes</option>
<option value="separated">Screened queue lanes</option>
</select>
</div>
</section>
<section class="control-section">
<h3 class="section-title">Compare scenarios</h3>
<div class="preset-buttons">
<button type="button" data-preset="balanced">Balanced room</button>
<button type="button" data-preset="fast">Faster lines</button>
<button type="button" data-preset="private">More privacy</button>
</div>
<button class="reset-button" id="resetButton" type="button">Reset assumptions</button>
</section>
</aside>
<section class="stage-card" aria-label="Voxel polling room scene">
<div class="stage-header">
<div class="stage-title">
<h2>Fictional polling-room floor plan</h2>
<p>Fixed room footprint · animated at 8× service time</p>
</div>
<div class="stage-tools">
<span id="statusPill" class="status-pill">Stable flow</span>
<button id="cameraReset" class="icon-button" type="button" title="Reset camera" aria-label="Reset camera">↺</button>
</div>
</div>
<div id="viewport">
<div class="scene-chip top-left" id="sceneChip">3 check-ins · 6 stations</div>
<div class="scene-chip bottom-left">Voxel view · people represent queue state</div>
<div class="camera-help">Drag: orbit · wheel/pinch: zoom<br>Right-drag: pan</div>
</div>
<div class="stage-summary">
<div><span>Check-in</span><strong id="stageIntake">3 desks · 45 sec</strong></div>
<div><span>Voting</span><strong id="stageVoting">6 stations · 90 sec</strong></div>
<div><span>Floor area</span><strong>Fixed 22 × 16 units</strong></div>
<div><span>Animation</span><strong>Illustrative only</strong></div>
</div>
</section>
<aside class="panel analysis-panel" aria-label="Scenario results">
<div class="panel-heading">
<p class="eyebrow">Model output</p>
<h2>Waiting versus privacy</h2>
<p>Both measures are fictional planning proxies, not observations.</p>
</div>
<div class="metric-grid">
<div class="metric" id="waitMetric">
<div class="label">Expected queue wait</div>
<div class="value" id="waitValue">—</div>
<div class="sub">Across check-in and voting queues</div>
</div>
<div class="metric" id="privacyMetric">
<div class="label">Privacy index</div>
<div class="value" id="privacyValue">—</div>
<div class="sub">Illustrative geometry-based score</div>
</div>
<div class="metric">
<div class="label">Typical visit</div>
<div class="value" id="visitValue">—</div>
<div class="sub">Wait plus both mean service times</div>
</div>
<div class="metric">
<div class="label">Room capacity</div>
<div class="value" id="capacityValue">—</div>
<div class="sub" id="capacitySub">Voters per hour</div>
</div>
</div>
<section class="analysis-section">
<h3>Trade-off position</h3>
<div class="plot" aria-label="Privacy and wait time trade-off chart">
<span class="plot-label x">Longer wait →</span>
<span class="plot-label y">More privacy →</span>
<span class="plot-quadrant fast-private">Fast + private</span>
<span class="plot-quadrant fast-exposed">Fast + exposed</span>
<span class="plot-quadrant slow-private">Slow + private</span>
<span class="plot-quadrant slow-exposed">Slow + exposed</span>
<div id="plotMarker" title="Current scenario"></div>
</div>
<div class="plot-values">
<span id="plotWait">Wait: —</span>
<span id="plotPrivacy">Privacy: —</span>
</div>
</section>
<section class="analysis-section">
<h3>Privacy anatomy</h3>
<div class="anatomy-row"><span>Screen shielding</span><strong id="privacyShield">—</strong></div>
<div class="anatomy-row"><span>Station spacing</span><strong id="privacySpacing">—</strong></div>
<div class="anatomy-row"><span>Queue separation</span><strong id="privacyQueue">—</strong></div>
<div class="anatomy-row"><span>Density & crowding</span><strong id="privacyDensity">—</strong></div>
</section>
<div class="insight-card">
<h3 id="insightTitle">Reading the scenario</h3>
<p id="insightText">Adjust the layout to see how the trade-off changes.</p>
</div>
<details open>
<summary>Stated service-time assumptions</summary>
<ul class="assumption-list">
<li>Every arriving voter checks in and then uses one voting station.</li>
<li>Arrivals are modeled as a Poisson process at the selected hourly rate.</li>
<li>Check-in and ballot stages use independent FIFO queues with fixed mean service times.</li>
<li>Expected wait uses a steady-state M/M/c queueing approximation for each stage.</li>
<li>No walking time, queue transfer time, staff breaks, equipment failures, accessibility accommodations, or absentee voting are modeled.</li>
<li>The room footprint is fixed. More stations can reduce waiting while increasing visual density.</li>
<li>The animated people are a visual queue representation, not a statistically sampled micro-simulation.</li>
</ul>
</details>
<div class="boundary-note">
<strong>Separation from real election data:</strong> every number in this
sandbox is a user-selected fictional assumption. The privacy score is a
design heuristic—not a legal, accessibility, security, or election audit.
</div>
</aside>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
const presets = {
balanced: {
arrivals: 210,
intakeDesks: 3,
checkinTime: 45,
booths: 6,
ballotTime: 90,
screenStyle: "partial",
spacing: "standard",
queueStyle: "marked"
},
fast: {
arrivals: 420,
intakeDesks: 4,
checkinTime: 25,
booths: 10,
ballotTime: 60,
screenStyle: "open",
spacing: "compact",
queueStyle: "open"
},
private: {
arrivals: 120,
intakeDesks: 2,
checkinTime: 60,
booths: 5,
ballotTime: 120,
screenStyle: "full",
spacing: "spacious",
queueStyle: "separated"
}
};
const state = { ...presets.balanced };
const elements = {
arrivals: $("arrivals"),
intakeDesks: $("intakeDesks"),
checkinTime: $("checkinTime"),
booths: $("booths"),
ballotTime: $("ballotTime"),
screenStyle: $("screenStyle"),
spacing: $("spacing"),
queueStyle: $("queueStyle")
};
const viewport = $("viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdfe8ec);
scene.fog = new THREE.Fog(0xdfe8ec, 35, 62);
const camera = new THREE.PerspectiveCamera(39, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
viewport.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xeaf6ff, 0x708393, 2.35);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff6e8, 3.25);
sun.position.set(-8, 20, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -20;
sun.shadow.camera.right = 20;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 50;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbfdfff, 1.1);
fill.position.set(16, 9, -13);
scene.add(fill);
const world = new THREE.Group();
const layoutGroup = new THREE.Group();
scene.add(world, layoutGroup);
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(color, new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02,
flatShading: true
}));
}
return materialCache.get(color);
}
function box(group, width, height, depth, x, y, z, color, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
group.add(mesh);
return mesh;
}
function makeLabel(text, color = "#29495d") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "rgba(255,255,255,0.88)";
ctx.beginPath();
ctx.roundRect(8, 12, 496, 104, 22);
ctx.fill();
ctx.strokeStyle = "rgba(54,78,94,0.20)";
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = color;
ctx.font = "700 42px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 66);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false
}));
sprite.scale.set(4.1, 1.025, 1);
sprite.renderOrder = 10;
return sprite;
}
function clearGroup(group) {
group.traverse((object) => {
if (object.geometry) object.geometry.dispose();
if (object.isSprite) {
if (object.material.map) object.material.map.dispose();
object.material.dispose();
}
});
group.clear();
}
function buildStaticRoom() {
box(world, 22.5, 0.45, 16.5, 0, -0.28, 0, 0xbecbd1, false);
box(world, 21.9, 0.12, 15.9, 0, -0.015, 0, 0xe5ebed, false);
// Tile seams.
for (let x = -10; x <= 10; x += 1) {
box(world, 0.022, 0.012, 15.8, x, 0.052, 0, 0xd4dde1, false);
}
for (let z = -7; z <= 7; z += 1) {
box(world, 21.8, 0.012, 0.022, 0, 0.053, z, 0xd4dde1, false);
}
// Back and side walls.
box(world, 22.2, 3.8, 0.28, 0, 1.9, -7.75, 0xf2f4f2);
box(world, 0.28, 3.8, 16.0, -10.9, 1.9, 0, 0xe7ecec);
// Wall base and trim.
box(world, 22.0, 0.28, 0.36, 0, 0.16, -7.58, 0x8fa5af, false);
box(world, 0.36, 0.28, 15.7, -10.73, 0.16, 0, 0x8fa5af, false);
// Stylized windows on the back wall.
for (let x = -8.3; x <= 8.5; x += 4.15) {
box(world, 2.5, 1.55, 0.10, x, 2.25, -7.56, 0x89b5c7);
box(world, 0.07, 1.62, 0.13, x, 2.25, -7.49, 0xeef5f5);
box(world, 2.58, 0.07, 0.13, x, 2.25, -7.49, 0xeef5f5);
}
// Entrance threshold.
box(world, 3.3, 0.045, 0.8, -7.3, 0.08, 7.05, 0x4a7181, false);
box(world, 2.9, 0.05, 0.12, -7.3, 0.11, 6.8, 0xd8a64f, false);
// Waiting bench along the left rear.
box(world, 2.7, 0.18, 0.7, -8.7, 0.65, -4.9, 0xb88754);
box(world, 2.7, 0.85, 0.16, -8.7, 1.12, -5.22, 0xc99b68);
box(world, 0.18, 0.62, 0.55, -9.75, 0.3, -4.9, 0x536875);
box(world, 0.18, 0.62, 0.55, -7.65, 0.3, -4.9, 0x536875);
// Small voxel plant.
box(world, 0.65, 0.65, 0.65, 9.6, 0.33, -6.5, 0xb67d5e);
box(world, 0.25, 1.15, 0.25, 9.6, 1.05, -6.5, 0x477a5e);
box(world, 0.75, 0.55, 0.65, 9.6, 1.55, -6.5, 0x4d896a);
box(world, 0.55, 0.65, 0.55, 10.0, 1.95, -6.5, 0x5b9877);
const entranceLabel = makeLabel("ENTRANCE", "#6f5425");
entranceLabel.position.set(-7.3, 1.35, 7.1);
entranceLabel.scale.set(2.8, 0.7, 1);
world.add(entranceLabel);
const votingLabel = makeLabel("VOTING STATIONS");
votingLabel.position.set(4.9, 3.55, -6.8);
world.add(votingLabel);
const checkinLabel = makeLabel("CHECK-IN");
checkinLabel.position.set(-5.4, 3.05, 3.8);
world.add(checkinLabel);
}
const spacingConfig = {
compact: { width: 1.12, depth: 1.20, gap: 0.16, privacy: -14 },
standard: { width: 1.43, depth: 1.48, gap: 0.34, privacy: 0 },
spacious: { width: 1.72, depth: 1.78, gap: 0.52, privacy: 10 }
};
const screenConfig = {
open: { score: 34, color: 0x9eb0b8 },
partial: { score: 64, color: 0x7297a7 },
full: { score: 90, color: 0x537b8e }
};
const layoutMeta = {
deskPositions: [],
boothPositions: []
};
function addQueueRail(x, z, width, separated) {
const color = separated ? 0x3f7f78 : 0xd2a34d;
box(layoutGroup, 0.10, 0.85, 0.10, x, 0.45, z, color);
box(layoutGroup, 0.10, 0.85, 0.10, x + width, 0.45, z, color);
box(layoutGroup, width, 0.10, 0.10, x + width / 2, 0.83, z, color);
}
function buildLayout(resetPeople = true) {
clearGroup(layoutGroup);
layoutMeta.deskPositions = [];
layoutMeta.boothPositions = [];
const screen = screenConfig[state.screenStyle];
const spacing = spacingConfig[state.spacing];
// Check-in desks.
for (let i = 0; i < state.intakeDesks; i++) {
const x = -7.35 + i * 1.72;
const z = 2.95;
box(layoutGroup, 1.42, 0.18, 1.05, x, 1.05, z, 0xc59a6b);
box(layoutGroup, 1.25, 0.92, 0.18, x, 0.56, z + 0.35, 0xa87950);
box(layoutGroup, 0.12, 0.92, 0.8, x - 0.64, 0.56, z, 0xa87950);
box(layoutGroup, 0.12, 0.92, 0.8, x + 0.64, 0.56, z, 0xa87950);
// Check-in monitor.
box(layoutGroup, 0.62, 0.42, 0.09, x, 1.48, z - 0.03, 0x344e5e);
box(layoutGroup, 0.07, 0.35, 0.07, x, 1.18, z - 0.03, 0x344e5e);
// Shield height follows the selected screen style.
const shieldHeight =
state.screenStyle === "full" ? 2.1 :
state.screenStyle === "partial" ? 1.25 : 0.58;
box(
layoutGroup,
1.25,
shieldHeight,
0.13,
x,
shieldHeight / 2 + 0.12,
z - 0.58,
screen.color
);
layoutMeta.deskPositions.push(new THREE.Vector3(x, 0, z + 0.82));
}
// Queue markings and optional screened lanes.
const queueColor = state.queueStyle === "separated" ? 0x6ab0a5 :
state.queueStyle === "marked" ? 0xe0b252 : 0xaab8bc;
for (let i = 0; i < 9; i++) {
box(
layoutGroup,
0.58,
0.018,
0.07,
-7.8 + (i % 2) * 0.96,
0.075,
6.25 - Math.floor(i / 2) * 0.63,
queueColor,
false
);
}
if (state.queueStyle !== "open") {
addQueueRail(-9.3, 6.55, 2.5, state.queueStyle === "separated");
addQueueRail(-9.3, 4.35, 2.5, state.queueStyle === "separated");
}
// Second-stage waiting line toward the voting stations.
for (let i = 0; i < 12; i++) {
box(
layoutGroup,
0.40,
0.018,
0.065,
-0.85 + (i % 6) * 0.59,
0.076,
4.75 - Math.floor(i / 6) * 0.64,
queueColor,
false
);
}
if (state.queueStyle === "separated") {
addQueueRail(-1.2, 5.1, 3.55, true);
addQueueRail(-1.2, 3.78, 3.55, true);
}
// Voting stations.
const columns = state.booths <= 4 ? state.booths : 4;
const rows = Math.ceil(state.booths / columns);
const startX = 0.35;
const startZ = -5.55;
for (let i = 0; i < state.booths; i++) {
const col = i % columns;
const row = Math.floor(i / columns);
const x = startX + spacing.width / 2 + col * (spacing.width + spacing.gap);
const z = startZ + spacing.depth / 2 + row * (spacing.depth + spacing.gap);
layoutMeta.boothPositions.push(new THREE.Vector3(x, 0, z));
// Booth floor pad.
box(
layoutGroup,
spacing.width,
0.045,
spacing.depth,
x,
0.085,
z,
state.screenStyle === "open" ? 0xd2dadd : 0xc5d6dc,
false
);
const partitionColor = screen.color;
if (state.screenStyle === "full") {
box(layoutGroup, 0.13, 2.25, spacing.depth, x - spacing.width / 2, 1.19, z, partitionColor);
box(layoutGroup, 0.13, 2.25, spacing.depth, x + spacing.width / 2, 1.19, z, partitionColor);
box(layoutGroup, spacing.width, 2.25, 0.13, x, 1.19, z - spacing.depth / 2, partitionColor);
box(layoutGroup, spacing.width * 0.54, 1.72, 0.13, x - spacing.width * 0.23, 0.92, z + spacing.depth / 2, partitionColor);
} else if (state.screenStyle === "partial") {
box(layoutGroup, 0.13, 1.00, spacing.depth, x - spacing.width / 2, 0.57, z, partitionColor);
box(layoutGroup, 0.13, 1.00, spacing.depth, x + spacing.width / 2, 0.57, z, partitionColor);
box(layoutGroup, spacing.width, 1.65, 0.13, x, 0.89, z - spacing.depth / 2, partitionColor);
box(layoutGroup, spacing.width * 0.48, 0.72, 0.13, x - spacing.width * 0.26, 0.42, z + spacing.depth / 2, partitionColor);
} else {
box(layoutGroup, spacing.width, 0.34, 0.13, x, 0.24, z - spacing.depth / 2, partitionColor);
box(layoutGroup, 0.13, 0.48, spacing.depth, x - spacing.width / 2, 0.31, z, partitionColor);
}
// Voting desk and machine.
box(layoutGroup, spacing.width * 0.68, 0.15, 0.60, x, 0.98, z - 0.17, 0xb17f55);
box(layoutGroup, spacing.width * 0.48, 0.48, 0.12, x, 1.30, z - 0.30, 0x385363);
box(layoutGroup, 0.34, 0.04, 0.28, x, 1.10, z + 0.02, 0x506a77);
box(layoutGroup, 0.14, 0.03, 0.14, x + 0.25, 1.08, z + 0.03, 0x527c73);
}
if (resetPeople && simulation) simulation.reset();
}
// ----- Queueing model -----
function erlangCWait(arrivalsPerHour, servers, serviceSeconds) {
const serviceRate = 3600 / serviceSeconds;
const offeredLoad = arrivalsPerHour / serviceRate;
const utilization = offeredLoad / servers;
if (utilization >= 0.999999) {
return { wait: null, utilization, capacity: servers * serviceRate };
}
let sum = 1;
let term = 1;
for (let i = 1; i < servers; i++) {
term *= offeredLoad / i;
sum += term;
}
const cTerm = term * offeredLoad / (servers - offeredLoad);
const probabilityWait = cTerm / (sum + cTerm);
const waitSeconds = probabilityWait / (servers * serviceRate - arrivalsPerHour);
return {
wait: Math.max(0, waitSeconds),
utilization,
capacity: servers * serviceRate
};
}
function calculateScenario() {
const intake = erlangCWait(state.arrivals, state.intakeDesks, state.checkinTime);
const voting = erlangCWait(state.arrivals, state.booths, state.ballotTime);
const overloaded = intake.wait === null || voting.wait === null;
const totalWait = overloaded
? null
: intake.wait + voting.wait;
const capacity = Math.min(intake.capacity, voting.capacity);
const maxUtilization = Math.max(intake.utilization, voting.utilization);
const shielding = screenConfig[state.screenStyle].score;
const spacing = spacingConfig[state.spacing].privacy;
const queuePrivacy = {
open: 0,
marked: 8,
separated: 16
}[state.queueStyle];
const densityPenalty = Math.max(0, (state.booths - 6) * 2.4);
const crowdingPenalty = Math.max(0, (maxUtilization - 0.70) * 18);
const privacy = Math.round(
Math.max(5, Math.min(98, shielding + spacing + queuePrivacy - densityPenalty - crowdingPenalty))
);
return {
intake,
voting,
overloaded,
totalWait,
capacity,
maxUtilization,
privacy,
components: { shielding, spacing, queuePrivacy, densityPenalty, crowdingPenalty }
};
}
// ----- Illustrative animation -----
const personBodyGeometry = new THREE.BoxGeometry(0.34, 0.63, 0.28);
const personHeadGeometry = new THREE.BoxGeometry(0.31, 0.31, 0.31);
const personLegGeometry = new THREE.BoxGeometry(0.11, 0.42, 0.14);
const personMaterials = {
waiting: new THREE.MeshStandardMaterial({ color: 0xe5a23f, roughness: 0.85 }),
checkin: new THREE.MeshStandardMaterial({ color: 0x3d9ca2, roughness: 0.85 }),
queue2: new THREE.MeshStandardMaterial({ color: 0xe5a23f, roughness: 0.85 }),
voting: new THREE.MeshStandardMaterial({ color: 0x7566ad, roughness: 0.85 })
};
function makePerson(stage) {
const group = new THREE.Group();
const colorKey = stage === 1 ? "checkin" : stage === 3 ? "voting" : "waiting";
const body = new THREE.Mesh(personBodyGeometry, personMaterials[colorKey]);
body.position.y = 0.67;
body.castShadow = true;
const head = new THREE.Mesh(personHeadGeometry, personMaterials[colorKey]);
head.position.y = 1.16;
head.castShadow = true;
const leftLeg = new THREE.Mesh(personLegGeometry, personMaterials[colorKey]);
leftLeg.position.set(-0.10, 0.25, 0);
leftLeg.castShadow = true;
const rightLeg = new THREE.Mesh(personLegGeometry, personMaterials[colorKey]);
rightLeg.position.set(0.10, 0.25, 0);
rightLeg.castShadow = true;
group.add(body, head, leftLeg, rightLeg);
scene.add(group);
return group;
}
class PollSimulation {
constructor() {
this.agents = [];
this.q1 = [];
this.q2 = [];
this.desks = [];
this.booths = [];
this.nextArrival = 0;
this.nextId = 1;
this.reset();
}
reset() {
this.agents.forEach((agent) => scene.remove(agent.mesh));
this.agents = [];
this.q1 = [];
this.q2 = [];
this.nextId = 1;
this.desks = Array.from({ length: state.intakeDesks }, () => null);
this.booths = Array.from({ length: state.booths }, () => null);
this.nextArrival = -Math.log(Math.max(1e-9, Math.random())) /
Math.max(1, state.arrivals / 3600);
// Seed a readable queue instead of beginning with an empty room.
for (let i = 0; i < 8; i++) this.addAgent();
}
addAgent() {
if (this.agents.length >= 140) return;
const agent = {
id: this.nextId++,
stage: 0,
serviceIndex: -1,
mesh: makePerson(0)
};
agent.mesh.position.set(-7.3, 0, 6.55);
this.agents.push(agent);
this.q1.push(agent);
}
assignCheckin() {
while (this.q1.length) {
const index = this.desks.findIndex((desk) => desk === null);
if (index < 0) break;
const agent = this.q1.shift();
agent.stage = 1;
agent.serviceIndex = index;
this.desks[index] = agent;
}
}
assignVoting() {
while (this.q2.length) {
const index = this.booths.findIndex((booth) => booth === null);
if (index < 0) break;
const agent = this.q2.shift();
agent.stage = 3;
agent.serviceIndex = index;
this.booths[index] = agent;
}
}
advance(simSeconds) {
const rate = state.arrivals / 3600;
if (rate > 0) {
this.nextArrival -= simSeconds;
while (this.nextArrival <= 0) {
this.addAgent();
this.nextArrival += -Math.log(Math.max(1e-9, Math.random())) / rate;
}
}
for (let i = 0; i < this.desks.length; i++) {
const agent = this.desks[i];
if (!agent) continue;
agent.remaining = (agent.remaining ?? state.checkinTime) - simSeconds;
if (agent.remaining <= 0) {
this.desks[i] = null;
agent.stage = 2;
this.q2.push(agent);
}
}
for (let i = 0; i < this.booths.length; i++) {
const agent = this.booths[i];
if (!agent) continue;
agent.remaining = (agent.remaining ?? state.ballotTime) - simSeconds;
if (agent.remaining <= 0) {
this.booths[i] = null;
agent.stage = 4;
}
}
this.assignCheckin();
this.assignVoting();
const completed = this.agents.filter((agent) => agent.stage === 4);
completed.forEach((agent) => {
scene.remove(agent.mesh);
this.agents.splice(this.agents.indexOf(agent), 1);
});
}
}
const simulation = new PollSimulation();
const tempTarget = new THREE.Vector3();
function updatePeople(delta) {
const smoothing = 1 - Math.exp(-delta * 7);
simulation.q1.forEach((agent, index) => {
const row = Math.floor(index / 2);
const column = index % 2;
tempTarget.set(
-7.82 + column * 0.98,
0,
6.28 - row * 0.64
);
agent.mesh.position.lerp(tempTarget, smoothing);
agent.mesh.rotation.y = Math.PI;
});
simulation.desks.forEach((agent, index) => {
if (!agent) return;
tempTarget.copy(layoutMeta.deskPositions[index]);
tempTarget.z += 0.08;
agent.mesh.position.lerp(tempTarget, smoothing);
agent.mesh.rotation.y = Math.PI;
});
simulation.q2.forEach((agent, index) => {
const row = Math.floor(index / 6);
const column = index % 6;
tempTarget.set(
-0.87 + column * 0.60,
0,
4.78 - row * 0.65
);
agent.mesh.position.lerp(tempTarget, smoothing);
agent.mesh.rotation.y = Math.PI;
});
simulation.booths.forEach((agent, index) => {
if (!agent) return;
tempTarget.copy(layoutMeta.boothPositions[index]);
tempTarget.z += 0.22;
agent.mesh.position.lerp(tempTarget, smoothing);
agent.mesh.rotation.y = 0;
});
}
// ----- UI calculations -----
function formatDuration(seconds) {
if (seconds === null || !Number.isFinite(seconds)) return "Over capacity";
if (seconds < 90) return `${Math.max(1, Math.round(seconds / 5) * 5)} sec`;
if (seconds < 3600) return `${(seconds / 60).toFixed(1)} min`;
return `${(seconds / 3600).toFixed(1)} hr`;
}
function signed(value) {
return value > 0 ? `+${Math.round(value)}` : `${Math.round(value)}`;
}
function updateAnalysis() {
const result = calculateScenario();
$("waitValue").textContent = formatDuration(result.totalWait);
$("privacyValue").textContent = `${result.privacy} / 100`;
$("visitValue").textContent = result.overloaded
? "Unstable"
: formatDuration(result.totalWait + state.checkinTime + state.ballotTime);
$("capacityValue").textContent = `${Math.round(result.capacity)}`;
$("capacitySub").textContent = `voters/hour · demand ${state.arrivals}/hour`;
$("waitMetric").classList.toggle("alert", result.overloaded);
const statusPill = $("statusPill");
statusPill.classList.remove("warn", "bad");
if (result.overloaded) {
statusPill.textContent = "Over capacity";
statusPill.classList.add("bad");
} else if (result.maxUtilization > 0.90) {
statusPill.textContent = "Near capacity";
statusPill.classList.add("warn");
} else {
statusPill.textContent = "Stable flow";
}
const waitForPlot = result.overloaded ? 15 : result.totalWait / 60;
const plotX = Math.max(2, Math.min(98, 5 + (waitForPlot / 15) * 90));
const plotY = Math.max(5, Math.min(95, 5 + result.privacy * 0.90));
$("plotMarker").style.left = `${plotX}%`;
$("plotMarker").style.bottom = `${plotY}%`;
$("plotWait").textContent = `Wait: ${result.overloaded ? "unstable" : formatDuration(result.totalWait)}`;
$("plotPrivacy").textContent = `Privacy: ${result.privacy}`;
const c = result.components;
$("privacyShield").textContent = signed(c.shielding);
$("privacySpacing").textContent = signed(c.spacing);
$("privacyQueue").textContent = signed(c.queuePrivacy);
$("privacyDensity").textContent = signed(-(c.densityPenalty + c.crowdingPenalty));
$("privacyDensity").classList.toggle("negative", c.densityPenalty + c.crowdingPenalty < 0);
let title = "A workable middle ground";
let text = "The current assumptions avoid a capacity failure while retaining some physical separation. Screens and queue treatment can improve the privacy score without changing service times.";
if (result.overloaded) {
if (result.intake.wait === null && result.voting.wait === null) {
title = "Both stages are over capacity";
text = "Add desks or stations, reduce the arrival rate, or revise the stated service times. With demand above capacity, a steady-state wait cannot be defined.";
} else if (result.intake.wait === null) {
title = "Check-in is the bottleneck";
text = "The check-in stage cannot process the selected arrival rate. Add a check-in desk or shorten the assumed check-in service time.";
} else {
title = "Voting stations are the bottleneck";
text = "The voting stage cannot process the selected arrival rate. Add a station or shorten the assumed ballot service time.";
}
} else if (result.totalWait > 300) {
title = "Privacy is costly in queue time";
text = "The layout creates a protected voting experience, but station capacity is creating a long wait. More stations may recover time while spacing and screens preserve much of the privacy gain.";
} else if (result.privacy < 55) {
title = "Fast lines, but exposed waiting";
text = "The layout favors throughput. Partial or full-height screens and a separated queue can improve visual privacy without changing the service-time assumptions.";
} else if (result.privacy >= 78 && result.totalWait < 120) {
title = "A strong balance";
text = "The room appears to provide short waits and substantial visual separation under the stated assumptions. Validate the assumptions with real accessibility and operations review before applying them elsewhere.";
} else if (result.maxUtilization > 0.90) {
title = "Stable, but with little margin";
text = "Demand remains below capacity, but a small increase in arrivals or service time could create a substantial queue. Treat this as a near-capacity design.";
}
$("insightTitle").textContent = title;
$("insightText").textContent = text;
$("sceneChip").textContent =
`${state.intakeDesks} check-in${state.intakeDesks === 1 ? "" : "s"} · ` +
`${state.booths} voting station${state.booths === 1 ? "" : "s"}`;
$("stageIntake").textContent =
`${state.intakeDesks} desk${state.intakeDesks === 1 ? "" : "s"} · ${state.checkinTime} sec`;
$("stageVoting").textContent =
`${state.booths} station${state.booths === 1 ? "" : "s"} · ${state.ballotTime} sec`;
}
function updateControlDisplays() {
$("arrivalsOut").textContent = `${state.arrivals}/hour`;
$("intakeDesksOut").textContent = `${state.intakeDesks}`;
$("checkinTimeOut").textContent = `${state.checkinTime} sec`;
$("boothsOut").textContent = `${state.booths}`;
$("ballotTimeOut").textContent = `${state.ballotTime} sec`;
Object.entries(elements).forEach(([key, input]) => {
if (input.type === "range") {
const percent = ((state[key] - input.min) / (input.max - input.min)) * 100;
input.style.setProperty("--fill", `${percent}%`);
}
});
}
function syncInputs() {
Object.entries(elements).forEach(([key, input]) => {
input.value = state[key];
});
updateControlDisplays();
}
function handleControlChange(key, rebuild = false) {
state[key] = elements[key].type === "range"
? Number(elements[key].value)
: elements[key].value;
updateControlDisplays();
updateAnalysis();
if (rebuild) {
buildLayout(true);
}
}
Object.entries(elements).forEach(([key, input]) => {
const rebuild = [
"intakeDesks",
"booths",
"screenStyle",
"spacing",
"queueStyle"
].includes(key);
input.addEventListener("input", () => handleControlChange(key, rebuild));
input.addEventListener("change", () => handleControlChange(key, rebuild));
});
document.querySelectorAll("[data-preset]").forEach((button) => {
button.addEventListener("click", () => {
Object.assign(state, presets[button.dataset.preset]);
syncInputs();
buildLayout(true);
updateAnalysis();
});
});
$("resetButton").addEventListener("click", () => {
Object.assign(state, presets.balanced);
syncInputs();
buildLayout(true);
updateAnalysis();
});
// ----- Custom camera controls: no addons -----
const cameraState = {
target: new THREE.Vector3(0, 0.65, 0),
radius: 27,
theta: 0.72,
phi: 0.79
};
function applyCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z + cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.target.set(0, 0.65, 0);
cameraState.radius = 27;
cameraState.theta = 0.72;
cameraState.phi = 0.79;
applyCamera();
}
$("cameraReset").addEventListener("click", resetCamera);
let drag = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
drag = {
id: event.pointerId,
x: event.clientX,
y: event.clientY,
pan: event.button === 2 || event.button === 1
};
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!drag || drag.id !== event.pointerId) return;
const dx = event.clientX - drag.x;
const dy = event.clientY - drag.y;
drag.x = event.clientX;
drag.y = event.clientY;
if (drag.pan) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
const right = new THREE.Vector3().crossVectors(forward, camera.up).normalize();
const screenUp = new THREE.Vector3().crossVectors(right, forward).normalize();
const panScale = cameraState.radius * 0.0014;
cameraState.target.addScaledVector(right, -dx * panScale);
cameraState.target.addScaledVector(screenUp, dy * panScale);
cameraState.target.x = THREE.MathUtils.clamp(cameraState.target.x, -10, 10);
cameraState.target.z = THREE.MathUtils.clamp(cameraState.target.z, -8, 8);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(cameraState.phi + dy * 0.005, 0.28, 1.35);
}
applyCamera();
});
function endDrag(event) {
if (drag && drag.id === event.pointerId) drag = null;
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.018,
17,
43
);
applyCamera();
}, { passive: false });
// Basic touch pinch zoom.
const touches = new Map();
let pinchDistance = 0;
renderer.domElement.addEventListener("touchstart", (event) => {
for (const touch of event.changedTouches) {
touches.set(touch.identifier, {
x: touch.clientX,
y: touch.clientY
});
}
if (touches.size === 2) {
const [a, b] = [...touches.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
}, { passive: true });
renderer.domElement.addEventListener("touchmove", (event) => {
if (event.touches.length === 2 && touches.size === 2) {
event.preventDefault();
const a = event.touches[0];
const b = event.touches[1];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + (pinchDistance - distance) * 0.025,
17,
43
);
applyCamera();
}
pinchDistance = distance;
}
}, { passive: false });
renderer.domElement.addEventListener("touchend", (event) => {
for (const touch of event.changedTouches) touches.delete(touch.identifier);
if (touches.size < 2) pinchDistance = 0;
});
const resizeObserver = new ResizeObserver(() => {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
});
resizeObserver.observe(viewport);
// ----- Boot and animation -----
buildStaticRoom();
buildLayout(false);
simulation.reset();
syncInputs();
updateAnalysis();
resetCamera();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
simulation.advance(delta * 8);
updatePeople(delta);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```