Prompt specification
Build or customize the Three.js 3D scene "Compare mill orientation under the same wind" 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: Compare mill orientation under the same wind
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/compare-mill-orientation-under-the-same-wind-x2560
Scene Description Prompt:
I'd like to see this as a low-poly Three.js scene: Compare mill orientation under the same wind. Let users rotate the mill cap relative to a fixed wind arrow. Display qualitative available power under a stated simplified model while preserving the same grain-processing load. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (compare-mill-orientation-under-the-same-wind-x2560):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Windmill Orientation Lab</title>
<style>
:root {
--ink: #24322d;
--muted: #6d776f;
--paper: #f7f5ed;
--panel: #fffdf7;
--line: #dedfd5;
--wind: #208f86;
--wind-soft: #d8efea;
--accent: #df6b4d;
--accent-soft: #f8e1d7;
--a: #5267d8;
--b: #d89632;
--amber: #b9771c;
--good: #367b59;
--warn: #b35d32;
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
button { color: inherit; }
#app {
display: grid;
grid-template-columns: minmax(0, 1fr) 420px;
width: 100%;
height: 100%;
}
#viewport {
position: relative;
min-width: 0;
overflow: hidden;
background: #dfe8df;
isolation: isolate;
}
#scene {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active { cursor: grabbing; }
.scene-header {
position: absolute;
top: 24px;
left: 26px;
right: 26px;
z-index: 4;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20px;
pointer-events: none;
}
.scene-title {
max-width: 480px;
text-shadow: 0 1px 0 rgba(255,255,255,.5);
}
.scene-title .eyebrow {
display: block;
margin-bottom: 7px;
color: #47645a;
font-size: 11px;
font-weight: 800;
letter-spacing: .18em;
text-transform: uppercase;
}
.scene-title h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 3.4vw, 54px);
font-weight: 500;
line-height: .98;
letter-spacing: -.035em;
}
.scene-title p {
max-width: 440px;
margin: 11px 0 0;
color: #52675f;
font-size: 14px;
line-height: 1.5;
}
.weather-card {
min-width: 178px;
padding: 13px 15px;
border: 1px solid rgba(255,255,255,.65);
border-radius: 14px;
background: rgba(255,253,247,.83);
box-shadow: 0 12px 35px rgba(52,70,59,.10);
backdrop-filter: blur(10px);
}
.weather-row {
display: flex;
align-items: center;
gap: 9px;
color: var(--wind);
font-size: 10px;
font-weight: 900;
letter-spacing: .14em;
text-transform: uppercase;
}
.weather-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--wind);
box-shadow: 0 0 0 4px var(--wind-soft);
}
.weather-value {
display: flex;
align-items: baseline;
gap: 6px;
margin-top: 6px;
font-size: 25px;
font-weight: 750;
letter-spacing: -.04em;
}
.weather-value small {
color: var(--muted);
font-size: 12px;
font-weight: 650;
letter-spacing: 0;
}
.weather-meta {
margin-top: 4px;
color: var(--muted);
font-size: 11px;
}
.scene-legend {
position: absolute;
left: 26px;
bottom: 24px;
z-index: 4;
display: flex;
flex-wrap: wrap;
gap: 8px;
pointer-events: none;
}
.legend-chip {
display: flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border: 1px solid rgba(255,255,255,.7);
border-radius: 999px;
background: rgba(255,253,247,.82);
color: #4d5e55;
font-size: 11px;
font-weight: 650;
box-shadow: 0 6px 20px rgba(52,70,59,.07);
backdrop-filter: blur(8px);
}
.legend-chip i {
width: 18px;
height: 3px;
border-radius: 2px;
background: currentColor;
}
.legend-chip.wind { color: var(--wind); }
.legend-chip.cap { color: var(--accent); }
.legend-chip.load { color: var(--amber); }
.scene-help {
position: absolute;
right: 25px;
bottom: 25px;
z-index: 4;
color: #60736a;
font-size: 11px;
font-weight: 650;
pointer-events: none;
text-shadow: 0 1px 0 rgba(255,255,255,.65);
}
.world-label {
position: absolute;
z-index: 3;
padding: 6px 9px;
border-radius: 7px;
font-size: 9px;
font-weight: 900;
letter-spacing: .1em;
line-height: 1;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -50%);
box-shadow: 0 5px 14px rgba(39,55,48,.10);
}
.wind-label {
color: #fff;
background: var(--wind);
}
.axis-label {
color: #fff;
background: var(--accent);
}
.load-label {
color: #fff;
background: var(--amber);
}
.snapshot-label {
width: 25px;
height: 25px;
padding: 0;
border: 2px solid #fff;
border-radius: 50%;
color: #fff;
font-size: 11px;
line-height: 21px;
text-align: center;
}
.snapshot-label.a { background: var(--a); }
.snapshot-label.b { background: var(--b); }
#panel {
position: relative;
z-index: 8;
height: 100%;
overflow-y: auto;
border-left: 1px solid var(--line);
background: var(--panel);
box-shadow: -14px 0 40px rgba(49,65,57,.06);
scrollbar-width: thin;
scrollbar-color: #c8cbc1 transparent;
}
.panel-inner { padding: 28px 27px 34px; }
.panel-kicker {
display: flex;
align-items: center;
gap: 9px;
color: var(--wind);
font-size: 10px;
font-weight: 900;
letter-spacing: .16em;
text-transform: uppercase;
}
.panel-kicker::before {
content: "";
width: 24px;
height: 2px;
background: currentColor;
}
.panel-title {
margin: 12px 0 10px;
font-family: Georgia, "Times New Roman", serif;
font-size: 34px;
font-weight: 500;
line-height: 1.02;
letter-spacing: -.035em;
}
.intro {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.fixed-load-pill {
display: flex;
align-items: center;
gap: 9px;
margin: 17px 0 24px;
padding: 10px 12px;
border: 1px solid #ead9b9;
border-radius: 10px;
background: #fbf1d9;
color: #735119;
font-size: 11px;
font-weight: 750;
}
.fixed-load-pill svg {
width: 17px;
height: 17px;
flex: 0 0 auto;
stroke: var(--amber);
fill: none;
stroke-width: 1.8;
stroke-linecap: round;
stroke-linejoin: round;
}
.section {
padding: 22px 0;
border-top: 1px solid var(--line);
}
.section:first-of-type { padding-top: 0; border-top: 0; }
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 14px;
}
.section-heading h2 {
margin: 0;
font-size: 11px;
font-weight: 900;
letter-spacing: .14em;
text-transform: uppercase;
}
.bearing-readout {
color: var(--accent);
font-size: 25px;
font-weight: 800;
letter-spacing: -.04em;
}
.bearing-readout small {
color: var(--muted);
font-size: 11px;
font-weight: 700;
letter-spacing: 0;
}
.range-wrap { margin: 8px 0 0; }
input[type="range"] {
width: 100%;
height: 6px;
margin: 8px 0 0;
border-radius: 99px;
appearance: none;
background: linear-gradient(to right, var(--accent) 0 var(--pct, 25%), #dedfd6 var(--pct, 25%) 100%);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 20px;
height: 20px;
border: 4px solid #fff;
border-radius: 50%;
appearance: none;
background: var(--accent);
box-shadow: 0 2px 7px rgba(48,61,53,.25);
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 4px solid #fff;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 2px 7px rgba(48,61,53,.25);
}
.range-labels {
display: flex;
justify-content: space-between;
margin-top: 9px;
color: #929990;
font-size: 9px;
font-weight: 750;
letter-spacing: .06em;
text-transform: uppercase;
}
.range-labels .best { color: var(--wind); }
.button-row {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 8px;
margin-top: 17px;
}
button {
border: 1px solid var(--line);
border-radius: 9px;
background: #fff;
padding: 9px 10px;
font-size: 11px;
font-weight: 800;
cursor: pointer;
transition: transform .15s ease, border-color .15s ease, background .15s ease;
}
button:hover {
border-color: #b9beb4;
background: #f8f8f2;
transform: translateY(-1px);
}
button:active { transform: translateY(0); }
button.primary {
border-color: var(--wind);
background: var(--wind);
color: #fff;
}
button.primary:hover {
border-color: #16776f;
background: #16776f;
}
.power-hero {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.power-hero > span {
padding-bottom: 5px;
color: var(--muted);
font-size: 11px;
font-weight: 700;
}
.power-number {
color: var(--accent);
font-size: 43px;
font-weight: 800;
line-height: .9;
letter-spacing: -.06em;
}
.power-number small {
margin-left: 4px;
color: var(--muted);
font-size: 14px;
font-weight: 750;
letter-spacing: 0;
}
.meter {
position: relative;
height: 13px;
overflow: visible;
border-radius: 99px;
background: #e8e8df;
}
.meter-fill {
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #e98b6f, var(--accent));
transition: width .12s linear;
}
.load-marker {
position: absolute;
top: -6px;
width: 2px;
height: 25px;
background: var(--amber);
transform: translateX(-1px);
}
.load-marker::after {
content: "4.0 kW load";
position: absolute;
top: -18px;
left: 50%;
color: var(--amber);
font-size: 9px;
font-weight: 850;
white-space: nowrap;
transform: translateX(-50%);
}
.meter-labels {
display: flex;
justify-content: space-between;
margin-top: 8px;
color: #929990;
font-size: 9px;
font-weight: 700;
}
.power-stats {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin-top: 20px;
}
.power-stat {
min-width: 0;
padding: 11px 9px;
border: 1px solid var(--line);
border-radius: 10px;
background: #fafaf4;
}
.power-stat span {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: .07em;
text-transform: uppercase;
}
.power-stat strong {
display: block;
font-size: 16px;
letter-spacing: -.025em;
white-space: nowrap;
}
.status {
margin-top: 12px;
padding: 10px 12px;
border-radius: 9px;
font-size: 11px;
font-weight: 750;
line-height: 1.4;
}
.status.good {
background: #e4f1e8;
color: var(--good);
}
.status.warn {
background: #f8e6db;
color: var(--warn);
}
.micro-note {
margin: 10px 0 0;
color: #858c84;
font-size: 10px;
line-height: 1.45;
}
.compare-note {
margin: -3px 0 13px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.compare-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.snapshot-card {
min-width: 0;
padding: 11px;
border: 1px solid var(--line);
border-radius: 11px;
background: #fafaf5;
}
.snapshot-head {
display: flex;
align-items: center;
gap: 6px;
margin-bottom: 10px;
}
.snapshot-badge {
width: 23px;
height: 23px;
border-radius: 50%;
color: #fff;
font-size: 11px;
font-weight: 900;
line-height: 23px;
text-align: center;
}
.snapshot-badge.a { background: var(--a); }
.snapshot-badge.b { background: var(--b); }
.snapshot-head strong {
font-size: 13px;
letter-spacing: -.02em;
}
.snapshot-head button {
margin-left: auto;
padding: 4px 6px;
border-radius: 6px;
font-size: 8px;
letter-spacing: .04em;
text-transform: uppercase;
}
.snapshot-delta {
color: var(--muted);
font-size: 9px;
font-weight: 700;
}
.mini-metric {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 5px;
margin-top: 9px;
font-size: 9px;
font-weight: 750;
}
.mini-metric span { color: var(--muted); }
.mini-metric b { font-size: 11px; }
.mini-meter {
position: relative;
height: 6px;
margin-top: 5px;
overflow: visible;
border-radius: 99px;
background: #e3e4dc;
}
.mini-meter i {
display: block;
height: 100%;
border-radius: inherit;
}
.snapshot-card.a .mini-meter i { background: var(--a); }
.snapshot-card.b .mini-meter i { background: var(--b); }
.mini-meter em {
position: absolute;
top: -2px;
width: 1px;
height: 10px;
background: var(--amber);
}
.save-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 9px;
}
.comparison-result {
margin-top: 12px;
padding: 10px 11px;
border-left: 3px solid var(--accent);
background: #f4f1e8;
color: #59645d;
font-size: 10px;
font-weight: 650;
line-height: 1.45;
}
details {
padding: 15px;
border: 1px solid var(--line);
border-radius: 11px;
background: #fafaf4;
}
summary {
cursor: pointer;
font-size: 11px;
font-weight: 850;
letter-spacing: .04em;
}
.equation {
margin: 15px 0 12px;
padding: 12px;
border-radius: 8px;
background: #eff2eb;
color: #405048;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
line-height: 1.65;
overflow-x: auto;
}
.assumptions {
margin: 0;
padding-left: 17px;
color: var(--muted);
font-size: 10px;
line-height: 1.6;
}
.assumptions li { margin: 6px 0; }
@media (max-width: 960px) {
html, body { overflow: auto; }
#app { display: block; height: auto; min-height: 100%; }
#viewport { height: 58vh; min-height: 430px; }
#panel { height: auto; overflow: visible; border-left: 0; border-top: 1px solid var(--line); }
.panel-inner { max-width: 650px; margin: 0 auto; }
.scene-header { top: 18px; left: 18px; right: 18px; }
.weather-card { min-width: 148px; }
.scene-help { display: none; }
.scene-legend { left: 18px; bottom: 18px; }
}
@media (max-width: 600px) {
#viewport { height: 52vh; min-height: 370px; }
.scene-title h1 { font-size: 32px; }
.scene-title p { display: none; }
.weather-card { min-width: 132px; padding: 10px 11px; }
.weather-value { font-size: 21px; }
.scene-legend { right: 15px; gap: 5px; }
.legend-chip { padding: 6px 8px; font-size: 9px; }
.panel-inner { padding: 24px 19px 32px; }
.panel-title { font-size: 30px; }
.power-stat { padding: 9px 7px; }
.power-stat strong { font-size: 14px; }
}
</style>
</head>
<body>
<main id="app">
<section id="viewport" aria-label="Interactive low-poly windmill scene">
<canvas id="scene" aria-label="Three-dimensional windmill orientation scene"></canvas>
<header class="scene-header">
<div class="scene-title">
<span class="eyebrow">Orientation study / 01</span>
<h1>Same wind.<br>Different yield.</h1>
<p>Turn the mill cap against a fixed wind arrow, then pin two orientations to compare their available power.</p>
</div>
<div class="weather-card">
<div class="weather-row"><span class="weather-dot"></span> Fixed wind</div>
<div class="weather-value">8.0 <small>m/s</small></div>
<div class="weather-meta">Wind bearing 090° · unchanged</div>
</div>
</header>
<div class="world-label wind-label" id="windLabel">Fixed wind · 090°</div>
<div class="world-label axis-label" id="axisLabel">Cap axis · 090°</div>
<div class="world-label load-label" id="loadLabel">Fixed grain load · 4.0 kW</div>
<div class="world-label snapshot-label a" id="labelA">A</div>
<div class="world-label snapshot-label b" id="labelB">B</div>
<div class="scene-legend">
<div class="legend-chip wind"><i></i> Fixed wind</div>
<div class="legend-chip cap"><i></i> Cap / rotor axis</div>
<div class="legend-chip load"><i></i> Grain load</div>
</div>
<div class="scene-help">Drag the cap to turn · Drag the scene to orbit · Scroll to zoom</div>
</section>
<aside id="panel">
<div class="panel-inner">
<div class="panel-kicker">Windmill orientation lab</div>
<h2 class="panel-title">Align for power,<br>not by instinct.</h2>
<p class="intro">The rotor works best when its plane faces the wind. Rotate the cap and watch the indicative power change while the grain-processing demand stays fixed.</p>
<div class="fixed-load-pill">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M12 21V10M12 13c-4 0-6-2-6-5 3 0 6 1 6 5Zm0-3c4 0 6-2 6-5-3 0-6 1-6 5Zm0 5c-3 0-5-1-5-4 3 0 5 1 5 4Zm0-2c3 0 5-1 5-4-3 0-5 1-5 4Z"/>
</svg>
Grain-processing load is fixed at 4.0 kW in every orientation.
</div>
<section class="section">
<div class="section-heading">
<h2>Current cap bearing</h2>
<div class="bearing-readout"><span id="bearingValue">090°</span> <small>/ 360°</small></div>
</div>
<div class="range-wrap">
<input id="bearingRange" type="range" min="0" max="359" step="1" value="90" aria-label="Cap bearing in degrees" />
<div class="range-labels">
<span>000°</span>
<span class="best">Best · 090°</span>
<span>359°</span>
</div>
</div>
<div class="button-row">
<button id="turnLeft" type="button">−15°</button>
<button id="alignButton" class="primary" type="button">Align to wind</button>
<button id="turnRight" type="button">+15°</button>
</div>
</section>
<section class="section">
<div class="section-heading">
<h2>Available power</h2>
<span class="micro-note" style="margin:0">Indicative model</span>
</div>
<div class="power-hero">
<span>Wind power reaching the rotor</span>
<div class="power-number"><span id="availableValue">10.0</span><small>kW</small></div>
</div>
<div class="meter" aria-label="Available power meter">
<div class="meter-fill" id="availableBar" style="width:100%"></div>
<div class="load-marker" id="loadMarker"></div>
</div>
<div class="meter-labels"><span>0 kW</span><span id="maxPowerLabel">10.0 kW maximum</span></div>
<div class="power-stats">
<div class="power-stat"><span>To grain</span><strong id="deliveredValue">4.0 kW</strong></div>
<div class="power-stat"><span>Alignment</span><strong id="mismatchValue">0°</strong></div>
<div class="power-stat"><span>Load met</span><strong id="coverageValue">100%</strong></div>
</div>
<div class="status good" id="statusBox" aria-live="polite">Load met · 6.0 kW available surplus</div>
<p class="micro-note">Available power is shown independently of the load. Grain power is capped at the unchanged 4.0 kW processing demand.</p>
</section>
<section class="section">
<div class="section-heading">
<h2>Compare orientations</h2>
<button id="saveA" type="button" style="padding:5px 7px;font-size:8px">Save A</button>
<button id="saveB" type="button" style="padding:5px 7px;font-size:8px">Save B</button>
</div>
<p class="compare-note">Both snapshots use the same 8.0 m/s wind and the same 4.0 kW grain load.</p>
<div class="compare-grid" id="compareCards"></div>
<div class="comparison-result" id="comparisonResult"></div>
</section>
<section class="section">
<details>
<summary>Simplified model & assumptions</summary>
<div class="equation">
P<sub>available</sub> = ½ρAv³ · max(0, cos Δ)³<br>
P<sub>grain</sub> = min(P<sub>available</sub>, 4.0 kW)
</div>
<ul class="assumptions">
<li>Air density ρ = 1.225 kg/m³.</li>
<li>Effective rotor area A = 24 m².</li>
<li>Wind speed v = 8.0 m/s, held constant.</li>
<li>Δ is the shortest signed angle between cap and wind bearings.</li>
<li>The cosine-cubed factor represents projected area plus a simplified loss with misalignment.</li>
<li>No turbulence, wind-speed variation, drivetrain efficiency, startup behavior, or detailed aerodynamics are modeled.</li>
<li>The 4.0 kW grain-processing requirement never changes. Any surplus is not assigned to the grain process.</li>
</ul>
</details>
</section>
</div>
</aside>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const canvas = document.getElementById("scene");
const WIND_SPEED = 8.0;
const WIND_BEARING = 90;
const EFFECTIVE_AREA = 24;
const AIR_DENSITY = 1.225;
const GRAIN_LOAD = 4000;
const RAW_POWER = 0.5 * AIR_DENSITY * EFFECTIVE_AREA * Math.pow(WIND_SPEED, 3);
const colors = {
wind: 0x208f86,
accent: 0xdf6b4d,
a: 0x5267d8,
b: 0xd89632,
amber: 0xb9771c
};
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdfe8df);
scene.fog = new THREE.Fog(0xdfe8df, 18, 42);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 100);
const cameraState = {
theta: 0.72,
phi: 0.94,
radius: 13.7,
target: new THREE.Vector3(0, 2.65, 0)
};
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
flatShading: true,
...options
});
}
const mat = {
ground: material(0xaebda0),
island: material(0xc4c6a6),
path: material(0xd8cba6),
stone: material(0xb7b6a8),
stoneDark: material(0x8f9388),
plaster: material(0xe8e0cd),
plasterShade: material(0xd6cdb8),
timber: material(0x6f5038),
timberLight: material(0xa5784b),
roof: material(0xa64f3b),
roofDark: material(0x793c31),
sail: material(0xe5d5ad),
dark: material(0x2d3733),
glass: material(0x526c68, { roughness: 0.35, metalness: 0.12 }),
leaf: material(0x66805f),
leafDark: material(0x4f6c50),
trunk: material(0x71533b),
bag: material(0xc8a66d),
wind: material(colors.wind, { transparent: true, opacity: 0.9 }),
accent: material(colors.accent),
a: material(colors.a),
b: material(colors.b),
amber: material(colors.amber)
};
const hemi = new THREE.HemisphereLight(0xf6fbff, 0x778369, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff2d7, 3.25);
sun.position.set(-7, 13, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9ec9c6, 0.65);
fill.position.set(8, 6, -8);
scene.add(fill);
function mesh(geometry, material, position, parent = scene) {
const object = new THREE.Mesh(geometry, material);
if (position) object.position.copy(position);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function cylinderBetween(a, b, radius, material, parent = scene, radialSegments = 6) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const object = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, radialSegments),
material
);
object.position.copy(a).add(b).multiplyScalar(0.5);
object.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function coneBetween(tip, direction, length, radius, material, parent = scene) {
const dir = direction.clone().normalize();
const object = new THREE.Mesh(
new THREE.ConeGeometry(radius, length, 6),
material
);
object.position.copy(tip).addScaledVector(dir, -length * 0.5);
object.quaternion.setFromUnitVectors(new THREE.Vector3(0, 1, 0), dir);
object.castShadow = true;
parent.add(object);
return object;
}
// Ground and paths.
const ground = mesh(
new THREE.PlaneGeometry(100, 100),
mat.ground,
new THREE.Vector3(0, -0.36, 0)
);
ground.rotation.x = -Math.PI / 2;
ground.castShadow = false;
mesh(
new THREE.CylinderGeometry(8.2, 8.55, 0.36, 32),
mat.island,
new THREE.Vector3(0, -0.18, 0)
);
const path = mesh(
new THREE.RingGeometry(2.15, 5.1, 32),
mat.path,
new THREE.Vector3(0, 0.012, 0)
);
path.rotation.x = -Math.PI / 2;
path.castShadow = false;
// Orientation ring and radial ticks.
const ringPoints = [];
for (let i = 0; i < 72; i++) {
const angle = i / 72 * Math.PI * 2;
ringPoints.push(new THREE.Vector3(Math.sin(angle) * 4.38, 0.055, Math.cos(angle) * 4.38));
}
const ringGeometry = new THREE.BufferGeometry().setFromPoints(ringPoints);
const ring = new THREE.LineLoop(
ringGeometry,
new THREE.LineBasicMaterial({ color: 0x73877d, transparent: true, opacity: 0.38 })
);
scene.add(ring);
const tickMaterial = material(0x84978d);
for (let i = 0; i < 24; i++) {
const angle = i / 24 * Math.PI * 2;
const tick = mesh(
new THREE.BoxGeometry(i % 6 === 0 ? 0.07 : 0.045, 0.025, i % 6 === 0 ? 0.42 : 0.25),
tickMaterial,
new THREE.Vector3(Math.sin(angle) * 4.38, 0.065, Math.cos(angle) * 4.38)
);
tick.rotation.y = angle;
tick.castShadow = false;
}
// Traditional low-poly post mill.
mesh(
new THREE.CylinderGeometry(1.48, 1.72, 0.45, 10),
mat.stoneDark,
new THREE.Vector3(0, 0.225, 0)
);
mesh(
new THREE.CylinderGeometry(1.1, 1.48, 3.65, 10),
mat.plaster,
new THREE.Vector3(0, 2.45, 0)
);
mesh(
new THREE.CylinderGeometry(1.52, 1.52, 0.2, 12),
mat.timberLight,
new THREE.Vector3(0, 4.14, 0)
);
[1.0, 2.65].forEach((y, index) => {
const radius = index === 0 ? 1.38 : 1.2;
const band = mesh(
new THREE.TorusGeometry(radius, 0.035, 4, 12),
mat.stoneDark,
new THREE.Vector3(0, y, 0)
);
band.rotation.x = Math.PI / 2;
});
const doorFrame = mesh(
new THREE.BoxGeometry(0.83, 1.58, 0.13),
mat.timber,
new THREE.Vector3(0, 1.25, 1.39)
);
doorFrame.castShadow = false;
mesh(
new THREE.BoxGeometry(0.62, 1.35, 0.16),
mat.dark,
new THREE.Vector3(0, 1.22, 1.47)
);
mesh(
new THREE.BoxGeometry(0.45, 0.55, 0.14),
mat.timber,
new THREE.Vector3(0, 2.86, 1.19)
);
mesh(
new THREE.BoxGeometry(0.32, 0.41, 0.16),
mat.glass,
new THREE.Vector3(0, 2.86, 1.25)
);
for (const side of [-1, 1]) {
const frame = mesh(
new THREE.BoxGeometry(0.13, 0.55, 0.45),
mat.timber,
new THREE.Vector3(side * 1.28, 2.72, 0)
);
const glass = mesh(
new THREE.BoxGeometry(0.16, 0.39, 0.31),
mat.glass,
new THREE.Vector3(side * 1.34, 2.72, 0)
);
frame.castShadow = false;
glass.castShadow = false;
}
// Random-looking masonry blocks around the base.
for (let i = 0; i < 11; i++) {
const angle = i / 11 * Math.PI * 2 + 0.08;
const radius = 1.59;
const block = mesh(
new THREE.BoxGeometry(0.36, 0.18, 0.22),
i % 3 === 0 ? mat.stone : mat.stoneDark,
new THREE.Vector3(Math.sin(angle) * radius, 0.34, Math.cos(angle) * radius)
);
block.rotation.y = angle;
}
// Rotating cap and rotor.
const capGroup = new THREE.Group();
capGroup.position.y = 4.18;
scene.add(capGroup);
mesh(
new THREE.CylinderGeometry(0.82, 0.98, 0.78, 8),
mat.roofDark,
new THREE.Vector3(0, 0.4, 0),
capGroup
);
mesh(
new THREE.ConeGeometry(1.15, 1.18, 8),
mat.roof,
new THREE.Vector3(0, 1.28, 0),
capGroup
);
const rotorGroup = new THREE.Group();
rotorGroup.position.set(0, 0.68, 1.42);
capGroup.add(rotorGroup);
const hub = mesh(
new THREE.CylinderGeometry(0.3, 0.3, 0.44, 10),
mat.timberLight,
new THREE.Vector3(0, 0, 0),
rotorGroup
);
hub.rotation.x = Math.PI / 2;
function createBlade() {
const blade = new THREE.Group();
mesh(
new THREE.BoxGeometry(0.13, 2.75, 0.13),
mat.timber,
new THREE.Vector3(0, 1.45, 0),
blade
);
[-0.35, 0.38].forEach((x) => {
mesh(
new THREE.BoxGeometry(0.075, 2.16, 0.09),
mat.timberLight,
new THREE.Vector3(x, 1.57, 0),
blade
);
});
for (let i = 0; i < 7; i++) {
mesh(
new THREE.BoxGeometry(0.82, 0.075, 0.09),
mat.timberLight,
new THREE.Vector3(0.015, 0.63 + i * 0.31, 0),
blade
);
}
mesh(
new THREE.BoxGeometry(0.07, 1.7, 0.07),
mat.sail,
new THREE.Vector3(0.38, 1.56, 0.035),
blade
);
return blade;
}
for (let i = 0; i < 4; i++) {
const blade = createBlade();
blade.rotation.z = i * Math.PI / 2;
rotorGroup.add(blade);
}
cylinderBetween(
new THREE.Vector3(0, 0.68, 0.65),
new THREE.Vector3(0, 0.68, 1.5),
0.14,
mat.timber,
capGroup
);
// Tail pole and vane.
cylinderBetween(
new THREE.Vector3(0, 0.58, -0.65),
new THREE.Vector3(0, 0.58, -2.75),
0.08,
mat.timber,
capGroup
);
const tail = mesh(
new THREE.BoxGeometry(0.08, 0.72, 0.68),
mat.timberLight,
new THREE.Vector3(0, 0.63, -2.54),
capGroup
);
tail.rotation.x = -0.12;
// Ground-level cap-axis needle.
cylinderBetween(
new THREE.Vector3(0, -3.79, 0.6),
new THREE.Vector3(0, -3.79, 4.13),
0.035,
mat.accent,
capGroup
);
coneBetween(
new THREE.Vector3(0, -3.79, 4.45),
new THREE.Vector3(0, 0, 1),
0.44,
0.14,
mat.accent,
capGroup
);
capGroup.traverse((object) => {
if (object.isMesh) object.userData.capPart = true;
});
// Fixed wind arrow in world space.
cylinderBetween(
new THREE.Vector3(-5.8, 0.48, 3.45),
new THREE.Vector3(4.35, 0.48, 3.45),
0.065,
mat.wind,
scene
);
coneBetween(
new THREE.Vector3(4.9, 0.48, 3.45),
new THREE.Vector3(1, 0, 0),
0.9,
0.25,
mat.wind,
scene
);
// Grain sacks and a fixed amber ground ring.
const loadRing = mesh(
new THREE.RingGeometry(0.7, 0.9, 24),
mat.amber,
new THREE.Vector3(-1.85, 0.03, 2.28)
);
loadRing.rotation.x = -Math.PI / 2;
loadRing.castShadow = false;
const sackPositions = [
[-2.08, 0.35, 2.25, 1.0],
[-1.55, 0.34, 2.4, 0.95],
[-1.84, 0.78, 2.24, 0.82]
];
sackPositions.forEach(([x, y, z, scale]) => {
const sack = mesh(
new THREE.DodecahedronGeometry(0.42, 0),
mat.bag,
new THREE.Vector3(x, y, z)
);
sack.scale.set(scale, 1.15 * scale, 0.88 * scale);
sack.rotation.set(0.1, 0.3, -0.08);
});
// Trees around the island.
const treePositions = [
[-6.3, -0.1, -3.4, 1.1],
[-5.2, -0.1, -5.0, 0.85],
[5.8, -0.1, -4.6, 1.2],
[6.5, -0.1, 1.8, 0.9],
[-6.4, -0.1, 3.9, 0.72]
];
treePositions.forEach(([x, y, z, scale], index) => {
const tree = new THREE.Group();
tree.position.set(x, y, z);
tree.scale.setScalar(scale);
scene.add(tree);
mesh(
new THREE.CylinderGeometry(0.13, 0.19, 1.15, 6),
mat.trunk,
new THREE.Vector3(0, 0.56, 0),
tree
);
mesh(
new THREE.ConeGeometry(0.8, 1.7, 7),
index % 2 ? mat.leafDark : mat.leaf,
new THREE.Vector3(0, 1.55, 0),
tree
);
mesh(
new THREE.ConeGeometry(0.58, 1.35, 7),
mat.leaf,
new THREE.Vector3(0, 2.22, 0),
tree
);
});
// Low-poly distant hills.
[
[-10, 0, -15, 8, 5],
[3, 0, -18, 11, 6],
[15, 0, -12, 7, 4]
].forEach(([x, y, z, radius, height]) => {
const hill = mesh(
new THREE.ConeGeometry(radius, height, 7),
material(indexColor(0x8ea18b)),
new THREE.Vector3(x, y + height * 0.5 - 0.4, z)
);
hill.castShadow = false;
});
function indexColor(hex) {
return hex;
}
// Faceted clouds.
const cloudMaterial = material(0xf7f5e9);
[
[-4, 8.7, -11, 1.0],
[4.8, 9.5, -14, 1.25],
[10, 8, -17, 0.8]
].forEach(([x, y, z, scale]) => {
const cloud = new THREE.Group();
cloud.position.set(x, y, z);
cloud.scale.setScalar(scale);
scene.add(cloud);
[[-0.8, 0, 0, 0.8], [0, 0.28, 0, 1.0], [0.85, -0.02, 0, 0.72]].forEach(([cx, cy, cz, s]) => {
const puff = mesh(
new THREE.IcosahedronGeometry(0.8 * s, 0),
cloudMaterial,
new THREE.Vector3(cx, cy, cz),
cloud
);
puff.castShadow = false;
puff.receiveShadow = false;
});
});
// Wind streaks moving in the fixed wind direction.
const streaks = [];
const streakGeometry = new THREE.BoxGeometry(0.75, 0.025, 0.025);
const streakMaterial = new THREE.MeshBasicMaterial({
color: colors.wind,
transparent: true,
opacity: 0.28
});
for (let i = 0; i < 15; i++) {
const streak = new THREE.Mesh(streakGeometry, streakMaterial);
streak.position.set(
-6 + Math.random() * 12,
0.42 + Math.random() * 0.65,
2.0 + Math.random() * 2.6
);
streak.userData.speed = 0.65 + Math.random() * 0.8;
scene.add(streak);
streaks.push(streak);
}
// A/B orientation markers on the compass.
function makeSnapshotMarker(materialRef) {
const group = new THREE.Group();
mesh(
new THREE.CylinderGeometry(0.06, 0.08, 0.55, 6),
materialRef,
new THREE.Vector3(0, 0.28, 0),
group
);
mesh(
new THREE.ConeGeometry(0.16, 0.32, 6),
materialRef,
new THREE.Vector3(0, 0.68, 0),
group
);
scene.add(group);
return group;
}
const markerA = makeSnapshotMarker(mat.a);
const markerB = makeSnapshotMarker(mat.b);
// State and model calculations.
let bearing = WIND_BEARING;
let snapshotA = { bearing: WIND_BEARING };
let snapshotB = { bearing: 40 };
let rotorAngle = 0;
let elapsed = 0;
const wrapDegrees = (value) => ((value % 360) + 360) % 360;
function signedDelta(angle, reference) {
let delta = wrapDegrees(angle - reference);
if (delta > 180) delta -= 360;
return delta;
}
function availablePower(angle) {
const delta = signedDelta(angle, WIND_BEARING);
const projected = Math.max(0, Math.cos(THREE.MathUtils.degToRad(delta)));
return RAW_POWER * projected * projected * projected;
}
function kW(watts) {
return (watts / 1000).toFixed(1);
}
function updateMarker(marker, angle) {
const radians = THREE.MathUtils.degToRad(angle);
marker.position.set(Math.sin(radians) * 4.58, 0.03, Math.cos(radians) * 4.58);
}
function snapshotMarkup(key, snapshot) {
const available = availablePower(snapshot.bearing);
const delivered = Math.min(available, GRAIN_LOAD);
const delta = signedDelta(snapshot.bearing, WIND_BEARING);
const deltaText = `${delta > 0 ? "+" : ""}${Math.round(delta)}°`;
const width = Math.max(0, Math.min(100, available / RAW_POWER * 100));
const markerPosition = Math.min(100, GRAIN_LOAD / RAW_POWER * 100);
return `
<article class="snapshot-card ${key.toLowerCase()}">
<div class="snapshot-head">
<span class="snapshot-badge ${key.toLowerCase()}">${key}</span>
<strong>${String(Math.round(snapshot.bearing)).padStart(3, "0")}°</strong>
<button type="button" data-load="${key}" aria-label="Load orientation ${key}">View</button>
</div>
<div class="snapshot-delta">Wind offset ${deltaText}</div>
<div class="mini-metric"><span>Available</span><b>${kW(available)} kW</b></div>
<div class="mini-meter"><i style="width:${width}%"></i><em style="left:${markerPosition}%"></em></div>
<div class="mini-metric"><span>To grain</span><b>${kW(delivered)} kW</b></div>
</article>
`;
}
function updateComparison() {
document.getElementById("compareCards").innerHTML =
snapshotMarkup("A", snapshotA) + snapshotMarkup("B", snapshotB);
updateMarker(markerA, snapshotA.bearing);
updateMarker(markerB, snapshotB.bearing);
const availableA = availablePower(snapshotA.bearing);
const availableB = availablePower(snapshotB.bearing);
const difference = Math.abs(availableA - availableB);
const result = document.getElementById("comparisonResult");
if (difference < 10) {
result.textContent = "A and B receive the same available power. Their grain-processing demand remains 4.0 kW.";
} else {
const winner = availableA > availableB ? "A" : "B";
const loser = winner === "A" ? "B" : "A";
result.textContent = `${winner} has ${kW(difference)} kW more available power than ${loser}. Both retain the same 4.0 kW grain load.`;
}
}
function updateAll() {
capGroup.rotation.y = THREE.MathUtils.degToRad(bearing);
const available = availablePower(bearing);
const delivered = Math.min(available, GRAIN_LOAD);
const delta = signedDelta(bearing, WIND_BEARING);
const absoluteDelta = Math.abs(delta);
const coverage = Math.min(100, delivered / GRAIN_LOAD * 100);
const surplus = Math.max(0, available - GRAIN_LOAD);
const shortfall = Math.max(0, GRAIN_LOAD - available);
document.getElementById("bearingValue").textContent =
`${String(Math.round(bearing)).padStart(3, "0")}°`;
document.getElementById("axisLabel").textContent =
`Cap axis · ${String(Math.round(bearing)).padStart(3, "0")}°`;
document.getElementById("availableValue").textContent = kW(available);
document.getElementById("deliveredValue").textContent = `${kW(delivered)} kW`;
document.getElementById("mismatchValue").textContent = `${Math.round(absoluteDelta)}°`;
document.getElementById("coverageValue").textContent = `${Math.round(coverage)}%`;
document.getElementById("availableBar").style.width =
`${Math.max(0, Math.min(100, available / RAW_POWER * 100))}%`;
document.getElementById("maxPowerLabel").textContent = `${kW(RAW_POWER)} kW maximum`;
const statusBox = document.getElementById("statusBox");
if (shortfall <= 1) {
statusBox.className = "status good";
statusBox.textContent = `Load met · ${kW(surplus)} kW available surplus`;
} else {
statusBox.className = "status warn";
statusBox.textContent = `Load short by ${kW(shortfall)} kW · grain processing is underpowered`;
}
const range = document.getElementById("bearingRange");
range.value = Math.round(bearing);
range.style.setProperty("--pct", `${bearing / 359 * 100}%`);
range.setAttribute("aria-valuetext", `${Math.round(bearing)} degrees`);
updateComparison();
}
function setBearing(value) {
bearing = wrapDegrees(value);
updateAll();
}
document.getElementById("bearingRange").addEventListener("input", (event) => {
setBearing(Number(event.target.value));
});
document.getElementById("turnLeft").addEventListener("click", () => setBearing(bearing - 15));
document.getElementById("turnRight").addEventListener("click", () => setBearing(bearing + 15));
document.getElementById("alignButton").addEventListener("click", () => setBearing(WIND_BEARING));
document.getElementById("saveA").addEventListener("click", () => {
snapshotA = { bearing };
updateComparison();
});
document.getElementById("saveB").addEventListener("click", () => {
snapshotB = { bearing };
updateComparison();
});
document.getElementById("compareCards").addEventListener("click", (event) => {
const button = event.target.closest("[data-load]");
if (!button) return;
const snapshot = button.dataset.load === "A" ? snapshotA : snapshotB;
setBearing(snapshot.bearing);
});
// Custom camera controls and direct cap dragging.
function updateCamera() {
const { theta, phi, radius, target } = 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);
}
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let dragging = null;
let lastX = 0;
let lastY = 0;
function pointerToNDC(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
pointerToNDC(event);
raycaster.setFromCamera(pointer, camera);
const capHit = raycaster.intersectObject(capGroup, true).length > 0;
dragging = capHit ? "cap" : "camera";
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = dragging === "cap" ? "ew-resize" : "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
if (dragging === "cap") {
setBearing(bearing + dx * 0.42);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(cameraState.phi + dy * 0.005, 0.48, 1.37);
updateCamera();
}
lastX = event.clientX;
lastY = event.clientY;
});
function endDrag(event) {
if (!dragging) return;
dragging = null;
canvas.style.cursor = "grab";
if (canvas.hasPointerCapture(event.pointerId)) canvas.releasePointerCapture(event.pointerId);
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("pointerleave", (event) => {
if (dragging === "camera") endDrag(event);
});
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.008,
8.5,
21
);
updateCamera();
}, { passive: false });
// Labels projected from world-space positions.
function placeLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const width = viewport.clientWidth;
const height = viewport.clientHeight;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
const visible = projected.z > -1 && projected.z < 1;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.opacity = visible ? "1" : "0";
}
const windLabel = document.getElementById("windLabel");
const axisLabel = document.getElementById("axisLabel");
const loadLabel = document.getElementById("loadLabel");
const labelA = document.getElementById("labelA");
const labelB = document.getElementById("labelB");
function resize() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
updateCamera();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(viewport);
resize();
updateAll();
updateCamera();
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
const powerFactor = availablePower(bearing) / RAW_POWER;
rotorAngle -= delta * (0.14 + powerFactor * 0.63);
rotorGroup.rotation.z = rotorAngle;
streaks.forEach((streak, index) => {
streak.position.x += delta * streak.userData.speed;
if (streak.position.x > 6.3) {
streak.position.x = -6.3;
streak.position.y = 0.42 + Math.random() * 0.65;
streak.position.z = 2.0 + Math.random() * 2.6;
}
streak.material.opacity = 0.18 + 0.1 * Math.sin(elapsed * 2 + index);
});
renderer.render(scene, camera);
capGroup.updateWorldMatrix(true, false);
placeLabel(windLabel, new THREE.Vector3(3.7, 1.05, 3.45));
placeLabel(axisLabel, capGroup.localToWorld(new THREE.Vector3(0, -3.45, 4.35)));
placeLabel(loadLabel, new THREE.Vector3(-1.85, 1.35, 2.28));
placeLabel(labelA, markerA.position.clone().add(new THREE.Vector3(0, 0.95, 0)));
placeLabel(labelB, markerB.position.clone().add(new THREE.Vector3(0, 0.95, 0)));
});
</script>
</body>
</html>
```