Prompt specification
Build or customize the Three.js 3D scene "Synthetic Wind Series Drives a Toy Turbine" 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: Synthetic Wind Series Drives a Toy Turbine
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/synthetic-wind-series-drives-a-toy-turbine-x3998
Scene Description Prompt:
A voxel toy turbine driven by synthetic wind, displaying wind input and output from a simplified response curve. Three.js from cdnjs, one HTML file.
Working Three.js Starter (synthetic-wind-series-drives-a-toy-turbine-x3998):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Wind Lab</title>
<style>
:root {
--bg: #09151e;
--panel: rgba(13, 30, 41, 0.82);
--panel-border: rgba(173, 226, 231, 0.16);
--text: #edf8f6;
--muted: #91aeb4;
--cyan: #65e4e8;
--mint: #9df2c4;
--orange: #ff9a62;
--red: #ff6f70;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#app,
#app canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#app canvas {
display: block;
touch-action: none;
cursor: grab;
}
#app canvas:active {
cursor: grabbing;
}
.overlay {
position: fixed;
inset: 0;
pointer-events: none;
}
.topbar {
position: absolute;
top: 22px;
left: 24px;
right: 24px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20px;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
text-shadow: 0 2px 16px rgba(0, 0, 0, 0.4);
}
.brand-mark {
position: relative;
width: 44px;
height: 44px;
border: 1px solid rgba(101, 228, 232, 0.36);
border-radius: 13px;
background: rgba(11, 30, 40, 0.74);
box-shadow: inset 0 0 24px rgba(101, 228, 232, 0.08);
backdrop-filter: blur(12px);
}
.brand-mark::before {
content: "";
position: absolute;
width: 9px;
height: 9px;
left: 17px;
top: 17px;
border-radius: 2px;
background: var(--orange);
box-shadow: 0 0 14px rgba(255, 154, 98, 0.5);
}
.brand-mark::after {
content: "";
position: absolute;
width: 24px;
height: 3px;
left: 10px;
top: 20px;
border-radius: 2px;
background: var(--cyan);
transform-origin: center;
transform: rotate(0deg);
box-shadow:
0 -8px 0 -1px var(--cyan),
0 8px 0 -1px var(--cyan);
}
.eyebrow,
.metric-label,
.kicker {
margin: 0;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.brand h1 {
margin: 3px 0 0;
font-size: clamp(22px, 2.3vw, 32px);
line-height: 1;
letter-spacing: -0.04em;
}
.brand .subline {
margin: 6px 0 0;
color: #b7ccd0;
font-size: 12px;
}
.metrics {
display: flex;
gap: 10px;
pointer-events: auto;
}
.metric {
min-width: 132px;
padding: 12px 15px;
border: 1px solid var(--panel-border);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.16);
backdrop-filter: blur(16px);
}
.metric strong {
display: block;
margin-top: 4px;
font-size: 24px;
line-height: 1;
letter-spacing: -0.04em;
font-variant-numeric: tabular-nums;
}
.metric strong small {
margin-left: 3px;
color: var(--muted);
font-size: 11px;
font-weight: 700;
letter-spacing: 0;
}
.metric.output strong {
color: var(--mint);
}
.metric.rpm strong {
color: var(--cyan);
}
.panel {
position: absolute;
bottom: 22px;
width: 350px;
padding: 18px;
border: 1px solid var(--panel-border);
border-radius: 18px;
background: var(--panel);
box-shadow:
0 22px 60px rgba(0, 0, 0, 0.28),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
backdrop-filter: blur(18px);
pointer-events: auto;
}
.control-panel {
left: 24px;
}
.graph-panel {
right: 24px;
width: 380px;
}
.panel-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 18px;
}
.panel-head h2 {
margin: 4px 0 0;
font-size: 20px;
letter-spacing: -0.035em;
}
.live-badge {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 7px 9px;
border: 1px solid rgba(157, 242, 196, 0.18);
border-radius: 999px;
color: var(--mint);
background: rgba(157, 242, 196, 0.07);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.12em;
}
.live-badge i {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--mint);
box-shadow: 0 0 10px var(--mint);
animation: pulse 1.6s infinite;
}
@keyframes pulse {
50% {
opacity: 0.35;
transform: scale(0.75);
}
}
.value-row {
display: flex;
align-items: end;
justify-content: space-between;
margin-bottom: 10px;
}
.value-row label {
color: #c4d8da;
font-size: 13px;
font-weight: 650;
}
.wind-value {
color: var(--cyan);
font-size: 29px;
font-weight: 850;
line-height: 1;
letter-spacing: -0.05em;
font-variant-numeric: tabular-nums;
}
.wind-value small {
color: var(--muted);
font-size: 11px;
letter-spacing: 0;
}
input[type="range"] {
width: 100%;
height: 6px;
margin: 8px 0 4px;
border-radius: 999px;
outline: none;
appearance: none;
background: linear-gradient(
to right,
var(--cyan) 0%,
var(--cyan) var(--fill, 36%),
rgba(136, 178, 184, 0.2) var(--fill, 36%),
rgba(136, 178, 184, 0.2) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 19px;
height: 19px;
border: 4px solid #163541;
border-radius: 50%;
appearance: none;
background: var(--cyan);
box-shadow: 0 0 0 1px rgba(101, 228, 232, 0.45), 0 0 16px rgba(101, 228, 232, 0.25);
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 4px solid #163541;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 0 1px rgba(101, 228, 232, 0.45), 0 0 16px rgba(101, 228, 232, 0.25);
}
.range-labels {
display: flex;
justify-content: space-between;
color: #718e95;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.presets {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
margin-top: 16px;
}
.preset,
.sweep-button {
border: 1px solid rgba(169, 211, 216, 0.13);
border-radius: 9px;
color: #bdd0d3;
background: rgba(255, 255, 255, 0.035);
cursor: pointer;
transition:
color 160ms ease,
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.preset {
padding: 9px 5px;
font-size: 10px;
font-weight: 800;
}
.preset:hover,
.preset.active {
color: var(--cyan);
border-color: rgba(101, 228, 232, 0.34);
background: rgba(101, 228, 232, 0.08);
}
.preset:active,
.sweep-button:active {
transform: translateY(1px);
}
.sweep-button {
width: 100%;
margin-top: 10px;
padding: 11px 14px;
color: #dceeed;
background: rgba(101, 228, 232, 0.08);
font-size: 11px;
font-weight: 850;
letter-spacing: 0.04em;
}
.sweep-button:hover,
.sweep-button.active {
color: var(--cyan);
border-color: rgba(101, 228, 232, 0.35);
background: rgba(101, 228, 232, 0.13);
}
.state-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 13px;
padding-top: 13px;
border-top: 1px solid rgba(169, 211, 216, 0.1);
color: var(--muted);
font-size: 11px;
}
#responseState {
color: var(--mint);
font-weight: 750;
}
.curve-wrap {
position: relative;
margin: -4px -4px 0;
border-radius: 12px;
overflow: hidden;
background:
radial-gradient(circle at 70% 20%, rgba(101, 228, 232, 0.06), transparent 46%),
rgba(4, 14, 21, 0.25);
}
.curve-wrap svg {
display: block;
width: 100%;
height: auto;
overflow: visible;
}
.grid-line {
stroke: rgba(167, 207, 212, 0.12);
stroke-width: 1;
}
.threshold {
stroke: rgba(255, 154, 98, 0.2);
stroke-width: 1;
stroke-dasharray: 3 5;
}
.axis-label {
fill: #78949a;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.04em;
}
.axis-title {
fill: #9ab2b7;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.curve-line {
fill: none;
stroke: var(--cyan);
stroke-width: 3;
stroke-linecap: round;
stroke-linejoin: round;
filter: drop-shadow(0 0 5px rgba(101, 228, 232, 0.3));
}
.active-line {
stroke: rgba(255, 255, 255, 0.38);
stroke-width: 1;
stroke-dasharray: 3 4;
}
.active-dot {
fill: var(--mint);
stroke: #14333a;
stroke-width: 3;
filter: drop-shadow(0 0 7px rgba(157, 242, 196, 0.55));
}
.graph-footer {
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
gap: 12px;
margin-top: 10px;
padding-top: 12px;
border-top: 1px solid rgba(169, 211, 216, 0.1);
}
.graph-footer p {
margin: 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.legend {
display: flex;
align-items: center;
gap: 6px;
color: #b8cdd0;
font-size: 10px;
white-space: nowrap;
}
.legend i {
width: 16px;
height: 3px;
border-radius: 4px;
background: var(--cyan);
box-shadow: 0 0 8px rgba(101, 228, 232, 0.45);
}
.orbit-hint {
position: absolute;
left: 50%;
bottom: 25px;
transform: translateX(-50%);
padding: 8px 11px;
border: 1px solid rgba(169, 211, 216, 0.1);
border-radius: 999px;
color: rgba(190, 213, 216, 0.65);
background: rgba(9, 23, 31, 0.54);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.07em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
@media (max-width: 1050px) {
.metric.rpm {
display: none;
}
.panel {
width: 320px;
}
.graph-panel {
width: 350px;
}
}
@media (max-width: 780px) {
.topbar {
top: 13px;
left: 13px;
right: 13px;
}
.brand .subline,
.metrics {
display: none;
}
.control-panel {
left: 12px;
right: 12px;
bottom: 12px;
width: auto;
padding: 14px;
}
.graph-panel {
top: 78px;
right: 12px;
bottom: auto;
width: 285px;
padding: 13px;
}
.panel-head {
margin-bottom: 10px;
}
.panel-head h2 {
font-size: 16px;
}
.graph-footer {
display: none;
}
.orbit-hint {
display: none;
}
}
@media (max-width: 480px) {
.graph-panel {
width: calc(100% - 24px);
}
.control-panel {
max-height: 255px;
overflow: auto;
}
.presets {
margin-top: 11px;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div class="overlay">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<p class="eyebrow">Interactive energy sandbox</p>
<h1>Voxel Wind Lab</h1>
<p class="subline">Synthetic wind · simplified turbine response</p>
</div>
</div>
<div class="metrics">
<div class="metric">
<span class="metric-label">Wind input</span>
<strong id="windMetric">8.0<small>m/s</small></strong>
</div>
<div class="metric output">
<span class="metric-label">Power output</span>
<strong id="powerMetric">0.0<small>kW</small></strong>
</div>
<div class="metric rpm">
<span class="metric-label">Rotor speed</span>
<strong id="rpmMetric">0<small>rpm</small></strong>
</div>
</div>
</header>
<section class="panel control-panel">
<div class="panel-head">
<div>
<p class="kicker">01 / Wind source</p>
<h2>Synthetic wind</h2>
</div>
<span class="live-badge"><i></i> Live</span>
</div>
<div class="value-row">
<label for="windSlider">Wind speed</label>
<div class="wind-value"><span id="windValue">8.0</span> <small>m/s</small></div>
</div>
<input
id="windSlider"
type="range"
min="0"
max="22"
step="0.1"
value="8"
aria-label="Synthetic wind speed"
>
<div class="range-labels">
<span>0 · Calm</span>
<span>11 · Half</span>
<span>22 · Storm</span>
</div>
<div class="presets" aria-label="Wind presets">
<button class="preset" data-wind="2">Calm</button>
<button class="preset" data-wind="7">Breeze</button>
<button class="preset" data-wind="12">Rated</button>
<button class="preset" data-wind="21">Storm</button>
</div>
<button id="sweepButton" class="sweep-button" aria-pressed="false">
▶ Sweep response curve
</button>
<div class="state-row">
<span>Turbine state</span>
<span id="responseState">Rising output</span>
</div>
</section>
<section class="panel graph-panel">
<div class="panel-head">
<div>
<p class="kicker">02 / Response curve</p>
<h2>Wind → power</h2>
</div>
<div class="live-badge">12 kW max</div>
</div>
<div class="curve-wrap">
<svg
id="curveSvg"
viewBox="0 0 360 190"
role="img"
aria-label="Turbine power response curve"
>
<defs>
<linearGradient id="curveFill" x1="0" y1="0" x2="0" y2="1">
<stop offset="0%" stop-color="#65e4e8" stop-opacity="0.28"></stop>
<stop offset="100%" stop-color="#65e4e8" stop-opacity="0.01"></stop>
</linearGradient>
</defs>
<g>
<line class="grid-line" x1="38" y1="14" x2="344" y2="14"></line>
<line class="grid-line" x1="38" y1="84" x2="344" y2="84"></line>
<line class="grid-line" x1="38" y1="154" x2="344" y2="154"></line>
<line class="grid-line" x1="38" y1="14" x2="38" y2="154"></line>
<line class="grid-line" x1="121.45" y1="14" x2="121.45" y2="154"></line>
<line class="grid-line" x1="204.91" y1="14" x2="204.91" y2="154"></line>
<line class="grid-line" x1="288.36" y1="14" x2="288.36" y2="154"></line>
<line class="grid-line" x1="344" y1="14" x2="344" y2="154"></line>
<line class="threshold" x1="79.73" y1="14" x2="79.73" y2="154"></line>
<line class="threshold" x1="288.36" y1="14" x2="288.36" y2="154"></line>
<path
id="curveArea"
fill="url(#curveFill)"
d=""
></path>
<path id="curveLine" class="curve-line" d=""></path>
<line id="activeLine" class="active-line" x1="149" y1="14" x2="149" y2="154"></line>
<circle id="activeDot" class="active-dot" cx="149" cy="154" r="6"></circle>
<text class="axis-label" x="31" y="158" text-anchor="end">0</text>
<text class="axis-label" x="31" y="88" text-anchor="end">6</text>
<text class="axis-label" x="31" y="18" text-anchor="end">12</text>
<text class="axis-label" x="38" y="173" text-anchor="middle">0</text>
<text class="axis-label" x="121.45" y="173" text-anchor="middle">6</text>
<text class="axis-label" x="204.91" y="173" text-anchor="middle">12</text>
<text class="axis-label" x="288.36" y="173" text-anchor="middle">18</text>
<text class="axis-label" x="344" y="173" text-anchor="middle">22 m/s</text>
<text class="axis-title" x="8" y="91" transform="rotate(-90 8 91)">kW</text>
</g>
</svg>
</div>
<div class="graph-footer">
<p>
Cut-in at 3 m/s · rated at 12 m/s<br />
Cut-out above 20 m/s
</p>
<div class="legend"><i></i> Power output</div>
</div>
</section>
<div class="orbit-hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (selector) => document.querySelector(selector);
const app = $("#app");
const slider = $("#windSlider");
const windValue = $("#windValue");
const windMetric = $("#windMetric");
const powerMetric = $("#powerMetric");
const rpmMetric = $("#rpmMetric");
const responseState = $("#responseState");
const sweepButton = $("#sweepButton");
const MAX_WIND = 22;
const RATED_WIND = 12;
const CUT_IN = 3;
const RATED_END = 18;
const CUT_OUT = 20;
const MAX_POWER = 12;
let windSpeed = 8;
let actualRpm = 0;
let sweepActive = false;
let sweepStart = 0;
// ------------------------------------------------------------
// Simplified wind-turbine response
// ------------------------------------------------------------
function turbineResponse(speed) {
if (speed < CUT_IN || speed >= CUT_OUT) return 0;
if (speed < RATED_WIND) {
const rise =
(Math.pow(speed, 3) - Math.pow(CUT_IN, 3)) /
(Math.pow(RATED_WIND, 3) - Math.pow(CUT_IN, 3));
return MAX_POWER * Math.max(0, rise);
}
if (speed <= RATED_END) return MAX_POWER;
return MAX_POWER * ((CUT_OUT - speed) / (CUT_OUT - RATED_END));
}
function operatingState(speed) {
if (speed < CUT_IN) return "Below cut-in";
if (speed < RATED_WIND) return "Rising output";
if (speed <= RATED_END) return "Rated output";
if (speed < CUT_OUT) return "Cut-out ramp";
return "Shutdown";
}
// ------------------------------------------------------------
// Three.js scene
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x09151e);
scene.fog = new THREE.FogExp2(0x09151e, 0.026);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
app.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xbbeeff, 0x183936, 2.0);
scene.add(hemisphere);
const sunlight = new THREE.DirectionalLight(0xfff3d7, 3.2);
sunlight.position.set(-5, 10, 7);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(2048, 2048);
sunlight.shadow.camera.left = -10;
sunlight.shadow.camera.right = 10;
sunlight.shadow.camera.top = 10;
sunlight.shadow.camera.bottom = -10;
sunlight.shadow.camera.near = 1;
sunlight.shadow.camera.far = 30;
sunlight.shadow.bias = -0.00035;
scene.add(sunlight);
const rimLight = new THREE.DirectionalLight(0x65e4e8, 1.35);
rimLight.position.set(7, 5, -7);
scene.add(rimLight);
const materialCache = new Map();
function getMaterial(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0.03
})
);
}
return materialCache.get(color);
}
function makeBox(size, position, color, parent = scene, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
getMaterial(color)
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Voxel terrain
// ------------------------------------------------------------
makeBox([15.2, 0.34, 10.5], [0, -0.34, 0], "#102b2d");
const tileGeometry = new THREE.BoxGeometry(0.76, 0.24, 0.76);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.9
});
const columns = 18;
const rows = 12;
const tiles = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
columns * rows
);
tiles.receiveShadow = true;
tiles.castShadow = false;
const dummy = new THREE.Object3D();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
dummy.position.set(
(column - (columns - 1) / 2) * 0.8,
-0.12 + (Math.random() - 0.5) * 0.025,
(row - (rows - 1) / 2) * 0.8
);
dummy.updateMatrix();
tiles.setMatrixAt(tileIndex, dummy.matrix);
const variation = Math.random();
if (variation > 0.87) tileColor.set("#32706a");
else if (variation > 0.62) tileColor.set("#245d59");
else if (variation > 0.3) tileColor.set("#1d504e");
else tileColor.set("#194744");
tiles.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
if (tiles.instanceColor) tiles.instanceColor.needsUpdate = true;
scene.add(tiles);
// Small voxel shrubs around the terrain.
const shrubPositions = [
[-5.7, 0.25, 3.2],
[-6.2, 0.18, -2.8],
[4.9, 0.22, 3.4],
[6.1, 0.16, -3.5],
[3.8, 0.2, -3.8],
[-4.3, 0.17, 3.8]
];
shrubPositions.forEach((position, index) => {
const group = new THREE.Group();
group.position.set(...position);
scene.add(group);
makeBox([0.18, 0.55, 0.18], [0, 0.1, 0], "#755640", group);
makeBox(
[0.8, 0.65, 0.8],
[0, 0.55, 0],
index % 2 ? "#4c9a75" : "#3d8568",
group
);
makeBox(
[0.55, 0.4, 0.55],
[0.17, 0.92, 0.08],
"#69b68a",
group
);
});
// ------------------------------------------------------------
// Voxel turbine
// ------------------------------------------------------------
const turbine = new THREE.Group();
scene.add(turbine);
// Foundation.
makeBox([1.45, 0.25, 1.45], [0, 0.13, 0], "#486668", turbine);
makeBox([1.18, 0.16, 1.18], [0, 0.32, 0], "#d5e7df", turbine);
// Stacked, slightly tapered square tower.
const towerLevels = 11;
for (let i = 0; i < towerLevels; i++) {
const t = i / (towerLevels - 1);
const width = 1.02 - t * 0.36;
const y = 0.49 + i * 0.39;
let color = i % 2 ? "#d7e7df" : "#f0f4e8";
if (i === 2 || i === 7) color = "#ff9a62";
makeBox(
[width, 0.36, width * 0.86],
[0, y, 0],
color,
turbine
);
}
// Collar and nacelle.
makeBox([0.76, 0.26, 0.7], [0, 4.48, 0], "#79999b", turbine);
makeBox([2.0, 0.74, 0.82], [0.12, 4.83, 0], "#ff8f61", turbine);
makeBox([1.05, 0.31, 0.64], [0.38, 5.35, 0], "#f3c17f", turbine);
makeBox([0.35, 0.24, 0.44], [0.93, 5.34, 0], "#325c62", turbine);
// Small rear mast and tail vane.
makeBox([0.12, 0.68, 0.12], [1.12, 5.3, 0], "#56777b", turbine);
makeBox([0.52, 0.08, 0.36], [1.35, 5.58, 0], "#65e4e8", turbine);
makeBox([0.28, 0.06, 0.22], [1.58, 5.58, 0], "#f3c17f", turbine);
// Rotor faces into the incoming -X wind.
const rotor = new THREE.Group();
rotor.position.set(-1.04, 4.83, 0);
turbine.add(rotor);
makeBox([0.56, 0.56, 0.56], [0, 0, 0], "#f4f0dc", rotor);
makeBox([0.18, 0.18, 0.18], [-0.34, 0, 0], "#ff9a62", rotor);
// Pixel-like details on the front face.
makeBox([0.08, 0.12, 0.12], [-0.34, 0.13, 0.13], "#325c62", rotor);
makeBox([0.08, 0.12, 0.12], [-0.34, 0.13, -0.13], "#325c62", rotor);
makeBox([0.08, 0.12, 0.12], [-0.34, -0.13, 0.13], "#325c62", rotor);
makeBox([0.08, 0.12, 0.12], [-0.34, -0.13, -0.13], "#325c62", rotor);
// Three voxel blades, each built from stacked rectangular blocks.
const bladeSegments = [
{ y: 0.39, width: 0.22, color: "#ff9a62" },
{ y: 0.78, width: 0.28, color: "#ff9a62" },
{ y: 1.18, width: 0.34, color: "#ff865d" },
{ y: 1.59, width: 0.40, color: "#ff9a62" },
{ y: 2.00, width: 0.43, color: "#ffe3a8" }
];
for (let bladeIndex = 0; bladeIndex < 3; bladeIndex++) {
const blade = new THREE.Group();
blade.rotation.x = (bladeIndex / 3) * Math.PI * 2;
rotor.add(blade);
bladeSegments.forEach((segment) => {
makeBox(
[0.17, 0.37, segment.width],
[0, segment.y, 0],
segment.color,
blade
);
});
}
// ------------------------------------------------------------
// Synthetic wind particles
// ------------------------------------------------------------
const MAX_PARTICLES = 120;
const particleGeometry = new THREE.BoxGeometry(1, 1, 1);
const particleMaterial = new THREE.MeshBasicMaterial({
color: 0x8ff6ff,
transparent: true,
opacity: 0.58,
depthWrite: false
});
const windMesh = new THREE.InstancedMesh(
particleGeometry,
particleMaterial,
MAX_PARTICLES
);
windMesh.frustumCulled = false;
scene.add(windMesh);
const particles = [];
const particleDummy = new THREE.Object3D();
for (let i = 0; i < MAX_PARTICLES; i++) {
const particle = {
x: -10 + Math.random() * 19,
y: 0.8 + Math.random() * 6.4,
z: -5.3 + Math.random() * 10.6,
size: 0.055 + Math.random() * 0.075,
factor: 0.72 + Math.random() * 0.58,
phase: Math.random() * Math.PI * 2
};
particles.push(particle);
particleDummy.position.set(particle.x, particle.y, particle.z);
particleDummy.scale.setScalar(particle.size);
particleDummy.updateMatrix();
windMesh.setMatrixAt(i, particleDummy.matrix);
const color = new THREE.Color().setHSL(
0.51 + Math.random() * 0.055,
0.82,
0.72 + Math.random() * 0.12
);
windMesh.setColorAt(i, color);
}
if (windMesh.instanceColor) windMesh.instanceColor.needsUpdate = true;
// ------------------------------------------------------------
// Voxel clouds
// ------------------------------------------------------------
const clouds = [];
function createCloud(x, y, z, scale, speed) {
const cloud = new THREE.Group();
cloud.position.set(x, y, z);
cloud.scale.setScalar(scale);
scene.add(cloud);
makeBox([1.7, 0.7, 0.8], [0, 0, 0], "#b6d5d8", cloud, false);
makeBox([1.0, 0.8, 0.8], [0.8, 0.22, 0], "#d4e8e6", cloud, false);
makeBox([0.8, 0.6, 0.8], [-0.85, 0.15, 0], "#c9e2e0", cloud, false);
makeBox([0.65, 0.45, 0.8], [1.35, -0.08, 0], "#a7c9ce", cloud, false);
cloud.userData.speed = speed;
clouds.push(cloud);
}
createCloud(-5.8, 7.3, -4.7, 0.75, 0.16);
createCloud(3.4, 8.1, -5.2, 0.52, 0.11);
createCloud(-1.5, 6.5, 5.4, 0.42, 0.09);
// ------------------------------------------------------------
// Direct camera controls — no Three.js addons
// ------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 2.75, 0);
const initialCamera = {
theta: -0.72,
phi: 1.25,
radius: 13.8
};
let cameraTheta = initialCamera.theta;
let cameraPhi = initialCamera.phi;
let cameraRadius = initialCamera.radius;
let dragging = false;
let pointerX = 0;
let pointerY = 0;
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + cameraRadius * sinPhi * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraTheta = initialCamera.theta;
cameraPhi = initialCamera.phi;
cameraRadius = initialCamera.radius;
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi - dy * 0.006,
0.48,
1.48
);
pointerX = event.clientX;
pointerY = event.clientY;
updateCamera();
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
8.5,
23
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
updateCamera();
// ------------------------------------------------------------
// UI and response graph
// ------------------------------------------------------------
const graphLeft = 38;
const graphRight = 344;
const graphTop = 14;
const graphBottom = 154;
function graphX(speed) {
return graphLeft + (speed / MAX_WIND) * (graphRight - graphLeft);
}
function graphY(power) {
return graphBottom - (power / MAX_POWER) * (graphBottom - graphTop);
}
const curveLine = $("#curveLine");
const curveArea = $("#curveArea");
const activeLine = $("#activeLine");
const activeDot = $("#activeDot");
let curvePath = "";
const areaPoints = [];
for (let i = 0; i <= 220; i++) {
const speed = (i / 220) * MAX_WIND;
const power = turbineResponse(speed);
const x = graphX(speed);
const y = graphY(power);
curvePath += `${i === 0 ? "M" : "L"} ${x.toFixed(2)} ${y.toFixed(2)} `;
areaPoints.push([x, y]);
}
curveLine.setAttribute("d", curvePath);
curveArea.setAttribute(
"d",
`M ${graphLeft} ${graphBottom} L ${areaPoints
.map(([x, y]) => `${x.toFixed(2)} ${y.toFixed(2)}`)
.join(" L ")} L ${graphRight} ${graphBottom} Z`
);
function updatePresetButtons() {
document.querySelectorAll(".preset").forEach((button) => {
button.classList.toggle(
"active",
Math.abs(Number(button.dataset.wind) - windSpeed) < 0.05
);
});
}
function applyWind(speed) {
windSpeed = THREE.MathUtils.clamp(speed, 0, MAX_WIND);
const power = turbineResponse(windSpeed);
slider.value = windSpeed.toFixed(1);
slider.style.setProperty(
"--fill",
`${(windSpeed / MAX_WIND) * 100}%`
);
windValue.textContent = windSpeed.toFixed(1);
windMetric.innerHTML = `${windSpeed.toFixed(1)}<small>m/s</small>`;
powerMetric.innerHTML = `${power.toFixed(1)}<small>kW</small>`;
responseState.textContent = operatingState(windSpeed);
const x = graphX(windSpeed);
const y = graphY(power);
activeLine.setAttribute("x1", x);
activeLine.setAttribute("x2", x);
activeDot.setAttribute("cx", x);
activeDot.setAttribute("cy", y);
updatePresetButtons();
}
function stopSweep() {
sweepActive = false;
sweepButton.classList.remove("active");
sweepButton.setAttribute("aria-pressed", "false");
sweepButton.textContent = "▶ Sweep response curve";
}
slider.addEventListener("input", () => {
stopSweep();
applyWind(Number(slider.value));
});
document.querySelectorAll(".preset").forEach((button) => {
button.addEventListener("click", () => {
stopSweep();
applyWind(Number(button.dataset.wind));
});
});
sweepButton.addEventListener("click", () => {
if (sweepActive) {
stopSweep();
return;
}
sweepActive = true;
sweepStart = performance.now();
sweepButton.classList.add("active");
sweepButton.setAttribute("aria-pressed", "true");
sweepButton.textContent = "Ⅱ Stop response sweep";
});
applyWind(windSpeed);
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
let previousTime = performance.now();
let rotorAngle = 0;
function animate(now) {
const dt = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (sweepActive) {
const elapsed = (now - sweepStart) % 18000;
const speed =
elapsed < 9000
? (elapsed / 9000) * MAX_WIND
: (1 - (elapsed - 9000) / 9000) * MAX_WIND;
applyWind(speed);
}
const power = turbineResponse(windSpeed);
const targetRpm =
windSpeed >= CUT_OUT || windSpeed < CUT_IN
? 0
: 4 + (power / MAX_POWER) * 32;
actualRpm = THREE.MathUtils.lerp(
actualRpm,
targetRpm,
1 - Math.pow(0.001, dt)
);
rotorAngle += (actualRpm / 60) * Math.PI * 2 * dt;
rotor.rotation.x = rotorAngle;
rpmMetric.innerHTML = `${Math.round(actualRpm)}<small>rpm</small>`;
// Particle density and movement follow the synthetic wind.
const visibleParticles = Math.round(
THREE.MathUtils.clamp(windSpeed * 5.5, 0, MAX_PARTICLES)
);
windMesh.count = visibleParticles;
const windVelocity = 0.45 + windSpeed * 0.62;
for (let i = 0; i < visibleParticles; i++) {
const particle = particles[i];
particle.x += dt * windVelocity * particle.factor;
particle.y += Math.sin(now * 0.0016 + particle.phase) * dt * 0.025;
if (particle.x > 8.3) {
particle.x = -9.8;
particle.y = 0.8 + Math.random() * 6.4;
particle.z = -5.3 + Math.random() * 10.6;
}
const stretch = 0.12 + windSpeed * 0.028;
particleDummy.position.set(
particle.x,
particle.y,
particle.z
);
particleDummy.scale.set(
stretch,
particle.size,
particle.size
);
particleDummy.updateMatrix();
windMesh.setMatrixAt(i, particleDummy.matrix);
}
windMesh.instanceMatrix.needsUpdate = true;
// Slowly move the clouds downwind.
clouds.forEach((cloud) => {
cloud.position.x += dt * cloud.userData.speed;
if (cloud.position.x > 11) cloud.position.x = -12;
});
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
</script>
</body>
</html>
```