Prompt specification
Build or customize the Three.js 3D scene "Wind observations over a schoolyard" 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: Wind observations over a schoolyard
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/wind-observations-over-a-schoolyard-x1278
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring wind observations around a schoolyard in a clean stylized style. Place a low wall, an open grass area, a paved corner, and several small instrument stands with separate direction vanes and speed indicators. Animate one prescribed airflow direction and give the stations synthetic readings that can be compared side by side. Keep the readings explicitly illustrative rather than claiming a computed wind field around the wall. The vanes should indicate direction while the separate meters indicate speed, so those two observations are not confused. Let one station be selected without moving the other instruments.
Working Three.js Starter (wind-observations-over-a-schoolyard-x1278):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Schoolyard Wind — Illustrative Observations</title>
<style>
:root {
--ink: #17313d;
--muted: #607783;
--panel: rgba(255, 255, 255, 0.91);
--line: rgba(23, 49, 61, 0.13);
--coral: #e96f51;
--teal: #159b98;
--amber: #f2bd54;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
background: #dcecef;
}
#scene,
#scene canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
}
#scene canvas {
touch-action: none;
outline: none;
}
.hud {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.card {
position: absolute;
pointer-events: auto;
border: 1px solid rgba(255, 255, 255, 0.82);
border-radius: 18px;
background: var(--panel);
box-shadow:
0 16px 45px rgba(36, 72, 83, 0.14),
0 2px 6px rgba(36, 72, 83, 0.06);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
.intro {
top: 20px;
left: 20px;
width: 350px;
padding: 19px 20px 17px;
}
.eyebrow {
margin: 0 0 6px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 25px;
line-height: 1.08;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 14px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 12px;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
min-width: 0;
padding: 9px;
border-radius: 11px;
background: rgba(238, 245, 245, 0.85);
color: #415c66;
font-size: 11px;
font-weight: 700;
}
.legend-symbol {
position: relative;
flex: 0 0 26px;
width: 26px;
height: 26px;
border-radius: 8px;
background: white;
box-shadow: inset 0 0 0 1px var(--line);
}
.legend-symbol.direction::after {
content: "";
position: absolute;
left: 5px;
top: 12px;
width: 14px;
height: 3px;
border-radius: 3px;
background: var(--coral);
transform: rotate(-18deg);
}
.legend-symbol.direction::before {
content: "";
position: absolute;
right: 4px;
top: 7px;
width: 0;
height: 0;
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
border-left: 7px solid var(--coral);
transform: rotate(-18deg);
}
.legend-symbol.speed::after {
content: "m/s";
position: absolute;
inset: 0;
display: grid;
place-items: center;
color: var(--teal);
font-size: 9px;
font-weight: 900;
}
.disclaimer {
margin: 0;
padding: 11px 12px;
border-left: 3px solid var(--amber);
border-radius: 4px 10px 10px 4px;
background: #fff5dc;
color: #705b2b;
font-size: 11px;
line-height: 1.45;
}
.readout {
top: 20px;
right: 20px;
width: 330px;
padding: 18px;
}
.card-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 12px;
}
.card-heading h2 {
margin: 0;
font-size: 13px;
letter-spacing: 0.02em;
}
.small-pill {
padding: 5px 8px;
border-radius: 999px;
background: #e7f3f2;
color: var(--teal);
font-size: 10px;
font-weight: 800;
text-transform: uppercase;
letter-spacing: 0.07em;
}
.station-heading {
display: flex;
align-items: center;
gap: 11px;
margin-bottom: 13px;
}
.station-badge {
display: grid;
place-items: center;
width: 43px;
height: 43px;
flex: 0 0 43px;
border-radius: 13px;
background: var(--amber);
color: #503b13;
font-size: 20px;
font-weight: 900;
box-shadow: 0 6px 16px rgba(242, 189, 84, 0.25);
}
.station-heading strong {
display: block;
font-size: 16px;
}
.station-heading small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 11px;
}
.measurements {
margin: 0;
border-top: 1px solid var(--line);
}
.measurement {
display: grid;
grid-template-columns: 1fr auto;
gap: 10px;
align-items: baseline;
padding: 10px 0;
border-bottom: 1px solid var(--line);
}
.measurement dt {
color: var(--muted);
font-size: 11px;
font-weight: 700;
}
.measurement dd {
margin: 0;
text-align: right;
font-size: 13px;
font-weight: 800;
}
.measurement .speed-value {
color: var(--teal);
font-size: 24px;
letter-spacing: -0.04em;
}
.measurement .unit {
color: var(--muted);
font-size: 11px;
font-weight: 700;
}
.selection-note {
margin: 12px 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.station-buttons {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
}
.station-button {
height: 34px;
border: 1px solid var(--line);
border-radius: 9px;
background: white;
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 850;
cursor: pointer;
transition: 140ms ease;
}
.station-button:hover {
border-color: var(--amber);
transform: translateY(-1px);
}
.station-button.active {
border-color: var(--amber);
background: #fff4d8;
box-shadow: 0 0 0 2px rgba(242, 189, 84, 0.18);
}
.direction-card {
top: 337px;
right: 20px;
width: 330px;
padding: 16px 18px;
}
.direction-main {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
}
.direction-main strong {
display: block;
font-size: 14px;
}
.direction-main small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 11px;
}
.direction-arrow {
display: grid;
place-items: center;
width: 60px;
height: 60px;
flex: 0 0 60px;
border-radius: 50%;
background: #fff0eb;
color: var(--coral);
font-size: 33px;
font-weight: 900;
}
.direction-card p {
margin: 11px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.pause-button {
width: 100%;
margin-top: 12px;
padding: 9px;
border: 1px solid var(--line);
border-radius: 10px;
background: white;
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 800;
cursor: pointer;
}
.pause-button:hover {
border-color: var(--teal);
color: var(--teal);
}
.comparison {
bottom: 20px;
left: 20px;
width: 440px;
padding: 17px 18px;
}
.comparison .card-heading {
margin-bottom: 8px;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 11px;
}
th,
td {
padding: 8px 6px;
border-bottom: 1px solid var(--line);
text-align: left;
}
thead th {
color: var(--muted);
font-size: 9px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
tbody tr {
cursor: pointer;
transition: background 130ms ease;
}
tbody tr:hover,
tbody tr.selected {
background: #fff6df;
}
tbody th {
width: 50px;
}
.row-station {
width: 26px;
height: 26px;
border: 0;
border-radius: 8px;
background: #eaf1f2;
color: var(--ink);
font: inherit;
font-weight: 900;
cursor: pointer;
}
.selected .row-station {
background: var(--amber);
}
.speed-cell {
color: var(--teal);
font-weight: 900;
white-space: nowrap;
}
.comparison-note {
margin: 9px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.controls-help {
right: 20px;
bottom: 20px;
padding: 11px 14px;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.controls-help strong {
color: var(--ink);
}
@media (max-width: 820px) {
.intro {
width: min(330px, calc(100vw - 40px));
}
.readout {
top: auto;
right: 20px;
bottom: 20px;
width: 300px;
}
.direction-card {
top: 20px;
right: 20px;
width: 285px;
}
.comparison {
display: none;
}
.controls-help {
display: none;
}
}
@media (max-width: 590px) {
.intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
}
.intro h1 {
font-size: 21px;
}
.legend,
.subtitle {
display: none;
}
.disclaimer {
font-size: 10px;
}
.direction-card {
top: 185px;
right: 12px;
width: 230px;
padding: 12px;
}
.direction-arrow {
width: 46px;
height: 46px;
flex-basis: 46px;
font-size: 25px;
}
.readout {
right: 12px;
bottom: 12px;
width: calc(100vw - 24px);
padding: 13px;
}
.measurement {
padding: 7px 0;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="hud">
<section class="card intro">
<p class="eyebrow">Schoolyard wind study</p>
<h1>Illustrative observations</h1>
<p class="subtitle">
A prescribed airflow moves across the yard. Compare independent station
readouts without mistaking direction for speed.
</p>
<div class="legend">
<div class="legend-item">
<span class="legend-symbol direction"></span>
<span>Coral vane = direction</span>
</div>
<div class="legend-item">
<span class="legend-symbol speed"></span>
<span>Teal display = speed</span>
</div>
</div>
<p class="disclaimer">
<strong>Illustrative only.</strong> The speeds are authored synthetic
point samples for visual comparison. They are not calculated from a
wind field around the wall.
</p>
</section>
<section class="card readout">
<div class="card-heading">
<h2>Selected station</h2>
<span class="small-pill">Live readout</span>
</div>
<div class="station-heading">
<div class="station-badge" id="selectedBadge">A</div>
<div>
<strong id="selectedName">West lawn</strong>
<small id="selectedLocation">Grass area</small>
</div>
</div>
<dl class="measurements">
<div class="measurement">
<dt>Direction vane</dt>
<dd>
From 240° WSW
<br>
<span class="unit">Arrow points toward 060° ENE</span>
</dd>
</div>
<div class="measurement">
<dt>Separate speed meter</dt>
<dd>
<span class="speed-value" id="selectedSpeed">2.3</span>
<span class="unit">m/s</span>
</dd>
</div>
</dl>
<p class="selection-note">
Selection changes only the highlight and readout. No instrument or
other station is repositioned.
</p>
<div class="station-buttons" id="stationButtons"></div>
</section>
<section class="card direction-card">
<div class="card-heading">
<h2>Prescribed airflow</h2>
<span class="small-pill">Single direction</span>
</div>
<div class="direction-main">
<div>
<strong>From 240° WSW</strong>
<small>Toward 060° ENE</small>
</div>
<div class="direction-arrow" aria-hidden="true">↗</div>
</div>
<p>
All coral direction vanes settle toward the same downwind heading.
Teal meters show only speed.
</p>
<button class="pause-button" id="pauseButton" type="button">
Pause airflow animation
</button>
</section>
<section class="card comparison">
<div class="card-heading">
<h2>Side-by-side synthetic samples</h2>
<span class="small-pill">m/s</span>
</div>
<table>
<thead>
<tr>
<th>Station</th>
<th>Location</th>
<th>Speed meter</th>
</tr>
</thead>
<tbody id="comparisonRows"></tbody>
</table>
<p class="comparison-note">
Authored values for this illustration; not a computed local wind field.
Click a row or a station to select it.
</p>
</section>
<section class="card controls-help">
<strong>Camera:</strong> drag to orbit · scroll to zoom<br>
<strong>Scene:</strong> click a station to select it
</section>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Data: the speed values are deliberately authored synthetic samples.
// They do not represent a computed airflow field.
// ---------------------------------------------------------------------
const FLOW_FROM_BEARING = 240;
const FLOW_TO_BEARING = 60;
const stations = [
{
id: "A",
name: "West lawn",
location: "Grass area",
speed: 2.3,
position: [-8.2, 0, -4.4]
},
{
id: "B",
name: "North lawn",
location: "Grass area",
speed: 3.6,
position: [-1.1, 0, -5.5]
},
{
id: "C",
name: "East lawn",
location: "Near low wall",
speed: 4.4,
position: [5.0, 0, -3.5]
},
{
id: "D",
name: "Paved corner",
location: "Paved area",
speed: 3.1,
position: [8.4, 0, 5.3]
}
];
const host = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdcecef);
scene.fog = new THREE.Fog(0xdcecef, 39, 72);
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.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
host.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 1.2, -1.2);
let cameraYaw = 0.73;
let cameraPitch = 0.88;
let cameraRadius = 31;
function updateCamera() {
const sinPitch = Math.sin(cameraPitch);
camera.position.set(
cameraTarget.x + cameraRadius * sinPitch * Math.sin(cameraYaw),
cameraTarget.y + cameraRadius * Math.cos(cameraPitch),
cameraTarget.z + cameraRadius * sinPitch * Math.cos(cameraYaw)
);
camera.lookAt(cameraTarget);
}
updateCamera();
// ---------------------------------------------------------------------
// Lighting and material palette
// ---------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xf6fcff, 0x9db783, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4dc, 3.25);
sun.position.set(-13, 24, 15);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -25;
sun.shadow.camera.right = 25;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -22;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00025;
scene.add(sun);
const materials = {
grass: new THREE.MeshStandardMaterial({
color: 0xa9ca91,
roughness: 0.96
}),
grassEdge: new THREE.MeshStandardMaterial({
color: 0x91b77b,
roughness: 1
}),
soil: new THREE.MeshStandardMaterial({
color: 0xb8aa89,
roughness: 1
}),
pavement: new THREE.MeshStandardMaterial({
color: 0xc9d0d1,
roughness: 0.9
}),
line: new THREE.MeshStandardMaterial({
color: 0xf7f3e9,
roughness: 0.85
}),
wall: new THREE.MeshStandardMaterial({
color: 0xe9dfc8,
roughness: 0.86
}),
wallCap: new THREE.MeshStandardMaterial({
color: 0xf4ead5,
roughness: 0.8
}),
building: new THREE.MeshStandardMaterial({
color: 0xf0e8d8,
roughness: 0.85
}),
roof: new THREE.MeshStandardMaterial({
color: 0x58777c,
roughness: 0.8
}),
window: new THREE.MeshStandardMaterial({
color: 0x80b8c7,
roughness: 0.28,
metalness: 0.08
}),
trunk: new THREE.MeshStandardMaterial({
color: 0x8e694d,
roughness: 1
}),
leaves: new THREE.MeshStandardMaterial({
color: 0x78a875,
roughness: 0.94,
flatShading: true
}),
metal: new THREE.MeshStandardMaterial({
color: 0x61737a,
roughness: 0.52,
metalness: 0.35
}),
coral: new THREE.MeshStandardMaterial({
color: 0xe96f51,
roughness: 0.55,
metalness: 0.08
}),
coralLight: new THREE.MeshStandardMaterial({
color: 0xf49b82,
roughness: 0.6
}),
teal: new THREE.MeshStandardMaterial({
color: 0x159b98,
roughness: 0.48,
metalness: 0.1
}),
tealDark: new THREE.MeshStandardMaterial({
color: 0x286b70,
roughness: 0.56,
metalness: 0.14
}),
footing: new THREE.MeshStandardMaterial({
color: 0xe0dfd7,
roughness: 0.85
})
};
function addMesh(
geometry,
material,
position = [0, 0, 0],
parent = scene,
castShadow = true,
receiveShadow = true
) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
// ---------------------------------------------------------------------
// Schoolyard: grass, paved corner, low walls, building, and landscaping
// ---------------------------------------------------------------------
addMesh(
new THREE.BoxGeometry(38, 0.45, 28),
materials.soil,
[0, -0.32, 0]
);
addMesh(
new THREE.BoxGeometry(37.4, 0.16, 27.4),
materials.grass,
[0, -0.08, 0]
);
// A narrow darker lawn border makes the open grass area legible.
addMesh(
new THREE.BoxGeometry(39, 0.08, 29),
materials.grassEdge,
[0, -0.22, 0],
scene,
false,
true
);
// Paved corner in the southeast part of the yard.
addMesh(
new THREE.BoxGeometry(11.3, 0.12, 9.5),
materials.pavement,
[11.1, 0, 4.8]
);
// Simple court markings.
addMesh(
new THREE.BoxGeometry(9.7, 0.025, 0.065),
materials.line,
[11.1, 0.077, 0.75],
scene,
false,
false
);
addMesh(
new THREE.BoxGeometry(9.7, 0.025, 0.065),
materials.line,
[11.1, 0.077, 8.85],
scene,
false,
false
);
addMesh(
new THREE.BoxGeometry(0.065, 0.025, 8.1),
materials.line,
[6.3, 0.078, 4.8],
scene,
false,
false
);
addMesh(
new THREE.BoxGeometry(0.065, 0.025, 8.1),
materials.line,
[15.9, 0.078, 4.8],
scene,
false,
false
);
addMesh(
new THREE.BoxGeometry(0.065, 0.025, 8.1),
materials.line,
[11.1, 0.078, 4.8],
scene,
false,
false
);
// Low north wall.
addMesh(
new THREE.BoxGeometry(32, 1.15, 0.48),
materials.wall,
[0, 0.575, -11.55]
);
addMesh(
new THREE.BoxGeometry(32.4, 0.16, 0.66),
materials.wallCap,
[0, 1.2, -11.55]
);
// Low west wall.
addMesh(
new THREE.BoxGeometry(0.48, 1.15, 19.3),
materials.wall,
[-16.55, 0.575, -1.85]
);
addMesh(
new THREE.BoxGeometry(0.66, 0.16, 19.6),
materials.wallCap,
[-16.55, 1.2, -1.85]
);
// Subtle wall joints.
for (let x = -14; x <= 14; x += 4) {
addMesh(
new THREE.BoxGeometry(0.045, 1.05, 0.51),
materials.wallCap,
[x, 0.55, -11.55]
);
}
// Stylized school building behind the north wall.
addMesh(
new THREE.BoxGeometry(24, 4.5, 4.3),
materials.building,
[0, 2.25, -15.2]
);
addMesh(
new THREE.BoxGeometry(24.7, 0.38, 4.8),
materials.roof,
[0, 4.65, -15.2]
);
for (let x = -9; x <= 9; x += 3) {
addMesh(
new THREE.BoxGeometry(1.65, 1.55, 0.08),
materials.window,
[x, 2.65, -13.01]
);
addMesh(
new THREE.BoxGeometry(1.85, 0.08, 0.12),
materials.wallCap,
[x, 1.79, -12.98]
);
}
addMesh(
new THREE.BoxGeometry(2.2, 2.6, 0.12),
materials.tealDark,
[0, 1.3, -12.98]
);
addMesh(
new THREE.BoxGeometry(0.07, 2.6, 0.15),
materials.wallCap,
[0, 1.3, -12.89]
);
// A few stylized trees behind the wall.
function addTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
addMesh(
new THREE.CylinderGeometry(0.16, 0.23, 2.5, 9),
materials.trunk,
[0, 1.25, 0],
group
);
addMesh(
new THREE.IcosahedronGeometry(1.35, 1),
materials.leaves,
[0, 3.0, 0],
group
);
addMesh(
new THREE.IcosahedronGeometry(0.9, 1),
materials.leaves,
[-0.65, 2.35, 0.12],
group
);
}
addTree(-14.3, -14.3, 1.05);
addTree(12.7, -14.5, 1.15);
addTree(16.4, -8.7, 0.9);
// ---------------------------------------------------------------------
// Canvas-based labels and meter faces
// ---------------------------------------------------------------------
function roundedRect(context, x, y, w, h, radius) {
const r = Math.min(radius, w / 2, h / 2);
context.beginPath();
context.moveTo(x + r, y);
context.arcTo(x + w, y, x + w, y + h, r);
context.arcTo(x + w, y + h, x, y + h, r);
context.arcTo(x, y + h, x, y, r);
context.arcTo(x, y, x + w, y, r);
context.closePath();
}
function makeTexture(canvas) {
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function makeStationLabel(station) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 220;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(context, 10, 10, 492, 200, 34);
context.fillStyle = "rgba(255,255,255,0.96)";
context.fill();
context.lineWidth = 9;
context.strokeStyle = "#e5ecec";
context.stroke();
roundedRect(context, 28, 30, 112, 160, 24);
context.fillStyle = "#f2bd54";
context.fill();
context.fillStyle = "#17313d";
context.font = "900 82px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(station.id, 84, 112);
context.textAlign = "left";
context.font = "800 35px system-ui, sans-serif";
context.fillText(station.name, 164, 86);
context.fillStyle = "#607783";
context.font = "600 25px system-ui, sans-serif";
context.fillText(station.location, 164, 137);
const material = new THREE.SpriteMaterial({
map: makeTexture(canvas),
transparent: true,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(2.35, 1.01, 1);
return sprite;
}
function makeSpeedGauge(station) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 320;
const context = canvas.getContext("2d");
roundedRect(context, 8, 8, 496, 304, 34);
context.fillStyle = "#103b45";
context.fill();
context.lineWidth = 12;
context.strokeStyle = "#35bdb6";
context.stroke();
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = "#a9e2df";
context.font = "800 27px system-ui, sans-serif";
context.fillText(`STATION ${station.id} · SPEED`, 256, 55);
context.fillStyle = "#ffffff";
context.font = "900 104px system-ui, sans-serif";
context.fillText(station.speed.toFixed(1), 256, 157);
context.fillStyle = "#75d8d2";
context.font = "800 35px system-ui, sans-serif";
context.fillText("m/s", 256, 231);
context.fillStyle = "#87aaa9";
context.font = "700 21px system-ui, sans-serif";
context.fillText("SYNTHETIC SAMPLE", 256, 280);
const material = new THREE.SpriteMaterial({
map: makeTexture(canvas),
transparent: true,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(1.38, 0.86, 1);
return sprite;
}
function makeNoticeSprite() {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 300;
const context = canvas.getContext("2d");
roundedRect(context, 8, 8, 1008, 284, 34);
context.fillStyle = "#fff2cf";
context.fill();
context.lineWidth = 12;
context.strokeStyle = "#e5ad42";
context.stroke();
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = "#725725";
context.font = "900 51px system-ui, sans-serif";
context.fillText("ILLUSTRATIVE SAMPLES", 512, 102);
context.fillStyle = "#8b6c35";
context.font = "700 35px system-ui, sans-serif";
context.fillText("Not a computed wind field", 512, 178);
context.font = "600 25px system-ui, sans-serif";
context.fillText("Authored values for visual comparison", 512, 231);
const material = new THREE.SpriteMaterial({
map: makeTexture(canvas),
transparent: true,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(6.4, 1.875, 1);
return sprite;
}
// ---------------------------------------------------------------------
// Instrument construction
// ---------------------------------------------------------------------
function makeDirectionArrow(materialSet) {
const arrow = new THREE.Group();
const shaft = addMesh(
new THREE.BoxGeometry(1.18, 0.075, 0.075),
materialSet,
[-0.03, 0, 0],
arrow
);
const point = addMesh(
new THREE.ConeGeometry(0.19, 0.43, 4),
materialSet,
[0.76, 0, 0],
arrow
);
point.rotation.z = -Math.PI / 2;
const tail = addMesh(
new THREE.BoxGeometry(0.38, 0.28, 0.055),
materialSet,
[-0.57, 0.12, 0],
arrow
);
return arrow;
}
const stationObjects = new Map();
const pickTargets = [];
for (const station of stations) {
const group = new THREE.Group();
group.position.set(...station.position);
scene.add(group);
const haloMaterial = new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.18,
depthWrite: false,
side: THREE.DoubleSide
});
const halo = addMesh(
new THREE.RingGeometry(1.55, 1.7, 64),
haloMaterial,
[0, 0.062, 0],
group,
false,
false
);
halo.rotation.x = -Math.PI / 2;
// The direction vane has its own stand.
const vaneStand = new THREE.Group();
vaneStand.position.set(-0.9, 0, 0.14);
group.add(vaneStand);
addMesh(
new THREE.CylinderGeometry(0.3, 0.34, 0.12, 20),
materials.footing,
[0, 0.06, 0],
vaneStand
);
addMesh(
new THREE.CylinderGeometry(0.045, 0.055, 2.16, 12),
materials.coral,
[0, 1.13, 0],
vaneStand
);
addMesh(
new THREE.CylinderGeometry(0.085, 0.085, 0.16, 16),
materials.coralLight,
[0, 2.18, 0],
vaneStand
);
const vanePivot = new THREE.Group();
vanePivot.position.y = 2.34;
vaneStand.add(vanePivot);
const vaneArrow = makeDirectionArrow(materials.coral);
vanePivot.add(vaneArrow);
const directionTag = makeStationLabel({
id: "DIR",
name: "Direction",
location: "Arrow = downwind"
});
directionTag.scale.set(1.65, 0.71, 1);
directionTag.position.set(0, 1.34, 0.08);
vaneStand.add(directionTag);
// The speed display has a separate stand and a distinct teal housing.
const meterStand = new THREE.Group();
meterStand.position.set(0.93, 0, 0.14);
group.add(meterStand);
addMesh(
new THREE.CylinderGeometry(0.31, 0.35, 0.12, 20),
materials.footing,
[0, 0.06, 0],
meterStand
);
addMesh(
new THREE.CylinderGeometry(0.055, 0.065, 1.05, 12),
materials.tealDark,
[0, 0.58, 0],
meterStand
);
addMesh(
new THREE.BoxGeometry(0.95, 0.78, 0.25),
materials.teal,
[0, 1.28, 0],
meterStand
);
const gauge = makeSpeedGauge(station);
gauge.position.set(0, 1.3, 0.19);
meterStand.add(gauge);
addMesh(
new THREE.CylinderGeometry(0.035, 0.035, 0.62, 10),
materials.metal,
[0, 1.95, 0],
meterStand
);
// A small three-cup rotor visually reinforces the speed instrument.
const rotor = new THREE.Group();
rotor.position.set(0, 2.27, 0);
meterStand.add(rotor);
addMesh(
new THREE.SphereGeometry(0.105, 12, 8),
materials.tealDark,
[0, 0, 0],
rotor
);
for (let i = 0; i < 3; i++) {
const angle = (i / 3) * Math.PI * 2;
const arm = addMesh(
new THREE.BoxGeometry(0.48, 0.035, 0.035),
materials.tealDark,
[0, 0, 0],
rotor
);
arm.rotation.y = angle;
arm.position.x = Math.cos(angle) * 0.24;
arm.position.z = -Math.sin(angle) * 0.24;
const cup = addMesh(
new THREE.SphereGeometry(0.13, 12, 8),
materials.teal,
[
Math.cos(angle) * 0.49,
0,
-Math.sin(angle) * 0.49
],
rotor
);
cup.scale.set(1, 0.7, 1);
}
const label = makeStationLabel(station);
label.position.set(0, 3.02, 0);
group.add(label);
// Invisible but raycastable selection volume.
const pickMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false,
colorWrite: false
});
const pickMesh = addMesh(
new THREE.SphereGeometry(2.05, 12, 8),
pickMaterial,
[0, 1.45, 0],
group,
false,
false
);
pickMesh.userData.stationId = station.id;
pickTargets.push(pickMesh);
stationObjects.set(station.id, {
group,
halo,
haloMaterial,
vanePivot,
rotor
});
}
// A physical notice in the scene repeats the illustrative-data caveat.
const noticePost = new THREE.Group();
noticePost.position.set(-11.1, 0, 9.1);
scene.add(noticePost);
addMesh(
new THREE.CylinderGeometry(0.07, 0.09, 2.3, 10),
materials.metal,
[-1.7, 1.15, 0],
noticePost
);
addMesh(
new THREE.CylinderGeometry(0.07, 0.09, 2.3, 10),
materials.metal,
[1.7, 1.15, 0],
noticePost
);
const notice = makeNoticeSprite();
notice.position.set(0, 2.15, 0);
noticePost.add(notice);
// ---------------------------------------------------------------------
// Prescribed airflow and animated arrows
// ---------------------------------------------------------------------
const toRadians = THREE.MathUtils.degToRad;
const flowDirection = new THREE.Vector3(
Math.sin(toRadians(FLOW_TO_BEARING)),
0,
-Math.cos(toRadians(FLOW_TO_BEARING))
).normalize();
const flowAcross = new THREE.Vector3(
-flowDirection.z,
0,
flowDirection.x
).normalize();
const targetVaneRotation = Math.atan2(
-flowDirection.z,
flowDirection.x
);
const flowMaterial = new THREE.MeshBasicMaterial({
color: 0x5b99a8,
transparent: true,
opacity: 0.38,
depthWrite: false
});
const flowArrows = [];
for (let i = 0; i < 15; i++) {
const arrow = new THREE.Group();
addMesh(
new THREE.BoxGeometry(0.88, 0.035, 0.045),
flowMaterial,
[-0.12, 0, 0],
arrow,
false,
false
);
const point = addMesh(
new THREE.ConeGeometry(0.11, 0.3, 3),
flowMaterial,
[0.48, 0, 0],
arrow,
false,
false
);
point.rotation.z = -Math.PI / 2;
arrow.rotation.y = targetVaneRotation;
const along = -24 + i * 3.3 + (i % 3) * 0.65;
const across = -12 + ((i * 7.4) % 24);
const height = 3.3 + ((i * 1.37) % 4.2);
arrow.position
.copy(flowDirection)
.multiplyScalar(along)
.addScaledVector(flowAcross, across);
arrow.position.y = height;
scene.add(arrow);
flowArrows.push({
group: arrow,
along,
across,
height,
rate: 1.35 + (i % 4) * 0.08
});
}
// ---------------------------------------------------------------------
// Selection UI and station picking
// ---------------------------------------------------------------------
let selectedStationId = "A";
let paused = false;
const selectedBadge = document.getElementById("selectedBadge");
const selectedName = document.getElementById("selectedName");
const selectedLocation = document.getElementById("selectedLocation");
const selectedSpeed = document.getElementById("selectedSpeed");
const stationButtons = document.getElementById("stationButtons");
const comparisonRows = document.getElementById("comparisonRows");
const pauseButton = document.getElementById("pauseButton");
for (const station of stations) {
const button = document.createElement("button");
button.className = "station-button";
button.type = "button";
button.dataset.stationId = station.id;
button.textContent = station.id;
button.addEventListener("click", () => selectStation(station.id));
stationButtons.appendChild(button);
const row = document.createElement("tr");
row.dataset.stationId = station.id;
row.innerHTML = `
<th scope="row">
<button class="row-station" type="button"
aria-label="Select station ${station.id}">${station.id}</button>
</th>
<td>${station.location}</td>
<td class="speed-cell">${station.speed.toFixed(1)} m/s</td>
`;
row.addEventListener("click", () => selectStation(station.id));
comparisonRows.appendChild(row);
}
function selectStation(id) {
if (!stationObjects.has(id)) return;
selectedStationId = id;
const station = stations.find((item) => item.id === id);
selectedBadge.textContent = station.id;
selectedName.textContent = station.name;
selectedLocation.textContent = station.location;
selectedSpeed.textContent = station.speed.toFixed(1);
for (const [stationId, object] of stationObjects) {
const isSelected = stationId === id;
object.haloMaterial.color.setHex(
isSelected ? 0xf2bd54 : 0xffffff
);
object.haloMaterial.opacity = isSelected ? 0.96 : 0.16;
}
for (const button of stationButtons.querySelectorAll("button")) {
button.classList.toggle(
"active",
button.dataset.stationId === id
);
}
for (const row of comparisonRows.querySelectorAll("tr")) {
row.classList.toggle(
"selected",
row.dataset.stationId === id
);
}
}
selectStation(selectedStationId);
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused
? "Resume airflow animation"
: "Pause airflow animation";
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function raycastStation(clientX, clientY) {
const rect = renderer.domElement.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(pickTargets, false);
return hits.length ? hits[0].object.userData.stationId : null;
}
// ---------------------------------------------------------------------
// Direct camera controls: orbit and zoom, without external add-ons
// ---------------------------------------------------------------------
let dragging = false;
let movedWhileDragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
movedWhileDragging = false;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (dragging) {
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
if (Math.abs(dx) + Math.abs(dy) > 2) {
movedWhileDragging = true;
}
cameraYaw -= dx * 0.0055;
cameraPitch = THREE.MathUtils.clamp(
cameraPitch - dy * 0.0045,
0.3,
1.35
);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
} else {
const stationId = raycastStation(event.clientX, event.clientY);
renderer.domElement.style.cursor = stationId
? "pointer"
: "grab";
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!movedWhileDragging) {
const stationId = raycastStation(event.clientX, event.clientY);
if (stationId) selectStation(stationId);
}
dragging = false;
renderer.domElement.style.cursor = "grab";
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.018,
17,
46
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.style.cursor = "grab";
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
function dampAngle(current, target, lambda, delta) {
const difference = Math.atan2(
Math.sin(target - current),
Math.cos(target - current)
);
return current + difference * (1 - Math.exp(-lambda * delta));
}
const clock = new THREE.Clock();
// Start the vanes at slightly different headings so they visibly
// settle toward the same prescribed airflow direction.
for (const [index, station] of stations.entries()) {
const object = stationObjects.get(station.id);
object.vanePivot.rotation.y =
targetVaneRotation + (index - 1.5) * 0.55;
}
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) {
for (const station of stations) {
const object = stationObjects.get(station.id);
object.vanePivot.rotation.y = dampAngle(
object.vanePivot.rotation.y,
targetVaneRotation,
3.4,
delta
);
// Rotor rate is a visual cue tied to the authored speed sample.
object.rotor.rotation.y +=
station.speed * 1.65 * delta;
}
for (const arrow of flowArrows) {
arrow.along += arrow.rate * delta;
if (arrow.along > 24) {
arrow.along = -24;
}
arrow.group.position
.copy(flowDirection)
.multiplyScalar(arrow.along)
.addScaledVector(flowAcross, arrow.across);
arrow.group.position.y = arrow.height;
}
}
renderer.render(scene, camera);
});
</script>
</body>
</html>
```