Prompt specification
Build or customize the Three.js 3D scene "Open or close the canal in a route model" 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: Open or close the canal in a route model
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/open-or-close-the-canal-in-a-route-model-x2480
Scene Description Prompt:
Please use Three.js from cdnjs for a low-poly scene based on this idea: Open or close the canal in a route model. Let users toggle the Suez connection in a simplified shipping graph. Recompute routes and compare distance while keeping historical events distinct from the interactive hypothetical scenario. Return one self-contained HTML file.
Working Three.js Starter (open-or-close-the-canal-in-a-route-model-x2480):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Canal / Route Lab</title>
<style>
:root {
--ink: #17252b;
--muted: #6f7c7d;
--paper: #f3f1e9;
--panel: #faf9f4;
--line: #d9ddd5;
--sea: #07151d;
--teal: #23bfa8;
--teal-light: #75e5d4;
--amber: #efa557;
--red: #e15d4f;
--shadow: 0 18px 48px rgba(5, 18, 24, 0.15);
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
width: 100%;
min-height: 100%;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button {
font: inherit;
}
.topbar {
height: 68px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 24px;
background: rgba(250, 249, 244, 0.96);
border-bottom: 1px solid var(--line);
position: relative;
z-index: 20;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
}
.brand-mark {
width: 38px;
height: 38px;
display: grid;
place-items: center;
border-radius: 11px;
background: var(--sea);
color: var(--teal-light);
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.brand-mark svg {
width: 25px;
height: 25px;
}
.brand-title {
font-size: 15px;
font-weight: 800;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.brand-subtitle {
margin-top: 2px;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.top-actions {
display: flex;
align-items: center;
gap: 12px;
}
.scenario-badge,
.status-badge {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 8px 11px;
border-radius: 999px;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.scenario-badge {
color: #176d60;
background: #dff3ed;
border: 1px solid #b9dfd5;
}
.scenario-badge::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 4px rgba(35, 191, 168, 0.13);
}
.status-badge {
color: #435154;
background: #edf0eb;
border: 1px solid #d5d9d2;
}
.reset-button,
.icon-button {
border: 1px solid var(--line);
background: var(--panel);
color: var(--ink);
cursor: pointer;
transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}
.reset-button {
padding: 9px 13px;
border-radius: 9px;
font-size: 12px;
font-weight: 700;
}
.reset-button:hover,
.icon-button:hover {
transform: translateY(-1px);
background: #fff;
border-color: #bdc7c3;
}
.app {
height: calc(100vh - 68px);
display: grid;
grid-template-columns: 370px minmax(0, 1fr);
}
.sidebar {
overflow-y: auto;
padding: 20px;
background: var(--paper);
border-right: 1px solid var(--line);
scrollbar-width: thin;
scrollbar-color: #c8cec7 transparent;
}
.card {
background: var(--panel);
border: 1px solid var(--line);
border-radius: 16px;
box-shadow: var(--shadow);
margin-bottom: 16px;
overflow: hidden;
}
.card-inner {
padding: 19px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 18px;
height: 2px;
background: currentColor;
}
.scenario-card {
border-top: 4px solid var(--teal);
}
.scenario-card .eyebrow {
color: #168b79;
}
h1,
h2,
h3,
p {
margin-top: 0;
}
.scenario-card h1 {
margin: 12px 0 8px;
font-size: 25px;
line-height: 1.08;
letter-spacing: -0.035em;
}
.scenario-card p {
color: var(--muted);
font-size: 13px;
line-height: 1.55;
margin-bottom: 18px;
}
.toggle-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
padding: 14px;
border: 1px solid #d7e3de;
background: #edf7f4;
border-radius: 13px;
}
.toggle-copy strong {
display: block;
font-size: 14px;
margin-bottom: 3px;
}
.toggle-copy span {
display: block;
color: var(--muted);
font-size: 11px;
}
.switch {
position: relative;
width: 58px;
height: 32px;
flex: 0 0 auto;
border: 0;
border-radius: 999px;
padding: 0;
background: #aab4b2;
cursor: pointer;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
transition: background 220ms ease;
}
.switch::after {
content: "";
position: absolute;
width: 24px;
height: 24px;
left: 4px;
top: 4px;
border-radius: 50%;
background: white;
box-shadow: 0 2px 7px rgba(0, 0, 0, 0.2);
transition: transform 220ms cubic-bezier(.2, .8, .2, 1);
}
.switch[aria-checked="true"] {
background: var(--teal);
}
.switch[aria-checked="true"]::after {
transform: translateX(26px);
}
.switch:focus-visible,
.reset-button:focus-visible,
.icon-button:focus-visible {
outline: 3px solid rgba(35, 191, 168, 0.25);
outline-offset: 3px;
}
.model-note {
display: flex;
gap: 9px;
margin-top: 13px;
color: #697678;
font-size: 11px;
line-height: 1.45;
}
.model-note strong {
color: #35524d;
}
.route-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.route-title {
margin: 9px 0 0;
font-size: 18px;
letter-spacing: -0.02em;
}
.route-current-badge {
white-space: nowrap;
padding: 6px 9px;
border-radius: 999px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
color: #116f61;
background: #ddf3ed;
}
.distance-block {
padding: 17px 0 15px;
margin-top: 14px;
border-top: 1px solid #e1e3dc;
border-bottom: 1px solid #e1e3dc;
}
.metric-label {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.distance-value {
margin: 4px 0 5px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 34px;
line-height: 1;
letter-spacing: -0.06em;
font-weight: 800;
}
.route-caption {
color: var(--muted);
font-size: 12px;
}
.route-steps {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 5px;
margin: 15px 0 17px;
color: #45575a;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.025em;
}
.route-steps .arrow {
color: #a1aaa7;
}
.comparison-title {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 9px;
}
.comparison-title h3 {
margin: 0;
font-size: 12px;
}
.comparison-title span {
color: var(--muted);
font-size: 10px;
}
.compare-row {
padding: 10px 0;
border-top: 1px solid #e4e6df;
opacity: 0.62;
transition: opacity 180ms ease;
}
.compare-row.active {
opacity: 1;
}
.compare-top {
display: flex;
justify-content: space-between;
gap: 10px;
margin-bottom: 7px;
font-size: 12px;
}
.compare-name {
display: flex;
align-items: center;
gap: 8px;
font-weight: 750;
}
.compare-dot {
width: 9px;
height: 9px;
border-radius: 50%;
}
.compare-distance {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-weight: 800;
}
.bar-track {
height: 5px;
border-radius: 99px;
overflow: hidden;
background: #e6e8e1;
}
.bar-fill {
height: 100%;
border-radius: inherit;
transition: width 500ms cubic-bezier(.2, .8, .2, 1);
}
.compare-detail {
display: flex;
justify-content: space-between;
margin-top: 6px;
color: var(--muted);
font-size: 10px;
}
.delta-panel {
display: flex;
align-items: center;
justify-content: space-between;
gap: 15px;
margin-top: 14px;
padding: 12px 13px;
border-radius: 11px;
color: #63401f;
background: #fbeddc;
border: 1px solid #eed8ba;
}
.delta-panel.closed {
color: #6b392e;
background: #f7e3dc;
border-color: #edcbc0;
}
.delta-panel span {
font-size: 10px;
font-weight: 750;
letter-spacing: 0.045em;
text-transform: uppercase;
}
.delta-panel strong {
white-space: nowrap;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 15px;
}
.distance-disclaimer {
margin: 11px 1px 0;
color: #818987;
font-size: 10px;
line-height: 1.45;
}
.history-card {
background: #e9ebe5;
border-color: #d2d6ce;
box-shadow: none;
}
.history-card .card-inner {
padding: 17px 19px 19px;
}
.history-card .eyebrow {
color: #626b68;
}
.history-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-top: 10px;
}
.history-heading h2 {
margin: 0;
font-size: 17px;
}
.reference-tag {
padding: 5px 7px;
border: 1px solid #c8cdc4;
border-radius: 5px;
color: #6c7571;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
.history-intro {
margin: 9px 0 15px;
color: #68716e;
font-size: 11px;
line-height: 1.5;
}
.timeline {
margin: 0;
padding: 0;
list-style: none;
}
.timeline li {
position: relative;
display: grid;
grid-template-columns: 46px 1fr;
gap: 10px;
padding-bottom: 14px;
}
.timeline li::before {
content: "";
position: absolute;
left: 51px;
top: 9px;
bottom: -2px;
width: 1px;
background: #c5cbc2;
}
.timeline li:last-child {
padding-bottom: 0;
}
.timeline li:last-child::before {
display: none;
}
.timeline time {
padding-top: 2px;
color: #4c5955;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11px;
font-weight: 800;
}
.timeline p {
position: relative;
margin: 0;
padding-left: 12px;
color: #56615e;
font-size: 11px;
line-height: 1.45;
}
.timeline p::before {
content: "";
position: absolute;
left: -4px;
top: 5px;
width: 7px;
height: 7px;
border-radius: 50%;
background: #7f8a84;
box-shadow: 0 0 0 3px #e9ebe5;
}
.history-footnote {
margin: 15px 0 0;
padding-top: 12px;
border-top: 1px solid #d0d5cc;
color: #68726e;
font-size: 10px;
line-height: 1.45;
}
.viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: var(--sea);
}
#scene {
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.scene-vignette {
position: absolute;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 55% 45%, transparent 40%, rgba(2, 10, 14, 0.25) 100%),
linear-gradient(to bottom, rgba(4, 15, 21, 0.05), transparent 25%, transparent 75%, rgba(4, 15, 21, 0.28));
}
.scene-topline {
position: absolute;
left: 24px;
top: 22px;
right: 24px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
pointer-events: none;
}
.scene-title {
color: #f2f5ef;
text-shadow: 0 2px 14px rgba(0, 0, 0, 0.4);
}
.scene-title .eyebrow {
color: #74cbbb;
}
.scene-title h2 {
margin: 8px 0 3px;
font-size: 21px;
letter-spacing: -0.025em;
}
.scene-title p {
margin: 0;
color: rgba(225, 235, 232, 0.68);
font-size: 11px;
}
.live-route {
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 9px;
color: #dfe9e5;
background: rgba(7, 21, 29, 0.72);
backdrop-filter: blur(10px);
font-size: 11px;
font-weight: 700;
white-space: nowrap;
}
.live-route span {
display: inline-block;
width: 8px;
height: 8px;
margin-right: 7px;
border-radius: 50%;
background: var(--teal-light);
box-shadow: 0 0 0 4px rgba(117, 229, 212, 0.12);
}
.map-controls {
position: absolute;
top: 92px;
right: 22px;
display: grid;
gap: 7px;
}
.icon-button {
width: 36px;
height: 36px;
display: grid;
place-items: center;
border-color: rgba(255, 255, 255, 0.13);
color: #e8efeb;
background: rgba(7, 21, 29, 0.78);
backdrop-filter: blur(10px);
border-radius: 9px;
font-size: 19px;
}
.icon-button:hover {
color: white;
background: rgba(18, 43, 51, 0.92);
border-color: rgba(255, 255, 255, 0.24);
}
.labels-layer {
position: absolute;
inset: 0;
pointer-events: none;
overflow: hidden;
}
.map-label {
position: absolute;
transform: translate(-50%, -100%);
padding: 4px 6px;
border-radius: 4px;
color: rgba(242, 246, 240, 0.9);
background: rgba(6, 19, 25, 0.64);
border: 1px solid rgba(255, 255, 255, 0.08);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
box-shadow: 0 5px 12px rgba(0, 0, 0, 0.14);
}
.map-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 8px;
background: rgba(255, 255, 255, 0.35);
}
.map-label.secondary {
color: rgba(224, 234, 230, 0.68);
background: rgba(6, 19, 25, 0.42);
font-size: 8px;
border-color: transparent;
}
.map-label.canal {
color: #c8fff4;
border-color: rgba(117, 229, 212, 0.4);
background: rgba(16, 86, 76, 0.76);
}
.map-label.canal.closed {
color: #ffe4df;
border-color: rgba(225, 93, 79, 0.65);
background: rgba(113, 43, 36, 0.82);
}
.region-label {
position: absolute;
transform: translate(-50%, -50%);
color: rgba(213, 220, 208, 0.18);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
white-space: nowrap;
text-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
.scene-bottom {
position: absolute;
left: 22px;
right: 22px;
bottom: 20px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 18px;
pointer-events: none;
}
.scene-metrics {
display: grid;
grid-template-columns: repeat(3, minmax(112px, 1fr));
gap: 1px;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 12px;
background: rgba(7, 21, 29, 0.76);
backdrop-filter: blur(12px);
box-shadow: 0 14px 34px rgba(0, 0, 0, 0.2);
}
.scene-metric {
padding: 11px 13px;
min-width: 118px;
}
.scene-metric + .scene-metric {
border-left: 1px solid rgba(255, 255, 255, 0.08);
}
.scene-metric span {
display: block;
margin-bottom: 5px;
color: rgba(218, 230, 226, 0.57);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.scene-metric strong {
color: #edf4ef;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 14px;
}
.legend {
display: flex;
align-items: center;
gap: 15px;
padding: 9px 11px;
border-radius: 9px;
color: rgba(225, 235, 231, 0.7);
background: rgba(7, 21, 29, 0.7);
border: 1px solid rgba(255, 255, 255, 0.09);
backdrop-filter: blur(10px);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.legend-line {
width: 19px;
border-top: 3px solid var(--teal-light);
}
.legend-line.cape {
border-color: var(--amber);
}
.legend-line.dashed {
border-top-style: dashed;
opacity: 0.65;
}
.interaction-hint {
position: absolute;
left: 23px;
bottom: 111px;
color: rgba(215, 229, 225, 0.45);
font-size: 9px;
letter-spacing: 0.06em;
text-transform: uppercase;
pointer-events: none;
}
@media (max-width: 950px) {
body {
overflow: auto;
}
.app {
height: auto;
display: flex;
flex-direction: column;
}
.viewport {
order: -1;
height: 58vh;
min-height: 470px;
}
.sidebar {
width: 100%;
overflow: visible;
border-right: 0;
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 16px;
align-items: start;
}
.card {
margin: 0;
}
.scenario-card,
.route-card {
grid-column: span 1;
}
.history-card {
grid-column: 1 / -1;
}
}
@media (max-width: 650px) {
.topbar {
height: 60px;
padding: 0 14px;
}
.brand-subtitle,
.status-badge,
.reset-button {
display: none;
}
.app {
min-height: calc(100vh - 60px);
}
.viewport {
height: 55vh;
min-height: 420px;
}
.sidebar {
display: block;
padding: 14px;
}
.card {
margin-bottom: 14px;
}
.scene-topline {
left: 15px;
top: 15px;
right: 15px;
}
.scene-title h2 {
font-size: 17px;
}
.live-route {
display: none;
}
.map-controls {
right: 14px;
top: 82px;
}
.scene-bottom {
left: 12px;
right: 12px;
bottom: 12px;
}
.scene-metrics {
width: 100%;
grid-template-columns: repeat(3, 1fr);
}
.scene-metric {
min-width: 0;
padding: 9px;
}
.scene-metric strong {
font-size: 11px;
}
.legend,
.interaction-hint,
.map-label.secondary {
display: none;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
scroll-behavior: auto !important;
transition-duration: 0.01ms !important;
animation-duration: 0.01ms !important;
}
}
</style>
</head>
<body>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none">
<path d="M4 7h6l3 5h7M4 17h6l3-5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
<circle cx="4" cy="7" r="2" fill="#07151d" stroke="currentColor" stroke-width="1.5"/>
<circle cx="20" cy="12" r="2" fill="#07151d" stroke="currentColor" stroke-width="1.5"/>
<circle cx="4" cy="17" r="2" fill="#07151d" stroke="currentColor" stroke-width="1.5"/>
</svg>
</div>
<div>
<div class="brand-title">Canal / Route Lab</div>
<div class="brand-subtitle">Interactive shipping graph</div>
</div>
</div>
<div class="top-actions">
<div class="scenario-badge">Hypothetical scenario</div>
<div class="status-badge" id="headerStatus">Suez connection open</div>
<button class="reset-button" id="headerReset">Reset view</button>
</div>
</header>
<main class="app">
<aside class="sidebar">
<section class="card scenario-card" aria-labelledby="scenarioHeading">
<div class="card-inner">
<div class="eyebrow">Interactive hypothetical</div>
<h1 id="scenarioHeading">Open or close the canal.</h1>
<p>Change one modeled connection and watch the shortest route recalculate between two fixed ports.</p>
<div class="toggle-row">
<div class="toggle-copy">
<strong>Suez connection</strong>
<span id="toggleCaption">Passage is available</span>
</div>
<button
class="switch"
id="canalToggle"
type="button"
role="switch"
aria-checked="true"
aria-label="Suez canal connection"
></button>
</div>
<div class="model-note">
<span aria-hidden="true">↳</span>
<div><strong>Model boundary:</strong> this toggle changes only the shipping graph. It does not alter the historical timeline or represent live shipping conditions.</div>
</div>
</div>
</section>
<section class="card route-card" aria-labelledby="routeHeading">
<div class="card-inner">
<div class="route-header">
<div>
<div class="eyebrow">Route comparison</div>
<h2 class="route-title" id="routeHeading">Rotterdam → Shanghai</h2>
</div>
<div class="route-current-badge" id="routeCurrentBadge">Via Suez</div>
</div>
<div class="distance-block">
<div class="metric-label">Modeled distance</div>
<div class="distance-value" id="distanceValue">25,300 km</div>
<div class="route-caption" id="routeCaption">6 legs · selected route via Suez</div>
</div>
<div class="route-steps" id="routeSteps" aria-label="Selected route sequence"></div>
<div class="comparison-title">
<h3>Scenario comparison</h3>
<span>Illustrative distances</span>
</div>
<div class="compare-row active" id="suezCompare">
<div class="compare-top">
<div class="compare-name">
<span class="compare-dot" style="background:#23bfa8"></span>
Suez open
</div>
<div class="compare-distance" id="suezDistance">25,300 km</div>
</div>
<div class="bar-track">
<div class="bar-fill" id="suezBar" style="width:86.35%;background:#23bfa8"></div>
</div>
<div class="compare-detail">
<span>Gibraltar · Port Said · Suez</span>
<span>Baseline</span>
</div>
</div>
<div class="compare-row" id="capeCompare">
<div class="compare-top">
<div class="compare-name">
<span class="compare-dot" style="background:#efa557"></span>
Suez closed
</div>
<div class="compare-distance" id="capeDistance">29,300 km</div>
</div>
<div class="bar-track">
<div class="bar-fill" id="capeBar" style="width:100%;background:#efa557"></div>
</div>
<div class="compare-detail">
<span>Cape of Good Hope · Singapore</span>
<span id="capeDelta">+4,000 km</span>
</div>
</div>
<div class="delta-panel" id="deltaPanel">
<span id="deltaLabel">Shorter than closed scenario</span>
<strong id="deltaValue">−4,000 km</strong>
</div>
<p class="distance-disclaimer">
Distances are simplified graph estimates for comparison, not navigational guidance or real-time conditions.
</p>
</div>
</section>
<section class="card history-card" aria-labelledby="historyHeading">
<div class="card-inner">
<div class="eyebrow">Historical record</div>
<div class="history-heading">
<h2 id="historyHeading">A separate timeline</h2>
<span class="reference-tag">Reference only</span>
</div>
<p class="history-intro">
These events provide context only. None of them is connected to the interactive toggle or route calculation.
</p>
<ol class="timeline">
<li>
<time datetime="1869">1869</time>
<p>The Suez Canal opened to regular international shipping traffic.</p>
</li>
<li>
<time datetime="1956">1956</time>
<p>The Suez Crisis unfolded following Egypt’s nationalization of the canal company.</p>
</li>
<li>
<time datetime="1967">1967–75</time>
<p>The canal was closed after the Six-Day War and reopened in 1975.</p>
</li>
<li>
<time datetime="2024">2024</time>
<p>Red Sea security disruptions prompted many operators to consider Cape diversions.</p>
</li>
</ol>
<p class="history-footnote">
The timeline is intentionally detached from the model: changing the hypothetical connection never rewrites these historical events.
</p>
</div>
</section>
</aside>
<section class="viewport" id="viewport" aria-label="Interactive three-dimensional shipping route map">
<canvas id="scene"></canvas>
<div class="scene-vignette"></div>
<div class="labels-layer" id="labelsLayer"></div>
<div class="scene-topline">
<div class="scene-title">
<div class="eyebrow">Low-poly graph / live model</div>
<h2>One connection, two shipping paths</h2>
<p>Drag to rotate · scroll to zoom · double-click to reset</p>
</div>
<div class="live-route" id="liveRoute"><span></span>Route via Suez</div>
</div>
<div class="map-controls" aria-label="Camera controls">
<button class="icon-button" id="zoomIn" type="button" aria-label="Zoom in">+</button>
<button class="icon-button" id="zoomOut" type="button" aria-label="Zoom out">−</button>
<button class="icon-button" id="resetView" type="button" aria-label="Reset camera view">↺</button>
</div>
<div class="interaction-hint">Camera controls implemented directly in Three.js scene</div>
<div class="scene-bottom">
<div class="scene-metrics">
<div class="scene-metric">
<span>Modeled distance</span>
<strong id="sceneDistance">25,300 km</strong>
</div>
<div class="scene-metric">
<span>Scenario difference</span>
<strong id="sceneDelta">−4,000 km</strong>
</div>
<div class="scene-metric">
<span>Active passage</span>
<strong id="scenePassage">Suez</strong>
</div>
</div>
<div class="legend">
<div class="legend-item"><span class="legend-line"></span> Active</div>
<div class="legend-item"><span class="legend-line dashed"></span> Alternative</div>
<div class="legend-item"><span class="legend-line cape"></span> Cape path</div>
</div>
</div>
</section>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const viewport = document.getElementById("viewport");
const labelsLayer = document.getElementById("labelsLayer");
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const COLORS = {
open: 0x23bfa8,
openLight: 0x75e5d4,
closed: 0xefa557,
closedLight: 0xffc980,
red: 0xe15d4f,
land: 0xb9b49b,
landSide: 0x777963
};
const nodes = {
rtm: { name: "Rotterdam", lon: 4.5, lat: 51.9 },
gib: { name: "Gibraltar", lon: -5.4, lat: 36.0 },
ps: { name: "Port Said", lon: 32.3, lat: 31.3 },
suz: { name: "Suez", lon: 32.5, lat: 29.9 },
mum: { name: "Mumbai", lon: 72.9, lat: 19.1 },
sin: { name: "Singapore", lon: 103.8, lat: 1.3 },
sha: { name: "Shanghai", lon: 121.5, lat: 31.2 },
cpt: { name: "Cape Town", lon: 18.4, lat: -33.9 }
};
const edges = [
{ id: "rtm-gib", a: "rtm", b: "gib", km: 6400 },
{ id: "gib-ps", a: "gib", b: "ps", km: 3300 },
{ id: "canal", a: "ps", b: "suz", km: 190, canal: true },
{ id: "suz-mum", a: "suz", b: "mum", km: 6100 },
{ id: "mum-sin", a: "mum", b: "sin", km: 5200 },
{ id: "sin-sha", a: "sin", b: "sha", km: 4300 },
{ id: "rtm-cpt", a: "rtm", b: "cpt", km: 13500 },
{ id: "cpt-sin", a: "cpt", b: "sin", km: 11500 }
];
function project(lon, lat) {
return {
x: (lon + 10) * 0.48 - 32,
z: (50 - lat) * 0.55 - 18
};
}
Object.entries(nodes).forEach(([id, node]) => {
const p = project(node.lon, node.lat);
node.position = new THREE.Vector3(p.x, 0.36, p.z);
});
function shortestPath(canalAvailable) {
const adjacency = new Map(Object.keys(nodes).map(id => [id, []]));
for (const edge of edges) {
if (edge.canal && !canalAvailable) continue;
adjacency.get(edge.a).push({ to: edge.b, km: edge.km });
adjacency.get(edge.b).push({ to: edge.a, km: edge.km });
}
const distances = new Map(Object.keys(nodes).map(id => [id, Infinity]));
const previous = new Map();
const remaining = new Set(Object.keys(nodes));
distances.set("rtm", 0);
while (remaining.size) {
let current = null;
let currentDistance = Infinity;
for (const id of remaining) {
if (distances.get(id) < currentDistance) {
current = id;
currentDistance = distances.get(id);
}
}
if (current === null) break;
if (current === "sha") break;
remaining.delete(current);
for (const link of adjacency.get(current)) {
if (!remaining.has(link.to)) continue;
const candidate = currentDistance + link.km;
if (candidate < distances.get(link.to)) {
distances.set(link.to, candidate);
previous.set(link.to, current);
}
}
}
const path = [];
let cursor = "sha";
while (cursor) {
path.unshift(cursor);
cursor = previous.get(cursor);
}
return { path, distance: distances.get("sha") };
}
const openRoute = shortestPath(true);
const closedRoute = shortestPath(false);
let canalOpen = true;
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07151d);
scene.fog = new THREE.Fog(0x07151d, 90, 165);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 250);
const cameraTarget = new THREE.Vector3(-1, 0, 0);
let cameraRadius = 96;
let cameraTheta = 0.05;
let cameraPhi = 0.72;
let dragging = false;
let dragX = 0;
let dragY = 0;
const hemisphere = new THREE.HemisphereLight(0xb9d9d8, 0x25332d, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffe6bd, 2.3);
keyLight.position.set(-30, 55, 25);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -60;
keyLight.shadow.camera.right = 60;
keyLight.shadow.camera.top = 50;
keyLight.shadow.camera.bottom = -50;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 140;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x49bfae, 1.1);
rimLight.position.set(45, 25, -40);
scene.add(rimLight);
let seed = 7243;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function createSea() {
const geometry = new THREE.PlaneGeometry(100, 74, 14, 10);
geometry.rotateX(-Math.PI / 2);
const position = geometry.attributes.position;
for (let i = 0; i < position.count; i++) {
position.setY(i, -1.08 + random() * 0.07);
}
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
color: 0x0a2730,
roughness: 0.82,
metalness: 0.05,
flatShading: true
});
const sea = new THREE.Mesh(geometry, material);
sea.receiveShadow = true;
scene.add(sea);
const grid = new THREE.GridHelper(92, 23, 0x28505a, 0x173740);
grid.position.y = -0.965;
grid.material.transparent = true;
grid.material.opacity = 0.18;
grid.material.depthWrite = false;
scene.add(grid);
}
createSea();
function createLand(polygon, topColor = COLORS.land, sideColor = COLORS.landSide) {
const shape = new THREE.Shape();
polygon.forEach(([lon, lat], index) => {
const p = project(lon, lat);
if (index === 0) shape.moveTo(p.x, -p.z);
else shape.lineTo(p.x, -p.z);
});
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.8,
bevelEnabled: false,
curveSegments: 1
});
geometry.rotateX(-Math.PI / 2);
const topMaterial = new THREE.MeshStandardMaterial({
color: topColor,
roughness: 0.93,
metalness: 0,
flatShading: true
});
const sideMaterial = new THREE.MeshStandardMaterial({
color: sideColor,
roughness: 1,
metalness: 0,
flatShading: true
});
const mesh = new THREE.Mesh(geometry, [topMaterial, sideMaterial]);
mesh.position.y = -1;
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
const outlinePoints = polygon.map(([lon, lat]) => {
const p = project(lon, lat);
return new THREE.Vector3(p.x, -0.17, p.z);
});
outlinePoints.push(outlinePoints[0].clone());
const outlineGeometry = new THREE.BufferGeometry().setFromPoints(outlinePoints);
const outlineMaterial = new THREE.LineBasicMaterial({
color: 0xe8e2c9,
transparent: true,
opacity: 0.28
});
scene.add(new THREE.Line(outlineGeometry, outlineMaterial));
}
createLand([
[-10,36],[-9,43],[-5,49],[2,51],[8,54],[10,58],[18,60],
[25,71],[35,69],[42,62],[37,56],[30,52],[29,46],[23,42],
[15,39],[12,44],[6,43],[3,38]
], 0xb9b79d, 0x6f796a);
createLand([
[-17,36],[-5,37],[10,34],[25,31],[34,29],[39,19],[51,12],
[48,3],[42,-8],[35,-22],[27,-35],[19,-34],[14,-22],[10,-7],
[5,4],[-2,5],[-8,5],[-13,12],[-17,22]
], 0xc49a72, 0x776b56);
createLand([
[27,71],[45,68],[60,73],[90,77],[120,70],[145,62],[160,54],
[150,45],[140,42],[128,35],[122,25],[113,20],[108,10],[102,2],
[96,8],[90,22],[80,8],[76,10],[72,22],[65,25],[57,25],
[49,30],[42,38],[35,37],[28,40],[25,48],[30,55],[22,58]
], 0xb4b49a, 0x687567);
createLand([
[113,-12],[121,-15],[132,-11],[142,-15],[153,-27],[146,-38],
[133,-36],[122,-31],[115,-23]
], 0xb89e79, 0x766d59);
createLand([
[48,-13],[51,-16],[50,-24],[47,-26],[44,-20]
], 0xa79070, 0x6b6252);
createLand([
[130,32],[135,34],[140,40],[145,44],[142,37],[137,32]
], 0xa7ad98, 0x657267);
createLand([
[-54,59],[-44,61],[-23,70],[-20,82],[-38,84],[-60,76]
], 0xc7c8b4, 0x7e897d);
createLand([
[95,5],[104,2],[106,-6],[100,-3]
], 0xa98f6e, 0x6c6251);
createLand([
[107,-6],[115,-7],[119,-9],[110,-8]
], 0xa98f6e, 0x6c6251);
const mountainMaterial = new THREE.MeshStandardMaterial({
color: 0x777b6b,
roughness: 1,
flatShading: true
});
const mountainLocations = [
[-3,45,1.7],[7,46,1.3],[33,36,1.7],[43,32,1.3],
[69,35,2.3],[77,32,1.8],[92,28,2.1],[103,31,1.6],
[17,8,1.5],[29,8,1.2],[120,28,1.4]
];
for (const [lon, lat, height] of mountainLocations) {
const p = project(lon, lat);
const radius = 0.9 + random() * 0.9;
const mountain = new THREE.Mesh(
new THREE.ConeGeometry(radius, height, 5),
mountainMaterial
);
mountain.position.set(p.x, -0.18 + height / 2, p.z);
mountain.rotation.y = random() * Math.PI;
mountain.castShadow = true;
scene.add(mountain);
}
function cylinderBetween(a, b, radius, material) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 6, 1, false),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
return mesh;
}
function createSolidRoute(path, color) {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.75,
roughness: 0.38,
metalness: 0.08
});
const glowMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.12,
depthWrite: false
});
for (let i = 0; i < path.length - 1; i++) {
const a = nodes[path[i]].position.clone();
const b = nodes[path[i + 1]].position.clone();
a.y = 0.38;
b.y = 0.38;
group.add(cylinderBetween(a, b, 0.075, material));
group.add(cylinderBetween(a, b, 0.17, glowMaterial));
}
return group;
}
function createDashedRoute(path, color) {
const points = path.map(id => {
const p = nodes[id].position.clone();
p.y = 0.39;
return p;
});
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineDashedMaterial({
color,
dashSize: 0.52,
gapSize: 0.34,
transparent: true,
opacity: 0.48,
depthWrite: false
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
return line;
}
const openSolid = createSolidRoute(openRoute.path, COLORS.openLight);
const closedSolid = createSolidRoute(closedRoute.path, COLORS.closedLight);
const openDashed = createDashedRoute(openRoute.path, COLORS.openLight);
const closedDashed = createDashedRoute(closedRoute.path, COLORS.closedLight);
scene.add(openSolid, closedSolid, openDashed, closedDashed);
const nodeMeshes = new Map();
const nodeRings = new Map();
for (const [id, node] of Object.entries(nodes)) {
const isEndpoint = id === "rtm" || id === "sha";
const isCanal = id === "ps" || id === "suz";
const color = isCanal ? COLORS.openLight : isEndpoint ? 0xf2ead5 : 0xc9d7d0;
const group = new THREE.Group();
group.position.copy(node.position);
const pinMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: isCanal ? 0.55 : 0.18,
roughness: 0.4
});
const pin = new THREE.Mesh(
new THREE.IcosahedronGeometry(isEndpoint ? 0.42 : 0.29, 0),
pinMaterial
);
pin.position.y = 0.34;
pin.castShadow = true;
group.add(pin);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(isEndpoint ? 0.72 : 0.52, 0.045, 4, 24),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: isCanal ? 0.75 : 0.45,
depthWrite: false
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.06;
group.add(ring);
scene.add(group);
nodeMeshes.set(id, { group, pin, material: pinMaterial });
nodeRings.set(id, ring);
}
const gateGroup = new THREE.Group();
const ps = nodes.ps.position;
const suz = nodes.suz.position;
gateGroup.position.copy(ps).add(suz).multiplyScalar(0.5);
gateGroup.position.y = 0.54;
const gateRedMaterial = new THREE.MeshStandardMaterial({
color: COLORS.red,
emissive: COLORS.red,
emissiveIntensity: 0.8,
roughness: 0.38
});
const closedCross = new THREE.Group();
const barA = new THREE.Mesh(new THREE.BoxGeometry(1.15, 0.13, 0.13), gateRedMaterial);
const barB = new THREE.Mesh(new THREE.BoxGeometry(0.13, 0.13, 1.15), gateRedMaterial);
closedCross.add(barA, barB);
gateGroup.add(closedCross);
const openLock = new THREE.Mesh(
new THREE.TorusGeometry(0.28, 0.075, 5, 12),
new THREE.MeshStandardMaterial({
color: COLORS.openLight,
emissive: COLORS.openLight,
emissiveIntensity: 0.8
})
);
openLock.rotation.x = Math.PI / 2;
gateGroup.add(openLock);
scene.add(gateGroup);
function createShip() {
const ship = new THREE.Group();
const hullMaterial = new THREE.MeshStandardMaterial({
color: 0xe6e0ca,
roughness: 0.55,
metalness: 0.06,
flatShading: true
});
const hull = new THREE.Mesh(
new THREE.CylinderGeometry(0, 0.38, 1.45, 4),
hullMaterial
);
hull.rotation.x = Math.PI / 2;
hull.rotation.z = Math.PI / 4;
hull.scale.z = 0.72;
ship.add(hull);
const deck = new THREE.Mesh(
new THREE.BoxGeometry(0.34, 0.18, 0.62),
new THREE.MeshStandardMaterial({
color: 0x35515a,
roughness: 0.7
})
);
deck.position.set(0, 0.2, -0.18);
ship.add(deck);
const stripe = new THREE.Mesh(
new THREE.BoxGeometry(0.12, 0.12, 0.92),
new THREE.MeshBasicMaterial({ color: COLORS.openLight })
);
stripe.position.set(0, 0.02, 0.05);
ship.add(stripe);
ship.scale.setScalar(0.72);
scene.add(ship);
return { group: ship, stripe };
}
const ships = [createShip(), createShip()];
let shipRoute = openRoute.path;
function routePoints(path) {
return path.map(id => nodes[id].position.clone().setY(0.63));
}
function sampleRoute(path, t) {
const points = routePoints(path);
const lengths = [];
let total = 0;
for (let i = 0; i < points.length - 1; i++) {
const length = points[i].distanceTo(points[i + 1]);
lengths.push(length);
total += length;
}
let target = THREE.MathUtils.clamp(t, 0, 0.999999) * total;
for (let i = 0; i < lengths.length; i++) {
if (target <= lengths[i]) {
const amount = lengths[i] === 0 ? 0 : target / lengths[i];
const position = new THREE.Vector3().lerpVectors(points[i], points[i + 1], amount);
const direction = new THREE.Vector3().subVectors(points[i + 1], points[i]).normalize();
return { position, direction };
}
target -= lengths[i];
}
return { position: points.at(-1), direction: new THREE.Vector3(0, 0, 1) };
}
const labelDefinitions = [
{ id: "rtm", text: "ROTTERDAM", kind: "primary" },
{ id: "gib", text: "GIBRALTAR", kind: "secondary" },
{ id: "mum", text: "MUMBAI", kind: "secondary" },
{ id: "sin", text: "SINGAPORE", kind: "secondary" },
{ id: "sha", text: "SHANGHAI", kind: "primary" },
{ id: "cpt", text: "CAPE TOWN", kind: "primary" }
];
const mapLabels = [];
for (const definition of labelDefinitions) {
const element = document.createElement("div");
element.className = `map-label ${definition.kind}`;
element.textContent = definition.text;
labelsLayer.appendChild(element);
mapLabels.push({
element,
position: nodes[definition.id].position.clone().setY(1.15)
});
}
const canalLabelElement = document.createElement("div");
canalLabelElement.className = "map-label canal";
canalLabelElement.textContent = "SUEZ · OPEN";
labelsLayer.appendChild(canalLabelElement);
mapLabels.push({
element: canalLabelElement,
position: nodes.ps.position.clone().add(nodes.suz.position).multiplyScalar(0.5).setY(1.3)
});
const regionDefinitions = [
{ text: "EURASIA", lon: 80, lat: 54 },
{ text: "AFRICA", lon: 20, lat: 10 },
{ text: "INDIAN OCEAN", lon: 70, lat: -13 },
{ text: "SOUTH CHINA SEA", lon: 112, lat: 10 }
];
for (const region of regionDefinitions) {
const element = document.createElement("div");
element.className = "region-label";
element.textContent = region.text;
labelsLayer.appendChild(element);
const p = project(region.lon, region.lat);
mapLabels.push({ element, position: new THREE.Vector3(p.x, 0.05, p.z) });
}
const numberFormat = new Intl.NumberFormat("en-US");
function updateRouteSteps(path) {
const routeSteps = document.getElementById("routeSteps");
routeSteps.replaceChildren();
path.forEach((id, index) => {
if (index > 0) {
const arrow = document.createElement("span");
arrow.className = "arrow";
arrow.textContent = "→";
routeSteps.appendChild(arrow);
}
const step = document.createElement("span");
step.textContent = nodes[id].name;
routeSteps.appendChild(step);
});
}
function updateUI() {
const current = canalOpen ? openRoute : closedRoute;
const delta = closedRoute.distance - openRoute.distance;
const distance = numberFormat.format(current.distance);
const signedDelta = `${canalOpen ? "−" : "+"}${numberFormat.format(delta)} km`;
document.getElementById("canalToggle").setAttribute("aria-checked", String(canalOpen));
document.getElementById("toggleCaption").textContent = canalOpen
? "Passage is available"
: "Passage is unavailable";
document.getElementById("headerStatus").textContent = canalOpen
? "Suez connection open"
: "Suez connection closed";
document.getElementById("routeCurrentBadge").textContent = canalOpen ? "Via Suez" : "Via Cape";
document.getElementById("distanceValue").textContent = `${distance} km`;
document.getElementById("routeCaption").textContent =
`${current.path.length - 1} legs · selected route ${canalOpen ? "via Suez" : "via the Cape"}`;
document.getElementById("sceneDistance").textContent = `${distance} km`;
document.getElementById("sceneDelta").textContent = signedDelta;
document.getElementById("scenePassage").textContent = canalOpen ? "Suez" : "Cape of Good Hope";
document.getElementById("liveRoute").innerHTML =
`<span style="background:${canalOpen ? "var(--teal-light)" : "var(--amber)"}"></span>` +
`Route ${canalOpen ? "via Suez" : "via the Cape"}`;
document.getElementById("deltaLabel").textContent = canalOpen
? "Shorter than closed scenario"
: "Longer than open scenario";
document.getElementById("deltaValue").textContent = signedDelta;
document.getElementById("deltaPanel").classList.toggle("closed", !canalOpen);
document.getElementById("suezCompare").classList.toggle("active", canalOpen);
document.getElementById("capeCompare").classList.toggle("active", !canalOpen);
document.getElementById("suezDistance").textContent = `${numberFormat.format(openRoute.distance)} km`;
document.getElementById("capeDistance").textContent = `${numberFormat.format(closedRoute.distance)} km`;
document.getElementById("capeDelta").textContent = `+${numberFormat.format(delta)} km`;
const maxDistance = Math.max(openRoute.distance, closedRoute.distance);
document.getElementById("suezBar").style.width = `${(openRoute.distance / maxDistance) * 100}%`;
document.getElementById("capeBar").style.width = `${(closedRoute.distance / maxDistance) * 100}%`;
updateRouteSteps(current.path);
}
function updateSceneState() {
openSolid.visible = canalOpen;
openDashed.visible = !canalOpen;
closedSolid.visible = !canalOpen;
closedDashed.visible = canalOpen;
closedCross.visible = !canalOpen;
openLock.visible = canalOpen;
for (const id of ["ps", "suz"]) {
const material = nodeMeshes.get(id).material;
material.color.setHex(canalOpen ? COLORS.openLight : COLORS.red);
material.emissive.setHex(canalOpen ? COLORS.openLight : COLORS.red);
}
canalLabelElement.textContent = canalOpen ? "SUEZ · OPEN" : "SUEZ · CLOSED";
canalLabelElement.classList.toggle("closed", !canalOpen);
const shipColor = canalOpen ? COLORS.openLight : COLORS.closedLight;
ships.forEach(ship => ship.stripe.material.color.setHex(shipColor));
shipRoute = canalOpen ? openRoute.path : closedRoute.path;
updateUI();
}
document.getElementById("canalToggle").addEventListener("click", () => {
canalOpen = !canalOpen;
updateSceneState();
});
function applyCamera() {
const aspect = viewport.clientWidth / Math.max(viewport.clientHeight, 1);
const aspectScale = Math.max(1, 1.18 / aspect);
const radius = cameraRadius * aspectScale;
camera.position.set(
cameraTarget.x + radius * Math.sin(cameraPhi) * Math.sin(cameraTheta),
cameraTarget.y + radius * Math.cos(cameraPhi),
cameraTarget.z + radius * Math.sin(cameraPhi) * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraRadius = 96;
cameraTheta = 0.05;
cameraPhi = 0.72;
cameraTarget.set(-1, 0, 0);
applyCamera();
}
document.getElementById("resetView").addEventListener("click", resetCamera);
document.getElementById("headerReset").addEventListener("click", resetCamera);
document.getElementById("zoomIn").addEventListener("click", () => {
cameraRadius = Math.max(62, cameraRadius - 7);
applyCamera();
});
document.getElementById("zoomOut").addEventListener("click", () => {
cameraRadius = Math.min(145, cameraRadius + 7);
applyCamera();
});
canvas.addEventListener("pointerdown", event => {
dragging = true;
dragX = event.clientX;
dragY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const deltaX = event.clientX - dragX;
const deltaY = event.clientY - dragY;
dragX = event.clientX;
dragY = event.clientY;
cameraTheta -= deltaX * 0.006;
cameraPhi = THREE.MathUtils.clamp(cameraPhi - deltaY * 0.005, 0.34, 1.17);
applyCamera();
});
function stopDragging(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("dblclick", resetCamera);
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(cameraRadius * Math.exp(event.deltaY * 0.001), 62, 145);
applyCamera();
}, { passive: false });
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / Math.max(height, 1);
camera.updateProjectionMatrix();
applyCamera();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(viewport);
resize();
const projected = new THREE.Vector3();
function positionLabel(label) {
projected.copy(label.position).project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * viewport.clientWidth;
const y = (-projected.y * 0.5 + 0.5) * viewport.clientHeight;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
ships.forEach((ship, index) => {
const t = reducedMotion
? 0.22 + index * 0.38
: (elapsed * 0.032 + index * 0.47) % 1;
const sample = sampleRoute(shipRoute, t);
ship.group.position.copy(sample.position);
ship.group.rotation.y = Math.atan2(sample.direction.x, sample.direction.z);
ship.group.position.y += Math.sin(elapsed * 2.2 + index) * 0.035;
});
nodeRings.forEach((ring, id) => {
const pulse = 1 + Math.sin(elapsed * 2.2 + id.length) * 0.08;
ring.scale.setScalar(pulse);
});
if (!reducedMotion) {
closedCross.rotation.y = Math.sin(elapsed * 0.9) * 0.08;
openLock.rotation.z = elapsed * 0.35;
}
mapLabels.forEach(positionLabel);
renderer.render(scene, camera);
}
updateSceneState();
animate();
</script>
</body>
</html>
```