Prompt specification
Build or customize the Three.js 3D scene "Change wind direction in a schematic dune-transport model" 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: Change wind direction in a schematic dune-transport model
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/change-wind-direction-in-a-schematic-dune-transport-mo-x3096
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts the Namib Desert's coastal dunes. Let users rotate an assumed wind vector and inspect sand-motion arrows. Preserve the existing terrain while labeling any resulting landform evolution as qualitative and illustrative. Low-poly.
Working Three.js Starter (change-wind-direction-in-a-schematic-dune-transport-mo-x3096):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Namib Coastal Dunes — Qualitative Wind Study</title>
<style>
:root {
color-scheme: dark;
--ink: #f5f0e6;
--muted: #b8c1bb;
--glass: rgba(20, 31, 30, 0.78);
--glass-strong: rgba(16, 25, 24, 0.92);
--line: rgba(230, 237, 228, 0.18);
--cyan: #57e0d1;
--sand: #f1bd69;
--rust: #b96843;
--warning: #ffd17a;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9e5df;
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%;
cursor: grab;
touch-action: none;
outline: none;
}
#viewport canvas.dragging {
cursor: grabbing;
}
.ui {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.panel {
pointer-events: auto;
background:
linear-gradient(
145deg,
rgba(35, 49, 46, 0.88),
rgba(15, 24, 23, 0.76)
);
border: 1px solid var(--line);
border-radius: 16px;
box-shadow:
0 16px 45px rgba(16, 24, 22, 0.22),
inset 0 1px 0 rgba(255, 255, 255, 0.05);
backdrop-filter: blur(16px) saturate(115%);
-webkit-backdrop-filter: blur(16px) saturate(115%);
}
.intro {
position: absolute;
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 19px 21px 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: #b8cbc5;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 1px;
content: "";
background: var(--cyan);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(27px, 3vw, 38px);
font-weight: 500;
line-height: 1.03;
letter-spacing: -0.025em;
}
.intro p {
max-width: 340px;
margin: 10px 0 14px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.chips {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
.chip {
padding: 6px 9px;
border: 1px solid var(--line);
border-radius: 999px;
color: #dbe4de;
background: rgba(255, 255, 255, 0.045);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.chip.accent {
border-color: rgba(87, 224, 209, 0.34);
color: var(--cyan);
background: rgba(87, 224, 209, 0.08);
}
.status {
position: absolute;
top: 24px;
right: 24px;
width: 288px;
padding: 16px 17px;
}
.status-row {
display: flex;
align-items: flex-start;
gap: 10px;
}
.status-dot {
width: 8px;
height: 8px;
flex: 0 0 auto;
margin-top: 5px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 0 4px rgba(87, 224, 209, 0.11);
}
.status strong {
display: block;
font-size: 12px;
letter-spacing: 0.02em;
}
.status p {
margin: 4px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.qualitative-note {
margin-top: 13px;
padding: 10px 11px;
border-left: 2px solid var(--warning);
border-radius: 0 8px 8px 0;
background: rgba(255, 209, 122, 0.075);
color: #e7dfcd;
font-size: 10.5px;
line-height: 1.45;
}
.qualitative-note b {
color: var(--warning);
}
.wind-panel {
position: absolute;
bottom: 24px;
left: 24px;
width: 304px;
padding: 17px;
}
.panel-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 13px;
}
.panel-heading h2 {
margin: 0;
font-size: 12px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.panel-heading span {
color: #9caaa4;
font-size: 9px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.wind-content {
display: grid;
grid-template-columns: 118px 1fr;
gap: 15px;
align-items: center;
}
.compass {
position: relative;
width: 118px;
height: 118px;
touch-action: none;
cursor: grab;
outline: none;
}
.compass:active {
cursor: grabbing;
}
.compass:focus-visible {
border-radius: 50%;
box-shadow: 0 0 0 3px rgba(87, 224, 209, 0.35);
}
.compass svg {
display: block;
width: 100%;
height: 100%;
overflow: visible;
}
.cardinal {
position: absolute;
color: #9eaaa5;
font-size: 8px;
font-weight: 800;
pointer-events: none;
}
.cardinal.n { top: -3px; left: 50%; transform: translateX(-50%); }
.cardinal.e { right: -2px; top: 50%; transform: translateY(-50%); }
.cardinal.s { bottom: -3px; left: 50%; transform: translateX(-50%); }
.cardinal.w { left: -4px; top: 50%; transform: translateY(-50%); }
.bearing-readout small {
display: block;
margin-bottom: 3px;
color: #91a19a;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.bearing-readout strong {
display: block;
color: var(--cyan);
font-family: Georgia, "Times New Roman", serif;
font-size: 34px;
font-weight: 500;
line-height: 1;
}
.bearing-readout em {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 9px;
font-style: normal;
line-height: 1.35;
}
.range-row {
margin-top: 15px;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
border-radius: 999px;
appearance: none;
background: linear-gradient(
90deg,
rgba(87, 224, 209, 0.78),
rgba(87, 224, 209, 0.16)
);
cursor: ew-resize;
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
border: 2px solid #15302c;
border-radius: 50%;
appearance: none;
background: var(--cyan);
box-shadow: 0 0 0 3px rgba(87, 224, 209, 0.12);
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 2px solid #15302c;
border-radius: 50%;
background: var(--cyan);
}
.legend {
display: flex;
align-items: center;
gap: 9px;
margin-top: 12px;
color: #aab5af;
font-size: 9.5px;
line-height: 1.35;
}
.legend-gradient {
width: 76px;
height: 5px;
flex: 0 0 auto;
border-radius: 999px;
background: linear-gradient(90deg, var(--rust), var(--sand));
}
.inspector {
position: absolute;
right: 24px;
bottom: 24px;
width: 286px;
padding: 16px 17px;
}
.inspector[hidden] {
display: none;
}
.inspector-top {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 11px;
}
.inspector-top h2 {
margin: 0;
font-size: 12px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.close-button {
width: 25px;
height: 25px;
padding: 0;
border: 1px solid var(--line);
border-radius: 50%;
color: #cad3ce;
background: transparent;
cursor: pointer;
}
.close-button:hover {
color: white;
background: rgba(255, 255, 255, 0.08);
}
.metric {
display: flex;
justify-content: space-between;
gap: 15px;
padding: 7px 0;
border-top: 1px solid rgba(255, 255, 255, 0.08);
color: var(--muted);
font-size: 10.5px;
}
.metric b {
color: #f1e7d3;
font-weight: 650;
text-align: right;
}
.inspector-note {
margin-top: 9px;
color: #9facA6;
font-size: 10px;
line-height: 1.45;
}
.scene-tag {
position: absolute;
z-index: 3;
max-width: 245px;
padding: 7px 10px;
border: 1px solid rgba(255, 209, 122, 0.42);
border-radius: 8px;
opacity: 0;
color: #f4e8cf;
background: rgba(33, 39, 34, 0.85);
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.16);
font-size: 9px;
line-height: 1.35;
letter-spacing: 0.035em;
pointer-events: none;
transform: translate(-50%, -115%);
transition: opacity 150ms ease;
}
.scene-tag::before {
display: inline-block;
width: 5px;
height: 5px;
margin-right: 6px;
border-radius: 50%;
content: "";
background: var(--warning);
vertical-align: 1px;
}
.scene-tag.wind {
border-color: rgba(87, 224, 209, 0.45);
color: #d9fff8;
}
.scene-tag.wind::before {
background: var(--cyan);
}
.hint {
position: absolute;
left: 50%;
bottom: 25px;
padding: 8px 13px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 999px;
color: rgba(248, 247, 238, 0.86);
background: rgba(25, 37, 34, 0.55);
backdrop-filter: blur(10px);
font-size: 9.5px;
letter-spacing: 0.025em;
transform: translateX(-50%);
white-space: nowrap;
}
@media (max-width: 760px) {
.intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.intro p {
margin: 8px 0 10px;
font-size: 11px;
}
.status {
top: 168px;
right: 12px;
width: 238px;
padding: 12px 13px;
}
.status .qualitative-note {
display: none;
}
.wind-panel {
bottom: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px;
}
.wind-content {
grid-template-columns: 92px 1fr;
}
.compass {
width: 92px;
height: 92px;
}
.bearing-readout strong {
font-size: 28px;
}
.range-row,
.legend {
margin-top: 9px;
}
.inspector {
right: 12px;
bottom: 220px;
width: 238px;
}
.hint {
display: none;
}
.scene-tag {
display: none;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div class="ui">
<header class="intro panel">
<div class="eyebrow">Coastal geomorphology / interpretive model</div>
<h1>Namib coastal dunes</h1>
<p>
Rotate the assumed wind vector, then select a sand-motion arrow to
inspect its qualitative transport cue. The low-poly terrain remains fixed.
</p>
<div class="chips">
<span class="chip accent">Interactive wind</span>
<span class="chip">Low-poly terrain</span>
<span class="chip">Qualitative only</span>
</div>
</header>
<aside class="status panel">
<div class="status-row">
<span class="status-dot"></span>
<div>
<strong>Terrain held fixed</strong>
<p>
Wind updates only the directional arrows and interpretive exposure
cues. No erosion or deposition is applied to the mesh.
</p>
</div>
</div>
<div class="qualitative-note">
<b>Possible landform evolution:</b> windward reworking and lee-side
shadowing may occur. These cues are qualitative and illustrative only.
</div>
</aside>
<section class="wind-panel panel">
<div class="panel-heading">
<h2>Assumed wind vector</h2>
<span>Direction of travel</span>
</div>
<div class="wind-content">
<div
id="compass"
class="compass"
role="slider"
tabindex="0"
aria-label="Wind vector bearing"
aria-valuemin="0"
aria-valuemax="359"
aria-valuenow="35"
>
<svg viewBox="0 0 120 120" aria-hidden="true">
<circle
cx="60"
cy="60"
r="47"
fill="rgba(255,255,255,0.025)"
stroke="rgba(255,255,255,0.14)"
stroke-width="1"
/>
<circle
cx="60"
cy="60"
r="34"
fill="none"
stroke="rgba(255,255,255,0.07)"
stroke-width="1"
stroke-dasharray="2 5"
/>
<path
d="M60 13V24 M60 96V107 M13 60H24 M96 60H107"
stroke="rgba(255,255,255,0.27)"
stroke-width="1"
/>
<g id="windNeedle" transform="rotate(35 60 60)">
<line
x1="60"
y1="60"
x2="60"
y2="25"
stroke="#57e0d1"
stroke-width="3"
stroke-linecap="round"
/>
<polygon points="60,13 53,27 67,27" fill="#57e0d1" />
<circle cx="60" cy="60" r="5" fill="#183c38" stroke="#57e0d1" stroke-width="2" />
</g>
</svg>
<span class="cardinal n">N</span>
<span class="cardinal e">E</span>
<span class="cardinal s">S</span>
<span class="cardinal w">W</span>
</div>
<div class="bearing-readout">
<small>Flow toward</small>
<strong id="bearingValue">035°</strong>
<em>Assumed vector, not measured data</em>
</div>
</div>
<div class="range-row">
<input
id="bearingRange"
type="range"
min="0"
max="359"
step="1"
value="35"
aria-label="Wind vector bearing in degrees"
>
</div>
<div class="legend">
<span class="legend-gradient"></span>
<span>Illustrative relative transport cue: low → high exposure</span>
</div>
</section>
<aside id="inspector" class="inspector panel" hidden>
<div class="inspector-top">
<h2>Sand-motion cue</h2>
<button id="closeInspector" class="close-button" aria-label="Close inspector">×</button>
</div>
<div class="metric">
<span>Arrow</span>
<b id="arrowId">—</b>
</div>
<div class="metric">
<span>Assumed flow</span>
<b id="arrowBearing">—</b>
</div>
<div class="metric">
<span>Exposure cue</span>
<b id="arrowExposure">—</b>
</div>
<div class="metric">
<span>Interpretation</span>
<b id="arrowInterpretation">—</b>
</div>
<p class="inspector-note">
Direction follows the assumed wind. Length and color suggest only
qualitative local exposure and must not be read as measured sand flux.
</p>
</aside>
<div id="windwardTag" class="scene-tag">
ILLUSTRATIVE · possible windward reworking
</div>
<div id="leeTag" class="scene-tag">
ILLUSTRATIVE · possible lee-side shadowing
</div>
<div id="windTag" class="scene-tag wind">
ASSUMED WIND VECTOR · not measured
</div>
<div class="hint">
Drag to orbit · wheel or pinch to zoom · select an arrow to inspect
</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 viewport = document.getElementById("viewport");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd9e5df);
scene.fog = new THREE.Fog(0xd9e5df, 155, 345);
const camera = new THREE.PerspectiveCamera(
44,
window.innerWidth / window.innerHeight,
0.1,
700
);
const cameraState = {
azimuth: 0.62,
polar: 0.88,
distance: 195,
target: new THREE.Vector3(0, 3, 18)
};
function updateCamera() {
const { azimuth, polar, distance, target } = cameraState;
const horizontal = Math.sin(polar) * distance;
camera.position.set(
target.x + Math.sin(azimuth) * horizontal,
target.y + Math.cos(polar) * distance,
target.z + Math.cos(azimuth) * horizontal
);
camera.lookAt(target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xe7f1ed, 0x8a5f3d, 2.15);
scene.add(hemisphere);
const sunlight = new THREE.DirectionalLight(0xffe0ad, 3.0);
sunlight.position.set(-90, 115, 65);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(2048, 2048);
sunlight.shadow.camera.left = -145;
sunlight.shadow.camera.right = 145;
sunlight.shadow.camera.top = 145;
sunlight.shadow.camera.bottom = -145;
sunlight.shadow.camera.near = 1;
sunlight.shadow.camera.far = 330;
sunlight.shadow.bias = -0.00035;
sunlight.shadow.normalBias = 0.25;
scene.add(sunlight);
function mulberry32(seed) {
return function () {
let t = (seed += 0x6d2b79f5);
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const clamp = THREE.MathUtils.clamp;
function coastZ(x) {
return -52 + 4 * Math.sin(x * 0.047) + 2 * Math.sin(x * 0.111);
}
/*
The terrain function is evaluated exactly once when constructing the
static mesh. Wind changes never call this function to alter geometry.
*/
function terrainHeight(x, z) {
const coast = coastZ(x);
const inland = z - coast;
let height;
if (inland < 0) {
height = -1.25 + inland * 0.035;
} else {
height = -1.25 + inland * 0.038;
height += 0.28 * Math.sin(x * 0.13 + z * 0.09);
height += 0.22 * Math.sin(x * 0.23) * Math.sin(z * 0.07);
const ridge1 = -22 + x * 0.018 + 2.7 * Math.sin(x * 0.052);
const ridge2 = 15 + x * 0.028 + 3.1 * Math.sin(x * 0.038);
const ridge3 = 59 + x * 0.021 + 4.0 * Math.sin(x * 0.031);
height += 6.4 * Math.exp(-Math.pow((z - ridge1) / 5.2, 2));
height += 7.2 * Math.exp(-Math.pow((z - ridge2) / 5.8, 2));
height += 6.0 * Math.exp(-Math.pow((z - ridge3) / 6.5, 2));
height +=
3.6 *
Math.exp(
-Math.pow(x + 47, 2) / 470 -
Math.pow(z + 2, 2) / 78
);
height +=
4.1 *
Math.exp(
-Math.pow(x - 42, 2) / 540 -
Math.pow(z - 39, 2) / 92
);
height +=
3.8 *
Math.exp(
-Math.pow(x - 4, 2) / 610 -
Math.pow(z - 82, 2) / 120
);
}
return height;
}
const terrainWidth = 230;
const terrainDepth = 205;
const terrainZMin = -75;
const columns = 72;
const rows = 62;
const stepX = terrainWidth / columns;
const stepZ = terrainDepth / rows;
const terrainPositions = [];
const terrainColors = [];
const terrainRandom = mulberry32(41827);
const sandLow = new THREE.Color(0xb97c46);
const sandMid = new THREE.Color(0xd7a35c);
const sandHigh = new THREE.Color(0xf0c985);
const wetSand = new THREE.Color(0x756956);
const faceColor = new THREE.Color();
function pushTriangle(a, b, c) {
const averageHeight = (a[1] + b[1] + c[1]) / 3;
faceColor.copy(sandLow).lerp(sandMid, clamp(averageHeight / 8, 0, 1));
if (averageHeight > 7) {
faceColor.lerp(
sandHigh,
clamp((averageHeight - 7) / 7, 0, 1)
);
}
if (averageHeight < -0.65) {
faceColor.lerp(wetSand, clamp((-averageHeight - 0.65) / 2, 0, 0.75));
}
const variation = 0.94 + terrainRandom() * 0.12;
faceColor.multiplyScalar(variation);
for (const vertex of [a, b, c]) {
terrainPositions.push(vertex[0], vertex[1], vertex[2]);
terrainColors.push(faceColor.r, faceColor.g, faceColor.b);
}
}
for (let iz = 0; iz < rows; iz++) {
for (let ix = 0; ix < columns; ix++) {
const x0 = -terrainWidth / 2 + ix * stepX;
const x1 = x0 + stepX;
const z0 = terrainZMin + iz * stepZ;
const z1 = z0 + stepZ;
const a = [x0, terrainHeight(x0, z0), z0];
const b = [x1, terrainHeight(x1, z0), z0];
const c = [x0, terrainHeight(x0, z1), z1];
const d = [x1, terrainHeight(x1, z1), z1];
// Upward-facing winding.
pushTriangle(a, c, b);
pushTriangle(b, c, d);
}
}
const terrainGeometry = new THREE.BufferGeometry();
terrainGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(terrainPositions, 3)
);
terrainGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(terrainColors, 3)
);
terrainGeometry.computeVertexNormals();
const terrain = new THREE.Mesh(
terrainGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 1,
metalness: 0,
flatShading: true
})
);
terrain.receiveShadow = true;
terrain.castShadow = true;
scene.add(terrain);
// Low-poly ocean.
const oceanGeometry = new THREE.PlaneGeometry(300, 190, 28, 20);
oceanGeometry.rotateX(-Math.PI / 2);
const ocean = new THREE.Mesh(
oceanGeometry,
new THREE.MeshStandardMaterial({
color: 0x24788a,
roughness: 0.38,
metalness: 0.08,
transparent: true,
opacity: 0.88,
flatShading: true,
depthWrite: false
})
);
ocean.position.set(0, -1.13, -117);
ocean.receiveShadow = true;
ocean.renderOrder = 1;
scene.add(ocean);
// A thin, angular surf line following the coast.
const surfPoints = [];
for (let i = 0; i <= 120; i++) {
const x = -112 + (224 * i) / 120;
surfPoints.push(
new THREE.Vector3(
x,
-1.035,
coastZ(x) + 0.55 + 0.25 * Math.sin(x * 0.31)
)
);
}
const surf = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(surfPoints),
new THREE.LineBasicMaterial({
color: 0xe8f4ed,
transparent: true,
opacity: 0.76
})
);
scene.add(surf);
// Sparse offshore wave marks.
const waveMaterial = new THREE.LineBasicMaterial({
color: 0xbce4df,
transparent: true,
opacity: 0.27
});
for (let row = 0; row < 6; row++) {
const points = [];
const z = -67 - row * 14;
for (let i = 0; i < 18; i++) {
const x = -112 + i * 13 + (row % 2) * 4;
points.push(
new THREE.Vector3(
x,
-1.08,
z + Math.sin(i * 1.7 + row) * 1.4
)
);
}
scene.add(
new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
waveMaterial
)
);
}
// Distant low-poly rocky forms, well behind the main dune field.
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0x9d7650,
roughness: 1,
flatShading: true
});
const rockData = [
[-89, 104, 8, 1.8],
[-67, 116, 11, 1.45],
[74, 108, 9, 1.6],
[96, 120, 12, 1.25]
];
for (const [x, z, radius, height] of rockData) {
const rock = new THREE.Mesh(
new THREE.IcosahedronGeometry(radius, 0),
rockMaterial
);
rock.position.set(x, terrainHeight(x, z) + radius * 0.42, z);
rock.scale.set(1.15, height / radius, 0.9);
rock.rotation.set(0.1, x * 0.07, 0.06);
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
}
// Main assumed-wind vector.
const windAnchorX = -86;
const windAnchorZ = 59;
const windGroundY = terrainHeight(windAnchorX, windAnchorZ);
const windOrigin = new THREE.Vector3(
windAnchorX,
windGroundY + 4.8,
windAnchorZ
);
const mast = new THREE.Mesh(
new THREE.CylinderGeometry(0.16, 0.22, 4.5, 6),
new THREE.MeshStandardMaterial({
color: 0x314b47,
roughness: 0.65,
metalness: 0.25,
flatShading: true
})
);
mast.position.set(
windAnchorX,
windGroundY + 2.25,
windAnchorZ
);
mast.castShadow = true;
scene.add(mast);
const windArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
windOrigin,
24,
0x57e0d1,
4.5,
2.2
);
windArrow.line.material.transparent = true;
windArrow.line.material.opacity = 0.95;
windArrow.cone.material.transparent = true;
windArrow.cone.material.opacity = 0.95;
scene.add(windArrow);
// Shared flat arrow geometry.
const arrowShape = new THREE.Shape();
arrowShape.moveTo(-2.55, -0.32);
arrowShape.lineTo(0.75, -0.32);
arrowShape.lineTo(0.75, -0.88);
arrowShape.lineTo(2.55, 0);
arrowShape.lineTo(0.75, 0.88);
arrowShape.lineTo(0.75, 0.32);
arrowShape.lineTo(-2.55, 0.32);
arrowShape.closePath();
const sandArrowGeometry = new THREE.ShapeGeometry(arrowShape);
sandArrowGeometry.rotateX(-Math.PI / 2);
const arrowEntries = [];
const arrowMeshes = [];
const arrowRandom = mulberry32(90210);
const lowArrowColor = new THREE.Color(0xb96843);
const highArrowColor = new THREE.Color(0xffd36a);
let arrowId = 1;
for (let row = 0; row < 7; row++) {
for (let column = 0; column < 10; column++) {
const x =
-101 +
column * 22 +
(arrowRandom() - 0.5) * 10;
const z =
-33 +
row * 21 +
(arrowRandom() - 0.5) * 9;
if (z < coastZ(x) + 5) {
continue;
}
const epsilon = 1.2;
const gradientX =
(terrainHeight(x + epsilon, z) -
terrainHeight(x - epsilon, z)) /
(2 * epsilon);
const gradientZ =
(terrainHeight(x, z + epsilon) -
terrainHeight(x, z - epsilon)) /
(2 * epsilon);
const gradientMagnitude = Math.hypot(gradientX, gradientZ);
const spatialVariation =
0.5 + 0.5 * Math.sin(x * 0.17 + z * 0.11 + 1.4);
const material = new THREE.MeshStandardMaterial({
color: lowArrowColor,
emissive: 0x000000,
emissiveIntensity: 0,
roughness: 0.72,
metalness: 0,
transparent: true,
opacity: 0.9,
side: THREE.DoubleSide,
depthWrite: false,
flatShading: true
});
const mesh = new THREE.Mesh(sandArrowGeometry, material);
mesh.position.set(x, terrainHeight(x, z) + 1.45, z);
mesh.castShadow = false;
mesh.renderOrder = 2;
const entry = {
id: arrowId++,
mesh,
gradientX,
gradientZ,
gradientMagnitude,
spatialVariation,
potential: 0.3,
alignment: 0
};
mesh.userData.entry = entry;
arrowEntries.push(entry);
arrowMeshes.push(mesh);
scene.add(mesh);
}
}
const state = {
bearing: 35,
selected: null,
hovered: null
};
function flowDirection(bearing = state.bearing) {
const radians = THREE.MathUtils.degToRad(bearing);
return new THREE.Vector3(
Math.sin(radians),
0,
-Math.cos(radians)
);
}
function exposureLabel(potential) {
if (potential >= 0.68) return "High";
if (potential >= 0.43) return "Moderate";
return "Low";
}
function interpretationLabel(alignment) {
if (alignment > 0.38) return "Possible windward reworking";
if (alignment < -0.38) return "Possible lee-side sheltering";
return "Possible oblique reworking";
}
function styleArrow(mesh) {
const entry = mesh.userData.entry;
const selected = state.selected === mesh;
const hovered = state.hovered === mesh;
mesh.material.emissive.copy(entry.baseColor || lowArrowColor);
mesh.material.emissiveIntensity = selected ? 0.48 : hovered ? 0.2 : 0;
mesh.material.opacity = selected ? 1 : hovered ? 1 : 0.88;
const scale = selected ? 1.12 : hovered ? 1.06 : 1;
mesh.scale.x = entry.lengthScale * scale;
mesh.scale.y = scale;
mesh.scale.z = scale;
}
function updateInspector() {
const inspector = document.getElementById("inspector");
if (!state.selected) {
inspector.hidden = true;
return;
}
const entry = state.selected.userData.entry;
inspector.hidden = false;
document.getElementById("arrowId").textContent =
`Cue ${String(entry.id).padStart(2, "0")}`;
document.getElementById("arrowBearing").textContent =
`${String(Math.round(state.bearing)).padStart(3, "0")}°`;
document.getElementById("arrowExposure").textContent =
`${exposureLabel(entry.potential)} · illustrative`;
document.getElementById("arrowInterpretation").textContent =
interpretationLabel(entry.alignment);
}
function updateWind() {
const direction = flowDirection();
const arrowRotation = THREE.MathUtils.degToRad(90 - state.bearing);
windArrow.setDirection(direction);
for (const entry of arrowEntries) {
const { mesh, gradientX, gradientZ, gradientMagnitude } = entry;
const alignment =
gradientMagnitude > 0.015
? (gradientX * direction.x + gradientZ * direction.z) /
gradientMagnitude
: 0;
const potential = clamp(
0.17 +
0.65 * clamp(alignment, 0, 1) +
0.18 * entry.spatialVariation,
0.08,
1
);
const color = lowArrowColor.clone().lerp(highArrowColor, potential);
entry.alignment = alignment;
entry.potential = potential;
entry.lengthScale = 0.74 + potential * 0.54;
entry.baseColor = color;
mesh.rotation.y = arrowRotation;
mesh.material.color.copy(color);
mesh.scale.x = entry.lengthScale;
}
document.getElementById("bearingValue").textContent =
`${String(Math.round(state.bearing)).padStart(3, "0")}°`;
document.getElementById("bearingRange").value =
String(Math.round(state.bearing));
document.getElementById("windNeedle").setAttribute(
"transform",
`rotate(${state.bearing} 60 60)`
);
document.getElementById("compass").setAttribute(
"aria-valuenow",
String(Math.round(state.bearing))
);
updateInspector();
}
function selectArrow(mesh) {
state.selected = mesh;
for (const arrow of arrowMeshes) {
styleArrow(arrow);
}
updateInspector();
}
// Wind dial interaction.
const compass = document.getElementById("compass");
const bearingRange = document.getElementById("bearingRange");
function bearingFromPointer(event) {
const rect = compass.getBoundingClientRect();
const centerX = rect.left + rect.width / 2;
const centerY = rect.top + rect.height / 2;
const dx = event.clientX - centerX;
const dy = event.clientY - centerY;
const angle = THREE.MathUtils.radToDeg(
Math.atan2(dx, -dy)
);
return (angle + 360) % 360;
}
let draggingCompass = false;
compass.addEventListener("pointerdown", (event) => {
draggingCompass = true;
compass.setPointerCapture(event.pointerId);
state.bearing = bearingFromPointer(event);
updateWind();
event.preventDefault();
});
compass.addEventListener("pointermove", (event) => {
if (!draggingCompass) return;
state.bearing = bearingFromPointer(event);
updateWind();
});
compass.addEventListener("pointerup", (event) => {
draggingCompass = false;
if (compass.hasPointerCapture(event.pointerId)) {
compass.releasePointerCapture(event.pointerId);
}
});
compass.addEventListener("keydown", (event) => {
let change = 0;
if (event.key === "ArrowLeft" || event.key === "ArrowDown") {
change = -5;
} else if (event.key === "ArrowRight" || event.key === "ArrowUp") {
change = 5;
} else if (event.key === "Home") {
state.bearing = 0;
updateWind();
event.preventDefault();
return;
}
if (change !== 0) {
state.bearing = (state.bearing + change + 360) % 360;
updateWind();
event.preventDefault();
}
});
bearingRange.addEventListener("input", () => {
state.bearing = Number(bearingRange.value);
updateWind();
});
document.getElementById("closeInspector").addEventListener("click", () => {
state.selected = null;
for (const arrow of arrowMeshes) {
styleArrow(arrow);
}
updateInspector();
});
// Direct camera controls: no addons or example scripts.
const canvas = renderer.domElement;
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let draggingCamera = false;
let pointerMoved = false;
let lastPointerX = 0;
let lastPointerY = 0;
let accumulatedPointerDistance = 0;
function raycastArrow(clientX, clientY) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(arrowMeshes, false);
return hits.length ? hits[0].object : null;
}
canvas.addEventListener("pointerdown", (event) => {
if (event.pointerType === "mouse" && event.button !== 0) return;
draggingCamera = true;
pointerMoved = false;
accumulatedPointerDistance = 0;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (draggingCamera) {
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
accumulatedPointerDistance += Math.hypot(dx, dy);
if (accumulatedPointerDistance > 3) pointerMoved = true;
cameraState.azimuth -= dx * 0.006;
cameraState.polar = clamp(
cameraState.polar - dy * 0.005,
0.28,
1.36
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
return;
}
const hovered = raycastArrow(event.clientX, event.clientY);
if (hovered !== state.hovered) {
state.hovered = hovered;
for (const arrow of arrowMeshes) {
styleArrow(arrow);
}
}
canvas.style.cursor = hovered ? "pointer" : "grab";
});
canvas.addEventListener("pointerup", (event) => {
draggingCamera = false;
canvas.classList.remove("dragging");
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
if (!pointerMoved) {
const arrow = raycastArrow(event.clientX, event.clientY);
selectArrow(arrow);
}
});
canvas.addEventListener("pointercancel", () => {
draggingCamera = false;
canvas.classList.remove("dragging");
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.distance = clamp(
cameraState.distance * Math.exp(event.deltaY * 0.001),
78,
285
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
cameraState.azimuth = 0.62;
cameraState.polar = 0.88;
cameraState.distance = 195;
updateCamera();
});
window.addEventListener("keydown", (event) => {
if (event.key === "Escape") {
state.selected = null;
for (const arrow of arrowMeshes) {
styleArrow(arrow);
}
updateInspector();
}
});
// Project the qualitative annotations into screen space.
const windwardTag = document.getElementById("windwardTag");
const leeTag = document.getElementById("leeTag");
const windTag = document.getElementById("windTag");
function positionTag(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.08 &&
Math.abs(projected.y) < 1.08;
if (!visible) {
element.style.opacity = "0";
return;
}
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.opacity = "0.94";
}
function updateAnnotations() {
const direction = flowDirection();
const crest = new THREE.Vector3(8, 0, -18);
crest.y = terrainHeight(crest.x, crest.z) + 3.2;
const windward = crest.clone().addScaledVector(direction, -19);
windward.y = terrainHeight(windward.x, windward.z) + 3.2;
const lee = crest.clone().addScaledVector(direction, 19);
lee.y = terrainHeight(lee.x, lee.z) + 3.2;
const windLabel = windOrigin.clone().addScaledVector(direction, 12);
windLabel.y += 1.5;
positionTag(windwardTag, windward);
positionTag(leeTag, lee);
positionTag(windTag, windLabel);
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
}
window.addEventListener("resize", resize);
updateWind();
updateCamera();
function animate() {
requestAnimationFrame(animate);
updateAnnotations();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```