Prompt specification
Build or customize the Three.js 3D scene "Patagonian U-shaped valley and proglacial lake" 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 U-shaped valley and proglacial lake
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/patagonian-u-shaped-valley-and-proglacial-lake-x3111
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring Patagonia's glacial valleys and meltwater. Build a bounded landscape with steep valley walls, glacier tongue, lake, and moraine ridge. Use clear geometric relationships and label the deliberately compressed regional scale. Low-poly.
Working Three.js Starter (patagonian-u-shaped-valley-and-proglacial-lake-x3111):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Patagonia — Compressed Glacial Valley</title>
<style>
:root {
color-scheme: dark;
--ink: #edf4ef;
--muted: #b8c9c3;
--glass: rgba(20, 39, 40, 0.82);
--line: rgba(222, 240, 233, 0.35);
--accent: #8fd8d5;
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: #dbe7e3;
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;
cursor: grab;
}
canvas:active { cursor: grabbing; }
#overlay {
position: fixed;
inset: 0;
pointer-events: none;
color: var(--ink);
}
.title-block {
position: absolute;
top: 24px;
left: 26px;
max-width: min(440px, calc(100vw - 52px));
text-shadow: 0 2px 18px rgba(25, 47, 45, 0.45);
}
.kicker {
margin-bottom: 7px;
color: #f4d7a1;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.24em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3.1vw, 48px);
font-weight: 650;
letter-spacing: -0.045em;
line-height: 0.98;
}
.subtitle {
margin-top: 10px;
color: #e3efea;
font-size: 12px;
line-height: 1.45;
letter-spacing: 0.05em;
}
.scale-note {
position: absolute;
top: 24px;
right: 24px;
width: 264px;
padding: 14px 15px;
border: 1px solid var(--line);
border-radius: 3px;
background: var(--glass);
box-shadow: 0 12px 35px rgba(27, 45, 43, 0.16);
backdrop-filter: blur(12px);
}
.scale-note .label {
color: #f4d7a1;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
line-height: 1.35;
text-transform: uppercase;
}
.scale-note p {
margin: 7px 0 11px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.scale-bar {
position: relative;
height: 7px;
border-bottom: 2px solid #e7f0eb;
}
.scale-bar::before,
.scale-bar::after {
content: "";
position: absolute;
bottom: -5px;
width: 1px;
height: 9px;
background: #e7f0eb;
}
.scale-bar::before { left: 0; }
.scale-bar::after { right: 0; }
.scale-caption {
margin-top: 6px;
color: #d9e7e1;
font-size: 9px;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.controls {
position: absolute;
right: 24px;
bottom: 22px;
display: flex;
align-items: center;
gap: 13px;
padding: 10px 12px;
border: 1px solid var(--line);
border-radius: 3px;
background: var(--glass);
color: var(--muted);
font-size: 10px;
letter-spacing: 0.04em;
pointer-events: auto;
backdrop-filter: blur(10px);
}
.controls button {
border: 1px solid rgba(225, 241, 234, 0.32);
border-radius: 2px;
padding: 6px 9px;
background: rgba(238, 248, 243, 0.08);
color: var(--ink);
font: inherit;
cursor: pointer;
}
.controls button:hover {
background: rgba(238, 248, 243, 0.18);
}
.compass {
position: absolute;
left: 27px;
bottom: 24px;
display: flex;
align-items: center;
gap: 11px;
color: rgba(245, 250, 247, 0.9);
text-shadow: 0 1px 8px rgba(24, 43, 42, 0.55);
}
.compass-ring {
position: relative;
width: 40px;
height: 40px;
border: 1px solid rgba(245, 250, 247, 0.7);
border-radius: 50%;
}
.compass-ring::before {
content: "";
position: absolute;
left: 18px;
top: 5px;
width: 0;
height: 0;
border-right: 4px solid transparent;
border-bottom: 13px solid #f4d7a1;
border-left: 4px solid transparent;
transform: rotate(18deg);
}
.compass-ring::after {
content: "";
position: absolute;
left: 18px;
bottom: 5px;
width: 0;
height: 0;
border-right: 4px solid transparent;
border-top: 11px solid rgba(245, 250, 247, 0.82);
border-left: 4px solid transparent;
transform: rotate(18deg);
}
.compass-copy {
font-size: 9px;
font-weight: 700;
letter-spacing: 0.16em;
line-height: 1.55;
text-transform: uppercase;
}
.map-label {
position: absolute;
top: 0;
left: 0;
width: 0;
height: 0;
opacity: 0;
transition: opacity 120ms linear;
pointer-events: none;
filter: drop-shadow(0 2px 5px rgba(22, 40, 39, 0.4));
}
.map-label.visible { opacity: 1; }
.map-label .stem {
position: absolute;
top: 0;
left: 0;
width: 35px;
height: 1px;
background: rgba(246, 251, 248, 0.82);
}
.map-label .stem::before {
content: "";
position: absolute;
left: -3px;
top: -3px;
width: 7px;
height: 7px;
border: 1px solid #f6fbf8;
border-radius: 50%;
background: rgba(34, 65, 63, 0.86);
}
.map-label .copy {
position: absolute;
top: -50%;
left: 43px;
padding: 6px 8px;
border-left: 2px solid var(--accent);
border-radius: 1px;
background: rgba(19, 39, 40, 0.82);
color: #f2f7f3;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.13em;
line-height: 1.25;
text-transform: uppercase;
white-space: nowrap;
backdrop-filter: blur(5px);
}
.map-label.left .stem {
left: auto;
right: 0;
}
.map-label.left .stem::before {
left: auto;
right: -3px;
}
.map-label.left .copy {
left: auto;
right: 43px;
border-right: 2px solid var(--accent);
border-left: 0;
text-align: right;
}
.map-label.glacier .copy { border-color: #c4eceb; }
.map-label.moraine .copy { border-color: #c7a97d; }
.map-label.wall .copy { border-color: #d6d5c8; }
@media (max-width: 720px) {
.title-block { top: 18px; left: 18px; }
.scale-note {
top: auto;
right: 14px;
bottom: 66px;
width: 230px;
}
.controls {
right: 14px;
bottom: 14px;
left: 14px;
justify-content: space-between;
}
.compass { display: none; }
.map-label.wall { display: none; }
.map-label .copy { font-size: 8px; }
}
</style>
</head>
<body>
<div id="overlay">
<header class="title-block">
<div class="kicker">Patagonia · Glacial geomorphology</div>
<h1>Glacial Valley<br>and Meltwater</h1>
<div class="subtitle">
Low-poly regional study: U-shaped valley, glacier tongue,
moraine ridge, and proglacial lake.
</div>
</header>
<aside class="scale-note">
<div class="label">Regional scale compressed</div>
<p>
Horizontal distances are condensed into a schematic transect.
Vertical relief is exaggerated approximately ×2.
</p>
<div class="scale-bar"></div>
<div class="scale-caption">Schematic regional scale · not to scale</div>
</aside>
<div class="compass">
<div class="compass-ring"></div>
<div class="compass-copy">Glacier flow<br>↓ valley axis</div>
</div>
<div class="controls">
<span>Drag: orbit · Wheel: zoom · Shift-drag: pan</span>
<button id="reset-view" type="button">Reset</button>
</div>
<div id="label-glacier" class="map-label glacier left">
<span class="stem"></span><span class="copy">Glacier tongue</span>
</div>
<div id="label-lake" class="map-label">
<span class="stem"></span><span class="copy">Meltwater lake</span>
</div>
<div id="label-moraine" class="map-label moraine">
<span class="stem"></span><span class="copy">Moraine ridge</span>
</div>
<div id="label-melt" class="map-label">
<span class="stem"></span><span class="copy">Proglacial meltwater</span>
</div>
<div id="label-wall" class="map-label wall left">
<span class="stem"></span><span class="copy">Steep valley wall</span>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, camera, lighting
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly model of a Patagonian glacial valley"
);
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdbe7e3);
scene.fog = new THREE.Fog(0xdbe7e3, 88, 155);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
240
);
const hemisphere = new THREE.HemisphereLight(0xeaf6f5, 0x454a40, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d8, 3.35);
sun.position.set(-30, 52, 32);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -55;
sun.shadow.camera.right = 55;
sun.shadow.camera.top = 55;
sun.shadow.camera.bottom = -55;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 130;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xa9d8dd, 0.65);
fill.position.set(28, 18, -32);
scene.add(fill);
// -------------------------------------------------------------------------
// Deterministic helpers and terrain functions
// -------------------------------------------------------------------------
const clamp = (v, a, b) => Math.max(a, Math.min(b, v));
function smoothstep(a, b, x) {
const t = clamp((x - a) / (b - a), 0, 1);
return t * t * (3 - 2 * t);
}
function seededRandom(seed) {
let s = seed >>> 0;
return () => {
s = (s * 1664525 + 1013904223) >>> 0;
return s / 4294967296;
};
}
const random = seededRandom(731927);
function valleyCenter(z) {
return -1.15 + 0.9 * Math.sin((z + 8) * 0.08);
}
function floorElevation(z) {
return 0.35 + Math.max(0, 4 - z) * 0.34;
}
function terrainNoise(x, z) {
return (
0.50 * Math.sin(x * 0.83 + z * 0.41) +
0.27 * Math.sin(x * 1.71 - z * 0.63) +
0.23 * Math.sin(x * 0.27 - z * 0.20)
);
}
function lakeRadius(x, z) {
return Math.sqrt(
Math.pow(x / 11.2, 2) +
Math.pow((z - 13.0) / 9.7, 2)
);
}
function terrainHeight(x, z) {
const center = valleyCenter(z);
const distance = Math.abs(x - center);
const ridge = 0.5 + 0.5 * terrainNoise(x * 0.65, z * 0.65);
if (z <= 4) {
const floor = floorElevation(z);
const wall = smoothstep(6.2, 16.5, distance);
const upstreamMass = smoothstep(8, 24, -z);
const shoulders =
0.55 * Math.sin(x * 0.46 - z * 0.29) *
smoothstep(8, 14, distance);
return (
floor +
wall * (11.5 + 7.0 * ridge) +
upstreamMass * wall * 3.6 +
shoulders
);
}
const r = lakeRadius(x, z);
const basin = -2.3 + 0.8 * Math.pow(r, 3);
const shore = smoothstep(0.92, 1.18, r) * 6.5;
const wall = smoothstep(8.0, 17.0, distance);
return basin + shore + wall * (10.5 + 6.2 * ridge);
}
// -------------------------------------------------------------------------
// Faceted terrain surface
// -------------------------------------------------------------------------
const cols = 62;
const rows = 54;
const minX = -31;
const maxX = 31;
const minZ = -27;
const maxZ = 27;
const terrainPositions = [];
const terrainIndices = [];
const heightGrid = [];
for (let r = 0; r < rows; r++) {
const z = minZ + (maxZ - minZ) * r / (rows - 1);
const row = [];
for (let c = 0; c < cols; c++) {
const x = minX + (maxX - minX) * c / (cols - 1);
const y = terrainHeight(x, z);
row.push(y);
terrainPositions.push(x, y, z);
}
heightGrid.push(row);
}
for (let r = 0; r < rows - 1; r++) {
for (let c = 0; c < cols - 1; c++) {
const a = r * cols + c;
const b = a + 1;
const d = (r + 1) * cols + c;
const cNext = d + 1;
terrainIndices.push(a, d, b, b, d, cNext);
}
}
let terrainGeometry = new THREE.BufferGeometry();
terrainGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(terrainPositions, 3)
);
terrainGeometry.setIndex(terrainIndices);
terrainGeometry = terrainGeometry.toNonIndexed();
const terrainColors = [];
const color = new THREE.Color();
const grass = [
new THREE.Color(0x596957),
new THREE.Color(0x66735c),
new THREE.Color(0x707866)
];
const rock = [
new THREE.Color(0x555b58),
new THREE.Color(0x626763),
new THREE.Color(0x72736c),
new THREE.Color(0x4d5554)
];
const bed = [
new THREE.Color(0x586151),
new THREE.Color(0x62695a),
new THREE.Color(0x50594f)
];
const snow = new THREE.Color(0xe6ece7);
for (let i = 0; i < terrainGeometry.attributes.position.count; i += 3) {
const x =
(terrainGeometry.attributes.position.getX(i) +
terrainGeometry.attributes.position.getX(i + 1) +
terrainGeometry.attributes.position.getX(i + 2)) / 3;
const y =
(terrainGeometry.attributes.position.getY(i) +
terrainGeometry.attributes.position.getY(i + 1) +
terrainGeometry.attributes.position.getY(i + 2)) / 3;
const z =
(terrainGeometry.attributes.position.getZ(i) +
terrainGeometry.attributes.position.getZ(i + 1) +
terrainGeometry.attributes.position.getZ(i + 2)) / 3;
const r = lakeRadius(x, z);
const variation = random();
if (z > 4 && r < 1.05) {
color.copy(bed[Math.floor(variation * bed.length)]);
} else if (Math.abs(x - valleyCenter(z)) < 6.7 && z < 4) {
color.copy(bed[Math.floor(variation * bed.length)]).lerp(rock[1], 0.28);
} else if (y > 10) {
color.copy(rock[Math.floor(variation * rock.length)]);
const snowAmount =
smoothstep(15, 23, y) * (z < -2 ? 0.86 : 0.17);
color.lerp(snow, snowAmount);
} else {
color.copy(grass[Math.floor(variation * grass.length)]);
color.lerp(rock[0], smoothstep(5, 11, y) * 0.62);
}
color.offsetHSL(0, 0, (random() - 0.5) * 0.055);
for (let j = 0; j < 3; j++) {
terrainColors.push(color.r, color.g, color.b);
}
}
terrainGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(terrainColors, 3)
);
terrainGeometry.computeVertexNormals();
const terrainMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
flatShading: true,
roughness: 0.96,
metalness: 0
});
const terrain = new THREE.Mesh(terrainGeometry, terrainMaterial);
terrain.castShadow = true;
terrain.receiveShadow = true;
scene.add(terrain);
// -------------------------------------------------------------------------
// Bounded cutaway sides and base
// -------------------------------------------------------------------------
const sidePositions = [];
const sideColors = [];
const upperSide = new THREE.Color(0x4b5350);
const lowerSide = new THREE.Color(0x303937);
const sideBaseY = -6;
const sideMidY = -3.15;
function addSideQuad(a, b, c, d, ca, cb, cc, cd) {
const verts = [a, b, c, a, c, d];
const cols = [ca, cb, cc, ca, cc, cd];
for (let i = 0; i < verts.length; i++) {
sidePositions.push(...verts[i]);
sideColors.push(cols[i].r, cols[i].g, cols[i].b);
}
}
// Front and back.
for (let c = 0; c < cols - 1; c++) {
const x0 = minX + (maxX - minX) * c / (cols - 1);
const x1 = minX + (maxX - minX) * (c + 1) / (cols - 1);
const frontTop0 = heightGrid[rows - 1][c];
const frontTop1 = heightGrid[rows - 1][c + 1];
addSideQuad(
[x0, frontTop0, maxZ], [x1, frontTop1, maxZ],
[x1, sideMidY, maxZ], [x0, sideMidY, maxZ],
upperSide, upperSide, lowerSide, lowerSide
);
addSideQuad(
[x0, sideMidY, maxZ], [x1, sideMidY, maxZ],
[x1, sideBaseY, maxZ], [x0, sideBaseY, maxZ],
lowerSide, lowerSide, lowerSide, lowerSide
);
const backTop0 = heightGrid[0][c];
const backTop1 = heightGrid[0][c + 1];
addSideQuad(
[x1, backTop1, minZ], [x0, backTop0, minZ],
[x0, sideMidY, minZ], [x1, sideMidY, minZ],
upperSide, upperSide, lowerSide, lowerSide
);
addSideQuad(
[x1, sideMidY, minZ], [x0, sideMidY, minZ],
[x0, sideBaseY, minZ], [x1, sideBaseY, minZ],
lowerSide, lowerSide, lowerSide, lowerSide
);
}
// Left and right.
for (let r = 0; r < rows - 1; r++) {
const z0 = minZ + (maxZ - minZ) * r / (rows - 1);
const z1 = minZ + (maxZ - minZ) * (r + 1) / (rows - 1);
const leftTop0 = heightGrid[r][0];
const leftTop1 = heightGrid[r + 1][0];
const rightTop0 = heightGrid[r][cols - 1];
const rightTop1 = heightGrid[r + 1][cols - 1];
addSideQuad(
[minX, leftTop1, z1], [minX, leftTop0, z0],
[minX, sideMidY, z0], [minX, sideMidY, z1],
upperSide, upperSide, lowerSide, lowerSide
);
addSideQuad(
[minX, sideMidY, z1], [minX, sideMidY, z0],
[minX, sideBaseY, z0], [minX, sideBaseY, z1],
lowerSide, lowerSide, lowerSide, lowerSide
);
addSideQuad(
[maxX, rightTop0, z0], [maxX, rightTop1, z1],
[maxX, sideMidY, z1], [maxX, sideMidY, z0],
upperSide, upperSide, lowerSide, lowerSide
);
addSideQuad(
[maxX, sideMidY, z0], [maxX, sideMidY, z1],
[maxX, sideBaseY, z1], [maxX, sideBaseY, z0],
lowerSide, lowerSide, lowerSide, lowerSide
);
}
const sideGeometry = new THREE.BufferGeometry();
sideGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(sidePositions, 3)
);
sideGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(sideColors, 3)
);
sideGeometry.computeVertexNormals();
const sides = new THREE.Mesh(
sideGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
flatShading: true,
roughness: 1,
side: THREE.DoubleSide
})
);
sides.castShadow = true;
sides.receiveShadow = true;
scene.add(sides);
// A subtle rim makes the bounded transect legible.
const rimPoints = [];
for (let c = 0; c < cols; c++) {
const x = minX + (maxX - minX) * c / (cols - 1);
rimPoints.push(new THREE.Vector3(x, heightGrid[rows - 1][c] + 0.03, maxZ));
}
for (let r = rows - 2; r >= 0; r--) {
const z = minZ + (maxZ - minZ) * r / (rows - 1);
rimPoints.push(new THREE.Vector3(maxX, heightGrid[r][cols - 1] + 0.03, z));
}
for (let c = cols - 2; c >= 0; c--) {
const x = minX + (maxX - minX) * c / (cols - 1);
rimPoints.push(new THREE.Vector3(x, heightGrid[0][c] + 0.03, minZ));
}
for (let r = 1; r < rows; r++) {
const z = minZ + (maxZ - minZ) * r / (rows - 1);
rimPoints.push(new THREE.Vector3(minX, heightGrid[r][0] + 0.03, z));
}
const rim = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(rimPoints),
new THREE.LineBasicMaterial({
color: 0xa8b3ad,
transparent: true,
opacity: 0.55
})
);
scene.add(rim);
// -------------------------------------------------------------------------
// Glacier tongue
// -------------------------------------------------------------------------
function glacierWidth(z) {
const t = clamp((z + 24) / 28, 0, 1);
return 3.55 + 2.8 * smoothstep(0.58, 1, t);
}
function glacierHeight(x, z) {
return (
floorElevation(z) +
0.12 +
0.055 * Math.sin(z * 1.7 + x * 0.35)
);
}
const glacierRows = 25;
const glacierCols = 3;
const glacierPositions = [];
const glacierIndices = [];
for (let r = 0; r < glacierRows; r++) {
const z = -24 + 28 * r / (glacierRows - 1);
const center = valleyCenter(z);
const width = glacierWidth(z);
for (let c = 0; c < glacierCols; c++) {
const offset = (c - 1) * width;
const x = center + offset;
const crown = c === 1 ? 0.08 : 0;
glacierPositions.push(x, glacierHeight(x, z) + crown, z);
}
}
for (let r = 0; r < glacierRows - 1; r++) {
for (let c = 0; c < glacierCols - 1; c++) {
const a = r * glacierCols + c;
const b = a + 1;
const d = (r + 1) * glacierCols + c;
const cNext = d + 1;
glacierIndices.push(a, d, b, b, d, cNext);
}
}
let glacierGeometry = new THREE.BufferGeometry();
glacierGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(glacierPositions, 3)
);
glacierGeometry.setIndex(glacierIndices);
glacierGeometry = glacierGeometry.toNonIndexed();
const glacierColors = [];
const glacierPalette = [
new THREE.Color(0xb8dadd),
new THREE.Color(0xd9ece8),
new THREE.Color(0xeaf2ec),
new THREE.Color(0xa9d0d6)
];
for (let i = 0; i < glacierGeometry.attributes.position.count; i += 3) {
const c = glacierPalette[Math.floor(random() * glacierPalette.length)];
for (let j = 0; j < 3; j++) {
glacierColors.push(c.r, c.g, c.b);
}
}
glacierGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(glacierColors, 3)
);
glacierGeometry.computeVertexNormals();
const glacier = new THREE.Mesh(
glacierGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
flatShading: true,
roughness: 0.62,
metalness: 0.02
})
);
glacier.castShadow = true;
glacier.receiveShadow = true;
scene.add(glacier);
// Vertical ice face at the lake-facing terminus.
const terminusZ = 4;
const terminusCenter = valleyCenter(terminusZ);
const terminusWidth = glacierWidth(terminusZ);
const terminusTop = glacierHeight(terminusCenter, terminusZ);
const terminusGeometry = new THREE.BufferGeometry();
terminusGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
terminusCenter - terminusWidth, terminusTop, terminusZ,
terminusCenter + terminusWidth, terminusTop, terminusZ,
terminusCenter + terminusWidth * 0.92, -0.25, terminusZ,
terminusCenter - terminusWidth, terminusTop, terminusZ,
terminusCenter + terminusWidth * 0.92, -0.25, terminusZ,
terminusCenter - terminusWidth * 0.92, -0.25, terminusZ
], 3)
);
terminusGeometry.computeVertexNormals();
const terminus = new THREE.Mesh(
terminusGeometry,
new THREE.MeshStandardMaterial({
color: 0x9bcbd1,
flatShading: true,
roughness: 0.6,
side: THREE.DoubleSide
})
);
terminus.castShadow = true;
scene.add(terminus);
// Transverse crevasses, merged into one low-poly overlay.
const crevassePositions = [];
const crevasseLevels = [-18.4, -15.3, -12.3, -9.4, -6.5, -3.5];
const fractions = [-0.88, -0.58, -0.23, 0.18, 0.55, 0.86];
for (const z of crevasseLevels) {
for (let s = 0; s < fractions.length - 1; s++) {
const f0 = fractions[s];
const f1 = fractions[s + 1] - 0.035;
const z0 = z + Math.sin(s * 2.1 + z) * 0.22;
const z1 = z0 + 0.18 + random() * 0.13;
const width0 = glacierWidth(z0);
const width1 = glacierWidth(z1);
const center = valleyCenter(z);
const x0 = center + f0 * width0;
const x1 = center + f1 * width0;
const x2 = center + f1 * width1;
const x3 = center + f0 * width1;
crevassePositions.push(
x0, glacierHeight(x0, z0) + 0.035, z0,
x1, glacierHeight(x1, z0) + 0.035, z0,
x2, glacierHeight(x2, z1) + 0.035, z1,
x0, glacierHeight(x0, z0) + 0.035, z0,
x2, glacierHeight(x2, z1) + 0.035, z1,
x3, glacierHeight(x3, z1) + 0.035, z1
);
}
}
const crevasseGeometry = new THREE.BufferGeometry();
crevasseGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(crevassePositions, 3)
);
crevasseGeometry.computeVertexNormals();
const crevasses = new THREE.Mesh(
crevasseGeometry,
new THREE.MeshBasicMaterial({
color: 0x397f92,
transparent: true,
opacity: 0.78,
side: THREE.DoubleSide
})
);
scene.add(crevasses);
// -------------------------------------------------------------------------
// Low-poly meltwater lake
// -------------------------------------------------------------------------
const waterLevel = 0.16;
const lakeCenterZ = 13;
const lakePositions = [];
const lakeRings = 18;
const lakeOutline = [];
for (let i = 0; i < lakeRings; i++) {
const angle = i / lakeRings * Math.PI * 2;
const radialVariation =
0.94 +
0.055 * Math.sin(angle * 3 + 0.4) +
0.035 * Math.sin(angle * 5 - 0.7);
lakeOutline.push({
x: Math.cos(angle) * 11.3 * radialVariation,
z: lakeCenterZ + Math.sin(angle) * 10.4 * radialVariation
});
}
for (let i = 0; i < lakeRings; i++) {
const a = lakeOutline[i];
const b = lakeOutline[(i + 1) % lakeRings];
lakePositions.push(
0, waterLevel, lakeCenterZ,
a.x, waterLevel, a.z,
b.x, waterLevel, b.z
);
}
const lakeGeometry = new THREE.BufferGeometry();
lakeGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(lakePositions, 3)
);
lakeGeometry.computeVertexNormals();
const lake = new THREE.Mesh(
lakeGeometry,
new THREE.MeshPhysicalMaterial({
color: 0x48a9ad,
roughness: 0.22,
metalness: 0.03,
transparent: true,
opacity: 0.9,
flatShading: true,
side: THREE.DoubleSide,
clearcoat: 0.28,
clearcoatRoughness: 0.32
})
);
lake.receiveShadow = true;
scene.add(lake);
// Small angular ice fragments near the calving front.
const iceFragmentGeometry = new THREE.IcosahedronGeometry(1, 0);
const iceFragmentMaterial = new THREE.MeshStandardMaterial({
color: 0xdcece7,
roughness: 0.55,
flatShading: true
});
for (let i = 0; i < 9; i++) {
const fragment = new THREE.Mesh(iceFragmentGeometry, iceFragmentMaterial);
const x = (random() - 0.5) * 10;
const z = 5 + random() * 8;
const scale = 0.22 + random() * 0.48;
fragment.position.set(x, waterLevel + scale * 0.32, z);
fragment.scale.set(scale * (0.8 + random()), scale * 0.55, scale);
fragment.rotation.set(random(), random() * Math.PI, random());
fragment.castShadow = true;
scene.add(fragment);
}
// -------------------------------------------------------------------------
// Proglacial meltwater channel
// -------------------------------------------------------------------------
const streamCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(6.0, 0, -5.0),
new THREE.Vector3(6.4, 0, -2.0),
new THREE.Vector3(6.2, 0, 0.5),
new THREE.Vector3(5.4, 0, 3.2),
new THREE.Vector3(4.2, 0, 5.2),
new THREE.Vector3(3.0, 0, 7.5)
],
false,
"catmullrom",
0.35
);
const streamPoints = streamCurve.getPoints(44);
const streamPositions = [];
for (let i = 0; i < streamPoints.length - 1; i++) {
const p = streamPoints[i];
const q = streamPoints[i + 1];
const dx = q.x - p.x;
const dz = q.z - p.z;
const length = Math.hypot(dx, dz) || 1;
const nx = -dz / length;
const nz = dx / length;
const width = 0.34 + 0.22 * Math.sin(i * 0.38);
const y0 = p.z > 3.5
? waterLevel + 0.026
: terrainHeight(p.x, p.z) + 0.075;
const y1 = q.z > 3.5
? waterLevel + 0.026
: terrainHeight(q.x, q.z) + 0.075;
streamPositions.push(
p.x - nx * width, y0, p.z - nz * width,
p.x + nx * width, y0, p.z + nz * width,
q.x + nx * width, y1, q.z + nz * width,
p.x - nx * width, y0, p.z - nz * width,
q.x + nx * width, y1, q.z + nz * width,
q.x - nx * width, y1, q.z - nz * width
);
}
const streamGeometry = new THREE.BufferGeometry();
streamGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(streamPositions, 3)
);
streamGeometry.computeVertexNormals();
const stream = new THREE.Mesh(
streamGeometry,
new THREE.MeshPhysicalMaterial({
color: 0x4fc0bd,
roughness: 0.18,
transparent: true,
opacity: 0.92,
side: THREE.DoubleSide
})
);
stream.receiveShadow = true;
scene.add(stream);
// -------------------------------------------------------------------------
// Curving lateral / terminal moraine ridge
// -------------------------------------------------------------------------
const moraineCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(9.0, 0, -13),
new THREE.Vector3(9.5, 0, -9),
new THREE.Vector3(9.0, 0, -5),
new THREE.Vector3(8.5, 0, -1),
new THREE.Vector3(8.8, 0, 3.5),
new THREE.Vector3(10.3, 0, 7.5),
new THREE.Vector3(11.0, 0, 13),
new THREE.Vector3(9.5, 0, 18),
new THREE.Vector3(6.0, 0, 21.5)
],
false,
"catmullrom",
0.32
);
const moraineSamples = moraineCurve.getPoints(70);
const morainePositions = [];
const moraineColors = [];
const moraineDark = new THREE.Color(0x655747);
const moraineLight = new THREE.Color(0x8b755b);
const moraineRows = [];
for (let i = 0; i < moraineSamples.length; i++) {
const p = moraineSamples[i];
const prev = moraineSamples[Math.max(0, i - 1)];
const next = moraineSamples[Math.min(moraineSamples.length - 1, i + 1)];
const dx = next.x - prev.x;
const dz = next.z - prev.z;
const length = Math.hypot(dx, dz) || 1;
const nx = -dz / length;
const nz = dx / length;
const halfWidth = 1.35 + 0.18 * Math.sin(i * 0.31);
const leftX = p.x + nx * halfWidth;
const leftZ = p.z + nz * halfWidth;
const rightX = p.x - nx * halfWidth;
const rightZ = p.z - nz * halfWidth;
const leftY = terrainHeight(leftX, leftZ) + 0.025;
const rightY = terrainHeight(rightX, rightZ) + 0.025;
const crestY =
terrainHeight(p.x, p.z) +
1.05 +
0.15 * Math.sin(i * 0.46);
moraineRows.push([
[leftX, leftY, leftZ],
[p.x, crestY, p.z],
[rightX, rightY, rightZ]
]);
}
function pushMoraineTriangle(a, b, c, shade) {
morainePositions.push(...a, ...b, ...c);
const col = moraineDark.clone().lerp(moraineLight, shade);
for (let j = 0; j < 3; j++) {
moraineColors.push(col.r, col.g, col.b);
}
}
for (let i = 0; i < moraineRows.length - 1; i++) {
const a = moraineRows[i];
const b = moraineRows[i + 1];
pushMoraineTriangle(a[0], b[0], a[1], 0.1);
pushMoraineTriangle(b[0], b[1], a[1], 0.48);
pushMoraineTriangle(a[1], b[1], a[2], 0.48);
pushMoraineTriangle(b[1], b[2], a[2], 0.08);
}
const moraineGeometry = new THREE.BufferGeometry();
moraineGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(morainePositions, 3)
);
moraineGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(moraineColors, 3)
);
moraineGeometry.computeVertexNormals();
const moraine = new THREE.Mesh(
moraineGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
flatShading: true,
roughness: 1
})
);
moraine.castShadow = true;
moraine.receiveShadow = true;
scene.add(moraine);
// Angular boulders scattered along the moraine crest.
const boulderGeometry = new THREE.DodecahedronGeometry(0.58, 0);
const boulderMaterial = new THREE.MeshStandardMaterial({
color: 0x796957,
roughness: 1,
flatShading: true
});
const boulderCount = 48;
const boulders = new THREE.InstancedMesh(
boulderGeometry,
boulderMaterial,
boulderCount
);
boulders.castShadow = true;
boulders.receiveShadow = true;
const dummy = new THREE.Object3D();
for (let i = 0; i < boulderCount; i++) {
const t = random();
const p = moraineCurve.getPoint(t);
const tangent = moraineCurve.getTangent(t);
const offset = (random() - 0.5) * 1.35;
const x = p.x - tangent.z * offset;
const z = p.z + tangent.x * offset;
const scale = 0.32 + random() * 0.68;
dummy.position.set(
x,
terrainHeight(x, z) + 0.48 + scale * 0.35,
z
);
dummy.rotation.set(random() * 2, random() * 2, random() * 2);
dummy.scale.set(
scale * (0.75 + random() * 0.5),
scale * (0.65 + random() * 0.4),
scale * (0.8 + random() * 0.5)
);
dummy.updateMatrix();
boulders.setMatrixAt(i, dummy.matrix);
const boulderColor = new THREE.Color(0x776857).offsetHSL(
0,
(random() - 0.5) * 0.05,
(random() - 0.5) * 0.12
);
boulders.setColorAt(i, boulderColor);
}
boulders.instanceMatrix.needsUpdate = true;
if (boulders.instanceColor) boulders.instanceColor.needsUpdate = true;
scene.add(boulders);
// -------------------------------------------------------------------------
// Ground receiving the diorama's shadow
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(220, 220),
new THREE.MeshStandardMaterial({
color: 0xc7d4cf,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -6.06;
ground.receiveShadow = true;
scene.add(ground);
// -------------------------------------------------------------------------
// Direct camera controls: orbit, zoom, pan, keyboard, touch
// -------------------------------------------------------------------------
const defaultView = {
target: new THREE.Vector3(0, 5.0, -2),
theta: 0.52,
phi: 1.02,
radius: 70
};
const desired = {
target: defaultView.target.clone(),
theta: defaultView.theta,
phi: defaultView.phi,
radius: defaultView.radius
};
const current = {
target: defaultView.target.clone(),
theta: defaultView.theta,
phi: defaultView.phi,
radius: defaultView.radius
};
function resetView() {
desired.target.copy(defaultView.target);
desired.theta = defaultView.theta;
desired.phi = defaultView.phi;
desired.radius = defaultView.radius;
}
function applyCamera() {
const sinPhi = Math.sin(current.phi);
camera.position.set(
current.target.x + current.radius * sinPhi * Math.sin(current.theta),
current.target.y + current.radius * Math.cos(current.phi),
current.target.z + current.radius * sinPhi * Math.cos(current.theta)
);
camera.lookAt(current.target);
camera.updateMatrixWorld();
}
let dragging = false;
let pointerId = null;
let lastX = 0;
let lastY = 0;
let activeButton = 0;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerId = event.pointerId;
activeButton = event.button;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(pointerId);
event.preventDefault();
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
const panning = event.shiftKey || activeButton === 2;
if (panning) {
const scale = desired.radius * 0.00115;
const right = new THREE.Vector3(
Math.cos(desired.theta),
0,
-Math.sin(desired.theta)
);
const forward = new THREE.Vector3(
-Math.sin(desired.theta),
0,
-Math.cos(desired.theta)
);
desired.target.addScaledVector(right, -dx * scale);
desired.target.addScaledVector(forward, dy * scale);
desired.target.x = clamp(desired.target.x, -18, 18);
desired.target.z = clamp(desired.target.z, -24, 24);
} else {
desired.theta -= dx * 0.0055;
desired.phi = clamp(desired.phi + dy * 0.0045, 0.48, 1.38);
}
});
function endDrag(event) {
if (pointerId !== null && canvas.hasPointerCapture(pointerId)) {
canvas.releasePointerCapture(pointerId);
}
dragging = false;
pointerId = null;
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
36,
105
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
document.getElementById("reset-view").addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
const step = 0.08;
if (event.key === "ArrowLeft") desired.theta += step;
if (event.key === "ArrowRight") desired.theta -= step;
if (event.key === "ArrowUp") desired.phi = clamp(desired.phi - step, 0.48, 1.38);
if (event.key === "ArrowDown") desired.phi = clamp(desired.phi + step, 0.48, 1.38);
if (event.key === "+" || event.key === "=") {
desired.radius = clamp(desired.radius - 4, 36, 105);
}
if (event.key === "-" || event.key === "_") {
desired.radius = clamp(desired.radius + 4, 36, 105);
}
if (event.key.toLowerCase() === "r") resetView();
});
// -------------------------------------------------------------------------
// Projected map labels
// -------------------------------------------------------------------------
const labelData = [
{
element: document.getElementById("label-glacier"),
point: new THREE.Vector3(-1.0, 9.2, -13.5)
},
{
element: document.getElementById("label-lake"),
point: new THREE.Vector3(-1.5, waterLevel, 15.0)
},
{
element: document.getElementById("label-moraine"),
point: new THREE.Vector3(9.0, terrainHeight(9, -1) + 1.5, -1.0)
},
{
element: document.getElementById("label-melt"),
point: new THREE.Vector3(6.2, terrainHeight(6.2, 0.5) + 0.4, 0.5)
},
{
element: document.getElementById("label-wall"),
point: new THREE.Vector3(14.2, terrainHeight(14.2, -10) + 0.4, -10)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labelData) {
projected.copy(label.point).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.12 &&
projected.x < 1.12 &&
projected.y > -1.12 &&
projected.y < 1.12;
label.element.classList.toggle("visible", visible);
if (visible) {
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.transform = `translate(${x}px, ${y}px)`;
}
}
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
renderer.setAnimationLoop(() => {
const smoothing = 0.11;
current.theta += (desired.theta - current.theta) * smoothing;
current.phi += (desired.phi - current.phi) * smoothing;
current.radius += (desired.radius - current.radius) * smoothing;
current.target.lerp(desired.target, smoothing);
applyCamera();
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```