Prompt specification
Build or customize the Three.js 3D scene "Seasonal mountain valley travel routes" 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: Seasonal mountain valley travel routes
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/seasonal-mountain-valley-travel-routes-x1347
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows seasonal changes to mountain travel routes. Create a valley with a high pass, lower tunnel, and two settlements. Toggle a schematic snow condition that closes the pass while leaving the alternative route open. Low-poly.
Working Three.js Starter (seasonal-mountain-valley-travel-routes-x1347):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Seasonal Mountain Routes</title>
<style>
:root {
--ink: #19323a;
--muted: #62777d;
--panel: rgba(248, 252, 252, 0.88);
--border: rgba(33, 69, 76, 0.15);
--green: #21a77f;
--green-soft: #d9f4e9;
--amber: #edae45;
--red: #d7514b;
--red-soft: #fbe3df;
--shadow: 0 18px 55px rgba(28, 56, 63, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cbdde4;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
linear-gradient(180deg, rgba(19, 49, 57, 0.08), transparent 22%),
radial-gradient(circle at 50% 45%, transparent 52%, rgba(20, 46, 54, 0.12));
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.brand {
position: absolute;
top: 24px;
left: 26px;
max-width: 470px;
text-shadow: 0 1px 18px rgba(255, 255, 255, 0.65);
}
.eyebrow {
margin-bottom: 8px;
color: #2e626a;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(34px, 4vw, 58px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.045em;
}
.brand p {
max-width: 390px;
margin: 12px 0 0;
color: #526e75;
font-size: 14px;
line-height: 1.55;
}
.panel {
position: absolute;
top: 22px;
right: 22px;
width: 320px;
padding: 18px;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 22px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(16px) saturate(1.1);
pointer-events: auto;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 14px;
}
.panel-heading span {
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.weather-badge {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 6px 9px;
border-radius: 999px;
background: #e4f1f4;
color: #35626b;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: 300ms ease;
}
.weather-badge::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: #4ca88e;
content: "";
box-shadow: 0 0 0 4px rgba(76, 168, 142, 0.12);
}
.snow-on .weather-badge {
background: #e2ebf2;
color: #486473;
}
.snow-on .weather-badge::before {
background: #7da4ba;
box-shadow: 0 0 0 4px rgba(125, 164, 186, 0.16);
}
.toggle {
display: grid;
grid-template-columns: 48px 1fr;
align-items: center;
gap: 13px;
width: 100%;
padding: 14px;
border: 1px solid var(--border);
border-radius: 16px;
background: rgba(255, 255, 255, 0.62);
color: var(--ink);
text-align: left;
cursor: pointer;
transition: border-color 180ms ease, background 180ms ease,
transform 180ms ease;
}
.toggle:hover {
border-color: rgba(33, 106, 96, 0.35);
transform: translateY(-1px);
}
.toggle:active {
transform: translateY(0);
}
.toggle-track {
position: relative;
display: block;
width: 48px;
height: 28px;
border-radius: 999px;
background: #b8c6c9;
transition: background 220ms ease;
}
.toggle-thumb {
position: absolute;
top: 4px;
left: 4px;
width: 20px;
height: 20px;
border-radius: 50%;
background: white;
box-shadow: 0 3px 10px rgba(24, 52, 59, 0.25);
transition: transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.toggle[aria-checked="true"] .toggle-track {
background: #5f8fa5;
}
.toggle[aria-checked="true"] .toggle-thumb {
transform: translateX(20px);
}
.toggle strong,
.toggle small {
display: block;
}
.toggle strong {
margin-bottom: 3px;
font-size: 14px;
}
.toggle small {
color: var(--muted);
font-size: 11px;
}
.condition-copy {
min-height: 44px;
margin: 13px 2px 15px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.route-list {
display: grid;
gap: 8px;
}
.route-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 11px 12px;
border: 1px solid var(--border);
border-radius: 13px;
background: rgba(255, 255, 255, 0.48);
}
.route-name {
display: flex;
align-items: center;
gap: 9px;
font-size: 12px;
font-weight: 700;
}
.route-name i {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--amber);
box-shadow: 0 0 0 4px rgba(237, 174, 69, 0.13);
transition: background 200ms ease, box-shadow 200ms ease;
}
.route-row.tunnel .route-name i {
background: var(--green);
box-shadow: 0 0 0 4px rgba(33, 167, 127, 0.13);
}
.route-state {
padding: 5px 8px;
border-radius: 8px;
background: var(--green-soft);
color: #18775f;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.1em;
}
.route-row.closed .route-state {
background: var(--red-soft);
color: #aa3936;
}
.route-row.closed .route-name i {
background: var(--red);
box-shadow: 0 0 0 4px rgba(215, 81, 75, 0.13);
}
.view-switcher {
position: absolute;
left: 50%;
bottom: 23px;
display: flex;
gap: 4px;
padding: 5px;
border: 1px solid rgba(255, 255, 255, 0.6);
border-radius: 14px;
background: rgba(248, 252, 252, 0.82);
box-shadow: 0 10px 32px rgba(25, 54, 62, 0.15);
backdrop-filter: blur(14px);
transform: translateX(-50%);
pointer-events: auto;
}
.view-switcher button {
padding: 9px 13px;
border: 0;
border-radius: 10px;
background: transparent;
color: #637a80;
font-size: 11px;
font-weight: 750;
cursor: pointer;
}
.view-switcher button:hover,
.view-switcher button.active {
background: #e2edef;
color: #254e57;
}
.legend {
position: absolute;
bottom: 25px;
left: 26px;
display: flex;
align-items: center;
gap: 16px;
color: #4c6970;
font-size: 11px;
font-weight: 700;
text-shadow: 0 1px 10px rgba(255, 255, 255, 0.7);
}
.legend span {
display: flex;
align-items: center;
gap: 7px;
}
.legend i {
width: 18px;
height: 4px;
border-radius: 3px;
background: var(--amber);
}
.legend .alternative {
background: var(--green);
}
.hint {
position: absolute;
right: 25px;
bottom: 28px;
color: rgba(47, 76, 83, 0.72);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.03em;
}
#labels {
position: fixed;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 10px;
background: rgba(249, 253, 252, 0.86);
box-shadow: 0 8px 25px rgba(31, 58, 64, 0.16);
color: #284e57;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.03em;
white-space: nowrap;
transform: translate(-50%, -100%);
transition: opacity 150ms ease;
backdrop-filter: blur(8px);
}
.world-label::after {
position: absolute;
bottom: -5px;
left: 50%;
width: 8px;
height: 8px;
border-right: 1px solid rgba(255, 255, 255, 0.72);
border-bottom: 1px solid rgba(255, 255, 255, 0.72);
background: rgba(249, 253, 252, 0.86);
content: "";
transform: translateX(-50%) rotate(45deg);
}
.world-label small {
display: block;
margin-top: 2px;
color: #769096;
font-size: 8px;
font-weight: 700;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.world-label.pass {
border-color: rgba(237, 174, 69, 0.45);
}
.world-label.pass.closed {
border-color: rgba(215, 81, 75, 0.58);
background: rgba(255, 242, 239, 0.91);
color: #a43935;
}
.world-label.tunnel {
border-color: rgba(33, 167, 127, 0.42);
}
@media (max-width: 760px) {
.brand {
top: 16px;
left: 17px;
}
.brand p {
display: none;
}
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
padding: 13px;
border-radius: 18px;
}
.panel-heading,
.condition-copy {
display: none;
}
.toggle {
padding: 10px;
}
.route-list {
grid-template-columns: 1fr 1fr;
margin-top: 9px;
}
.route-row {
padding: 9px;
}
.route-name {
font-size: 10px;
}
.route-state {
padding: 4px 6px;
font-size: 8px;
}
.view-switcher {
bottom: 238px;
}
.view-switcher button {
padding: 8px 10px;
font-size: 10px;
}
.legend,
.hint {
display: none;
}
.world-label {
font-size: 8px;
padding: 5px 7px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="vignette"></div>
<div class="hud">
<header class="brand">
<div class="eyebrow">Alpine route study · Winter operations</div>
<h1>Seasonal<br />Mountain Routes</h1>
<p>
A schematic valley showing how winter conditions can close the high
pass while the lower tunnel preserves access between both settlements.
</p>
</header>
<aside class="panel" aria-label="Route conditions">
<div class="panel-heading">
<span>Live route status</span>
<div class="weather-badge" id="weatherBadge">Clear weather</div>
</div>
<button
class="toggle"
id="snowToggle"
type="button"
role="switch"
aria-checked="false"
aria-label="Toggle schematic snow condition"
>
<span class="toggle-track"><span class="toggle-thumb"></span></span>
<span>
<strong>Snow event</strong>
<small>Schematic winter closure</small>
</span>
</button>
<p class="condition-copy" id="conditionCopy">
Both routes are open. The high pass is exposed to winter conditions.
</p>
<div class="route-list">
<div class="route-row pass" id="passRow">
<span class="route-name"><i></i>High pass</span>
<span class="route-state" id="passState">Open</span>
</div>
<div class="route-row tunnel">
<span class="route-name"><i></i>Lower tunnel</span>
<span class="route-state">Open</span>
</div>
</div>
</aside>
<div class="legend">
<span><i id="passLegend"></i>High pass route</span>
<span><i class="alternative"></i>Lower tunnel route</span>
</div>
<nav class="view-switcher" aria-label="Camera views">
<button class="active" type="button" data-view="overview">Overview</button>
<button type="button" data-view="pass">High pass</button>
<button type="button" data-view="tunnel">Lower tunnel</button>
</nav>
<div class="hint">Drag to orbit · Scroll or pinch to zoom · Press S for snow</div>
</div>
<div id="labels">
<div class="world-label" id="labelVillageA">
Pinehaven
<small>West settlement</small>
</div>
<div class="world-label" id="labelVillageB">
Silverbrook
<small>East settlement</small>
</div>
<div class="world-label pass" id="labelPass">
High pass · 2,840 m
<small id="passLabelState">Route open</small>
</div>
<div class="world-label tunnel" id="labelTunnel">
Lower tunnel · 2,410 m
<small>Snow alternative open</small>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const sceneContainer = 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.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
sceneContainer.appendChild(renderer.domElement);
const scene = new THREE.Scene();
const clearSky = new THREE.Color(0xcbdde4);
const snowSky = new THREE.Color(0xaabdc8);
scene.background = clearSky.clone();
scene.fog = new THREE.Fog(clearSky.clone(), 48, 108);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
180
);
const hemisphere = new THREE.HemisphereLight(0xd9edf5, 0x504b37, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffefd2, 3.25);
sun.position.set(-23, 38, 27);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -42;
sun.shadow.camera.right = 42;
sun.shadow.camera.top = 34;
sun.shadow.camera.bottom = -34;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 100;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d7e7, 0.65);
fill.position.set(24, 16, -24);
scene.add(fill);
// -------------------------------------------------------------------------
// Terrain generation
// -------------------------------------------------------------------------
const TERRAIN_WIDTH = 64;
const TERRAIN_DEPTH = 44;
const PASS_Z = -10;
const TUNNEL_Z = 8;
const TUNNEL_FLOOR = 5.15;
function terrainHeight(x, z) {
const ridgeFalloff = Math.exp(-Math.pow(Math.abs(x) / 13, 4));
const passMassif =
18 * Math.exp(-Math.pow((z - PASS_Z) / 6.8, 2));
const tunnelMassif =
11 * Math.exp(-Math.pow((z - TUNNEL_Z) / 7.2, 2));
const sideRise = 3.2 * Math.pow(Math.abs(x) / 32, 3);
const noise =
0.5 * Math.sin(x * 0.43 + z * 0.21) +
0.32 * Math.cos(z * 0.56 - x * 0.18) +
0.2 * Math.sin((x + z) * 0.77);
// Small notches at the two tunnel portals make the entrances readable.
const portalCut =
4.4 *
Math.exp(-Math.pow((z - TUNNEL_Z) / 2.4, 2)) *
Math.exp(-Math.pow((Math.abs(x) - 9) / 3.2, 2));
return (
0.45 +
ridgeFalloff * (passMassif + tunnelMassif) +
sideRise +
noise -
portalCut
);
}
const terrainGeometry = new THREE.PlaneGeometry(
TERRAIN_WIDTH,
TERRAIN_DEPTH,
64,
44
);
terrainGeometry.rotateX(-Math.PI / 2);
const terrainPositions = terrainGeometry.attributes.position;
const terrainHeights = new Float32Array(terrainPositions.count);
const terrainBaseColors = new Float32Array(terrainPositions.count * 3);
const grassLow = new THREE.Color(0x567653);
const grassHigh = new THREE.Color(0x667656);
const rock = new THREE.Color(0x77746a);
const highRock = new THREE.Color(0x8c8982);
const snowColor = new THREE.Color(0xe9f4f3);
const temporaryColor = new THREE.Color();
for (let i = 0; i < terrainPositions.count; i++) {
const x = terrainPositions.getX(i);
const z = terrainPositions.getZ(i);
const y = terrainHeight(x, z);
terrainPositions.setY(i, y);
terrainHeights[i] = y;
if (y < 2.3) {
temporaryColor.copy(grassLow);
} else if (y < 7.5) {
temporaryColor.copy(grassLow).lerp(grassHigh, (y - 2.3) / 5.2);
} else if (y < 13) {
temporaryColor.copy(grassHigh).lerp(rock, (y - 7.5) / 5.5);
} else {
temporaryColor.copy(rock).lerp(highRock, Math.min(1, (y - 13) / 8));
}
const variation =
0.035 *
Math.sin(x * 1.7 + z * 0.9) +
0.025 *
Math.cos(x * 0.6 - z * 1.4);
temporaryColor.offsetHSL(variation, 0, variation * 0.7);
terrainBaseColors[i * 3] = temporaryColor.r;
terrainBaseColors[i * 3 + 1] = temporaryColor.g;
terrainBaseColors[i * 3 + 2] = temporaryColor.b;
}
terrainGeometry.setAttribute(
"color",
new THREE.BufferAttribute(
terrainBaseColors.slice(),
3
).setUsage(THREE.DynamicDrawUsage)
);
terrainGeometry.computeVertexNormals();
const terrainMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.96,
metalness: 0,
flatShading: true
});
const terrain = new THREE.Mesh(terrainGeometry, terrainMaterial);
terrain.receiveShadow = true;
terrain.castShadow = true;
scene.add(terrain);
const earthBase = new THREE.Mesh(
new THREE.BoxGeometry(65, 3.2, 45),
new THREE.MeshStandardMaterial({
color: 0x5a5548,
roughness: 1,
flatShading: true
})
);
earthBase.position.y = -1.7;
earthBase.receiveShadow = true;
scene.add(earthBase);
// -------------------------------------------------------------------------
// Route ribbons
// -------------------------------------------------------------------------
const highRouteOpen = new THREE.Color(0xedae45);
const highRouteClosed = new THREE.Color(0xd7514b);
const tunnelRouteColor = new THREE.Color(0x21a77f);
const routeUnderlayMaterial = new THREE.MeshStandardMaterial({
color: 0x39484a,
roughness: 0.9,
side: THREE.DoubleSide
});
const highRouteMaterial = new THREE.MeshStandardMaterial({
color: highRouteOpen.clone(),
roughness: 0.78,
side: THREE.DoubleSide
});
const tunnelRouteMaterial = new THREE.MeshStandardMaterial({
color: tunnelRouteColor.clone(),
roughness: 0.78,
side: THREE.DoubleSide
});
function createRibbon(xzPoints, width, material, verticalOffset, samples = 180) {
const curve = new THREE.CatmullRomCurve3(
xzPoints.map(
(point) => new THREE.Vector3(point[0], 0, point[1])
),
false,
"centripetal"
);
const positions = [];
const indices = [];
const normals = [];
for (let i = 0; i <= samples; i++) {
const t = i / samples;
const point = curve.getPoint(t);
const tangent = curve.getTangent(t);
const side = new THREE.Vector3(-tangent.z, 0, tangent.x).normalize();
const y = terrainHeight(point.x, point.z) + verticalOffset;
positions.push(
point.x + side.x * width * 0.5,
y,
point.z + side.z * width * 0.5
);
positions.push(
point.x - side.x * width * 0.5,
y,
point.z - side.z * width * 0.5
);
normals.push(0, 1, 0, 0, 1, 0);
if (i < samples) {
const a = i * 2;
indices.push(a, a + 2, a + 1);
indices.push(a + 1, a + 2, a + 3);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"normal",
new THREE.Float32BufferAttribute(normals, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
const highRouteXZ = [
[-24, 7],
[-21, 3],
[-17, -2],
[-12, -7],
[-7, -9.5],
[-2, -10],
[3, -10],
[8, -9],
[13, -6],
[17, -1],
[21, 4],
[25, 8]
];
const westTunnelXZ = [
[-24, 9],
[-19, 9],
[-15, 8.7],
[-12, 8.3],
[-9, 8]
];
const eastTunnelXZ = [
[9, 8],
[12, 8.3],
[15, 8.7],
[19, 9],
[24, 9]
];
createRibbon(
highRouteXZ,
1.05,
routeUnderlayMaterial,
0.16
);
createRibbon(
highRouteXZ,
0.58,
highRouteMaterial,
0.24
);
createRibbon(
westTunnelXZ,
1.05,
routeUnderlayMaterial,
0.16,
70
);
createRibbon(
westTunnelXZ,
0.58,
tunnelRouteMaterial,
0.24,
70
);
createRibbon(
eastTunnelXZ,
1.05,
routeUnderlayMaterial,
0.16,
70
);
createRibbon(
eastTunnelXZ,
0.58,
tunnelRouteMaterial,
0.24,
70
);
// Schematic x-ray line through the mountain.
const undergroundGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-9, TUNNEL_FLOOR, TUNNEL_Z),
new THREE.Vector3(9, TUNNEL_FLOOR, TUNNEL_Z)
]);
const undergroundMaterial = new THREE.LineDashedMaterial({
color: tunnelRouteColor.clone(),
dashSize: 0.8,
gapSize: 0.48,
transparent: true,
opacity: 0.38,
depthTest: false,
depthWrite: false
});
const undergroundLine = new THREE.Line(
undergroundGeometry,
undergroundMaterial
);
undergroundLine.computeLineDistances();
undergroundLine.renderOrder = 8;
scene.add(undergroundLine);
// -------------------------------------------------------------------------
// Tunnel portals
// -------------------------------------------------------------------------
const concreteMaterial = new THREE.MeshStandardMaterial({
color: 0xbfc3b8,
roughness: 0.94,
flatShading: true
});
const darkInteriorMaterial = new THREE.MeshBasicMaterial({
color: 0x14282c,
side: THREE.DoubleSide
});
function createPortal(x) {
const portal = new THREE.Group();
portal.position.set(x, TUNNEL_FLOOR, TUNNEL_Z);
const radius = 2.35;
const interior = new THREE.Mesh(
new THREE.CircleGeometry(radius, 16, 0, Math.PI),
darkInteriorMaterial
);
interior.rotation.y = Math.PI / 2;
portal.add(interior);
const archPoints = [];
for (let i = 0; i <= 16; i++) {
const theta = (i / 16) * Math.PI;
archPoints.push(
new THREE.Vector3(
0,
Math.sin(theta) * radius,
Math.cos(theta) * radius
)
);
}
const arch = new THREE.Mesh(
new THREE.TubeGeometry(
new THREE.CatmullRomCurve3(archPoints),
24,
0.24,
5,
false
),
concreteMaterial
);
arch.castShadow = true;
portal.add(arch);
for (const side of [-1, 1]) {
const wing = new THREE.Mesh(
new THREE.BoxGeometry(0.55, 1.65, 0.55),
concreteMaterial
);
wing.position.set(0, 0.78, side * (radius + 0.15));
wing.castShadow = true;
portal.add(wing);
}
const sign = new THREE.Mesh(
new THREE.BoxGeometry(0.16, 0.42, 1.6),
new THREE.MeshStandardMaterial({
color: 0x21a77f,
emissive: 0x0a3229,
emissiveIntensity: 0.25
})
);
sign.position.set(-0.18, radius + 0.5, 0);
portal.add(sign);
scene.add(portal);
}
createPortal(-9);
createPortal(9);
// -------------------------------------------------------------------------
// Pass closure barrier
// -------------------------------------------------------------------------
const closureGroup = new THREE.Group();
closureGroup.position.set(0, terrainHeight(0, PASS_Z) + 0.25, PASS_Z);
closureGroup.visible = false;
const closureMaterials = [];
function closureMaterial(color, emissive = 0x000000) {
const material = new THREE.MeshStandardMaterial({
color,
emissive,
emissiveIntensity: 0.3,
roughness: 0.72,
transparent: true,
opacity: 0
});
closureMaterials.push(material);
return material;
}
const barrierRed = closureMaterial(0xd94f47, 0x5a0d09);
const barrierWhite = closureMaterial(0xf2eee4);
const post = new THREE.Mesh(
new THREE.BoxGeometry(0.24, 1.75, 0.24),
barrierWhite
);
post.position.set(0, 0.87, -1.55);
post.castShadow = true;
closureGroup.add(post);
for (let i = 0; i < 4; i++) {
const segment = new THREE.Mesh(
new THREE.BoxGeometry(0.22, 0.22, 0.69),
i % 2 === 0 ? barrierRed : barrierWhite
);
segment.position.set(0, 1.45, -1.15 + i * 0.7);
segment.castShadow = true;
closureGroup.add(segment);
}
const xMarker = new THREE.Group();
xMarker.position.set(0, 4.15, 0);
const barA = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 3.05, 0.18),
barrierRed
);
barA.rotation.x = 0.72;
xMarker.add(barA);
const barB = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 3.05, 0.18),
barrierRed
);
barB.rotation.x = -0.72;
xMarker.add(barB);
closureGroup.add(xMarker);
scene.add(closureGroup);
// -------------------------------------------------------------------------
// Villages
// -------------------------------------------------------------------------
const wallMaterials = [];
const roofMaterials = [];
function createHouse(x, z, wallColor, roofColor, scale = 1) {
const house = new THREE.Group();
const y = terrainHeight(x, z);
const wallMaterial = new THREE.MeshStandardMaterial({
color: wallColor,
roughness: 0.92,
flatShading: true
});
const roofMaterial = new THREE.MeshStandardMaterial({
color: roofColor,
roughness: 0.88,
flatShading: true
});
wallMaterials.push(wallMaterial);
roofMaterials.push(roofMaterial);
const width = 1.7 * scale;
const depth = 1.45 * scale;
const height = 1.25 * scale;
const walls = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
wallMaterial
);
walls.position.y = height * 0.5;
walls.castShadow = true;
walls.receiveShadow = true;
house.add(walls);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(width * 0.78, 0.92 * scale, 4),
roofMaterial
);
roof.position.y = height + 0.43 * scale;
roof.rotation.y = Math.PI / 4;
roof.castShadow = true;
house.add(roof);
const chimney = new THREE.Mesh(
new THREE.BoxGeometry(0.28 * scale, 0.75 * scale, 0.28 * scale),
roofMaterial
);
chimney.position.set(width * 0.25, height + 0.55 * scale, 0);
chimney.castShadow = true;
house.add(chimney);
const windowMaterial = new THREE.MeshBasicMaterial({
color: 0xffd77d
});
for (const wx of [-0.42, 0.42]) {
const windowMesh = new THREE.Mesh(
new THREE.PlaneGeometry(0.26 * scale, 0.31 * scale),
windowMaterial
);
windowMesh.position.set(
wx * scale,
0.68 * scale,
depth * 0.5 + 0.006
);
house.add(windowMesh);
}
house.position.set(x, y, z);
house.rotation.y = (Math.sin(x * 2.3 + z) * 0.16);
scene.add(house);
}
function createVillage(cx, cz, roofColor) {
const housePositions = [
[-3.1, -2.0, 0.9],
[-0.4, -3.1, 1.05],
[2.7, -2.1, 0.85],
[-3.0, 1.8, 1.0],
[0.3, 2.3, 0.82],
[3.1, 1.7, 1.08],
[5.0, -0.2, 0.82]
];
const wallColors = [0xe8d9bd, 0xd8c6a6, 0xeee4cf, 0xcbbda4];
housePositions.forEach((entry, index) => {
createHouse(
cx + entry[0],
cz + entry[1],
wallColors[index % wallColors.length],
roofColor,
entry[2]
);
});
const plaza = new THREE.Mesh(
new THREE.CylinderGeometry(2.1, 2.25, 0.12, 12),
new THREE.MeshStandardMaterial({
color: 0x8a806e,
roughness: 1,
flatShading: true
})
);
plaza.position.set(cx, terrainHeight(cx, cz) + 0.05, cz);
plaza.receiveShadow = true;
scene.add(plaza);
}
createVillage(-25, 8, 0xa95645);
createVillage(25, 8, 0x426f7d);
// -------------------------------------------------------------------------
// Trees and rocks
// -------------------------------------------------------------------------
const trunkMaterial = new THREE.MeshStandardMaterial({
color: 0x594537,
roughness: 1,
flatShading: true
});
const foliageMaterial = new THREE.MeshStandardMaterial({
color: 0x355844,
roughness: 1,
flatShading: true
});
const trunkGeometry = new THREE.CylinderGeometry(0.14, 0.19, 1.1, 5);
const foliageGeometry = new THREE.ConeGeometry(0.78, 2.2, 6);
let randomSeed = 48127;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
function createTree(x, z, scale = 1) {
const y = terrainHeight(x, z);
const tree = new THREE.Group();
const trunk = new THREE.Mesh(trunkGeometry, trunkMaterial);
trunk.position.y = 0.55 * scale;
trunk.scale.setScalar(scale);
trunk.castShadow = true;
const foliage = new THREE.Mesh(foliageGeometry, foliageMaterial);
foliage.position.y = 1.75 * scale;
foliage.scale.setScalar(scale);
foliage.castShadow = true;
tree.add(trunk, foliage);
tree.position.set(x, y, z);
tree.rotation.y = random() * Math.PI;
scene.add(tree);
}
let treeCount = 0;
let attempts = 0;
while (treeCount < 38 && attempts < 600) {
attempts++;
const x = -29 + random() * 58;
const z = -18 + random() * 36;
const y = terrainHeight(x, z);
const nearTunnelApproach = Math.abs(z - 8) < 2.2 && Math.abs(x) > 11;
const nearVillageA =
Math.hypot(x + 25, z - 8) < 7;
const nearVillageB =
Math.hypot(x - 25, z - 8) < 7;
if (y > 9 || nearTunnelApproach || nearVillageA || nearVillageB) {
continue;
}
createTree(x, z, 0.65 + random() * 0.65);
treeCount++;
}
const rockGeometry = new THREE.IcosahedronGeometry(0.65, 0);
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0x77766d,
roughness: 1,
flatShading: true
});
const rocks = new THREE.InstancedMesh(
rockGeometry,
rockMaterial,
34
);
rocks.castShadow = true;
rocks.receiveShadow = true;
const dummy = new THREE.Object3D();
for (let i = 0; i < 34; i++) {
const x = -30 + random() * 60;
const z = -20 + random() * 40;
dummy.position.set(
x,
terrainHeight(x, z) + 0.2,
z
);
dummy.rotation.set(
random() * Math.PI,
random() * Math.PI,
random() * Math.PI
);
const scale = 0.35 + random() * 0.9;
dummy.scale.set(scale, scale * 0.7, scale);
dummy.updateMatrix();
rocks.setMatrixAt(i, dummy.matrix);
}
scene.add(rocks);
// -------------------------------------------------------------------------
// Snow particles
// -------------------------------------------------------------------------
const snowCount = 90;
const snowGeometry = new THREE.OctahedronGeometry(0.105, 0);
const snowMaterial = new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0,
depthWrite: false
});
const snowMesh = new THREE.InstancedMesh(
snowGeometry,
snowMaterial,
snowCount
);
snowMesh.visible = false;
snowMesh.frustumCulled = false;
scene.add(snowMesh);
const snowParticles = [];
for (let i = 0; i < snowCount; i++) {
snowParticles.push({
x: -32 + random() * 64,
y: 3 + random() * 29,
z: -22 + random() * 44,
speed: 1.1 + random() * 2.3,
drift: 0.25 + random() * 0.6,
scale: 0.55 + random() * 1.1,
phase: random() * Math.PI * 2
});
}
// -------------------------------------------------------------------------
// Custom orbit camera controls
// -------------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 7, -1),
desiredTarget: new THREE.Vector3(0, 7, -1),
radius: 59,
desiredRadius: 59,
theta: 0.72,
desiredTheta: 0.72,
phi: 1.02,
desiredPhi: 1.02
};
const spherical = new THREE.Spherical();
function updateCamera(dt) {
const damping = 1 - Math.exp(-dt * 8);
controls.radius +=
(controls.desiredRadius - controls.radius) * damping;
controls.theta +=
(controls.desiredTheta - controls.theta) * damping;
controls.phi +=
(controls.desiredPhi - controls.phi) * damping;
controls.target.lerp(
controls.desiredTarget,
damping
);
spherical.set(
controls.radius,
controls.phi,
controls.theta
);
camera.position.setFromSpherical(spherical);
camera.position.add(controls.target);
camera.lookAt(controls.target);
}
const pointers = new Map();
let lastPinchDistance = 0;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
renderer.domElement.setPointerCapture(event.pointerId);
if (pointers.size === 2) {
lastPinchDistance = pointerDistance();
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const current = {
x: event.clientX,
y: event.clientY
};
pointers.set(event.pointerId, current);
if (pointers.size === 1) {
const dx = current.x - previous.x;
const dy = current.y - previous.y;
controls.desiredTheta -= dx * 0.006;
controls.desiredPhi = THREE.MathUtils.clamp(
controls.desiredPhi - dy * 0.005,
0.38,
1.43
);
} else if (pointers.size === 2) {
const distance = pointerDistance();
if (lastPinchDistance > 0 && distance > 0) {
controls.desiredRadius = THREE.MathUtils.clamp(
controls.desiredRadius * (lastPinchDistance / distance),
15,
85
);
}
lastPinchDistance = distance;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
lastPinchDistance = pointers.size === 2 ? pointerDistance() : 0;
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.desiredRadius = THREE.MathUtils.clamp(
controls.desiredRadius * Math.exp(event.deltaY * 0.001),
15,
85
);
},
{ passive: false }
);
const cameraViews = {
overview: {
target: new THREE.Vector3(0, 7, -1),
radius: 59,
theta: 0.72,
phi: 1.02
},
pass: {
target: new THREE.Vector3(0, 15, -9),
radius: 25,
theta: 0.8,
phi: 1.14
},
tunnel: {
target: new THREE.Vector3(0, 5.8, 8),
radius: 21,
theta: 0.65,
phi: 1.16
}
};
function setCameraView(name) {
const view = cameraViews[name];
if (!view) return;
controls.desiredTarget.copy(view.target);
controls.desiredRadius = view.radius;
controls.desiredTheta = view.theta;
controls.desiredPhi = view.phi;
document.querySelectorAll("[data-view]").forEach((button) => {
button.classList.toggle("active", button.dataset.view === name);
});
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => {
setCameraView(button.dataset.view);
});
});
// -------------------------------------------------------------------------
// Condition toggle and UI
// -------------------------------------------------------------------------
const snowToggle = document.getElementById("snowToggle");
const weatherBadge = document.getElementById("weatherBadge");
const conditionCopy = document.getElementById("conditionCopy");
const passRow = document.getElementById("passRow");
const passState = document.getElementById("passState");
const passLegend = document.getElementById("passLegend");
const labelPass = document.getElementById("labelPass");
const passLabelState = document.getElementById("passLabelState");
let snowTarget = 0;
let snowBlend = 0;
let lastTerrainSnowBlend = -1;
function setSnowCondition(enabled) {
snowTarget = enabled ? 1 : 0;
snowToggle.setAttribute("aria-checked", String(enabled));
document.body.classList.toggle("snow-on", enabled);
weatherBadge.textContent = enabled ? "Snow event" : "Clear weather";
conditionCopy.textContent = enabled
? "The high pass is closed by snow. The lower tunnel remains open and preserves access."
: "Both routes are open. The high pass is exposed to winter conditions.";
passRow.classList.toggle("closed", enabled);
passState.textContent = enabled ? "Closed" : "Open";
passLegend.style.background = enabled ? "#d7514b" : "#edae45";
labelPass.classList.toggle("closed", enabled);
passLabelState.textContent = enabled
? "Closed by snow"
: "Route open";
}
snowToggle.addEventListener("click", () => {
setSnowCondition(snowToggle.getAttribute("aria-checked") !== "true");
});
window.addEventListener("keydown", (event) => {
if (
event.key.toLowerCase() === "s" &&
event.target === document.body
) {
setSnowCondition(snowTarget === 0);
}
});
function updateTerrainSnow(amount) {
const colors = terrainGeometry.attributes.color.array;
for (let i = 0; i < terrainHeights.length; i++) {
const height = terrainHeights[i];
const altitude = THREE.MathUtils.smoothstep(height, 7.2, 17.5);
const breakup =
0.78 +
0.14 *
Math.sin(i * 1.91) +
0.08 *
Math.cos(i * 0.37);
const snowAmount =
THREE.MathUtils.clamp(
altitude * breakup * amount,
0,
1
);
const index = i * 3;
colors[index] = THREE.MathUtils.lerp(
terrainBaseColors[index],
snowColor.r,
snowAmount
);
colors[index + 1] = THREE.MathUtils.lerp(
terrainBaseColors[index + 1],
snowColor.g,
snowAmount
);
colors[index + 2] = THREE.MathUtils.lerp(
terrainBaseColors[index + 2],
snowColor.b,
snowAmount
);
}
terrainGeometry.attributes.color.needsUpdate = true;
}
// -------------------------------------------------------------------------
// Projected world labels
// -------------------------------------------------------------------------
const labels = [
{
element: document.getElementById("labelVillageA"),
position: new THREE.Vector3(
-25,
terrainHeight(-25, 8) + 4.6,
8
)
},
{
element: document.getElementById("labelVillageB"),
position: new THREE.Vector3(
25,
terrainHeight(25, 8) + 4.6,
8
)
},
{
element: labelPass,
position: new THREE.Vector3(
0,
terrainHeight(0, PASS_Z) + 7.1,
PASS_Z
)
},
{
element: document.getElementById("labelTunnel"),
position: new THREE.Vector3(
0,
TUNNEL_FLOOR + 3.3,
TUNNEL_Z
)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
for (const label of labels) {
projected.copy(label.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.25 &&
Math.abs(projected.y) < 1.25;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
label.element.style.opacity = visible ? "1" : "0";
}
}
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
updateCamera(dt);
const snowDamping = 1 - Math.exp(-dt * 3.5);
snowBlend += (snowTarget - snowBlend) * snowDamping;
if (
Math.abs(snowBlend - lastTerrainSnowBlend) > 0.003 ||
(snowBlend === 0 && lastTerrainSnowBlend !== 0)
) {
updateTerrainSnow(snowBlend);
lastTerrainSnowBlend = snowBlend;
}
scene.background.copy(clearSky).lerp(snowSky, snowBlend);
scene.fog.color.copy(scene.background);
highRouteMaterial.color
.copy(highRouteOpen)
.lerp(highRouteClosed, snowBlend);
closureGroup.visible = snowBlend > 0.025;
for (const material of closureMaterials) {
material.opacity = snowBlend;
}
const closureScale = 0.3 + snowBlend * 0.7;
closureGroup.scale.set(
1,
closureScale,
1
);
// Slightly whiten roofs and foliage during the schematic snow event.
for (const material of roofMaterials) {
material.color.lerp(
new THREE.Color(0xdbe6e7),
snowBlend * 0.3
);
}
if (snowBlend > 0.005) {
snowMesh.visible = true;
snowMaterial.opacity = snowBlend * 0.9;
for (let i = 0; i < snowCount; i++) {
const flake = snowParticles[i];
flake.y -= dt * flake.speed;
flake.x += dt * flake.drift;
flake.phase += dt * 1.7;
if (flake.y < 1.2) {
flake.y = 30 + Math.random() * 3;
flake.x = -32 + Math.random() * 64;
}
if (flake.x > 33) {
flake.x = -33;
}
dummy.position.set(
flake.x + Math.sin(flake.phase) * 0.35,
flake.y,
flake.z
);
dummy.rotation.set(
flake.phase,
flake.phase * 0.7,
flake.phase * 0.45
);
dummy.scale.setScalar(flake.scale);
dummy.updateMatrix();
snowMesh.setMatrixAt(i, dummy.matrix);
}
snowMesh.instanceMatrix.needsUpdate = true;
} else {
snowMesh.visible = false;
}
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(
Math.min(window.devicePixelRatio, 2)
);
renderer.setSize(
window.innerWidth,
window.innerHeight
);
});
setCameraView("overview");
animate();
</script>
</body>
</html>
```