Prompt specification
Build or customize the Three.js 3D scene "Texture and mixing kitchen exhibit" 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: Texture and mixing kitchen exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/texture-and-mixing-kitchen-exhibit-x0120
Scene Description Prompt:
Texture and mixing kitchen exhibit. Build transparent bowls containing coarse and fine herb pieces in identical mixtures; stirring shows their distribution differences using visible particles and clearly labeled qualitative behavior. Please build this with Three.js from cdnjs in one self-contained HTML file, using visible voxel blocks.
Working Three.js Starter (texture-and-mixing-kitchen-exhibit-x0120):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Texture Lab — Mixing Kitchen Exhibit</title>
<style>
:root {
--panel: rgba(17, 28, 24, 0.88);
--panel-border: rgba(220, 238, 224, 0.14);
--text: #f3f7ef;
--muted: #aebdb2;
--green: #a7d96c;
--green-dark: #5d9a62;
--amber: #e8bb68;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #15201b;
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.hero {
position: absolute;
top: 25px;
left: 28px;
width: min(440px, calc(100vw - 390px));
text-shadow: 0 2px 16px rgba(0, 0, 0, 0.35);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--green);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 23px;
height: 2px;
background: var(--green);
}
h1 {
margin: 0;
font-size: clamp(29px, 3.2vw, 47px);
line-height: 1.02;
letter-spacing: -0.045em;
font-weight: 760;
}
.hero p {
max-width: 420px;
margin: 12px 0 0;
color: #c5d1c8;
font-size: 14px;
line-height: 1.55;
}
.control-panel {
position: absolute;
top: 24px;
right: 24px;
width: 325px;
padding: 18px;
border: 1px solid var(--panel-border);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 20px 55px rgba(0, 0, 0, 0.26);
backdrop-filter: blur(16px);
pointer-events: auto;
}
.panel-heading {
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
margin-bottom: 14px;
}
.panel-heading strong {
display: block;
font-size: 13px;
letter-spacing: 0.02em;
}
.live-state {
display: flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
white-space: nowrap;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #839188;
box-shadow: 0 0 0 4px rgba(131, 145, 136, 0.08);
transition: 180ms ease;
}
.live-dot.active {
background: var(--green);
box-shadow: 0 0 0 4px rgba(167, 217, 108, 0.13);
animation: pulse 1.2s infinite;
}
@keyframes pulse {
50% {
box-shadow: 0 0 0 7px rgba(167, 217, 108, 0.03);
}
}
.stir-button {
width: 100%;
min-height: 54px;
border: 0;
border-radius: 13px;
background: var(--green);
color: #172018;
font-size: 14px;
font-weight: 850;
cursor: pointer;
box-shadow: 0 8px 24px rgba(105, 159, 73, 0.18);
transition: transform 150ms ease, background 150ms ease;
}
.stir-button:hover {
transform: translateY(-1px);
background: #b9e781;
}
.stir-button:active {
transform: translateY(1px);
}
.stir-button.stopped {
background: #e4ece4;
}
.speed-row {
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
gap: 10px;
margin-top: 18px;
font-size: 12px;
font-weight: 650;
}
.speed-row output {
min-width: 42px;
padding: 4px 7px;
border: 1px solid var(--panel-border);
border-radius: 7px;
color: var(--green);
text-align: center;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
grid-column: 1 / -1;
width: 100%;
height: 4px;
margin: 2px 0 0;
border-radius: 4px;
appearance: none;
background: linear-gradient(
90deg,
var(--green) 0%,
var(--green) 33%,
rgba(255, 255, 255, 0.12) 33%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
border: 3px solid #263329;
border-radius: 50%;
appearance: none;
background: var(--green);
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.2);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid #263329;
border-radius: 50%;
background: var(--green);
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 15px;
}
.secondary-button {
min-height: 38px;
border: 1px solid var(--panel-border);
border-radius: 10px;
background: rgba(255, 255, 255, 0.035);
color: #dce6de;
font-size: 11px;
font-weight: 750;
cursor: pointer;
}
.secondary-button:hover {
background: rgba(255, 255, 255, 0.08);
}
.experiment-note {
margin-top: 16px;
padding-top: 14px;
border-top: 1px solid var(--panel-border);
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.experiment-note strong {
color: #e7efe8;
}
.blend-row {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
color: #e4ebe5;
font-size: 11px;
font-weight: 700;
}
.swatches {
display: flex;
gap: 4px;
}
.swatch {
width: 11px;
height: 11px;
border-radius: 3px;
}
.swatch.basil {
background: #8fc65b;
}
.swatch.parsley {
background: #2e7651;
}
.comparison {
position: absolute;
left: 50%;
bottom: 23px;
display: flex;
gap: 12px;
transform: translateX(-50%);
}
.behavior-card {
width: 292px;
padding: 15px 16px;
border: 1px solid var(--panel-border);
border-radius: 15px;
background: rgba(17, 28, 24, 0.88);
box-shadow: 0 15px 45px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(15px);
}
.card-top {
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
margin-bottom: 8px;
}
.card-title {
display: flex;
align-items: center;
gap: 9px;
font-size: 13px;
font-weight: 850;
}
.voxel-icon {
width: 16px;
height: 16px;
border-radius: 3px;
background: #8fc65b;
box-shadow:
4px 4px 0 #2e7651,
8px 0 0 rgba(143, 198, 91, 0.45);
transform: translateY(-2px);
}
.voxel-icon.small {
width: 10px;
height: 10px;
border-radius: 2px;
box-shadow:
3px 3px 0 #2e7651,
6px 0 0 rgba(143, 198, 91, 0.45);
}
.behavior-tag {
padding: 5px 7px;
border-radius: 6px;
background: rgba(232, 187, 104, 0.13);
color: #f2cc87;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.08em;
text-align: right;
text-transform: uppercase;
}
.behavior-card.fine .behavior-tag {
background: rgba(167, 217, 108, 0.12);
color: #bde58a;
}
.behavior-card p {
margin: 0;
color: #adbbb1;
font-size: 11px;
line-height: 1.5;
}
.bowl-label {
position: absolute;
width: 180px;
padding: 10px 12px;
border: 1px solid rgba(225, 241, 228, 0.17);
border-radius: 12px;
background: rgba(14, 24, 20, 0.88);
box-shadow: 0 10px 35px rgba(0, 0, 0, 0.2);
backdrop-filter: blur(12px);
transform: translate(-50%, -100%);
transition: opacity 120ms linear;
}
.bowl-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -8px;
width: 1px;
height: 8px;
background: rgba(225, 241, 228, 0.34);
}
.label-kicker {
color: var(--green);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.label-title {
margin-top: 3px;
font-size: 14px;
font-weight: 850;
}
.label-behavior {
margin-top: 4px;
color: #d6dfd7;
font-size: 9px;
font-weight: 750;
line-height: 1.3;
}
.label-metrics {
display: flex;
gap: 12px;
margin-top: 7px;
padding-top: 6px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
color: #91a096;
font-size: 8px;
font-weight: 700;
}
.label-metrics b {
color: #d7e2d9;
}
.camera-hint {
position: absolute;
right: 26px;
bottom: 25px;
color: rgba(225, 235, 227, 0.55);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.04em;
}
@media (max-width: 1050px) {
.hero {
width: 360px;
}
.hero p {
display: none;
}
.comparison {
left: 24px;
transform: none;
}
.behavior-card {
width: 260px;
}
.camera-hint {
display: none;
}
}
@media (max-width: 720px) {
.hero {
top: 17px;
left: 17px;
width: calc(100vw - 34px);
}
.hero h1 {
font-size: 29px;
}
.control-panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
padding: 13px;
}
.experiment-note,
.speed-row {
display: none;
}
.comparison {
top: 105px;
bottom: auto;
left: 12px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 6px;
}
.behavior-card {
width: auto;
padding: 10px;
}
.behavior-card p,
.behavior-tag {
display: none;
}
.card-title {
font-size: 10px;
}
.bowl-label {
width: 142px;
padding: 8px 9px;
}
.label-title {
font-size: 11px;
}
.label-behavior {
font-size: 8px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive kitchen mixing exhibit"></canvas>
<div class="ui">
<header class="hero">
<div class="eyebrow">Texture Lab · Exhibit 04</div>
<h1>Texture changes<br>the mixing story.</h1>
<p>
Two transparent bowls, the same basil-and-parsley blend, and the same
stirrer. Only the herb cut size changes.
</p>
</header>
<aside class="control-panel" aria-label="Experiment controls">
<div class="panel-heading">
<strong>Controlled mixing comparison</strong>
<div class="live-state">
<span id="liveDot" class="live-dot"></span>
<span id="liveState">Ready</span>
</div>
</div>
<button id="stirButton" class="stir-button" type="button">
▶ Start stirring both bowls
</button>
<div class="speed-row">
<label for="speed">Stir speed</label>
<output id="speedValue" for="speed">1.0×</output>
<input
id="speed"
type="range"
min="0.5"
max="1.8"
step="0.1"
value="1"
>
</div>
<div class="button-row">
<button id="resetButton" class="secondary-button" type="button">
↺ Reset mixture
</button>
<button id="viewButton" class="secondary-button" type="button">
⌂ Reset view
</button>
</div>
<div class="experiment-note">
<div class="blend-row">
<span>Same blend in both bowls</span>
<span class="swatches" aria-label="Basil and parsley">
<span class="swatch basil"></span>
<span class="swatch parsley"></span>
</span>
</div>
<strong>60% basil · 40% parsley.</strong><br>
72 large voxels versus 216 small voxels preserve a comparable batch
volume. Every herb piece is rendered as a visible block.
</div>
</aside>
<div id="labelA" class="bowl-label">
<div class="label-kicker">Bowl A · Same blend</div>
<div class="label-title">Coarse-cut herbs</div>
<div id="behaviorA" class="label-behavior">SETTLED · PATCHY LAYER</div>
<div class="label-metrics">
<span>Suspended <b id="suspensionA">0%</b></span>
<span>Evenness <b id="evennessA">0%</b></span>
</div>
</div>
<div id="labelB" class="bowl-label">
<div class="label-kicker">Bowl B · Same blend</div>
<div class="label-title">Fine-cut herbs</div>
<div id="behaviorB" class="label-behavior">SETTLED · EVEN LAYER</div>
<div class="label-metrics">
<span>Suspended <b id="suspensionB">0%</b></span>
<span>Evenness <b id="evennessB">0%</b></span>
</div>
</div>
<section class="comparison" aria-label="Qualitative behavior comparison">
<article class="behavior-card">
<div class="card-top">
<div class="card-title">
<span class="voxel-icon"></span>
COARSE CUT
</div>
<div id="coarseTag" class="behavior-tag">Fast settling · clumpy</div>
</div>
<p>
Large blocks rise briefly, then fall quickly. Visible clumps and
patchy layers develop as the mixture loses circulation.
</p>
</article>
<article class="behavior-card fine">
<div class="card-top">
<div class="card-title">
<span class="voxel-icon small"></span>
FINE CUT
</div>
<div id="fineTag" class="behavior-tag">Slow settling · even</div>
</div>
<p>
Small blocks follow the flow longer and remain suspended. The
distribution stays more even instead of collapsing into clumps.
</p>
</article>
</section>
<div class="camera-hint">Drag to orbit · Scroll or pinch to zoom</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const canvas = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x17211c);
scene.fog = new THREE.Fog(0x17211c, 12, 24);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
60
);
const state = {
stirring: false,
speed: 1,
simulationTime: 0,
stirStartTime: 0,
stirEndTime: 0,
justReset: true
};
const cameraTarget = new THREE.Vector3(0, 1.05, 0);
const cameraState = {
radius: 10.6,
theta: 0.12,
phi: 1.08
};
function updateCamera() {
const { radius, theta, phi } = cameraState;
camera.position.set(
cameraTarget.x + radius * Math.sin(phi) * Math.sin(theta),
cameraTarget.y + radius * Math.cos(phi),
cameraTarget.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraState.radius = window.innerWidth < 720 ? 13.4 : 10.6;
cameraState.theta = 0.12;
cameraState.phi = 1.08;
updateCamera();
}
resetCamera();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xdbead8, 0x3a3027, 2.0));
const keyLight = new THREE.DirectionalLight(0xfff1cf, 4.1);
keyLight.position.set(4.5, 8.5, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.normalBias = 0.035;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x91c8a2, 2.2);
rimLight.position.set(-5, 4.5, -2);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffbb6d, 30, 11, 2);
warmLight.position.set(5.5, 2.8, 3);
scene.add(warmLight);
// -------------------------------------------------------------------------
// Procedural kitchen textures
// -------------------------------------------------------------------------
function makeCounterTexture() {
const c = document.createElement("canvas");
c.width = c.height = 512;
const ctx = c.getContext("2d");
ctx.fillStyle = "#9b7651";
ctx.fillRect(0, 0, 512, 512);
for (let row = 0; row < 4; row++) {
const y = row * 128;
const shade = 139 + row * 7;
ctx.fillStyle = `rgb(${shade + 25}, ${shade - 5}, ${shade - 47})`;
ctx.fillRect(0, y, 512, 126);
ctx.strokeStyle = "rgba(52,35,22,.36)";
ctx.lineWidth = 3;
ctx.beginPath();
ctx.moveTo(0, y + 1);
ctx.lineTo(512, y + 1);
ctx.stroke();
for (let j = 0; j < 30; j++) {
const gy = y + 8 + Math.random() * 110;
ctx.strokeStyle = `rgba(69,43,25,${0.035 + Math.random() * 0.055})`;
ctx.lineWidth = 1 + Math.random();
ctx.beginPath();
ctx.moveTo(0, gy);
ctx.bezierCurveTo(
140,
gy + Math.random() * 12 - 6,
350,
gy + Math.random() * 12 - 6,
512,
gy
);
ctx.stroke();
}
}
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(3.5, 2);
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function makeTileTexture() {
const c = document.createElement("canvas");
c.width = c.height = 512;
const ctx = c.getContext("2d");
ctx.fillStyle = "#b9b7a9";
ctx.fillRect(0, 0, 512, 512);
const tile = 128;
for (let y = 0; y < 512; y += tile) {
for (let x = 0; x < 512; x += tile) {
const light = 208 + Math.floor(Math.random() * 14);
ctx.fillStyle = `rgb(${light}, ${light + 1}, ${light - 10})`;
ctx.fillRect(x + 4, y + 4, tile - 8, tile - 8);
ctx.strokeStyle = "rgba(255,255,255,.22)";
ctx.lineWidth = 2;
ctx.strokeRect(x + 7, y + 7, tile - 14, tile - 14);
}
}
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(4, 2);
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function makeSignTexture() {
const c = document.createElement("canvas");
c.width = 1024;
c.height = 256;
const ctx = c.getContext("2d");
ctx.fillStyle = "#17241d";
ctx.fillRect(0, 0, 1024, 256);
ctx.strokeStyle = "#83a96b";
ctx.lineWidth = 8;
ctx.strokeRect(14, 14, 996, 228);
ctx.textAlign = "center";
ctx.fillStyle = "#d7e9ce";
ctx.font = "800 53px Arial";
ctx.fillText("TEXTURE / MIXING LAB", 512, 102);
ctx.fillStyle = "#91b67c";
ctx.font = "700 25px Arial";
ctx.fillText("SAME BLEND • SAME FLOW • DIFFERENT CUT SIZE", 512, 158);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
// -------------------------------------------------------------------------
// Kitchen environment
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const counterMaterial = new THREE.MeshStandardMaterial({
map: makeCounterTexture(),
roughness: 0.77,
metalness: 0.02
});
const counter = new THREE.Mesh(
new THREE.BoxGeometry(18, 0.34, 9),
counterMaterial
);
counter.position.set(0, -0.13, -0.7);
counter.receiveShadow = true;
scene.add(counter);
const wallMaterial = new THREE.MeshStandardMaterial({
map: makeTileTexture(),
roughness: 0.9
});
const wall = new THREE.Mesh(
new THREE.BoxGeometry(18, 6.5, 0.22),
wallMaterial
);
wall.position.set(0, 3, -4.8);
wall.receiveShadow = true;
scene.add(wall);
const darkWood = new THREE.MeshStandardMaterial({
color: 0x4d3727,
roughness: 0.8
});
const shelf = new THREE.Mesh(
new THREE.BoxGeometry(11.5, 0.18, 0.72),
darkWood
);
shelf.position.set(0, 3.85, -4.35);
shelf.castShadow = true;
shelf.receiveShadow = true;
scene.add(shelf);
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(5.4, 1.35),
new THREE.MeshBasicMaterial({ map: makeSignTexture() })
);
sign.position.set(0, 3.35, -4.66);
scene.add(sign);
const board = new THREE.Mesh(
new THREE.BoxGeometry(2.2, 0.12, 1.45),
new THREE.MeshStandardMaterial({
color: 0xb88450,
roughness: 0.76
})
);
board.position.set(-5.1, 0.11, -0.65);
board.rotation.y = 0.24;
board.castShadow = true;
board.receiveShadow = true;
scene.add(board);
const knifeHandle = new THREE.Mesh(
new THREE.BoxGeometry(0.78, 0.1, 0.24),
new THREE.MeshStandardMaterial({
color: 0x322820,
roughness: 0.65
})
);
knifeHandle.position.set(-4.95, 0.24, -0.35);
knifeHandle.rotation.y = 0.24;
knifeHandle.castShadow = true;
scene.add(knifeHandle);
const knifeBlade = new THREE.Mesh(
new THREE.BoxGeometry(0.9, 0.045, 0.34),
new THREE.MeshStandardMaterial({
color: 0xc7d2d3,
metalness: 0.85,
roughness: 0.25
})
);
knifeBlade.position.set(-5.63, 0.22, -0.51);
knifeBlade.rotation.y = 0.24;
knifeBlade.castShadow = true;
scene.add(knifeBlade);
const boardHerbMaterial = new THREE.MeshStandardMaterial({
color: 0x6fa448,
roughness: 0.88
});
for (let i = 0; i < 15; i++) {
const herb = new THREE.Mesh(
unitBox,
i % 4 === 0
? new THREE.MeshStandardMaterial({
color: 0x397d4e,
roughness: 0.9
})
: boardHerbMaterial
);
herb.scale.set(
0.08 + Math.random() * 0.08,
0.055 + Math.random() * 0.05,
0.08 + Math.random() * 0.08
);
herb.position.set(
-5.45 + Math.random() * 0.85,
0.24 + Math.random() * 0.1,
-0.95 + Math.random() * 0.55
);
herb.rotation.set(
Math.random(),
Math.random() * Math.PI,
Math.random()
);
herb.castShadow = true;
scene.add(herb);
}
// Simple block-built herb canisters on the shelf.
const canisterGlass = new THREE.MeshStandardMaterial({
color: 0xbdd6c6,
transparent: true,
opacity: 0.2,
roughness: 0.15,
depthWrite: false
});
const canisterLid = new THREE.MeshStandardMaterial({
color: 0x313b34,
roughness: 0.55,
metalness: 0.3
});
for (let i = 0; i < 4; i++) {
const group = new THREE.Group();
group.position.set(-3.65 + i * 2.35, 4.36, -4.3);
const jar = new THREE.Mesh(
new THREE.BoxGeometry(0.75, 0.85, 0.58),
canisterGlass
);
jar.castShadow = true;
group.add(jar);
const lid = new THREE.Mesh(
new THREE.BoxGeometry(0.82, 0.12, 0.65),
canisterLid
);
lid.position.y = 0.47;
lid.castShadow = true;
group.add(lid);
const contentMaterial = new THREE.MeshStandardMaterial({
color: i % 2 === 0 ? 0x7daf50 : 0x376f4b,
roughness: 0.95
});
for (let j = 0; j < 13; j++) {
const piece = new THREE.Mesh(unitBox, contentMaterial);
piece.scale.set(0.12, 0.1, 0.11);
piece.position.set(
(Math.random() - 0.5) * 0.48,
-0.25 + Math.random() * 0.45,
(Math.random() - 0.5) * 0.33
);
piece.rotation.set(
Math.random(),
Math.random(),
Math.random()
);
group.add(piece);
}
scene.add(group);
}
// -------------------------------------------------------------------------
// Shared materials and geometry
// -------------------------------------------------------------------------
const herbMaterials = [
new THREE.MeshStandardMaterial({
color: 0x8fc65b,
roughness: 0.82,
emissive: 0x15270d,
emissiveIntensity: 0.22,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x2e7651,
roughness: 0.88,
emissive: 0x0b1e13,
emissiveIntensity: 0.18,
flatShading: true
})
];
const metalMaterial = new THREE.MeshStandardMaterial({
color: 0xd4ddd8,
metalness: 0.72,
roughness: 0.28
});
const woodMaterial = new THREE.MeshStandardMaterial({
color: 0xb88452,
roughness: 0.67
});
const glassMaterial = new THREE.MeshPhysicalMaterial({
color: 0xc5e4dd,
transparent: true,
opacity: 0.22,
roughness: 0.08,
metalness: 0,
clearcoat: 0.8,
clearcoatRoughness: 0.1,
side: THREE.DoubleSide,
depthWrite: false
});
const rimGeometry = new THREE.BoxGeometry(0.065, 0.065, 0.15);
// -------------------------------------------------------------------------
// Bowls and stirrers
// -------------------------------------------------------------------------
function createBowl(type, xPosition) {
const group = new THREE.Group();
group.position.x = xPosition;
scene.add(group);
const profile = [
new THREE.Vector2(0.0, 0.20),
new THREE.Vector2(0.46, 0.20),
new THREE.Vector2(0.66, 0.25),
new THREE.Vector2(0.86, 0.43),
new THREE.Vector2(1.04, 0.82),
new THREE.Vector2(1.18, 1.34),
new THREE.Vector2(1.27, 1.86),
new THREE.Vector2(1.225, 1.86),
new THREE.Vector2(1.135, 1.36),
new THREE.Vector2(1.0, 0.88),
new THREE.Vector2(0.82, 0.51),
new THREE.Vector2(0.63, 0.36),
new THREE.Vector2(0.45, 0.34),
new THREE.Vector2(0.0, 0.34)
];
const glass = new THREE.Mesh(
new THREE.LatheGeometry(profile, 72),
glassMaterial
);
glass.renderOrder = 4;
group.add(glass);
// Voxel-built rim makes the transparent outline immediately legible.
for (let i = 0; i < 56; i++) {
const angle = (i / 56) * Math.PI * 2;
const rim = new THREE.Mesh(rimGeometry, glassMaterial);
rim.position.set(
Math.cos(angle) * 1.245,
1.87,
Math.sin(angle) * 1.245
);
rim.rotation.y = angle;
rim.renderOrder = 5;
group.add(rim);
}
// A warm wooden foot gives the glass bowl a physical kitchen object feel.
const foot = new THREE.Mesh(
new THREE.CylinderGeometry(0.54, 0.61, 0.13, 40),
woodMaterial
);
foot.position.y = 0.14;
foot.castShadow = true;
foot.receiveShadow = true;
group.add(foot);
const stirrer = new THREE.Group();
group.add(stirrer);
const shaft = new THREE.Mesh(
new THREE.BoxGeometry(0.055, 1.95, 0.055),
metalMaterial
);
shaft.position.y = 1.43;
shaft.castShadow = true;
stirrer.add(shaft);
const grip = new THREE.Mesh(
new THREE.BoxGeometry(0.3, 0.13, 0.13),
woodMaterial
);
grip.position.y = 2.44;
grip.castShadow = true;
stirrer.add(grip);
const paddle = new THREE.Group();
paddle.position.y = 0.79;
stirrer.add(paddle);
const hub = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 0.15, 0.18),
metalMaterial
);
hub.castShadow = true;
paddle.add(hub);
for (let i = 0; i < 4; i++) {
const angle = (i / 4) * Math.PI * 2;
const blade = new THREE.Mesh(
new THREE.BoxGeometry(0.7, 0.075, 0.12),
metalMaterial
);
blade.position.set(
Math.cos(angle) * 0.31,
0,
Math.sin(angle) * 0.31
);
blade.rotation.y = -angle;
blade.castShadow = true;
paddle.add(blade);
}
return {
type,
group,
stirrer,
paddle,
particles: [],
xPosition
};
}
const bowlA = createBowl("coarse", -2.15);
const bowlB = createBowl("fine", 2.15);
// -------------------------------------------------------------------------
// Voxel particles
// -------------------------------------------------------------------------
function seededRandom(seed) {
let value = seed >>> 0;
return function () {
value += 0x6d2b79f5;
let t = value;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
function createParticles(bowl) {
const isCoarse = bowl.type === "coarse";
const random = seededRandom(isCoarse ? 4401 : 4402);
const count = isCoarse ? 72 : 216;
const side = isCoarse ? 0.16 : 0.111;
const perLayer = isCoarse ? 36 : 54;
const layerHeight = isCoarse ? 0.16 : 0.115;
for (let i = 0; i < count; i++) {
const layer = Math.floor(i / perLayer);
const angle = random() * Math.PI * 2;
const radius = Math.sqrt(random()) * (isCoarse ? 0.82 : 0.89);
const x = Math.cos(angle) * radius;
const z = Math.sin(angle) * radius;
const y = 0.49 + layer * layerHeight + random() * 0.025;
// Exact 60/40 blend ratio in both bowls.
const species = i % 5 < 3 ? 0 : 1;
const mesh = new THREE.Mesh(unitBox, herbMaterials[species]);
const sizeVariation = 0.93 + random() * 0.14;
mesh.scale.set(
side * sizeVariation,
side * (0.9 + random() * 0.18),
side * (0.93 + random() * 0.14)
);
mesh.position.set(x, y, z);
mesh.rotation.set(
random() * Math.PI,
random() * Math.PI,
random() * Math.PI
);
mesh.castShadow = true;
mesh.receiveShadow = true;
bowl.group.add(mesh);
bowl.particles.push({
mesh,
x,
y,
z,
vx: 0,
vy: 0,
vz: 0,
phase: random() * Math.PI * 2,
cluster: i % 3,
start: { x, y, z }
});
}
}
createParticles(bowlA);
createParticles(bowlB);
// -------------------------------------------------------------------------
// Mixing simulation
// -------------------------------------------------------------------------
const coarseProperties = {
gravity: 3.6,
drag: 1.5,
flow: 1.65,
radialJitter: 0.58,
verticalGain: 4.4,
restGain: 3.8,
restY: 0.49,
baseY: 0.56,
amplitude: 0.48,
waveSpeed: 2.15,
lift: 3.9,
cluster: 0.75,
maxY: 1.64
};
const fineProperties = {
gravity: 0.95,
drag: 0.62,
flow: 2.25,
radialJitter: 0.26,
verticalGain: 2.75,
restGain: 1.25,
restY: 0.48,
baseY: 0.62,
amplitude: 0.94,
waveSpeed: 1.45,
lift: 1.9,
cluster: 0.025,
maxY: 1.76
};
function updateParticles(bowl, dt, time) {
const props = bowl.type === "coarse"
? coarseProperties
: fineProperties;
for (const p of bowl.particles) {
const radius = Math.max(0.001, Math.hypot(p.x, p.z));
const tangentX = -p.z / radius;
const tangentZ = p.x / radius;
let ax = 0;
let az = 0;
let ay = -props.gravity;
if (state.stirring) {
const flow = props.flow * state.speed;
ax += tangentX * flow;
az += tangentZ * flow;
// Gentle inward correction keeps particles following the bowl wall.
ax -= p.x * 0.18;
az -= p.z * 0.18;
// Small deterministic perturbations prevent a perfectly sterile flow.
ax += Math.sin(time * 2.15 + p.phase * 3.1) * props.radialJitter;
az += Math.cos(time * 1.73 + p.phase * 2.6) * props.radialJitter;
const wave = 0.5 + 0.5 * Math.sin(time * props.waveSpeed + p.phase);
const shapedWave = bowl.type === "coarse"
? Math.pow(wave, 2.6)
: wave;
const targetY =
props.baseY + props.amplitude * shapedWave;
ay += (targetY - p.y) * props.verticalGain;
ay +=
Math.max(
0,
Math.sin(time * 2.25 + p.phase * 1.7)
) * props.lift;
// Coarse pieces collect around a few moving flow centers.
// Fine pieces remain much more evenly distributed.
const clusterAngle = time * 0.58 + (p.cluster / 3) * Math.PI * 2;
const clusterX = Math.cos(clusterAngle) * 0.43;
const clusterZ = Math.sin(clusterAngle) * 0.43;
ax += (clusterX - p.x) * props.cluster;
az += (clusterZ - p.z) * props.cluster;
} else {
// Fine pieces settle slowly; coarse pieces return to the base quickly.
ay += (props.restY - p.y) * props.restGain;
}
p.vx += ax * dt;
p.vy += ay * dt;
p.vz += az * dt;
const damping = Math.exp(-props.drag * dt);
p.vx *= damping;
p.vy *= damping;
p.vz *= damping;
p.x += p.vx * dt;
p.y += p.vy * dt;
p.z += p.vz * dt;
if (p.y < 0.43) {
p.y = 0.43;
if (p.vy < 0) p.vy *= -0.12;
}
if (p.y > props.maxY) {
p.y = props.maxY;
if (p.vy > 0) p.vy *= -0.15;
}
// The bowl narrows toward its base.
const heightRatio = THREE.MathUtils.clamp(
(p.y - 0.43) / (props.maxY - 0.43),
0,
1
);
const maxRadius = 0.84 + heightRatio * 0.3;
const currentRadius = Math.hypot(p.x, p.z);
if (currentRadius > maxRadius) {
const correction = maxRadius / currentRadius;
p.x *= correction;
p.z *= correction;
const radialVelocity = (p.vx * p.x + p.vz * p.z) / maxRadius;
if (radialVelocity > 0) {
p.vx -= (p.vx * p.x + p.vz * p.z) / (maxRadius * maxRadius) *
radialVelocity;
p.vz -= (p.vx * p.x + p.vz * p.z) / (maxRadius * maxRadius) *
radialVelocity;
}
}
p.mesh.position.set(p.x, p.y, p.z);
// A subtle block tumble communicates drag and changing orientation.
p.mesh.rotation.x += p.vz * dt * 0.18;
p.mesh.rotation.z -= p.vx * dt * 0.18;
}
}
// -------------------------------------------------------------------------
// Readouts and qualitative labels
// -------------------------------------------------------------------------
function calculateMetrics(bowl) {
const particles = bowl.particles;
const bins = new Array(10).fill(0);
let suspended = 0;
let averageY = 0;
for (const p of particles) {
const angle = (Math.atan2(p.z, p.x) + Math.PI * 2) % (Math.PI * 2);
const bin = Math.min(9, Math.floor((angle / (Math.PI * 2)) * 10));
bins[bin]++;
if (p.y > 0.72) suspended++;
averageY += p.y;
}
averageY /= particles.length;
let yVariance = 0;
for (const p of particles) {
yVariance += Math.pow(p.y - averageY, 2);
}
yVariance = Math.sqrt(yVariance / particles.length);
const expected = particles.length / bins.length;
let angularVariation = 0;
for (const count of bins) {
angularVariation += Math.pow(count - expected, 2);
}
angularVariation = Math.sqrt(angularVariation / bins.length) / expected;
const evenness = THREE.MathUtils.clamp(
1 - (angularVariation * 0.7 + (yVariance / 0.58) * 0.3),
0,
1
);
return {
suspension: suspended / particles.length,
evenness
};
}
const labelA = document.getElementById("labelA");
const labelB = document.getElementById("labelB");
const behaviorA = document.getElementById("behaviorA");
const behaviorB = document.getElementById("behaviorB");
const suspensionA = document.getElementById("suspensionA");
const suspensionB = document.getElementById("suspensionB");
const evennessA = document.getElementById("evennessA");
const evennessB = document.getElementById("evennessB");
const coarseTag = document.getElementById("coarseTag");
const fineTag = document.getElementById("fineTag");
const liveDot = document.getElementById("liveDot");
const liveState = document.getElementById("liveState");
let metricsTimer = 0;
function updateReadouts() {
const metricsA = calculateMetrics(bowlA);
const metricsB = calculateMetrics(bowlB);
suspensionA.textContent = `${Math.round(metricsA.suspension * 100)}%`;
suspensionB.textContent = `${Math.round(metricsB.suspension * 100)}%`;
evennessA.textContent = `${Math.round(metricsA.evenness * 100)}%`;
evennessB.textContent = `${Math.round(metricsB.evenness * 100)}%`;
if (state.stirring) {
const elapsed = state.simulationTime - state.stirStartTime;
liveDot.classList.add("active");
liveState.textContent = "Stirring";
if (elapsed < 1.35) {
behaviorA.textContent = "LIFTING IN LARGE CHUNKS";
coarseTag.textContent = "Brief lift · large blocks";
} else {
behaviorA.textContent = "FAST SETTLING · CLUMPS FORM";
coarseTag.textContent = "Fast settling · clumpy";
}
behaviorB.textContent = "EVEN SUSPENSION · SLOW SETTLING";
fineTag.textContent = "Slow settling · even";
} else {
liveDot.classList.remove("active");
const settling =
!state.justReset &&
performance.now() - state.stirEndTime < 2600;
liveState.textContent = settling ? "Settling" : "Ready";
behaviorA.textContent = settling
? "SETTLING FAST · PATCHY LAYER"
: "SETTLED · PATCHY LAYER";
behaviorB.textContent = settling
? "SETTLING SLOW · EVEN LAYER"
: "SETTLED · EVEN LAYER";
coarseTag.textContent = settling
? "Settling fast · clumpy"
: "Fast settling · clumpy";
fineTag.textContent = settling
? "Settling slow · even"
: "Slow settling · even";
}
}
// -------------------------------------------------------------------------
// DOM projected labels
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function positionLabel(element, x, y, z) {
projected.set(x, y, z).project(camera);
const screenX = (projected.x * 0.5 + 0.5) * window.innerWidth;
const screenY = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${screenX}px`;
element.style.top = `${screenY}px`;
element.style.opacity =
projected.z > 1 || projected.z < -1 ? "0" : "1";
}
// -------------------------------------------------------------------------
// UI actions
// -------------------------------------------------------------------------
const stirButton = document.getElementById("stirButton");
const speedInput = document.getElementById("speed");
const speedValue = document.getElementById("speedValue");
const resetButton = document.getElementById("resetButton");
const viewButton = document.getElementById("viewButton");
function setStirring(active) {
state.stirring = active;
state.justReset = false;
if (active) {
state.stirStartTime = state.simulationTime;
stirButton.textContent = "Ⅱ Pause stirring both bowls";
stirButton.classList.add("stopped");
} else {
state.stirEndTime = performance.now();
stirButton.textContent = "▶ Resume stirring both bowls";
stirButton.classList.add("stopped");
}
updateReadouts();
}
function resetMixture() {
state.stirring = false;
state.justReset = true;
for (const bowl of [bowlA, bowlB]) {
for (const p of bowl.particles) {
p.x = p.start.x;
p.y = p.start.y;
p.z = p.start.z;
p.vx = 0;
p.vy = 0;
p.vz = 0;
p.mesh.position.set(p.x, p.y, p.z);
p.mesh.rotation.set(0, 0, 0);
}
}
stirButton.textContent = "▶ Start stirring both bowls";
stirButton.classList.remove("stopped");
updateReadouts();
}
stirButton.addEventListener("click", () => {
setStirring(!state.stirring);
});
resetButton.addEventListener("click", resetMixture);
viewButton.addEventListener("click", resetCamera);
function updateSliderBackground() {
const percent =
((Number(speedInput.value) - Number(speedInput.min)) /
(Number(speedInput.max) - Number(speedInput.min))) *
100;
speedInput.style.background = `linear-gradient(
90deg,
var(--green) 0%,
var(--green) ${percent}%,
rgba(255,255,255,.12) ${percent}%,
rgba(255,255,255,.12) 100%
)`;
}
speedInput.addEventListener("input", () => {
state.speed = Number(speedInput.value);
speedValue.textContent = `${state.speed.toFixed(1)}×`;
updateSliderBackground();
});
updateSliderBackground();
window.addEventListener("keydown", (event) => {
if (
event.code === "Space" &&
event.target.tagName !== "INPUT" &&
event.target.tagName !== "BUTTON"
) {
event.preventDefault();
setStirring(!state.stirring);
}
if (
event.key.toLowerCase() === "r" &&
event.target.tagName !== "INPUT"
) {
resetMixture();
}
});
// -------------------------------------------------------------------------
// Custom camera controls: orbit, zoom, and touch pinch
// -------------------------------------------------------------------------
const pointers = new Map();
let lastX = 0;
let lastY = 0;
let pinchDistance = 0;
function getPinchDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].clientX - values[1].clientX,
values[0].clientY - values[1].clientY
);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
clientX: event.clientX,
clientY: event.clientY
});
if (pointers.size === 1) {
lastX = event.clientX;
lastY = event.clientY;
} else if (pointers.size === 2) {
pinchDistance = getPinchDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
clientX: event.clientX,
clientY: event.clientY
});
if (pointers.size === 1) {
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.48,
1.43
);
lastX = event.clientX;
lastY = event.clientY;
} else if (pointers.size === 2) {
const nextDistance = getPinchDistance();
if (pinchDistance > 0 && nextDistance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (pinchDistance / nextDistance),
6.2,
16
);
}
pinchDistance = nextDistance;
}
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 1) {
const remaining = [...pointers.values()][0];
lastX = remaining.clientX;
lastY = remaining.clientY;
} else if (pointers.size === 0) {
pinchDistance = 0;
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("lostpointercapture", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.007,
6.2,
16
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// 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();
function animate() {
const dt = Math.min(clock.getDelta(), 0.035);
state.simulationTime += dt;
updateParticles(bowlA, dt, state.simulationTime);
updateParticles(bowlB, dt, state.simulationTime);
const stirAngle = state.stirring
? state.simulationTime * 3.2 * state.speed
: state.stirEndTime
? state.stirEndTime * 0.0007
: 0;
bowlA.stirrer.rotation.y = stirAngle;
bowlB.stirrer.rotation.y = stirAngle;
// The paddles rotate around their own axis as well as the bowl axis.
bowlA.paddle.rotation.y = stirAngle * 1.7;
bowlB.paddle.rotation.y = stirAngle * 1.7;
metricsTimer += dt;
if (metricsTimer > 0.12) {
metricsTimer = 0;
updateReadouts();
}
positionLabel(labelA, bowlA.xPosition, 2.25, 0);
positionLabel(labelB, bowlB.xPosition, 2.25, 0);
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```