Prompt specification
Build or customize the Three.js 3D scene "Paddy bund and small inlet board" 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: Paddy bund and small inlet board
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/paddy-bund-and-small-inlet-board-x2365
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring irrigation in a medieval Japanese farming village. Model one shallow rice-field corner with raised bund and adjustable inlet board. Distinguish the planted surface, stored water, and higher walking edge. Stylized solid forms.
Working Three.js Starter (paddy-bund-and-small-inlet-board-x2365):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Medieval Japanese Irrigation Corner</title>
<style>
:root {
color-scheme: light;
--ink: #27352d;
--paper: rgba(248, 245, 229, 0.88);
--line: rgba(54, 70, 55, 0.18);
--water: #58aaa8;
--planted: #78945a;
--earth: #a87d50;
--wood: #65452e;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #bdcfc3;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
canvas {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 44%, transparent 48%, rgba(39, 49, 37, 0.13) 110%),
linear-gradient(to bottom, rgba(255,255,255,0.08), transparent 28%);
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--line);
background: var(--paper);
box-shadow: 0 14px 40px rgba(46, 56, 43, 0.14);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.title-panel {
top: 22px;
left: 22px;
width: min(355px, calc(100vw - 44px));
padding: 18px 20px 17px;
border-radius: 5px 20px 5px 5px;
}
.eyebrow {
margin: 0 0 7px;
color: #687467;
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(25px, 3vw, 34px);
font-weight: 600;
line-height: 1.04;
letter-spacing: -0.025em;
}
.subtitle {
margin: 10px 0 0;
max-width: 285px;
color: #5a685d;
font-size: 12px;
line-height: 1.5;
}
.control-panel {
top: 22px;
right: 22px;
width: 260px;
padding: 17px;
border-radius: 20px 5px 5px 5px;
}
.control-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 13px;
}
.control-title strong {
font-size: 11px;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.angle-readout {
color: #4f6555;
font-family: Georgia, serif;
font-size: 21px;
font-variant-numeric: tabular-nums;
}
.control-label {
display: flex;
justify-content: space-between;
margin-bottom: 8px;
color: #667368;
font-size: 11px;
}
input[type="range"] {
width: 100%;
height: 24px;
margin: 0;
accent-color: #527d67;
cursor: pointer;
}
.flow-track {
height: 6px;
margin-top: 8px;
overflow: hidden;
border-radius: 10px;
background: rgba(79, 105, 91, 0.12);
}
.flow-fill {
width: 72%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #80b6a3, #4d9b9e);
transition: width 0.12s ease-out;
}
.control-note {
margin: 12px 0 0;
color: #687368;
font-size: 10px;
line-height: 1.45;
}
.legend {
left: 22px;
bottom: 22px;
display: grid;
grid-template-columns: repeat(2, auto);
gap: 10px 18px;
padding: 13px 15px;
border-radius: 5px 5px 18px 5px;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
color: #556257;
font-size: 11px;
white-space: nowrap;
}
.swatch {
width: 12px;
height: 12px;
border: 1px solid rgba(0,0,0,0.09);
border-radius: 3px;
box-shadow: inset 0 1px rgba(255,255,255,0.25);
}
.hint {
right: 22px;
bottom: 22px;
padding: 10px 13px;
border-radius: 14px 4px 4px 4px;
color: #637066;
font-size: 10px;
letter-spacing: 0.02em;
}
button {
margin-top: 12px;
width: 100%;
padding: 9px 12px;
border: 1px solid rgba(54, 70, 55, 0.2);
border-radius: 9px;
background: rgba(255,255,255,0.38);
color: #45574a;
font: inherit;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
cursor: pointer;
transition: background 0.2s, transform 0.2s;
}
button:hover {
background: rgba(255,255,255,0.72);
transform: translateY(-1px);
}
.world-label {
position: fixed;
z-index: 5;
display: none;
padding: 6px 9px;
border: 1px solid rgba(255,255,255,0.68);
border-radius: 20px;
background: rgba(250, 248, 235, 0.83);
box-shadow: 0 5px 16px rgba(40, 49, 38, 0.12);
color: #4d5b50;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.03em;
pointer-events: none;
transform: translate(-50%, -120%);
white-space: nowrap;
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -8px;
width: 1px;
height: 8px;
background: rgba(77,91,80,0.5);
}
@media (max-width: 700px) {
.title-panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
.subtitle {
display: none;
}
.control-panel {
top: auto;
right: 12px;
bottom: 65px;
width: 220px;
padding: 13px;
}
.control-note,
.legend-item:nth-child(n+3) {
display: none;
}
.legend {
left: 12px;
bottom: 12px;
grid-template-columns: 1fr;
padding: 10px 12px;
}
.hint {
display: none;
}
.world-label {
display: none !important;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive Three.js scene of a medieval Japanese rice-field irrigation corner"></canvas>
<div class="vignette"></div>
<header class="panel title-panel">
<p class="eyebrow">Mizu no tani · c. 1500</p>
<h1>The Sluice Corner</h1>
<p class="subtitle">
A shallow paddy beside the village path. Raise the timber inlet board to
release water from the elevated channel.
</p>
</header>
<aside class="panel control-panel">
<div class="control-title">
<strong>Inlet board</strong>
<span class="angle-readout" id="angleValue">58°</span>
</div>
<div class="control-label">
<span>Closed</span>
<span>Open</span>
</div>
<input
id="boardAngle"
type="range"
min="0"
max="80"
value="58"
step="1"
aria-label="Adjustable inlet board angle"
>
<div class="flow-track"><div class="flow-fill" id="flowFill"></div></div>
<p class="control-note">
The board pivots upward from its lower edge. More clearance sends a
stronger stream into the stored-water basin.
</p>
<button id="resetView" type="button">Reset camera</button>
</aside>
<div class="panel legend" aria-label="Scene legend">
<div class="legend-item">
<span class="swatch" style="background:#778b56"></span>
Planted paddy bed
</div>
<div class="legend-item">
<span class="swatch" style="background:#58aaa8"></span>
Stored water
</div>
<div class="legend-item">
<span class="swatch" style="background:#ad865c"></span>
Raised walking edge
</div>
<div class="legend-item">
<span class="swatch" style="background:#67472f"></span>
Adjustable inlet
</div>
</div>
<div class="panel hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<div class="world-label" id="labelWater">Stored water</div>
<div class="world-label" id="labelPlanted">Planted surface</div>
<div class="world-label" id="labelBund">Higher walking edge</div>
<div class="world-label" id="labelInlet">Timber inlet board</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -----------------------------------------------------------------------
// Renderer and scene
// -----------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xbed1c5);
scene.fog = new THREE.Fog(0xbed1c5, 24, 52);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xf2f1d7, 0x665741, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffdfaa, 3.25);
sun.position.set(-8, 15, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 38;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const coolFill = new THREE.DirectionalLight(0xa7d6dc, 0.72);
coolFill.position.set(10, 6, -11);
scene.add(coolFill);
const standard = (color, roughness = 0.85, metalness = 0) =>
new THREE.MeshStandardMaterial({
color,
roughness,
metalness,
flatShading: true
});
const materials = {
earth: standard(0x765d42),
earthSide: standard(0x684f39),
grass: standard(0x78925b),
path: standard(0xb39a6d),
fieldFloor: standard(0x6f7554),
planted: standard(0x718052),
furrow: standard(0x505c3e),
waterFloor: standard(0x467c75),
stone: standard(0x8c8d7b),
stoneDark: standard(0x666d61),
wood: standard(0x65452f),
woodLight: standard(0x896140),
plaster: standard(0xd4c39c),
timber: standard(0x3f3328),
roof: standard(0x5a4939),
thatch: standard(0x9b7547),
rope: standard(0x6e6245),
foliage: standard(0x4f7045),
foliageLight: standard(0x69864f),
trunk: standard(0x594635)
};
function box(w, h, d, mat, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
mat?.isMaterial ? mat : standard(mat)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(
radiusTop,
radiusBottom,
height,
mat,
x,
y,
z,
segments = 10,
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
mat?.isMaterial ? mat : standard(mat)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderBetween(a, b, radius, mat, parent = scene, segments = 8) {
const direction = new THREE.Vector3().subVectors(b, a);
const mesh = cylinder(
radius,
radius,
direction.length(),
mat,
(a.x + b.x) / 2,
(a.y + b.y) / 2,
(a.z + b.z) / 2,
segments,
parent
);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
// -----------------------------------------------------------------------
// Distant landscape
// -----------------------------------------------------------------------
const distantGround = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
standard(0x8fa078)
);
distantGround.rotation.x = -Math.PI / 2;
distantGround.position.y = -0.94;
distantGround.receiveShadow = true;
scene.add(distantGround);
[
[-14, 3.1, -23, 5.2, 8.5, 0x809387],
[-7, 2.4, -26, 4.4, 7.0, 0x87998d],
[1, 3.4, -28, 6.2, 9.4, 0x7f9285],
[10, 2.6, -25, 4.8, 7.8, 0x8b9b8c],
[18, 3.7, -30, 6.4, 10.5, 0x7e9085]
].forEach(([x, y, z, r, h, color]) => {
const mountain = new THREE.Mesh(
new THREE.ConeGeometry(r, h, 6),
standard(color)
);
mountain.position.set(x, y - 0.9, z);
mountain.scale.z = 0.72;
mountain.rotation.y = Math.random() * Math.PI;
mountain.receiveShadow = true;
scene.add(mountain);
});
// -----------------------------------------------------------------------
// Village ground and paddy basin
// -----------------------------------------------------------------------
box(16.5, 0.78, 12.5, materials.earthSide, 0, -0.43, 0);
box(16.35, 0.12, 12.35, materials.grass, 0, 0.02, 0);
// Slightly exposed earthen platform strata.
for (let i = 0; i < 15; i++) {
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.16 + Math.random() * 0.12, 0),
i % 3 === 0 ? materials.stoneDark : materials.stone
);
rock.position.set(
-7.7 + Math.random() * 15.4,
-0.47 + Math.random() * 0.13,
(i % 2 ? 1 : -1) * 6.23
);
rock.scale.y = 0.55;
rock.rotation.set(Math.random(), Math.random(), Math.random());
scene.add(rock);
}
// Basin floor.
box(10.9, 0.13, 8.75, materials.fieldFloor, -0.25, 0.12, 0.02);
// Stored water occupies the left half of the shallow basin.
box(5.35, 0.08, 8.28, materials.waterFloor, -2.62, 0.20, 0.03);
const waterMaterial = new THREE.MeshPhysicalMaterial({
color: 0x59aaa8,
roughness: 0.2,
metalness: 0.04,
clearcoat: 0.75,
clearcoatRoughness: 0.2,
transparent: true,
opacity: 0.7,
depthWrite: false,
side: THREE.DoubleSide
});
const water = new THREE.Mesh(
new THREE.PlaneGeometry(5.34, 8.28),
waterMaterial
);
water.rotation.x = -Math.PI / 2;
water.position.set(-2.62, 0.43, 0.03);
water.receiveShadow = true;
water.renderOrder = 2;
scene.add(water);
// Planted bed, visibly lower than the walking edge but distinct from water.
box(4.82, 0.18, 8.28, materials.planted, 2.49, 0.23, 0.03);
const furrowMaterial = standard(0x566341);
const riceRows = [0.72, 1.46, 2.20, 2.94, 3.68, 4.42];
riceRows.forEach((x) => {
box(0.09, 0.025, 7.9, furrowMaterial, x, 0.332, 0.02);
box(0.22, 0.035, 7.85, materials.furrow, x + 0.31, 0.33, 0.02);
});
// -----------------------------------------------------------------------
// Raised walking edge and low field bunds
// -----------------------------------------------------------------------
// High back and left walking edges.
box(11.65, 0.91, 1.02, materials.path, -0.13, 0.48, -4.68);
box(1.03, 0.91, 9.34, materials.path, -5.90, 0.48, -0.02);
// Walkable cap and grassy outer lips.
box(11.25, 0.12, 0.72, standard(0xc2aa7c), -0.18, 0.99, -4.68);
box(0.72, 0.12, 9.12, materials.grass, -5.90, 0.99, -0.02);
box(11.64, 0.13, 0.16, materials.grass, -0.13, 1.01, -5.11);
// Lower foreground and right bunds.
box(11.65, 0.48, 0.67, materials.earth, -0.13, 0.28, 4.61);
box(0.67, 0.48, 9.34, materials.earth, 5.30, 0.28, -0.01);
box(11.55, 0.09, 0.58, materials.grass, -0.13, 0.56, 4.61);
box(0.58, 0.09, 9.24, materials.grass, 5.30, 0.56, -0.01);
// Stepping stones on the high left edge.
for (let i = 0; i < 8; i++) {
const stone = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.31, 0),
i % 2 ? materials.stone : materials.stoneDark
);
stone.position.set(-5.9, 1.075, -3.65 + i * 1.04);
stone.scale.set(0.85, 0.22, 0.72);
stone.rotation.y = Math.random() * Math.PI;
stone.castShadow = true;
stone.receiveShadow = true;
scene.add(stone);
}
// Small edge posts and a cord define the lower front bund.
const cordPoints = [];
for (let i = 0; i < 7; i++) {
const x = -5.0 + i * 1.65;
cylinder(0.065, 0.085, 0.58, materials.wood, x, 0.84, 4.58, 7);
cordPoints.push(new THREE.Vector3(x, 1.05, 4.58));
}
for (let i = 0; i < cordPoints.length - 1; i++) {
cylinderBetween(
cordPoints[i],
cordPoints[i + 1],
0.022,
materials.rope,
scene,
6
);
}
// -----------------------------------------------------------------------
// Stylized medieval Japanese farm buildings
// -----------------------------------------------------------------------
function gableRoof(w, d, h, material) {
const geometry = new THREE.BufferGeometry();
const positions = new Float32Array([
-w / 2, -d / 2, 0,
-w / 2, 0, h,
-w / 2, d / 2, 0,
w / 2, -d / 2, 0,
w / 2, 0, h,
w / 2, d / 2, 0
]);
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3)
);
geometry.setIndex([
0, 2, 1, 3, 4, 5,
0, 1, 4, 0, 4, 3,
1, 2, 5, 1, 5, 4,
0, 3, 5, 0, 5, 2
]);
geometry.computeVertexNormals();
const roofMaterial = material.clone();
roofMaterial.side = THREE.DoubleSide;
return new THREE.Mesh(geometry, roofMaterial);
}
function buildHouse(x, z, w, d, wallHeight, roofMaterial, small = false) {
const group = new THREE.Group();
group.position.set(x, 0.06, z);
scene.add(group);
box(w + 0.22, 0.22, d + 0.18, materials.stoneDark, 0, 0.11, 0, group);
box(w, wallHeight, d, materials.plaster, 0, 0.22 + wallHeight / 2, 0, group);
// Dark exposed timber frame.
const front = d / 2 + 0.035;
const postHeight = wallHeight + 0.08;
[-w / 2 + 0.05, 0, w / 2 - 0.05].forEach((px) => {
box(0.11, postHeight, 0.12, materials.timber, px, 0.23 + postHeight / 2, front, group);
});
box(w + 0.02, 0.13, 0.14, materials.timber, 0, 0.24 + wallHeight, front, group);
box(w + 0.02, 0.11, 0.14, materials.timber, 0, 0.24 + wallHeight * 0.48, front, group);
// Door.
box(0.52, 0.88, 0.09, materials.wood, -w * 0.23, 0.66, front + 0.04, group);
box(0.025, 0.84, 0.025, materials.timber, -w * 0.23, 0.66, front + 0.095, group);
// Shoji-like window.
const wx = w * 0.24;
const wy = 0.22 + wallHeight * 0.6;
box(0.67, 0.61, 0.065, standard(0xe7d7a8), wx, wy, front + 0.04, group);
for (let i = 0; i < 3; i++) {
box(0.035, 0.57, 0.035, materials.timber, wx - 0.2 + i * 0.2, wy, front + 0.085, group);
}
box(0.62, 0.035, 0.035, materials.timber, wx, wy, front + 0.085, group);
const roof = gableRoof(w + 0.48, d + 0.48, small ? 0.65 : 0.86, roofMaterial);
roof.position.y = 0.23 + wallHeight;
roof.castShadow = true;
roof.receiveShadow = true;
group.add(roof);
const ridge = cylinder(
0.065,
0.065,
w + 0.52,
materials.timber,
0,
0.23 + wallHeight + (small ? 0.65 : 0.86),
0,
8,
group
);
ridge.rotation.z = Math.PI / 2;
// Under-eave supports.
[-w / 2 - 0.08, w / 2 + 0.08].forEach((px) => {
box(0.09, 0.23, d + 0.2, materials.timber, px, 0.23 + wallHeight - 0.08, 0, group);
});
return group;
}
buildHouse(2.25, -5.52, 3.15, 1.62, 1.38, materials.roof);
buildHouse(-4.72, -5.48, 1.75, 1.30, 1.03, materials.thatch, true);
function tree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.05, z);
group.scale.setScalar(scale);
scene.add(group);
cylinder(0.11, 0.16, 1.35, materials.trunk, 0, 0.68, 0, 8, group);
const crownGeometry = new THREE.IcosahedronGeometry(0.76, 1);
const crownA = new THREE.Mesh(crownGeometry, materials.foliage);
crownA.position.set(-0.22, 1.5, 0.05);
crownA.scale.set(1, 1.08, 0.85);
crownA.castShadow = true;
group.add(crownA);
const crownB = new THREE.Mesh(crownGeometry, materials.foliageLight);
crownB.position.set(0.32, 1.62, -0.03);
crownB.scale.set(0.72, 0.82, 0.72);
crownB.castShadow = true;
group.add(crownB);
}
tree(4.75, -5.57, 1.05);
tree(-6.58, -3.80, 0.84);
tree(6.40, -2.88, 0.72);
// Stone lantern beside the farmhouse.
const lantern = new THREE.Group();
lantern.position.set(4.25, 0.08, -4.95);
scene.add(lantern);
box(0.44, 0.16, 0.44, materials.stone, 0, 0.08, 0, lantern);
cylinder(0.12, 0.17, 0.62, materials.stone, 0, 0.45, 0, 6, lantern);
box(0.43, 0.15, 0.43, materials.stoneDark, 0, 0.81, 0, lantern);
cylinder(0.19, 0.27, 0.19, materials.stone, 0, 0.98, 0, 6, lantern);
const cap = new THREE.Mesh(
new THREE.ConeGeometry(0.34, 0.24, 6),
materials.stoneDark
);
cap.position.y = 1.19;
cap.castShadow = true;
lantern.add(cap);
// -----------------------------------------------------------------------
// Irrigation channel, sluice frame, and adjustable board
// -----------------------------------------------------------------------
const inletX = -2.35;
const inletZ = -4.08;
// Elevated supply channel running toward the sluice.
box(0.86, 0.12, 1.86, materials.stoneDark, inletX, 0.88, -5.13);
box(0.66, 0.055, 1.76, standard(0x58a9aa), inletX, 0.985, -5.13);
box(0.13, 0.35, 1.90, materials.stone, inletX - 0.43, 1.00, -5.13);
box(0.13, 0.35, 1.90, materials.stone, inletX + 0.43, 1.00, -5.13);
// Sluice frame.
box(0.16, 1.64, 0.19, materials.wood, inletX - 0.78, 0.75, inletZ);
box(0.16, 1.64, 0.19, materials.wood, inletX + 0.78, 0.75, inletZ);
box(1.84, 0.17, 0.21, materials.wood, inletX, 1.57, inletZ);
const hinge = cylinder(
0.09,
0.09,
1.54,
materials.woodLight,
inletX,
1.36,
inletZ,
10
);
hinge.rotation.z = Math.PI / 2;
// Board hangs downward from the hinge; positive UI angle lifts its bottom.
const boardPivot = new THREE.Group();
boardPivot.position.set(inletX, 1.36, inletZ);
scene.add(boardPivot);
box(1.30, 1.08, 0.14, materials.wood, 0, -0.54, 0, boardPivot);
box(1.18, 0.045, 0.025, materials.woodLight, 0, -0.30, 0.082, boardPivot);
box(1.18, 0.045, 0.025, materials.woodLight, 0, -0.78, 0.082, boardPivot);
box(0.42, 0.09, 0.18, materials.timber, 0, -0.88, 0.12, boardPivot);
// A little barrel and a leaning rake provide human scale.
cylinder(0.19, 0.23, 0.36, materials.woodLight, -1.22, 0.56, -3.91, 12);
const barrelRim = new THREE.Mesh(
new THREE.TorusGeometry(0.21, 0.025, 6, 16),
materials.timber
);
barrelRim.rotation.x = Math.PI / 2;
barrelRim.position.set(-1.22, 0.74, -3.91);
scene.add(barrelRim);
cylinderBetween(
new THREE.Vector3(-1.46, 0.28, -3.79),
new THREE.Vector3(-1.18, 1.48, -4.10),
0.026,
materials.woodLight
);
box(0.64, 0.07, 0.08, materials.wood, -1.47, 0.29, -3.78);
for (let i = 0; i < 5; i++) {
box(0.035, 0.16, 0.04, materials.woodLight,
-1.70 + i * 0.115, 0.20, -3.78);
}
// -----------------------------------------------------------------------
// Rice plants using instanced low-poly blades
// -----------------------------------------------------------------------
const bladeCount = riceRows.length * 16 * 3;
const bladeGeometry = new THREE.ConeGeometry(0.045, 0.43, 4);
const bladeMaterial = standard(0xffffff, 0.92);
const blades = new THREE.InstancedMesh(
bladeGeometry,
bladeMaterial,
bladeCount
);
const dummy = new THREE.Object3D();
const bladeColor = new THREE.Color();
let bladeIndex = 0;
riceRows.forEach((x) => {
for (let row = 0; row < 16; row++) {
const z = -3.52 + row * 0.49;
for (let blade = 0; blade < 3; blade++) {
const h = 0.78 + Math.random() * 0.42;
dummy.position.set(
x + (Math.random() - 0.5) * 0.13,
0.33 + (0.43 * h) / 2,
z + (Math.random() - 0.5) * 0.12
);
dummy.rotation.set(
(Math.random() - 0.5) * 0.36,
Math.random() * Math.PI,
(Math.random() - 0.5) * 0.38
);
dummy.scale.set(0.85 + Math.random() * 0.25, h, 0.85);
dummy.updateMatrix();
blades.setMatrixAt(bladeIndex, dummy.matrix);
const hue = 0.22 + Math.random() * 0.035;
bladeColor.setHSL(hue, 0.34 + Math.random() * 0.12, 0.36 + Math.random() * 0.15);
blades.setColorAt(bladeIndex, bladeColor);
bladeIndex++;
}
}
});
blades.instanceMatrix.needsUpdate = true;
if (blades.instanceColor) blades.instanceColor.needsUpdate = true;
blades.castShadow = true;
blades.receiveShadow = true;
scene.add(blades);
// -----------------------------------------------------------------------
// Water animation: sheet, droplets, ripples, and reflected light streaks
// -----------------------------------------------------------------------
const flowSheetGeometry = new THREE.BufferGeometry();
flowSheetGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
-0.52, 0, 0,
0.52, 0, 0,
-0.35, 0, 1.27,
0.35, 0, 1.27
], 3)
);
flowSheetGeometry.setIndex([0, 1, 2, 1, 3, 2]);
flowSheetGeometry.computeVertexNormals();
const flowSheetMaterial = new THREE.MeshBasicMaterial({
color: 0x8ed3d0,
transparent: true,
opacity: 0.2,
depthWrite: false,
side: THREE.DoubleSide
});
const flowSheet = new THREE.Mesh(flowSheetGeometry, flowSheetMaterial);
flowSheet.position.set(inletX, 0.445, inletZ - 0.03);
flowSheet.renderOrder = 3;
scene.add(flowSheet);
const dropCount = 30;
const drops = new THREE.InstancedMesh(
new THREE.SphereGeometry(0.045, 6, 4),
new THREE.MeshBasicMaterial({
color: 0xb8ece5,
transparent: true,
opacity: 0.82,
depthWrite: false
}),
dropCount
);
drops.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
drops.frustumCulled = false;
drops.renderOrder = 4;
scene.add(drops);
const dropSeeds = Array.from({ length: dropCount }, () => ({
offset: Math.random(),
lane: (Math.random() - 0.5) * 0.78,
lift: Math.random() * 0.09,
scale: 0.7 + Math.random() * 0.8
}));
const ripples = [];
const rippleGeometry = new THREE.RingGeometry(0.18, 0.205, 28);
for (let i = 0; i < 10; i++) {
const rippleMaterial = new THREE.MeshBasicMaterial({
color: i < 5 ? 0xd2eee5 : 0xa8d9d4,
transparent: true,
opacity: 0.2,
depthWrite: false,
side: THREE.DoubleSide
});
const ripple = new THREE.Mesh(rippleGeometry, rippleMaterial);
ripple.rotation.x = -Math.PI / 2;
if (i < 5) {
ripple.position.set(
inletX + (Math.random() - 0.5) * 0.55,
0.452,
-3.25 + Math.random() * 0.5
);
} else {
ripple.position.set(
-4.85 + Math.random() * 4.65,
0.452,
-3.6 + Math.random() * 7.2
);
}
ripple.renderOrder = 3;
scene.add(ripple);
ripples.push(ripple);
}
const glints = [];
for (let i = 0; i < 5; i++) {
const glint = new THREE.Mesh(
new THREE.PlaneGeometry(0.75 + Math.random() * 0.8, 0.045),
new THREE.MeshBasicMaterial({
color: 0xe5f5e9,
transparent: true,
opacity: 0.19,
depthWrite: false,
side: THREE.DoubleSide
})
);
glint.rotation.x = -Math.PI / 2;
glint.position.set(
-4.65 + Math.random() * 4.3,
0.455,
-3.6 + Math.random() * 7.1
);
glint.renderOrder = 4;
scene.add(glint);
glints.push({ mesh: glint, x: glint.position.x, phase: Math.random() * 6 });
}
// -----------------------------------------------------------------------
// UI and board control
// -----------------------------------------------------------------------
const angleSlider = document.querySelector("#boardAngle");
const angleValue = document.querySelector("#angleValue");
const flowFill = document.querySelector("#flowFill");
let boardAngle = Number(angleSlider.value);
function setBoardAngle(value) {
boardAngle = THREE.MathUtils.clamp(value, 0, 80);
const radians = THREE.MathUtils.degToRad(boardAngle);
// Negative X rotation lifts the lower edge toward the field.
boardPivot.rotation.x = -radians;
const openRatio = boardAngle / 80;
angleValue.textContent = `${Math.round(boardAngle)}°`;
flowFill.style.width = `${openRatio * 100}%`;
flowSheet.visible = boardAngle > 5;
flowSheetMaterial.opacity = 0.05 + openRatio * 0.22;
flowSheet.position.y = 0.445 + openRatio * 0.045;
drops.visible = boardAngle > 7;
drops.count = Math.floor(openRatio * dropCount);
}
angleSlider.addEventListener("input", (event) => {
setBoardAngle(Number(event.target.value));
});
setBoardAngle(boardAngle);
// -----------------------------------------------------------------------
// Direct camera controls — no Three.js addons
// -----------------------------------------------------------------------
const cameraState = {
theta: 0.67,
phi: 1.01,
radius: 18.6,
target: new THREE.Vector3(0, 0.35, -0.35)
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y +
cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.theta = 0.67;
cameraState.phi = 1.01;
cameraState.radius = 18.6;
cameraState.target.set(0, 0.35, -0.35);
updateCamera();
}
document.querySelector("#resetView").addEventListener("click", resetCamera);
canvas.addEventListener("dblclick", resetCamera);
let dragging = false;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
cameraState.theta -= dx * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.0045,
0.46,
1.34
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
11.5,
28
);
updateCamera();
},
{ passive: false }
);
// World-space feature labels.
const worldLabels = [
{
element: document.querySelector("#labelWater"),
point: new THREE.Vector3(-3.25, 0.49, 1.15)
},
{
element: document.querySelector("#labelPlanted"),
point: new THREE.Vector3(2.75, 0.42, 2.5)
},
{
element: document.querySelector("#labelBund"),
point: new THREE.Vector3(-5.0, 1.10, -3.7)
},
{
element: document.querySelector("#labelInlet"),
point: new THREE.Vector3(-2.35, 1.66, -4.08)
}
];
const projected = new THREE.Vector3();
function updateWorldLabels() {
worldLabels.forEach(({ element, point }) => {
projected.copy(point).project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "block" : "none";
if (!visible) return;
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
});
}
// -----------------------------------------------------------------------
// Animation loop
// -----------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const time = clock.getElapsedTime();
const openRatio = boardAngle / 80;
waterMaterial.opacity = 0.68 + Math.sin(time * 0.65) * 0.025;
// Moving droplets through the sluice opening.
if (drops.visible) {
dropSeeds.slice(0, drops.count).forEach((seed, index) => {
const u = (time * (0.28 + openRatio * 0.33) + seed.offset) % 1;
const spread = 0.45 + u * 0.14;
dummy.position.set(
inletX + seed.lane * spread,
0.43 + Math.sin(u * Math.PI) * seed.lift,
inletZ - 0.02 + u * 1.32
);
dummy.rotation.set(0, 0, 0);
dummy.scale.setScalar(seed.scale);
dummy.updateMatrix();
drops.setMatrixAt(index, dummy.matrix);
});
drops.instanceMatrix.needsUpdate = true;
}
// Expanding surface rings.
ripples.forEach((ripple, index) => {
const phase = (time * (index < 5 ? 0.28 : 0.14) + index * 0.137) % 1;
const scale = 0.6 + phase * (index < 5 ? 3.0 : 2.0);
ripple.scale.setScalar(scale);
ripple.material.opacity = (1 - phase) * (index < 5 ? 0.28 : 0.14);
});
// Quiet lateral movement of reflected light on the stored water.
glints.forEach(({ mesh, x, phase }) => {
mesh.position.x = x + Math.sin(time * 0.35 + phase) * 0.12;
mesh.material.opacity = 0.12 + (Math.sin(time * 0.7 + phase) + 1) * 0.035;
});
updateWorldLabels();
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
updateCamera();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```