Prompt specification
Build or customize the Three.js 3D scene "Winter terrain observation model" 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: Winter terrain observation model
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/winter-terrain-observation-model-x1252
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this low-poly scene: Allow camera inspection of slope angle, gullies, and cornice geometry on a miniature mountain; provide geometric labels only and avoid advice about safe routes or avalanche conditions.
Working Three.js Starter (winter-terrain-observation-model-x1252):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Miniature Mountain Geometry</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(12, 24, 33, 0.82);
--border: rgba(170, 214, 224, 0.18);
--text: #e8f2f3;
--muted: #91a8ae;
--cyan: #58d8cf;
--violet: #9aaaff;
--snow: #e3f0ef;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #081119;
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene,
#leaders,
#labels {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
#leaders {
z-index: 3;
width: 100%;
height: 100%;
pointer-events: none;
}
#labels {
z-index: 4;
pointer-events: none;
}
.panel {
position: fixed;
z-index: 5;
border: 1px solid var(--border);
background: var(--panel);
box-shadow:
0 18px 50px rgba(0, 0, 0, 0.24),
inset 0 1px rgba(255, 255, 255, 0.035);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#title-panel {
top: 22px;
left: 22px;
min-width: 245px;
padding: 16px 18px;
border-radius: 4px;
}
.eyebrow {
margin-bottom: 6px;
color: var(--cyan);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 20px;
font-weight: 630;
letter-spacing: -0.025em;
}
.subtitle {
margin-top: 5px;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.05em;
}
#focus-panel {
top: 22px;
right: 22px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 7px;
max-width: min(520px, calc(100vw - 44px));
padding: 10px;
border-radius: 4px;
}
.focus-button {
appearance: none;
border: 1px solid rgba(157, 198, 207, 0.17);
border-radius: 3px;
padding: 9px 11px;
background: rgba(255, 255, 255, 0.035);
color: #b9c9cc;
font: inherit;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition:
color 160ms ease,
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.focus-button:hover {
color: #ffffff;
border-color: rgba(157, 198, 207, 0.42);
background: rgba(255, 255, 255, 0.07);
transform: translateY(-1px);
}
.focus-button.active {
color: #efffff;
border-color: rgba(88, 216, 207, 0.56);
background: rgba(88, 216, 207, 0.12);
}
#legend-panel {
bottom: 22px;
left: 22px;
min-width: 230px;
padding: 13px 15px;
border-radius: 4px;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin: 7px 0;
color: #afc0c4;
font-size: 10px;
letter-spacing: 0.045em;
}
.legend-row:first-of-type {
margin-top: 9px;
}
.swatch {
width: 20px;
height: 3px;
flex: 0 0 auto;
border-radius: 2px;
box-shadow: 0 0 9px currentColor;
}
.swatch.slope {
color: var(--cyan);
background: currentColor;
}
.swatch.gully {
color: var(--violet);
background: currentColor;
}
.swatch.cornice {
color: var(--snow);
background: currentColor;
}
#controls-hint {
right: 22px;
bottom: 22px;
padding: 11px 14px;
border-radius: 4px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.04em;
}
.feature-label {
--accent: #58d8cf;
position: absolute;
display: flex;
align-items: center;
gap: 8px;
min-width: 108px;
padding: 7px 9px;
border: 1px solid color-mix(in srgb, var(--accent) 48%, transparent);
border-left: 3px solid var(--accent);
border-radius: 3px;
background: rgba(8, 18, 26, 0.9);
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.28);
color: #e6f0f1;
font: inherit;
pointer-events: auto;
cursor: pointer;
transform: translate(-50%, -50%);
transition:
background 150ms ease,
box-shadow 150ms ease;
}
.feature-label:hover {
background: rgba(15, 31, 41, 0.96);
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.36);
}
.feature-label .label-name {
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
white-space: nowrap;
}
.feature-label .label-value {
padding-left: 8px;
border-left: 1px solid rgba(255, 255, 255, 0.13);
color: var(--accent);
font-size: 10px;
font-variant-numeric: tabular-nums;
white-space: nowrap;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #081119;
transition: opacity 500ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
.loader {
width: 34px;
height: 34px;
border: 1px solid rgba(88, 216, 207, 0.18);
border-top-color: var(--cyan);
border-radius: 50%;
animation: spin 900ms linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
@media (max-width: 760px) {
#title-panel {
top: 12px;
left: 12px;
min-width: 0;
padding: 12px 14px;
}
h1 {
font-size: 16px;
}
.subtitle {
display: none;
}
#focus-panel {
top: 82px;
right: 12px;
left: 12px;
max-width: none;
}
.focus-button {
padding: 8px 9px;
font-size: 9px;
}
#legend-panel {
bottom: 12px;
left: 12px;
min-width: 0;
}
#controls-hint {
right: 12px;
bottom: 12px;
max-width: 145px;
text-align: right;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<svg id="leaders" aria-hidden="true"></svg>
<div id="labels"></div>
<header id="title-panel" class="panel">
<div class="eyebrow">Ridge / Geometry 07</div>
<h1>Miniature Mountain</h1>
<div class="subtitle">Low-poly elevation model · model units: u</div>
</header>
<nav id="focus-panel" class="panel" aria-label="Geometric features">
<button class="focus-button active" data-focus="overview">Overview</button>
<button class="focus-button" data-focus="s1">Slope S1</button>
<button class="focus-button" data-focus="s2">Slope S2</button>
<button class="focus-button" data-focus="g1">Gully G1</button>
<button class="focus-button" data-focus="g2">Gully G2</button>
<button class="focus-button" data-focus="c1">Cornice C1</button>
</nav>
<section id="legend-panel" class="panel" aria-label="Geometry legend">
<div class="eyebrow">Surface Geometry</div>
<div class="legend-row">
<span class="swatch slope"></span>
<span>Slope planes and angle arcs</span>
</div>
<div class="legend-row">
<span class="swatch gully"></span>
<span>Channel axes</span>
</div>
<div class="legend-row">
<span class="swatch cornice"></span>
<span>Cornice lip</span>
</div>
</section>
<div id="controls-hint" class="panel">
Drag: orbit · Shift/right-drag: pan · Scroll: zoom · R: reset
</div>
<div id="loading"><div class="loader"></div></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const labelHost = document.getElementById("labels");
const leaderHost = document.getElementById("leaders");
const loading = document.getElementById("loading");
const renderer = new THREE.WebGLRenderer({
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.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x081119);
scene.fog = new THREE.FogExp2(0x081119, 0.025);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xb9dce5, 0x18252b, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff5df, 3.25);
keyLight.position.set(5.5, 10, 6.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 26;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x6da9d6, 1.1);
fillLight.position.set(-7, 4, -6);
scene.add(fillLight);
const rimLight = new THREE.PointLight(0x70e5dc, 11, 18, 2);
rimLight.position.set(-4.5, 6.2, -3.8);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.CircleGeometry(22, 96),
new THREE.MeshStandardMaterial({
color: 0x0b171f,
roughness: 1,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.47;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(30, 30, 0x244551, 0x19313a);
grid.position.y = -0.465;
grid.material.transparent = true;
grid.material.opacity = 0.18;
scene.add(grid);
const plinth = new THREE.Mesh(
new THREE.CylinderGeometry(6.05, 6.25, 0.42, 72),
new THREE.MeshStandardMaterial({
color: 0x142630,
roughness: 0.72,
metalness: 0.12
})
);
plinth.position.y = -0.23;
plinth.receiveShadow = true;
plinth.castShadow = true;
scene.add(plinth);
const plinthTop = new THREE.Mesh(
new THREE.CylinderGeometry(5.91, 5.91, 0.025, 72),
new THREE.MeshStandardMaterial({
color: 0x1b3039,
roughness: 0.88,
metalness: 0.05
})
);
plinthTop.position.y = -0.005;
plinthTop.receiveShadow = true;
scene.add(plinthTop);
const plinthRing = new THREE.Mesh(
new THREE.TorusGeometry(5.78, 0.018, 6, 128),
new THREE.MeshBasicMaterial({
color: 0x4bc6c0,
transparent: true,
opacity: 0.46
})
);
plinthRing.rotation.x = Math.PI / 2;
plinthRing.position.y = 0.012;
scene.add(plinthRing);
const clamp = THREE.MathUtils.clamp;
function smoothstep(edge0, edge1, value) {
const t = clamp((value - edge0) / (edge1 - edge0), 0, 1);
return t * t * (3 - 2 * t);
}
function gullyPathA(z) {
return -0.82 + 0.16 * Math.sin(z * 1.28) + 0.055 * z;
}
function gullyPathB(z) {
return 1.42 + 0.13 * Math.sin(z * 1.08 + 0.7) + 0.035 * z;
}
function gullyStrength(x, z) {
const activeA =
smoothstep(-1.35, -0.1, z) *
(1 - smoothstep(4.1, 5.1, z));
const activeB =
smoothstep(-0.8, 0.55, z) *
(1 - smoothstep(4.0, 5.0, z));
const a = Math.exp(-Math.pow((x - gullyPathA(z)) / 0.34, 2)) * activeA;
const b = Math.exp(-Math.pow((x - gullyPathB(z)) / 0.31, 2)) * activeB;
return { a, b, max: Math.max(a, b) };
}
function heightAt(x, z) {
const main = Math.exp(
-(Math.pow(x + 0.2, 2) / 9.0 + Math.pow(z + 0.25, 2) / 7.8)
);
const ridge =
0.86 *
Math.exp(-Math.pow(z + 0.55, 2) / 0.58) *
Math.exp(-Math.pow(x - 0.12, 2) / 15.0);
const east =
0.52 *
Math.exp(
-(Math.pow(x - 2.0, 2) / 5.2 + Math.pow(z + 0.1, 2) / 10.0)
);
const shoulder =
0.22 *
Math.exp(
-(Math.pow(x + 2.5, 2) / 5.0 + Math.pow(z - 1.2, 2) / 8.0)
);
const gully = gullyStrength(x, z);
let height =
0.13 +
4.25 * main +
ridge +
east +
shoulder -
0.57 * gully.a -
0.43 * gully.b;
height +=
0.045 *
Math.sin(x * 1.62 + z * 0.83) *
Math.cos(z * 1.21 - x * 0.35);
return height;
}
function gradientAt(x, z) {
const epsilon = 0.035;
const dx =
(heightAt(x + epsilon, z) - heightAt(x - epsilon, z)) /
(2 * epsilon);
const dz =
(heightAt(x, z + epsilon) - heightAt(x, z - epsilon)) /
(2 * epsilon);
return { dx, dz };
}
let randomState = 91247;
function random() {
randomState =
(randomState * 1664525 + 1013904223) >>> 0;
return randomState / 4294967296;
}
const terrainPositions = [];
const terrainColors = [];
const lowColor = new THREE.Color(0x35474d);
const middleColor = new THREE.Color(0x667477);
const highColor = new THREE.Color(0x99a4a4);
const snowColor = new THREE.Color(0xd9e2df);
const gullyColor = new THREE.Color(0x243a43);
function terrainColorForTriangle(a, b, c) {
const centerY = (a.y + b.y + c.y) / 3;
const centerX = (a.x + b.x + c.x) / 3;
const centerZ = (a.z + b.z + c.z) / 3;
const color = new THREE.Color();
if (centerY < 1.75) {
color.lerpColors(lowColor, middleColor, centerY / 1.75);
} else if (centerY < 3.2) {
color.lerpColors(
middleColor,
highColor,
(centerY - 1.75) / 1.45
);
} else {
color.lerpColors(
highColor,
snowColor,
clamp((centerY - 3.2) / 0.72, 0, 1)
);
}
const gully = gullyStrength(centerX, centerZ).max;
if (gully > 0.12) {
color.lerp(gullyColor, clamp(gully * 0.72, 0, 0.67));
}
const ab = new THREE.Vector3().subVectors(b, a);
const ac = new THREE.Vector3().subVectors(c, a);
const normal = new THREE.Vector3().crossVectors(ab, ac).normalize();
const steepness = clamp((0.86 - normal.y) * 1.7, 0, 0.2);
color.multiplyScalar(1 - steepness);
const variation = 0.91 + random() * 0.16;
color.multiplyScalar(variation);
return color;
}
function addTerrainTriangle(a, b, c) {
terrainPositions.push(
a.x, a.y, a.z,
b.x, b.y, b.z,
c.x, c.y, c.z
);
const color = terrainColorForTriangle(a, b, c);
for (let i = 0; i < 3; i++) {
terrainColors.push(color.r, color.g, color.b);
}
}
const radialSegments = 48;
const radialRings = 20;
const mountainRadius = 5.55;
const ringVertices = [];
function boundaryScale(angle) {
return (
1 +
0.052 * Math.sin(angle * 3 + 0.4) +
0.027 * Math.sin(angle * 7 - 0.8)
);
}
const center = new THREE.Vector3(0, heightAt(0, 0), 0);
ringVertices.push([]);
for (let ring = 1; ring <= radialRings; ring++) {
const radiusFactor = ring / radialRings;
const ringPoints = [];
for (let segment = 0; segment < radialSegments; segment++) {
const angle = (segment / radialSegments) * Math.PI * 2;
const edge = boundaryScale(angle);
const x =
Math.cos(angle) *
mountainRadius *
radiusFactor *
edge;
const z =
Math.sin(angle) *
mountainRadius *
radiusFactor *
edge;
ringPoints.push(new THREE.Vector3(x, heightAt(x, z), z));
}
ringVertices.push(ringPoints);
}
for (let segment = 0; segment < radialSegments; segment++) {
const next = (segment + 1) % radialSegments;
addTerrainTriangle(
center,
ringVertices[1][next],
ringVertices[1][segment]
);
}
for (let ring = 1; ring < radialRings; ring++) {
for (let segment = 0; segment < radialSegments; segment++) {
const next = (segment + 1) % radialSegments;
const p00 = ringVertices[ring][segment];
const p01 = ringVertices[ring][next];
const p10 = ringVertices[ring + 1][segment];
const p11 = ringVertices[ring + 1][next];
addTerrainTriangle(p00, p01, p10);
addTerrainTriangle(p01, p11, p10);
}
}
const terrainGeometry = new THREE.BufferGeometry();
terrainGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(terrainPositions, 3)
);
terrainGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(terrainColors, 3)
);
terrainGeometry.computeVertexNormals();
const terrain = new THREE.Mesh(
terrainGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.98,
metalness: 0,
flatShading: true
})
);
terrain.castShadow = true;
terrain.receiveShadow = true;
scene.add(terrain);
const terrainWire = new THREE.LineSegments(
new THREE.WireframeGeometry(terrainGeometry),
new THREE.LineBasicMaterial({
color: 0xb8d0d1,
transparent: true,
opacity: 0.055,
depthWrite: false
})
);
terrainWire.position.y = 0.003;
terrain.add(terrainWire);
const skirtPositions = [];
for (let segment = 0; segment < radialSegments; segment++) {
const next = (segment + 1) % radialSegments;
const a = ringVertices[radialRings][segment];
const b = ringVertices[radialRings][next];
const ab = new THREE.Vector3(a.x, -0.025, a.z);
const bb = new THREE.Vector3(b.x, -0.025, b.z);
skirtPositions.push(
a.x, a.y, a.z,
b.x, b.y, b.z,
ab.x, ab.y, ab.z,
b.x, b.y, b.z,
bb.x, bb.y, bb.z,
ab.x, ab.y, ab.z
);
}
const skirtGeometry = new THREE.BufferGeometry();
skirtGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(skirtPositions, 3)
);
skirtGeometry.computeVertexNormals();
const skirt = new THREE.Mesh(
skirtGeometry,
new THREE.MeshStandardMaterial({
color: 0x25373d,
roughness: 1,
side: THREE.DoubleSide
})
);
skirt.castShadow = true;
skirt.receiveShadow = true;
scene.add(skirt);
function createCornice() {
const positions = [];
const colors = [];
const stations = 14;
const topColor = new THREE.Color(0xe7efeb);
const edgeColor = new THREE.Color(0xc8d9d8);
const underColor = new THREE.Color(0x8fa9ae);
function addTriangle(a, b, c, color) {
positions.push(
a.x, a.y, a.z,
b.x, b.y, b.z,
c.x, c.y, c.z
);
for (let i = 0; i < 3; i++) {
colors.push(color.r, color.g, color.b);
}
}
const stationData = [];
for (let i = 0; i <= stations; i++) {
const t = i / stations;
const x = -1.62 + t * 3.35;
const innerZ = -0.13 + 0.07 * Math.sin(t * Math.PI * 2);
const overhang = 0.58 + 0.08 * Math.sin(t * Math.PI);
const outerZ = innerZ - overhang;
const innerY = heightAt(x, innerZ) + 0.035;
const outerY =
innerY - 0.12 - 0.1 * Math.sin(t * Math.PI);
stationData.push({
innerTop: new THREE.Vector3(x, innerY, innerZ),
outerTop: new THREE.Vector3(x, outerY, outerZ),
outerBottom: new THREE.Vector3(x, outerY - 0.17, outerZ),
innerBottom: new THREE.Vector3(x, innerY - 0.22, innerZ)
});
}
for (let i = 0; i < stations; i++) {
const a = stationData[i];
const b = stationData[i + 1];
addTriangle(a.innerTop, b.innerTop, b.outerTop, topColor);
addTriangle(a.innerTop, b.outerTop, a.outerTop, topColor);
addTriangle(a.outerTop, b.outerTop, b.outerBottom, edgeColor);
addTriangle(a.outerTop, b.outerBottom, a.outerBottom, edgeColor);
addTriangle(
a.outerBottom,
b.outerBottom,
b.innerBottom,
underColor
);
addTriangle(
a.outerBottom,
b.innerBottom,
a.innerBottom,
underColor
);
addTriangle(
a.innerBottom,
b.innerBottom,
b.innerTop,
edgeColor
);
addTriangle(
a.innerBottom,
b.innerTop,
a.innerTop,
edgeColor
);
}
addTriangle(
stationData[0].innerTop,
stationData[0].outerTop,
stationData[0].outerBottom,
edgeColor
);
addTriangle(
stationData[0].innerTop,
stationData[0].outerBottom,
stationData[0].innerBottom,
edgeColor
);
const last = stationData[stationData.length - 1];
addTriangle(last.innerTop, last.outerBottom, last.outerTop, edgeColor);
addTriangle(last.innerTop, last.innerBottom, last.outerBottom, edgeColor);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.9,
metalness: 0,
flatShading: true,
side: THREE.DoubleSide
})
);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
const edgeLines = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry, 8),
new THREE.LineBasicMaterial({
color: 0xe8ffff,
transparent: true,
opacity: 0.58
})
);
mesh.add(edgeLines);
const sample = stationData[Math.floor(stations * 0.53)];
return {
mesh,
anchor: sample.outerTop.clone().add(new THREE.Vector3(0, 0.12, 0)),
overhang: 0.66
};
}
const cornice = createCornice();
function createSlopePatch({
id,
title,
color,
centerX,
centerZ,
width,
depth,
rotation,
offset
}) {
const group = new THREE.Group();
scene.add(group);
const subdivisions = 6;
const positions = [];
const indices = [];
const localCos = Math.cos(rotation);
const localSin = Math.sin(rotation);
function mapLocal(u, v) {
const x = centerX + u * localCos - v * localSin;
const z = centerZ + u * localSin + v * localCos;
return new THREE.Vector3(x, heightAt(x, z) + 0.028, z);
}
for (let row = 0; row <= subdivisions; row++) {
const v = (row / subdivisions - 0.5) * depth;
for (let column = 0; column <= subdivisions; column++) {
const u = (column / subdivisions - 0.5) * width;
const point = mapLocal(u, v);
positions.push(point.x, point.y, point.z);
}
}
for (let row = 0; row < subdivisions; row++) {
for (let column = 0; column < subdivisions; column++) {
const a = row * (subdivisions + 1) + column;
const b = a + 1;
const d = a + subdivisions + 1;
const c = d + 1;
indices.push(a, b, d, b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const patch = new THREE.Mesh(
geometry,
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.13,
side: THREE.DoubleSide,
depthWrite: false,
polygonOffset: true,
polygonOffsetFactor: -1,
polygonOffsetUnits: -1
})
);
group.add(patch);
const perimeter = [];
const perimeterSteps = 8;
for (let i = 0; i <= perimeterSteps; i++) {
perimeter.push(
mapLocal(
-width / 2 + (i / perimeterSteps) * width,
-depth / 2
)
);
}
for (let i = 0; i <= perimeterSteps; i++) {
perimeter.push(
mapLocal(
width / 2,
-depth / 2 + (i / perimeterSteps) * depth
)
);
}
for (let i = 0; i <= perimeterSteps; i++) {
perimeter.push(
mapLocal(
width / 2 - (i / perimeterSteps) * width,
depth / 2
)
);
}
for (let i = 0; i <= perimeterSteps; i++) {
perimeter.push(
mapLocal(
-width / 2,
depth / 2 - (i / perimeterSteps) * depth
)
);
}
const perimeterLine = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(perimeter),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.72
})
);
group.add(perimeterLine);
const gradient = gradientAt(centerX, centerZ);
const slopeMagnitude = Math.hypot(gradient.dx, gradient.dz);
const angleRadians = Math.atan(slopeMagnitude);
const angleDegrees = THREE.MathUtils.radToDeg(angleRadians);
const downhill = new THREE.Vector3(
-gradient.dx,
0,
-gradient.dz
).normalize();
const centerPoint = new THREE.Vector3(
centerX,
heightAt(centerX, centerZ) + 0.07,
centerZ
);
const arcRadius = 0.58;
const arcPoints = [];
const arcSegments = 28;
for (let i = 0; i <= arcSegments; i++) {
const angle = (i / arcSegments) * angleRadians;
arcPoints.push(
new THREE.Vector3(
centerPoint.x + downhill.x * Math.cos(angle) * arcRadius,
centerPoint.y - Math.sin(angle) * arcRadius,
centerPoint.z + downhill.z * Math.cos(angle) * arcRadius
)
);
}
const arc = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(arcPoints),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.95
})
);
group.add(arc);
const tangentLength = 0.86;
const tangentEnd = new THREE.Vector3(
centerPoint.x + downhill.x * tangentLength,
centerPoint.y - Math.tan(angleRadians) * tangentLength,
centerPoint.z + downhill.z * tangentLength
);
const horizontalEnd = new THREE.Vector3(
centerPoint.x + downhill.x * arcRadius,
centerPoint.y,
centerPoint.z + downhill.z * arcRadius
);
const angleRays = new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints([
centerPoint,
horizontalEnd,
centerPoint,
tangentEnd
]),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.58
})
);
group.add(angleRays);
const arcAnchor = arcPoints[
Math.floor(arcPoints.length * 0.52)
].clone().add(new THREE.Vector3(0, 0.12, 0));
return {
id,
title,
metric: `${angleDegrees.toFixed(1)}°`,
anchor: arcAnchor,
color,
offset
};
}
function createGully({
id,
title,
color,
path,
width,
offset
}) {
const points = [];
for (let i = 0; i <= 28; i++) {
const z = -0.42 + (i / 28) * 4.35;
const x = path(z);
points.push(
new THREE.Vector3(x, heightAt(x, z) + 0.07, z)
);
}
const curve = new THREE.CatmullRomCurve3(points);
const corridor = new THREE.Mesh(
new THREE.TubeGeometry(curve, 80, width, 6, false),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.11,
depthWrite: false
})
);
scene.add(corridor);
const axis = new THREE.Mesh(
new THREE.TubeGeometry(curve, 80, 0.025, 6, false),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.93
})
);
scene.add(axis);
const anchorZ = 1.75;
const anchorX = path(anchorZ);
return {
id,
title,
metric: `${width.toFixed(2)} u`,
anchor: new THREE.Vector3(
anchorX,
heightAt(anchorX, anchorZ) + 0.16,
anchorZ
),
color,
offset
};
}
const featureDefinitions = [
createSlopePatch({
id: "s1",
title: "SLOPE S1",
color: 0x58d8cf,
centerX: -2.22,
centerZ: 0.95,
width: 1.52,
depth: 1.35,
rotation: -0.25,
offset: [-105, -52]
}),
createSlopePatch({
id: "s2",
title: "SLOPE S2",
color: 0x7bdad0,
centerX: 2.28,
centerZ: 1.12,
width: 1.38,
depth: 1.2,
rotation: 0.28,
offset: [95, 52]
}),
createGully({
id: "g1",
title: "GULLY G1",
color: 0x9aaaff,
path: gullyPathA,
width: 0.34,
offset: [-85, 55]
}),
createGully({
id: "g2",
title: "GULLY G2",
color: 0x72bff0,
path: gullyPathB,
width: 0.31,
offset: [92, 42]
}),
{
id: "c1",
title: "CORNICE C1",
metric: `${cornice.overhang.toFixed(2)} u`,
anchor: cornice.anchor,
color: 0xe3f0ef,
offset: [92, -74]
}
];
const featureMap = new Map();
const labelElements = [];
for (const definition of featureDefinitions) {
featureMap.set(definition.id, definition);
const element = document.createElement("button");
element.className = "feature-label";
element.style.setProperty("--accent", `#${definition.color.toString(16).padStart(6, "0")}`);
element.innerHTML = `
<span class="label-name">${definition.title}</span>
<span class="label-value">${definition.metric}</span>
`;
element.setAttribute("aria-label", `${definition.title}, ${definition.metric}`);
element.addEventListener("click", () => focusFeature(definition.id));
labelHost.appendChild(element);
const line = document.createElementNS(
"http://www.w3.org/2000/svg",
"line"
);
line.setAttribute("stroke", `#${definition.color.toString(16).padStart(6, "0")}`);
line.setAttribute("stroke-width", "1");
line.setAttribute("stroke-opacity", "0.58");
leaderHost.appendChild(line);
const dot = document.createElementNS(
"http://www.w3.org/2000/svg",
"circle"
);
dot.setAttribute("r", "2.4");
dot.setAttribute("fill", `#${definition.color.toString(16).padStart(6, "0")}`);
leaderHost.appendChild(dot);
labelElements.push({
definition,
element,
line,
dot
});
}
const overviewPreset = {
target: new THREE.Vector3(0, 1.9, 0),
radius: 12.3,
theta: 0.72,
phi: 1.04
};
const currentCameraState = {
target: overviewPreset.target.clone(),
radius: overviewPreset.radius,
theta: overviewPreset.theta,
phi: overviewPreset.phi
};
const goalCameraState = {
target: overviewPreset.target.clone(),
radius: overviewPreset.radius,
theta: overviewPreset.theta,
phi: overviewPreset.phi
};
const focusPresets = {
overview: overviewPreset,
s1: {
target: featureMap.get("s1").anchor.clone(),
radius: 6.15,
theta: 0.55,
phi: 1.08
},
s2: {
target: featureMap.get("s2").anchor.clone(),
radius: 6.0,
theta: 0.9,
phi: 1.04
},
g1: {
target: featureMap.get("g1").anchor.clone(),
radius: 5.25,
theta: 0.22,
phi: 1.12
},
g2: {
target: featureMap.get("g2").anchor.clone(),
radius: 5.15,
theta: 0.46,
phi: 1.1
},
c1: {
target: featureMap.get("c1").anchor.clone(),
radius: 4.25,
theta: 0.16,
phi: 1.16
}
};
const focusButtons = [
...document.querySelectorAll(".focus-button")
];
function focusFeature(id) {
const preset = focusPresets[id];
if (!preset) return;
goalCameraState.target.copy(preset.target);
goalCameraState.radius = preset.radius;
goalCameraState.theta = preset.theta;
goalCameraState.phi = preset.phi;
for (const button of focusButtons) {
button.classList.toggle("active", button.dataset.focus === id);
}
}
focusButtons.forEach((button) => {
button.addEventListener("click", () => {
focusFeature(button.dataset.focus);
});
});
const pointers = new Map();
let pointerMode = "orbit";
let lastPinchDistance = 0;
let lastPinchMidpoint = null;
function pointerDistance(a, b) {
return Math.hypot(a.x - b.x, a.y - b.y);
}
function pointerMidpoint(a, b) {
return {
x: (a.x + b.x) * 0.5,
y: (a.y + b.y) * 0.5
};
}
function panCamera(dx, dy) {
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrixWorld,
0
);
const up = new THREE.Vector3().setFromMatrixColumn(
camera.matrixWorld,
1
);
const scale = goalCameraState.radius * 0.00135;
goalCameraState.target
.addScaledVector(right, -dx * scale)
.addScaledVector(up, dy * scale);
goalCameraState.target.x = clamp(
goalCameraState.target.x,
-6,
6
);
goalCameraState.target.y = clamp(
goalCameraState.target.y,
0.1,
5.2
);
goalCameraState.target.z = clamp(
goalCameraState.target.z,
-6,
6
);
}
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
pointerMode =
event.button === 2 || event.shiftKey ? "pan" : "orbit";
} else if (pointers.size === 2) {
pointerMode = "pinch";
const values = [...pointers.values()];
lastPinchDistance = pointerDistance(values[0], values[1]);
lastPinchMidpoint = pointerMidpoint(values[0], values[1]);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
if (pointerMode === "pan" || event.shiftKey) {
panCamera(dx, dy);
} else {
goalCameraState.theta -= dx * 0.006;
goalCameraState.phi = clamp(
goalCameraState.phi + dy * 0.005,
0.22,
1.47
);
}
} else if (pointers.size >= 2) {
const values = [...pointers.values()];
const distance = pointerDistance(values[0], values[1]);
const midpoint = pointerMidpoint(values[0], values[1]);
if (lastPinchDistance > 0) {
goalCameraState.radius = clamp(
goalCameraState.radius *
(lastPinchDistance / Math.max(distance, 1)),
3.1,
21
);
}
if (lastPinchMidpoint) {
panCamera(
midpoint.x - lastPinchMidpoint.x,
midpoint.y - lastPinchMidpoint.y
);
}
lastPinchDistance = distance;
lastPinchMidpoint = midpoint;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 1) {
pointerMode = "orbit";
lastPinchDistance = 0;
lastPinchMidpoint = null;
} else if (pointers.size === 0) {
lastPinchDistance = 0;
lastPinchMidpoint = null;
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
goalCameraState.radius = clamp(
goalCameraState.radius * Math.exp(event.deltaY * 0.001),
3.1,
21
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "arrowleft") {
goalCameraState.theta -= 0.08;
} else if (key === "arrowright") {
goalCameraState.theta += 0.08;
} else if (key === "arrowup") {
goalCameraState.phi = clamp(
goalCameraState.phi - 0.05,
0.22,
1.47
);
} else if (key === "arrowdown") {
goalCameraState.phi = clamp(
goalCameraState.phi + 0.05,
0.22,
1.47
);
} else if (key === "+" || key === "=") {
goalCameraState.radius = clamp(
goalCameraState.radius * 0.9,
3.1,
21
);
} else if (key === "-") {
goalCameraState.radius = clamp(
goalCameraState.radius * 1.1,
3.1,
21
);
} else if (key === "r") {
focusFeature("overview");
}
});
function damp(current, target, lambda, deltaTime) {
return THREE.MathUtils.lerp(
current,
target,
1 - Math.exp(-lambda * deltaTime)
);
}
function shortestAngleDifference(from, to) {
let difference = (to - from) % (Math.PI * 2);
if (difference > Math.PI) difference -= Math.PI * 2;
if (difference < -Math.PI) difference += Math.PI * 2;
return difference;
}
const spherical = new THREE.Spherical();
const cameraOffset = new THREE.Vector3();
const cameraSpace = new THREE.Vector3();
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const item of labelElements) {
const definition = item.definition;
cameraSpace
.copy(definition.anchor)
.applyMatrix4(camera.matrixWorldInverse);
projected.copy(definition.anchor).project(camera);
const visible =
cameraSpace.z < 0 &&
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.18 &&
Math.abs(projected.y) < 1.18;
if (!visible) {
item.element.style.display = "none";
item.line.style.display = "none";
item.dot.style.display = "none";
continue;
}
const anchorX = (projected.x * 0.5 + 0.5) * width;
const anchorY = (-projected.y * 0.5 + 0.5) * height;
const labelX = anchorX + definition.offset[0];
const labelY = anchorY + definition.offset[1];
item.element.style.display = "flex";
item.line.style.display = "";
item.dot.style.display = "";
item.element.style.left = `${labelX}px`;
item.element.style.top = `${labelY}px`;
item.line.setAttribute("x1", anchorX);
item.line.setAttribute("y1", anchorY);
item.line.setAttribute("x2", labelX);
item.line.setAttribute("y2", labelY);
item.dot.setAttribute("cx", anchorX);
item.dot.setAttribute("cy", anchorY);
}
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
leaderHost.setAttribute("viewBox", `0 0 ${window.innerWidth} ${window.innerHeight}`);
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
const deltaTime = Math.min(clock.getDelta(), 0.05);
const smoothing = 7.5;
currentCameraState.target.lerp(
goalCameraState.target,
1 - Math.exp(-smoothing * deltaTime)
);
currentCameraState.radius = damp(
currentCameraState.radius,
goalCameraState.radius,
smoothing,
deltaTime
);
currentCameraState.theta +=
shortestAngleDifference(
currentCameraState.theta,
goalCameraState.theta
) *
(1 - Math.exp(-smoothing * deltaTime));
currentCameraState.phi = damp(
currentCameraState.phi,
goalCameraState.phi,
smoothing,
deltaTime
);
spherical.set(
currentCameraState.radius,
currentCameraState.phi,
currentCameraState.theta
);
cameraOffset.setFromSpherical(spherical);
camera.position
.copy(currentCameraState.target)
.add(cameraOffset);
camera.lookAt(currentCameraState.target);
camera.updateMatrixWorld();
updateLabels();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 600);
});
}
}
animate();
</script>
</body>
</html>
```