Prompt specification
Build or customize the Three.js 3D scene "Migration route stopover chain" 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: Migration route stopover chain
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/migration-route-stopover-chain-x0657
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows bird migration stopovers. Display a schematic route across three habitat patches with a small bird marker; label distances as illustrative and make intermediate resting locations distinct from endpoints. Voxel style.
Working Three.js Starter (migration-route-stopover-chain-x0657):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Migration Stopovers</title>
<style>
:root {
--ink: #243a35;
--muted: #687770;
--paper: rgba(250, 250, 243, 0.92);
--line: rgba(44, 70, 61, 0.16);
--green: #397a61;
--orange: #ef9f3c;
--coral: #eb6548;
--shadow: 0 14px 40px rgba(37, 61, 52, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9eee7;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
#viewport canvas:active {
cursor: grabbing;
}
#labels {
position: fixed;
inset: 0;
pointer-events: none;
overflow: hidden;
z-index: 2;
}
.panel {
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.72);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.intro {
position: fixed;
top: 24px;
left: 24px;
width: 310px;
padding: 20px 21px 18px;
border-radius: 18px;
z-index: 4;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 13px;
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.signal {
width: 9px;
height: 9px;
border-radius: 3px;
background: var(--orange);
box-shadow: 0 0 0 4px rgba(239, 159, 60, 0.14);
transform: rotate(45deg);
}
h1 {
margin: 0;
font-size: clamp(30px, 3vw, 43px);
line-height: 0.96;
letter-spacing: -0.055em;
font-weight: 820;
}
h1 span {
color: var(--green);
}
.intro p {
margin: 14px 0 16px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.scale-note {
display: flex;
align-items: center;
gap: 9px;
padding-top: 13px;
border-top: 1px solid var(--line);
color: #586960;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.075em;
text-transform: uppercase;
}
.ruler {
position: relative;
width: 29px;
height: 8px;
flex: 0 0 auto;
border-bottom: 2px solid var(--orange);
}
.ruler::before,
.ruler::after {
content: "";
position: absolute;
bottom: -4px;
width: 2px;
height: 7px;
background: var(--orange);
}
.ruler::before {
left: 0;
}
.ruler::after {
right: 0;
}
.journey {
position: fixed;
top: 24px;
right: 24px;
width: 260px;
padding: 18px;
border-radius: 18px;
z-index: 4;
}
.journey h2 {
margin: 0 0 14px;
font-size: 11px;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.status {
display: flex;
align-items: center;
gap: 11px;
min-height: 45px;
}
.status-dot {
width: 12px;
height: 12px;
flex: 0 0 auto;
border-radius: 4px;
background: var(--coral);
transform: rotate(45deg);
animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
50% {
box-shadow: 0 0 0 7px rgba(235, 101, 72, 0.12);
}
}
.status small {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.status strong {
display: block;
font-size: 12px;
line-height: 1.35;
}
.progress-track {
height: 5px;
margin: 15px 0 7px;
overflow: hidden;
border-radius: 8px;
background: #dce4dc;
}
#progress-fill {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--orange), var(--coral));
transition: width 0.1s linear;
}
.progress-copy {
display: flex;
justify-content: space-between;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.follow-button {
width: 100%;
margin-top: 15px;
padding: 10px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.58);
color: var(--ink);
font-size: 11px;
font-weight: 800;
cursor: pointer;
transition: background 0.2s, transform 0.2s;
}
.follow-button:hover {
background: white;
transform: translateY(-1px);
}
.follow-button[aria-pressed="true"] {
border-color: rgba(57, 122, 97, 0.3);
background: #e2eee7;
color: var(--green);
}
.legend {
position: fixed;
left: 24px;
bottom: 24px;
display: flex;
gap: 17px;
align-items: center;
padding: 13px 16px;
border-radius: 14px;
z-index: 4;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
color: #52645d;
font-size: 10px;
font-weight: 750;
white-space: nowrap;
}
.legend-mark {
width: 16px;
height: 12px;
border-radius: 3px;
}
.legend-mark.route {
height: 4px;
background: repeating-linear-gradient(
90deg,
var(--orange) 0 5px,
transparent 5px 8px
);
}
.legend-mark.habitat {
border: 2px solid var(--green);
background: #a8be78;
}
.legend-mark.rest {
border: 2px solid var(--orange);
background: #f2d49a;
transform: rotate(45deg);
border-radius: 2px;
}
.legend-mark.bird {
width: 12px;
height: 12px;
background: var(--coral);
clip-path: polygon(0 35%, 45% 0, 100% 40%, 58% 55%, 100% 100%, 38% 67%);
}
.help {
position: fixed;
right: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 12px;
padding: 9px 11px;
border-radius: 12px;
z-index: 4;
}
.help span {
color: #64736c;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.05em;
text-transform: uppercase;
}
#reset-view {
padding: 7px 10px;
border: 1px solid var(--line);
border-radius: 8px;
background: white;
color: var(--ink);
font-size: 10px;
font-weight: 800;
cursor: pointer;
}
.habitat-label,
.rest-label,
.distance-label {
position: absolute;
transform: translate(-50%, -50%);
white-space: nowrap;
will-change: left, top, opacity;
}
.habitat-label {
display: flex;
align-items: center;
gap: 9px;
padding: 8px 11px 8px 8px;
border: 1px solid rgba(255, 255, 255, 0.85);
border-radius: 12px;
background: rgba(250, 250, 243, 0.94);
box-shadow: 0 8px 24px rgba(35, 61, 50, 0.13);
}
.habitat-index {
display: grid;
width: 29px;
height: 29px;
place-items: center;
border-radius: 8px;
background: var(--green);
color: white;
font-size: 10px;
font-weight: 850;
}
.habitat-label span,
.rest-label span {
display: block;
margin-bottom: 2px;
color: #77857e;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.habitat-label strong,
.rest-label strong {
display: block;
color: var(--ink);
font-size: 11px;
font-weight: 820;
}
.rest-label {
display: flex;
align-items: center;
gap: 8px;
padding: 7px 10px 7px 7px;
border: 1px solid rgba(205, 143, 48, 0.22);
border-radius: 10px;
background: rgba(255, 248, 226, 0.95);
box-shadow: 0 7px 20px rgba(92, 73, 36, 0.11);
}
.rest-diamond {
width: 16px;
height: 16px;
border: 3px solid var(--orange);
border-radius: 3px;
transform: rotate(45deg);
}
.distance-label {
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 8px;
background: rgba(255, 255, 255, 0.84);
color: #6d766d;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.04em;
box-shadow: 0 5px 14px rgba(35, 61, 50, 0.08);
}
#loading {
position: fixed;
inset: 0;
display: grid;
place-items: center;
background: #e9eee7;
color: var(--green);
font-size: 11px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
z-index: 10;
transition: opacity 0.35s;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 800px) {
.intro {
top: 12px;
left: 12px;
width: 245px;
padding: 15px;
}
.intro p {
display: none;
}
.scale-note {
margin-top: 13px;
}
.journey {
display: none;
}
.legend {
left: 12px;
bottom: 12px;
gap: 11px;
padding: 10px 12px;
}
.legend-item {
font-size: 8px;
}
.help {
right: 12px;
bottom: 12px;
}
.help span {
display: none;
}
.distance-label {
display: none !important;
}
.habitat-label {
padding: 6px 8px 6px 6px;
}
.habitat-index {
width: 24px;
height: 24px;
}
.habitat-label span,
.rest-label span {
display: none;
}
.habitat-label strong,
.rest-label strong {
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div id="labels" aria-hidden="true"></div>
<header class="intro panel">
<div class="eyebrow">
<span class="signal"></span>
Voyage map / autumn
</div>
<h1>Migration<br /><span>stopovers</span></h1>
<p>
Three essential habitat patches connected by two smaller resting locations.
Follow the little voxel bird as it crosses the schematic route.
</p>
<div class="scale-note">
<span class="ruler"></span>
Distances illustrative · not to scale
</div>
</header>
<aside class="journey panel" aria-label="Journey progress">
<h2>Journey</h2>
<div class="status">
<span class="status-dot"></span>
<div>
<small>Current phase</small>
<strong id="status-text">Leaving the tidal marsh</strong>
</div>
</div>
<div class="progress-track">
<span id="progress-fill"></span>
</div>
<div class="progress-copy">
<span>Departure</span>
<span>Wintering ground</span>
</div>
<button id="follow-bird" class="follow-button" aria-pressed="false">
Follow bird
</button>
</aside>
<div class="legend panel" aria-label="Map legend">
<div class="legend-item"><span class="legend-mark route"></span>Route</div>
<div class="legend-item"><span class="legend-mark habitat"></span>Habitat</div>
<div class="legend-item"><span class="legend-mark rest"></span>Rest stop</div>
<div class="legend-item"><span class="legend-mark bird"></span>Bird</div>
</div>
<div class="help panel">
<span>Drag to orbit · Scroll to zoom</span>
<button id="reset-view">Reset view</button>
</div>
<div id="loading">Building stopover map…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const labelsContainer = document.getElementById("labels");
const statusText = document.getElementById("status-text");
const progressFill = document.getElementById("progress-fill");
const followButton = document.getElementById("follow-bird");
const resetButton = document.getElementById("reset-view");
// -------------------------------------------------------------------------
// Renderer, camera and lighting
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9eee7);
scene.fog = new THREE.Fog(0xe9eee7, 25, 54);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel map of a bird migration route"
);
renderer.domElement.tabIndex = 0;
viewport.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xfafff6, 0x7a806e, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0cf, 3.25);
sun.position.set(-7, 15, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 42;
sun.shadow.bias = -0.0005;
scene.add(sun);
const fillLight = new THREE.DirectionalLight(0x99c9cf, 0.75);
fillLight.position.set(12, 6, -10);
scene.add(fillLight);
// -------------------------------------------------------------------------
// Small voxel construction helpers
// -------------------------------------------------------------------------
const materialCache = new Map();
function material(color, options = {}) {
const key = `${color}-${JSON.stringify(options)}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
...options
})
);
}
return materialCache.get(key);
}
function box(parent, width, height, depth, color, x, y, z, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
color?.isMaterial ? color : material(color, options.material || {})
);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function seededRandom(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;
};
}
// The broad, pale floor gives the map the feel of a tabletop diorama.
box(scene, 28, 0.38, 16, "#dfe5d9", 0, -0.83, 0, {
castShadow: false
});
const floorTileMaterials = [
material("#d3ddcf"),
material("#dce3d6"),
material("#e6e9de"),
material("#cbd8ca")
];
const scatterRandom = seededRandom(31);
for (let i = 0; i < 46; i++) {
const side = i % 2 === 0 ? -1 : 1;
const x = side * (11.3 + scatterRandom() * 2.2);
const z = (scatterRandom() - 0.5) * 14;
const size = 0.25 + scatterRandom() * 0.45;
box(
scene,
size,
0.035,
size,
floorTileMaterials[i % floorTileMaterials.length],
x,
-0.625,
z,
{ castShadow: false }
);
}
const earthMaterials = {
marsh: material("#786d50"),
meadow: material("#8b7951"),
delta: material("#6e7052")
};
const tileMaterials = {
marsh: [
material("#789c68"),
material("#8baa72"),
material("#6e9564"),
material("#9bb678")
],
meadow: [
material("#a6b866"),
material("#b9c472"),
material("#94a95d"),
material("#c4ca79")
],
delta: [
material("#6d9978"),
material("#7ca386"),
material("#5e896f"),
material("#8eac88")
]
};
const waterMaterials = [
material("#5ca5aa", { roughness: 0.3, metalness: 0.04 }),
material("#67afb0", { roughness: 0.34, metalness: 0.03 })
];
const trunkMaterial = material("#72533b");
const leafMaterials = [
material("#3f7955"),
material("#4d895d"),
material("#639565"),
material("#397253")
];
function addTree(parent, x, z, scale = 1, paletteOffset = 0) {
const trunk = box(
parent,
0.18 * scale,
0.88 * scale,
0.18 * scale,
trunkMaterial,
x,
0.13 + 0.44 * scale,
z
);
box(
parent,
0.76 * scale,
0.52 * scale,
0.72 * scale,
leafMaterials[(paletteOffset + 1) % leafMaterials.length],
x,
0.13 + 1.02 * scale,
z
);
box(
parent,
0.58 * scale,
0.46 * scale,
0.57 * scale,
leafMaterials[(paletteOffset + 2) % leafMaterials.length],
x,
0.13 + 1.47 * scale,
z
);
box(
parent,
0.34 * scale,
0.34 * scale,
0.34 * scale,
leafMaterials[(paletteOffset + 3) % leafMaterials.length],
x,
0.13 + 1.82 * scale,
z
);
return trunk;
}
function addReeds(parent, x, z, height = 0.55) {
box(
parent,
0.065,
height,
0.065,
"#527d58",
x,
0.16 + height / 2,
z
);
box(
parent,
0.11,
0.13,
0.11,
"#8b7145",
x,
0.16 + height,
z
);
}
function addHabitat({
index,
x,
z,
kind,
accent,
treePositions,
flowerPositions = [],
reedPositions = []
}) {
const root = new THREE.Group();
root.position.set(x, 0, z);
scene.add(root);
box(root, 4.55, 0.44, 4.55, earthMaterials[kind], 0, -0.34, 0);
const random = seededRandom(120 + index * 17);
const cell = 0.62;
for (let ix = -3; ix <= 3; ix++) {
for (let iz = -3; iz <= 3; iz++) {
// Rounded, stepped voxel edges.
if (Math.abs(ix) === 3 && Math.abs(iz) === 3) continue;
if (Math.abs(ix) + Math.abs(iz) === 6 && random() > 0.4) continue;
const isWater =
(kind === "marsh" && ix < 0 && iz > -3) ||
(kind === "delta" && ix > 0 && iz < 2);
const height = isWater
? 0.12
: 0.18 + Math.floor(random() * 3) * 0.045;
const palette = tileMaterials[kind];
const tileMaterial = isWater
? waterMaterials[(ix + iz + 10) % waterMaterials.length]
: palette[(ix + iz + index + 20) % palette.length];
box(
root,
cell * 0.9,
height,
cell * 0.9,
tileMaterial,
ix * cell,
-0.105 + height / 2,
iz * cell
);
}
}
treePositions.forEach(([tx, tz], i) => {
addTree(root, tx, tz, 0.82 + (i % 2) * 0.12, index + i);
});
reedPositions.forEach(([rx, rz], i) => {
addReeds(root, rx, rz, 0.4 + (i % 3) * 0.08);
});
const flowerColors = ["#f4ce62", "#ef8e68", "#f2eee0", "#e4aa4e"];
flowerPositions.forEach(([fx, fz], i) => {
box(
root,
0.055,
0.27,
0.055,
"#66864d",
fx,
0.24,
fz
);
box(
root,
0.13,
0.13,
0.13,
flowerColors[i % flowerColors.length],
fx,
0.4,
fz
);
});
// A small square wayfinding post differentiates the large habitat patches.
box(root, 0.13, 0.65, 0.13, "#596b5d", 1.77, 0.43, 1.65);
box(root, 0.34, 0.2, 0.34, accent, 1.77, 0.84, 1.65);
return root;
}
const habitats = [
{
index: 1,
x: -9,
z: 0,
kind: "marsh",
accent: "#4f8b6b",
treePositions: [
[1.38, 1.35],
[1.82, 0.12],
[0.73, 1.82]
],
reedPositions: [
[-1.65, 1.35],
[-1.2, 1.65],
[-2.15, 0.8],
[-1.9, -0.35],
[-0.8, -1.55]
]
},
{
index: 2,
x: 0,
z: 0,
kind: "meadow",
accent: "#d6aa45",
treePositions: [
[-1.78, -1.62],
[1.72, -1.72],
[-1.9, 0.48]
],
flowerPositions: [
[-1.25, 1.38],
[-0.62, 1.72],
[0.72, 1.5],
[1.32, 1.1],
[-1.4, -0.65],
[0.85, -1.25],
[1.55, -0.55]
]
},
{
index: 3,
x: 9,
z: 0,
kind: "delta",
accent: "#4b8f86",
treePositions: [
[-1.45, 1.45],
[-1.92, 0.18],
[-0.72, 1.82]
],
reedPositions: [
[1.5, 1.55],
[1.05, 1.78],
[2.0, 0.78],
[1.75, -0.35],
[1.12, -1.5]
]
}
];
habitats.forEach(addHabitat);
function addRestStop(x, z, number) {
const root = new THREE.Group();
root.position.set(x, 0, z);
scene.add(root);
box(root, 2.25, 0.38, 2.25, "#b59c6c", 0, -0.28, 0);
box(root, 1.28, 0.13, 1.28, "#d8c58e", 0, -0.015, 0);
const cornerMaterial = material("#91a58a");
[
[-0.76, -0.76],
[0.76, -0.76],
[-0.76, 0.76],
[0.76, 0.76]
].forEach(([cx, cz]) => {
box(root, 0.43, 0.17, 0.43, cornerMaterial, cx, 0.02, cz);
});
// The amber beacon sits beside the path, leaving the resting pad readable.
box(root, 0.13, 0.63, 0.13, "#8e7048", 0.7, 0.37, -0.65);
box(root, 0.34, 0.2, 0.34, "#eda64a", 0.7, 0.78, -0.65);
box(root, 0.18, 0.18, 0.18, "#fff0b0", 0.7, 0.97, -0.65);
box(root, 0.32, 0.28, 0.32, "#678a59", -0.72, 0.16, -0.65);
box(root, 0.28, 0.25, 0.28, "#789760", 0.72, 0.15, 0.67);
return root;
}
const restStops = [
{ number: 1, x: -4.5, z: 1.25 },
{ number: 2, x: 4.5, z: -1.25 }
];
restStops.forEach((stop) => addRestStop(stop.x, stop.z, stop.number));
// -------------------------------------------------------------------------
// Schematic route: four illustrative legs between five route points
// -------------------------------------------------------------------------
const routeY = 0.35;
const distanceValues = [120, 85, 140, 95];
const waypointData = [
new THREE.Vector3(-9, routeY, 0),
new THREE.Vector3(-4.5, routeY, 1.25),
new THREE.Vector3(0, routeY, 0),
new THREE.Vector3(4.5, routeY, -1.25),
new THREE.Vector3(9, routeY, 0)
];
const routeSegments = [
new THREE.CubicBezierCurve3(
waypointData[0],
new THREE.Vector3(-7.2, routeY, 0),
new THREE.Vector3(-6.0, routeY, 1.25),
waypointData[1]
),
new THREE.CubicBezierCurve3(
waypointData[1],
new THREE.Vector3(-3.2, routeY, 1.25),
new THREE.Vector3(-1.2, routeY, 0),
waypointData[2]
),
new THREE.CubicBezierCurve3(
waypointData[2],
new THREE.Vector3(1.2, routeY, 0),
new THREE.Vector3(3.2, routeY, -1.25),
waypointData[3]
),
new THREE.CubicBezierCurve3(
waypointData[3],
new THREE.Vector3(5.8, routeY, -1.25),
new THREE.Vector3(7.2, routeY, 0),
waypointData[4]
)
];
const routeMaterial = material("#eda34a", {
roughness: 0.62,
emissive: "#b5671b",
emissiveIntensity: 0.08
});
routeSegments.forEach((segment) => {
const length = segment.getLength();
const dashCount = Math.floor(length / 0.38);
for (let i = 0; i < dashCount; i++) {
const t = (i + 0.5) / dashCount;
const point = segment.getPoint(t);
const tangent = segment.getTangent(t);
const dash = box(
scene,
0.3,
0.075,
0.11,
routeMaterial,
point.x,
point.y,
point.z
);
dash.rotation.y = Math.atan2(-tangent.z, tangent.x);
}
});
// -------------------------------------------------------------------------
// Voxel bird and its shadow
// -------------------------------------------------------------------------
const bird = new THREE.Group();
bird.scale.setScalar(1.08);
scene.add(bird);
const birdBodyMaterial = material("#eb6548", { roughness: 0.72 });
const birdWingMaterial = material("#304d45", { roughness: 0.8 });
const birdBeakMaterial = material("#ffc85b");
const birdEyeMaterial = material("#1f302c");
box(bird, 0.48, 0.23, 0.27, birdBodyMaterial, 0, 0, 0);
box(bird, 0.22, 0.22, 0.22, birdBodyMaterial, 0.27, 0.08, 0);
box(bird, 0.14, 0.08, 0.11, birdBeakMaterial, 0.43, 0.07, 0);
box(bird, 0.24, 0.08, 0.1, birdWingMaterial, -0.31, 0.015, 0.06);
box(bird, 0.24, 0.08, 0.1, birdWingMaterial, -0.31, 0.015, -0.06);
box(bird, 0.035, 0.045, 0.035, birdEyeMaterial, 0.34, 0.13, 0.1);
box(bird, 0.035, 0.045, 0.035, birdEyeMaterial, 0.34, 0.13, -0.1);
const leftWing = new THREE.Group();
const rightWing = new THREE.Group();
bird.add(leftWing, rightWing);
box(leftWing, 0.31, 0.065, 0.26, birdWingMaterial, -0.015, 0.015, -0.19);
box(leftWing, 0.18, 0.055, 0.2, birdWingMaterial, -0.055, 0.015, -0.4);
box(rightWing, 0.31, 0.065, 0.26, birdWingMaterial, -0.015, 0.015, 0.19);
box(rightWing, 0.18, 0.055, 0.2, birdWingMaterial, -0.055, 0.015, 0.4);
const birdShadow = new THREE.Group();
scene.add(birdShadow);
const shadowMaterial = new THREE.MeshBasicMaterial({
color: 0x314a3f,
transparent: true,
opacity: 0.15,
depthWrite: false
});
box(birdShadow, 0.58, 0.012, 0.36, shadowMaterial, 0, 0, 0, {
castShadow: false,
receiveShadow: false
});
// -------------------------------------------------------------------------
// Decorative voxel clouds
// -------------------------------------------------------------------------
const cloudMaterial = material("#f8faf4", { roughness: 1 });
const clouds = [];
function addCloud(x, y, z, scale, phase) {
const cloud = new THREE.Group();
cloud.position.set(x, y, z);
cloud.scale.setScalar(scale);
scene.add(cloud);
box(cloud, 1.5, 0.48, 0.6, cloudMaterial, 0, 0, 0);
box(cloud, 0.8, 0.7, 0.7, cloudMaterial, -0.45, 0.14, 0);
box(cloud, 0.65, 0.52, 0.65, cloudMaterial, 0.52, 0.08, 0);
box(cloud, 0.45, 0.38, 0.5, cloudMaterial, 0.95, -0.04, 0);
cloud.userData.baseX = x;
cloud.userData.phase = phase;
clouds.push(cloud);
}
addCloud(-8.5, 6.4, -7.8, 0.85, 0.2);
addCloud(2.5, 7.2, -9.2, 0.65, 1.7);
addCloud(10.8, 5.8, -5.5, 0.72, 3.1);
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
const projectedLabels = [];
function addLabel(position, html, className) {
const element = document.createElement("div");
element.className = className;
element.innerHTML = html;
labelsContainer.appendChild(element);
projectedLabels.push({
element,
position: position.clone()
});
}
addLabel(
new THREE.Vector3(-9, 2.55, 0),
`
<div class="habitat-index">01</div>
<div>
<span>Spring staging</span>
<strong>Tidal Marsh</strong>
</div>
`,
"habitat-label"
);
addLabel(
new THREE.Vector3(0, 2.55, 0),
`
<div class="habitat-index">02</div>
<div>
<span>Refueling habitat</span>
<strong>Prairie Mosaic</strong>
</div>
`,
"habitat-label"
);
addLabel(
new THREE.Vector3(9, 2.55, 0),
`
<div class="habitat-index">03</div>
<div>
<span>Wintering ground</span>
<strong>Delta Reedbed</strong>
</div>
`,
"habitat-label"
);
addLabel(
new THREE.Vector3(-4.5, 1.25, 1.25),
`
<div class="rest-diamond"></div>
<div>
<span>Intermediate pause</span>
<strong>Rest 01</strong>
</div>
`,
"rest-label"
);
addLabel(
new THREE.Vector3(4.5, 1.25, -1.25),
`
<div class="rest-diamond"></div>
<div>
<span>Intermediate pause</span>
<strong>Rest 02</strong>
</div>
`,
"rest-label"
);
routeSegments.forEach((segment, i) => {
const point = segment.getPoint(0.52);
point.y = 0.78;
addLabel(point, `≈ ${distanceValues[i]} km`, "distance-label");
});
// -------------------------------------------------------------------------
// Custom orbit controls — no external control modules
// -------------------------------------------------------------------------
const orbit = {
radius: 22,
theta: 0.18,
phi: 1.02,
target: new THREE.Vector3(0, 0, 0),
following: false
};
const spherical = new THREE.Spherical();
const cameraOffset = new THREE.Vector3();
const followTarget = new THREE.Vector3();
const canvas = renderer.domElement;
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
function updateCamera(dt) {
if (orbit.following) {
followTarget.set(bird.position.x, 0, bird.position.z);
orbit.target.lerp(
followTarget,
1 - Math.exp(-dt * 2.25)
);
}
spherical.set(orbit.radius, orbit.phi, orbit.theta);
cameraOffset.setFromSpherical(spherical);
camera.position.copy(orbit.target).add(cameraOffset);
camera.lookAt(orbit.target);
camera.updateMatrixWorld();
}
canvas.addEventListener("pointerdown", (event) => {
if (event.pointerType === "mouse" && event.button !== 0) return;
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.005,
0.42,
1.38
);
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
11,
48
);
},
{ passive: false }
);
function resetView() {
orbit.following = false;
followButton.setAttribute("aria-pressed", "false");
followButton.textContent = "Follow bird";
orbit.target.set(0, 0, 0);
orbit.radius = window.innerWidth < 700 ? 45 : 22;
orbit.theta = 0.18;
orbit.phi = 1.02;
}
resetButton.addEventListener("click", resetView);
canvas.addEventListener("dblclick", resetView);
followButton.addEventListener("click", () => {
orbit.following = !orbit.following;
followButton.setAttribute("aria-pressed", String(orbit.following));
followButton.textContent = orbit.following
? "Following bird"
: "Follow bird";
});
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") orbit.theta -= 0.08;
if (event.key === "ArrowRight") orbit.theta += 0.08;
if (event.key === "ArrowUp") orbit.phi = Math.max(0.42, orbit.phi - 0.06);
if (event.key === "ArrowDown") orbit.phi = Math.min(1.38, orbit.phi + 0.06);
if (event.key === "+" || event.key === "=") {
orbit.radius = Math.max(11, orbit.radius - 1);
}
if (event.key === "-") orbit.radius = Math.min(48, orbit.radius + 1);
});
// -------------------------------------------------------------------------
// Bird animation and journey state
// -------------------------------------------------------------------------
const journey = {
leg: 0,
t: 0,
paused: false,
wait: 0
};
const durations = distanceValues.map((distance) => distance / 34);
const cumulativeDistance = [0];
distanceValues.forEach((distance) => {
cumulativeDistance.push(
cumulativeDistance[cumulativeDistance.length - 1] + distance
);
});
const totalDistance = cumulativeDistance[cumulativeDistance.length - 1];
const movingStatus = [
"Crossing the tidal flats",
"Flying toward Prairie Mosaic",
"Over the coastal corridor",
"Approaching Delta Reedbed"
];
const pausedStatus = [
"Resting at intermediate Rest 01",
"Refueling at Prairie Mosaic",
"Resting at intermediate Rest 02",
"Wintering habitat reached"
];
let previousStatus = "";
function updateBird(dt, elapsed) {
if (!journey.paused) {
journey.t += dt / durations[journey.leg];
if (journey.t >= 1) {
journey.t = 1;
journey.paused = true;
journey.wait = journey.leg === routeSegments.length - 1 ? 2.4 : 1.45;
}
} else {
journey.wait -= dt;
if (journey.wait <= 0) {
if (journey.leg === routeSegments.length - 1) {
journey.leg = 0;
journey.t = 0;
} else {
journey.leg += 1;
journey.t = 0;
}
journey.paused = false;
}
}
const curve = routeSegments[journey.leg];
const point = curve.getPoint(journey.t);
const tangent = curve.getTangent(journey.t);
const bob = journey.paused ? 0 : Math.sin(elapsed * 5.2) * 0.07;
bird.position.set(point.x, point.y + 1.03 + bob, point.z);
bird.rotation.y = Math.atan2(-tangent.z, tangent.x);
bird.rotation.z = journey.paused ? 0 : Math.sin(elapsed * 2.1) * 0.035;
const flap = journey.paused
? 0
: Math.sin(elapsed * 13.5) * 0.48;
leftWing.rotation.x = -flap;
rightWing.rotation.x = flap;
birdShadow.position.set(point.x, 0.155, point.z);
birdShadow.rotation.y = bird.rotation.y;
birdShadow.scale.setScalar(1 - bob * 0.9);
const status = journey.paused
? pausedStatus[journey.leg]
: movingStatus[journey.leg];
if (status !== previousStatus) {
statusText.textContent = status;
previousStatus = status;
}
const traveled =
cumulativeDistance[journey.leg] +
distanceValues[journey.leg] * journey.t;
progressFill.style.width = `${(traveled / totalDistance) * 100}%`;
}
// -------------------------------------------------------------------------
// Label projection and resize
// -------------------------------------------------------------------------
const projectedPoint = new THREE.Vector3();
function updateLabels() {
projectedLabels.forEach(({ element, position }) => {
projectedPoint.copy(position).project(camera);
const visible =
projectedPoint.z > -1 &&
projectedPoint.z < 1 &&
Math.abs(projectedPoint.x) < 1.25 &&
Math.abs(projectedPoint.y) < 1.25;
element.style.visibility = visible ? "visible" : "hidden";
element.style.opacity = visible ? "1" : "0";
if (visible) {
const x = (projectedPoint.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projectedPoint.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
});
}
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", onResize);
// -------------------------------------------------------------------------
// Animation loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
elapsed += dt;
updateBird(dt, elapsed);
updateCamera(dt);
clouds.forEach((cloud) => {
cloud.position.x =
cloud.userData.baseX +
Math.sin(elapsed * 0.08 + cloud.userData.phase) * 0.65;
});
updateLabels();
renderer.render(scene, camera);
}
// Start at the departure habitat and remove the loading message.
bird.position.set(-9, routeY + 1.03, 0);
updateCamera(0.016);
renderer.render(scene, camera);
document.getElementById("loading").classList.add("hidden");
animate();
</script>
</body>
</html>
```