Prompt specification
Build or customize the Three.js 3D scene "Orographic rain teaching landscape" 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: Orographic rain teaching landscape
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/orographic-rain-teaching-landscape-x1216
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing condensation and cloud formation. Provide wind-direction and moisture controls on a mountain model; update illustrative cloud and rainfall zones with a schematic label and avoid treating the visualization as a weather forecast. Low-poly.
Working Three.js Starter (orographic-rain-teaching-landscape-x1216):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Mountain Cloud Formation — Schematic</title>
<style>
:root {
--ink: #17373c;
--muted: #60777a;
--teal: #167b83;
--teal-dark: #0f5e65;
--cyan: #9edfdc;
--rain: #3979b8;
--panel: rgba(248, 251, 247, 0.93);
--border: rgba(23, 55, 60, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dcebed;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#viewport canvas.dragging {
cursor: grabbing;
}
.top-stamp {
position: fixed;
top: 18px;
right: 20px;
z-index: 5;
display: flex;
align-items: center;
gap: 10px;
padding: 9px 12px;
border: 1px solid rgba(23, 55, 60, 0.16);
border-radius: 999px;
background: rgba(248, 251, 247, 0.78);
backdrop-filter: blur(10px);
color: #466468;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
pointer-events: none;
}
.top-stamp strong {
padding: 4px 7px;
border-radius: 999px;
background: #17373c;
color: #f7faf6;
font-size: 9px;
letter-spacing: 0.1em;
}
.panel {
position: fixed;
top: 18px;
left: 18px;
z-index: 10;
width: 330px;
max-height: calc(100vh - 36px);
overflow: auto;
padding: 19px;
border: 1px solid var(--border);
border-radius: 20px;
background: var(--panel);
box-shadow:
0 22px 60px rgba(31, 65, 68, 0.16),
0 3px 10px rgba(31, 65, 68, 0.08);
backdrop-filter: blur(16px) saturate(1.08);
}
.eyebrow {
margin: 0 0 7px;
color: var(--teal);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 25px;
line-height: 1.08;
letter-spacing: -0.035em;
}
.intro {
margin: 10px 0 18px;
color: var(--muted);
font-size: 12.5px;
line-height: 1.55;
}
.control {
padding: 15px 0;
border-top: 1px solid var(--border);
}
.control:first-of-type {
border-top: 0;
padding-top: 4px;
}
.control-head {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
}
.control label {
font-size: 12px;
font-weight: 780;
}
output {
color: var(--teal-dark);
font-size: 12px;
font-weight: 800;
text-align: right;
}
input[type="range"] {
--pct: 50%;
width: 100%;
height: 18px;
margin: 0;
appearance: none;
background: transparent;
cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
height: 5px;
border-radius: 999px;
background:
linear-gradient(
90deg,
var(--teal) 0 var(--pct),
#d8e4df var(--pct) 100%
);
}
input[type="range"]::-moz-range-track {
height: 5px;
border-radius: 999px;
background: #d8e4df;
}
input[type="range"]::-moz-range-progress {
height: 5px;
border-radius: 999px;
background: var(--teal);
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
margin-top: -5.5px;
appearance: none;
border: 3px solid #f8fbf7;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 1px 6px rgba(18, 73, 78, 0.28);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid #f8fbf7;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 1px 6px rgba(18, 73, 78, 0.28);
}
.range-ends {
display: flex;
justify-content: space-between;
margin-top: 3px;
color: #839596;
font-size: 9.5px;
font-weight: 650;
}
.wind-row {
display: grid;
grid-template-columns: 91px 1fr;
align-items: center;
gap: 13px;
}
.compass {
position: relative;
width: 86px;
height: 86px;
border: 1px solid rgba(23, 55, 60, 0.16);
border-radius: 50%;
background:
radial-gradient(circle at center, #fff 0 43%, transparent 44%),
conic-gradient(
from -45deg,
rgba(22, 123, 131, 0.03),
rgba(22, 123, 131, 0.12),
rgba(22, 123, 131, 0.03)
);
box-shadow: inset 0 0 0 5px rgba(255, 255, 255, 0.35);
}
.compass::before,
.compass::after {
position: absolute;
content: "";
background: rgba(23, 55, 60, 0.12);
}
.compass::before {
top: 9px;
bottom: 9px;
left: 50%;
width: 1px;
}
.compass::after {
top: 50%;
right: 9px;
left: 9px;
height: 1px;
}
.cardinal {
position: absolute;
z-index: 1;
color: #637b7e;
font-size: 8px;
font-weight: 850;
}
.cardinal.n { top: 4px; left: 50%; transform: translateX(-50%); }
.cardinal.e { top: 50%; right: 5px; transform: translateY(-50%); }
.cardinal.s { bottom: 4px; left: 50%; transform: translateX(-50%); }
.cardinal.w { top: 50%; left: 5px; transform: translateY(-50%); }
#flowNeedle {
position: absolute;
z-index: 2;
top: 50%;
left: 50%;
width: 30px;
height: 30px;
transform: translate(-50%, -50%);
color: var(--teal);
font-size: 27px;
font-weight: 900;
line-height: 30px;
text-align: center;
text-shadow: 0 2px 4px rgba(23, 55, 60, 0.18);
transition: transform 120ms ease-out;
}
.wind-copy {
min-width: 0;
}
#windDirection {
margin-bottom: 5px;
font-size: 13px;
font-weight: 800;
}
#windExplanation {
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.readouts {
display: grid;
gap: 11px;
padding: 14px 0;
border-top: 1px solid var(--border);
}
.readout-head {
display: flex;
justify-content: space-between;
gap: 10px;
margin-bottom: 6px;
font-size: 11px;
font-weight: 760;
}
.readout-head span:last-child {
color: var(--muted);
font-weight: 680;
text-align: right;
}
.bar {
height: 6px;
overflow: hidden;
border-radius: 999px;
background: #dce6e1;
}
.bar > span {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
transition: width 180ms ease-out;
}
#condensationBar {
background: linear-gradient(90deg, #93d8d5, #2a969d);
}
#rainfallBar {
background: linear-gradient(90deg, #8bc3dd, #3979b8);
}
.status {
padding: 12px 13px;
border: 1px solid rgba(22, 123, 131, 0.12);
border-radius: 13px;
background: rgba(158, 223, 220, 0.13);
color: #365e62;
font-size: 11.5px;
line-height: 1.5;
}
.disclaimer {
margin: 13px 0 0;
color: #728688;
font-size: 9.5px;
line-height: 1.45;
}
.actions {
display: flex;
gap: 8px;
margin-top: 13px;
}
.button {
flex: 1;
padding: 9px 10px;
border: 1px solid rgba(23, 55, 60, 0.14);
border-radius: 10px;
background: rgba(255, 255, 255, 0.65);
color: var(--ink);
font-size: 10.5px;
font-weight: 780;
cursor: pointer;
transition:
background 140ms ease,
transform 140ms ease;
}
.button:hover {
background: #fff;
transform: translateY(-1px);
}
.button:focus-visible,
input:focus-visible {
outline: 2px solid var(--teal);
outline-offset: 3px;
}
.world-label {
position: fixed;
z-index: 4;
min-width: 150px;
max-width: 205px;
padding: 9px 11px 9px 12px;
border: 1px solid rgba(23, 55, 60, 0.16);
border-radius: 11px;
background: rgba(248, 251, 247, 0.88);
box-shadow: 0 8px 24px rgba(31, 65, 68, 0.12);
backdrop-filter: blur(8px);
pointer-events: none;
transform: translate(-50%, calc(-100% - 22px));
transition: opacity 160ms ease;
}
.world-label::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 22px;
content: "";
background: linear-gradient(rgba(23, 55, 60, 0.55), rgba(23, 55, 60, 0.12));
}
.world-label::before {
position: absolute;
top: calc(100% + 20px);
left: 50%;
width: 7px;
height: 7px;
border: 2px solid rgba(248, 251, 247, 0.9);
border-radius: 50%;
content: "";
background: var(--teal);
transform: translate(-50%, -50%);
}
.world-label strong {
display: block;
margin-bottom: 2px;
font-size: 10.5px;
letter-spacing: 0.015em;
}
.world-label small {
display: block;
color: #687e81;
font-size: 9px;
line-height: 1.35;
}
#rainLabel::before {
background: var(--rain);
}
.legend {
position: fixed;
right: 20px;
bottom: 18px;
z-index: 5;
display: flex;
gap: 13px;
padding: 9px 12px;
border: 1px solid var(--border);
border-radius: 12px;
background: rgba(248, 251, 247, 0.83);
backdrop-filter: blur(10px);
color: #506b6e;
font-size: 9px;
font-weight: 760;
pointer-events: none;
}
.legend span {
display: flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 3px;
}
.swatch.cloud { background: #dcebed; border: 1px solid #9eb7bc; }
.swatch.rain { background: #70a9d1; }
.swatch.flow { background: #2d9298; }
.help {
position: fixed;
right: 20px;
bottom: 64px;
z-index: 5;
color: rgba(23, 55, 60, 0.63);
font-size: 9px;
font-weight: 680;
letter-spacing: 0.03em;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 50;
display: grid;
place-items: center;
background: #dcebed;
color: var(--ink);
font-size: 12px;
font-weight: 750;
letter-spacing: 0.04em;
transition: opacity 250ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
.panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 48vh;
padding: 15px;
border-radius: 17px;
}
h1 {
font-size: 21px;
}
.intro {
margin-bottom: 10px;
}
.control {
padding: 10px 0;
}
.readouts,
.actions,
.disclaimer {
display: none;
}
.status {
margin-top: 8px;
padding: 9px 10px;
}
.top-stamp {
top: 10px;
right: 10px;
font-size: 8px;
}
.legend,
.help {
display: none;
}
.world-label {
min-width: 120px;
max-width: 145px;
padding: 7px 8px;
}
.world-label strong {
font-size: 9px;
}
.world-label small {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div id="loading">Loading the low-poly mountain model…</div>
<div class="top-stamp">
LOW-POLY PROCESS STUDY
<strong>NOT A FORECAST</strong>
</div>
<aside class="panel" aria-label="Cloud formation controls">
<p class="eyebrow">Mountain cloud lab</p>
<h1>Condensation &<br>orographic rainfall</h1>
<p class="intro">
Explore how schematic airflow, uplift, and moisture alter a cloud band
on a mountain.
</p>
<div class="control">
<div class="control-head">
<label for="moisture">Relative moisture</label>
<output id="moistureValue" for="moisture">68%</output>
</div>
<input
id="moisture"
type="range"
min="0"
max="100"
value="68"
aria-label="Relative moisture"
>
<div class="range-ends">
<span>Dry</span>
<span>Moist</span>
</div>
</div>
<div class="control">
<div class="control-head">
<label for="wind">Wind direction</label>
<output id="windValue" for="wind">From W</output>
</div>
<div class="wind-row">
<div class="compass" aria-hidden="true">
<span class="cardinal n">N</span>
<span class="cardinal e">E</span>
<span class="cardinal s">S</span>
<span class="cardinal w">W</span>
<span id="flowNeedle">↑</span>
</div>
<div class="wind-copy">
<div id="windDirection">From W · toward E</div>
<div id="windExplanation">
Air approaches the western slope, rises, and cools.
</div>
</div>
</div>
<input
id="wind"
type="range"
min="0"
max="359"
value="270"
aria-label="Wind direction in degrees, measured as the direction the wind comes from"
>
<div class="range-ends">
<span>0° / N</span>
<span>180° / S</span>
<span>359° / N</span>
</div>
</div>
<div class="readouts">
<div>
<div class="readout-head">
<span>Condensation band</span>
<span id="condensationText">Forming</span>
</div>
<div class="bar"><span id="condensationBar"></span></div>
</div>
<div>
<div class="readout-head">
<span>Downwind rainfall</span>
<span id="rainfallText">Light</span>
</div>
<div class="bar"><span id="rainfallBar"></span></div>
</div>
</div>
<div class="status" id="status">
A cloud band is shown over the windward slope. Rain appears on the
downwind side as a conceptual illustration.
</div>
<p class="disclaimer">
This is a conceptual process visualization, not a weather forecast.
Real cloud and rainfall patterns depend on atmospheric stability,
humidity, terrain, and many other factors.
</p>
<div class="actions">
<button class="button" id="resetView" type="button">Reset view</button>
<button class="button" id="resetControls" type="button">Reset controls</button>
</div>
</aside>
<div id="cloudLabel" class="world-label">
<strong>Condensation zone</strong>
<small>Schematic cooling and cloud formation on the windward slope</small>
</div>
<div id="rainLabel" class="world-label">
<strong>Rainfall zone</strong>
<small>Illustrative precipitation on the downwind side</small>
</div>
<div class="help">Drag to orbit · Scroll to zoom</div>
<div class="legend" aria-hidden="true">
<span><i class="swatch flow"></i>Airflow</span>
<span><i class="swatch cloud"></i>Cloud band</span>
<span><i class="swatch rain"></i>Rain zone</span>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// DOM and shared state
// -------------------------------------------------------------------------
const viewport = document.querySelector("#viewport");
const loading = document.querySelector("#loading");
const moistureInput = document.querySelector("#moisture");
const windInput = document.querySelector("#wind");
const moistureValue = document.querySelector("#moistureValue");
const windValue = document.querySelector("#windValue");
const windDirection = document.querySelector("#windDirection");
const windExplanation = document.querySelector("#windExplanation");
const flowNeedle = document.querySelector("#flowNeedle");
const condensationText = document.querySelector("#condensationText");
const rainfallText = document.querySelector("#rainfallText");
const condensationBar = document.querySelector("#condensationBar");
const rainfallBar = document.querySelector("#rainfallBar");
const status = document.querySelector("#status");
const cloudLabel = document.querySelector("#cloudLabel");
const rainLabel = document.querySelector("#rainLabel");
const state = {
moisture: 68,
windAzimuth: 270
};
const clamp = THREE.MathUtils.clamp;
const smoothstep = THREE.MathUtils.smoothstep;
const fract = (value) => value - Math.floor(value);
function seededRandom(seed) {
let state = seed >>> 0;
return () => {
state += 0x6d2b79f5;
let result = state;
result = Math.imul(result ^ (result >>> 15), result | 1);
result ^= result + Math.imul(result ^ (result >>> 7), result | 61);
return ((result ^ (result >>> 14)) >>> 0) / 4294967296;
};
}
// -------------------------------------------------------------------------
// Renderer, scene, camera, and lighting
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdcebed);
scene.fog = new THREE.Fog(0xdcebed, 48, 92);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
150
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(
0xe8fbff,
0x65745e,
2.25
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff7dc, 3.2);
sun.position.set(-18, 31, 16);
sun.castShadow = true;
sun.shadow.mapSize.set(1024, 1024);
sun.shadow.camera.left = -32;
sun.shadow.camera.right = 32;
sun.shadow.camera.top = 28;
sun.shadow.camera.bottom = -28;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 85;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x9bd8e5, 1.1);
rimLight.position.set(20, 14, -24);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Low-poly terrain
// -------------------------------------------------------------------------
function heightAt(x, z) {
const radial =
(x * x) / (12.8 * 12.8) +
(z * z) / (11.3 * 11.3);
const mainPeak = 16.8 * Math.exp(-1.42 * radial);
const easternPeak = 4.9 * Math.exp(
-(((x - 6.3) ** 2) / 74 + ((z - 3.5) ** 2) / 58)
);
const westernRidge = 3.2 * Math.exp(
-(((x + 6.2) ** 2) / 125 + ((z + 4.7) ** 2) / 82)
);
const foothill = 2.2 * Math.exp(
-(((x + 11.5) ** 2) / 130 + ((z - 7.5) ** 2) / 80)
);
const noise =
(
Math.sin(x * 0.61 + z * 0.17) * 0.58 +
Math.sin(z * 0.77 - x * 0.23) * 0.42 +
Math.sin((x + z) * 0.39) * 0.31
) *
Math.min(1, mainPeak / 4);
return Math.max(
0,
mainPeak + easternPeak + westernRidge + foothill + noise
);
}
function createTerrain() {
const segments = 28;
const width = 42;
const depth = 36;
const positions = [];
const colors = [];
const indices = [];
const lowColor = new THREE.Color(0x567b61);
const middleColor = new THREE.Color(0x7e8370);
const rockColor = new THREE.Color(0x817a70);
const snowColor = new THREE.Color(0xe5ece7);
for (let iz = 0; iz <= segments; iz++) {
for (let ix = 0; ix <= segments; ix++) {
const x = -width / 2 + (ix / segments) * width;
const z = -depth / 2 + (iz / segments) * depth;
const height = heightAt(x, z);
positions.push(x, height, z);
const color = new THREE.Color();
color.copy(lowColor);
color.lerp(middleColor, smoothstep(height, 1.2, 8.5));
color.lerp(rockColor, smoothstep(height, 8, 12.5));
color.lerp(snowColor, smoothstep(height, 12.3, 15.5));
const variation = 0.94 + 0.08 * fract(Math.sin(x * 4.7 + z * 2.3));
color.multiplyScalar(variation);
colors.push(color.r, color.g, color.b);
}
}
for (let iz = 0; iz < segments; iz++) {
for (let ix = 0; ix < segments; ix++) {
const a = iz * (segments + 1) + ix;
const b = a + 1;
const c = a + segments + 1;
const d = c + 1;
indices.push(a, c, b, b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
flatShading: true,
roughness: 0.96,
metalness: 0
});
const terrain = new THREE.Mesh(geometry, material);
terrain.castShadow = true;
terrain.receiveShadow = true;
scene.add(terrain);
// Build a faceted skirt so the terrain reads as a solid diorama.
const perimeter = [];
for (let ix = 0; ix <= segments; ix++) {
const x = -width / 2 + (ix / segments) * width;
perimeter.push({ x, z: -depth / 2 });
}
for (let iz = 1; iz <= segments; iz++) {
const z = -depth / 2 + (iz / segments) * depth;
perimeter.push({ x: width / 2, z });
}
for (let ix = segments - 1; ix >= 0; ix--) {
const x = -width / 2 + (ix / segments) * width;
perimeter.push({ x, z: depth / 2 });
}
for (let iz = segments - 1; iz >= 1; iz--) {
const z = -depth / 2 + (iz / segments) * depth;
perimeter.push({ x: -width / 2, z });
}
const skirtPositions = [];
const skirtIndices = [];
const bottom = -3.1;
for (let i = 0; i < perimeter.length; i++) {
const a = perimeter[i];
const b = perimeter[(i + 1) % perimeter.length];
const ah = heightAt(a.x, a.z);
const bh = heightAt(b.x, b.z);
const offset = skirtPositions.length / 3;
skirtPositions.push(
a.x, ah, a.z,
b.x, bh, b.z,
a.x, bottom, a.z,
b.x, bottom, b.z
);
skirtIndices.push(
offset, offset + 2, offset + 1,
offset + 1, offset + 2, offset + 3
);
}
const skirtGeometry = new THREE.BufferGeometry();
skirtGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(skirtPositions, 3)
);
skirtGeometry.setIndex(skirtIndices);
skirtGeometry.computeVertexNormals();
const skirt = new THREE.Mesh(
skirtGeometry,
new THREE.MeshStandardMaterial({
color: 0x4b625b,
roughness: 1,
flatShading: true,
side: THREE.DoubleSide
})
);
skirt.receiveShadow = true;
scene.add(skirt);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
new THREE.MeshStandardMaterial({
color: 0xc9ded9,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = bottom - 0.025;
ground.receiveShadow = true;
scene.add(ground);
}
createTerrain();
// -------------------------------------------------------------------------
// Instanced low-poly trees
// -------------------------------------------------------------------------
function createTrees() {
const random = seededRandom(4219);
const placements = [];
for (let attempt = 0; attempt < 140 && placements.length < 64; attempt++) {
const x = (random() - 0.5) * 35;
const z = (random() - 0.5) * 29;
const height = heightAt(x, z);
if (height > 5.2 || height < 0.35) continue;
if (Math.hypot(x, z) < 3.2) continue;
placements.push({
x,
z,
height,
scale: 0.65 + random() * 0.75,
rotation: random() * Math.PI * 2
});
}
const count = placements.length;
const trunkGeometry = new THREE.CylinderGeometry(0.13, 0.18, 1.1, 5);
trunkGeometry.translate(0, 0.55, 0);
const crownGeometry = new THREE.ConeGeometry(0.58, 1.55, 5);
crownGeometry.translate(0, 1.42, 0);
const trunks = new THREE.InstancedMesh(
trunkGeometry,
new THREE.MeshStandardMaterial({
color: 0x6d5944,
roughness: 1,
flatShading: true
}),
count
);
const crowns = new THREE.InstancedMesh(
crownGeometry,
new THREE.MeshStandardMaterial({
color: 0x315f4b,
roughness: 1,
flatShading: true
}),
count
);
const dummy = new THREE.Object3D();
const treeColors = [
new THREE.Color(0x315f4b),
new THREE.Color(0x3b6d52),
new THREE.Color(0x2c594a),
new THREE.Color(0x477659)
];
placements.forEach((tree, index) => {
dummy.position.set(tree.x, tree.height, tree.z);
dummy.rotation.set(0, tree.rotation, 0);
dummy.scale.setScalar(tree.scale);
dummy.updateMatrix();
trunks.setMatrixAt(index, dummy.matrix);
crowns.setMatrixAt(index, dummy.matrix);
crowns.setColorAt(index, treeColors[index % treeColors.length]);
});
trunks.castShadow = true;
crowns.castShadow = true;
trunks.receiveShadow = true;
crowns.receiveShadow = true;
scene.add(trunks, crowns);
}
createTrees();
// -------------------------------------------------------------------------
// Direction helpers
// -------------------------------------------------------------------------
function getWindVectors() {
const radians = THREE.MathUtils.degToRad(state.windAzimuth);
// Meteorological direction: 0° means wind comes from north.
const source = new THREE.Vector3(
Math.sin(radians),
0,
-Math.cos(radians)
).normalize();
const toward = source.clone().negate();
const cross = new THREE.Vector3(-source.z, 0, source.x);
return { source, toward, cross };
}
function cardinalName(degrees) {
const names = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"];
return names[Math.round(((degrees % 360) + 360) % 360 / 45) % 8];
}
// -------------------------------------------------------------------------
// Cloud group
// -------------------------------------------------------------------------
const cloudGeometry = new THREE.IcosahedronGeometry(1, 0);
const clouds = [];
const random = seededRandom(90210);
for (let cloudIndex = 0; cloudIndex < 8; cloudIndex++) {
const group = new THREE.Group();
const puffCount = 5 + (cloudIndex % 3);
const puffData = [];
for (let puffIndex = 0; puffIndex < puffCount; puffIndex++) {
const material = new THREE.MeshStandardMaterial({
color:
puffIndex % 3 === 0
? 0xf0f5f1
: puffIndex % 3 === 1
? 0xddebed
: 0xc9dce0,
roughness: 1,
metalness: 0,
flatShading: true,
transparent: true,
opacity: 0.9,
depthWrite: false
});
const puff = new THREE.Mesh(cloudGeometry, material);
const scaleX = 0.85 + random() * 0.65;
const scaleY = 0.55 + random() * 0.38;
const scaleZ = 0.75 + random() * 0.58;
puff.scale.set(scaleX, scaleY, scaleZ);
puff.position.set(
(random() - 0.5) * 2.2,
(random() - 0.45) * 0.75,
(random() - 0.5) * 1.35
);
group.add(puff);
puffData.push({ puff, baseOpacity: 0.74 + random() * 0.22 });
}
group.userData.puffs = puffData;
group.userData.seed = random();
group.userData.phase = random() * Math.PI * 2;
group.userData.cross = (random() - 0.5) * 8.5;
group.userData.heightOffset = random() * 2.2;
clouds.push(group);
scene.add(group);
}
// -------------------------------------------------------------------------
// Terrain-conforming schematic zones
// -------------------------------------------------------------------------
function createZone(radius, color) {
const geometry = new THREE.CircleGeometry(radius, 18);
geometry.rotateX(-Math.PI / 2);
const local = [];
const position = geometry.attributes.position;
for (let i = 0; i < position.count; i++) {
local.push({
x: position.getX(i),
z: position.getZ(i)
});
}
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0,
depthWrite: false,
side: THREE.DoubleSide,
polygonOffset: true,
polygonOffsetFactor: -1
});
const mesh = new THREE.Mesh(geometry, material);
mesh.renderOrder = 2;
scene.add(mesh);
return { mesh, local, center: new THREE.Vector3() };
}
const condensationZone = createZone(5.6, 0x79d9d3);
const rainfallZone = createZone(4.8, 0x5799ca);
function updateZone(zone, center, source, cross, alongStretch, crossStretch) {
zone.center.copy(center);
const position = zone.mesh.geometry.attributes.position;
zone.local.forEach((local, index) => {
const along = local.x * source.x + local.z * source.z;
const across = local.x * cross.x + local.z * cross.z;
const x =
center.x +
source.x * along * alongStretch +
cross.x * across * crossStretch;
const z =
center.z +
source.z * along * alongStretch +
cross.z * across * crossStretch;
position.setXYZ(index, x, heightAt(x, z) + 0.14, z);
});
position.needsUpdate = true;
}
// -------------------------------------------------------------------------
// Flow lines and wind arrow
// -------------------------------------------------------------------------
const flowLines = [];
for (let i = 0; i < 3; i++) {
const geometry = new THREE.BufferGeometry();
const material = new THREE.LineDashedMaterial({
color: 0x278b92,
transparent: true,
opacity: 0.32,
dashSize: 0.65,
gapSize: 0.42,
depthWrite: false
});
const line = new THREE.Line(geometry, material);
line.renderOrder = 3;
scene.add(line);
flowLines.push(line);
}
const windArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(),
7,
0x167b83,
1.5,
0.8
);
scene.add(windArrow);
function updateFlowPaths() {
const { source, toward, cross } = getWindVectors();
flowLines.forEach((line, lineIndex) => {
const offset = (lineIndex - 1) * 2.25;
const crossOffset = cross.clone().multiplyScalar(offset);
const path = [];
const addPoint = (distance, lift) => {
const position = source
.clone()
.multiplyScalar(distance)
.add(crossOffset);
position.y = heightAt(position.x, position.z) + lift;
path.push(position);
};
addPoint(16, 2.1);
addPoint(10, 5.0);
addPoint(4, 11.2);
const crest = toward.clone().multiplyScalar(4).add(crossOffset);
crest.y = heightAt(crest.x, crest.z) + 10.5;
path.push(crest);
const lee = toward.clone().multiplyScalar(11).add(crossOffset);
lee.y = heightAt(lee.x, lee.z) + 5.0;
path.push(lee);
addPoint(-17, 2.1);
const curve = new THREE.CatmullRomCurve3(
path,
false,
"catmullrom",
0.45
);
line.geometry.setFromPoints(curve.getPoints(80));
line.computeLineDistances();
});
windArrow.setDirection(toward);
const arrowPosition = source.clone().multiplyScalar(15.5);
arrowPosition.y = heightAt(arrowPosition.x, arrowPosition.z) + 3.4;
windArrow.position.copy(arrowPosition);
windArrow.setLength(7, 1.5, 0.8);
updateZone(
condensationZone,
source.clone().multiplyScalar(5.4),
source,
cross,
1.12,
0.92
);
updateZone(
rainfallZone,
toward.clone().multiplyScalar(7.3),
source,
cross,
1.28,
0.82
);
}
// -------------------------------------------------------------------------
// Rising condensation motes
// -------------------------------------------------------------------------
const moteCount = 110;
const motePositions = new Float32Array(moteCount * 3);
const moteSeeds = [];
for (let i = 0; i < moteCount; i++) {
moteSeeds.push({
phase: random(),
along: 1.5 + random() * 7.5,
across: (random() - 0.5) * 8.5,
speed: 0.045 + random() * 0.055
});
}
const moteGeometry = new THREE.BufferGeometry();
moteGeometry.setAttribute(
"position",
new THREE.BufferAttribute(motePositions, 3).setUsage(
THREE.DynamicDrawUsage
)
);
const motes = new THREE.Points(
moteGeometry,
new THREE.PointsMaterial({
color: 0xd8ffff,
size: 0.17,
transparent: true,
opacity: 0,
depthWrite: false,
sizeAttenuation: true
})
);
scene.add(motes);
// -------------------------------------------------------------------------
// Moving wind streaks
// -------------------------------------------------------------------------
const windStreakCount = 60;
const windStreakPositions = new Float32Array(windStreakCount * 6);
const windStreakSeeds = [];
for (let i = 0; i < windStreakCount; i++) {
windStreakSeeds.push({
phase: random(),
across: (random() - 0.5) * 11,
speed: 0.045 + random() * 0.065
});
}
const windStreakGeometry = new THREE.BufferGeometry();
windStreakGeometry.setAttribute(
"position",
new THREE.BufferAttribute(windStreakPositions, 3).setUsage(
THREE.DynamicDrawUsage
)
);
const windStreaks = new THREE.LineSegments(
windStreakGeometry,
new THREE.LineBasicMaterial({
color: 0xf1ffff,
transparent: true,
opacity: 0.45,
depthWrite: false
})
);
scene.add(windStreaks);
// -------------------------------------------------------------------------
// Schematic rain streaks
// -------------------------------------------------------------------------
const rainCount = 170;
const rainPositions = new Float32Array(rainCount * 6);
const rainSeeds = [];
for (let i = 0; i < rainCount; i++) {
rainSeeds.push({
phase: random(),
along: 1.2 + random() * 13.5,
across: (random() - 0.5) * 7.2,
speed: 0.42 + random() * 0.55,
top: 13 + random() * 8
});
}
const rainGeometry = new THREE.BufferGeometry();
rainGeometry.setAttribute(
"position",
new THREE.BufferAttribute(rainPositions, 3).setUsage(
THREE.DynamicDrawUsage
)
);
const rainMaterial = new THREE.LineBasicMaterial({
color: 0x397fb8,
transparent: true,
opacity: 0,
depthWrite: false
});
const rain = new THREE.LineSegments(rainGeometry, rainMaterial);
rain.renderOrder = 4;
scene.add(rain);
// -------------------------------------------------------------------------
// Dynamic visual updates
// -------------------------------------------------------------------------
const labelVector = new THREE.Vector3();
function updateDynamic(time) {
const { source, toward, cross } = getWindVectors();
const moisture = state.moisture;
const condensationAmount = smoothstep(moisture, 12, 96);
const rainfallAmount = smoothstep(moisture, 42, 100);
// Cloud band: grows, thickens, and rises from the windward slope.
clouds.forEach((cloud, index) => {
const threshold = 14 + index * 7.2;
const visibility = smoothstep(moisture, threshold, threshold + 17);
const along = 9.8 - (index / (clouds.length - 1)) * 8.1;
const across = cloud.userData.cross;
const x =
source.x * along +
cross.x * across;
const z =
source.z * along +
cross.z * across;
const terrainHeight = heightAt(x, z);
const bob = Math.sin(time * 0.55 + cloud.userData.phase) * 0.22;
cloud.position.set(
x,
terrainHeight + 4.1 + cloud.userData.heightOffset + bob,
z
);
const size =
0.58 +
condensationAmount * 1.03 +
(index % 3) * 0.08;
cloud.scale.set(size * 1.14, size * 0.78, size);
cloud.visible = visibility > 0.015;
cloud.userData.puffs.forEach(({ puff, baseOpacity }) => {
puff.material.opacity = visibility * baseOpacity;
});
});
condensationZone.mesh.material.opacity =
0.045 + condensationAmount * 0.17;
rainfallZone.mesh.material.opacity =
0.025 + rainfallAmount * 0.16;
// Rising condensation particles.
const moteAttribute = moteGeometry.attributes.position;
moteSeeds.forEach((seed, index) => {
const rise = fract(seed.phase + time * seed.speed);
const along = seed.along - rise * 2.3;
const x =
source.x * along +
cross.x * seed.across;
const z =
source.z * along +
cross.z * seed.across;
const ground = heightAt(x, z);
const y = ground + 0.6 + rise * (7.5 + condensationAmount * 5);
moteAttribute.setXYZ(index, x, y, z);
});
moteAttribute.needsUpdate = true;
motes.material.opacity = 0.08 + condensationAmount * 0.42;
// Wind streaks.
const streakAttribute = windStreakGeometry.attributes.position;
windStreakSeeds.forEach((seed, index) => {
const travel = fract(seed.phase + time * seed.speed);
const along = 15.5 - travel * 31;
const x = source.x * along + cross.x * seed.across;
const z = source.z * along + cross.z * seed.across;
const y =
heightAt(x, z) +
2.2 +
Math.sin(travel * Math.PI) * 7.5;
const endX = x - source.x * 0.8;
const endZ = z - source.z * 0.8;
const offset = index * 6;
windStreakPositions[offset] = x;
windStreakPositions[offset + 1] = y;
windStreakPositions[offset + 2] = z;
windStreakPositions[offset + 3] = endX;
windStreakPositions[offset + 4] = y + 0.08;
windStreakPositions[offset + 5] = endZ;
});
streakAttribute.needsUpdate = true;
windStreaks.material.opacity = 0.16 + condensationAmount * 0.25;
// Rain: only a portion of the buffer is drawn as moisture increases.
const visibleRainCount = Math.floor(rainfallAmount * rainCount);
rainGeometry.setDrawRange(0, visibleRainCount * 2);
rainMaterial.opacity = 0.28 + rainfallAmount * 0.48;
const rainAttribute = rainGeometry.attributes.position;
for (let index = 0; index < visibleRainCount; index++) {
const seed = rainSeeds[index];
const drop = fract(seed.phase + time * seed.speed);
const x =
toward.x * seed.along +
cross.x * seed.across;
const z =
toward.z * seed.along +
cross.z * seed.across;
const ground = heightAt(x, z) + 0.15;
const cloudBase = Math.max(seed.top, ground + 3);
const y = cloudBase - drop * (cloudBase - ground);
const offset = index * 6;
rainPositions[offset] = x;
rainPositions[offset + 1] = y;
rainPositions[offset + 2] = z;
rainPositions[offset + 3] = x - 0.08;
rainPositions[offset + 4] = Math.max(ground, y - 0.72);
rainPositions[offset + 5] = z;
}
rainAttribute.needsUpdate = true;
// Screen-space labels follow their schematic zones.
const cloudAnchor = source.clone().multiplyScalar(5.8);
cloudAnchor.y = heightAt(cloudAnchor.x, cloudAnchor.z) + 8.8;
labelVector.copy(cloudAnchor).project(camera);
const cloudVisible = labelVector.z > -1 && labelVector.z < 1;
cloudLabel.style.left =
`${(labelVector.x * 0.5 + 0.5) * window.innerWidth}px`;
cloudLabel.style.top =
`${(-labelVector.y * 0.5 + 0.5) * window.innerHeight}px`;
cloudLabel.style.opacity = cloudVisible
? String(0.55 + condensationAmount * 0.45)
: "0";
const rainAnchor = toward.clone().multiplyScalar(7.5);
rainAnchor.y = heightAt(rainAnchor.x, rainAnchor.z) + 4.7;
labelVector.copy(rainAnchor).project(camera);
const rainVisible = labelVector.z > -1 && labelVector.z < 1;
rainLabel.style.left =
`${(labelVector.x * 0.5 + 0.5) * window.innerWidth}px`;
rainLabel.style.top =
`${(-labelVector.y * 0.5 + 0.5) * window.innerHeight}px`;
rainLabel.style.opacity = rainVisible
? String(0.2 + rainfallAmount * 0.8)
: "0";
}
// -------------------------------------------------------------------------
// UI
// -------------------------------------------------------------------------
function setRangeFill(input) {
const percent =
((Number(input.value) - Number(input.min)) /
(Number(input.max) - Number(input.min))) *
100;
input.style.setProperty("--pct", `${percent}%`);
}
function updateUI() {
const moisture = state.moisture;
const condensationAmount = smoothstep(moisture, 12, 96);
const rainfallAmount = smoothstep(moisture, 42, 100);
moistureValue.textContent = `${moisture}%`;
moistureInput.style.setProperty(
"--pct",
`${moisture}%`
);
const from = cardinalName(state.windAzimuth);
const to = cardinalName((state.windAzimuth + 180) % 360);
windValue.textContent = `From ${from}`;
windDirection.textContent = `From ${from} · toward ${to}`;
const flowDegrees = (state.windAzimuth + 180) % 360;
flowNeedle.style.transform =
`translate(-50%, -50%) rotate(${flowDegrees}deg)`;
windExplanation.textContent =
`Air approaches the ${from.toLowerCase()} side, rises over the mountain, ` +
`and cools toward the ${to.toLowerCase()} side.`;
condensationBar.style.width =
`${condensationAmount * 100}%`;
rainfallBar.style.width =
`${rainfallAmount * 100}%`;
if (moisture < 25) {
condensationText.textContent = "Limited";
rainfallText.textContent = "None shown";
status.textContent =
"Little condensation is shown because the illustrative air is relatively dry. " +
"The airflow still illustrates uplift over the mountain.";
} else if (moisture < 48) {
condensationText.textContent = "Beginning";
rainfallText.textContent = "None shown";
status.textContent =
"A small cloud band begins to form near the windward crest as rising air cools. " +
"No substantial rainfall zone is shown.";
} else if (moisture < 72) {
condensationText.textContent = "Forming";
rainfallText.textContent = "Light";
status.textContent =
"A cloud band is shown over the windward slope. A light, illustrative " +
"rainfall zone appears on the downwind side.";
} else {
condensationText.textContent = "Broad band";
rainfallText.textContent = "Strong";
status.textContent =
"A broad cloud band and a more visible downwind rainfall zone are shown. " +
"This remains a conceptual illustration, not a prediction.";
}
}
moistureInput.addEventListener("input", () => {
state.moisture = Number(moistureInput.value);
updateUI();
});
windInput.addEventListener("input", () => {
state.windAzimuth = Number(windInput.value);
setRangeFill(windInput);
updateUI();
updateFlowPaths();
});
document.querySelector("#resetControls").addEventListener("click", () => {
state.moisture = 68;
state.windAzimuth = 270;
moistureInput.value = "68";
windInput.value = "270";
setRangeFill(moistureInput);
setRangeFill(windInput);
updateUI();
updateFlowPaths();
});
// -------------------------------------------------------------------------
// Direct camera controls: orbit and zoom
// -------------------------------------------------------------------------
const cameraState = {
yaw: 0.72,
pitch: 0.62,
distance: 39,
target: new THREE.Vector3(0, 4.3, 0)
};
function updateCamera() {
const horizontal =
Math.cos(cameraState.pitch) * cameraState.distance;
camera.position.set(
cameraState.target.x +
Math.sin(cameraState.yaw) * horizontal,
cameraState.target.y +
Math.sin(cameraState.pitch) * cameraState.distance,
cameraState.target.z +
Math.cos(cameraState.yaw) * horizontal
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.yaw = 0.72;
cameraState.pitch = 0.62;
cameraState.distance = 39;
cameraState.target.set(0, 4.3, 0);
updateCamera();
}
document.querySelector("#resetView").addEventListener("click", resetCamera);
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraState.yaw -= deltaX * 0.006;
cameraState.pitch = clamp(
cameraState.pitch + deltaY * 0.0045,
0.28,
1.25
);
});
function stopDragging(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (
event &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.distance = clamp(
cameraState.distance * Math.exp(event.deltaY * 0.001),
22,
58
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// -------------------------------------------------------------------------
// Initialization and render loop
// -------------------------------------------------------------------------
setRangeFill(moistureInput);
setRangeFill(windInput);
updateUI();
updateFlowPaths();
updateCamera();
const clock = new THREE.Clock();
let firstFrame = true;
renderer.setAnimationLoop(() => {
const elapsed = clock.getElapsedTime();
updateCamera();
updateDynamic(elapsed);
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 300);
}
});
</script>
</body>
</html>
```