Prompt specification
Build or customize the Three.js 3D scene "Chronology and Theme Gallery Routes" 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: Chronology and Theme Gallery Routes
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/chronology-and-theme-gallery-routes-x3311
Scene Description Prompt:
Chronology and theme gallery routes. Build a small museum whose same exhibits can be arranged chronologically or thematically. Show how each path emphasizes different relationships without changing the source facts. Please build this with Three.js from cdnjs in one self-contained HTML file, using visible voxel blocks.
Working Three.js Starter (chronology-and-theme-gallery-routes-x3311):
```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="#081119" />
<title>Atlas Museum — One Collection, Two Stories</title>
<style>
:root {
--bg: #081119;
--panel: rgba(10, 22, 31, 0.9);
--panel-soft: rgba(15, 31, 42, 0.76);
--line: rgba(205, 230, 240, 0.14);
--text: #f2f4ed;
--muted: #9fb0b7;
--gold: #f2c96e;
--cyan: #79d8cf;
--shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, a { font: inherit; }
button:focus-visible,
a:focus-visible,
canvas:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 3px;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
.topbar {
position: fixed;
z-index: 20;
top: 0;
left: 0;
right: 0;
min-height: 74px;
padding: 12px 22px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
background: linear-gradient(180deg, rgba(5, 13, 19, 0.97), rgba(5, 13, 19, 0.74));
border-bottom: 1px solid var(--line);
backdrop-filter: blur(16px);
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
position: relative;
width: 31px;
height: 31px;
flex: 0 0 auto;
}
.brand-mark i {
position: absolute;
width: 12px;
height: 12px;
background: var(--gold);
box-shadow: 0 0 18px rgba(242, 201, 110, 0.18);
}
.brand-mark i:nth-child(1) { left: 0; top: 0; }
.brand-mark i:nth-child(2) { right: 0; top: 0; opacity: .58; }
.brand-mark i:nth-child(3) { left: 0; bottom: 0; opacity: .58; }
.brand-mark i:nth-child(4) { right: 0; bottom: 0; }
.brand-copy { min-width: 0; }
.eyebrow {
margin: 0 0 3px;
color: var(--gold);
font-size: 10px;
font-weight: 800;
letter-spacing: .19em;
text-transform: uppercase;
}
.brand h1 {
margin: 0;
font-size: 17px;
font-weight: 700;
letter-spacing: -.02em;
white-space: nowrap;
}
.brand h1 span {
color: var(--muted);
font-weight: 450;
}
.top-actions {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 12px;
}
.route-switch {
display: flex;
gap: 4px;
padding: 4px;
background: rgba(255, 255, 255, .045);
border: 1px solid var(--line);
border-radius: 11px;
}
.route-link {
min-width: 132px;
padding: 10px 14px;
display: flex;
align-items: center;
justify-content: center;
gap: 9px;
color: var(--muted);
background: transparent;
border: 0;
border-radius: 8px;
text-decoration: none;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition: background .2s ease, color .2s ease;
}
.route-link span {
color: #60747d;
font-size: 10px;
letter-spacing: .08em;
}
.route-link:hover { color: var(--text); }
.route-link.active {
color: #071219;
background: var(--gold);
}
.route-link.active span { color: rgba(7, 18, 25, .55); }
.link-button {
padding: 10px 12px;
color: var(--text);
background: rgba(255, 255, 255, .045);
border: 1px solid var(--line);
border-radius: 9px;
font-size: 11px;
font-weight: 750;
cursor: pointer;
}
.link-button[aria-pressed="false"] {
color: var(--muted);
opacity: .68;
}
.card {
position: fixed;
z-index: 12;
background: var(--panel);
border: 1px solid var(--line);
border-radius: 15px;
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
}
.route-card {
top: 98px;
left: 22px;
width: 310px;
padding: 19px;
}
.route-card h2,
.detail-card h2 {
margin: 0;
font-weight: 680;
letter-spacing: -.035em;
}
.route-card h2 {
max-width: 250px;
font-size: 25px;
line-height: 1.08;
}
.route-description {
margin: 11px 0 15px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.fixed-note {
padding: 10px 11px;
color: #d9e2e2;
background: rgba(255, 255, 255, .035);
border-left: 2px solid var(--cyan);
font-size: 10px;
line-height: 1.45;
}
.rail-title {
margin: 17px 0 9px;
color: #738890;
font-size: 9px;
font-weight: 800;
letter-spacing: .16em;
text-transform: uppercase;
}
#routeRail {
min-height: 29px;
display: flex;
align-items: center;
gap: 6px;
flex-wrap: wrap;
}
.chron-node {
position: relative;
width: 19px;
height: 26px;
padding: 0;
border: 0;
background: transparent;
cursor: pointer;
}
.chron-node::before {
content: "";
position: absolute;
top: 11px;
left: 0;
width: 19px;
height: 1px;
background: rgba(242, 201, 110, .35);
}
.chron-node:first-child::before { left: 9px; width: 10px; }
.chron-node:last-child::before { width: 10px; }
.chron-node span {
position: absolute;
z-index: 1;
top: 7px;
left: 6px;
width: 9px;
height: 9px;
background: #776d50;
border: 2px solid #15222a;
border-radius: 50%;
}
.chron-node.active span,
.chron-node:hover span {
background: var(--gold);
box-shadow: 0 0 0 3px rgba(242, 201, 110, .13);
}
.theme-chip {
padding: 6px 8px;
display: flex;
align-items: center;
gap: 6px;
color: #aebbc0;
background: rgba(255, 255, 255, .035);
border: 1px solid var(--line);
border-radius: 7px;
font-size: 9px;
cursor: pointer;
}
.theme-chip i {
width: 7px;
height: 7px;
background: var(--swatch);
border-radius: 1px;
}
.theme-chip.active {
color: #fff;
border-color: color-mix(in srgb, var(--swatch), transparent 50%);
}
.detail-card {
top: 98px;
right: 22px;
width: 340px;
max-height: calc(100vh - 122px);
padding: 19px;
overflow: auto;
}
.detail-card h2 {
margin-top: 8px;
font-size: 24px;
line-height: 1.1;
}
.detail-date {
margin-top: 7px;
color: var(--gold);
font-size: 11px;
font-weight: 800;
letter-spacing: .08em;
text-transform: uppercase;
}
.tag-row {
margin-top: 13px;
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.tag {
padding: 5px 7px;
color: #c8d4d8;
background: rgba(255, 255, 255, .045);
border: 1px solid var(--line);
border-radius: 5px;
font-size: 9px;
font-weight: 700;
}
.source-fact {
margin-top: 18px;
padding-top: 16px;
border-top: 1px solid var(--line);
}
.source-label {
margin-bottom: 7px;
color: #768b94;
font-size: 9px;
font-weight: 800;
letter-spacing: .14em;
text-transform: uppercase;
}
.source-fact p {
margin: 0;
color: #dce4e3;
font-family: Georgia, "Times New Roman", serif;
font-size: 15px;
line-height: 1.48;
}
.route-relation {
margin-top: 18px;
padding: 13px;
background: rgba(121, 216, 207, .055);
border: 1px solid rgba(121, 216, 207, .14);
border-radius: 9px;
}
.route-relation h3 {
margin: 0 0 6px;
color: var(--cyan);
font-size: 9px;
letter-spacing: .13em;
text-transform: uppercase;
}
.route-relation p {
margin: 0;
color: #b9c7ca;
font-size: 11px;
line-height: 1.5;
}
.related-list {
margin-top: 10px;
display: grid;
gap: 6px;
}
.related-button {
width: 100%;
padding: 8px 9px;
display: flex;
justify-content: space-between;
gap: 8px;
color: #d9e1df;
background: rgba(255, 255, 255, .035);
border: 1px solid var(--line);
border-radius: 6px;
text-align: left;
font-size: 10px;
cursor: pointer;
}
.related-button:hover {
background: rgba(255, 255, 255, .075);
border-color: rgba(255, 255, 255, .2);
}
.related-button span {
color: var(--gold);
white-space: nowrap;
}
.record-id {
margin-top: 14px;
color: #647982;
font-size: 9px;
letter-spacing: .08em;
}
.control-hint {
position: fixed;
z-index: 10;
left: 50%;
bottom: 18px;
transform: translateX(-50%);
padding: 9px 13px;
color: #a6b7bd;
background: rgba(5, 13, 19, .7);
border: 1px solid var(--line);
border-radius: 8px;
font-size: 10px;
white-space: nowrap;
backdrop-filter: blur(12px);
pointer-events: none;
}
.loading {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
background: #081119;
transition: opacity .45s ease, visibility .45s ease;
}
.loading.hidden {
opacity: 0;
visibility: hidden;
}
.loading-block {
display: flex;
align-items: center;
gap: 12px;
color: #cbd8da;
font-size: 12px;
letter-spacing: .08em;
text-transform: uppercase;
}
.loading-cube {
width: 18px;
height: 18px;
background: var(--gold);
box-shadow: 8px 8px 0 rgba(242, 201, 110, .35);
animation: pulse 1s steps(2) infinite;
}
@keyframes pulse {
50% { transform: translateY(-7px); box-shadow: 8px 15px 0 rgba(242, 201, 110, .18); }
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 900px) {
.topbar { padding: 10px 12px; }
.brand h1 span { display: none; }
.route-link { min-width: auto; padding: 9px 10px; }
.link-button { display: none; }
.route-card {
top: 83px;
left: 12px;
width: 270px;
padding: 15px;
}
.route-card h2 { font-size: 21px; }
.route-description { font-size: 11px; }
#routeRail { display: none; }
.rail-title { display: none; }
.detail-card {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 41vh;
padding: 15px;
}
.detail-card h2 { font-size: 21px; }
.control-hint { display: none; }
}
@media (max-width: 520px) {
.brand-copy .eyebrow { display: none; }
.brand h1 { font-size: 13px; }
.brand-mark { width: 24px; height: 24px; }
.brand-mark i { width: 9px; height: 9px; }
.route-link { font-size: 10px; }
.route-link span { display: none; }
.route-card { width: calc(100% - 24px); }
.route-card h2 { max-width: none; }
.fixed-note { display: none; }
.detail-card { max-height: 38vh; }
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: .001ms !important;
transition-duration: .001ms !important;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive voxel museum. Drag to orbit, shift-drag to pan, scroll to zoom, and click exhibits to inspect them."
></canvas>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"><i></i><i></i><i></i><i></i></div>
<div class="brand-copy">
<p class="eyebrow">Atlas Museum / Gallery 01</p>
<h1>One collection <span>— two stories</span></h1>
</div>
</div>
<div class="top-actions">
<nav class="route-switch" aria-label="Gallery routes">
<a class="route-link active" data-route="chronology" href="#chronology" aria-current="page">
<span>01</span>Chronology
</a>
<a class="route-link" data-route="themes" href="#themes">
<span>02</span>Theme gallery
</a>
</nav>
<button id="connectionsButton" class="link-button" aria-pressed="true">Links on</button>
</div>
</header>
<aside class="card route-card" aria-labelledby="routeTitle">
<p id="routeKicker" class="eyebrow">Route 01 / Time</p>
<h2 id="routeTitle">The collection becomes a timeline.</h2>
<p id="routeDescription" class="route-description"></p>
<div class="fixed-note">
Only position and connecting lines change. Dates, identities, and source facts remain fixed.
</div>
<p class="rail-title" id="railTitle">The chronological path</p>
<div id="routeRail"></div>
</aside>
<aside class="card detail-card" aria-labelledby="detailTitle">
<p id="detailKicker" class="eyebrow">Exhibit record</p>
<h2 id="detailTitle"></h2>
<div id="detailDate" class="detail-date"></div>
<div id="detailTags" class="tag-row"></div>
<section class="source-fact">
<div class="source-label">Source fact / route-independent</div>
<p id="detailFact"></p>
</section>
<section class="route-relation">
<h3 id="relationTitle">Chronology relation</h3>
<p id="relationBody"></p>
<div id="relatedList" class="related-list"></div>
</section>
<div id="recordId" class="record-id"></div>
</aside>
<div class="control-hint">Drag to orbit · Shift-drag to pan · Scroll to zoom · Click an exhibit</div>
<div id="live" class="sr-only" aria-live="polite"></div>
<div id="loading" class="loading">
<div class="loading-block"><span class="loading-cube"></span>Building the museum</div>
</div>
<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 reducedMotion = matchMedia("(prefers-reduced-motion: reduce)").matches;
const themeDefinitions = [
{ id: "making", title: "Making & Material", color: "#72d6c9" },
{ id: "image", title: "Image & Story", color: "#ee8f72" },
{ id: "land", title: "Land & Public Life", color: "#e6c765" },
{ id: "power", title: "Power & Order", color: "#b897e8" },
{ id: "knowledge", title: "Knowledge & Exchange", color: "#79a7ff" }
];
const collection = [
{
id: "lomekwi",
title: "Lomekwi Tool",
year: -3300000,
date: "c. 3.3 million years ago",
themes: ["making"],
fact: "The stone tools found at Lomekwi 3 in Kenya date to about 3.3 million years ago, making them among the oldest known stone tools.",
model: {
rows: [
"..GG...",
".GGGG..",
"GGGGGGG",
"GGGGGG.",
".GGG..."
],
palette: { G: "#75817f" }
}
},
{
id: "handaxe",
title: "Acheulean Handaxe",
year: -1760000,
date: "c. 1.76 million years ago",
themes: ["making"],
fact: "Acheulean handaxes first appeared about 1.76 million years ago. Their broad, worked shape was shaped on both sides.",
model: {
rows: [
"...BB..",
"..BBBB.",
".BBBBB.",
"BBBBBBB",
".BBBBB.",
"..BBB.."
],
palette: { B: "#b48b61" }
}
},
{
id: "chauvet",
title: "Chauvet Cave Art",
year: -36000,
date: "c. 36,000 BCE",
themes: ["image"],
fact: "The paintings and traces of human presence in Chauvet Cave date to at least 36,000 years ago, among the earliest known cave art.",
model: {
rows: [
"........",
"..BBBB..",
".BBWBBB.",
"BBBBBBBB",
".BBBBBB.",
"..B..B.."
],
palette: { B: "#9c553b", W: "#352d29" }
}
},
{
id: "venus",
title: "Venus of Willendorf",
year: -25000,
date: "c. 25,000 BCE",
themes: ["image"],
fact: "This small limestone figure was made around 25,000 BCE in what is now Austria. It is among the oldest known human figurines.",
model: {
rows: [
"...S...",
"..SSS..",
"..SWS..",
".SSSSS.",
".SSSSS.",
"..SSS..",
"..LLL.."
],
palette: { S: "#d1ad76", W: "#644634", L: "#a77951" }
}
},
{
id: "papyrus",
title: "Papyrus Scroll",
year: -3000,
date: "c. 3000 BCE",
themes: ["knowledge"],
fact: "The earliest known papyrus sheets date to around 3000 BCE. Papyrus became a durable writing material across the ancient Mediterranean.",
model: {
rows: [
"........",
"..PPPP..",
".PPPPPP.",
"PPPPPPPP",
".PPPPPP.",
"..PPPP.."
],
palette: { P: "#c4a25d" }
}
},
{
id: "stonehenge",
title: "Stonehenge",
year: -2999,
date: "c. 3000–2000 BCE",
themes: ["land"],
fact: "Stonehenge was built in several stages, chiefly between about 3000 and 2000 BCE. Its stones came from across the surrounding landscape.",
model: {
rows: [
"..S...S..",
"..S...S..",
"..S...S..",
".SSSSSSS.",
"SSSSSSSSS"
],
palette: { S: "#8d8b7d" }
}
},
{
id: "hammurabi",
title: "Hammurabi Code",
year: -1754,
date: "c. 1754 BCE",
themes: ["power"],
fact: "A basalt stele from Babylon contains 282 laws attributed to King Hammurabi, making it one of the best-known early legal collections.",
model: {
rows: [
"..GGGG..",
".GGGGGG.",
"GGGGGGGG",
"GGYYYYGG",
"GGYYYYGG",
".GGGGGG.",
"..GGGG.."
],
palette: { G: "#424a49", Y: "#c6a85e" }
}
},
{
id: "tut",
title: "Tutankhamun Mask",
year: -1323,
date: "c. 1323 BCE",
themes: ["power"],
fact: "This gold funerary mask was made for the Egyptian pharaoh Tutankhamun, whose death is conventionally dated to 1323 BCE.",
model: {
rows: [
"...B....",
"..BBB...",
".BWBBW..",
"..BGB...",
"..GBG...",
"..GGG...",
".BBBBB.."
],
palette: { B: "#d7aa42", W: "#173a4c", G: "#17637b" }
}
},
{
id: "antikythera",
title: "Antikythera Mechanism",
year: -150,
date: "c. 150–100 BCE",
themes: ["knowledge"],
fact: "The Antikythera mechanism used a complex set of bronze gears to model astronomical cycles, including the positions of the Sun and Moon.",
model: {
rows: [
"..YYYY..",
".Y....Y.",
"Y..YY..Y",
"Y.YY..Y.",
"Y..YY..Y",
".Y....Y.",
"..YYYY.."
],
palette: { Y: "#9c7545" }
}
},
{
id: "terracotta",
title: "Terracotta Warrior",
year: -210,
date: "c. 210 BCE",
themes: ["power"],
fact: "The Terracotta Army was created for the tomb of China's first emperor, Qin Shi Huang, in the late third century BCE.",
model: {
rows: [
"...F...",
"..FFF..",
"..FHF..",
".FFFFFF.",
"FFFFF...",
".F...F.."
],
palette: { F: "#a85e43", H: "#643d31" }
}
},
{
id: "colosseum",
title: "Colosseum",
year: 80,
date: "c. 70–80 CE",
themes: ["land"],
fact: "The Flavian Amphitheatre opened around 80 CE. Its surrounding arcades and vaults supported a vast program of public spectacle.",
model: {
rows: [
"CCCCCCCCC",
"CCCCCCCCC",
"C.CC.CC.C",
"C.CC.CC.C",
"C.CC.CC.C",
"CCCCCCCCC"
],
palette: { C: "#bda77e" }
}
},
{
id: "hagia",
title: "Hagia Sophia",
year: 537,
date: "537 CE",
themes: ["land"],
fact: "Hagia Sophia was completed in Constantinople in 537 CE. Its vast dome made it one of the defining buildings of Byzantine architecture.",
model: {
rows: [
"...DDD...",
"..DDDDD..",
".DDDDDDD.",
"DDDDDDDDD",
".DDDDDDD.",
"..D...D..",
"..D...D.."
],
palette: { D: "#bc756d" }
}
},
{
id: "clock",
title: "Elephant Clock",
year: 1206,
date: "1206 CE",
themes: ["making"],
fact: "Al-Jazari described an ingenious water-powered clock shaped like an elephant in 1206. It was part of a body of mechanical devices for practical use and display.",
model: {
rows: [
"...BBB...",
"..BEEB..",
".BBEEEB.",
"BBBBBBB.",
".B...B..",
"..CCC...",
"..C.C..."
],
palette: { B: "#53737b", E: "#c0b8a2", C: "#a47d45" }
}
},
{
id: "printing",
title: "Movable-Type Press",
year: 1450,
date: "c. 1450 CE",
themes: ["image"],
fact: "Movable metal type was used in Europe around 1450. The press made it practical to reproduce many copies of the same page.",
model: {
rows: [
"..RRRR..",
".R....R.",
".RRWWRR.",
"R.RWWR.R",
"R.RWWR.R",
".RRWWRR.",
"..RRRR.."
],
palette: { R: "#6e4136", W: "#c4ad80" }
}
}
];
function deepFreeze(value) {
if (value && typeof value === "object" && !Object.isFrozen(value)) {
Object.freeze(value);
Object.values(value).forEach(deepFreeze);
}
return value;
}
deepFreeze(themeDefinitions);
deepFreeze(collection);
const sortedCollection = [...collection].sort((a, b) => a.year - b.year);
const themeMap = new Map(themeDefinitions.map(theme => [theme.id, theme]));
const itemMap = new Map(collection.map(item => [item.id, item]));
const scene = new THREE.Scene();
scene.background = new THREE.Color("#081119");
scene.fog = new THREE.Fog("#081119", 31, 53);
const camera = new THREE.PerspectiveCamera(43, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
const hemisphere = new THREE.HemisphereLight(0xc8ebf2, 0x17202a, 1.9);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffe0ad, 3.2);
keyLight.position.set(8, 15, 10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -14;
keyLight.shadow.camera.right = 14;
keyLight.shadow.camera.top = 13;
keyLight.shadow.camera.bottom = -13;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 40;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x5cbdc7, 1.25);
rimLight.position.set(-10, 8, -8);
scene.add(rimLight);
function seededRandom(seed) {
return function () {
seed |= 0;
seed = seed + 0x6D2B79F5 | 0;
let t = Math.imul(seed ^ seed >>> 15, 1 | seed);
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
return ((t ^ t >>> 14) >>> 0) / 4294967296;
};
}
const random = seededRandom(84291);
function makeFloor() {
const base = new THREE.Mesh(
new THREE.BoxGeometry(18.1, 0.28, 12.1),
new THREE.MeshStandardMaterial({ color: 0x101d25, roughness: 0.96 })
);
base.position.y = -0.18;
base.receiveShadow = true;
scene.add(base);
const columns = 30;
const rows = 20;
const spacing = 0.59;
const geometry = new THREE.BoxGeometry(0.545, 0.065, 0.545);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.91,
metalness: 0.03
});
const tiles = new THREE.InstancedMesh(geometry, material, columns * rows);
const matrix = new THREE.Matrix4();
const color = new THREE.Color();
const dark = new THREE.Color("#14252e");
const light = new THREE.Color("#263b43");
let index = 0;
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const x = (column - (columns - 1) / 2) * spacing;
const z = (row - (rows - 1) / 2) * spacing;
matrix.makeTranslation(x, -0.015, z);
tiles.setMatrixAt(index, matrix);
color.copy(dark).lerp(light, random() * 0.65);
tiles.setColorAt(index, color);
index++;
}
}
tiles.instanceMatrix.needsUpdate = true;
tiles.instanceColor.needsUpdate = true;
tiles.receiveShadow = true;
scene.add(tiles);
const wallGeometry = new THREE.BoxGeometry(0.56, 0.48, 0.56);
const wallMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.87
});
const wallCount = 31 + 16;
const walls = new THREE.InstancedMesh(wallGeometry, wallMaterial, wallCount);
let wallIndex = 0;
for (let column = 0; column < 31; column++) {
matrix.makeTranslation(
(column - 15) * 0.59,
0.23,
-5.91
);
walls.setMatrixAt(wallIndex, matrix);
color.set("#263842").multiplyScalar(0.78 + random() * 0.25);
walls.setColorAt(wallIndex++, color);
}
for (let row = 0; row < 16; row++) {
matrix.makeTranslation(
-8.91,
0.23,
(row - 7.5) * 0.59
);
walls.setMatrixAt(wallIndex, matrix);
color.set("#263842").multiplyScalar(0.78 + random() * 0.25);
walls.setColorAt(wallIndex++, color);
}
walls.instanceMatrix.needsUpdate = true;
walls.instanceColor.needsUpdate = true;
walls.castShadow = true;
walls.receiveShadow = true;
scene.add(walls);
}
makeFloor();
const dynamicConnections = new THREE.Group();
scene.add(dynamicConnections);
const pickables = [];
const exhibitObjects = new Map();
const voxelGeometry = new THREE.BoxGeometry(0.182, 0.182, 0.182);
const voxelMaterials = new Map();
const plinthMaterial = new THREE.MeshStandardMaterial({
color: 0x1b2c35,
roughness: 0.72,
metalness: 0.12
});
const plinthTopMaterial = new THREE.MeshStandardMaterial({
color: 0x30434a,
roughness: 0.62,
metalness: 0.16
});
const hitMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
});
const selectionMaterial = new THREE.MeshBasicMaterial({ color: 0xffe19a });
function getVoxelMaterial(color) {
if (!voxelMaterials.has(color)) {
voxelMaterials.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.76,
metalness: 0.04
})
);
}
return voxelMaterials.get(color);
}
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function makeLabelSprite(item) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 150;
const ctx = labelCanvas.getContext("2d");
ctx.clearRect(0, 0, 512, 150);
roundedRect(ctx, 5, 5, 502, 140, 18);
ctx.fillStyle = "rgba(7, 17, 24, 0.92)";
ctx.fill();
ctx.strokeStyle = "rgba(220, 235, 237, 0.20)";
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = "#f3f5ee";
ctx.font = "700 31px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(item.title.toUpperCase(), 256, 55, 468);
ctx.fillStyle = "#e8bd62";
ctx.font = "700 22px system-ui, sans-serif";
ctx.fillText(item.date.toUpperCase(), 256, 104, 462);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(1.72, 0.50, 1);
sprite.userData.exhibitId = item.id;
sprite.renderOrder = 3;
return sprite;
}
function makeSelectionFrame() {
const frame = new THREE.Group();
const y = 0.205;
const x = 0.62;
const z = 0.54;
const horizontalGeometry = new THREE.BoxGeometry(1.28, 0.035, 0.035);
const verticalGeometry = new THREE.BoxGeometry(0.035, 0.035, 1.12);
for (const side of [-1, 1]) {
const horizontal = new THREE.Mesh(horizontalGeometry, selectionMaterial);
horizontal.position.set(0, y, side * z);
frame.add(horizontal);
const vertical = new THREE.Mesh(verticalGeometry, selectionMaterial);
vertical.position.set(side * x, y, 0);
frame.add(vertical);
}
frame.visible = false;
return frame;
}
function makeExhibit(item) {
const group = new THREE.Group();
group.userData.exhibitId = item.id;
const plinth = new THREE.Mesh(
new THREE.BoxGeometry(1.12, 0.17, 0.96),
plinthMaterial
);
plinth.position.y = 0.085;
plinth.castShadow = true;
plinth.receiveShadow = true;
group.add(plinth);
const plinthTop = new THREE.Mesh(
new THREE.BoxGeometry(0.96, 0.025, 0.81),
plinthTopMaterial
);
plinthTop.position.y = 0.183;
plinthTop.receiveShadow = true;
group.add(plinthTop);
const model = new THREE.Group();
const rows = item.model.rows;
const width = Math.max(...rows.map(row => row.length));
const cube = 0.21;
rows.forEach((row, rowIndex) => {
[...row].forEach((character, columnIndex) => {
if (character === ".") return;
const color = item.model.palette[character];
const mesh = new THREE.Mesh(voxelGeometry, getVoxelMaterial(color));
mesh.position.set(
(columnIndex - (width - 1) / 2) * cube,
0.28 + (rows.length - 1 - rowIndex) * cube,
0
);
mesh.castShadow = true;
mesh.receiveShadow = true;
model.add(mesh);
});
});
group.add(model);
const label = makeLabelSprite(item);
label.position.y = 0.31 + rows.length * 0.21 + 0.27;
group.add(label);
pickables.push(label);
const hitbox = new THREE.Mesh(
new THREE.BoxGeometry(1.6, 2.1, 1.25),
hitMaterial
);
hitbox.position.y = 0.93;
hitbox.userData.exhibitId = item.id;
group.add(hitbox);
pickables.push(hitbox);
const frame = makeSelectionFrame();
group.add(frame);
group.userData.frame = frame;
scene.add(group);
exhibitObjects.set(item.id, group);
}
collection.forEach(makeExhibit);
function makeRouteSign(title, subtitle, color) {
const signCanvas = document.createElement("canvas");
signCanvas.width = 1024;
signCanvas.height = 256;
const ctx = signCanvas.getContext("2d");
ctx.clearRect(0, 0, 1024, 256);
roundedRect(ctx, 12, 12, 1000, 232, 24);
ctx.fillStyle = "rgba(7, 17, 24, 0.91)";
ctx.fill();
ctx.strokeStyle = color;
ctx.lineWidth = 5;
ctx.stroke();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = color;
ctx.font = "800 26px system-ui, sans-serif";
ctx.fillText("ATLAS MUSEUM / ONE COLLECTION", 512, 62);
ctx.fillStyle = "#f1f3ec";
ctx.font = "750 64px system-ui, sans-serif";
ctx.fillText(title.toUpperCase(), 512, 125, 920);
ctx.fillStyle = "#9fb1b8";
ctx.font = "600 27px system-ui, sans-serif";
ctx.fillText(subtitle.toUpperCase(), 512, 196, 920);
const texture = new THREE.CanvasTexture(signCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
sprite.scale.set(5.5, 1.375, 1);
sprite.position.set(0, 1.55, -5.38);
sprite.renderOrder = 2;
return sprite;
}
let routeSign = makeRouteSign(
"Chronology Hall",
"Earlier objects lead toward later ones",
"#f2c96e"
);
scene.add(routeSign);
function makeFlatThemeLabel(title, color) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 768;
labelCanvas.height = 160;
const ctx = labelCanvas.getContext("2d");
ctx.clearRect(0, 0, 768, 160);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = color;
ctx.font = "800 34px system-ui, sans-serif";
ctx.fillText(title.toUpperCase(), 384, 80, 730);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(2.9, 0.6),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide
})
);
mesh.rotation.x = -Math.PI / 2;
return mesh;
}
const arrangements = { chronology: new Map(), themes: new Map() };
const firstRowCount = Math.ceil(sortedCollection.length / 2);
const chronologicalXs = sortedCollection.map((item, index) => {
if (index < firstRowCount) {
return {
x: -7.35 + index * 2.1,
z: -2.72
};
}
return {
x: 7.35 - (index - firstRowCount) * 2.1,
z: 2.67
};
});
sortedCollection.forEach((item, index) => {
arrangements.chronology.set(item.id, chronologicalXs[index]);
});
const clusterCenters = {
making: { x: -5.25, z: -2.55 },
image: { x: 0, z: -2.55 },
land: { x: 5.25, z: -2.55 },
power: { x: -2.65, z: 2.55 },
knowledge: { x: 2.65, z: 2.55 }
};
const clusterOffsets = [
{ x: -1.02, z: -0.52 },
{ x: 1.02, z: -0.52 },
{ x: 0, z: 0.86 }
];
themeDefinitions.forEach(theme => {
const members = collection.filter(item => item.themes.includes(theme.id));
const center = clusterCenters[theme.id];
members.forEach((item, index) => {
const offset = clusterOffsets[index];
arrangements.themes.set(item.id, {
x: center.x + offset.x,
z: center.z + offset.z
});
});
});
function clearDynamicGroup(group) {
while (group.children.length) {
const child = group.children.pop();
child.traverse(object => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
const materials = Array.isArray(object.material)
? object.material
: [object.material];
materials.forEach(material => material.dispose());
}
});
}
}
function addSegment(group, start, end, color, opacity = 0.9) {
const dx = end.x - start.x;
const dz = end.z - start.z;
const length = Math.hypot(dx, dz);
if (length < 0.001) return;
const geometry = new THREE.BoxGeometry(length, 0.035, 0.065);
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false
});
const segment = new THREE.Mesh(geometry, material);
segment.position.set(
(start.x + end.x) / 2,
0.087,
(start.z + end.z) / 2
);
segment.rotation.y = -Math.atan2(dz, dx);
group.add(segment);
}
function addThemeZone(theme, center) {
const columns = 5;
const rows = 5;
const spacing = 0.55;
const geometry = new THREE.BoxGeometry(0.505, 0.022, 0.505);
const material = new THREE.MeshBasicMaterial({
color: theme.color,
transparent: true,
opacity: 0.11,
depthWrite: false
});
const tiles = new THREE.InstancedMesh(geometry, material, columns * rows);
const matrix = new THREE.Matrix4();
let index = 0;
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
matrix.makeTranslation(
center.x + (column - 2) * spacing,
0.067,
center.z + (row - 2) * spacing
);
tiles.setMatrixAt(index++, matrix);
}
}
tiles.instanceMatrix.needsUpdate = true;
dynamicConnections.add(tiles);
const label = makeFlatThemeLabel(theme.title, theme.color);
label.position.set(center.x, 0.102, center.z + 1.66);
dynamicConnections.add(label);
}
function buildConnections(route) {
clearDynamicGroup(dynamicConnections);
if (route === "chronology") {
const color = "#f2c96e";
for (let index = 0; index < sortedCollection.length - 1; index++) {
const a = arrangements.chronology.get(sortedCollection[index].id);
const b = arrangements.chronology.get(sortedCollection[index + 1].id);
addSegment(dynamicConnections, a, b, color, 0.76);
}
sortedCollection.forEach((item, index) => {
const point = arrangements.chronology.get(item.id);
const marker = new THREE.Mesh(
new THREE.BoxGeometry(0.13, 0.05, 0.13),
new THREE.MeshBasicMaterial({ color, transparent: true, opacity: 0.9 })
);
marker.position.set(point.x, 0.115, point.z);
dynamicConnections.add(marker);
});
} else {
themeDefinitions.forEach(theme => {
const center = clusterCenters[theme.id];
addThemeZone(theme, center);
const members = collection.filter(item => item.themes.includes(theme.id));
for (let i = 0; i < members.length; i++) {
for (let j = i + 1; j < members.length; j++) {
addSegment(
dynamicConnections,
arrangements.themes.get(members[i].id),
arrangements.themes.get(members[j].id),
theme.color,
0.76
);
}
}
});
}
}
const state = {
route: "chronology",
selected: sortedCollection[0].id,
connections: true,
routeTween: null
};
const cameraState = {
yaw: 0.55,
pitch: 0.73,
distance: 21.5,
target: new THREE.Vector3(0, 0.45, 0)
};
const desiredCamera = {
yaw: cameraState.yaw,
pitch: cameraState.pitch,
distance: cameraState.distance,
target: cameraState.target.clone()
};
function getBaseDistance() {
if (camera.aspect < 0.72) return 28;
if (camera.aspect < 1.1) return 25;
return 21.5;
}
function setRouteSign(route) {
scene.remove(routeSign);
routeSign.material.map?.dispose();
routeSign.material.dispose();
routeSign = route === "chronology"
? makeRouteSign(
"Chronology Hall",
"Earlier objects lead toward later ones",
"#f2c96e"
)
: makeRouteSign(
"Theme Gallery",
"Shared questions create new neighbours",
"#79d8cf"
);
scene.add(routeSign);
}
function updateRouteUI(route) {
document.querySelectorAll(".route-link").forEach(link => {
const active = link.dataset.route === route;
link.classList.toggle("active", active);
if (active) link.setAttribute("aria-current", "page");
else link.removeAttribute("aria-current");
});
if (route === "chronology") {
document.querySelector("#routeKicker").textContent = "Route 01 / Time";
document.querySelector("#routeTitle").textContent = "The collection becomes a timeline.";
document.querySelector("#routeDescription").textContent =
"Distance now represents elapsed time. The golden path links each object to its immediate predecessor and successor.";
document.querySelector("#railTitle").textContent = "The chronological path";
} else {
document.querySelector("#routeKicker").textContent = "Route 02 / Theme";
document.querySelector("#routeTitle").textContent = "The collection becomes a constellation.";
document.querySelector("#routeDescription").textContent =
"Distance now represents shared subject. Colored clusters reveal affinities that the chronological path intentionally separates.";
document.querySelector("#railTitle").textContent = "The thematic clusters";
}
renderRouteRail();
updateDetails();
document.querySelector("#live").textContent =
route === "chronology"
? "Chronology route selected. Exhibits are arranged from earliest to latest."
: "Theme gallery selected. Exhibits are grouped by shared subject.";
}
function renderRouteRail() {
const rail = document.querySelector("#routeRail");
rail.replaceChildren();
if (state.route === "chronology") {
sortedCollection.forEach(item => {
const button = document.createElement("button");
button.className = "chron-node";
if (item.id === state.selected) button.classList.add("active");
button.title = `${item.title} — ${item.date}`;
button.setAttribute("aria-label", button.title);
button.innerHTML = "<span></span>";
button.addEventListener("click", () => selectExhibit(item.id));
rail.appendChild(button);
});
} else {
themeDefinitions.forEach(theme => {
const button = document.createElement("button");
button.className = "theme-chip";
button.style.setProperty("--swatch", theme.color);
const selectedMember = itemMap.get(state.selected);
if (selectedMember?.themes.includes(theme.id)) {
button.classList.add("active");
}
const dot = document.createElement("i");
const text = document.createElement("span");
text.textContent = theme.title;
button.append(dot, text);
button.addEventListener("click", () => {
const firstMember = collection.find(item => item.themes.includes(theme.id));
selectExhibit(firstMember.id);
});
rail.appendChild(button);
});
}
}
function updateDetails() {
const item = itemMap.get(state.selected);
if (!item) return;
document.querySelector("#detailKicker").textContent = "Exhibit record";
document.querySelector("#detailTitle").textContent = item.title;
document.querySelector("#detailDate").textContent = item.date;
document.querySelector("#detailFact").textContent = item.fact;
const tags = document.querySelector("#detailTags");
tags.replaceChildren();
item.themes.forEach(themeId => {
const tag = document.createElement("span");
tag.className = "tag";
tag.textContent = themeMap.get(themeId).title;
tags.appendChild(tag);
});
const relationTitle = document.querySelector("#relationTitle");
const relationBody = document.querySelector("#relationBody");
const relatedList = document.querySelector("#relatedList");
relatedList.replaceChildren();
if (state.route === "chronology") {
const index = sortedCollection.findIndex(entry => entry.id === item.id);
const before = sortedCollection[index - 1];
const after = sortedCollection[index + 1];
relationTitle.textContent = "Chronology relation";
relationBody.textContent = before && after
? `${before.title} immediately precedes this object; ${after.title} follows it. The gold line expresses this temporal neighborhood.`
: before
? `${before.title} immediately precedes this object, which begins the chronological path.`
: `${after.title} follows this object, which begins the chronological path.`;
if (before) addRelatedButton(before, "before");
if (after) addRelatedButton(after, "after");
} else {
const themeId = item.themes[0];
const theme = themeMap.get(themeId);
const peers = collection.filter(
entry => entry.id !== item.id && entry.themes.includes(themeId)
);
relationTitle.textContent = "Thematic relation";
relationBody.textContent =
`The cluster link shows objects joined by “${theme.title}”—a relationship made visible rather than chronological.`;
peers.forEach(peer => addRelatedButton(peer, "shares theme"));
}
const recordIndex = sortedCollection.findIndex(entry => entry.id === item.id) + 1;
document.querySelector("#recordId").textContent =
`SOURCE RECORD ${String(recordIndex).padStart(2, "0")} / ${String(collection.length).padStart(2, "0")} · FACTS DO NOT CHANGE BETWEEN ROUTES`;
}
function addRelatedButton(item, relationship) {
const button = document.createElement("button");
button.className = "related-button";
const name = document.createElement("strong");
name.textContent = item.title;
const relation = document.createElement("span");
relation.textContent = relationship;
button.append(name, relation);
button.addEventListener("click", () => selectExhibit(item.id));
document.querySelector("#relatedList").appendChild(button);
}
function selectExhibit(id) {
if (!itemMap.has(id)) return;
state.selected = id;
exhibitObjects.forEach((group, exhibitId) => {
group.userData.frame.visible = exhibitId === id;
});
updateDetails();
renderRouteRail();
document.querySelector("#live").textContent =
`${itemMap.get(id).title} selected. ${itemMap.get(id).date}.`;
}
function switchRoute(route, instant = false) {
state.route = route;
const arrangement = arrangements[route];
const tweenItems = [];
collection.forEach(item => {
const group = exhibitObjects.get(item.id);
const target = arrangement.get(item.id);
const targetPosition = new THREE.Vector3(target.x, 0, target.z);
if (instant || reducedMotion) {
group.position.copy(targetPosition);
} else {
tweenItems.push({
group,
start: group.position.clone(),
end: targetPosition
});
}
});
state.routeTween = tweenItems.length
? { start: performance.now(), duration: 1050, items: tweenItems }
: null;
buildConnections(route);
dynamicConnections.visible = state.connections;
setRouteSign(route);
updateRouteUI(route);
desiredCamera.yaw = route === "chronology" ? 0.55 : 0.38;
desiredCamera.pitch = route === "chronology" ? 0.73 : 0.79;
desiredCamera.distance = getBaseDistance();
desiredCamera.target.set(0, 0.45, 0);
}
document.querySelectorAll(".route-link").forEach(link => {
link.addEventListener("click", event => {
event.preventDefault();
const route = link.dataset.route;
if (location.hash !== `#${route}`) {
location.hash = route;
} else {
switchRoute(route);
}
});
});
document.querySelector("#connectionsButton").addEventListener("click", event => {
state.connections = !state.connections;
dynamicConnections.visible = state.connections;
event.currentTarget.setAttribute("aria-pressed", String(state.connections));
event.currentTarget.textContent = state.connections ? "Links on" : "Links off";
});
function routeFromHash() {
return location.hash === "#themes" ? "themes" : "chronology";
}
window.addEventListener("hashchange", () => {
switchRoute(routeFromHash());
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = false;
let dragDistance = 0;
let lastPointerX = 0;
let lastPointerY = 0;
let pointerButton = 0;
function pickExhibit(clientX, clientY) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickables, false);
return hits.length ? hits[0].object.userData.exhibitId : null;
}
canvas.addEventListener("pointerdown", event => {
pointerDown = true;
dragDistance = 0;
pointerButton = event.button;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!pointerDown) {
const hovered = pickExhibit(event.clientX, event.clientY);
canvas.style.cursor = hovered ? "pointer" : "grab";
return;
}
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
dragDistance += Math.hypot(dx, dy);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
if (event.shiftKey || pointerButton === 2) {
const right = new THREE.Vector3(
Math.cos(desiredCamera.yaw),
0,
-Math.sin(desiredCamera.yaw)
);
desiredCamera.target.addScaledVector(right, -dx * desiredCamera.distance * 0.0012);
desiredCamera.target.x = THREE.MathUtils.clamp(desiredCamera.target.x, -5, 5);
desiredCamera.target.z = THREE.MathUtils.clamp(desiredCamera.target.z, -3.5, 3.5);
} else {
desiredCamera.yaw -= dx * 0.005;
desiredCamera.pitch = THREE.MathUtils.clamp(
desiredCamera.pitch + dy * 0.004,
0.34,
1.17
);
}
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointerup", event => {
if (pointerDown && dragDistance < 6 && pointerButton === 0) {
const id = pickExhibit(event.clientX, event.clientY);
if (id) selectExhibit(id);
}
pointerDown = false;
canvas.style.cursor = "grab";
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
pointerDown = false;
canvas.style.cursor = "grab";
});
canvas.addEventListener("wheel", event => {
event.preventDefault();
desiredCamera.distance = THREE.MathUtils.clamp(
desiredCamera.distance + event.deltaY * 0.012,
12,
34
);
}, { passive: false });
canvas.addEventListener("contextmenu", event => event.preventDefault());
window.addEventListener("keydown", event => {
if (["INPUT", "TEXTAREA", "SELECT"].includes(document.activeElement?.tagName)) return;
switch (event.key) {
case "ArrowLeft":
desiredCamera.yaw += 0.09;
break;
case "ArrowRight":
desiredCamera.yaw -= 0.09;
break;
case "ArrowUp":
desiredCamera.pitch = Math.min(1.17, desiredCamera.pitch + 0.07);
break;
case "ArrowDown":
desiredCamera.pitch = Math.max(0.34, desiredCamera.pitch - 0.07);
break;
case "+":
case "=":
desiredCamera.distance = Math.max(12, desiredCamera.distance - 1);
break;
case "-":
desiredCamera.distance = Math.min(34, desiredCamera.distance + 1);
break;
case "1":
location.hash = "chronology";
break;
case "2":
location.hash = "themes";
break;
default:
return;
}
event.preventDefault();
});
let previousBaseDistance = 21.5;
function resize() {
const width = innerWidth;
const height = innerHeight;
const newBaseDistance = getBaseDistance();
const scale = newBaseDistance / previousBaseDistance;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
desiredCamera.distance = THREE.MathUtils.clamp(
desiredCamera.distance * scale,
12,
34
);
previousBaseDistance = newBaseDistance;
}
window.addEventListener("resize", resize);
function easeInOutCubic(value) {
return value < 0.5
? 4 * value * value * value
: 1 - Math.pow(-2 * value + 2, 3) / 2;
}
let previousTime = performance.now();
function animate(now) {
const dt = Math.min(0.05, (now - previousTime) / 1000);
previousTime = now;
if (state.routeTween) {
const raw = THREE.MathUtils.clamp(
(now - state.routeTween.start) / state.routeTween.duration,
0,
1
);
const eased = easeInOutCubic(raw);
state.routeTween.items.forEach(entry => {
entry.group.position.lerpVectors(entry.start, entry.end, eased);
});
if (raw >= 1) state.routeTween = null;
}
const damping = 1 - Math.exp(-dt * 7);
cameraState.yaw = THREE.MathUtils.lerp(cameraState.yaw, desiredCamera.yaw, damping);
cameraState.pitch = THREE.MathUtils.lerp(cameraState.pitch, desiredCamera.pitch, damping);
cameraState.distance = THREE.MathUtils.lerp(cameraState.distance, desiredCamera.distance, damping);
cameraState.target.lerp(desiredCamera.target, damping);
const horizontalDistance = Math.cos(cameraState.pitch) * cameraState.distance;
camera.position.set(
cameraState.target.x + Math.sin(cameraState.yaw) * horizontalDistance,
cameraState.target.y + Math.sin(cameraState.pitch) * cameraState.distance,
cameraState.target.z + Math.cos(cameraState.yaw) * horizontalDistance
);
camera.lookAt(cameraState.target);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
resize();
const initialRoute = routeFromHash();
if (!location.hash) {
history.replaceState(null, "", "#chronology");
}
switchRoute(initialRoute, true);
cameraState.yaw = desiredCamera.yaw;
cameraState.pitch = desiredCamera.pitch;
cameraState.distance = desiredCamera.distance;
cameraState.target.copy(desiredCamera.target);
selectExhibit(sortedCollection[0].id);
requestAnimationFrame(animate);
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```