Prompt specification
Build or customize the Three.js 3D scene "Glacial valley cross-section piece" 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: Glacial valley cross-section piece
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/glacial-valley-cross-section-piece-x1149
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows glacial valleys. Show a broad U-shaped valley beside a narrow V-shaped river valley, using matching mountain blocks so the contrasting cross sections remain immediately readable. Low-poly.
Working Three.js Starter (glacial-valley-cross-section-piece-x1149):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Glacial U vs. River V</title>
<style>
:root {
--ink: #173039;
--muted: #597077;
--ice: #34bbc7;
--river: #eb805b;
--panel: rgba(247, 250, 247, 0.78);
--line: rgba(23, 48, 57, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce8e6;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas.dragging {
cursor: grabbing;
}
.ui {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
header {
position: absolute;
top: 30px;
left: 34px;
max-width: 440px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 14px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
width: 25px;
height: 2px;
content: "";
background: var(--ink);
}
h1 {
margin: 0;
font-size: clamp(38px, 5.4vw, 74px);
font-weight: 760;
letter-spacing: -0.065em;
line-height: 0.91;
}
header p {
max-width: 370px;
margin: 19px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.key-card {
position: absolute;
top: 30px;
right: 30px;
width: 238px;
padding: 17px 18px 15px;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 3px;
background: var(--panel);
box-shadow: 0 14px 40px rgba(44, 72, 77, 0.08);
backdrop-filter: blur(15px);
}
.key-heading {
display: flex;
align-items: center;
justify-content: space-between;
padding-bottom: 12px;
border-bottom: 1px solid var(--line);
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.key-heading strong {
color: var(--ink);
font-size: 11px;
letter-spacing: 0.04em;
}
.profile-row {
display: grid;
grid-template-columns: 76px 1fr;
align-items: center;
gap: 12px;
padding-top: 14px;
}
.profile-row svg {
display: block;
width: 76px;
height: 34px;
overflow: visible;
}
.profile-row strong {
display: block;
margin-bottom: 3px;
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.profile-row small {
color: var(--muted);
font-size: 10px;
}
.profile-row.ice strong {
color: #148f9b;
}
.profile-row.river strong {
color: #c95e3b;
}
.key-footer {
margin-top: 14px;
padding-top: 11px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 9px;
letter-spacing: 0.06em;
}
.world-label {
position: absolute;
display: flex;
align-items: center;
gap: 10px;
min-width: 178px;
padding: 9px 12px 9px 9px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 3px;
background: rgba(248, 251, 248, 0.84);
box-shadow: 0 9px 24px rgba(43, 69, 74, 0.1);
transform: translate(-50%, -50%);
backdrop-filter: blur(10px);
white-space: nowrap;
}
.world-label .number {
display: grid;
width: 29px;
height: 29px;
place-items: center;
flex: 0 0 auto;
border-radius: 50%;
color: white;
font-size: 10px;
font-weight: 800;
}
.world-label.ice .number {
background: var(--ice);
}
.world-label.river .number {
background: var(--river);
}
.world-label b {
display: block;
margin-bottom: 2px;
font-size: 10px;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.world-label small {
display: block;
color: var(--muted);
font-size: 10px;
}
.footer {
position: absolute;
right: 30px;
bottom: 27px;
left: 34px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 20px;
}
.instructions {
display: flex;
align-items: center;
gap: 14px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.instructions span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.instructions b {
padding: 4px 6px;
border: 1px solid rgba(23, 48, 57, 0.2);
border-radius: 2px;
color: var(--ink);
font-size: 9px;
}
.reset {
pointer-events: auto;
padding: 9px 13px;
border: 1px solid rgba(23, 48, 57, 0.22);
border-radius: 2px;
background: rgba(247, 250, 247, 0.65);
color: var(--ink);
cursor: pointer;
font: inherit;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
transition: background 160ms ease, transform 160ms ease;
backdrop-filter: blur(10px);
}
.reset:hover {
background: rgba(255, 255, 255, 0.95);
transform: translateY(-1px);
}
@media (max-width: 760px) {
header {
top: 20px;
left: 20px;
}
header p {
display: none;
}
.key-card {
top: 18px;
right: 18px;
width: 170px;
padding: 12px;
}
.profile-row {
grid-template-columns: 54px 1fr;
gap: 8px;
}
.profile-row svg {
width: 54px;
}
.profile-row small,
.key-footer {
display: none;
}
.footer {
right: 18px;
bottom: 18px;
left: 18px;
}
.instructions span:not(:first-child) {
display: none;
}
.world-label {
min-width: 0;
padding: 7px 9px;
}
.world-label small {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="ui">
<header>
<div class="eyebrow">Landform study / 01</div>
<h1>Glacial U.<br>River V.</h1>
<p>
Two matched mountain blocks reveal how ice creates a broad,
flat-floored trough while rivers cut a narrow, angular valley.
</p>
</header>
<aside class="key-card">
<div class="key-heading">
Matched scale <strong>1 : 1</strong>
</div>
<div class="profile-row ice">
<svg viewBox="0 0 76 34" aria-hidden="true">
<path
d="M3 5 H25 C34 5 34 28 42 28 C50 28 50 5 59 5 H73"
fill="none"
stroke="#20aab7"
stroke-width="4"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
<div>
<strong>Glacial section</strong>
<small>Broad floor · rounded walls</small>
</div>
</div>
<div class="profile-row river">
<svg viewBox="0 0 76 34" aria-hidden="true">
<path
d="M3 5 L38 29 L73 5"
fill="none"
stroke="#e87550"
stroke-width="4"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
<div>
<strong>Fluvial section</strong>
<small>Narrow base · straight walls</small>
</div>
</div>
<div class="key-footer">Same width, depth, and mountain height</div>
</aside>
<div id="glacial-label" class="world-label ice">
<span class="number">01</span>
<div>
<b>Glacial valley</b>
<small>Broad U-shaped cross section</small>
</div>
</div>
<div id="river-label" class="world-label river">
<span class="number">02</span>
<div>
<b>River valley</b>
<small>Narrow V-shaped cross section</small>
</div>
</div>
<div class="footer">
<div class="instructions">
<span><b>Drag</b> Orbit</span>
<span><b>Scroll</b> Zoom</span>
<span><b>R</b> Reset view</span>
</div>
<button class="reset" id="reset" type="button">Reset view</button>
</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 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;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8e6);
scene.fog = new THREE.Fog(0xdce8e6, 125, 215);
const camera = new THREE.OrthographicCamera(-50, 50, 30, -30, 0.1, 300);
const cameraTarget = new THREE.Vector3(0, 3.5, 0);
const hemisphere = new THREE.HemisphereLight(0xf6fbff, 0x71807b, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff7e8, 3.1);
sun.position.set(-34, 65, 42);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -70;
sun.shadow.camera.right = 70;
sun.shadow.camera.top = 70;
sun.shadow.camera.bottom = -70;
sun.shadow.camera.near = 5;
sun.shadow.camera.far = 150;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8d9e1, 0.8);
fill.position.set(45, 25, -35);
scene.add(fill);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(230, 190),
new THREE.MeshStandardMaterial({
color: 0xd1ded9,
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -2.98;
ground.receiveShadow = true;
scene.add(ground);
const BLOCK_WIDTH = 32;
const BLOCK_DEPTH = 52;
const BLOCK_BOTTOM = -2.15;
const GRID_X = 28;
const GRID_Z = 40;
const ICE_COLOR = 0x32bdc8;
const FLUVIAL_COLOR = 0xeb805b;
function clamp(value, min, max) {
return Math.min(max, Math.max(min, value));
}
function smoothstep(min, max, value) {
const t = clamp((value - min) / (max - min), 0, 1);
return t * t * (3 - 2 * t);
}
function hash(value) {
const n = Math.sin(value * 12.9898) * 43758.5453;
return n - Math.floor(n);
}
// The surrounding mountain envelope is identical for both blocks.
function commonMountainProfile(distanceFromCenter) {
const a = distanceFromCenter;
if (a <= 12.4) {
return 7 + 5 * Math.sin((Math.PI * a) / 24.8);
}
return 12 - (a - 12.4) * 0.28;
}
// Two erosion profiles applied to the same outer mountain block.
function heightAt(type, x, z) {
const a = Math.abs(x);
const longitudinalFloor = 0.45 + (BLOCK_DEPTH / 2 - z) * 0.022;
const longitudinalMountain = (BLOCK_DEPTH / 2 - z) * 0.01;
const common = commonMountainProfile(a) + longitudinalMountain;
let height;
if (type === "glacial") {
if (a <= 5.2) {
height = longitudinalFloor;
} else if (a <= 10.8) {
const t = (a - 5.2) / 5.6;
const roundedWall = t * t * (3 - 2 * t);
height =
longitudinalFloor +
(common - longitudinalFloor) * roundedWall;
} else {
height = common;
}
} else {
if (a <= 0.65) {
height = longitudinalFloor;
} else if (a <= 10.8) {
const t = (a - 0.65) / (10.8 - 0.65);
const commonAtJoin =
commonMountainProfile(10.8) + longitudinalMountain;
height =
longitudinalFloor +
(commonAtJoin - longitudinalFloor) * t;
} else {
height = common;
}
}
// Low-amplitude deterministic faceting. It fades to zero at the
// exposed front profile so the two sections remain clean and readable.
const frontFade = smoothstep(0, 9, BLOCK_DEPTH / 2 - z);
const roughMask = clamp((a - 1) / 5, 0, 1);
const roughness =
Math.sin(x * 0.73 + z * 0.37) * 0.22 +
Math.sin(x * 0.31 - z * 0.51) * 0.16 +
Math.sin(z * 0.83 + x * 0.19) * 0.1;
height += roughness * roughMask * frontFade;
return height;
}
function colorForHeight(height, variation = 0.5) {
let color;
if (height > 11.35) {
color = new THREE.Color(0xe8eeee);
} else if (height > 9.1) {
color = new THREE.Color(0x7e8d8e);
} else if (height > 6.0) {
color = new THREE.Color(0x78877e);
} else if (height > 2.3) {
color = new THREE.Color(0x8b9984);
} else {
color = new THREE.Color(0x9eada0);
}
color.multiplyScalar(0.91 + variation * 0.15);
return color;
}
function createTerrainMesh(type, seed) {
const positions = [];
const colors = [];
const dx = BLOCK_WIDTH / GRID_X;
const dz = BLOCK_DEPTH / GRID_Z;
const heights = [];
for (let iz = 0; iz <= GRID_Z; iz++) {
const row = [];
for (let ix = 0; ix <= GRID_X; ix++) {
const x = -BLOCK_WIDTH / 2 + ix * dx;
const z = -BLOCK_DEPTH / 2 + iz * dz;
row.push({ x, z, y: heightAt(type, x, z) });
}
heights.push(row);
}
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);
}
}
for (let iz = 0; iz < GRID_Z; iz++) {
for (let ix = 0; ix < GRID_X; ix++) {
const p00 = heights[iz][ix];
const p10 = heights[iz][ix + 1];
const p01 = heights[iz + 1][ix];
const p11 = heights[iz + 1][ix + 1];
const averageHeight =
(p00.y + p10.y + p01.y + p11.y) / 4;
const variation = hash(
ix * 127.1 + iz * 311.7 + seed * 74.7
);
const color = colorForHeight(averageHeight, variation);
if ((ix + iz) % 2 === 0) {
addTriangle(p00, p01, p10, color);
addTriangle(p10, p01, p11, color);
} else {
addTriangle(p00, p01, p11, color);
addTriangle(p00, p11, p10, 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,
roughness: 0.94,
metalness: 0,
flatShading: true
});
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function createBlockSides(type, seed) {
const positions = [];
const colors = [];
const bottomColor = new THREE.Color(0x617377);
function addTriangle(a, b, c, colorA, colorB, colorC) {
positions.push(
a.x, a.y, a.z,
b.x, b.y, b.z,
c.x, c.y, c.z
);
colors.push(
colorA.r, colorA.g, colorA.b,
colorB.r, colorB.g, colorB.b,
colorC.r, colorC.g, colorC.b
);
}
function addSideQuad(topA, topB, colorA, colorB) {
const bottomA = {
x: topA.x,
y: BLOCK_BOTTOM,
z: topA.z
};
const bottomB = {
x: topB.x,
y: BLOCK_BOTTOM,
z: topB.z
};
addTriangle(topA, bottomA, topB, colorA, bottomColor, colorB);
addTriangle(topB, bottomA, bottomB, colorB, bottomColor, bottomColor);
}
const edgeSamples = 28;
// Front and back.
for (let i = 0; i < edgeSamples; i++) {
const x0 = -BLOCK_WIDTH / 2 + (i / edgeSamples) * BLOCK_WIDTH;
const x1 = -BLOCK_WIDTH / 2 + ((i + 1) / edgeSamples) * BLOCK_WIDTH;
const frontA = { x: x0, y: heightAt(type, x0, BLOCK_DEPTH / 2), z: BLOCK_DEPTH / 2 };
const frontB = { x: x1, y: heightAt(type, x1, BLOCK_DEPTH / 2), z: BLOCK_DEPTH / 2 };
addSideQuad(
frontA,
frontB,
colorForHeight(frontA.y, hash(i + seed)),
colorForHeight(frontB.y, hash(i + 1 + seed))
);
const backA = { x: x0, y: heightAt(type, x0, -BLOCK_DEPTH / 2), z: -BLOCK_DEPTH / 2 };
const backB = { x: x1, y: heightAt(type, x1, -BLOCK_DEPTH / 2), z: -BLOCK_DEPTH / 2 };
addSideQuad(
backA,
backB,
colorForHeight(backA.y, hash(i + 20 + seed)),
colorForHeight(backB.y, hash(i + 21 + seed))
);
}
// Left and right.
for (let i = 0; i < edgeSamples; i++) {
const z0 = -BLOCK_DEPTH / 2 + (i / edgeSamples) * BLOCK_DEPTH;
const z1 = -BLOCK_DEPTH / 2 + ((i + 1) / edgeSamples) * BLOCK_DEPTH;
const leftA = { x: -BLOCK_WIDTH / 2, y: heightAt(type, -BLOCK_WIDTH / 2, z0), z: z0 };
const leftB = { x: -BLOCK_WIDTH / 2, y: heightAt(type, -BLOCK_WIDTH / 2, z1), z: z1 };
addSideQuad(
leftA,
leftB,
colorForHeight(leftA.y, hash(i + 40 + seed)),
colorForHeight(leftB.y, hash(i + 41 + seed))
);
const rightA = { x: BLOCK_WIDTH / 2, y: heightAt(type, BLOCK_WIDTH / 2, z0), z: z0 };
const rightB = { x: BLOCK_WIDTH / 2, y: heightAt(type, BLOCK_WIDTH / 2, z1), z: z1 };
addSideQuad(
rightA,
rightB,
colorForHeight(rightA.y, hash(i + 60 + seed)),
colorForHeight(rightB.y, hash(i + 61 + seed))
);
}
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,
roughness: 0.96,
metalness: 0,
flatShading: true,
side: THREE.DoubleSide
});
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function createWaterRibbon(type) {
const positions = [];
const indices = [];
const segments = 42;
const zMin = -BLOCK_DEPTH / 2 + 0.35;
const zMax = BLOCK_DEPTH / 2 - 0.35;
for (let i = 0; i <= segments; i++) {
const t = i / segments;
const z = THREE.MathUtils.lerp(zMin, zMax, t);
const isGlacier = type === "glacial";
const center = isGlacier
? Math.sin(z * 0.18) * 0.25
: Math.sin(z * 0.34 + 0.8) * 0.16;
const halfWidth = isGlacier
? 3.15 - t * 0.35
: 0.4;
const leftX = center - halfWidth;
const rightX = center + halfWidth;
positions.push(
leftX, heightAt(type, leftX, z) + 0.075, z,
rightX, heightAt(type, rightX, z) + 0.075, z
);
if (i < segments) {
const a = i * 2;
indices.push(a, a + 2, a + 1, a + 1, a + 2, a + 3);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
color: type === "glacial" ? 0xa8e1e4 : 0x3e91a8,
roughness: type === "glacial" ? 0.42 : 0.3,
metalness: type === "glacial" ? 0.02 : 0.08,
flatShading: true
});
const mesh = new THREE.Mesh(geometry, material);
mesh.receiveShadow = true;
return mesh;
}
function createFlowLines(type) {
const group = new THREE.Group();
const offsets =
type === "glacial"
? [-1.8, -0.65, 0.65, 1.8]
: [-0.08, 0.08];
for (let lineIndex = 0; lineIndex < offsets.length; lineIndex++) {
const points = [];
const offset = offsets[lineIndex];
const segments = 36;
for (let i = 0; i <= segments; i++) {
const z = THREE.MathUtils.lerp(
-BLOCK_DEPTH / 2 + 0.7,
BLOCK_DEPTH / 2 - 0.7,
i / segments
);
const center =
type === "glacial"
? Math.sin(z * 0.18) * 0.25
: Math.sin(z * 0.34 + 0.8) * 0.16;
const x = center + offset;
points.push(
new THREE.Vector3(
x,
heightAt(type, x, z) + 0.12,
z
)
);
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineBasicMaterial({
color: type === "glacial" ? 0xe9ffff : 0x9fd5df,
transparent: true,
opacity: type === "glacial" ? 0.48 : 0.72
});
group.add(new THREE.Line(geometry, material));
}
return group;
}
function createProfileRibbon(type, color) {
const positions = [];
const segments = 100;
const thickness = 0.18;
for (let i = 0; i < segments; i++) {
const x0 = -BLOCK_WIDTH / 2 + (i / segments) * BLOCK_WIDTH;
const x1 = -BLOCK_WIDTH / 2 + ((i + 1) / segments) * BLOCK_WIDTH;
const y0 = heightAt(type, x0, BLOCK_DEPTH / 2);
const y1 = heightAt(type, x1, BLOCK_DEPTH / 2);
const dx = x1 - x0;
const dy = y1 - y0;
const length = Math.hypot(dx, dy);
const nx = (-dy / length) * thickness * 0.5;
const ny = (dx / length) * thickness * 0.5;
const z = 0.58;
positions.push(
x0 + nx, y0 + ny, z,
x0 - nx, y0 - ny, z,
x1 + nx, y1 + ny, z,
x1 + nx, y1 + ny, z,
x0 - nx, y0 - ny, z,
x1 - nx, y1 - ny, z
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.computeVertexNormals();
return new THREE.Mesh(
geometry,
new THREE.MeshBasicMaterial({
color,
toneMapped: false,
side: THREE.DoubleSide
})
);
}
function createCrossSection(type, accentColor) {
const group = new THREE.Group();
group.position.z = BLOCK_DEPTH / 2 + 0.29;
const shapePoints = [
new THREE.Vector2(-BLOCK_WIDTH / 2, BLOCK_BOTTOM)
];
const segments = 100;
for (let i = 0; i <= segments; i++) {
const x =
-BLOCK_WIDTH / 2 + (i / segments) * BLOCK_WIDTH;
const y = heightAt(type, x, BLOCK_DEPTH / 2);
shapePoints.push(new THREE.Vector2(x, y));
}
shapePoints.push(
new THREE.Vector2(BLOCK_WIDTH / 2, BLOCK_BOTTOM)
);
const shape = new THREE.Shape(shapePoints);
const panelGeometry = new THREE.ShapeGeometry(shape);
const panelMaterial = new THREE.MeshBasicMaterial({
color: accentColor,
transparent: true,
opacity: 0.11,
depthWrite: false,
side: THREE.DoubleSide,
toneMapped: false
});
const panel = new THREE.Mesh(panelGeometry, panelMaterial);
panel.renderOrder = 5;
group.add(panel);
group.add(createProfileRibbon(type, accentColor));
const floorY = heightAt(type, 0, BLOCK_DEPTH / 2) + 0.2;
const floorWidth = type === "glacial" ? 10.4 : 1.3;
const horizontal = new THREE.Mesh(
new THREE.BoxGeometry(floorWidth, 0.09, 0.16),
new THREE.MeshBasicMaterial({
color: accentColor,
toneMapped: false
})
);
horizontal.position.set(0, floorY, 0.78);
group.add(horizontal);
for (const x of [-floorWidth / 2, floorWidth / 2]) {
const tick = new THREE.Mesh(
new THREE.BoxGeometry(0.09, 0.38, 0.16),
horizontal.material
);
tick.position.set(x, floorY, 0.78);
group.add(tick);
}
return group;
}
function createValleyBlock(type, x, seed) {
const group = new THREE.Group();
group.position.x = x;
scene.add(group);
const plinth = new THREE.Mesh(
new THREE.BoxGeometry(BLOCK_WIDTH + 0.85, 0.6, BLOCK_DEPTH + 0.85),
new THREE.MeshStandardMaterial({
color: 0xdce3dd,
roughness: 0.88,
metalness: 0
})
);
plinth.position.y = -2.45;
plinth.castShadow = true;
plinth.receiveShadow = true;
group.add(plinth);
group.add(createTerrainMesh(type, seed));
group.add(createBlockSides(type, seed));
group.add(createWaterRibbon(type));
group.add(createFlowLines(type));
const accent =
type === "glacial" ? ICE_COLOR : FLUVIAL_COLOR;
group.add(createCrossSection(type, accent));
return group;
}
createValleyBlock("glacial", -20, 3);
createValleyBlock("river", 20, 17);
// Manual orthographic camera controls.
let azimuth = 0.52;
let polar = 1.08;
const radius = 96;
let zoom = 1;
let dragging = false;
let previousX = 0;
let previousY = 0;
function updateCamera() {
camera.position.set(
cameraTarget.x + radius * Math.sin(polar) * Math.sin(azimuth),
cameraTarget.y + radius * Math.cos(polar),
cameraTarget.z + radius * Math.sin(polar) * Math.cos(azimuth)
);
camera.lookAt(cameraTarget);
camera.zoom = zoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(55, 84 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
function resetView() {
azimuth = 0.52;
polar = 1.08;
zoom = 1;
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.classList.add("dragging");
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
azimuth -= dx * 0.006;
polar = clamp(polar + dy * 0.005, 0.55, 1.42);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
function stopDragging(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (
event &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("dblclick", resetView);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoom = clamp(
zoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.65
);
updateCamera();
},
{ passive: false }
);
document.getElementById("reset").addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
resetView();
}
});
window.addEventListener("resize", resize);
const glacialLabel = document.getElementById("glacial-label");
const riverLabel = document.getElementById("river-label");
const projected = new THREE.Vector3();
function positionWorldLabel(element, x, y, z) {
projected.set(x, y, z).project(camera);
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
element.style.visibility = projected.z < 1 ? "visible" : "hidden";
}
resize();
resetView();
function animate() {
requestAnimationFrame(animate);
positionWorldLabel(
glacialLabel,
-20,
-0.9,
BLOCK_DEPTH / 2 + 2.2
);
positionWorldLabel(
riverLabel,
20,
-0.9,
BLOCK_DEPTH / 2 + 2.2
);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```