Prompt specification
Build or customize the Three.js 3D scene "Public exhibition orientation walk" 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: Public exhibition orientation walk
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/public-exhibition-orientation-walk-x0435
Scene Description Prompt:
Animate a visitor following stylized gallery landmarks while matching map segments light up in order. Build standalone HTML using Three.js from cdnjs.
Working Three.js Starter (public-exhibition-orientation-walk-x0435):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#0b1210" />
<title>Gallery Atlas — A Guided Walk</title>
<style>
:root {
--ink: #eef2e9;
--muted: #93a39a;
--panel: rgba(12, 20, 17, 0.82);
--panel-solid: #101915;
--line: rgba(225, 239, 229, 0.13);
--lime: #d7ff72;
--coral: #ff956d;
--blue: #76d8ff;
--shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #0b1210;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene,
#scene canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#scene canvas {
display: block;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.atmosphere {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 65% 42%, transparent 0 35%, rgba(4, 8, 7, 0.28) 100%),
linear-gradient(180deg, rgba(3, 8, 7, 0.16), transparent 30%, rgba(3, 8, 7, 0.3));
z-index: 2;
}
.topbar {
position: fixed;
z-index: 10;
top: 0;
left: 0;
right: 0;
height: 76px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 28px;
border-bottom: 1px solid rgba(230, 244, 234, 0.1);
background: linear-gradient(180deg, rgba(7, 13, 11, 0.82), rgba(7, 13, 11, 0));
pointer-events: none;
}
.brand,
.top-actions {
pointer-events: auto;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
}
.brand-mark {
position: relative;
width: 37px;
height: 37px;
border: 1px solid rgba(215, 255, 114, 0.55);
border-radius: 50%;
display: grid;
place-items: center;
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
background: var(--lime);
}
.brand-mark::before {
width: 14px;
height: 1px;
transform: rotate(45deg);
}
.brand-mark::after {
width: 1px;
height: 14px;
transform: rotate(45deg);
}
.brand-copy {
display: flex;
flex-direction: column;
gap: 3px;
}
.brand-title {
font-size: 12px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.brand-subtitle {
color: var(--muted);
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.top-actions {
display: flex;
align-items: center;
gap: 16px;
}
.live-status {
display: flex;
align-items: center;
gap: 9px;
color: #b9c6bd;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--lime);
box-shadow: 0 0 0 5px rgba(215, 255, 114, 0.08), 0 0 14px var(--lime);
animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
50% {
opacity: 0.45;
transform: scale(0.8);
}
}
.glass-button {
border: 1px solid var(--line);
background: rgba(15, 25, 21, 0.62);
color: var(--ink);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
border-radius: 999px;
min-height: 38px;
padding: 0 16px;
cursor: pointer;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
transition:
border-color 180ms ease,
background 180ms ease,
transform 180ms ease;
}
.glass-button:hover {
border-color: rgba(215, 255, 114, 0.46);
background: rgba(26, 39, 31, 0.86);
transform: translateY(-1px);
}
.panel {
position: fixed;
z-index: 8;
border: 1px solid var(--line);
background: var(--panel);
backdrop-filter: blur(22px) saturate(120%);
-webkit-backdrop-filter: blur(22px) saturate(120%);
box-shadow: var(--shadow);
}
.route-panel {
top: 96px;
left: 24px;
bottom: 112px;
width: 286px;
border-radius: 22px;
overflow: hidden;
display: flex;
flex-direction: column;
}
.route-intro {
padding: 23px 22px 18px;
border-bottom: 1px solid var(--line);
}
.eyebrow {
color: var(--lime);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.route-intro h1 {
margin: 8px 0 7px;
font-family: Georgia, "Times New Roman", serif;
font-size: 29px;
font-weight: 400;
line-height: 1.05;
letter-spacing: -0.03em;
}
.route-intro p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.route-list {
padding: 10px;
overflow-y: auto;
scrollbar-width: thin;
scrollbar-color: rgba(215, 255, 114, 0.25) transparent;
}
.route-stop {
width: 100%;
border: 0;
color: inherit;
background: transparent;
display: grid;
grid-template-columns: 32px 1fr 18px;
align-items: center;
gap: 10px;
text-align: left;
padding: 11px 10px;
border-radius: 13px;
cursor: pointer;
transition: background 180ms ease;
}
.route-stop:hover {
background: rgba(255, 255, 255, 0.045);
}
.route-stop.active {
background: rgba(215, 255, 114, 0.075);
}
.stop-number {
width: 30px;
height: 30px;
border-radius: 50%;
display: grid;
place-items: center;
border: 1px solid rgba(221, 235, 225, 0.18);
color: #9baa9f;
font-size: 10px;
font-weight: 750;
transition: all 220ms ease;
}
.route-stop.active .stop-number {
color: #17200e;
border-color: var(--lime);
background: var(--lime);
box-shadow: 0 0 20px rgba(215, 255, 114, 0.22);
}
.route-stop.completed .stop-number {
color: var(--lime);
border-color: rgba(215, 255, 114, 0.38);
background: rgba(215, 255, 114, 0.08);
}
.stop-copy {
min-width: 0;
}
.stop-name {
display: block;
margin-bottom: 3px;
font-size: 12px;
font-weight: 680;
color: #dce5dd;
}
.route-stop.active .stop-name {
color: #ffffff;
}
.stop-meta {
display: block;
color: #7e9085;
font-size: 9px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.stop-arrow {
color: #53645b;
font-size: 14px;
opacity: 0;
transform: translateX(-5px);
transition: all 180ms ease;
}
.route-stop:hover .stop-arrow,
.route-stop.active .stop-arrow {
opacity: 1;
transform: translateX(0);
}
.route-footer {
margin-top: auto;
padding: 15px 20px;
display: flex;
justify-content: space-between;
border-top: 1px solid var(--line);
color: #7f9187;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.map-panel {
top: 96px;
right: 24px;
width: 322px;
border-radius: 22px;
overflow: hidden;
}
.map-header {
padding: 18px 20px 8px;
display: flex;
align-items: center;
justify-content: space-between;
}
.map-header strong {
font-size: 10px;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.map-header span {
color: var(--muted);
font-size: 9px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.map-wrap {
margin: 0 12px;
border-radius: 16px;
overflow: hidden;
background:
radial-gradient(circle at 50% 45%, rgba(215, 255, 114, 0.055), transparent 48%),
rgba(5, 12, 9, 0.45);
}
#mapSvg {
display: block;
width: 100%;
height: 190px;
}
.map-base {
stroke: #34463d;
stroke-width: 5;
stroke-linecap: round;
opacity: 0.78;
}
.map-live {
stroke: var(--lime);
stroke-width: 5;
stroke-linecap: round;
filter: drop-shadow(0 0 4px rgba(215, 255, 114, 0.85));
}
.map-grid {
stroke: rgba(213, 235, 221, 0.045);
stroke-width: 1;
}
.map-stop {
fill: #15221b;
stroke: #6d8074;
stroke-width: 1.5;
transition: all 220ms ease;
}
.map-stop-label {
fill: #a9b8ae;
font-size: 7px;
font-weight: 800;
text-anchor: middle;
dominant-baseline: central;
pointer-events: none;
}
.map-stop.active {
fill: var(--lime);
stroke: #f2ffc8;
filter: drop-shadow(0 0 5px rgba(215, 255, 114, 0.7));
}
.map-stop.active + .map-stop-label {
fill: #14200e;
}
.map-stop.completed {
fill: #415c2f;
stroke: var(--lime);
}
.map-stop.completed + .map-stop-label {
fill: var(--lime);
}
.map-legend {
padding: 10px 20px 14px;
display: flex;
gap: 16px;
color: #84958b;
font-size: 9px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.map-legend span {
display: flex;
align-items: center;
gap: 6px;
}
.legend-line {
width: 16px;
height: 2px;
background: #415149;
}
.legend-line.lit {
background: var(--lime);
box-shadow: 0 0 7px rgba(215, 255, 114, 0.65);
}
.current-card {
border-top: 1px solid var(--line);
padding: 18px 20px 20px;
background: linear-gradient(135deg, rgba(215, 255, 114, 0.045), transparent 60%);
}
.current-top {
display: flex;
align-items: center;
justify-content: space-between;
}
.current-index {
color: var(--coral);
font-family: Georgia, serif;
font-size: 27px;
line-height: 1;
}
.current-wings {
color: #75877c;
font-size: 8px;
font-weight: 750;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.current-card h2 {
margin: 10px 0 7px;
font-family: Georgia, "Times New Roman", serif;
font-size: 22px;
font-weight: 400;
letter-spacing: -0.02em;
}
.current-card p {
margin: 0;
color: #96a69c;
font-size: 11px;
line-height: 1.5;
}
.journey {
position: fixed;
z-index: 12;
left: 50%;
bottom: 24px;
transform: translateX(-50%);
width: min(590px, calc(100vw - 40px));
min-height: 68px;
display: grid;
grid-template-columns: auto 1fr auto;
align-items: center;
gap: 18px;
padding: 12px 15px;
border: 1px solid var(--line);
border-radius: 20px;
background: rgba(9, 16, 13, 0.88);
backdrop-filter: blur(22px);
-webkit-backdrop-filter: blur(22px);
box-shadow: var(--shadow);
}
.transport {
display: flex;
gap: 7px;
}
.icon-button {
width: 38px;
height: 38px;
padding: 0;
border-radius: 50%;
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.035);
color: #dce8df;
display: grid;
place-items: center;
cursor: pointer;
transition: all 160ms ease;
}
.icon-button:hover {
color: var(--lime);
border-color: rgba(215, 255, 114, 0.35);
background: rgba(215, 255, 114, 0.08);
}
.icon-button svg {
width: 14px;
height: 14px;
fill: currentColor;
}
.timeline {
min-width: 0;
}
.timeline-top {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 9px;
color: #a9b7ae;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.timeline-top strong {
color: var(--lime);
font-weight: 800;
}
.progress-bars {
display: grid;
grid-template-columns: repeat(8, 1fr);
gap: 5px;
}
.progress-segment {
height: 3px;
overflow: hidden;
border-radius: 99px;
background: rgba(213, 233, 220, 0.13);
}
.progress-segment span {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: var(--lime);
box-shadow: 0 0 9px rgba(215, 255, 114, 0.65);
}
.tour-clock {
min-width: 54px;
color: #d9e4dc;
font-variant-numeric: tabular-nums;
font-size: 11px;
text-align: right;
}
.tour-clock small {
display: block;
margin-top: 3px;
color: #65786c;
font-size: 8px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.world-label {
position: fixed;
z-index: 7;
pointer-events: none;
padding: 7px 10px;
border-radius: 9px;
border: 1px solid rgba(215, 255, 114, 0.35);
background: rgba(9, 17, 13, 0.82);
color: #eaf5e7;
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
transform: translate(-50%, -100%);
opacity: 0;
transition: opacity 180ms ease;
white-space: nowrap;
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -5px;
width: 8px;
height: 8px;
border-right: 1px solid rgba(215, 255, 114, 0.35);
border-bottom: 1px solid rgba(215, 255, 114, 0.35);
background: rgba(9, 17, 13, 0.82);
transform: translateX(-50%) rotate(45deg);
}
#boot {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
background: #0b1210;
transition: opacity 700ms ease, visibility 700ms ease;
}
#boot.out {
opacity: 0;
visibility: hidden;
}
.boot-inner {
text-align: center;
}
.boot-ring {
width: 50px;
height: 50px;
margin: 0 auto 18px;
border-radius: 50%;
border: 1px solid rgba(215, 255, 114, 0.18);
border-top-color: var(--lime);
animation: spin 1s linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
.boot-inner span {
color: #a8b7ad;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
@media (max-width: 980px) {
.route-panel {
display: none;
}
.map-panel {
width: 292px;
}
#mapSvg {
height: 165px;
}
}
@media (max-width: 650px) {
.topbar {
height: 64px;
padding: 0 14px;
}
.brand-subtitle,
.live-status {
display: none;
}
.glass-button {
padding: 0 12px;
font-size: 9px;
}
.map-panel {
top: 76px;
right: 12px;
width: 230px;
}
.map-header {
padding: 13px 14px 5px;
}
#mapSvg {
height: 132px;
}
.map-legend,
.current-card {
display: none;
}
.journey {
bottom: 12px;
width: calc(100vw - 24px);
gap: 10px;
padding: 10px;
}
.tour-clock {
display: none;
}
.journey {
grid-template-columns: auto 1fr;
}
.world-label {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="atmosphere"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div class="brand-copy">
<div class="brand-title">Gallery Atlas</div>
<div class="brand-subtitle">A guided architectural walk</div>
</div>
</div>
<div class="top-actions">
<div class="live-status">
<span class="live-dot"></span>
<span id="liveText">On route</span>
</div>
<button class="glass-button" id="overviewButton" type="button">Gallery view</button>
</div>
</header>
<aside class="panel route-panel">
<div class="route-intro">
<div class="eyebrow">Curated route · 08 stops</div>
<h1>Through the<br />quiet galleries.</h1>
<p>Follow the illuminated path from the entrance arch to the final exhibition hall.</p>
</div>
<nav class="route-list" id="routeList" aria-label="Gallery route"></nav>
<div class="route-footer">
<span>Open today</span>
<span>10:00 — 19:00</span>
</div>
</aside>
<aside class="panel map-panel">
<div class="map-header">
<strong>Live route</strong>
<span id="mapProgress">01 / 08</span>
</div>
<div class="map-wrap">
<svg id="mapSvg" viewBox="0 0 300 180" role="img" aria-label="Live gallery route map"></svg>
</div>
<div class="map-legend">
<span><i class="legend-line"></i> Unvisited</span>
<span><i class="legend-line lit"></i> Walked</span>
</div>
<section class="current-card" aria-live="polite">
<div class="current-top">
<span class="current-index" id="currentIndex">01</span>
<span class="current-wings" id="currentWings">South entrance</span>
</div>
<h2 id="currentTitle">Portal Arch</h2>
<p id="currentDescription">A suspended brass lintel marks the beginning of the collection.</p>
</section>
</aside>
<div class="world-label" id="worldLabel">01 · Portal Arch</div>
<section class="journey" aria-label="Tour controls">
<div class="transport">
<button class="icon-button" id="pauseButton" type="button" aria-label="Pause tour" title="Pause tour">
<svg id="pauseIcon" viewBox="0 0 24 24" aria-hidden="true">
<path d="M6 5h4v14H6zm8 0h4v14h-4z" />
</svg>
</button>
<button class="icon-button" id="replayButton" type="button" aria-label="Restart tour" title="Restart tour">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M12 5a7 7 0 1 1-6.65 4.84l1.86.78A5 5 0 1 0 8 7.27V10H3V5l3.09 3.09A6.96 6.96 0 0 1 12 5z" />
</svg>
</button>
</div>
<div class="timeline">
<div class="timeline-top">
<span id="timelineLabel">Approaching Portal Arch</span>
<strong id="timelinePercent">0%</strong>
</div>
<div class="progress-bars" id="progressBars"></div>
</div>
<div class="tour-clock">
<span id="tourClock">00:00</span>
<small>Walk time</small>
</div>
</section>
<div id="boot">
<div class="boot-inner">
<div class="boot-ring"></div>
<span>Preparing the gallery</span>
</div>
</div>
<noscript>This experience 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";
// -------------------------------------------------------------------------
// Data
// -------------------------------------------------------------------------
const routePoints = [
new THREE.Vector3(-42, 0, 16),
new THREE.Vector3(-24, 0, 16),
new THREE.Vector3(-24, 0, 0),
new THREE.Vector3(-8, 0, 0),
new THREE.Vector3(-8, 0, -18),
new THREE.Vector3(12, 0, -18),
new THREE.Vector3(12, 0, 12),
new THREE.Vector3(32, 0, 12),
new THREE.Vector3(32, 0, -8)
];
const stops = [
{
name: "Portal Arch",
type: "Threshold",
wings: "South entrance",
description: "A suspended brass lintel marks the beginning of the collection."
},
{
name: "Sculpture Court",
type: "Sculpture",
wings: "West garden",
description: "A woven bronze form turns slowly above a low stone plinth."
},
{
name: "Light Atrium",
type: "Installation",
wings: "Central atrium",
description: "A floating halo gathers the daylight from four slender columns."
},
{
name: "Archive Hall",
type: "Archive",
wings: "North wing",
description: "Geometric shelves preserve studies, editions, and small works on paper."
},
{
name: "Chromatic Room",
type: "Color study",
wings: "East annex",
description: "Saturated planes create a sequence of shifting, overlapping color fields."
},
{
name: "Moon Terrace",
type: "Sculpture",
wings: "Upper terrace",
description: "A pale sphere appears to hover above the garden in quiet suspension."
},
{
name: "Reflection Pool",
type: "Landscape",
wings: "Glass court",
description: "Still water doubles the evening sky and the geometry of the courtyard."
},
{
name: "Grand Gallery",
type: "Finale",
wings: "Main hall",
description: "The route concludes beneath a monumental colonnade and a field of warm light."
}
];
const $ = (selector) => document.querySelector(selector);
const routeList = $("#routeList");
const routeButtons = [];
const progressElements = [];
stops.forEach((stop, index) => {
const button = document.createElement("button");
button.className = "route-stop";
button.type = "button";
button.innerHTML = `
<span class="stop-number">${String(index + 1).padStart(2, "0")}</span>
<span class="stop-copy">
<span class="stop-name">${stop.name}</span>
<span class="stop-meta">${stop.type} · ${index % 2 ? "3" : "4"} min</span>
</span>
<span class="stop-arrow">›</span>
`;
button.addEventListener("click", () => previewStop(index));
routeList.appendChild(button);
routeButtons.push(button);
const segment = document.createElement("div");
segment.className = "progress-segment";
segment.innerHTML = "<span></span>";
$("#progressBars").appendChild(segment);
progressElements.push(segment.firstElementChild);
});
// -------------------------------------------------------------------------
// Three.js setup
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b1411);
scene.fog = new THREE.Fog(0x0b1411, 44, 112);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
180
);
const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: "high-performance" });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.1;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.id = "galleryCanvas";
$("#scene").appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xddeee4, 0x172019, 1.7);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff2d5, 2.8);
sun.position.set(-20, 42, 24);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -65;
sun.shadow.camera.right = 65;
sun.shadow.camera.top = 55;
sun.shadow.camera.bottom = -55;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 110;
sun.shadow.bias = -0.00025;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x79bfff, 1.1);
rimLight.position.set(38, 18, -35);
scene.add(rimLight);
const gallery = new THREE.Group();
scene.add(gallery);
const animated = {
rings: [],
sculptures: [],
panels: [],
beacons: [],
water: null,
portalGlow: null
};
const standard = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0.05,
...options
});
const materials = {
ground: standard(0x101a16, { roughness: 0.96 }),
stone: standard(0x34423b, { roughness: 0.88 }),
paleStone: standard(0x9ba69b, { roughness: 0.82 }),
darkStone: standard(0x1d2923, { roughness: 0.9 }),
bronze: standard(0xc59b55, { metalness: 0.62, roughness: 0.34 }),
coral: standard(0xe77f5d, { roughness: 0.58 }),
lime: standard(0xc9f16a, { emissive: 0x547817, emissiveIntensity: 0.42 }),
glow: new THREE.MeshBasicMaterial({ color: 0xd7ff72 }),
window: standard(0xffd995, {
emissive: 0xffc86d,
emissiveIntensity: 1.4,
roughness: 0.4
})
};
function addMesh(geometry, material, x = 0, y = 0, z = 0, parent = gallery) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBox(w, h, d, material, x, y, z, parent = gallery) {
return addMesh(new THREE.BoxGeometry(w, h, d), material, x, y, z, parent);
}
function addCylinder(rt, rb, h, material, x, y, z, parent = gallery, segments = 20) {
return addMesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
material,
x,
y,
z,
parent
);
}
// Ground and subtle architectural grid.
const ground = addMesh(
new THREE.PlaneGeometry(125, 92),
materials.ground,
0,
-0.08,
0
);
ground.rotation.x = -Math.PI / 2;
ground.castShadow = false;
const grid = new THREE.GridHelper(120, 40, 0x293b32, 0x1a2b23);
grid.position.y = -0.015;
grid.material.transparent = true;
grid.material.opacity = 0.24;
gallery.add(grid);
// Gallery plinths and perimeter walls.
addBox(15, 0.34, 13, materials.darkStone, -37, 0.06, 1);
addBox(15, 0.34, 13, materials.darkStone, -37, 0.06, -26);
addBox(24, 0.34, 15, materials.darkStone, 4, 0.06, -30);
addBox(25, 0.34, 18, materials.darkStone, 35, 0.06, -24);
addBox(23, 0.34, 20, materials.darkStone, 31, 0.06, 20);
// Background pavilions.
function addBuilding(x, z, w, d, h, color, windowRows = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
gallery.add(group);
const bodyMaterial = standard(color, { roughness: 0.86 });
addBox(w, h, d, bodyMaterial, 0, h / 2, 0, group);
addBox(w + 0.6, 0.45, d + 0.6, materials.darkStone, 0, h + 0.15, 0, group);
const columns = Math.max(2, Math.floor(w / 4));
for (let row = 0; row < windowRows; row++) {
for (let column = 0; column < columns; column++) {
const wx = -w / 2 + 2.2 + column * ((w - 4.4) / Math.max(1, columns - 1));
const wy = 2.4 + row * 3.1;
addBox(1.5, 1.25, 0.12, materials.window, wx, wy, d / 2 + 0.07, group);
}
}
return group;
}
addBuilding(-40, -10, 15, 17, 8, 0x25322c, 2);
addBuilding(-14, 28, 20, 11, 6, 0x2d3933, 1);
addBuilding(22, -34, 25, 11, 9, 0x202c27, 2);
addBuilding(48, -18, 13, 24, 7, 0x2a3731, 2);
addBuilding(48, 24, 16, 14, 5, 0x24312b, 1);
// -------------------------------------------------------------------------
// Route geometry
// -------------------------------------------------------------------------
const routeSegments = [];
for (let i = 0; i < routePoints.length - 1; i++) {
const a = routePoints[i];
const b = routePoints[i + 1];
const length = a.distanceTo(b);
const angle = -Math.atan2(b.z - a.z, b.x - a.x);
const baseGeometry = new THREE.BoxGeometry(length, 0.07, 2.25);
baseGeometry.translate(length / 2, 0, 0);
const base = new THREE.Mesh(
baseGeometry,
standard(0x27382f, {
roughness: 0.82,
emissive: 0x0d1712,
emissiveIntensity: 0.25
})
);
base.position.set(a.x, 0.055, a.z);
base.rotation.y = angle;
base.receiveShadow = true;
gallery.add(base);
const lightGeometry = new THREE.BoxGeometry(length, 0.045, 1.38);
lightGeometry.translate(length / 2, 0, 0);
const lightMaterial = new THREE.MeshBasicMaterial({
color: 0xd7ff72,
transparent: true,
opacity: 0.02,
depthWrite: false
});
const light = new THREE.Mesh(lightGeometry, lightMaterial);
light.position.set(a.x, 0.115, a.z);
light.rotation.y = angle;
light.scale.x = 0.001;
gallery.add(light);
const glowGeometry = new THREE.BoxGeometry(length, 0.018, 2.75);
glowGeometry.translate(length / 2, 0, 0);
const glowMaterial = new THREE.MeshBasicMaterial({
color: 0xbfff58,
transparent: true,
opacity: 0,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const glow = new THREE.Mesh(glowGeometry, glowMaterial);
glow.position.set(a.x, 0.105, a.z);
glow.rotation.y = angle;
glow.scale.x = 0.001;
gallery.add(glow);
routeSegments.push({
a,
b,
length,
angle,
light,
glow,
fill: 0
});
}
// -------------------------------------------------------------------------
// Landmarks
// -------------------------------------------------------------------------
// 01 — Portal Arch.
const portal = new THREE.Group();
portal.position.copy(routePoints[1]);
gallery.add(portal);
addBox(0.9, 4.8, 0.9, materials.paleStone, 0, 2.4, -3.1, portal);
addBox(0.9, 4.8, 0.9, materials.paleStone, 0, 2.4, 3.1, portal);
addBox(1.05, 0.75, 7.2, materials.darkStone, 0, 4.85, 0, portal);
const portalGlowMaterial = new THREE.MeshBasicMaterial({
color: 0xffd087,
transparent: true,
opacity: 0.9
});
const portalGlow = addBox(1.08, 0.11, 5.7, portalGlowMaterial, 0, 4.43, 0, portal);
animated.portalGlow = portalGlowMaterial;
const portalRing = addMesh(
new THREE.TorusGeometry(1.15, 0.08, 10, 48),
materials.bronze,
0,
2.9,
3.65,
portal
);
portalRing.rotation.y = Math.PI / 2;
// 02 — Sculpture Court.
const sculptureCourt = new THREE.Group();
sculptureCourt.position.set(-29, 0, 0);
gallery.add(sculptureCourt);
addBox(3.2, 0.55, 3.2, materials.paleStone, 0, 0.28, 0, sculptureCourt);
addBox(2.5, 0.85, 2.5, materials.darkStone, 0, 0.9, 0, sculptureCourt);
const knot = addMesh(
new THREE.TorusKnotGeometry(1.28, 0.3, 96, 14),
materials.coral,
0,
2.45,
0,
sculptureCourt
);
knot.rotation.set(0.35, 0.2, 0.1);
animated.sculptures.push(knot);
// 03 — Light Atrium.
const atrium = new THREE.Group();
atrium.position.set(-8, 0, -4.5);
gallery.add(atrium);
for (const x of [-3.1, 3.1]) {
for (const z of [-2.8, 2.8]) {
addCylinder(0.22, 0.28, 5.2, materials.paleStone, x, 2.6, z, atrium);
}
}
const atriumRing = addMesh(
new THREE.TorusGeometry(2.6, 0.16, 12, 80),
materials.glow,
0,
3.7,
0,
atrium
);
atriumRing.rotation.x = Math.PI / 2;
animated.rings.push(atriumRing);
const innerRing = addMesh(
new THREE.TorusGeometry(1.75, 0.055, 10, 64),
materials.bronze,
0,
3.7,
0,
atrium
);
innerRing.rotation.x = Math.PI / 2;
animated.rings.push(innerRing);
// 04 — Archive Hall.
const archive = new THREE.Group();
archive.position.set(-13, 0, -23);
gallery.add(archive);
addBox(12, 0.25, 8.5, materials.darkStone, 0, 0.12, 0, archive);
for (let shelf = 0; shelf < 4; shelf++) {
const x = -4.2 + shelf * 2.8;
addBox(1.65, 4.8, 0.65, materials.stone, x, 2.4, -1.4, archive);
addBox(1.85, 0.22, 1.15, materials.bronze, x, 4.65, -1.2, archive);
for (let book = 0; book < 5; book++) {
const bookMaterial = standard(
book % 2 ? 0x596e5e : 0x283d33,
{ roughness: 0.9 }
);
addBox(
0.19,
1.3 + (book % 3) * 0.25,
0.25,
bookMaterial,
x - 0.55 + book * 0.27,
1.2 + (book % 3) * 0.12,
-0.98,
archive
);
}
}
// 05 — Chromatic Room.
const chromatic = new THREE.Group();
chromatic.position.set(15, 0, -23);
gallery.add(chromatic);
const chromaColors = [0xff795f, 0xf7ca66, 0x78d8ff, 0x9ee49b, 0xb998f5];
chromaColors.forEach((color, index) => {
const panelMaterial = standard(color, {
roughness: 0.55,
emissive: color,
emissiveIntensity: 0.16
});
const panel = addBox(
2.2,
5.8,
0.28,
panelMaterial,
-4.4 + index * 2.2,
3.05,
0,
chromatic
);
panel.rotation.y = (index - 2) * 0.08;
animated.panels.push(panel);
});
// 06 — Moon Terrace.
const moon = new THREE.Group();
moon.position.set(6, 0, 13);
gallery.add(moon);
addCylinder(2.4, 2.8, 0.5, materials.paleStone, 0, 0.25, 0, moon, 32);
const moonSphere = addMesh(
new THREE.SphereGeometry(1.7, 36, 24),
standard(0xe7eee2, {
roughness: 0.5,
emissive: 0xb5c8bb,
emissiveIntensity: 0.42
}),
0,
3.25,
0,
moon
);
animated.sculptures.push(moonSphere);
const moonRing = addMesh(
new THREE.TorusGeometry(2.25, 0.055, 10, 72),
materials.bronze,
0,
3.25,
0,
moon
);
moonRing.rotation.x = Math.PI / 2;
animated.rings.push(moonRing);
// 07 — Reflection Pool.
const pool = new THREE.Group();
pool.position.set(38, 0, 12);
gallery.add(pool);
addBox(10, 0.38, 9.5, materials.paleStone, 0, 0.12, 0, pool);
const waterMaterial = new THREE.MeshPhysicalMaterial({
color: 0x4ea5bd,
roughness: 0.1,
metalness: 0.05,
transparent: true,
opacity: 0.76,
clearcoat: 1,
clearcoatRoughness: 0.12,
side: THREE.DoubleSide
});
const water = addBox(8.5, 0.04, 8, waterMaterial, 0, 0.35, 0, pool);
animated.water = water;
for (const x of [-4.7, 4.7]) {
addBox(0.25, 0.4, 9.5, materials.bronze, x, 0.4, 0, pool);
}
// 08 — Grand Gallery.
const grand = new THREE.Group();
grand.position.set(32, 0, -15);
gallery.add(grand);
addBox(18, 0.4, 12, materials.paleStone, 0, 0.2, 0, grand);
for (let column = 0; column < 6; column++) {
const x = -7.2 + column * 2.88;
addCylinder(0.48, 0.58, 6.8, materials.paleStone, x, 3.6, 1.6, grand, 24);
addBox(1.35, 0.3, 1.35, materials.bronze, x, 0.58, 1.6, grand);
addBox(1.4, 0.38, 1.4, materials.paleStone, x, 7.05, 1.6, grand);
}
addBox(19, 0.8, 2.2, materials.darkStone, 0, 7.45, 1.6, grand);
addBox(16.8, 0.1, 1.1, materials.glow, 0, 6.9, 1.6, grand);
// -------------------------------------------------------------------------
// Landscaping and atmospheric details
// -------------------------------------------------------------------------
let seed = 93741;
function random() {
seed |= 0;
seed = (seed + 0x6d2b79f5) | 0;
let value = Math.imul(seed ^ (seed >>> 15), 1 | seed);
value = (value + Math.imul(value ^ (value >>> 7), 61 | value)) ^ value;
return ((value ^ (value >>> 14)) >>> 0) / 4294967296;
}
const foliageMaterials = [
standard(0x244237, { roughness: 1 }),
standard(0x2f5140, { roughness: 1 }),
standard(0x19372d, { roughness: 1 })
];
function addTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
gallery.add(group);
addCylinder(0.16, 0.25, 2.5, materials.darkStone, 0, 1.25, 0, group, 9);
const crown = addMesh(
new THREE.IcosahedronGeometry(1.45, 1),
foliageMaterials[Math.floor(random() * foliageMaterials.length)],
0,
3.15,
0,
group
);
crown.scale.y = 1.18;
}
const treePositions = [
[-49, 27], [-48, 6], [-48, -15], [-37, -34], [-30, 28],
[-16, 24], [-16, -37], [0, 28], [3, -40], [18, -39],
[28, -34], [47, -36], [50, -8], [50, 2], [49, 26],
[42, 27], [23, 26], [-37, 28], [17, 28], [-3, -38]
];
treePositions.forEach(([x, z], index) => {
addTree(x, z, 0.72 + random() * 0.42);
});
const dustGeometry = new THREE.BufferGeometry();
const dustCount = 220;
const dustPositions = new Float32Array(dustCount * 3);
for (let i = 0; i < dustCount; i++) {
dustPositions[i * 3] = -60 + random() * 120;
dustPositions[i * 3 + 1] = 1 + random() * 17;
dustPositions[i * 3 + 2] = -43 + random() * 86;
}
dustGeometry.setAttribute("position", new THREE.BufferAttribute(dustPositions, 3));
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xd8e8d7,
size: 0.075,
transparent: true,
opacity: 0.36,
depthWrite: false
})
);
scene.add(dust);
// Stop beacons.
for (let i = 1; i < routePoints.length; i++) {
const beacon = new THREE.Group();
beacon.position.copy(routePoints[i]);
gallery.add(beacon);
const ring = addMesh(
new THREE.TorusGeometry(0.52, 0.045, 8, 42),
materials.glow,
0,
0.18,
0,
beacon
);
ring.rotation.x = Math.PI / 2;
const diamond = addMesh(
new THREE.OctahedronGeometry(0.2, 0),
materials.glow,
0,
1.15,
0,
beacon
);
const beaconLight = new THREE.PointLight(0xd7ff72, 0.55, 4.5, 2);
beaconLight.position.y = 0.8;
beacon.add(beaconLight);
animated.beacons.push({ ring, diamond, light: beaconLight, phase: i * 0.7 });
}
// -------------------------------------------------------------------------
// Visitor
// -------------------------------------------------------------------------
const visitor = new THREE.Group();
gallery.add(visitor);
const visitorShadow = addMesh(
new THREE.CircleGeometry(0.62, 32),
new THREE.MeshBasicMaterial({
color: 0x07100a,
transparent: true,
opacity: 0.38,
depthWrite: false
}),
0,
0.015,
0,
visitor
);
visitorShadow.rotation.x = -Math.PI / 2;
const visitorRing = addMesh(
new THREE.TorusGeometry(0.78, 0.045, 8, 48),
materials.glow,
0,
0.12,
0,
visitor
);
visitorRing.rotation.x = Math.PI / 2;
const legsMaterial = standard(0x24322b);
addCylinder(0.12, 0.14, 0.55, legsMaterial, -0.15, 0.38, 0, visitor, 12);
addCylinder(0.12, 0.14, 0.55, legsMaterial, 0.15, 0.38, 0, visitor, 12);
const body = addMesh(
new THREE.CapsuleGeometry(0.31, 0.62, 5, 12),
materials.coral,
0,
0.98,
0,
visitor
);
body.scale.z = 0.76;
addMesh(
new THREE.SphereGeometry(0.29, 20, 16),
standard(0xefe7d7, { roughness: 0.72 }),
0,
1.65,
0,
visitor
);
addBox(0.42, 0.58, 0.24, materials.lime, 0, 1.02, -0.3, visitor);
const visitorLight = new THREE.PointLight(0xffb07e, 1.25, 6, 2);
visitorLight.position.set(0, 1.2, 0);
visitor.add(visitorLight);
visitor.position.copy(routePoints[0]);
// A small trail of luminous points.
const trailCount = 30;
const trailArray = new Float32Array(trailCount * 3);
for (let i = 0; i < trailCount; i++) {
trailArray[i * 3] = routePoints[0].x;
trailArray[i * 3 + 1] = 0.15;
trailArray[i * 3 + 2] = routePoints[0].z;
}
const trailGeometry = new THREE.BufferGeometry();
trailGeometry.setAttribute("position", new THREE.BufferAttribute(trailArray, 3));
const trail = new THREE.Points(
trailGeometry,
new THREE.PointsMaterial({
color: 0xd7ff72,
size: 0.11,
transparent: true,
opacity: 0.65,
depthWrite: false
})
);
scene.add(trail);
// -------------------------------------------------------------------------
// Synchronized SVG map
// -------------------------------------------------------------------------
const svg = $("#mapSvg");
const NS = "http://www.w3.org/2000/svg";
const mapLines = [];
const mapStopElements = [];
function mapCoordinate(point) {
return {
x: 30 + ((point.x + 42) / 74) * 240,
y: 25 + ((point.z + 18) / 34) * 125
};
}
for (let x = 20; x < 300; x += 28) {
const line = document.createElementNS(NS, "line");
line.setAttribute("x1", x);
line.setAttribute("x2", x);
line.setAttribute("y1", 10);
line.setAttribute("y2", 170);
line.setAttribute("class", "map-grid");
svg.appendChild(line);
}
for (let y = 12; y < 180; y += 26) {
const line = document.createElementNS(NS, "line");
line.setAttribute("x1", 10);
line.setAttribute("x2", 290);
line.setAttribute("y1", y);
line.setAttribute("y2", y);
line.setAttribute("class", "map-grid");
svg.appendChild(line);
}
for (let i = 0; i < routeSegments.length; i++) {
const segment = routeSegments[i];
const a = mapCoordinate(segment.a);
const b = mapCoordinate(segment.b);
const base = document.createElementNS(NS, "line");
base.setAttribute("x1", a.x);
base.setAttribute("y1", a.y);
base.setAttribute("x2", b.x);
base.setAttribute("y2", b.y);
base.setAttribute("class", "map-base");
svg.appendChild(base);
const live = document.createElementNS(NS, "line");
live.setAttribute("x1", a.x);
live.setAttribute("y1", a.y);
live.setAttribute("x2", b.x);
live.setAttribute("y2", b.y);
live.setAttribute("class", "map-live");
svg.appendChild(live);
mapLines.push({ live, length: live.getTotalLength() });
}
for (let i = 1; i < routePoints.length; i++) {
const point = mapCoordinate(routePoints[i]);
const circle = document.createElementNS(NS, "circle");
circle.setAttribute("cx", point.x);
circle.setAttribute("cy", point.y);
circle.setAttribute("r", "8");
circle.setAttribute("class", "map-stop");
svg.appendChild(circle);
const label = document.createElementNS(NS, "text");
label.setAttribute("x", point.x);
label.setAttribute("y", point.y);
label.setAttribute("class", "map-stop-label");
label.textContent = String(i);
svg.appendChild(label);
mapStopElements.push({ circle, label });
}
// -------------------------------------------------------------------------
// Timeline and state
// -------------------------------------------------------------------------
const timeline = {
segment: 0,
phase: "move",
segmentTime: 0,
dwellTime: 0,
elapsed: 0,
paused: false,
complete: false
};
const totalDuration = routeSegments.reduce(
(sum, segment) => sum + segmentDuration(segment),
0
) + stops.length * 0.75;
function segmentDuration(segment) {
return 2.5 + segment.length * 0.035;
}
function easeInOutCubic(value) {
return value < 0.5
? 4 * value * value * value
: 1 - Math.pow(-2 * value + 2, 3) / 2;
}
function formatTime(seconds) {
const minutes = Math.floor(seconds / 60);
const remainder = Math.floor(seconds % 60);
return `${String(minutes).padStart(2, "0")}:${String(remainder).padStart(2, "0")}`;
}
function updateCurrentCard() {
const index = Math.min(timeline.segment, stops.length - 1);
const stop = stops[index];
$("#currentIndex").textContent = String(index + 1).padStart(2, "0");
$("#currentTitle").textContent = timeline.complete ? "Walk complete" : stop.name;
$("#currentWings").textContent = timeline.complete ? "All galleries" : stop.wings;
$("#currentDescription").textContent = timeline.complete
? "You have reached the Grand Gallery. The full route is now illuminated."
: stop.description;
}
function updateMapAndWorld() {
routeSegments.forEach((segment, index) => {
const fill = segment.fill;
segment.light.scale.x = Math.max(0.001, fill);
segment.glow.scale.x = Math.max(0.001, fill);
segment.light.material.opacity = 0.04 + fill * 0.85;
segment.glow.material.opacity = fill * 0.13;
const map = mapLines[index];
map.live.style.strokeDasharray = `${map.length * fill} ${map.length + 1}`;
map.live.style.opacity = fill > 0 ? "1" : "0";
progressElements[index].style.width = `${fill * 100}%`;
});
mapStopElements.forEach((item, index) => {
item.circle.classList.toggle("active", index === timeline.segment && !timeline.complete);
item.circle.classList.toggle("completed", index < timeline.segment || timeline.complete);
});
routeButtons.forEach((button, index) => {
button.classList.toggle("active", index === timeline.segment && !timeline.complete);
button.classList.toggle("completed", index < timeline.segment || timeline.complete);
});
const stopIndex = Math.min(timeline.segment, stops.length - 1);
const completedCount = timeline.complete ? stops.length : timeline.segment;
const percent = Math.round((completedCount / stops.length) * 100);
$("#mapProgress").textContent = `${String(completedCount).padStart(2, "0")} / 08`;
$("#timelinePercent").textContent = `${percent}%`;
$("#timelineLabel").textContent = timeline.complete
? "Gallery walk complete"
: `Approaching ${stops[stopIndex].name}`;
$("#tourClock").textContent = formatTime(timeline.elapsed);
$("#liveText").textContent = timeline.complete
? "Tour complete"
: timeline.paused
? "Paused"
: "On route";
}
function resetTour() {
timeline.segment = 0;
timeline.phase = "move";
timeline.segmentTime = 0;
timeline.dwellTime = 0;
timeline.elapsed = 0;
timeline.paused = false;
timeline.complete = false;
routeSegments.forEach((segment) => {
segment.fill = 0;
});
visitor.position.copy(routePoints[0]);
visitor.rotation.y = 0;
for (let i = 0; i < trailCount; i++) {
trailArray[i * 3] = routePoints[0].x;
trailArray[i * 3 + 1] = 0.15;
trailArray[i * 3 + 2] = routePoints[0].z;
}
$("#pauseIcon").innerHTML = '<path d="M6 5h4v14H6zm8 0h4v14h-4z" />';
$("#pauseButton").setAttribute("aria-label", "Pause tour");
updateCurrentCard();
updateMapAndWorld();
}
function updateTimeline(dt) {
if (timeline.paused || timeline.complete) return;
timeline.elapsed += dt;
if (timeline.phase === "move") {
const segment = routeSegments[timeline.segment];
const duration = segmentDuration(segment);
timeline.segmentTime += dt;
const raw = Math.min(1, timeline.segmentTime / duration);
const eased = easeInOutCubic(raw);
segment.fill = eased;
visitor.position.lerpVectors(segment.a, segment.b, eased);
const direction = segment.b.clone().sub(segment.a);
visitor.rotation.y = -Math.atan2(direction.z, direction.x);
if (raw >= 1) {
segment.fill = 1;
timeline.segment += 1;
if (timeline.segment >= routeSegments.length) {
timeline.complete = true;
timeline.segment = stops.length - 1;
updateCurrentCard();
} else {
timeline.phase = "dwell";
timeline.dwellTime = 0;
updateCurrentCard();
}
}
} else if (timeline.phase === "dwell") {
timeline.dwellTime += dt;
if (timeline.dwellTime >= 0.75) {
timeline.phase = "move";
timeline.segmentTime = 0;
}
}
updateMapAndWorld();
}
// -------------------------------------------------------------------------
// Custom camera controls
// -------------------------------------------------------------------------
const cameraState = {
yaw: 0.68,
pitch: 0.62,
distance: 28,
mode: "follow",
focusedStop: null
};
const cameraTarget = new THREE.Vector3().copy(routePoints[0]);
const desiredTarget = new THREE.Vector3();
const desiredCamera = new THREE.Vector3();
const lookAhead = new THREE.Vector3(1, 0, 0);
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.004,
0.32,
1.18
);
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
if (cameraState.mode === "overview") {
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance + event.deltaY * 0.035,
48,
105
);
} else if (cameraState.mode === "stop") {
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance + event.deltaY * 0.02,
11,
30
);
} else {
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance + event.deltaY * 0.015,
13,
46
);
}
},
{ passive: false }
);
function updateCamera(dt) {
if (cameraState.mode === "overview") {
desiredTarget.set(-3, 0.5, -2);
} else if (cameraState.mode === "stop" && cameraState.focusedStop !== null) {
desiredTarget.copy(routePoints[cameraState.focusedStop + 1]);
desiredTarget.y = 1.5;
} else {
const segment = routeSegments[Math.min(timeline.segment, routeSegments.length - 1)];
lookAhead.copy(segment.b).sub(segment.a).normalize();
desiredTarget.copy(visitor.position);
desiredTarget.y = 1.1;
desiredTarget.addScaledVector(lookAhead, 2.8);
}
const horizontalDistance = Math.cos(cameraState.pitch) * cameraState.distance;
desiredCamera.set(
desiredTarget.x + Math.sin(cameraState.yaw) * horizontalDistance,
desiredTarget.y + Math.sin(cameraState.pitch) * cameraState.distance,
desiredTarget.z + Math.cos(cameraState.yaw) * horizontalDistance
);
const damping = 1 - Math.exp(-dt * 4.3);
cameraTarget.lerp(desiredTarget, damping);
camera.position.lerp(desiredCamera, damping);
camera.lookAt(cameraTarget);
}
function previewStop(index) {
cameraState.mode = "stop";
cameraState.focusedStop = index;
cameraState.distance = 17;
$("#overviewButton").textContent = "Follow visitor";
}
$("#overviewButton").addEventListener("click", () => {
if (cameraState.mode === "overview") {
cameraState.mode = "follow";
cameraState.focusedStop = null;
$("#overviewButton").textContent = "Gallery view";
} else {
cameraState.mode = "overview";
cameraState.focusedStop = null;
cameraState.distance = 76;
$("#overviewButton").textContent = "Follow visitor";
}
});
$("#pauseButton").addEventListener("click", () => {
timeline.paused = !timeline.paused;
if (timeline.paused) {
$("#pauseIcon").innerHTML = '<path d="M8 5v14l11-7z" />';
$("#pauseButton").setAttribute("aria-label", "Resume tour");
} else {
$("#pauseIcon").innerHTML = '<path d="M6 5h4v14H6zm8 0h4v14h-4z" />';
$("#pauseButton").setAttribute("aria-label", "Pause tour");
}
updateMapAndWorld();
});
$("#replayButton").addEventListener("click", resetTour);
// -------------------------------------------------------------------------
// Projection labels and animation loop
// -------------------------------------------------------------------------
const worldLabel = $("#worldLabel");
const projected = new THREE.Vector3();
function updateWorldLabel() {
const index = Math.min(timeline.segment, stops.length - 1);
const anchor = routePoints[index + 1].clone();
anchor.y = 3.0;
projected.copy(anchor).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.1 &&
Math.abs(projected.y) < 1.1;
if (!visible) {
worldLabel.style.opacity = "0";
return;
}
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
worldLabel.style.left = `${x}px`;
worldLabel.style.top = `${y}px`;
worldLabel.style.opacity = timeline.complete ? "0" : "0.92";
worldLabel.textContent = `${String(index + 1).padStart(2, "0")} · ${stops[index].name}`;
}
function updateTrail() {
for (let i = trailCount - 1; i > 0; i--) {
trailArray[i * 3] = trailArray[(i - 1) * 3];
trailArray[i * 3 + 1] = trailArray[(i - 1) * 3 + 1];
trailArray[i * 3 + 2] = trailArray[(i - 1) * 3 + 2];
}
trailArray[0] = visitor.position.x;
trailArray[1] = 0.15;
trailArray[2] = visitor.position.z;
trailGeometry.attributes.position.needsUpdate = true;
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateTimeline(dt);
updateCamera(dt);
updateTrail();
animated.rings.forEach((ring, index) => {
ring.rotation.z = elapsed * (0.08 + index * 0.025);
ring.rotation.y = Math.sin(elapsed * 0.25 + index) * 0.15;
});
animated.sculptures.forEach((sculpture, index) => {
sculpture.rotation.y = elapsed * (0.2 + index * 0.035);
sculpture.position.y =
(index === 0 ? 2.45 : 3.25) + Math.sin(elapsed * 0.8 + index) * 0.09;
});
animated.panels.forEach((panel, index) => {
panel.position.y = 3.05 + Math.sin(elapsed * 0.8 + index * 0.7) * 0.08;
});
animated.beacons.forEach((beacon) => {
beacon.diamond.rotation.y = elapsed * 0.8;
beacon.diamond.position.y = 1.15 + Math.sin(elapsed * 1.8 + beacon.phase) * 0.12;
beacon.ring.material.opacity = 0.65 + Math.sin(elapsed * 2 + beacon.phase) * 0.2;
beacon.light.intensity = 0.35 + Math.sin(elapsed * 2 + beacon.phase) * 0.15;
});
if (animated.portalGlow) {
animated.portalGlow.opacity = 0.72 + Math.sin(elapsed * 1.4) * 0.18;
}
if (animated.water) {
animated.water.material.opacity = 0.72 + Math.sin(elapsed * 0.7) * 0.04;
}
dust.rotation.y = elapsed * 0.006;
updateWorldLabel();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
$("#boot").classList.add("out");
}
}
resetTour();
animate();
</script>
</body>
</html>
```