Prompt specification
Build or customize the Three.js 3D scene "Cup anemometer and vane pair" 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: Cup anemometer and vane pair
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/cup-anemometer-and-vane-pair-x1277
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing wind direction and speed. Model a three-cup rotor beside a directional vane on separate axes; show the vane pointing into wind while rotor speed represents an illustrative speed signal. Low-poly.
Working Three.js Starter (cup-anemometer-and-vane-pair-x1277):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Wind Direction & Speed — Three.js</title>
<style>
:root {
color-scheme: dark;
--bg: #07131d;
--panel: rgba(9, 25, 36, 0.82);
--panel-strong: rgba(11, 31, 44, 0.94);
--border: rgba(151, 224, 235, 0.17);
--text: #edfaff;
--muted: #91aeb9;
--cyan: #55e5d5;
--orange: #ffad57;
--soft: #c6e4eb;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 72% 20%, rgba(28, 93, 106, 0.25), transparent 38%),
radial-gradient(circle at 22% 78%, rgba(44, 70, 98, 0.2), transparent 36%),
linear-gradient(150deg, #0b1c29 0%, var(--bg) 55%, #050d14 100%);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.glass {
border: 1px solid var(--border);
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(16px) saturate(125%);
-webkit-backdrop-filter: blur(16px) saturate(125%);
}
.brand {
position: fixed;
top: 26px;
left: 28px;
z-index: 5;
pointer-events: none;
}
.brand-kicker {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 7px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.brand-kicker::before {
width: 23px;
height: 2px;
content: "";
background: var(--cyan);
box-shadow: 0 0 12px rgba(85, 229, 213, 0.65);
}
.brand h1 {
margin: 0;
font-size: clamp(24px, 3vw, 38px);
font-weight: 720;
letter-spacing: -0.045em;
line-height: 1;
}
.brand p {
margin: 9px 0 0;
color: var(--muted);
font-size: 12px;
letter-spacing: 0.04em;
}
.readouts {
position: fixed;
top: 24px;
right: 24px;
z-index: 5;
display: flex;
gap: 10px;
pointer-events: none;
}
.readout {
min-width: 142px;
padding: 15px 16px 14px;
border-radius: 13px;
}
.readout-label {
display: block;
margin-bottom: 8px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.readout-value {
display: block;
font-size: 25px;
font-weight: 740;
letter-spacing: -0.04em;
line-height: 1;
}
.readout-value small {
color: var(--soft);
font-size: 12px;
font-weight: 550;
letter-spacing: 0;
}
.readout-note {
display: block;
min-height: 13px;
margin-top: 7px;
color: var(--muted);
font-size: 10px;
}
.readout.direction .readout-value {
color: var(--orange);
}
.readout.speed .readout-value {
color: var(--cyan);
}
.signal-track {
width: 100%;
height: 4px;
margin-top: 11px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.09);
}
.signal-fill {
width: 34%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--cyan), #b7fff5);
box-shadow: 0 0 12px rgba(85, 229, 213, 0.45);
transition: width 120ms ease-out;
}
.controls {
position: fixed;
bottom: 24px;
left: 28px;
z-index: 6;
width: min(410px, calc(100vw - 56px));
padding: 18px;
border-radius: 17px;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 16px;
}
.panel-heading h2 {
margin: 0;
font-size: 13px;
font-weight: 750;
letter-spacing: 0.02em;
}
.live {
display: flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.live::before {
width: 6px;
height: 6px;
content: "";
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 10px var(--cyan);
animation: pulse 1.8s infinite;
}
@keyframes pulse {
50% {
opacity: 0.4;
transform: scale(0.75);
}
}
.control-row {
display: grid;
grid-template-columns: 1fr 112px;
align-items: center;
gap: 20px;
}
.control-title {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-bottom: 9px;
}
.control-title label {
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.control-title output {
color: var(--orange);
font-size: 13px;
font-weight: 720;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 7px 0;
appearance: none;
border-radius: 999px;
outline: none;
background: linear-gradient(
90deg,
var(--orange) 0%,
var(--orange) var(--fill, 50%),
rgba(255, 255, 255, 0.1) var(--fill, 50%),
rgba(255, 255, 255, 0.1) 100%
);
cursor: pointer;
}
input[type="range"].speed-range {
background: linear-gradient(
90deg,
var(--cyan) 0%,
var(--cyan) var(--fill, 34%),
rgba(255, 255, 255, 0.1) var(--fill, 34%),
rgba(255, 255, 255, 0.1) 100%
);
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
appearance: none;
border: 3px solid #dffefa;
border-radius: 50%;
background: #173642;
box-shadow: 0 0 0 4px rgba(85, 229, 213, 0.12);
}
input[type="range"]::-moz-range-thumb {
width: 10px;
height: 10px;
border: 3px solid #dffefa;
border-radius: 50%;
background: #173642;
box-shadow: 0 0 0 4px rgba(85, 229, 213, 0.12);
}
.dial {
position: relative;
width: 112px;
height: 112px;
border: 1px solid rgba(255, 173, 87, 0.22);
border-radius: 50%;
background:
radial-gradient(circle, rgba(255, 173, 87, 0.1), transparent 64%),
rgba(3, 13, 20, 0.42);
box-shadow: inset 0 0 0 8px rgba(255, 255, 255, 0.018);
}
.dial::before {
position: absolute;
inset: 13px;
content: "";
border: 1px dashed rgba(255, 255, 255, 0.12);
border-radius: 50%;
}
.dial span {
position: absolute;
color: #738e9a;
font-size: 8px;
font-weight: 800;
}
.dial .n { top: 7px; left: 50%; transform: translateX(-50%); color: var(--soft); }
.dial .e { top: 50%; right: 7px; transform: translateY(-50%); }
.dial .s { bottom: 7px; left: 50%; transform: translateX(-50%); }
.dial .w { top: 50%; left: 7px; transform: translateY(-50%); }
.needle {
position: absolute;
z-index: 2;
top: 22px;
left: calc(50% - 1px);
width: 2px;
height: 34px;
border-radius: 2px;
background: var(--orange);
box-shadow: 0 0 9px rgba(255, 173, 87, 0.55);
transform: rotate(315deg);
transform-origin: 1px 34px;
transition: transform 180ms ease-out;
}
.needle::before {
position: absolute;
top: -5px;
left: -4px;
width: 0;
height: 0;
content: "";
border-right: 5px solid transparent;
border-bottom: 8px solid var(--orange);
border-left: 5px solid transparent;
}
.needle::after {
position: absolute;
top: 50%;
left: -3px;
width: 8px;
height: 8px;
content: "";
border: 2px solid var(--orange);
border-radius: 50%;
background: #0a1b26;
transform: translateY(-50%);
}
.direction-buttons {
display: grid;
grid-template-columns: repeat(8, 1fr);
gap: 4px;
margin-top: 13px;
}
.direction-buttons button {
padding: 6px 0;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 6px;
background: rgba(255, 255, 255, 0.035);
color: #8ca8b3;
font: inherit;
font-size: 9px;
font-weight: 750;
cursor: pointer;
transition: 140ms ease;
}
.direction-buttons button:hover,
.direction-buttons button.active {
border-color: rgba(255, 173, 87, 0.5);
background: rgba(255, 173, 87, 0.12);
color: var(--orange);
}
.divider {
height: 1px;
margin: 16px 0 14px;
background: rgba(255, 255, 255, 0.075);
}
.speed-header {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-bottom: 8px;
}
.speed-header label {
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.speed-header output {
color: var(--cyan);
font-size: 14px;
font-weight: 730;
}
.panel-footer {
display: flex;
justify-content: space-between;
gap: 12px;
margin-top: 14px;
color: #78939e;
font-size: 9px;
line-height: 1.45;
}
.panel-footer span:first-child {
color: #a5c1ca;
}
.orange {
color: var(--orange);
}
.cyan {
color: var(--cyan);
}
.hint {
position: fixed;
right: 26px;
bottom: 27px;
z-index: 5;
padding: 9px 12px;
border-radius: 9px;
color: var(--muted);
font-size: 10px;
pointer-events: none;
}
@media (max-width: 820px) {
.brand {
top: 18px;
left: 18px;
}
.brand p {
display: none;
}
.readouts {
top: 86px;
right: 16px;
left: 16px;
gap: 7px;
}
.readout {
flex: 1;
min-width: 0;
padding: 11px;
}
.readout-value {
font-size: 19px;
}
.readout-note {
font-size: 9px;
}
.controls {
right: 16px;
bottom: 16px;
left: 16px;
width: auto;
padding: 15px;
}
.hint {
display: none;
}
}
@media (max-width: 480px) {
.brand h1 {
font-size: 25px;
}
.readouts {
top: 73px;
}
.readout-label {
font-size: 8px;
}
.readout-value {
font-size: 17px;
}
.control-row {
grid-template-columns: 1fr 96px;
gap: 14px;
}
.dial {
width: 96px;
height: 96px;
}
.needle {
top: 18px;
height: 30px;
transform-origin: 1px 30px;
}
.panel-footer {
display: block;
}
.panel-footer span {
display: block;
margin-top: 3px;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive three-dimensional wind instrument"></div>
<header class="brand">
<div class="brand-kicker">Meteorological study</div>
<h1>Wind / 01</h1>
<p>Three-cup anemometer and directional vane</p>
</header>
<section class="readouts" aria-live="polite">
<div class="readout direction glass">
<span class="readout-label">Wind from</span>
<span class="readout-value" id="directionValue">NW</span>
<span class="readout-note" id="degreesValue">315° source direction</span>
</div>
<div class="readout speed glass">
<span class="readout-label">Wind speed</span>
<span class="readout-value"><span id="speedValue">8.4</span> <small>m/s</small></span>
<span class="readout-note" id="speedNote">30.2 km/h</span>
</div>
<div class="readout glass">
<span class="readout-label">Rotor signal</span>
<span class="readout-value" id="rotorValue">34%</span>
<span class="readout-note">Illustrative drive</span>
<div class="signal-track">
<div class="signal-fill" id="signalFill"></div>
</div>
</div>
</section>
<section class="controls glass">
<div class="panel-heading">
<h2>Live wind controls</h2>
<div class="live">Interactive</div>
</div>
<div class="control-row">
<div>
<div class="control-title">
<label for="directionRange">Source direction</label>
<output id="directionOutput" for="directionRange">315° NW</output>
</div>
<input
id="directionRange"
type="range"
min="0"
max="359"
step="1"
value="315"
aria-label="Wind source direction in degrees"
>
<div class="direction-buttons" id="directionButtons">
<button data-direction="0">N</button>
<button data-direction="45">NE</button>
<button data-direction="90">E</button>
<button data-direction="135">SE</button>
<button data-direction="180">S</button>
<button data-direction="225">SW</button>
<button data-direction="270">W</button>
<button data-direction="315" class="active">NW</button>
</div>
</div>
<div class="dial" aria-hidden="true">
<span class="n">N</span>
<span class="e">E</span>
<span class="s">S</span>
<span class="w">W</span>
<div class="needle" id="needle"></div>
</div>
</div>
<div class="divider"></div>
<div class="speed-header">
<label for="speedRange">Illustrative wind speed</label>
<output id="speedOutput" for="speedRange">8.4 m/s</output>
</div>
<input
id="speedRange"
class="speed-range"
type="range"
min="0"
max="25"
step="0.1"
value="8.4"
aria-label="Illustrative wind speed in meters per second"
>
<div class="panel-footer">
<span><b class="orange">Orange</b> vane points into the source.</span>
<span><b class="cyan">Cyan</b> streaks show downwind airflow.</span>
</div>
</section>
<div class="hint glass">Drag to orbit · Scroll to zoom · Double-click to reset</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 renderer
// ---------------------------------------------------------------------
const host = document.getElementById("scene");
const directionRange = document.getElementById("directionRange");
const speedRange = document.getElementById("speedRange");
const directionOutput = document.getElementById("directionOutput");
const speedOutput = document.getElementById("speedOutput");
const needle = document.getElementById("needle");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x07131d, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.id = "scene-canvas";
renderer.domElement.tabIndex = 0;
host.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x07131d, 0.035);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
100
);
// ---------------------------------------------------------------------
// Camera controls, implemented directly without addons
// ---------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 1.65, 0),
radius: 10.5,
theta: 0.58,
phi: 1.15
};
const defaultCamera = { ...cameraState, target: cameraState.target.clone() };
function updateCamera() {
const { target, radius, theta, phi } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
}
function resetCamera() {
cameraState.radius = defaultCamera.radius;
cameraState.theta = defaultCamera.theta;
cameraState.phi = defaultCamera.phi;
cameraState.target.copy(defaultCamera.target);
updateCamera();
}
const pointers = new Map();
let dragId = null;
let pinchDistance = 0;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
dragId = event.pointerId;
} else {
dragId = null;
pinchDistance = pointerDistance();
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size >= 2) {
const distance = pointerDistance();
if (pinchDistance > 0 && distance > 0) {
cameraState.radius *= pinchDistance / distance;
cameraState.radius = THREE.MathUtils.clamp(cameraState.radius, 6, 18);
}
pinchDistance = distance;
return;
}
if (event.pointerId === dragId) {
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.48,
1.43
);
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 1) {
const [id, position] = pointers.entries().next().value;
dragId = id;
pointers.set(id, position);
pinchDistance = 0;
} else if (pointers.size === 0) {
dragId = null;
pinchDistance = 0;
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius *= Math.exp(event.deltaY * 0.001);
cameraState.radius = THREE.MathUtils.clamp(cameraState.radius, 6, 18);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
updateCamera();
// ---------------------------------------------------------------------
// Lighting and materials
// ---------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xa8dfff, 0x17222c, 1.9));
const keyLight = new THREE.DirectionalLight(0xffe0b8, 3.1);
keyLight.position.set(5, 8, 5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 22;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x58d9ff, 1.35);
rimLight.position.set(-5, 4, -6);
scene.add(rimLight);
const cyanLight = new THREE.PointLight(0x38e5d4, 10, 8, 2);
cyanLight.position.set(-2, 2.4, 1.5);
scene.add(cyanLight);
const metal = new THREE.MeshStandardMaterial({
color: 0x263b46,
metalness: 0.72,
roughness: 0.34,
flatShading: true
});
const darkMetal = new THREE.MeshStandardMaterial({
color: 0x11242d,
metalness: 0.55,
roughness: 0.48,
flatShading: true
});
const platformMaterial = new THREE.MeshStandardMaterial({
color: 0x1d3540,
metalness: 0.12,
roughness: 0.82,
flatShading: true
});
const creamMaterial = new THREE.MeshStandardMaterial({
color: 0xe7f2ed,
metalness: 0.12,
roughness: 0.4,
flatShading: true
});
const tealMaterial = new THREE.MeshStandardMaterial({
color: 0x43cdbd,
metalness: 0.28,
roughness: 0.38,
flatShading: true
});
const orangeMaterial = new THREE.MeshStandardMaterial({
color: 0xff9d3e,
emissive: 0x8d3206,
emissiveIntensity: 0.35,
metalness: 0.28,
roughness: 0.4,
flatShading: true
});
const doubleSideOrange = new THREE.MeshStandardMaterial({
color: 0xff9d3e,
emissive: 0x6d2404,
emissiveIntensity: 0.25,
side: THREE.DoubleSide,
flatShading: true
});
// ---------------------------------------------------------------------
// Geometry helpers
// ---------------------------------------------------------------------
function addMesh(geometry, material, parent = scene) {
const object = new THREE.Mesh(geometry, material);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function cylinderBetween(start, end, radius, material, parent = scene, sides = 8) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radius,
radius,
length,
sides,
1,
false
);
const object = addMesh(geometry, material, parent);
object.position.copy(start).add(end).multiplyScalar(0.5);
object.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return object;
}
function roundedRect(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + width - radius, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
ctx.lineTo(x + width, y + height - radius);
ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
ctx.lineTo(x + radius, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
}
function createLabel(text, options = {}) {
const {
color = "#dff9f5",
background = "rgba(6, 20, 28, 0.82)",
border = "rgba(85, 229, 213, 0.22)",
width = 512,
height = 96,
scale = [2, 0.36]
} = options;
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, width, height);
roundedRect(ctx, 3, 3, width - 6, height - 6, 15);
ctx.fillStyle = background;
ctx.fill();
ctx.strokeStyle = border;
ctx.lineWidth = 2;
ctx.stroke();
ctx.fillStyle = color;
ctx.font = `750 ${height * 0.34}px ui-sans-serif, system-ui, sans-serif`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, width / 2, height / 2 + 1);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(scale[0], scale[1], 1);
sprite.renderOrder = 10;
return sprite;
}
// ---------------------------------------------------------------------
// Ground and platform
// ---------------------------------------------------------------------
const ground = addMesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({
color: 0x0c1b24,
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.23;
ground.castShadow = false;
const grid = new THREE.GridHelper(36, 36, 0x2d6470, 0x17333e);
grid.position.y = -0.215;
grid.material.transparent = true;
grid.material.opacity = 0.32;
scene.add(grid);
const platform = addMesh(
new THREE.CylinderGeometry(4.65, 4.8, 0.24, 16),
platformMaterial
);
platform.position.y = -0.03;
const platformEdge = addMesh(
new THREE.TorusGeometry(4.63, 0.035, 6, 64),
new THREE.MeshStandardMaterial({
color: 0x4a7f88,
emissive: 0x12383d,
emissiveIntensity: 0.3,
roughness: 0.55
})
);
platformEdge.rotation.x = Math.PI / 2;
platformEdge.position.y = 0.095;
// ---------------------------------------------------------------------
// Three-cup rotor on a vertical axis
// ---------------------------------------------------------------------
const rotorX = -1.45;
const rotorBase = addMesh(
new THREE.CylinderGeometry(0.48, 0.58, 0.28, 10),
darkMetal
);
rotorBase.position.set(rotorX, 0.23, 0);
const rotorFoot = addMesh(
new THREE.CylinderGeometry(0.24, 0.31, 0.13, 10),
tealMaterial
);
rotorFoot.position.set(rotorX, 0.42, 0);
const rotorMast = addMesh(
new THREE.CylinderGeometry(0.065, 0.085, 2.55, 8),
metal
);
rotorMast.position.set(rotorX, 1.68, 0);
const rotor = new THREE.Group();
rotor.position.set(rotorX, 3.02, 0);
scene.add(rotor);
const rotorHub = addMesh(
new THREE.CylinderGeometry(0.14, 0.14, 0.22, 10),
orangeMaterial,
rotor
);
rotorHub.position.y = 0.07;
const cupGeometry = new THREE.SphereGeometry(
0.225,
12,
6,
0,
Math.PI * 2,
0,
Math.PI / 2
);
const rimGeometry = new THREE.TorusGeometry(0.216, 0.018, 6, 12);
for (let i = 0; i < 3; i++) {
const angle = (i / 3) * Math.PI * 2;
const radial = new THREE.Vector3(Math.cos(angle), 0, Math.sin(angle));
const endpoint = radial.clone().multiplyScalar(0.7);
cylinderBetween(
new THREE.Vector3(0, 0, 0),
endpoint,
0.027,
metal,
rotor,
7
);
const cupPivot = new THREE.Group();
cupPivot.position.copy(endpoint);
cupPivot.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
radial
);
rotor.add(cupPivot);
addMesh(cupGeometry, creamMaterial, cupPivot);
const rim = addMesh(rimGeometry, tealMaterial, cupPivot);
rim.rotation.x = Math.PI / 2;
const joint = addMesh(
new THREE.SphereGeometry(0.052, 8, 5),
orangeMaterial,
cupPivot
);
joint.position.y = -0.045;
}
const rotorLabel = createLabel("3-CUP ROTOR", {
color: "#a9fff3",
scale: [1.85, 0.33]
});
rotorLabel.position.set(rotorX, 3.72, 0);
scene.add(rotorLabel);
// ---------------------------------------------------------------------
// Directional vane on a separate horizontal axis
// ---------------------------------------------------------------------
const vaneX = 1.35;
const vaneBase = addMesh(
new THREE.CylinderGeometry(0.48, 0.58, 0.28, 10),
darkMetal
);
vaneBase.position.set(vaneX, 0.23, 0);
const vaneFoot = addMesh(
new THREE.CylinderGeometry(0.24, 0.31, 0.13, 10),
orangeMaterial
);
vaneFoot.position.set(vaneX, 0.42, 0);
const vaneMast = addMesh(
new THREE.CylinderGeometry(0.065, 0.085, 2.55, 8),
metal
);
vaneMast.position.set(vaneX, 1.68, 0);
const vane = new THREE.Group();
vane.position.set(vaneX, 2.86, 0);
scene.add(vane);
const horizontalShaft = addMesh(
new THREE.CylinderGeometry(0.035, 0.035, 1.86, 8),
metal,
vane
);
horizontalShaft.rotation.x = Math.PI / 2;
horizontalShaft.position.z = -0.1;
const arrowCone = addMesh(
new THREE.ConeGeometry(0.16, 0.4, 6),
orangeMaterial,
vane
);
arrowCone.position.set(0, 0, -1.23);
arrowCone.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
new THREE.Vector3(0, 0, -1)
);
const tailGeometry = new THREE.BufferGeometry();
tailGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
-0.34, 0, 0.67,
0.00, 0, 1.23,
0.34, 0, 0.67
], 3)
);
tailGeometry.computeVertexNormals();
addMesh(tailGeometry, doubleSideOrange, vane);
const verticalTailGeometry = new THREE.BufferGeometry();
verticalTailGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
0, -0.025, 0.68,
0, 0.28, 1.03,
0, -0.025, 1.27
], 3)
);
verticalTailGeometry.computeVertexNormals();
addMesh(verticalTailGeometry, doubleSideOrange, vane);
const counterweight = addMesh(
new THREE.SphereGeometry(0.12, 8, 6),
creamMaterial,
vane
);
counterweight.position.set(0, 0, 0.95);
const vaneLabel = createLabel("DIRECTIONAL VANE", {
color: "#ffd2a3",
border: "rgba(255, 173, 87, 0.25)",
scale: [2.15, 0.34]
});
vaneLabel.position.set(vaneX, 3.62, 0);
scene.add(vaneLabel);
// ---------------------------------------------------------------------
// Ground compass beneath the vane
// ---------------------------------------------------------------------
const compassRing = addMesh(
new THREE.TorusGeometry(1.55, 0.018, 6, 64),
new THREE.MeshStandardMaterial({
color: 0x7597a0,
emissive: 0x17343b,
emissiveIntensity: 0.35,
roughness: 0.55
})
);
compassRing.rotation.x = Math.PI / 2;
compassRing.position.set(vaneX, 0.14, 0);
for (let degrees = 0; degrees < 360; degrees += 15) {
const angle = THREE.MathUtils.degToRad(degrees);
const isCardinal = degrees % 90 === 0;
const tick = addMesh(
new THREE.BoxGeometry(
isCardinal ? 0.038 : 0.024,
0.025,
isCardinal ? 0.18 : 0.11
),
isCardinal ? orangeMaterial : darkMetal
);
tick.position.set(
vaneX + Math.sin(angle) * 1.55,
0.15,
-Math.cos(angle) * 1.55
);
tick.rotation.y = angle;
}
const cardinalData = [
["N", 0],
["E", 90],
["S", 180],
["W", 270]
];
for (const [text, degrees] of cardinalData) {
const angle = THREE.MathUtils.degToRad(degrees);
const label = createLabel(text, {
color: text === "N" ? "#ffd2a3" : "#d5e9ed",
background: "rgba(5, 18, 25, 0.82)",
border: "rgba(117, 151, 160, 0.28)",
width: 128,
height: 96,
scale: [0.28, 0.21]
});
label.position.set(
vaneX + Math.sin(angle) * 1.91,
0.31,
-Math.cos(angle) * 1.91
);
scene.add(label);
}
// ---------------------------------------------------------------------
// Animated downwind streaks and low-poly arrowheads
// ---------------------------------------------------------------------
const streakCount = 34;
const streakPositions = new Float32Array(streakCount * 2 * 3);
const streakGeometry = new THREE.BufferGeometry();
streakGeometry.setAttribute(
"position",
new THREE.BufferAttribute(streakPositions, 3).setUsage(THREE.DynamicDrawUsage)
);
const streakMaterial = new THREE.LineBasicMaterial({
color: 0x78dfe7,
transparent: true,
opacity: 0.34,
depthWrite: false
});
const streaks = new THREE.LineSegments(streakGeometry, streakMaterial);
streaks.frustumCulled = false;
scene.add(streaks);
const particles = Array.from({ length: streakCount }, () => ({
phase: Math.random() * 14,
offset: (Math.random() - 0.5) * 7.2,
y: 0.45 + Math.random() * 3.9,
length: 0.18 + Math.random() * 0.32
}));
const arrowCount = 15;
const windArrowMaterial = new THREE.MeshStandardMaterial({
color: 0x65e6dd,
emissive: 0x176963,
emissiveIntensity: 0.75,
roughness: 0.4,
transparent: true,
opacity: 0.68,
flatShading: true
});
const windArrows = new THREE.InstancedMesh(
new THREE.ConeGeometry(0.04, 0.17, 4),
windArrowMaterial,
arrowCount
);
windArrows.frustumCulled = false;
scene.add(windArrows);
const arrowParticles = Array.from({ length: arrowCount }, () => ({
phase: Math.random() * 14,
offset: (Math.random() - 0.5) * 7,
y: 0.5 + Math.random() * 3.7
}));
const dummy = new THREE.Object3D();
const up = new THREE.Vector3(0, 1, 0);
// ---------------------------------------------------------------------
// Wind state and interface
// ---------------------------------------------------------------------
const cardinalNames = [
"N", "NNE", "NE", "ENE",
"E", "ESE", "SE", "SSE",
"S", "SSW", "SW", "WSW",
"W", "WNW", "NW", "NNW"
];
const sourceDirection = new THREE.Vector3();
const downwindDirection = new THREE.Vector3();
const perpendicular = new THREE.Vector3();
let windFromDegrees = 315;
let windSpeed = 8.4;
let rotorAngle = 0;
function cardinalName(degrees) {
return cardinalNames[Math.round(degrees / 22.5) % 16];
}
function setRangeFill(input, color) {
const percent =
((Number(input.value) - Number(input.min)) /
(Number(input.max) - Number(input.min))) * 100;
input.style.setProperty("--fill", `${percent}%`);
input.style.accentColor = color;
}
function applyDirection() {
const radians = THREE.MathUtils.degToRad(windFromDegrees);
const name = cardinalName(windFromDegrees);
// Source direction: the direction from which the wind arrives.
sourceDirection.set(Math.sin(radians), 0, -Math.cos(radians));
// Air travels in the opposite direction.
downwindDirection.copy(sourceDirection).multiplyScalar(-1);
perpendicular.set(downwindDirection.z, 0, -downwindDirection.x);
// The vane's local nose is -Z.
vane.rotation.y = -radians;
needle.style.transform = `rotate(${windFromDegrees}deg)`;
directionOutput.textContent = `${windFromDegrees}° ${name}`;
document.getElementById("directionValue").textContent = name;
document.getElementById("degreesValue").textContent =
`${windFromDegrees}° source direction`;
document.querySelectorAll("#directionButtons button").forEach((button) => {
button.classList.toggle(
"active",
Number(button.dataset.direction) === windFromDegrees
);
});
setRangeFill(directionRange, "#ffad57");
}
function applySpeed() {
const rotorSignal = Math.round((windSpeed / 25) * 100);
document.getElementById("speedValue").textContent = windSpeed.toFixed(1);
document.getElementById("speedNote").textContent =
`${(windSpeed * 3.6).toFixed(1)} km/h`;
document.getElementById("rotorValue").textContent = `${rotorSignal}%`;
document.getElementById("signalFill").style.width = `${rotorSignal}%`;
speedOutput.textContent = `${windSpeed.toFixed(1)} m/s`;
setRangeFill(speedRange, "#55e5d5");
}
directionRange.addEventListener("input", () => {
windFromDegrees = Number(directionRange.value);
applyDirection();
});
speedRange.addEventListener("input", () => {
windSpeed = Number(speedRange.value);
applySpeed();
});
document.getElementById("directionButtons").addEventListener("click", (event) => {
const button = event.target.closest("button[data-direction]");
if (!button) return;
windFromDegrees = Number(button.dataset.direction);
directionRange.value = windFromDegrees;
applyDirection();
});
applyDirection();
applySpeed();
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
// Illustrative rotor response: speed directly controls angular velocity.
rotorAngle += delta * windSpeed * 0.075;
rotor.rotation.y = rotorAngle;
const travel = elapsed * (0.35 + windSpeed * 0.2);
const fieldLength = 14;
for (let i = 0; i < particles.length; i++) {
const particle = particles[i];
const along =
((particle.phase + travel) % fieldLength) - fieldLength / 2;
const centerX = downwindDirection.x * along + perpendicular.x * particle.offset;
const centerZ = downwindDirection.z * along + perpendicular.z * particle.offset;
const tailX = centerX - downwindDirection.x * particle.length;
const tailZ = centerZ - downwindDirection.z * particle.length;
const index = i * 6;
streakPositions[index] = tailX;
streakPositions[index + 1] = particle.y;
streakPositions[index + 2] = tailZ;
streakPositions[index + 3] = centerX;
streakPositions[index + 4] = particle.y;
streakPositions[index + 5] = centerZ;
}
streakGeometry.attributes.position.needsUpdate = true;
streakMaterial.opacity = 0.08 + (windSpeed / 25) * 0.34;
for (let i = 0; i < arrowParticles.length; i++) {
const particle = arrowParticles[i];
const along =
((particle.phase + travel * 1.08) % fieldLength) - fieldLength / 2;
dummy.position.set(
downwindDirection.x * along + perpendicular.x * particle.offset,
particle.y,
downwindDirection.z * along + perpendicular.z * particle.offset
);
dummy.quaternion.setFromUnitVectors(up, downwindDirection);
dummy.updateMatrix();
windArrows.setMatrixAt(i, dummy.matrix);
}
windArrows.instanceMatrix.needsUpdate = true;
windArrowMaterial.opacity = windSpeed === 0 ? 0.15 : 0.68;
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
// ---------------------------------------------------------------------
// Resize handling
// ---------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
</script>
</body>
</html>
```