Prompt specification
Build or customize the Three.js 3D scene "Irrigation-to-meal learning diorama" 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: Irrigation-to-meal learning diorama
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/irrigation-to-meal-learning-diorama-x0148
Scene Description Prompt:
Build a low-poly rice journey from irrigated paddy through drying rack and grain store to kitchen. Three.js from cdnjs, one HTML file.
Working Three.js Starter (irrigation-to-meal-learning-diorama-x0148):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#173f32">
<title>The Grain Road — A Low-Poly Rice Journey</title>
<style>
:root {
--ink: #173f32;
--paper: #fffaf0;
--gold: #e6ad42;
--mint: #b8d9b7;
--glass: rgba(255, 250, 240, 0.88);
--shadow: 0 18px 50px rgba(30, 53, 41, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce9df;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
#ui {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 10;
}
.topbar {
position: absolute;
top: 22px;
left: 24px;
right: 24px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20px;
}
.brand {
pointer-events: auto;
max-width: 430px;
padding: 15px 18px 16px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 18px;
background: var(--glass);
box-shadow: var(--shadow);
backdrop-filter: blur(15px);
-webkit-backdrop-filter: blur(15px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 5px;
color: #6a806e;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 20px;
height: 2px;
border-radius: 2px;
background: var(--gold);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(27px, 3vw, 42px);
font-weight: 500;
line-height: 1;
letter-spacing: -0.035em;
}
.brand p {
margin: 8px 0 0;
color: #617568;
font-size: 12px;
line-height: 1.45;
}
.overview {
pointer-events: auto;
padding: 11px 15px;
border: 1px solid rgba(255, 255, 255, 0.76);
border-radius: 999px;
background: var(--glass);
box-shadow: var(--shadow);
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(12px);
transition: transform 160ms ease, background 160ms ease;
}
.overview:hover {
transform: translateY(-2px);
background: #fffdf7;
}
.chapter-nav {
position: absolute;
top: 50%;
right: 24px;
width: 226px;
padding: 9px;
transform: translateY(-50%);
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 19px;
background: var(--glass);
box-shadow: var(--shadow);
pointer-events: auto;
backdrop-filter: blur(15px);
-webkit-backdrop-filter: blur(15px);
}
.chapter-nav::before {
content: "THE JOURNEY";
display: block;
padding: 7px 10px 10px;
color: #738478;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.18em;
}
.chapter {
position: relative;
width: 100%;
display: flex;
align-items: center;
gap: 11px;
padding: 9px 10px;
border: 0;
border-radius: 12px;
background: transparent;
color: var(--ink);
text-align: left;
font: inherit;
cursor: pointer;
transition: background 180ms ease, transform 180ms ease;
}
.chapter:hover {
background: rgba(184, 217, 183, 0.28);
transform: translateX(-2px);
}
.chapter.active {
background: var(--ink);
color: #fffdf4;
}
.chapter .num {
flex: 0 0 31px;
width: 31px;
height: 31px;
display: grid;
place-items: center;
border: 1px solid rgba(23, 63, 50, 0.2);
border-radius: 50%;
color: var(--gold);
font-size: 10px;
font-weight: 900;
}
.chapter.active .num {
border-color: rgba(255, 255, 255, 0.28);
background: rgba(255, 255, 255, 0.08);
}
.chapter strong {
display: block;
font-size: 12px;
font-weight: 800;
}
.chapter small {
display: block;
margin-top: 2px;
color: #7b8a7e;
font-size: 9px;
}
.chapter.active small {
color: #bcd0c4;
}
.stage-card {
position: absolute;
left: 24px;
bottom: 24px;
width: min(370px, calc(100vw - 48px));
padding: 17px 18px 16px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 18px;
background: var(--glass);
box-shadow: var(--shadow);
pointer-events: auto;
backdrop-filter: blur(15px);
-webkit-backdrop-filter: blur(15px);
}
.stage-kicker {
color: #75877a;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.stage-card h2 {
margin: 5px 0 5px;
font-family: Georgia, "Times New Roman", serif;
font-size: 24px;
font-weight: 500;
letter-spacing: -0.025em;
}
.stage-card p {
margin: 0;
color: #637469;
font-size: 11px;
line-height: 1.55;
}
.progress {
height: 3px;
margin-top: 14px;
overflow: hidden;
border-radius: 3px;
background: rgba(23, 63, 50, 0.11);
}
.progress > div {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #74a87b, #e6ad42);
transition: width 500ms ease;
}
.controls {
position: absolute;
right: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 12px;
pointer-events: auto;
}
.hint {
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.68);
border-radius: 12px;
background: rgba(255, 250, 240, 0.76);
color: #6b7d70;
font-size: 9px;
line-height: 1.5;
text-align: right;
backdrop-filter: blur(12px);
}
.hint b {
color: var(--ink);
font-weight: 800;
}
#tourButton {
display: flex;
align-items: center;
gap: 9px;
min-width: 164px;
justify-content: center;
padding: 13px 17px;
border: 0;
border-radius: 999px;
background: var(--ink);
box-shadow: 0 12px 28px rgba(23, 63, 50, 0.26);
color: #fffdf5;
font: inherit;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.035em;
cursor: pointer;
transition: transform 160ms ease, box-shadow 160ms ease;
}
#tourButton:hover {
transform: translateY(-2px);
box-shadow: 0 16px 34px rgba(23, 63, 50, 0.32);
}
#tourIcon {
color: var(--gold);
font-size: 13px;
}
.loader {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: #e6eee4;
transition: opacity 600ms ease, visibility 600ms ease;
}
.loader-inner {
text-align: center;
color: var(--ink);
}
.loader-grain {
width: 42px;
height: 55px;
margin: 0 auto 18px;
border-radius: 60% 40% 58% 42%;
background: var(--gold);
box-shadow: 14px 8px 0 #d69a34;
animation: grainPulse 1.2s ease-in-out infinite alternate;
}
.loader strong {
font-family: Georgia, "Times New Roman", serif;
font-size: 21px;
font-weight: 500;
}
.loader small {
display: block;
margin-top: 6px;
color: #758478;
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
body.ready .loader {
opacity: 0;
visibility: hidden;
}
@keyframes grainPulse {
from {
transform: translateY(4px) rotate(-8deg);
}
to {
transform: translateY(-4px) rotate(8deg);
}
}
@media (max-width: 760px) {
.topbar {
top: 12px;
left: 12px;
right: 12px;
}
.brand {
max-width: calc(100vw - 24px);
padding: 12px 14px;
}
.brand p {
display: none;
}
.overview {
position: absolute;
top: 88px;
right: 0;
padding: 9px 12px;
font-size: 9px;
}
.chapter-nav {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
display: flex;
gap: 4px;
padding: 7px;
overflow-x: auto;
transform: none;
}
.chapter-nav::before {
display: none;
}
.chapter {
flex: 1 0 46px;
justify-content: center;
padding: 7px;
}
.chapter .copy {
display: none;
}
.stage-card {
top: 128px;
bottom: auto;
left: 12px;
width: min(330px, calc(100vw - 24px));
padding: 12px 14px;
}
.stage-card h2 {
font-size: 20px;
}
.stage-card p {
display: none;
}
.progress {
margin-top: 9px;
}
.controls {
right: 12px;
bottom: 78px;
}
.hint {
display: none;
}
#tourButton {
min-width: 0;
padding: 11px 14px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly rice journey"></canvas>
<div id="ui">
<div class="topbar">
<div class="brand">
<div class="eyebrow">From field to table</div>
<h1>The Grain Road</h1>
<p>Follow a handful of rice from irrigation to the evening meal.</p>
</div>
<button class="overview" id="overviewButton">View whole journey</button>
</div>
<nav class="chapter-nav" aria-label="Journey chapters">
<button class="chapter active" data-stage="0">
<span class="num">01</span>
<span class="copy">
<strong>Irrigated paddy</strong>
<small>Water, roots, and green shoots</small>
</span>
</button>
<button class="chapter" data-stage="1">
<span class="num">02</span>
<span class="copy">
<strong>Drying rack</strong>
<small>Sun and carefully turned sheaves</small>
</span>
</button>
<button class="chapter" data-stage="2">
<span class="num">03</span>
<span class="copy">
<strong>Grain store</strong>
<small>Harvest gathered and protected</small>
</span>
</button>
<button class="chapter" data-stage="3">
<span class="num">04</span>
<span class="copy">
<strong>Kitchen</strong>
<small>Grain becomes a shared meal</small>
</span>
</button>
</nav>
<section class="stage-card" aria-live="polite">
<div class="stage-kicker" id="stageKicker">Chapter 01 / 04</div>
<h2 id="stageTitle">Irrigated paddy</h2>
<p id="stageDescription">
Shallow water cools the roots while young rice stalks rise in neat rows.
</p>
<div class="progress"><div id="progressFill"></div></div>
</section>
<div class="controls">
<div class="hint">
<b>Drag</b> orbit · <b>Wheel</b> zoom<br>
<b>Shift-drag</b> pan · <b>1–4</b> chapters
</div>
<button id="tourButton">
<span id="tourIcon">▶</span>
<span id="tourText">Follow the grain</span>
</button>
</div>
</div>
<div class="loader">
<div class="loader-inner">
<div class="loader-grain"></div>
<strong>Planting the journey</strong>
<small>Building a tiny rice landscape</small>
</div>
</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,
alpha: false,
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.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce9df);
scene.fog = new THREE.Fog(0xdce9df, 24, 58);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemi = new THREE.HemisphereLight(0xeaf6ec, 0x745f43, 2.05);
scene.add(hemi);
const sunLight = new THREE.DirectionalLight(0xffe3a2, 3.25);
sunLight.position.set(-11, 18, 11);
sunLight.castShadow = true;
sunLight.shadow.mapSize.set(2048, 2048);
sunLight.shadow.camera.left = -24;
sunLight.shadow.camera.right = 24;
sunLight.shadow.camera.top = 17;
sunLight.shadow.camera.bottom = -17;
sunLight.shadow.camera.near = 1;
sunLight.shadow.camera.far = 48;
sunLight.shadow.bias = -0.00035;
scene.add(sunLight);
const fill = new THREE.DirectionalLight(0x9fc7d8, 0.75);
fill.position.set(14, 8, -12);
scene.add(fill);
// -------------------------------------------------------------------------
// Materials and modeling helpers
// -------------------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
flatShading: true,
...options
});
const M = {
soil: material(0x94704c),
soilDark: material(0x705239),
earthEdge: material(0xb59261),
grass: material(0x91ad70),
grassDark: material(0x66885c),
grassLight: material(0xb3c982),
path: material(0xc2aa78),
stone: material(0xa9a68d),
water: material(0x63b9c8, {
transparent: true,
opacity: 0.78,
roughness: 0.18,
metalness: 0.04,
depthWrite: false
}),
waterLight: material(0xa9e0df, {
transparent: true,
opacity: 0.48,
roughness: 0.12,
depthWrite: false
}),
bamboo: material(0xb7954d),
bambooLight: material(0xd0b86c),
bambooDark: material(0x7c6335),
wood: material(0x9b7142),
woodDark: material(0x61452e),
woodLight: material(0xc29a61),
thatch: material(0xb98842),
thatchDark: material(0x896232),
rice: material(0xe8c85d),
riceLight: material(0xf4dda0),
riceCream: material(0xfff0c5),
sack: material(0xc9a36c),
sackDark: material(0xa87948),
roof: material(0x436b57),
roofDark: material(0x2e5042),
charcoal: material(0x303633),
metal: material(0x6c7771, { roughness: 0.42, metalness: 0.42 }),
ceramic: material(0xd4774e),
ceramicLight: material(0xe7b47e),
leaf: material(0x578c43),
leafLight: material(0x79a94f),
trunk: material(0x75563a),
hill: material(0x8ba78a),
hillFar: material(0xa2b9a1),
cloud: material(0xf4f5e8),
skin: material(0xbf835a),
shirt: material(0xb95e43),
shirtBlue: material(0x416e72),
hat: material(0xd3ad62),
dark: material(0x2e3a30)
};
function box(parent, size, position, mat, rotation = [0, 0, 0]) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(...size), mat);
mesh.position.set(...position);
mesh.rotation.set(...rotation);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(
parent,
topRadius,
bottomRadius,
height,
position,
mat,
segments = 8,
rotation = [0, 0, 0]
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(topRadius, bottomRadius, height, segments),
mat
);
mesh.position.set(...position);
mesh.rotation.set(...rotation);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function ico(parent, radius, position, mat, detail = 0) {
const mesh = new THREE.Mesh(
new THREE.IcosahedronGeometry(radius, detail),
mat
);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function torus(parent, radius, tube, position, mat, rotation = [0, 0, 0]) {
const mesh = new THREE.Mesh(
new THREE.TorusGeometry(radius, tube, 4, 12),
mat
);
mesh.position.set(...position);
mesh.rotation.set(...rotation);
parent.add(mesh);
return mesh;
}
let seed = 83671;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
// -------------------------------------------------------------------------
// Landscape base and connecting path
// -------------------------------------------------------------------------
box(scene, [31.4, 0.65, 12.2], [0, -0.38, 0], M.soil);
box(scene, [31, 0.14, 11.8], [0, -0.01, 0], M.grass);
box(scene, [30.8, 0.11, 0.22], [0, -0.15, 6.02], M.soilDark);
for (let i = 0; i < 21; i++) {
const x = -7.7 + i * 0.82;
const z = 2.65 + Math.sin(i * 0.72) * 0.28;
const stone = cylinder(
scene,
0.35 + random() * 0.12,
0.38 + random() * 0.12,
0.09,
[x, 0.08, z],
i % 3 === 0 ? M.stone : M.path,
7
);
stone.rotation.y = random() * Math.PI;
stone.scale.z = 0.62 + random() * 0.35;
}
const arrowShape = new THREE.Shape();
arrowShape.moveTo(-0.36, -0.24);
arrowShape.lineTo(0.05, -0.24);
arrowShape.lineTo(0.05, -0.42);
arrowShape.lineTo(0.42, 0);
arrowShape.lineTo(0.05, 0.42);
arrowShape.lineTo(0.05, 0.24);
arrowShape.lineTo(-0.36, 0.24);
arrowShape.closePath();
const arrowGeometry = new THREE.ShapeGeometry(arrowShape);
const arrowMaterial = material(0xe2b54f, { side: THREE.DoubleSide });
[-6.1, 0.2, 7.1].forEach((x) => {
const arrow = new THREE.Mesh(arrowGeometry, arrowMaterial);
arrow.rotation.x = -Math.PI / 2;
arrow.position.set(x, 0.085, 2.2);
scene.add(arrow);
});
// -------------------------------------------------------------------------
// Chapter 1: irrigated paddy
// -------------------------------------------------------------------------
const paddy = new THREE.Group();
paddy.position.x = -10.65;
scene.add(paddy);
box(paddy, [5, 0.24, 0.34], [0, 0.12, -2.5], M.soilDark);
box(paddy, [5, 0.24, 0.34], [0, 0.12, 2.5], M.soilDark);
box(paddy, [0.34, 0.24, 5], [-2.42, 0.12, 0], M.soilDark);
box(paddy, [0.34, 0.24, 5], [2.42, 0.12, 0], M.soilDark);
box(paddy, [4.48, 0.08, 4.66], [0, 0.055, 0], M.soil);
box(paddy, [4.4, 0.035, 4.58], [0, 0.105, 0], M.water);
box(paddy, [0.12, 0.18, 4.55], [0, 0.19, 0], M.soilDark);
// Irrigation channel and simple bamboo outlet.
box(scene, [3.3, 0.12, 0.55], [-6.75, 0.04, 2.42], M.soilDark);
box(scene, [3.25, 0.04, 0.36], [-6.75, 0.12, 2.42], M.waterLight);
cylinder(paddy, 0.07, 0.07, 1.45, [2.05, 0.74, 2.62], M.bamboo, 6);
cylinder(paddy, 0.05, 0.05, 0.78, [2.05, 0.48, 2.23], M.bambooLight, 6, [
Math.PI / 2,
0,
0
]);
box(paddy, [0.22, 0.16, 0.16], [2.05, 0.12, 2.53], M.woodDark);
const plantCount = 168;
const stems = new THREE.InstancedMesh(
new THREE.CylinderGeometry(0.022, 0.032, 0.95, 5),
M.leaf,
plantCount
);
const heads = new THREE.InstancedMesh(
new THREE.IcosahedronGeometry(0.088, 0),
M.rice,
plantCount
);
const leaves = new THREE.InstancedMesh(
new THREE.ConeGeometry(0.065, 0.32, 4),
M.leafLight,
plantCount * 2
);
stems.castShadow = true;
heads.castShadow = true;
leaves.castShadow = true;
const dummy = new THREE.Object3D();
for (let i = 0; i < plantCount; i++) {
const x = -1.98 + random() * 3.96;
const z = -2.05 + random() * 4.1;
const h = 0.78 + random() * 0.42;
dummy.position.set(x, 0.12 + h * 0.5, z);
dummy.rotation.set(0, random() * Math.PI, (random() - 0.5) * 0.13);
dummy.scale.set(1, h, 1);
dummy.updateMatrix();
stems.setMatrixAt(i, dummy.matrix);
dummy.position.set(x, 0.14 + h, z);
dummy.rotation.set(0, random() * Math.PI, 0);
dummy.scale.set(0.72, 1.35, 0.72);
dummy.updateMatrix();
heads.setMatrixAt(i, dummy.matrix);
heads.setColorAt(
i,
new THREE.Color().setHSL(0.13 + random() * 0.025, 0.65, 0.56 + random() * 0.1)
);
for (let side = 0; side < 2; side++) {
const leafIndex = i * 2 + side;
dummy.position.set(
x + (side ? 0.07 : -0.07),
0.12 + h * (0.42 + random() * 0.15),
z
);
dummy.rotation.set(
(random() - 0.5) * 0.35,
random() * Math.PI,
side ? -1.0 - random() * 0.25 : 1.0 + random() * 0.25
);
dummy.scale.set(1, 0.8 + random() * 0.45, 1);
dummy.updateMatrix();
leaves.setMatrixAt(leafIndex, dummy.matrix);
}
}
stems.instanceMatrix.needsUpdate = true;
heads.instanceMatrix.needsUpdate = true;
leaves.instanceMatrix.needsUpdate = true;
if (heads.instanceColor) heads.instanceColor.needsUpdate = true;
paddy.add(stems, heads, leaves);
// Small animated water rings.
const ripples = [];
for (let i = 0; i < 8; i++) {
const rippleMaterial = new THREE.MeshBasicMaterial({
color: 0xd2f1e5,
transparent: true,
opacity: 0.35,
depthWrite: false
});
const ripple = torus(
paddy,
0.16,
0.012,
[-1.8 + random() * 3.6, 0.135, -1.8 + random() * 3.6],
rippleMaterial,
[Math.PI / 2, 0, 0]
);
ripples.push({
mesh: ripple,
phase: random() * Math.PI * 2,
speed: 0.55 + random() * 0.4
});
}
// -------------------------------------------------------------------------
// Chapter 2: drying rack
// -------------------------------------------------------------------------
const dryingRack = new THREE.Group();
dryingRack.position.x = -3.45;
scene.add(dryingRack);
for (let i = 0; i < 11; i++) {
box(
dryingRack,
[0.23, 0.1, 2.8],
[-1.6 + i * 0.32, 0.17, 0],
i % 2 ? M.bamboo : M.bambooLight
);
}
[-1.72, 1.72].forEach((x) => {
[-1.12, 1.12].forEach((z) => {
cylinder(dryingRack, 0.105, 0.13, 3.25, [x, 1.72, z], M.bamboo, 7);
cylinder(dryingRack, 0.125, 0.125, 0.1, [x, 0.18, z], M.bambooDark, 7);
});
});
[-1.12, 1.12].forEach((z) => {
cylinder(
dryingRack,
0.09,
0.09,
3.75,
[0, 3.15, z],
M.bambooLight,
7,
[0, 0, Math.PI / 2]
);
});
[-1.72, 1.72].forEach((x) => {
cylinder(
dryingRack,
0.08,
0.08,
2.45,
[x, 3.15, 0],
M.bamboo,
7,
[Math.PI / 2, 0, 0]
);
});
// Hanging sheaves.
[-1.16, 0, 1.16].forEach((x, index) => {
cylinder(
dryingRack,
0.025,
0.025,
0.43,
[x, 2.92, -0.62],
M.bambooDark,
6
);
const sheaf = cylinder(
dryingRack,
0.035,
0.25,
0.67,
[x, 2.22, -0.62],
index % 2 ? M.riceLight : M.rice,
7,
[0, 0, Math.PI]
);
sheaf.scale.z = 0.72;
cylinder(
dryingRack,
0.21,
0.21,
0.07,
[x, 2.48, -0.62],
M.bambooDark,
7
);
});
// Three shallow drying trays.
[-1.1, 0, 1.1].forEach((x) => {
box(dryingRack, [0.94, 0.09, 1.42], [x, 1.15, 0.42], M.bambooLight);
box(dryingRack, [0.78, 0.07, 1.18], [x, 1.22, 0.42], M.riceLight);
[-0.47, 0.47].forEach((dx) => {
box(dryingRack, [0.055, 0.08, 1.5], [x + dx, 1.17, 0.42], M.bambooDark);
});
});
// Woven baskets below.
[-0.82, 0.82].forEach((x) => {
cylinder(dryingRack, 0.46, 0.34, 0.42, [x, 0.46, -0.62], M.bambooDark, 9);
const mound = ico(dryingRack, 0.4, [x, 0.7, -0.62], M.rice);
mound.scale.set(1, 0.35, 1);
torus(dryingRack, 0.4, 0.025, [x, 0.65, -0.62], M.bambooLight, [
Math.PI / 2,
0,
0
]);
});
// -------------------------------------------------------------------------
// Chapter 3: grain store
// -------------------------------------------------------------------------
const grainStore = new THREE.Group();
grainStore.position.x = 4.05;
scene.add(grainStore);
[-1.8, 0, 1.8].forEach((x) => {
[-1.55, 1.55].forEach((z) => {
box(grainStore, [0.22, 1.25, 0.22], [x, 0.62, z], M.woodDark);
});
});
for (let i = 0; i < 12; i++) {
box(
grainStore,
[0.36, 0.16, 3.55],
[-2.05 + i * 0.37, 1.23, 0],
i % 2 ? M.wood : M.woodLight
);
}
box(grainStore, [4.45, 2.1, 0.16], [0, 2.28, -1.78], M.wood);
box(grainStore, [0.16, 2.1, 3.55], [-2.18, 2.28, 0], M.wood);
box(grainStore, [0.16, 2.1, 3.55], [2.18, 2.28, 0], M.wood);
for (let i = 0; i < 8; i++) {
box(
grainStore,
[0.08, 1.5, 0.09],
[-1.75 + i * 0.5, 2.2, -1.67],
M.woodDark
);
}
box(grainStore, [4.75, 0.19, 0.22], [0, 3.25, 1.65], M.woodDark);
box(grainStore, [0.2, 3.0, 0.2], [-2.05, 2.42, 1.6], M.woodDark);
box(grainStore, [0.2, 3.0, 0.2], [2.05, 2.42, 1.6], M.woodDark);
box(grainStore, [5.15, 0.19, 2.45], [0, 3.5, 0.92], M.thatch, [0.41, 0, 0]);
box(grainStore, [5.15, 0.19, 2.45], [0, 3.5, -0.92], M.thatchDark, [-0.41, 0, 0]);
box(grainStore, [5.35, 0.16, 0.17], [0, 3.95, 0], M.woodDark);
// Sacks.
function makeSack(parent, x, y, z, scale = 1) {
const sack = ico(parent, 0.56, [x, y, z], M.sack);
sack.scale.set(0.9 * scale, 1.15 * scale, 0.78 * scale);
const neck = cylinder(
parent,
0.19 * scale,
0.24 * scale,
0.16 * scale,
[x, y + 0.52 * scale, z],
M.sackDark,
7
);
neck.scale.z = 0.8;
torus(
parent,
0.2 * scale,
0.024 * scale,
[x, y + 0.48 * scale, z],
M.woodDark,
[Math.PI / 2, 0, 0]
);
return sack;
}
makeSack(grainStore, -1.35, 1.72, -0.4, 0.95);
makeSack(grainStore, -0.35, 1.65, -0.72, 1.05);
makeSack(grainStore, 0.82, 1.69, -0.48, 0.92);
makeSack(grainStore, 1.55, 1.62, -0.92, 0.76);
// Raised grain bin.
cylinder(grainStore, 0.56, 0.47, 0.9, [1.35, 1.78, 0.72], M.bambooDark, 10);
cylinder(grainStore, 0.58, 0.58, 0.07, [1.35, 2.25, 0.72], M.riceLight, 10);
// Bundles under the eave.
[-1.2, 0, 1.2].forEach((x) => {
cylinder(grainStore, 0.03, 0.03, 0.35, [x, 2.91, 1.1], M.bambooDark, 6);
const bundle = cylinder(
grainStore,
0.035,
0.22,
0.63,
[x, 2.3, 1.1],
M.rice,
7,
[0, 0, Math.PI]
);
bundle.scale.z = 0.7;
});
// -------------------------------------------------------------------------
// Chapter 4: kitchen
// -------------------------------------------------------------------------
const kitchen = new THREE.Group();
kitchen.position.x = 11.05;
scene.add(kitchen);
box(kitchen, [4.6, 0.18, 3.7], [0, 0.12, 0], M.woodLight);
[-2, 2].forEach((x) => {
[-1.5, 1.5].forEach((z) => {
box(kitchen, [0.18, 3.15, 0.18], [x, 1.62, z], M.woodDark);
});
});
box(kitchen, [4.4, 1.8, 0.14], [0, 1.9, -1.48], M.woodLight);
box(kitchen, [4.65, 0.18, 2.02], [0, 3.3, 0.93], M.roof, [0.37, 0, 0]);
box(kitchen, [4.65, 0.18, 2.02], [0, 3.3, -0.93], M.roofDark, [-0.37, 0, 0]);
// Counter and cabinets.
box(kitchen, [3.7, 0.9, 1.25], [-0.1, 0.64, 0.02], M.wood);
box(kitchen, [3.9, 0.14, 1.42], [-0.1, 1.13, 0.02], M.woodLight);
[-1.25, -0.25, 0.75].forEach((x) => {
box(kitchen, [0.82, 0.64, 0.06], [x, 0.69, 0.67], M.woodDark);
box(kitchen, [0.18, 0.05, 0.07], [x, 0.74, 0.72], M.bambooLight);
});
// Stove and cooking pot.
cylinder(kitchen, 0.48, 0.52, 0.12, [-0.8, 1.27, 0], M.charcoal, 10);
cylinder(kitchen, 0.36, 0.44, 0.44, [-0.8, 1.53, 0], M.metal, 10);
cylinder(kitchen, 0.38, 0.38, 0.06, [-0.8, 1.78, 0], M.charcoal, 10);
cylinder(kitchen, 0.08, 0.08, 0.12, [-0.8, 1.86, 0], M.woodDark, 8);
box(kitchen, [0.12, 0.34, 0.13], [-0.8, 1.91, 0], M.charcoal);
const lid = cylinder(kitchen, 0.42, 0.4, 0.09, [-0.8, 1.82, 0], M.metal, 10);
lid.scale.z = 0.8;
// Bowl of prepared rice.
cylinder(kitchen, 0.38, 0.24, 0.26, [0.82, 1.34, 0.12], M.ceramic, 12);
const riceMound = ico(kitchen, 0.34, [0.82, 1.52, 0.12], M.riceCream);
riceMound.scale.set(1, 0.3, 1);
// Cutting board, bowl, and utensils.
box(kitchen, [0.72, 0.07, 0.48], [0.55, 1.24, 0.72], M.bambooLight, [0, 0.12, 0]);
cylinder(kitchen, 0.3, 0.25, 0.16, [1.55, 1.29, 0.42], M.ceramicLight, 10);
// Wall shelf and jars.
box(kitchen, [3.2, 0.11, 0.4], [0, 2.05, -1.22], M.woodDark);
[-1.05, -0.35, 0.35, 1.05].forEach((x, index) => {
const jar = cylinder(
kitchen,
0.18 + (index % 2) * 0.03,
0.2,
0.45,
[x, 2.33, -1.18],
index % 2 ? M.ceramic : M.sack,
8
);
cylinder(kitchen, 0.15, 0.15, 0.08, [x, 2.59, -1.18], M.woodDark, 8);
});
// Hanging utensils.
for (let i = 0; i < 4; i++) {
const x = -1.3 + i * 0.34;
cylinder(kitchen, 0.025, 0.025, 0.55, [x, 2.43, -1.02], M.metal, 6);
const spoon = ico(kitchen, 0.11, [x, 2.12, -1.02], M.metal);
spoon.scale.set(0.6, 1.1, 0.25);
}
// Steam puffs.
const steam = [];
for (let i = 0; i < 6; i++) {
const steamMaterial = new THREE.MeshBasicMaterial({
color: 0xf3f0df,
transparent: true,
opacity: 0.28,
depthWrite: false
});
const puff = ico(kitchen, 0.13, [-0.8, 2.1, 0], steamMaterial);
steam.push({ mesh: puff, phase: i / 6, speed: 0.27 + i * 0.015 });
}
// -------------------------------------------------------------------------
// People
// -------------------------------------------------------------------------
function makePerson(parent, position, shirtMat, isFarmer = false) {
const person = new THREE.Group();
person.position.set(...position);
parent.add(person);
cylinder(person, 0.07, 0.08, 0.48, [-0.12, 0.28, 0], M.woodDark, 6);
cylinder(person, 0.07, 0.08, 0.48, [0.12, 0.28, 0], M.woodDark, 6);
cylinder(person, 0.2, 0.27, 0.55, [0, 0.72, 0], shirtMat, 7);
ico(person, 0.18, [0, 1.15, 0], M.skin, 1);
cylinder(person, 0.28, 0.28, 0.06, [0, 1.31, 0], M.hat, 10);
cylinder(person, 0.13, 0.2, 0.2, [0, 1.42, 0], M.hat, 8);
cylinder(person, 0.055, 0.065, 0.48, [-0.3, 0.74, 0], shirtMat, 6, [0, 0, -0.35]);
cylinder(person, 0.055, 0.065, 0.48, [0.3, 0.74, 0], shirtMat, 6, [0, 0, 0.35]);
if (isFarmer) {
cylinder(person, 0.025, 0.025, 1.7, [0.52, 0.65, 0], M.bamboo, 6, [0, 0, 0.12]);
}
return person;
}
makePerson(scene, [-7.5, 0.08, 1.12], M.shirt, true);
makePerson(kitchen, [1.5, 0.22, 1.45], M.shirtBlue, false);
// -------------------------------------------------------------------------
// Background scenery
// -------------------------------------------------------------------------
function makeTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0.06, z);
tree.scale.setScalar(scale);
scene.add(tree);
cylinder(tree, 0.12, 0.18, 1.4, [0, 0.7, 0], M.trunk, 6);
ico(tree, 0.9, [0, 1.65, 0], M.grassDark);
ico(tree, 0.68, [-0.35, 2.12, 0.08], M.grass);
ico(tree, 0.62, [0.35, 2.0, -0.08], M.grassLight);
}
[
[-14.2, -3.8, 1.0],
[-6.6, -4.2, 0.82],
[0.25, -4.15, 0.9],
[8.0, -4.25, 0.86],
[15.0, -2.7, 1.05],
[-13.7, 4.1, 0.72],
[15.2, 3.8, 0.74]
].forEach((args) => makeTree(...args));
[
[-17.5, -8.7, 5.7, 4.4],
[-10.5, -9.5, 6.4, 5.3],
[-2.2, -9.0, 5.4, 4.1],
[6.3, -9.6, 6.8, 5.7],
[15.1, -8.5, 5.6, 4.8]
].forEach(([x, z, radius, height], index) => {
const hill = new THREE.Mesh(
new THREE.ConeGeometry(radius, height, 6),
index % 2 ? M.hill : M.hillFar
);
hill.position.set(x, height * 0.5 - 0.08, z);
hill.rotation.y = index * 0.63;
hill.receiveShadow = true;
scene.add(hill);
});
const clouds = [];
[
[-9, 8.5, -10, 1.1],
[5.5, 10, -12, 1.35],
[14, 7.8, -9, 0.85]
].forEach(([x, y, z, scale], index) => {
const cloud = new THREE.Group();
cloud.position.set(x, y, z);
cloud.scale.setScalar(scale);
scene.add(cloud);
ico(cloud, 0.72, [-0.7, 0, 0], M.cloud);
ico(cloud, 0.9, [0, 0.18, 0], M.cloud);
ico(cloud, 0.68, [0.7, 0, 0], M.cloud);
clouds.push({ group: cloud, speed: 0.025 + index * 0.006 });
});
const sun = new THREE.Mesh(
new THREE.IcosahedronGeometry(1.1, 1),
new THREE.MeshBasicMaterial({ color: 0xffd477 })
);
sun.position.set(-15, 11, -16);
scene.add(sun);
// Tiny field flowers.
for (let i = 0; i < 42; i++) {
const x = -14.5 + random() * 29;
const z = random() > 0.5 ? -3.7 + random() * 1.2 : 4.4 + random() * 0.7;
if (Math.abs(x + 10.65) < 3 || Math.abs(x + 3.45) < 2.5 ||
Math.abs(x - 4.05) < 2.8 || Math.abs(x - 11.05) < 2.8) continue;
cylinder(scene, 0.015, 0.018, 0.2, [x, 0.16, z], M.leaf, 4);
ico(scene, 0.065, [x, 0.29, z], i % 3 ? M.riceLight : M.ceramicLight);
}
// -------------------------------------------------------------------------
// In-world chapter labels made from canvas textures
// -------------------------------------------------------------------------
function makeLabel(text, position) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 112;
const ctx = labelCanvas.getContext("2d");
ctx.clearRect(0, 0, 512, 112);
const x = 12;
const y = 12;
const w = 488;
const h = 88;
const r = 22;
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + w - r, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
ctx.lineTo(x + w, y + h - r);
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
ctx.lineTo(x + r, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
ctx.fillStyle = "rgba(255, 250, 240, 0.94)";
ctx.fill();
ctx.strokeStyle = "rgba(23, 63, 50, 0.28)";
ctx.lineWidth = 4;
ctx.stroke();
ctx.fillStyle = "#173f32";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "700 31px system-ui, sans-serif";
ctx.fillText(text, 256, 55);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.position.set(...position);
sprite.scale.set(4.1, 0.9, 1);
sprite.renderOrder = 20;
scene.add(sprite);
return sprite;
}
makeLabel("IRRIGATED PADDY", [-10.65, 3.35, -1.5]);
makeLabel("DRYING RACK", [-3.45, 4.05, -0.65]);
makeLabel("GRAIN STORE", [4.05, 4.75, -1.15]);
makeLabel("KITCHEN", [11.05, 4.05, -0.85]);
// -------------------------------------------------------------------------
// Animated rice route
// -------------------------------------------------------------------------
const route = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(-10.7, 0.38, 0.8),
new THREE.Vector3(-9.6, 0.46, 1.75),
new THREE.Vector3(-8.1, 0.34, 2.18),
new THREE.Vector3(-6.5, 0.28, 1.65),
new THREE.Vector3(-5.25, 0.35, 0.45),
new THREE.Vector3(-3.45, 3.05, 0.15),
new THREE.Vector3(-2.0, 2.15, 0.5),
new THREE.Vector3(-0.2, 0.36, 1.4),
new THREE.Vector3(2.25, 0.35, 1.65),
new THREE.Vector3(3.65, 1.55, 0.35),
new THREE.Vector3(5.25, 1.4, -0.25),
new THREE.Vector3(7.4, 0.35, 1.25),
new THREE.Vector3(9.5, 0.35, 1.5),
new THREE.Vector3(10.95, 1.75, 0.3),
new THREE.Vector3(11.7, 1.48, 0.05)
],
false,
"catmullrom",
0.34
);
const routeGeometry = new THREE.BufferGeometry().setFromPoints(route.getPoints(180));
const routeMaterial = new THREE.LineDashedMaterial({
color: 0xe5a63c,
transparent: true,
opacity: 0.32,
dashSize: 0.18,
gapSize: 0.16
});
const routeLine = new THREE.Line(routeGeometry, routeMaterial);
routeLine.computeLineDistances();
scene.add(routeLine);
const grainCount = 76;
const grainGeometry = new THREE.IcosahedronGeometry(0.068, 0);
const grainMaterial = material(0xffdea0, {
roughness: 0.56,
emissive: 0x6f4307,
emissiveIntensity: 0.16
});
const movingGrains = new THREE.InstancedMesh(
grainGeometry,
grainMaterial,
grainCount
);
movingGrains.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
movingGrains.frustumCulled = false;
movingGrains.castShadow = true;
for (let i = 0; i < grainCount; i++) {
const color = new THREE.Color().setHSL(
0.115 + random() * 0.025,
0.64,
0.69 + random() * 0.12
);
movingGrains.setColorAt(i, color);
}
if (movingGrains.instanceColor) movingGrains.instanceColor.needsUpdate = true;
scene.add(movingGrains);
const grainDummy = new THREE.Object3D();
const up = new THREE.Vector3(0, 1, 0);
// -------------------------------------------------------------------------
// Custom camera controls
// -------------------------------------------------------------------------
const stages = [
{
title: "Irrigated paddy",
description:
"Shallow water cools the roots while young rice stalks rise in neat rows.",
target: new THREE.Vector3(-10.55, 1.05, 0),
radius: 9.1,
theta: 0.34,
phi: 1.02
},
{
title: "Drying rack",
description:
"Golden sheaves and bamboo trays turn in the sun, releasing moisture from the grain.",
target: new THREE.Vector3(-3.45, 1.7, 0),
radius: 8.6,
theta: 0.12,
phi: 1.02
},
{
title: "Grain store",
description:
"The harvest is gathered into sacks and raised bins, safe from damp and pests.",
target: new THREE.Vector3(4.05, 1.75, 0),
radius: 8.8,
theta: -0.08,
phi: 1.01
},
{
title: "Kitchen",
description:
"Cleaned rice becomes a warm meal—where a season of careful work becomes nourishment.",
target: new THREE.Vector3(11.0, 1.55, 0),
radius: 8.5,
theta: -0.23,
phi: 1.02
}
];
const goal = {
target: new THREE.Vector3(0, 1.05, 0),
radius: 22,
theta: 0.1,
phi: 1.05
};
const current = {
target: goal.target.clone(),
radius: goal.radius,
theta: goal.theta,
phi: goal.phi
};
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function setCameraFromOrbit() {
const sinPhi = Math.sin(current.phi);
camera.position.set(
current.target.x + current.radius * sinPhi * Math.sin(current.theta),
current.target.y + current.radius * Math.cos(current.phi),
current.target.z + current.radius * sinPhi * Math.cos(current.theta)
);
camera.lookAt(current.target);
}
setCameraFromOrbit();
let activeStage = 0;
let tourRunning = false;
let tourTime = 0;
const tourDuration = 6.2;
const totalTourDuration = 25.5;
const chapterButtons = [...document.querySelectorAll(".chapter")];
const stageKicker = document.querySelector("#stageKicker");
const stageTitle = document.querySelector("#stageTitle");
const stageDescription = document.querySelector("#stageDescription");
const progressFill = document.querySelector("#progressFill");
const tourButton = document.querySelector("#tourButton");
const tourIcon = document.querySelector("#tourIcon");
const tourText = document.querySelector("#tourText");
function updateStageUI(index) {
activeStage = index;
const stage = stages[index];
chapterButtons.forEach((button, buttonIndex) => {
button.classList.toggle("active", buttonIndex === index);
});
stageKicker.textContent = `Chapter ${String(index + 1).padStart(2, "0")} / 04`;
stageTitle.textContent = stage.title;
stageDescription.textContent = stage.description;
progressFill.style.width = `${(index / (stages.length - 1)) * 100}%`;
}
function goToStage(index) {
const stage = stages[index];
goal.target.copy(stage.target);
goal.radius = stage.radius;
goal.theta = stage.theta;
goal.phi = stage.phi;
updateStageUI(index);
}
function stopTour() {
tourRunning = false;
tourIcon.textContent = "▶";
tourText.textContent = "Follow the grain";
}
function toggleTour() {
if (tourRunning) {
stopTour();
return;
}
tourRunning = true;
tourTime = 0;
goToStage(0);
tourIcon.textContent = "Ⅱ";
tourText.textContent = "Pause journey";
}
chapterButtons.forEach((button) => {
button.addEventListener("click", () => {
stopTour();
goToStage(Number(button.dataset.stage));
});
});
tourButton.addEventListener("click", toggleTour);
document.querySelector("#overviewButton").addEventListener("click", () => {
stopTour();
goal.target.set(0, 1.05, 0);
goal.radius = 22;
goal.theta = 0.1;
goal.phi = 1.05;
updateStageUI(0);
});
const pointer = {
active: false,
moved: false,
mode: "orbit",
x: 0,
y: 0
};
canvas.addEventListener("pointerdown", (event) => {
pointer.active = true;
pointer.moved = false;
pointer.mode =
event.button === 2 || event.shiftKey ? "pan" : "orbit";
pointer.x = event.clientX;
pointer.y = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!pointer.active) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (Math.abs(dx) + Math.abs(dy) > 2) pointer.moved = true;
if (!pointer.moved) return;
stopTour();
if (pointer.mode === "pan") {
const scale = goal.radius * 0.0015;
goal.target.x -= dx * scale;
goal.target.z += dy * scale;
goal.target.x = clamp(goal.target.x, -15, 15);
goal.target.z = clamp(goal.target.z, -6, 6);
} else {
goal.theta -= dx * 0.006;
goal.phi = clamp(goal.phi - dy * 0.005, 0.48, 1.38);
}
});
function releasePointer(event) {
pointer.active = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
stopTour();
goal.radius = clamp(goal.radius + event.deltaY * 0.012, 5.2, 29);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key >= "1" && event.key <= "4") {
stopTour();
goToStage(Number(event.key) - 1);
}
if (event.code === "Space") {
event.preventDefault();
toggleTour();
}
if (event.key === "ArrowLeft") {
stopTour();
goal.theta += 0.12;
}
if (event.key === "ArrowRight") {
stopTour();
goal.theta -= 0.12;
}
if (event.key === "ArrowUp") {
stopTour();
goal.phi = clamp(goal.phi - 0.08, 0.48, 1.38);
}
if (event.key === "ArrowDown") {
stopTour();
goal.phi = clamp(goal.phi + 0.08, 0.48, 1.38);
}
if (event.key === "Escape") {
stopTour();
goal.target.set(0, 1.05, 0);
goal.radius = 22;
goal.theta = 0.1;
goal.phi = 1.05;
}
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
elapsed += dt;
// Camera easing.
const cameraEase = 1 - Math.exp(-dt * 4.7);
current.target.lerp(goal.target, cameraEase);
current.radius += (goal.radius - current.radius) * cameraEase;
current.theta += (goal.theta - current.theta) * cameraEase;
current.phi += (goal.phi - current.phi) * cameraEase;
setCameraFromOrbit();
// Guided chapter progression.
if (tourRunning) {
tourTime += dt;
const nextStage = Math.min(3, Math.floor(tourTime / tourDuration));
if (nextStage !== activeStage) {
goToStage(nextStage);
}
progressFill.style.width = `${Math.min(100, (tourTime / totalTourDuration) * 100)}%`;
if (tourTime >= totalTourDuration) {
tourRunning = false;
tourIcon.textContent = "↻";
tourText.textContent = "Replay journey";
progressFill.style.width = "100%";
}
}
// Moving rice kernels.
const routeSpeed = tourRunning ? 0.048 : 0.034;
for (let i = 0; i < grainCount; i++) {
const u = (elapsed * routeSpeed * (0.8 + (i % 9) * 0.055) + i / grainCount) % 1;
const point = route.getPointAt(u);
const tangent = route.getTangentAt(u);
grainDummy.position.copy(point);
grainDummy.quaternion.setFromUnitVectors(up, tangent);
grainDummy.scale.set(0.72, 1.35, 0.72);
grainDummy.updateMatrix();
movingGrains.setMatrixAt(i, grainDummy.matrix);
}
movingGrains.instanceMatrix.needsUpdate = true;
// Paddy ripples.
ripples.forEach((ripple) => {
const phase = elapsed * ripple.speed + ripple.phase;
const scale = 0.8 + ((phase % 1) * 1.8);
ripple.mesh.scale.setScalar(scale);
ripple.mesh.material.opacity = Math.max(0, 0.35 * (1 - (phase % 1)));
});
// Kitchen steam.
steam.forEach((puff) => {
const phase = (elapsed * puff.speed + puff.phase) % 1;
puff.mesh.position.set(
-0.8 + Math.sin(phase * 7 + puff.phase * 10) * 0.13,
2.02 + phase * 1.25,
Math.cos(phase * 6 + puff.phase * 8) * 0.1
);
puff.mesh.scale.setScalar(0.45 + phase * 0.95);
puff.mesh.material.opacity = 0.3 * Math.sin(phase * Math.PI);
});
// Very slow cloud drift.
clouds.forEach((cloud) => {
cloud.group.position.x += cloud.speed * dt;
if (cloud.group.position.x > 18) cloud.group.position.x = -18;
});
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
updateStageUI(0);
animate();
requestAnimationFrame(() => {
document.body.classList.add("ready");
});
</script>
</body>
</html>
```