Prompt specification
Build or customize the Three.js 3D scene "Mediterranean and Red Sea route comparison" 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: Mediterranean and Red Sea route comparison
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/mediterranean-and-red-sea-route-comparison-x2479
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: Mediterranean and Red Sea route comparison. Build a schematic regional model showing the Suez connection and the longer route around Africa. Keep distances illustrative and include the canal's broader labor and political context in notes.
Working Three.js Starter (mediterranean-and-red-sea-route-comparison-x2479):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#07151c" />
<title>Suez vs. the Long Way South</title>
<style>
:root {
color-scheme: dark;
--ink: #eef6f4;
--muted: #9eb3b7;
--panel: rgba(7, 21, 28, 0.86);
--panel-strong: rgba(8, 24, 31, 0.95);
--line: rgba(207, 229, 227, 0.16);
--suez: #ffca66;
--cape: #4de0ea;
--paper: #f5f0df;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07151c;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
summary {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
#scene:active {
cursor: grabbing;
}
.ui {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.masthead {
position: absolute;
top: 28px;
left: 30px;
width: min(560px, calc(100vw - 390px));
filter: drop-shadow(0 8px 28px rgba(0, 0, 0, 0.28));
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
color: #c7d7d5;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--suez);
box-shadow: 0 0 0 5px rgba(255, 202, 102, 0.12);
content: "";
}
h1 {
max-width: 560px;
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(35px, 4.5vw, 67px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.045em;
text-wrap: balance;
}
.dek {
max-width: 510px;
margin: 15px 0 0;
color: #b8c9c8;
font-size: 14px;
line-height: 1.55;
}
.panel {
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.26);
backdrop-filter: blur(18px) saturate(125%);
-webkit-backdrop-filter: blur(18px) saturate(125%);
}
.route-panel {
position: absolute;
top: 26px;
right: 26px;
width: 344px;
padding: 19px;
pointer-events: auto;
}
.panel-kicker {
margin: 0 0 6px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.panel-title {
margin: 0 0 16px;
font-family: Georgia, "Times New Roman", serif;
font-size: 22px;
font-weight: 500;
}
.route-row {
margin-top: 15px;
}
.route-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
}
.route-name {
display: flex;
min-width: 0;
align-items: center;
gap: 9px;
color: #eef5f2;
font-size: 13px;
font-weight: 680;
}
.route-name .dot {
flex: 0 0 auto;
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--route-color);
box-shadow: 0 0 14px color-mix(in srgb, var(--route-color) 65%, transparent);
}
.distance {
flex: 0 0 auto;
font-variant-numeric: tabular-nums;
color: var(--route-color);
font-size: 13px;
font-weight: 800;
}
.route-sub {
margin: 5px 0 0 18px;
color: var(--muted);
font-size: 11px;
}
.meter {
height: 4px;
margin: 10px 0 0 18px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.08);
}
.meter > span {
display: block;
width: var(--meter-width);
height: 100%;
border-radius: inherit;
background: var(--route-color);
box-shadow: 0 0 14px color-mix(in srgb, var(--route-color) 50%, transparent);
}
.delta {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-top: 18px;
padding: 12px 13px;
border: 1px solid rgba(255, 202, 102, 0.18);
border-radius: 11px;
background: rgba(255, 202, 102, 0.055);
}
.delta strong {
color: var(--suez);
font-size: 12px;
}
.delta span {
color: var(--muted);
font-size: 11px;
line-height: 1.4;
text-align: right;
}
.fine-print {
margin: 11px 2px 0;
color: #81979b;
font-size: 10px;
line-height: 1.45;
}
.view-controls {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 15px;
}
.view-controls button {
min-height: 36px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.045);
color: #d8e6e4;
cursor: pointer;
font-size: 11px;
font-weight: 700;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
.view-controls button:hover {
border-color: rgba(255, 255, 255, 0.3);
background: rgba(255, 255, 255, 0.09);
transform: translateY(-1px);
}
.context {
position: absolute;
bottom: 26px;
left: 26px;
width: min(450px, calc(100vw - 420px));
overflow: hidden;
pointer-events: auto;
}
.context summary {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
padding: 15px 17px;
color: #e3eeeb;
cursor: pointer;
font-size: 12px;
font-weight: 720;
list-style: none;
}
.context summary::-webkit-details-marker {
display: none;
}
.context summary::after {
color: var(--suez);
font-size: 17px;
content: "+";
}
.context[open] summary::after {
content: "−";
}
.context-body {
padding: 0 17px 16px;
border-top: 1px solid var(--line);
}
.context-body p {
margin: 12px 0 0;
color: #b4c5c4;
font-size: 11px;
line-height: 1.58;
}
.context-body strong {
color: #edf4f1;
font-weight: 700;
}
.context-note {
margin-top: 13px !important;
padding-top: 11px;
border-top: 1px dashed rgba(255, 255, 255, 0.12);
color: #82999c !important;
font-size: 10px !important;
}
.hint {
position: absolute;
bottom: 30px;
left: 50%;
display: flex;
align-items: center;
gap: 9px;
padding: 9px 13px;
border: 1px solid rgba(255, 255, 255, 0.11);
border-radius: 99px;
background: rgba(5, 18, 24, 0.66);
color: #9cb0b2;
font-size: 10px;
white-space: nowrap;
transform: translateX(-50%);
backdrop-filter: blur(10px);
}
.hint b {
color: #d9e6e3;
font-weight: 700;
}
.compass {
position: absolute;
right: 34px;
bottom: 28px;
display: grid;
place-items: center;
width: 52px;
height: 52px;
border: 1px solid var(--line);
border-radius: 50%;
background: rgba(7, 21, 28, 0.7);
color: #dce9e6;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
backdrop-filter: blur(10px);
}
.compass::before {
position: absolute;
top: 5px;
border-right: 4px solid transparent;
border-bottom: 8px solid var(--suez);
border-left: 4px solid transparent;
content: "";
}
#labels {
position: fixed;
inset: 0;
z-index: 3;
overflow: hidden;
pointer-events: none;
}
.map-label {
position: absolute;
left: 0;
top: 0;
color: #eef5f1;
font-size: 10px;
font-weight: 730;
letter-spacing: 0.08em;
line-height: 1.2;
text-align: center;
text-shadow:
0 1px 2px #061319,
0 0 8px #061319,
0 0 14px #061319;
white-space: nowrap;
transform: translate(-50%, -50%);
will-change: transform;
}
.map-label.water {
color: #9dd8e2;
font-family: Georgia, "Times New Roman", serif;
font-size: 12px;
font-style: italic;
font-weight: 500;
letter-spacing: 0.02em;
opacity: 0.88;
}
.map-label.region {
color: rgba(245, 240, 223, 0.82);
font-family: Georgia, "Times New Roman", serif;
font-size: 16px;
font-weight: 500;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.map-label.place {
color: #f4f7f2;
font-size: 10px;
}
.map-label.place::before {
display: inline-block;
width: 4px;
height: 4px;
margin-right: 6px;
border-radius: 50%;
background: #eaf4ef;
content: "";
vertical-align: 2px;
}
.map-label.critical {
padding: 5px 7px;
border: 1px solid rgba(255, 202, 102, 0.46);
border-radius: 5px;
background: rgba(5, 19, 24, 0.78);
color: #ffe19d;
font-size: 9px;
}
.map-label.route {
padding: 5px 8px;
border: 1px solid color-mix(in srgb, var(--label-color) 48%, transparent);
border-radius: 99px;
background: rgba(4, 17, 23, 0.74);
color: var(--label-color);
font-size: 9px;
letter-spacing: 0.11em;
text-transform: uppercase;
}
@media (max-width: 900px) {
.masthead {
width: calc(100vw - 370px);
}
.context {
width: calc(100vw - 390px);
}
.hint {
display: none;
}
}
@media (max-width: 700px) {
.masthead {
top: 18px;
left: 18px;
width: calc(100vw - 36px);
}
h1 {
max-width: 360px;
font-size: 38px;
}
.dek {
display: none;
}
.route-panel {
top: 142px;
right: 12px;
width: min(315px, calc(100vw - 24px));
padding: 15px;
}
.route-panel .panel-title {
margin-bottom: 12px;
font-size: 19px;
}
.context {
bottom: 12px;
left: 12px;
width: calc(100vw - 24px);
}
.context[open] {
max-height: 42vh;
overflow-y: auto;
}
.compass {
display: none;
}
.map-label.region {
font-size: 13px;
}
.map-label.water {
font-size: 10px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel map comparing the Suez route with the sea route around Africa"></canvas>
<div id="labels" aria-hidden="true"></div>
<main class="ui">
<header class="masthead">
<div class="eyebrow">Route atlas · comparative geography</div>
<h1>Suez vs. the long way south</h1>
<p class="dek">
A schematic voxel model of the Mediterranean–Suez–Red Sea corridor and the
much longer passage around Africa.
</p>
</header>
<aside class="panel route-panel" aria-label="Illustrative route comparison">
<p class="panel-kicker">Illustrative voyage</p>
<h2 class="panel-title">Rotterdam → Singapore</h2>
<div class="route-row" style="--route-color: var(--suez); --meter-width: 65%;">
<div class="route-heading">
<div class="route-name"><span class="dot"></span>Via Suez</div>
<div class="distance">≈15,500 km</div>
</div>
<div class="route-sub">Mediterranean · Suez · Red Sea · Indian Ocean</div>
<div class="meter"><span></span></div>
</div>
<div class="route-row" style="--route-color: var(--cape); --meter-width: 100%;">
<div class="route-heading">
<div class="route-name"><span class="dot"></span>Around the Cape</div>
<div class="distance">≈24,000 km</div>
</div>
<div class="route-sub">Atlantic · Cape of Good Hope · Indian Ocean</div>
<div class="meter"><span></span></div>
</div>
<div class="delta">
<strong>+≈8,500 km</strong>
<span>about 55% more distance<br />for the Cape route</span>
</div>
<p class="fine-print">
Rounded comparison values only. Distances depend on ports, traffic lanes,
weather, and routing; this model is not for navigation.
</p>
<div class="view-controls">
<button id="reset-view" type="button">Reset view</button>
<button id="top-view" type="button">Top view</button>
</div>
</aside>
<details class="panel context" open>
<summary>Context: labor, empire & present-day politics</summary>
<div class="context-body">
<p>
<strong>Construction, 1859–69.</strong> The canal was built under Khedive
Ismail’s Egyptian government. Egyptian workers were joined by laborers
recruited or conscripted from Ottoman territories and by European
contractors and engineers. The exact balance between coerced, conscripted,
and paid labor remains debated, but the project was marked by harsh
conditions, deaths, and displacement.
</p>
<p>
<strong>Imperial power.</strong> Britain acquired a major share of the canal
company in 1875 and occupied Egypt in 1882. The canal consequently became
both a commercial artery and a strategic instrument of imperial control.
</p>
<p>
<strong>Today.</strong> The canal remains under Egyptian sovereignty, but
Red Sea insecurity—including Houthi attacks on shipping—along with military
tensions, rerouting, and insurance costs can sharply alter traffic. The
canal also affects coastal livelihoods, water salinity, and marine
ecosystems.
</p>
<p class="context-note">
Schematic landforms and route paths are intentionally simplified. The
approximately 193 km canal length is a familiar reference; the voyage
distances shown are rounded and illustrative rather than navigational.
</p>
</div>
</details>
<div class="hint" aria-hidden="true">
<b>Drag</b> orbit · <b>Shift-drag</b> pan ·
<b>Scroll</b> zoom · <b>Double-click</b> reset
</div>
<div class="compass" aria-hidden="true">N</div>
</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.querySelector("#scene");
const labelLayer = document.querySelector("#labels");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.setClearColor(0x07151c);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07151c);
scene.fog = new THREE.Fog(0x07151c, 245, 430);
const camera = new THREE.OrthographicCamera(-100, 100, 70, -70, 0.1, 600);
const hemisphere = new THREE.HemisphereLight(0xbfe8f2, 0x293326, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffedc2, 3.25);
sun.position.set(-65, 115, 65);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -125;
sun.shadow.camera.right = 125;
sun.shadow.camera.top = 110;
sun.shadow.camera.bottom = -110;
sun.shadow.camera.near = 10;
sun.shadow.camera.far = 280;
sun.shadow.normalBias = 0.035;
scene.add(sun);
scene.add(sun.target);
const fill = new THREE.DirectionalLight(0x65b7cf, 0.65);
fill.position.set(90, 50, -80);
scene.add(fill);
const SCALE = 1.4;
const ROUTE_Y = 8.2;
const LON_MIN = -31;
const LON_MAX = 109;
const LAT_MIN = -42;
const LAT_MAX = 59;
const xFor = lon => lon * SCALE;
const zFor = lat => -lat * SCALE;
function hash2(lon, lat) {
const value = Math.sin(lon * 12.9898 + lat * 78.233) * 43758.5453;
return value - Math.floor(value);
}
function pointInPolygon(x, y, polygon) {
let inside = false;
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
const [xi, yi] = polygon[i];
const [xj, yj] = polygon[j];
const intersects =
yi > y !== yj > y &&
x < ((xj - xi) * (y - yi)) / (yj - yi) + xi;
if (intersects) inside = !inside;
}
return inside;
}
const africa = [
[-17, 35], [-8, 36], [0, 35], [10, 37], [20, 32], [30, 31],
[34, 27], [37, 19], [39, 14], [43, 11], [51, 12], [48, 3],
[43, -1], [41, -10], [35, -18], [33, -26], [27, -34], [18, -35],
[12, -28], [9, -17], [5, -5], [1, 5], [-7, 5], [-13, 10],
[-17, 16], [-17, 27]
];
const europe = [
[-10, 36], [-10, 43], [-6, 48], [0, 50], [5, 54], [8, 58],
[14, 56], [19, 52], [24, 48], [31, 46], [31, 41], [28, 36],
[23, 36], [18, 40], [12, 38], [8, 44], [3, 43], [0, 39], [-5, 36]
];
const asia = [
[25, 70], [75, 73], [96, 65], [110, 50], [110, 25], [101, 22],
[92, 25], [84, 30], [74, 25], [66, 22], [60, 15], [52, 13],
[45, 13], [39, 18], [35, 27], [31, 32], [28, 39], [23, 45],
[15, 47], [10, 43], [5, 44], [0, 50], [5, 55], [14, 58],
[25, 60], [40, 62], [55, 66]
];
const arabia = [
[34.8, 30], [43, 30], [50, 26], [55, 20], [52, 13],
[46, 12], [43, 12], [39, 18], [36, 24]
];
const sinai = [
[31, 31], [34.8, 31], [35.3, 29.5], [33.8, 27.8], [31.5, 29.8]
];
const india = [
[68, 25], [78, 29], [88, 27], [92, 22], [88, 15],
[80, 8], [76, 10], [73, 20]
];
const southeastAsia = [
[92, 22], [100, 20], [107, 10], [105, 2], [100, 6], [98, 15], [92, 18]
];
const britain = [
[-8, 50], [-5, 50], [-4, 54], [-7, 59], [-3, 59], [0, 54], [1, 51]
];
const madagascar = [
[47, -13], [50, -17], [49, -24], [45, -25], [43, -19]
];
const landMasks = [
["africa", africa],
["sinai", arabia],
["europe", europe],
["arabia", arabia],
["india", india],
["seasia", southeastAsia],
["asia", asia],
["britain", europe],
["madagascar", africa]
];
const palettes = {
africa: [0xb98a58, 0xc79862, 0xa97d50, 0xd0a66e],
europe: [0x78a68e, 0x87b49b, 0x699b86, 0x96bda5],
asia: [0x74896c, 0x819775, 0x667d63, 0x8d9f7d],
arabia: [0xc49b62, 0xd0aa70, 0xb58c55, 0xdab77b],
india: [0x819473, 0x91a17d, 0x718765],
seasia: [0x66835e, 0x78916c, 0x587553],
sinai: [0xc59b63, 0xd1aa70],
britain: [0x7eaa94, 0x91b7a2],
madagascar: [0xa77e50, 0xb98a59]
};
function categoryAt(lon, lat) {
for (const [name, polygon] of landMasks) {
if (pointInPolygon(lon, lat, polygon)) return name;
}
return null;
}
function terrainHeight(category, lon, lat) {
const noise = hash2(lon, lat);
let height = 1.2 + noise * 1.75;
if (category === "africa") {
height += lon > 14 && lat > -12 && lat < 20 ? 2.25 : 0.35;
height += lat < -18 ? 0.45 : 0;
} else if (category === "europe") {
height += lat > 48 ? 2.1 : 0.75;
} else if (category === "asia") {
height += lat > 48 ? 2.2 : 0.65;
} else if (category === "arabia" || category === "sinai") {
height += 0.2;
} else if (category === "india" || category === "seasia") {
height += 1.05;
}
return Math.min(height, 6.3);
}
const mapWidth = (LON_MAX - LON_MIN) * SCALE;
const mapDepth = (LAT_MAX - LAT_MIN) * SCALE;
const mapCenterX = ((LON_MIN + LON_MAX) / 2) * SCALE;
const mapCenterZ = -((LAT_MIN + LAT_MAX) / 2) * SCALE;
const base = new THREE.Mesh(
new THREE.BoxGeometry(mapWidth + 11, 1.2, mapDepth + 11),
new THREE.MeshStandardMaterial({
color: 0x041116,
roughness: 0.95,
metalness: 0.05
})
);
base.position.set(mapCenterX, -0.75, mapCenterZ);
base.receiveShadow = true;
scene.add(base);
const ocean = new THREE.Mesh(
new THREE.PlaneGeometry(mapWidth + 8, mapDepth + 8),
new THREE.MeshStandardMaterial({
color: 0x0a3446,
roughness: 0.82,
metalness: 0.03
})
);
ocean.rotation.x = -Math.PI / 2;
ocean.position.set(mapCenterX, -0.05, mapCenterZ);
ocean.receiveShadow = true;
scene.add(ocean);
const gridPositions = [];
for (let lon = -20; lon <= 100; lon += 10) {
gridPositions.push(
xFor(lon), 0.08, zFor(LAT_MIN),
xFor(lon), 0.08, zFor(LAT_MAX)
);
}
for (let lat = -40; lat <= 50; lat += 10) {
gridPositions.push(
xFor(LON_MIN), 0.08, zFor(lat),
xFor(LON_MAX), 0.08, zFor(lat)
);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPositions, 3)
);
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x83c4d0,
transparent: true,
opacity: 0.105,
depthWrite: false
})
);
scene.add(grid);
const cells = [];
const step = 1.8;
for (let lon = LON_MIN + step / 2; lon < LON_MAX; lon += step) {
for (let lat = LAT_MIN + step / 2; lat < LAT_MAX; lat += step) {
const category = categoryAt(lon, lat);
if (!category) continue;
cells.push({
lon,
lat,
category,
height: terrainHeight(category, lon, lat)
});
}
}
const landGeometry = new THREE.BoxGeometry(step * 0.9, 1, step * 0.9);
const landMaterial = new THREE.MeshStandardMaterial({
roughness: 0.86,
metalness: 0.02,
vertexColors: true
});
const land = new THREE.InstancedMesh(
landGeometry,
landMaterial,
cells.length
);
land.castShadow = true;
land.receiveShadow = true;
const dummy = new THREE.Object3D();
const color = new THREE.Color();
cells.forEach((cell, index) => {
dummy.position.set(xFor(cell.lon), cell.height / 2, zFor(cell.lat));
dummy.scale.set(1, cell.height, 1);
dummy.updateMatrix();
land.setMatrixAt(index, dummy.matrix);
const palette = palettes[cell.category] || palettes.africa;
const paletteIndex = Math.floor(hash2(cell.lon + 7, cell.lat - 4) * palette.length);
color.setHex(palette[paletteIndex]);
color.offsetHSL(0, 0, (hash2(cell.lat, cell.lon) - 0.5) * 0.06);
land.setColorAt(index, color);
});
land.instanceMatrix.needsUpdate = true;
if (land.instanceColor) land.instanceColor.needsUpdate = true;
scene.add(land);
const routeGroup = new THREE.Group();
scene.add(routeGroup);
function makeRoute(points, routeColor, speed, phase) {
const curvePoints = points.map(
([lon, lat]) => new THREE.Vector3(xFor(lon), ROUTE_Y, zFor(lat))
);
const curve = new THREE.CatmullRomCurve3(
curvePoints,
false,
"centripetal",
0.25
);
const glow = new THREE.Mesh(
new THREE.TubeGeometry(curve, 420, 0.82, 8, false),
new THREE.MeshBasicMaterial({
color: routeColor,
transparent: true,
opacity: 0.13,
depthWrite: false,
toneMapped: false
})
);
const core = new THREE.Mesh(
new THREE.TubeGeometry(curve, 420, 0.25, 8, false),
new THREE.MeshBasicMaterial({
color: routeColor,
toneMapped: false
})
);
const marker = new THREE.Mesh(
new THREE.SphereGeometry(0.62, 16, 12),
new THREE.MeshBasicMaterial({
color: 0xffffff,
toneMapped: false
})
);
marker.position.copy(curve.getPointAt(phase));
routeGroup.add(glow, core, marker);
return { curve, marker, speed, phase };
}
const routes = [];
routes.push(
makeRoute(
[
[4.5, 52], [7, 48], [10, 41], [17, 37], [24, 35.5],
[29, 33], [32.55, 30.1], [34, 27], [37, 20], [43, 12.3],
[52, 12], [62, 14], [73, 20], [85, 6], [96, 3], [103.8, 1.3]
],
0xffca66,
0.035,
0.12
)
);
routes.push(
makeRoute(
[
[4.5, 52], [0, 48], [-8, 44], [-10, 36], [-18, 30],
[-21, 15], [-18, -8], [-10, -25], [4, -36], [16, -38],
[24, -37], [32, -31], [38, -21], [43, -7], [48, 5],
[53, 13], [62, 18], [74, 19], [86, 9], [96, 3], [103.8, 1.3]
],
0x4de0ea,
0.025,
0.62
)
);
function addEndpoint(lon, lat) {
const group = new THREE.Group();
group.position.set(xFor(lon), 0, zFor(lat));
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.12, 8.7, 10),
new THREE.MeshBasicMaterial({ color: 0xe9f4ef })
);
pole.position.y = 4.35;
const cap = new THREE.Mesh(
new THREE.SphereGeometry(0.72, 18, 12),
new THREE.MeshBasicMaterial({ color: 0xffffff })
);
cap.position.y = 8.8;
const ring = new THREE.Mesh(
new THREE.TorusGeometry(1.35, 0.11, 8, 36),
new THREE.MeshBasicMaterial({
color: 0xe9f4ef,
transparent: true,
opacity: 0.7
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.35;
group.add(pole, cap, ring);
scene.add(group);
}
addEndpoint(4.5, 52);
addEndpoint(103.8, 1.3);
const canalStart = new THREE.Vector3(xFor(32.42), ROUTE_Y + 0.16, zFor(31.05));
const canalEnd = new THREE.Vector3(xFor(32.68), ROUTE_Y + 0.16, zFor(28.95));
const canalCurve = new THREE.LineCurve3(canalStart, canalEnd);
const canal = new THREE.Mesh(
new THREE.TubeGeometry(canalCurve, 20, 0.38, 8, false),
new THREE.MeshBasicMaterial({
color: 0xfff0bc,
toneMapped: false
})
);
scene.add(canal);
for (let i = 0; i <= 6; i++) {
const marker = new THREE.Mesh(
new THREE.BoxGeometry(0.38, 0.38, 0.38),
new THREE.MeshBasicMaterial({ color: 0xffffff })
);
marker.position.copy(canalCurve.getPoint(i / 6));
marker.position.y += 0.12;
scene.add(marker);
}
const canalBeacon = new THREE.Mesh(
new THREE.TorusGeometry(1.6, 0.12, 8, 40),
new THREE.MeshBasicMaterial({
color: 0xffca66,
transparent: true,
opacity: 0.9,
toneMapped: false
})
);
canalBeacon.rotation.x = Math.PI / 2;
canalBeacon.position.set(xFor(32.55), ROUTE_Y + 0.25, zFor(30));
scene.add(canalBeacon);
const labels = [];
function addLabel(html, lon, lat, kind = "place", y = 9) {
const element = document.createElement("div");
element.className = `map-label ${kind}`;
element.innerHTML = html;
labelLayer.appendChild(element);
labels.push({
element,
position: new THREE.Vector3(xFor(lon), y, zFor(lat))
});
return element;
}
addLabel("Mediterranean Sea", 16, 37.5, "water", 1.4);
addLabel("Red Sea", 39.5, 18.5, "water", 1.4);
addLabel("Atlantic Ocean", -18, 9, "water", 1.4);
addLabel("Indian Ocean", 65, -18, "water", 1.4);
addLabel("Arabian Sea", 65, 13, "water", 1.4);
addLabel("Europe", 16, 48, "region", 7);
addLabel("Africa", 18, 5, "region", 7);
addLabel("Asia", 77, 39, "region", 7);
addLabel("Arabian Peninsula", 46, 23, "region", 7);
addLabel("Rotterdam", 4.5, 52, "place", 12);
addLabel("Singapore", 103.8, 1.3, "place", 12);
addLabel("Gibraltar", -7, 36, "place", 8);
addLabel("Bab el-Mandeb", 43.2, 12.2, "place", 9);
addLabel("Cape of Good Hope", 18, -37, "place", 8);
addLabel("Suez Canal · 193 km", 32.55, 30, "critical", 11);
addLabel(
"Route A · Suez",
24.5,
35.7,
"route",
11
).style.setProperty("--label-color", "#ffca66");
addLabel(
"Route B · Around Africa",
30,
-38.3,
"route",
11
).style.setProperty("--label-color", "#4de0ea");
const controls = {
target: new THREE.Vector3(31, 0, -10),
desiredTarget: new THREE.Vector3(31, 0, -10),
theta: 0.28,
phi: 0.76,
desiredTheta: 0.28,
desiredPhi: 0.76,
zoom: 1,
desiredZoom: 1
};
function updateCamera(instant = false) {
const damping = instant ? 1 : 0.11;
controls.theta += (controls.desiredTheta - controls.theta) * damping;
controls.phi += (controls.desiredPhi - controls.phi) * damping;
controls.zoom += (controls.desiredZoom - controls.zoom) * damping;
controls.target.lerp(controls.desiredTarget, damping);
const distance = 225;
const sinPhi = Math.sin(controls.phi);
const offset = new THREE.Vector3(
distance * sinPhi * Math.sin(controls.theta),
distance * Math.cos(controls.phi),
distance * sinPhi * Math.cos(controls.theta)
);
camera.position.copy(controls.target).add(offset);
camera.lookAt(controls.target);
const aspect = window.innerWidth / window.innerHeight;
const viewHeight = Math.max(138, 212 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.zoom = controls.zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resetView() {
controls.desiredTarget.set(31, 0, -10);
controls.desiredTheta = 0.28;
controls.desiredPhi = 0.76;
controls.desiredZoom = 1;
}
document.querySelector("#reset-view").addEventListener("click", resetView);
document.querySelector("#top-view").addEventListener("click", () => {
controls.desiredTarget.set(35, 0, -8);
controls.desiredTheta = 0;
controls.desiredPhi = 0.09;
controls.desiredZoom = 0.93;
});
let dragging = false;
let panning = false;
let previousX = 0;
let previousY = 0;
let pointerId = null;
canvas.addEventListener("pointerdown", event => {
dragging = true;
panning = event.shiftKey || event.button === 2;
previousX = event.clientX;
previousY = event.clientY;
pointerId = event.pointerId;
canvas.setPointerCapture(pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (panning) {
const right = new THREE.Vector3(1, 0, 0).applyQuaternion(camera.quaternion);
const forward = new THREE.Vector3(0, 0, -1).applyQuaternion(camera.quaternion);
right.y = 0;
forward.y = 0;
right.normalize();
forward.normalize();
const panScale = 0.11 * controls.zoom;
controls.desiredTarget
.addScaledVector(right, -dx * panScale)
.addScaledVector(forward, dy * panScale);
} else {
controls.desiredTheta -= dx * 0.0055;
controls.desiredPhi = THREE.MathUtils.clamp(
controls.desiredPhi - dy * 0.0045,
0.09,
1.25
);
}
});
function endDrag(event) {
if (!dragging) return;
dragging = false;
panning = false;
if (pointerId !== null && canvas.hasPointerCapture(pointerId)) {
canvas.releasePointerCapture(pointerId);
}
pointerId = null;
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
controls.desiredZoom = THREE.MathUtils.clamp(
controls.desiredZoom * Math.exp(-event.deltaY * 0.001),
0.65,
2.45
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
function resize() {
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
updateCamera(true);
}
window.addEventListener("resize", resize);
if (window.innerWidth <= 700) {
document.querySelector(".context").open = false;
}
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
projected.copy(label.position).project(camera);
const visible =
projected.z >= -1 &&
projected.z <= 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
label.element.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
updateCamera();
sun.target.position.set(35, 0, -10);
routes.forEach(route => {
const progress = (elapsed * route.speed + route.phase) % 1;
route.marker.position.copy(route.curve.getPointAt(progress));
});
const pulse = 1 + Math.sin(elapsed * 3.1) * 0.16;
canalBeacon.scale.setScalar(pulse);
canalBeacon.material.opacity = 0.72 + Math.sin(elapsed * 3.1) * 0.18;
renderer.render(scene, camera);
updateLabels();
}
updateCamera(true);
animate();
</script>
</body>
</html>
```