Prompt specification
Build or customize the Three.js 3D scene "Outdated Map Expedition Puzzle" 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: Outdated Map Expedition Puzzle
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/outdated-map-expedition-puzzle-x3544
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts hidden terrain, exploration, and uncertain maps. Create an exploration scenario where a bridge changes after being observed. Keep the remembered map stale until revisited and show how planning under outdated knowledge can fail. Low-poly.
Working Three.js Starter (outdated-map-expedition-puzzle-x3544):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>The Shifting Span — A Field Planning Exercise</title>
<style>
:root {
--ink: #102a2e;
--panel: rgba(12, 31, 35, 0.9);
--panel-soft: rgba(19, 44, 48, 0.78);
--line: rgba(194, 225, 211, 0.18);
--paper: #edf1dc;
--muted: #9db8ad;
--mint: #9fe0b4;
--amber: #ffc66d;
--red: #ff7d6b;
--blue: #90cddd;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9c9c0;
color: var(--paper);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.topbar {
position: fixed;
top: 22px;
left: 24px;
z-index: 5;
pointer-events: none;
text-shadow: 0 2px 16px rgba(10, 30, 30, 0.25);
}
.eyebrow {
margin-bottom: 7px;
color: #294d4c;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
max-width: 520px;
color: #173638;
font-size: clamp(26px, 4vw, 48px);
font-weight: 850;
letter-spacing: -0.055em;
line-height: 0.96;
}
.subtitle {
margin-top: 10px;
color: #355655;
font-size: 13px;
font-weight: 600;
}
.glass {
border: 1px solid var(--line);
background: var(--panel);
box-shadow: 0 22px 60px rgba(5, 22, 25, 0.28);
backdrop-filter: blur(15px);
}
#memory-panel {
position: fixed;
top: 22px;
right: 22px;
z-index: 6;
width: 316px;
padding: 15px;
border-radius: 18px;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.panel-title {
color: var(--paper);
font-size: 12px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.badge {
display: inline-flex;
align-items: center;
min-height: 24px;
padding: 4px 9px;
border: 1px solid rgba(255, 198, 109, 0.35);
border-radius: 999px;
color: var(--amber);
background: rgba(255, 198, 109, 0.08);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
white-space: nowrap;
}
.badge.stale {
color: var(--amber);
border-color: rgba(255, 198, 109, 0.5);
animation: stalePulse 1.8s ease-in-out infinite;
}
.badge.synced {
color: var(--mint);
border-color: rgba(159, 224, 180, 0.38);
background: rgba(159, 224, 180, 0.08);
}
@keyframes stalePulse {
50% {
box-shadow: 0 0 18px rgba(255, 198, 109, 0.13);
}
}
.map-frame {
position: relative;
overflow: hidden;
border: 1px solid rgba(201, 229, 214, 0.14);
border-radius: 12px;
background: #d9dfc8;
}
#memory-map {
display: block;
width: 100%;
height: auto;
aspect-ratio: 4 / 3;
}
.map-frame::after {
position: absolute;
inset: 0;
pointer-events: none;
content: "";
background:
repeating-linear-gradient(
to bottom,
rgba(14, 48, 48, 0.035) 0,
rgba(14, 48, 48, 0.035) 1px,
transparent 1px,
transparent 4px
);
mix-blend-mode: multiply;
}
.map-meta {
display: grid;
grid-template-columns: 1fr 0.72fr 0.72fr;
gap: 8px;
margin-top: 12px;
}
.meta-cell {
min-width: 0;
padding: 9px 8px;
border: 1px solid rgba(201, 229, 214, 0.1);
border-radius: 10px;
background: rgba(255, 255, 255, 0.035);
}
.meta-cell small {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.meta-cell strong {
display: block;
overflow: hidden;
color: var(--paper);
font-size: 11px;
font-weight: 750;
text-overflow: ellipsis;
white-space: nowrap;
}
.map-note {
display: flex;
justify-content: space-between;
gap: 12px;
margin-top: 10px;
color: var(--muted);
font-size: 9px;
line-height: 1.45;
}
.hatch-key {
display: inline-block;
width: 15px;
height: 8px;
margin-right: 5px;
vertical-align: -1px;
border: 1px solid rgba(30, 65, 58, 0.25);
background:
repeating-linear-gradient(
135deg,
rgba(30, 65, 58, 0.28) 0,
rgba(30, 65, 58, 0.28) 1px,
transparent 1px,
transparent 4px
);
}
#story {
position: fixed;
bottom: 24px;
left: 24px;
z-index: 7;
width: min(460px, calc(100vw - 48px));
padding: 18px;
border-radius: 18px;
}
.story-top {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
}
#phase-number {
color: var(--amber);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.progress {
display: flex;
gap: 5px;
margin-left: auto;
}
.progress span {
width: 16px;
height: 3px;
border-radius: 999px;
background: rgba(237, 241, 220, 0.16);
transition: background 250ms ease;
}
.progress span.done {
background: var(--mint);
}
.progress span.current {
background: var(--amber);
box-shadow: 0 0 10px rgba(255, 198, 109, 0.35);
}
#story-title {
margin: 0 0 8px;
color: var(--paper);
font-size: 21px;
font-weight: 820;
letter-spacing: -0.025em;
}
#story-copy {
min-height: 58px;
margin: 0 0 15px;
color: #b9ccc1;
font-size: 13px;
line-height: 1.5;
}
.action-row {
display: flex;
gap: 10px;
}
#action-button {
flex: 1;
min-height: 44px;
padding: 11px 16px;
border: 0;
border-radius: 11px;
color: #173234;
background: var(--amber);
box-shadow: 0 8px 24px rgba(255, 198, 109, 0.15);
cursor: pointer;
font-size: 12px;
font-weight: 850;
letter-spacing: 0.025em;
transition:
transform 160ms ease,
filter 160ms ease,
opacity 160ms ease;
}
#action-button:hover:not(:disabled) {
filter: brightness(1.07);
transform: translateY(-1px);
}
#action-button:active:not(:disabled) {
transform: translateY(1px);
}
#action-button:disabled {
cursor: default;
opacity: 0.55;
}
#reset-button {
width: 46px;
border: 1px solid var(--line);
border-radius: 11px;
color: var(--paper);
background: rgba(255, 255, 255, 0.045);
cursor: pointer;
font-size: 18px;
}
#toast {
position: fixed;
top: 25px;
left: 50%;
z-index: 20;
max-width: min(560px, calc(100vw - 48px));
padding: 12px 17px;
border: 1px solid rgba(159, 224, 180, 0.28);
border-radius: 12px;
color: #e8f1df;
background: rgba(13, 39, 42, 0.94);
box-shadow: 0 15px 50px rgba(5, 20, 22, 0.3);
font-size: 12px;
font-weight: 650;
line-height: 1.45;
opacity: 0;
pointer-events: none;
transform: translate(-50%, -14px);
transition:
opacity 220ms ease,
transform 220ms ease;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#toast.warning {
border-color: rgba(255, 198, 109, 0.35);
color: #ffe0a8;
}
#toast.error {
border-color: rgba(255, 125, 107, 0.38);
color: #ffc0b7;
}
.controls-hint {
position: fixed;
right: 24px;
bottom: 24px;
z-index: 5;
padding: 9px 12px;
border: 1px solid rgba(16, 42, 46, 0.12);
border-radius: 999px;
color: #315452;
background: rgba(235, 240, 220, 0.72);
backdrop-filter: blur(8px);
font-size: 10px;
font-weight: 750;
pointer-events: none;
}
@media (max-width: 860px) {
#memory-panel {
top: 14px;
right: 14px;
width: 250px;
padding: 11px;
}
.map-meta {
grid-template-columns: 1fr 1fr;
}
.map-meta .meta-cell:first-child {
grid-column: 1 / -1;
}
.map-note {
display: none;
}
.topbar {
top: 15px;
left: 15px;
}
.subtitle {
display: none;
}
#story {
right: 14px;
bottom: 14px;
left: 14px;
width: auto;
}
.controls-hint {
display: none;
}
}
@media (max-width: 570px) {
#memory-panel {
width: 192px;
}
.panel-title {
font-size: 9px;
}
.badge {
padding: 3px 6px;
font-size: 7px;
}
#memory-map {
max-height: 142px;
}
.map-meta {
display: none;
}
h1 {
max-width: 170px;
font-size: 26px;
}
.eyebrow {
font-size: 8px;
}
#story {
padding: 14px;
}
#story-title {
font-size: 17px;
}
#story-copy {
min-height: 0;
font-size: 11px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="topbar">
<div class="eyebrow">Field exercise / uncertain maps</div>
<h1>The Shifting Span</h1>
<div class="subtitle">Observe. Remember. The world may not agree.</div>
</header>
<aside id="memory-panel" class="glass" aria-label="Remembered field map">
<div class="panel-heading">
<div class="panel-title">Field memory</div>
<div id="stale-badge" class="badge">Unverified</div>
</div>
<div class="map-frame">
<canvas id="memory-map" width="560" height="420"></canvas>
</div>
<div class="map-meta">
<div class="meta-cell">
<small>Remembered bridge</small>
<strong id="believed-bridge">Unknown</strong>
</div>
<div class="meta-cell">
<small>Confidence</small>
<strong id="confidence">35%</strong>
</div>
<div class="meta-cell">
<small>Memory age</small>
<strong id="memory-age">Not surveyed</strong>
</div>
</div>
<div class="map-note">
<span><span class="hatch-key"></span>Low-confidence terrain</span>
<span>Planner input: notebook only</span>
</div>
</aside>
<section id="story" class="glass" aria-live="polite">
<div class="story-top">
<div id="phase-number">Phase 01 / Scout</div>
<div id="progress" class="progress" aria-hidden="true">
<span></span><span></span><span></span><span></span><span></span><span></span>
</div>
</div>
<h2 id="story-title">Start with what you know</h2>
<p id="story-copy"></p>
<div class="action-row">
<button id="action-button">Scout the ridge</button>
<button id="reset-button" title="Restart scenario" aria-label="Restart scenario">↻</button>
</div>
</section>
<div id="toast" role="status"></div>
<div class="controls-hint">
Drag: rotate · Wheel: zoom · Right-drag: pan · Click terrain: log fragment
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const container = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb9c9c0);
scene.fog = new THREE.Fog(0xb9c9c0, 24, 43);
const camera = new THREE.OrthographicCamera(-10, 10, 8, -8, 0.1, 100);
camera.position.set(13, 13, 17);
camera.lookAt(0, 0, 0);
const hemisphere = new THREE.HemisphereLight(0xe8f2de, 0x40524e, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe2b1, 3.3);
sun.position.set(-9, 16, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -16;
sun.shadow.camera.right = 16;
sun.shadow.camera.top = 16;
sun.shadow.camera.bottom = -16;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9ccad4, 0.65);
fill.position.set(12, 7, -10);
scene.add(fill);
const world = new THREE.Group();
scene.add(world);
const tileRecords = [];
const tileMeshes = [];
const knownTiles = new Map();
const terrainGroup = new THREE.Group();
world.add(terrainGroup);
const chasm = new THREE.Mesh(
new THREE.PlaneGeometry(32, 30),
new THREE.MeshStandardMaterial({
color: 0x1e3a42,
roughness: 1,
metalness: 0
})
);
chasm.rotation.x = -Math.PI / 2;
chasm.position.y = -3.05;
chasm.receiveShadow = true;
world.add(chasm);
const westXs = [-9, -7, -5, -3];
const eastXs = [3, 5, 7, 9];
const zs = [-7, -5, -3, -1, 1, 3, 5, 7];
const tileGeometry = new THREE.BoxGeometry(1.94, 3, 1.94);
function tileColor(x, z) {
const palette = [0x769477, 0x819d79, 0x6f9277, 0x8ca27a];
const index = Math.abs((x * 13 + z * 7) % palette.length);
return palette[index];
}
function addTerrainTile(x, z) {
const material = new THREE.MeshStandardMaterial({
color: tileColor(x, z),
roughness: 0.95,
flatShading: true
});
const mesh = new THREE.Mesh(tileGeometry, material);
mesh.position.set(x, -1.5, z);
mesh.receiveShadow = true;
mesh.castShadow = true;
mesh.userData.center = { x, z };
terrainGroup.add(mesh);
tileMeshes.push(mesh);
const fogMaterial = new THREE.MeshBasicMaterial({
color: 0x607a77,
transparent: true,
opacity: 0.61,
depthWrite: false,
side: THREE.DoubleSide
});
const fog = new THREE.Mesh(
new THREE.PlaneGeometry(1.91, 1.91),
fogMaterial
);
fog.rotation.x = -Math.PI / 2;
fog.position.set(x, 0.035, z);
world.add(fog);
tileRecords.push({
x,
z,
fog,
targetOpacity: 0.61,
confidence: 0
});
}
for (const x of westXs) {
for (const z of zs) addTerrainTile(x, z);
}
for (const x of eastXs) {
for (const z of zs) addTerrainTile(x, z);
}
// Low-poly trees and rocks.
const treePositions = [
[-9, 7], [-9, 3], [-5, 7], [-5, -1], [-3, 5],
[3, 7], [5, 5], [9, 5], [9, -1], [7, 7], [3, -7]
];
function addTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = (x * 0.37 + z * 0.21) % Math.PI;
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.09, 0.12, 0.75, 5),
new THREE.MeshStandardMaterial({ color: 0x5b4935, roughness: 1 })
);
trunk.position.y = 0.38;
trunk.castShadow = true;
group.add(trunk);
const crown = new THREE.Mesh(
new THREE.ConeGeometry(0.48, 1.35, 6),
new THREE.MeshStandardMaterial({
color: 0x365f50,
roughness: 1,
flatShading: true
})
);
crown.position.y = 1.2;
crown.castShadow = true;
group.add(crown);
const lower = new THREE.Mesh(
new THREE.ConeGeometry(0.35, 0.9, 6),
new THREE.MeshStandardMaterial({
color: 0x47735e,
roughness: 1,
flatShading: true
})
);
lower.position.y = 0.95;
lower.castShadow = true;
group.add(lower);
group.scale.setScalar(scale);
world.add(group);
}
treePositions.forEach(([x, z], index) => {
addTree(x, z, 0.8 + (index % 3) * 0.12);
});
const rockGeometry = new THREE.IcosahedronGeometry(0.34, 0);
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0x82918a,
roughness: 1,
flatShading: true
});
[
[-8, -2], [-6, 1], [-4, -5], [4, 1], [6, -5],
[8, 3], [3, 5], [-9, -7]
].forEach(([x, z]) => {
const rock = new THREE.Mesh(rockGeometry, rockMaterial);
rock.position.set(x, 0.16, z);
rock.scale.set(1 + Math.abs(x % 3) * 0.18, 0.65, 1.1);
rock.rotation.set(0.2, x * 0.2, 0.15);
rock.castShadow = true;
world.add(rock);
});
// -------------------------------------------------------------------------
// Labels made locally with canvas textures
// -------------------------------------------------------------------------
function makeLabel(text, color = "#173638", background = "rgba(237,241,220,0.86)") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 112;
const context = canvas.getContext("2d");
context.fillStyle = background;
context.beginPath();
context.roundRect(4, 4, 504, 104, 22);
context.fill();
context.strokeStyle = "rgba(23,54,56,0.18)";
context.lineWidth = 3;
context.stroke();
context.fillStyle = color;
context.font = "800 38px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 58);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false
})
);
sprite.scale.set(3.15, 0.69, 1);
return sprite;
}
const campLabel = makeLabel("WEST CAMP");
campLabel.position.set(-7, 2.15, 5);
world.add(campLabel);
const bridgeLabel = makeLabel("OLD SPAN");
bridgeLabel.position.set(0, 2.55, 1);
world.add(bridgeLabel);
const fordLabel = makeLabel("SOUTH ?", "#6e5830", "rgba(239,225,188,0.8)");
fordLabel.position.set(0, 1.3, -3);
fordLabel.material.opacity = 0.55;
world.add(fordLabel);
const targetLabel = makeLabel("EAST CAMP");
targetLabel.position.set(7, 2.2, -3);
world.add(targetLabel);
// Camp tent.
const tent = new THREE.Mesh(
new THREE.ConeGeometry(1.12, 1.55, 4),
new THREE.MeshStandardMaterial({
color: 0xd58b55,
roughness: 0.95,
flatShading: true
})
);
tent.position.set(-7.2, 0.75, 5.1);
tent.rotation.y = Math.PI / 4;
tent.castShadow = true;
world.add(tent);
const tentDoor = new THREE.Mesh(
new THREE.ConeGeometry(0.45, 0.85, 3),
new THREE.MeshStandardMaterial({ color: 0x284647, flatShading: true })
);
tentDoor.position.set(-6.77, 0.42, 5.1);
tentDoor.rotation.y = Math.PI / 4;
world.add(tentDoor);
// Goal flag.
const flagPole = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.055, 1.8, 6),
new THREE.MeshStandardMaterial({ color: 0x695541 })
);
flagPole.position.set(7, 0.9, -3);
flagPole.castShadow = true;
world.add(flagPole);
const flagGeometry = new THREE.BufferGeometry();
flagGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[0, 0, 0, 0.9, -0.22, 0, 0, -0.52, 0],
3
)
);
flagGeometry.computeVertexNormals();
const flag = new THREE.Mesh(
flagGeometry,
new THREE.MeshStandardMaterial({
color: 0xf3bc62,
side: THREE.DoubleSide,
flatShading: true
})
);
flag.position.set(7.05, 1.65, -3);
world.add(flag);
// -------------------------------------------------------------------------
// The bridge: initially solid, then physically changed after observation.
// -------------------------------------------------------------------------
const bridge = new THREE.Group();
world.add(bridge);
const plankMaterial = new THREE.MeshStandardMaterial({
color: 0xb17845,
roughness: 0.9,
flatShading: true
});
const bridgePlanks = [];
for (let i = 0; i < 7; i++) {
const plank = new THREE.Mesh(
new THREE.BoxGeometry(0.5, 0.16, 1.45),
plankMaterial
);
plank.position.set(-1.75 + i * 0.583, 0.15, 1);
plank.castShadow = true;
plank.receiveShadow = true;
bridge.add(plank);
bridgePlanks.push(plank);
}
function addBeam(length, x, z) {
const beam = new THREE.Mesh(
new THREE.BoxGeometry(length, 0.18, 0.17),
new THREE.MeshStandardMaterial({ color: 0x715038, flatShading: true })
);
beam.position.set(x, -0.02, z);
beam.castShadow = true;
bridge.add(beam);
}
addBeam(1.55, -1.3, 0.43);
addBeam(1.55, -1.3, 1.57);
addBeam(1.55, 1.3, 0.43);
addBeam(1.55, 1.3, 1.57);
const postMaterial = new THREE.MeshStandardMaterial({
color: 0x644b36,
roughness: 1,
flatShading: true
});
for (const x of [-2.05, 2.05]) {
for (const z of [0.3, 1.7]) {
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.09, 0.12, 1.15, 6),
postMaterial
);
post.position.set(x, 0.55, z);
post.castShadow = true;
bridge.add(post);
}
}
// Split handrails leave the actual center visibly open when the span moves.
for (const z of [0.3, 1.7]) {
for (const [x, length] of [[-1.25, 1.55], [1.25, 1.55]]) {
const rail = new THREE.Mesh(
new THREE.CylinderGeometry(0.032, 0.032, length, 6),
postMaterial
);
rail.rotation.z = Math.PI / 2;
rail.position.set(x, 0.86, z);
bridge.add(rail);
}
}
// Low mist makes the physical change easy to miss from a distance.
const bridgeMistMaterial = new THREE.MeshBasicMaterial({
color: 0xc6d8d1,
transparent: true,
opacity: 0.19,
depthWrite: false,
side: THREE.DoubleSide
});
const bridgeMist = new THREE.Mesh(
new THREE.PlaneGeometry(4.4, 3.2),
bridgeMistMaterial
);
bridgeMist.rotation.x = -Math.PI / 2;
bridgeMist.position.set(0, 0.73, 1);
world.add(bridgeMist);
// Survey marker at the west abutment.
const surveyRing = new THREE.Mesh(
new THREE.TorusGeometry(0.38, 0.035, 5, 18),
new THREE.MeshStandardMaterial({ color: 0xf0bd67 })
);
surveyRing.rotation.x = Math.PI / 2;
surveyRing.position.set(-3, 0.06, 1);
world.add(surveyRing);
// -------------------------------------------------------------------------
// Alternate stepping stones at the south ford
// -------------------------------------------------------------------------
const stepPositions = [
[-1.35, -3],
[-0.45, -3],
[0.45, -3],
[1.35, -3]
];
const stepMeshes = [];
const stepFog = [];
for (const [x, z] of stepPositions) {
const material = new THREE.MeshStandardMaterial({
color: 0x526b68,
roughness: 1,
flatShading: true
});
const stone = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.45, 0),
material
);
stone.position.set(x, -0.03, z);
stone.scale.set(1.15, 0.55, 0.95);
stone.rotation.y = x * 0.7;
stone.castShadow = true;
stone.receiveShadow = true;
world.add(stone);
stepMeshes.push(stone);
const fog = new THREE.Mesh(
new THREE.PlaneGeometry(0.95, 0.95),
new THREE.MeshBasicMaterial({
color: 0x6c8780,
transparent: true,
opacity: 0.72,
depthWrite: false
})
);
fog.rotation.x = -Math.PI / 2;
fog.position.set(x, 0.5, z);
world.add(fog);
stepFog.push(fog);
}
// -------------------------------------------------------------------------
// Explorer
// -------------------------------------------------------------------------
const explorer = new THREE.Group();
const explorerVisual = new THREE.Group();
explorer.add(explorerVisual);
world.add(explorer);
const currentPosition = new THREE.Vector3(-7, 0.15, 5);
explorer.position.copy(currentPosition);
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.22, 0.29, 0.65, 6),
new THREE.MeshStandardMaterial({
color: 0xe5a84c,
roughness: 0.9,
flatShading: true
})
);
body.position.y = 0.57;
body.castShadow = true;
explorerVisual.add(body);
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.22, 1),
new THREE.MeshStandardMaterial({
color: 0xe7c8a3,
roughness: 1,
flatShading: true
})
);
head.position.y = 1.05;
head.castShadow = true;
explorerVisual.add(head);
const hat = new THREE.Mesh(
new THREE.ConeGeometry(0.27, 0.28, 7),
new THREE.MeshStandardMaterial({
color: 0x315b55,
roughness: 1,
flatShading: true
})
);
hat.position.y = 1.28;
hat.castShadow = true;
explorerVisual.add(hat);
const nose = new THREE.Mesh(
new THREE.ConeGeometry(0.065, 0.18, 5),
new THREE.MeshStandardMaterial({ color: 0xe7c8a3 })
);
nose.rotation.x = Math.PI / 2;
nose.position.set(0, 1.03, 0.23);
explorerVisual.add(nose);
const pack = new THREE.Mesh(
new THREE.BoxGeometry(0.28, 0.38, 0.18),
new THREE.MeshStandardMaterial({
color: 0x385f56,
roughness: 1,
flatShading: true
})
);
pack.position.set(0, 0.63, -0.27);
pack.castShadow = true;
explorerVisual.add(pack);
// -------------------------------------------------------------------------
// Scenario state
// -------------------------------------------------------------------------
const state = {
stage: 0,
busy: false,
falling: false,
routeFailed: false,
bridgePhysical: "solid",
bridgeRemembered: "unknown",
lastMemoryUpdate: performance.now(),
lastSurveyTime: null,
plannedPath: null,
routeFailedColor: false
};
let motion = null;
let toastTimer = null;
let bridgeBreakAmount = 0;
let routeGroup = null;
let routeMaterials = [];
const actionButton = document.querySelector("#action-button");
const resetButton = document.querySelector("#reset-button");
const toast = document.querySelector("#toast");
const storyCopy = [
[
"Start with what you know",
"Your field map is mostly blank. Scout the ridge around camp, then approach the old crossing. You may also click individual terrain fragments to log them at low confidence."
],
[
"Observe before you commit",
"The old span is the only remembered crossing. Approach its west abutment so the survey can record whether it is still usable."
],
[
"The observation is logged",
"At the moment of observation, the bridge looks solid. Your map now carries that belief while the field team waits beside the abutment."
],
[
"The map did not move. The bridge did.",
"A metallic release echoes from the mist. The physical span changed after it was observed, but the notebook still remembers a solid crossing. This is the danger of stale knowledge."
],
[
"Plan from memory",
"The planner accepts the remembered bridge as safe and creates a route to East Camp. It is using the notebook, not making a fresh observation."
],
[
"The remembered route fails",
"The missing center is discovered only on arrival. The expedition retreats to the abutment, where the map is finally corrected by revisiting the site."
],
[
"Look for a different crossing",
"Survey the south ford. The stepping stones are now visible, but they remain uncertain until you log the new observation."
],
[
"Rebuild the plan",
"Create a detour through the newly observed stones. This route depends on evidence gathered after the original bridge survey."
],
[
"A better route from better evidence",
"The detour reaches East Camp. The important failure was not merely the missing bridge—it was planning from a belief that had stopped being current."
]
];
function setKnown(x, z, confidence) {
const key = `${x},${z}`;
knownTiles.set(key, confidence);
const record = tileRecords.find(
(tile) => tile.x === x && tile.z === z
);
if (record) {
record.confidence = confidence;
record.targetOpacity = 0.015 + (1 - confidence) * 0.56;
}
}
function revealAround(x, z, confidence) {
for (const dx of [-2, 0, 2]) {
for (const dz of [-2, 0, 2]) {
const tile = tileRecords.find(
(record) => record.x === x + dx && record.z === z + dz
);
if (tile) {
const c = dx === 0 && dz === 0 ? confidence : confidence * 0.72;
setKnown(tile.x, tile.z, c);
}
}
}
}
function showToast(message, type = "") {
clearTimeout(toastTimer);
toast.textContent = message;
toast.className = type;
requestAnimationFrame(() => toast.classList.add("show"));
toastTimer = setTimeout(() => toast.classList.remove("show"), 4300);
}
function updateActionButton() {
const labels = [
"Scout the ridge",
"Approach and observe the bridge",
"Recording observation…",
"Plan route from memory",
"Follow remembered plan",
"Explore the south ford",
"Plan the ford detour",
"Follow the surveyed detour",
"Expedition complete"
];
actionButton.textContent = labels[state.stage];
if (
state.busy ||
state.falling ||
state.stage === 2 ||
state.stage === 8
) {
actionButton.disabled = true;
} else {
actionButton.disabled = false;
}
}
function setStage(stage) {
state.stage = stage;
const [title, copy] = storyCopy[stage];
document.querySelector("#phase-number").textContent = [
"Phase 01 / Scout",
"Phase 02 / Observe",
"Phase 02 / Record",
"Phase 03 / Change",
"Phase 04 / Plan",
"Phase 05 / Failure",
"Phase 06 / Re-explore",
"Phase 07 / Re-plan",
"Phase 08 / Arrive"
][stage];
document.querySelector("#story-title").textContent = title;
document.querySelector("#story-copy").textContent = copy;
const progress = document.querySelectorAll("#progress span");
const activeProgress = [0, 1, 2, 2, 3, 3, 4, 5, 5][stage];
progress.forEach((element, index) => {
element.className =
index < activeProgress
? "done"
: index === activeProgress
? "current"
: "";
});
updateActionButton();
}
// -------------------------------------------------------------------------
// Movement and planned-route geometry
// -------------------------------------------------------------------------
function makeVector(point) {
return new THREE.Vector3(point[0], 0.15, point[1]);
}
function startMotion(points, onComplete) {
const vectors = points.map(makeVector);
state.busy = true;
updateActionButton();
motion = {
points: vectors,
index: 1,
elapsed: 0,
duration: Math.max(0.7, vectors[0].distanceTo(vectors[1]) * 0.62),
onComplete
};
}
function updateMotion(dt) {
if (!motion) return;
motion.elapsed += dt;
const progress = Math.min(1, motion.elapsed / motion.duration);
const from = motion.points[motion.index - 1];
const to = motion.points[motion.index];
currentPosition.lerpVectors(from, to, progress);
explorer.position.copy(currentPosition);
const directionX = to.x - from.x;
const directionZ = to.z - from.z;
if (Math.abs(directionX) + Math.abs(directionZ) > 0.001) {
explorer.rotation.y = Math.atan2(directionX, directionZ);
}
if (progress >= 1) {
motion.index++;
motion.elapsed = 0;
if (motion.index >= motion.points.length) {
const callback = motion.onComplete;
motion = null;
state.busy = false;
if (callback) callback();
} else {
motion.duration = Math.max(
0.55,
motion.points[motion.index - 1].distanceTo(
motion.points[motion.index]
) * 0.62
);
}
}
}
function addCylinderBetween(group, a, b, material) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(0.038, 0.038, length, 6),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
group.add(mesh);
}
function drawPlannedRoute(points, color = 0xffbd61) {
if (routeGroup) {
world.remove(routeGroup);
routeGroup.traverse((child) => {
if (child.geometry) child.geometry.dispose();
if (child.material) child.material.dispose();
});
}
routeGroup = new THREE.Group();
routeMaterials = [];
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.92
});
routeMaterials.push(material);
const vectors = points.map((point) => makeVector(point));
for (let i = 0; i < vectors.length - 1; i++) {
const a = vectors[i].clone();
const b = vectors[i + 1].clone();
a.y = 0.29;
b.y = 0.29;
addCylinderBetween(routeGroup, a, b, material);
}
for (const point of vectors) {
const marker = new THREE.Mesh(
new THREE.SphereGeometry(0.075, 6, 4),
material
);
marker.position.set(point.x, 0.31, point.z);
routeGroup.add(marker);
}
world.add(routeGroup);
}
function recolorRoute(color) {
for (const material of routeMaterials) {
material.color.setHex(color);
}
}
// -------------------------------------------------------------------------
// Scenario actions
// -------------------------------------------------------------------------
actionButton.addEventListener("click", () => {
switch (state.stage) {
case 0:
startMotion(
[
[-7, 5],
[-6, 4],
[-5, 4]
],
() => {
revealAround(-5, 4, 0.48);
setStage(1);
showToast(
"Ridge fragments logged at low confidence. The old bridge remains the only remembered crossing."
);
}
);
break;
case 1:
startMotion(
[
[-5, 4],
[-5, 2],
[-3, 1]
],
() => {
revealAround(-3, 1, 0.78);
state.bridgeRemembered = "solid";
state.lastSurveyTime = performance.now();
state.lastMemoryUpdate = performance.now();
setStage(2);
showToast(
"Observation recorded: bridge solid, 94% confidence. The survey is now stored in memory."
);
setTimeout(() => {
if (state.stage !== 2) return;
state.bridgePhysical = "broken";
setStage(3);
showToast(
"A metallic release comes from the mist. The bridge changed after observation; the remembered map has not.",
"warning"
);
}, 2100);
}
);
break;
case 3:
state.plannedPath = [
[-3, 1],
[-1.4, 1],
[1.5, 1],
[3, 1],
[5, -1],
[7, -3]
];
drawPlannedRoute(state.plannedPath);
setStage(4);
showToast(
"Plan accepted from the notebook. The planner has not requested a fresh bridge observation."
);
break;
case 4:
startMotion(
[
[-3, 1],
[-1.4, 1],
[-0.1, 1]
],
() => {
state.falling = true;
state.routeFailed = true;
recolorRoute(0xff7667);
showToast(
"The remembered route fails at the missing center. Retreating to the west abutment…",
"error"
);
updateActionButton();
}
);
break;
case 5:
startMotion(
[
[-0.1, 1],
[-2.3, 0.4],
[-3, -1],
[-3, -3],
[-1.35, -3]
],
() => {
for (const stone of stepMeshes) {
stone.material.color.setHex(0x9b916f);
stone.material.emissive.setHex(0x18211a);
}
for (const fog of stepFog) {
fog.material.opacity = 0.03;
}
fordLabel.material.opacity = 1;
setKnown(-3, -3, 0.73);
setStage(6);
showToast(
"South ford surveyed. Four stepping stones are visible and the new crossing can now be planned."
);
}
);
break;
case 6:
state.plannedPath = [
[-1.35, -3],
[-0.45, -3],
[0.45, -3],
[1.35, -3],
[2.5, -3],
[4.5, -3],
[7, -3]
];
drawPlannedRoute(state.plannedPath, 0x9fe0b4);
setStage(7);
showToast(
"Detour accepted. This plan is based on the newly surveyed south ford."
);
break;
case 7:
startMotion(state.plannedPath, () => {
setStage(8);
showToast(
"East Camp reached. Fresh evidence replaced the failed assumption.",
""
);
});
break;
}
});
resetButton.addEventListener("click", () => location.reload());
// -------------------------------------------------------------------------
// Memory map rendering
// -------------------------------------------------------------------------
const mapCanvas = document.querySelector("#memory-map");
const mapContext = mapCanvas.getContext("2d");
const MAP_W = mapCanvas.width;
const MAP_H = mapCanvas.height;
function mapX(x) {
return ((x + 11) / 22) * MAP_W;
}
function mapY(z) {
return ((z + 9) / 18) * MAP_H;
}
function drawMemoryMap(now) {
const ctx = mapContext;
ctx.clearRect(0, 0, MAP_W, MAP_H);
ctx.fillStyle = "#dce1ca";
ctx.fillRect(0, 0, MAP_W, MAP_H);
// Paper grid.
ctx.strokeStyle = "rgba(32, 68, 61, 0.075)";
ctx.lineWidth = 1;
for (let x = 0; x <= MAP_W; x += 40) {
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, MAP_H);
ctx.stroke();
}
for (let y = 0; y <= MAP_H; y += 40) {
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(MAP_W, y);
ctx.stroke();
}
// Remembered chasm corridor.
ctx.fillStyle = "rgba(43, 91, 96, 0.12)";
ctx.fillRect(mapX(-2), 0, mapX(2) - mapX(-2), MAP_H);
// Known terrain.
for (const [key, confidence] of knownTiles) {
const [x, z] = key.split(",").map(Number);
const px = mapX(x - 0.94);
const py = mapY(z - 0.94);
const size = ((1.88 / 22) * MAP_W);
ctx.save();
ctx.globalAlpha = 0.25 + confidence * 0.68;
ctx.fillStyle = confidence > 0.75 ? "#789b77" : "#91a080";
ctx.fillRect(px, py, size, size);
ctx.strokeStyle = "rgba(24, 62, 53, 0.25)";
ctx.lineWidth = 1.5;
ctx.strokeRect(px, py, size, size);
if (confidence < 0.76) {
ctx.beginPath();
ctx.rect(px, py, size, size);
ctx.clip();
ctx.strokeStyle = "rgba(32, 67, 56, 0.25)";
ctx.lineWidth = 2;
for (let h = -size; h < size * 2; h += 9) {
ctx.beginPath();
ctx.moveTo(px + h, py);
ctx.lineTo(px + h + size, py + size);
ctx.stroke();
}
ctx.fillStyle = "rgba(23, 57, 49, 0.58)";
ctx.font = "bold 19px system-ui";
ctx.textAlign = "center";
ctx.fillText("?", px + size / 2, py + size / 2 + 7);
}
ctx.restore();
}
// South ford stones, only after they are in memory.
const stonesKnown = knownTiles.has("-3,-3");
if (stonesKnown) {
ctx.fillStyle = "#766f55";
for (const [x, z] of stepPositions) {
ctx.beginPath();
ctx.arc(mapX(x), mapY(z), 7, 0, Math.PI * 2);
ctx.fill();
}
}
// The bridge state is the remembered state, never a live physical query.
const bridgeLeft = mapX(-2);
const bridgeRight = mapX(2);
const bridgeY = mapY(1);
if (state.bridgeRemembered === "solid") {
ctx.strokeStyle = "#347d5b";
ctx.lineWidth = 12;
ctx.lineCap = "round";
ctx.beginPath();
ctx.moveTo(bridgeLeft, bridgeY);
ctx.lineTo(bridgeRight, bridgeY);
ctx.stroke();
} else if (state.bridgeRemembered === "broken") {
ctx.strokeStyle = "#c65348";
ctx.lineWidth = 11;
ctx.lineCap = "round";
ctx.beginPath();
ctx.moveTo(bridgeLeft, bridgeY);
ctx.lineTo(mapX(-0.35), bridgeY);
ctx.moveTo(mapX(0.35), bridgeY);
ctx.lineTo(bridgeRight, bridgeY);
ctx.stroke();
} else {
ctx.save();
ctx.setLineDash([8, 7]);
ctx.strokeStyle = "rgba(45, 69, 58, 0.55)";
ctx.lineWidth = 3;
ctx.beginPath();
ctx.moveTo(bridgeLeft, bridgeY);
ctx.lineTo(bridgeRight, bridgeY);
ctx.stroke();
ctx.restore();
ctx.fillStyle = "rgba(40, 61, 52, 0.65)";
ctx.font = "bold 22px system-ui";
ctx.textAlign = "center";
ctx.fillText("?", (bridgeLeft + bridgeRight) / 2, bridgeY - 14);
}
// Planned route.
if (state.plannedPath) {
ctx.save();
ctx.setLineDash([12, 8]);
ctx.strokeStyle = state.routeFailed ? "#c65348" : "#d18b30";
ctx.lineWidth = 5;
ctx.lineJoin = "round";
ctx.beginPath();
state.plannedPath.forEach((point, index) => {
if (index === 0) ctx.moveTo(mapX(point[0]), mapY(point[1]));
else ctx.lineTo(mapX(point[0]), mapY(point[1]));
});
ctx.stroke();
ctx.restore();
}
// Camp and target.
function drawPin(x, z, color, label) {
const px = mapX(x);
const py = mapY(z);
ctx.fillStyle = color;
ctx.beginPath();
ctx.arc(px, py, 7, 0, Math.PI * 2);
ctx.fill();
ctx.font = "bold 16px system-ui";
ctx.textAlign = "center";
ctx.fillStyle = "rgba(20, 48, 42, 0.85)";
ctx.fillText(label, px, py - 13);
}
drawPin(-7, 5, "#244f49", "CAMP");
drawPin(7, -3, "#d18b30", "TARGET");
// Current explorer.
ctx.fillStyle = "#183e3d";
ctx.strokeStyle = "#f4f1d9";
ctx.lineWidth = 3;
ctx.beginPath();
ctx.arc(
mapX(currentPosition.x),
mapY(currentPosition.z),
8,
0,
Math.PI * 2
);
ctx.fill();
ctx.stroke();
// North arrow.
ctx.strokeStyle = "rgba(23, 54, 48, 0.65)";
ctx.fillStyle = "rgba(23, 54, 48, 0.65)";
ctx.lineWidth = 3;
ctx.beginPath();
ctx.moveTo(MAP_W - 35, 58);
ctx.lineTo(MAP_W - 35, 22);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(MAP_W - 35, 17);
ctx.lineTo(MAP_W - 42, 31);
ctx.lineTo(MAP_W - 28, 31);
ctx.closePath();
ctx.fill();
ctx.font = "bold 15px system-ui";
ctx.textAlign = "center";
ctx.fillText("N", MAP_W - 35, 78);
// Update memory metadata.
const badge = document.querySelector("#stale-badge");
const belief = document.querySelector("#believed-bridge");
const confidenceLabel = document.querySelector("#confidence");
const ageLabel = document.querySelector("#memory-age");
if (state.bridgeRemembered === "unknown") {
badge.textContent = "Unverified";
badge.className = "badge";
belief.textContent = "Unknown";
confidenceLabel.textContent = "35%";
ageLabel.textContent = "Not surveyed";
} else if (state.bridgePhysical !== state.bridgeRemembered) {
badge.textContent = "Stale";
badge.className = "badge stale";
belief.textContent = "Solid (surveyed)";
confidenceLabel.textContent = "94%";
const age = Math.max(
0,
Math.floor((now - state.lastMemoryUpdate) / 1000)
);
ageLabel.textContent = `${age}s old`;
} else {
badge.textContent =
state.bridgeRemembered === "solid" ? "Synced" : "Revisited";
badge.className = "badge synced";
belief.textContent =
state.bridgeRemembered === "solid"
? "Solid (surveyed)"
: "Missing center";
confidenceLabel.textContent =
state.bridgeRemembered === "solid" ? "94%" : "100%";
const age = Math.max(
0,
Math.floor((now - state.lastMemoryUpdate) / 1000)
);
ageLabel.textContent = age < 2 ? "Just now" : `${age}s old`;
}
}
// -------------------------------------------------------------------------
// Custom camera controls — no external control modules
// -------------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 0, 0),
theta: Math.atan2(13, 17),
phi: Math.acos(13 / Math.sqrt(13 * 13 + 17 * 17)),
radius: Math.sqrt(13 * 13 + 13 * 13 + 17 * 17),
dragging: false,
panning: false,
lastX: 0,
lastY: 0,
startX: 0,
startY: 0
};
function applyCamera() {
const sinPhi = Math.sin(controls.phi);
controls.target.x +=
controls.radius * sinPhi * Math.sin(controls.theta);
controls.target.y +=
controls.radius * Math.cos(controls.phi);
controls.target.z +=
controls.radius * sinPhi * Math.cos(controls.theta);
camera.position.copy(controls.target);
camera.lookAt(0, 0, 0);
controls.target.set(0, 0, 0);
}
function setCameraFromAngles() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.radius * sinPhi * Math.sin(controls.theta),
controls.radius * Math.cos(controls.phi),
controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
function panCamera(dx, dy) {
camera.updateMatrixWorld();
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrixWorld,
0
);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const worldPerPixel =
(17 / camera.zoom) / renderer.domElement.clientHeight;
controls.target.addScaledVector(right, -dx * worldPerPixel);
controls.target.addScaledVector(forward, -dy * worldPerPixel);
const maxX = 13;
const maxZ = 12;
controls.target.x = THREE.MathUtils.clamp(
controls.target.x,
-maxX,
maxX
);
controls.target.z = THREE.MathUtils.clamp(
controls.target.z,
-maxZ,
maxZ
);
}
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
renderer.domElement.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.panning =
event.button === 2 || event.shiftKey || event.ctrlKey;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
controls.startX = event.clientX;
controls.startY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
if (controls.panning) {
panCamera(dx, dy);
} else {
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.005,
0.38,
1.38
);
}
controls.lastX = event.clientX;
controls.lastY = event.clientY;
setCameraFromAngles();
});
renderer.domElement.addEventListener("pointerup", (event) => {
const wasClick =
Math.hypot(
event.clientX - controls.startX,
event.clientY - controls.startY
) < 6;
controls.dragging = false;
if (!wasClick || controls.panning) return;
const rect = renderer.domElement.getBoundingClientRect();
pointer.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(tileMeshes, false);
if (hits.length) {
const { x, z } = hits[0].object.userData.center;
const key = `${x},${z}`;
if (!knownTiles.has(key)) {
setKnown(x, z, 0.3);
showToast(
`Terrain fragment logged at 30% confidence. Unknown ground remains uncertain.`,
"warning"
);
} else {
const confidence = knownTiles.get(key);
showToast(
`Logged fragment: ${Math.round(confidence * 100)}% confidence.`
);
}
}
});
renderer.domElement.addEventListener("pointercancel", () => {
controls.dragging = false;
});
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
camera.zoom = THREE.MathUtils.clamp(
camera.zoom * (event.deltaY > 0 ? 0.9 : 1.1),
0.65,
2.4
);
camera.updateProjectionMatrix();
},
{ passive: false }
);
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = aspect < 0.8 ? 20 : 17;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let lastMapUpdate = 0;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const now = performance.now();
updateMotion(dt);
// The bridge physically breaks after the observation has been recorded.
const targetBreak =
state.bridgePhysical === "broken" ? 1 : 0;
bridgeBreakAmount = THREE.MathUtils.lerp(
bridgeBreakAmount,
targetBreak,
1 - Math.pow(0.001, dt)
);
bridgePlanks.forEach((plank, index) => {
let targetRotation = 0;
let targetY = 0.15;
if (index === 3) {
targetRotation = 1.18;
targetY = -0.72;
} else if (index === 2) {
targetRotation = 0.52;
targetY = -0.22;
} else if (index === 4) {
targetRotation = -0.52;
targetY = -0.22;
}
plank.rotation.z = THREE.MathUtils.lerp(
plank.rotation.z,
targetRotation * bridgeBreakAmount,
1 - Math.pow(0.001, dt)
);
plank.position.y = THREE.MathUtils.lerp(
plank.position.y,
targetY,
1 - Math.pow(0.001, dt)
);
});
// Fog caps recede as terrain becomes known.
for (const tile of tileRecords) {
tile.fog.material.opacity = THREE.MathUtils.lerp(
tile.fog.material.opacity,
tile.targetOpacity,
1 - Math.pow(0.005, dt)
);
}
// Explorer walking bob and failed crossing fall.
if (state.falling) {
const fall = state.fallData || (state.fallData = { time: 0 });
fall.time += dt;
const p = Math.min(1, fall.time / 0.85);
explorer.position.set(
-0.1,
0.15 - 1.65 * p * p,
1
);
explorer.rotation.z = p * 1.18;
explorerVisual.position.y = 0;
if (p >= 1) {
state.falling = false;
state.fallData = null;
currentPosition.set(-2.25, 0.15, 1);
explorer.position.copy(currentPosition);
explorer.rotation.z = 0;
// Memory is corrected only after retreating to and revisiting the site.
state.bridgeRemembered = "broken";
state.lastMemoryUpdate = performance.now();
setStage(5);
showToast(
"Back at the west abutment, the map is corrected: the bridge has a missing center.",
"warning"
);
}
} else if (motion) {
explorerVisual.position.y =
Math.abs(Math.sin(now * 0.012)) * 0.055;
} else {
explorerVisual.position.y = 0;
}
// A small amount of drifting mist.
bridgeMist.position.x = Math.sin(now * 0.00045) * 0.13;
bridgeMist.position.z = 1 + Math.cos(now * 0.00037) * 0.08;
if (now - lastMapUpdate > 180) {
drawMemoryMap(now);
lastMapUpdate = now;
}
renderer.render(scene, camera);
}
// Initial state.
setKnown(-7, 5, 0.96);
setStage(0);
drawMemoryMap(performance.now());
setCameraFromAngles();
resize();
animate();
</script>
</body>
</html>
```