Prompt specification
Build or customize the Three.js 3D scene "Dry and swollen rice grains" 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: Dry and swollen rice grains
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/dry-and-swollen-rice-grains-x0145
Scene Description Prompt:
Create a standalone stylized scene in one HTML file using Three.js from cdnjs. Place enlarged dry and cooked rice grain models beside a real-scale spoon for context; compare their lengths and volumes using explicitly illustrative measurement guides.
Working Three.js Starter (dry-and-swollen-rice-grains-x0145):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Rice Grain Scale Study</title>
<style>
:root {
color-scheme: dark;
--ink: #edf8f1;
--muted: #a8c4bc;
--panel: rgba(7, 27, 29, 0.82);
--line: rgba(213, 244, 229, 0.15);
--dry: #ff9a76;
--cooked: #78dfbd;
--spoon: #f3c875;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 72% 18%, #204547 0%, transparent 38%),
linear-gradient(145deg, #0c2528, #102e31 55%, #091d20);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
body::after {
content: "";
position: fixed;
inset: 0;
z-index: 1;
pointer-events: none;
background: radial-gradient(circle at 50% 45%, transparent 42%, rgba(1, 12, 14, 0.38));
}
#scene {
position: fixed;
inset: 0;
z-index: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas.dragging {
cursor: grabbing;
}
.ui {
position: fixed;
z-index: 3;
pointer-events: none;
}
.ui button {
pointer-events: auto;
}
header {
top: 28px;
left: 30px;
width: min(420px, calc(100vw - 60px));
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
color: #b9d6cc;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 28px;
height: 2px;
background: var(--cooked);
border-radius: 2px;
}
h1 {
margin: 0;
max-width: 390px;
font-size: clamp(34px, 4.2vw, 58px);
font-weight: 720;
line-height: 0.98;
letter-spacing: -0.055em;
text-wrap: balance;
}
header p {
max-width: 385px;
margin: 18px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.6;
}
header p strong {
color: var(--ink);
font-weight: 650;
}
.controls {
top: 28px;
right: 30px;
display: flex;
gap: 8px;
padding: 6px;
border: 1px solid var(--line);
border-radius: 15px;
background: rgba(7, 27, 29, 0.7);
backdrop-filter: blur(16px);
box-shadow: 0 12px 34px rgba(0, 0, 0, 0.18);
}
button {
min-height: 38px;
padding: 0 13px;
border: 1px solid transparent;
border-radius: 10px;
background: transparent;
color: #d8ece4;
font: inherit;
font-size: 12px;
font-weight: 650;
letter-spacing: 0.01em;
cursor: pointer;
transition:
color 160ms ease,
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
button:hover {
color: white;
background: rgba(255, 255, 255, 0.07);
border-color: rgba(255, 255, 255, 0.08);
}
button:active {
transform: translateY(1px);
}
button[aria-pressed="true"] {
color: #092225;
background: #b9ead8;
}
.readout {
right: 30px;
bottom: 28px;
width: 390px;
padding: 20px;
border: 1px solid var(--line);
border-radius: 20px;
background: var(--panel);
backdrop-filter: blur(18px);
box-shadow: 0 22px 65px rgba(0, 0, 0, 0.28);
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-bottom: 15px;
color: #bcd6cd;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.illustrative {
padding: 5px 7px;
border: 1px solid rgba(243, 200, 117, 0.28);
border-radius: 6px;
color: var(--spoon);
font-size: 8px;
letter-spacing: 0.1em;
white-space: nowrap;
}
.metrics {
display: grid;
gap: 1px;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 12px;
background: rgba(255, 255, 255, 0.07);
}
.metric {
display: grid;
grid-template-columns: 1fr auto;
gap: 4px 12px;
align-items: baseline;
padding: 11px 13px;
background: rgba(8, 29, 31, 0.96);
}
.metric .name {
color: #dcece6;
font-size: 12px;
font-weight: 700;
}
.metric .value {
font-variant-numeric: tabular-nums;
font-size: 15px;
font-weight: 750;
letter-spacing: -0.02em;
}
.metric .detail {
grid-column: 1 / -1;
color: #8eaea5;
font-size: 10px;
}
.metric.dry .value {
color: var(--dry);
}
.metric.cooked .value {
color: var(--cooked);
}
.metric.spoon .value {
color: var(--spoon);
}
.volume-block {
margin-top: 17px;
}
.volume-heading {
display: flex;
justify-content: space-between;
margin-bottom: 9px;
color: #bcd6cd;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.volume-heading span:last-child {
color: #7e9f96;
font-size: 9px;
font-weight: 550;
letter-spacing: 0;
text-transform: none;
}
.bar-row {
display: grid;
grid-template-columns: 64px 1fr 55px;
align-items: center;
gap: 10px;
margin-top: 8px;
color: #9ebbb2;
font-size: 10px;
}
.track {
height: 7px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.08);
}
.fill {
height: 100%;
border-radius: inherit;
}
.fill.dry {
width: 33.333%;
background: var(--dry);
}
.fill.cooked {
width: 100%;
background: var(--cooked);
}
.bar-row strong {
color: #e7f4ee;
font-variant-numeric: tabular-nums;
text-align: right;
font-size: 10px;
}
.note {
margin: 15px 0 0;
padding-top: 13px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
color: #7fa098;
font-size: 9.5px;
line-height: 1.5;
}
.hint {
left: 30px;
bottom: 29px;
display: flex;
align-items: center;
gap: 9px;
color: rgba(201, 225, 216, 0.62);
font-size: 10px;
letter-spacing: 0.035em;
}
.hint::before {
content: "";
width: 7px;
height: 7px;
border: 1px solid rgba(201, 225, 216, 0.6);
border-radius: 50%;
box-shadow: 0 0 0 4px rgba(201, 225, 216, 0.06);
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #10292c;
color: #c6dfd6;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 500ms ease, visibility 500ms ease;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
@media (max-width: 760px) {
header {
top: 20px;
left: 18px;
width: calc(100vw - 36px);
}
h1 {
max-width: 260px;
font-size: 34px;
}
header p {
display: none;
}
.controls {
top: auto;
right: 14px;
bottom: 14px;
flex-direction: column;
padding: 5px;
}
.controls button {
min-height: 34px;
padding: 0 10px;
font-size: 10px;
}
.readout {
right: 14px;
bottom: 14px;
width: min(350px, calc(100vw - 85px));
padding: 14px;
border-radius: 16px;
}
.panel-title {
margin-bottom: 10px;
}
.metric {
padding: 8px 10px;
}
.volume-block,
.note {
display: none;
}
.hint {
display: none;
}
}
@media (max-width: 470px) {
.eyebrow {
font-size: 9px;
}
h1 {
font-size: 30px;
}
.readout {
width: calc(100vw - 76px);
}
.metric .detail {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="ui">
<div class="eyebrow">Rice / Scale study</div>
<h1>A grain, magnified.</h1>
<p>
The <strong>17 cm spoon remains true to scale</strong>. The dry and cooked
grains are both enlarged to <strong>7×</strong> so their shape and volume
differences can be compared clearly.
</p>
</header>
<nav class="controls ui" aria-label="Scene controls">
<button id="reset" type="button" title="Reset camera">↺ Reset</button>
<button id="guides" type="button" aria-pressed="true">◫ Guides</button>
<button id="orbit" type="button" aria-pressed="false">⟳ Drift</button>
</nav>
<section class="readout ui" aria-label="Illustrative measurements">
<div class="panel-title">
<span>Model measurements</span>
<span class="illustrative">Illustrative values</span>
</div>
<div class="metrics">
<div class="metric spoon">
<span class="name">Spoon</span>
<span class="value">17.0 cm</span>
<span class="detail">True scale · one scene unit equals one centimetre</span>
</div>
<div class="metric dry">
<span class="name">Dry grain</span>
<span class="value">7.0 mm</span>
<span class="detail">7.0 × 2.2 × 2.0 mm · shown at 7×</span>
</div>
<div class="metric cooked">
<span class="name">Cooked grain</span>
<span class="value">8.5 mm</span>
<span class="detail">8.5 × 3.4 × 3.2 mm · shown at 7×</span>
</div>
</div>
<div class="volume-block">
<div class="volume-heading">
<span>Volume comparison</span>
<span>same bar scale</span>
</div>
<div class="bar-row">
<span>Dry</span>
<div class="track"><div class="fill dry"></div></div>
<strong>0.020 cm³</strong>
</div>
<div class="bar-row">
<span>Cooked</span>
<div class="track"><div class="fill cooked"></div></div>
<strong>0.060 cm³</strong>
</div>
</div>
<p class="note">
The modeled cooked grain has about 3× the dry grain’s volume. Grain size
and swelling vary with cultivar, water uptake, and cooking method.
</p>
</section>
<div class="hint ui">Drag to orbit · Scroll or pinch to zoom</div>
<div id="loading">Preparing the scale study</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 sceneHost = document.getElementById("scene");
const loading = document.getElementById("loading");
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;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional comparison of dry and cooked rice grains"
);
renderer.domElement.setAttribute("role", "img");
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x10292c);
scene.fog = new THREE.FogExp2(0x10292c, 0.018);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const target = new THREE.Vector3(0, 0.45, 0.9);
const controls = {
theta: 0.34,
phi: 1.02,
radius: window.innerWidth < 700 ? 42 : 25,
targetTheta: 0.34,
targetPhi: 1.02,
targetRadius: window.innerWidth < 700 ? 42 : 25
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
target.x + controls.radius * sinPhi * Math.sin(controls.theta),
target.y + controls.radius * Math.cos(controls.phi),
target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(target);
}
updateCamera();
// -------------------------------------------------------------------------
// Lighting and ground
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xdff8ee, 0x18302c, 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffe2b3, 4.2);
keyLight.position.set(1.5, 12, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -14;
keyLight.shadow.camera.right = 14;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.00025;
keyLight.target.position.set(0, 0, 1);
scene.add(keyLight, keyLight.target);
const fillLight = new THREE.DirectionalLight(0x86c7c3, 2.3);
fillLight.position.set(-9, 6, -5);
scene.add(fillLight);
const warmLight = new THREE.PointLight(0xffa36f, 24, 18, 2);
warmLight.position.set(8, 4, 5);
scene.add(warmLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(70, 70),
new THREE.MeshStandardMaterial({
color: 0x153537,
roughness: 0.94,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.035;
ground.receiveShadow = true;
scene.add(ground);
const stage = new THREE.Mesh(
new THREE.CircleGeometry(14.5, 128),
new THREE.MeshStandardMaterial({
color: 0x193d3f,
roughness: 0.92,
metalness: 0
})
);
stage.rotation.x = -Math.PI / 2;
stage.position.y = -0.015;
stage.receiveShadow = true;
scene.add(stage);
const grid = new THREE.GridHelper(30, 30, 0x4d7771, 0x355c59);
grid.position.y = 0.002;
grid.material.transparent = true;
grid.material.opacity = 0.13;
scene.add(grid);
[
{ radius: 10.8, opacity: 0.14 },
{ radius: 7.6, opacity: 0.09 }
].forEach(({ radius, opacity }) => {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(radius, 0.012, 6, 180),
new THREE.MeshBasicMaterial({
color: 0x9bd5c5,
transparent: true,
opacity,
depthWrite: false
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.015;
scene.add(ring);
});
// -------------------------------------------------------------------------
// Utility geometry
// -------------------------------------------------------------------------
const yAxis = new THREE.Vector3(0, 1, 0);
function cylinderBetween(a, b, radius, material, parent = scene) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 8),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(yAxis, direction.normalize());
parent.add(mesh);
return mesh;
}
function guideMaterial(color) {
return new THREE.MeshBasicMaterial({
color,
toneMapped: false
});
}
function roundedRectPath(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + width - r, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + r);
ctx.lineTo(x + width, y + height - r);
ctx.quadraticCurveTo(x + width, y + height, x + width - r, y + height);
ctx.lineTo(x + r, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function makeLabel(title, value, detail, accent, worldWidth = 4) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 240;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.shadowColor = "rgba(0, 0, 0, 0.35)";
ctx.shadowBlur = 22;
ctx.shadowOffsetY = 10;
roundedRectPath(ctx, 8, 8, 624, 224, 30);
ctx.fillStyle = "rgba(7, 27, 29, 0.90)";
ctx.fill();
ctx.shadowColor = "transparent";
ctx.strokeStyle = "rgba(220, 246, 235, 0.17)";
ctx.lineWidth = 2;
ctx.stroke();
ctx.fillStyle = accent;
roundedRectPath(ctx, 34, 31, 8, 36, 4);
ctx.fill();
ctx.fillStyle = "#b8d1c8";
ctx.font = "700 25px system-ui, sans-serif";
ctx.textBaseline = "middle";
ctx.fillText(title.toUpperCase(), 59, 49);
ctx.fillStyle = "#f0faf5";
ctx.font = "750 52px system-ui, sans-serif";
ctx.fillText(value, 38, 116);
ctx.fillStyle = "#91afa6";
ctx.font = "500 23px system-ui, sans-serif";
ctx.fillText(detail, 39, 184);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
})
);
sprite.scale.set(worldWidth, worldWidth * (240 / 640), 1);
sprite.renderOrder = 30;
return sprite;
}
// -------------------------------------------------------------------------
// Procedural rice-grain geometry
// -------------------------------------------------------------------------
function makeGrainTexture(baseColor, fleckColor, dry = false) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = baseColor;
ctx.fillRect(0, 0, canvas.width, canvas.height);
let seed = dry ? 9421 : 2817;
const random = () => {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
};
const count = dry ? 460 : 230;
for (let i = 0; i < count; i++) {
const x = random() * canvas.width;
const y = random() * canvas.height;
const length = dry ? 2 + random() * 9 : 1 + random() * 4;
const thickness = 0.5 + random() * 1.4;
ctx.strokeStyle = fleckColor;
ctx.globalAlpha = dry ? 0.08 + random() * 0.15 : 0.035 + random() * 0.07;
ctx.lineWidth = thickness;
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(x + length, y + (random() - 0.5) * 2);
ctx.stroke();
}
ctx.globalAlpha = 1;
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function createGrainGeometry(
length,
width,
height,
bend = 0,
withCrease = false
) {
const longitudinalSegments = 72;
const radialSegments = 30;
const positions = [];
const uvs = [];
const indices = [];
const grooveDepth = withCrease ? height * 0.085 : 0;
const profileAt = (t) => {
const base = Math.pow(Math.max(0, Math.sin(Math.PI * t)), 0.62);
return base * (0.92 + 0.08 * Math.sin(Math.PI * t));
};
for (let i = 0; i <= longitudinalSegments; i++) {
const t = i / longitudinalSegments;
const x = length * (t - 0.5);
const profile = profileAt(t);
const centerY = bend * Math.sin(Math.PI * t);
for (let j = 0; j <= radialSegments; j++) {
const v = j / radialSegments;
const theta = v * Math.PI * 2;
const sinTheta = Math.sin(theta);
const cosTheta = Math.cos(theta);
let y = centerY + height * profile * cosTheta;
if (withCrease) {
const groove = Math.exp(-Math.pow(sinTheta / 0.2, 2));
y -= grooveDepth * profile * groove * Math.max(cosTheta, 0);
}
const z = width * profile * sinTheta;
positions.push(x, y, z);
uvs.push(t, v);
}
}
const row = radialSegments + 1;
for (let i = 0; i < longitudinalSegments; i++) {
for (let j = 0; j < radialSegments; j++) {
const a = i * row + j;
const b = (i + 1) * row + j;
const c = (i + 1) * row + j + 1;
const d = i * row + j + 1;
indices.push(a, c, b);
indices.push(b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
geometry.setIndex(indices);
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
return {
geometry,
profileAt
};
}
const dryTexture = makeGrainTexture(
"#e8d5a8",
"#8b6a3f",
true
);
const cookedTexture = makeGrainTexture(
"#f3e6c8",
"#b59c75",
false
);
const dryMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
map: dryTexture,
roughness: 0.78,
metalness: 0.02
});
const cookedMaterial = new THREE.MeshPhysicalMaterial({
color: 0xffffff,
map: cookedTexture,
roughness: 0.48,
metalness: 0,
clearcoat: 0.25,
clearcoatRoughness: 0.6,
sheen: 0.22,
sheenColor: new THREE.Color(0xfff1ce)
});
// -------------------------------------------------------------------------
// Real-scale spoon: 17 cm overall length
// One scene unit equals one centimetre.
// -------------------------------------------------------------------------
const spoonGroup = new THREE.Group();
scene.add(spoonGroup);
const spoonMaterial = new THREE.MeshPhysicalMaterial({
color: 0xd6aa6c,
metalness: 0.56,
roughness: 0.28,
clearcoat: 0.3,
clearcoatRoughness: 0.45
});
const rimMaterial = new THREE.MeshPhysicalMaterial({
color: 0xf1ca91,
metalness: 0.62,
roughness: 0.22
});
const spoonCenterX = -6.2;
const spoonCenterZ = -1.4;
const bowlRadiusX = 2.5;
const bowlRadiusZ = 1.7;
const bowlRimY = 0.62;
// Lower half of a scaled sphere forms the concave bowl.
const bowl = new THREE.Mesh(
new THREE.SphereGeometry(
1,
72,
32,
0,
Math.PI * 2,
Math.PI / 2,
Math.PI / 2
),
new THREE.MeshPhysicalMaterial({
color: 0xc99b5d,
metalness: 0.54,
roughness: 0.3,
clearcoat: 0.28,
side: THREE.DoubleSide
})
);
bowl.scale.set(bowlRadiusX, 0.55, bowlRadiusZ);
bowl.position.set(spoonCenterX, bowlRimY, spoonCenterZ);
bowl.castShadow = true;
bowl.receiveShadow = true;
spoonGroup.add(bowl);
// Elliptical rim.
const rimPoints = [];
for (let i = 0; i < 100; i++) {
const angle = (i / 100) * Math.PI * 2;
rimPoints.push(
new THREE.Vector3(
spoonCenterX + Math.cos(angle) * bowlRadiusX,
bowlRimY,
spoonCenterZ + Math.sin(angle) * bowlRadiusZ
)
);
}
const rimCurve = new THREE.CatmullRomCurve3(rimPoints, true);
const rim = new THREE.Mesh(
new THREE.TubeGeometry(rimCurve, 120, 0.025, 8, true),
rimMaterial
);
rim.castShadow = true;
spoonGroup.add(rim);
// Sculpted, bevelled handle.
const handleShape = new THREE.Shape();
handleShape.moveTo(-4.25, 0.62);
handleShape.bezierCurveTo(-1.8, 0.43, 2.8, 0.34, 7.65, 0.3);
handleShape.quadraticCurveTo(8.3, 0.3, 8.3, 0);
handleShape.quadraticCurveTo(8.3, -0.3, 7.65, -0.3);
handleShape.bezierCurveTo(2.8, -0.34, -1.8, -0.43, -4.25, -0.62);
handleShape.closePath();
const handleGeometry = new THREE.ExtrudeGeometry(handleShape, {
depth: 0.16,
bevelEnabled: true,
bevelSegments: 3,
bevelSize: 0.08,
bevelThickness: 0.07,
curveSegments: 28
});
handleGeometry.rotateX(-Math.PI / 2);
const handle = new THREE.Mesh(handleGeometry, spoonMaterial);
handle.position.set(0, 0.12, spoonCenterZ);
handle.castShadow = true;
handle.receiveShadow = true;
spoonGroup.add(handle);
// A few genuinely tiny rice grains in the spoon reinforce its true scale.
const miniGrain = createGrainGeometry(0.7, 0.22, 0.2, 0, false);
const miniSeed = { value: 5221 };
const miniRandom = () => {
miniSeed.value = (miniSeed.value * 1664525 + 1013904223) >>> 0;
return miniSeed.value / 4294967296;
};
for (let i = 0; i < 9; i++) {
const dx = (miniRandom() - 0.5) * 1.45;
const dz = (miniRandom() - 0.5) * 1.15;
const normalized =
(dx / bowlRadiusX) ** 2 + (dz / bowlRadiusZ) ** 2;
const surfaceY =
bowlRimY - 0.55 * Math.sqrt(Math.max(0.04, 1 - normalized));
const mini = new THREE.Mesh(miniGrain.geometry, dryMaterial);
mini.position.set(spoonCenterX + dx, surfaceY + 0.105, spoonCenterZ + dz);
mini.rotation.y = miniRandom() * Math.PI;
mini.castShadow = true;
spoonGroup.add(mini);
}
// -------------------------------------------------------------------------
// Enlarged dry and cooked grains
// -------------------------------------------------------------------------
const displayScale = 7;
const dryDisplay = createGrainGeometry(
0.7 * displayScale,
0.22 * displayScale,
0.2 * displayScale,
0.09,
true
);
const cookedDisplay = createGrainGeometry(
0.85 * displayScale,
0.34 * displayScale,
0.32 * displayScale,
0.035,
false
);
const dryGrain = new THREE.Mesh(dryDisplay.geometry, dryMaterial);
dryGrain.position.set(-3.55, 0.72, 3.35);
dryGrain.castShadow = true;
dryGrain.receiveShadow = true;
scene.add(dryGrain);
// Dark central crease on the dry grain.
const creasePoints = [];
for (let i = 0; i <= 40; i++) {
const t = 0.1 + (i / 40) * 0.8;
const x = 4.9 * (t - 0.5);
const profile = dryDisplay.profileAt(t);
const y = 0.09 * Math.sin(Math.PI * t) + 1.4 * profile * 0.915;
const z = Math.sin(t * 11) * 0.012;
creasePoints.push(new THREE.Vector3(x, y, z));
}
const crease = new THREE.Mesh(
new THREE.TubeGeometry(
new THREE.CatmullRomCurve3(creasePoints),
60,
0.016,
6,
false
),
new THREE.MeshStandardMaterial({
color: 0x9d7749,
roughness: 0.9
})
);
dryGrain.add(crease);
const cookedGrain = new THREE.Mesh(cookedDisplay.geometry, cookedMaterial);
cookedGrain.position.set(3.75, 1.14, 3.35);
cookedGrain.castShadow = true;
cookedGrain.receiveShadow = true;
scene.add(cookedGrain);
// Permanent object labels.
const dryLabel = makeLabel(
"Dry grain",
"7.0 mm",
"actual length · model shown at 7×",
"#ff9a76",
4.05
);
dryLabel.position.set(-3.55, 3.0, 3.35);
scene.add(dryLabel);
const cookedLabel = makeLabel(
"Cooked grain",
"8.5 mm",
"actual length · model shown at 7×",
"#78dfbd",
4.05
);
cookedLabel.position.set(3.75, 3.48, 3.35);
scene.add(cookedLabel);
cylinderBetween(
new THREE.Vector3(-3.55, 2.24, 3.35),
new THREE.Vector3(-3.55, 1.48, 3.35),
0.017,
guideMaterial(0xff9a76)
);
cylinderBetween(
new THREE.Vector3(3.75, 2.72, 3.35),
new THREE.Vector3(3.75, 2.34, 3.35),
0.017,
guideMaterial(0x78dfbd)
);
// -------------------------------------------------------------------------
// Measurement guides
// -------------------------------------------------------------------------
const guideGroup = new THREE.Group();
scene.add(guideGroup);
function addXBracket(
minX,
maxX,
y,
z,
color,
parent = guideGroup,
tickDepth = 0.32
) {
const material = guideMaterial(color);
cylinderBetween(
new THREE.Vector3(minX, y, z),
new THREE.Vector3(maxX, y, z),
0.017,
material,
parent
);
cylinderBetween(
new THREE.Vector3(minX, y, z - tickDepth),
new THREE.Vector3(minX, y, z + tickDepth),
0.017,
material,
parent
);
cylinderBetween(
new THREE.Vector3(maxX, y, z - tickDepth),
new THREE.Vector3(maxX, y, z + tickDepth),
0.017,
material,
parent
);
const middle = (minX + maxX) / 2;
cylinderBetween(
new THREE.Vector3(middle, y, z - 0.14),
new THREE.Vector3(middle, y, z + 0.14),
0.013,
material,
parent
);
}
// 17 cm spoon bracket.
addXBracket(-8.7, 8.3, 0.045, 0.55, 0xf3c875, guideGroup, 0.38);
const spoonLabel = makeLabel(
"Spoon",
"17.0 cm",
"true scale · 1 scene unit = 1 cm",
"#f3c875",
3.7
);
spoonLabel.position.set(0, 1.05, 0.55);
guideGroup.add(spoonLabel);
// Displayed-length brackets below the enlarged grains.
addXBracket(
-3.55 - 4.9 / 2,
-3.55 + 4.9 / 2,
0.055,
4.9,
0xff9a76
);
addXBracket(
3.75 - 5.95 / 2,
3.75 + 5.95 / 2,
0.055,
4.9,
0x78dfbd
);
const dryScaleLabel = makeLabel(
"Display span",
"7×",
"actual length listed above",
"#ff9a76",
2.25
);
dryScaleLabel.position.set(-3.55, 0.48, 5.05);
guideGroup.add(dryScaleLabel);
const cookedScaleLabel = makeLabel(
"Display span",
"7×",
"actual length listed above",
"#78dfbd",
2.25
);
cookedScaleLabel.position.set(3.75, 0.48, 5.05);
guideGroup.add(cookedScaleLabel);
// Same-scale volume bars. Height is proportional to the illustrative values.
function createVolumeBar(x, z, volume, color) {
const group = new THREE.Group();
group.position.set(x, 0, z);
guideGroup.add(group);
const height = volume * 45;
const radius = 0.52;
const base = new THREE.Mesh(
new THREE.CylinderGeometry(radius + 0.2, radius + 0.2, 0.07, 48),
new THREE.MeshStandardMaterial({
color: 0x315354,
roughness: 0.62,
metalness: 0.25
})
);
base.position.y = 0.035;
base.receiveShadow = true;
group.add(base);
const shell = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, 40, 1, true),
new THREE.MeshPhysicalMaterial({
color,
transparent: true,
opacity: 0.13,
roughness: 0.2,
side: THREE.DoubleSide,
depthWrite: false
})
);
shell.position.y = height / 2 + 0.07;
group.add(shell);
const fill = new THREE.Mesh(
new THREE.CylinderGeometry(radius * 0.54, radius * 0.54, height, 40),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.3,
depthWrite: false
})
);
fill.position.y = height / 2 + 0.07;
group.add(fill);
for (let i = 0; i <= 3; i++) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(radius, 0.012, 6, 48),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.62
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.07 + (height * i) / 3;
group.add(ring);
}
const topRing = new THREE.Mesh(
new THREE.TorusGeometry(radius, 0.025, 8, 48),
new THREE.MeshBasicMaterial({ color })
);
topRing.rotation.x = Math.PI / 2;
topRing.position.y = height + 0.07;
group.add(topRing);
return group;
}
createVolumeBar(-7.35, 3.5, 0.020, 0xff9a76);
createVolumeBar(7.35, 3.5, 0.060, 0x78dfbd);
const dryVolumeLabel = makeLabel(
"Dry volume",
"0.020 cm³",
"same-scale volume bar",
"#ff9a76",
2.75
);
dryVolumeLabel.position.set(-7.35, 1.52, 3.5);
guideGroup.add(dryVolumeLabel);
const cookedVolumeLabel = makeLabel(
"Cooked volume",
"0.060 cm³",
"same-scale volume bar",
"#78dfbd",
2.75
);
cookedVolumeLabel.position.set(7.35, 3.25, 3.5);
guideGroup.add(cookedVolumeLabel);
// -------------------------------------------------------------------------
// Custom camera controls — no addons
// -------------------------------------------------------------------------
const canvas = renderer.domElement;
const pointers = new Map();
let pinchDistance = 0;
let autoOrbit = false;
canvas.addEventListener("pointerdown", (event) => {
if (event.pointerType === "mouse" && event.button !== 0) return;
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
canvas.classList.add("dragging");
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
if (pointers.size === 1) {
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
controls.targetTheta -= dx * 0.0055;
controls.targetPhi = THREE.MathUtils.clamp(
controls.targetPhi - dy * 0.0045,
0.48,
1.42
);
} else if (pointers.size === 2) {
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0 && distance > 0) {
controls.targetRadius = THREE.MathUtils.clamp(
controls.targetRadius * (pinchDistance / distance),
11,
58
);
}
pinchDistance = distance;
return;
}
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
if (pointers.size === 0) canvas.classList.remove("dragging");
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("lostpointercapture", releasePointer);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.targetRadius = THREE.MathUtils.clamp(
controls.targetRadius * Math.exp(event.deltaY * 0.001),
11,
58
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
switch (event.key) {
case "ArrowLeft":
controls.targetTheta -= 0.08;
break;
case "ArrowRight":
controls.targetTheta += 0.08;
break;
case "ArrowUp":
controls.targetPhi = Math.max(0.48, controls.targetPhi - 0.06);
break;
case "ArrowDown":
controls.targetPhi = Math.min(1.42, controls.targetPhi + 0.06);
break;
case "+":
case "=":
controls.targetRadius = Math.max(11, controls.targetRadius - 1.5);
break;
case "-":
controls.targetRadius = Math.min(58, controls.targetRadius + 1.5);
break;
case "r":
case "R":
resetView();
break;
}
});
function resetView() {
controls.targetTheta = 0.34;
controls.targetPhi = 1.02;
controls.targetRadius = window.innerWidth < 700 ? 42 : 25;
}
const resetButton = document.getElementById("reset");
const guidesButton = document.getElementById("guides");
const orbitButton = document.getElementById("orbit");
resetButton.addEventListener("click", resetView);
guidesButton.addEventListener("click", () => {
guideGroup.visible = !guideGroup.visible;
guidesButton.setAttribute(
"aria-pressed",
String(guideGroup.visible)
);
});
orbitButton.addEventListener("click", () => {
autoOrbit = !autoOrbit;
orbitButton.setAttribute("aria-pressed", String(autoOrbit));
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
if (autoOrbit && pointers.size === 0) {
controls.targetTheta += delta * 0.09;
}
controls.theta +=
(controls.targetTheta - controls.theta) * (1 - Math.exp(-8 * delta));
controls.phi +=
(controls.targetPhi - controls.phi) * (1 - Math.exp(-8 * delta));
controls.radius +=
(controls.targetRadius - controls.radius) * (1 - Math.exp(-8 * delta));
updateCamera();
renderer.render(scene, camera);
});
requestAnimationFrame(() => {
loading.classList.add("hidden");
});
</script>
</body>
</html>
```