Prompt specification
Build or customize the Three.js 3D scene "Compare valley routes under a hypothetical pass closure" 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: Compare valley routes under a hypothetical pass closure
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/compare-valley-routes-under-a-hypothetical-pass-closur-x3084
Scene Description Prompt:
Close a hypothetical Himalayan mountain pass and compare alternate low-poly valley routes with their added distances. Three.js from cdnjs in one HTML file.
Working Three.js Starter (compare-valley-routes-under-a-hypothetical-pass-closur-x3084):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Himalayan Pass Closure — Route Comparison</title>
<style>
:root {
color-scheme: dark;
--bg: #081317;
--panel: rgba(10, 24, 28, 0.82);
--panel-solid: #102329;
--border: rgba(185, 222, 220, 0.15);
--text: #eef6f3;
--muted: #94aaa8;
--west: #f6b94b;
--east: #35d6c4;
--danger: #ff6262;
--blue: #89c9ff;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
color: inherit;
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
}
.brand {
position: fixed;
top: 22px;
left: 22px;
width: 355px;
padding: 19px 20px 17px;
border: 1px solid var(--border);
border-radius: 18px;
background:
linear-gradient(145deg, rgba(21, 47, 51, 0.91), rgba(8, 22, 26, 0.88));
box-shadow: 0 20px 55px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(18px);
z-index: 5;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
color: #9fc4be;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--east);
box-shadow: 0 0 13px var(--east);
}
h1 {
margin: 0;
font-size: clamp(23px, 2.2vw, 31px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.brand p {
margin: 9px 0 16px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.toolbar {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.tool-button {
min-height: 32px;
padding: 7px 10px;
border: 1px solid rgba(185, 222, 220, 0.15);
border-radius: 9px;
background: rgba(255, 255, 255, 0.045);
color: #cfddda;
cursor: pointer;
font-size: 11px;
transition: 160ms ease;
}
.tool-button:hover {
border-color: rgba(185, 222, 220, 0.35);
background: rgba(255, 255, 255, 0.09);
transform: translateY(-1px);
}
.closure-banner {
position: fixed;
top: 22px;
right: 22px;
z-index: 5;
display: flex;
align-items: center;
gap: 12px;
max-width: 330px;
padding: 13px 16px;
border: 1px solid rgba(255, 98, 98, 0.35);
border-radius: 14px;
background: rgba(46, 16, 20, 0.82);
box-shadow: 0 16px 40px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(16px);
}
.closure-icon {
display: grid;
flex: 0 0 31px;
width: 31px;
height: 31px;
place-items: center;
border-radius: 50%;
background: rgba(255, 98, 98, 0.13);
color: var(--danger);
font-size: 16px;
font-weight: 900;
}
.closure-banner strong {
display: block;
margin-bottom: 2px;
color: #ffd8d8;
font-size: 12px;
}
.closure-banner span {
color: #c9999d;
font-size: 10px;
}
.panel {
position: fixed;
z-index: 4;
border: 1px solid var(--border);
border-radius: 17px;
background: var(--panel);
box-shadow: 0 20px 55px rgba(0, 0, 0, 0.27);
backdrop-filter: blur(18px);
}
.routes-panel {
top: 156px;
left: 22px;
width: 355px;
padding: 15px;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin: 0 2px 11px;
color: #c8d8d5;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.panel-heading small {
color: #6f8986;
font-size: 9px;
font-weight: 600;
letter-spacing: 0.04em;
}
.route-card {
position: relative;
width: 100%;
margin-top: 9px;
padding: 14px;
overflow: hidden;
border: 1px solid rgba(185, 222, 220, 0.11);
border-radius: 13px;
background: rgba(255, 255, 255, 0.035);
text-align: left;
cursor: pointer;
transition: 180ms ease;
}
.route-card::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 3px;
background: var(--route-color);
opacity: 0.28;
transition: 180ms ease;
}
.route-card:hover {
border-color: rgba(185, 222, 220, 0.25);
background: rgba(255, 255, 255, 0.06);
transform: translateX(2px);
}
.route-card.active {
border-color: color-mix(in srgb, var(--route-color) 52%, transparent);
background:
linear-gradient(
100deg,
color-mix(in srgb, var(--route-color) 11%, transparent),
rgba(255, 255, 255, 0.035)
);
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.025);
}
.route-card.active::before {
opacity: 1;
box-shadow: 0 0 16px var(--route-color);
}
.route-card-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.route-name {
display: flex;
align-items: center;
gap: 9px;
font-size: 13px;
font-weight: 750;
}
.route-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--route-color);
box-shadow: 0 0 12px color-mix(in srgb, var(--route-color) 65%, transparent);
}
.add-pill {
padding: 4px 7px;
border-radius: 999px;
background: color-mix(in srgb, var(--route-color) 13%, transparent);
color: var(--route-color);
font-size: 10px;
font-weight: 800;
white-space: nowrap;
}
.route-description {
margin: 8px 0 12px 18px;
color: #839a97;
font-size: 10px;
line-height: 1.4;
}
.route-metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
padding-left: 18px;
}
.route-metrics div {
min-width: 0;
}
.route-metrics strong {
display: block;
font-size: 14px;
letter-spacing: -0.02em;
}
.route-metrics span {
display: block;
margin-top: 2px;
overflow: hidden;
color: #6f8986;
font-size: 8px;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
text-overflow: ellipsis;
}
.show-pass {
width: 100%;
margin-top: 10px;
padding: 9px;
border: 1px dashed rgba(255, 98, 98, 0.28);
border-radius: 10px;
background: rgba(255, 98, 98, 0.035);
color: #d99599;
cursor: pointer;
font-size: 10px;
transition: 160ms ease;
}
.show-pass:hover,
.show-pass.active {
border-color: rgba(255, 98, 98, 0.55);
background: rgba(255, 98, 98, 0.09);
color: #ffd2d2;
}
.comparison-panel {
top: 105px;
right: 22px;
width: 310px;
padding: 16px;
}
.selected-title {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 12px;
font-size: 13px;
font-weight: 750;
}
.selected-title .route-dot {
flex: 0 0 auto;
}
.distance-hero {
display: flex;
align-items: baseline;
gap: 7px;
margin-bottom: 3px;
}
.distance-hero strong {
font-size: 39px;
line-height: 1;
letter-spacing: -0.055em;
}
.distance-hero span {
color: var(--muted);
font-size: 12px;
}
.route-status {
min-height: 18px;
color: #78918e;
font-size: 10px;
}
.added-block {
margin-top: 15px;
padding: 12px;
border: 1px solid rgba(185, 222, 220, 0.1);
border-radius: 11px;
background: rgba(255, 255, 255, 0.035);
}
.added-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 9px;
font-size: 10px;
}
.added-heading span {
color: #819996;
}
.added-heading strong {
color: var(--selected-color, var(--west));
font-size: 14px;
}
.bar-track {
position: relative;
height: 7px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.08);
}
.bar-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: var(--selected-color, var(--west));
box-shadow: 0 0 14px var(--selected-color, var(--west));
transition: width 350ms ease, background 250ms ease;
}
.bar-scale {
display: flex;
justify-content: space-between;
margin-top: 6px;
color: #617b78;
font-size: 8px;
}
.stat-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 10px;
}
.stat {
padding: 10px;
border: 1px solid rgba(185, 222, 220, 0.08);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
}
.stat span {
display: block;
color: #6f8986;
font-size: 8px;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.stat strong {
display: block;
margin-top: 4px;
font-size: 12px;
}
.comparison-list {
display: grid;
gap: 8px;
margin-top: 13px;
padding-top: 13px;
border-top: 1px solid rgba(185, 222, 220, 0.09);
}
.compare-row {
display: grid;
grid-template-columns: 65px 1fr 35px;
align-items: center;
gap: 8px;
padding: 4px 0;
border: 0;
background: transparent;
text-align: left;
cursor: pointer;
}
.compare-name {
display: flex;
align-items: center;
gap: 6px;
color: #91a7a4;
font-size: 9px;
}
.compare-row.active .compare-name {
color: #e8f2ef;
font-weight: 700;
}
.compare-track {
position: relative;
height: 5px;
border-radius: 999px;
background: rgba(255, 255, 255, 0.065);
}
.compare-fill {
height: 100%;
border-radius: inherit;
background: var(--row-color);
opacity: 0.65;
transition: 250ms ease;
}
.compare-row.active .compare-fill {
opacity: 1;
box-shadow: 0 0 9px var(--row-color);
}
.baseline-marker {
position: absolute;
top: -3px;
bottom: -3px;
left: 58.54%;
width: 1px;
background: rgba(255, 255, 255, 0.45);
}
.compare-value {
color: #d8e5e2;
font-size: 10px;
font-weight: 750;
text-align: right;
}
.legend {
position: fixed;
right: 22px;
bottom: 21px;
z-index: 4;
display: flex;
align-items: center;
gap: 15px;
padding: 10px 13px;
border: 1px solid var(--border);
border-radius: 12px;
background: rgba(10, 24, 28, 0.75);
color: #92a8a5;
backdrop-filter: blur(14px);
font-size: 9px;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
white-space: nowrap;
}
.legend-line {
width: 19px;
height: 3px;
border-radius: 3px;
background: var(--legend-color);
box-shadow: 0 0 8px color-mix(in srgb, var(--legend-color) 55%, transparent);
}
.legend-line.dashed {
height: 2px;
background: repeating-linear-gradient(
90deg,
var(--legend-color) 0 5px,
transparent 5px 8px
);
}
.help {
position: fixed;
bottom: 21px;
left: 22px;
z-index: 4;
color: rgba(213, 230, 226, 0.58);
font-size: 9px;
line-height: 1.6;
pointer-events: none;
}
.help strong {
color: rgba(231, 243, 240, 0.78);
font-weight: 650;
}
.map-label {
position: fixed;
top: 0;
left: 0;
z-index: 3;
padding: 5px 8px;
border: 1px solid rgba(185, 222, 220, 0.17);
border-radius: 7px;
background: rgba(8, 20, 23, 0.78);
box-shadow: 0 5px 16px rgba(0, 0, 0, 0.2);
color: #dce9e6;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.04em;
pointer-events: none;
transform: translate(-50%, -50%);
transition: opacity 150ms ease, color 180ms ease, border-color 180ms ease;
white-space: nowrap;
}
.map-label.danger {
border-color: rgba(255, 98, 98, 0.38);
color: #ff9898;
}
.map-label.active {
border-color: color-mix(in srgb, var(--route-color) 60%, transparent);
color: var(--route-color);
}
.loader {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #081317;
transition: opacity 500ms ease;
}
.loader.hidden {
opacity: 0;
pointer-events: none;
}
.loader div {
color: #a6c1bd;
font-size: 11px;
letter-spacing: 0.16em;
text-transform: uppercase;
}
@media (max-width: 1020px) {
.brand,
.routes-panel {
width: 315px;
}
.comparison-panel {
width: 280px;
}
}
@media (max-width: 760px) {
.brand {
top: 10px;
left: 10px;
width: calc(100% - 20px);
padding: 14px;
}
.brand p {
margin-bottom: 10px;
}
.closure-banner {
top: 148px;
right: 10px;
max-width: 230px;
padding: 10px;
}
.routes-panel {
top: auto;
bottom: 10px;
left: 10px;
width: calc(100% - 20px);
padding: 10px;
}
.route-card {
padding: 10px 12px;
}
.route-description,
.route-metrics {
display: none;
}
.comparison-panel {
top: 215px;
right: 10px;
width: 235px;
max-height: 47vh;
overflow-y: auto;
padding: 12px;
}
.distance-hero strong {
font-size: 30px;
}
.legend,
.help {
display: none;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive 3D map of a hypothetical Himalayan pass and two alternate valley routes"
></canvas>
<header class="brand">
<div class="eyebrow">Hypothetical route study</div>
<h1>When the pass closes,<br />the valley takes over.</h1>
<p>
A low-poly comparison of two alternate routes around a sealed
high-altitude crossing.
</p>
<div class="toolbar">
<button class="tool-button" id="resetView" type="button">3D view</button>
<button class="tool-button" id="topView" type="button">Top view</button>
<button class="tool-button" id="focusRoute" type="button">
Focus selected
</button>
</div>
</header>
<div class="closure-banner">
<div class="closure-icon">×</div>
<div>
<strong>PASS CLOSED — GATES LOCKED</strong>
<span>Seasonal snow · no through traffic</span>
</div>
</div>
<section class="panel routes-panel" aria-label="Route alternatives">
<div class="panel-heading">
<span>Choose an alternate</span>
<small>Added distance vs. 48 km pass</small>
</div>
<button
class="route-card active"
type="button"
data-route="west"
style="--route-color: var(--west)"
aria-pressed="true"
>
<div class="route-card-top">
<div class="route-name">
<span class="route-dot"></span>
West Valley Route
</div>
<span class="add-pill">+19 km</span>
</div>
<div class="route-description">
Shorter valley detour with a short rough-gravel section.
</div>
<div class="route-metrics">
<div><strong>67 km</strong><span>Total distance</span></div>
<div><strong>4h 10m</strong><span>Est. travel</span></div>
<div><strong>4,360 m</strong><span>Max altitude</span></div>
</div>
</button>
<button
class="route-card"
type="button"
data-route="east"
style="--route-color: var(--east)"
aria-pressed="false"
>
<div class="route-card-top">
<div class="route-name">
<span class="route-dot"></span>
East River Route
</div>
<span class="add-pill">+34 km</span>
</div>
<div class="route-description">
Longer, fully paved descent that stays below the pass.
</div>
<div class="route-metrics">
<div><strong>82 km</strong><span>Total distance</span></div>
<div><strong>4h 55m</strong><span>Est. travel</span></div>
<div><strong>3,780 m</strong><span>Max altitude</span></div>
</div>
</button>
<button class="show-pass" id="showPass" type="button">
View the closed 48 km pass route
</button>
</section>
<aside class="panel comparison-panel" aria-live="polite">
<div class="selected-title">
<span class="route-dot" id="selectedDot"></span>
<span id="selectedTitle">West Valley Route</span>
</div>
<div class="distance-hero">
<strong id="selectedDistance">67</strong>
<span>kilometres</span>
</div>
<div class="route-status" id="selectedStatus">
Recommended shorter alternate · moderate road conditions
</div>
<div class="added-block">
<div class="added-heading">
<span>Added distance</span>
<strong id="selectedAdded">+19 km</strong>
</div>
<div class="bar-track">
<div class="bar-fill" id="addedBar"></div>
</div>
<div class="bar-scale">
<span>Pass baseline</span>
<span>+34 km maximum</span>
</div>
</div>
<div class="stat-grid">
<div class="stat">
<span>Distance increase</span>
<strong id="selectedPercent">+40%</strong>
</div>
<div class="stat">
<span>Estimated travel</span>
<strong id="selectedDuration">4h 10m</strong>
</div>
<div class="stat">
<span>Maximum altitude</span>
<strong id="selectedElevation">4,360 m</strong>
</div>
<div class="stat">
<span>Road surface</span>
<strong id="selectedSurface">8 km gravel</strong>
</div>
</div>
<div class="comparison-list">
<button
class="compare-row"
type="button"
data-route="closed"
style="--row-color: #7e9290"
>
<span class="compare-name">
<span class="route-dot" style="--route-color: #7e9290"></span>
Pass
</span>
<span class="compare-track">
<span class="compare-fill" style="width: 58.54%"></span>
<span class="baseline-marker"></span>
</span>
<span class="compare-value">48 km</span>
</button>
<button
class="compare-row active"
type="button"
data-route="west"
style="--row-color: var(--west)"
>
<span class="compare-name">
<span class="route-dot" style="--route-color: var(--west)"></span>
West
</span>
<span class="compare-track">
<span class="compare-fill" style="width: 81.71%"></span>
<span class="baseline-marker"></span>
</span>
<span class="compare-value">67 km</span>
</button>
<button
class="compare-row"
type="button"
data-route="east"
style="--row-color: var(--east)"
>
<span class="compare-name">
<span class="route-dot" style="--route-color: var(--east)"></span>
East
</span>
<span class="compare-track">
<span class="compare-fill" style="width: 100%"></span>
<span class="baseline-marker"></span>
</span>
<span class="compare-value">82 km</span>
</button>
</div>
</aside>
<div class="legend" aria-hidden="true">
<div class="legend-item">
<span class="legend-line dashed" style="--legend-color: #ff6262"></span>
Closed pass
</div>
<div class="legend-item">
<span class="legend-line" style="--legend-color: #f6b94b"></span>
West alternate
</div>
<div class="legend-item">
<span class="legend-line" style="--legend-color: #35d6c4"></span>
East alternate
</div>
</div>
<div class="help">
<strong>Drag</strong> to orbit · <strong>Shift-drag</strong> to pan ·
<strong>Scroll</strong> to zoom · <strong>R</strong> to reset
</div>
<div class="map-label danger" id="labelPass">PASS CLOSED</div>
<div class="map-label" id="labelWest" style="--route-color: #f6b94b">
WEST VALLEY
</div>
<div class="map-label" id="labelEast" style="--route-color: #35d6c4">
EAST RIVER
</div>
<div class="map-label" id="labelStart">START GATE</div>
<div class="map-label" id="labelEnd">LOWLAND GATE</div>
<div class="loader" id="loader">
<div>Building the valley</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 canvas = document.querySelector("#scene");
const loader = document.querySelector("#loader");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x081317);
scene.fog = new THREE.FogExp2(0x081317, 0.0085);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
500
);
const renderer = new THREE.WebGLRenderer({
canvas,
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.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const hemisphere = new THREE.HemisphereLight(0xb8dbe2, 0x16221f, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffeed7, 3.1);
sun.position.set(-45, 75, 38);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -90;
sun.shadow.camera.right = 90;
sun.shadow.camera.top = 80;
sun.shadow.camera.bottom = -80;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 190;
sun.shadow.bias = -0.00025;
scene.add(sun);
const routes = {
closed: {
name: "Closed Pass Route",
shortName: "Pass",
distance: 48,
added: 0,
percent: "Baseline",
duration: "3h 05m",
elevation: "4,820 m",
surface: "Closed · paved",
status: "Closed by seasonal snow and gate restrictions",
color: 0xff6262,
css: "#ff6262",
points: [
[-62, 43],
[-50, 34],
[-37, 24],
[-23, 14],
[-10, 5],
[0, 0],
[12, -8],
[26, -19],
[41, -29],
[54, -37],
[62, -43]
]
},
west: {
name: "West Valley Route",
shortName: "West Valley",
distance: 67,
added: 19,
percent: "+40%",
duration: "4h 10m",
elevation: "4,360 m",
surface: "8 km gravel",
status: "Recommended shorter alternate · moderate road conditions",
color: 0xf6b94b,
css: "#f6b94b",
points: [
[-62, 43],
[-53, 32],
[-57, 19],
[-62, 5],
[-61, -10],
[-55, -25],
[-43, -35],
[-25, -39],
[-7, -40],
[12, -38],
[31, -37],
[48, -35],
[57, -39],
[62, -43]
]
},
east: {
name: "East River Route",
shortName: "East River",
distance: 82,
added: 34,
percent: "+71%",
duration: "4h 55m",
elevation: "3,780 m",
surface: "Fully paved",
status: "Longest alternate · lower altitude and fully paved",
color: 0x35d6c4,
css: "#35d6c4",
points: [
[-62, 43],
[-50, 47],
[-35, 51],
[-18, 54],
[0, 53],
[18, 49],
[34, 42],
[48, 32],
[59, 19],
[65, 3],
[64, -15],
[62, -31],
[62, -43]
]
}
};
function terrainHeight(x, z) {
const radial = Math.sqrt((x / 75) ** 2 + (z / 65) ** 2);
let height = 2.1 + 4.2 * Math.pow(Math.min(radial, 1.6), 1.7);
// Eastern peak.
height +=
21 *
Math.exp(-(((x - 18) / 24) ** 2 + ((z + 12) / 17) ** 2));
// Western peak.
height +=
19 *
Math.exp(-(((x + 31) / 21) ** 2 + ((z - 9) / 16) ** 2));
// Central saddle / ridge.
height +=
10 *
Math.exp(-(((z + 0.28 * x) / 7.5) ** 2)) *
Math.exp(-(x * x) / 3600);
// Broad western valley.
height -=
3.1 *
Math.exp(-(((z + 38) / 12) ** 2)) *
Math.exp(-(((x + 3) / 72) ** 4));
// Eastern river corridor.
const riverCenter = 52 - Math.max(0, x - 35) * 1.05;
height -=
3.2 *
Math.exp(-(((z - riverCenter) / 11) ** 2)) *
Math.exp(-(((x + 4) / 72) ** 4));
const noise =
0.46 * Math.sin(x * 0.23) * Math.cos(z * 0.18) +
0.25 * Math.sin(x * 0.51 + z * 0.31);
return Math.max(0.8, height + noise);
}
function buildTerrain() {
const geometry = new THREE.PlaneGeometry(150, 130, 52, 46);
geometry.rotateX(-Math.PI / 2);
const position = geometry.attributes.position;
for (let i = 0; i < position.count; i++) {
const x = position.getX(i);
const z = position.getZ(i);
position.setY(i, terrainHeight(x, z));
}
const faceted = geometry.toNonIndexed();
const colors = [];
const vertices = faceted.attributes.position;
for (let i = 0; i < vertices.count; i += 3) {
const averageHeight =
(vertices.getY(i) +
vertices.getY(i + 1) +
vertices.getY(i + 2)) /
3;
const hash =
Math.sin(i * 12.9898) * 43758.5453;
const jitter = (hash - Math.floor(hash) - 0.5) * 0.065;
let color;
if (averageHeight > 19) {
color = new THREE.Color(0xdce7e7);
} else if (averageHeight > 14) {
color = new THREE.Color(0x59666b);
} else if (averageHeight > 9) {
color = new THREE.Color(0x354b4d);
} else if (averageHeight > 5) {
color = new THREE.Color(0x25413a);
} else {
color = new THREE.Color(0x19342f);
}
color.offsetHSL(jitter * 0.35, jitter * 0.2, jitter);
for (let vertex = 0; vertex < 3; vertex++) {
colors.push(color.r, color.g, color.b);
}
}
faceted.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
faceted.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
flatShading: true,
roughness: 0.93,
metalness: 0.02
});
const terrain = new THREE.Mesh(faceted, material);
terrain.receiveShadow = true;
scene.add(terrain);
return terrain;
}
buildTerrain();
function sampledGroundCurve(points, elevationOffset = 1.1) {
const controlPoints = points.map(
([x, z]) => new THREE.Vector3(x, 0, z)
);
const planarCurve = new THREE.CatmullRomCurve3(
controlPoints,
false,
"catmullrom",
0.35
);
const samples = [];
for (let i = 0; i <= 260; i++) {
const point = planarCurve.getPoint(i / 260);
point.y = terrainHeight(point.x, point.z) + elevationOffset;
samples.push(point);
}
return new THREE.CatmullRomCurve3(samples, false, "centripetal");
}
const routeObjects = {};
function buildRoute(data) {
const curve = sampledGroundCurve(data.points, 1.15);
const geometry = new THREE.TubeGeometry(
curve,
260,
0.29,
5,
false
);
const material = new THREE.MeshStandardMaterial({
color: data.color,
emissive: data.color,
emissiveIntensity: 0.22,
roughness: 0.5,
metalness: 0.05,
transparent: true,
opacity: 0.92,
depthWrite: false
});
const mesh = new THREE.Mesh(geometry, material);
mesh.renderOrder = 4;
scene.add(mesh);
const haloGeometry = new THREE.TubeGeometry(
curve,
260,
0.82,
5,
false
);
const haloMaterial = new THREE.MeshBasicMaterial({
color: data.color,
transparent: true,
opacity: 0.1,
depthWrite: false
});
const halo = new THREE.Mesh(haloGeometry, haloMaterial);
halo.renderOrder = 3;
scene.add(halo);
return { curve, mesh, halo };
}
routeObjects.west = buildRoute(routes.west);
routeObjects.east = buildRoute(routes.east);
const closedCurve = sampledGroundCurve(routes.closed.points, 1.05);
const closedGeometry = new THREE.BufferGeometry().setFromPoints(
closedCurve.getPoints(260)
);
const closedMaterial = new THREE.LineDashedMaterial({
color: routes.closed.color,
dashSize: 1.65,
gapSize: 1.05,
transparent: true,
opacity: 0.72,
depthWrite: false
});
const closedLine = new THREE.Line(closedGeometry, closedMaterial);
closedLine.computeLineDistances();
closedLine.renderOrder = 4;
scene.add(closedLine);
routeObjects.closed = { curve: closedCurve, line: closedLine };
// Turquoise river following the eastern route corridor.
const riverCurve = sampledGroundCurve(routes.east.points, 0.2);
const riverGeometry = new THREE.TubeGeometry(
riverCurve,
280,
0.72,
6,
false
);
const riverMaterial = new THREE.MeshStandardMaterial({
color: 0x39b9c4,
emissive: 0x0b6570,
emissiveIntensity: 0.18,
roughness: 0.28,
metalness: 0.08,
transparent: true,
opacity: 0.87
});
const river = new THREE.Mesh(riverGeometry, riverMaterial);
river.receiveShadow = true;
river.renderOrder = 2;
scene.add(river);
function buildGate(x, z, color) {
const group = new THREE.Group();
group.position.set(x, terrainHeight(x, z), z);
const poleMaterial = new THREE.MeshStandardMaterial({
color: 0x263538,
roughness: 0.8
});
const topMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.6,
roughness: 0.4
});
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.19, 3.3, 6),
poleMaterial
);
pole.position.y = 1.65;
pole.castShadow = true;
group.add(pole);
const top = new THREE.Mesh(
new THREE.OctahedronGeometry(0.58),
topMaterial
);
top.position.y = 3.55;
top.castShadow = true;
group.add(top);
scene.add(group);
return group;
}
buildGate(-62, 43, 0x69e3bd);
buildGate(62, -43, 0x89c9ff);
// Closed-pass marker and barrier.
const closureGroup = new THREE.Group();
const passHeight = terrainHeight(0, 0);
closureGroup.position.set(0, passHeight, 0);
const beacon = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.2, 4.4, 6),
new THREE.MeshStandardMaterial({
color: 0x722d31,
roughness: 0.7
})
);
beacon.position.y = 2.2;
beacon.castShadow = true;
closureGroup.add(beacon);
const barrierMaterial = new THREE.MeshStandardMaterial({
color: routes.closed.color,
emissive: routes.closed.color,
emissiveIntensity: 0.6,
roughness: 0.45
});
const barA = new THREE.Mesh(
new THREE.BoxGeometry(4.8, 0.36, 0.36),
barrierMaterial
);
const barB = barA.clone();
barA.position.y = 1.65;
barB.position.y = 1.65;
barA.rotation.y = Math.PI / 4;
barB.rotation.y = -Math.PI / 4;
closureGroup.add(barA, barB);
const warning = new THREE.Mesh(
new THREE.OctahedronGeometry(0.72),
barrierMaterial
);
warning.position.y = 4.65;
closureGroup.add(warning);
scene.add(closureGroup);
const pulseMaterial = new THREE.MeshBasicMaterial({
color: routes.closed.color,
transparent: true,
opacity: 0.7,
depthWrite: false
});
const closurePulse = new THREE.Mesh(
new THREE.TorusGeometry(3.2, 0.09, 6, 48),
pulseMaterial
);
closurePulse.rotation.x = Math.PI / 2;
closurePulse.position.set(0, passHeight + 0.25, 0);
scene.add(closurePulse);
// Low-poly trees.
function randomGenerator(seed) {
return function () {
seed |= 0;
seed = (seed + 0x6d2b79f5) | 0;
let value = Math.imul(seed ^ (seed >>> 15), 1 | seed);
value =
value +
Math.imul(value ^ (value >>> 7), 61 | value) ^
value;
return ((value ^ (value >>> 14)) >>> 0) / 4294967296;
};
}
const random = randomGenerator(9173);
const treePositions = [];
const allRoutePoints = [
...routes.closed.points,
...routes.west.points,
...routes.east.points
];
for (let attempts = 0; attempts < 900; attempts++) {
const x = -70 + random() * 140;
const z = -59 + random() * 118;
const y = terrainHeight(x, z);
if (y < 2.8 || y > 9.2) continue;
const nearRoute = allRoutePoints.some(
([routeX, routeZ]) =>
(routeX - x) ** 2 + (routeZ - z) ** 2 < 18
);
if (nearRoute) continue;
treePositions.push({
x,
y,
z,
scale: 0.72 + random() * 0.7,
rotation: random() * Math.PI * 2
});
}
const trunkGeometry = new THREE.CylinderGeometry(
0.12,
0.17,
1.1,
5
);
const crownGeometry = new THREE.ConeGeometry(0.68, 2.15, 5);
const trunkMesh = new THREE.InstancedMesh(
trunkGeometry,
new THREE.MeshStandardMaterial({ color: 0x4a3528, roughness: 1 }),
treePositions.length
);
const crownMesh = new THREE.InstancedMesh(
crownGeometry,
new THREE.MeshStandardMaterial({
color: 0x234f3f,
roughness: 1,
flatShading: true
}),
treePositions.length
);
const dummy = new THREE.Object3D();
treePositions.forEach((tree, index) => {
dummy.position.set(tree.x, tree.y + 0.55 * tree.scale, tree.z);
dummy.rotation.set(0, tree.rotation, 0);
dummy.scale.setScalar(tree.scale);
dummy.updateMatrix();
trunkMesh.setMatrixAt(index, dummy.matrix);
dummy.position.set(tree.x, tree.y + 1.65 * tree.scale, tree.z);
dummy.updateMatrix();
crownMesh.setMatrixAt(index, dummy.matrix);
});
trunkMesh.castShadow = true;
crownMesh.castShadow = true;
trunkMesh.instanceMatrix.needsUpdate = true;
crownMesh.instanceMatrix.needsUpdate = true;
scene.add(trunkMesh, crownMesh);
// Sparse low-poly cloud clusters.
const cloudGeometry = new THREE.IcosahedronGeometry(1, 0);
const cloudMaterial = new THREE.MeshStandardMaterial({
color: 0xe2edeb,
emissive: 0x8fa7a6,
emissiveIntensity: 0.08,
transparent: true,
opacity: 0.68,
roughness: 1,
flatShading: true,
depthWrite: false
});
[
[-26, 31, -18, 2.2],
[16, 35, -7, 2.7],
[38, 30, 10, 1.9],
[-49, 29, 24, 1.6],
[4, 38, 32, 2.3],
[57, 27, -31, 1.8]
].forEach(([x, y, z, scale]) => {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
for (let i = 0; i < 4; i++) {
const cloud = new THREE.Mesh(cloudGeometry, cloudMaterial);
cloud.position.set(
(i - 1.5) * 1.15,
Math.sin(i * 1.7) * 0.45,
Math.cos(i * 1.4) * 0.8
);
cloud.scale.set(1.1 + (i % 2) * 0.35, 0.72, 0.85);
group.add(cloud);
}
scene.add(group);
});
// Animated vehicle.
const vehicle = new THREE.Group();
const vehicleBody = new THREE.Mesh(
new THREE.BoxGeometry(1.35, 0.45, 0.78),
new THREE.MeshStandardMaterial({
color: 0xf4f2e9,
roughness: 0.45,
metalness: 0.1
})
);
vehicleBody.position.y = 0.38;
vehicleBody.castShadow = true;
const vehicleCab = new THREE.Mesh(
new THREE.BoxGeometry(0.68, 0.36, 0.64),
new THREE.MeshStandardMaterial({
color: routes.west.color,
emissive: routes.west.color,
emissiveIntensity: 0.35,
roughness: 0.35
})
);
vehicleCab.position.set(0, 0.76, -0.08);
vehicleCab.castShadow = true;
const vehicleLight = new THREE.Mesh(
new THREE.SphereGeometry(0.13, 8, 6),
new THREE.MeshBasicMaterial({ color: 0xffe6a1 })
);
vehicleLight.position.set(0, 0.8, 0.37);
vehicle.add(vehicleBody, vehicleCab, vehicleLight);
scene.add(vehicle);
const forward = new THREE.Vector3(0, 0, 1);
let vehicleProgress = 0;
let activeRoute = "west";
// Custom camera controls, implemented without Three.js addons.
const orbit = {
target: new THREE.Vector3(0, 7, 0),
distance: 126,
theta: 0.78,
phi: 1.03,
minDistance: 42,
maxDistance: 205,
minPhi: 0.08,
maxPhi: 1.46
};
function updateCamera() {
orbit.phi = THREE.MathUtils.clamp(
orbit.phi,
orbit.minPhi,
orbit.maxPhi
);
orbit.distance = THREE.MathUtils.clamp(
orbit.distance,
orbit.minDistance,
orbit.maxDistance
);
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.distance * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.distance * Math.cos(orbit.phi),
orbit.target.z + orbit.distance * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
camera.updateMatrixWorld();
}
function resetCamera() {
orbit.target.set(0, 7, 0);
orbit.distance = 126;
orbit.theta = 0.78;
orbit.phi = 1.03;
updateCamera();
}
function topCamera() {
orbit.target.set(0, 3, 0);
orbit.distance = 138;
orbit.theta = 0;
orbit.phi = 0.085;
updateCamera();
}
updateCamera();
const pointers = new Map();
let previousPinchDistance = 0;
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
canvas.addEventListener("pointerdown", (event) => {
canvas.focus();
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
const values = [...pointers.values()];
previousPinchDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
});
canvas.addEventListener("pointermove", (event) => {
const pointer = pointers.get(event.pointerId);
if (!pointer) return;
if (pointers.size === 2) {
pointer.x = event.clientX;
pointer.y = event.clientY;
const values = [...pointers.values()];
const distance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (previousPinchDistance > 0 && distance > 0) {
orbit.distance *= previousPinchDistance / distance;
updateCamera();
}
previousPinchDistance = distance;
return;
}
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (event.shiftKey || event.buttons === 2) {
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
0
);
const up = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
1
);
const panScale = orbit.distance * 0.00135;
orbit.target.addScaledVector(right, -dx * panScale);
orbit.target.addScaledVector(up, dy * panScale);
} else {
orbit.theta -= dx * 0.0055;
orbit.phi -= dy * 0.0045;
}
updateCamera();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = 0;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.distance *= Math.exp(event.deltaY * 0.001);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
resetCamera();
}
if (event.key === "ArrowLeft") orbit.theta += 0.08;
if (event.key === "ArrowRight") orbit.theta -= 0.08;
if (event.key === "ArrowUp") orbit.phi -= 0.06;
if (event.key === "ArrowDown") orbit.phi += 0.06;
if (event.key === "+" || event.key === "=") orbit.distance *= 0.9;
if (event.key === "-") orbit.distance *= 1.1;
updateCamera();
});
const selectedTitle = document.querySelector("#selectedTitle");
const selectedDot = document.querySelector("#selectedDot");
const selectedDistance = document.querySelector("#selectedDistance");
const selectedStatus = document.querySelector("#selectedStatus");
const selectedAdded = document.querySelector("#selectedAdded");
const selectedPercent = document.querySelector("#selectedPercent");
const selectedDuration = document.querySelector("#selectedDuration");
const selectedElevation = document.querySelector("#selectedElevation");
const selectedSurface = document.querySelector("#selectedSurface");
const addedBar = document.querySelector("#addedBar");
const comparisonPanel = document.querySelector(".comparison-panel");
const showPass = document.querySelector("#showPass");
function selectRoute(key) {
activeRoute = key;
const route = routes[key];
selectedTitle.textContent = route.name;
selectedDistance.textContent = route.distance;
selectedStatus.textContent = route.status;
selectedAdded.textContent =
key === "closed" ? "0 km" : `+${route.added} km`;
selectedPercent.textContent = route.percent;
selectedDuration.textContent = route.duration;
selectedElevation.textContent = route.elevation;
selectedSurface.textContent = route.surface;
selectedDot.style.setProperty("--route-color", route.css);
comparisonPanel.style.setProperty("--selected-color", route.css);
addedBar.style.width = `${(route.added / 34) * 100}%`;
addedBar.style.background = route.css;
document.querySelectorAll(".route-card").forEach((card) => {
const isActive = card.dataset.route === key;
card.classList.toggle("active", isActive);
card.setAttribute("aria-pressed", String(isActive));
});
document.querySelectorAll(".compare-row").forEach((row) => {
row.classList.toggle("active", row.dataset.route === key);
});
showPass.classList.toggle("active", key === "closed");
["west", "east"].forEach((routeKey) => {
const object = routeObjects[routeKey];
const isActive = routeKey === key;
object.mesh.material.opacity = isActive ? 1 : 0.48;
object.mesh.material.emissiveIntensity = isActive ? 0.52 : 0.16;
object.halo.material.opacity = isActive ? 0.23 : 0.07;
});
routeObjects.closed.line.material.opacity =
key === "closed" ? 1 : 0.72;
document.querySelector("#labelWest").classList.toggle(
"active",
key === "west"
);
document.querySelector("#labelEast").classList.toggle(
"active",
key === "east"
);
vehicle.visible = key !== "closed";
vehicleProgress = 0;
if (key !== "closed") {
vehicleCab.material.color.setHex(route.color);
vehicleCab.material.emissive.setHex(route.color);
}
}
document.querySelectorAll("[data-route]").forEach((button) => {
button.addEventListener("click", () => {
selectRoute(button.dataset.route);
});
});
showPass.addEventListener("click", () => selectRoute("closed"));
document.querySelector("#resetView").addEventListener("click", resetCamera);
document.querySelector("#topView").addEventListener("click", topCamera);
document.querySelector("#focusRoute").addEventListener("click", () => {
if (activeRoute === "closed") {
orbit.target.set(0, 7, 0);
orbit.distance = 112;
} else if (activeRoute === "west") {
orbit.target.set(-25, 5, -15);
orbit.distance = 102;
} else {
orbit.target.set(18, 4, 18);
orbit.distance = 108;
}
updateCamera();
});
// Project world-space labels into HTML overlays.
const labelDefinitions = [
{
element: document.querySelector("#labelPass"),
position: new THREE.Vector3(0, passHeight + 5.3, 0)
},
{
element: document.querySelector("#labelWest"),
position: new THREE.Vector3(
-43,
terrainHeight(-43, -35) + 2.5,
-35
)
},
{
element: document.querySelector("#labelEast"),
position: new THREE.Vector3(
14,
terrainHeight(14, 50) + 2.5,
50
)
},
{
element: document.querySelector("#labelStart"),
position: new THREE.Vector3(
-62,
terrainHeight(-62, 43) + 4.2,
43
)
},
{
element: document.querySelector("#labelEnd"),
position: new THREE.Vector3(
62,
terrainHeight(62, -43) + 4.2,
-43
)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
labelDefinitions.forEach((label) => {
projected.copy(label.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.12 &&
Math.abs(projected.y) < 1.12;
label.element.style.left = `${
(projected.x * 0.5 + 0.5) * window.innerWidth
}px`;
label.element.style.top = `${
(-projected.y * 0.5 + 0.5) * window.innerHeight
}px`;
label.element.style.opacity = visible ? "1" : "0";
});
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (activeRoute !== "closed") {
vehicleProgress = (vehicleProgress + delta * 0.034) % 1;
const route = routes[activeRoute];
const curve = routeObjects[activeRoute].curve;
const point = curve.getPointAt(vehicleProgress);
const tangent = curve.getTangentAt(vehicleProgress).normalize();
vehicle.position.copy(point);
vehicle.position.y += 0.28;
vehicle.quaternion.setFromUnitVectors(forward, tangent);
}
const pulse = 1 + Math.sin(clock.elapsedTime * 2.2) * 0.16;
closurePulse.scale.setScalar(pulse);
pulseMaterial.opacity = 0.42 + (Math.sin(clock.elapsedTime * 2.2) + 1) * 0.16;
warning.rotation.y += delta * 0.65;
warning.position.y = 4.65 + Math.sin(clock.elapsedTime * 2) * 0.12;
updateLabels();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
loader.classList.add("hidden");
setTimeout(() => loader.remove(), 550);
}
}
selectRoute("west");
animate();
</script>
</body>
</html>
```