Prompt specification
Build or customize the Three.js 3D scene "Choose a map for the journey" 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: Choose a map for the journey
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/choose-a-map-for-the-journey-x1324
Scene Description Prompt:
Switch between local and regional low-poly maps of one fictional journey; change detail while preserving destination distance. One HTML file using Three.js from cdnjs.
Working Three.js Starter (choose-a-map-for-the-journey-x1324):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>The Lumen Coast — Fictional Journey Atlas</title>
<style>
:root {
--ink: #132b27;
--ink-soft: rgba(19, 43, 39, 0.72);
--paper: #f2f2e9;
--paper-dim: rgba(242, 242, 233, 0.68);
--accent: #f16d45;
--accent-dark: #bc482b;
--lime: #dce986;
--line: rgba(242, 242, 233, 0.17);
--shadow: 0 18px 60px rgba(10, 35, 31, 0.24);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #8eafac;
color: var(--paper);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
z-index: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.vignette {
position: fixed;
inset: 0;
z-index: 1;
pointer-events: none;
background:
linear-gradient(180deg, rgba(12, 35, 31, 0.12), transparent 24%),
radial-gradient(circle at 52% 46%, transparent 42%, rgba(8, 30, 27, 0.16));
}
.topbar {
position: fixed;
z-index: 10;
top: 0;
left: 0;
right: 0;
height: 74px;
padding: 0 28px;
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: center;
border-bottom: 1px solid rgba(255, 255, 255, 0.18);
background: rgba(18, 43, 38, 0.86);
backdrop-filter: blur(18px) saturate(120%);
-webkit-backdrop-filter: blur(18px) saturate(120%);
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}
.brand-mark {
width: 36px;
height: 36px;
display: grid;
place-items: center;
border: 1px solid rgba(255, 255, 255, 0.28);
border-radius: 50%;
color: var(--lime);
}
.brand-mark svg {
width: 20px;
height: 20px;
}
.brand-name {
font-size: 12px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.brand-sub {
margin-top: 3px;
color: rgba(255, 255, 255, 0.55);
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.journey-title {
text-align: center;
font-family: Georgia, "Times New Roman", serif;
font-size: 19px;
font-style: italic;
letter-spacing: 0.02em;
}
.edition {
justify-self: end;
display: flex;
align-items: center;
gap: 10px;
color: rgba(255, 255, 255, 0.62);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.edition-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px rgba(241, 109, 69, 0.14);
}
.panel {
position: fixed;
z-index: 10;
top: 98px;
left: 24px;
width: 340px;
max-height: calc(100vh - 122px);
overflow: auto;
padding: 24px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 20px;
background:
linear-gradient(145deg, rgba(25, 55, 49, 0.96), rgba(12, 37, 33, 0.91));
box-shadow: var(--shadow);
backdrop-filter: blur(20px) saturate(115%);
-webkit-backdrop-filter: blur(20px) saturate(120%);
scrollbar-width: thin;
scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}
.eyebrow {
margin-bottom: 9px;
color: var(--lime);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 35px;
font-weight: 500;
line-height: 1.04;
letter-spacing: -0.035em;
}
.intro {
margin: 13px 0 20px;
color: rgba(255, 255, 255, 0.64);
font-size: 12px;
line-height: 1.6;
}
.route-names {
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: center;
gap: 12px;
padding: 15px 0 17px;
border-top: 1px solid var(--line);
border-bottom: 1px solid var(--line);
}
.route-place:last-child {
text-align: right;
}
.route-label {
display: block;
margin-bottom: 5px;
color: rgba(255, 255, 255, 0.42);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.route-place strong {
display: block;
font-family: Georgia, "Times New Roman", serif;
font-size: 15px;
font-weight: 500;
}
.route-arrow {
color: var(--accent);
font-size: 18px;
}
.stats {
display: grid;
grid-template-columns: 1.35fr 1fr 1fr;
gap: 8px;
padding: 17px 0;
}
.stat strong {
display: block;
margin-bottom: 4px;
font-size: 17px;
font-weight: 750;
}
.stat span {
color: rgba(255, 255, 255, 0.43);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.distance-lock {
position: relative;
display: flex;
align-items: center;
gap: 11px;
padding: 12px;
overflow: hidden;
border: 1px solid rgba(220, 233, 134, 0.24);
border-radius: 12px;
background: rgba(220, 233, 134, 0.08);
}
.distance-lock svg {
flex: 0 0 auto;
width: 18px;
height: 18px;
color: var(--lime);
}
.distance-lock strong {
display: block;
font-size: 11px;
letter-spacing: 0.04em;
}
.distance-lock span {
display: block;
margin-top: 3px;
color: rgba(255, 255, 255, 0.5);
font-size: 9px;
line-height: 1.4;
}
.locked-pulse::after {
content: "";
position: absolute;
inset: 0;
background: rgba(220, 233, 134, 0.18);
animation: lockPulse 650ms ease-out;
pointer-events: none;
}
@keyframes lockPulse {
from {
opacity: 1;
transform: translateX(-100%);
}
to {
opacity: 0;
transform: translateX(100%);
}
}
.section-title {
margin: 21px 0 10px;
color: rgba(255, 255, 255, 0.55);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.segmented {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 4px;
padding: 4px;
border: 1px solid rgba(255, 255, 255, 0.11);
border-radius: 12px;
background: rgba(0, 0, 0, 0.13);
}
.segmented button {
min-height: 42px;
border: 0;
border-radius: 9px;
background: transparent;
color: rgba(255, 255, 255, 0.55);
cursor: pointer;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
transition:
background 180ms ease,
color 180ms ease,
transform 180ms ease;
}
.segmented button:hover {
color: #fff;
}
.segmented button.active {
background: var(--paper);
color: var(--ink);
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.16);
}
.scope-note {
min-height: 38px;
margin: 10px 1px 0;
color: rgba(255, 255, 255, 0.47);
font-size: 10px;
line-height: 1.5;
}
.panel-actions {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
margin-top: 18px;
}
.action-button {
min-height: 42px;
padding: 0 14px;
border: 1px solid rgba(255, 255, 255, 0.17);
border-radius: 10px;
background: transparent;
cursor: pointer;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: background 180ms ease, border-color 180ms ease;
}
.action-button:hover {
border-color: rgba(255, 255, 255, 0.38);
background: rgba(255, 255, 255, 0.07);
}
.action-button.primary {
border-color: var(--accent);
background: var(--accent);
color: #fff;
}
.action-button.primary:hover {
background: #ff7c53;
}
.action-button.icon-button {
width: 44px;
padding: 0;
font-size: 18px;
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.map-label {
position: absolute;
min-width: 92px;
padding: 7px 9px;
transform: translate(-50%, -100%);
border: 1px solid rgba(255, 255, 255, 0.56);
border-radius: 8px;
background: rgba(242, 242, 233, 0.91);
box-shadow: 0 5px 18px rgba(17, 43, 39, 0.17);
color: var(--ink);
opacity: 0;
transition: opacity 120ms linear;
white-space: nowrap;
}
.map-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -5px;
width: 8px;
height: 8px;
transform: translateX(-50%) rotate(45deg);
border-right: 1px solid rgba(255, 255, 255, 0.56);
border-bottom: 1px solid rgba(255, 255, 255, 0.56);
background: rgba(242, 242, 233, 0.91);
}
.map-label .label-kicker {
display: block;
margin-bottom: 2px;
color: var(--accent-dark);
font-size: 7px;
font-weight: 900;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.map-label strong {
font-family: Georgia, "Times New Roman", serif;
font-size: 12px;
font-weight: 600;
}
.map-label.destination {
border-color: rgba(241, 109, 69, 0.55);
background: rgba(255, 244, 232, 0.95);
}
.map-label.destination::after {
border-color: rgba(241, 109, 69, 0.55);
background: rgba(255, 244, 232, 0.95);
}
.map-label.place {
min-width: auto;
padding: 5px 8px;
border-color: transparent;
background: rgba(22, 48, 43, 0.78);
box-shadow: none;
color: #fff;
}
.map-label.place::after {
display: none;
}
.map-label.place strong {
font-family: inherit;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.detail-card {
position: fixed;
z-index: 10;
right: 24px;
bottom: 24px;
width: 294px;
padding: 17px 18px 15px;
border: 1px solid rgba(255, 255, 255, 0.17);
border-radius: 16px;
background: rgba(17, 43, 38, 0.89);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
}
.detail-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 13px;
}
.detail-heading span:first-child {
color: rgba(255, 255, 255, 0.58);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
#detailName {
color: var(--lime);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
appearance: none;
border-radius: 99px;
outline: none;
background: linear-gradient(
90deg,
var(--lime) 0%,
var(--lime) var(--range-fill, 50%),
rgba(255, 255, 255, 0.17) var(--range-fill, 50%)
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
appearance: none;
border: 3px solid var(--ink);
border-radius: 50%;
background: var(--lime);
box-shadow: 0 0 0 1px rgba(220, 233, 134, 0.55);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid var(--ink);
border-radius: 50%;
background: var(--lime);
box-shadow: 0 0 0 1px rgba(220, 233, 134, 0.55);
}
.detail-ticks {
display: flex;
justify-content: space-between;
margin-top: 8px;
color: rgba(255, 255, 255, 0.38);
font-size: 8px;
font-weight: 700;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.scale-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 14px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: rgba(255, 255, 255, 0.55);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.scale-line {
width: 48px;
height: 5px;
border-right: 1px solid var(--paper);
border-bottom: 1px solid var(--paper);
border-left: 1px solid var(--paper);
}
.compass {
position: fixed;
z-index: 8;
top: 96px;
right: 25px;
width: 54px;
height: 54px;
display: grid;
place-items: center;
border: 1px solid rgba(255, 255, 255, 0.35);
border-radius: 50%;
background: rgba(18, 43, 38, 0.65);
box-shadow: 0 8px 25px rgba(15, 40, 36, 0.16);
backdrop-filter: blur(10px);
}
.compass-needle {
position: relative;
width: 26px;
height: 34px;
transform-origin: 50% 60%;
transition: transform 80ms linear;
}
.compass-needle::before {
content: "";
position: absolute;
top: 2px;
left: 8px;
border-right: 5px solid transparent;
border-bottom: 17px solid var(--accent);
border-left: 5px solid transparent;
}
.compass-needle::after {
content: "N";
position: absolute;
top: -3px;
left: 9px;
color: #fff;
font-size: 8px;
font-weight: 900;
}
.help {
position: fixed;
z-index: 7;
left: 50%;
bottom: 27px;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 9px;
padding: 8px 12px;
border-radius: 99px;
background: rgba(18, 43, 38, 0.57);
color: rgba(255, 255, 255, 0.67);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.07em;
text-transform: uppercase;
backdrop-filter: blur(10px);
pointer-events: none;
}
.help svg {
width: 14px;
height: 14px;
opacity: 0.8;
}
@media (max-width: 900px) {
.panel {
width: 310px;
}
.help {
display: none;
}
}
@media (max-width: 680px) {
.topbar {
height: 62px;
padding: 0 14px;
grid-template-columns: 1fr auto;
}
.journey-title,
.edition {
display: none;
}
.panel {
top: auto;
left: 12px;
right: 12px;
bottom: 12px;
width: auto;
max-height: 46vh;
padding: 17px;
border-radius: 16px;
}
h1 {
font-size: 26px;
}
.intro {
display: none;
}
.route-names {
padding: 11px 0;
}
.stats {
padding: 12px 0;
}
.detail-card {
top: 78px;
right: 12px;
bottom: auto;
width: 230px;
padding: 13px 14px;
}
.compass {
display: none;
}
.map-label.place {
display: none !important;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive low-poly map of the fictional Lumen Coast journey"></main>
<div class="vignette"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6">
<path d="M12 3 4.5 7v10L12 21l7.5-4V7L12 3Z" />
<path d="m4.5 7 7.5 4 7.5-4M12 11v10M8 5l8 4" />
</svg>
</div>
<div>
<div class="brand-name">Wayfinder</div>
<div class="brand-sub">Fictional field atlas</div>
</div>
</div>
<div class="journey-title">The Lumen Coast</div>
<div class="edition">
<span class="edition-dot"></span>
Archive route 07
</div>
</header>
<aside class="panel">
<div class="eyebrow">One journey · Two map scales</div>
<h1>The Lumen<br />Coast Crossing</h1>
<p class="intro">
Follow the old survey road from Morrow Quay to Vesper Isle.
Switch the map scope or terrain resolution without changing the journey.
</p>
<div class="route-names">
<div class="route-place">
<span class="route-label">Origin</span>
<strong>Morrow Quay</strong>
</div>
<div class="route-arrow" aria-hidden="true">→</div>
<div class="route-place">
<span class="route-label">Destination</span>
<strong>Vesper Isle</strong>
</div>
</div>
<div class="stats">
<div class="stat">
<strong>128 km</strong>
<span>Distance</span>
</div>
<div class="stat">
<strong>3 days</strong>
<span>On foot</span>
</div>
<div class="stat">
<strong>1,840 m</strong>
<span>Ascent</span>
</div>
</div>
<div class="distance-lock" id="distanceCard">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" aria-hidden="true">
<rect x="5" y="10" width="14" height="11" rx="2" />
<path d="M8 10V7a4 4 0 0 1 8 0v3M12 14v3" />
</svg>
<div>
<strong>Destination distance locked at 128 km</strong>
<span>Changing map scale or terrain detail never changes the endpoint distance.</span>
</div>
</div>
<div class="section-title">Map scope</div>
<div class="segmented" role="group" aria-label="Map scope">
<button type="button" data-mode="local" class="active">Local</button>
<button type="button" data-mode="regional">Regional</button>
</div>
<p class="scope-note" id="scopeNote">
A close survey of the coast, with denser terrain and nearby landmarks.
</p>
<div class="panel-actions">
<button type="button" class="action-button primary" id="traceBtn" aria-pressed="false">
Trace journey
</button>
<button type="button" class="action-button icon-button" id="resetBtn" title="Reset map view" aria-label="Reset map view">
↺
</button>
</div>
</aside>
<div id="labels" aria-hidden="true"></div>
<div class="compass" aria-hidden="true">
<div class="compass-needle" id="compassNeedle"></div>
</div>
<section class="detail-card" aria-label="Terrain detail controls">
<div class="detail-heading">
<span>Landscape detail</span>
<span id="detailName">Balanced</span>
</div>
<input
id="detailSlider"
type="range"
min="1"
max="3"
step="1"
value="2"
aria-label="Landscape detail"
/>
<div class="detail-ticks">
<span>Coarse</span>
<span>Balanced</span>
<span>Fine</span>
</div>
<div class="scale-row">
<span id="scaleText">20 km scale</span>
<span class="scale-line" aria-hidden="true"></span>
</div>
</section>
<div class="help" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
<path d="M8 11V7a2 2 0 1 1 4 0v4-2a2 2 0 1 1 4 0v3-1a2 2 0 1 1 4 0v4c0 4-3 6-7 6h-1c-3 0-5-1-7-4l-2-3a2 2 0 0 1 3-2l2 2v-3Z" />
</svg>
Drag to orbit · Scroll to zoom
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const labelsRoot = document.getElementById("labels");
const distanceCard = document.getElementById("distanceCard");
const scopeNote = document.getElementById("scopeNote");
const detailSlider = document.getElementById("detailSlider");
const detailName = document.getElementById("detailName");
const scaleText = document.getElementById("scaleText");
const traceBtn = document.getElementById("traceBtn");
const resetBtn = document.getElementById("resetBtn");
const compassNeedle = document.getElementById("compassNeedle");
const modeButtons = [...document.querySelectorAll("[data-mode]")];
const JOURNEY_DISTANCE_KM = 128;
// These normalized route coordinates are shared by every level of detail.
const ROUTE_POINTS = [
[-0.62, 0.50],
[-0.49, 0.42],
[-0.39, 0.28],
[-0.24, 0.31],
[-0.13, 0.11],
[ 0.01, 0.04],
[ 0.12,-0.08],
[ 0.25, 0.02],
[ 0.35, 0.16],
[ 0.46, 0.34],
[ 0.55, 0.42],
[ 0.64, 0.52]
];
const CONFIG = {
local: {
width: 96,
depth: 72,
radius: 128,
phi: 1.02,
theta: 0.72,
fogNear: 95,
fogFar: 360,
scale: "20 km scale"
},
regional: {
width: 360,
depth: 260,
radius: 610,
phi: 0.96,
theta: 0.72,
fogNear: 420,
fogFar: 1550,
scale: "80 km scale"
}
};
const DETAIL = {
1: { name: "Coarse", columns: 17, rows: 13 },
2: { name: "Balanced", columns: 29, rows: 22 },
3: { name: "Fine", columns: 47, rows: 36 }
};
let currentMode = "local";
let currentDetail = 2;
let mapGroup = null;
let routeCurve = null;
let traveler = null;
let destinationRing = null;
let annotations = [];
let journeyProgress = 0;
let tracing = false;
let mapIntro = 1;
let viewTween = null;
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Low-poly 3D journey map");
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x91b3af);
scene.fog = new THREE.Fog(0x91b3af, 95, 360);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
3000
);
const hemisphere = new THREE.HemisphereLight(0xf2f7e8, 0x4b6358, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffefd0, 3.25);
sun.position.set(-140, 210, 115);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.bias = -0.00045;
sun.shadow.normalBias = 0.045;
scene.add(sun);
scene.add(sun.target);
const water = new THREE.Mesh(
new THREE.PlaneGeometry(4000, 4000),
new THREE.MeshStandardMaterial({
color: 0x6f9e9e,
roughness: 0.78,
metalness: 0.04
})
);
water.rotation.x = -Math.PI / 2;
water.position.y = -0.12;
water.receiveShadow = true;
scene.add(water);
const orbit = {
target: new THREE.Vector3(-6, 2, 0),
radius: 128,
phi: 1.02,
theta: 0.72
};
function seededRandom(seed) {
let value = seed >>> 0;
return function () {
value += 0x6D2B79F5;
let t = value;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
function terrainHeight(nx, nz) {
const hills = [
[-0.62, 0.50, 4.9, 0.125],
[-0.43, 0.36, 3.3, 0.115],
[-0.20, 0.19, 4.6, 0.135],
[ 0.06,-0.07, 3.4, 0.125],
[ 0.30, 0.05, 4.2, 0.135],
[ 0.51, 0.29, 3.2, 0.120],
[ 0.64, 0.52, 5.1, 0.135],
[-0.05, 0.57, 1.8, 0.125],
[ 0.35, 0.59, 1.7, 0.115],
[-0.56,-0.35, 1.3, 0.150]
];
let height = -0.42;
for (const [hx, hz, amplitude, spread] of hills) {
const dx = nx - hx;
const dz = nz - hz;
height += amplitude * Math.exp(
-(dx * dx + dz * dz) / (2 * spread * spread)
);
}
height += 0.36 * Math.sin(nx * 14.3 + 0.5) * Math.cos(nz * 12.7 - 0.3);
height += 0.18 * Math.sin(nx * 29.0 - nz * 21.0 + 1.2);
height += 0.10 * Math.cos(nx * 51.0 + nz * 43.0);
return height;
}
function terrainColor(height, variation) {
let color;
if (height < 0) {
color = new THREE.Color(0x547e7d);
} else if (height < 0.75) {
color = new THREE.Color(0xc7c39b);
} else if (height < 2.0) {
color = new THREE.Color(0x9eae82);
} else if (height < 3.4) {
color = new THREE.Color(0x758f6c);
} else if (height < 4.8) {
color = new THREE.Color(0x879773);
} else {
color = new THREE.Color(0xc2c1a0);
}
color.offsetHSL(0, 0, variation);
return color;
}
function buildTerrain(config, resolution, worldScale) {
const positions = [];
const colors = [];
const points = [];
const random = seededRandom(7183 + resolution.columns * 11);
for (let z = 0; z <= resolution.rows; z++) {
for (let x = 0; x <= resolution.columns; x++) {
let nx = -1 + (x / resolution.columns) * 2;
let nz = -1 + (z / resolution.rows) * 2;
if (x > 0 && x < resolution.columns) {
nx += (random() - 0.5) * (1.7 / resolution.columns);
}
if (z > 0 && z < resolution.rows) {
nz += (random() - 0.5) * (1.7 / resolution.rows);
}
points.push({
x: nx * config.width * 0.5,
z: nz * config.depth * 0.5,
y: terrainHeight(nx, nz) * worldScale
});
}
}
function point(x, z) {
return points[z * (resolution.columns + 1) + x];
}
function pushTriangle(a, b, c, faceIndex) {
const average = (a.y + b.y + c.y) / 3;
const variation =
((Math.sin(faceIndex * 91.17 + 13.7) + 1) * 0.5 - 0.5) * 0.045;
const color = terrainColor(average, variation);
for (const vertex of [a, b, c]) {
positions.push(vertex.x, vertex.y, vertex.z);
colors.push(color.r, color.g, color.b);
}
}
let faceIndex = 0;
for (let z = 0; z < resolution.rows; z++) {
for (let x = 0; x < resolution.columns; x++) {
const p00 = point(x, z);
const p10 = point(x + 1, z);
const p01 = point(x, z + 1);
const p11 = point(x + 1, z + 1);
if ((x + z) % 2 === 0) {
pushTriangle(p00, p01, p10, faceIndex++);
pushTriangle(p10, p01, p11, faceIndex++);
} else {
pushTriangle(p00, p01, p11, faceIndex++);
pushTriangle(p00, p11, p10, faceIndex++);
}
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
flatShading: true,
roughness: 0.96,
metalness: 0
});
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function buildRoute(config, worldScale) {
const controls = ROUTE_POINTS.map(([nx, nz]) =>
new THREE.Vector3(
nx * config.width * 0.5,
0,
nz * config.depth * 0.5
)
);
const baseCurve = new THREE.CatmullRomCurve3(
controls,
false,
"catmullrom",
0.35
);
const sampled = [];
const sampleCount = 180;
for (let i = 0; i <= sampleCount; i++) {
const point = baseCurve.getPoint(i / sampleCount);
const nx = point.x / (config.width * 0.5);
const nz = point.z / (config.depth * 0.5);
const landHeight = terrainHeight(nx, nz) * worldScale;
point.y = Math.max(landHeight + 1.25, 1.15);
sampled.push(point);
}
const curve = new THREE.CatmullRomCurve3(
sampled,
false,
"centripetal"
);
const radius = 0.58 * worldScale;
const underlay = new THREE.Mesh(
new THREE.TubeGeometry(curve, 180, radius * 1.72, 6, false),
new THREE.MeshBasicMaterial({ color: 0x693e31 })
);
const route = new THREE.Mesh(
new THREE.TubeGeometry(curve, 180, radius, 7, false),
new THREE.MeshBasicMaterial({ color: 0xf16d45 })
);
route.renderOrder = 2;
underlay.renderOrder = 1;
return { curve, route, underlay };
}
function nearRoute(nx, nz) {
for (const [rx, rz] of ROUTE_POINTS) {
const dx = nx - rx;
const dz = nz - rz;
if (dx * dx + dz * dz < 0.0024) return true;
}
return false;
}
function buildTrees(config, worldScale) {
const random = seededRandom(4419);
const maxTrees = 150;
const treeData = [];
for (let attempt = 0; attempt < 900 && treeData.length < maxTrees; attempt++) {
const nx = random() * 2 - 1;
const nz = random() * 2 - 1;
const height = terrainHeight(nx, nz) * worldScale;
if (height < 1.15 || nearRoute(nx, nz)) continue;
treeData.push({
x: nx * config.width * 0.5,
z: nz * config.depth * 0.5,
y: height,
scale: worldScale * (0.65 + random() * 0.55),
rotation: random() * Math.PI * 2,
tint: random()
});
}
const count = treeData.length;
const group = new THREE.Group();
const trunk = new THREE.InstancedMesh(
new THREE.CylinderGeometry(0.35, 0.52, 3.2, 5),
new THREE.MeshStandardMaterial({
color: 0x685343,
roughness: 1,
flatShading: true
}),
count
);
const crown = new THREE.InstancedMesh(
new THREE.ConeGeometry(2.35, 6.2, 6),
new THREE.MeshStandardMaterial({
color: 0x4f6d54,
roughness: 1,
flatShading: true
}),
count
);
trunk.castShadow = true;
crown.castShadow = true;
trunk.receiveShadow = true;
crown.receiveShadow = true;
trunk.frustumCulled = false;
crown.frustumCulled = false;
const dummy = new THREE.Object3D();
treeData.forEach((tree, index) => {
dummy.position.set(
tree.x,
tree.y + 1.6 * tree.scale,
tree.z
);
dummy.rotation.set(0, tree.rotation, 0);
dummy.scale.setScalar(tree.scale);
dummy.updateMatrix();
trunk.setMatrixAt(index, dummy.matrix);
dummy.position.set(
tree.x,
tree.y + 4.9 * tree.scale,
tree.z
);
dummy.rotation.set(0, tree.rotation + 0.3, 0);
dummy.scale.setScalar(tree.scale);
dummy.updateMatrix();
crown.setMatrixAt(index, dummy.matrix);
const color = new THREE.Color(0x4b6951);
color.offsetHSL(
(tree.tint - 0.5) * 0.025,
(tree.tint - 0.5) * 0.08,
(tree.tint - 0.5) * 0.06
);
crown.setColorAt(index, color);
});
trunk.instanceMatrix.needsUpdate = true;
crown.instanceMatrix.needsUpdate = true;
if (crown.instanceColor) crown.instanceColor.needsUpdate = true;
group.add(trunk, crown);
return group;
}
function buildMarker(point, worldScale, destination) {
const marker = new THREE.Group();
marker.position.copy(point);
marker.scale.setScalar(worldScale);
const poleMaterial = new THREE.MeshStandardMaterial({
color: destination ? 0x8d3827 : 0x244f48,
roughness: 0.72
});
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.22, 0.3, 7.2, 6),
poleMaterial
);
pole.position.y = 3.6;
pole.castShadow = true;
marker.add(pole);
const head = new THREE.Mesh(
new THREE.OctahedronGeometry(1.25, 0),
new THREE.MeshStandardMaterial({
color: destination ? 0xf16d45 : 0xdce986,
emissive: destination ? 0x40130b : 0x273017,
emissiveIntensity: 0.35,
roughness: 0.55,
flatShading: true
})
);
head.position.y = 7.8;
head.castShadow = true;
marker.add(head);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(2.8, 0.25, 5, 28),
new THREE.MeshBasicMaterial({
color: destination ? 0xf16d45 : 0xdce986
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.35;
marker.add(ring);
if (destination) destinationRing = ring;
return marker;
}
function addAnnotation(title, kicker, point, type = "place") {
const element = document.createElement("div");
element.className = `map-label ${type}`;
element.innerHTML = `
<span class="label-kicker">${kicker}</span>
<strong>${title}</strong>
`;
labelsRoot.appendChild(element);
annotations.push({
element,
position: point.clone(),
type
});
}
function disposeMap(group) {
if (!group) return;
group.traverse((object) => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
const materials = Array.isArray(object.material)
? object.material
: [object.material];
for (const material of materials) {
material.dispose();
}
}
});
}
function buildMap() {
if (mapGroup) {
scene.remove(mapGroup);
disposeMap(mapGroup);
}
labelsRoot.replaceChildren();
annotations = [];
const config = CONFIG[currentMode];
const resolution = DETAIL[currentDetail];
const worldScale = config.width / 96;
mapGroup = new THREE.Group();
scene.add(mapGroup);
const terrain = buildTerrain(config, resolution, worldScale);
mapGroup.add(terrain);
const routeData = buildRoute(config, worldScale);
routeCurve = routeData.curve;
mapGroup.add(routeData.underlay, routeData.route);
mapGroup.add(buildTrees(config, worldScale));
const origin = routeCurve.getPointAt(0);
const destination = routeCurve.getPointAt(1);
mapGroup.add(buildMarker(origin, worldScale, false));
mapGroup.add(buildMarker(destination, worldScale, true));
const originLabel = origin.clone();
originLabel.y += 10 * worldScale;
const destinationLabel = destination.clone();
destinationLabel.y += 10 * worldScale;
addAnnotation(
"Morrow Quay",
"Origin",
originLabel,
"origin"
);
addAnnotation(
"Vesper Isle",
`${JOURNEY_DISTANCE_KM} km`,
destinationLabel,
"destination"
);
const landmarks = [
{ t: 0.19, name: "Fenwake" },
{ t: 0.47, name: "Lowglass" },
{ t: 0.76, name: "Cinder Sound" }
];
for (const landmark of landmarks) {
const point = routeCurve.getPointAt(landmark.t);
point.y += 7 * worldScale;
addAnnotation(landmark.name, "Waypoint", point, "place");
}
traveler = new THREE.Group();
traveler.scale.setScalar(worldScale);
const travelerBody = new THREE.Mesh(
new THREE.IcosahedronGeometry(1.15, 1),
new THREE.MeshStandardMaterial({
color: 0xfff8e7,
emissive: 0xf16d45,
emissiveIntensity: 0.5,
roughness: 0.4,
flatShading: true
})
);
travelerBody.castShadow = true;
traveler.add(travelerBody);
const travelerHalo = new THREE.Mesh(
new THREE.TorusGeometry(2.1, 0.2, 5, 24),
new THREE.MeshBasicMaterial({ color: 0xf16d45 })
);
travelerHalo.rotation.x = Math.PI / 2;
traveler.add(travelerHalo);
mapGroup.add(traveler);
traveler.position.copy(routeCurve.getPointAt(journeyProgress));
scene.fog.near = config.fogNear;
scene.fog.far = config.fogFar;
sun.position.set(
-145 * worldScale,
210 * worldScale,
115 * worldScale
);
sun.shadow.camera.left = -260 * worldScale;
sun.shadow.camera.right = 260 * worldScale;
sun.shadow.camera.top = 260 * worldScale;
sun.shadow.camera.bottom = -260 * worldScale;
sun.shadow.camera.near = 10;
sun.shadow.camera.far = 1000 * worldScale;
sun.shadow.camera.updateProjectionMatrix();
mapIntro = 0;
}
function responsiveRadius(base) {
const aspect = window.innerWidth / window.innerHeight;
const factor = aspect < 1 ? Math.min(2.15, 1.05 / aspect) : 1;
return base * factor;
}
function getPreset() {
const config = CONFIG[currentMode];
const worldScale = config.width / 96;
const target = new THREE.Vector3(
-config.width * 0.055,
2.2 * worldScale,
0
);
const radius = responsiveRadius(config.radius);
const phi = config.phi;
const theta = config.theta;
const position = new THREE.Vector3(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
return { target, position, radius, phi, theta };
}
function startViewTween() {
const preset = getPreset();
viewTween = {
start: performance.now(),
duration: 900,
fromPosition: camera.position.clone(),
fromTarget: orbit.target.clone(),
toPosition: preset.position,
toTarget: preset.target,
preset
};
}
function applyOrbit() {
const { target, radius, phi, theta } = orbit;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
}
function updateUI(pulseDistance = false) {
for (const button of modeButtons) {
button.classList.toggle("active", button.dataset.mode === currentMode);
button.setAttribute(
"aria-pressed",
String(button.dataset.mode === currentMode)
);
}
detailSlider.value = String(currentDetail);
detailName.textContent = DETAIL[currentDetail].name;
const fill = ((currentDetail - 1) / 2) * 100;
detailSlider.style.setProperty("--range-fill", `${fill}%`);
scaleText.textContent = CONFIG[currentMode].scale;
scopeNote.textContent =
currentMode === "local"
? "A close survey of the coast, with denser terrain and nearby landmarks."
: "A wider atlas view showing the same route, surrounding islands, and open water.";
if (pulseDistance) {
distanceCard.classList.remove("locked-pulse");
void distanceCard.offsetWidth;
distanceCard.classList.add("locked-pulse");
}
}
function setMode(mode) {
if (!CONFIG[mode]) return;
currentMode = mode;
currentDetail = mode === "local" ? 2 : 1;
buildMap();
updateUI(true);
startViewTween();
}
modeButtons.forEach((button) => {
button.addEventListener("click", () => {
if (button.dataset.mode !== currentMode) {
setMode(button.dataset.mode);
}
});
});
detailSlider.addEventListener("input", () => {
currentDetail = Number(detailSlider.value);
detailName.textContent = DETAIL[currentDetail].name;
const fill = ((currentDetail - 1) / 2) * 100;
detailSlider.style.setProperty("--range-fill", `${fill}%`);
buildMap();
updateUI(true);
});
traceBtn.addEventListener("click", () => {
if (!tracing && journeyProgress >= 0.999) {
journeyProgress = 0;
}
tracing = !tracing;
traceBtn.setAttribute("aria-pressed", String(tracing));
traceBtn.textContent = tracing ? "Pause trace" : "Trace journey";
});
resetBtn.addEventListener("click", () => {
startViewTween();
});
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
viewTween = null;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + dy * 0.0045,
0.32,
1.38
);
});
function endDrag(event) {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
viewTween = null;
const config = CONFIG[currentMode];
const minimum = responsiveRadius(config.radius) * 0.45;
const maximum = responsiveRadius(config.radius) * 2.1;
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
minimum,
maximum
);
},
{ passive: false }
);
renderer.domElement.style.cursor = "grab";
function updateAnnotations() {
if (!mapGroup) return;
const width = window.innerWidth;
const height = window.innerHeight;
for (const annotation of annotations) {
const projected = mapGroup.localToWorld(
annotation.position.clone()
).project(camera);
const visible = projected.z > -1 && projected.z < 1;
annotation.element.style.opacity = visible ? "1" : "0";
annotation.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
annotation.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
function animate(time) {
const delta = Math.min(0.05, (time - (animate.lastTime || time)) / 1000);
animate.lastTime = time;
if (viewTween) {
const raw = Math.min(
1,
(time - viewTween.start) / viewTween.duration
);
const eased =
raw < 0.5
? 4 * raw * raw * raw
: 1 - Math.pow(-2 * raw + 2, 3) / 2;
camera.position.lerpVectors(
viewTween.fromPosition,
viewTween.toPosition,
eased
);
orbit.target.lerpVectors(
viewTween.fromTarget,
viewTween.toTarget,
eased
);
camera.lookAt(orbit.target);
if (raw >= 1) {
const offset = camera.position.clone().sub(orbit.target);
orbit.radius = offset.length();
orbit.phi = Math.acos(
THREE.MathUtils.clamp(offset.y / orbit.radius, -1, 1)
);
orbit.theta = Math.atan2(offset.x, offset.z);
viewTween = null;
}
} else {
applyOrbit();
}
if (mapGroup && mapIntro < 1) {
mapIntro = Math.min(1, mapIntro + delta * 2.7);
const eased = 1 - Math.pow(1 - mapIntro, 3);
mapGroup.scale.setScalar(0.97 + eased * 0.03);
}
if (routeCurve && traveler) {
if (tracing) {
journeyProgress = Math.min(1, journeyProgress + delta / 24);
if (journeyProgress >= 1) {
tracing = false;
traceBtn.textContent = "Replay trace";
traceBtn.setAttribute("aria-pressed", "false");
}
}
const point = routeCurve.getPointAt(journeyProgress);
traveler.position.copy(point);
traveler.position.y += 1.4;
traveler.rotation.y += delta * 1.6;
}
if (destinationRing) {
const pulse = 1 + Math.sin(time * 0.0035) * 0.13;
destinationRing.scale.setScalar(pulse);
}
compassNeedle.style.transform = `rotate(${-orbit.theta}rad)`;
updateAnnotations();
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);
});
buildMap();
updateUI();
const initialPreset = getPreset();
orbit.target.copy(initialPreset.target);
orbit.radius = initialPreset.radius;
orbit.phi = initialPreset.phi;
orbit.theta = initialPreset.theta;
applyOrbit();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```