Prompt specification
Build or customize the Three.js 3D scene "Himalayan valley from forest to alpine terrain" 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: Himalayan valley from forest to alpine terrain
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/himalayan-valley-from-forest-to-alpine-terrain-x3083
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows Himalayan valleys and elevation zones. Build a bounded landscape transect showing referenced elevation zones, river, settlement, and high pass. Label vertical exaggeration and distinguish broad patterns from exact ecological boundaries. Low-poly.
Working Three.js Starter (himalayan-valley-from-forest-to-alpine-terrain-x3083):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Himalayan Elevation Transect</title>
<style>
:root {
--ink: #172724;
--muted: #5f706b;
--paper: rgba(247, 249, 245, 0.92);
--line: rgba(38, 65, 57, 0.16);
--accent: #cf6944;
--river: #1f8794;
--pass: #9b663b;
--shadow: 0 14px 38px rgba(25, 46, 40, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce7e3;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
summary {
font: inherit;
}
#app {
position: relative;
width: 100%;
height: 100%;
isolation: isolate;
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
#scene:active {
cursor: grabbing;
}
#labels {
position: absolute;
inset: 0;
z-index: 2;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
display: flex;
flex-direction: column;
gap: 2px;
min-width: 92px;
max-width: 190px;
padding: 7px 9px 8px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 8px;
background: rgba(250, 251, 247, 0.88);
box-shadow: 0 5px 16px rgba(27, 44, 39, 0.14);
transform: translate(-50%, -100%);
transition: opacity 150ms ease;
backdrop-filter: blur(6px);
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -15px;
width: 1px;
height: 14px;
background: rgba(38, 57, 51, 0.58);
}
.world-label::before {
content: "";
position: absolute;
left: calc(50% - 3px);
bottom: -18px;
width: 6px;
height: 6px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 50%;
background: #263d35;
}
.world-label .label-title {
font-size: 10px;
font-weight: 800;
line-height: 1.12;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.world-label .label-sub {
font-size: 10px;
line-height: 1.2;
color: var(--muted);
}
.world-label.river {
border-color: rgba(31, 135, 148, 0.3);
background: rgba(237, 250, 250, 0.91);
}
.world-label.river .label-title {
color: #176c77;
}
.world-label.settlement {
border-color: rgba(207, 105, 68, 0.35);
background: rgba(255, 247, 240, 0.92);
}
.world-label.settlement .label-title {
color: #a64e30;
}
.world-label.pass {
border-color: rgba(155, 102, 59, 0.4);
background: rgba(251, 246, 237, 0.94);
}
.world-label.pass .label-title {
color: #82532e;
}
.world-label.minor {
min-width: 0;
padding: 5px 7px;
border-radius: 6px;
background: rgba(250, 251, 247, 0.78);
box-shadow: 0 3px 10px rgba(27, 44, 39, 0.09);
}
.world-label.minor::before,
.world-label.minor::after {
display: none;
}
.panel {
position: absolute;
z-index: 4;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 13px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
}
.title-card {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 18px 20px 16px;
}
.eyebrow {
margin-bottom: 7px;
color: #63756d;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
max-width: 340px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(27px, 3vw, 39px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
margin: 12px 0 14px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.metrics {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
.metric {
padding: 6px 8px;
border: 1px solid var(--line);
border-radius: 6px;
background: rgba(255, 255, 255, 0.48);
color: #42564f;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.035em;
}
.metric.exaggeration {
border-color: rgba(207, 105, 68, 0.34);
background: rgba(207, 105, 68, 0.1);
color: #934b32;
}
.legend {
bottom: 22px;
left: 22px;
width: min(305px, calc(100vw - 44px));
padding: 16px 17px 14px;
}
.panel-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
margin-bottom: 10px;
}
.panel-heading h2 {
margin: 0;
font-size: 13px;
letter-spacing: 0.025em;
}
.panel-heading span {
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.zone-list {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 6px 12px;
}
.zone {
display: grid;
grid-template-columns: 11px 1fr;
align-items: center;
gap: 7px;
min-width: 0;
}
.swatch {
width: 11px;
height: 11px;
border: 1px solid rgba(24, 42, 35, 0.13);
border-radius: 3px;
}
.zone-text {
min-width: 0;
font-size: 10px;
line-height: 1.15;
}
.zone-text b {
display: block;
font-weight: 750;
}
.zone-text span {
color: var(--muted);
font-size: 9px;
}
.legend-note {
margin: 12px 0 0;
padding-top: 10px;
border-top: 1px solid var(--line);
color: #68766f;
font-size: 9.5px;
line-height: 1.45;
}
.legend-note strong {
color: #40574e;
}
.reading {
top: 22px;
right: 22px;
width: min(315px, calc(100vw - 44px));
padding: 14px 15px 15px;
}
.reading summary {
display: flex;
align-items: center;
justify-content: space-between;
cursor: pointer;
list-style: none;
color: #30493f;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.025em;
}
.reading summary::-webkit-details-marker {
display: none;
}
.reading summary::after {
content: "+";
color: #7b8c84;
font-size: 17px;
font-weight: 400;
}
.reading[open] summary::after {
content: "−";
}
.reading-body {
margin-top: 12px;
color: #53665e;
font-size: 10px;
line-height: 1.48;
}
.caveat {
margin-bottom: 11px;
padding: 9px 10px;
border-left: 3px solid var(--accent);
border-radius: 0 6px 6px 0;
background: rgba(207, 105, 68, 0.085);
color: #694a3d;
}
.caveat strong {
color: #8b4931;
}
.reading-body h3 {
margin: 11px 0 4px;
color: #344d43;
font-size: 9px;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.reading-body p {
margin: 0 0 8px;
}
.reading-body ul {
margin: 0;
padding-left: 16px;
}
.reading-body li {
margin-bottom: 4px;
}
.reading-body a {
color: #2d6f69;
text-decoration-color: rgba(45, 111, 105, 0.35);
text-underline-offset: 2px;
}
.controls {
position: absolute;
right: 22px;
bottom: 22px;
z-index: 5;
display: flex;
align-items: center;
gap: 7px;
}
.control-button {
min-height: 34px;
padding: 8px 11px;
border: 1px solid rgba(40, 63, 54, 0.18);
border-radius: 8px;
background: rgba(250, 251, 247, 0.9);
color: #354d43;
box-shadow: 0 6px 18px rgba(26, 45, 39, 0.12);
cursor: pointer;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.025em;
backdrop-filter: blur(8px);
}
.control-button:hover {
background: #fff;
border-color: rgba(40, 63, 54, 0.34);
}
.control-button[aria-pressed="false"] {
opacity: 0.62;
}
.hint {
position: absolute;
right: 23px;
bottom: 65px;
z-index: 3;
color: rgba(41, 63, 55, 0.74);
font-size: 9px;
font-weight: 650;
letter-spacing: 0.025em;
text-align: right;
text-shadow: 0 1px 3px rgba(255, 255, 255, 0.9);
}
.loading {
position: absolute;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #dce7e3;
color: #52665e;
font-size: 11px;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 950px) {
.reading {
top: auto;
bottom: 72px;
right: 16px;
width: 285px;
}
.reading:not([open]) {
width: auto;
}
.legend {
left: 16px;
bottom: 16px;
}
.title-card {
top: 16px;
left: 16px;
}
.controls {
right: 16px;
bottom: 16px;
}
.hint {
display: none;
}
}
@media (max-width: 640px) {
.title-card {
width: calc(100vw - 32px);
padding: 14px 16px;
}
h1 {
font-size: 28px;
}
.subtitle {
margin: 8px 0 10px;
}
.legend {
width: calc(100vw - 32px);
padding: 12px 14px;
}
.zone-list {
grid-template-columns: repeat(3, 1fr);
gap: 5px 8px;
}
.zone-text {
font-size: 8px;
}
.zone-text span {
font-size: 8px;
}
.legend-note {
margin-top: 8px;
padding-top: 8px;
}
.reading {
bottom: 228px;
left: 16px;
right: auto;
width: calc(100vw - 32px);
max-height: 42vh;
overflow: auto;
}
.controls {
left: 16px;
right: auto;
}
.world-label:not(.feature):not(.minor) {
display: none;
}
}
</style>
</head>
<body>
<main id="app">
<canvas
id="scene"
tabindex="0"
aria-label="Interactive low-poly Himalayan elevation transect with a river, settlement, and high pass"
></canvas>
<div id="labels" aria-hidden="true"></div>
<header class="panel title-card">
<div class="eyebrow">Illustrative Himalayan transect · south → north</div>
<h1>From river valley to high pass</h1>
<p class="subtitle">
A bounded, low-poly terrain profile linking broad elevation envelopes
with a glacial-fed river, a valley settlement, and a high-pass crossing.
</p>
<div class="metrics">
<span class="metric">60 km transect</span>
<span class="metric">30 km depth</span>
<span class="metric">7 elevation zones</span>
<span class="metric exaggeration">Vertical exaggeration ×2.0</span>
</div>
</header>
<section class="panel legend" aria-label="Elevation zone legend">
<div class="panel-heading">
<h2>Broad elevation envelopes</h2>
<span>Approx. m a.s.l.</span>
</div>
<div class="zone-list">
<div class="zone">
<i class="swatch" style="background:#496b50"></i>
<div class="zone-text"><b>Lower valley</b><span>500–1,000</span></div>
</div>
<div class="zone">
<i class="swatch" style="background:#678457"></i>
<div class="zone-text"><b>Lower montane</b><span>1,000–1,800</span></div>
</div>
<div class="zone">
<i class="swatch" style="background:#89965a"></i>
<div class="zone-text"><b>Upper montane</b><span>1,800–2,800</span></div>
</div>
<div class="zone">
<i class="swatch" style="background:#a29b63"></i>
<div class="zone-text"><b>Subalpine</b><span>2,800–3,600</span></div>
</div>
<div class="zone">
<i class="swatch" style="background:#ad9675"></i>
<div class="zone-text"><b>Alpine</b><span>3,600–4,500</span></div>
</div>
<div class="zone">
<i class="swatch" style="background:#c6b9a3"></i>
<div class="zone-text"><b>Nival</b><span>4,500–5,200</span></div>
</div>
<div class="zone">
<i class="swatch" style="background:#e7ece8"></i>
<div class="zone-text"><b>Snow / ice</b><span>above 5,200</span></div>
</div>
</div>
<p class="legend-note">
<strong>Broad pattern only.</strong> These are schematic elevation
envelopes, not exact ecological boundaries. Forestline, treeline,
alpine, and nival limits vary with aspect, moisture, geology, and disturbance.
</p>
</section>
<details class="panel reading" open>
<summary>How to read this model</summary>
<div class="reading-body">
<div class="caveat">
<strong>Pattern, not a boundary map.</strong>
Terrain colors are a teaching synthesis based mainly on elevation.
They do not identify a precise ecological or land-cover boundary.
</div>
<p>
The horizontal footprint is schematic. North is toward the high pass.
The river and settlement are illustrative rather than a surveyed place.
</p>
<h3>Model conventions</h3>
<ul>
<li>Horizontal scale: 1 scene unit = 0.5 km.</li>
<li>Vertical scale: 1 scene unit = 250 m.</li>
<li>Vertical exaggeration: <strong>×2.0</strong>.</li>
<li>River width, trees, buildings, and markers are enlarged for legibility.</li>
</ul>
<h3>Regional context references</h3>
<ul>
<li>
Dineris, R. (2002),
<a href="https://link.springer.com/book/10.1007/978-94-007-0064-3"
target="_blank" rel="noreferrer">
Mountain Ecosystem Development
</a>, Springer.
</li>
<li>
UNEP-WCMC (2010),
<a href="https://www.unep-wcmc.org/resources/assessment/mountain-biodiversity-assessment"
target="_blank" rel="noreferrer">
Mountain Biodiversity Assessment
</a>.
</li>
<li>
ICIMOD (2023),
<a href="https://www.icimod.org/himalayan-assessment-2023/"
target="_blank" rel="noreferrer">
Himalayan Assessment 2023
</a>.
</li>
</ul>
<p>
The numerical cutoffs in this display were selected for visual clarity;
they are not a formal vegetation classification. Consult local
vegetation, geological, and hazard maps for site-level decisions.
</p>
</div>
</details>
<div class="hint">Drag to orbit · Shift/right-drag to pan · Scroll to zoom</div>
<nav class="controls" aria-label="View controls">
<button class="control-button" id="resetView" type="button">Reset</button>
<button class="control-button" id="planView" type="button">Plan view</button>
<button class="control-button" id="toggleLabels" type="button" aria-pressed="true">
Labels
</button>
</nav>
<div class="loading" id="loading">Building Himalayan transect</div>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Application state
// ---------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const labelLayer = document.querySelector("#labels");
const loading = document.querySelector("#loading");
const WIDTH = 120;
const DEPTH = 60;
const X_MIN = -WIDTH / 2;
const X_MAX = WIDTH / 2;
const Z_MIN = -DEPTH / 2;
const Z_MAX = DEPTH / 2;
// Horizontal: 2 scene units per kilometre.
// Vertical: 1 scene unit per 250 m = 4 scene units per kilometre.
// Therefore the displayed vertical exaggeration is 4 / 2 = 2×.
const VERTICAL_EXAGGERATION = 2;
const METERS_PER_UNIT = 250;
const zones = [
{ max: 1000, color: 0x496b50, name: "Lower valley" },
{ max: 1800, color: 0x678457, name: "Lower montane" },
{ max: 2800, color: 0x89965a, name: "Upper montane" },
{ max: 3600, color: 0xa29b63, name: "Subalpine" },
{ max: 4500, color: 0xad9675, name: "Alpine" },
{ max: 5200, color: 0xc6b9a3, name: "Nival" },
{ max: Infinity, color: 0xe7ece8, name: "Snow / ice" }
];
function zoneForElevation(elevation) {
for (let i = 0; i < zones.length; i++) {
if (elevation < zones[i].max) return i;
}
return zones.length - 1;
}
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(20250308);
// ---------------------------------------------------------------------
// Renderer, scene, camera
// ---------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
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;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce7e3);
scene.fog = new THREE.Fog(0xdce7e3, 145, 285);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
450
);
const controls = {
theta: 0.78,
phi: 0.74,
radius: 164,
targetTheta: 0.78,
targetPhi: 0.74,
targetRadius: 164,
target: new THREE.Vector3(0, 7.5, 0)
};
function updateCamera() {
controls.theta += (controls.targetTheta - controls.theta) * 0.10;
controls.phi += (controls.targetPhi - controls.phi) * 0.10;
controls.radius += (controls.targetRadius - controls.radius) * 0.10;
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.cos(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.sin(controls.theta)
);
camera.lookAt(controls.target);
camera.updateMatrixWorld();
}
updateCamera();
// ---------------------------------------------------------------------
// Lighting
// ---------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xf4f6ef, 0x60716a, 1.65);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4dc, 2.55);
sun.position.set(-48, 88, 42);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -85;
sun.shadow.camera.right = 85;
sun.shadow.camera.top = 70;
sun.shadow.camera.bottom = -70;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 220;
sun.shadow.bias = -0.00045;
sun.shadow.normalBias = 0.035;
sun.target.position.set(0, 5, 0);
scene.add(sun);
scene.add(sun.target);
const rim = new THREE.DirectionalLight(0xc9e2e6, 0.65);
rim.position.set(65, 35, -70);
scene.add(rim);
// ---------------------------------------------------------------------
// Terrain field
// ---------------------------------------------------------------------
function valleyCenterZ(x) {
const t = (x - X_MIN) / WIDTH;
return (
2.7 * Math.sin(t * Math.PI * 2.05) +
1.15 * Math.sin(t * Math.PI * 4.2 + 0.4)
);
}
function elevationMeters(x, z) {
const t = THREE.MathUtils.clamp((x - X_MIN) / WIDTH, 0, 1);
const center = valleyCenterZ(x);
const distance = Math.abs(z - center);
const longitudinalFloor =
600 +
3900 * t +
120 * Math.sin(t * Math.PI);
const crossRange =
2550 * Math.pow(distance / 30, 1.31);
const shoulder =
430 *
Math.pow(distance / 30, 1.8) *
Math.pow(Math.sin((x + 60) * 0.055 + 1.2), 2);
const roughness =
(165 * Math.sin(x * 0.115 + z * 0.19) +
105 * Math.sin(x * 0.235 - z * 0.125 + 1.7)) *
(0.24 + 0.76 * Math.min(distance / 25, 1));
const passCut =
250 *
Math.exp(
-(
Math.pow(x - 42, 2) / 95 +
Math.pow(distance, 2) / 40
)
);
return Math.max(
240,
longitudinalFloor + crossRange + shoulder + roughness - passCut
);
}
function terrainY(x, z) {
return elevationMeters(x, z) / METERS_PER_UNIT;
}
const terrainGroup = new THREE.Group();
scene.add(terrainGroup);
function terrainColor(elevation) {
const zone = zones[zoneForElevation(elevation)];
const color = new THREE.Color(zone.color);
const hsl = {};
color.getHSL(hsl);
const lightness = THREE.MathUtils.clamp(
hsl.l * (0.93 + random() * 0.14),
0,
1
);
return color.setHSL(hsl.h, hsl.s, lightness);
}
function buildTerrain() {
const nx = 72;
const nz = 34;
const positions = [];
const colors = [];
function pushVertex(x, z) {
positions.push(x, terrainY(x, z), z);
}
function pushFace(a, b, c) {
const elevation =
(
elevationMeters(a[0], a[1]) +
elevationMeters(b[0], b[1]) +
elevationMeters(c[0], c[1])
) / 3;
const color = terrainColor(elevation);
pushVertex(a[0], a[1]);
pushVertex(b[0], b[1]);
pushVertex(c[0], c[1]);
for (let i = 0; i < 3; i++) {
colors.push(color.r, color.g, color.b);
}
}
for (let iz = 0; iz < nz; iz++) {
const z0 = Z_MIN + (iz / nz) * DEPTH;
const z1 = Z_MIN + ((iz + 1) / nz) * DEPTH;
for (let ix = 0; ix < nx; ix++) {
const x0 = X_MIN + (ix / nx) * WIDTH;
const x1 = X_MIN + ((ix + 1) / nx) * WIDTH;
const p00 = [x0, z0];
const p10 = [x1, z0];
const p01 = [x0, z1];
const p11 = [x1, z1];
// Counter-clockwise when viewed from above.
pushFace(p00, p01, p10);
pushFace(p10, p01, p11);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
flatShading: true,
roughness: 0.97,
metalness: 0
});
const terrain = new THREE.Mesh(geometry, material);
terrain.castShadow = true;
terrain.receiveShadow = true;
terrainGroup.add(terrain);
}
buildTerrain();
// ---------------------------------------------------------------------
// Stratified cut edges and base
// ---------------------------------------------------------------------
function buildStratifiedEdges() {
const perimeter = [];
for (let i = 0; i <= 72; i++) {
perimeter.push([X_MIN + (i / 72) * WIDTH, Z_MIN]);
}
for (let i = 1; i <= 34; i++) {
perimeter.push([X_MAX, Z_MIN + (i / 34) * DEPTH]);
}
for (let i = 1; i <= 72; i++) {
perimeter.push([X_MAX - (i / 72) * WIDTH, Z_MAX]);
}
for (let i = 1; i < 34; i++) {
perimeter.push([X_MIN, Z_MAX - (i / 34) * DEPTH]);
}
const positions = [];
const colors = [];
const levels = [0, 1000, 2000, 3000, 4000, 5000, 6000, 7000];
const strataColors = [
0x4e453d,
0x675044,
0x80644f,
0x756557,
0x68706c,
0x9a9e99,
0xd7dcd8
];
function addVertex(x, y, z, color) {
positions.push(x, y, z);
colors.push(color.r, color.g, color.b);
}
for (let i = 0; i < perimeter.length; i++) {
const p0 = perimeter[i];
const p1 = perimeter[(i + 1) % perimeter.length];
const top0 = terrainY(p0[0], p0[1]);
const top1 = terrainY(p1[0], p1[1]);
for (let band = 0; band < levels.length - 1; band++) {
const low = levels[band] / METERS_PER_UNIT;
const high = levels[band + 1] / METERS_PER_UNIT;
const high0 = Math.min(high, top0);
const high1 = Math.min(high, top1);
if (high0 <= low || high1 <= low) continue;
const color = new THREE.Color(strataColors[band]);
const hsl = {};
color.getHSL(hsl);
color.setHSL(
hsl.h,
hsl.s,
THREE.MathUtils.clamp(hsl.l * (0.93 + random() * 0.13), 0, 1)
);
addVertex(p0[0], low, p0[1], color);
addVertex(p1[0], low, p1[1], color);
addVertex(p1[0], high1, p1[1], color);
addVertex(p0[0], low, p0[1], color);
addVertex(p1[0], high1, p1[1], color);
addVertex(p0[0], high0, p0[1], color);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
flatShading: true,
roughness: 1,
side: THREE.DoubleSide
});
const edges = new THREE.Mesh(geometry, material);
edges.castShadow = true;
edges.receiveShadow = true;
terrainGroup.add(edges);
const rimPoints = perimeter.map(([x, z]) =>
new THREE.Vector3(x, terrainY(x, z) + 0.035, z)
);
const rimGeometry = new THREE.BufferGeometry().setFromPoints(rimPoints);
const rim = new THREE.LineLoop(
rimGeometry,
new THREE.LineBasicMaterial({
color: 0xf2f4ec,
transparent: true,
opacity: 0.52
})
);
terrainGroup.add(rim);
}
buildStratifiedEdges();
const base = new THREE.Mesh(
new THREE.BoxGeometry(WIDTH + 0.8, 1, DEPTH + 0.8),
new THREE.MeshStandardMaterial({
color: 0x4d5149,
roughness: 0.95
})
);
base.position.y = -0.56;
base.castShadow = true;
base.receiveShadow = true;
scene.add(base);
// ---------------------------------------------------------------------
// Low-poly forest symbols
// ---------------------------------------------------------------------
function slopeMetric(x, z) {
const dx = Math.abs(
elevationMeters(x + 1, z) - elevationMeters(x - 1, z)
);
const dz = Math.abs(
elevationMeters(x, z + 1) - elevationMeters(x, z - 1)
);
return dx + dz;
}
function buildForest() {
const broadleafPoints = [];
const coniferPoints = [];
let attempts = 0;
while (broadleafPoints.length < 105 && attempts < 7000) {
attempts++;
const x = -58 + random() * 99;
const z = -28 + random() * 56;
const elevation = elevationMeters(x, z);
const center = valleyCenterZ(x);
if (
elevation < 920 ||
elevation > 2650 ||
Math.abs(z - center) < 3.4 ||
slopeMetric(x, z) > 125 ||
Math.abs(x + 16) < 7
) continue;
broadleafPoints.push({ x, z, elevation, scale: 0.7 + random() * 0.55 });
}
attempts = 0;
while (coniferPoints.length < 170 && attempts < 8000) {
attempts++;
const x = -49 + random() * 94;
const z = -28 + random() * 56;
const elevation = elevationMeters(x, z);
const center = valleyCenterZ(x);
if (
elevation < 2150 ||
elevation > 3500 ||
Math.abs(z - center) < 3.2 ||
slopeMetric(x, z) > 170 ||
Math.abs(x + 16) < 6
) continue;
coniferPoints.push({ x, z, elevation, scale: 0.65 + random() * 0.6 });
}
const dummy = new THREE.Object3D();
if (broadleafPoints.length) {
const geometry = new THREE.IcosahedronGeometry(0.72, 0);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
flatShading: true,
roughness: 1
});
const mesh = new THREE.InstancedMesh(
geometry,
material,
broadleafPoints.length
);
broadleafPoints.forEach((point, index) => {
dummy.position.set(
point.x,
point.elevation / METERS_PER_UNIT + 0.48 * point.scale,
point.z
);
dummy.rotation.set(0, random() * Math.PI, 0);
dummy.scale.set(
point.scale * 1.1,
point.scale * 0.9,
point.scale
);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
const color = new THREE.Color().setHSL(
0.27 + random() * 0.035,
0.28 + random() * 0.13,
0.29 + random() * 0.08
);
mesh.setColorAt(index, color);
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
}
if (coniferPoints.length) {
const geometry = new THREE.ConeGeometry(0.52, 1.65, 5);
geometry.translate(0, 0.825, 0);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
flatShading: true,
roughness: 1
});
const mesh = new THREE.InstancedMesh(
geometry,
material,
coniferPoints.length
);
coniferPoints.forEach((point, index) => {
dummy.position.set(
point.x,
point.elevation / METERS_PER_UNIT,
point.z
);
dummy.rotation.set(0, random() * Math.PI, 0);
dummy.scale.setScalar(point.scale);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
const color = new THREE.Color().setHSL(
0.32 + random() * 0.035,
0.25 + random() * 0.12,
0.22 + random() * 0.07
);
mesh.setColorAt(index, color);
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
}
}
buildForest();
// ---------------------------------------------------------------------
// River
// ---------------------------------------------------------------------
function buildRiver() {
const points = [];
for (let i = 0; i <= 120; i++) {
const x = 56 - (115 * i / 120);
const z = valleyCenterZ(x);
const y = elevationMeters(x, z) / METERS_PER_UNIT + 0.14;
points.push(new THREE.Vector3(x, y, z));
}
const curve = new THREE.CatmullRomCurve3(points, false, "centripetal");
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 360, 0.24, 5, false),
new THREE.MeshStandardMaterial({
color: 0x197c8a,
emissive: 0x0b3540,
emissiveIntensity: 0.18,
roughness: 0.48,
metalness: 0.05
})
);
tube.castShadow = true;
tube.receiveShadow = true;
scene.add(tube);
const glintPoints = points.map((point) =>
new THREE.Vector3(point.x, point.y + 0.21, point.z)
);
const glintCurve = new THREE.CatmullRomCurve3(
glintPoints,
false,
"centripetal"
);
const glint = new THREE.Mesh(
new THREE.TubeGeometry(glintCurve, 300, 0.055, 4, false),
new THREE.MeshBasicMaterial({
color: 0xa8e2e0,
transparent: true,
opacity: 0.82
})
);
scene.add(glint);
// Small arrows communicate downstream direction.
for (const x of [-38, -5, 27, 48]) {
const z = valleyCenterZ(x);
const y = elevationMeters(x, z) / METERS_PER_UNIT + 0.48;
const aheadX = x - 1;
const aheadZ = valleyCenterZ(aheadX);
const aheadY =
elevationMeters(aheadX, aheadZ) / METERS_PER_UNIT + 0.48;
const direction = new THREE.Vector3(
aheadX - x,
aheadY - y,
aheadZ - z
).normalize();
const arrow = new THREE.ArrowHelper(
direction,
new THREE.Vector3(x, y, z),
3.0,
0xb5ebe6,
0.72,
0.42
);
arrow.line.material.transparent = true;
arrow.line.material.opacity = 0.84;
scene.add(arrow);
}
}
buildRiver();
// ---------------------------------------------------------------------
// Illustrative settlement
// ---------------------------------------------------------------------
function buildSettlement() {
const settlementX = -16;
const settlement = new THREE.Group();
const wallMaterials = [
new THREE.MeshStandardMaterial({ color: 0xe4d7bf, roughness: 0.9 }),
new THREE.MeshStandardMaterial({ color: 0xc9b38f, roughness: 0.9 }),
new THREE.MeshStandardMaterial({ color: 0xf0e8d9, roughness: 0.9 })
];
const roofMaterial = new THREE.MeshStandardMaterial({
color: 0x9f5139,
roughness: 0.82,
flatShading: true
});
const roofGeometry = new THREE.ConeGeometry(0.78, 0.62, 4);
roofGeometry.rotateY(Math.PI / 4);
for (let i = 0; i < 18; i++) {
const x = settlementX + (random() - 0.5) * 10.5;
const z = valleyCenterZ(settlementX) + 3.2 + (random() - 0.5) * 6.5;
const y = elevationMeters(x, z) / METERS_PER_UNIT;
const width = 0.65 + random() * 0.42;
const depth = 0.58 + random() * 0.34;
const height = 0.55 + random() * 0.35;
const house = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
wallMaterials[i % wallMaterials.length]
);
house.position.set(x, y + height / 2, z);
house.rotation.y = (random() - 0.5) * 0.18;
house.castShadow = true;
house.receiveShadow = true;
settlement.add(house);
const roof = new THREE.Mesh(roofGeometry, roofMaterial);
roof.position.set(x, y + height + 0.28, z);
roof.rotation.y = house.rotation.y;
roof.scale.set(
width / 1.02,
1,
depth / 1.02
);
roof.castShadow = true;
settlement.add(roof);
}
const markerMaterial = new THREE.MeshStandardMaterial({
color: 0xcf6944,
emissive: 0x57210f,
emissiveIntensity: 0.12,
roughness: 0.7
});
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.07, 0.09, 3.3, 6),
markerMaterial
);
const markerX = settlementX - 1;
const markerZ = valleyCenterZ(settlementX) + 0.5;
const markerY = elevationMeters(markerX, markerZ) / METERS_PER_UNIT;
pole.position.set(markerX, markerY + 1.65, markerZ);
pole.castShadow = true;
settlement.add(pole);
const flag = new THREE.Mesh(
new THREE.PlaneGeometry(1.25, 0.65),
new THREE.MeshStandardMaterial({
color: 0xcf6944,
side: THREE.DoubleSide,
roughness: 0.8
})
);
flag.position.set(markerX + 0.61, markerY + 2.9, markerZ);
flag.rotation.y = -0.25;
settlement.add(flag);
scene.add(settlement);
}
buildSettlement();
// ---------------------------------------------------------------------
// High-pass symbol
// ---------------------------------------------------------------------
function buildPass() {
const x = 42;
const z = valleyCenterZ(x);
const y = elevationMeters(x, z) / METERS_PER_UNIT;
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color: 0xb58143,
emissive: 0x40260e,
emissiveIntensity: 0.12,
roughness: 0.72
});
for (const side of [-1, 1]) {
const post = new THREE.Mesh(
new THREE.BoxGeometry(0.34, 4.1, 0.34),
material
);
post.position.set(x, y + 2.05, z + side * 1.45);
post.castShadow = true;
group.add(post);
const cairn = new THREE.Group();
for (let i = 0; i < 4; i++) {
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.42 - i * 0.065, 0),
new THREE.MeshStandardMaterial({
color: i % 2 ? 0x817667 : 0x9a8d78,
flatShading: true,
roughness: 1
})
);
rock.position.y = i * 0.39;
rock.scale.set(1, 0.72, 1);
rock.castShadow = true;
cairn.add(rock);
}
cairn.position.set(x + 1.2, y, z + side * 3.2);
group.add(cairn);
}
const beam = new THREE.Mesh(
new THREE.BoxGeometry(0.38, 0.38, 3.25),
material
);
beam.position.set(x, y + 3.75, z);
beam.castShadow = true;
group.add(beam);
const pennant = new THREE.Mesh(
new THREE.ConeGeometry(0.48, 1.25, 3),
new THREE.MeshStandardMaterial({
color: 0xcf6944,
flatShading: true,
roughness: 0.8
})
);
pennant.position.set(x, y + 4.75, z);
pennant.rotation.z = -Math.PI / 2;
pennant.castShadow = true;
group.add(pennant);
scene.add(group);
}
buildPass();
// ---------------------------------------------------------------------
// North arrow and 20 km scale bar
// ---------------------------------------------------------------------
const northOrigin = new THREE.Vector3(-66, 0.7, 25);
const northArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
northOrigin,
9,
0x304b40,
1.8,
0.9
);
scene.add(northArrow);
const scaleStart = new THREE.Vector3(-55, 0.65, 33);
const scaleEnd = new THREE.Vector3(-15, 0.65, 33);
const scaleGeometry = new THREE.BufferGeometry().setFromPoints([
scaleStart,
scaleEnd
]);
const scaleLine = new THREE.Line(
scaleGeometry,
new THREE.LineBasicMaterial({ color: 0x304b40 })
);
scene.add(scaleLine);
for (const x of [-55, -35, -15]) {
const tick = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(x, 0.65, 32.4),
new THREE.Vector3(x, 0.65, 33.6)
]),
new THREE.LineBasicMaterial({ color: 0x304b40 })
);
scene.add(tick);
}
// ---------------------------------------------------------------------
// HTML world labels projected from 3D anchors
// ---------------------------------------------------------------------
const labels = [];
let labelsVisible = true;
function addLabel({
title,
subtitle = "",
anchor,
offset = [0, 0],
className = ""
}) {
const element = document.createElement("div");
element.className = `world-label ${className}`;
const titleElement = document.createElement("span");
titleElement.className = "label-title";
titleElement.textContent = title;
element.appendChild(titleElement);
if (subtitle) {
const subtitleElement = document.createElement("span");
subtitleElement.className = "label-sub";
subtitleElement.textContent = subtitle;
element.appendChild(subtitleElement);
}
labelLayer.appendChild(element);
labels.push({
element,
anchor: anchor.clone(),
offset
});
}
function anchorAt(x, z, verticalOffset = 0.6) {
return new THREE.Vector3(
x,
terrainY(x, z) + verticalOffset,
z
);
}
addLabel({
title: "Lower valley",
subtitle: "broad river-valley belt",
anchor: anchorAt(-45, valleyCenterZ(-45) - 7, 1.2),
offset: [-18, -8],
className: "feature"
});
addLabel({
title: "Lower montane",
subtitle: "broad forest pattern",
anchor: anchorAt(-31, -21, 1.2),
offset: [-20, -8],
className: "feature"
});
addLabel({
title: "Upper montane",
subtitle: "broad forest pattern",
anchor: anchorAt(-4, 22, 1.2),
offset: [12, -8],
className: "feature"
});
addLabel({
title: "Subalpine",
subtitle: "approx. 2.8–3.6 km",
anchor: anchorAt(13, -22, 1.2),
offset: [-10, -8],
className: "feature"
});
addLabel({
title: "Alpine",
subtitle: "approx. 3.6–4.5 km",
anchor: anchorAt(31, 22, 1.2),
offset: [16, -8],
className: "feature"
});
addLabel({
title: "Nival / snow",
subtitle: "above approx. 4.5 km",
anchor: anchorAt(52, 24, 1.5),
offset: [18, -10],
className: "feature"
});
const riverAnchorX = -8;
addLabel({
title: "Glacial-fed river",
subtitle: "flow toward lower valley",
anchor: new THREE.Vector3(
riverAnchorX,
terrainY(riverAnchorX, valleyCenterZ(riverAnchorX)) + 1.1,
valleyCenterZ(riverAnchorX)
),
offset: [-8, -12],
className: "river feature"
});
addLabel({
title: "Valley settlement",
subtitle: "illustrative · approx. 2,150 m",
anchor: new THREE.Vector3(
-16,
terrainY(-16, valleyCenterZ(-16) + 3.2) + 3.4,
valleyCenterZ(-16) + 3.2
),
offset: [-30, 16],
className: "settlement feature"
});
addLabel({
title: "High pass",
subtitle: "illustrative · approx. 4,050 m",
anchor: new THREE.Vector3(
42,
terrainY(42, valleyCenterZ(42)) + 5.1,
valleyCenterZ(42)
),
offset: [18, -8],
className: "pass feature"
});
addLabel({
title: "N",
anchor: northOrigin.clone().add(new THREE.Vector3(9, 0.4, 0)),
offset: [0, 0],
className: "minor"
});
addLabel({
title: "20 km",
anchor: scaleStart.clone().lerp(scaleEnd, 0.5).add(new THREE.Vector3(0, 0.7, 0)),
offset: [0, 0],
className: "minor"
});
const projected = new THREE.Vector3();
function updateLabels() {
const width = renderer.domElement.clientWidth;
const height = renderer.domElement.clientHeight;
for (const label of labels) {
projected.copy(label.anchor).project(camera);
const visible =
labelsVisible &&
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.25 &&
projected.x < 1.25 &&
projected.y > -1.25 &&
projected.y < 1.25;
label.element.style.opacity = visible ? "1" : "0";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * width + label.offset[0];
const y = (-projected.y * 0.5 + 0.5) * height + label.offset[1];
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
// ---------------------------------------------------------------------
// Direct camera controls — no addons
// ---------------------------------------------------------------------
let drag = null;
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
drag = {
id: event.pointerId,
x: event.clientX,
y: event.clientY,
pan: event.shiftKey || event.button === 2
};
});
canvas.addEventListener("pointermove", (event) => {
if (!drag || drag.id !== event.pointerId) return;
const dx = event.clientX - drag.x;
const dy = event.clientY - drag.y;
drag.x = event.clientX;
drag.y = event.clientY;
if (drag.pan) {
camera.updateMatrixWorld();
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
0
);
const up = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
1
);
const panScale = controls.radius * 0.00135;
controls.target.addScaledVector(right, -dx * panScale);
controls.target.addScaledVector(up, dy * panScale);
controls.target.x = THREE.MathUtils.clamp(
controls.target.x,
-30,
30
);
controls.target.y = THREE.MathUtils.clamp(
controls.target.y,
2,
19
);
controls.target.z = THREE.MathUtils.clamp(
controls.target.z,
-22,
22
);
} else {
controls.targetTheta -= dx * 0.0052;
controls.targetPhi = THREE.MathUtils.clamp(
controls.targetPhi - dy * 0.0045,
0.08,
1.43
);
}
});
function endDrag(event) {
if (drag && drag.id === event.pointerId) {
drag = null;
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.targetRadius = THREE.MathUtils.clamp(
controls.targetRadius * Math.exp(event.deltaY * 0.001),
62,
265
);
},
{ passive: false }
);
function resetView() {
controls.targetTheta = 0.78;
controls.targetPhi = 0.74;
controls.targetRadius = 164;
controls.target.set(0, 7.5, 0);
}
document.querySelector("#resetView").addEventListener("click", resetView);
document.querySelector("#planView").addEventListener("click", () => {
controls.targetTheta = 0;
controls.targetPhi = 0.08;
controls.targetRadius = 158;
controls.target.set(0, 8, 0);
});
const labelsButton = document.querySelector("#toggleLabels");
labelsButton.addEventListener("click", () => {
labelsVisible = !labelsVisible;
labelsButton.setAttribute("aria-pressed", String(labelsVisible));
});
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetView();
if (event.key.toLowerCase() === "l") labelsButton.click();
});
// ---------------------------------------------------------------------
// Resize and render loop
// ---------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
function animate() {
requestAnimationFrame(animate);
updateCamera();
renderer.render(scene, camera);
updateLabels();
}
renderer.render(scene, camera);
updateLabels();
requestAnimationFrame(() => {
loading.classList.add("hidden");
});
animate();
</script>
</body>
</html>
```