Prompt specification
Build or customize the Three.js 3D scene "Cloud cover changes a navigation plan" 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: Cloud cover changes a navigation plan
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/cloud-cover-changes-a-navigation-plan-x2248
Scene Description Prompt:
Clouds hide navigational stars during a schematic voxel coastal voyage; switch to visible landmarks or mark orientation uncertain. Three.js from cdnjs, standalone HTML.
Working Three.js Starter (cloud-cover-changes-a-navigation-plan-x2248):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>The Clouded Meridian — Voxel Coastal Voyage</title>
<style>
:root {
--ink: #071722;
--panel: rgba(7, 24, 34, 0.88);
--panel-solid: #0b2230;
--line: rgba(176, 218, 220, 0.2);
--text: #edf5ed;
--muted: #9eb8b8;
--cyan: #76d6d2;
--gold: #ffc66d;
--coral: #ff796b;
--green: #a8d887;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--ink);
color: var(--text);
font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
}
#vignette {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
background:
linear-gradient(180deg, rgba(2, 11, 17, 0.36), transparent 25%, transparent 72%, rgba(2, 11, 17, 0.48)),
radial-gradient(circle at 55% 48%, transparent 35%, rgba(2, 9, 15, 0.26) 100%);
}
#hud {
position: fixed;
inset: 0;
z-index: 4;
pointer-events: none;
}
.interactive {
pointer-events: auto;
}
.topbar {
position: absolute;
top: 0;
left: 0;
right: 0;
min-height: 92px;
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: center;
gap: 24px;
padding: 18px 24px;
background: linear-gradient(180deg, rgba(3, 15, 23, 0.92), rgba(3, 15, 23, 0));
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
width: 40px;
height: 40px;
border: 1px solid rgba(118, 214, 210, 0.55);
display: grid;
place-items: center;
transform: rotate(45deg);
background: rgba(118, 214, 210, 0.07);
flex: 0 0 auto;
}
.brand-mark::after {
content: "";
width: 14px;
height: 14px;
background: var(--gold);
box-shadow: 0 0 18px rgba(255, 198, 109, 0.45);
}
.brand-copy {
min-width: 0;
}
.eyebrow {
margin: 0 0 5px;
color: var(--cyan);
font-size: 10px;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(20px, 2vw, 29px);
font-weight: 500;
letter-spacing: 0.02em;
white-space: nowrap;
}
.route-card {
min-width: 250px;
padding: 10px 18px;
border-top: 1px solid var(--line);
border-bottom: 1px solid var(--line);
text-align: center;
background: rgba(6, 24, 34, 0.44);
}
.route-card .route-line {
font-size: 11px;
letter-spacing: 0.16em;
color: var(--text);
}
.route-card .route-sub {
margin-top: 6px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.14em;
}
.weather-card {
justify-self: end;
display: flex;
align-items: center;
gap: 12px;
padding: 10px 12px;
border: 1px solid var(--line);
background: rgba(7, 24, 34, 0.72);
}
.weather-icon {
width: 25px;
height: 17px;
position: relative;
opacity: 0.85;
}
.weather-icon::before,
.weather-icon::after {
content: "";
position: absolute;
background: var(--muted);
border-radius: 5px;
}
.weather-icon::before {
width: 25px;
height: 10px;
left: 0;
top: 4px;
}
.weather-icon::after {
width: 13px;
height: 8px;
left: 5px;
top: 0;
}
.weather-value {
font-size: 10px;
letter-spacing: 0.12em;
color: var(--muted);
}
.weather-value strong {
display: block;
margin-top: 4px;
color: var(--text);
font-size: 12px;
font-weight: 500;
}
.panel {
background: var(--panel);
border: 1px solid var(--line);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.18);
backdrop-filter: blur(12px);
}
.nav-panel {
position: absolute;
left: 24px;
top: 112px;
width: 306px;
padding: 18px;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 15px;
}
.panel-heading h2 {
margin: 0;
font-size: 10px;
font-weight: 500;
letter-spacing: 0.19em;
text-transform: uppercase;
color: var(--muted);
}
.tiny-code {
color: var(--cyan);
font-size: 9px;
letter-spacing: 0.12em;
}
.sky-window {
height: 105px;
position: relative;
overflow: hidden;
border: 1px solid rgba(118, 214, 210, 0.22);
background:
radial-gradient(circle at 75% 20%, rgba(69, 128, 145, 0.2), transparent 34%),
#06131e;
}
.sky-window::before {
content: "";
position: absolute;
inset: 0;
background: repeating-linear-gradient(
0deg,
transparent,
transparent 20px,
rgba(118, 214, 210, 0.04) 21px
);
}
.star-layer,
.cloud-layer {
position: absolute;
inset: 0;
transition: opacity 300ms ease, transform 600ms ease;
}
.star {
position: absolute;
width: 2px;
height: 2px;
background: #eaf8ef;
box-shadow: 0 0 6px rgba(234, 248, 239, 0.75);
}
.star.north {
width: 5px;
height: 5px;
left: 32%;
top: 20%;
background: var(--gold);
box-shadow: 0 0 10px var(--gold), 0 0 22px rgba(255, 198, 109, 0.55);
}
.cloud-pixel {
position: absolute;
width: 38px;
height: 24px;
border-radius: 6px;
background: #879ea5;
box-shadow:
20px 7px 0 #9bb0b4,
42px -2px 0 #708a93,
63px 7px 0 #a5b8b9;
opacity: 0.92;
}
.sky-horizon {
position: absolute;
left: 0;
right: 0;
bottom: 0;
height: 19px;
background: #0b2630;
border-top: 1px solid rgba(118, 214, 210, 0.17);
}
.sky-caption {
position: absolute;
right: 8px;
bottom: 4px;
z-index: 2;
color: rgba(220, 238, 235, 0.65);
font-size: 8px;
letter-spacing: 0.13em;
}
.visibility-row {
display: flex;
justify-content: space-between;
align-items: baseline;
margin: 14px 0 7px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.13em;
}
.visibility-row strong {
color: var(--text);
font-size: 11px;
font-weight: 500;
}
.meter {
height: 3px;
background: rgba(255, 255, 255, 0.08);
overflow: hidden;
}
.meter > span {
display: block;
height: 100%;
width: 75%;
background: linear-gradient(90deg, var(--coral), var(--gold) 45%, var(--cyan));
transition: width 220ms ease;
}
.cover-controls {
display: flex;
gap: 8px;
align-items: center;
margin-top: 12px;
}
.cover-controls input[type="range"] {
flex: 1;
height: 3px;
accent-color: var(--cyan);
cursor: pointer;
}
.mini-button,
.mode-button,
.action-button,
.landmark-button,
.voyage-button {
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.025);
cursor: pointer;
transition: border-color 160ms ease, background 160ms ease, color 160ms ease;
}
.mini-button {
padding: 7px 8px;
color: var(--muted);
font-size: 8px;
letter-spacing: 0.08em;
white-space: nowrap;
}
.mini-button:hover,
.mode-button:hover,
.landmark-button:hover,
.voyage-button:hover {
border-color: rgba(118, 214, 210, 0.55);
color: var(--text);
}
.navigation-status {
margin-top: 16px;
padding: 14px;
border-left: 2px solid var(--cyan);
background: rgba(118, 214, 210, 0.055);
transition: border-color 200ms ease, background 200ms ease;
}
.navigation-status.warning {
border-left-color: var(--coral);
background: rgba(255, 121, 107, 0.07);
}
.status-row {
display: flex;
align-items: center;
gap: 8px;
}
.status-dot {
width: 7px;
height: 7px;
background: var(--cyan);
box-shadow: 0 0 10px rgba(118, 214, 210, 0.75);
}
.warning .status-dot {
background: var(--coral);
box-shadow: 0 0 10px rgba(255, 121, 107, 0.75);
}
#statusTitle {
font-size: 11px;
letter-spacing: 0.11em;
}
#statusCopy {
min-height: 42px;
margin: 8px 0 0;
color: var(--muted);
font-size: 9px;
line-height: 1.65;
}
.mode-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
margin-top: 14px;
}
.mode-button {
padding: 9px 5px;
color: var(--muted);
font-size: 8px;
letter-spacing: 0.08em;
}
.mode-button.active {
background: rgba(118, 214, 210, 0.12);
border-color: var(--cyan);
color: var(--text);
}
.action-button {
width: 100%;
margin-top: 9px;
padding: 11px 10px;
border-color: rgba(255, 198, 109, 0.52);
background: rgba(255, 198, 109, 0.1);
color: var(--gold);
font-size: 9px;
letter-spacing: 0.1em;
}
.action-button:hover {
background: rgba(255, 198, 109, 0.18);
border-color: var(--gold);
}
.landmarks-section {
margin-top: 17px;
padding-top: 15px;
border-top: 1px solid var(--line);
}
.landmarks-heading {
margin-bottom: 9px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.14em;
}
.landmark-button {
width: 100%;
display: grid;
grid-template-columns: 1fr auto;
gap: 12px;
align-items: center;
padding: 9px 10px;
margin-top: 6px;
text-align: left;
}
.landmark-button.active {
border-color: rgba(255, 198, 109, 0.6);
background: rgba(255, 198, 109, 0.07);
}
.landmark-name {
font-size: 9px;
letter-spacing: 0.05em;
}
.landmark-meta {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 8px;
}
.lm-bearing {
color: var(--gold);
font-size: 12px;
}
.log {
list-style: none;
padding: 0;
margin: 13px 0 0;
color: var(--muted);
font-size: 8px;
line-height: 1.55;
}
.log li {
padding: 5px 0;
border-top: 1px dotted rgba(176, 218, 220, 0.12);
}
.log time {
color: var(--cyan);
margin-right: 7px;
}
.compass-panel {
position: absolute;
right: 24px;
bottom: 24px;
width: 185px;
padding: 13px;
}
.compass-wrap {
position: relative;
width: 158px;
height: 158px;
margin: 0 auto;
}
.compass-wrap svg {
width: 100%;
height: 100%;
overflow: visible;
}
.compass-ring {
fill: rgba(4, 18, 27, 0.65);
stroke: rgba(118, 214, 210, 0.45);
stroke-width: 1;
}
.compass-ticks {
stroke: rgba(176, 218, 220, 0.34);
stroke-width: 1;
}
.compass-letter {
fill: var(--muted);
font: 8px monospace;
text-anchor: middle;
dominant-baseline: middle;
}
.compass-letter.north {
fill: var(--gold);
}
#needle {
transition: transform 150ms linear;
transform-origin: 80px 80px;
}
.compass-panel.uncertain #needle {
animation: uncertainNeedle 1.7s ease-in-out infinite;
}
@keyframes uncertainNeedle {
0%, 100% { opacity: 0.45; }
50% { opacity: 0.9; }
}
.compass-readout {
display: flex;
justify-content: space-between;
padding-top: 9px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 8px;
letter-spacing: 0.08em;
}
#headingValue {
color: var(--gold);
}
.voyage-controls {
position: absolute;
left: 50%;
bottom: 24px;
transform: translateX(-50%);
width: min(470px, calc(100vw - 420px));
min-width: 360px;
padding: 13px 15px;
}
.voyage-top {
display: flex;
justify-content: space-between;
align-items: center;
gap: 15px;
margin-bottom: 10px;
}
.leg-name {
font-size: 10px;
letter-spacing: 0.09em;
}
.leg-meta {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 8px;
}
.voyage-buttons {
display: flex;
gap: 7px;
}
.voyage-button {
min-width: 70px;
padding: 8px 10px;
font-size: 8px;
letter-spacing: 0.08em;
}
.voyage-button.primary {
border-color: rgba(118, 214, 210, 0.55);
color: var(--cyan);
background: rgba(118, 214, 210, 0.08);
}
.progress-track {
height: 3px;
background: rgba(255, 255, 255, 0.08);
}
#voyageProgress {
width: 5%;
height: 100%;
background: var(--cyan);
box-shadow: 0 0 10px rgba(118, 214, 210, 0.45);
}
.control-hint {
margin-top: 9px;
color: rgba(158, 184, 184, 0.62);
font-size: 7px;
letter-spacing: 0.1em;
text-align: center;
}
#labels {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
overflow: hidden;
}
.world-label {
position: absolute;
transform: translate(-50%, -100%);
display: flex;
align-items: center;
gap: 7px;
padding: 6px 8px;
border: 1px solid rgba(176, 218, 220, 0.28);
background: rgba(4, 17, 25, 0.82);
color: var(--text);
font-size: 8px;
letter-spacing: 0.08em;
white-space: nowrap;
pointer-events: auto;
cursor: pointer;
transition: border-color 150ms ease, background 150ms ease;
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -8px;
width: 1px;
height: 8px;
background: rgba(176, 218, 220, 0.48);
}
.world-label:hover,
.world-label.active {
border-color: var(--gold);
background: rgba(31, 35, 31, 0.92);
}
.world-label .label-code {
color: var(--gold);
}
.world-label.ship-label {
pointer-events: none;
border-color: rgba(118, 214, 210, 0.4);
}
#toast {
position: absolute;
left: 50%;
top: 102px;
transform: translate(-50%, -15px);
max-width: min(460px, calc(100vw - 30px));
padding: 11px 15px;
border: 1px solid rgba(255, 198, 109, 0.5);
background: rgba(17, 31, 34, 0.94);
color: var(--gold);
font-size: 9px;
line-height: 1.5;
letter-spacing: 0.06em;
text-align: center;
opacity: 0;
transition: opacity 200ms ease, transform 200ms ease;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #071722;
color: var(--cyan);
font-size: 10px;
letter-spacing: 0.22em;
transition: opacity 500ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 1050px) {
.route-card {
display: none;
}
.topbar {
grid-template-columns: 1fr auto;
}
.voyage-controls {
width: 400px;
min-width: 0;
left: calc(50% - 30px);
}
}
@media (max-width: 760px) {
.topbar {
padding: 12px;
}
.weather-card {
padding: 8px;
}
.weather-icon {
display: none;
}
h1 {
font-size: 18px;
}
.brand-mark {
width: 30px;
height: 30px;
}
.nav-panel {
left: 10px;
top: 82px;
width: 260px;
padding: 12px;
}
.sky-window {
height: 76px;
}
.log,
.landmarks-section {
display: none;
}
.compass-panel {
right: 10px;
bottom: 92px;
width: 135px;
padding: 9px;
}
.compass-wrap {
width: 114px;
height: 114px;
}
.voyage-controls {
left: 10px;
right: 10px;
bottom: 10px;
width: auto;
transform: none;
}
.voyage-buttons .voyage-button {
min-width: auto;
}
#toast {
top: 78px;
}
}
@media (max-height: 720px) and (min-width: 761px) {
.nav-panel {
top: 96px;
transform: scale(0.92);
transform-origin: top left;
}
.compass-panel {
transform: scale(0.86);
transform-origin: bottom right;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive schematic voxel coastal voyage"></canvas>
<div id="vignette"></div>
<div id="labels"></div>
<main id="hud">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div class="brand-copy">
<p class="eyebrow">Tideline Survey / Passage 07</p>
<h1>The Clouded Meridian</h1>
</div>
</div>
<div class="route-card">
<div class="route-line">WEST QUAY → NORTH CAPE</div>
<div class="route-sub" id="routeSub">COASTAL VOYAGE · CHART 4B · NIGHT PASSAGE</div>
</div>
<div class="weather-card interactive">
<div class="weather-icon" aria-hidden="true"></div>
<div class="weather-value">
CLOUD COVER
<strong id="coverValue">26%</strong>
</div>
</div>
</header>
<section class="nav-panel panel interactive">
<div class="panel-heading">
<h2>Celestial Window</h2>
<span class="tiny-code">FIX / 02</span>
</div>
<div class="sky-window" aria-label="Star visibility preview">
<div class="star-layer" id="starLayer"></div>
<div class="cloud-layer" id="cloudLayer"></div>
<div class="sky-horizon"></div>
<div class="sky-caption">NORTHERN SKY</div>
</div>
<div class="visibility-row">
<span>STAR VISIBILITY</span>
<strong id="visibilityValue">74%</strong>
</div>
<div class="meter"><span id="visibilityBar"></span></div>
<div class="cover-controls">
<button class="mini-button" id="clearSky">CLEAR SKY</button>
<input id="cloudSlider" type="range" min="0" max="100" value="26" aria-label="Cloud cover">
<button class="mini-button" id="summonSquall">SQUALL</button>
</div>
<div class="navigation-status" id="navigationStatus">
<div class="status-row">
<span class="status-dot"></span>
<span id="statusTitle">STAR FIX LOCKED</span>
</div>
<p id="statusCopy">The north star is visible. Celestial orientation is available with high confidence.</p>
</div>
<div class="mode-grid" aria-label="Navigation mode">
<button class="mode-button active" data-mode="stars">STARS</button>
<button class="mode-button" data-mode="landmarks">LANDMARKS</button>
<button class="mode-button" data-mode="uncertain">UNCERTAIN</button>
</div>
<button class="action-button" id="contextAction">MARK ORIENTATION UNCERTAIN</button>
<section class="landmarks-section">
<div class="landmarks-heading">VISIBLE SHORELINE FIXES</div>
<div id="landmarkList"></div>
<ol class="log" id="voyageLog"></ol>
</section>
</section>
<section class="voyage-controls panel interactive">
<div class="voyage-top">
<div>
<div class="leg-name" id="legName">DEPARTURE CHANNEL</div>
<span class="leg-meta" id="voyageMeta">VOXEL CUTTER · 00:00 ELAPSED</span>
</div>
<div class="voyage-buttons">
<button class="voyage-button primary" id="sailToggle">PAUSE</button>
<button class="voyage-button" id="resetVoyage">RESET</button>
</div>
</div>
<div class="progress-track"><div id="voyageProgress"></div></div>
<div class="control-hint">DRAG TO ORBIT · SCROLL TO ZOOM · SPACE TO PAUSE · L FOR LANDMARKS · U FOR UNCERTAIN</div>
</section>
<section class="compass-panel panel" id="compassPanel">
<div class="compass-wrap">
<svg viewBox="0 0 160 160" aria-label="Ship heading compass">
<circle class="compass-ring" cx="80" cy="80" r="69"></circle>
<circle class="compass-ticks" cx="80" cy="80" r="57" fill="none" stroke-dasharray="1 7"></circle>
<path class="compass-ticks" d="M80 11v10 M80 139v10 M11 80h10 M139 80h10"></path>
<text class="compass-letter north" x="80" y="19">N</text>
<text class="compass-letter" x="143" y="80">E</text>
<text class="compass-letter" x="80" y="146">S</text>
<text class="compass-letter" x="17" y="80">W</text>
<g id="needle">
<path d="M80 25 L87 83 L80 76 L73 83 Z" fill="#ffc66d"></path>
<path d="M80 135 L73 77 L80 84 L87 77 Z" fill="#52727b"></path>
<circle cx="80" cy="80" r="5" fill="#071722" stroke="#76d6d2"></circle>
</g>
</svg>
</div>
<div class="compass-readout">
<span>SHIP HEADING</span>
<span id="headingValue">090°</span>
</div>
</section>
<div id="toast" role="status" aria-live="polite"></div>
</main>
<div id="loading">BUILDING COASTAL CHART…</div>
<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 scene = new THREE.Scene();
scene.background = new THREE.Color(0x071722);
scene.fog = new THREE.Fog(0x071722, 76, 138);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.6));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.18;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
220
);
const cameraState = {
target: new THREE.Vector3(0, 2, 3),
radius: 91,
azimuth: 0.69,
elevation: 0.66
};
function updateCamera() {
const { target, radius, azimuth, elevation } = cameraState;
camera.position.set(
target.x + radius * Math.sin(azimuth) * Math.cos(elevation),
target.y + radius * Math.sin(elevation),
target.z + radius * Math.cos(azimuth) * Math.cos(elevation)
);
camera.lookAt(target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xb8e0e7, 0x10251e, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffdfb0, 2.6);
sun.position.set(-28, 48, 24);
sun.castShadow = true;
sun.shadow.mapSize.set(1024, 1024);
sun.shadow.camera.left = -58;
sun.shadow.camera.right = 58;
sun.shadow.camera.top = 48;
sun.shadow.camera.bottom = -48;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 130;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x5cced4, 0.75);
rimLight.position.set(34, 22, -28);
scene.add(rimLight);
let randomSeed = 84173;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
function coastEdge(x) {
return -9 + 4 * Math.sin(x * 0.13) + 2 * Math.cos(x * 0.045);
}
function surfaceHeight(x, z) {
const distance = coastEdge(x) - z;
if (distance < 4.5) return 0.78 + random() * 0.25;
return 1.3 + random() * 2.2;
}
// Water and chart plinth.
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x0b3544,
roughness: 0.86,
metalness: 0.04
});
const water = new THREE.Mesh(
new THREE.BoxGeometry(100, 1.2, 60),
waterMaterial
);
water.position.set(0, -0.68, 8);
water.receiveShadow = true;
scene.add(water);
const plinth = new THREE.Mesh(
new THREE.BoxGeometry(101.2, 1.8, 61.2),
new THREE.MeshStandardMaterial({ color: 0x06151f, roughness: 0.95 })
);
plinth.position.set(0, -1.9, 8);
scene.add(plinth);
// Contour and wave marks.
const wavePositions = [];
for (let i = 0; i < 390; i++) {
const x = -48 + random() * 96;
const z = -6 + random() * 49;
if (Math.abs(x + 24) < 5 && Math.abs(z - 14) < 4) continue;
if (Math.abs(x - 14) < 5 && Math.abs(z - 15) < 4) continue;
const length = 0.45 + random() * 1.6;
wavePositions.push(x, 0.02, z, x + length, 0.02, z);
}
const waveGeometry = new THREE.BufferGeometry();
waveGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(wavePositions, 3)
);
const waveMaterial = new THREE.LineBasicMaterial({
color: 0x62b7ba,
transparent: true,
opacity: 0.23
});
const waves = new THREE.LineSegments(waveGeometry, waveMaterial);
scene.add(waves);
// Instanced voxel coastline.
const terrainBuckets = {
sand: [],
grass: [],
rock: []
};
for (let ix = -25; ix <= 25; ix++) {
const x = ix * 2;
const edge = coastEdge(x);
for (let z = -27; z < edge - 0.35; z += 2) {
const distance = edge - z;
let type = "grass";
let height = 1.25 + random() * 2.4;
if (distance < 4.5) {
type = "sand";
height = 0.72 + random() * 0.3;
} else if (distance < 7.2 && random() < 0.33) {
type = "rock";
height = 2.2 + random() * 1.4;
}
terrainBuckets[type].push({
x,
z,
height,
color: random()
});
}
}
const terrainGeometry = new THREE.BoxGeometry(2, 1, 2);
const dummy = new THREE.Object3D();
const terrainColors = {
sand: new THREE.Color(0xc6b987),
grass: new THREE.Color(0x56785f),
rock: new THREE.Color(0x69727a)
};
Object.entries(terrainBuckets).forEach(([type, blocks]) => {
const material = new THREE.MeshStandardMaterial({
roughness: 0.95,
metalness: 0,
vertexColors: true
});
const mesh = new THREE.InstancedMesh(
terrainGeometry,
material,
blocks.length
);
blocks.forEach((block, index) => {
dummy.position.set(block.x, block.height / 2, block.z);
dummy.scale.set(1, block.height, 1);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
const color = terrainColors[type].clone();
color.offsetHSL(
(random() - 0.5) * 0.025,
(random() - 0.5) * 0.08,
(random() - 0.5) * 0.09
);
mesh.setColorAt(index, color);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.instanceColor.needsUpdate = true;
mesh.receiveShadow = true;
scene.add(mesh);
});
// Small voxel trees.
const trunkMaterial = new THREE.MeshStandardMaterial({
color: 0x58483a,
roughness: 1
});
const crownMaterial = new THREE.MeshStandardMaterial({
color: 0x3e6854,
roughness: 1
});
for (let i = 0; i < 54; i++) {
const x = -47 + random() * 94;
const z = -26 + random() * 14;
if (z > coastEdge(x) - 6) continue;
const ground = 1.3 + random() * 1.5;
const trunk = new THREE.Mesh(
new THREE.BoxGeometry(0.34, 1.35, 0.34),
trunkMaterial
);
trunk.position.set(x, ground + 0.67, z);
scene.add(trunk);
const crown = new THREE.Mesh(
new THREE.BoxGeometry(1.5 + random(), 1.6, 1.5 + random()),
crownMaterial
);
crown.position.set(x, ground + 1.75, z);
crown.rotation.y = random() * Math.PI;
scene.add(crown);
}
function buildIslet(x, z, scale = 1) {
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0x697278,
roughness: 1
});
const group = new THREE.Group();
const base = new THREE.Mesh(
new THREE.BoxGeometry(5 * scale, 1.2 * scale, 3.4 * scale),
rockMaterial
);
base.position.y = 0.55 * scale;
group.add(base);
const middle = new THREE.Mesh(
new THREE.BoxGeometry(3.1 * scale, 2.1 * scale, 2.5 * scale),
rockMaterial
);
middle.position.set(0.4 * scale, 1.8 * scale, 0);
group.add(middle);
const top = new THREE.Mesh(
new THREE.BoxGeometry(1.7 * scale, 1.5 * scale, 1.8 * scale),
rockMaterial
);
top.position.set(-0.2 * scale, 3.1 * scale, 0.1);
group.add(top);
group.position.set(x, 0, z);
group.traverse(object => {
if (object.isMesh) {
object.castShadow = true;
object.receiveShadow = true;
}
});
scene.add(group);
return group;
}
buildIslet(-24, 15, 0.9);
buildIslet(14, 15, 0.75);
// Route.
const routePoints = [
new THREE.Vector3(-43, 0.1, 7),
new THREE.Vector3(-32, 0.1, 9),
new THREE.Vector3(-19, 0.1, 6),
new THREE.Vector3(-7, 0.1, 10),
new THREE.Vector3(7, 0.1, 5),
new THREE.Vector3(20, 0.1, 8),
new THREE.Vector3(32, 0.1, 4),
new THREE.Vector3(43, 0.1, 7)
];
const routeCurve = new THREE.CatmullRomCurve3(routePoints, false, "catmullrom", 0.3);
const routeLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(routePoints),
new THREE.LineDashedMaterial({
color: 0x76d6d2,
transparent: true,
opacity: 0.46,
dashSize: 0.8,
gapSize: 0.65
})
);
routeLine.computeLineDistances();
scene.add(routeLine);
routePoints.forEach(point => {
const ring = new THREE.Mesh(
new THREE.RingGeometry(0.65, 0.83, 20),
new THREE.MeshBasicMaterial({
color: 0x76d6d2,
transparent: true,
opacity: 0.46,
side: THREE.DoubleSide
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.set(point.x, 0.08, point.z);
scene.add(ring);
});
// Landmarks.
const landmarks = [
{
id: "harbor",
name: "West Harbor Beacon",
code: "WHB",
position: new THREE.Vector3(-33, 0, -10),
color: 0xff796b
},
{
id: "stack",
name: "Meridian Sea Stack",
code: "MSS",
position: new THREE.Vector3(4, 0, -10),
color: 0x76d6d2
},
{
id: "cape",
name: "North Cape Light",
code: "NCL",
position: new THREE.Vector3(29, 0, -10),
color: 0xffc66d
}
];
function voxelBox(parent, size, position, color, emissive = 0x000000) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.75,
emissive,
emissiveIntensity: emissive ? 0.8 : 0
});
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function buildLighthouse(position) {
const group = new THREE.Group();
group.userData.landmarkId = "cape";
voxelBox(group, [2.8, 0.45, 2.8], [0, 0.2, 0], 0x77756b);
voxelBox(group, [1.55, 2.1, 1.55], [0, 1.4, 0], 0xe6e1cf);
voxelBox(group, [1.72, 0.65, 1.72], [0, 2.65, 0], 0xca594e);
voxelBox(group, [1.45, 1.5, 1.45], [0, 3.65, 0], 0xe6e1cf);
voxelBox(group, [2.05, 0.3, 2.05], [0, 4.55, 0], 0x39474a);
voxelBox(group, [1.3, 1.05, 1.3], [0, 5.15, 0], 0xffd97e, 0xffb83d);
voxelBox(group, [1.75, 0.55, 1.75], [0, 5.92, 0], 0x39474a);
voxelBox(group, [0.3, 0.85, 0.3], [0, 6.55, 0], 0x39474a);
const light = new THREE.PointLight(0xffc96b, 3.5, 16, 2);
light.position.set(0, 5.15, 0);
group.add(light);
group.position.copy(position);
scene.add(group);
return group;
}
function buildBeacon(position) {
const group = new THREE.Group();
group.userData.landmarkId = "harbor";
voxelBox(group, [2.1, 0.4, 2.1], [0, 0.2, 0], 0x77756b);
voxelBox(group, [1.15, 3.1, 1.15], [0, 1.75, 0], 0xe6e1cf);
voxelBox(group, [1.35, 0.65, 1.35], [0, 2.2, 0], 0xca594e);
voxelBox(group, [0.95, 0.85, 0.95], [0, 3.7, 0], 0xffd97e, 0xffb83d);
voxelBox(group, [1.35, 0.35, 1.35], [0, 4.3, 0], 0x39474a);
const light = new THREE.PointLight(0xff796b, 2.1, 11, 2);
light.position.set(0, 3.7, 0);
group.add(light);
group.position.copy(position);
scene.add(group);
return group;
}
const capeLight = buildLighthouse(landmarks[2].position);
const harborBeacon = buildBeacon(landmarks[0].position);
const stackGroup = new THREE.Group();
stackGroup.userData.landmarkId = "stack";
voxelBox(stackGroup, [4.2, 1.0, 3.1], [0, 0.5, 0], 0x59666d);
voxelBox(stackGroup, [2.7, 2.7, 2.3], [0.4, 2.3, 0], 0x6f7779);
voxelBox(stackGroup, [1.6, 1.6, 1.7], [-0.2, 4.2, 0], 0x7f8583);
voxelBox(stackGroup, [0.55, 1.8, 0.55], [-0.2, 5.65, 0], 0x76d6d2, 0x2e8889);
stackGroup.position.copy(landmarks[1].position);
scene.add(stackGroup);
const pickables = [capeLight, harborBeacon, stackGroup];
// Voxel cutter.
const ship = new THREE.Group();
const hullMaterial = new THREE.MeshStandardMaterial({
color: 0x17313c,
roughness: 0.72
});
const deckMaterial = new THREE.MeshStandardMaterial({
color: 0xc3a86b,
roughness: 0.9
});
const trimMaterial = new THREE.MeshStandardMaterial({
color: 0xff796b,
roughness: 0.68
});
const sailMaterial = new THREE.MeshStandardMaterial({
color: 0xe8e3cf,
roughness: 0.95
});
voxelBox(ship, [4.8, 0.9, 2.0], [0, 0.48, 0], 0x17313c);
voxelBox(ship, [1.2, 0.85, 1.55], [2.55, 0.58, 0], 0x17313c);
voxelBox(ship, [0.65, 0.75, 1.2], [3.22, 0.62, 0], 0x17313c);
voxelBox(ship, [4.15, 0.25, 1.62], [0, 1.03, 0], 0xc3a86b);
voxelBox(ship, [1.5, 1.1, 1.35], [-0.75, 1.65, 0], 0xd8d2ba);
voxelBox(ship, [0.92, 0.48, 1.38], [-0.75, 2.4, 0], 0xff796b);
voxelBox(ship, [0.22, 3.3, 0.22], [0.75, 2.45, 0], 0x594a38);
voxelBox(ship, [2.1, 2.0, 0.18], [0.2, 2.6, 0], 0xe8e3cf);
voxelBox(ship, [0.75, 0.22, 0.12], [0.75, 4.03, 0], 0xff796b);
const wakeMaterial = new THREE.MeshBasicMaterial({
color: 0xb6e5dc,
transparent: true,
opacity: 0.24
});
for (let i = 0; i < 6; i++) {
const wake = new THREE.Mesh(
new THREE.BoxGeometry(0.65, 0.05, 0.45 + i * 0.1),
wakeMaterial
);
wake.position.set(-2.7 - i * 0.72, 0.08, (i % 2 ? 1 : -1) * (0.15 + i * 0.08));
ship.add(wake);
}
ship.traverse(object => {
if (object.isMesh) object.castShadow = true;
});
scene.add(ship);
// Night sky points behind the cloud layer.
const starPositions = [];
const starColors = [];
for (let i = 0; i < 150; i++) {
const x = -48 + random() * 96;
const y = 21 + random() * 15;
const z = -7 - random() * 12;
starPositions.push(x, y, z);
const color = new THREE.Color().setHSL(0.52 + random() * 0.08, 0.35, 0.72 + random() * 0.25);
starColors.push(color.r, color.g, color.b);
}
const starGeometry = new THREE.BufferGeometry();
starGeometry.setAttribute("position", new THREE.Float32BufferAttribute(starPositions, 3));
starGeometry.setAttribute("color", new THREE.Float32BufferAttribute(starColors, 3));
const starMaterial = new THREE.PointsMaterial({
size: 0.52,
vertexColors: true,
transparent: true,
opacity: 0.9,
depthWrite: false,
sizeAttenuation: true
});
const stars = new THREE.Points(starGeometry, starMaterial);
scene.add(stars);
const northStar = new THREE.Mesh(
new THREE.SphereGeometry(0.58, 8, 8),
new THREE.MeshBasicMaterial({
color: 0xffd681,
transparent: true,
opacity: 1
})
);
northStar.position.set(-12, 28.5, -7);
scene.add(northStar);
const starHaloMaterial = new THREE.SpriteMaterial({
color: 0xffcc76,
transparent: true,
opacity: 0.7,
depthWrite: false
});
const haloCanvas = document.createElement("canvas");
haloCanvas.width = 64;
haloCanvas.height = 64;
const haloContext = haloCanvas.getContext("2d");
const haloGradient = haloContext.createRadialGradient(32, 32, 0, 32, 32, 32);
haloGradient.addColorStop(0, "rgba(255,220,140,1)");
haloGradient.addColorStop(0.15, "rgba(255,205,110,.7)");
haloGradient.addColorStop(1, "rgba(255,205,110,0)");
haloContext.fillStyle = haloGradient;
haloContext.fillRect(0, 0, 64, 64);
const haloTexture = new THREE.CanvasTexture(haloCanvas);
starHaloMaterial.map = haloTexture;
const starHalo = new THREE.Sprite(starHaloMaterial);
starHalo.position.copy(northStar.position);
starHalo.scale.set(5.5, 5.5, 1);
scene.add(starHalo);
// Voxel clouds between the camera and celestial layer.
const cloudMaterial = new THREE.MeshStandardMaterial({
color: 0xb4c7c9,
roughness: 1,
transparent: true,
opacity: 0.5,
depthWrite: false
});
const cloudShadowMaterial = new THREE.MeshStandardMaterial({
color: 0x718b92,
roughness: 1,
transparent: true,
opacity: 0.42,
depthWrite: false
});
const clouds = [];
const cloudLayout = [
[-40, 29, 7, 1.1],
[-26, 31, 11, 1.2],
[-11, 29, 8, 1.0],
[5, 32, 12, 1.15],
[22, 29, 7, 1.25],
[38, 30, 11, 1.0]
];
cloudLayout.forEach(([x, y, z, scale], cloudIndex) => {
const group = new THREE.Group();
group.position.set(x, y, z);
group.userData.baseX = x;
group.userData.speed = 0.12 + random() * 0.13;
group.userData.phase = random() * Math.PI * 2;
const pieces = 5 + Math.floor(random() * 4);
for (let i = 0; i < pieces; i++) {
const width = 3.2 + random() * 4.5;
const depth = 2.8 + random() * 3.5;
const height = 1.4 + random() * 1.8;
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
i % 3 === 0 ? cloudShadowMaterial : cloudMaterial
);
mesh.position.set(
(random() - 0.5) * 7,
(random() - 0.5) * 1.5,
(random() - 0.5) * 4
);
group.add(mesh);
}
group.scale.setScalar(scale);
scene.add(group);
clouds.push(group);
});
// Bearing lines.
const bearingLines = landmarks.map(() => {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(),
new THREE.Vector3()
]);
const material = new THREE.LineDashedMaterial({
color: 0xffc66d,
transparent: true,
opacity: 0.8,
dashSize: 0.9,
gapSize: 0.6
});
const line = new THREE.Line(geometry, material);
line.visible = false;
scene.add(line);
return line;
});
const northLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([new THREE.Vector3(), northStar.position]),
new THREE.LineDashedMaterial({
color: 0xffd681,
transparent: true,
opacity: 0.34,
dashSize: 0.8,
gapSize: 0.8
})
);
northLine.computeLineDistances();
northLine.visible = false;
scene.add(northLine);
// World-space labels.
const labelRoot = document.querySelector("#labels");
const worldLabels = [];
landmarks.forEach(landmark => {
const label = document.createElement("button");
label.className = "world-label";
label.dataset.landmark = landmark.id;
label.innerHTML = `<span class="label-code">${landmark.code}</span><span>${landmark.name}</span>`;
label.addEventListener("click", () => selectLandmark(landmark.id));
labelRoot.appendChild(label);
worldLabels.push({
element: label,
position: landmark.position.clone().add(new THREE.Vector3(0, 8.8, 0)),
landmarkId: landmark.id
});
});
const shipLabel = document.createElement("div");
shipLabel.className = "world-label ship-label";
shipLabel.innerHTML = `<span class="label-code">VC-01</span><span>VOXEL CUTTER</span>`;
labelRoot.appendChild(shipLabel);
worldLabels.push({
element: shipLabel,
position: new THREE.Vector3(),
ship: true
});
// Navigation state.
let mode = "stars";
let selectedLandmark = "cape";
let cloudCover = 0.26;
let visibility = 0.74;
let sailing = true;
let progress = 0.045;
let elapsed = 0;
let lastUiUpdate = 0;
let wasObscured = false;
let toastTimer = null;
const landmarkList = document.querySelector("#landmarkList");
landmarks.forEach(landmark => {
const button = document.createElement("button");
button.className = "landmark-button";
button.dataset.landmark = landmark.id;
button.innerHTML = `
<span>
<span class="landmark-name">${landmark.name}</span>
<span class="landmark-meta">range <span class="lm-range">—</span></span>
</span>
<span class="lm-bearing">—</span>
`;
button.addEventListener("click", () => selectLandmark(landmark.id));
landmarkList.appendChild(button);
});
// DOM star and cloud preview.
const starLayer = document.querySelector("#starLayer");
const cloudLayer = document.querySelector("#cloudLayer");
for (let i = 0; i < 32; i++) {
const star = document.createElement("i");
star.className = "star";
star.style.left = `${5 + random() * 90}%`;
star.style.top = `${5 + random() * 72}%`;
const size = random() > 0.82 ? 3 : 2;
star.style.width = `${size}px`;
star.style.height = `${size}px`;
starLayer.appendChild(star);
}
const northPreview = document.createElement("i");
northPreview.className = "star north";
starLayer.appendChild(northPreview);
for (let i = 0; i < 5; i++) {
const cloud = document.createElement("i");
cloud.className = "cloud-pixel";
cloud.style.left = `${-20 + i * 23 + random() * 8}%`;
cloud.style.top = `${8 + random() * 48}%`;
cloud.style.transform = `scale(${0.65 + random() * 0.7})`;
cloudLayer.appendChild(cloud);
}
function formatTime(seconds) {
const minutes = Math.floor(seconds / 60).toString().padStart(2, "0");
const remainder = Math.floor(seconds % 60).toString().padStart(2, "0");
return `${minutes}:${remainder}`;
}
function addLog(message) {
const log = document.querySelector("#voyageLog");
const item = document.createElement("li");
const time = document.createElement("time");
time.textContent = formatTime(elapsed);
item.appendChild(time);
item.appendChild(document.createTextNode(message));
log.prepend(item);
while (log.children.length > 3) log.lastElementChild.remove();
}
function showToast(message) {
const toast = document.querySelector("#toast");
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 3600);
}
function bearingTo(position) {
const dx = position.x - ship.position.x;
const dz = position.z - ship.position.z;
return (THREE.MathUtils.radToDeg(Math.atan2(dx, -dz)) + 360) % 360;
}
function selectLandmark(id) {
selectedLandmark = id;
setMode("landmarks", false);
const landmark = landmarks.find(item => item.id === id);
addLog(`Bearing taken from ${landmark.name}.`);
showToast(`${landmark.name.toUpperCase()} SELECTED — SHORELINE BEARING ACTIVE`);
updateUi(true);
}
function setMode(nextMode, announce = true) {
mode = nextMode;
document.querySelectorAll(".mode-button").forEach(button => {
button.classList.toggle("active", button.dataset.mode === mode);
});
if (announce) {
if (mode === "landmarks") {
addLog("Navigation switched to visible shoreline landmarks.");
showToast("LANDMARK NAVIGATION ACTIVE");
} else if (mode === "uncertain") {
addLog("Orientation explicitly marked uncertain.");
showToast("ORIENTATION MARKED UNCERTAIN");
} else {
addLog("Celestial navigation selected.");
showToast("CELESTIAL NAVIGATION SELECTED");
}
}
updateUi(true);
}
function setCloudCover(value) {
cloudCover = clamp(value / 100, 0, 1);
visibility = 1 - cloudCover;
document.querySelector("#cloudSlider").value = Math.round(cloudCover * 100);
updateUi(true);
}
function updateWeather() {
const obscured = visibility < 0.45;
const starOpacity = 0.08 + visibility * 0.92;
starMaterial.opacity = starOpacity;
northStar.material.opacity = starOpacity;
starHaloMaterial.opacity = starOpacity * 0.7;
starLayer.style.opacity = String(0.08 + visibility * 0.92);
cloudLayer.style.opacity = String(0.08 + cloudCover * 0.9);
cloudLayer.style.transform = `translateX(${(cloudCover - 0.5) * 18}px)`;
cloudMaterial.opacity = 0.18 + cloudCover * 0.68;
cloudShadowMaterial.opacity = 0.12 + cloudCover * 0.5;
clouds.forEach(cloud => {
const scale = 0.55 + cloudCover * 0.65;
cloud.scale.setScalar(scale * cloud.userData.baseScale || scale);
cloud.visible = cloudCover > 0.035;
});
if (obscured && !wasObscured) {
addLog("North star obscured. Orientation is uncertain.");
showToast("CLOUDS HAVE HIDDEN THE NORTH STAR — ORIENTATION UNCERTAIN");
}
wasObscured = obscured;
}
function updateUi(force = false) {
if (!force && elapsed - lastUiUpdate < 0.12) return;
lastUiUpdate = elapsed;
const clear = visibility >= 0.45;
const statusPanel = document.querySelector("#navigationStatus");
const statusTitle = document.querySelector("#statusTitle");
const statusCopy = document.querySelector("#statusCopy");
const action = document.querySelector("#contextAction");
const compassPanel = document.querySelector("#compassPanel");
document.querySelector("#coverValue").textContent = `${Math.round(cloudCover * 100)}%`;
document.querySelector("#visibilityValue").textContent = `${Math.round(visibility * 100)}%`;
document.querySelector("#visibilityBar").style.width = `${visibility * 100}%`;
if (mode === "stars") {
if (clear) {
statusTitle.textContent = "STAR FIX LOCKED";
statusCopy.textContent = "The north star is visible. Celestial orientation is available with high confidence.";
statusPanel.classList.remove("warning");
action.textContent = "MARK ORIENTATION UNCERTAIN";
} else {
statusTitle.textContent = "ORIENTATION UNCERTAIN";
statusCopy.textContent = "Cloud cover hides the north star. Use a visible shoreline landmark or keep your last estimated heading.";
statusPanel.classList.add("warning");
action.textContent = "USE VISIBLE LANDMARKS";
}
} else if (mode === "landmarks") {
const landmark = landmarks.find(item => item.id === selectedLandmark);
statusTitle.textContent = "LANDMARK BEARING FIX";
statusCopy.textContent = `Orientation is referenced to ${landmark.name}. The highlighted bearing line is the current visual fix.`;
statusPanel.classList.remove("warning");
action.textContent = "MARK ORIENTATION UNCERTAIN";
} else {
statusTitle.textContent = "ORIENTATION UNCERTAIN";
statusCopy.textContent = "The vessel is proceeding by estimate only. No reliable celestial or shoreline reference is being used.";
statusPanel.classList.add("warning");
action.textContent = "RECOVER VIA LANDMARKS";
}
compassPanel.classList.toggle("uncertain", mode === "uncertain" || (mode === "stars" && !clear));
landmarks.forEach((landmark, index) => {
const button = landmarkList.querySelector(`[data-landmark="${landmark.id}"]`);
const bearing = bearingTo(landmark.position);
const range = Math.hypot(
landmark.position.x - ship.position.x,
landmark.position.z - ship.position.z
) / 7;
button.querySelector(".lm-bearing").textContent = `${Math.round(bearing).toString().padStart(3, "0")}°`;
button.querySelector(".lm-range").textContent = `${range.toFixed(1)} nm`;
button.classList.toggle("active", landmark.id === selectedLandmark);
const label = worldLabels.find(item => item.landmarkId === landmark.id);
if (label) label.element.classList.toggle("active", landmark.id === selectedLandmark);
});
const tangent = routeCurve.getTangentAt(clamp(progress, 0, 0.9999)).normalize();
const heading = (THREE.MathUtils.radToDeg(Math.atan2(tangent.x, -tangent.z)) + 360) % 360;
const uncertaintyOffset = mode === "uncertain" ? Math.sin(elapsed * 5) * 3.5 : 0;
document.querySelector("#needle").setAttribute(
"transform",
`rotate(${heading + uncertaintyOffset} 80 80)`
);
document.querySelector("#headingValue").textContent =
`${Math.round(heading).toString().padStart(3, "0")}°${mode === "uncertain" ? " ?" : ""}`;
document.querySelector("#voyageProgress").style.width = `${progress * 100}%`;
document.querySelector("#voyageMeta").textContent =
`VOXEL CUTTER · ${formatTime(elapsed)} ELAPSED`;
const legNames = [
"DEPARTURE CHANNEL",
"WEST QUAY APPROACH",
"LOW ISLET PASSAGE",
"MERIDIAN STACK BEARING",
"CAPE REEF TURN",
"NORTH CAPE ARRIVAL"
];
const legIndex = Math.min(legNames.length - 1, Math.floor(progress * legNames.length));
document.querySelector("#legName").textContent = legNames[legIndex];
document.querySelector("#routeSub").textContent =
`${Math.round(progress * 100)}% COMPLETE · ${visibility < 0.45 ? "CLOUDS" : "CLEAR SKY"} · CHART 4B`;
updateWeather();
}
// Pointer-driven camera controls, implemented without external controls.
let dragging = false;
let pointerMoved = false;
let lastPointerX = 0;
let lastPointerY = 0;
canvas.addEventListener("pointerdown", event => {
dragging = true;
pointerMoved = false;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
if (Math.abs(deltaX) + Math.abs(deltaY) > 2) pointerMoved = true;
cameraState.azimuth -= deltaX * 0.005;
cameraState.elevation = clamp(
cameraState.elevation + deltaY * 0.004,
0.3,
1.08
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
});
canvas.addEventListener("pointerup", event => {
dragging = false;
canvas.style.cursor = "grab";
if (!pointerMoved) handleSceneClick(event);
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
canvas.style.cursor = "grab";
});
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = clamp(
cameraState.radius + event.deltaY * 0.055,
51,
112
);
updateCamera();
}, { passive: false });
canvas.style.cursor = "grab";
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function handleSceneClick(event) {
pointer.x = (event.clientX / window.innerWidth) * 2 - 1;
pointer.y = -(event.clientY / window.innerHeight) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickables, true);
if (!hits.length) return;
let object = hits[0].object;
while (object && !object.userData.landmarkId) object = object.parent;
if (object?.userData.landmarkId) {
selectLandmark(object.userData.landmarkId);
}
}
// UI controls.
document.querySelectorAll(".mode-button").forEach(button => {
button.addEventListener("click", () => setMode(button.dataset.mode));
});
document.querySelector("#contextAction").addEventListener("click", () => {
if (mode === "stars" && visibility < 0.45) {
setMode("landmarks");
} else if (mode === "uncertain") {
setMode("landmarks");
} else {
setMode("uncertain");
}
});
document.querySelector("#cloudSlider").addEventListener("input", event => {
setCloudCover(Number(event.target.value));
});
document.querySelector("#clearSky").addEventListener("click", () => {
setCloudCover(7);
showToast("CLEAR SKY REQUESTED — NORTH STAR VISIBLE");
});
document.querySelector("#summonSquall").addEventListener("click", () => {
setCloudCover(86);
showToast("SQUALL LINE ENTERING — STAR FIX LOST");
});
document.querySelector("#sailToggle").addEventListener("click", () => {
sailing = !sailing;
document.querySelector("#sailToggle").textContent = sailing ? "PAUSE" : "RESUME";
});
document.querySelector("#resetVoyage").addEventListener("click", () => {
progress = 0.045;
elapsed = 0;
sailing = true;
document.querySelector("#sailToggle").textContent = "PAUSE";
addLog("Voyage reset to departure channel.");
updateUi(true);
});
window.addEventListener("keydown", event => {
if (event.code === "Space") {
event.preventDefault();
document.querySelector("#sailToggle").click();
}
if (event.key.toLowerCase() === "l") setMode("landmarks");
if (event.key.toLowerCase() === "u") setMode("uncertain");
if (event.key.toLowerCase() === "s") setMode("stars");
if (event.key.toLowerCase() === "c") setCloudCover(7);
});
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.6));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
function updateLabels() {
worldLabels.forEach(label => {
const position = label.ship
? ship.position.clone().add(new THREE.Vector3(0, 5.1, 0))
: label.position;
const projected = position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.display = visible ? "flex" : "none";
if (!visible) return;
label.element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
label.element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
});
}
function updateBearingLines() {
const showLandmarks = mode === "landmarks";
const showNorth = mode === "stars" && visibility >= 0.45;
bearingLines.forEach((line, index) => {
line.visible = showLandmarks;
if (!showLandmarks) return;
const landmark = landmarks[index];
const positions = line.geometry.attributes.position;
positions.setXYZ(0, ship.position.x, 0.22, ship.position.z);
positions.setXYZ(1, landmark.position.x, 0.22, landmark.position.z);
positions.needsUpdate = true;
line.computeLineDistances();
line.material.opacity = landmark.id === selectedLandmark ? 0.85 : 0.18;
line.material.color.setHex(landmark.id === selectedLandmark ? 0xffc66d : 0x76d6d2);
});
northLine.visible = showNorth;
if (showNorth) {
const positions = northLine.geometry.attributes.position;
positions.setXYZ(0, ship.position.x, 0.25, ship.position.z);
positions.needsUpdate = true;
northLine.computeLineDistances();
}
}
const clock = new THREE.Clock();
let firstFrame = true;
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
if (sailing && progress < 1) {
progress = Math.min(1, progress + delta * 0.009);
if (progress >= 1) {
sailing = false;
document.querySelector("#sailToggle").textContent = "REPLAY";
addLog("North Cape reached. Voyage complete.");
showToast("NORTH CAPE REACHED — VOYAGE COMPLETE");
}
}
const routePosition = routeCurve.getPointAt(clamp(progress, 0, 1));
const tangent = routeCurve.getTangentAt(clamp(progress, 0, 0.9999)).normalize();
ship.position.copy(routePosition);
ship.position.y = 0.04 + Math.sin(elapsed * 1.8) * 0.045;
ship.rotation.z = Math.sin(elapsed * 1.35) * 0.015;
const heading = Math.atan2(tangent.x, -tangent.z);
ship.rotation.y = Math.PI / 2 - heading;
waves.position.x = Math.sin(elapsed * 0.28) * 0.18;
waves.position.z = Math.cos(elapsed * 0.21) * 0.12;
waveMaterial.opacity = 0.19 + Math.sin(elapsed * 0.8) * 0.035;
clouds.forEach((cloud, index) => {
const data = cloud.userData;
cloud.position.x = data.baseX + Math.sin(elapsed * data.speed + data.phase) * 2.6;
cloud.position.y += Math.sin(elapsed * 0.35 + index) * 0.001;
const cloudScale = 0.52 + cloudCover * 0.78;
cloud.scale.setScalar(cloudScale);
});
northStar.material.opacity = 0.08 + visibility * 0.92;
northStar.scale.setScalar(0.85 + visibility * 0.25);
starHaloMaterial.opacity = (0.08 + visibility * 0.92) * 0.65;
starHalo.scale.setScalar(4.8 + visibility * 1.2);
updateBearingLines();
updateLabels();
updateUi();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
document.querySelector("#loading").classList.add("hidden");
}
});
addLog("Departure channel entered. Celestial fix available.");
updateWeather();
updateUi(true);
</script>
</body>
</html>
```