Prompt specification
Build or customize the Three.js 3D scene "Plan access and water points for a historical exhibit" 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: Plan access and water points for a historical exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/plan-access-and-water-points-for-a-historical-exhibit-x2444
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts the 1963 March on Washington. Let users inspect fictional service-placement options on a clearly labeled educational model. Keep the logistical exercise distinct from claims about the actual event organizers' decisions. Voxel style.
Working Three.js Starter (plan-access-and-water-points-for-a-historical-exhibit-x2444):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>March on Washington — Fictional Service-Placement Model</title>
<style>
:root {
--ink: #17232b;
--muted: #596873;
--paper: #f7f3e9;
--panel: #fffdf8;
--line: #d9d4c8;
--orange: #df6b32;
--orange-soft: #fff0e5;
--blue: #236b86;
--shadow: 0 12px 30px rgba(24, 39, 48, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
width: 100%;
height: 100%;
color: var(--ink);
background: var(--paper);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button,
select,
input {
font: inherit;
}
button {
color: inherit;
}
#app {
display: grid;
grid-template-rows: auto minmax(0, 1fr);
height: 100%;
}
header {
z-index: 10;
display: grid;
grid-template-columns: minmax(280px, 0.9fr) minmax(440px, 1.35fr);
gap: 24px;
align-items: center;
padding: 16px 22px;
color: #fff;
background: #1f3440;
border-bottom: 5px solid var(--orange);
}
.eyebrow {
margin: 0 0 5px;
color: #a9d3df;
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(1.2rem, 2.3vw, 2rem);
line-height: 1.05;
letter-spacing: -0.025em;
}
.subtitle {
margin: 6px 0 0;
color: #d7e3e7;
font-size: 0.86rem;
}
.fiction-warning {
padding-left: 18px;
border-left: 1px solid rgba(255, 255, 255, 0.24);
}
.fiction-warning strong {
display: block;
margin-bottom: 4px;
color: #ffc39f;
font-size: 0.78rem;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.fiction-warning p {
margin: 0;
color: #edf3f4;
font-size: 0.83rem;
line-height: 1.45;
}
main {
display: grid;
grid-template-columns: minmax(0, 1fr) 390px;
min-height: 0;
}
#viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #cfe3e8;
isolation: isolate;
}
#canvas-wrap,
#labels {
position: absolute;
inset: 0;
}
#canvas-wrap canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
#labels {
z-index: 3;
pointer-events: none;
overflow: hidden;
}
.scene-label {
position: absolute;
display: none;
transform: translate(-50%, -100%);
padding: 5px 8px;
color: #24343c;
background: rgba(255, 253, 248, 0.92);
border: 1px solid rgba(36, 52, 60, 0.24);
border-radius: 5px;
box-shadow: 0 4px 12px rgba(26, 42, 51, 0.12);
font-size: 0.68rem;
font-weight: 700;
line-height: 1.25;
white-space: nowrap;
backdrop-filter: blur(4px);
}
.scene-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 10px;
background: rgba(36, 52, 60, 0.42);
}
.scene-label.context {
color: #354850;
background: rgba(255, 253, 248, 0.84);
font-size: 0.64rem;
letter-spacing: 0.02em;
}
.scene-label.service {
border-left: 5px solid var(--label-color, #777);
}
.scene-label.service span {
display: block;
margin-top: 2px;
color: #68757c;
font-size: 0.59rem;
font-weight: 600;
}
.scene-label.candidate {
color: #503100;
background: #fff0bd;
border: 2px solid #d79224;
box-shadow: 0 0 0 4px rgba(244, 192, 76, 0.2);
}
#viewport-top {
position: absolute;
z-index: 4;
top: 15px;
left: 15px;
right: 15px;
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 12px;
pointer-events: none;
}
.model-badge,
.view-badge {
padding: 8px 10px;
color: #20333b;
background: rgba(255, 253, 248, 0.9);
border: 1px solid rgba(31, 52, 64, 0.18);
border-radius: 6px;
box-shadow: var(--shadow);
font-size: 0.7rem;
font-weight: 800;
letter-spacing: 0.04em;
text-transform: uppercase;
backdrop-filter: blur(5px);
}
.model-badge::before {
content: "";
display: inline-block;
width: 8px;
height: 8px;
margin-right: 7px;
background: var(--orange);
border-radius: 2px;
}
.view-badge {
color: #53656e;
font-weight: 700;
}
#bottom-controls {
position: absolute;
z-index: 5;
left: 14px;
right: 14px;
bottom: 14px;
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 9px 14px;
padding: 10px 12px;
background: rgba(255, 253, 248, 0.92);
border: 1px solid rgba(31, 52, 64, 0.18);
border-radius: 8px;
box-shadow: var(--shadow);
backdrop-filter: blur(6px);
}
.control-group {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 7px;
}
.control-group label {
display: inline-flex;
align-items: center;
gap: 5px;
color: #40535c;
font-size: 0.72rem;
font-weight: 700;
cursor: pointer;
}
.control-group input {
accent-color: var(--orange);
}
.control-button {
padding: 6px 9px;
background: #fff;
border: 1px solid #bfc8cb;
border-radius: 5px;
font-size: 0.72rem;
font-weight: 700;
cursor: pointer;
}
.control-button:hover {
border-color: var(--orange);
color: #9a421f;
}
.control-hint {
margin-left: auto;
color: #66767e;
font-size: 0.67rem;
}
#toast {
position: absolute;
z-index: 8;
left: 50%;
bottom: 82px;
transform: translate(-50%, 12px);
max-width: min(440px, 85vw);
padding: 9px 13px;
color: white;
background: rgba(25, 43, 52, 0.92);
border-radius: 6px;
box-shadow: var(--shadow);
font-size: 0.78rem;
opacity: 0;
pointer-events: none;
transition: opacity 160ms ease, transform 160ms ease;
}
#toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
aside {
min-height: 0;
overflow-y: auto;
padding: 18px;
background: var(--panel);
border-left: 1px solid var(--line);
box-shadow: -8px 0 25px rgba(40, 52, 57, 0.06);
}
aside section {
padding-bottom: 18px;
margin-bottom: 18px;
border-bottom: 1px solid var(--line);
}
aside section:last-child {
padding-bottom: 0;
margin-bottom: 0;
border-bottom: 0;
}
h2,
h3 {
margin: 0 0 9px;
line-height: 1.2;
}
h2 {
font-size: 1.12rem;
}
h3 {
font-size: 0.78rem;
letter-spacing: 0.08em;
text-transform: uppercase;
}
p {
margin: 0 0 10px;
color: var(--muted);
font-size: 0.8rem;
line-height: 1.5;
}
.sidebar-warning {
padding: 10px 11px;
margin-bottom: 13px;
color: #643318;
background: var(--orange-soft);
border-left: 4px solid var(--orange);
border-radius: 4px;
font-size: 0.76rem;
line-height: 1.45;
}
label.field-label {
display: block;
margin: 8px 0 5px;
color: #4b5d66;
font-size: 0.68rem;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
select {
width: 100%;
padding: 9px 10px;
color: var(--ink);
background: white;
border: 1px solid #bcc6c9;
border-radius: 5px;
cursor: pointer;
}
#scenario-note {
min-height: 38px;
margin-top: 7px;
font-size: 0.74rem;
}
#service-tabs {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
margin: 9px 0 14px;
}
.service-tab {
display: flex;
align-items: center;
gap: 7px;
min-height: 40px;
padding: 7px 8px;
text-align: left;
background: #fff;
border: 1px solid #c9d0d1;
border-radius: 5px;
font-size: 0.72rem;
font-weight: 700;
cursor: pointer;
}
.service-tab:hover {
border-color: var(--service-color);
}
.service-tab.active {
color: #fff;
background: var(--service-color);
border-color: var(--service-color);
box-shadow: 0 3px 9px color-mix(in srgb, var(--service-color) 30%, transparent);
}
.service-dot {
flex: 0 0 auto;
width: 10px;
height: 10px;
background: var(--service-color);
border-radius: 2px;
}
.service-tab.active .service-dot {
background: #fff;
}
#option-list {
display: grid;
gap: 7px;
margin-bottom: 11px;
}
.option-card {
display: grid;
grid-template-columns: 27px 1fr;
gap: 8px;
width: 100%;
padding: 9px;
text-align: left;
background: #fff;
border: 1px solid #cbd2d2;
border-radius: 6px;
cursor: pointer;
}
.option-card:hover {
border-color: #cc8b35;
}
.option-card.selected {
background: #fff8e9;
border: 2px solid #d79224;
padding: 8px;
}
.option-letter {
display: grid;
place-items: center;
width: 25px;
height: 25px;
color: #6b470f;
background: #ffe3a6;
border-radius: 4px;
font-size: 0.74rem;
font-weight: 900;
}
.option-name {
display: flex;
justify-content: space-between;
gap: 8px;
font-size: 0.76rem;
font-weight: 800;
}
.placed-badge {
flex: 0 0 auto;
padding: 2px 5px;
color: #24614d;
background: #dff4e8;
border-radius: 3px;
font-size: 0.57rem;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.option-zone {
display: block;
margin-top: 3px;
color: #738087;
font-size: 0.65rem;
font-weight: 600;
}
#inspector {
padding: 11px;
background: #f0f3f2;
border: 1px solid #d1d9d8;
border-radius: 6px;
}
.inspector-kicker {
margin-bottom: 5px;
color: #8a5a22;
font-size: 0.61rem;
font-weight: 900;
letter-spacing: 0.09em;
text-transform: uppercase;
}
#inspector h4 {
margin: 0 0 6px;
font-size: 0.88rem;
}
#inspector p {
margin-bottom: 9px;
font-size: 0.74rem;
}
.metric-tags {
display: flex;
flex-wrap: wrap;
gap: 5px;
margin-bottom: 10px;
}
.metric-tags span {
padding: 4px 6px;
color: #41545d;
background: #fff;
border: 1px solid #d4dcdb;
border-radius: 4px;
font-size: 0.62rem;
font-weight: 700;
}
.primary-button {
width: 100%;
padding: 9px 10px;
color: #fff;
background: #254c5d;
border: 0;
border-radius: 5px;
font-size: 0.75rem;
font-weight: 800;
cursor: pointer;
}
.primary-button:hover {
background: #183b4a;
}
.primary-button:disabled {
color: #52635d;
background: #dce7df;
cursor: default;
}
#placement-list {
display: grid;
gap: 6px;
}
.placement-row {
display: grid;
grid-template-columns: 11px 1fr;
gap: 8px;
align-items: start;
padding: 7px 8px;
background: #fff;
border: 1px solid #d8dddd;
border-radius: 5px;
font-size: 0.7rem;
}
.placement-row .service-dot {
width: 9px;
height: 9px;
margin-top: 3px;
}
.placement-row strong {
display: block;
font-size: 0.71rem;
}
.placement-row span {
display: block;
margin-top: 2px;
color: #738087;
font-size: 0.63rem;
}
.model-lens {
padding: 11px;
background: #eef4f5;
border: 1px solid #cadadc;
border-radius: 6px;
}
.model-lens p:last-child {
margin-bottom: 0;
}
.fine-print {
color: #78858b;
font-size: 0.68rem;
}
@media (max-width: 980px) {
body {
overflow: auto;
}
#app {
height: auto;
min-height: 100%;
}
header {
grid-template-columns: 1fr;
gap: 11px;
}
.fiction-warning {
padding-left: 0;
padding-top: 10px;
border-left: 0;
border-top: 1px solid rgba(255, 255, 255, 0.24);
}
main {
display: block;
}
#viewport {
height: 65vh;
min-height: 500px;
}
aside {
max-height: none;
border-left: 0;
border-top: 1px solid var(--line);
}
#service-tabs {
grid-template-columns: repeat(3, 1fr);
}
}
@media (max-width: 620px) {
header {
padding: 13px 15px;
}
#viewport {
height: 58vh;
min-height: 430px;
}
#service-tabs {
grid-template-columns: 1fr 1fr;
}
#viewport-top {
top: 9px;
left: 9px;
right: 9px;
}
.view-badge,
.control-hint {
display: none;
}
#bottom-controls {
left: 8px;
right: 8px;
bottom: 8px;
gap: 7px;
}
.scene-label.context {
display: none !important;
}
}
</style>
</head>
<body>
<div id="app">
<header>
<div>
<p class="eyebrow">Educational Voxel Scene · August 28, 1963</p>
<h1>March on Washington for Jobs and Freedom</h1>
<p class="subtitle">Washington Mall · Inspect a fictional service-placement exercise</p>
</div>
<div class="fiction-warning">
<strong>Clearly fictional educational model</strong>
<p>
Landmark references evoke the real setting, but the colored service sites,
candidate locations, scenarios, and planning judgments are invented.
They are not a reconstruction or evidence of actual event organizers’
decisions, and they should not be read as documenting historical operations.
</p>
</div>
</header>
<main>
<section id="viewport" aria-label="Interactive voxel model of the Washington Mall">
<div id="canvas-wrap"></div>
<div id="labels"></div>
<div id="viewport-top">
<div class="model-badge">Fictional logistics model</div>
<div class="view-badge">Schematic space · not an archival reconstruction</div>
</div>
<div id="bottom-controls">
<div class="control-group">
<label><input id="toggle-current" type="checkbox" checked> Placements</label>
<label><input id="toggle-candidates" type="checkbox" checked> Candidates</label>
<label><input id="toggle-crowd" type="checkbox" checked> Crowd</label>
<label><input id="toggle-context" type="checkbox" checked> Context labels</label>
</div>
<button id="reset-view" class="control-button" type="button">Reset view</button>
<div class="control-hint">Drag: orbit · Shift/right-drag: pan · Wheel/pinch: zoom · Click: inspect</div>
</div>
<div id="toast" role="status" aria-live="polite"></div>
</section>
<aside aria-label="Fictional service-placement controls">
<section>
<h2>Fictional logistics lab</h2>
<div class="sidebar-warning">
<strong>This is an exercise, not historical evidence.</strong>
Every service type, colored booth, site, scenario, and qualitative outcome
below was invented for this educational model.
</div>
<label class="field-label" for="scenario">Invented scenario</label>
<select id="scenario">
<option value="balanced">Balanced fictional plan</option>
<option value="program">Program-side emphasis</option>
<option value="perimeter">Perimeter-spread plan</option>
<option value="custom" disabled>Custom fictional plan</option>
</select>
<p id="scenario-note"></p>
</section>
<section>
<h3>1. Inspect a fictional service</h3>
<div id="service-tabs"></div>
<h3>2. Compare candidate locations</h3>
<p>
Select a card to inspect it, then choose whether to place that
fictional location in the model.
</p>
<div id="option-list"></div>
<div id="inspector" aria-live="polite"></div>
</section>
<section>
<h3>Current fictional placements</h3>
<div id="placement-list"></div>
</section>
<section>
<h3>How to read the model</h3>
<div class="model-lens">
<p>
The exercise evaluates only three assumed planning lenses:
distance within a schematic crowd, path conflict, and geographic
spread among attendees.
</p>
<p>
“Broad,” “moderate,” and “local” are qualitative teaching labels.
They are not historical distances, measured outcomes, or evidence
about how real organizers operated.
</p>
</div>
</section>
<section>
<h3>Historical frame</h3>
<p>
The real March on Washington for Jobs and Freedom took place on
August 28, 1963, with the Lincoln Memorial as the central setting
for its program.
</p>
<p>
This voxel scene simplifies landmark scale, crowd density, paths,
the program platform, and the number and placement of service points.
It does not reconstruct the historical site plan.
</p>
<p class="fine-print">
Educational use only. The service categories are deliberately generic
and fictional; their inclusion does not imply that comparable services
existed or were arranged in this way.
</p>
</section>
</aside>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// State and instructional data
// ---------------------------------------------------------------------
const services = {
firstAid: {
name: "First aid",
color: "#e85d55",
glyph: "+"
},
water: {
name: "Water",
color: "#3497c8",
glyph: "W"
},
support: {
name: "Mobility support",
color: "#249b78",
glyph: "S"
},
info: {
name: "Information",
color: "#e3a12f",
glyph: "i"
},
waste: {
name: "Waste station",
color: "#9168b5",
glyph: "B"
}
};
const candidates = {
firstAid: [
{
id: "A",
name: "Memorial-side aid point",
zone: "South program edge",
x: 14,
z: 75,
description:
"A fictional aid post close to the schematic program-side crowd. It offers short modeled access for people already near that end of the scene, but may draw incidental foot traffic toward the forecourt.",
reach: "Reach: program-focused",
route: "Route impact: moderate",
spread: "Spread: limited"
},
{
id: "B",
name: "East Mall aid point",
zone: "East central service band",
x: 42,
z: 35,
description:
"A fictional aid point in the east central service band. This is the most balanced of the invented choices because it can serve the central crowd without occupying the main north-south desire line.",
reach: "Reach: broad",
route: "Route impact: low",
spread: "Spread: balanced"
},
{
id: "C",
name: "West approach aid point",
zone: "West gateway",
x: -42,
z: 12,
description:
"A fictional aid point near the west approach. It spreads service toward an edge of the schematic crowd, but it is modeled as less convenient for people gathered near the program.",
reach: "Reach: approach-focused",
route: "Route impact: moderate",
spread: "Spread: west-weighted"
}
],
water: [
{
id: "A",
name: "Memorial-side water point",
zone: "South service edge",
x: 24,
z: 70,
description:
"A fictional water point on the program-side edge of the crowd. It reduces modeled walking distance for the southern cluster, though it concentrates service in one part of the scene.",
reach: "Reach: program-side",
route: "Route impact: moderate",
spread: "Spread: concentrated"
},
{
id: "B",
name: "East central water point",
zone: "East central service band",
x: 40,
z: 45,
description:
"A fictional water point along the east side of the central crowd. The assumed trade-off is broad access without blocking the primary cross-Mall walking line.",
reach: "Reach: broad",
route: "Route impact: low",
spread: "Spread: east-weighted"
},
{
id: "C",
name: "West central water point",
zone: "West central service band",
x: -40,
z: 45,
description:
"A fictional water point along the west side of the central crowd. It creates a west-side counterpart to the east option, but leaves the opposite side less directly served.",
reach: "Reach: broad",
route: "Route impact: low",
spread: "Spread: west-weighted"
}
],
support: [
{
id: "A",
name: "Accessible viewing-side rendezvous",
zone: "South-east viewing band",
x: 18,
z: 72,
description:
"An invented mobility-support rendezvous near the schematic viewing area. The model treats it as convenient for attendees seeking a transfer or rest point near the program.",
reach: "Reach: viewing-focused",
route: "Route impact: moderate",
spread: "Spread: south-focused"
},
{
id: "B",
name: "East transfer rendezvous",
zone: "East service band",
x: 45,
z: 58,
description:
"An invented mobility-support rendezvous at the east edge of the crowd. The assumed benefit is easier access for people arriving from that side without placing it in the central walking corridor.",
reach: "Reach: east-focused",
route: "Route impact: low",
spread: "Spread: east-weighted"
},
{
id: "C",
name: "West approach rendezvous",
zone: "West gateway",
x: -42,
z: 12,
description:
"An invented mobility-support rendezvous near the west approach. This spreads the fictional service geographically, but the model treats it as less convenient for people already in the southern crowd.",
reach: "Reach: approach-focused",
route: "Route impact: low",
spread: "Spread: west-weighted"
}
],
info: [
{
id: "A",
name: "Program-side orientation desk",
zone: "South program edge",
x: 0,
z: 68,
description:
"An invented orientation desk near the schematic program area. It is modeled as easy for nearby attendees to find, but its central location may become a gathering and route-conflict point.",
reach: "Reach: program-focused",
route: "Route impact: high",
spread: "Spread: limited"
},
{
id: "B",
name: "East central information desk",
zone: "East central service band",
x: 42,
z: 35,
description:
"An invented information desk along the east service band. The model assumes a reasonable central reach while keeping the desk out of the principal north-south path.",
reach: "Reach: broad",
route: "Route impact: low",
spread: "Spread: east-weighted"
},
{
id: "C",
name: "West approach information desk",
zone: "West gateway",
x: -42,
z: 12,
description:
"An invented information desk at the west approach. It serves people entering from that side and balances the right-side information placement, but is farther from the central crowd.",
reach: "Reach: approach-focused",
route: "Route impact: low",
spread: "Spread: west-weighted"
}
],
waste: [
{
id: "A",
name: "East perimeter service bay",
zone: "East outer edge",
x: 52,
z: 28,
description:
"An invented waste station at the east perimeter. The model treats the edge as less likely to interrupt main walking routes, while accepting a longer carry distance from the crowd center.",
reach: "Reach: edge-focused",
route: "Route impact: low",
spread: "Spread: east-weighted"
},
{
id: "B",
name: "West perimeter service bay",
zone: "West outer edge",
x: -52,
z: 28,
description:
"An invented waste station at the west perimeter. Like the east option, it is assumed to preserve main routes, but it shifts the assumed collection burden toward the west side.",
reach: "Reach: edge-focused",
route: "Route impact: low",
spread: "Spread: west-weighted"
},
{
id: "C",
name: "Rear support edge bay",
zone: "South-east service edge",
x: 25,
z: 99,
description:
"An invented waste station behind the schematic crowd near the memorial-side edge. It keeps the central area clear but is modeled as remote from most of the gathering area.",
reach: "Reach: local",
route: "Route impact: low",
spread: "Spread: south-focused"
}
]
};
const scenarios = {
balanced: {
note:
"This invented plan distributes most fictional services across the central and outer crowd while retaining one program-side water point.",
placements: {
firstAid: "B",
water: "A",
support: "B",
info: "C",
waste: "A"
}
},
program: {
note:
"This invented plan concentrates several services near the schematic program area. The model invites discussion of convenience versus route conflict.",
placements: {
firstAid: "A",
water: "A",
support: "A",
info: "A",
waste: "C"
}
},
perimeter: {
note:
"This invented plan spreads support and information toward the west approach while using outer service edges. It is a teaching scenario, not a historical plan.",
placements: {
firstAid: "C",
water: "C",
support: "C",
info: "C",
waste: "B"
}
}
};
const state = {
scenario: "balanced",
service: "firstAid",
placements: { ...scenarios.balanced.placements },
inspect: { type: "candidate", candidateId: "A" },
showCurrent: true,
showCandidates: true,
showCrowd: true,
showContext: true
};
// ---------------------------------------------------------------------
// Renderer, scene, and camera
// ---------------------------------------------------------------------
const viewport = document.querySelector("#viewport");
const canvasWrap = document.querySelector("#canvas-wrap");
const labelsRoot = document.querySelector("#labels");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcfe3e8);
scene.fog = new THREE.Fog(0xcfe3e8, 340, 650);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.domElement.setAttribute(
"aria-label",
"Voxel model of the March on Washington with fictional service-placement options"
);
renderer.domElement.tabIndex = 0;
canvasWrap.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-100, 100, 100, -100, 0.1, 1000);
const controls = {
target: new THREE.Vector3(0, 0, 3),
yaw: 0.43,
pitch: 0.77,
zoom: 0.9,
baseExtent: 105,
radius: 320
};
function updateCamera() {
const cp = Math.cos(controls.pitch);
camera.position.set(
controls.target.x + Math.sin(controls.yaw) * cp * controls.radius,
controls.target.y + Math.sin(controls.pitch) * controls.radius,
controls.target.z + Math.cos(controls.yaw) * cp * controls.radius
);
camera.lookAt(controls.target);
const aspect = Math.max(0.2, viewport.clientWidth / viewport.clientHeight);
const half = controls.baseExtent / controls.zoom;
camera.left = -half * aspect;
camera.right = half * aspect;
camera.top = half;
camera.bottom = -half;
camera.updateProjectionMatrix();
}
function resetView() {
controls.target.set(0, 0, 3);
controls.yaw = 0.43;
controls.pitch = 0.77;
controls.zoom = 0.9;
updateCamera();
}
const hemi = new THREE.HemisphereLight(0xf4fbff, 0x66765f, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1d3, 3.0);
sun.position.set(-85, 150, 95);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -180;
sun.shadow.camera.right = 180;
sun.shadow.camera.top = 180;
sun.shadow.camera.bottom = -180;
sun.shadow.camera.near = 10;
sun.shadow.camera.far = 420;
sun.shadow.bias = -0.0005;
scene.add(sun);
// ---------------------------------------------------------------------
// Voxel construction helpers
// ---------------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
flatShading: true,
...options
});
const materials = {
ground: material(0x789569),
grass: material(0x829b6b),
path: material(0xc9b996),
plaza: material(0xd2c4a5),
stone: material(0xd9d3c4),
whiteStone: material(0xf0ebdc),
monument: material(0xd8d3c8),
monumentDark: material(0xc7c2b7),
water: material(0x61a9c0, { roughness: 0.35, metalness: 0.05 }),
waterLight: material(0xaed9df, { roughness: 0.3 }),
trunk: material(0x6c513a),
leaf: material(0x537a52),
leafLight: material(0x6d8d59),
cloud: material(0xf4f3e9),
stage: material(0x8c7254),
screen: material(0x273b43),
black: material(0x26363c)
};
function makeBox(parent, width, height, depth, x, y, z, mat, cast = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeTextPanel(text, width, height, background = "#263b43", foreground = "#fff4dc") {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = foreground;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "900 82px monospace";
ctx.fillText(text, canvas.width / 2, canvas.height / 2, 940);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.NearestFilter;
texture.magFilter = THREE.NearestFilter;
const mat = new THREE.MeshBasicMaterial({
map: texture,
side: THREE.DoubleSide
});
return new THREE.Mesh(new THREE.PlaneGeometry(width, height), mat);
}
const environment = new THREE.Group();
scene.add(environment);
// Ground, paths, and landscape
makeBox(environment, 220, 3, 270, 0, -1.5, 5, materials.ground, false);
makeBox(environment, 214, 0.25, 264, 0, 0.1, 5, materials.grass, false);
// Perimeter paths
makeBox(environment, 22, 0.28, 264, -77, 0.2, 5, materials.path, false);
makeBox(environment, 22, 0.28, 264, 77, 0.2, 5, materials.path, false);
// Cross paths around the crowd and plaza
makeBox(environment, 218, 0.28, 18, 0, 0.22, 48, materials.path, false);
makeBox(environment, 218, 0.28, 14, 0, 0.22, -60, materials.path, false);
makeBox(environment, 104, 0.3, 50, 0, 0.24, 101, materials.plaza, false);
// Reflecting Pool
makeBox(environment, 39, 0.6, 101, 0, 0.48, -6, materials.stone, false);
makeBox(environment, 31, 0.28, 93, 0, 0.83, -6, materials.water, false);
for (let i = 0; i < 22; i++) {
const z = -48 + i * 4;
const x = Math.sin(i * 2.17) * 8;
makeBox(
environment,
3.4 + (i % 3),
0.08,
0.45,
x,
1.01,
z,
materials.waterLight,
false
);
}
// Washington Monument — simplified voxel landmark
makeBox(environment, 49, 0.5, 49, 0, 0.38, -86, materials.plaza, false);
makeBox(environment, 30, 5, 30, 0, 3.1, -86, materials.monumentDark);
makeBox(environment, 14, 34, 14, 0, 22.6, -86, materials.monument);
makeBox(environment, 11, 23, 11, 0, 50.8, -86, materials.monument);
makeBox(environment, 7.5, 10, 7.5, 0, 67.3, -86, materials.whiteStone);
makeBox(environment, 3, 3, 3, 0, 73.8, -86, materials.monumentDark);
// Lincoln Memorial — simplified voxel landmark
for (let i = 0; i < 5; i++) {
makeBox(
environment,
88 - i * 5,
1.1,
7,
0,
0.8 + i * 1.05,
72 + i * 3,
materials.whiteStone
);
}
makeBox(environment, 66, 19, 27, 0, 12.2, 101, materials.monument);
makeBox(environment, 72, 5, 37, 0, 26.8, 99, materials.whiteStone);
makeBox(environment, 62, 3, 31, 0, 30.8, 99, materials.stone);
for (let i = 0; i < 11; i++) {
const x = -30 + i * 6;
makeBox(environment, 3.1, 20, 3.1, x, 12.8, 84.2, materials.whiteStone);
makeBox(environment, 4.3, 1.2, 4.3, x, 23.2, 84.2, materials.stone);
}
// Illustrative program platform and event sign
makeBox(environment, 24, 2.2, 9, 0, 1.3, 69, materials.stage);
makeBox(environment, 2.2, 3.2, 2.2, 0, 3.8, 69, materials.screen);
makeBox(environment, 29, 7.5, 1.2, 0, 13.1, 68.7, materials.screen);
const eventSign = makeTextPanel(
"JOBS AND FREEDOM",
27,
5.8,
"#243c46",
"#f8e4b8"
);
eventSign.position.set(0, 13.1, 69.35);
environment.add(eventSign);
// Voxel trees along the edges
function addTree(x, z, scale = 1) {
makeBox(
environment,
1.5 * scale,
7 * scale,
1.5 * scale,
x,
3.5 * scale,
z,
materials.trunk
);
makeBox(
environment,
7 * scale,
6 * scale,
7 * scale,
x,
9 * scale,
z,
materials.leaf
);
makeBox(
environment,
5 * scale,
4 * scale,
5 * scale,
x + 1.3 * scale,
12 * scale,
z - 0.8 * scale,
materials.leafLight
);
}
for (let i = 0; i < 13; i++) {
const z = -95 + i * 18;
addTree(-96, z, 0.85 + (i % 3) * 0.08);
addTree(96, z - 5, 0.85 + (i % 2) * 0.08);
}
// Blocky clouds
const cloudMat = materials.cloud;
[
[-78, 98, -45, 1.0],
[65, 112, -10, 1.25],
[4, 125, -105, 0.8]
].forEach(([x, y, z, s]) => {
makeBox(environment, 26 * s, 7 * s, 12 * s, x, y, z, cloudMat, false);
makeBox(environment, 15 * s, 9 * s, 13 * s, x - 6 * s, y + 5 * s, z, cloudMat, false);
makeBox(environment, 13 * s, 6 * s, 11 * s, x + 10 * s, y + 3 * s, z, cloudMat, false);
});
// ---------------------------------------------------------------------
// Schematic crowd
// ---------------------------------------------------------------------
const crowdGroup = new THREE.Group();
scene.add(crowdGroup);
function mulberry32(seed) {
return function () {
let t = seed += 0x6D2B79F5;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = mulberry32(1963);
const personCount = 230;
const bodyGeometry = new THREE.BoxGeometry(2.1, 3.7, 1.35);
const headGeometry = new THREE.BoxGeometry(1.35, 1.35, 1.35);
const bodyMaterial = material(0xffffff);
const headMaterial = material(0xffffff);
const bodies = new THREE.InstancedMesh(bodyGeometry, bodyMaterial, personCount);
const heads = new THREE.InstancedMesh(headGeometry, headMaterial, personCount);
bodies.castShadow = true;
bodies.receiveShadow = true;
heads.castShadow = true;
const clothing = [
0x3e6173, 0x8c443b, 0xb7923f, 0x46554b, 0x6d4e73,
0xc4b08a, 0x28556a, 0x984b38, 0x4e7255, 0x8a7657
];
const skin = [0x6f4935, 0x8d6247, 0xb88764, 0xd0a47e, 0x5c3d2c];
const matrix = new THREE.Matrix4();
const position = new THREE.Vector3();
const quaternion = new THREE.Quaternion();
const scale = new THREE.Vector3(1, 1, 1);
const color = new THREE.Color();
for (let i = 0; i < personCount; i++) {
let x = (random() - 0.5) * 108;
let z = 30 + random() * 47;
// Keep a small central aisle and avoid placing people in the pool.
if (Math.abs(x) < 7) x += x < 0 ? -8 : 8;
if (z > 63 && Math.abs(x) < 19) z -= 4;
position.set(x, 2.05, z);
matrix.compose(position, quaternion, scale);
bodies.setMatrixAt(i, matrix);
bodies.setColorAt(i, color.setHex(clothing[i % clothing.length]));
position.set(x, 4.55, z);
matrix.compose(position, quaternion, scale);
heads.setMatrixAt(i, matrix);
heads.setColorAt(i, color.setHex(skin[i % skin.length]));
}
bodies.instanceMatrix.needsUpdate = true;
heads.instanceMatrix.needsUpdate = true;
bodies.instanceColor.needsUpdate = true;
heads.instanceColor.needsUpdate = true;
crowdGroup.add(bodies, heads);
// A few illustrative crowd signs
const crowdSigns = [
[-27, 43, "JOBS AND FREEDOM"],
[-8, 58, "EQUAL RIGHTS"],
[17, 48, "DECENT WORK"],
[32, 61, "JOBS AND FREEDOM"]
];
for (const [x, z, text] of crowdSigns) {
makeBox(crowdGroup, 0.55, 8, 0.55, x, 4, z, materials.trunk);
const sign = makeTextPanel(text, 10, 2.6, "#6f3e36", "#f6e5bd");
sign.position.set(x, 8.5, z + 0.35);
crowdGroup.add(sign);
}
// ---------------------------------------------------------------------
// Fictional service markers
// ---------------------------------------------------------------------
const currentGroup = new THREE.Group();
const candidateGroup = new THREE.Group();
scene.add(currentGroup, candidateGroup);
let currentClickables = [];
let candidateClickables = [];
function clearGroup(group) {
while (group.children.length) {
const child = group.children[0];
child.traverse((object) => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
const mats = Array.isArray(object.material)
? object.material
: [object.material];
for (const mat of mats) {
if (mat.map) mat.map.dispose();
mat.dispose();
}
}
});
group.remove(child);
}
}
function markerMaterials(color) {
return {
body: material(color),
roof: material(new THREE.Color(color).multiplyScalar(0.72)),
pale: material(0xf7f0da)
};
}
function makeCurrentMarker(serviceId, candidate) {
const service = services[serviceId];
const mats = markerMaterials(service.color);
const group = new THREE.Group();
group.position.set(candidate.x, 0.3, candidate.z);
makeBox(group, 7.2, 0.5, 7.2, 0, 0.25, 0, mats.pale);
makeBox(group, 5.4, 3.4, 5.4, 0, 2.1, 0, mats.body);
makeBox(group, 7.2, 0.8, 7.2, 0, 4.2, 0, mats.roof);
const icon = makeTextPanel(
service.glyph,
2.8,
2.1,
service.color,
"#fffdf3"
);
icon.position.set(0, 2.15, 2.76);
group.add(icon);
group.userData = {
clickType: "current",
serviceId,
candidateId: candidate.id
};
return group;
}
function makeCandidateMarker(serviceId, candidate) {
const group = new THREE.Group();
group.position.set(candidate.x, 0.3, candidate.z);
const fillMat = new THREE.MeshBasicMaterial({
color: 0xffc75a,
transparent: true,
opacity: 0.14,
depthWrite: false
});
const base = new THREE.Mesh(
new THREE.BoxGeometry(8.5, 0.35, 8.5),
fillMat
);
base.position.y = 0.2;
group.add(base);
const box = new THREE.Mesh(
new THREE.BoxGeometry(6.8, 4.2, 6.8),
new THREE.MeshBasicMaterial({
color: 0xffd679,
transparent: true,
opacity: 0.1,
depthWrite: false
})
);
box.position.y = 2.3;
group.add(box);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(6.8, 4.2, 6.8)),
new THREE.LineBasicMaterial({
color: 0xd28a1b,
transparent: true,
opacity: 0.95
})
);
edges.position.y = 2.3;
group.add(edges);
makeBox(
group,
0.45,
4.8,
0.45,
0,
2.4,
0,
material(0xe1a63b)
);
group.userData = {
clickType: "candidate",
serviceId,
candidateId: candidate.id
};
return group;
}
function buildCurrentMarkers() {
clearGroup(currentGroup);
currentClickables = [];
for (const serviceId of Object.keys(services)) {
const candidate = candidates[serviceId].find(
(item) => item.id === state.placements[serviceId]
);
const marker = makeCurrentMarker(serviceId, candidate);
currentGroup.add(marker);
currentClickables.push(marker);
}
currentGroup.visible = state.showCurrent;
rebuildCurrentLabels();
}
function buildCandidateMarkers() {
clearGroup(candidateGroup);
candidateClickables = [];
for (const candidate of candidates[state.service]) {
const marker = makeCandidateMarker(state.service, candidate);
candidateGroup.add(marker);
candidateClickables.push(marker);
}
candidateGroup.visible = state.showCandidates;
}
// ---------------------------------------------------------------------
// Projected HTML labels
// ---------------------------------------------------------------------
const labels = [];
function addLabel(text, world, className, visible = () => true, extra = null) {
const element = document.createElement("div");
element.className = `scene-label ${className}`;
element.innerHTML = text;
labelsRoot.appendChild(element);
const label = {
element,
world: world.clone(),
visible
};
if (extra) Object.assign(label, extra);
labels.push(label);
return label;
}
const contextLabels = [
addLabel(
"Washington Monument · simplified",
new THREE.Vector3(0, 81, -86),
"context",
() => state.showContext
),
addLabel(
"Reflecting Pool",
new THREE.Vector3(0, 3, -6),
"context",
() => state.showContext
),
addLabel(
"Lincoln Memorial · simplified",
new THREE.Vector3(0, 37, 100),
"context",
() => state.showContext
),
addLabel(
"Illustrative program platform",
new THREE.Vector3(0, 20, 69),
"context",
() => state.showContext
),
addLabel(
"Schematic crowd — not an archival reconstruction",
new THREE.Vector3(-20, 8, 45),
"context",
() => state.showContext
)
];
function rebuildCurrentLabels() {
for (const label of labels) {
if (label.serviceLabel) {
label.element.remove();
labels.splice(labels.indexOf(label), 1);
}
}
for (const serviceId of Object.keys(services)) {
const service = services[serviceId];
const candidate = candidates[serviceId].find(
(item) => item.id === state.placements[serviceId]
);
addLabel(
`<strong>${service.name}</strong><span>${candidate.zone}</span>`,
new THREE.Vector3(candidate.x, 7.2, candidate.z),
"service",
() => state.showCurrent,
{
serviceLabel: true,
serviceColor: service.color
}
).element.style.setProperty("--label-color", service.color);
}
}
function rebuildCandidateLabel() {
const old = labels.find((label) => label.candidateLabel);
if (old) {
old.element.remove();
labels.splice(labels.indexOf(old), 1);
}
if (state.inspect.type !== "candidate") return;
const candidate = candidates[state.service].find(
(item) => item.id === state.inspect.candidateId
);
if (!candidate) return;
addLabel(
`Candidate ${candidate.id} · ${candidates[state.service].find(x => x.id === candidate.id).name}`,
new THREE.Vector3(candidate.x, 7.2, candidate.z),
"candidate",
() => state.showCandidates,
{ candidateLabel: true }
);
}
const projected = new THREE.Vector3();
function positionLabels() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
for (const label of labels) {
projected.copy(label.world).project(camera);
const visible =
label.visible() &&
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.1 &&
projected.x < 1.1 &&
projected.y > -1.1 &&
projected.y < 1.1;
if (!visible) {
label.element.style.display = "none";
continue;
}
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.display = "block";
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
// ---------------------------------------------------------------------
// Interface
// ---------------------------------------------------------------------
const serviceTabs = document.querySelector("#service-tabs");
const optionList = document.querySelector("#option-list");
const inspector = document.querySelector("#inspector");
const placementList = document.querySelector("#placement-list");
const scenarioSelect = document.querySelector("#scenario");
const scenarioNote = document.querySelector("#scenario-note");
const toast = document.querySelector("#toast");
let toastTimer;
function showToast(message) {
toast.textContent = message;
toast.classList.add("visible");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("visible"), 2200);
}
function renderServiceTabs() {
serviceTabs.innerHTML = "";
for (const [serviceId, service] of Object.entries(services)) {
const button = document.createElement("button");
button.type = "button";
button.className = "service-tab";
button.classList.toggle("active", state.service === serviceId);
button.style.setProperty("--service-color", service.color);
button.innerHTML = `
<span class="service-dot"></span>
<span>${service.name}</span>
`;
button.addEventListener("click", () => selectService(serviceId));
serviceTabs.appendChild(button);
}
}
function renderOptions() {
optionList.innerHTML = "";
const selected = state.inspect.type === "candidate"
? state.inspect.candidateId
: null;
for (const candidate of candidates[state.service]) {
const button = document.createElement("button");
button.type = "button";
button.className = "option-card";
button.classList.toggle("selected", selected === candidate.id);
const isPlaced = state.placements[state.service] === candidate.id;
button.innerHTML = `
<span class="option-letter">${candidate.id}</span>
<span>
<span class="option-name">
<span>${candidate.name}</span>
${isPlaced ? '<span class="placed-badge">Placed</span>' : ""}
</span>
<span class="option-zone">${candidate.zone}</span>
</span>
`;
button.addEventListener("click", () => {
state.inspect = { type: "candidate", candidateId: candidate.id };
renderOptions();
renderInspector();
rebuildCandidateLabel();
});
optionList.appendChild(button);
}
}
function renderInspector() {
const service = services[state.service];
if (state.inspect.type === "current") {
const candidate = candidates[state.service].find(
(item) => item.id === state.placements[state.service]
);
inspector.innerHTML = `
<div class="inspector-kicker">Current fictional placement</div>
<h4>${service.name} · ${candidate.name}</h4>
<p>${candidate.description}</p>
<div class="metric-tags">
<span>${candidate.reach}</span>
<span>${candidate.route}</span>
<span>${candidate.spread}</span>
</div>
<button id="edit-alternatives" class="primary-button" type="button">
Compare alternative locations
</button>
`;
document
.querySelector("#edit-alternatives")
.addEventListener("click", () => selectService(state.service));
return;
}
const candidate = candidates[state.service].find(
(item) => item.id === state.inspect.candidateId
) || candidates[state.service][0];
const alreadyPlaced = state.placements[state.service] === candidate.id;
inspector.innerHTML = `
<div class="inspector-kicker">Fictional candidate location</div>
<h4>${service.name} · ${candidate.name}</h4>
<p>${candidate.description}</p>
<div class="metric-tags">
<span>${candidate.reach}</span>
<span>${candidate.route}</span>
<span>${candidate.spread}</span>
</div>
<button id="use-candidate" class="primary-button" type="button"
${alreadyPlaced ? "disabled" : ""}>
${alreadyPlaced
? "Currently used in this fictional plan"
: "Use this fictional location"}
</button>
`;
const button = document.querySelector("#use-candidate");
if (!alreadyPlaced) {
button.addEventListener("click", () => {
state.placements[state.service] = candidate.id;
state.scenario = "custom";
scenarioSelect.value = "custom";
buildCurrentMarkers();
renderServiceTabs();
renderOptions();
renderInspector();
renderPlacements();
showToast(`${service.name} moved to a fictional candidate location.`);
});
}
}
function renderPlacements() {
placementList.innerHTML = "";
for (const [serviceId, service] of Object.entries(services)) {
const candidate = candidates[serviceId].find(
(item) => item.id === state.placements[serviceId]
);
const row = document.createElement("div");
row.className = "placement-row";
row.style.setProperty("--service-color", service.color);
row.innerHTML = `
<span class="service-dot"></span>
<span>
<strong>${service.name}</strong>
<span>${candidate.name} · ${candidate.zone}</span>
</span>
`;
placementList.appendChild(row);
}
}
function selectService(serviceId) {
state.service = serviceId;
state.inspect = {
type: "candidate",
candidateId: candidates[serviceId][0].id
};
buildCandidateMarkers();
renderServiceTabs();
renderOptions();
renderInspector();
rebuildCandidateLabel();
}
function applyScenario(scenarioId, announce = true) {
const scenario = scenarios[scenarioId];
if (!scenario) return;
state.scenario = scenarioId;
state.placements = { ...scenario.placements };
state.inspect = { type: "current" };
buildCurrentMarkers();
buildCandidateMarkers();
scenarioSelect.value = scenarioId;
scenarioNote.textContent = scenario.note;
renderServiceTabs();
renderOptions();
renderInspector();
renderPlacements();
rebuildCandidateLabel();
if (announce) {
showToast("Invented scenario applied. This is not a historical plan.");
}
}
scenarioSelect.addEventListener("change", () => {
applyScenario(scenarioSelect.value);
});
document.querySelector("#toggle-current").addEventListener("change", (event) => {
state.showCurrent = event.target.checked;
currentGroup.visible = state.showCurrent;
});
document.querySelector("#toggle-candidates").addEventListener("change", (event) => {
state.showCandidates = event.target.checked;
candidateGroup.visible = state.showCandidates;
});
document.querySelector("#toggle-crowd").addEventListener("change", (event) => {
state.showCrowd = event.target.checked;
crowdGroup.visible = state.showCrowd;
});
document.querySelector("#toggle-context").addEventListener("change", (event) => {
state.showContext = event.target.checked;
});
document.querySelector("#reset-view").addEventListener("click", resetView);
// ---------------------------------------------------------------------
// Direct camera controls — no Three.js addons
// ---------------------------------------------------------------------
const pointers = new Map();
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
let downInfo = null;
let gestureStartDistance = 0;
let gestureStartZoom = 1;
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function panCamera(dx, dy) {
const units = (2 * controls.baseExtent / controls.zoom) /
Math.max(1, viewport.clientHeight);
const right = new THREE.Vector3(
Math.cos(controls.yaw),
0,
-Math.sin(controls.yaw)
);
const forward = new THREE.Vector3(
-Math.sin(controls.yaw),
0,
-Math.cos(controls.yaw)
);
controls.target.addScaledVector(right, -dx * units);
controls.target.addScaledVector(forward, -dy * units);
controls.target.x = clamp(controls.target.x, -100, 100);
controls.target.z = clamp(controls.target.z, -110, 120);
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
startX: event.clientX,
startY: event.clientY
});
downInfo = {
x: event.clientX,
y: event.clientY,
moved: 0,
button: event.button,
shift: event.shiftKey
};
if (pointers.size === 2) {
const values = [...pointers.values()];
gestureStartDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
gestureStartZoom = controls.zoom;
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const pointer = pointers.get(event.pointerId);
if (!pointer) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (downInfo) {
downInfo.moved += Math.abs(dx) + Math.abs(dy);
}
if (pointers.size === 2) {
const values = [...pointers.values()];
const distance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (gestureStartDistance > 0) {
controls.zoom = clamp(
gestureStartZoom * distance / gestureStartDistance,
0.46,
2.5
);
updateCamera();
}
const centerX = (values[0].x + values[1].x) / 2;
const centerY = (values[0].y + values[1].y) / 2;
if (downInfo) {
const totalDx = centerX - downInfo.x;
const totalDy = centerY - downInfo.y;
panCamera(totalDx, totalDy);
downInfo.x = centerX;
downInfo.y = centerY;
}
return;
}
if (downInfo.button === 2 || downInfo.shift) {
panCamera(dx, dy);
} else {
controls.yaw -= dx * 0.006;
controls.pitch = clamp(
controls.pitch + dy * 0.005,
0.28,
1.38
);
updateCamera();
}
});
function isActuallyVisible(object) {
let current = object;
while (current) {
if (!current.visible) return false;
current = current.parent;
}
return true;
}
function findClickData(object) {
let current = object;
while (current) {
if (current.userData && current.userData.clickType) {
return current.userData;
}
current = current.parent;
}
return null;
}
function inspectSceneAt(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointerNDC.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
const clickables = [...currentClickables, ...candidateClickables];
const intersections = raycaster.intersectObjects(clickables, true);
for (const intersection of intersections) {
if (!isActuallyVisible(intersection.object)) continue;
const data = findClickData(intersection.object);
if (!data) continue;
state.service = data.serviceId;
if (data.clickType === "candidate") {
state.inspect = {
type: "candidate",
candidateId: data.candidateId
};
buildCandidateMarkers();
renderServiceTabs();
renderOptions();
renderInspector();
rebuildCandidateLabel();
} else {
state.inspect = { type: "current" };
buildCandidateMarkers();
renderServiceTabs();
renderOptions();
renderInspector();
rebuildCandidateLabel();
}
showToast(`${services[state.service].name}: ${data.candidateId} option inspected.`);
break;
}
}
renderer.domElement.addEventListener("pointerup", (event) => {
if (
downInfo &&
downInfo.moved < 8 &&
downInfo.button === 0 &&
pointers.size <= 1
) {
inspectSceneAt(event.clientX, event.clientY);
}
pointers.delete(event.pointerId);
downInfo = null;
});
renderer.domElement.addEventListener("pointercancel", (event) => {
pointers.delete(event.pointerId);
downInfo = null;
});
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
const factor = Math.exp(-event.deltaY * 0.0012);
controls.zoom = clamp(controls.zoom * factor, 0.46, 2.5);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("keydown", (event) => {
const step = 0.08;
if (event.key === "ArrowLeft") controls.yaw += step;
else if (event.key === "ArrowRight") controls.yaw -= step;
else if (event.key === "ArrowUp") controls.pitch = clamp(controls.pitch - step, 0.28, 1.38);
else if (event.key === "ArrowDown") controls.pitch = clamp(controls.pitch + step, 0.28, 1.38);
else if (event.key === "+" || event.key === "=") controls.zoom = clamp(controls.zoom * 1.1, 0.46, 2.5);
else if (event.key === "-") controls.zoom = clamp(controls.zoom / 1.1, 0.46, 2.5);
else if (event.key.toLowerCase() === "r") resetView();
else return;
event.preventDefault();
updateCamera();
});
// ---------------------------------------------------------------------
// Resize and render loop
// ---------------------------------------------------------------------
function resize() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
renderer.setSize(width, height, false);
updateCamera();
}
new ResizeObserver(resize).observe(viewport);
resize();
applyScenario("balanced", false);
resetView();
renderer.setAnimationLoop(() => {
positionLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```