Prompt specification
Build or customize the Three.js 3D scene "Malacca port within a regional route network" 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: Malacca port within a regional route network
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/malacca-port-within-a-regional-route-network-x2603
Scene Description Prompt:
Malacca port within a regional route network. Build a compact waterfront model linked to a schematic regional sea-route display. Show the port as one node among several and identify sourced trade connections. Please build this with Three.js from cdnjs in one self-contained HTML file, using low-poly forms.
Working Three.js Starter (malacca-port-within-a-regional-route-network-x2603):
```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="#071821" />
<title>Malacca Port — Regional Trade Network</title>
<style>
:root {
--bg: #071821;
--panel: rgba(8, 25, 34, 0.88);
--panel-solid: #0a202b;
--line: rgba(170, 220, 225, 0.16);
--text: #e9f4f2;
--muted: #91aaa9;
--cyan: #70e4d1;
--cyan-soft: rgba(112, 228, 209, 0.14);
--orange: #f3a34b;
--red: #ec765d;
--blue: #69a9dc;
--shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 28% 22%, #163c49 0, #0a2430 38%, #06151e 100%);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
a {
font: inherit;
}
button {
color: inherit;
}
#app {
position: relative;
width: 100%;
height: 100%;
isolation: isolate;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.topbar {
position: fixed;
z-index: 20;
top: 0;
left: 0;
right: 0;
height: 68px;
padding: 0 22px;
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid rgba(190, 230, 230, 0.12);
background: linear-gradient(180deg, rgba(5, 18, 25, 0.9), rgba(5, 18, 25, 0.25));
backdrop-filter: blur(13px);
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}
.brand-mark {
width: 35px;
height: 35px;
display: grid;
place-items: center;
flex: 0 0 auto;
border: 1px solid rgba(112, 228, 209, 0.35);
background: rgba(112, 228, 209, 0.08);
transform: rotate(45deg);
}
.brand-mark::after {
content: "";
width: 12px;
height: 12px;
border: 2px solid var(--cyan);
border-top-color: transparent;
border-radius: 50%;
}
.brand-copy {
min-width: 0;
}
.brand-copy strong {
display: block;
font-size: 13px;
letter-spacing: 0.16em;
font-weight: 750;
}
.brand-copy span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.header-stats {
display: flex;
align-items: center;
gap: 24px;
margin-left: auto;
margin-right: 24px;
}
.header-stat {
display: flex;
align-items: baseline;
gap: 6px;
white-space: nowrap;
}
.header-stat b {
font-size: 15px;
font-variant-numeric: tabular-nums;
}
.header-stat span {
color: var(--muted);
font-size: 9px;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.top-actions {
display: flex;
gap: 8px;
}
.button {
min-height: 35px;
padding: 0 13px;
border: 1px solid var(--line);
border-radius: 3px;
background: rgba(15, 42, 51, 0.7);
color: #d9e9e7;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.09em;
text-transform: uppercase;
cursor: pointer;
transition:
border-color 160ms ease,
background 160ms ease,
color 160ms ease;
}
.button:hover,
.button:focus-visible {
border-color: rgba(112, 228, 209, 0.65);
background: rgba(112, 228, 209, 0.11);
color: #fff;
outline: none;
}
.button.primary {
border-color: rgba(112, 228, 209, 0.35);
color: var(--cyan);
}
.scene-title {
position: fixed;
z-index: 10;
top: 93px;
left: 25px;
width: min(440px, calc(100vw - 450px));
pointer-events: none;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.5);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 23px;
height: 1px;
background: var(--cyan);
box-shadow: 0 0 10px rgba(112, 228, 209, 0.6);
}
.scene-title h1 {
margin: 0;
font-size: clamp(34px, 4.5vw, 64px);
line-height: 0.94;
letter-spacing: -0.055em;
font-weight: 760;
}
.scene-title h1 span {
color: rgba(226, 241, 239, 0.5);
font-weight: 390;
}
.scene-title > p {
max-width: 390px;
margin: 15px 0 0;
color: #aec3c2;
font-size: 12px;
line-height: 1.6;
}
.scene-tags {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 14px;
}
.scene-tag {
padding: 6px 9px;
border: 1px solid rgba(174, 220, 218, 0.16);
border-radius: 2px;
background: rgba(5, 20, 27, 0.55);
color: #b9cecc;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
.network-panel {
position: fixed;
z-index: 15;
top: 84px;
right: 18px;
bottom: 18px;
width: 365px;
overflow: auto;
border: 1px solid rgba(171, 221, 220, 0.17);
border-radius: 5px;
background:
linear-gradient(145deg, rgba(13, 39, 49, 0.94), rgba(6, 23, 31, 0.9));
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
scrollbar-width: thin;
scrollbar-color: rgba(112, 228, 209, 0.35) transparent;
}
.panel-head {
padding: 19px 19px 14px;
border-bottom: 1px solid var(--line);
}
.panel-head .eyebrow {
margin-bottom: 7px;
font-size: 9px;
}
.panel-head h2 {
margin: 0;
font-size: 22px;
letter-spacing: -0.035em;
font-weight: 700;
}
.panel-head p {
margin: 8px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.network-summary {
display: flex;
gap: 14px;
margin-top: 13px;
color: #9bb3b1;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.network-summary span {
display: flex;
align-items: center;
gap: 6px;
}
.network-summary i {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 9px rgba(112, 228, 209, 0.5);
}
.map-wrap {
position: relative;
margin: 12px 12px 0;
overflow: hidden;
border: 1px solid rgba(162, 215, 214, 0.1);
border-radius: 3px;
background:
radial-gradient(circle at 48% 48%, rgba(25, 74, 86, 0.28), transparent 57%),
#071a23;
}
#networkMap {
display: block;
width: 100%;
height: auto;
min-height: 220px;
}
.map-caption {
position: absolute;
left: 10px;
bottom: 8px;
padding: 4px 6px;
border: 1px solid rgba(160, 215, 213, 0.1);
background: rgba(4, 16, 23, 0.78);
color: #718d8c;
font-size: 8px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.map-route {
fill: none;
stroke: #4b8790;
stroke-width: 1.4;
stroke-dasharray: 4 5;
opacity: 0.38;
vector-effect: non-scaling-stroke;
cursor: pointer;
transition:
stroke 180ms ease,
stroke-width 180ms ease,
opacity 180ms ease;
}
.map-route:hover,
.map-route.active {
stroke: var(--cyan);
stroke-width: 2.3;
opacity: 1;
}
.map-route.active {
animation: routeDash 1.5s linear infinite;
filter: drop-shadow(0 0 3px rgba(112, 228, 209, 0.65));
}
@keyframes routeDash {
to {
stroke-dashoffset: -18;
}
}
.map-node {
cursor: pointer;
outline: none;
}
.map-node .node-halo {
fill: rgba(112, 228, 209, 0.04);
stroke: rgba(112, 228, 209, 0.24);
stroke-width: 1;
opacity: 0;
transition: opacity 180ms ease;
}
.map-node .node-core {
fill: #1c5660;
stroke: #83aaa9;
stroke-width: 1.2;
transition:
fill 180ms ease,
stroke 180ms ease,
r 180ms ease;
}
.map-node text {
fill: #a6bdbc;
font-size: 9px;
font-weight: 650;
pointer-events: none;
}
.map-node text.code {
fill: #648280;
font-size: 7px;
letter-spacing: 0.09em;
}
.map-node:hover .node-core,
.map-node:focus-visible .node-core,
.map-node.active .node-core {
fill: var(--cyan);
stroke: #d9fff6;
r: 5.2;
}
.map-node.active .node-halo {
opacity: 1;
}
.map-node:hover text,
.map-node.active text {
fill: #e7f6f2;
}
.map-node.home .node-core {
fill: var(--orange);
stroke: #ffe0ad;
stroke-width: 1.5;
}
.map-node.home text {
fill: #f5d8af;
}
.selected-card {
margin: 12px;
padding: 15px;
border: 1px solid rgba(112, 228, 209, 0.2);
border-radius: 3px;
background:
linear-gradient(135deg, rgba(112, 228, 209, 0.075), rgba(8, 28, 37, 0.48));
}
.card-meta {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
color: #87a2a0;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.source-pill {
padding: 4px 6px;
border: 1px solid rgba(112, 228, 209, 0.22);
border-radius: 2px;
color: var(--cyan);
background: rgba(112, 228, 209, 0.06);
}
.selected-card h3 {
margin: 11px 0 6px;
font-size: 18px;
letter-spacing: -0.025em;
}
.selected-card > p {
margin: 0;
color: #a7bfbd;
font-size: 10.5px;
line-height: 1.55;
}
.evidence-list {
margin: 13px 0 0;
padding: 0;
list-style: none;
}
.evidence-list li {
display: grid;
grid-template-columns: 75px 1fr;
gap: 8px;
padding: 7px 0;
border-top: 1px solid rgba(167, 215, 212, 0.1);
color: #789493;
font-size: 9px;
line-height: 1.4;
}
.evidence-list b {
color: #c3d5d3;
font-weight: 700;
}
.source-link {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid rgba(167, 215, 212, 0.1);
color: var(--cyan);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-decoration: none;
text-transform: uppercase;
}
.source-link:hover {
color: #b5fff0;
}
.panel-note {
padding: 1px 18px 18px;
color: #688381;
font-size: 9px;
line-height: 1.55;
}
.panel-note strong {
color: #9eb5b3;
}
.view-tools {
position: fixed;
z-index: 12;
left: 24px;
bottom: 24px;
display: flex;
gap: 8px;
}
.view-tools .button {
background: rgba(5, 21, 28, 0.75);
backdrop-filter: blur(8px);
}
.control-hint {
position: fixed;
z-index: 10;
left: 50%;
bottom: 26px;
transform: translateX(-50%);
padding: 8px 12px;
border: 1px solid rgba(160, 214, 212, 0.12);
border-radius: 999px;
background: rgba(5, 20, 27, 0.54);
color: #78928f;
font-size: 9px;
letter-spacing: 0.05em;
pointer-events: none;
backdrop-filter: blur(8px);
white-space: nowrap;
}
.world-label {
position: fixed;
z-index: 8;
padding: 5px 8px;
border-left: 2px solid var(--cyan);
background: rgba(5, 20, 27, 0.68);
color: #d9ece9;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
pointer-events: none;
transform: translate(-50%, -50%);
white-space: nowrap;
backdrop-filter: blur(5px);
}
.world-label.warm {
border-color: var(--orange);
}
.world-label.water {
border-color: rgba(112, 228, 209, 0.4);
color: #81b5b4;
background: rgba(5, 20, 27, 0.3);
}
#toast {
position: fixed;
z-index: 40;
left: 50%;
top: 82px;
max-width: min(460px, calc(100vw - 32px));
padding: 10px 14px;
border: 1px solid rgba(112, 228, 209, 0.3);
border-radius: 3px;
background: rgba(8, 30, 39, 0.94);
color: #d6e8e5;
box-shadow: 0 12px 35px rgba(0, 0, 0, 0.3);
font-size: 10px;
line-height: 1.45;
opacity: 0;
pointer-events: none;
transform: translate(-50%, -8px);
transition:
opacity 180ms ease,
transform 180ms ease;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
dialog {
width: min(720px, calc(100vw - 32px));
max-height: min(760px, calc(100vh - 40px));
padding: 0;
border: 1px solid rgba(166, 221, 217, 0.22);
border-radius: 5px;
background: #091f29;
color: var(--text);
box-shadow: 0 35px 100px rgba(0, 0, 0, 0.6);
}
dialog::backdrop {
background: rgba(2, 10, 15, 0.72);
backdrop-filter: blur(7px);
}
.dialog-head {
position: sticky;
z-index: 2;
top: 0;
padding: 19px 21px 15px;
border-bottom: 1px solid var(--line);
background: rgba(9, 31, 41, 0.96);
backdrop-filter: blur(12px);
}
.dialog-head h2 {
margin: 0;
font-size: 22px;
letter-spacing: -0.03em;
}
.dialog-head p {
margin: 7px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.dialog-close {
position: absolute;
top: 15px;
right: 16px;
width: 32px;
height: 32px;
border: 1px solid var(--line);
border-radius: 3px;
background: transparent;
color: #aac0be;
cursor: pointer;
font-size: 19px;
}
.dialog-body {
padding: 19px 21px 24px;
}
.method-note {
margin-bottom: 16px;
padding: 13px 14px;
border-left: 3px solid var(--orange);
background: rgba(243, 163, 75, 0.075);
color: #b9c9c6;
font-size: 10px;
line-height: 1.6;
}
.source-list {
display: grid;
gap: 9px;
}
.source-item {
padding: 13px 14px;
border: 1px solid rgba(164, 213, 211, 0.11);
border-radius: 3px;
background: rgba(16, 44, 54, 0.48);
}
.source-item .source-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
}
.source-item h3 {
margin: 0;
font-size: 13px;
}
.source-item .type {
color: var(--cyan);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
white-space: nowrap;
}
.source-item p {
margin: 6px 0 0;
color: #91aaa8;
font-size: 10px;
line-height: 1.55;
}
.source-item a {
display: inline-block;
margin-top: 9px;
color: var(--cyan);
font-size: 9px;
font-weight: 700;
text-decoration: none;
overflow-wrap: anywhere;
}
.source-item a:hover {
text-decoration: underline;
}
#loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
background: #071821;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
.loader {
width: min(320px, 75vw);
text-align: center;
}
.loader-line {
position: relative;
width: 100%;
height: 1px;
margin-bottom: 16px;
overflow: hidden;
background: rgba(112, 228, 209, 0.15);
}
.loader-line::after {
content: "";
position: absolute;
width: 42%;
height: 100%;
background: var(--cyan);
animation: loading 1.2s ease-in-out infinite;
}
@keyframes loading {
from {
transform: translateX(-110%);
}
to {
transform: translateX(350%);
}
}
.loader strong {
display: block;
font-size: 11px;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.loader span {
display: block;
margin-top: 7px;
color: var(--muted);
font-size: 9px;
}
@media (max-width: 1000px) {
.header-stats {
display: none;
}
.network-panel {
width: 330px;
}
.scene-title {
width: calc(100vw - 390px);
}
.control-hint {
display: none;
}
}
@media (max-width: 720px) {
.topbar {
height: 60px;
padding: 0 12px;
}
.brand-copy span {
display: none;
}
.brand-copy strong {
font-size: 10px;
}
.top-actions .button {
min-height: 32px;
padding: 0 9px;
font-size: 8px;
}
#resetView {
display: none;
}
.scene-title {
top: 76px;
left: 15px;
width: calc(100vw - 30px);
}
.scene-title h1 {
font-size: 38px;
}
.scene-title > p {
display: none;
}
.scene-tags {
margin-top: 10px;
}
.network-panel {
top: auto;
left: 9px;
right: 9px;
bottom: 9px;
width: auto;
max-height: 47vh;
}
.panel-head {
padding: 13px 15px 10px;
}
.panel-head h2 {
font-size: 17px;
}
.panel-head p,
.network-summary {
display: none;
}
.map-wrap {
display: none;
}
.selected-card {
margin: 9px;
padding: 12px;
}
.selected-card h3 {
margin-top: 8px;
font-size: 16px;
}
.evidence-list {
display: none;
}
.view-tools {
left: 12px;
bottom: calc(47vh + 18px);
}
.view-tools .button {
padding: 0 9px;
font-size: 8px;
}
.world-label {
display: none;
}
}
</style>
</head>
<body>
<div id="app">
<canvas id="scene" aria-label="Interactive low-poly model of Malacca Port"></canvas>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div class="brand-copy">
<strong>STRAIT / 01</strong>
<span>Regional maritime trade atlas</span>
</div>
</div>
<div class="header-stats" aria-label="Network summary">
<div class="header-stat"><b>07</b><span>Network nodes</span></div>
<div class="header-stat"><b>06</b><span>Trade corridors</span></div>
<div class="header-stat"><b>MY</b><span>Selected port</span></div>
</div>
<div class="top-actions">
<button class="button" id="resetView">Reset view</button>
<button class="button primary" id="openSources">Sources</button>
</div>
</header>
<section class="scene-title" aria-labelledby="sceneHeading">
<div class="eyebrow">Port within a network</div>
<h1 id="sceneHeading">Malacca <span>Port</span></h1>
<p>
A low-poly waterfront study of the Malaysian port, connected to
documented regional trade relationships and gateway nodes.
</p>
<div class="scene-tags">
<span class="scene-tag">Malaysia · MY</span>
<span class="scene-tag">Strait gateway</span>
<span class="scene-tag" id="connectionLabel">Melaka → Singapore</span>
</div>
</section>
<aside class="network-panel" aria-label="Regional sea-route network">
<div class="panel-head">
<div class="eyebrow">Schematic sea-route display</div>
<h2>One port, many connections</h2>
<p>
Select a node or corridor to highlight its connection in the 3D scene
and inspect the supporting trade evidence.
</p>
<div class="network-summary">
<span><i></i>Active corridor</span>
<span>Melaka at center</span>
<span>Not navigational</span>
</div>
</div>
<div class="map-wrap">
<svg
id="networkMap"
viewBox="0 0 640 320"
role="img"
aria-label="Schematic network linking Malacca to six regional gateway nodes"
>
<defs>
<pattern id="mapGrid" width="32" height="32" patternUnits="userSpaceOnUse">
<path
d="M32 0H0V32"
fill="none"
stroke="rgba(140,190,190,.055)"
stroke-width="1"
/>
</pattern>
<filter id="nodeGlow">
<feGaussianBlur stdDeviation="3" result="blur" />
<feMerge>
<feMergeNode in="blur" />
<feMergeNode in="SourceGraphic" />
</feMerge>
</filter>
</defs>
<rect width="640" height="320" fill="url(#mapGrid)" />
<!-- Deliberately simplified geography -->
<g fill="#15343d" stroke="#29505a" stroke-width="1">
<path d="M313 18 L590 18 L604 71 L548 100 L483 86 L437 111 L365 92 L320 69 Z" />
<path d="M361 91 L447 115 L480 160 L448 205 L402 193 L370 161 L330 143 Z" />
<path d="M14 42 L129 42 L147 86 L108 122 L42 111 L12 81 Z" />
<path d="M14 158 L95 166 L124 219 L100 287 L29 300 L9 252 Z" />
<path d="M213 117 L245 130 L250 166 L222 177 L203 151 Z" />
</g>
<g fill="none" stroke="rgba(110,175,175,.07)" stroke-width="1">
<path d="M0 106H640" />
<path d="M0 250H640" />
<path d="M184 0V320" />
<path d="M495 0V320" />
</g>
<g id="mapRoutes"></g>
<g id="mapNodes"></g>
</svg>
<div class="map-caption">Gateway nodes · regional abstraction</div>
</div>
<article class="selected-card" id="selectedCard" aria-live="polite"></article>
<div class="panel-note">
<strong>Reading note.</strong>
Trade lines represent documented commercial relationships or recognized
maritime corridors. They do not assert exact vessel itineraries, port
calls, or navigation tracks.
</div>
</aside>
<div class="view-tools" aria-label="Camera views">
<button class="button" id="quayView">Quay close-up</button>
<button class="button" id="overviewView">Full port</button>
</div>
<div class="control-hint">Drag to orbit · Wheel to zoom · Shift-drag to pan</div>
<div class="world-label" id="terminalLabel">Melaka container terminal</div>
<div class="world-label warm" id="shipLabel">Regional cargo service</div>
<div class="world-label water" id="straitLabel">Strait of Malacca</div>
<div id="toast" role="status" aria-live="polite"></div>
<dialog id="sourcesDialog">
<div class="dialog-head">
<h2>Evidence & sources</h2>
<p>Data and contextual sources used to construct the schematic network.</p>
<button class="dialog-close" id="closeSources" aria-label="Close sources">×</button>
</div>
<div class="dialog-body">
<div class="method-note">
<strong>Methodology.</strong>
Bilateral trade links use the United Nations Comtrade reporter/partner
framework. Gateway cities are representative network nodes, while
the Suez connection represents a recognized east–west maritime
corridor. Geographic positions and route curves are intentionally
schematic rather than navigational.
</div>
<div class="source-list" id="sourceList"></div>
</div>
</dialog>
<div id="loading">
<div class="loader">
<div class="loader-line"></div>
<strong>Constructing the waterfront</strong>
<span>Three.js · low-poly regional network</span>
</div>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (selector) => document.querySelector(selector);
const canvas = $("#scene");
// -------------------------------------------------------------------------
// Data model
// -------------------------------------------------------------------------
const sourceData = {
comtrade: {
name: "UN Comtrade Data Explorer",
type: "Bilateral trade data",
publisher: "United Nations Statistics Division",
url: "https://comtradeplus.un.org/",
note:
"Official international merchandise trade data. For each UN Comtrade connection, select Malaysia as reporter and the named partner country, then choose an annual period and the all-goods trade flow."
},
unctad: {
name: "Review of Maritime Transport 2024",
type: "Maritime corridor context",
publisher: "United Nations Conference on Trade and Development",
url: "https://unctad.org/publication/review-maritime-transport-2024",
note:
"Provides global maritime-trade and hub-connectivity context, including the strategic role of east–west shipping corridors and the Suez route."
},
pka: {
name: "Port Klang Authority",
type: "Official port-network context",
publisher: "Port Klang Authority, Malaysia",
url: "https://www.portauthority.com.my/",
note:
"Official information about Malaysia's principal container-port network. The Port Klang link represents a domestic gateway connection, not an international bilateral trade pair."
},
mpa: {
name: "Maritime and Port Authority of Singapore",
type: "Official port context",
publisher: "Maritime and Port Authority of Singapore",
url: "https://www.mpa.gov.sg/industry/port-statistics",
note:
"Official port statistics and strategic information supporting Singapore's role as a regional maritime gateway."
},
melaka: {
name: "Melaka State Government",
type: "Selected-port context",
publisher: "Government of Melaka",
url: "https://www.melaka.gov.my/",
note:
"Official state information and services used as the geographic and administrative context for the selected Melaka port node."
},
suez: {
name: "Suez Canal Authority",
type: "Official corridor context",
publisher: "Suez Canal Authority",
url: "https://www.suezcanal.gov.eg/",
note:
"Official information about the Suez Canal as the gateway represented by the Suez node in the schematic."
}
};
const routes = {
sg: {
partner: "Singapore",
code: "SG",
title: "Singapore gateway",
relation: "Malaysia–Singapore bilateral merchandise trade relationship.",
evidence: "Bilateral merchandise trade",
scope: "Reporter: Malaysia · All goods",
source: "comtrade",
sourceShort: "UN Comtrade",
support: ["mpa"],
path: "M294 184 C291 201 290 218 286 232",
direction: new THREE.Vector3(-0.08, 0, 0.35),
node: { x: 286, y: 232, dx: 11, dy: 14, anchor: "start" }
},
pk: {
partner: "Port Klang",
code: "MY",
title: "National port-network gateway",
relation: "Domestic connection between Melaka and Malaysia's principal container-port gateway.",
evidence: "National port-network link",
scope: "Malaysia · Gateway node",
source: "pka",
sourceShort: "Port Klang Authority",
support: [],
path: "M294 184 C310 170 324 160 340 153",
direction: new THREE.Vector3(0.22, 0, 0.45),
node: { x: 340, y: 153, dx: 11, dy: -7, anchor: "start" }
},
cn: {
partner: "Guangzhou",
code: "CN",
title: "China trade gateway",
relation: "Malaysia–China bilateral merchandise trade relationship, represented by the Guangzhou gateway.",
evidence: "Bilateral merchandise trade",
scope: "Reporter: Malaysia · All goods",
source: "comtrade",
sourceShort: "UN Comtrade",
support: [],
path: "M294 184 C356 155 425 98 478 84",
direction: new THREE.Vector3(0.65, 0, 0.68),
node: { x: 478, y: 84, dx: -10, dy: -8, anchor: "end" }
},
lk: {
partner: "Colombo",
code: "LK",
title: "South Asia gateway",
relation: "Malaysia–Sri Lanka bilateral merchandise trade relationship, represented by Colombo.",
evidence: "Bilateral merchandise trade",
scope: "Reporter: Malaysia · All goods",
source: "comtrade",
sourceShort: "UN Comtrade",
support: [],
path: "M294 184 C266 147 235 110 205 93",
direction: new THREE.Vector3(-0.15, 0, 0.68),
node: { x: 205, y: 93, dx: -10, dy: -8, anchor: "end" }
},
nl: {
partner: "Rotterdam",
code: "NL",
title: "North Sea gateway",
relation: "Malaysia–Netherlands bilateral merchandise trade relationship, represented by Rotterdam.",
evidence: "Bilateral merchandise trade",
scope: "Reporter: Malaysia · All goods",
source: "comtrade",
sourceShort: "UN Comtrade",
support: [],
path: "M294 184 C240 95 132 72 75 60",
direction: new THREE.Vector3(-0.72, 0, -0.60),
node: { x: 75, y: 60, dx: -10, dy: -8, anchor: "end" }
},
suez: {
partner: "Suez",
code: "EG",
title: "East–west corridor gateway",
relation: "Recognized east–west maritime corridor connecting Asian trade with the Suez gateway.",
evidence: "Maritime corridor",
scope: "Regional gateway · Not a trade pair",
source: "unctad",
sourceShort: "UNCTAD RMT",
support: ["suez"],
path: "M294 184 C218 181 125 190 68 211",
direction: new THREE.Vector3(-0.80, 0, 0.08),
node: { x: 68, y: 211, dx: -10, dy: 15, anchor: "end" }
}
};
const nodePositions = {
malacca: { x: 294, y: 184, dx: 13, dy: -8, anchor: "start" }
};
const state = {
route: "sg",
camera: {
target: new THREE.Vector3(8, 3, 0),
radius: 112,
theta: -0.88,
phi: 0.82
}
};
// -------------------------------------------------------------------------
// Build schematic network SVG
// -------------------------------------------------------------------------
$("#mapRoutes").innerHTML = Object.entries(routes)
.map(
([id, route]) =>
`<path class="map-route" data-route="${id}" d="${route.path}" tabindex="0" role="button" aria-label="Select ${route.partner} connection"></path>`
)
.join("");
const partnerNodes = Object.entries(routes)
.map(([id, route]) => {
const p = route.node;
return `
<g class="map-node" data-route="${id}" tabindex="0" role="button"
aria-label="Select ${route.partner} connection"
transform="translate(${p.x} ${p.y})">
<circle class="node-halo" r="10"></circle>
<circle class="node-core" r="3.7"></circle>
<text x="${p.dx}" y="${p.dy}" text-anchor="${p.anchor}">${route.partner}</text>
<text class="code" x="${p.dx}" y="${p.dy + 10}" text-anchor="${p.anchor}">${route.code}</text>
</g>
`;
})
.join("");
const melaka = nodePositions.malacca;
$("#mapNodes").innerHTML = `
<g class="map-node home" data-node="malacca" tabindex="0" role="button"
aria-label="Select Malacca and Singapore corridor"
transform="translate(${melaka.x} ${melaka.y})">
<circle class="node-halo" r="13"></circle>
<circle class="node-core" r="5.2" filter="url(#nodeGlow)"></circle>
<text x="${melaka.dx}" y="${melaka.dy}" text-anchor="${melaka.anchor}">MELAKA</text>
<text class="code" x="${melaka.dx}" y="${melaka.dy + 10}" text-anchor="${melaka.anchor}">SELECTED · MY</text>
</g>
${partnerNodes}
`;
$("#sourceList").innerHTML = Object.entries(sourceData)
.map(
([id, source]) => `
<article class="source-item" id="source-${id}">
<div class="source-top">
<h3>${source.name}</h3>
<span class="type">${source.type}</span>
</div>
<p>${source.publisher}. ${source.note}</p>
<a href="${source.url}" target="_blank" rel="noopener noreferrer">
Open official source ↗
</a>
</article>
`
)
.join("");
function setActiveRoute(id) {
if (!routes[id]) return;
state.route = id;
const route = routes[id];
document.querySelectorAll(".map-route").forEach((path) => {
path.classList.toggle("active", path.dataset.route === id);
});
document.querySelectorAll(".map-node").forEach((node) => {
node.classList.toggle("active", node.dataset.route === id);
});
$("#connectionLabel").textContent = `Melaka → ${route.partner}`;
const source = sourceData[route.source];
const supporting = route.support.length
? route.support
.map((supportId) => sourceData[supportId])
.map((item) => item.name)
.join(" · ")
: "UN Comtrade reporter/partner search";
$("#selectedCard").innerHTML = `
<div class="card-meta">
<span class="source-pill">${route.sourceShort}</span>
<span>MY → ${route.code}</span>
</div>
<h3>${route.title}</h3>
<p>${route.relation}</p>
<ul class="evidence-list">
<li><b>Evidence</b><span>${route.evidence}</span></li>
<li><b>Scope</b><span>${route.scope}</span></li>
<li><b>Context</b><span>${supporting}</span></li>
</ul>
<a class="source-link" href="${source.url}" target="_blank" rel="noopener noreferrer">
Open ${source.name} <span>↗</span>
</a>
`;
updateRouteVisuals();
}
document.querySelectorAll("[data-route]").forEach((element) => {
const activate = () => setActiveRoute(element.dataset.route);
element.addEventListener("click", activate);
element.addEventListener("keydown", (event) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
activate();
}
});
});
$('[data-node="malacca"]').addEventListener("click", () => setActiveRoute("sg"));
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: 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.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.setClearColor(0x071821, 0);
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x081a24, 0.0047);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
500
);
const ambient = new THREE.HemisphereLight(0x9fd8dd, 0x15232a, 1.65);
scene.add(ambient);
const sun = new THREE.DirectionalLight(0xffd8a6, 3.3);
sun.position.set(-45, 70, 40);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -100;
sun.shadow.camera.right = 100;
sun.shadow.camera.top = 90;
sun.shadow.camera.bottom = -90;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 220;
sun.shadow.bias = -0.00035;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x62d7e2, 1.1);
rim.position.set(55, 24, -65);
scene.add(rim);
const world = new THREE.Group();
scene.add(world);
const pickables = [];
const materials = {
water: new THREE.MeshStandardMaterial({
color: 0x0b5969,
roughness: 0.38,
metalness: 0.18,
transparent: true,
opacity: 0.96,
flatShading: true
}),
land: new THREE.MeshStandardMaterial({
color: 0x50605d,
roughness: 0.94,
flatShading: true
}),
quay: new THREE.MeshStandardMaterial({
color: 0x8c9187,
roughness: 0.88,
flatShading: true
}),
asphalt: new THREE.MeshStandardMaterial({
color: 0x26383d,
roughness: 0.95
}),
orange: new THREE.MeshStandardMaterial({
color: 0xf0a044,
roughness: 0.56,
metalness: 0.08,
flatShading: true
}),
darkMetal: new THREE.MeshStandardMaterial({
color: 0x263237,
roughness: 0.62,
metalness: 0.42,
flatShading: true
}),
white: new THREE.MeshStandardMaterial({
color: 0xd9dfd7,
roughness: 0.7,
flatShading: true
}),
roof: new THREE.MeshStandardMaterial({
color: 0x3d6970,
roughness: 0.72,
flatShading: true
}),
roadPaint: new THREE.MeshStandardMaterial({
color: 0xc5b989,
roughness: 0.9
})
};
const containerMaterials = [
0xc75e4b,
0xd98a45,
0x477f88,
0x718e5d,
0xb8a85d,
0x596f86
].map(
(color) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.05,
flatShading: true
})
);
function addBox(parent, width, height, depth, material, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
segments,
material,
x = 0,
y = 0,
z = 0
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Low-poly animated water
const waterGeometry = new THREE.PlaneGeometry(190, 140, 24, 18);
waterGeometry.rotateX(-Math.PI / 2);
const waterBase = new Float32Array(
waterGeometry.attributes.position.array.length
);
for (let i = 0; i < waterGeometry.attributes.position.count; i++) {
waterBase[i * 3] = waterGeometry.attributes.position.getX(i);
waterBase[i * 3 + 2] = waterGeometry.attributes.position.getZ(i);
}
const water = new THREE.Mesh(waterGeometry, materials.water);
water.position.y = 0;
water.receiveShadow = true;
world.add(water);
// Subtle water grid
const gridPoints = [];
for (let x = -90; x <= 10; x += 10) {
gridPoints.push(x, 0.09, -65, x, 0.09, 65);
}
for (let z = -60; z <= 60; z += 10) {
gridPoints.push(-90, 0.09, z, 10, 0.09, z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPoints, 3)
);
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x82c9c8,
transparent: true,
opacity: 0.075
})
);
world.add(grid);
// Port land and quay
const port = new THREE.Group();
world.add(port);
const land = addBox(
port,
70,
2.4,
100,
materials.land,
48,
0.45,
0
);
land.receiveShadow = true;
addBox(port, 5, 1.5, 97, materials.quay, 11.5, 0.85, 0);
addBox(port, 1.2, 0.34, 97, materials.white, 8.7, 1.75, 0);
addBox(port, 12, 0.18, 96, materials.asphalt, 43, 1.72, 0);
// Road lane markers
for (let z = -43; z <= 43; z += 8) {
addBox(port, 0.35, 0.035, 3.2, materials.roadPaint, 43, 1.83, z);
}
// Container yard
let stackIndex = 0;
for (let z = -40; z <= 38; z += 9) {
for (const x of [18.5, 25.2, 31.9]) {
const levels = 1 + ((Math.abs(Math.round(z + x)) + stackIndex) % 3 === 0 ? 1 : 0);
for (let level = 0; level < levels; level++) {
const material =
containerMaterials[
(Math.abs(Math.round(z + x * 2)) + level + stackIndex) %
containerMaterials.length
];
const container = addBox(
port,
5.8,
2.65,
2.75,
material,
x,
3.05 + level * 2.72,
z
);
container.userData.info = "Container stack · regional cargo transfer point";
pickables.push(container);
}
stackIndex++;
}
}
// Gantry cranes
function createCrane(z, index) {
const crane = new THREE.Group();
crane.position.set(9, 1.75, z);
port.add(crane);
const pieces = [
addBox(crane, 0.7, 14, 0.7, materials.orange, 0, 7, 2.1),
addBox(crane, 0.7, 14, 0.7, materials.orange, 0, 7, -2.1),
addBox(crane, 0.7, 14, 0.7, materials.orange, 4.5, 7, 2.1),
addBox(crane, 0.7, 14, 0.7, materials.orange, 4.5, 7, -2.1),
addBox(crane, 7, 0.7, 5.4, materials.orange, 2.2, 14.2, 0),
addBox(crane, 29, 0.65, 0.85, materials.orange, 1.3, 15.0, 0),
addBox(crane, 0.07, 8.2, 0.07, materials.darkMetal, -10.5, 10.7, 0),
addBox(crane, 3.2, 0.25, 2.2, materials.darkMetal, -10.5, 6.5, 0)
];
pieces.forEach((piece) => {
piece.userData.info = `Ship-to-shore gantry crane ${index + 1} · quay cargo handling`;
pickables.push(piece);
});
}
[-31, -6, 19, 39].forEach(createCrane);
// Warehouses
[-31, -9, 13, 35].forEach((z, index) => {
const warehouse = addBox(
port,
14,
6,
17,
materials.white,
58,
4.7,
z
);
addBox(port, 15, 0.8, 18, materials.roof, 58, 8, z);
warehouse.userData.info = `Port warehouse ${index + 1} · inland and maritime logistics`;
pickables.push(warehouse);
});
// Storage tanks
for (let i = 0; i < 3; i++) {
const tank = addCylinder(
port,
4.3,
4.3,
5.5,
8,
materials.white,
67,
4.4,
-43 + i * 10
);
tank.userData.info = "Bulk-liquid storage · low-poly terminal asset";
pickables.push(tank);
}
// Simplified port city
for (let i = 0; i < 12; i++) {
const height = 5 + ((i * 7) % 11);
const building = addBox(
port,
4.4 + (i % 3),
height,
6.5,
i % 3 === 0 ? materials.roof : materials.white,
74 + (i % 2) * 4,
1.65 + height / 2,
-45 + i * 8
);
building.userData.info = "Port-city edge · simplified low-poly massing";
pickables.push(building);
}
// Trucks
for (let i = 0; i < 7; i++) {
const truck = new THREE.Group();
truck.position.set(43, 2, -38 + i * 13);
truck.rotation.y = i % 2 ? Math.PI : 0;
port.add(truck);
const body = addBox(
truck,
2.3,
2.2,
5.5,
containerMaterials[i % containerMaterials.length],
0,
1.4,
0
);
addBox(truck, 2.1, 1.7, 1.8, materials.white, 0, 1.1, 3.3);
body.userData.info = "Intermodal transfer vehicle · quay logistics";
pickables.push(body);
}
// Coastal rocks and low-poly details
for (let i = 0; i < 25; i++) {
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.7 + (i % 3) * 0.22, 0),
materials.quay
);
rock.position.set(8.8, 1.5, -47 + i * 4);
rock.scale.set(1, 0.65, 1.2);
rock.castShadow = true;
port.add(rock);
}
// Cargo ship
const ship = new THREE.Group();
ship.position.set(-4.7, 0, 6);
world.add(ship);
const hullShape = new THREE.Shape();
hullShape.moveTo(0, -19);
hullShape.lineTo(4.7, -13);
hullShape.lineTo(4.7, 13);
hullShape.lineTo(0, 19);
hullShape.lineTo(-4.7, 13);
hullShape.lineTo(-4.7, -13);
hullShape.closePath();
const hullGeometry = new THREE.ExtrudeGeometry(hullShape, {
depth: 3.5,
bevelEnabled: true,
bevelSegments: 1,
bevelSize: 0.35,
bevelThickness: 0.35,
curveSegments: 1
});
hullGeometry.rotateX(Math.PI / 2);
const hullMaterial = new THREE.MeshStandardMaterial({
color: 0x9b493d,
roughness: 0.7,
metalness: 0.12,
flatShading: true
});
const hull = new THREE.Mesh(hullGeometry, hullMaterial);
hull.position.y = 2.35;
hull.castShadow = true;
hull.receiveShadow = true;
ship.add(hull);
const deck = addBox(ship, 8.7, 0.35, 23, materials.darkMetal, 0, 2.55, 0);
deck.userData.info = "Container vessel · active regional cargo corridor";
pickables.push(deck);
for (let row = 0; row < 4; row++) {
for (let col = 0; col < 3; col++) {
const levels = row < 2 ? 2 : 1;
for (let level = 0; level < levels; level++) {
addBox(
ship,
2.25,
1.55,
3.9,
containerMaterials[(row + col + level + 1) % containerMaterials.length],
-2.65 + col * 2.65,
3.55 + level * 1.58,
-5 + row * 4.8
);
}
}
}
const bridge = addBox(ship, 7.2, 5, 4.6, materials.white, 0, 5.3, -12.3);
bridge.userData.info = "Vessel bridge and accommodation block";
pickables.push(bridge);
addBox(ship, 5.7, 0.7, 4.4, materials.darkMetal, 0, 8.1, -12.3);
addBox(ship, 0.16, 4.5, 0.16, materials.white, 0, 10.5, -12.3);
addBox(ship, 3.8, 0.12, 0.12, materials.white, 0, 11.9, -12.3);
// Selected-port beacon over water
const beacon = new THREE.Mesh(
new THREE.TorusGeometry(4.1, 0.12, 6, 48),
new THREE.MeshBasicMaterial({
color: 0x70e4d1,
transparent: true,
opacity: 0.6
})
);
beacon.rotation.x = Math.PI / 2;
beacon.position.set(-2, 0.32, 10);
world.add(beacon);
const beaconCore = new THREE.Mesh(
new THREE.OctahedronGeometry(0.9, 0),
new THREE.MeshStandardMaterial({
color: 0x70e4d1,
emissive: 0x286f65,
emissiveIntensity: 1.6,
roughness: 0.35
})
);
beaconCore.position.copy(beacon.position);
beaconCore.position.y = 0.8;
world.add(beaconCore);
// -------------------------------------------------------------------------
// Linked 3D sea-route visuals
// -------------------------------------------------------------------------
const routeVisuals = {};
Object.entries(routes).forEach(([id, route], routeIndex) => {
const origin = new THREE.Vector3(-2, 0.55, 10);
const direction = route.direction.clone().normalize();
const end = origin.clone().addScaledVector(direction, 86);
end.y = 0.7;
const control1 = origin.clone().addScaledVector(direction, 25);
control1.y = 13;
const control2 = origin.clone().addScaledVector(direction, 57);
control2.y = 10;
const curve = new THREE.CubicBezierCurve3(
origin,
control1,
control2,
end
);
const lineMaterial = new THREE.LineDashedMaterial({
color: 0x68b7ba,
transparent: true,
opacity: 0.3,
dashSize: 2.1,
gapSize: 1.6,
scale: 1
});
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(curve.getPoints(100)),
lineMaterial
);
line.computeLineDistances();
world.add(line);
const tubeMaterial = new THREE.MeshBasicMaterial({
color: 0x70e4d1,
transparent: true,
opacity: 0.08,
depthWrite: false
});
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 80, 0.09, 5, false),
tubeMaterial
);
world.add(tube);
const packet = new THREE.Mesh(
new THREE.OctahedronGeometry(0.65, 0),
new THREE.MeshBasicMaterial({ color: 0xa5fff0 })
);
world.add(packet);
routeVisuals[id] = {
curve,
line,
lineMaterial,
tube,
tubeMaterial,
packet,
offset: routeIndex * 0.17
};
});
function updateRouteVisuals() {
Object.entries(routeVisuals).forEach(([id, visual]) => {
const selected = id === state.route;
visual.lineMaterial.opacity = selected ? 0.95 : 0.18;
visual.lineMaterial.color.setHex(selected ? 0x70e4d1 : 0x4f99a0);
visual.tubeMaterial.opacity = selected ? 0.48 : 0.035;
visual.tubeMaterial.color.setHex(selected ? 0x70e4d1 : 0x4f99a0);
visual.packet.visible = selected;
visual.packet.scale.setScalar(selected ? 1.15 : 0.7);
});
}
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, touch pinch
// -------------------------------------------------------------------------
const pointers = new Map();
let gesture = null;
let previousPinchDistance = 0;
function updateCamera() {
const { target, radius, theta, phi } = state.camera;
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + radius * sinPhi * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
function setOverview() {
state.camera.target.set(8, 3, 0);
state.camera.radius = 112;
state.camera.theta = -0.88;
state.camera.phi = 0.82;
updateCamera();
}
function setQuayView() {
state.camera.target.set(7, 5, 1);
state.camera.radius = 53;
state.camera.theta = -0.72;
state.camera.phi = 0.89;
updateCamera();
}
function panCamera(dx, dy) {
const factor = (state.camera.radius / window.innerHeight) * 1.45;
const right = new THREE.Vector3(1, 0, 0).applyQuaternion(camera.quaternion);
const up = new THREE.Vector3(0, 1, 0).applyQuaternion(camera.quaternion);
state.camera.target.addScaledVector(right, -dx * factor);
state.camera.target.addScaledVector(up, dy * factor);
state.camera.target.x = THREE.MathUtils.clamp(
state.camera.target.x,
-25,
65
);
state.camera.target.y = THREE.MathUtils.clamp(
state.camera.target.y,
0,
14
);
state.camera.target.z = THREE.MathUtils.clamp(
state.camera.target.z,
-48,
48
);
}
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
gesture = {
id: event.pointerId,
lastX: event.clientX,
lastY: event.clientY,
startX: event.clientX,
startY: event.clientY,
moved: 0,
pan: event.button === 2 || event.shiftKey
};
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
previousPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (previousPinchDistance > 0) {
state.camera.radius = THREE.MathUtils.clamp(
state.camera.radius * (previousPinchDistance / distance),
32,
190
);
}
previousPinchDistance = distance;
return;
}
if (!gesture || gesture.id !== event.pointerId) return;
const dx = event.clientX - gesture.lastX;
const dy = event.clientY - gesture.lastY;
gesture.moved += Math.hypot(dx, dy);
if (gesture.pan) {
panCamera(dx, dy);
} else {
state.camera.theta -= dx * 0.006;
state.camera.phi = THREE.MathUtils.clamp(
state.camera.phi + dy * 0.005,
0.25,
1.45
);
}
gesture.lastX = event.clientX;
gesture.lastY = event.clientY;
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) {
previousPinchDistance = 0;
}
if (
gesture &&
gesture.id === event.pointerId &&
gesture.moved < 6
) {
pickScene(event);
}
if (pointers.size === 0) {
gesture = null;
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const factor = Math.exp(event.deltaY * 0.001);
state.camera.radius = THREE.MathUtils.clamp(
state.camera.radius * factor,
32,
190
);
},
{ passive: false }
);
// Scene picking
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
function pickScene(event) {
const rect = canvas.getBoundingClientRect();
pointerNDC.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
const hits = raycaster.intersectObjects(pickables, false);
if (hits.length) {
showToast(hits[0].object.userData.info || "Port asset");
}
}
let toastTimer;
function showToast(message) {
const toast = $("#toast");
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2200);
}
$("#resetView").addEventListener("click", setOverview);
$("#overviewView").addEventListener("click", setOverview);
$("#quayView").addEventListener("click", setQuayView);
// Sources dialog
const sourcesDialog = $("#sourcesDialog");
$("#openSources").addEventListener("click", () => {
if (typeof sourcesDialog.showModal === "function") {
sourcesDialog.showModal();
} else {
sourcesDialog.setAttribute("open", "");
}
});
$("#closeSources").addEventListener("click", () => {
if (typeof sourcesDialog.close === "function") {
sourcesDialog.close();
} else {
sourcesDialog.removeAttribute("open");
}
});
sourcesDialog.addEventListener("click", (event) => {
if (event.target === sourcesDialog) {
sourcesDialog.close();
}
});
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
const worldLabels = [
{
element: $("#terminalLabel"),
position: new THREE.Vector3(21, 16, -12)
},
{
element: $("#shipLabel"),
position: new THREE.Vector3(-4.5, 11, 8)
},
{
element: $("#straitLabel"),
position: new THREE.Vector3(-30, 1, -34)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
worldLabels.forEach(({ element, position }) => {
projected.copy(position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.1 &&
Math.abs(projected.y) < 1.1;
element.style.display = visible ? "block" : "none";
if (visible) {
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
});
}
// -------------------------------------------------------------------------
// Animation loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let frame = 0;
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const delta = Math.min(clock.getDelta(), 0.05);
frame++;
// Gentle low-poly water movement
const positions = waterGeometry.attributes.position;
for (let i = 0; i < positions.count; i++) {
const x = waterBase[i * 3];
const z = waterBase[i * 3 + 2];
positions.setY(
i,
Math.sin(x * 0.09 + elapsed * 0.7) * 0.16 +
Math.cos(z * 0.115 - elapsed * 0.55) * 0.1
);
}
positions.needsUpdate = true;
if (frame % 5 === 0) waterGeometry.computeVertexNormals();
ship.position.y = Math.sin(elapsed * 0.75) * 0.08;
ship.rotation.z = Math.sin(elapsed * 0.42) * 0.004;
beacon.rotation.z = elapsed * 0.18;
const beaconScale = 1 + Math.sin(elapsed * 2) * 0.08;
beacon.scale.setScalar(beaconScale);
beaconCore.rotation.y = elapsed * 0.9;
beaconCore.rotation.x = elapsed * 0.45;
Object.values(routeVisuals).forEach((visual) => {
const t = (elapsed * 0.075 + visual.offset) % 1;
visual.packet.position.copy(visual.curve.getPoint(t));
visual.packet.rotation.x = elapsed * 1.5;
visual.packet.rotation.y = elapsed * 1.1;
});
updateCamera();
updateLabels();
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
setActiveRoute("sg");
setOverview();
animate();
requestAnimationFrame(() => {
$("#loading").classList.add("hidden");
setTimeout(() => $("#loading").remove(), 450);
});
</script>
</body>
</html>
```