Prompt specification
Build or customize the Three.js 3D scene "Mountain pass with snow sheds" 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: Mountain pass with snow sheds
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/mountain-pass-with-snow-sheds-x1251
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing snowpack and avalanche terrain. Compose a winding road, steep snow-covered slope, protective gallery, and drainage channel; the terrain must visibly explain why the road passes beneath the gallery. Voxel style.
Working Three.js Starter (mountain-pass-with-snow-sheds-x1251):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Snowpack & Avalanche Gallery</title>
<style>
:root {
--ink: #18313d;
--muted: #58717d;
--panel: rgba(247, 252, 253, 0.90);
--line: rgba(35, 77, 91, 0.18);
--cyan: #21a9c4;
--orange: #e88645;
--yellow: #f0c85c;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9d8e7;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas:active {
cursor: grabbing;
}
.brand,
.info,
.controls,
.callout {
position: absolute;
z-index: 5;
}
.brand {
top: 22px;
left: 24px;
width: min(430px, calc(100vw - 390px));
padding: 18px 20px 16px;
background: var(--panel);
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 16px;
box-shadow: 0 12px 34px rgba(28, 67, 82, 0.14);
backdrop-filter: blur(12px);
pointer-events: none;
}
.kicker,
.tag {
display: block;
margin-bottom: 7px;
color: #31849a;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 2.3vw, 34px);
line-height: 1.05;
letter-spacing: -0.04em;
}
.brand p {
margin: 10px 0 13px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 15px;
color: #425f6b;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
display: inline-block;
width: 14px;
height: 7px;
border-radius: 2px;
background: #eef6f7;
box-shadow: inset 0 -2px rgba(56, 89, 102, 0.16);
}
.swatch.path {
background: var(--cyan);
}
.swatch.road {
background: #354750;
}
.swatch.gallery {
background: #68777d;
}
.info {
top: 22px;
right: 24px;
width: 320px;
padding: 20px;
background: var(--panel);
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 16px;
box-shadow: 0 12px 34px rgba(28, 67, 82, 0.14);
backdrop-filter: blur(12px);
}
.info h2 {
margin: 0 0 9px;
font-size: 20px;
letter-spacing: -0.03em;
}
.info p {
margin: 0 0 15px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.diagram {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
margin: 0 0 14px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(226, 241, 245, 0.58);
}
.diagram div {
min-height: 43px;
padding: 9px 10px;
border-radius: 6px;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.diagram .snowpack {
grid-column: 1 / -1;
background: #d9ebf0;
border-left: 5px solid #93adba;
}
.diagram .flow {
grid-column: 1 / -1;
min-height: 28px;
padding: 6px 10px;
color: #087d99;
background: rgba(33, 169, 196, 0.14);
text-align: center;
}
.diagram .shed {
color: white;
background: #68777d;
}
.diagram .protected {
color: white;
background: #354750;
}
.logic {
display: grid;
gap: 8px;
color: #435f6b;
font-size: 11px;
line-height: 1.4;
}
.logic div {
position: relative;
padding-left: 17px;
}
.logic div::before {
content: "";
position: absolute;
top: 5px;
left: 0;
width: 7px;
height: 7px;
background: var(--cyan);
border-radius: 2px;
}
.callout {
left: 0;
top: 0;
min-width: 132px;
max-width: 210px;
padding: 8px 10px;
transform: translate(-50%, -100%);
background: rgba(250, 253, 254, 0.91);
border: 1px solid rgba(255, 255, 255, 0.9);
border-radius: 8px;
box-shadow: 0 6px 16px rgba(29, 68, 83, 0.15);
pointer-events: none;
transition: opacity 160ms ease;
}
.callout::after {
content: "";
position: absolute;
left: 50%;
bottom: -17px;
width: 2px;
height: 17px;
background: rgba(28, 86, 103, 0.65);
}
.callout b {
display: block;
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.callout small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
line-height: 1.35;
}
.callout.path b {
color: #0785a2;
}
.callout.gallery b {
color: #53636a;
}
.callout.road b {
color: #263f4b;
}
.callout.water b {
color: #1788a3;
}
.controls {
left: 50%;
bottom: 22px;
display: flex;
align-items: center;
gap: 8px;
padding: 7px;
transform: translateX(-50%);
background: rgba(247, 252, 253, 0.9);
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 12px;
box-shadow: 0 10px 26px rgba(26, 65, 80, 0.16);
backdrop-filter: blur(10px);
}
.controls button {
min-width: 40px;
height: 36px;
padding: 0 12px;
border: 0;
border-radius: 8px;
color: #294854;
background: #e3eef1;
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition: background 150ms ease, transform 150ms ease;
}
.controls button:hover {
background: #d4e7eb;
transform: translateY(-1px);
}
.controls button.active {
color: white;
background: #268fa8;
}
.hint {
padding: 0 8px;
color: #647c86;
font-size: 10px;
white-space: nowrap;
}
.labels-off .callout {
opacity: 0 !important;
}
#loading {
position: absolute;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: #294b5a;
background: #c6e0e9;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hide {
opacity: 0;
pointer-events: none;
}
@media (max-width: 800px) {
.brand {
left: 12px;
top: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
.brand p,
.legend {
display: none;
}
.info {
top: auto;
right: 12px;
bottom: 78px;
width: 250px;
padding: 14px;
}
.info p,
.logic {
display: none;
}
.diagram {
margin-bottom: 0;
}
.controls {
bottom: 12px;
}
.hint {
display: none;
}
.callout {
min-width: 104px;
padding: 6px 8px;
}
.callout small {
display: none;
}
}
</style>
</head>
<body>
<div id="loading">Building alpine terrain…</div>
<section class="brand">
<span class="kicker">Alpine infrastructure / field study 03</span>
<h1>Snowpack & Avalanche Gallery</h1>
<p>
A voxel terrain study showing how a steep, snow-loaded chute is separated
from a winding road by a protective snow gallery.
</p>
<div class="legend">
<span><i class="swatch"></i>Snowpack</span>
<span><i class="swatch path"></i>Slide path</span>
<span><i class="swatch road"></i>Road</span>
<span><i class="swatch gallery"></i>Gallery</span>
</div>
</section>
<aside class="info">
<span class="tag">Why the road goes below</span>
<h2>Gallery logic</h2>
<p>
The road curves along the valley toe. Directly above it, a steep snow
chute feeds avalanche debris toward the structure.
</p>
<div class="diagram" aria-label="Gallery protection diagram">
<div class="snowpack">Steep snowpack</div>
<div class="flow">↓ Avalanche debris</div>
<div class="shed">Uphill wall + roof</div>
<div class="protected">Protected road below</div>
</div>
<div class="logic">
<div>The solid uphill wall intercepts moving snow and ice.</div>
<div>The roof carries debris over the traffic lane.</div>
<div>The open downhill side preserves visibility and access.</div>
<div>The lined channel carries meltwater away from the road.</div>
</div>
</aside>
<div class="callout" id="label-snowpack">
<b>Steep snowpack</b>
<small>Terraced, snow-loaded upper slope</small>
</div>
<div class="callout path" id="label-path">
<b>Avalanche chute</b>
<small>Debris funnels toward the uphill wall</small>
</div>
<div class="callout gallery" id="label-gallery">
<b>Protective gallery</b>
<small>Roof and retaining wall form a snow shed</small>
</div>
<div class="callout road" id="label-road">
<b>Road below</b>
<small>The winding route passes through the open gallery</small>
</div>
<div class="callout water" id="label-water">
<b>Drainage channel</b>
<small>Lined channel carries snowmelt to the outfall</small>
</div>
<div class="controls">
<button id="reset-view" title="Reset camera">Reset view</button>
<button id="toggle-flow" class="active">Avalanche flow</button>
<button id="toggle-labels" class="active">Labels</button>
<span class="hint">Drag to orbit · Scroll to zoom</span>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Renderer, scene and camera
// ---------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb9d8e7);
scene.fog = new THREE.Fog(0xb9d8e7, 48, 86);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
150
);
const view = {
target: new THREE.Vector3(0, 3.2, -1.5),
yaw: 0.57,
pitch: 0.49,
radius: 39
};
function updateCamera() {
const cp = Math.cos(view.pitch);
camera.position.set(
view.target.x + view.radius * cp * Math.sin(view.yaw),
view.target.y + view.radius * Math.sin(view.pitch),
view.target.z + view.radius * cp * Math.cos(view.yaw)
);
camera.lookAt(view.target);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xf1fbff, 0x53656c, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff2d9, 3.1);
sun.position.set(-13, 24, 16);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -28;
sun.shadow.camera.right = 28;
sun.shadow.camera.top = 28;
sun.shadow.camera.bottom = -28;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00045;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9ed9ec, 0.65);
fill.position.set(18, 8, -12);
scene.add(fill);
// ---------------------------------------------------------------------
// Shared materials and geometry helpers
// ---------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materials = {
rock: new THREE.MeshStandardMaterial({
color: 0x697a82,
roughness: 0.96,
metalness: 0
}),
snow: new THREE.MeshStandardMaterial({
color: 0xf2f7f6,
roughness: 0.91
}),
snowBlue: new THREE.MeshStandardMaterial({
color: 0xdceef2,
roughness: 0.93
}),
asphalt: new THREE.MeshStandardMaterial({
color: 0x35464e,
roughness: 0.93
}),
foundation: new THREE.MeshStandardMaterial({
color: 0x5a666b,
roughness: 0.95
}),
lane: new THREE.MeshStandardMaterial({
color: 0xf0ca63,
roughness: 0.8
}),
concrete: new THREE.MeshStandardMaterial({
color: 0x68767c,
roughness: 0.9
}),
concreteLight: new THREE.MeshStandardMaterial({
color: 0x8b989c,
roughness: 0.92
}),
water: new THREE.MeshStandardMaterial({
color: 0x27b8d0,
emissive: 0x0a7185,
emissiveIntensity: 0.3,
roughness: 0.25,
metalness: 0.05
}),
path: new THREE.MeshStandardMaterial({
color: 0x2bb8d0,
emissive: 0x117c92,
emissiveIntensity: 0.4,
transparent: true,
opacity: 0.8,
roughness: 0.5
}),
avalancheSnow: new THREE.MeshStandardMaterial({
color: 0xd8f4fb,
emissive: 0x143d48,
emissiveIntensity: 0.15,
roughness: 0.86
}),
trunk: new THREE.MeshStandardMaterial({
color: 0x655447,
roughness: 1
}),
pine: new THREE.MeshStandardMaterial({
color: 0x315c50,
roughness: 1
}),
pineDark: new THREE.MeshStandardMaterial({
color: 0x24483f,
roughness: 1
}),
warning: new THREE.MeshStandardMaterial({
color: 0xe78343,
roughness: 0.78
}),
warningLight: new THREE.MeshStandardMaterial({
color: 0xffd66c,
roughness: 0.7
})
};
function addBox(
width,
height,
depth,
material,
x,
y,
z,
castShadow = true,
receiveShadow = true
) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
scene.add(mesh);
return mesh;
}
function addSegment(
a,
b,
width,
height,
y,
material,
offset = 0,
castShadow = true,
receiveShadow = true
) {
const dx = b.x - a.x;
const dz = b.z - a.z;
const length = Math.hypot(dx, dz);
const normal = new THREE.Vector3(-dz / length, 0, dx / length);
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(length * 1.025, height, width);
mesh.position.set(
(a.x + b.x) * 0.5 + normal.x * offset,
y,
(a.z + b.z) * 0.5 + normal.z * offset
);
mesh.rotation.y = -Math.atan2(dz, dx);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
scene.add(mesh);
return mesh;
}
let seed = 73129;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
// ---------------------------------------------------------------------
// Terrain functions: winding road at the toe of a steep mountain
// ---------------------------------------------------------------------
function roadZ(x) {
return 3.4 + 1.55 * Math.sin((x + 4) * 0.23);
}
function roadPoint(x) {
return new THREE.Vector3(x, 0, roadZ(x));
}
function noise2(x, z) {
const n = Math.sin(x * 12.9898 + z * 78.233) * 43758.5453;
return n - Math.floor(n);
}
function heightAt(x, z) {
const uphill = roadZ(x) - z;
const t = THREE.MathUtils.clamp((uphill - 2.0) / 13, 0, 1);
const ridge =
0.93 +
0.10 * Math.cos(x * 0.23) +
0.06 * Math.sin(z * 0.37);
// A central depression creates a recognizable avalanche chute.
const chute =
2.35 *
t *
Math.exp(-Math.pow((x - 0.6) / 3.0, 2));
const rough =
0.16 *
Math.sin(x * 1.7 + z * 0.8) *
Math.min(1, t * 3);
return (
0.72 +
11.8 * Math.pow(t, 1.13) * ridge -
chute +
rough
);
}
function offsetRoadPoint(x, offset, y = 0) {
const derivative =
(roadZ(x + 0.01) - roadZ(x - 0.01)) / 0.02;
const length = Math.hypot(1, derivative);
const normal = new THREE.Vector3(
-derivative / length,
0,
1 / length
);
return roadPoint(x).addScaledVector(normal, offset).setY(y);
}
// Dark base makes the block-built terrain edges read as a cutaway model.
addBox(
38,
1.0,
32,
materials.foundation,
0,
-0.3,
0,
false,
true
);
const cell = 0.75;
const xMin = -18;
const xMax = 18;
const zMin = -15;
const zMax = 15;
const nx = Math.round((xMax - xMin) / cell) + 1;
const nz = Math.round((zMax - zMin) / cell) + 1;
const columnCount = nx * nz;
const terrainRock = new THREE.InstancedMesh(
unitBox,
materials.rock,
columnCount
);
const terrainSnow = new THREE.InstancedMesh(
unitBox,
materials.snow,
columnCount
);
terrainRock.castShadow = true;
terrainRock.receiveShadow = true;
terrainSnow.castShadow = true;
terrainSnow.receiveShadow = true;
const dummy = new THREE.Object3D();
const instanceColor = new THREE.Color();
let instanceIndex = 0;
for (let iz = 0; iz < nz; iz++) {
const z = zMin + iz * cell;
for (let ix = 0; ix < nx; ix++) {
const x = xMin + ix * cell;
const height = heightAt(x, z);
const rockHeight = Math.max(0.12, height - 0.19);
dummy.position.set(x, rockHeight * 0.5, z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(cell * 0.995, rockHeight, cell * 0.995);
dummy.updateMatrix();
terrainRock.setMatrixAt(instanceIndex, dummy.matrix);
const rockLight = 0.25 + noise2(x, z) * 0.12;
instanceColor.setHSL(0.56, 0.10, rockLight);
terrainRock.setColorAt(instanceIndex, instanceColor);
// Some exposed cliff cells have smaller snow caps.
const exposed = noise2(x + 91, z - 41) > 0.83;
const capWidth = cell * (exposed ? 0.68 : 0.995);
const capDepth = cell * (exposed ? 0.72 : 0.995);
dummy.position.set(x, height - 0.095, z);
dummy.scale.set(capWidth, 0.19, capDepth);
dummy.updateMatrix();
terrainSnow.setMatrixAt(instanceIndex, dummy.matrix);
instanceColor.setHSL(
0.55,
0.18 + noise2(x - 23, z + 12) * 0.08,
0.86 + noise2(x + 8, z + 52) * 0.07
);
terrainSnow.setColorAt(instanceIndex, instanceColor);
instanceIndex++;
}
}
terrainRock.instanceMatrix.needsUpdate = true;
terrainRock.instanceColor.needsUpdate = true;
terrainSnow.instanceMatrix.needsUpdate = true;
terrainSnow.instanceColor.needsUpdate = true;
terrainRock.computeBoundingSphere();
terrainSnow.computeBoundingSphere();
scene.add(terrainRock, terrainSnow);
// ---------------------------------------------------------------------
// Winding road, snow berms and lane markers
// ---------------------------------------------------------------------
for (let x = xMin; x < xMax - 0.01; x += 0.5) {
const a = roadPoint(x);
const b = roadPoint(Math.min(x + 0.5, xMax));
addSegment(
a,
b,
2.6,
0.27,
0.78,
materials.foundation,
0,
false,
true
);
addSegment(
a,
b,
2.5,
0.18,
0.94,
materials.asphalt,
0,
false,
true
);
}
for (let x = -17.4; x < 17.0; x += 1.12) {
const a = roadPoint(x);
const b = roadPoint(Math.min(x + 0.92, xMax));
addSegment(
a,
b,
0.27,
0.22,
1.08,
materials.snow,
-1.37,
false,
true
);
addSegment(
a,
b,
0.27,
0.22,
1.08,
materials.snow,
1.37,
false,
true
);
}
for (let x = -17.6; x < 17.3; x += 1.55) {
const a = roadPoint(x);
const b = roadPoint(x + 0.72);
addSegment(
a,
b,
0.085,
0.025,
1.048,
materials.lane,
0,
false,
false
);
}
// ---------------------------------------------------------------------
// Open-sided protective gallery over the road
// ---------------------------------------------------------------------
const galleryStart = -5.25;
const galleryEnd = 5.25;
for (let x = galleryStart; x < galleryEnd - 0.01; x += 0.6) {
const next = Math.min(x + 0.6, galleryEnd);
const a = roadPoint(x);
const b = roadPoint(next);
// Main roof slab.
addSegment(
a,
b,
4.75,
0.36,
3.15,
materials.concrete,
0
);
// Snow on top of the roof.
addSegment(
a,
b,
4.83,
0.17,
3.415,
materials.snow,
0
);
// The uphill retaining wall intercepts avalanche debris.
addSegment(
a,
b,
0.38,
1.83,
2.03,
materials.concreteLight,
-1.88
);
}
const postPositions = [-5.15, -3.65, -2.15, -0.65, 0.85, 2.35, 3.85, 5.15];
for (const x of postPositions) {
for (const side of [-1, 1]) {
const p = offsetRoadPoint(x, side * 1.72, 1.96);
addBox(
0.34,
2.18,
0.34,
materials.concrete,
p.x,
p.y,
p.z
);
const foot = offsetRoadPoint(x, side * 1.72, 0.88);
addBox(
0.52,
0.18,
0.52,
materials.concreteLight,
foot.x,
foot.y,
foot.z
);
}
}
// Small voxel icicles along the open downhill edge.
for (let x = -4.9; x < 5.2; x += 1.2) {
const p = offsetRoadPoint(x, 2.22, 2.91);
addBox(
0.12,
0.42 + random() * 0.18,
0.12,
materials.snow,
p.x,
p.y,
p.z,
false,
false
);
}
// Snow and ice caught on the roof illustrate its protective purpose.
for (let i = 0; i < 12; i++) {
const x = -4.7 + i * 0.82 + (random() - 0.5) * 0.25;
const p = offsetRoadPoint(x, -0.45 + random() * 0.9, 3.64);
const size = 0.32 + random() * 0.40;
addBox(
size,
size * 0.65,
size * 0.85,
i % 3 === 0 ? materials.avalancheSnow : materials.snow,
p.x,
p.y,
p.z
);
}
// A small debris pile beyond the gallery's downhill end.
for (let i = 0; i < 11; i++) {
const x = 6.0 + random() * 2.5;
const z = roadZ(x) + 2.3 + random() * 1.5;
const size = 0.35 + random() * 0.65;
addBox(
size,
size * 0.75,
size,
random() > 0.5 ? materials.snow : materials.avalancheSnow,
x,
0.82 + size * 0.35,
z
);
}
// ---------------------------------------------------------------------
// Drainage channel: concrete U-section, blue meltwater and an outfall
// ---------------------------------------------------------------------
const channelOffset = 2.58;
for (let x = xMin; x < xMax - 0.01; x += 0.75) {
const next = Math.min(x + 0.75, xMax);
const a = roadPoint(x);
const b = roadPoint(next);
addSegment(
a,
b,
0.78,
0.12,
0.77,
materials.concreteLight,
channelOffset,
false,
true
);
addSegment(
a,
b,
0.55,
0.04,
0.85,
materials.water,
channelOffset,
false,
false
);
addSegment(
a,
b,
0.13,
0.31,
0.91,
materials.concrete,
channelOffset - 0.43,
false,
true
);
addSegment(
a,
b,
0.13,
0.31,
0.91,
materials.concrete,
channelOffset + 0.43,
false,
true
);
}
const outletX = 17.15;
const outletStart = offsetRoadPoint(outletX, channelOffset);
const outletEnd = new THREE.Vector3(outletX, 0, 10.8);
addSegment(
outletStart,
outletEnd,
0.78,
0.12,
0.77,
materials.concreteLight,
0,
false,
true
);
addSegment(
outletStart,
outletEnd,
0.55,
0.04,
0.85,
materials.water,
0,
false,
false
);
addBox(
2.1,
0.06,
1.25,
materials.water,
outletX,
0.84,
11.0,
false,
false
);
// ---------------------------------------------------------------------
// Avalanche route markers and animated voxel snow chunks
// ---------------------------------------------------------------------
const avalancheGroup = new THREE.Group();
scene.add(avalancheGroup);
const routeStartZ = -12.0;
const routeEndZ = roadZ(0.6) - 2.35;
function routeX(z) {
return 0.6 + 0.45 * Math.sin((z + 9) * 0.42);
}
for (let i = 0; i < 25; i++) {
const t = i / 24;
const z = THREE.MathUtils.lerp(routeStartZ, routeEndZ, t);
const x = routeX(z);
const y = heightAt(x, z) + 0.12;
const marker = new THREE.Mesh(unitBox, materials.path);
marker.scale.set(0.42, 0.075, 0.88);
marker.position.set(x, y, z);
marker.rotation.y = -0.18 * Math.sin(i * 0.9);
marker.castShadow = false;
avalancheGroup.add(marker);
}
// Voxel arrowheads make the downhill movement direction explicit.
for (const t of [0.2, 0.43, 0.67, 0.84]) {
const z = THREE.MathUtils.lerp(routeStartZ, routeEndZ, t);
const x = routeX(z);
const y = heightAt(x, z) + 0.18;
const widths = [0.72, 0.48, 0.24];
for (let j = 0; j < widths.length; j++) {
const arrow = new THREE.Mesh(unitBox, materials.path);
arrow.scale.set(widths[j], 0.09, 0.19);
arrow.position.set(x, y, z + j * 0.19);
arrow.castShadow = false;
avalancheGroup.add(arrow);
}
}
const avalancheChunks = [];
for (let i = 0; i < 13; i++) {
const chunk = new THREE.Mesh(unitBox, materials.avalancheSnow);
const size = 0.28 + random() * 0.48;
chunk.scale.set(size, size * 0.8, size * 1.12);
chunk.castShadow = true;
chunk.receiveShadow = true;
chunk.userData.phase = i / 13;
chunk.userData.spin = (random() - 0.5) * 2.4;
avalancheGroup.add(chunk);
avalancheChunks.push(chunk);
}
// ---------------------------------------------------------------------
// Blocky alpine trees, rocks and drifts
// ---------------------------------------------------------------------
function addTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, heightAt(x, z), z);
group.scale.setScalar(scale);
const trunk = new THREE.Mesh(unitBox, materials.trunk);
trunk.scale.set(0.26, 1.15, 0.26);
trunk.position.y = 0.57;
trunk.castShadow = true;
group.add(trunk);
const foliageLayers = [
{ s: 1.48, y: 1.08, h: 0.65 },
{ s: 1.12, y: 1.61, h: 0.62 },
{ s: 0.72, y: 2.09, h: 0.58 }
];
for (let i = 0; i < foliageLayers.length; i++) {
const layer = foliageLayers[i];
const foliage = new THREE.Mesh(
unitBox,
i === 1 ? materials.pineDark : materials.pine
);
foliage.scale.set(layer.s, layer.h, layer.s);
foliage.position.y = layer.y;
foliage.castShadow = true;
foliage.receiveShadow = true;
group.add(foliage);
const cap = new THREE.Mesh(unitBox, materials.snow);
cap.scale.set(layer.s * 1.04, 0.16, layer.s * 1.04);
cap.position.y = layer.y + layer.h * 0.5 + 0.055;
cap.castShadow = true;
group.add(cap);
}
scene.add(group);
}
let treeCount = 0;
for (let attempt = 0; attempt < 500 && treeCount < 31; attempt++) {
const x = -16.5 + random() * 33;
const z = -13 + random() * (roadZ(x) + 7);
if (z > roadZ(x) - 3.2) continue;
if (Math.abs(x - 0.6) < 4.2) continue;
if (heightAt(x, z) < 1.7) continue;
addTree(x, z, 0.72 + random() * 0.55);
treeCount++;
}
for (let i = 0; i < 34; i++) {
const x = -17 + random() * 34;
const z = -12.5 + random() * 24;
if (z > roadZ(x) - 2.4 && Math.abs(x) < 16) {
// Keep the road and drainage corridor clear.
continue;
}
const baseY = heightAt(x, z);
const size = 0.35 + random() * 0.85;
const rock = addBox(
size,
size * (0.5 + random() * 0.6),
size,
materials.rock,
x,
baseY + size * 0.25,
z
);
rock.rotation.y = random() * Math.PI;
if (random() > 0.25) {
addBox(
size * 0.86,
0.13,
size * 0.82,
materials.snow,
x,
baseY + size * 0.58,
z
);
}
}
// Wind-shaped snow drifts on the open valley floor.
for (let i = 0; i < 24; i++) {
const side = i % 2 === 0 ? -1 : 1;
const x = side * (8 + random() * 8);
const z = roadZ(x) + 3.6 + random() * 8;
const width = 0.7 + random() * 1.8;
const depth = 0.45 + random() * 1.1;
addBox(
width,
0.16 + random() * 0.18,
depth,
materials.snow,
x,
0.82,
z
);
}
// ---------------------------------------------------------------------
// Avalanche warning sign at the gallery entrance
// ---------------------------------------------------------------------
const warningPosition = offsetRoadPoint(-6.0, -1.55);
addBox(
0.11,
1.55,
0.11,
materials.concrete,
warningPosition.x,
1.48,
warningPosition.z
);
addBox(
0.95,
0.72,
0.12,
materials.warning,
warningPosition.x,
2.18,
warningPosition.z
);
// Pixel-like warning symbol.
addBox(
0.50,
0.12,
0.06,
materials.warningLight,
warningPosition.x,
2.18,
warningPosition.z + 0.10
);
addBox(
0.12,
0.36,
0.06,
materials.warningLight,
warningPosition.x,
2.22,
warningPosition.z + 0.10
);
// ---------------------------------------------------------------------
// Projected HTML callouts
// ---------------------------------------------------------------------
const labels = [
{
element: document.getElementById("label-snowpack"),
anchor: new THREE.Vector3(-6.6, heightAt(-6.6, -8.2) + 0.8, -8.2),
dx: -55,
dy: -18
},
{
element: document.getElementById("label-path"),
anchor: new THREE.Vector3(
routeX(-3.5),
heightAt(routeX(-3.5), -3.5) + 0.8,
-3.5
),
dx: 48,
dy: -12
},
{
element: document.getElementById("label-gallery"),
anchor: new THREE.Vector3(1.8, 3.75, roadZ(1.8)),
dx: 58,
dy: -8
},
{
element: document.getElementById("label-road"),
anchor: new THREE.Vector3(0, 1.12, roadZ(0)),
dx: -60,
dy: 16
},
{
element: document.getElementById("label-water"),
anchor: offsetRoadPoint(10.4, channelOffset, 1.1),
dx: 15,
dy: 15
}
];
const projected = new THREE.Vector3();
function updateLabels() {
for (const label of labels) {
projected.copy(label.anchor).project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.opacity = visible ? "1" : "0";
label.element.style.left =
(projected.x * 0.5 + 0.5) * window.innerWidth + label.dx + "px";
label.element.style.top =
(-projected.y * 0.5 + 0.5) * window.innerHeight + label.dy + "px";
}
}
// ---------------------------------------------------------------------
// Custom orbit controls — no external controls module
// ---------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
view.yaw -= dx * 0.006;
view.pitch = THREE.MathUtils.clamp(
view.pitch + dy * 0.0045,
0.22,
1.08
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius + event.deltaY * 0.018,
22,
56
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
function resetView() {
view.target.set(0, 3.2, -1.5);
view.yaw = 0.57;
view.pitch = 0.49;
view.radius = 39;
updateCamera();
}
document.getElementById("reset-view").addEventListener("click", resetView);
document.getElementById("toggle-flow").addEventListener("click", (event) => {
avalancheGroup.visible = !avalancheGroup.visible;
event.currentTarget.classList.toggle("active", avalancheGroup.visible);
});
document
.getElementById("toggle-labels")
.addEventListener("click", (event) => {
document.body.classList.toggle("labels-off");
event.currentTarget.classList.toggle(
"active",
!document.body.classList.contains("labels-off")
);
});
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetView();
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
if (avalancheGroup.visible) {
for (const chunk of avalancheChunks) {
const t = (elapsed * 0.052 + chunk.userData.phase) % 1;
const z = THREE.MathUtils.lerp(routeStartZ, routeEndZ, t);
const x = routeX(z);
const y =
heightAt(x, z) +
0.25 +
Math.sin(t * Math.PI) * 0.38;
chunk.position.set(x, y, z);
chunk.rotation.x = elapsed * chunk.userData.spin;
chunk.rotation.y = elapsed * chunk.userData.spin * 0.7;
const fade = Math.min(1, (1 - t) * 6);
chunk.scale.multiplyScalar(1);
chunk.material.opacity = fade;
}
}
updateCamera();
updateLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hide");
});
</script>
</body>
</html>
```