Prompt specification
Build or customize the Three.js 3D scene "Village mill and upstream irrigation branches" 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: Village mill and upstream irrigation branches
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/village-mill-and-upstream-irrigation-branches-x2379
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Build a compact medieval-inspired village with mill, fields, and branching water channels. Show competing water uses as an illustrative situation rather than a universal historical arrangement.
Working Three.js Starter (village-mill-and-upstream-irrigation-branches-x2379):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Water at the Village Edge</title>
<style>
:root {
--ink: #243129;
--paper: rgba(248, 243, 228, 0.94);
--paper-solid: #f8f3e4;
--line: rgba(54, 68, 55, 0.19);
--mill: #bd6b3f;
--fields: #8b9b42;
--village: #438da0;
--shadow: 0 12px 35px rgba(30, 39, 31, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c8d7cf;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.panel {
position: absolute;
z-index: 10;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.58);
box-shadow: var(--shadow);
backdrop-filter: blur(9px);
-webkit-backdrop-filter: blur(9px);
}
#intro {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 20px 22px 19px;
border-radius: 5px 18px 18px 18px;
}
.eyebrow {
margin-bottom: 7px;
color: #6f795e;
font: 700 10px/1.2 Arial, sans-serif;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0 0 8px;
font-size: clamp(25px, 3vw, 38px);
line-height: 1.02;
font-weight: 500;
}
#intro p {
margin: 0;
color: #526055;
font: 14px/1.48 Arial, sans-serif;
}
.disclaimer {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 13px;
padding: 6px 9px;
border-radius: 999px;
background: #e7e0ca;
color: #625f49;
font: 700 10px/1.2 Arial, sans-serif;
letter-spacing: 0.04em;
}
.disclaimer::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: #ba754e;
}
#allocation-panel {
right: 22px;
bottom: 22px;
width: min(410px, calc(100vw - 44px));
padding: 17px 18px 16px;
border-radius: 18px 18px 5px 18px;
}
.panel-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
}
.panel-heading h2 {
margin: 0;
font-size: 19px;
font-weight: 500;
}
.panel-heading span {
color: #778071;
font: 10px/1 Arial, sans-serif;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.allocation-bar {
display: flex;
width: 100%;
height: 13px;
overflow: hidden;
margin: 4px 0 13px;
border-radius: 999px;
background: #ddd8c7;
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.12);
}
.allocation-bar > div {
transition: width 500ms cubic-bezier(.2,.8,.2,1);
}
#bar-mill { background: var(--mill); }
#bar-fields { background: var(--fields); }
#bar-village { background: var(--village); }
.use-list {
display: grid;
gap: 8px;
margin-bottom: 13px;
}
.use-row {
display: grid;
grid-template-columns: 12px 1fr 38px;
align-items: center;
gap: 8px;
font: 12px/1.2 Arial, sans-serif;
}
.use-row strong {
font-weight: 600;
}
.use-dot {
width: 9px;
height: 9px;
border-radius: 50%;
}
.use-row .dot-mill { background: var(--mill); }
.use-row .dot-fields { background: var(--fields); }
.use-row .dot-village { background: var(--village); }
.use-row output {
text-align: right;
font-variant-numeric: tabular-nums;
color: #596257;
}
.scenario-buttons {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 6px;
}
.scenario-buttons button {
min-height: 36px;
padding: 7px 5px;
border: 1px solid var(--line);
border-radius: 7px;
background: rgba(255, 255, 255, 0.5);
color: #4e584c;
cursor: pointer;
font: 600 10px/1.15 Arial, sans-serif;
transition:
transform 120ms ease,
background 160ms ease,
color 160ms ease;
}
.scenario-buttons button:hover {
transform: translateY(-1px);
background: #fffdf7;
}
.scenario-buttons button.active {
background: #33453a;
border-color: #33453a;
color: #fffaf0;
}
#response {
margin: 11px 1px 0;
color: #687164;
font: italic 11px/1.35 Georgia, serif;
}
#hint {
position: absolute;
z-index: 5;
left: 22px;
bottom: 22px;
padding: 8px 11px;
border-radius: 999px;
background: rgba(37, 49, 42, 0.74);
color: #f6f0df;
font: 10px/1 Arial, sans-serif;
letter-spacing: 0.04em;
pointer-events: none;
}
#labels {
position: absolute;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
padding: 5px 8px;
border: 1px solid rgba(255,255,255,.6);
border-radius: 4px;
background: rgba(248, 243, 228, .87);
box-shadow: 0 4px 14px rgba(25, 35, 28, .13);
color: #38443a;
white-space: nowrap;
font: 700 9px/1 Arial, sans-serif;
letter-spacing: .11em;
text-transform: uppercase;
transform: translate(-50%, -100%);
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 15px;
background: rgba(56, 68, 58, .48);
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #e7dfc9;
color: #4d5b4e;
font: 14px Arial, sans-serif;
letter-spacing: .08em;
}
@media (max-width: 720px) {
#intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
#intro p {
display: none;
}
.disclaimer {
margin-top: 10px;
}
#allocation-panel {
right: 12px;
bottom: 12px;
width: calc(100vw - 24px);
padding: 13px 14px;
}
#hint,
.world-label {
display: none;
}
.use-list {
gap: 5px;
}
}
</style>
</head>
<body>
<div id="loading">Building the village…</div>
<div id="labels"></div>
<section id="intro" class="panel">
<div class="eyebrow">An illustrative water-allocation scene</div>
<h1>Water at the<br />Village Edge</h1>
<p>
Imagine a dry year in one compact, medieval-inspired village. A shared
headworks divides a limited stream among a mill, two fields, and water
for the village and its animals.
</p>
<div class="disclaimer">Fictional scenario — not a historical reconstruction</div>
</section>
<section id="allocation-panel" class="panel">
<div class="panel-heading">
<h2>Choose a priority</h2>
<span>Illustrative share</span>
</div>
<div class="allocation-bar" aria-label="Water allocation">
<div id="bar-mill"></div>
<div id="bar-fields"></div>
<div id="bar-village"></div>
</div>
<div class="use-list">
<div class="use-row">
<span class="use-dot dot-mill"></span>
<strong>Mill power</strong>
<output id="pct-mill">34%</output>
</div>
<div class="use-row">
<span class="use-dot dot-fields"></span>
<strong>Field irrigation</strong>
<output id="pct-fields">33%</output>
</div>
<div class="use-row">
<span class="use-dot dot-village"></span>
<strong>Village and livestock</strong>
<output id="pct-village">33%</output>
</div>
</div>
<div class="scenario-buttons">
<button data-scenario="balanced" class="active">Even split</button>
<button data-scenario="mill">Mill first</button>
<button data-scenario="fields">Fields first</button>
<button data-scenario="village">Village first</button>
</div>
<p id="response">
The gate positions, branch flows, mill wheel, and communal trough respond
to this fictional priority setting.
</p>
</section>
<div id="hint">Drag to orbit · Scroll or pinch to zoom · Double-click to reset</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene, camera, and lights
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc9d9d2);
scene.fog = new THREE.Fog(0xc9d9d2, 27, 49);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xeaf3e7, 0x72634f, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe3b0, 3.1);
sun.position.set(-9, 17, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 42;
sun.shadow.bias = -0.00035;
scene.add(sun);
const palette = {
grass: 0x81965d,
grassDark: 0x657c4d,
earth: 0x78664e,
soil: 0x72543b,
soilLight: 0x96714b,
stone: 0x8d9186,
stoneDark: 0x646c64,
plaster: 0xd9cba7,
plasterPink: 0xd6bba1,
plasterPale: 0xe3d9bb,
wood: 0x60462f,
woodLight: 0x8b6842,
roof: 0x8d4935,
roofDark: 0x65372f,
roofGray: 0x626d67,
water: 0x4f9eaa,
waterDeep: 0x347d8b,
crop: 0xc7a64d,
cropGreen: 0x839347,
leaf: 0x4f7049,
leafLight: 0x688553
};
const standard = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
flatShading: true,
...options
});
const materials = {
grass: standard(palette.grass),
grassDark: standard(palette.grassDark),
earth: standard(palette.earth),
soil: standard(palette.soil),
soilLight: standard(palette.soilLight),
stone: standard(palette.stone),
stoneDark: standard(palette.stoneDark),
wood: standard(palette.wood),
woodLight: standard(palette.woodLight),
roof: standard(palette.roof),
roofDark: standard(palette.roofDark),
roofGray: standard(palette.roofGray),
plaster: standard(palette.plaster),
plasterPink: standard(palette.plasterPink),
plasterPale: standard(palette.plasterPale),
leaf: standard(palette.leaf),
leafLight: standard(palette.leafLight),
crop: standard(palette.crop),
cropGreen: standard(palette.cropGreen),
water: standard(palette.water, {
roughness: 0.2,
metalness: 0.05,
transparent: true,
opacity: 0.9,
side: THREE.DoubleSide
}),
waterDeep: standard(palette.waterDeep, {
roughness: 0.25,
transparent: true,
opacity: 0.92,
side: THREE.DoubleSide
})
};
const world = new THREE.Group();
scene.add(world);
function mesh(geometry, material, parent = world) {
const object = new THREE.Mesh(geometry, material);
object.castShadow = material !== materials.water;
object.receiveShadow = true;
parent.add(object);
return object;
}
function box(w, h, d, material, x = 0, y = 0, z = 0, parent = world) {
const object = mesh(new THREE.BoxGeometry(w, h, d), material, parent);
object.position.set(x, y, z);
return object;
}
function cylinder(
topRadius,
bottomRadius,
height,
segments,
material,
x = 0,
y = 0,
z = 0,
parent = world
) {
const object = mesh(
new THREE.CylinderGeometry(topRadius, bottomRadius, height, segments),
material,
parent
);
object.position.set(x, y, z);
return object;
}
let seed = 7319;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
// ------------------------------------------------------------
// Ribbon geometry used for paths and channels
// ------------------------------------------------------------
function ribbonData(curve, width, material, y) {
const segments = Math.max(24, Math.ceil(curve.getLength() * 15));
const count = (segments + 1) * 2;
const centers = new Float32Array(count * 3);
const normals = new Float32Array(count * 3);
const sides = new Float32Array(count);
const positions = new Float32Array(count * 3);
const indices = [];
for (let i = 0; i <= segments; i++) {
const t = i / segments;
const p = curve.getPointAt(t);
const tangent = curve.getTangentAt(t);
const normal = new THREE.Vector3(-tangent.z, 0, tangent.x).normalize();
for (let side = 0; side < 2; side++) {
const vertex = i * 2 + side;
centers[vertex * 3] = p.x;
centers[vertex * 3 + 1] = y;
centers[vertex * 3 + 2] = p.z;
normals[vertex * 3] = normal.x;
normals[vertex * 3 + 1] = 0;
normals[vertex * 3 + 2] = normal.z;
sides[vertex] = side === 0 ? -1 : 1;
}
if (i < segments) {
const a = i * 2;
const b = (i + 1) * 2;
indices.push(a, a + 1, b, a + 1, b + 1, b);
}
}
const geometry = new THREE.BufferGeometry();
const attribute = new THREE.BufferAttribute(positions, 3);
attribute.setUsage(THREE.DynamicDrawUsage);
geometry.setAttribute("position", attribute);
geometry.setIndex(indices);
function setWidth(nextWidth) {
for (let vertex = 0; vertex < count; vertex++) {
const offset = (nextWidth * 0.5) * sides[vertex];
positions[vertex * 3] =
centers[vertex * 3] + normals[vertex * 3] * offset;
positions[vertex * 3 + 1] = centers[vertex * 3 + 1];
positions[vertex * 3 + 2] =
centers[vertex * 3 + 2] + normals[vertex * 3 + 2] * offset;
}
attribute.needsUpdate = true;
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
}
setWidth(width);
const object = mesh(geometry, material);
return { object, geometry, setWidth };
}
function curveFrom(points) {
return new THREE.CatmullRomCurve3(
points.map(([x, z]) => new THREE.Vector3(x, 0, z)),
false,
"catmullrom",
0.42
);
}
// ------------------------------------------------------------
// Terrain, paths, palisade, and scattered landscape details
// ------------------------------------------------------------
const island = mesh(
new THREE.CylinderGeometry(12, 12.7, 1.05, 16),
[materials.earth, materials.grass, materials.earth]
);
island.position.y = -0.525;
const laneMaterial = standard(0xb7a27c, { roughness: 1 });
const laneCurves = [
[
[-9.5, 0.9],
[-7, 1.9],
[-4.8, 2.1],
[-2.5, 2.8],
[0, 3.1],
[3.3, 4.3],
[6.4, 5.2],
[8.3, 3.6]
],
[
[-7.5, 2],
[-6.7, -0.5],
[-5.5, -2.3],
[-3.7, -4],
[-1.7, -5.5]
],
[
[-3.5, 2.8],
[-2.2, 4.4],
[-1, 6.1]
]
];
laneCurves.forEach((points) => {
ribbonData(curveFrom(points), 0.66, laneMaterial, 0.018);
});
// A small palisade, with a gap where the stream enters.
for (let i = 0; i < 48; i++) {
const angle = (i / 48) * Math.PI * 2;
if (Math.abs(angle - Math.PI) < 0.16) continue;
const x = Math.cos(angle) * 11.25;
const z = Math.sin(angle) * 11.25;
cylinder(
0.13,
0.17,
1.35,
5,
materials.woodLight,
x,
0.675,
z
);
const point = mesh(
new THREE.ConeGeometry(0.17, 0.38, 5),
materials.woodLight
);
point.position.set(x, 1.53, z);
point.rotation.y = angle;
}
function addTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
world.add(group);
cylinder(0.14, 0.2, 1.3, 5, materials.wood, 0, 0.65, 0, group);
const crown = mesh(
new THREE.IcosahedronGeometry(0.95, 0),
materials.leaf,
group
);
crown.position.y = 1.65;
crown.scale.set(1, 1.15, 0.95);
const crown2 = mesh(
new THREE.IcosahedronGeometry(0.62, 0),
materials.leafLight,
group
);
crown2.position.set(0.48, 1.45, 0.08);
}
[
[-9.2, 6.8, 1.1],
[-8.7, -5.9, 1.0],
[-4.3, -8.1, 1.15],
[1.2, -8.4, 0.9],
[8.6, -6.2, 1.1],
[10.1, 0.7, 1.2],
[8.8, 7.7, 1.05],
[4.8, 9.1, 1.0],
[-0.5, 9.2, 0.8],
[-9.8, 2.3, 0.95],
[6.2, -8.5, 0.75]
].forEach(([x, z, scale]) => addTree(x, z, scale));
// ------------------------------------------------------------
// Buildings
// ------------------------------------------------------------
function addGable(group, width, depth, height, material) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[
-width / 2, 0, 0,
width / 2, 0, 0,
0, height, 0
],
3
)
);
geometry.setIndex([0, 1, 2]);
geometry.computeVertexNormals();
const gableMaterial = material.clone();
gableMaterial.side = THREE.DoubleSide;
const front = mesh(geometry, gableMaterial, group);
front.position.set(0, 0, depth / 2 + 0.005);
const back = mesh(geometry, gableMaterial, group);
back.position.set(0, 0, -depth / 2 - 0.005);
back.rotation.y = Math.PI;
}
function addRoof(group, width, depth, wallHeight, roofHeight, material) {
const slopeLength = Math.sqrt((width / 2) ** 2 + roofHeight ** 2);
const angle = Math.atan2(roofHeight, width / 2);
const roofGeometry = new THREE.BoxGeometry(
slopeLength + 0.25,
0.16,
depth + 0.35
);
const left = mesh(roofGeometry, material, group);
left.position.set(-width / 4, wallHeight + roofHeight / 2, 0);
left.rotation.z = angle;
const right = mesh(roofGeometry, material, group);
right.position.set(width / 4, wallHeight + roofHeight / 2, 0);
right.rotation.z = -angle;
}
function addCottage(x, z, rotation, roofMaterial, wallMaterial, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
group.scale.setScalar(scale);
world.add(group);
const width = 2.45;
const depth = 2.05;
const wallHeight = 1.55;
box(width + 0.18, 0.22, depth + 0.18, materials.stoneDark, 0, 0.11, 0, group);
box(width, wallHeight, depth, wallMaterial, 0, wallHeight / 2 + 0.16, 0, group);
addGable(group, width, depth, 0.82, wallMaterial);
addRoof(group, width, depth, wallHeight + 0.16, 0.82, roofMaterial);
// Exposed timber framing.
[-width / 2 + 0.08, width / 2 - 0.08].forEach((beamX) => {
box(0.12, wallHeight, 0.12, materials.wood, beamX, wallHeight / 2 + 0.18, depth / 2 + 0.04, group);
box(0.12, wallHeight, 0.12, materials.wood, beamX, wallHeight / 2 + 0.18, -depth / 2 - 0.04, group);
});
box(width, 0.13, 0.13, materials.wood, 0, 1.47, depth / 2 + 0.045, group);
box(width, 0.13, 0.13, materials.wood, 0, 0.67, depth / 2 + 0.045, group);
const diagonal = box(
0.11,
1.65,
0.11,
materials.wood,
0.34,
0.94,
depth / 2 + 0.055,
group
);
diagonal.rotation.z = -0.66;
box(0.52, 0.86, 0.08, materials.wood, -0.48, 0.59, depth / 2 + 0.075, group);
box(0.44, 0.43, 0.08, materials.stoneDark, 0.58, 1.03, depth / 2 + 0.075, group);
box(0.38, 0.36, 0.08, materials.stoneDark, -width / 2 - 0.045, 1.02, 0, group);
const windowMaterial = standard(0x675c42, {
emissive: 0x5f421e,
emissiveIntensity: 0.15
});
box(0.36, 0.31, 0.09, windowMaterial, 0.58, 1.03, depth / 2 + 0.08, group);
box(0.38, 0.85, 0.42, materials.stone, width * 0.28, 2.1, -0.37, group);
}
addCottage(-6.5, 4.25, -0.08, materials.roof, materials.plaster);
addCottage(-3.35, 6.25, 0.05, materials.roofDark, materials.plasterPale);
addCottage(-0.25, 6.55, -0.03, materials.roof, materials.plasterPink);
addCottage(3.0, 6.55, 0.05, materials.roofGray, materials.plaster);
addCottage(6.25, 4.55, -0.18, materials.roofDark, materials.plasterPink);
addCottage(-6.75, -2.35, 0.12, materials.roofGray, materials.plaster);
addCottage(-5.25, -5.35, -0.04, materials.roof, materials.plasterPale, 0.92);
// Small chapel tower.
const chapel = new THREE.Group();
chapel.position.set(-7.7, 0, 7.15);
world.add(chapel);
box(1.55, 2.65, 1.55, materials.stone, 0, 1.325, 0, chapel);
box(1.72, 0.22, 1.72, materials.stoneDark, 0, 0.15, 0, chapel);
box(0.46, 0.67, 0.08, materials.wood, 0, 1.78, 0.81, chapel);
const steeple = mesh(
new THREE.ConeGeometry(1.18, 1.25, 4),
materials.roofDark,
chapel
);
steeple.position.y = 3.22;
steeple.rotation.y = Math.PI / 4;
// Mill.
const mill = new THREE.Group();
mill.position.set(2.45, 0, 3.72);
mill.rotation.y = 0.02;
world.add(mill);
box(3.45, 0.28, 2.85, materials.stoneDark, 0, 0.14, 0, mill);
box(3.2, 2.05, 2.6, materials.plasterPale, 0, 1.27, 0, mill);
addGable(mill, 3.2, 2.6, 1.05, materials.plasterPale);
addRoof(mill, 3.2, 2.6, 2.29, 1.05, materials.roofDark);
[-1.48, 1.48].forEach((beamX) => {
box(0.17, 2, 0.17, materials.wood, beamX, 1.28, 1.34, mill);
});
box(3.12, 0.16, 0.16, materials.wood, 0, 1.98, 1.35, mill);
box(0.78, 1.1, 0.1, materials.wood, 0.15, 0.8, 1.35, mill);
box(0.52, 0.5, 0.09, materials.stoneDark, -0.9, 1.47, 1.35, mill);
const sackMaterial = standard(0xb29b6c);
const sack = mesh(
new THREE.DodecahedronGeometry(0.38, 0),
sackMaterial,
mill
);
sack.position.set(1.25, 0.52, 1.64);
sack.scale.set(0.85, 1.25, 0.85);
// Water wheel: pivot faces west, where the millrace arrives.
const millWheelPivot = new THREE.Group();
millWheelPivot.position.set(0.03, 1.33, 3.7);
millWheelPivot.rotation.y = Math.PI / 2;
world.add(millWheelPivot);
const millWheelSpinner = new THREE.Group();
millWheelPivot.add(millWheelSpinner);
const wheelRim = mesh(
new THREE.TorusGeometry(1.02, 0.13, 4, 12),
materials.wood,
millWheelSpinner
);
for (let i = 0; i < 10; i++) {
const angle = (i / 10) * Math.PI * 2;
const spoke = box(
0.11,
1.95,
0.11,
materials.woodLight,
Math.cos(angle) * 0.49,
Math.sin(angle) * 0.49,
0,
millWheelSpinner
);
spoke.rotation.z = angle - Math.PI / 2;
const paddle = box(
0.38,
0.14,
0.52,
materials.woodLight,
Math.cos(angle) * 0.96,
Math.sin(angle) * 0.96,
0,
millWheelSpinner
);
paddle.rotation.z = angle;
}
const axle = cylinder(
0.18,
0.18,
1.1,
8,
materials.wood,
0,
0,
0,
millWheelSpinner
);
axle.rotation.x = Math.PI / 2;
// ------------------------------------------------------------
// Fields
// ------------------------------------------------------------
function addField(cx, cz, width, depth, cropMaterial) {
box(width + 0.12, 0.16, depth + 0.12, materials.soil, cx, 0.08, cz);
const rows = 6;
const columns = 8;
const stalkGeometry = new THREE.ConeGeometry(0.075, 0.48, 4);
const crops = new THREE.InstancedMesh(stalkGeometry, cropMaterial, rows * columns);
crops.castShadow = true;
crops.receiveShadow = true;
const matrix = new THREE.Matrix4();
const quaternion = new THREE.Quaternion();
const scale = new THREE.Vector3();
const position = new THREE.Vector3();
let index = 0;
for (let row = 0; row < rows; row++) {
const x = cx - width / 2 + 0.3 + row * ((width - 0.6) / (rows - 1));
box(
0.065,
0.035,
depth - 0.28,
materials.soilLight,
x,
0.175,
cz
);
for (let column = 0; column < columns; column++) {
const z = cz - depth / 2 + 0.35 + column * ((depth - 0.7) / (columns - 1));
const height = 0.75 + random() * 0.55;
position.set(
x + (random() - 0.5) * 0.05,
0.16 + height * 0.24,
z + (random() - 0.5) * 0.05
);
quaternion.setFromEuler(new THREE.Euler(0, random() * Math.PI, 0));
scale.set(1, height, 1);
matrix.compose(position, quaternion, scale);
crops.setMatrixAt(index++, matrix);
}
}
world.add(crops);
// Low fence along the outer field edge.
[-1, 1].forEach((side) => {
const fenceX = cx + side * (width / 2 + 0.28);
for (let i = 0; i < 5; i++) {
const z = cz - depth / 2 + i * (depth / 4);
cylinder(
0.06,
0.08,
0.62,
5,
materials.wood,
fenceX,
0.31,
z
);
}
box(
0.07,
0.07,
depth + 0.12,
materials.wood,
fenceX,
0.45,
cz
);
});
}
addField(4.65, -0.35, 2.65, 3.9, materials.crop);
addField(7.75, -1.2, 2.65, 4.15, materials.cropGreen);
// Small irrigation laterals from the main branch into the plots.
ribbonData(
curveFrom([
[4.7, -2.62],
[4.7, -2.18],
[4.7, -1.6]
]),
0.18,
materials.water,
0.09
);
ribbonData(
curveFrom([
[7.55, -3.25],
[7.55, -2.8],
[7.55, -2.25]
]),
0.18,
materials.water,
0.09
);
// ------------------------------------------------------------
// Water network and shared headworks
// ------------------------------------------------------------
const intakeCurve = curveFrom([
[-12.0, 0.3],
[-10.2, 0.35],
[-8.0, 0.55],
[-6.0, 0.32],
[-3.5, 0.3]
]);
ribbonData(intakeCurve, 1.18, materials.earth, 0.035);
ribbonData(intakeCurve, 0.68, materials.water, 0.082);
const sourcePool = mesh(
new THREE.CircleGeometry(1.25, 16),
materials.waterDeep
);
sourcePool.rotation.x = -Math.PI / 2;
sourcePool.position.set(-11.45, 0.075, 0.3);
sourcePool.scale.x = 1.25;
// Shared wooden and stone control platform.
box(2.3, 0.22, 2.05, materials.stoneDark, -3.5, 0.11, 0.3);
box(1.55, 0.24, 1.25, materials.woodLight, -3.5, 0.31, 0.3);
const headPool = mesh(
new THREE.CircleGeometry(0.53, 10),
materials.waterDeep
);
headPool.rotation.x = -Math.PI / 2;
headPool.position.set(-3.5, 0.45, 0.3);
const allocation = {
mill: 34,
fields: 33,
village: 33
};
const branchDefinitions = [
{
id: "mill",
color: 0xbd6b3f,
points: [
[-3.5, 0.3],
[-2.8, 1.05],
[-2.0, 2.45],
[-1.0, 3.45],
[0.05, 3.7]
]
},
{
id: "fields",
color: 0x8b9b42,
points: [
[-3.5, 0.3],
[-1.55, -0.72],
[0.8, -1.35],
[3.55, -2.08],
[6.2, -2.95],
[8.85, -4.08]
]
},
{
id: "village",
color: 0x438da0,
points: [
[-3.5, 0.3],
[-4.2, -1.25],
[-4.05, -3.15],
[-2.65, -4.35],
[-0.75, -5.35]
]
}
];
const glintMaterial = standard(0xd9f4e9, {
emissive: 0x9ed9d7,
emissiveIntensity: 0.22,
transparent: true,
opacity: 0.82
});
const branches = [];
function addGate(curve, color) {
const t = 0.12;
const point = curve.getPointAt(t);
const tangent = curve.getTangentAt(t);
const group = new THREE.Group();
group.position.set(point.x, 0.03, point.z);
group.rotation.y = Math.atan2(tangent.x, tangent.z);
world.add(group);
[-0.48, 0.48].forEach((x) => {
box(0.14, 1.1, 0.18, materials.wood, x, 0.55, 0, group);
});
box(1.15, 0.15, 0.18, materials.woodLight, 0, 1.03, 0, group);
const board = box(
0.84,
0.55,
0.11,
materials.woodLight,
0,
0.48,
0,
group
);
cylinder(
0.035,
0.035,
1.2,
5,
materials.wood,
0.77,
0.6,
0,
group
);
const flag = box(
0.42,
0.24,
0.045,
standard(color),
0.98,
1.03,
0,
group
);
flag.rotation.z = -0.06;
return board;
}
branchDefinitions.forEach((definition) => {
const curve = curveFrom(definition.points);
const bank = ribbonData(curve, 1.05, materials.earth, 0.04);
const water = ribbonData(curve, 0.4, materials.water, 0.088);
const gateBoard = addGate(curve, definition.color);
const glints = [];
for (let i = 0; i < 8; i++) {
const glint = box(
0.07,
0.025,
0.32,
glintMaterial,
0,
0,
0
);
glint.castShadow = false;
glints.push(glint);
}
branches.push({
...definition,
curve,
bank,
water,
gateBoard,
glints,
flowOffset: random(),
currentWidth: 0.4
});
});
// A short tailrace below the wheel.
const tailCurve = curveFrom([
[0.05, 3.7],
[0.15, 2.75],
[0.75, 1.85],
[1.8, 1.55],
[2.55, 1.95]
]);
ribbonData(tailCurve, 0.95, materials.earth, 0.04);
ribbonData(tailCurve, 0.48, materials.water, 0.085);
// ------------------------------------------------------------
// Village water, well, livestock, and miscellaneous details
// ------------------------------------------------------------
const trough = new THREE.Group();
trough.position.set(-0.65, 0, -5.65);
world.add(trough);
box(1.95, 0.44, 0.85, materials.stone, 0, 0.22, 0, trough);
box(1.48, 0.06, 0.48, materials.water, 0, 0.46, 0, trough);
box(0.14, 0.95, 0.85, materials.stone, -0.94, 0.4, 0, trough);
box(0.14, 0.95, 0.85, materials.stone, 0.94, 0.4, 0, trough);
const troughWater = trough.children[1];
const bucket = mesh(
new THREE.CylinderGeometry(0.18, 0.14, 0.3, 7),
materials.woodLight
);
bucket.position.set(1.3, 0.15, 0.2);
// Village well.
const well = new THREE.Group();
well.position.set(-2.05, 0, 3.65);
world.add(well);
cylinder(0.55, 0.66, 0.67, 8, materials.stone, 0, 0.335, 0, well);
const wellOpening = mesh(
new THREE.CircleGeometry(0.4, 8),
materials.waterDeep,
well
);
wellOpening.rotation.x = -Math.PI / 2;
wellOpening.position.y = 0.68;
[-0.58, 0.58].forEach((x) => {
cylinder(0.07, 0.09, 1.25, 5, materials.wood, x, 1.05, 0, well);
});
box(1.4, 0.12, 0.15, materials.wood, 0, 1.61, 0, well);
function addSheep(x, z, rotation) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
world.add(group);
const body = mesh(
new THREE.IcosahedronGeometry(0.43, 0),
standard(0xe2dfcf),
group
);
body.position.y = 0.48;
body.scale.set(1.2, 0.78, 0.78);
const head = mesh(
new THREE.IcosahedronGeometry(0.21, 0),
materials.stoneDark,
group
);
head.position.set(0.44, 0.52, 0);
head.scale.set(1.2, 0.9, 0.8);
[-0.24, 0.23].forEach((legX) => {
[-0.17, 0.17].forEach((legZ) => {
cylinder(
0.035,
0.045,
0.35,
4,
materials.stoneDark,
legX,
0.19,
legZ,
group
);
});
});
}
addSheep(0.9, -6.0, -0.4);
addSheep(1.65, -6.35, 0.6);
addSheep(-1.65, -6.2, 2.4);
// Low rocks beside the channels.
function addRock(x, z, scale) {
const rock = mesh(
new THREE.DodecahedronGeometry(0.25, 0),
materials.stoneDark
);
rock.position.set(x, 0.16, z);
rock.scale.set(scale * 1.25, scale * 0.7, scale);
rock.rotation.set(random(), random() * Math.PI, random() * 0.25);
}
branches.forEach((branch) => {
for (let i = 0; i < 9; i++) {
const t = 0.15 + random() * 0.75;
const point = branch.curve.getPointAt(t);
const tangent = branch.curve.getTangentAt(t);
const normal = new THREE.Vector3(-tangent.z, 0, tangent.x).normalize();
const side = random() > 0.5 ? 1 : -1;
addRock(
point.x + normal.x * 0.68 * side,
point.z + normal.z * 0.68 * side,
0.65 + random() * 0.7
);
}
});
// A short bridge over the main intake.
box(1.3, 0.14, 1.25, materials.woodLight, -6.25, 0.22, 0.43);
[-0.55, 0.55].forEach((offset) => {
box(0.09, 0.7, 0.09, materials.wood, -6.25 + offset, 0.55, 0.83);
box(0.09, 0.7, 0.09, materials.wood, -6.25 + offset, 0.55, 0.03);
box(0.08, 0.08, 1.0, materials.wood, -6.25 + offset, 0.82, 0.43);
});
// ------------------------------------------------------------
// World labels
// ------------------------------------------------------------
const labelDefinitions = [
{ text: "Mill wheel", point: new THREE.Vector3(0.05, 3.0, 3.7) },
{ text: "Irrigation fields", point: new THREE.Vector3(6.35, 1.65, -1.2) },
{ text: "Village water", point: new THREE.Vector3(-0.65, 1.25, -5.65) },
{ text: "Shared headworks", point: new THREE.Vector3(-3.5, 1.75, 0.3) }
];
const labels = labelDefinitions.map((definition) => {
const element = document.createElement("div");
element.className = "world-label";
element.textContent = definition.text;
document.getElementById("labels").appendChild(element);
return { ...definition, element };
});
function updateLabels() {
labels.forEach((label) => {
const projected = label.point.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.display = visible ? "block" : "none";
if (visible) {
label.element.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
label.element.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
}
});
}
// ------------------------------------------------------------
// Allocation controls
// ------------------------------------------------------------
const scenarios = {
balanced: { mill: 34, fields: 33, village: 33 },
mill: { mill: 55, fields: 25, village: 20 },
fields: { mill: 20, fields: 55, village: 25 },
village: { mill: 20, fields: 25, village: 55 }
};
const responseMessages = {
balanced:
"An even fictional split keeps all three uses visible, though none receives a large surplus.",
mill:
"The mill gate opens widest and the wheel turns faster in this priority scenario.",
fields:
"The irrigation branch broadens and carries more visible flow toward the two fields.",
village:
"More water reaches the communal trough, while the mill and field channels narrow."
};
let currentScenario = "balanced";
function applyScenario(name) {
currentScenario = name;
Object.assign(allocation, scenarios[name]);
Object.keys(allocation).forEach((id) => {
const percent = allocation[id];
document.getElementById(`bar-${id}`).style.width = `${percent}%`;
document.getElementById(`pct-${id}`).value = `${percent}%`;
document.getElementById(`pct-${id}`).textContent = `${percent}%`;
});
document.querySelectorAll("[data-scenario]").forEach((button) => {
button.classList.toggle("active", button.dataset.scenario === name);
});
document.getElementById("response").textContent = responseMessages[name];
}
document.querySelectorAll("[data-scenario]").forEach((button) => {
button.addEventListener("click", () => applyScenario(button.dataset.scenario));
});
applyScenario("balanced");
// ------------------------------------------------------------
// Direct orbit controls: no examples or addons are used
// ------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 0.75, 0.7),
radius: 23.5,
theta: -0.72,
phi: 0.98,
dragging: false,
pointerX: 0,
pointerY: 0,
lastPinchDistance: 0
};
const pointers = new Map();
function updateCamera() {
controls.phi = THREE.MathUtils.clamp(controls.phi, 0.43, 1.35);
controls.radius = THREE.MathUtils.clamp(controls.radius, 12, 33);
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
camera.updateMatrixWorld();
}
function resetCamera() {
controls.radius = 23.5;
controls.theta = -0.72;
controls.phi = 0.98;
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
renderer.domElement.setPointerCapture(event.pointerId);
if (pointers.size === 1) {
controls.dragging = true;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
controls.lastPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1 && controls.dragging) {
const dx = event.clientX - controls.pointerX;
const dy = event.clientY - controls.pointerY;
controls.theta -= dx * 0.006;
controls.phi -= dy * 0.005;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
updateCamera();
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (controls.lastPinchDistance > 0) {
controls.radius *= controls.lastPinchDistance / distance;
updateCamera();
}
controls.lastPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) controls.lastPinchDistance = 0;
if (pointers.size === 0) controls.dragging = false;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("lostpointercapture", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius += event.deltaY * 0.013;
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") controls.theta -= 0.08;
if (event.key === "ArrowRight") controls.theta += 0.08;
if (event.key === "ArrowUp") controls.phi -= 0.06;
if (event.key === "ArrowDown") controls.phi += 0.06;
if (event.key === "r" || event.key === "R") resetCamera();
updateCamera();
});
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
branches.forEach((branch) => {
const percent = allocation[branch.id];
const targetWidth = 0.14 + percent * 0.007;
branch.currentWidth +=
(targetWidth - branch.currentWidth) * (1 - Math.exp(-delta * 4));
branch.water.setWidth(branch.currentWidth);
branch.water.object.material.opacity = 0.78 + percent * 0.003;
const gateProgress = THREE.MathUtils.clamp(percent / 55, 0, 1);
branch.gateBoard.position.y = 0.28 + gateProgress * 0.64;
branch.flowOffset = (branch.flowOffset + delta * 0.075) % 1;
const visibleGlints = Math.max(2, Math.ceil((percent / 100) * 8));
branch.glints.forEach((glint, index) => {
glint.visible = index < visibleGlints;
if (!glint.visible) return;
const t = (index / visibleGlints + branch.flowOffset) % 1;
const point = branch.curve.getPointAt(t);
const tangent = branch.curve.getTangentAt(t);
glint.position.set(point.x, 0.12, point.z);
glint.rotation.y = Math.atan2(tangent.x, tangent.z);
glint.scale.z = 0.8 + (percent / 100) * 0.65;
});
});
const millSpeed = 0.12 + allocation.mill * 0.017;
millWheelSpinner.rotation.z -= delta * millSpeed;
const villageFill = 0.45 + (allocation.village / 100) * 0.75;
troughWater.scale.x +=
(villageFill - troughWater.scale.x) * (1 - Math.exp(-delta * 4));
// Gentle movement in the fields suggests wind without adding realism effects.
materials.crop.color.setHex(palette.crop);
materials.cropGreen.color.setHex(palette.cropGreen);
updateCamera();
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateCamera();
animate();
document.getElementById("loading").remove();
</script>
</body>
</html>
```