Prompt specification
Build or customize the Three.js 3D scene "Covered-pot water uptake model" 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: Covered-pot water uptake model
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/covered-pot-water-uptake-model-x0146
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts rice and water absorption. Show a pot cutaway with grains and water; a qualitative timeline expands the grains while lowering free water, keeping steam as a separate visible pathway. Voxel style.
Working Three.js Starter (covered-pot-water-uptake-model-x0146):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Rice & Water Absorption — Voxel Timeline</title>
<style>
:root {
color-scheme: dark;
--bg: #07131d;
--panel: rgba(9, 24, 35, 0.86);
--panel-border: rgba(165, 211, 224, 0.18);
--text: #eaf7f8;
--muted: #8ca8b1;
--cyan: #42c8ef;
--cyan-soft: #8be5ff;
--rice: #f4dfaa;
--steam: #ffd47c;
--green: #8de1b6;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 48% 38%, #173747 0%, #0a1c29 42%, #06111a 100%);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
body {
position: relative;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
#scene canvas.dragging {
cursor: grabbing;
}
.ui {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.panel {
border: 1px solid var(--panel-border);
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.brand {
position: absolute;
top: 24px;
left: 26px;
max-width: 440px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--cyan-soft);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 24px;
height: 3px;
background: var(--cyan);
box-shadow: 8px 0 0 rgba(66, 200, 239, 0.35);
}
h1 {
margin: 0;
font-size: clamp(27px, 3.3vw, 48px);
line-height: 0.98;
letter-spacing: -0.045em;
}
.brand p {
max-width: 380px;
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.legend {
position: absolute;
top: 24px;
right: 26px;
width: 218px;
padding: 14px 15px;
border-radius: 14px;
pointer-events: auto;
}
.legend-title {
margin-bottom: 11px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 13px 1fr auto;
align-items: center;
gap: 9px;
padding: 6px 0;
font-size: 12px;
}
.legend-row small {
color: var(--muted);
font-size: 10px;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 2px;
box-shadow: 0 0 14px currentColor;
}
.swatch.water {
color: var(--cyan);
background: var(--cyan);
}
.swatch.rice {
color: var(--rice);
background: var(--rice);
}
.swatch.steam {
color: var(--steam);
background: var(--steam);
}
.view-reset {
width: 100%;
margin-top: 10px;
padding: 8px 10px;
border: 1px solid rgba(139, 229, 255, 0.18);
border-radius: 8px;
color: var(--muted);
background: rgba(139, 229, 255, 0.05);
font: inherit;
font-size: 10px;
cursor: pointer;
}
.view-reset:hover {
color: var(--text);
background: rgba(139, 229, 255, 0.11);
}
.model-card {
position: absolute;
top: 174px;
left: 26px;
width: 250px;
padding: 16px;
border-radius: 14px;
}
.model-card h2 {
margin: 0 0 4px;
font-size: 13px;
letter-spacing: -0.01em;
}
.model-card > p {
margin: 0 0 15px;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.metric {
margin-top: 12px;
}
.metric-heading {
display: flex;
justify-content: space-between;
margin-bottom: 6px;
font-size: 10px;
}
.metric-heading span:first-child {
color: var(--muted);
}
.metric-heading span:last-child {
font-weight: 800;
letter-spacing: 0.08em;
}
.meter {
height: 6px;
overflow: hidden;
border-radius: 2px;
background: rgba(255, 255, 255, 0.08);
}
.meter > div {
height: 100%;
width: 0;
transition: width 80ms linear;
}
#grainFill {
background: var(--rice);
}
#waterFill {
background: var(--cyan);
}
.steam-row {
display: flex;
align-items: center;
gap: 8px;
margin-top: 15px;
padding-top: 12px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
color: var(--steam);
font-size: 10px;
}
.steam-row b {
font-size: 11px;
}
.steam-row small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
.steam-row .steam-dashes {
display: flex;
gap: 3px;
align-items: flex-end;
}
.steam-dashes i {
display: block;
width: 4px;
background: var(--steam);
border-radius: 1px;
}
.steam-dashes i:nth-child(1) { height: 8px; }
.steam-dashes i:nth-child(2) { height: 14px; }
.steam-dashes i:nth-child(3) { height: 20px; }
.annotation {
position: fixed;
z-index: 6;
display: flex;
align-items: center;
gap: 9px;
min-width: 132px;
padding: 8px 10px;
transform: translate(-50%, -50%);
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 9px;
background: rgba(6, 17, 26, 0.82);
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
pointer-events: none;
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
}
.annotation::after {
content: "";
position: absolute;
top: 50%;
left: -22px;
width: 21px;
height: 1px;
background: currentColor;
opacity: 0.55;
}
.annotation .icon {
display: grid;
width: 25px;
height: 25px;
place-items: center;
border-radius: 6px;
color: #06131c;
font-size: 13px;
font-weight: 900;
}
.annotation b {
display: block;
font-size: 11px;
}
.annotation small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
white-space: nowrap;
}
#riceCallout {
color: var(--rice);
}
#riceCallout .icon {
background: var(--rice);
}
#waterCallout {
color: var(--cyan);
}
#waterCallout .icon {
background: var(--cyan);
}
#steamCallout {
color: var(--steam);
}
#steamCallout .icon {
background: var(--steam);
}
.timeline-shell {
position: absolute;
bottom: 22px;
left: 50%;
width: min(930px, calc(100% - 40px));
transform: translateX(-50%);
padding: 15px 18px 14px;
border-radius: 16px;
pointer-events: auto;
}
.timeline-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
margin-bottom: 11px;
}
.phase-title {
display: flex;
align-items: baseline;
gap: 9px;
min-width: 0;
}
.phase-title strong {
font-size: 13px;
white-space: nowrap;
}
.phase-title span {
overflow: hidden;
color: var(--muted);
font-size: 10px;
text-overflow: ellipsis;
white-space: nowrap;
}
.timeline-actions {
display: flex;
flex-shrink: 0;
gap: 7px;
}
button {
font: inherit;
}
.play-button,
.reset-button {
height: 31px;
border-radius: 8px;
cursor: pointer;
}
.play-button {
min-width: 82px;
border: 1px solid rgba(66, 200, 239, 0.4);
color: #071722;
background: var(--cyan);
font-size: 10px;
font-weight: 900;
}
.play-button:hover {
background: var(--cyan-soft);
}
.reset-button {
width: 31px;
border: 1px solid rgba(255, 255, 255, 0.13);
color: var(--muted);
background: rgba(255, 255, 255, 0.04);
font-size: 16px;
}
.reset-button:hover {
color: var(--text);
background: rgba(255, 255, 255, 0.09);
}
.range-wrap {
position: relative;
height: 17px;
}
#timeline {
--fill: 0%;
position: absolute;
inset: 0;
width: 100%;
height: 17px;
margin: 0;
appearance: none;
-webkit-appearance: none;
background:
linear-gradient(
to right,
var(--cyan) 0%,
var(--cyan) var(--fill),
rgba(255, 255, 255, 0.1) var(--fill),
rgba(255, 255, 255, 0.1) 100%
)
center / 100% 5px no-repeat;
cursor: pointer;
}
#timeline::-webkit-slider-thumb {
width: 14px;
height: 14px;
appearance: none;
-webkit-appearance: none;
border: 3px solid #dffaff;
border-radius: 2px;
background: var(--cyan);
box-shadow: 0 0 0 4px rgba(66, 200, 239, 0.14);
}
#timeline::-moz-range-thumb {
width: 10px;
height: 10px;
border: 3px solid #dffaff;
border-radius: 2px;
background: var(--cyan);
box-shadow: 0 0 0 4px rgba(66, 200, 239, 0.14);
}
.milestones {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: 4px;
margin-top: 7px;
}
.milestone {
padding: 0;
border: 0;
color: #647f89;
background: transparent;
font-size: 9px;
text-align: left;
cursor: pointer;
}
.milestone span {
display: block;
margin-bottom: 4px;
color: #48636e;
font-size: 8px;
font-variant-numeric: tabular-nums;
}
.milestone.active,
.milestone:hover {
color: var(--text);
}
.milestone.active span {
color: var(--cyan);
}
.hint {
position: absolute;
right: 26px;
bottom: 148px;
color: rgba(173, 203, 211, 0.55);
font-size: 9px;
letter-spacing: 0.04em;
pointer-events: none;
}
@media (max-width: 780px) {
.brand {
top: 18px;
left: 18px;
}
.brand p {
display: none;
}
.legend {
top: 16px;
right: 16px;
width: 154px;
padding: 10px;
}
.legend-row {
grid-template-columns: 10px 1fr;
gap: 7px;
font-size: 10px;
}
.legend-row small,
.view-reset {
display: none;
}
.model-card,
.annotation,
.hint {
display: none;
}
.timeline-shell {
bottom: 10px;
width: calc(100% - 20px);
padding: 12px;
}
.phase-title span {
display: none;
}
.milestone {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="ui">
<header class="brand">
<div class="eyebrow">Qualitative material study</div>
<h1>Rice &<br>Water Absorption</h1>
<p>
A cutaway voxel model: free water falls while the grains swell.
Warm vapor remains a distinct outward pathway.
</p>
</header>
<aside class="legend panel">
<div class="legend-title">Visible components</div>
<div class="legend-row">
<span class="swatch water"></span>
<span>Free water</span>
<small>falls</small>
</div>
<div class="legend-row">
<span class="swatch rice"></span>
<span>Rice body</span>
<small>swells</small>
</div>
<div class="legend-row">
<span class="swatch steam"></span>
<span>Steam</span>
<small>separate</small>
</div>
<button id="resetView" class="view-reset" type="button">
Reset camera view
</button>
</aside>
<aside class="model-card panel">
<h2>Inside the cutaway</h2>
<p>Qualitative only — not a measured time or absorption rate.</p>
<div class="metric">
<div class="metric-heading">
<span>Grain volume</span>
<span id="grainState">COMPACT</span>
</div>
<div class="meter"><div id="grainFill"></div></div>
</div>
<div class="metric">
<div class="metric-heading">
<span>Free water</span>
<span id="waterState">HIGH</span>
</div>
<div class="meter"><div id="waterFill"></div></div>
</div>
<div class="steam-row">
<span class="steam-dashes"><i></i><i></i><i></i></span>
<div>
<b>Warm vapor route</b>
<small>Not counted as remaining liquid water.</small>
</div>
</div>
</aside>
<div id="riceCallout" class="annotation">
<span class="icon">▦</span>
<div><b>Rice grains</b><small id="riceDetail">absorbing water</small></div>
</div>
<div id="waterCallout" class="annotation">
<span class="icon">≈</span>
<div><b>Free water</b><small id="waterDetail">high level</small></div>
</div>
<div id="steamCallout" class="annotation">
<span class="icon">↑</span>
<div><b>Steam pathway</b><small>warm vapor exits above</small></div>
</div>
<section class="timeline-shell panel">
<div class="timeline-top">
<div class="phase-title">
<strong id="phaseName">Water available</strong>
<span id="phaseNote">Free water surrounds the compact grains.</span>
</div>
<div class="timeline-actions">
<button id="playButton" class="play-button" type="button">▶ Play</button>
<button id="resetTimeline" class="reset-button" type="button"
title="Reset timeline" aria-label="Reset timeline">↺</button>
</div>
</div>
<div class="range-wrap">
<input id="timeline" type="range" min="0" max="1000" value="120"
aria-label="Rice absorption timeline">
</div>
<div class="milestones">
<button class="milestone" type="button" data-progress="0">
<span>01</span>Dry grain
</button>
<button class="milestone" type="button" data-progress="0.22">
<span>02</span>Water present
</button>
<button class="milestone" type="button" data-progress="0.48">
<span>03</span>Absorption
</button>
<button class="milestone" type="button" data-progress="0.74">
<span>04</span>Swelling
</button>
<button class="milestone" type="button" data-progress="1">
<span>05</span>Near balance
</button>
</div>
</section>
<div class="hint">DRAG TO ORBIT · SCROLL TO ZOOM · DOUBLE-CLICK TO RESET</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// DOM and shared state
// -------------------------------------------------------------------------
const sceneHost = document.querySelector("#scene");
const timelineInput = document.querySelector("#timeline");
const playButton = document.querySelector("#playButton");
const resetTimelineButton = document.querySelector("#resetTimeline");
const resetViewButton = document.querySelector("#resetView");
const phaseName = document.querySelector("#phaseName");
const phaseNote = document.querySelector("#phaseNote");
const grainState = document.querySelector("#grainState");
const waterState = document.querySelector("#waterState");
const grainFill = document.querySelector("#grainFill");
const waterFill = document.querySelector("#waterFill");
const riceDetail = document.querySelector("#riceDetail");
const waterDetail = document.querySelector("#waterDetail");
const milestoneButtons = [
...document.querySelectorAll(".milestone")
];
const state = {
progress: Number(timelineInput.value) / 1000,
playing: false,
elapsed: 0
};
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
function smoothstep(a, b, value) {
const x = clamp((value - a) / (b - a), 0, 1);
return x * x * (3 - 2 * x);
}
function seededRandom(seed) {
return function () {
let t = seed += 0x6D2B79F5;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = seededRandom(91827);
// -------------------------------------------------------------------------
// Renderer, scene, lighting
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: 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;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x081923, 0.025);
const camera = new THREE.PerspectiveCamera(
45,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 0.65, 0);
const cameraHome = {
azimuth: 0.52,
polar: 1.18,
radius: 12.2
};
const cameraState = { ...cameraHome };
function updateCamera() {
const { azimuth, polar, radius } = cameraState;
camera.position.set(
cameraTarget.x +
radius * Math.sin(polar) * Math.sin(azimuth),
cameraTarget.y + radius * Math.cos(polar),
cameraTarget.z +
radius * Math.sin(polar) * Math.cos(azimuth)
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0x9bdfff, 0x14232d, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffdfae, 3.1);
keyLight.position.set(5.5, 9, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -6;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x55d6ff, 1.8);
rimLight.position.set(-6, 4, -5);
scene.add(rimLight);
const steamLight = new THREE.PointLight(0xffc86d, 1.6, 8, 2);
steamLight.position.set(0, 2.7, 0);
scene.add(steamLight);
// -------------------------------------------------------------------------
// Ground and voxel plinth
// -------------------------------------------------------------------------
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x07141d,
roughness: 0.95,
metalness: 0.05
});
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -2.66;
floor.receiveShadow = true;
scene.add(floor);
const plinth = new THREE.Mesh(
new THREE.CylinderGeometry(4.15, 4.45, 0.34, 16),
new THREE.MeshStandardMaterial({
color: 0x102a37,
roughness: 0.82,
metalness: 0.16,
flatShading: true
})
);
plinth.position.y = -2.47;
plinth.receiveShadow = true;
plinth.castShadow = true;
scene.add(plinth);
const plinthTop = new THREE.Mesh(
new THREE.CylinderGeometry(3.75, 3.75, 0.08, 16),
new THREE.MeshStandardMaterial({
color: 0x163442,
roughness: 0.76,
metalness: 0.22,
flatShading: true
})
);
plinthTop.position.y = -2.27;
plinthTop.receiveShadow = true;
scene.add(plinthTop);
// -------------------------------------------------------------------------
// Voxel pot with a missing front sector
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const wallMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.64,
metalness: 0.32,
flatShading: true
});
const wallCells = [];
const wallSegments = 48;
const wallRows = 8;
const openingAngle = 1.06;
const openingHalfWidth = 0.73;
function angularDistance(a, b) {
return Math.atan2(Math.sin(a - b), Math.cos(a - b));
}
for (let row = 0; row < wallRows; row++) {
const y = -1.96 + row * 0.48;
for (let segment = 0; segment < wallSegments; segment++) {
const theta = (segment / wallSegments) * Math.PI * 2;
const nearOpening =
Math.abs(angularDistance(theta, openingAngle)) < openingHalfWidth;
// Keep the lowest ring intact so the vessel reads as a pot.
if (row > 0 && nearOpening) continue;
wallCells.push({
theta,
y,
row,
segment,
rim: row === wallRows - 1
});
}
}
const wallMesh = new THREE.InstancedMesh(
unitBox,
wallMaterial,
wallCells.length
);
wallMesh.castShadow = true;
wallMesh.receiveShadow = true;
const dummy = new THREE.Object3D();
const steelPalette = [
0x294653,
0x315564,
0x3a5d69,
0x243f4c,
0x42616a
];
wallCells.forEach((cell, index) => {
const tangentWidth = (2 * Math.PI * 2.93) / wallSegments + 0.025;
dummy.position.set(
Math.cos(cell.theta) * 2.93,
cell.y,
Math.sin(cell.theta) * 2.93
);
dummy.rotation.set(
0,
Math.PI / 2 - cell.theta,
0
);
dummy.scale.set(
tangentWidth,
cell.rim ? 0.23 : 0.44,
cell.rim ? 0.40 : 0.30
);
dummy.updateMatrix();
wallMesh.setMatrixAt(index, dummy.matrix);
let color = new THREE.Color(
steelPalette[Math.floor(random() * steelPalette.length)]
);
if (cell.rim) color.multiplyScalar(1.18);
wallMesh.setColorAt(index, color);
});
wallMesh.instanceMatrix.needsUpdate = true;
if (wallMesh.instanceColor) wallMesh.instanceColor.needsUpdate = true;
scene.add(wallMesh);
const potBase = new THREE.Mesh(
new THREE.CylinderGeometry(2.95, 2.95, 0.32, 16),
new THREE.MeshStandardMaterial({
color: 0x294653,
roughness: 0.7,
metalness: 0.3,
flatShading: true
})
);
potBase.position.y = -2.18;
potBase.castShadow = true;
potBase.receiveShadow = true;
scene.add(potBase);
const handleMaterial = new THREE.MeshStandardMaterial({
color: 0x203b48,
roughness: 0.58,
metalness: 0.42,
flatShading: true
});
for (const side of [-1, 1]) {
const handle = new THREE.Group();
const vertical = new THREE.Mesh(
new THREE.BoxGeometry(0.25, 1.35, 0.32),
handleMaterial
);
vertical.position.set(side * 3.38, 0.2, 0);
const upper = new THREE.Mesh(
new THREE.BoxGeometry(0.8, 0.18, 0.32),
handleMaterial
);
upper.position.set(side * 3.08, 0.78, 0);
const lower = upper.clone();
lower.position.y = -0.38;
handle.add(vertical, upper, lower);
handle.traverse(object => {
if (object.isMesh) object.castShadow = true;
});
scene.add(handle);
}
// -------------------------------------------------------------------------
// Free water: a faceted body plus a pixelated surface
// -------------------------------------------------------------------------
const waterBottom = -2.0;
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x35c9f0,
transparent: true,
opacity: 0.19,
roughness: 0.24,
metalness: 0.08,
depthWrite: false,
side: THREE.DoubleSide,
flatShading: true
});
const waterVolume = new THREE.Mesh(
new THREE.CylinderGeometry(2.48, 2.48, 1, 24),
waterMaterial
);
waterVolume.renderOrder = 2;
scene.add(waterVolume);
const waterSurfaceMaterial = new THREE.MeshStandardMaterial({
color: 0x6bdcff,
transparent: true,
opacity: 0.4,
roughness: 0.18,
metalness: 0.05,
depthWrite: false,
emissive: 0x0d4a63,
emissiveIntensity: 0.35
});
const surfaceCells = [];
const cellSize = 0.25;
for (let x = -2.375; x <= 2.375; x += cellSize) {
for (let z = -2.375; z <= 2.375; z += cellSize) {
if (x * x + z * z < 2.39 * 2.39) {
surfaceCells.push({ x, z });
}
}
}
const waterSurface = new THREE.InstancedMesh(
unitBox,
waterSurfaceMaterial,
surfaceCells.length
);
waterSurface.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
waterSurface.renderOrder = 3;
scene.add(waterSurface);
// -------------------------------------------------------------------------
// Rice: three instanced voxel pieces per grain
// -------------------------------------------------------------------------
const grainCount = 180;
const grains = [];
for (let layer = 0; layer < 6; layer++) {
const radius = 2.18 - layer * 0.12;
for (let i = 0; i < 30; i++) {
const theta = random() * Math.PI * 2;
const r = Math.sqrt(random()) * radius;
const euler = new THREE.Euler(
(random() - 0.5) * 0.34,
random() * Math.PI * 2,
(random() - 0.5) * 0.34
);
grains.push({
x: Math.cos(theta) * r,
y: -1.43 + layer * 0.46 + (random() - 0.5) * 0.13,
z: Math.sin(theta) * r,
layer,
quaternion: new THREE.Quaternion().setFromEuler(euler),
tone: random()
});
}
}
const riceBodyMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.82,
metalness: 0,
flatShading: true
});
const riceBody = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.34, 0.14, 0.15),
riceBodyMaterial,
grainCount
);
const riceHead = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.14, 0.14, 0.15),
riceBodyMaterial,
grainCount
);
const riceTip = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.08, 0.10, 0.11),
riceBodyMaterial,
grainCount
);
for (const mesh of [riceBody, riceHead, riceTip]) {
mesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
}
const ricePalette = [
0xf3dfad,
0xe8cf94,
0xffedc8,
0xd9bc7e,
0xf8e6bc
];
grains.forEach((grain, index) => {
const color = new THREE.Color(
ricePalette[Math.floor(grain.tone * ricePalette.length)]
);
riceBody.setColorAt(index, color);
riceHead.setColorAt(index, color);
riceTip.setColorAt(index, color);
});
if (riceBody.instanceColor) riceBody.instanceColor.needsUpdate = true;
if (riceHead.instanceColor) riceHead.instanceColor.needsUpdate = true;
if (riceTip.instanceColor) riceTip.instanceColor.needsUpdate = true;
// -------------------------------------------------------------------------
// Blue absorption tracers move inward toward the grains
// -------------------------------------------------------------------------
const tracerCount = 22;
const tracerMesh = new THREE.InstancedMesh(
unitBox,
new THREE.MeshStandardMaterial({
color: 0x4dd8ff,
emissive: 0x145a75,
emissiveIntensity: 0.75,
roughness: 0.35,
transparent: true,
opacity: 0.82,
depthWrite: false
}),
tracerCount
);
tracerMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
tracerMesh.renderOrder = 4;
scene.add(tracerMesh);
const tracerData = Array.from({ length: tracerCount }, () => ({
phase: random(),
theta: random() * Math.PI * 2,
height: -1.1 + random() * 2.0,
speed: 0.7 + random() * 0.5
}));
// -------------------------------------------------------------------------
// Separate golden steam pathway
// -------------------------------------------------------------------------
const steamCount = 46;
const steamMesh = new THREE.InstancedMesh(
unitBox,
new THREE.MeshStandardMaterial({
color: 0xffd783,
emissive: 0x6b3e0d,
emissiveIntensity: 0.5,
roughness: 0.9,
transparent: true,
opacity: 0.48,
depthWrite: false,
flatShading: true
}),
steamCount
);
steamMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
steamMesh.renderOrder = 5;
scene.add(steamMesh);
const steamData = Array.from({ length: steamCount }, () => ({
phase: random(),
x: (random() - 0.5) * 1.7,
z: (random() - 0.5) * 1.5,
size: 0.1 + random() * 0.075,
drift: random() * Math.PI * 2
}));
// -------------------------------------------------------------------------
// Scene animation
// -------------------------------------------------------------------------
const worldPosition = new THREE.Vector3();
const localOffset = new THREE.Vector3();
const scaleVector = new THREE.Vector3();
const matrix = new THREE.Matrix4();
function setInstance(
mesh,
index,
position,
quaternion,
scaleX,
scaleY,
scaleZ
) {
scaleVector.set(scaleX, scaleY, scaleZ);
matrix.compose(position, quaternion, scaleVector);
mesh.setMatrixAt(index, matrix);
}
function updateRice(progress) {
const lengthScale = 1 + 0.48 * progress;
const thicknessScale = 1 + 1.05 * smoothstep(0.02, 0.95, progress);
grains.forEach((grain, index) => {
const lift = progress * (0.07 + grain.layer * 0.105);
worldPosition.set(
grain.x * (1 + 0.035 * progress),
grain.y + lift,
grain.z * (1 + 0.035 * progress)
);
const segments = [
{
mesh: riceBody,
offset: -0.04,
sx: lengthScale,
sy: thicknessScale,
sz: thicknessScale
},
{
mesh: riceHead,
offset: 0.18,
sx: lengthScale,
sy: thicknessScale,
sz: thicknessScale
},
{
mesh: riceTip,
offset: 0.29,
sx: lengthScale,
sy: thicknessScale * 0.78,
sz: thicknessScale * 0.78
}
];
for (const segment of segments) {
localOffset
.set(segment.offset * lengthScale, 0, 0)
.applyQuaternion(grain.quaternion);
worldPosition.add(localOffset);
setInstance(
segment.mesh,
index,
worldPosition,
grain.quaternion,
segment.sx,
segment.sy,
segment.sz
);
worldPosition.sub(localOffset);
}
});
riceBody.instanceMatrix.needsUpdate = true;
riceHead.instanceMatrix.needsUpdate = true;
riceTip.instanceMatrix.needsUpdate = true;
}
function updateWater(progress) {
const level = lerp(1.95, 0.46, smoothstep(0.03, 0.97, progress));
const depth = Math.max(0.05, level - waterBottom);
waterVolume.scale.y = depth;
waterVolume.position.y = waterBottom + depth * 0.5;
surfaceCells.forEach((cell, index) => {
dummy.position.set(cell.x, level + 0.026, cell.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(0.244, 0.052, 0.244);
dummy.updateMatrix();
waterSurface.setMatrixAt(index, dummy.matrix);
});
waterSurface.instanceMatrix.needsUpdate = true;
return level;
}
function updateTracers(progress) {
const envelope =
progress > 0.06 && progress < 0.96
? Math.sin(Math.PI * ((progress - 0.06) / 0.9))
: 0;
tracerData.forEach((tracer, index) => {
const life = (
state.elapsed * 0.17 * tracer.speed + tracer.phase
) % 1;
const radius = lerp(2.25, 0.28, life);
const size = 0.07 * envelope * Math.sin(Math.PI * life);
dummy.position.set(
Math.cos(tracer.theta) * radius,
tracer.height + life * 0.45,
Math.sin(tracer.theta) * radius
);
dummy.rotation.set(0, life * Math.PI, 0);
dummy.scale.set(size, size, size);
dummy.updateMatrix();
tracerMesh.setMatrixAt(index, dummy.matrix);
});
tracerMesh.instanceMatrix.needsUpdate = true;
}
function updateSteam() {
steamData.forEach((particle, index) => {
const life = (
state.elapsed * 0.115 + particle.phase
) % 1;
const fadeShape = Math.pow(Math.sin(Math.PI * life), 0.7);
const size = particle.size * fadeShape * (1 + life * 1.8);
dummy.position.set(
particle.x +
Math.sin(life * 5.0 + particle.drift) * (0.12 + life * 0.48) +
life * 0.34,
1.88 + life * 3.85,
particle.z +
Math.cos(life * 4.2 + particle.drift) * (0.1 + life * 0.34)
);
dummy.rotation.set(
particle.drift * 0.15,
particle.drift + life,
particle.drift * 0.1
);
dummy.scale.set(size, size, size);
dummy.updateMatrix();
steamMesh.setMatrixAt(index, dummy.matrix);
});
steamMesh.instanceMatrix.needsUpdate = true;
}
// -------------------------------------------------------------------------
// Timeline UI
// -------------------------------------------------------------------------
const phases = [
{
at: 0,
name: "Dry grain",
note: "Compact rice is placed in the pot."
},
{
at: 0.18,
name: "Water available",
note: "Free water surrounds the compact grains."
},
{
at: 0.42,
name: "Absorption",
note: "Water enters the grain bodies and begins swelling them."
},
{
at: 0.68,
name: "Swelling",
note: "The grains expand while the free-water level falls."
},
{
at: 0.91,
name: "Near balance",
note: "Little free water remains; the grain volume is larger."
}
];
function updateUI(progress) {
timelineInput.value = String(Math.round(progress * 1000));
timelineInput.style.setProperty("--fill", `${progress * 100}%`);
let currentPhase = phases[0];
for (const phase of phases) {
if (progress >= phase.at) currentPhase = phase;
}
phaseName.textContent = currentPhase.name;
phaseNote.textContent = currentPhase.note;
grainFill.style.width = `${26 + progress * 74}%`;
waterFill.style.width = `${100 - progress * 77}%`;
grainState.textContent =
progress < 0.25 ? "COMPACT" :
progress < 0.68 ? "SWELLING" :
"SWOLLEN";
waterState.textContent =
progress < 0.3 ? "HIGH" :
progress < 0.72 ? "FALLING" :
"LOW";
riceDetail.textContent =
progress < 0.3 ? "beginning to absorb" :
progress < 0.72 ? "expanding with water" :
"fully swollen";
waterDetail.textContent =
progress < 0.3 ? "high level" :
progress < 0.72 ? "level falling" :
"only a little remains";
milestoneButtons.forEach(button => {
const at = Number(button.dataset.progress);
button.classList.toggle("active", progress >= at - 0.015);
});
if (state.playing) {
playButton.textContent = "Ⅱ Pause";
} else if (progress >= 0.999) {
playButton.textContent = "↻ Replay";
} else {
playButton.textContent = "▶ Play";
}
}
timelineInput.addEventListener("input", () => {
state.progress = Number(timelineInput.value) / 1000;
state.playing = false;
updateUI(state.progress);
});
playButton.addEventListener("click", () => {
if (state.progress >= 0.999) state.progress = 0;
state.playing = !state.playing;
updateUI(state.progress);
});
resetTimelineButton.addEventListener("click", () => {
state.progress = 0;
state.playing = false;
updateUI(state.progress);
});
milestoneButtons.forEach(button => {
button.addEventListener("click", () => {
state.progress = Number(button.dataset.progress);
state.playing = false;
updateUI(state.progress);
});
});
// -------------------------------------------------------------------------
// Direct camera controls — no addons
// -------------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.azimuth -= deltaX * 0.006;
cameraState.polar = clamp(
cameraState.polar + deltaY * 0.005,
0.68,
1.47
);
});
function stopDragging(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (event && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraState.radius = clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
9.3,
17
);
},
{ passive: false }
);
function resetView() {
cameraState.azimuth = cameraHome.azimuth;
cameraState.polar = cameraHome.polar;
cameraState.radius = cameraHome.radius;
}
resetViewButton.addEventListener("click", resetView);
renderer.domElement.addEventListener("dblclick", resetView);
// -------------------------------------------------------------------------
// Projected HTML annotations
// -------------------------------------------------------------------------
const riceCallout = document.querySelector("#riceCallout");
const waterCallout = document.querySelector("#waterCallout");
const steamCallout = document.querySelector("#steamCallout");
const projected = new THREE.Vector3();
function placeAnnotation(element, point, offsetX, offsetY) {
projected.copy(point).project(camera);
const x = (projected.x * 0.5 + 0.5) * window.innerWidth + offsetX;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight + offsetY;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function updateAnnotations() {
placeAnnotation(
riceCallout,
new THREE.Vector3(-2.2, 0.55, 1.8),
-34,
-24
);
placeAnnotation(
waterCallout,
new THREE.Vector3(2.35, -0.45, 1.45),
83,
13
);
placeAnnotation(
steamCallout,
new THREE.Vector3(2.25, 3.45, -0.1),
92,
-13
);
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", onResize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
state.elapsed += delta;
if (state.playing) {
state.progress = clamp(state.progress + delta / 18, 0, 1);
if (state.progress >= 1) {
state.playing = false;
}
updateUI(state.progress);
}
updateCamera();
updateRice(state.progress);
updateWater(state.progress);
updateTracers(state.progress);
updateSteam();
updateAnnotations();
renderer.render(scene, camera);
}
updateUI(state.progress);
animate();
</script>
</body>
</html>
```