Prompt specification
Build or customize the Three.js 3D scene "Wind-powered grain milling and storage scene" 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-powered grain milling and storage scene
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/wind-powered-grain-milling-and-storage-scene-x2559
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows windmill orientation and mechanical work. Build a compact historical milling scene with sails, drive train, millstones, grain input, and flour output. Show a continuous material and energy path through the structure. Low-poly.
Working Three.js Starter (wind-powered-grain-milling-and-storage-scene-x2559):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>The Grain Works — Windmill Milling Study</title>
<style>
:root {
--ink: #24352f;
--muted: #68766e;
--paper: rgba(250, 247, 235, 0.94);
--line: rgba(46, 65, 57, 0.16);
--energy: #f4b83f;
--grain: #ce922f;
--flour: #fff1ce;
--wind: #73c8cf;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cbd8d0;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#viewport {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid rgba(255, 255, 255, 0.58);
background: var(--paper);
box-shadow:
0 14px 38px rgba(36, 53, 47, 0.12),
inset 0 1px 0 rgba(255, 255, 255, 0.8);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#title-card {
top: 22px;
left: 22px;
width: min(370px, calc(100vw - 44px));
padding: 19px 21px 17px;
border-radius: 4px 18px 18px 18px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: #78847c;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(28px, 3.5vw, 44px);
font-weight: 500;
letter-spacing: -0.035em;
line-height: 0.95;
}
#title-card p {
max-width: 310px;
margin: 12px 0 15px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.status-row {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
.status {
display: inline-flex;
align-items: center;
gap: 7px;
min-height: 25px;
padding: 5px 9px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(255, 255, 255, 0.48);
color: #52625a;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.status::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--energy);
content: "";
box-shadow: 0 0 0 3px rgba(244, 184, 63, 0.16);
}
#controls {
right: 22px;
bottom: 22px;
width: min(390px, calc(100vw - 44px));
padding: 16px;
border-radius: 18px 4px 18px 18px;
}
.control-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 13px 16px;
}
.control {
min-width: 0;
}
.control-heading {
display: flex;
justify-content: space-between;
gap: 10px;
margin-bottom: 7px;
color: #58675f;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.control-heading output {
color: var(--ink);
font-variant-numeric: tabular-nums;
letter-spacing: 0.04em;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 7px 0;
border-radius: 999px;
outline: none;
accent-color: #57766a;
cursor: pointer;
}
input[type="checkbox"] {
width: 14px;
height: 14px;
margin: 0;
accent-color: #57766a;
cursor: pointer;
}
.checks {
display: flex;
flex-wrap: wrap;
gap: 11px 16px;
margin: 14px 0;
padding: 11px 0;
border-top: 1px solid var(--line);
border-bottom: 1px solid var(--line);
}
.check {
display: inline-flex;
align-items: center;
gap: 6px;
color: #59675f;
font-size: 10px;
font-weight: 700;
cursor: pointer;
user-select: none;
}
.buttons {
display: grid;
grid-template-columns: 1.35fr 1fr 1fr;
gap: 7px;
}
button {
min-height: 34px;
padding: 7px 10px;
border: 1px solid rgba(50, 72, 63, 0.18);
border-radius: 9px;
background: rgba(255, 255, 255, 0.65);
color: var(--ink);
font-size: 10px;
font-weight: 800;
cursor: pointer;
transition:
background 150ms ease,
transform 150ms ease;
}
button:hover {
background: white;
transform: translateY(-1px);
}
button.primary {
border-color: #4f6c60;
background: #4f6c60;
color: white;
}
button.primary:hover {
background: #405d52;
}
#compass {
position: fixed;
z-index: 9;
top: 22px;
right: 22px;
width: 100px;
height: 100px;
border: 1px solid rgba(255, 255, 255, 0.6);
border-radius: 50%;
background: rgba(248, 246, 232, 0.76);
box-shadow: 0 12px 30px rgba(40, 58, 50, 0.11);
backdrop-filter: blur(10px);
pointer-events: none;
}
#compass::before,
#compass::after {
position: absolute;
content: "";
}
#compass::before {
inset: 11px;
border: 1px dashed rgba(49, 71, 61, 0.25);
border-radius: 50%;
}
#compass::after {
top: 8px;
left: 50%;
width: 1px;
height: 9px;
background: #738179;
}
.cardinal {
position: absolute;
color: #718078;
font-size: 8px;
font-weight: 900;
}
.north { top: 13px; left: 47px; }
.south { bottom: 8px; left: 46px; }
.east { top: 43px; right: 8px; }
.west { top: 43px; left: 7px; }
#wind-arrow {
position: absolute;
top: 24px;
left: 48px;
width: 2px;
height: 49px;
transform-origin: 50% 100%;
background: var(--wind);
}
#wind-arrow::before {
position: absolute;
top: -2px;
left: -4px;
border-right: 5px solid transparent;
border-bottom: 9px solid var(--wind);
border-left: 5px solid transparent;
content: "";
}
#compass-label {
position: absolute;
right: 0;
bottom: -17px;
left: 0;
color: #6b7971;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.15em;
text-align: center;
text-transform: uppercase;
}
#legend {
position: fixed;
z-index: 8;
bottom: 22px;
left: 22px;
display: flex;
flex-direction: column;
gap: 7px;
padding: 12px 14px;
border-radius: 13px;
color: #58675f;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.04em;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
}
.swatch {
width: 19px;
height: 4px;
border-radius: 99px;
background: var(--energy);
box-shadow: 0 0 7px currentColor;
}
.swatch.grain { background: var(--grain); }
.swatch.flour { background: var(--flour); border: 1px solid #b8a16d; }
.swatch.wind { background: var(--wind); }
#hint {
position: fixed;
z-index: 8;
top: 22px;
left: 50%;
padding: 7px 10px;
border-radius: 999px;
background: rgba(249, 247, 235, 0.66);
color: #69776f;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
transform: translateX(-50%);
pointer-events: none;
}
#labels {
position: fixed;
z-index: 5;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
top: 0;
left: 0;
display: flex;
align-items: center;
gap: 7px;
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 999px;
background: rgba(247, 244, 229, 0.86);
box-shadow: 0 5px 16px rgba(33, 48, 42, 0.1);
color: #485a51;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
will-change: transform;
}
.scene-label::before {
width: 6px;
height: 6px;
border: 2px solid #f8f3df;
border-radius: 50%;
background: var(--dot, #668277);
box-shadow: 0 0 0 1px var(--dot, #668277);
content: "";
}
@media (max-width: 720px) {
#title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
#title-card p {
display: none;
}
#controls {
right: 12px;
bottom: 12px;
width: calc(100vw - 24px);
padding: 12px;
}
#compass {
top: 120px;
right: 12px;
width: 76px;
height: 76px;
transform: scale(0.82);
transform-origin: top right;
}
#legend,
#hint {
display: none;
}
.control-grid {
gap: 10px 12px;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div id="labels"></div>
<section id="title-card" class="panel">
<div class="eyebrow">Historical milling study · c. 1780</div>
<h1>The Grain Works</h1>
<p>
A cutaway tower mill tracing one continuous journey: wind becomes shaft
power, grain becomes flour, and every transfer remains visible.
</p>
<div class="status-row">
<div class="status">Wind aligned <span id="power-value">100%</span></div>
<div class="status">4-sail tower mill</div>
</div>
</section>
<div id="compass" aria-label="Wind direction compass">
<span class="cardinal north">N</span>
<span class="cardinal south">S</span>
<span class="cardinal east">E</span>
<span class="cardinal west">W</span>
<div id="wind-arrow"></div>
<div id="compass-label">Wind flow</div>
</div>
<div id="hint">Click + drag to orbit · scroll to zoom</div>
<section id="controls" class="panel">
<div class="control-grid">
<label class="control">
<span class="control-heading">
Wind bearing
<output id="wind-output">035°</output>
</span>
<input id="wind-range" type="range" min="0" max="359" value="35">
</label>
<label class="control">
<span class="control-heading">
Cap bearing
<output id="cap-output">035°</output>
</span>
<input id="cap-range" type="range" min="0" max="359" value="35">
</label>
<label class="control">
<span class="control-heading">
Mill speed
<output id="speed-output">1.0×</output>
</span>
<input id="speed-range" type="range" min="0.35" max="1.8" step="0.05" value="1">
</label>
<label class="control">
<span class="control-heading">
Camera
<output id="camera-output">Overview</output>
</span>
<input id="camera-range" type="range" min="8" max="22" step="0.1" value="15">
</label>
</div>
<div class="checks">
<label class="check">
<input id="cutaway-toggle" type="checkbox" checked>
Cutaway
</label>
<label class="check">
<input id="flow-toggle" type="checkbox" checked>
Flow paths
</label>
<label class="check">
<input id="label-toggle" type="checkbox" checked>
Labels
</label>
<label class="check">
<input id="auto-toggle" type="checkbox">
Auto-trim
</label>
</div>
<div class="buttons">
<button id="trim-button" class="primary">Turn into wind</button>
<button id="pause-button">Pause</button>
<button id="reset-button">Reset view</button>
</div>
</section>
<aside id="legend">
<div class="legend-item"><span class="swatch"></span>Mechanical energy</div>
<div class="legend-item"><span class="swatch grain"></span>Grain transfer</div>
<div class="legend-item"><span class="swatch flour"></span>Flour output</div>
<div class="legend-item"><span class="swatch wind"></span>Wind stream</div>
</aside>
<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 scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbd8d0);
scene.fog = new THREE.Fog(0xcbd8d0, 18, 38);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
80
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
viewport.appendChild(renderer.domElement);
const UP = new THREE.Vector3(0, 1, 0);
const X_AXIS = new THREE.Vector3(1, 0, 0);
const standard = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...options
});
const materials = {
ground: standard(0xaeb9a4),
platform: standard(0xa9a38e),
wall: standard(0xc9b894),
wallDark: standard(0x9d8f75),
timber: standard(0x6c4931),
timberLight: standard(0x9a7048),
roof: standard(0x59625a),
roofTrim: standard(0x3d4842),
stone: standard(0x777b73),
stoneLight: standard(0x97998e),
grain: standard(0xd6a13a),
flour: standard(0xe9dfc1),
sack: standard(0xb89a68),
flourSack: standard(0xd7c9a5),
iron: standard(0x49534e, { metalness: 0.62, roughness: 0.42 }),
brass: standard(0xd59a32, {
metalness: 0.58,
roughness: 0.32,
emissive: 0x5c2c00,
emissiveIntensity: 0.18
}),
sail: standard(0xe3d5ad, {
side: THREE.DoubleSide,
roughness: 0.95
}),
sailShade: standard(0xc8b88f, {
side: THREE.DoubleSide,
roughness: 0.95
}),
skin: standard(0xc48d69),
shirt: standard(0x6c7770),
trousers: standard(0x514b42),
leaf: standard(0x667a5a),
leafLight: standard(0x81916a)
};
function addMesh(geometry, material, parent = scene) {
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderBetween(a, b, radius, material, parent = scene, segments = 8) {
const direction = b.clone().sub(a);
const mesh = addMesh(
new THREE.CylinderGeometry(
radius,
radius,
direction.length(),
segments
),
material,
parent
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(UP, direction.normalize());
return mesh;
}
function boxBetween(a, b, width, height, material, parent = scene) {
const direction = b.clone().sub(a);
const mesh = addMesh(
new THREE.BoxGeometry(direction.length(), height, width),
material,
parent
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(X_AXIS, direction.normalize());
return mesh;
}
// Lighting.
scene.add(new THREE.HemisphereLight(0xe9f3ee, 0x716853, 2.0));
const sun = new THREE.DirectionalLight(0xffe6b4, 3.1);
sun.position.set(-8, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9dcbd0, 0.8);
fill.position.set(8, 6, -9);
scene.add(fill);
// Ground and compact mill platform.
const ground = addMesh(
new THREE.PlaneGeometry(45, 45),
materials.ground
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.08;
ground.castShadow = false;
const platform = addMesh(
new THREE.CylinderGeometry(3.25, 3.4, 0.18, 14),
materials.platform
);
platform.position.y = 0.0;
const lowerStep = addMesh(
new THREE.CylinderGeometry(2.95, 3.1, 0.15, 14),
materials.wallDark
);
lowerStep.position.set(0, 0.12, 0.45);
// Tower: full wall and a deliberately open cutaway version.
const fullWall = new THREE.Group();
const cutWall = new THREE.Group();
scene.add(fullWall, cutWall);
const fullShell = addMesh(
new THREE.CylinderGeometry(2.08, 2.43, 4.55, 12),
materials.wall,
fullWall
);
fullShell.position.y = 2.535;
const cutShell = addMesh(
new THREE.CylinderGeometry(
2.08,
2.43,
4.55,
12,
1,
true,
0.61,
Math.PI * 2 - 1.22
),
materials.wall,
cutWall
);
cutShell.material = materials.wall.clone();
cutShell.material.side = THREE.DoubleSide;
cutShell.position.y = 2.535;
const interiorFloor = addMesh(
new THREE.CylinderGeometry(2.35, 2.35, 0.18, 12),
materials.stone,
cutWall
);
interiorFloor.position.y = 0.27;
// Timber framing visible in the cutaway.
for (const x of [-1.62, 1.62]) {
const post = addMesh(
new THREE.BoxGeometry(0.16, 3.9, 0.16),
materials.timber,
cutWall
);
post.position.set(x, 2.2, -0.78);
}
for (const y of [1.3, 3.75]) {
const beam = addMesh(
new THREE.BoxGeometry(3.45, 0.14, 0.16),
materials.timber,
cutWall
);
beam.position.set(0, y, -0.78);
}
// A few inset windows on the intact facade.
const windowMaterial = standard(0x34433f, {
roughness: 0.48,
emissive: 0x17211e,
emissiveIntensity: 0.12
});
const backWindow = addMesh(
new THREE.BoxGeometry(0.58, 0.88, 0.1),
windowMaterial,
fullWall
);
backWindow.position.set(0, 3.55, -2.08);
for (const angle of [-0.85, 0.85]) {
const x = Math.sin(angle) * 2.14;
const z = Math.cos(angle) * 2.14;
const sideWindow = addMesh(
new THREE.BoxGeometry(0.55, 0.78, 0.1),
windowMaterial,
fullWall
);
sideWindow.position.set(x, 3.45, z);
sideWindow.rotation.y = angle;
}
// Rotating cap and roof.
const capPivot = new THREE.Group();
capPivot.position.y = 4.95;
scene.add(capPivot);
const capDeck = addMesh(
new THREE.CylinderGeometry(1.65, 1.65, 0.18, 12),
materials.timberLight,
capPivot
);
capDeck.position.y = 0.03;
const roof = addMesh(
new THREE.CylinderGeometry(0, 1.55, 1.25, 10),
materials.roof,
capPivot
);
roof.position.y = 0.72;
const roofBand = addMesh(
new THREE.CylinderGeometry(1.48, 1.58, 0.12, 10),
materials.roofTrim,
capPivot
);
roofBand.position.y = 0.13;
const finial = addMesh(
new THREE.ConeGeometry(0.14, 0.48, 6),
materials.brass,
capPivot
);
finial.position.y = 1.55;
// Main windshaft.
const windshaft = cylinderBetween(
new THREE.Vector3(0, 2.62, 0),
new THREE.Vector3(0, 6.04, 0),
0.085,
materials.brass
);
// Four low-poly lattice sails.
const rotor = new THREE.Group();
rotor.position.y = 1.15;
capPivot.add(rotor);
const hub = addMesh(
new THREE.CylinderGeometry(0.27, 0.27, 0.46, 10),
materials.iron,
rotor
);
hub.rotation.x = Math.PI / 2;
for (let i = 0; i < 4; i++) {
const arm = new THREE.Group();
arm.rotation.z = Math.PI / 4 + i * Math.PI / 2;
rotor.add(arm);
const spar = addMesh(
new THREE.BoxGeometry(3.3, 0.11, 0.13),
materials.timber,
arm
);
spar.position.x = 1.65;
const outerRail = addMesh(
new THREE.BoxGeometry(0.1, 0.78, 0.13),
materials.timberLight,
arm
);
outerRail.position.set(3.18, 0, 0);
const innerRail = addMesh(
new THREE.BoxGeometry(0.08, 0.78, 0.11),
materials.timber,
arm
);
innerRail.position.set(0.64, 0, 0);
const cloth = addMesh(
new THREE.PlaneGeometry(2.47, 0.67, 4, 1),
i % 2 ? materials.sail : materials.sailShade,
arm
);
cloth.position.set(1.91, 0, -0.075);
for (const x of [1.05, 1.65, 2.25, 2.85]) {
const rib = addMesh(
new THREE.BoxGeometry(0.055, 0.76, 0.08),
materials.timberLight,
arm
);
rib.position.set(x, 0, 0.015);
}
const diagonal = addMesh(
new THREE.BoxGeometry(2.6, 0.045, 0.07),
materials.timber,
arm
);
diagonal.position.set(1.9, 0, 0.04);
diagonal.rotation.z = 0.16;
}
// Horizontal crown wheel on the lower end of the windshaft.
const crownWheel = new THREE.Group();
crownWheel.position.set(0, 2.92, 0);
scene.add(crownWheel);
const crownDisk = addMesh(
new THREE.CylinderGeometry(0.61, 0.61, 0.13, 12),
materials.iron,
crownWheel
);
for (let i = 0; i < 16; i++) {
const a = (i / 16) * Math.PI * 2;
const tooth = addMesh(
new THREE.BoxGeometry(0.2, 0.12, 0.15),
materials.brass,
crownWheel
);
tooth.position.set(Math.cos(a) * 0.67, 0, Math.sin(a) * 0.67);
tooth.rotation.y = -a;
}
function makeVerticalGear(radius, teeth, thickness, material) {
const group = new THREE.Group();
const disk = addMesh(
new THREE.CylinderGeometry(radius * 0.7, radius * 0.7, thickness, 12),
material,
group
);
disk.rotation.x = Math.PI / 2;
for (let i = 0; i < teeth; i++) {
const a = (i / teeth) * Math.PI * 2;
const tooth = addMesh(
new THREE.BoxGeometry(radius * 0.25, radius * 0.2, thickness),
material,
group
);
tooth.position.set(
Math.cos(a) * radius * 0.79,
Math.sin(a) * radius * 0.79,
0
);
tooth.rotation.z = a;
}
const hub = addMesh(
new THREE.CylinderGeometry(radius * 0.19, radius * 0.19, thickness * 1.4, 8),
materials.brass,
group
);
hub.rotation.x = Math.PI / 2;
return group;
}
const gearA = makeVerticalGear(0.57, 14, 0.17, materials.iron);
gearA.position.set(0.08, 2.65, 0.28);
scene.add(gearA);
const gearB = makeVerticalGear(0.43, 12, 0.16, materials.brass);
gearB.position.set(-0.63, 2.42, 0.29);
scene.add(gearB);
cylinderBetween(
new THREE.Vector3(0, 2.72, 0),
new THREE.Vector3(0.08, 2.65, 0.28),
0.09,
materials.iron
);
// Millstones.
const stoneX = -0.82;
const stoneZ = 0.35;
const bedStone = addMesh(
new THREE.CylinderGeometry(1.02, 1.08, 0.3, 12),
materials.stone,
scene
);
bedStone.position.set(stoneX, 0.49, stoneZ);
const eye = addMesh(
new THREE.CylinderGeometry(0.19, 0.19, 0.04, 12),
materials.iron,
scene
);
eye.position.set(stoneX, 0.66, stoneZ);
const runner = new THREE.Group();
runner.position.set(stoneX, 0, stoneZ);
scene.add(runner);
const runnerStone = addMesh(
new THREE.CylinderGeometry(0.86, 0.91, 0.27, 12),
materials.stoneLight,
runner
);
runnerStone.position.y = 0.83;
for (let i = 0; i < 10; i++) {
const a = (i / 10) * Math.PI * 2;
const furrow = addMesh(
new THREE.BoxGeometry(0.62, 0.025, 0.045),
materials.stone,
runner
);
furrow.position.set(Math.cos(a) * 0.39, 0.975, Math.sin(a) * 0.39);
furrow.rotation.y = -a;
}
const stoneCap = addMesh(
new THREE.CylinderGeometry(0.16, 0.22, 0.22, 8),
materials.brass,
runner
);
stoneCap.position.y = 1.04;
const stoneSpindle = cylinderBetween(
new THREE.Vector3(stoneX, 0.55, stoneZ),
new THREE.Vector3(stoneX, 2.25, stoneZ),
0.055,
materials.brass
);
// Hopper and grain eye.
const hopper = addMesh(
new THREE.CylinderGeometry(0.58, 0.13, 0.58, 8),
materials.timberLight
);
hopper.position.set(stoneX, 1.91, stoneZ);
const hopperBand = addMesh(
new THREE.TorusGeometry(0.58, 0.045, 4, 8),
materials.timber
);
hopperBand.position.set(stoneX, 2.2, stoneZ);
hopperBand.rotation.x = Math.PI / 2;
const grainMound = addMesh(
new THREE.CylinderGeometry(0.51, 0.51, 0.1, 10),
materials.grain
);
grainMound.position.set(stoneX, 2.18, stoneZ);
// Grain elevator outside the tower.
const elevator = new THREE.Group();
elevator.position.set(-3.05, 0, 1.3);
scene.add(elevator);
for (const x of [-0.24, 0.24]) {
const rail = addMesh(
new THREE.BoxGeometry(0.075, 2.7, 0.08),
materials.timber,
elevator
);
rail.position.set(x, 1.55, 0);
}
const elevatorTop = addMesh(
new THREE.CylinderGeometry(0.28, 0.28, 0.12, 10),
materials.iron,
elevator
);
elevatorTop.position.y = 2.87;
const elevatorBottom = elevatorTop.clone();
elevatorBottom.position.y = 0.32;
elevator.add(elevatorBottom);
const buckets = [];
for (let i = 0; i < 8; i++) {
const bucket = new THREE.Group();
const base = addMesh(
new THREE.BoxGeometry(0.34, 0.09, 0.29),
materials.timberLight,
bucket
);
const back = addMesh(
new THREE.BoxGeometry(0.34, 0.2, 0.055),
materials.timber,
bucket
);
back.position.z = 0.12;
elevator.add(bucket);
buckets.push({
group: bucket,
phase: i / 8,
side: i % 2 ? 1 : -1
});
}
boxBetween(
new THREE.Vector3(-2.85, 2.83, 1.3),
new THREE.Vector3(-1.08, 2.29, 0.54),
0.35,
0.09,
materials.timberLight
);
// Flour trough from the stones to the output sacks.
boxBetween(
new THREE.Vector3(-0.67, 0.48, 0.7),
new THREE.Vector3(2.35, 0.28, 1.67),
0.45,
0.08,
materials.timberLight
);
function createSack(x, z, flour = false, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.16, z);
group.scale.setScalar(scale);
const body = addMesh(
new THREE.IcosahedronGeometry(0.4, 1),
flour ? materials.flourSack : materials.sack,
group
);
body.scale.set(0.86, 1.2, 0.78);
body.position.y = 0.36;
const neck = addMesh(
new THREE.CylinderGeometry(0.1, 0.16, 0.19, 7),
flour ? materials.flourSack : materials.sack,
group
);
neck.position.y = 0.78;
const tie = addMesh(
new THREE.TorusGeometry(0.12, 0.025, 4, 8),
materials.timber,
group
);
tie.position.y = 0.76;
tie.rotation.x = Math.PI / 2;
scene.add(group);
return group;
}
createSack(-3.7, 1.55, false, 1.0);
createSack(-3.35, 1.85, false, 0.86);
createSack(-3.95, 2.05, false, 0.78);
createSack(2.45, 1.82, true, 1.0);
createSack(2.86, 1.64, true, 0.86);
createSack(2.72, 2.18, true, 0.76);
// A small pile of wheat beside the grain sacks.
for (let i = 0; i < 13; i++) {
const a = i * 2.399;
const radius = 0.16 + (i % 4) * 0.08;
const stalk = addMesh(
new THREE.CylinderGeometry(0.012, 0.016, 0.34, 5),
materials.grain
);
stalk.position.set(
-4.24 + Math.cos(a) * radius,
0.24,
2.26 + Math.sin(a) * radius
);
stalk.rotation.z = Math.sin(a) * 0.25;
stalk.rotation.x = Math.cos(a) * 0.25;
}
// Low-poly worker for scale.
const worker = new THREE.Group();
worker.position.set(-1.95, 0.17, 2.6);
worker.rotation.y = -0.45;
const body = addMesh(
new THREE.CylinderGeometry(0.19, 0.25, 0.58, 6),
materials.shirt,
worker
);
body.position.y = 0.85;
const head = addMesh(
new THREE.IcosahedronGeometry(0.16, 1),
materials.skin,
worker
);
head.position.y = 1.28;
const hat = addMesh(
new THREE.CylinderGeometry(0.27, 0.27, 0.055, 8),
materials.timberLight,
worker
);
hat.position.y = 1.39;
const hatTop = addMesh(
new THREE.CylinderGeometry(0.14, 0.18, 0.16, 8),
materials.timberLight,
worker
);
hatTop.position.y = 1.49;
for (const x of [-0.11, 0.11]) {
const leg = addMesh(
new THREE.BoxGeometry(0.13, 0.57, 0.14),
materials.trousers,
worker
);
leg.position.set(x, 0.31, 0);
}
const arm = addMesh(
new THREE.BoxGeometry(0.12, 0.48, 0.12),
materials.shirt,
worker
);
arm.position.set(0.27, 0.88, 0);
arm.rotation.z = -0.35;
scene.add(worker);
// Sparse scenery.
const tree = new THREE.Group();
tree.position.set(5.1, 0, -3.3);
scene.add(tree);
const trunk = addMesh(
new THREE.CylinderGeometry(0.14, 0.2, 2.4, 7),
materials.timber,
tree
);
trunk.position.y = 1.2;
const crown1 = addMesh(
new THREE.IcosahedronGeometry(1.25, 0),
materials.leaf,
tree
);
crown1.position.y = 2.55;
crown1.scale.set(1, 1.15, 0.95);
const crown2 = addMesh(
new THREE.IcosahedronGeometry(0.85, 0),
materials.leafLight,
tree
);
crown2.position.set(0.55, 2.95, 0.1);
for (let i = 0; i < 9; i++) {
const fencePost = addMesh(
new THREE.BoxGeometry(0.12, 0.85, 0.12),
materials.timber
);
fencePost.position.set(-4.7 + i * 1.05, 0.33, -3.5);
}
const fenceRail = addMesh(
new THREE.BoxGeometry(8.6, 0.1, 0.1),
materials.timber
);
fenceRail.position.set(-0.35, 0.52, -3.5);
// ---------------------------------------------------------
// Continuous energy and material paths.
// ---------------------------------------------------------
const flowGroup = new THREE.Group();
scene.add(flowGroup);
function createFlow(points, color, particleCount, particleSize, speed) {
const curve = new THREE.CatmullRomCurve3(
points.map((p) => new THREE.Vector3(...p)),
false,
"catmullrom",
0.32
);
const tubeMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.42,
depthTest: false,
depthWrite: false
});
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 80, 0.024, 6, false),
tubeMaterial
);
tube.renderOrder = 8;
flowGroup.add(tube);
const particleMaterial = new THREE.MeshBasicMaterial({
color,
depthTest: false,
depthWrite: false
});
const particles = [];
for (let i = 0; i < particleCount; i++) {
const particle = new THREE.Mesh(
new THREE.SphereGeometry(particleSize, 6, 4),
particleMaterial
);
particle.renderOrder = 9;
flowGroup.add(particle);
particles.push(particle);
}
return { curve, particles, speed, offset: 0 };
}
const energyFlow = createFlow(
[
[0, 6.1, 0],
[0, 5.35, 0],
[0, 4.45, 0],
[0, 3.15, 0],
[0.04, 2.83, 0.2],
[-0.48, 2.56, 0.29],
[-0.82, 1.95, 0.35],
[-0.82, 0.97, 0.35]
],
0xffbd43,
15,
0.065,
0.12
);
const grainFlow = createFlow(
[
[-3.75, 0.65, 1.58],
[-3.05, 0.75, 1.3],
[-3.05, 1.55, 1.3],
[-3.05, 2.72, 1.3],
[-2.45, 2.66, 1.03],
[-1.42, 2.42, 0.69],
[-0.82, 2.19, 0.35],
[-0.82, 1.56, 0.35],
[-0.82, 0.98, 0.35]
],
0xd79a2e,
18,
0.047,
0.075
);
const flourFlow = createFlow(
[
[-0.82, 0.86, 0.35],
[-0.58, 0.57, 0.62],
[0.1, 0.46, 0.98],
[1.1, 0.36, 1.34],
[2.02, 0.3, 1.58],
[2.47, 0.62, 1.82]
],
0xffefbf,
16,
0.043,
0.095
);
const flows = [energyFlow, grainFlow, flourFlow];
const flowPoint = new THREE.Vector3();
function updateFlow(flow, time) {
flow.particles.forEach((particle, index) => {
const t =
(index / flow.particles.length + time * flow.speed) % 1;
flow.curve.getPointAt(t, flowPoint);
particle.position.copy(flowPoint);
});
}
// Wind stream arrows.
const windGroup = new THREE.Group();
scene.add(windGroup);
const windArrows = [];
const windArrowMaterial = new THREE.MeshBasicMaterial({
color: 0x77cbd2,
transparent: true,
opacity: 0.68,
depthWrite: false
});
for (let i = 0; i < 24; i++) {
const arrow = new THREE.Group();
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.012, 0.012, 0.45, 5),
windArrowMaterial
);
stem.position.y = -0.2;
arrow.add(stem);
const tip = new THREE.Mesh(
new THREE.ConeGeometry(0.065, 0.19, 5),
windArrowMaterial
);
tip.position.y = 0.08;
arrow.add(tip);
windGroup.add(arrow);
windArrows.push({
group: arrow,
phase: i / 24,
lane: ((i * 17) % 11 - 5) * 0.23,
height: 4.6 + ((i * 7) % 8) * 0.34
});
}
// Projected HTML labels.
const labelDefinitions = [
{
text: "04 · Wind-sails",
position: new THREE.Vector3(2.35, 6.75, 0),
color: "#73c8cf"
},
{
text: "03 · Windshaft",
position: new THREE.Vector3(0.25, 4.3, 0.1),
color: "#f4b83f"
},
{
text: "Drive train",
position: new THREE.Vector3(0.55, 2.65, 0.38),
color: "#f4b83f"
},
{
text: "02 · Millstones",
position: new THREE.Vector3(-1.7, 0.9, 0.48),
color: "#8a8d82"
},
{
text: "01 · Grain in",
position: new THREE.Vector3(-3.15, 1.1, 1.45),
color: "#ce922f"
},
{
text: "05 · Flour out",
position: new THREE.Vector3(2.65, 0.72, 1.75),
color: "#d8c798"
}
];
const labelElements = labelDefinitions.map((definition) => {
const element = document.createElement("div");
element.className = "scene-label";
element.textContent = definition.text;
element.style.setProperty("--dot", definition.color);
document.getElementById("labels").appendChild(element);
return { element, position: definition.position };
});
// ---------------------------------------------------------
// Direct camera controls — no external controls addon.
// ---------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 3.05, 0),
radius: 15,
theta: 0.58,
phi: 1.18
};
function updateCamera() {
const horizontal = Math.sin(cameraState.phi) * cameraState.radius;
camera.position.set(
cameraState.target.x +
Math.sin(cameraState.theta) * horizontal,
cameraState.target.y +
Math.cos(cameraState.phi) * cameraState.radius,
cameraState.target.z +
Math.cos(cameraState.theta) * horizontal
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.radius = 15;
cameraState.theta = 0.58;
cameraState.phi = 1.18;
cameraState.target.set(0, 3.05, 0);
document.getElementById("camera-range").value = 15;
document.getElementById("camera-output").textContent = "Overview";
updateCamera();
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
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;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.005,
0.62,
1.43
);
updateCamera();
});
function stopDragging() {
dragging = false;
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"pointerleave",
() => {
if (!dragging) return;
dragging = false;
}
);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
8,
22
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
// Interface state.
const ui = {
wind: 35,
cap: 35,
targetCap: THREE.MathUtils.degToRad(35),
currentCap: THREE.MathUtils.degToRad(35),
speed: 1,
paused: false,
autoTrim: false
};
const windRange = document.getElementById("wind-range");
const capRange = document.getElementById("cap-range");
const speedRange = document.getElementById("speed-range");
const cameraRange = document.getElementById("camera-range");
const autoToggle = document.getElementById("auto-toggle");
windRange.addEventListener("input", () => {
ui.wind = Number(windRange.value);
if (ui.autoTrim) {
ui.targetCap = THREE.MathUtils.degToRad(ui.wind);
}
});
capRange.addEventListener("input", () => {
ui.autoTrim = false;
autoToggle.checked = false;
ui.cap = Number(capRange.value);
ui.targetCap = THREE.MathUtils.degToRad(ui.cap);
});
autoToggle.addEventListener("change", () => {
ui.autoTrim = autoToggle.checked;
if (ui.autoTrim) {
ui.targetCap = THREE.MathUtils.degToRad(ui.wind);
}
});
speedRange.addEventListener("input", () => {
ui.speed = Number(speedRange.value);
document.getElementById("speed-output").textContent =
`${ui.speed.toFixed(2)}×`;
});
cameraRange.addEventListener("input", () => {
cameraState.radius = Number(cameraRange.value);
document.getElementById("camera-output").textContent =
cameraState.radius < 11
? "Close"
: cameraState.radius > 18
? "Wide"
: "Overview";
updateCamera();
});
const cutawayToggle = document.getElementById("cutaway-toggle");
const updateCutaway = () => {
cutWall.visible = cutawayToggle.checked;
fullWall.visible = !cutawayToggle.checked;
};
cutawayToggle.addEventListener("change", updateCutaway);
updateCutaway();
document.getElementById("flow-toggle").addEventListener("change", (e) => {
flowGroup.visible = e.target.checked;
});
document.getElementById("label-toggle").addEventListener("change", (e) => {
labelElements.forEach(({ element }) => {
element.style.display = e.target.checked ? "flex" : "none";
});
});
document.getElementById("trim-button").addEventListener("click", () => {
ui.targetCap = THREE.MathUtils.degToRad(ui.wind);
});
const pauseButton = document.getElementById("pause-button");
pauseButton.addEventListener("click", () => {
ui.paused = !ui.paused;
pauseButton.textContent = ui.paused ? "Resume" : "Pause";
});
document.getElementById("reset-button").addEventListener("click", resetCamera);
// Animation.
const clock = new THREE.Clock();
let simulationTime = 0;
const projected = new THREE.Vector3();
const windDirection = new THREE.Vector3();
const windSide = new THREE.Vector3();
function shortestAngle(from, to) {
return Math.atan2(Math.sin(to - from), Math.cos(to - from));
}
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const animationDt = ui.paused ? 0 : dt * ui.speed;
simulationTime += animationDt;
if (ui.autoTrim) {
ui.targetCap = THREE.MathUtils.degToRad(ui.wind);
}
ui.currentCap +=
shortestAngle(ui.currentCap, ui.targetCap) *
Math.min(1, dt * 3.2);
capPivot.rotation.y = -ui.currentCap;
const bearingDelta = shortestAngle(
THREE.MathUtils.degToRad(ui.wind),
ui.currentCap
);
const alignment = Math.abs(Math.cos(bearingDelta));
const power = 0.12 + alignment * 0.88;
rotor.rotation.z -= animationDt * (0.28 + power * 0.82);
crownWheel.rotation.y -= animationDt * power * 1.55;
gearA.rotation.z -= animationDt * power * 1.7;
gearB.rotation.z += animationDt * power * 2.2;
runner.rotation.y -= animationDt * power * 2.5;
flows.forEach((flow) => updateFlow(flow, simulationTime));
buckets.forEach((bucket) => {
const cycle = (bucket.phase + simulationTime * 0.095) % 1;
const up = bucket.side < 0;
bucket.group.position.set(
0,
up
? 0.4 + cycle * 2.28
: 2.68 - cycle * 2.28,
bucket.side * 0.17
);
bucket.group.rotation.z = up ? 0 : Math.PI;
});
const windRadians = THREE.MathUtils.degToRad(ui.wind);
windDirection.set(
Math.sin(windRadians),
0,
-Math.cos(windRadians)
);
windSide.crossVectors(windDirection, UP).normalize();
windArrows.forEach((arrow) => {
const travel = (arrow.phase + simulationTime * 0.055) % 1;
const distance = -10 + travel * 20;
arrow.group.position.copy(windDirection).multiplyScalar(distance);
arrow.group.position.addScaledVector(windSide, arrow.lane);
arrow.group.position.y = arrow.height;
arrow.group.quaternion.setFromUnitVectors(UP, windDirection);
});
// UI readouts.
const windDegrees = Math.round(ui.wind) % 360;
const capDegrees = Math.round(
THREE.MathUtils.radToDeg(ui.currentCap)
) % 360;
document.getElementById("wind-output").textContent =
`${String(windDegrees).padStart(3, "0")}°`;
document.getElementById("cap-output").textContent =
`${String(capDegrees).padStart(3, "0")}°`;
document.getElementById("power-value").textContent =
`${Math.round(power * 100)}%`;
if (document.activeElement !== capRange) {
capRange.value = capDegrees;
}
document.getElementById("wind-arrow").style.transform =
`rotate(${windDegrees}deg)`;
// Project labels into screen space.
labelElements.forEach(({ element, position }) => {
projected.copy(position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.1 &&
projected.x < 1.1 &&
projected.y > -1.1 &&
projected.y < 1.1;
element.style.opacity = visible ? "1" : "0";
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
element.style.transform =
`translate3d(${x}px, ${y}px, 0) translate(-50%, -50%)`;
});
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
updateCamera();
animate();
</script>
</body>
</html>
```