Prompt specification
Build or customize the Three.js 3D scene "Compare route estimates from different observed cues" 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: Compare route estimates from different observed cues
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/compare-route-estimates-from-different-observed-cues-x2612
Scene Description Prompt:
Use Three.js from cdnjs in one HTML file to explore uncertain positions from fictional Polynesian voyage observations in a voxel ocean.
Working Three.js Starter (compare-route-estimates-from-different-observed-cues-x2612):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Nalele — Fictional Voyage Lab</title>
<style>
:root {
--ink: #eaf8f7;
--muted: #8eacb2;
--panel: rgba(5, 22, 29, 0.92);
--panel-soft: rgba(255, 255, 255, 0.055);
--line: rgba(171, 224, 224, 0.14);
--cyan: #6ee7e5;
--amber: #ffc46b;
--coral: #ff826c;
--shadow: 0 24px 70px rgba(0, 0, 0, 0.36);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #061820;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#viewport,
#viewport canvas,
#labels {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#viewport canvas {
display: block;
touch-action: none;
cursor: grab;
}
#viewport canvas:active {
cursor: grabbing;
}
#labels {
z-index: 3;
pointer-events: none;
overflow: hidden;
}
.obs-label {
position: absolute;
z-index: 4;
display: none;
max-width: 170px;
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 5px;
background: rgba(4, 18, 24, 0.82);
color: #dff7f4;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.07em;
line-height: 1.15;
text-transform: uppercase;
white-space: nowrap;
pointer-events: auto;
cursor: pointer;
transform: translate(-50%, -100%);
box-shadow: 0 7px 20px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(8px);
}
.obs-label::after {
position: absolute;
bottom: -5px;
left: 50%;
width: 7px;
height: 7px;
border-right: 1px solid rgba(255, 255, 255, 0.15);
border-bottom: 1px solid rgba(255, 255, 255, 0.15);
background: rgba(4, 18, 24, 0.82);
content: "";
transform: translateX(-50%) rotate(45deg);
}
.obs-label.selected {
border-color: var(--amber);
color: #fff1d6;
box-shadow: 0 0 0 1px rgba(255, 196, 107, 0.18), 0 8px 24px #0006;
}
#panel {
position: fixed;
z-index: 10;
top: 16px;
bottom: 16px;
left: 16px;
width: 344px;
overflow-y: auto;
padding: 22px;
border: 1px solid var(--line);
border-radius: 18px;
background:
radial-gradient(circle at 15% 0%, rgba(68, 173, 180, 0.12), transparent 35%),
var(--panel);
box-shadow: var(--shadow);
scrollbar-width: thin;
scrollbar-color: #31515a transparent;
backdrop-filter: blur(18px);
}
#panel::-webkit-scrollbar {
width: 5px;
}
#panel::-webkit-scrollbar-thumb {
border-radius: 8px;
background: #31515a;
}
.eyebrow {
margin-bottom: 11px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 42px;
font-weight: 400;
line-height: 0.92;
letter-spacing: -0.045em;
}
h1 span {
color: var(--amber);
font-style: italic;
}
.intro {
margin: 14px 0 19px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.section {
padding: 16px 0;
border-top: 1px solid var(--line);
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 11px;
color: #cce5e3;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.section-title small {
color: var(--muted);
font-size: 9px;
font-weight: 600;
letter-spacing: 0.05em;
}
.timeline-meta {
display: flex;
justify-content: space-between;
margin-top: 7px;
color: var(--muted);
font-size: 10px;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 8px 0;
border-radius: 999px;
appearance: none;
background: linear-gradient(
90deg,
var(--cyan) 0%,
var(--cyan) var(--progress, 50%),
#294149 var(--progress, 50%),
#294149 100%
);
cursor: pointer;
outline: none;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
border: 3px solid #09232b;
border-radius: 50%;
appearance: none;
background: var(--amber);
box-shadow: 0 0 0 1px rgba(255, 196, 107, 0.45);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #09232b;
border-radius: 50%;
background: var(--amber);
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.metric {
min-height: 76px;
padding: 11px;
border: 1px solid var(--line);
border-radius: 10px;
background: var(--panel-soft);
}
.metric-label {
margin-bottom: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.metric-value {
color: #f1fffd;
font-family: Georgia, "Times New Roman", serif;
font-size: 19px;
line-height: 1.05;
}
.metric-value em {
color: var(--muted);
font-family: inherit;
font-size: 11px;
font-style: normal;
}
.metric-note {
margin-top: 5px;
color: var(--muted);
font-size: 9px;
}
.observation-list {
display: grid;
gap: 7px;
}
.observation {
position: relative;
display: grid;
grid-template-columns: 8px 1fr auto;
gap: 10px;
align-items: center;
width: 100%;
padding: 10px;
overflow: hidden;
border: 1px solid transparent;
border-radius: 9px;
background: rgba(255, 255, 255, 0.035);
text-align: left;
cursor: pointer;
transition: 160ms ease;
}
.observation:hover {
background: rgba(255, 255, 255, 0.07);
transform: translateX(2px);
}
.observation.selected {
border-color: rgba(255, 196, 107, 0.36);
background: rgba(255, 196, 107, 0.075);
}
.observation.upcoming {
opacity: 0.42;
}
.observation-dot {
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--accent);
box-shadow: 0 0 10px color-mix(in srgb, var(--accent), transparent 35%);
}
.observation-name {
overflow: hidden;
color: #e6f8f6;
font-size: 11px;
font-weight: 700;
text-overflow: ellipsis;
white-space: nowrap;
}
.observation-kind {
margin-top: 3px;
color: var(--muted);
font-size: 9px;
}
.observation-prob {
color: #bdd6d6;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
}
.editor-title {
margin: 0 0 5px;
color: #fff0d1;
font-family: Georgia, "Times New Roman", serif;
font-size: 19px;
font-weight: 400;
}
.editor-note {
margin: 0 0 14px;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.control-label {
display: flex;
justify-content: space-between;
margin-top: 11px;
color: #b9d1d1;
font-size: 10px;
}
.control-label output {
color: var(--amber);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.button-row {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 14px;
}
.small-button,
.tool-button {
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255, 255, 255, 0.045);
color: #d5e9e7;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
cursor: pointer;
transition: 150ms ease;
}
.small-button {
padding: 8px 10px;
}
.small-button:hover,
.tool-button:hover {
border-color: rgba(110, 231, 229, 0.5);
background: rgba(110, 231, 229, 0.09);
}
.small-button.active {
border-color: var(--amber);
color: var(--amber);
background: rgba(255, 196, 107, 0.08);
}
.band-buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 6px;
margin-top: 8px;
}
.band-buttons .small-button.active {
border-color: var(--cyan);
color: var(--cyan);
background: rgba(110, 231, 229, 0.08);
}
.toggle-row {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
.disclaimer {
padding: 14px 0 0;
border-top: 1px solid var(--line);
color: #769399;
font-size: 9px;
line-height: 1.55;
}
#topbar {
position: fixed;
z-index: 6;
top: 18px;
right: 18px;
display: flex;
gap: 7px;
padding: 6px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(4, 20, 27, 0.74);
box-shadow: 0 10px 35px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(12px);
}
.tool-button {
padding: 8px 11px;
border-color: transparent;
background: transparent;
}
.tool-button.active {
border-color: rgba(110, 231, 229, 0.34);
color: var(--cyan);
}
#hud {
position: fixed;
z-index: 5;
bottom: 22px;
left: 382px;
min-width: 250px;
padding: 12px 15px;
border-left: 2px solid var(--amber);
background: linear-gradient(90deg, rgba(4, 20, 27, 0.8), transparent);
pointer-events: none;
}
#hud-stage {
color: var(--amber);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
#hud-estimate {
margin-top: 5px;
color: #e9fbf8;
font-family: Georgia, "Times New Roman", serif;
font-size: 19px;
}
#hud-detail {
margin-top: 4px;
color: var(--muted);
font-size: 9px;
}
#legend {
position: fixed;
z-index: 5;
right: 20px;
bottom: 20px;
width: 205px;
padding: 13px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(4, 20, 27, 0.72);
color: var(--muted);
font-size: 9px;
line-height: 1.5;
pointer-events: none;
backdrop-filter: blur(10px);
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
margin-top: 7px;
}
.legend-swatch {
width: 10px;
height: 10px;
border-radius: 2px;
background: var(--cyan);
opacity: 0.55;
}
.legend-ring {
width: 14px;
height: 14px;
border: 1px solid var(--amber);
border-radius: 50%;
}
#panel-toggle {
position: fixed;
z-index: 20;
top: 18px;
left: 18px;
display: none;
width: 42px;
height: 42px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(4, 20, 27, 0.86);
color: var(--cyan);
font-size: 20px;
cursor: pointer;
}
#toast {
position: fixed;
z-index: 30;
top: 72px;
left: 50%;
padding: 9px 14px;
border: 1px solid rgba(110, 231, 229, 0.25);
border-radius: 8px;
background: rgba(4, 20, 27, 0.92);
color: #dff8f5;
font-size: 11px;
opacity: 0;
pointer-events: none;
transform: translate(-50%, -8px);
transition: 180ms ease;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#loading {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
background: #061820;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hide {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
#panel {
width: min(344px, calc(100vw - 32px));
transform: translateX(calc(-100% - 24px));
transition: transform 200ms ease;
}
body.panel-open #panel {
transform: translateX(0);
}
#panel-toggle {
display: block;
}
#topbar {
top: 18px;
right: 12px;
}
.tool-button {
padding: 8px;
}
#hud {
bottom: 20px;
left: 16px;
min-width: 0;
}
#legend {
display: none;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div id="labels"></div>
<button id="panel-toggle" aria-label="Toggle observation panel">☰</button>
<aside id="panel">
<header>
<div class="eyebrow">Synthetic archive · 08 reports</div>
<h1>Nalele<br /><span>Voyage Lab</span></h1>
<p class="intro">
Explore how scattered signs—swell, birds, smoke, and moonlight—combine into
uncertain positions across an imagined Pacific archipelago.
</p>
</header>
<section class="section">
<div class="section-title">
Voyage timeline
<small>Drag to reveal</small>
</div>
<input
id="timeline"
type="range"
min="0"
max="100"
value="100"
aria-label="Voyage timeline"
/>
<div class="timeline-meta">
<span id="timeline-start">Departure</span>
<span id="timeline-meta">8 reports · Day 14</span>
<span id="timeline-end">Landfall</span>
</div>
</section>
<section class="section">
<div class="section-title">
Weighted synthesis
<small id="visible-count">8 / 8 visible</small>
</div>
<div class="metrics">
<div class="metric">
<div class="metric-label">Estimated position</div>
<div class="metric-value" id="estimate-coord">—</div>
<div class="metric-note">grid coordinates · nmi</div>
</div>
<div class="metric">
<div class="metric-label">Weighted spread</div>
<div class="metric-value" id="estimate-radius">—</div>
<div class="metric-note" id="estimate-band">95% display band</div>
</div>
</div>
</section>
<section class="section">
<div class="section-title">
Observations
<small>Select to inspect</small>
</div>
<div id="observation-list" class="observation-list"></div>
</section>
<section class="section" id="editor">
<div class="section-title">
Evidence editor
<small id="editor-id">—</small>
</div>
<div id="editor-content"></div>
</section>
<section class="section">
<div class="section-title">
Display
<small>Explore uncertainty</small>
</div>
<div class="band-buttons">
<button class="small-button" data-band="1">68% field</button>
<button class="small-button active" data-band="1.96">95% field</button>
</div>
<div class="button-row toggle-row">
<button id="clouds-toggle" class="small-button active">Position voxels</button>
<button id="labels-toggle" class="small-button active">Map labels</button>
<button id="isolate-button" class="small-button">Isolate report</button>
</div>
<div class="button-row">
<button id="export-button" class="small-button">Export estimate JSON</button>
</div>
</section>
<footer class="disclaimer">
All islands, coordinates, dates, observations, and place names are fictional.
The estimate is an illustrative weighted synthesis, not a historical reconstruction.
One grid cell represents one fictional nautical mile.
</footer>
</aside>
<div id="topbar">
<button id="replay-button" class="tool-button">Replay</button>
<button id="top-button" class="tool-button">Top</button>
<button id="reset-button" class="tool-button">Reset view</button>
</div>
<div id="hud">
<div id="hud-stage">Current synthesis</div>
<div id="hud-estimate">—</div>
<div id="hud-detail">Drag to orbit · right-drag to pan · scroll to zoom</div>
</div>
<div id="legend">
<strong style="color:#dff8f5">Reading the map</strong>
<div class="legend-row">
<span class="legend-swatch"></span>
<span>Sampled possible positions</span>
</div>
<div class="legend-row">
<span class="legend-ring"></span>
<span>Selected observation’s uncertainty field</span>
</div>
<div class="legend-row">
<span style="color:#ffc46b">◆</span>
<span>Weighted voyage estimate</span>
</div>
</div>
<div id="toast"></div>
<div id="loading">Charting the imagined sea…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Fictional dataset
// -------------------------------------------------------------------------
const observations = [
{
id: "o1",
title: "Smoke on the wind",
place: "Unnamed western atoll",
type: "Air report",
day: "Day 1 · 05:40",
t: 0.08,
x: -21.5,
z: 15.8,
sigma: 3.4,
weight: 72,
probability: 0.72,
color: 0xffb45f,
note:
"A faint cooking smoke was reported downwind. The crew could not agree on its bearing."
},
{
id: "o2",
title: "Frigatebirds at dawn",
place: "Possible bird corridor",
type: "Flight report",
day: "Day 2 · 06:15",
t: 0.20,
x: -16.8,
z: 10.5,
sigma: 4.1,
weight: 58,
probability: 0.58,
color: 0xff826c,
note:
"Birds crossed low from east to west, suggesting land beyond them but not its distance."
},
{
id: "o3",
title: "Coconut oil scent",
place: "Reef-water margin",
type: "Scent report",
day: "Day 4 · 18:05",
t: 0.34,
x: -12.2,
z: 6.1,
sigma: 3.3,
weight: 81,
probability: 0.81,
color: 0xffd987,
note:
"Oil and blossoms appeared in the water. Their source could have drifted several miles."
},
{
id: "o4",
title: "A long western swell",
place: "Sheltered-water edge",
type: "Swell report",
day: "Day 6 · 14:30",
t: 0.48,
x: -8.4,
z: 2.3,
sigma: 4.6,
weight: 67,
probability: 0.67,
color: 0x71e0d2,
note:
"One unusually long swell entered from the west, often interpreted as a distant reef."
},
{
id: "o5",
title: "Moon reflected twice",
place: "Possible lagoon mouth",
type: "Light report",
day: "Day 8 · 21:10",
t: 0.62,
x: -1.4,
z: -2.0,
sigma: 3.9,
weight: 76,
probability: 0.76,
color: 0x91bfff,
note:
"Two separated reflections suggested an opening in a reef, though clouds obscured the horizon."
},
{
id: "o6",
title: "Rain against the sun",
place: "Western rain bank",
type: "Weather report",
day: "Day 10 · 16:50",
t: 0.76,
x: 6.7,
z: -7.1,
sigma: 4.4,
weight: 54,
probability: 0.54,
color: 0xb7a3ff,
note:
"A narrow rain curtain was interpreted as landfall, but its apparent direction shifted."
},
{
id: "o7",
title: "A darker horizon",
place: "Unconfirmed island chain",
type: "Visual report",
day: "Day 12 · 07:25",
t: 0.89,
x: 13.7,
z: -12.4,
sigma: 5.2,
weight: 61,
probability: 0.61,
color: 0x63b8ff,
note:
"A low silhouette appeared beyond the swell. Cloud and glare left several plausible bearings."
},
{
id: "o8",
title: "Land birds at sunrise",
place: "Probable eastern landfall",
type: "Sound report",
day: "Day 14 · 05:55",
t: 1.0,
x: 20.8,
z: -18.1,
sigma: 5.8,
weight: 69,
probability: 0.69,
color: 0x9bea78,
note:
"A brief chorus of unfamiliar birds indicated land, but did not distinguish island from mainland."
}
];
const state = {
selected: "o4",
progress: 1,
factor: 1.96,
showClouds: true,
showLabels: true,
isolate: false,
replaying: false,
replayStart: 0
};
const byId = new Map(observations.map((o) => [o.id, o]));
const $ = (id) => document.getElementById(id);
let toastTimer;
function toast(message) {
$("toast").textContent = message;
$("toast").classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => $("toast").classList.remove("show"), 2200);
}
function hex(color) {
return `#${color.toString(16).padStart(6, "0")}`;
}
function mulberry32(seed) {
return function () {
let t = (seed += 0x6d2b79f5);
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const viewport = $("viewport");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071b24);
scene.fog = new THREE.FogExp2(0x071b24, 0.0125);
const camera = new THREE.PerspectiveCamera(
45,
window.innerWidth / window.innerHeight,
0.1,
250
);
const cameraControl = {
target: new THREE.Vector3(0, 0, 0),
radius: 63,
theta: 0.63,
phi: 0.72
};
scene.add(new THREE.HemisphereLight(0x9ee9ec, 0x061318, 1.6));
const keyLight = new THREE.DirectionalLight(0xffdfae, 2.1);
keyLight.position.set(-24, 35, 18);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x4fb9d4, 0.9);
rimLight.position.set(20, 10, -30);
scene.add(rimLight);
function updateCamera() {
const { target, radius, theta, phi } = cameraControl;
const offset = new THREE.Vector3().setFromSphericalCoords(radius, phi, theta);
camera.position.copy(target).add(offset);
camera.lookAt(target);
}
updateCamera();
// -------------------------------------------------------------------------
// Voxel ocean
// -------------------------------------------------------------------------
const oceanSize = 42;
const oceanSpacing = 1.08;
const oceanHalf = (oceanSize - 1) * oceanSpacing * 0.5;
const oceanCells = [];
const oceanGeometry = new THREE.BoxGeometry(0.96, 1, 0.96);
const oceanMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.68,
metalness: 0.12,
flatShading: true,
vertexColors: true
});
const ocean = new THREE.InstancedMesh(
oceanGeometry,
oceanMaterial,
oceanSize * oceanSize
);
ocean.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
ocean.frustumCulled = false;
scene.add(ocean);
const oceanColor = new THREE.Color();
const oceanRandom = mulberry32(8041);
for (let iz = 0; iz < oceanSize; iz++) {
for (let ix = 0; ix < oceanSize; ix++) {
const x = (ix - oceanHalf / oceanSpacing) * oceanSpacing;
const z = (iz - oceanHalf / oceanSpacing) * oceanSpacing;
oceanCells.push({ x, z });
const c = new THREE.Color().setHSL(
0.51 + oceanRandom() * 0.025,
0.45 + oceanRandom() * 0.18,
0.22 + oceanRandom() * 0.08
);
ocean.setColorAt(oceanCells.length - 1, c);
}
}
ocean.instanceColor.needsUpdate = true;
function oceanLevel(x, z, time) {
const wave =
Math.sin(x * 0.38 + time * 0.52) * 0.13 +
Math.cos(z * 0.31 - time * 0.41) * 0.11 +
Math.sin((x + z) * 0.18 + time * 0.26) * 0.065;
return Math.round(wave * 10) / 10;
}
function surfaceY(x, z, time) {
return -0.18 + oceanLevel(x, z, time) * 0.42;
}
const matrixDummy = new THREE.Object3D();
function updateOcean(time) {
for (let i = 0; i < oceanCells.length; i++) {
const cell = oceanCells[i];
const level = oceanLevel(cell.x, cell.z, time);
const height = 0.34 + (level + 0.4) * 0.34;
matrixDummy.position.set(cell.x, -0.58 + height * 0.5, cell.z);
matrixDummy.rotation.set(0, 0, 0);
matrixDummy.scale.set(1, height, 1);
matrixDummy.updateMatrix();
ocean.setMatrixAt(i, matrixDummy.matrix);
}
ocean.instanceMatrix.needsUpdate = true;
}
// Faint survey grid.
const gridPositions = [];
for (let i = -20; i <= 20; i += 4) {
const p = i * oceanSpacing;
gridPositions.push(
p, -0.01, -oceanHalf,
p, -0.01, oceanHalf,
-oceanHalf, -0.01, p,
oceanHalf, -0.01, p
);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPositions, 3)
);
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x74cfd0,
transparent: true,
opacity: 0.12
})
);
scene.add(grid);
// -------------------------------------------------------------------------
// Fictional voxel islands
// -------------------------------------------------------------------------
function createIsland(cx, cz, seed, scale = 1) {
const random = mulberry32(seed);
const cells = [];
for (let gz = -5; gz <= 5; gz++) {
for (let gx = -5; gx <= 5; gx++) {
const x = gx * 0.52 * scale;
const z = gz * 0.52 * scale;
const distance = Math.sqrt(x * x + z * z);
const threshold =
2.1 * scale +
Math.sin(gx * 1.7 + seed) * 0.33 +
Math.cos(gz * 1.3 + seed) * 0.25;
if (distance < threshold) {
const height = 1 + Math.floor(random() * 3);
cells.push({ x: cx + x, z: cz + z, height });
}
}
}
const sand = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.5 * scale, 1, 0.5 * scale),
new THREE.MeshStandardMaterial({
color: 0xb59a69,
roughness: 0.95,
flatShading: true
}),
cells.length
);
const green = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.53 * scale, 0.2, 0.53 * scale),
new THREE.MeshStandardMaterial({
color: 0x467b58,
roughness: 0.9,
flatShading: true
}),
cells.length
);
const sandColor = new THREE.Color();
const greenColor = new THREE.Color();
cells.forEach((cell, index) => {
const columnHeight = cell.height * 0.3 * scale;
matrixDummy.position.set(
cell.x,
surfaceY(cell.x, cell.z, 0) + columnHeight * 0.5,
cell.z
);
matrixDummy.scale.set(1, columnHeight, 1);
matrixDummy.updateMatrix();
sand.setMatrixAt(index, matrixDummy.matrix);
sandColor.setHSL(0.11, 0.31, 0.43 + random() * 0.12);
sand.setColorAt(index, sandColor);
matrixDummy.position.set(
cell.x,
surfaceY(cell.x, cell.z, 0) + columnHeight + 0.05,
cell.z
);
matrixDummy.scale.set(1, 1, 1);
matrixDummy.updateMatrix();
green.setMatrixAt(index, matrixDummy.matrix);
greenColor.setHSL(0.34 + random() * 0.035, 0.28, 0.29 + random() * 0.1);
green.setColorAt(index, greenColor);
});
sand.instanceMatrix.needsUpdate = true;
green.instanceMatrix.needsUpdate = true;
sand.instanceColor.needsUpdate = true;
green.instanceColor.needsUpdate = true;
scene.add(sand, green);
}
createIsland(-21.5, 16.1, 102, 1.05);
createIsland(-13.3, 7.0, 304, 0.78);
createIsland(-3.8, -4.1, 710, 0.62);
createIsland(5.8, -7.8, 920, 0.85);
createIsland(14.2, -13.0, 1120, 1.1);
createIsland(21.4, -18.5, 1480, 1.25);
// -------------------------------------------------------------------------
// Voyage route
// -------------------------------------------------------------------------
const routePoints = [
new THREE.Vector3(-25, 0.35, 21),
new THREE.Vector3(-21, 0.35, 16),
new THREE.Vector3(-16, 0.35, 10),
new THREE.Vector3(-12, 0.35, 6),
new THREE.Vector3(-8, 0.35, 2),
new THREE.Vector3(-1, 0.35, -2),
new THREE.Vector3(7, 0.35, -7),
new THREE.Vector3(14, 0.35, -13),
new THREE.Vector3(21, 0.35, -19),
new THREE.Vector3(25, 0.35, -22)
];
const routeCurve = new THREE.CatmullRomCurve3(routePoints);
const routeLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(routeCurve.getPoints(320)),
new THREE.LineDashedMaterial({
color: 0x78dce0,
dashSize: 0.55,
gapSize: 0.45,
transparent: true,
opacity: 0.26
})
);
routeLine.computeLineDistances();
scene.add(routeLine);
const traveledGeometry = new THREE.TubeGeometry(routeCurve, 240, 0.075, 6, false);
const traveledRoute = new THREE.Mesh(
traveledGeometry,
new THREE.MeshBasicMaterial({
color: 0x72eee7,
transparent: true,
opacity: 0.72
})
);
scene.add(traveledRoute);
// -------------------------------------------------------------------------
// Stars and distant moon
// -------------------------------------------------------------------------
const starRandom = mulberry32(771);
const starPositions = [];
for (let i = 0; i < 650; i++) {
const angle = starRandom() * Math.PI * 2;
const radius = 65 + starRandom() * 80;
const y = 13 + starRandom() * 70;
starPositions.push(
Math.cos(angle) * radius,
y,
Math.sin(angle) * radius
);
}
const starGeometry = new THREE.BufferGeometry();
starGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(starPositions, 3)
);
scene.add(
new THREE.Points(
starGeometry,
new THREE.PointsMaterial({
color: 0xc8e8e8,
size: 0.35,
transparent: true,
opacity: 0.7,
sizeAttenuation: true
})
)
);
const moon = new THREE.Mesh(
new THREE.SphereGeometry(3.3, 24, 16),
new THREE.MeshStandardMaterial({
color: 0xffedc5,
emissive: 0xffc56f,
emissiveIntensity: 0.65,
roughness: 1
})
);
moon.position.set(-37, 28, -52);
scene.add(moon);
// -------------------------------------------------------------------------
// Observation markers, possible-position clouds, and labels
// -------------------------------------------------------------------------
const markerGroups = new Map();
const cloudMeshes = new Map();
const cloudCandidates = new Map();
const labels = new Map();
const pickTargets = [];
const cloudGeometry = new THREE.BoxGeometry(0.62, 0.62, 0.62);
observations.forEach((obs, index) => {
const group = new THREE.Group();
group.position.set(obs.x, 0, obs.z);
scene.add(group);
const coreMaterial = new THREE.MeshStandardMaterial({
color: obs.color,
emissive: obs.color,
emissiveIntensity: 0.65,
roughness: 0.32,
metalness: 0.1,
flatShading: true
});
const core = new THREE.Mesh(
new THREE.OctahedronGeometry(0.52, 0),
coreMaterial
);
core.userData.obsId = obs.id;
group.add(core);
pickTargets.push(core);
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.025, 1.25, 6),
new THREE.MeshBasicMaterial({
color: obs.color,
transparent: true,
opacity: 0.55
})
);
group.add(stem);
const ring68 = new THREE.Mesh(
new THREE.TorusGeometry(1, 0.024, 6, 96),
new THREE.MeshBasicMaterial({
color: obs.color,
transparent: true,
opacity: 0.25
})
);
ring68.rotation.x = Math.PI / 2;
group.add(ring68);
const ring95 = new THREE.Mesh(
new THREE.TorusGeometry(1, 0.018, 6, 96),
new THREE.MeshBasicMaterial({
color: obs.color,
transparent: true,
opacity: 0.13
})
);
ring95.rotation.x = Math.PI / 2;
group.add(ring95);
markerGroups.set(obs.id, { group, core, stem, ring68, ring95 });
const random = mulberry32(4300 + index * 91);
const candidates = [];
for (let i = 0; i < 64; i++) {
const radius = Math.sqrt(random());
const angle = random() * Math.PI * 2;
candidates.push({
radius,
angle,
scale: 0.7 + random() * 0.65,
rotation: random() * Math.PI
});
}
cloudCandidates.set(obs.id, candidates);
const cloud = new THREE.InstancedMesh(
cloudGeometry,
new THREE.MeshStandardMaterial({
color: obs.color,
emissive: obs.color,
emissiveIntensity: 0.18,
transparent: true,
opacity: 0.14,
depthWrite: false,
roughness: 0.5,
flatShading: true
}),
candidates.length
);
cloud.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
cloud.userData.obsId = obs.id;
cloud.frustumCulled = false;
cloud.renderOrder = 2;
scene.add(cloud);
cloudMeshes.set(obs.id, cloud);
pickTargets.push(cloud);
const label = document.createElement("button");
label.className = "obs-label";
label.textContent = obs.title;
label.style.borderColor = hex(obs.color);
label.addEventListener("click", (event) => {
event.stopPropagation();
selectObservation(obs.id);
});
$("labels").appendChild(label);
labels.set(obs.id, label);
});
function updateCloud(obs, time) {
const cloud = cloudMeshes.get(obs.id);
const candidates = cloudCandidates.get(obs.id);
const selected = state.selected === obs.id;
cloud.material.opacity = selected ? 0.58 : 0.12;
cloud.material.emissiveIntensity = selected ? 0.48 : 0.16;
candidates.forEach((candidate, index) => {
const distance = candidate.radius * obs.sigma * state.factor;
const x = obs.x + Math.cos(candidate.angle) * distance;
const z = obs.z + Math.sin(candidate.angle) * distance;
const scale = candidate.scale * (selected ? 1.18 : 0.95);
matrixDummy.position.set(
x,
surfaceY(x, z, time) + 0.22,
z
);
matrixDummy.rotation.set(0, candidate.rotation, 0);
matrixDummy.scale.setScalar(scale);
matrixDummy.updateMatrix();
cloud.setMatrixAt(index, matrixDummy.matrix);
});
cloud.instanceMatrix.needsUpdate = true;
}
function updateMarkers(time) {
observations.forEach((obs) => {
const marker = markerGroups.get(obs.id);
const selected = state.selected === obs.id;
const surface = surfaceY(obs.x, obs.z, time);
marker.core.position.y = surface + 1.05;
marker.core.rotation.y = time * 0.55 + obs.x;
marker.core.scale.setScalar(selected ? 1.25 : 0.86);
marker.stem.position.y = surface + 0.55;
marker.stem.scale.y = selected ? 1.25 : 0.85;
marker.ring68.position.y = surface + 0.07;
marker.ring95.position.y = surface + 0.065;
marker.ring68.scale.setScalar(obs.sigma);
marker.ring95.scale.setScalar(obs.sigma * 1.96);
marker.ring68.material.opacity = selected ? 0.75 : 0;
marker.ring95.material.opacity = selected ? 0.34 : 0;
});
}
// -------------------------------------------------------------------------
// Weighted estimate marker
// -------------------------------------------------------------------------
const estimateGroup = new THREE.Group();
scene.add(estimateGroup);
const estimateCore = new THREE.Mesh(
new THREE.OctahedronGeometry(0.72, 0),
new THREE.MeshStandardMaterial({
color: 0xffc46b,
emissive: 0xffa83c,
emissiveIntensity: 0.85,
roughness: 0.25,
metalness: 0.2,
flatShading: true
})
);
estimateGroup.add(estimateCore);
const estimateBeam = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.12, 5, 8, 1, true),
new THREE.MeshBasicMaterial({
color: 0xffc46b,
transparent: true,
opacity: 0.24,
depthWrite: false,
side: THREE.DoubleSide
})
);
estimateGroup.add(estimateBeam);
const estimateRing = new THREE.Mesh(
new THREE.TorusGeometry(1, 0.045, 7, 100),
new THREE.MeshBasicMaterial({
color: 0xffc46b,
transparent: true,
opacity: 0.75
})
);
estimateRing.rotation.x = Math.PI / 2;
estimateGroup.add(estimateRing);
const estimateOuterRing = new THREE.Mesh(
new THREE.TorusGeometry(1, 0.02, 6, 100),
new THREE.MeshBasicMaterial({
color: 0xffc46b,
transparent: true,
opacity: 0.3
})
);
estimateOuterRing.rotation.x = Math.PI / 2;
estimateGroup.add(estimateOuterRing);
let lastEstimate = null;
function calculateEstimate() {
const visible = observations.filter((obs) => {
const inTime = obs.t <= state.progress + 0.001;
const inIsolation = !state.isolate || obs.id === state.selected;
return inTime && inIsolation;
});
const weighted = visible.filter((obs) => obs.weight > 0);
const totalWeight = weighted.reduce((sum, obs) => sum + obs.weight, 0);
if (!totalWeight) {
estimateGroup.visible = false;
return null;
}
let x = 0;
let z = 0;
weighted.forEach((obs) => {
x += obs.x * obs.weight;
z += obs.z * obs.weight;
});
x /= totalWeight;
z /= totalWeight;
const spread = Math.sqrt(
weighted.reduce(
(sum, obs) => sum + obs.weight * obs.sigma * obs.sigma,
0
) / totalWeight
);
lastEstimate = { x, z, spread, count: visible.length };
estimateGroup.visible = true;
estimateGroup.position.set(x, 0, z);
estimateRing.scale.setScalar(spread * state.factor);
estimateOuterRing.scale.setScalar(spread * 1.96);
return lastEstimate;
}
function updateEstimateMarker(time) {
const estimate = lastEstimate;
if (!estimate) return;
const surface = surfaceY(estimate.x, estimate.z, time);
estimateCore.position.y = surface + 1.35;
estimateCore.rotation.y = time * 0.65;
estimateCore.rotation.x = time * 0.22;
estimateBeam.position.y = surface + 2.5;
estimateRing.position.y = surface + 0.08;
estimateOuterRing.position.y = surface + 0.07;
estimateOuterRing.material.opacity =
state.factor >= 1.9 ? 0.12 : 0.38;
}
// -------------------------------------------------------------------------
// UI rendering
// -------------------------------------------------------------------------
function renderObservationList() {
$("observation-list").innerHTML = observations
.map((obs) => {
const selected = obs.id === state.selected;
const upcoming = obs.t > state.progress + 0.001;
return `
<button
class="observation ${selected ? "selected" : ""} ${upcoming ? "upcoming" : ""}"
data-id="${obs.id}"
style="--accent:${hex(obs.color)}"
>
<span class="observation-dot"></span>
<span>
<span class="observation-name">${obs.title}</span>
<span class="observation-kind">${obs.type} · ${obs.day}</span>
</span>
<span class="observation-prob">${Math.round(obs.probability * 100)}%</span>
</button>
`;
})
.join("");
}
function renderEditor() {
const obs = byId.get(state.selected);
$("editor-id").textContent = obs.id.toUpperCase();
$("editor-content").innerHTML = `
<h3 class="editor-title">${obs.title}</h3>
<p class="editor-note">${obs.note}</p>
<label class="control-label" for="sigma-slider">
<span>Uncertain radius · σ</span>
<output id="sigma-output">${obs.sigma.toFixed(1)} nmi</output>
</label>
<input
id="sigma-slider"
type="range"
min="1"
max="9"
step="0.1"
value="${obs.sigma}"
style="--progress:${((obs.sigma - 1) / 8) * 100}%"
/>
<label class="control-label" for="weight-slider">
<span>Evidence weight</span>
<output id="weight-output">${obs.weight}%</output>
</label>
<input
id="weight-slider"
type="range"
min="0"
max="100"
step="1"
value="${obs.weight}"
style="--progress:${obs.weight}%"
/>
<div class="metric-note" style="margin-top:10px">
Reported observation confidence: ${Math.round(obs.probability * 100)}%
</div>
`;
const sigmaSlider = $("sigma-slider");
const weightSlider = $("weight-slider");
sigmaSlider.addEventListener("input", () => {
obs.sigma = Number(sigmaSlider.value);
sigmaSlider.style.setProperty(
"--progress",
`${((obs.sigma - 1) / 8) * 100}%`
);
$("sigma-output").textContent = `${obs.sigma.toFixed(1)} nmi`;
updateVisibility();
renderObservationList();
});
weightSlider.addEventListener("input", () => {
obs.weight = Number(weightSlider.value);
weightSlider.style.setProperty("--progress", `${obs.weight}%`);
$("weight-output").textContent = `${obs.weight}%`;
updateVisibility();
renderObservationList();
});
}
function updateTimelineUI() {
const slider = $("timeline");
slider.value = Math.round(state.progress * 100);
slider.style.setProperty("--progress", `${state.progress * 100}%`);
const visible = observations.filter(
(obs) => obs.t <= state.progress + 0.001
);
const latest = visible[visible.length - 1];
$("timeline-meta").textContent = latest
? `${visible.length} report${visible.length === 1 ? "" : "s"} · ${latest.day}`
: "Open ocean · no reports yet";
$("visible-count").textContent = `${visible.length} / 8 visible`;
}
function updateSummary() {
const estimate = calculateEstimate();
if (!estimate) {
$("estimate-coord").textContent = "—";
$("estimate-radius").textContent = "—";
$("hud-estimate").textContent = "No weighted estimate";
$("hud-stage").textContent = "Open ocean";
$("hud-detail").textContent = "Advance the timeline to reveal evidence";
return;
}
$("estimate-coord").innerHTML =
`${estimate.x.toFixed(1)}, ${estimate.z.toFixed(1)} <em>nmi</em>`;
$("estimate-radius").innerHTML =
`±${estimate.spread.toFixed(1)} <em>nmi</em>`;
$("estimate-band").textContent =
state.factor >= 1.9 ? "95% display band" : "68% display band";
$("hud-stage").textContent = "Current weighted synthesis";
$("hud-estimate").textContent =
`${estimate.x.toFixed(1)}, ${estimate.z.toFixed(1)} nmi`;
$("hud-detail").textContent =
`${estimate.count} report${estimate.count === 1 ? "" : "s"} · ` +
`weighted spread ±${estimate.spread.toFixed(1)} nmi`;
}
function updateVisibility() {
observations.forEach((obs) => {
const inTime = obs.t <= state.progress + 0.001;
const inIsolation = !state.isolate || obs.id === state.selected;
const visible = inTime && inIsolation;
const marker = markerGroups.get(obs.id);
marker.group.visible = visible;
cloudMeshes.get(obs.id).visible = visible && state.showClouds;
});
traveledGeometry.setDrawRange(
0,
Math.max(0, Math.floor(traveledGeometry.index.count * state.progress))
);
updateSummary();
}
function selectObservation(id) {
state.selected = id;
const obs = byId.get(id);
if (obs.t > state.progress + 0.001) {
state.progress = obs.t;
}
renderEditor();
renderObservationList();
updateTimelineUI();
updateVisibility();
}
// -------------------------------------------------------------------------
// UI events
// -------------------------------------------------------------------------
$("observation-list").addEventListener("click", (event) => {
const button = event.target.closest("[data-id]");
if (button) selectObservation(button.dataset.id);
});
$("timeline").addEventListener("input", (event) => {
state.progress = Number(event.target.value) / 100;
updateTimelineUI();
updateVisibility();
renderObservationList();
});
document.querySelectorAll("[data-band]").forEach((button) => {
button.addEventListener("click", () => {
state.factor = Number(button.dataset.band);
document.querySelectorAll("[data-band]").forEach((other) => {
other.classList.toggle("active", other === button);
});
updateVisibility();
});
});
$("clouds-toggle").addEventListener("click", () => {
state.showClouds = !state.showClouds;
$("clouds-toggle").classList.toggle("active", state.showClouds);
updateVisibility();
});
$("labels-toggle").addEventListener("click", () => {
state.showLabels = !state.showLabels;
$("labels-toggle").classList.toggle("active", state.showLabels);
});
$("isolate-button").addEventListener("click", () => {
state.isolate = !state.isolate;
$("isolate-button").classList.toggle("active", state.isolate);
$("isolate-button").textContent = state.isolate
? "Show all reports"
: "Isolate report";
updateVisibility();
toast(state.isolate ? "Showing one selected report" : "Showing all visible reports");
});
$("export-button").addEventListener("click", () => {
const estimate = calculateEstimate();
const payload = {
title: "Nalele Fictional Voyage Lab",
synthetic: true,
disclaimer:
"All observations, coordinates, islands, and dates are fictional.",
progress: state.progress,
displayBand: state.factor >= 1.9 ? "95%" : "68%",
weightedEstimate: estimate
? {
x: estimate.x,
z: estimate.z,
spreadNmi: estimate.spread,
reportCount: estimate.count
}
: null,
observations: observations.map((obs) => ({
id: obs.id,
title: obs.title,
type: obs.type,
day: obs.day,
x: obs.x,
z: obs.z,
sigmaNmi: obs.sigma,
weight: obs.weight,
reportedProbability: obs.probability,
visible: obs.t <= state.progress + 0.001
}))
};
const blob = new Blob([JSON.stringify(payload, null, 2)], {
type: "application/json"
});
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = "nalele-voyage-estimate.json";
link.click();
URL.revokeObjectURL(url);
toast("Estimate exported as JSON");
});
$("replay-button").addEventListener("click", () => {
state.replaying = true;
state.replayStart = performance.now();
state.progress = 0;
$("replay-button").textContent = "Stop";
$("replay-button").classList.add("active");
updateTimelineUI();
updateVisibility();
});
$("reset-button").addEventListener("click", () => {
cameraControl.target.set(0, 0, 0);
cameraControl.radius = 63;
cameraControl.theta = 0.63;
cameraControl.phi = 0.72;
toast("Camera reset");
});
$("top-button").addEventListener("click", () => {
cameraControl.phi = 0.025;
cameraControl.radius = 58;
cameraControl.theta = 0;
toast("Top-down chart view");
});
$("panel-toggle").addEventListener("click", () => {
document.body.classList.toggle("panel-open");
});
// -------------------------------------------------------------------------
// Custom camera controls: orbit, pan, wheel zoom, touch pinch
// -------------------------------------------------------------------------
const canvas = renderer.domElement;
const activePointers = new Map();
let interactionMode = null;
let lastX = 0;
let lastY = 0;
let pointerTravel = 0;
let pinchDistance = 0;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
activePointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (activePointers.size === 2) {
const [a, b] = [...activePointers.values()];
interactionMode = "pinch";
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
return;
}
interactionMode =
event.button === 2 || event.shiftKey ? "pan" : "orbit";
lastX = event.clientX;
lastY = event.clientY;
pointerTravel = 0;
});
canvas.addEventListener("pointermove", (event) => {
if (!activePointers.has(event.pointerId)) return;
const previous = activePointers.get(event.pointerId);
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size >= 2) {
const [a, b] = [...activePointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0) {
cameraControl.radius = THREE.MathUtils.clamp(
cameraControl.radius * (pinchDistance / distance),
12,
105
);
}
pinchDistance = distance;
return;
}
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
pointerTravel += Math.abs(dx) + Math.abs(dy);
lastX = event.clientX;
lastY = event.clientY;
if (interactionMode === "orbit") {
cameraControl.theta -= dx * 0.006;
cameraControl.phi = THREE.MathUtils.clamp(
cameraControl.phi - dy * 0.005,
0.025,
1.43
);
}
if (interactionMode === "pan") {
updateCamera();
const right = new THREE.Vector3(1, 0, 0).applyQuaternion(camera.quaternion);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const scale = cameraControl.radius * 0.0015;
cameraControl.target.addScaledVector(right, -dx * scale);
cameraControl.target.addScaledVector(forward, dy * scale);
cameraControl.target.x = THREE.MathUtils.clamp(
cameraControl.target.x,
-30,
30
);
cameraControl.target.z = THREE.MathUtils.clamp(
cameraControl.target.z,
-30,
30
);
}
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraControl.radius = THREE.MathUtils.clamp(
cameraControl.radius * Math.exp(event.deltaY * 0.001),
12,
105
);
},
{ passive: false }
);
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
canvas.addEventListener("pointerup", (event) => {
const wasClick =
interactionMode === "orbit" &&
pointerTravel < 7 &&
activePointers.size === 1;
activePointers.delete(event.pointerId);
if (wasClick) {
pointerNDC.x = (event.clientX / window.innerWidth) * 2 - 1;
pointerNDC.y = -(event.clientY / window.innerHeight) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
const hits = raycaster.intersectObjects(pickTargets, false);
if (hits.length && hits[0].object.userData.obsId) {
selectObservation(hits[0].object.userData.obsId);
}
}
if (activePointers.size === 0) {
interactionMode = null;
} else if (activePointers.size === 1) {
const [pointer] = [...activePointers.values()];
interactionMode = "orbit";
lastX = pointer.x;
lastY = pointer.y;
pointerTravel = 0;
}
});
canvas.addEventListener("pointercancel", (event) => {
activePointers.delete(event.pointerId);
if (!activePointers.size) interactionMode = null;
});
// -------------------------------------------------------------------------
// Label projection and animation loop
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function updateLabels(time) {
observations.forEach((obs) => {
const label = labels.get(obs.id);
const marker = markerGroups.get(obs.id);
const visible =
state.showLabels &&
marker.group.visible;
if (!visible) {
label.style.display = "none";
return;
}
projected.set(
obs.x,
surfaceY(obs.x, obs.z, time) + 2.05,
obs.z
);
projected.project(camera);
if (
projected.z < -1 ||
projected.z > 1 ||
Math.abs(projected.x) > 1.15 ||
Math.abs(projected.y) > 1.15
) {
label.style.display = "none";
return;
}
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.style.display = "block";
label.style.left = `${x}px`;
label.style.top = `${y}px`;
label.classList.toggle("selected", obs.id === state.selected);
});
}
let previousFrame = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - previousFrame) / 1000, 0.05);
previousFrame = now;
const time = now / 1000;
if (state.replaying) {
state.progress = Math.min((now - state.replayStart) / 12000, 1);
updateTimelineUI();
updateVisibility();
if (state.progress >= 1) {
state.replaying = false;
$("replay-button").textContent = "Replay";
$("replay-button").classList.remove("active");
renderObservationList();
}
}
updateCamera();
updateOcean(time);
observations.forEach((obs) => {
if (cloudMeshes.get(obs.id).visible) {
updateCloud(obs, time);
}
});
updateMarkers(time);
updateEstimateMarker(time);
updateLabels(time);
estimateRing.rotation.z = time * 0.12;
estimateOuterRing.rotation.z = -time * 0.08;
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.setSize(window.innerWidth, window.innerHeight);
});
renderObservationList();
renderEditor();
updateTimelineUI();
updateVisibility();
requestAnimationFrame(animate);
requestAnimationFrame(() => {
$("loading").classList.add("hide");
setTimeout(() => $("loading").remove(), 450);
});
</script>
</body>
</html>
```