Prompt specification
Build or customize the Three.js 3D scene "Patagonian glacier tongue above a meltwater stream" 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: Patagonian glacier tongue above a meltwater stream
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/patagonian-glacier-tongue-above-a-meltwater-stream-x3110
Scene Description Prompt:
A voxel Patagonian glacier tongue above a meltwater channel and rocky valley floor, with schematic ice motion. Three.js from cdnjs, one HTML file.
Working Three.js Starter (patagonian-glacier-tongue-above-a-meltwater-stream-x3110):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Patagonian Glacier — Voxel Field Model</title>
<style>
:root {
--ink: #17343d;
--muted: #587078;
--ice: #c9edf0;
--water: #43a6b8;
--paper: rgba(244, 248, 244, 0.88);
--line: rgba(23, 52, 61, 0.17);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 74% 18%, rgba(255, 249, 222, 0.95), transparent 23%),
linear-gradient(180deg, #a9cbd1 0%, #d4e0dc 54%, #e5e1d4 100%);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
linear-gradient(180deg, rgba(18, 50, 59, 0.06), transparent 22%),
radial-gradient(circle at center, transparent 58%, rgba(30, 55, 58, 0.13) 100%);
z-index: 2;
}
.brand {
position: fixed;
top: 28px;
left: 30px;
z-index: 5;
max-width: 360px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 9px;
color: #31535c;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 28px;
height: 2px;
background: #31535c;
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 54px);
font-weight: 740;
line-height: 0.95;
letter-spacing: -0.055em;
}
.brand p {
margin: 12px 0 0;
color: var(--muted);
font-size: 12px;
font-weight: 650;
letter-spacing: 0.075em;
text-transform: uppercase;
}
.coordinates {
display: inline-flex;
gap: 8px;
margin-top: 15px;
padding: 7px 10px;
border: 1px solid rgba(23, 52, 61, 0.22);
border-radius: 3px;
background: rgba(238, 246, 241, 0.48);
color: #31535c;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
letter-spacing: 0.07em;
}
.panel {
position: fixed;
right: 26px;
bottom: 25px;
z-index: 6;
width: 246px;
padding: 17px;
border: 1px solid rgba(29, 58, 65, 0.14);
border-radius: 10px;
background: var(--paper);
box-shadow: 0 18px 50px rgba(28, 58, 61, 0.13);
backdrop-filter: blur(14px);
}
.panel-title {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 13px;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.live {
display: flex;
align-items: center;
gap: 6px;
color: #47716e;
font-size: 9px;
letter-spacing: 0.08em;
}
.live::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: #48a886;
box-shadow: 0 0 0 4px rgba(72, 168, 134, 0.12);
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin: 9px 0;
color: #466168;
font-size: 11px;
}
.swatch {
width: 17px;
height: 10px;
flex: 0 0 auto;
border-radius: 2px;
box-shadow: inset 0 0 0 1px rgba(20, 52, 60, 0.12);
}
.swatch.ice { background: #d8f1ef; }
.swatch.crevasse { background: #518ba4; }
.swatch.water { background: #4ca8b7; }
.swatch.rock { background: #777b70; }
.swatch.flow {
position: relative;
background: #167692;
}
.swatch.flow::after {
content: "";
position: absolute;
right: -1px;
top: 1px;
border-top: 4px solid transparent;
border-bottom: 4px solid transparent;
border-left: 5px solid #167692;
}
.controls {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
margin-top: 15px;
padding-top: 14px;
border-top: 1px solid var(--line);
}
button {
min-height: 34px;
border: 1px solid rgba(23, 52, 61, 0.2);
border-radius: 5px;
background: rgba(255, 255, 255, 0.52);
color: #294a52;
font: inherit;
font-size: 10px;
font-weight: 750;
cursor: pointer;
transition: background 150ms ease, transform 150ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.95);
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
button.primary {
grid-column: 1 / -1;
background: #244c56;
color: #eff8f5;
border-color: #244c56;
}
.hint {
position: fixed;
left: 30px;
bottom: 27px;
z-index: 5;
display: flex;
align-items: center;
gap: 10px;
padding: 9px 12px;
border-left: 2px solid rgba(23, 52, 61, 0.55);
background: rgba(240, 247, 241, 0.48);
color: #4c6870;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.045em;
pointer-events: none;
}
.hint span {
color: #769097;
}
.compass {
position: fixed;
top: 29px;
right: 29px;
z-index: 5;
width: 47px;
height: 47px;
border: 1px solid rgba(23, 52, 61, 0.28);
border-radius: 50%;
color: #31535c;
text-align: center;
pointer-events: none;
}
.compass::before {
content: "";
position: absolute;
top: 6px;
left: 22px;
width: 0;
height: 0;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-bottom: 13px solid #31535c;
}
.compass span {
position: absolute;
bottom: 5px;
left: 0;
right: 0;
font-size: 9px;
font-weight: 900;
}
.annotation {
position: fixed;
z-index: 4;
display: flex;
align-items: center;
gap: 7px;
padding: 5px 8px;
border: 1px solid rgba(22, 51, 58, 0.2);
border-radius: 4px;
background: rgba(246, 250, 246, 0.82);
box-shadow: 0 6px 20px rgba(27, 53, 58, 0.09);
color: #24464f;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -50%);
transition: opacity 120ms ease;
}
.annotation::before {
content: "";
width: 5px;
height: 5px;
border-radius: 50%;
background: #207f98;
box-shadow: 0 0 0 3px rgba(32, 127, 152, 0.14);
}
.annotation.water::before { background: #43a6b8; }
.annotation.rock::before { background: #71766b; }
.annotation.flow::before { background: #167692; }
.annotations-hidden .annotation {
opacity: 0;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #c9dcd7;
color: #294a52;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
.brand {
top: 20px;
left: 20px;
}
h1 {
font-size: 36px;
}
.brand p,
.coordinates,
.compass {
display: none;
}
.panel {
right: 15px;
bottom: 15px;
width: 205px;
padding: 13px;
}
.hint {
left: 15px;
bottom: 15px;
max-width: calc(100% - 240px);
line-height: 1.45;
}
.hint .desktop {
display: none;
}
}
</style>
</head>
<body>
<div class="vignette"></div>
<header class="brand">
<div class="eyebrow">Field model 07 / Patagonia</div>
<h1>Ice Tongue</h1>
<p>Schematic voxel glacier study</p>
<div class="coordinates">46° 12′ S / 72° 48′ W</div>
</header>
<div class="compass"><span>N</span></div>
<section class="panel" aria-label="Scene legend and controls">
<div class="panel-title">
<span>Material key</span>
<span class="live">Active</span>
</div>
<div class="legend-row"><i class="swatch ice"></i>Glacier ice</div>
<div class="legend-row"><i class="swatch crevasse"></i>Crevasse field</div>
<div class="legend-row"><i class="swatch water"></i>Meltwater channel</div>
<div class="legend-row"><i class="swatch rock"></i>Rocky valley floor</div>
<div class="legend-row"><i class="swatch flow"></i>Schematic ice motion</div>
<div class="controls">
<button id="motionButton" class="primary" type="button">Pause motion</button>
<button id="labelsButton" type="button">Hide labels</button>
<button id="resetButton" type="button">Reset view</button>
</div>
</section>
<div class="hint">
<span>Drag to orbit</span>
<span>·</span>
<span>Wheel to zoom</span>
<span class="desktop">· Right-drag to pan · Pinch on touch</span>
</div>
<div id="loading">Building voxel field…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xc8d9d6, 31, 72);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
120
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xe8f8f4, 0x706b5d, 2.1);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff0cc, 3.25);
sun.position.set(-16, 25, 13);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -31;
sun.shadow.camera.right = 31;
sun.shadow.camera.top = 31;
sun.shadow.camera.bottom = -31;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 75;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8fc7d8, 0.65);
fill.position.set(18, 9, -18);
scene.add(fill);
// -------------------------------------------------------------------------
// Deterministic helpers
// -------------------------------------------------------------------------
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;
};
}
const random = mulberry32(471206);
const dummy = new THREE.Object3D();
const tempColor = new THREE.Color();
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
function smoothChannelX(z) {
if (z < 6) {
return 0.12 * Math.sin(z * 0.22);
}
return 2.0 * Math.sin((z - 6) * 0.34);
}
function terrainTop(x, z) {
const distance = Math.abs(x - smoothChannelX(z));
const sideRise = Math.pow(Math.max(0, distance - 3.4), 1.12) * 0.32;
const variation =
Math.sin(x * 1.71 + z * 0.47) * 0.13 +
Math.sin(x * 0.59 - z * 1.13) * 0.09;
return Math.min(5.5, -0.28 + sideRise + variation);
}
function glacierCenter(z) {
return 0.14 * Math.sin(z * 0.18);
}
function glacierWidth(z) {
const t = THREE.MathUtils.clamp((z + 20) / 25.4, 0, 1);
return 8.6 - t * 2.75;
}
function glacierTop(z, offset = 0) {
const t = THREE.MathUtils.clamp((z + 20) / 25.4, 0, 1);
const width = glacierWidth(z);
const crown = 0.55 * (1 - Math.min(1, Math.abs(offset) / (width * 0.82)));
let top = 6.0 - t * 3.25 + crown;
const bands = [-15.2, -10.9, -6.6, -2.2, 2.1];
for (const band of bands) {
if (Math.abs(z - band) < 0.48 && Math.abs(offset) < width * 0.73) {
top -= 0.48 + 0.38 * Math.sin((offset + 9) * 1.9);
}
}
return top;
}
function setInstance(mesh, index, x, y, z, sx, sy, sz, color, ry = 0) {
dummy.position.set(x, y, z);
dummy.rotation.set(0, ry, 0);
dummy.scale.set(sx, sy, sz);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
mesh.setColorAt(index, color);
}
// -------------------------------------------------------------------------
// Valley floor
// -------------------------------------------------------------------------
const base = new THREE.Mesh(
new THREE.BoxGeometry(54, 1.2, 58),
new THREE.MeshStandardMaterial({
color: 0x666b62,
roughness: 1
})
);
base.position.set(0, -1.1, -2);
base.receiveShadow = true;
scene.add(base);
const terrainData = [];
for (let x = -18; x <= 18; x++) {
for (let z = -24; z <= 20; z++) {
const channelDistance = Math.abs(x - smoothChannelX(z));
const isChannel = z > 5.35 && channelDistance < 1.55;
const top = isChannel ? -0.65 : terrainTop(x, z);
const height = top + 0.72;
let color;
if (isChannel) {
color = new THREE.Color(0x4d5551);
} else if (channelDistance < 3.8) {
color = new THREE.Color(0x777b70);
} else if (channelDistance < 7.5) {
color = new THREE.Color(0x74766a);
} else {
color = new THREE.Color(0x6d756a);
}
color.multiplyScalar(0.9 + random() * 0.18);
terrainData.push({
x,
y: top - height / 2,
z,
sx: 0.97,
sy: height,
sz: 0.97,
color
});
}
}
const terrain = new THREE.InstancedMesh(
cubeGeometry,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
metalness: 0
}),
terrainData.length
);
terrainData.forEach((d, i) => {
setInstance(
terrain, i,
d.x, d.y, d.z,
d.sx, d.sy, d.sz,
d.color
);
});
terrain.receiveShadow = true;
terrain.instanceMatrix.needsUpdate = true;
terrain.instanceColor.needsUpdate = true;
scene.add(terrain);
// -------------------------------------------------------------------------
// Meltwater channel
// -------------------------------------------------------------------------
const waterData = [];
const waterPalette = [0x3f9eaf, 0x55b3bd, 0x64bec4, 0x459dab];
for (let z = 5.25; z <= 19.8; z += 0.78) {
const center = smoothChannelX(z);
const halfWidth = 1.25 + 0.18 * Math.sin(z * 0.47);
for (let x = center - halfWidth; x <= center + halfWidth; x += 0.76) {
waterData.push({
x,
z,
color: new THREE.Color(
waterPalette[Math.floor(random() * waterPalette.length)]
)
});
}
}
const water = new THREE.InstancedMesh(
cubeGeometry,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.22,
metalness: 0.08,
transparent: true,
opacity: 0.92
}),
waterData.length
);
waterData.forEach((d, i) => {
setInstance(
water, i,
d.x, -0.48, d.z,
0.74, 0.13, 0.76,
d.color
);
});
water.receiveShadow = true;
water.instanceMatrix.needsUpdate = true;
water.instanceColor.needsUpdate = true;
scene.add(water);
// Foam / suspended sediment blocks in the channel.
const foamState = [];
const foamCount = 42;
for (let i = 0; i < foamCount; i++) {
foamState.push({
z: 5.5 + random() * 13.5,
lane: (random() - 0.5) * 1.35,
speed: 0.65 + random() * 0.65,
size: 0.07 + random() * 0.13,
phase: random() * Math.PI * 2
});
}
const foam = new THREE.InstancedMesh(
cubeGeometry,
new THREE.MeshBasicMaterial({
color: 0xdaf5ed,
transparent: true,
opacity: 0.82
}),
foamCount
);
foam.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
scene.add(foam);
// -------------------------------------------------------------------------
// Glacier tongue: stacked voxel blocks
// -------------------------------------------------------------------------
const iceBaseData = [];
const iceCapData = [];
for (let z = -20; z <= 5.35; z += 0.88) {
const center = glacierCenter(z);
const width = glacierWidth(z) + (random() - 0.5) * 0.42;
for (let x = -10; x <= 10; x++) {
const offset = x * 0.88;
const edgeNoise = (random() - 0.5) * 0.5;
if (Math.abs(offset) > width + edgeNoise) continue;
// Irregular terminal edge.
if (z > 4.25 && random() < 0.29) continue;
// Leave the meltwater portal open.
if (z > 4.0 && Math.abs(offset - center) < 1.25) continue;
const isCrevasse =
Math.abs(offset) < width * 0.73 &&
[-15.2, -10.9, -6.6, -2.2, 2.1].some(
band => Math.abs(z - band) < 0.47
);
let top = glacierTop(z, offset);
top += (random() - 0.5) * 0.14;
if (Math.abs(offset) > width - 0.55) top -= 0.16;
if (isCrevasse) top -= 0.12;
const edge = Math.abs(offset) / width;
const baseColor = new THREE.Color(0xaed9df);
if (isCrevasse) {
baseColor.set(0x477f98);
} else if (edge > 0.77) {
baseColor.set(0x88bfcb);
} else {
baseColor.set(0xaed9df);
}
baseColor.multiplyScalar(0.94 + random() * 0.11);
const capColor = new THREE.Color(
isCrevasse ? 0x75aabd : 0xd9efed
);
capColor.multiplyScalar(0.96 + random() * 0.08);
const bottom = -0.52;
const height = top - bottom;
iceBaseData.push({
x: center + offset,
y: bottom + height / 2,
z,
sx: 0.86,
sy: height,
sz: 0.86,
color: baseColor
});
iceCapData.push({
x: center + offset,
y: top + 0.055,
z,
sx: 0.83,
sy: 0.11,
sz: 0.83,
color: capColor
});
}
}
const iceBase = new THREE.InstancedMesh(
cubeGeometry,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.66,
metalness: 0.02
}),
iceBaseData.length
);
iceBaseData.forEach((d, i) => {
setInstance(
iceBase, i,
d.x, d.y, d.z,
d.sx, d.sy, d.sz,
d.color
);
});
iceBase.castShadow = true;
iceBase.receiveShadow = true;
iceBase.instanceMatrix.needsUpdate = true;
iceBase.instanceColor.needsUpdate = true;
scene.add(iceBase);
const iceCaps = new THREE.InstancedMesh(
cubeGeometry,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.78
}),
iceCapData.length
);
iceCapData.forEach((d, i) => {
setInstance(
iceCaps, i,
d.x, d.y, d.z,
d.sx, d.sy, d.sz,
d.color
);
});
iceCaps.castShadow = true;
iceCaps.receiveShadow = true;
iceCaps.instanceMatrix.needsUpdate = true;
iceCaps.instanceColor.needsUpdate = true;
scene.add(iceCaps);
// -------------------------------------------------------------------------
// Meltwater portal beneath the glacier terminus
// -------------------------------------------------------------------------
const portal = new THREE.Mesh(
new THREE.BoxGeometry(2.25, 1.75, 0.16),
new THREE.MeshBasicMaterial({ color: 0x153d4a })
);
portal.position.set(0.1, 0.52, 5.12);
scene.add(portal);
const archMaterial = new THREE.MeshStandardMaterial({
color: 0xa8d8de,
roughness: 0.68
});
const archLeft = new THREE.Mesh(
new THREE.BoxGeometry(1.25, 2.35, 1.15),
archMaterial
);
archLeft.position.set(-1.55, 0.65, 5.28);
archLeft.castShadow = true;
scene.add(archLeft);
const archRight = archLeft.clone();
archRight.position.x = 1.7;
scene.add(archRight);
const archTop = new THREE.Mesh(
new THREE.BoxGeometry(4.25, 0.65, 1.15),
archMaterial
);
archTop.position.set(0.1, 1.9, 5.28);
archTop.castShadow = true;
scene.add(archTop);
const waterfall = new THREE.Mesh(
new THREE.BoxGeometry(1.42, 1.36, 0.14),
new THREE.MeshBasicMaterial({
color: 0x72d0d5,
transparent: true,
opacity: 0.78
})
);
waterfall.position.set(0.1, 0.08, 5.38);
scene.add(waterfall);
// -------------------------------------------------------------------------
// Angular rock outcrops
// -------------------------------------------------------------------------
const rockData = [];
for (let i = 0; i < 170; i++) {
const x = (random() - 0.5) * 27;
const z = -18 + random() * 38;
const channelDistance = Math.abs(x - smoothChannelX(z));
if (channelDistance < 2.25) continue;
if (z < 5 && Math.abs(x) < 6.5) continue;
const size = 0.25 + random() * 0.95;
const height = size * (0.45 + random() * 1.25);
const shade = 0.43 + random() * 0.22;
rockData.push({
x,
y: terrainTop(x, z) + height / 2,
z,
sx: size * (0.75 + random() * 0.5),
sy: height,
sz: size * (0.75 + random() * 0.5),
color: new THREE.Color(shade, shade + 0.035, shade - 0.02),
ry: (random() > 0.5 ? 0 : Math.PI / 2) + (random() - 0.5) * 0.16
});
}
// A few larger stepped outcrops along the valley sides.
for (let i = 0; i < 42; i++) {
const side = random() > 0.5 ? 1 : -1;
const x = side * (6.8 + random() * 8.5);
const z = -16 + random() * 33;
const layers = 1 + Math.floor(random() * 3);
for (let layer = 0; layer < layers; layer++) {
const sx = 1.0 + random() * 1.8;
const sy = 0.55 + random() * 0.65;
const sz = 0.9 + random() * 1.6;
const y = terrainTop(x, z) + sy / 2 + layer * sy * 0.86;
const shade = 0.38 + random() * 0.2;
rockData.push({
x,
y,
z,
sx,
sy,
sz,
color: new THREE.Color(shade, shade + 0.04, shade),
ry: (random() > 0.5 ? 0 : Math.PI / 2)
});
}
}
const rocks = new THREE.InstancedMesh(
cubeGeometry,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1
}),
rockData.length
);
rockData.forEach((d, i) => {
setInstance(
rocks, i,
d.x, d.y, d.z,
d.sx, d.sy, d.sz,
d.color,
d.ry
);
});
rocks.castShadow = true;
rocks.receiveShadow = true;
rocks.instanceMatrix.needsUpdate = true;
rocks.instanceColor.needsUpdate = true;
scene.add(rocks);
// -------------------------------------------------------------------------
// Schematic ice-motion arrows
// -------------------------------------------------------------------------
const arrowMaterial = new THREE.MeshBasicMaterial({
color: 0x146f8c,
transparent: true,
opacity: 0.9,
depthWrite: false
});
const arrowShaftGeometry = new THREE.BoxGeometry(0.13, 0.075, 1.08);
const arrowHeadGeometry = new THREE.ConeGeometry(0.25, 0.48, 4);
const flowArrows = [];
for (const lane of [-0.65, 0, 0.65]) {
for (let i = 0; i < 3; i++) {
const group = new THREE.Group();
const shaft = new THREE.Mesh(arrowShaftGeometry, arrowMaterial);
group.add(shaft);
const head = new THREE.Mesh(arrowHeadGeometry, arrowMaterial);
head.rotation.x = Math.PI / 2;
head.position.z = 0.77;
group.add(head);
group.userData = {
lane,
phase: (i / 3 + (lane + 0.65) * 0.11) % 1,
speed: 0.07 + (i % 2) * 0.009
};
scene.add(group);
flowArrows.push(group);
}
}
function updateFlowArrows(time) {
for (const arrow of flowArrows) {
const progress = (time * arrow.userData.speed + arrow.userData.phase) % 1;
const z = -18.6 + progress * 22.2;
const zNext = z + 0.18;
const x = glacierCenter(z) +
arrow.userData.lane * glacierWidth(z) * 0.29;
const xNext = glacierCenter(zNext) +
arrow.userData.lane * glacierWidth(zNext) * 0.29;
const top = glacierTop(
z,
x - glacierCenter(z)
);
arrow.position.set(x, top + 0.25, z);
arrow.rotation.y = Math.atan2(xNext - x, zNext - z);
}
}
// -------------------------------------------------------------------------
// Screen-space labels
// -------------------------------------------------------------------------
const annotationElements = [];
let labelsVisible = true;
function addAnnotation(text, position, className = "") {
const element = document.createElement("div");
element.className = `annotation ${className}`;
element.textContent = text;
document.body.appendChild(element);
annotationElements.push({
element,
position: position.clone()
});
}
addAnnotation(
"Glacier tongue",
new THREE.Vector3(0.3, 4.3, -1.4)
);
addAnnotation(
"Meltwater channel",
new THREE.Vector3(1.8, 0.2, 11.8),
"water"
);
addAnnotation(
"Rocky valley floor",
new THREE.Vector3(-7.2, 1.4, 6.7),
"rock"
);
addAnnotation(
"Ice motion",
new THREE.Vector3(2.3, 5.8, -13.2),
"flow"
);
const projected = new THREE.Vector3();
function updateAnnotations() {
for (const annotation of annotationElements) {
projected.copy(annotation.position).project(camera);
const visible =
labelsVisible &&
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
annotation.element.style.opacity = visible ? "1" : "0";
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
annotation.element.style.left = `${x}px`;
annotation.element.style.top = `${y}px`;
}
}
// -------------------------------------------------------------------------
// Camera controls implemented directly
// -------------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 1.35, -1.6),
radius: 27,
theta: 0.59,
phi: 1.10
};
function resetCamera() {
controls.target.set(0, 1.35, -1.6);
controls.radius = 27;
controls.theta = 0.59;
controls.phi = 1.10;
updateCamera();
}
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
const cosPhi = Math.cos(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * cosPhi,
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
camera.updateMatrixWorld();
}
const pointers = new Map();
let dragMode = null;
let lastX = 0;
let lastY = 0;
let previousPinchDistance = 0;
const canvas = renderer.domElement;
function pointerDistance() {
const points = [...pointers.values()];
if (points.length < 2) return 0;
return Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
dragMode = event.button === 2 ? "pan" : "orbit";
lastX = event.clientX;
lastY = event.clientY;
} else {
dragMode = "pinch";
previousPinchDistance = pointerDistance();
}
});
canvas.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size >= 2) {
const distance = pointerDistance();
if (distance > 0 && previousPinchDistance > 0) {
controls.radius = THREE.MathUtils.clamp(
controls.radius * previousPinchDistance / distance,
12,
52
);
}
previousPinchDistance = distance;
updateCamera();
return;
}
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (dragMode === "orbit") {
controls.theta -= dx * 0.0052;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.0045,
0.43,
1.42
);
} else if (dragMode === "pan") {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3().crossVectors(
forward,
new THREE.Vector3(0, 1, 0)
).normalize();
const panScale = controls.radius * 0.0015;
controls.target.addScaledVector(right, -dx * panScale);
controls.target.addScaledVector(forward, dy * panScale);
controls.target.x = THREE.MathUtils.clamp(controls.target.x, -10, 10);
controls.target.z = THREE.MathUtils.clamp(controls.target.z, -16, 12);
controls.target.y = THREE.MathUtils.clamp(controls.target.y, -0.5, 5);
}
updateCamera();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 1) {
const remaining = [...pointers.values()][0];
lastX = remaining.x;
lastY = remaining.y;
dragMode = "orbit";
} else if (pointers.size === 0) {
dragMode = null;
previousPinchDistance = 0;
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("lostpointercapture", releasePointer);
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("wheel", event => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
12,
52
);
updateCamera();
}, { passive: false });
canvas.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// UI
// -------------------------------------------------------------------------
let motionRunning = true;
const motionButton = document.getElementById("motionButton");
const labelsButton = document.getElementById("labelsButton");
const resetButton = document.getElementById("resetButton");
motionButton.addEventListener("click", () => {
motionRunning = !motionRunning;
motionButton.textContent = motionRunning ? "Pause motion" : "Resume motion";
});
labelsButton.addEventListener("click", () => {
labelsVisible = !labelsVisible;
labelsButton.textContent = labelsVisible ? "Hide labels" : "Show labels";
});
resetButton.addEventListener("click", resetCamera);
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function onResize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
addEventListener("resize", onResize);
updateCamera();
updateFlowArrows(0);
let previousTime = performance.now();
let flowTime = 0;
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min(0.05, (now - previousTime) / 1000);
previousTime = now;
if (motionRunning) flowTime += delta;
updateFlowArrows(flowTime);
foamState.forEach((state, i) => {
const z = 5.3 + ((state.z - 5.3 + flowTime * state.speed) % 13.8);
const x = smoothChannelX(z) + state.lane;
const y = -0.28 + Math.sin(flowTime * 2.2 + state.phase) * 0.035;
dummy.position.set(x, y, z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(state.size, state.size * 0.55, state.size);
dummy.updateMatrix();
foam.setMatrixAt(i, dummy.matrix);
});
foam.instanceMatrix.needsUpdate = true;
waterfall.material.opacity = 0.69 + Math.sin(flowTime * 4.2) * 0.08;
waterfall.scale.y = 1 + Math.sin(flowTime * 3.5) * 0.035;
updateAnnotations();
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```