Prompt specification
Build or customize the Three.js 3D scene "Compare mountain relay stages under a closure" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Compare mountain relay stages under a closure
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/compare-mountain-relay-stages-under-a-closure-x2364
Scene Description Prompt:
Close a fictional bridge in an Inca-inspired low-poly mountain relay network; reroute messages and show added stages. Three.js from cdnjs, standalone HTML.
Working Three.js Starter (compare-mountain-relay-stages-under-a-closure-x2364):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Q'esuak Relay — Mountain Network</title>
<style>
:root {
--ink: #10241f;
--muted: #60756d;
--paper: rgba(244, 239, 221, 0.94);
--line: rgba(22, 57, 47, 0.14);
--teal: #087f70;
--mint: #65ddbd;
--gold: #e8a735;
--orange: #ec6e38;
--red: #d8493f;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #aec4b2;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#app,
#app canvas,
#labels {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#app canvas {
display: block;
touch-action: none;
}
#labels {
pointer-events: none;
overflow: hidden;
z-index: 2;
}
.world-label {
position: absolute;
left: 0;
top: 0;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 9px 6px 6px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 7px;
background: rgba(244, 239, 221, 0.91);
box-shadow: 0 7px 22px rgba(12, 39, 31, 0.17);
color: var(--ink);
white-space: nowrap;
transform: translate(-50%, -100%);
transition: opacity 160ms ease, background 160ms ease;
backdrop-filter: blur(6px);
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 12px;
background: rgba(22, 57, 47, 0.42);
}
.world-label .label-index {
display: grid;
place-items: center;
min-width: 23px;
height: 23px;
padding: 0 5px;
border-radius: 5px;
background: var(--teal);
color: #f6f1df;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.world-label .label-name {
font: 800 10px/1.1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.07em;
}
.world-label.added {
background: rgba(255, 235, 180, 0.95);
border-color: rgba(232, 167, 53, 0.55);
}
.world-label.added .label-index {
background: var(--gold);
color: #3f2a0b;
}
.world-label.bridge {
background: rgba(14, 42, 34, 0.9);
color: #f8f2dd;
border-color: rgba(255, 255, 255, 0.2);
}
.world-label.bridge .label-index {
background: var(--gold);
color: #3f2a0b;
}
.world-label.bridge.closed {
background: rgba(112, 31, 25, 0.94);
}
.world-label.bridge.closed .label-index {
background: #f16b5e;
}
#topbar {
position: fixed;
z-index: 4;
top: 18px;
left: 20px;
right: 20px;
display: flex;
align-items: center;
justify-content: space-between;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
color: #f6f0dc;
text-shadow: 0 2px 15px rgba(10, 35, 28, 0.3);
}
.brand-mark {
position: relative;
width: 38px;
height: 38px;
border: 2px solid rgba(246, 240, 220, 0.9);
transform: rotate(45deg);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
inset: 7px;
border: 1px solid rgba(246, 240, 220, 0.75);
}
.brand-mark::after {
inset: 13px;
background: var(--gold);
border: 0;
}
.brand strong {
display: block;
font: 900 13px/1.1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.13em;
}
.brand small {
display: block;
margin-top: 4px;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.18em;
opacity: 0.75;
}
.scenario-tag {
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.35);
border-radius: 999px;
background: rgba(18, 48, 39, 0.45);
color: #f8f1da;
font: 800 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.14em;
backdrop-filter: blur(8px);
}
#panel {
position: fixed;
z-index: 5;
top: 84px;
left: 20px;
width: min(348px, calc(100vw - 40px));
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 16px;
background: var(--paper);
box-shadow: 0 24px 70px rgba(15, 47, 37, 0.24);
backdrop-filter: blur(14px);
}
.panel-inner {
padding: 24px;
}
.eyebrow {
margin: 0 0 10px;
color: var(--teal);
font: 900 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
max-width: 290px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 4vw, 42px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.intro {
margin: 14px 0 19px;
color: #50645c;
font-size: 13px;
line-height: 1.55;
}
.status-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 13px 0;
border-top: 1px solid var(--line);
border-bottom: 1px solid var(--line);
}
.status-copy {
display: flex;
align-items: center;
gap: 9px;
min-width: 0;
}
.status-dot {
flex: 0 0 auto;
width: 9px;
height: 9px;
border-radius: 50%;
background: #36b68e;
box-shadow: 0 0 0 5px rgba(54, 182, 142, 0.13);
}
.status-dot.closed {
background: var(--red);
box-shadow: 0 0 0 5px rgba(216, 73, 63, 0.14);
}
.status-dot.pending {
background: var(--gold);
box-shadow: 0 0 0 5px rgba(232, 167, 53, 0.15);
animation: pulse 800ms ease-in-out infinite alternate;
}
@keyframes pulse {
to {
opacity: 0.4;
transform: scale(0.8);
}
}
.status-copy strong {
display: block;
font: 900 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
}
.status-copy small {
display: block;
margin-top: 3px;
overflow: hidden;
color: var(--muted);
font-size: 10px;
text-overflow: ellipsis;
white-space: nowrap;
}
.eta {
flex: 0 0 auto;
text-align: right;
}
.eta strong {
display: block;
font: 900 18px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.eta small {
color: var(--muted);
font: 700 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin: 16px 0;
}
.metric {
padding: 10px 9px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.32);
}
.metric strong {
display: block;
font: 900 15px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.metric span {
display: block;
margin-top: 5px;
color: var(--muted);
font: 800 7px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.primary {
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 14px 15px;
border: 0;
border-radius: 10px;
background: var(--ink);
color: #f8f2dd;
cursor: pointer;
box-shadow: 0 8px 20px rgba(16, 36, 31, 0.16);
transition: transform 150ms ease, background 150ms ease, opacity 150ms ease;
}
.primary:hover {
background: #1a3e33;
transform: translateY(-1px);
}
.primary:disabled {
cursor: wait;
opacity: 0.65;
transform: none;
}
.primary strong {
font: 900 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.04em;
}
.button-arrow {
display: grid;
place-items: center;
width: 24px;
height: 24px;
border-radius: 50%;
background: var(--gold);
color: #382709;
font-size: 15px;
}
.secondary-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 8px;
}
.secondary {
min-height: 38px;
padding: 9px 8px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255, 255, 255, 0.28);
color: #385048;
cursor: pointer;
font: 800 8px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.04em;
transition: background 150ms ease, border 150ms ease;
}
.secondary:hover:not(:disabled) {
border-color: rgba(8, 127, 112, 0.45);
background: rgba(101, 221, 189, 0.12);
}
.secondary:disabled {
cursor: not-allowed;
opacity: 0.4;
}
.closure-steps {
display: grid;
gap: 8px;
margin: 18px 0 0;
padding: 16px 0 0;
border-top: 1px solid var(--line);
list-style: none;
}
.closure-steps li {
display: grid;
grid-template-columns: 18px 1fr;
align-items: center;
gap: 9px;
color: #71817b;
font: 800 8px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.step-marker {
display: grid;
place-items: center;
width: 18px;
height: 18px;
border: 1px solid #b8c1b9;
border-radius: 50%;
font-size: 9px;
}
.closure-steps li.active {
color: #896319;
}
.closure-steps li.active .step-marker {
border-color: var(--gold);
background: #f4cd76;
color: #5b3d08;
}
.closure-steps li.done {
color: var(--teal);
}
.closure-steps li.done .step-marker {
border-color: var(--teal);
background: var(--teal);
color: white;
}
#route-note {
min-height: 38px;
margin: 15px 0 0;
color: #52665e;
font-size: 11px;
line-height: 1.5;
}
#legend {
position: fixed;
z-index: 4;
right: 20px;
bottom: 20px;
width: 205px;
padding: 15px 16px;
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 12px;
background: rgba(20, 49, 40, 0.74);
color: #f6f0dc;
box-shadow: 0 12px 35px rgba(15, 40, 32, 0.18);
backdrop-filter: blur(10px);
}
.legend-title {
margin-bottom: 11px;
color: rgba(246, 240, 220, 0.65);
font: 800 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin-top: 8px;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.05em;
}
.legend-line {
width: 24px;
height: 3px;
border-radius: 4px;
background: var(--mint);
}
.legend-line.detour {
background: var(--gold);
}
.legend-line.closed {
background: #ff6759;
}
#help {
position: fixed;
z-index: 4;
left: 50%;
bottom: 22px;
transform: translateX(-50%);
padding: 9px 13px;
border: 1px solid rgba(255, 255, 255, 0.38);
border-radius: 999px;
background: rgba(17, 47, 38, 0.55);
color: rgba(248, 242, 221, 0.83);
font: 700 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(8px);
pointer-events: none;
}
#reset-view {
position: fixed;
z-index: 5;
top: 82px;
right: 20px;
width: 38px;
height: 38px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 50%;
background: rgba(20, 49, 40, 0.65);
color: #f6f0dc;
cursor: pointer;
backdrop-filter: blur(8px);
}
#toast {
position: fixed;
z-index: 8;
left: 50%;
top: 24px;
max-width: min(420px, calc(100vw - 30px));
padding: 11px 16px;
border: 1px solid rgba(255, 255, 255, 0.45);
border-radius: 999px;
background: rgba(15, 43, 35, 0.92);
color: #f8f1da;
box-shadow: 0 12px 35px rgba(12, 33, 27, 0.24);
font: 800 9px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.04em;
text-align: center;
opacity: 0;
pointer-events: none;
transform: translate(-50%, -15px);
transition: opacity 220ms ease, transform 220ms ease;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #aec4b2;
color: #163a30;
transition: opacity 500ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
.loading-mark {
width: 34px;
height: 34px;
margin: 0 auto 15px;
border: 2px solid rgba(22, 58, 48, 0.3);
border-top-color: var(--teal);
border-radius: 50%;
animation: spin 900ms linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
#loading p {
font: 900 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.16em;
text-transform: uppercase;
}
@media (max-width: 720px) {
#topbar {
top: 12px;
left: 12px;
right: 12px;
}
.scenario-tag {
display: none;
}
#panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 48vh;
overflow-y: auto;
}
.panel-inner {
padding: 18px;
}
h1 {
max-width: none;
font-size: 30px;
}
.intro {
margin: 10px 0 13px;
}
.closure-steps,
#legend,
#help {
display: none;
}
#route-note {
margin-top: 10px;
}
.metrics {
margin: 12px 0;
}
.world-label:not(.bridge):not(.added) {
display: none;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div id="labels"></div>
<header id="topbar">
<div class="brand">
<div class="brand-mark"></div>
<div>
<strong>CHAKRA RELAY</strong>
<small>MOUNTAIN MESSAGE NETWORK</small>
</div>
</div>
<div class="scenario-tag">SCENARIO 07 · ALPINE SECTOR</div>
</header>
<aside id="panel" aria-label="Bridge closure controls">
<div class="panel-inner">
<p class="eyebrow">Fictional infrastructure / Live simulation</p>
<h1>The broken crossing</h1>
<p class="intro">
Close Q'esuak Bridge and redirect the mountain couriers through the
southern terraces.
</p>
<div class="status-row">
<div class="status-copy">
<span id="status-dot" class="status-dot"></span>
<div>
<strong id="status-title">BRIDGE OPEN</strong>
<small id="status-detail">3 couriers moving normally</small>
</div>
</div>
<div class="eta">
<strong id="eta-value">48s</strong>
<small>Transit ETA</small>
</div>
</div>
<div class="metrics">
<div class="metric">
<strong>03</strong>
<span>Couriers</span>
</div>
<div class="metric">
<strong id="station-count">05</strong>
<span>Base stages</span>
</div>
<div class="metric">
<strong id="added-count">+00</strong>
<span>Added stages</span>
</div>
</div>
<button id="action-button" class="primary">
<strong id="action-text">CLOSE BRIDGE & REROUTE</strong>
<span class="button-arrow">→</span>
</button>
<div class="secondary-row">
<button id="overlay-button" class="secondary" disabled>
SHOW ADDED STAGES
</button>
<button id="replay-button" class="secondary">
REPLAY COURIERS
</button>
</div>
<ol class="closure-steps">
<li id="step-gate">
<span class="step-marker">1</span>
<span>Lower the bridge barriers</span>
</li>
<li id="step-divert">
<span class="step-marker">2</span>
<span>Hold couriers at Waq Wasi</span>
</li>
<li id="step-reveal">
<span class="step-marker">3</span>
<span>Open the three-stage detour</span>
</li>
</ol>
<p id="route-note" aria-live="polite">
The original northern route uses the suspended bridge and five relay stages.
</p>
</div>
</aside>
<button id="reset-view" title="Reset camera" aria-label="Reset camera">↺</button>
<div id="legend">
<div class="legend-title">Route key</div>
<div class="legend-row"><span class="legend-line"></span>Original relay</div>
<div class="legend-row"><span class="legend-line detour"></span>Southern detour</div>
<div class="legend-row"><span class="legend-line closed"></span>Closed crossing</div>
</div>
<div id="help">Drag to orbit · Scroll to zoom · Click bridge to close</div>
<div id="toast" role="status"></div>
<div id="loading">
<div>
<div class="loading-mark"></div>
<p>Surveying the relay network</p>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Core scene
// ------------------------------------------------------------
const app = document.querySelector("#app");
const labelsLayer = document.querySelector("#labels");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xaec4b2);
scene.fog = new THREE.Fog(0xaec4b2, 38, 83);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
160
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
app.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xd9eadb, 0x4f4934, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe5af, 3.2);
sun.position.set(-18, 28, 16);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -34;
sun.shadow.camera.right = 34;
sun.shadow.camera.top = 30;
sun.shadow.camera.bottom = -30;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 80;
sun.shadow.bias = -0.0006;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x9ecfc9, 0.75);
rim.position.set(20, 12, -24);
scene.add(rim);
// Deterministic random so the scene is stable between reloads.
let randomSeed = 872341;
function random() {
randomSeed =
(randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
// ------------------------------------------------------------
// Low-poly terrain and terrain helpers
// ------------------------------------------------------------
function terrainHeight(x, z) {
const roll = 0.42 * Math.sin(x * 0.31) * Math.cos(z * 0.27);
const westPeak =
7.0 * Math.exp(-((x + 13) ** 2 / 95 + (z - 8) ** 2 / 55));
const eastPeak =
8.0 * Math.exp(-((x - 13) ** 2 / 90 + (z + 6) ** 2 / 70));
const westCliff =
3.8 * Math.exp(-((x + 5) ** 2 / 20 + z ** 2 / 32));
const eastCliff =
3.9 * Math.exp(-((x - 5) ** 2 / 22 + (z + 1) ** 2 / 38));
const gorge =
2.5 * Math.exp(-(x ** 2 / 8 + z ** 2 / 25));
return -1.1 + roll + westPeak + eastPeak + westCliff + eastCliff - gorge;
}
const terrainSource = new THREE.PlaneGeometry(56, 42, 44, 32);
terrainSource.rotateX(-Math.PI / 2);
const terrainPositions = terrainSource.attributes.position;
for (let i = 0; i < terrainPositions.count; i++) {
const x = terrainPositions.getX(i);
const z = terrainPositions.getZ(i);
terrainPositions.setY(i, terrainHeight(x, z));
}
const terrainGeometry = terrainSource.toNonIndexed();
terrainSource.dispose();
const terrainColors = [];
const position = terrainGeometry.attributes.position;
const color = new THREE.Color();
for (let i = 0; i < position.count; i += 3) {
const averageHeight =
(position.getY(i) +
position.getY(i + 1) +
position.getY(i + 2)) /
3;
if (averageHeight < -0.45) {
color.set(0x35584a);
} else if (averageHeight < 1.3) {
color.set(0x557950);
} else if (averageHeight < 3.2) {
color.set(0x718d55);
} else if (averageHeight < 4.8) {
color.set(0x8b8e61);
} else if (averageHeight < 5.7) {
color.set(0x7e8171);
} else {
color.set(0xd8d6bd);
}
color.multiplyScalar(0.9 + random() * 0.17);
for (let j = 0; j < 3; j++) {
terrainColors.push(color.r, color.g, color.b);
}
}
terrainGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(terrainColors, 3)
);
terrainGeometry.computeVertexNormals();
const terrain = new THREE.Mesh(
terrainGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 1,
flatShading: true
})
);
terrain.receiveShadow = true;
scene.add(terrain);
const earthBase = new THREE.Mesh(
new THREE.BoxGeometry(56, 1.5, 42),
new THREE.MeshStandardMaterial({
color: 0x334b3d,
roughness: 1
})
);
earthBase.position.set(0, -3.7, 0);
earthBase.receiveShadow = true;
scene.add(earthBase);
// A narrow river follows the bottom of the gorge.
const riverVertices = [];
const riverIndices = [];
for (let i = 0; i <= 42; i++) {
const z = -19 + (i / 42) * 38;
const centerX = 0.25 * Math.sin(z * 0.16);
const halfWidth = 0.28 + 0.08 * Math.sin(z * 0.51);
for (const side of [-1, 1]) {
const x = centerX + side * halfWidth;
riverVertices.push(x, terrainHeight(x, z) + 0.08, z);
}
if (i < 42) {
const a = i * 2;
riverIndices.push(a, a + 1, a + 2, a + 1, a + 3, a + 2);
}
}
const riverGeometry = new THREE.BufferGeometry();
riverGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(riverVertices, 3)
);
riverGeometry.setIndex(riverIndices);
riverGeometry.computeVertexNormals();
const river = new THREE.Mesh(
riverGeometry,
new THREE.MeshStandardMaterial({
color: 0x4eaaa2,
emissive: 0x143e39,
emissiveIntensity: 0.35,
roughness: 0.34,
side: THREE.DoubleSide
})
);
scene.add(river);
// ------------------------------------------------------------
// Materials and geometry helpers
// ------------------------------------------------------------
const materials = {
stone: new THREE.MeshStandardMaterial({
color: 0x8c8b75,
roughness: 0.95,
flatShading: true
}),
darkStone: new THREE.MeshStandardMaterial({
color: 0x5d665c,
roughness: 1,
flatShading: true
}),
wood: new THREE.MeshStandardMaterial({
color: 0x93633c,
roughness: 0.86,
flatShading: true
}),
darkWood: new THREE.MeshStandardMaterial({
color: 0x5f412c,
roughness: 0.9,
flatShading: true
}),
rope: new THREE.MeshStandardMaterial({
color: 0xc7a56d,
roughness: 0.95
}),
roof: new THREE.MeshStandardMaterial({
color: 0xa44f35,
roughness: 0.8,
flatShading: true
}),
roofGold: new THREE.MeshStandardMaterial({
color: 0xc68a32,
roughness: 0.72,
flatShading: true
}),
red: new THREE.MeshStandardMaterial({
color: 0xc84939,
roughness: 0.72,
flatShading: true
})
};
function cylinderBetween(a, b, radius, material, radialSegments = 6) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
function addTube(points, radius, material, segments = 32) {
const curve = new THREE.CatmullRomCurve3(points);
const mesh = new THREE.Mesh(
new THREE.TubeGeometry(curve, segments, radius, 5, false),
material
);
mesh.castShadow = true;
return mesh;
}
// ------------------------------------------------------------
// Decorative terraces, clouds and sun
// ------------------------------------------------------------
function addTerrace(centerX, centerZ) {
const group = new THREE.Group();
const baseY = terrainHeight(centerX, centerZ);
for (let i = 0; i < 4; i++) {
const radius = 3.7 - i * 0.62;
const terrace = new THREE.Mesh(
new THREE.CylinderGeometry(radius * 0.94, radius, 0.34, 12),
i % 2 ? materials.stone : materials.darkStone
);
terrace.position.set(centerX, baseY + 0.1 + i * 0.25, centerZ);
terrace.scale.z = 0.62;
terrace.rotation.y = 0.12 * i;
terrace.castShadow = true;
terrace.receiveShadow = true;
scene.add(terrace);
}
}
addTerrace(-11.5, -8.5);
addTerrace(11, -9.5);
const cloudMaterial = new THREE.MeshStandardMaterial({
color: 0xf0ead7,
roughness: 1,
flatShading: true
});
const clouds = [];
function addCloud(x, y, z, scale) {
const cloud = new THREE.Group();
const pieces = [
[-1.1, 0, 0, 0.9],
[0, 0.25, 0, 1.15],
[1.2, 0, 0, 0.8],
[0.35, -0.15, 0.4, 0.95]
];
for (const [px, py, pz, s] of pieces) {
const puff = new THREE.Mesh(
new THREE.IcosahedronGeometry(s, 0),
cloudMaterial
);
puff.position.set(px, py, pz);
puff.scale.y = 0.68;
cloud.add(puff);
}
cloud.position.set(x, y, z);
cloud.scale.setScalar(scale);
scene.add(cloud);
clouds.push(cloud);
}
addCloud(-17, 12.5, -16, 1.2);
addCloud(16, 15, -20, 1.5);
addCloud(4, 10.5, -17, 0.85);
const sunDisc = new THREE.Mesh(
new THREE.SphereGeometry(3.1, 16, 10),
new THREE.MeshBasicMaterial({ color: 0xf1d897 })
);
sunDisc.position.set(-28, 19, -35);
scene.add(sunDisc);
// ------------------------------------------------------------
// Relay stations
// ------------------------------------------------------------
const relayRecords = [];
function makeRelay(definition, index, added = false) {
const ground = terrainHeight(definition.x, definition.z);
const group = new THREE.Group();
group.position.set(definition.x, ground + 0.08, definition.z);
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.74, 0.86, 0.42, 6),
materials.darkStone
);
base.position.y = 0.2;
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
const tower = new THREE.Mesh(
new THREE.CylinderGeometry(0.32, 0.43, 1.18, 6),
materials.stone
);
tower.position.y = 0.91;
tower.castShadow = true;
group.add(tower);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(0.77, 0.62, 4),
added ? materials.roofGold : materials.roof
);
roof.position.y = 1.76;
roof.rotation.y = Math.PI / 4;
roof.castShadow = true;
group.add(roof);
const beaconMaterial = new THREE.MeshStandardMaterial({
color: added ? 0xffbd42 : 0x73f2cf,
emissive: added ? 0xe48b18 : 0x1c9d7c,
emissiveIntensity: 2,
roughness: 0.25,
flatShading: true
});
const beacon = new THREE.Mesh(
new THREE.OctahedronGeometry(0.25, 0),
beaconMaterial
);
beacon.position.y = 2.35;
group.add(beacon);
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.035, 1.65, 5),
materials.darkWood
);
pole.position.y = 1.48;
group.add(pole);
const flagGeometry = new THREE.BufferGeometry();
flagGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[0, 0, 0, 0.55, -0.13, 0, 0, -0.48, 0],
3
)
);
flagGeometry.computeVertexNormals();
const flag = new THREE.Mesh(
flagGeometry,
new THREE.MeshStandardMaterial({
color: added ? 0xe8a735 : 0x237d69,
side: THREE.DoubleSide,
roughness: 0.8,
flatShading: true
})
);
flag.position.set(0.03, 2.23, 0);
group.add(flag);
group.scale.setScalar(added ? 0.001 : 1);
scene.add(group);
const record = {
group,
beacon,
beaconMaterial,
routePosition: new THREE.Vector3(
definition.x,
ground + 1.12,
definition.z
),
added,
index,
name: definition.name
};
relayRecords.push(record);
return record;
}
const baseDefinitions = [
{ name: "COCHAPAMPA", x: -18, z: 9 },
{ name: "Q'OSGO", x: -12, z: 6 },
{ name: "WAQ WASI", x: -5.5, z: 0.5 },
{ name: "K'INTU", x: 10.5, z: -4 },
{ name: "QHASWA", x: 18, z: -8 }
];
const addedDefinitions = [
{ name: "KILLAY", x: -8.5, z: -8.5 },
{ name: "Q'ARA", x: -1.5, z: -10.5 },
{ name: "WIND NOTCH", x: 7, z: -8.5 }
];
baseDefinitions.forEach((definition, index) =>
makeRelay(definition, index + 1, false)
);
const addedRelays = addedDefinitions.map((definition, index) =>
makeRelay(definition, index + 6, true)
);
// ------------------------------------------------------------
// Bridge
// ------------------------------------------------------------
const bridgeGroup = new THREE.Group();
scene.add(bridgeGroup);
const bridgeClickMeshes = [];
const bridgeGates = [];
const bridgeWest = new THREE.Vector3(-2.8, 4.25, 0);
const bridgeEast = new THREE.Vector3(2.8, 4.25, 0);
const deckMaterial = materials.wood;
const plankCount = 19;
for (let i = 0; i < plankCount; i++) {
const t = i / (plankCount - 1);
const x = THREE.MathUtils.lerp(-2.65, 2.65, t);
const plank = new THREE.Mesh(
new THREE.BoxGeometry(0.31, 0.13, 1.5),
i % 3 === 0 ? materials.darkWood : deckMaterial
);
plank.position.set(x, 4.18, 0);
plank.rotation.z = (random() - 0.5) * 0.025;
plank.castShadow = true;
plank.receiveShadow = true;
plank.userData.bridge = true;
bridgeGroup.add(plank);
bridgeClickMeshes.push(plank);
}
for (const side of [-1, 1]) {
const z = side * 0.78;
const ropePoints = [];
for (let i = 0; i <= 16; i++) {
const t = i / 16;
const x = THREE.MathUtils.lerp(-2.8, 2.8, t);
const y = 5.95 - 1.05 * Math.sin(Math.PI * t);
ropePoints.push(new THREE.Vector3(x, y, z));
}
const rope = addTube(
ropePoints,
0.045,
materials.rope,
36
);
rope.userData.bridge = true;
bridgeGroup.add(rope);
bridgeClickMeshes.push(rope);
for (let i = 0; i < plankCount; i += 2) {
const t = i / (plankCount - 1);
const x = THREE.MathUtils.lerp(-2.65, 2.65, t);
const railY = 5.95 - 1.05 * Math.sin(Math.PI * t);
const vertical = cylinderBetween(
new THREE.Vector3(x, 4.22, z),
new THREE.Vector3(x, railY, z),
0.025,
materials.rope,
5
);
vertical.userData.bridge = true;
bridgeGroup.add(vertical);
bridgeClickMeshes.push(vertical);
}
}
for (const endpoint of [bridgeWest, bridgeEast]) {
const ground = terrainHeight(endpoint.x, endpoint.z);
const supportHeight = Math.max(1, endpoint.y - ground);
for (const side of [-1, 1]) {
const pier = new THREE.Mesh(
new THREE.BoxGeometry(0.48, supportHeight, 0.5),
materials.darkStone
);
pier.position.set(
endpoint.x,
ground + supportHeight / 2,
side * 0.83
);
pier.castShadow = true;
pier.receiveShadow = true;
pier.userData.bridge = true;
bridgeGroup.add(pier);
bridgeClickMeshes.push(pier);
const tower = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.16, 1.9, 6),
materials.darkWood
);
tower.position.set(endpoint.x, 5.08, side * 0.83);
tower.castShadow = true;
tower.userData.bridge = true;
bridgeGroup.add(tower);
bridgeClickMeshes.push(tower);
}
const gate = new THREE.Group();
gate.position.set(endpoint.x, 5.25, 0);
gate.rotation.x = Math.PI / 2;
const barrier = new THREE.Mesh(
new THREE.BoxGeometry(0.19, 0.2, 1.8),
materials.red
);
barrier.castShadow = true;
barrier.userData.bridge = true;
gate.add(barrier);
bridgeClickMeshes.push(barrier);
const cloth = new THREE.Mesh(
new THREE.BoxGeometry(0.1, 0.5, 1.45),
new THREE.MeshStandardMaterial({
color: 0xdc5944,
roughness: 0.85,
flatShading: true
})
);
cloth.position.y = -0.3;
cloth.userData.bridge = true;
gate.add(cloth);
bridgeClickMeshes.push(cloth);
bridgeGroup.add(gate);
bridgeGates.push(gate);
}
// ------------------------------------------------------------
// Route paths
// ------------------------------------------------------------
const routeSegments = [];
const detourSegments = [];
function makeRouteSegment(a, b, color = 0x65ddbd) {
const group = new THREE.Group();
const underMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.2,
depthWrite: false
});
const coreMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.95,
depthWrite: false
});
const under = cylinderBetween(a, b, 0.145, underMaterial, 6);
const core = cylinderBetween(a, b, 0.055, coreMaterial, 6);
core.renderOrder = 2;
under.renderOrder = 1;
group.add(under, core);
scene.add(group);
const segment = {
group,
underMaterial,
coreMaterial
};
return segment;
}
const p0 = relayRecords[0].routePosition;
const p1 = relayRecords[1].routePosition;
const p2 = relayRecords[2].routePosition;
const p5 = relayRecords[3].routePosition;
const p6 = relayRecords[4].routePosition;
const p7 = addedRelays[0].routePosition;
const p8 = addedRelays[1].routePosition;
const p9 = addedRelays[2].routePosition;
const originalPath = [
p0,
p1,
p2,
bridgeWest,
bridgeEast,
p5,
p6
];
const detourPath = [p2, p7, p8, p9, p5, p6];
for (let i = 0; i < originalPath.length - 1; i++) {
routeSegments.push(
makeRouteSegment(originalPath[i], originalPath[i + 1])
);
}
for (let i = 0; i < detourPath.length - 1; i++) {
detourSegments.push(
makeRouteSegment(detourPath[i], detourPath[i + 1], 0xffb83f)
);
}
const bridgeRouteSegment = routeSegments[3];
// ------------------------------------------------------------
// Courier messages
// ------------------------------------------------------------
const packets = [];
function makePacket(index) {
const group = new THREE.Group();
const color = [0xfff0a3, 0x8cf8d4, 0xff9d6d][index];
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 2.4,
roughness: 0.25,
flatShading: true
});
const gem = new THREE.Mesh(
new THREE.OctahedronGeometry(0.26, 0),
material
);
group.add(gem);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.37, 0.035, 4, 14),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.85
})
);
ring.rotation.x = Math.PI / 2;
group.add(ring);
const tail = new THREE.Mesh(
new THREE.ConeGeometry(0.1, 0.38, 4),
material
);
tail.position.y = -0.28;
tail.rotation.x = Math.PI;
group.add(tail);
scene.add(group);
packets.push({ group, gem, ring, progress: 0 });
}
makePacket(0);
makePacket(1);
makePacket(2);
function samplePath(path, progress) {
const lengths = [];
let total = 0;
for (let i = 0; i < path.length - 1; i++) {
const length = path[i].distanceTo(path[i + 1]);
lengths.push(length);
total += length;
}
let distance = THREE.MathUtils.clamp(progress, 0, 0.999999) * total;
for (let i = 0; i < lengths.length; i++) {
if (distance <= lengths[i]) {
const t = lengths[i] === 0 ? 0 : distance / lengths[i];
return new THREE.Vector3().lerpVectors(
path[i],
path[i + 1],
t
);
}
distance -= lengths[i];
}
return path[path.length - 1].clone();
}
function resetPackets() {
packets.forEach((packet, index) => {
packet.progress = [0.06, 0.39, 0.73][index];
});
}
resetPackets();
// ------------------------------------------------------------
// HTML world labels
// ------------------------------------------------------------
const labelRecords = [];
function addLabel(record, indexText, added = false) {
const element = document.createElement("div");
element.className = `world-label${added ? " added" : ""}`;
element.innerHTML = `
<span class="label-index">${indexText}</span>
<span class="label-name">${record.name}</span>
`;
labelsLayer.appendChild(element);
labelRecords.push({
element,
position: record.routePosition.clone().add(
new THREE.Vector3(0, 1.22, 0)
),
added
});
}
relayRecords.forEach((record, index) => {
addLabel(record, String(index + 1).padStart(2, "0"));
});
addedRelays.forEach((record, index) => {
addLabel(record, `+${index + 1}`, true);
});
const bridgeLabel = document.createElement("div");
bridgeLabel.className = "world-label bridge";
bridgeLabel.innerHTML = `
<span class="label-index">B</span>
<span class="label-name">Q'ESUAK BRIDGE</span>
`;
labelsLayer.appendChild(bridgeLabel);
labelRecords.push({
element: bridgeLabel,
position: new THREE.Vector3(0, 6.35, 0),
added: false,
bridge: true
});
// ------------------------------------------------------------
// UI and simulation state
// ------------------------------------------------------------
const state = {
closed: false,
rerouted: false,
reroutePending: false,
showAdded: false,
actionToken: 0,
routeDuration: 48,
addedReveal: 0
};
const statusDot = document.querySelector("#status-dot");
const statusTitle = document.querySelector("#status-title");
const statusDetail = document.querySelector("#status-detail");
const etaValue = document.querySelector("#eta-value");
const stationCount = document.querySelector("#station-count");
const addedCount = document.querySelector("#added-count");
const actionButton = document.querySelector("#action-button");
const actionText = document.querySelector("#action-text");
const overlayButton = document.querySelector("#overlay-button");
const replayButton = document.querySelector("#replay-button");
const routeNote = document.querySelector("#route-note");
const toast = document.querySelector("#toast");
const stepGate = document.querySelector("#step-gate");
const stepDivert = document.querySelector("#step-divert");
const stepReveal = document.querySelector("#step-reveal");
function showToast(message) {
toast.textContent = message;
toast.classList.add("show");
clearTimeout(showToast.timer);
showToast.timer = setTimeout(() => {
toast.classList.remove("show");
}, 2600);
}
function updateUI() {
stationCount.textContent = state.rerouted ? "05" : "05";
addedCount.textContent = state.rerouted ? "+03" : "+00";
if (state.reroutePending) {
statusDot.className = "status-dot pending";
statusTitle.textContent = "GATES CLOSING";
statusDetail.textContent = "Holding couriers at Waq Wasi";
actionText.textContent = "CLOSING CROSSING";
actionButton.disabled = true;
etaValue.textContent = "—";
routeNote.textContent =
"The barriers are lowering. Couriers are being held at the western relay before diversion.";
} else if (state.closed) {
statusDot.className = "status-dot closed";
statusTitle.textContent = "BRIDGE CLOSED";
statusDetail.textContent = "3 couriers on southern detour";
actionText.textContent = "REOPEN ORIGINAL BRIDGE";
actionButton.disabled = false;
etaValue.textContent = "68s";
routeNote.textContent =
"Messages now use Killay, Q'ara and Wind Notch. Three emergency relay stages were added to the network.";
} else {
statusDot.className = "status-dot";
statusTitle.textContent = "BRIDGE OPEN";
statusDetail.textContent = "3 couriers moving normally";
actionText.textContent = "CLOSE BRIDGE & REROUTE";
actionButton.disabled = false;
etaValue.textContent = "48s";
routeNote.textContent =
"The original northern route uses the suspended bridge and five relay stages.";
}
overlayButton.disabled = !state.rerouted;
overlayButton.textContent = state.showAdded
? "HIDE ADDED STAGES"
: "SHOW ADDED STAGES";
stepGate.className = state.closed ? "done" : "";
stepDivert.className = state.rerouted ? "done" : state.closed ? "active" : "";
stepReveal.className = state.rerouted ? "done" : "";
bridgeLabel.classList.toggle("closed", state.closed);
}
function handleAction() {
if (state.reroutePending) return;
const token = ++state.actionToken;
if (!state.closed) {
state.closed = true;
state.rerouted = false;
state.reroutePending = true;
state.showAdded = false;
state.routeDuration = 48;
updateUI();
showToast("Q'esuak barriers lowering — holding couriers.");
setTimeout(() => {
if (token !== state.actionToken || !state.closed) return;
state.rerouted = true;
state.reroutePending = false;
state.showAdded = true;
state.routeDuration = 68;
resetPackets();
updateUI();
showToast("Three added stages online — couriers rerouted south.");
}, 950);
} else {
state.closed = false;
state.rerouted = false;
state.reroutePending = false;
state.showAdded = false;
state.routeDuration = 48;
resetPackets();
updateUI();
showToast("Bridge reopened — couriers returning to the northern route.");
}
}
actionButton.addEventListener("click", handleAction);
overlayButton.addEventListener("click", () => {
if (!state.rerouted) return;
state.showAdded = !state.showAdded;
updateUI();
});
replayButton.addEventListener("click", () => {
resetPackets();
showToast("Courier sequence replayed.");
});
updateUI();
// ------------------------------------------------------------
// Direct camera controls: no external control addon
// ------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 1.4, -1),
yaw: 0.63,
pitch: 0.57,
distance: 42
};
const defaultCamera = { ...cameraState };
function updateCamera() {
const cosPitch = Math.cos(cameraState.pitch);
camera.position.set(
cameraState.target.x +
Math.sin(cameraState.yaw) * cosPitch * cameraState.distance,
cameraState.target.y +
Math.sin(cameraState.pitch) * cameraState.distance,
cameraState.target.z +
Math.cos(cameraState.yaw) * cosPitch * cameraState.distance
);
camera.lookAt(cameraState.target);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraState.yaw = defaultCamera.yaw;
cameraState.pitch = defaultCamera.pitch;
cameraState.distance = defaultCamera.distance;
cameraState.target.copy(defaultCamera.target);
updateCamera();
}
document.querySelector("#reset-view").addEventListener("click", resetCamera);
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
const pointerStart = new THREE.Vector2();
let pointerDown = false;
let dragging = false;
let lastPointer = new THREE.Vector2();
let hoverBridge = false;
function setPointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function testBridgeHit() {
raycaster.setFromCamera(pointer, camera);
return raycaster.intersectObjects(bridgeClickMeshes, false).length > 0;
}
renderer.domElement.addEventListener("pointerdown", event => {
if (event.button !== 0) return;
pointerDown = true;
dragging = false;
pointerStart.set(event.clientX, event.clientY);
lastPointer.set(event.clientX, event.clientY);
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", event => {
setPointer(event);
if (pointerDown) {
const dx = event.clientX - lastPointer.x;
const dy = event.clientY - lastPointer.y;
if (
pointerStart.distanceTo(
new THREE.Vector2(event.clientX, event.clientY)
) > 4
) {
dragging = true;
}
if (dragging) {
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.0045,
0.22,
1.18
);
updateCamera();
}
lastPointer.set(event.clientX, event.clientY);
} else {
hoverBridge = testBridgeHit();
renderer.domElement.style.cursor = hoverBridge ? "pointer" : "grab";
}
});
renderer.domElement.addEventListener("pointerup", event => {
setPointer(event);
const wasClick = !dragging && pointerStart.distanceTo(
new THREE.Vector2(event.clientX, event.clientY)
) < 5;
if (wasClick && testBridgeHit()) {
handleAction();
}
pointerDown = false;
dragging = false;
renderer.domElement.style.cursor = hoverBridge ? "pointer" : "grab";
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
dragging = false;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance + event.deltaY * 0.035,
23,
65
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", event => {
if (event.code === "Space") {
event.preventDefault();
handleAction();
}
if (event.key.toLowerCase() === "r") resetCamera();
});
// ------------------------------------------------------------
// Label projection
// ------------------------------------------------------------
const projected = new THREE.Vector3();
function updateLabels() {
const width = innerWidth;
const height = innerHeight;
for (const label of labelRecords) {
projected.copy(label.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.08 &&
projected.x < 1.08 &&
projected.y > -1.08 &&
projected.y < 1.08;
const addedAllowed = !label.added || state.showAdded;
const revealAllowed = !label.added || state.addedReveal > 0.45;
if (!visible || !addedAllowed || !revealAllowed) {
label.element.style.opacity = "0";
} else {
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
label.element.style.opacity = "1";
}
}
}
// ------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
const gateTarget = state.closed ? 0 : Math.PI / 2;
const gateEase = 1 - Math.exp(-7 * dt);
for (const gate of bridgeGates) {
gate.rotation.x += (gateTarget - gate.rotation.x) * gateEase;
}
const revealTarget = state.rerouted ? 1 : 0;
state.addedReveal +=
(revealTarget - state.addedReveal) *
(1 - Math.exp(-4.8 * dt));
for (const relay of addedRelays) {
relay.group.scale.setScalar(
Math.max(0.001, state.addedReveal)
);
}
for (const segment of detourSegments) {
segment.group.visible = state.addedReveal > 0.01;
segment.underMaterial.opacity = 0.2 * state.addedReveal;
segment.coreMaterial.opacity = 0.95 * state.addedReveal;
}
const bridgeColor = state.closed ? 0xff5b4d : 0x65ddbd;
bridgeRouteSegment.coreMaterial.color.setHex(bridgeColor);
bridgeRouteSegment.underMaterial.color.setHex(bridgeColor);
const activePath = state.rerouted ? detourPath : originalPath;
packets.forEach((packet, index) => {
if (state.reroutePending) {
packet.group.position.copy(p2);
packet.group.position.y += index * 0.06;
packet.group.position.x += (index - 1) * 0.14;
} else {
packet.progress =
(packet.progress + dt / state.routeDuration) % 1;
packet.group.position.copy(
samplePath(activePath, packet.progress)
);
}
packet.gem.rotation.y += dt * 1.7;
packet.gem.rotation.x += dt * 0.8;
packet.ring.rotation.z += dt * 1.4;
const pulse = 1 + Math.sin(elapsed * 4 + index) * 0.08;
packet.group.scale.setScalar(pulse);
});
for (const relay of relayRecords) {
relay.beacon.rotation.y += dt * 1.15;
relay.beaconMaterial.emissiveIntensity =
1.8 + Math.sin(elapsed * 2.8 + relay.index) * 0.55;
}
clouds.forEach((cloud, index) => {
cloud.position.x += dt * (0.07 + index * 0.018);
if (cloud.position.x > 24) cloud.position.x = -24;
});
updateCamera();
renderer.render(scene, camera);
updateLabels();
requestAnimationFrame(animate);
}
updateCamera();
resize();
animate();
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```