Prompt specification
Build or customize the Three.js 3D scene "Wind Arrow and Turbine Rotor Geometry" 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 Arrow and Turbine Rotor Geometry
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/wind-arrow-and-turbine-rotor-geometry-x3997
Scene Description Prompt:
Model a generic small turbine with a visible rotor plane and wind-direction arrow. Keep its structure schematic and avoid encoding power solely through rotation speed. Use Three.js from cdnjs in a single HTML file, with stylized solid shapes.
Working Three.js Starter (wind-arrow-and-turbine-rotor-geometry-x3997):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Generic Small Wind Turbine</title>
<style>
:root {
color-scheme: light;
--ink: #17343c;
--muted: #607980;
--panel: rgba(248, 252, 252, 0.88);
--line: rgba(23, 52, 60, 0.13);
--teal: #13b8a6;
--teal-dark: #087d76;
--orange: #f28b45;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8f0f2;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#viewport canvas.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid rgba(255, 255, 255, 0.72);
background: var(--panel);
box-shadow:
0 18px 50px rgba(25, 56, 65, 0.12),
inset 0 0 0 1px rgba(255, 255, 255, 0.38);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.intro {
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 22px 24px;
border-radius: 20px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--teal-dark);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 5px rgba(19, 184, 166, 0.13);
content: "";
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 38px);
line-height: 1.05;
letter-spacing: -0.045em;
}
.intro p {
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.readout {
top: 24px;
right: 24px;
width: 310px;
padding: 20px;
border-radius: 20px;
}
.readout-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 18px;
}
.readout-title {
font-size: 12px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.status {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 6px 9px;
border-radius: 999px;
background: rgba(19, 184, 166, 0.12);
color: var(--teal-dark);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.status::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: currentColor;
content: "";
}
.label-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
}
.label-row label {
color: var(--muted);
font-size: 12px;
font-weight: 650;
}
.value {
font-size: 19px;
font-weight: 780;
letter-spacing: -0.03em;
font-variant-numeric: tabular-nums;
}
.value small {
color: var(--muted);
font-size: 11px;
font-weight: 650;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 4px 0 20px;
border-radius: 999px;
outline: none;
appearance: none;
-webkit-appearance: none;
background: linear-gradient(
to right,
var(--teal) 0%,
var(--teal) var(--wind-fill, 50%),
#d9e4e6 var(--wind-fill, 50%),
#d9e4e6 100%
);
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
border: 3px solid white;
border-radius: 50%;
appearance: none;
-webkit-appearance: none;
background: var(--teal-dark);
box-shadow: 0 2px 8px rgba(8, 125, 118, 0.3);
cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid white;
border-radius: 50%;
background: var(--teal-dark);
box-shadow: 0 2px 8px rgba(8, 125, 118, 0.3);
cursor: pointer;
}
.power-block {
padding-top: 16px;
border-top: 1px solid var(--line);
}
.segments {
display: grid;
grid-template-columns: repeat(12, 1fr);
gap: 4px;
height: 17px;
margin: 10px 0 16px;
}
.segment {
min-width: 0;
border-radius: 3px;
background: #dce6e7;
transition:
background 180ms ease,
box-shadow 180ms ease,
transform 180ms ease;
}
.segment.active {
background: var(--teal);
box-shadow: 0 0 10px rgba(19, 184, 166, 0.34);
transform: translateY(-1px);
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-bottom: 15px;
}
.metric {
padding: 10px 11px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.45);
}
.metric span {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.metric strong {
font-size: 13px;
font-variant-numeric: tabular-nums;
}
.buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
button {
min-height: 38px;
border: 1px solid var(--line);
border-radius: 10px;
background: white;
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition:
transform 120ms ease,
border-color 120ms ease,
background 120ms ease;
}
button:hover {
border-color: rgba(8, 125, 118, 0.4);
background: #f2fbfa;
}
button:active {
transform: translateY(1px);
}
button.primary {
border-color: var(--teal-dark);
background: var(--teal-dark);
color: white;
}
.hint {
position: fixed;
bottom: 20px;
left: 50%;
z-index: 5;
padding: 9px 13px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 999px;
background: rgba(248, 252, 252, 0.78);
color: var(--muted);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.04em;
transform: translateX(-50%);
backdrop-filter: blur(12px);
pointer-events: none;
white-space: nowrap;
}
@media (max-width: 760px) {
.intro {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 16px 18px;
}
.intro p {
display: none;
}
.readout {
top: auto;
right: 14px;
bottom: 14px;
width: min(310px, calc(100vw - 28px));
padding: 16px;
}
.readout-header {
margin-bottom: 12px;
}
.power-block {
padding-top: 12px;
}
.metrics {
margin-bottom: 10px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="viewport" aria-label="Interactive 3D wind turbine model"></div>
<section class="panel intro">
<div class="eyebrow">Small turbine schematic</div>
<h1>Wind energy,<br />made legible.</h1>
<p>
The translucent disc exposes the rotor plane. Wind travels toward the
rotor, while the illuminated tower cells and meter show electrical output.
</p>
</section>
<section class="panel readout" aria-label="Turbine performance readout">
<div class="readout-header">
<div class="readout-title">Live readout</div>
<div class="status" id="status">Variable</div>
</div>
<div class="label-row">
<label for="wind-speed">Wind speed</label>
<div class="value">
<span id="wind-value">7.0</span> <small>m/s</small>
</div>
</div>
<input
id="wind-speed"
type="range"
min="0"
max="14"
step="0.1"
value="7"
aria-label="Wind speed in meters per second"
/>
<div class="power-block">
<div class="label-row">
<label>Electrical output</label>
<div class="value">
<span id="power-value">2.0</span> <small>kW</small>
</div>
</div>
<div class="segments" id="segments" aria-label="Power output meter"></div>
<div class="metrics">
<div class="metric">
<span>Capacity</span>
<strong>6.0 kW</strong>
</div>
<div class="metric">
<span>Rotor speed</span>
<strong id="rpm-value">22.5 rpm</strong>
</div>
</div>
<div class="buttons">
<button class="primary" id="pause-button" type="button">
Pause rotor
</button>
<button id="reset-button" type="button">Reset view</button>
</div>
</div>
</section>
<div class="hint">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";
const viewport = document.querySelector("#viewport");
// ---------------------------------------------------------------------
// Renderer, scene, camera, and lights
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8f0f2);
scene.fog = new THREE.Fog(0xe8f0f2, 23, 48);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance",
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
viewport.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xf9fdff, 0x7b9195, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.4);
keyLight.position.set(-7, 15, 10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -15;
keyLight.shadow.camera.right = 15;
keyLight.shadow.camera.top = 16;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 40;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x9eddd9, 1.35);
rimLight.position.set(9, 8, -10);
scene.add(rimLight);
// ---------------------------------------------------------------------
// Shared materials
// ---------------------------------------------------------------------
const turbineWhite = new THREE.MeshStandardMaterial({
color: 0xf7faf9,
roughness: 0.64,
metalness: 0.08,
});
const turbineShade = new THREE.MeshStandardMaterial({
color: 0xcbd9dc,
roughness: 0.7,
metalness: 0.12,
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x203d45,
roughness: 0.55,
metalness: 0.15,
});
const orangeMaterial = new THREE.MeshStandardMaterial({
color: 0xf28b45,
roughness: 0.48,
metalness: 0.08,
});
const tealMaterial = new THREE.MeshStandardMaterial({
color: 0x19bba9,
roughness: 0.38,
metalness: 0.1,
});
// ---------------------------------------------------------------------
// Ground and schematic base
// ---------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0xdfe8ea,
roughness: 0.95,
metalness: 0,
})
);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);
const foundation = new THREE.Mesh(
new THREE.CylinderGeometry(1.42, 1.58, 0.32, 48),
new THREE.MeshStandardMaterial({
color: 0xc2d0d3,
roughness: 0.88,
})
);
foundation.position.y = 0.16;
foundation.receiveShadow = true;
foundation.castShadow = true;
scene.add(foundation);
const foundationRing = new THREE.Mesh(
new THREE.TorusGeometry(1.18, 0.045, 10, 64),
new THREE.MeshStandardMaterial({
color: 0x88a4aa,
roughness: 0.7,
})
);
foundationRing.rotation.x = Math.PI / 2;
foundationRing.position.y = 0.335;
scene.add(foundationRing);
const groundGuide = new THREE.Mesh(
new THREE.RingGeometry(3.2, 3.23, 96),
new THREE.MeshBasicMaterial({
color: 0xaec3c7,
transparent: true,
opacity: 0.5,
side: THREE.DoubleSide,
})
);
groundGuide.rotation.x = -Math.PI / 2;
groundGuide.position.y = 0.012;
scene.add(groundGuide);
// ---------------------------------------------------------------------
// Turbine tower, nacelle, and base details
// ---------------------------------------------------------------------
const turbine = new THREE.Group();
scene.add(turbine);
const tower = new THREE.Mesh(
new THREE.CylinderGeometry(0.52, 0.82, 7.7, 40),
turbineWhite
);
tower.position.y = 3.85;
tower.castShadow = true;
tower.receiveShadow = true;
turbine.add(tower);
const towerCollar = new THREE.Mesh(
new THREE.CylinderGeometry(0.68, 0.68, 0.42, 32),
turbineShade
);
towerCollar.position.y = 7.62;
towerCollar.castShadow = true;
turbine.add(towerCollar);
const nacelle = new THREE.Mesh(
new THREE.BoxGeometry(2.65, 1.02, 1.04),
turbineWhite
);
nacelle.position.set(-0.52, 8.22, 0);
nacelle.castShadow = true;
turbine.add(nacelle);
const rearCap = new THREE.Mesh(
new THREE.SphereGeometry(0.53, 24, 16),
turbineWhite
);
rearCap.scale.set(0.72, 1, 1);
rearCap.position.set(0.81, 8.22, 0);
rearCap.castShadow = true;
turbine.add(rearCap);
const servicePanel = new THREE.Mesh(
new THREE.BoxGeometry(1.05, 0.48, 0.055),
orangeMaterial
);
servicePanel.position.set(-0.2, 8.25, 0.545);
turbine.add(servicePanel);
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.2, 0.2, 0.75, 24),
turbineShade
);
shaft.rotation.z = Math.PI / 2;
shaft.position.set(-2.05, 8.22, 0);
shaft.castShadow = true;
turbine.add(shaft);
// ---------------------------------------------------------------------
// Rotor plane and blades
// ---------------------------------------------------------------------
const rotorPlane = new THREE.Mesh(
new THREE.CircleGeometry(3.48, 96),
new THREE.MeshBasicMaterial({
color: 0x5bc8bd,
transparent: true,
opacity: 0.09,
side: THREE.DoubleSide,
depthWrite: false,
})
);
rotorPlane.rotation.y = Math.PI / 2;
rotorPlane.position.set(-2.31, 8.22, 0);
turbine.add(rotorPlane);
const rotorRim = new THREE.Mesh(
new THREE.TorusGeometry(3.48, 0.026, 8, 128),
new THREE.MeshBasicMaterial({
color: 0x35aaa0,
transparent: true,
opacity: 0.46,
})
);
rotorRim.rotation.y = Math.PI / 2;
rotorRim.position.set(-2.31, 8.22, 0);
turbine.add(rotorRim);
// Convert a shape authored in the XY plane into the rotor's YZ plane:
// local X -> world Y (radial), local Y -> world Z (tangential),
// local Z -> world X (rotor axis).
const bladeBasis = new THREE.Matrix4().makeBasis(
new THREE.Vector3(0, 1, 0),
new THREE.Vector3(0, 0, 1),
new THREE.Vector3(1, 0, 0)
);
function createBladeGeometry(tipOnly = false) {
const shape = new THREE.Shape();
if (tipOnly) {
shape.moveTo(2.7, -0.53);
shape.quadraticCurveTo(3.13, -0.48, 3.38, -0.16);
shape.quadraticCurveTo(3.5, 0.08, 3.27, 0.31);
shape.quadraticCurveTo(2.95, 0.48, 2.7, 0.52);
} else {
shape.moveTo(0.45, -0.14);
shape.quadraticCurveTo(0.96, -0.38, 2.38, -0.57);
shape.quadraticCurveTo(3.08, -0.69, 3.36, -0.22);
shape.quadraticCurveTo(3.51, 0.07, 3.27, 0.3);
shape.quadraticCurveTo(2.78, 0.51, 1.36, 0.44);
shape.quadraticCurveTo(0.78, 0.35, 0.48, 0.15);
}
shape.closePath();
const depth = tipOnly ? 0.19 : 0.16;
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
steps: 1,
bevelEnabled: true,
bevelSegments: 2,
bevelSize: tipOnly ? 0.025 : 0.035,
bevelThickness: tipOnly ? 0.025 : 0.035,
curveSegments: 20,
});
geometry.translate(0, 0, -depth / 2);
geometry.applyMatrix4(bladeBasis);
geometry.computeVertexNormals();
return geometry;
}
const bladeGeometry = createBladeGeometry(false);
const bladeTipGeometry = createBladeGeometry(true);
const rotor = new THREE.Group();
rotor.position.set(-2.42, 8.22, 0);
turbine.add(rotor);
for (let i = 0; i < 3; i++) {
const bladeGroup = new THREE.Group();
bladeGroup.rotation.x = (i * Math.PI * 2) / 3 + 0.22;
const blade = new THREE.Mesh(bladeGeometry, turbineWhite);
blade.castShadow = true;
blade.receiveShadow = true;
bladeGroup.add(blade);
const tip = new THREE.Mesh(bladeTipGeometry, orangeMaterial);
tip.castShadow = true;
bladeGroup.add(tip);
const root = new THREE.Mesh(
new THREE.CylinderGeometry(0.21, 0.21, 0.24, 16),
orangeMaterial
);
root.rotation.z = Math.PI / 2;
root.position.y = 0.56;
root.castShadow = true;
bladeGroup.add(root);
rotor.add(bladeGroup);
}
const hub = new THREE.Mesh(
new THREE.SphereGeometry(0.52, 28, 20),
turbineShade
);
hub.position.set(-2.42, 8.22, 0);
hub.castShadow = true;
turbine.add(hub);
const spinner = new THREE.Mesh(
new THREE.ConeGeometry(0.49, 0.9, 32),
turbineWhite
);
spinner.rotation.z = Math.PI / 2;
spinner.position.set(-2.88, 8.22, 0);
spinner.castShadow = true;
turbine.add(spinner);
// ---------------------------------------------------------------------
// Tower output indicator: independent visual encoding of power
// ---------------------------------------------------------------------
const outputPanel = new THREE.Mesh(
new THREE.BoxGeometry(0.58, 2.45, 0.09),
darkMaterial
);
outputPanel.position.set(0.04, 4.15, 0.69);
outputPanel.castShadow = true;
turbine.add(outputPanel);
const towerSegments = [];
for (let i = 0; i < 7; i++) {
const material = new THREE.MeshStandardMaterial({
color: 0x29484f,
emissive: 0x000000,
emissiveIntensity: 0,
roughness: 0.45,
});
const segment = new THREE.Mesh(
new THREE.BoxGeometry(0.29, 0.16, 0.055),
material
);
segment.position.set(0.04, 3.25 + i * 0.29, 0.76);
turbine.add(segment);
towerSegments.push(segment);
}
const beaconMaterial = new THREE.MeshStandardMaterial({
color: 0x19bba9,
emissive: 0x19bba9,
emissiveIntensity: 1.4,
roughness: 0.3,
});
const beacon = new THREE.Mesh(
new THREE.SphereGeometry(0.13, 18, 12),
beaconMaterial
);
beacon.position.set(0.42, 8.96, 0.31);
turbine.add(beacon);
const beaconStem = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.035, 0.35, 10),
turbineShade
);
beaconStem.position.set(0.42, 8.73, 0.31);
turbine.add(beaconStem);
// ---------------------------------------------------------------------
// Wind-direction arrow
// ---------------------------------------------------------------------
const windArrow = new THREE.Group();
scene.add(windArrow);
const arrowShaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.075, 0.075, 3.45, 16),
tealMaterial
);
arrowShaft.rotation.z = -Math.PI / 2;
arrowShaft.position.set(-5.68, 7.08, 3.12);
arrowShaft.castShadow = true;
windArrow.add(arrowShaft);
const arrowHead = new THREE.Mesh(
new THREE.ConeGeometry(0.31, 0.76, 24),
tealMaterial
);
arrowHead.rotation.z = -Math.PI / 2;
arrowHead.position.set(-3.58, 7.08, 3.12);
arrowHead.castShadow = true;
windArrow.add(arrowHead);
const flowDots = [];
for (let i = 0; i < 3; i++) {
const dot = new THREE.Mesh(
new THREE.SphereGeometry(0.105, 14, 10),
new THREE.MeshBasicMaterial({
color: 0x42d8c7,
transparent: true,
opacity: 0.8,
})
);
dot.position.set(-7 + i, 7.08, 3.12);
windArrow.add(dot);
flowDots.push(dot);
}
// ---------------------------------------------------------------------
// Small canvas-generated scene labels
// ---------------------------------------------------------------------
function makeLabel(text, accent = "#0b8d82") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(248,252,252,0.92)";
context.fillRect(8, 16, 496, 96);
context.fillStyle = accent;
context.fillRect(8, 16, 10, 96);
context.fillStyle = "#17343c";
context.font = "700 34px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 262, 65);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
})
);
sprite.renderOrder = 20;
return sprite;
}
const windLabel = makeLabel("WIND FLOW", "#0b8d82");
windLabel.scale.set(2.55, 0.64, 1);
windLabel.position.set(-5.25, 7.92, 3.12);
scene.add(windLabel);
const outputLabel = makeLabel("OUTPUT", "#f28b45");
outputLabel.scale.set(1.55, 0.39, 1);
outputLabel.position.set(0.06, 5.62, 0.8);
scene.add(outputLabel);
// ---------------------------------------------------------------------
// UI and turbine performance model
// ---------------------------------------------------------------------
const windSlider = document.querySelector("#wind-speed");
const windValue = document.querySelector("#wind-value");
const powerValue = document.querySelector("#power-value");
const rpmValue = document.querySelector("#rpm-value");
const statusElement = document.querySelector("#status");
const segmentsElement = document.querySelector("#segments");
const pauseButton = document.querySelector("#pause-button");
const resetButton = document.querySelector("#reset-button");
const ratedPower = 6;
const cutInSpeed = 2.5;
const ratedWindSpeed = 10;
let windSpeed = Number(windSlider.value);
let paused = false;
const meterSegments = [];
for (let i = 0; i < 12; i++) {
const segment = document.createElement("span");
segment.className = "segment";
segmentsElement.appendChild(segment);
meterSegments.push(segment);
}
function calculatePower(speed) {
if (speed <= cutInSpeed) return 0;
const normalized =
(speed ** 3 - cutInSpeed ** 3) /
(ratedWindSpeed ** 3 - cutInSpeed ** 3);
return ratedPower * THREE.MathUtils.clamp(normalized, 0, 1);
}
function calculateRpm(speed) {
const normalized = THREE.MathUtils.clamp(
(speed - cutInSpeed) / (ratedWindSpeed - cutInSpeed),
0,
1
);
return 8 + normalized * 26;
}
function updateReadout() {
const power = calculatePower(windSpeed);
const rpm = calculateRpm(windSpeed);
const activeSegments = Math.ceil((power / ratedPower) * 12);
windValue.textContent = windSpeed.toFixed(1);
powerValue.textContent = power.toFixed(1);
rpmValue.textContent = `${rpm.toFixed(1)} rpm`;
const sliderPercent = (windSpeed / Number(windSlider.max)) * 100;
windSlider.style.setProperty("--wind-fill", `${sliderPercent}%`);
meterSegments.forEach((segment, index) => {
segment.classList.toggle("active", index < activeSegments);
});
towerSegments.forEach((segment, index) => {
const active = index < Math.ceil((power / ratedPower) * 7);
segment.material.color.setHex(active ? 0x19bba9 : 0x29484f);
segment.material.emissive.setHex(active ? 0x0d8f80 : 0x000000);
segment.material.emissiveIntensity = active ? 1.25 : 0;
});
if (windSpeed < cutInSpeed) {
statusElement.textContent = "Below cut-in";
statusElement.style.color = "#a76b28";
statusElement.style.background = "rgba(242,139,69,0.13)";
beaconMaterial.color.setHex(0xf28b45);
beaconMaterial.emissive.setHex(0xf28b45);
} else if (windSpeed >= ratedWindSpeed) {
statusElement.textContent = "Rated";
statusElement.style.color = "#087d76";
statusElement.style.background = "rgba(19,184,166,0.12)";
beaconMaterial.color.setHex(0x19bba9);
beaconMaterial.emissive.setHex(0x19bba9);
} else {
statusElement.textContent = "Variable";
statusElement.style.color = "#087d76";
statusElement.style.background = "rgba(19,184,166,0.12)";
beaconMaterial.color.setHex(0x19bba9);
beaconMaterial.emissive.setHex(0x19bba9);
}
}
windSlider.addEventListener("input", () => {
windSpeed = Number(windSlider.value);
updateReadout();
});
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume rotor" : "Pause rotor";
pauseButton.setAttribute("aria-pressed", String(paused));
});
updateReadout();
// ---------------------------------------------------------------------
// Custom orbit controls implemented directly without camera add-ons
// ---------------------------------------------------------------------
const defaultView = {
target: new THREE.Vector3(-0.35, 4.5, 0),
radius: 17.8,
azimuth: -0.62,
polar: 1.13,
};
const cameraState = {
target: defaultView.target.clone(),
radius: defaultView.radius,
azimuth: defaultView.azimuth,
polar: defaultView.polar,
};
function updateCamera() {
const sinPolar = Math.sin(cameraState.polar);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPolar * Math.sin(cameraState.azimuth),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.polar),
cameraState.target.z +
cameraState.radius * sinPolar * Math.cos(cameraState.azimuth)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.target.copy(defaultView.target);
cameraState.radius = defaultView.radius;
cameraState.azimuth = defaultView.azimuth;
cameraState.polar = defaultView.polar;
updateCamera();
}
resetButton.addEventListener("click", resetCamera);
let dragging = false;
let previousX = 0;
let previousY = 0;
let activePointerId = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
activePointerId = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== activePointerId) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
cameraState.azimuth -= deltaX * 0.006;
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar - deltaY * 0.005,
0.34,
1.48
);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
function endDrag(event) {
if (event.pointerId !== activePointerId) return;
dragging = false;
activePointerId = null;
renderer.domElement.classList.remove("dragging");
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
9,
29
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
if (event.key === "ArrowLeft") cameraState.azimuth += 0.08;
if (event.key === "ArrowRight") cameraState.azimuth -= 0.08;
if (event.key === "ArrowUp") cameraState.polar -= 0.06;
if (event.key === "ArrowDown") cameraState.polar += 0.06;
if (event.key === "+" || event.key === "=") cameraState.radius -= 0.7;
if (event.key === "-") cameraState.radius += 0.7;
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar,
0.34,
1.48
);
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius,
9,
29
);
updateCamera();
});
// ---------------------------------------------------------------------
// Resize and animation
// ---------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
let simulationTime = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) {
simulationTime += delta;
const rpm = calculateRpm(windSpeed);
rotor.rotation.x += (rpm * Math.PI * 2 / 60) * delta;
flowDots.forEach((dot, index) => {
const progress = (simulationTime * 0.72 + index / 3) % 1;
dot.position.x = -7.05 + progress * 3.35;
dot.scale.setScalar(0.8 + Math.sin(progress * Math.PI) * 0.35);
dot.material.opacity = Math.sin(progress * Math.PI) * 0.9;
});
const pulse = 0.8 + Math.sin(simulationTime * 4.2) * 0.25;
beaconMaterial.emissiveIntensity =
calculatePower(windSpeed) > 0 ? pulse : 0.15;
}
renderer.render(scene, camera);
}
updateCamera();
animate();
</script>
</body>
</html>
```