Prompt specification
Build or customize the Three.js 3D scene "Harbor arrival to neighborhood settlement display" 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: Harbor arrival to neighborhood settlement display
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/harbor-arrival-to-neighborhood-settlement-display-x2583
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts immigrant arrival and processing at Ellis Island. Build a sourced historical sequence linking ship arrival, processing, ferry transfer, and a generic city neighborhood. Label the selected period and show that experiences varied. Voxel style.
Working Three.js Starter (harbor-arrival-to-neighborhood-settlement-display-x2583):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#183b45">
<title>Arrival at Ellis Island — A Voxel History</title>
<style>
:root {
--ink: #183b45;
--muted: #52666a;
--paper: rgba(255, 250, 238, 0.94);
--paper-solid: #fff9eb;
--line: rgba(24, 59, 69, 0.18);
--gold: #d4932f;
--gold-dark: #995c18;
--blue: #347c92;
--red: #b84f43;
--green: #53775c;
--shadow: 0 18px 50px rgba(22, 43, 49, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c9dfe1;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button,
select,
summary,
a {
font: inherit;
}
button,
select,
summary {
color: inherit;
}
a {
color: #225e73;
text-underline-offset: 2px;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
cursor: grab;
touch-action: none;
}
#scene.dragging {
cursor: grabbing;
}
.hero {
position: fixed;
z-index: 5;
top: 24px;
left: 26px;
width: min(430px, calc(100vw - 52px));
pointer-events: none;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.56);
border-radius: 3px;
background: rgba(255, 250, 238, 0.84);
box-shadow: 0 5px 18px rgba(25, 54, 61, 0.12);
color: var(--blue);
font-size: 0.7rem;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
background: var(--gold);
box-shadow: 0 0 0 3px rgba(212, 147, 47, 0.16);
}
h1 {
max-width: 400px;
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(2.35rem, 5vw, 4.15rem);
font-weight: 500;
line-height: 0.92;
letter-spacing: -0.055em;
}
.hero p {
max-width: 395px;
margin: 14px 0 0;
color: #314f57;
font-size: 0.92rem;
line-height: 1.48;
text-wrap: balance;
}
.period-badge {
display: inline-flex;
align-items: baseline;
gap: 8px;
margin-top: 15px;
padding: 9px 12px;
border-left: 4px solid var(--gold);
background: rgba(255, 250, 238, 0.9);
box-shadow: 0 5px 18px rgba(25, 54, 61, 0.12);
font-size: 0.75rem;
letter-spacing: 0.04em;
}
.period-badge span {
color: var(--muted);
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.1em;
}
.period-badge strong {
font-size: 0.88rem;
}
.story-panel {
position: fixed;
z-index: 10;
top: 24px;
right: 24px;
width: min(370px, calc(100vw - 48px));
max-height: calc(100vh - 154px);
overflow: auto;
padding: 20px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 5px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
scrollbar-width: thin;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
color: var(--muted);
font-size: 0.68rem;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
#stageCounter {
color: var(--gold-dark);
font-variant-numeric: tabular-nums;
}
.story-panel h2 {
margin: 0 0 9px;
font-family: Georgia, "Times New Roman", serif;
font-size: 1.75rem;
font-weight: 500;
line-height: 1.04;
letter-spacing: -0.025em;
}
.story-copy {
margin: 0;
color: #40575d;
font-size: 0.9rem;
line-height: 1.55;
}
.variation {
position: relative;
margin-top: 15px;
padding: 13px 14px 13px 16px;
border: 1px solid rgba(184, 79, 67, 0.22);
background: rgba(184, 79, 67, 0.065);
}
.variation::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 4px;
background: var(--red);
}
.variation strong {
display: block;
margin-bottom: 5px;
color: #8f4037;
font-size: 0.68rem;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.variation p {
margin: 0;
color: #5d4e49;
font-size: 0.84rem;
line-height: 1.5;
}
.era-picker {
margin-top: 17px;
padding-top: 16px;
border-top: 1px solid var(--line);
}
.era-picker label {
display: block;
margin-bottom: 7px;
color: var(--muted);
font-size: 0.68rem;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
select {
width: 100%;
padding: 10px 34px 10px 11px;
border: 1px solid rgba(24, 59, 69, 0.2);
border-radius: 3px;
outline: none;
background: var(--paper-solid);
color: var(--ink);
font-weight: 700;
cursor: pointer;
}
select:focus {
border-color: var(--blue);
box-shadow: 0 0 0 3px rgba(52, 124, 146, 0.12);
}
#periodText {
margin: 10px 0 0;
color: #4c6064;
font-size: 0.8rem;
line-height: 1.5;
}
.possible-outcomes {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 12px;
}
.possible-outcomes span {
padding: 5px 7px;
border: 1px solid var(--line);
border-radius: 2px;
background: rgba(255, 255, 255, 0.45);
color: #5a6c6e;
font-size: 0.67rem;
font-weight: 700;
}
.sources {
margin-top: 16px;
border-top: 1px solid var(--line);
padding-top: 12px;
}
.sources summary {
color: var(--blue);
font-size: 0.76rem;
font-weight: 800;
cursor: pointer;
}
.sources ul {
margin: 10px 0 0;
padding-left: 18px;
}
.sources li {
margin-bottom: 9px;
color: #586b6e;
font-size: 0.73rem;
line-height: 1.45;
}
.sources .caveat {
margin: 11px 0 0;
padding-top: 10px;
border-top: 1px solid var(--line);
color: #667577;
font-size: 0.72rem;
line-height: 1.45;
}
.timeline-wrap {
position: fixed;
z-index: 8;
right: 24px;
bottom: 20px;
left: 24px;
display: flex;
justify-content: center;
pointer-events: none;
}
.timeline {
display: grid;
grid-template-columns: repeat(4, minmax(145px, 1fr));
width: min(930px, 100%);
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 5px;
background: rgba(255, 250, 238, 0.93);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
pointer-events: auto;
}
.stage {
position: relative;
display: grid;
grid-template-columns: 31px 1fr;
gap: 9px;
min-height: 74px;
padding: 13px 12px;
border: 0;
border-right: 1px solid var(--line);
background: transparent;
text-align: left;
cursor: pointer;
transition: background 160ms ease, color 160ms ease;
}
.stage:last-child {
border-right: 0;
}
.stage:hover {
background: rgba(52, 124, 146, 0.08);
}
.stage.active {
background: var(--ink);
color: #fff9eb;
}
.stage-number {
display: grid;
place-items: center;
width: 30px;
height: 30px;
border: 1px solid currentColor;
border-radius: 2px;
font-size: 0.72rem;
font-weight: 900;
font-variant-numeric: tabular-nums;
}
.stage.active .stage-number {
border-color: var(--gold);
color: #f4bd61;
}
.stage-name {
display: block;
margin-top: 1px;
font-size: 0.8rem;
font-weight: 850;
line-height: 1.2;
}
.stage-note {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 0.68rem;
line-height: 1.25;
}
.stage.active .stage-note {
color: rgba(255, 249, 235, 0.68);
}
.controls {
position: fixed;
z-index: 7;
bottom: 108px;
left: 25px;
display: flex;
align-items: center;
gap: 7px;
}
.controls button {
display: grid;
place-items: center;
width: 34px;
height: 34px;
padding: 0;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 3px;
background: rgba(255, 250, 238, 0.9);
box-shadow: 0 5px 18px rgba(25, 54, 61, 0.13);
color: var(--ink);
font-weight: 900;
cursor: pointer;
}
.controls button:hover {
background: #fffaf0;
}
.controls span {
margin-left: 4px;
color: #456168;
font-size: 0.7rem;
font-weight: 750;
text-shadow: 0 1px rgba(255, 255, 255, 0.7);
}
.world-label {
position: fixed;
z-index: 4;
display: flex;
align-items: center;
gap: 7px;
padding: 7px 9px 7px 7px;
border: 1px solid rgba(255, 255, 255, 0.85);
border-radius: 3px;
background: rgba(255, 250, 238, 0.9);
box-shadow: 0 7px 20px rgba(25, 54, 61, 0.16);
color: var(--ink);
font-size: 0.69rem;
font-weight: 850;
white-space: nowrap;
cursor: pointer;
transform: translate(-50%, -100%);
transition: background 150ms ease, color 150ms ease;
}
.world-label::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 17px;
background: rgba(24, 59, 69, 0.42);
}
.world-label b {
display: grid;
place-items: center;
width: 21px;
height: 21px;
border-radius: 2px;
background: var(--gold);
color: #fff;
font-size: 0.64rem;
}
.world-label.active {
background: var(--ink);
color: #fff9eb;
}
.route-note {
position: fixed;
z-index: 4;
bottom: 105px;
right: 28px;
max-width: 250px;
padding: 7px 10px;
border-left: 3px solid var(--gold);
background: rgba(255, 250, 238, 0.78);
color: #5a6d70;
font-size: 0.66rem;
line-height: 1.4;
pointer-events: none;
}
#loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
background: #c9dfe1;
color: var(--ink);
font-size: 0.8rem;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 1000px) {
.hero {
width: 350px;
}
.hero p {
max-width: 330px;
}
.story-panel {
width: 330px;
}
.timeline {
grid-template-columns: repeat(4, minmax(125px, 1fr));
}
.stage {
padding: 11px 9px;
}
}
@media (max-width: 760px) {
.hero {
top: 13px;
left: 14px;
width: calc(100vw - 28px);
}
.eyebrow {
margin-bottom: 6px;
padding: 5px 7px;
font-size: 0.58rem;
}
h1 {
max-width: 290px;
font-size: 2.35rem;
}
.hero p,
.period-badge {
display: none;
}
.story-panel {
top: auto;
right: 10px;
bottom: 94px;
left: 10px;
width: auto;
max-height: 42vh;
padding: 14px;
}
.story-panel h2 {
font-size: 1.35rem;
}
.story-copy {
font-size: 0.78rem;
}
.variation {
margin-top: 10px;
padding: 9px 10px;
}
.variation p {
font-size: 0.75rem;
}
.era-picker {
margin-top: 11px;
padding-top: 11px;
}
#periodText,
.possible-outcomes,
.sources {
display: none;
}
.timeline-wrap {
right: 10px;
bottom: 10px;
left: 10px;
}
.timeline {
display: flex;
width: 100%;
overflow-x: auto;
}
.stage {
flex: 0 0 132px;
min-height: 70px;
}
.stage-note {
display: none;
}
.world-label,
.route-note,
.controls span {
display: none;
}
.controls {
bottom: 100px;
left: 12px;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
scroll-behavior: auto !important;
transition-duration: 0.01ms !important;
animation-duration: 0.01ms !important;
}
}
</style>
</head>
<body>
<canvas
id="scene"
aria-label="Interactive voxel diorama showing a ship arrival, ferry transfer, Ellis Island inspection building, and a generic city neighborhood."
></canvas>
<header class="hero">
<div class="eyebrow">Voxel history · New York Harbor</div>
<h1>Arrival at Ellis Island</h1>
<p>
A representative federal immigration sequence, from a ship in the harbor
to a possible onward journey through a city neighborhood.
</p>
<div class="period-badge">
<span>Selected period</span>
<strong id="selectedPeriod">1900–1914</strong>
</div>
</header>
<aside class="story-panel" aria-live="polite">
<div class="panel-heading">
<span>Representative sequence</span>
<span id="stageCounter">01 / 04</span>
</div>
<h2 id="stageTitle">Ship arrival</h2>
<p class="story-copy" id="stageBody"></p>
<div class="variation">
<strong>Experiences varied</strong>
<p id="stageVariation"></p>
</div>
<div class="era-picker">
<label for="periodSelect">Selected historical lens</label>
<select id="periodSelect">
<option value="1892-1899">1892–1899 · Barge Office era</option>
<option value="1900-1914" selected>1900–1914 · Main Building era</option>
<option value="1915-1917">1915–1917 · Wartime interruption</option>
<option value="1918-1930">1918–1930 · Quota era</option>
<option value="1932-1954">1932–1954 · Records & closing</option>
</select>
<p id="periodText"></p>
<div class="possible-outcomes" aria-label="Possible experiences, not fixed outcomes">
<span>swift passage</span>
<span>document review</span>
<span>medical concern</span>
<span>detention</span>
<span>onward travel</span>
</div>
</div>
<details class="sources">
<summary>Historical sources & caveats</summary>
<ul>
<li id="source-1">
<a
href="https://www.nps.gov/elis/learn/historyculture/index.htm"
target="_blank"
rel="noopener noreferrer"
>[1] National Park Service — Ellis Island History</a>.
Source basis for the Barge Office and Main Building eras, inspection
sequence, the 1907 peak, and the station's 1954 closure.
</li>
<li id="source-2">
<a
href="https://www.loc.gov/collections/immigration-and-relocation-in-u-s-history/"
target="_blank"
rel="noopener noreferrer"
>[2] Library of Congress — Immigration and Relocation in U.S. History</a>.
Broader historical and documentary context for migration, law, and
individual experience.
</li>
<li id="source-3">
<a
href="https://www.archives.gov/research/immigration"
target="_blank"
rel="noopener noreferrer"
>[3] National Archives — Immigration records research</a>.
Context for passenger manifests and immigration case records.
</li>
</ul>
<p class="caveat">
This is an educational diorama, not a reconstruction of one ship or
person. Many arrivals were inspected aboard ship, processed elsewhere,
or refused admission. The neighborhood is deliberately generic, and
the golden markers indicate narrative order rather than a literal road.
Figures and buildings are not to scale.
</p>
</details>
</aside>
<nav class="timeline-wrap" aria-label="Historical sequence stages">
<div class="timeline">
<button class="stage active" data-stage="0" aria-pressed="true">
<span class="stage-number">01</span>
<span>
<span class="stage-name">Ship arrival</span>
<span class="stage-note">New York Harbor</span>
</span>
</button>
<button class="stage" data-stage="1" aria-pressed="false">
<span class="stage-number">02</span>
<span>
<span class="stage-name">Barge / ferry</span>
<span class="stage-note">Transfer to the island</span>
</span>
</button>
<button class="stage" data-stage="2" aria-pressed="false">
<span class="stage-number">03</span>
<span>
<span class="stage-name">Inspection & registry</span>
<span class="stage-note">Federal processing</span>
</span>
</button>
<button class="stage" data-stage="3" aria-pressed="false">
<span class="stage-number">04</span>
<span>
<span class="stage-name">City neighborhood</span>
<span class="stage-note">A possible onward journey</span>
</span>
</button>
</div>
</nav>
<div class="controls" aria-label="Camera controls">
<button id="zoomIn" type="button" aria-label="Zoom in">+</button>
<button id="zoomOut" type="button" aria-label="Zoom out">−</button>
<button id="resetView" type="button" aria-label="Reset camera">↺</button>
<span>Drag to orbit · scroll to zoom</span>
</div>
<div class="route-note">
Golden blocks mark the story sequence. They are not a literal route.
</div>
<div id="loading">Building the harbor…</div>
<noscript>This interactive scene requires JavaScript.</noscript>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const reducedMotion = matchMedia("(prefers-reduced-motion: reduce)").matches;
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight, false);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#c9dfe1");
scene.fog = new THREE.Fog("#c9dfe1", 65, 125);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
180
);
scene.add(new THREE.HemisphereLight("#fff7dd", "#527783", 2.25));
const sun = new THREE.DirectionalLight("#fff0cb", 3.15);
sun.position.set(-24, 42, 25);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -55;
sun.shadow.camera.right = 55;
sun.shadow.camera.top = 45;
sun.shadow.camera.bottom = -45;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 110;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight("#c2e6ed", 1.2);
fill.position.set(30, 14, -25);
scene.add(fill);
// ---------------------------------------------------------------------
// Voxel construction helpers
// ---------------------------------------------------------------------
const materialCache = new Map();
function material(color) {
const key = String(color);
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0.02
})
);
}
return materialCache.get(key);
}
function box(
parent,
size,
position,
color,
options = {}
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
options.material || material(color)
);
mesh.position.set(position[0], position[1], position[2]);
if (options.rotation) {
mesh.rotation.set(
options.rotation[0] || 0,
options.rotation[1] || 0,
options.rotation[2] || 0
);
}
mesh.castShadow = options.cast !== false;
mesh.receiveShadow = options.receive !== false;
parent.add(mesh);
return mesh;
}
function group(parent, position = [0, 0, 0]) {
const result = new THREE.Group();
result.position.set(position[0], position[1], position[2]);
parent.add(result);
return result;
}
let randomSeed = 9137;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
const waterMaterial = new THREE.MeshStandardMaterial({
color: "#6caab4",
roughness: 0.48,
metalness: 0.08
});
const water = new THREE.Mesh(
new THREE.PlaneGeometry(150, 110),
waterMaterial
);
water.rotation.x = -Math.PI / 2;
water.position.set(0, -0.38, 0);
water.receiveShadow = true;
scene.add(water);
// Water is represented with small, flat voxel glints.
const waveGroup = group(scene);
const waveMaterial = new THREE.MeshBasicMaterial({
color: "#a9d1d5",
transparent: true,
opacity: 0.62
});
for (let i = 0; i < 92; i++) {
const x = -67 + random() * 134;
const z = -45 + random() * 90;
// Keep the main water open around the island and city blocks.
const onIsland =
x > -18 && x < 16 && z > -10 && z < 10;
const onCity =
x > 12 && x < 37 && z > -10 && z < 10;
if (!onIsland && !onCity) {
box(
waveGroup,
[0.7 + random() * 2.3, 0.055, 0.18],
[x, -0.30, z],
"#a9d1d5",
{ material: waveMaterial, cast: false }
);
}
}
// Ellis Island land.
box(scene, [32, 0.9, 16], [-1, 0.14, 0], "#b9aa75", {
receive: true
});
box(scene, [30.5, 0.16, 14.6], [-1, 0.63, 0], "#9fa979", {
cast: false
});
// Seawall blocks.
for (let x = -16; x <= 14; x += 2) {
box(scene, [1.85, 0.8, 0.6], [x, 0.05, 7.8], "#8f927f");
box(scene, [1.85, 0.8, 0.6], [x, 0.05, -7.8], "#8f927f");
}
// Generic mainland / city district.
box(scene, [23, 0.9, 19], [25, 0.12, 0], "#b8aa7c");
box(scene, [21.5, 0.15, 17.6], [25, 0.61, 0], "#9fa979", {
cast: false
});
// Roads and sidewalks.
box(scene, [22, 0.06, 3.1], [25, 0.72, 1.5], "#656b69", {
cast: false
});
box(scene, [3.0, 0.06, 17.8], [25.4, 0.72, 0], "#656b69", {
cast: false
});
box(scene, [22, 0.12, 0.38], [25, 0.75, -0.7], "#c7bfaa", {
cast: false
});
box(scene, [0.38, 0.12, 17.8], [24.3, 0.75, 0], "#c7bfaa", {
cast: false
});
for (let x = 15; x < 36; x += 3.1) {
box(scene, [1.2, 0.025, 0.12], [x, 0.765, 1.5], "#e8d69d", {
cast: false
});
}
// ---------------------------------------------------------------------
// Voxel people
// ---------------------------------------------------------------------
const skinColors = ["#b87955", "#d49a72", "#8d563f", "#e1ad82"];
const coatColors = [
"#7a3f3b",
"#3d6570",
"#68744d",
"#6d5d79",
"#8d713e",
"#415968",
"#9a6248"
];
function person(
parent,
x,
y,
z,
options = {}
) {
const g = group(parent, [x, y, z]);
const skin = options.skin || skinColors[
Math.floor(random() * skinColors.length)
];
const coat = options.coat || coatColors[
Math.floor(random() * coatColors.length)
];
const scale = options.scale || 1;
box(g, [0.17, 0.38, 0.2], [-0.12, 0.2, 0], "#3b4448");
box(g, [0.17, 0.38, 0.2], [0.12, 0.2, 0], "#3b4448");
box(g, [0.43, 0.55, 0.27], [0, 0.66, 0], coat);
box(g, [0.29, 0.29, 0.28], [0, 1.09, 0], skin);
box(g, [0.32, 0.07, 0.31], [0, 1.27, 0], options.hat || "#3d4546");
if (options.bag) {
box(g, [0.27, 0.25, 0.18], [0.34, 0.48, 0], "#795438");
box(g, [0.035, 0.2, 0.035], [0.34, 0.7, 0], "#4f3c31");
}
if (options.suitcase) {
box(g, [0.33, 0.42, 0.18], [0.35, 0.25, 0], "#684431");
box(g, [0.06, 0.12, 0.06], [0.35, 0.53, 0], "#3f342d");
}
g.scale.setScalar(scale);
return g;
}
function tree(parent, x, y, z, size = 1) {
const g = group(parent, [x, y, z]);
box(g, [0.32, 1.25, 0.32], [0, 0.62, 0], "#785c40");
box(g, [1.45, 0.95, 1.25], [0, 1.65, 0], "#627b50");
box(g, [0.95, 0.8, 0.9], [-0.28, 2.35, 0.05], "#70885a");
g.scale.setScalar(size);
return g;
}
// ---------------------------------------------------------------------
// Ocean liner
// ---------------------------------------------------------------------
const ship = group(scene, [-31, 0, 6]);
box(ship, [13.6, 1.25, 4.4], [0, 0.28, 0], "#203d4b");
box(ship, [12.8, 0.72, 4.05], [0, 1.12, 0], "#9d4039");
box(ship, [12.1, 0.36, 3.65], [0, 1.68, 0], "#d6cbae");
box(ship, [6.8, 2.35, 2.6], [-0.7, 2.88, 0], "#e5deca");
box(ship, [5.8, 1.35, 2.4], [-1.0, 4.68, 0], "#eee5cf");
box(ship, [1.15, 2.8, 1.2], [-3.5, 4.05, 0], "#a8453b");
box(ship, [1.18, 0.45, 1.23], [-3.5, 5.15, 0], "#2c3639");
// Stepped bow and stern.
box(ship, [1.4, 0.95, 3.35], [6.15, 0.9, 0], "#203d4b");
box(ship, [0.8, 0.7, 2.4], [6.9, 1.0, 0], "#9d4039");
box(ship, [1.2, 0.75, 3.4], [-6.4, 0.95, 0], "#203d4b");
// Portholes.
for (let x = -5.7; x <= 5.3; x += 0.85) {
box(ship, [0.28, 0.28, 0.08], [x, 1.1, 2.04], "#9bc4c8", {
cast: false
});
box(ship, [0.28, 0.28, 0.08], [x, 1.1, -2.04], "#9bc4c8", {
cast: false
});
}
for (let x = -3.7; x <= 2.3; x += 0.9) {
box(ship, [0.38, 0.48, 0.08], [x, 3.05, 1.33], "#527987", {
cast: false
});
}
// Mast, railings and deck passengers.
box(ship, [0.14, 4.0, 0.14], [3.4, 3.8, 0], "#d6c5a3");
box(ship, [2.0, 0.12, 0.12], [3.4, 5.3, 0], "#d6c5a3");
for (let x = -5.5; x < 6; x += 0.65) {
box(ship, [0.06, 0.36, 0.06], [x, 2.0, 1.72], "#d6c5a3", {
cast: false
});
}
person(ship, -1.9, 5.38, 0.55, { scale: 0.8, suitcase: true });
person(ship, -0.7, 5.38, 0.65, { scale: 0.82, coat: "#486c78" });
person(ship, 0.6, 5.38, 0.45, { scale: 0.78, coat: "#7b4b43" });
person(ship, 2.9, 1.87, 0.95, { scale: 0.85, bag: true });
// ---------------------------------------------------------------------
// Ferry / barge
// ---------------------------------------------------------------------
const ferry = group(scene, [-18.1, -0.05, 3.0]);
box(ferry, [5.5, 1.05, 2.35], [0, 0.35, 0], "#274d59");
box(ferry, [5.25, 0.35, 2.18], [0, 1.0, 0], "#d3b678");
box(ferry, [3.0, 1.6, 1.7], [-0.55, 1.93, 0], "#f0e6cf");
box(ferry, [1.25, 1.1, 1.45], [1.35, 1.62, 0], "#d3b678");
box(ferry, [1.0, 0.55, 1.5], [1.35, 2.4, 0], "#8db8c0");
box(ferry, [0.12, 1.65, 0.12], [-1.5, 2.65, 0], "#6e7775");
for (let x = -1.7; x <= 0.7; x += 0.55) {
box(ferry, [0.28, 0.35, 0.07], [x, 2.0, 0.88], "#4e8190", {
cast: false
});
}
person(ferry, -0.9, 1.18, 0.55, { scale: 0.78, suitcase: true });
person(ferry, 0.0, 1.18, 0.62, { scale: 0.8, coat: "#6d5c78" });
person(ferry, 0.85, 1.18, 0.45, { scale: 0.76, bag: true });
// Ferry landing and pier.
box(scene, [4.5, 0.5, 3.6], [-15.2, 0.5, 3.0], "#88765a");
box(scene, [3.7, 0.18, 3.0], [-15.2, 0.84, 3.0], "#ad956d");
box(scene, [0.3, 2.5, 0.3], [-16.7, 1.65, 4.3], "#5b5148");
box(scene, [0.3, 2.5, 0.3], [-13.8, 1.65, 4.3], "#5b5148");
// ---------------------------------------------------------------------
// Main Building / Registry Room, shown in cutaway
// ---------------------------------------------------------------------
const hall = group(scene, [-2, 0, 0]);
box(hall, [14.8, 0.35, 9.4], [0, 0.88, 0], "#c7b894");
box(hall, [14.8, 5.2, 0.45], [0, 3.55, -4.45], "#d9c9a7");
box(hall, [0.45, 5.2, 8.9], [-7.2, 3.55, 0], "#d9c9a7");
box(hall, [0.45, 5.2, 8.9], [7.2, 3.55, 0], "#d9c9a7");
// Columns across the open front.
for (let x = -6.4; x <= 6.4; x += 1.6) {
box(hall, [0.48, 4.85, 0.48], [x, 3.43, 4.18], "#eee2c7");
}
box(hall, [15.3, 0.5, 9.8], [0, 6.08, 0], "#567568");
box(hall, [15.8, 0.3, 10.2], [0, 6.42, 0], "#d9c9a7");
box(hall, [6.2, 0.42, 9.9], [0, 6.75, 0], "#567568");
// Side towers.
for (const x of [-5.4, 5.4]) {
box(hall, [2.6, 7.4, 3.3], [x, 4.45, -3.1], "#d9c9a7");
box(hall, [2.9, 0.45, 3.6], [x, 8.15, -3.1], "#567568");
box(hall, [0.65, 1.15, 0.65], [x, 8.65, -3.1], "#9b875f");
box(hall, [0.38, 0.38, 0.08], [x, 8.65, -2.75], "#f0df9a", {
cast: false
});
}
// Central pediment.
for (let i = 0; i < 3; i++) {
box(
hall,
[1.25 - i * 0.18, 0.45, 1.2],
[-0.65 + i * 0.65, 7.15 + i * 0.36, -3.1],
"#d9c9a7"
);
box(
hall,
[1.25 - i * 0.18, 0.45, 1.2],
[0.65 - i * 0.65, 7.15 + i * 0.36, -3.1],
"#d9c9a7"
);
}
// Registry and inspection counters.
for (const x of [-4.5, -1.5, 1.5, 4.5]) {
box(hall, [2.15, 0.92, 0.8], [x, 1.48, 0.55], "#89775b");
box(hall, [2.35, 0.16, 1.0], [x, 2.0, 0.55], "#b9a37d");
box(hall, [0.52, 0.25, 0.06], [x, 1.55, 0.97], "#395e67", {
cast: false
});
}
// Medical examination table and red cross.
box(hall, [2.2, 0.25, 0.9], [-5.2, 1.65, 2.8], "#e8dfcb");
box(hall, [0.18, 0.75, 0.18], [-5.2, 1.12, 2.8], "#7f806f");
box(hall, [0.75, 0.22, 0.08], [3.9, 3.2, -4.18], "#b64b42", {
cast: false
});
box(hall, [0.22, 0.75, 0.08], [3.9, 3.2, -4.17], "#b64b42", {
cast: false
});
// Queue rails.
for (const z of [3.25, 4.15]) {
for (let x = -5.5; x <= 5.5; x += 2.2) {
box(hall, [0.09, 0.95, 0.09], [x, 1.5, z], "#5f6664", {
cast: false
});
}
box(hall, [11.4, 0.08, 0.08], [0, 1.9, z], "#5f6664", {
cast: false
});
}
// People suggest varied movement through the building.
person(hall, -4.8, 1.08, 0.9, { scale: 0.86, coat: "#466c78" });
person(hall, -1.8, 1.08, 0.9, { scale: 0.86, coat: "#7b493f" });
person(hall, 1.1, 1.08, 0.9, { scale: 0.84, suitcase: true });
person(hall, -3.5, 1.08, 3.55, { scale: 0.84, bag: true });
person(hall, -1.5, 1.08, 3.55, { scale: 0.84, coat: "#536a4c" });
person(hall, 0.4, 1.08, 3.55, { scale: 0.84, coat: "#6e5972" });
person(hall, 2.3, 1.08, 3.55, { scale: 0.84, suitcase: true });
// Bags and cases near the entrance.
box(hall, [0.75, 0.48, 0.45], [-5.8, 1.32, 3.45], "#754d34");
box(hall, [0.6, 0.4, 0.38], [-5.0, 1.28, 3.6], "#5d4739");
box(hall, [0.5, 0.65, 0.32], [5.7, 1.4, 3.55], "#80603f");
// Flag.
box(hall, [0.09, 3.8, 0.09], [0, 8.45, -3.1], "#d4c9b0");
box(hall, [1.6, 0.82, 0.07], [0.75, 10.0, -3.1], "#a94c46");
for (let i = 0; i < 3; i++) {
for (let j = 0; j < 4; j++) {
box(
hall,
[0.12, 0.12, 0.035],
[0.23 + i * 0.34, 9.76 + j * 0.16, -3.05],
"#f5e9c7",
{ cast: false }
);
}
}
// Island landscaping.
const islandTrees = [
[-13.4, -5.2, 0.75],
[-12.0, 4.9, 0.66],
[-8.5, -6.2, 0.72],
[6.5, -6.0, 0.85],
[9.4, 4.9, 0.8],
[11.4, -2.8, 0.7]
];
for (const [x, z, s] of islandTrees) tree(scene, x, 0.7, z, s);
// Benches.
for (const x of [-11, 8.5]) {
box(scene, [1.8, 0.18, 0.55], [x, 1.15, 1.0], "#76563c");
box(scene, [1.8, 0.65, 0.12], [x, 1.45, 0.72], "#76563c");
}
// ---------------------------------------------------------------------
// Generic city neighborhood
// ---------------------------------------------------------------------
const city = group(scene);
function cityBuilding(x, z, w, d, h, color, roofColor) {
const b = group(city, [x, 0.75, z]);
box(b, [w, h, d], [0, h / 2, 0], color);
box(b, [w + 0.25, 0.28, d + 0.25], [0, h + 0.1, 0], roofColor);
const rows = Math.max(1, Math.floor(h / 1.65));
const cols = Math.max(1, Math.floor(w / 1.35));
for (let row = 0; row < rows; row++) {
for (let col = 0; col < cols; col++) {
const wx = -w / 2 + 0.85 + col * 1.35;
const wy = 1.05 + row * 1.5;
if (wx + 0.25 > w / 2) continue;
box(
b,
[0.48, 0.62, 0.06],
[wx, wy, d / 2 + 0.04],
row % 2 ? "#d9c887" : "#83aeb2",
{ cast: false }
);
}
}
box(b, [0.75, 1.1, 0.08], [0, 0.58, d / 2 + 0.05], "#4b5555");
return b;
}
cityBuilding(17.5, -5.8, 4.3, 3.7, 5.0, "#a96951", "#6e6259");
cityBuilding(22.4, -6.0, 4.8, 3.8, 7.3, "#b19a72", "#6b6259");
cityBuilding(28.2, -6.0, 4.6, 3.8, 4.6, "#7b8b75", "#64625b");
cityBuilding(33.0, -5.8, 3.8, 3.8, 6.1, "#a67863", "#6c6258");
cityBuilding(17.4, 5.5, 4.0, 4.0, 6.4, "#87907c", "#66645d");
cityBuilding(22.1, 5.7, 4.1, 4.1, 4.0, "#ac8263", "#6d625b");
cityBuilding(28.0, 5.7, 4.4, 4.2, 7.0, "#a36350", "#655d58");
// Corner shop and workshop awnings.
box(city, [2.2, 0.25, 0.85], [17.5, 2.7, -3.82], "#d1a546");
box(city, [1.7, 0.2, 0.7], [29.0, 2.5, -3.82], "#4f7c76");
// Streetcar or train car on the street.
const streetcar = group(city, [25.6, 0.83, 1.55]);
box(streetcar, [4.9, 1.55, 1.65], [0, 0.78, 0], "#3e7779");
box(streetcar, [5.1, 0.2, 1.75], [0, 1.62, 0], "#d0b781");
for (let x = -1.9; x <= 1.9; x += 0.95) {
box(streetcar, [0.7, 0.72, 0.07], [x, 1.0, 0.86], "#a9ced0", {
cast: false
});
}
box(streetcar, [0.22, 0.22, 0.22], [-1.7, -0.06, 0.9], "#303b3e");
box(streetcar, [0.22, 0.22, 0.22], [1.7, -0.06, 0.9], "#303b3e");
// City people, trees and lamps.
const cityPeople = [
[19.0, -1.4], [20.4, -1.3], [23.3, -1.5], [27.0, 2.9],
[30.2, 2.8], [18.1, 3.0], [21.7, 7.5], [26.7, -2.8]
];
for (const [x, z] of cityPeople) {
person(city, x, 0.75, z, {
scale: 0.84,
suitcase: random() > 0.55,
coat: coatColors[Math.floor(random() * coatColors.length)]
});
}
for (const [x, z] of [
[14.8, -2.7], [20.7, 3.8], [26.4, -2.7], [33.8, 2.8]
]) {
tree(city, x, 0.75, z, 0.75);
}
for (const x of [14.5, 21.8, 29.2, 35.2]) {
box(city, [0.12, 3.1, 0.12], [x, 2.25, 2.8], "#4b5553");
box(city, [0.45, 0.55, 0.45], [x, 3.8, 2.8], "#efcf7a");
}
// ---------------------------------------------------------------------
// Narrative route markers
// ---------------------------------------------------------------------
const routePoints = [
new THREE.Vector3(-30, 0, 5.8),
new THREE.Vector3(-18, 0, 3.0),
new THREE.Vector3(-8.5, 0, 2.2),
new THREE.Vector3(5.5, 0, 1.6),
new THREE.Vector3(15.8, 0, 1.5)
];
for (let segment = 0; segment < routePoints.length - 1; segment++) {
const a = routePoints[segment];
const b = routePoints[segment + 1];
const count = Math.ceil(a.distanceTo(b) / 1.35);
for (let i = 0; i < count; i++) {
const p = a.clone().lerp(b, i / count);
box(
scene,
[0.32, 0.15, 0.32],
[p.x, 0.77, p.z],
"#d79a38",
{ cast: false }
);
}
}
// Small square milestone at each stage.
const milestonePositions = [
[-30.2, 0.8, 5.8],
[-18.2, 0.8, 3.0],
[-8.7, 0.8, 2.4],
[14.3, 0.8, 1.5]
];
for (const [x, y, z] of milestonePositions) {
box(scene, [0.8, 0.4, 0.8], [x, y, z], "#d79a38");
box(scene, [0.45, 0.8, 0.45], [x, y + 0.55, z], "#f0c468");
}
// ---------------------------------------------------------------------
// Voxel clouds
// ---------------------------------------------------------------------
const cloudGroup = group(scene);
for (const [x, y, z, s] of [
[-28, 20, -18, 1.2],
[2, 24, -30, 1.5],
[28, 18, -15, 1.0],
[-2, 16, 28, 0.85]
]) {
const cloud = group(cloudGroup, [x, y, z]);
box(cloud, [4.2, 1.1, 1.5], [0, 0, 0], "#edf1e8", { cast: false });
box(cloud, [2.2, 1.6, 1.6], [-0.5, 0.6, 0], "#f5f3e8", { cast: false });
box(cloud, [2.4, 1.35, 1.5], [1.2, 0.35, 0], "#f5f3e8", { cast: false });
cloud.scale.setScalar(s);
}
// ---------------------------------------------------------------------
// Camera controls implemented without addons
// ---------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(-1, 2.2, 0),
theta: 0.78,
phi: 0.78,
radius: 59
};
const desiredCamera = {
target: cameraState.target.clone(),
theta: cameraState.theta,
phi: cameraState.phi,
radius: cameraState.radius
};
function updateCamera() {
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);
}
updateCamera();
const stageViews = [
{
target: new THREE.Vector3(-30, 3.6, 5.8),
radius: 22,
theta: 0.92,
phi: 0.82
},
{
target: new THREE.Vector3(-17.8, 2.0, 3.0),
radius: 18,
theta: 0.87,
phi: 0.85
},
{
target: new THREE.Vector3(-2.0, 3.5, 0),
radius: 24,
theta: 0.78,
phi: 0.79
},
{
target: new THREE.Vector3(25, 3.2, 0),
radius: 27,
theta: 0.72,
phi: 0.79
}
];
let dragging = false;
let previousX = 0;
let previousY = 0;
let pointerId = null;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerId = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
desiredCamera.theta -= dx * 0.006;
desiredCamera.phi = THREE.MathUtils.clamp(
desiredCamera.phi - dy * 0.005,
0.34,
1.34
);
});
function endDrag(event) {
if (event.pointerId !== pointerId) return;
dragging = false;
pointerId = null;
canvas.classList.remove("dragging");
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredCamera.radius = THREE.MathUtils.clamp(
desiredCamera.radius + event.deltaY * 0.025,
13,
82
);
},
{ passive: false }
);
document.querySelector("#zoomIn").addEventListener("click", () => {
desiredCamera.radius = Math.max(13, desiredCamera.radius - 5);
});
document.querySelector("#zoomOut").addEventListener("click", () => {
desiredCamera.radius = Math.min(82, desiredCamera.radius + 5);
});
document.querySelector("#resetView").addEventListener("click", () => {
desiredCamera.target.set(-1, 2.2, 0);
desiredCamera.theta = 0.78;
desiredCamera.phi = 0.78;
desiredCamera.radius = innerWidth < 760 ? 72 : 59;
});
// ---------------------------------------------------------------------
// Historical content and interface
// ---------------------------------------------------------------------
const periodData = {
"1892-1899": {
label: "1892–1899",
text:
"The first federal immigration station operated from the Barge Office. Ship doctors often examined travelers aboard ship before transfer. Inspections could be swift, and decisions were sometimes made with limited context."
},
"1900-1914": {
label: "1900–1914",
text:
"The Main Building opened in 1900 and the Registry Room became a central federal inspection setting. In 1907, more than one million people were processed—the station's busiest year."
},
"1915-1917": {
label: "1915–1917",
text:
"World War I sharply reduced transatlantic arrivals. Wartime controls, medical examination, and document requirements affected who could travel and what happened on arrival."
},
"1918-1930": {
label: "1918–1930",
text:
"Arrivals resumed after the war. The Immigration Acts of 1921 and 1924 established national-origins quotas, while legal, medical, and identity checks expanded."
},
"1932-1954": {
label: "1932–1954",
text:
"The building's role shifted as immigration and citizenship recordkeeping expanded. Many travelers no longer entered through Ellis Island. The federal processing station closed in 1954."
}
};
const stageData = [
{
title: "Ship arrival",
body:
"Large steamships often first anchored in New York Harbor rather than docking directly at Ellis Island. Shipboard listing and medical inspection could begin before anyone came ashore.",
variation:
"Travelers might be examined beside relatives, asked questions in a language they did not understand, or separated by shipboard class and authority. The voyage and waiting time shaped the beginning of each journey.",
source: 1
},
{
title: "Barge or ferry transfer",
body:
"Passengers and their baggage were transferred by a ferry or barge to the island. The move could involve long waits, heavy bundles, and the challenge of keeping family members together.",
variation:
"Children, older travelers, and people with limited English encountered different burdens. Travelers were not all processed in the same way, and some received their medical examination before boarding the transfer.",
source: 1
},
{
title: "Inspection and registry",
body:
"At the Main Building, federal inspectors examined documents, health, and legal eligibility. The registry, medical, and legal processes were intertwined, though they were not identical procedures.",
variation:
"Some people passed quickly. Others were detained, sent for medical care, required additional review, denied admission, or sent elsewhere. Gender, race, class, nationality, health, paperwork, and individual circumstances all shaped outcomes.",
source: 1
},
{
title: "A generic city neighborhood",
body:
"After processing, travelers might continue by train, streetcar, or ferry to cities and towns across the country. This neighborhood is deliberately generic; it does not identify a specific Ellis Island settlement.",
variation:
"New arrivals might join family networks or existing communities while also facing housing, work, language barriers, exclusion, and discrimination. No single neighborhood story represented every traveler.",
source: 2
}
];
const stageButtons = [...document.querySelectorAll(".stage")];
const periodSelect = document.querySelector("#periodSelect");
const stageTitle = document.querySelector("#stageTitle");
const stageBody = document.querySelector("#stageBody");
const stageVariation = document.querySelector("#stageVariation");
const stageCounter = document.querySelector("#stageCounter");
const selectedPeriod = document.querySelector("#selectedPeriod");
const periodText = document.querySelector("#periodText");
let currentStage = 0;
const sourceLinks = {
1: "https://www.nps.gov/elis/learn/historyculture/index.htm",
2: "https://www.loc.gov/collections/immigration-and-relocation-in-u-s-history/",
3: "https://www.archives.gov/research/immigration"
};
function sourceLink(number) {
return `<a href="${sourceLinks[number]}" target="_blank" rel="noopener noreferrer" aria-label="Open source ${number}">[${number}]</a>`;
}
function setStage(index, focus = true) {
currentStage = index;
const data = stageData[index];
stageTitle.textContent = data.title;
stageBody.innerHTML = `${data.body} ${sourceLink(data.source)}`;
stageVariation.textContent = data.variation;
stageCounter.textContent = `${String(index + 1).padStart(2, "0")} / 04`;
for (const button of stageButtons) {
const active = Number(button.dataset.stage) === index;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
}
for (const [i, label] of worldLabels.entries()) {
label.classList.toggle("active", i === index);
}
if (focus) {
const view = stageViews[index];
desiredCamera.target.copy(view.target);
desiredCamera.radius = view.radius;
desiredCamera.theta = view.theta;
desiredCamera.phi = view.phi;
}
}
stageButtons.forEach((button) => {
button.addEventListener("click", () => {
setStage(Number(button.dataset.stage), true);
});
});
periodSelect.addEventListener("change", () => {
const data = periodData[periodSelect.value];
selectedPeriod.textContent = data.label;
periodText.textContent = data.text;
});
const initialPeriod = periodData[periodSelect.value];
periodText.textContent = initialPeriod.text;
// ---------------------------------------------------------------------
// Projected HTML labels
// ---------------------------------------------------------------------
const labelNames = [
"01 Ship arrival",
"02 Barge / ferry",
"03 Inspection",
"04 City neighborhood"
];
const anchorPositions = [
new THREE.Vector3(-31, 10.2, 6),
new THREE.Vector3(-18, 4.8, 3),
new THREE.Vector3(-2, 10.0, 0),
new THREE.Vector3(25, 9.0, 0)
];
const worldLabels = labelNames.map((name, index) => {
const element = document.createElement("button");
element.type = "button";
element.className = "world-label";
element.innerHTML = `<b>${String(index + 1).padStart(2, "0")}</b><span>${name.replace(/^\d+\s+/, "")}</span>`;
element.setAttribute("aria-label", `Focus stage ${index + 1}: ${labelNames[index]}`);
element.addEventListener("click", () => setStage(index, true));
document.body.appendChild(element);
return element;
});
function updateWorldLabels() {
for (let i = 0; i < worldLabels.length; i++) {
const projected = anchorPositions[i].clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.12 &&
Math.abs(projected.y) < 1.12;
worldLabels[i].style.display = visible ? "flex" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
worldLabels[i].style.left = `${x}px`;
worldLabels[i].style.top = `${y}px`;
}
}
}
// Keyboard navigation between stages.
window.addEventListener("keydown", (event) => {
if (
event.target instanceof HTMLSelectElement ||
event.target instanceof HTMLInputElement
) return;
if (event.key === "ArrowRight" || event.key === "ArrowDown") {
event.preventDefault();
setStage((currentStage + 1) % stageData.length, true);
}
if (event.key === "ArrowLeft" || event.key === "ArrowUp") {
event.preventDefault();
setStage(
(currentStage - 1 + stageData.length) % stageData.length,
true
);
}
});
// ---------------------------------------------------------------------
// Resize and render loop
// ---------------------------------------------------------------------
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight, false);
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
const damping = reducedMotion ? 1 : 0.075;
cameraState.target.lerp(desiredCamera.target, damping);
cameraState.theta = THREE.MathUtils.lerp(
cameraState.theta,
desiredCamera.theta,
damping
);
cameraState.phi = THREE.MathUtils.lerp(
cameraState.phi,
desiredCamera.phi,
damping
);
cameraState.radius = THREE.MathUtils.lerp(
cameraState.radius,
desiredCamera.radius,
damping
);
updateCamera();
ship.position.y = Math.sin(elapsed * 0.75) * 0.045;
ferry.position.y = -0.05 + Math.sin(elapsed * 1.1 + 0.8) * 0.035;
updateWorldLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
setStage(0, false);
updateWorldLabels();
animate();
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 450);
});
</script>
</body>
</html>
```