Prompt specification
Build or customize the Three.js 3D scene "Rice meal portioning station" 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: Rice meal portioning station
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/rice-meal-portioning-station-x0147
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a rice-serving station in a warm stylized solid style. Arrange a pot of cooked rice, one serving scoop, a row of bowls, and two small side-dish platters on a counter. Let the user choose how many people will share the batch, then distribute identical scoop volumes among the bowls. Keep a visible measure of the remaining rice and make partial final servings apparent instead of creating extra food. Broad clusters can represent the rice without modeling every grain. The scene should show how one fixed batch is divided as the group size changes.
Working Three.js Starter (rice-meal-portioning-station-x0147):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Rice Sharing Station</title>
<style>
:root {
--ink: #49372d;
--muted: #806c5e;
--cream: #fff9ee;
--paper: rgba(255, 249, 238, 0.94);
--terracotta: #bd6949;
--sage: #5f806b;
--gold: #e8b95f;
--line: rgba(88, 61, 45, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #ead8c3;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.brand {
position: fixed;
z-index: 3;
top: 24px;
left: 26px;
pointer-events: none;
text-shadow: 0 2px 18px rgba(255, 247, 231, 0.85);
}
.brand small {
display: block;
margin-bottom: 5px;
color: var(--terracotta);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.brand h1 {
margin: 0;
font-size: clamp(25px, 3vw, 43px);
line-height: 0.95;
letter-spacing: -0.045em;
}
.panel {
position: fixed;
z-index: 4;
top: 22px;
right: 22px;
width: min(355px, calc(100vw - 32px));
padding: 21px;
border: 1px solid rgba(117, 78, 53, 0.16);
border-radius: 24px;
background: var(--paper);
box-shadow:
0 20px 55px rgba(86, 54, 33, 0.18),
inset 0 1px 0 rgba(255, 255, 255, 0.9);
backdrop-filter: blur(14px);
}
.eyebrow {
color: var(--terracotta);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.panel h2 {
margin: 6px 0 8px;
font-size: 24px;
letter-spacing: -0.035em;
}
.description {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.people-row {
display: flex;
align-items: end;
justify-content: space-between;
margin: 21px 0 10px;
}
.people-row label {
font-size: 13px;
font-weight: 750;
}
#peopleValue {
color: var(--terracotta);
font-size: 36px;
font-weight: 850;
line-height: 0.85;
letter-spacing: -0.05em;
}
input[type="range"] {
width: 100%;
height: 25px;
margin: 0;
accent-color: var(--terracotta);
cursor: pointer;
}
.range-labels {
display: flex;
justify-content: space-between;
margin-top: 1px;
color: var(--muted);
font-size: 10px;
}
.metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin: 19px 0 15px;
}
.metric {
min-width: 0;
padding: 12px 9px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(255, 255, 255, 0.48);
}
.metric span {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric strong {
display: block;
overflow: hidden;
font-size: 19px;
letter-spacing: -0.035em;
text-overflow: ellipsis;
white-space: nowrap;
}
.meter-label {
display: flex;
justify-content: space-between;
margin-bottom: 7px;
font-size: 11px;
font-weight: 700;
}
.meter-label span:last-child {
color: var(--muted);
font-weight: 600;
}
.pips {
display: grid;
grid-template-columns: repeat(17, 1fr);
gap: 3px;
height: 18px;
}
.pip {
align-self: stretch;
border-radius: 4px;
background: #e6d8c9;
transition: background 180ms ease, transform 180ms ease;
}
.pip.on {
background: var(--sage);
transform: scaleY(1.08);
}
.distribution {
display: grid;
grid-template-columns: repeat(9, 1fr);
gap: 5px;
margin-top: 15px;
}
.serving-chip {
position: relative;
display: grid;
min-height: 34px;
place-items: center;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 9px;
background: #eee2d4;
color: #9a8677;
font-size: 11px;
font-weight: 850;
}
.serving-chip.full {
border-color: rgba(95, 128, 107, 0.35);
background: #dce9df;
color: #41604e;
}
.serving-chip.partial {
border-color: rgba(232, 185, 95, 0.6);
background: #f7e8be;
color: #8b6521;
}
.serving-chip::after {
position: absolute;
right: 2px;
bottom: 1px;
color: rgba(73, 55, 45, 0.48);
content: attr(data-number);
font-size: 8px;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin-top: 12px;
color: var(--muted);
font-size: 10px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 5px;
}
.dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: #fff0c9;
box-shadow: 0 0 0 1px rgba(93, 68, 48, 0.14);
}
.dot.partial {
background: var(--gold);
}
.dot.empty {
background: #ded0c1;
}
.note {
margin: 14px 0 0;
padding-top: 13px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.controls {
display: flex;
gap: 8px;
margin-top: 14px;
}
button {
min-height: 38px;
padding: 0 13px;
border: 1px solid rgba(94, 63, 44, 0.18);
border-radius: 12px;
background: #fffaf0;
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition: transform 120ms ease, background 120ms ease;
}
button:hover {
background: #f5eadb;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
#hint {
position: fixed;
z-index: 2;
bottom: 18px;
left: 50%;
padding: 9px 13px;
border: 1px solid rgba(255, 255, 255, 0.35);
border-radius: 999px;
background: rgba(70, 48, 34, 0.72);
color: #fff7e9;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.02em;
pointer-events: none;
transform: translateX(-50%);
backdrop-filter: blur(8px);
}
#tooltip {
position: fixed;
z-index: 8;
display: none;
max-width: 210px;
padding: 8px 10px;
border-radius: 10px;
background: rgba(62, 43, 31, 0.92);
color: #fff7e9;
font-size: 11px;
line-height: 1.35;
pointer-events: none;
transform: translate(12px, 12px);
}
@media (max-width: 720px) {
.brand {
top: 16px;
left: 18px;
}
.brand h1 {
font-size: 26px;
}
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
padding: 16px;
border-radius: 20px;
}
.panel h2 {
font-size: 20px;
}
.description {
font-size: 12px;
}
.people-row {
margin-top: 15px;
}
.metrics {
margin: 14px 0 11px;
}
.note {
display: none;
}
#hint {
display: none;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive three-dimensional rice serving station"></div>
<header class="brand">
<small>One fixed batch</small>
<h1>Rice Sharing<br>Station</h1>
</header>
<section class="panel" aria-label="Rice portion controls">
<div class="eyebrow">Serving simulator</div>
<h2>How many are sharing?</h2>
<p class="description">
Each full bowl receives one identical scoop. When the pot runs low,
the final bowl receives only the rice that remains.
</p>
<div class="people-row">
<label for="people">People served</label>
<output id="peopleValue" for="people">4</output>
</div>
<input
id="people"
type="range"
min="1"
max="9"
step="1"
value="4"
aria-label="Number of people served"
>
<div class="range-labels">
<span>1 person</span>
<span>9 people</span>
</div>
<div class="metrics">
<div class="metric">
<span>Fixed batch</span>
<strong>8½</strong>
</div>
<div class="metric">
<span>In bowls</span>
<strong id="servedMetric">4</strong>
</div>
<div class="metric">
<span>Still in pot</span>
<strong id="remainingMetric">4½</strong>
</div>
</div>
<div class="meter-label">
<span>Remaining rice</span>
<span id="remainingPercent">53%</span>
</div>
<div id="potPips" class="pips" aria-hidden="true"></div>
<div id="distribution" class="distribution" aria-label="Bowl distribution"></div>
<div class="legend">
<span><i class="dot"></i> Full scoop</span>
<span><i class="dot partial"></i> Partial scoop</span>
<span><i class="dot empty"></i> Not served</span>
</div>
<p class="note">
The pot and bowls always total 8½ scoop volumes. A partial serving is
smaller rather than an additional scoop.
</p>
<div class="controls">
<button id="resetCamera" type="button">Reset camera</button>
<button id="minus" type="button" aria-label="Serve one fewer person">− Person</button>
<button id="plus" type="button" aria-label="Serve one more person">+ Person</button>
</div>
</section>
<div id="hint">Drag to orbit · Scroll to zoom · Hover a bowl</div>
<div id="tooltip" role="status"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Constants and state
// ------------------------------------------------------------
const BATCH_SCOOPS = 8.5;
const FULL_SCOOP_CAPACITY = 8;
const MAX_PEOPLE = 9;
const COUNTER_TOP = 0.08;
const sceneHost = document.querySelector("#scene");
const slider = document.querySelector("#people");
const peopleValue = document.querySelector("#peopleValue");
const servedMetric = document.querySelector("#servedMetric");
const remainingMetric = document.querySelector("#remainingMetric");
const remainingPercent = document.querySelector("#remainingPercent");
const distribution = document.querySelector("#distribution");
const potPips = document.querySelector("#potPips");
const tooltip = document.querySelector("#tooltip");
let people = Number(slider.value);
let served = 0;
let remaining = BATCH_SCOOPS;
let animatedPotFraction = remaining / BATCH_SCOOPS;
const cameraState = {
theta: 0.58,
phi: 1.03,
radius: 21.5,
target: new THREE.Vector3(-0.35, 0.42, -0.1)
};
const bowls = [];
const interactiveMeshes = [];
// ------------------------------------------------------------
// Renderer, camera, and lighting
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"A warm stylized rice pot, serving scoop, nine bowls, and two side dishes"
);
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#eadbc8");
scene.fog = new THREE.Fog("#eadbc8", 27, 54);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight("#fff5df", "#9a7358", 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight("#fff2d6", 3.2);
keyLight.position.set(-5, 12, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -15;
keyLight.shadow.camera.right = 15;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 38;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight("#c5d8d0", 1.1);
fillLight.position.set(10, 6, -7);
scene.add(fillLight);
// ------------------------------------------------------------
// Materials and helpers
// ------------------------------------------------------------
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.8,
metalness: 0,
flatShading: true,
...options
});
}
const materials = {
wood: standardMaterial("#ad6f48"),
woodDark: standardMaterial("#74452f"),
woodEdge: standardMaterial("#9a5e3e"),
floor: standardMaterial("#dcc8ad"),
wall: standardMaterial("#eadbc8"),
pot: standardMaterial("#4f7668", { roughness: 0.72 }),
potDark: standardMaterial("#3e5e53"),
cream: standardMaterial("#fff3d7"),
bowlCream: standardMaterial("#f8e8cf"),
bowlPeach: standardMaterial("#dfa17e"),
stripe: standardMaterial("#bd6949"),
riceFull: standardMaterial("#fff0c9", { roughness: 0.92 }),
ricePartial: standardMaterial("#edc66e", { roughness: 0.92 }),
brass: standardMaterial("#c58d42", {
roughness: 0.45,
metalness: 0.28
}),
green: standardMaterial("#6e934c"),
greenDark: standardMaterial("#456d3c"),
orange: standardMaterial("#d98638"),
plum: standardMaterial("#9d5b57")
};
function addMesh(geometry, material, parent, position = [0, 0, 0]) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, w, h, r) {
const radius = Math.min(r, w / 2, h / 2);
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.arcTo(x + w, y, x + w, y + h, radius);
ctx.arcTo(x + w, y + h, x, y + h, radius);
ctx.arcTo(x, y + h, x, y, radius);
ctx.arcTo(x, y, x + w, y, radius);
ctx.closePath();
}
function formatAmount(value) {
const whole = Math.floor(value + 0.001);
const fraction = value - whole;
if (fraction < 0.001) return String(whole);
if (Math.abs(fraction - 0.5) < 0.001) {
return whole ? `${whole}½` : "½";
}
return value.toFixed(1);
}
// ------------------------------------------------------------
// Room and counter
// ------------------------------------------------------------
const room = new THREE.Group();
scene.add(room);
const floor = addMesh(
new THREE.PlaneGeometry(70, 70),
materials.floor,
room,
[0, -1.35, 0]
);
floor.rotation.x = -Math.PI / 2;
floor.castShadow = false;
const wall = addMesh(
new THREE.PlaneGeometry(50, 22),
materials.wall,
room,
[0, 7.2, -6.2]
);
wall.castShadow = false;
const counter = new THREE.Group();
scene.add(counter);
addMesh(
new THREE.BoxGeometry(19.2, 0.56, 7.35),
materials.wood,
counter,
[0, -0.28, 0]
);
addMesh(
new THREE.BoxGeometry(19.35, 0.12, 7.48),
materials.woodEdge,
counter,
[0, 0.02, 0]
);
addMesh(
new THREE.BoxGeometry(18.9, 0.31, 0.16),
materials.woodDark,
counter,
[0, -0.57, 3.58]
);
// Subtle plank seams.
for (const z of [-2.75, -1.38, 0, 1.38, 2.75]) {
const seam = addMesh(
new THREE.BoxGeometry(18.95, 0.012, 0.018),
materials.woodDark,
counter,
[0, 0.083, z]
);
seam.castShadow = false;
}
for (const x of [-8.45, 8.45]) {
for (const z of [-2.85, 2.85]) {
addMesh(
new THREE.BoxGeometry(0.42, 0.79, 0.42),
materials.woodDark,
counter,
[x, -0.955, z]
);
}
}
// ------------------------------------------------------------
// Pot and dynamically lowering rice
// ------------------------------------------------------------
const pot = new THREE.Group();
pot.position.set(-6.25, COUNTER_TOP, -1.05);
scene.add(pot);
const potProfile = [
new THREE.Vector2(0.0, 0.0),
new THREE.Vector2(0.65, 0.0),
new THREE.Vector2(0.78, 0.08),
new THREE.Vector2(0.92, 0.58),
new THREE.Vector2(0.94, 0.72),
new THREE.Vector2(0.94, 0.78),
new THREE.Vector2(0.82, 0.78),
new THREE.Vector2(0.80, 0.61),
new THREE.Vector2(0.67, 0.13),
new THREE.Vector2(0.0, 0.13)
];
addMesh(
new THREE.LatheGeometry(potProfile, 24),
materials.pot,
pot
);
addMesh(
new THREE.TorusGeometry(0.88, 0.065, 8, 28),
materials.potDark,
pot,
[0, 0.78, 0]
).rotation.x = Math.PI / 2;
for (const side of [-1, 1]) {
const handle = addMesh(
new THREE.TorusGeometry(0.29, 0.06, 8, 20),
materials.potDark,
pot,
[side * 0.94, 0.43, 0]
);
handle.rotation.y = Math.PI / 2;
}
const potRiceFill = addMesh(
new THREE.CylinderGeometry(0.79, 0.79, 1, 20),
materials.riceFull,
pot
);
const potSurface = new THREE.Group();
pot.add(potSurface);
const riceLumpGeometry = new THREE.DodecahedronGeometry(1, 0);
const potLumpData = [
[-0.36, 0.00, 0.02, 0.18, 0.065, 0.16],
[ 0.30, 0.00, 0.11, 0.17, 0.060, 0.15],
[ 0.04, 0.00, -0.34, 0.19, 0.065, 0.16],
[-0.08, 0.04, 0.27, 0.18, 0.065, 0.16],
[ 0.38, 0.01,-0.22, 0.14, 0.055, 0.13],
[-0.36, 0.00,-0.29, 0.14, 0.055, 0.13],
[ 0.00, 0.03,-0.02, 0.20, 0.070, 0.17]
];
for (const [x, y, z, sx, sy, sz] of potLumpData) {
const lump = addMesh(
riceLumpGeometry,
materials.riceFull,
potSurface,
[x, y, z]
);
lump.scale.set(sx, sy, sz);
}
// ------------------------------------------------------------
// Physical pot-level gauge
// ------------------------------------------------------------
const gaugeCanvas = document.createElement("canvas");
gaugeCanvas.width = 640;
gaugeCanvas.height = 360;
const gaugeContext = gaugeCanvas.getContext("2d");
const gaugeTexture = new THREE.CanvasTexture(gaugeCanvas);
gaugeTexture.colorSpace = THREE.SRGBColorSpace;
const gaugeBoard = new THREE.Group();
gaugeBoard.position.set(-7.95, COUNTER_TOP, -2.5);
gaugeBoard.rotation.y = 0.58;
scene.add(gaugeBoard);
for (const x of [-0.85, 0.85]) {
addMesh(
new THREE.BoxGeometry(0.12, 1.25, 0.12),
materials.woodDark,
gaugeBoard,
[x, 0.625, 0]
);
}
addMesh(
new THREE.BoxGeometry(2.7, 1.72, 0.14),
materials.woodDark,
gaugeBoard,
[0, 1.5, 0]
);
const gaugeFace = addMesh(
new THREE.PlaneGeometry(2.48, 1.5),
new THREE.MeshBasicMaterial({ map: gaugeTexture }),
gaugeBoard,
[0, 1.5, 0.076]
);
gaugeFace.castShadow = false;
gaugeFace.receiveShadow = false;
function drawGauge() {
const ctx = gaugeContext;
ctx.clearRect(0, 0, 640, 360);
ctx.fillStyle = "#fff8e9";
ctx.fillRect(0, 0, 640, 360);
ctx.strokeStyle = "#c8945f";
ctx.lineWidth = 8;
ctx.strokeRect(9, 9, 622, 342);
ctx.textAlign = "center";
ctx.fillStyle = "#9b563e";
ctx.font = "800 29px system-ui, sans-serif";
ctx.fillText("POT LEVEL", 320, 57);
ctx.fillStyle = "#49372d";
ctx.font = "850 54px system-ui, sans-serif";
ctx.fillText(
`${formatAmount(remaining)} / 8½`,
320,
125
);
ctx.fillStyle = "#806c5e";
ctx.font = "650 18px system-ui, sans-serif";
ctx.fillText("HALF-SCOOP UNITS", 320, 158);
const gap = 7;
const width = 25;
const startX = (640 - (17 * width + 16 * gap)) / 2;
for (let i = 0; i < 17; i++) {
const x = startX + i * (width + gap);
ctx.fillStyle = i < Math.round(remaining * 2) ? "#5f806b" : "#dfcfbb";
roundedRect(ctx, x, 190, width, 50, 7);
ctx.fill();
}
ctx.fillStyle = "#806c5e";
ctx.font = "750 17px system-ui, sans-serif";
ctx.fillText("8½-SCOOP FIXED BATCH", 320, 304);
gaugeTexture.needsUpdate = true;
}
// ------------------------------------------------------------
// One serving scoop
// ------------------------------------------------------------
const scoop = new THREE.Group();
scoop.position.set(-3.85, COUNTER_TOP, -1.2);
scoop.rotation.y = -0.28;
scene.add(scoop);
const scoopBowl = addMesh(
new THREE.SphereGeometry(
0.34,
18,
9,
0,
Math.PI * 2,
0,
Math.PI / 2
),
standardMaterial("#d7aa72", { side: THREE.DoubleSide }),
scoop,
[0, 0.13, 0]
);
scoopBowl.scale.z = 0.72;
const scoopRim = addMesh(
new THREE.TorusGeometry(0.34, 0.035, 8, 24),
materials.brass,
scoop,
[0, 0.13, 0]
);
scoopRim.rotation.x = Math.PI / 2;
scoopRim.scale.y = 0.72;
const scoopHandle = addMesh(
new THREE.CylinderGeometry(0.055, 0.055, 0.8, 10),
materials.woodDark,
scoop,
[0.57, 0.13, 0]
);
scoopHandle.rotation.z = Math.PI / 2;
addMesh(
new THREE.BoxGeometry(0.19, 0.11, 0.16),
materials.brass,
scoop,
[0.29, 0.13, 0]
);
// ------------------------------------------------------------
// Two side-dish platters
// ------------------------------------------------------------
function makePlatter(x, z, foodType) {
const group = new THREE.Group();
group.position.set(x, COUNTER_TOP, z);
scene.add(group);
const profile = [
new THREE.Vector2(0.0, 0.0),
new THREE.Vector2(0.24, 0.0),
new THREE.Vector2(0.54, 0.025),
new THREE.Vector2(0.70, 0.12),
new THREE.Vector2(0.74, 0.17),
new THREE.Vector2(0.69, 0.195),
new THREE.Vector2(0.58, 0.09),
new THREE.Vector2(0.27, 0.045),
new THREE.Vector2(0.0, 0.045)
];
addMesh(
new THREE.LatheGeometry(profile, 24),
foodType === "green" ? materials.bowlCream : materials.bowlPeach,
group
);
const food = new THREE.Group();
food.position.y = 0.12;
group.add(food);
if (foodType === "green") {
const beanGeometry = new THREE.SphereGeometry(1, 10, 7);
const locations = [
[-0.34, 0.00, 0.12, 0.22],
[-0.10, 0.03, 0.27, 0.23],
[ 0.21, 0.00, 0.18, 0.21],
[ 0.37, 0.02,-0.05, 0.18],
[-0.27, 0.02,-0.20, 0.20],
[ 0.04, 0.03,-0.12, 0.22],
[-0.02, 0.05, 0.02, 0.18]
];
locations.forEach(([bx, by, bz, length], index) => {
const bean = addMesh(
beanGeometry,
index % 3 === 0 ? materials.greenDark : materials.green,
food,
[bx, by, bz]
);
bean.scale.set(length, 0.065, 0.09);
bean.rotation.y = index * 0.91;
bean.rotation.z = (index % 2 ? 1 : -1) * 0.18;
});
} else {
const pickleGeometry = new THREE.CylinderGeometry(
0.095,
0.095,
0.16,
9
);
const locations = [
[-0.34, 0.01, 0.12, 0.3],
[-0.10, 0.02, 0.28, 1.1],
[ 0.16, 0.00, 0.23, 0.6],
[ 0.34, 0.03, 0.00, 1.3],
[-0.31, 0.02,-0.18, 0.8],
[ 0.00, 0.02,-0.21, 0.4],
[ 0.22, 0.04,-0.19, 1.0],
[-0.07, 0.07, 0.02, 0.2]
];
locations.forEach(([px, py, pz, rot], index) => {
const pickle = addMesh(
pickleGeometry,
index % 4 === 0 ? materials.plum : materials.orange,
food,
[px, py, pz]
);
pickle.rotation.z = rot;
});
}
}
makePlatter(-5.55, 1.37, "green");
makePlatter(-3.25, 1.37, "orange");
// ------------------------------------------------------------
// Nine bowls, with broad rice clusters rather than individual grains
// ------------------------------------------------------------
const bowlProfile = [
new THREE.Vector2(0.00, 0.00),
new THREE.Vector2(0.19, 0.00),
new THREE.Vector2(0.28, 0.035),
new THREE.Vector2(0.42, 0.19),
new THREE.Vector2(0.46, 0.29),
new THREE.Vector2(0.455, 0.335),
new THREE.Vector2(0.405, 0.32),
new THREE.Vector2(0.36, 0.17),
new THREE.Vector2(0.19, 0.065),
new THREE.Vector2(0.00, 0.065)
];
function numberTexture(number) {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 128, 128);
ctx.fillStyle = "rgba(73,55,45,0.88)";
ctx.beginPath();
ctx.arc(64, 64, 47, 0, Math.PI * 2);
ctx.fill();
ctx.strokeStyle = "#e9c27d";
ctx.lineWidth = 4;
ctx.stroke();
ctx.fillStyle = "#fff4dc";
ctx.font = "800 55px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(String(number), 64, 67);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
for (let i = 0; i < MAX_PEOPLE; i++) {
const x = -1.3 + i * 1.22;
const z = 1.35;
const bowlGroup = new THREE.Group();
bowlGroup.position.set(x, COUNTER_TOP, z);
scene.add(bowlGroup);
const body = addMesh(
new THREE.LatheGeometry(bowlProfile, 24),
i % 3 === 1 ? materials.bowlPeach : materials.bowlCream,
bowlGroup
);
const rim = addMesh(
new THREE.TorusGeometry(0.435, 0.024, 7, 24),
materials.stripe,
bowlGroup,
[0, 0.325, 0]
);
rim.rotation.x = Math.PI / 2;
const riceMaterial = materials.riceFull.clone();
const rice = new THREE.Group();
rice.position.y = 0.145;
bowlGroup.add(rice);
const clusterData = [
[ 0.00, 0.00, 0.00, 0.19, 0.105, 0.16],
[-0.12, 0.00, 0.04, 0.145, 0.080, 0.13],
[ 0.13, 0.00, 0.035, 0.14, 0.078, 0.125],
[ 0.00, 0.00,-0.13, 0.15, 0.080, 0.13],
[ 0.035,0.045,-0.055,0.12, 0.07, 0.105]
];
for (const [rx, ry, rz, sx, sy, sz] of clusterData) {
const lump = addMesh(
riceLumpGeometry,
riceMaterial,
rice,
[rx, ry, rz]
);
lump.scale.set(sx, sy, sz);
}
// A small amber marker makes the reduced final serving obvious.
const partialMarker = addMesh(
new THREE.SphereGeometry(0.055, 10, 7),
materials.brass,
bowlGroup,
[0.405, 0.355, 0.03]
);
partialMarker.visible = false;
const plaque = addMesh(
new THREE.PlaneGeometry(0.28, 0.28),
new THREE.MeshBasicMaterial({
map: numberTexture(i + 1),
transparent: true,
depthWrite: false
}),
scene,
[x, COUNTER_TOP + 0.009, z + 0.65]
);
plaque.rotation.x = -Math.PI / 2;
plaque.castShadow = false;
plaque.receiveShadow = false;
body.userData.bowlIndex = i;
rim.userData.bowlIndex = i;
interactiveMeshes.push(body, rim);
bowls.push({
group: bowlGroup,
body,
rice,
riceMaterial,
partialMarker,
current: 0,
target: 0
});
}
// ------------------------------------------------------------
// Interface state and distribution
// ------------------------------------------------------------
for (let i = 0; i < 17; i++) {
const pip = document.createElement("span");
pip.className = "pip";
potPips.appendChild(pip);
}
const servingChips = [];
for (let i = 0; i < MAX_PEOPLE; i++) {
const chip = document.createElement("div");
chip.className = "serving-chip";
chip.dataset.number = String(i + 1);
chip.textContent = "·";
distribution.appendChild(chip);
servingChips.push(chip);
}
function updateDistribution() {
const targets = new Array(MAX_PEOPLE).fill(0);
const fullPeople = Math.min(people, FULL_SCOOP_CAPACITY);
for (let i = 0; i < fullPeople; i++) {
targets[i] = 1;
}
if (people === MAX_PEOPLE) {
targets[FULL_SCOOP_CAPACITY] = 0.5;
}
served = targets.reduce((sum, amount) => sum + amount, 0);
remaining = BATCH_SCOOPS - served;
bowls.forEach((bowl, index) => {
bowl.target = targets[index];
if (targets[index] > 0 && targets[index] < 0.99) {
bowl.riceMaterial.color.copy(materials.ricePartial.color);
} else {
bowl.riceMaterial.color.copy(materials.riceFull.color);
}
bowl.partialMarker.visible = targets[index] > 0 && targets[index] < 0.99;
});
peopleValue.textContent = String(people);
slider.setAttribute("aria-valuetext", `${people} people`);
servedMetric.textContent = formatAmount(served);
remainingMetric.textContent = formatAmount(remaining);
const percent = Math.round((remaining / BATCH_SCOOPS) * 100);
remainingPercent.textContent = `${percent}%`;
[...potPips.children].forEach((pip, index) => {
pip.classList.toggle("on", index < Math.round(remaining * 2));
});
servingChips.forEach((chip, index) => {
const amount = targets[index];
chip.className = "serving-chip";
if (amount === 1) {
chip.classList.add("full");
chip.textContent = "●";
chip.title = `Bowl ${index + 1}: one full scoop`;
} else if (amount > 0) {
chip.classList.add("partial");
chip.textContent = "½";
chip.title = `Bowl ${index + 1}: half scoop, the final partial serving`;
} else {
chip.textContent = "·";
chip.title = `Bowl ${index + 1}: not served`;
}
});
drawGauge();
}
slider.addEventListener("input", () => {
people = Number(slider.value);
updateDistribution();
});
document.querySelector("#minus").addEventListener("click", () => {
people = Math.max(1, people - 1);
slider.value = String(people);
updateDistribution();
});
document.querySelector("#plus").addEventListener("click", () => {
people = Math.min(MAX_PEOPLE, people + 1);
slider.value = String(people);
updateDistribution();
});
updateDistribution();
// ------------------------------------------------------------
// Direct camera controls: orbit, zoom, and reset
// ------------------------------------------------------------
let fitScale = 1;
let dragging = false;
let pointerX = 0;
let pointerY = 0;
let activePointerId = null;
function updateCamera() {
const radius = cameraState.radius * fitScale;
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + radius * Math.cos(cameraState.phi),
cameraState.target.z + radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.theta = 0.58;
cameraState.phi = 1.03;
cameraState.radius = 21.5;
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
activePointerId = event.pointerId;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
tooltip.style.display = "none";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (dragging && event.pointerId === activePointerId) {
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
cameraState.theta -= dx * 0.005;
cameraState.phi -= dy * 0.004;
cameraState.theta = THREE.MathUtils.clamp(
cameraState.theta,
-0.55,
1.2
);
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi,
0.58,
1.22
);
pointerX = event.clientX;
pointerY = event.clientY;
updateCamera();
return;
}
const rect = renderer.domElement.getBoundingClientRect();
const mouse = new THREE.Vector2(
((event.clientX - rect.left) / rect.width) * 2 - 1,
-((event.clientY - rect.top) / rect.height) * 2 + 1
);
raycaster.setFromCamera(mouse, camera);
const hit = raycaster.intersectObjects(interactiveMeshes, false)[0];
if (hit) {
const index = hit.object.userData.bowlIndex;
const amount = bowls[index].target;
if (amount === 1) {
tooltip.textContent = `Bowl ${index + 1} · 1 full scoop`;
} else if (amount > 0) {
tooltip.textContent = `Bowl ${index + 1} · ½ scoop (final partial serving)`;
} else {
tooltip.textContent = `Bowl ${index + 1} · Not served`;
}
tooltip.style.display = "block";
tooltip.style.left = `${event.clientX}px`;
tooltip.style.top = `${event.clientY}px`;
} else {
tooltip.style.display = "none";
}
});
const raycaster = new THREE.Raycaster();
function endDrag(event) {
if (event.pointerId !== activePointerId) return;
dragging = false;
activePointerId = null;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
13,
29
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.querySelector("#resetCamera").addEventListener("click", resetCamera);
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
camera.aspect = width / height;
camera.fov = camera.aspect < 0.8 ? 50 : 42;
camera.updateProjectionMatrix();
fitScale = Math.max(1, 1.22 / camera.aspect);
updateCamera();
}
window.addEventListener("resize", resize);
resize();
// ------------------------------------------------------------
// Animation: transfer rice from the pot to bowls
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
const targetPotFraction = remaining / BATCH_SCOOPS;
animatedPotFraction = THREE.MathUtils.damp(
animatedPotFraction,
targetPotFraction,
7.5,
dt
);
const f = Math.max(0.0001, animatedPotFraction);
const fillHeight = 0.57 * f;
potRiceFill.visible = animatedPotFraction > 0.002;
potRiceFill.scale.y = fillHeight;
potRiceFill.position.y = 0.15 + fillHeight / 2;
potSurface.visible = animatedPotFraction > 0.006;
potSurface.position.y = 0.15 + 0.57 * f;
potSurface.scale.set(
Math.sqrt(f),
Math.max(0.04, f),
Math.sqrt(f)
);
for (const bowl of bowls) {
bowl.current = THREE.MathUtils.damp(
bowl.current,
bowl.target,
8,
dt
);
const amount = Math.max(0, bowl.current);
bowl.rice.visible = amount > 0.004;
// Horizontal area shrinks with the square root of volume,
// while height scales with the remaining volume.
const widthScale = Math.sqrt(amount);
bowl.rice.scale.set(widthScale, amount, widthScale);
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```