Prompt specification
Build or customize the Three.js 3D scene "Small confectionery decorating bench" 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: Small confectionery decorating bench
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/small-confectionery-decorating-bench-x0091
Scene Description Prompt:
A stylized chocolate bench: fill mold cavities, then release matching finished shapes. Make one HTML file using Three.js from cdnjs.
Working Three.js Starter (small-confectionery-decorating-bench-x0091):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Cocoa Atelier — Chocolate Bench</title>
<style>
:root {
--ink: #281d19;
--muted: #77675d;
--paper: rgba(250, 247, 241, 0.88);
--line: rgba(61, 43, 34, 0.14);
--accent: #c66d3d;
--accent-dark: #8e4528;
--shadow: 0 20px 60px rgba(53, 34, 24, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eee6dc;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#app,
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#scene {
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.grain {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
opacity: 0.16;
mix-blend-mode: multiply;
background-image:
radial-gradient(circle at 20% 30%, rgba(74, 43, 29, 0.12) 0 0.6px, transparent 0.8px),
radial-gradient(circle at 70% 80%, rgba(74, 43, 29, 0.1) 0 0.7px, transparent 0.9px);
background-size: 5px 5px, 7px 7px;
}
.brand {
position: fixed;
top: 28px;
left: 30px;
z-index: 5;
pointer-events: none;
}
.brand-row {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 17px;
color: var(--accent-dark);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.brand-mark {
position: relative;
width: 25px;
height: 25px;
border: 1px solid currentColor;
border-radius: 50%;
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
background: currentColor;
}
.brand-mark::before {
top: 6px;
bottom: 6px;
left: 11px;
width: 1px;
}
.brand-mark::after {
top: 11px;
right: 6px;
left: 6px;
height: 1px;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(34px, 4.2vw, 64px);
font-weight: 400;
letter-spacing: -0.045em;
line-height: 0.95;
}
.brand p {
max-width: 430px;
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.6;
}
.panel {
position: fixed;
z-index: 6;
left: 24px;
bottom: 24px;
width: min(330px, calc(100vw - 48px));
padding: 20px;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 22px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(18px) saturate(120%);
-webkit-backdrop-filter: blur(18px) saturate(120%);
}
.panel::before {
content: "";
position: absolute;
top: 0;
right: 0;
left: 0;
height: 3px;
background: linear-gradient(90deg, var(--accent), #e2aa72 55%, transparent);
}
.panel-kicker {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 12px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.batch-badge {
padding: 5px 8px;
border: 1px solid var(--line);
border-radius: 999px;
color: var(--accent-dark);
background: rgba(255, 255, 255, 0.45);
}
.panel h2 {
margin: 0 0 4px;
font-family: Georgia, "Times New Roman", serif;
font-size: 26px;
font-weight: 400;
letter-spacing: -0.025em;
}
.status-line {
min-height: 20px;
margin-bottom: 16px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.steps {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-bottom: 17px;
}
.step {
position: relative;
padding-top: 12px;
color: #9a8c82;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.step::before {
content: "";
position: absolute;
top: 0;
right: 0;
left: 0;
height: 3px;
border-radius: 4px;
background: rgba(57, 39, 30, 0.1);
}
.step.active {
color: var(--accent-dark);
}
.step.active::before {
background: var(--accent);
}
.step.done {
color: #8c765f;
}
.step.done::before {
background: #b89170;
}
.shape-list {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
margin-bottom: 17px;
}
.shape-row {
display: flex;
align-items: center;
gap: 8px;
min-width: 0;
padding: 8px 9px;
border: 1px solid var(--line);
border-radius: 10px;
color: #65564d;
background: rgba(255, 255, 255, 0.38);
font-size: 10px;
font-weight: 700;
transition:
border-color 0.25s ease,
background 0.25s ease,
transform 0.25s ease;
}
.shape-row.filled {
border-color: rgba(151, 81, 45, 0.3);
background: rgba(211, 149, 109, 0.11);
}
.shape-row.released {
border-color: rgba(80, 133, 81, 0.35);
background: rgba(108, 155, 105, 0.12);
transform: translateY(-1px);
}
.shape-dot {
position: relative;
flex: 0 0 auto;
width: 13px;
height: 13px;
border: 1px solid rgba(72, 46, 34, 0.2);
border-radius: 4px;
background: #e5d7c8;
}
.shape-row[data-shape="0"] .shape-dot {
border-radius: 50%;
}
.shape-row[data-shape="1"] .shape-dot {
border-radius: 2px;
transform: rotate(30deg);
}
.shape-row[data-shape="2"] .shape-dot {
border-radius: 4px;
}
.shape-row[data-shape="3"] .shape-dot {
border-radius: 50% 50% 45% 45%;
transform: rotate(45deg) scale(0.86);
}
.shape-row.filled .shape-dot {
background: #6f351f;
}
.shape-row.released .shape-dot::after {
content: "";
position: absolute;
right: -4px;
bottom: -4px;
width: 6px;
height: 6px;
border: 1px solid #f7f2ea;
border-radius: 50%;
background: #72916c;
}
.progress-wrap {
margin-bottom: 13px;
}
.progress-meta {
display: flex;
justify-content: space-between;
margin-bottom: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.progress-track {
height: 5px;
overflow: hidden;
border-radius: 999px;
background: rgba(61, 43, 34, 0.1);
}
.progress-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #8e4528, #d78a57);
transition: width 0.08s linear;
}
.buttons {
display: grid;
grid-template-columns: 1fr 42px;
gap: 8px;
}
.primary,
.reset {
min-height: 43px;
border: 0;
border-radius: 12px;
cursor: pointer;
transition:
transform 0.18s ease,
box-shadow 0.18s ease,
background 0.18s ease;
}
.primary {
display: flex;
align-items: center;
justify-content: center;
gap: 9px;
color: #fffaf4;
background: var(--ink);
box-shadow: 0 8px 18px rgba(40, 29, 25, 0.18);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.primary:hover {
background: #402b22;
transform: translateY(-1px);
box-shadow: 0 11px 23px rgba(40, 29, 25, 0.24);
}
.primary:active,
.reset:active {
transform: translateY(1px);
}
.primary-icon {
display: inline-grid;
place-items: center;
width: 20px;
height: 20px;
border: 1px solid rgba(255, 255, 255, 0.24);
border-radius: 50%;
font-size: 9px;
}
.reset {
display: grid;
place-items: center;
color: var(--muted);
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.48);
font-size: 18px;
}
.reset:hover {
color: var(--ink);
background: rgba(255, 255, 255, 0.85);
}
.panel-footer {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: #8b7b70;
font-size: 9px;
letter-spacing: 0.05em;
}
.keyboard {
padding: 2px 5px;
border: 1px solid var(--line);
border-bottom-width: 2px;
border-radius: 4px;
color: #65564d;
background: rgba(255, 255, 255, 0.5);
font-size: 8px;
font-weight: 800;
}
.hint {
position: fixed;
z-index: 4;
right: 24px;
bottom: 23px;
display: flex;
align-items: center;
gap: 9px;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 999px;
color: #6d5c51;
background: rgba(249, 245, 238, 0.68);
box-shadow: 0 8px 25px rgba(63, 42, 31, 0.09);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.04em;
pointer-events: none;
}
.hint span {
display: inline-block;
width: 3px;
height: 3px;
border-radius: 50%;
background: #b3a398;
}
.live-badge {
position: fixed;
z-index: 4;
top: 26px;
right: 26px;
display: flex;
align-items: center;
gap: 8px;
padding: 8px 11px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 999px;
color: #705e53;
background: rgba(250, 247, 241, 0.68);
box-shadow: 0 8px 30px rgba(62, 42, 31, 0.08);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.live-badge::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: #8fa587;
box-shadow: 0 0 0 4px rgba(143, 165, 135, 0.15);
}
.tooltip {
position: fixed;
z-index: 9;
display: none;
min-width: 130px;
padding: 10px 12px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 10px;
color: #fff9f2;
background: rgba(43, 30, 24, 0.9);
box-shadow: 0 12px 30px rgba(32, 21, 16, 0.22);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
pointer-events: none;
transform: translate(12px, 12px);
}
.tooltip strong,
.tooltip span {
display: block;
}
.tooltip strong {
margin-bottom: 3px;
font-family: Georgia, "Times New Roman", serif;
font-size: 15px;
font-weight: 400;
}
.tooltip span {
color: rgba(255, 249, 242, 0.65);
font-size: 8px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
}
@media (max-width: 760px) {
.brand {
top: 18px;
left: 18px;
}
.brand-row {
margin-bottom: 10px;
}
.brand p {
display: none;
}
h1 {
font-size: 36px;
}
.panel {
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
padding: 15px;
border-radius: 17px;
}
.panel h2,
.shape-list,
.panel-footer {
display: none;
}
.panel-kicker {
margin-bottom: 7px;
}
.status-line {
min-height: 0;
margin-bottom: 10px;
}
.steps {
margin-bottom: 10px;
}
.hint,
.live-badge {
display: none;
}
}
</style>
</head>
<body>
<div id="app">
<canvas id="scene" aria-label="Interactive chocolate mold production bench"></canvas>
<div class="grain"></div>
<header class="brand">
<div class="brand-row">
<span class="brand-mark" aria-hidden="true"></span>
Cocoa Atelier
</div>
<h1>Chocolate Bench</h1>
<p>
A small study in precision casting. Fill the cavities, let the chocolate
set, then release four perfectly matched forms.
</p>
</header>
<div class="live-badge">Live workshop</div>
<aside class="panel" aria-label="Production controls">
<div class="panel-kicker">
<span>Form study / 004</span>
<span class="batch-badge">Batch 04</span>
</div>
<h2>Mold & release</h2>
<div class="status-line" id="status" aria-live="polite">
Four cavities are ready for filling.
</div>
<div class="steps" aria-label="Production stages">
<div class="step active" data-step="0">01 Fill</div>
<div class="step" data-step="1">02 Set</div>
<div class="step" data-step="2">03 Release</div>
</div>
<div class="shape-list" id="shapeList"></div>
<div class="progress-wrap">
<div class="progress-meta">
<span id="progressLabel">Ready</span>
<span id="progressPercent">0%</span>
</div>
<div class="progress-track">
<div class="progress-fill" id="progressFill"></div>
</div>
</div>
<div class="buttons">
<button class="primary" id="primaryButton" type="button">
<span class="primary-icon" id="primaryIcon">▶</span>
<span id="primaryText">Start production</span>
</button>
<button
class="reset"
id="resetButton"
type="button"
title="Reset batch"
aria-label="Reset batch"
>
↺
</button>
</div>
<div class="panel-footer">
<span>72% cacao · tempered</span>
<span><span class="keyboard">Space</span> to start or pause</span>
</div>
</aside>
<div class="hint">
Drag to orbit <span></span> Scroll to zoom <span></span> Right-drag to pan
</div>
<div class="tooltip" id="tooltip">
<strong></strong>
<span></span>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const statusEl = document.querySelector("#status");
const progressEl = document.querySelector("#progressFill");
const progressPercentEl = document.querySelector("#progressPercent");
const progressLabelEl = document.querySelector("#progressLabel");
const primaryButton = document.querySelector("#primaryButton");
const primaryText = document.querySelector("#primaryText");
const primaryIcon = document.querySelector("#primaryIcon");
const resetButton = document.querySelector("#resetButton");
const shapeList = document.querySelector("#shapeList");
const tooltip = document.querySelector("#tooltip");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeee6dc);
scene.fog = new THREE.Fog(0xeee6dc, 20, 42);
const camera = new THREE.PerspectiveCamera(
37,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 0.15, 0);
camera.position.set(8.5, 6.8, 11.4);
camera.lookAt(cameraTarget);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const hemisphere = new THREE.HemisphereLight(0xfff7e9, 0x70564a, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff3df, 3.2);
keyLight.position.set(-5, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 28;
keyLight.shadow.bias = -0.00025;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xffb47a, 1.65);
rimLight.position.set(8, 6, -5);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffa45c, 38, 13, 2);
warmLight.position.set(0, 4.2, 1.5);
scene.add(warmLight);
const materials = {
bench: new THREE.MeshStandardMaterial({
color: 0xd9cbb8,
roughness: 0.78,
metalness: 0.02
}),
benchEdge: new THREE.MeshStandardMaterial({
color: 0xbda88e,
roughness: 0.73
}),
tray: new THREE.MeshStandardMaterial({
color: 0x343a3e,
roughness: 0.38,
metalness: 0.56
}),
cavity: new THREE.MeshStandardMaterial({
color: 0x241a17,
roughness: 0.66,
metalness: 0.12
}),
brass: new THREE.MeshStandardMaterial({
color: 0xb87a43,
roughness: 0.3,
metalness: 0.78
}),
brassDark: new THREE.MeshStandardMaterial({
color: 0x745034,
roughness: 0.42,
metalness: 0.65
}),
pad: new THREE.MeshStandardMaterial({
color: 0xcbb79d,
roughness: 0.72
}),
floor: new THREE.MeshStandardMaterial({
color: 0xe7ddd1,
roughness: 0.94
})
};
const liquidColor = new THREE.Color(0x7d4024);
const setColor = new THREE.Color(0x4b2117);
function roundedRectShape(width, height, radius) {
const x = -width / 2;
const y = -height / 2;
const shape = new THREE.Shape();
shape.moveTo(x + radius, y);
shape.lineTo(x + width - radius, y);
shape.absarc(x + width - radius, y + radius, radius, -Math.PI / 2, 0, false);
shape.lineTo(x + width, y + height - radius);
shape.absarc(
x + width - radius,
y + height - radius,
radius,
0,
Math.PI / 2,
false
);
shape.lineTo(x + radius, y + height);
shape.absarc(x + radius, y + height - radius, radius, Math.PI / 2, Math.PI, false);
shape.lineTo(x, y + radius);
shape.absarc(x + radius, y + radius, radius, Math.PI, Math.PI * 1.5, false);
return shape;
}
function extrudedHorizontal(shape, depth, bevel = 0.035) {
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
steps: 1,
curveSegments: 28,
bevelEnabled: bevel > 0,
bevelSegments: 3,
bevelSize: bevel,
bevelThickness: bevel
});
geometry.translate(0, 0, -depth / 2);
geometry.rotateX(-Math.PI / 2);
geometry.computeVertexNormals();
return geometry;
}
function slabGeometry(width, depth, height, radius) {
return extrudedHorizontal(
roundedRectShape(width, depth, radius),
height,
0.025
);
}
function heartShape() {
const shape = new THREE.Shape();
shape.moveTo(0, -0.48);
shape.bezierCurveTo(-0.28, -0.32, -0.55, -0.05, -0.42, 0.25);
shape.bezierCurveTo(-0.28, 0.56, 0.02, 0.48, 0.18, 0.26);
shape.bezierCurveTo(0.34, 0.47, 0.62, 0.28, 0.46, -0.03);
shape.bezierCurveTo(0.34, -0.24, 0.18, -0.36, 0, -0.48);
shape.closePath();
return shape;
}
function addMesh(geometry, material, position, parent = scene) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Room and workbench.
const floor = addMesh(
new THREE.PlaneGeometry(80, 80),
materials.floor,
new THREE.Vector3(0, -2.85, 0)
);
floor.rotation.x = -Math.PI / 2;
floor.castShadow = false;
const benchTop = addMesh(
slabGeometry(12.8, 7.4, 0.34, 0.28),
materials.bench,
new THREE.Vector3(0, 0, 0)
);
const shelf = addMesh(
slabGeometry(11.5, 6.1, 0.18, 0.22),
materials.benchEdge,
new THREE.Vector3(0, -1.55, 0)
);
for (const x of [-5.55, 5.55]) {
for (const z of [-2.8, 2.8]) {
addMesh(
new THREE.BoxGeometry(0.42, 2.95, 0.42),
materials.benchEdge,
new THREE.Vector3(x, -1.32, z)
);
}
}
// Mold tray.
addMesh(
slabGeometry(11.35, 3.25, 0.18, 0.3),
materials.tray,
new THREE.Vector3(0, 0.28, -1.15)
);
// Copper dispensing gantry.
for (const x of [-5.55, 5.55]) {
addMesh(
new THREE.BoxGeometry(0.17, 2.42, 0.17),
materials.brassDark,
new THREE.Vector3(x, 1.35, -2.45)
);
}
addMesh(
new THREE.BoxGeometry(11.27, 0.17, 0.19),
materials.brassDark,
new THREE.Vector3(0, 2.5, -2.45)
);
const manifold = addMesh(
new THREE.CylinderGeometry(0.09, 0.09, 10.5, 18),
materials.brass,
new THREE.Vector3(0, 2.02, -2.15)
);
manifold.rotation.z = Math.PI / 2;
function createPlaqueTexture() {
const plaqueCanvas = document.createElement("canvas");
plaqueCanvas.width = 1024;
plaqueCanvas.height = 256;
const ctx = plaqueCanvas.getContext("2d");
ctx.fillStyle = "#2c2521";
ctx.fillRect(0, 0, 1024, 256);
ctx.strokeStyle = "#c58a52";
ctx.lineWidth = 5;
ctx.strokeRect(16, 16, 992, 224);
ctx.fillStyle = "#f1dcc4";
ctx.font = "600 68px Georgia";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText("COCOA / FORM 04", 512, 111);
ctx.fillStyle = "#c58a52";
ctx.font = "700 22px Arial";
ctx.fillText("TEMPERED • FOUR PART MOULD", 512, 185);
const texture = new THREE.CanvasTexture(plaqueCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
const plaque = addMesh(
new THREE.PlaneGeometry(2.8, 0.7),
new THREE.MeshBasicMaterial({ map: createPlaqueTexture() }),
new THREE.Vector3(0, 2.48, -2.34)
);
plaque.castShadow = false;
// Deterministic cocoa dust.
let randomSeed = 371;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
const dustPositions = [];
for (let i = 0; i < 190; i++) {
const x = (random() - 0.5) * 12.1;
const z = (random() - 0.5) * 6.7;
if (z > -2.75 && z < 0.35) continue;
dustPositions.push(x, 0.182, z);
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0x6f4633,
size: 0.024,
transparent: true,
opacity: 0.42,
sizeAttenuation: true
})
);
scene.add(dust);
const shapeDefinitions = [
{
name: "Round",
code: "Disc",
geometry: new THREE.CylinderGeometry(0.52, 0.52, 0.24, 48)
},
{
name: "Hexagon",
code: "Hex",
geometry: new THREE.CylinderGeometry(0.53, 0.53, 0.24, 6)
},
{
name: "Rounded block",
code: "Block",
geometry: extrudedHorizontal(
roundedRectShape(1.14, 0.86, 0.18),
0.24,
0.045
)
},
{
name: "Heart",
code: "Heart",
geometry: extrudedHorizontal(heartShape(), 0.24, 0.04)
}
];
const moldXs = [-4.2, -1.4, 1.4, 4.2];
const moldZ = -1.15;
const displayZ = 1.75;
const chocolateMeshes = [];
const streams = [];
const bubbleSets = [];
const shapeRows = [];
function numberTexture(number) {
const c = document.createElement("canvas");
c.width = 256;
c.height = 128;
const ctx = c.getContext("2d");
ctx.fillStyle = "#c58a52";
ctx.fillRect(0, 0, 256, 128);
ctx.fillStyle = "#2c2521";
ctx.font = "700 62px Arial";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(number, 128, 68);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
shapeDefinitions.forEach((definition, index) => {
const x = moldXs[index];
// Broad silicone/metal rim around each cavity.
const rim = addMesh(
definition.geometry.clone(),
index % 2 === 0 ? materials.tray : materials.cavity,
new THREE.Vector3(x, 0.43, moldZ)
);
rim.scale.set(1.15, 0.5, 1.15);
// Recessed-looking cavity floor.
const cavity = addMesh(
definition.geometry.clone(),
materials.cavity,
new THREE.Vector3(x, 0.49, moldZ)
);
cavity.scale.set(0.84, 0.18, 0.84);
const chocolateMaterial = new THREE.MeshPhysicalMaterial({
color: liquidColor.clone(),
roughness: 0.24,
metalness: 0,
clearcoat: 0.78,
clearcoatRoughness: 0.14,
envMapIntensity: 0.9
});
const chocolate = addMesh(
definition.geometry.clone(),
chocolateMaterial,
new THREE.Vector3(x, 0.51, moldZ)
);
chocolate.scale.set(0.84, 0.02, 0.84);
chocolate.visible = false;
chocolate.userData = {
name: definition.name,
meta: `${definition.code} · 100% matched`
};
chocolateMeshes.push(chocolate);
// Copper nozzle and animated chocolate stream.
const arm = addMesh(
new THREE.CylinderGeometry(0.065, 0.065, 1.02, 14),
materials.brass,
new THREE.Vector3(x, 2.02, -1.65)
);
arm.rotation.x = Math.PI / 2;
addMesh(
new THREE.CylinderGeometry(0.12, 0.075, 0.24, 18),
materials.brass,
new THREE.Vector3(x, 1.77, moldZ)
);
const streamMaterial = new THREE.MeshPhysicalMaterial({
color: 0x69331f,
roughness: 0.2,
clearcoat: 0.7,
transparent: true,
opacity: 0.95
});
const stream = addMesh(
new THREE.CylinderGeometry(0.045, 0.065, 1, 14),
streamMaterial,
new THREE.Vector3(x, 1.15, moldZ)
);
stream.visible = false;
stream.castShadow = false;
streams.push(stream);
const bubbleMaterial = new THREE.MeshPhysicalMaterial({
color: 0x9b5530,
roughness: 0.22,
clearcoat: 0.85,
transparent: true,
opacity: 0.7
});
const bubbles = [];
for (let b = 0; b < 3; b++) {
const bubble = addMesh(
new THREE.SphereGeometry(0.04, 12, 8),
bubbleMaterial,
new THREE.Vector3(
x + (b - 1) * 0.18,
0.64,
moldZ + (b % 2 ? 0.12 : -0.1)
)
);
bubble.visible = false;
bubble.castShadow = false;
bubbles.push(bubble);
}
bubbleSets.push(bubbles);
// Finished-chocolate presentation pad.
addMesh(
new THREE.CylinderGeometry(0.66, 0.69, 0.08, 48),
materials.pad,
new THREE.Vector3(x, 0.21, displayZ)
);
const padRing = addMesh(
new THREE.TorusGeometry(0.59, 0.014, 8, 48),
materials.brass,
new THREE.Vector3(x, 0.258, displayZ)
);
padRing.rotation.x = Math.PI / 2;
const numberPlate = addMesh(
new THREE.PlaneGeometry(0.48, 0.24),
new THREE.MeshBasicMaterial({ map: numberTexture(`0${index + 1}`) }),
new THREE.Vector3(x, 0.378, -2.18)
);
numberPlate.rotation.x = -Math.PI / 2;
numberPlate.castShadow = false;
const row = document.createElement("div");
row.className = "shape-row";
row.dataset.shape = index;
row.innerHTML = `<span class="shape-dot"></span><span>${definition.code}</span>`;
shapeList.appendChild(row);
shapeRows.push(row);
});
// Timeline.
const FILL_START = 0.15;
const FILL_STAGGER = 0.52;
const FILL_DURATION = 1.05;
const SET_START = 2.85;
const SET_END = 4.25;
const RELEASE_START = 4.45;
const RELEASE_STAGGER = 0.72;
const RELEASE_DURATION = 1.25;
const TOTAL_TIME = 8.0;
let animationTime = 0;
let running = false;
let paused = false;
let completed = false;
const clamp01 = (value) => Math.min(1, Math.max(0, value));
const easeOutCubic = (value) => 1 - Math.pow(1 - value, 3);
const easeInOutCubic = (value) =>
value < 0.5
? 4 * value * value * value
: 1 - Math.pow(-2 * value + 2, 3) / 2;
function quadraticBezier(out, a, b, c, t) {
const inverse = 1 - t;
out.set(
inverse * inverse * a.x + 2 * inverse * t * b.x + t * t * c.x,
inverse * inverse * a.y + 2 * inverse * t * b.y + t * t * c.y,
inverse * inverse * a.z + 2 * inverse * t * b.z + t * t * c.z
);
return out;
}
const flightPoint = new THREE.Vector3();
const flightControl = new THREE.Vector3();
const flightEnd = new THREE.Vector3();
function updateProduction(time) {
const settingProgress = clamp01((time - SET_START) / (SET_END - SET_START));
shapeDefinitions.forEach((definition, index) => {
const chocolate = chocolateMeshes[index];
const stream = streams[index];
const bubbles = bubbleSets[index];
const fillProgress = clamp01(
(time - FILL_START - index * FILL_STAGGER) / FILL_DURATION
);
const filled = easeOutCubic(fillProgress);
chocolate.material.color.lerpColors(liquidColor, setColor, settingProgress);
chocolate.material.roughness = 0.24 - settingProgress * 0.035;
chocolate.visible = fillProgress > 0;
if (fillProgress > 0 && fillProgress < 1) {
chocolate.position.set(moldXs[index], 0.51 + filled * 0.12, moldZ);
chocolate.scale.set(0.84, Math.max(0.02, filled * 0.84), 0.84);
chocolate.rotation.set(0, 0, 0);
} else {
chocolate.scale.set(0.84, 0.84, 0.84);
chocolate.position.set(moldXs[index], 0.63, moldZ);
chocolate.rotation.set(0, 0, 0);
}
// The stream shortens as the cavity fills.
const streamVisible = fillProgress > 0.015 && fillProgress < 0.92;
stream.visible = streamVisible;
if (streamVisible) {
const surface = 0.51 + filled * 0.24;
const streamTop = 1.64;
const length = Math.max(0.05, streamTop - surface);
stream.scale.set(1, length, 1);
stream.position.set(
moldXs[index],
surface + length * 0.5,
moldZ + Math.sin(time * 10 + index) * 0.006
);
stream.material.color.copy(chocolate.material.color);
}
bubbles.forEach((bubble, bubbleIndex) => {
bubble.visible = fillProgress > 0.42 && fillProgress < 0.96;
if (bubble.visible) {
const local = clamp01((fillProgress - 0.42) / 0.5);
const pulse = 0.5 + 0.5 * Math.sin(time * 7 + bubbleIndex * 1.7);
bubble.position.y = 0.51 + filled * 0.24 + 0.01;
bubble.scale.setScalar(0.25 + local * pulse * 0.75);
}
});
const releaseProgress = clamp01(
(time - RELEASE_START - index * RELEASE_STAGGER) / RELEASE_DURATION
);
if (releaseProgress > 0) {
const eased = easeInOutCubic(releaseProgress);
flightPoint.set(moldXs[index], 0.63, moldZ);
flightControl.set(moldXs[index], 2.35, 0.05);
flightEnd.set(moldXs[index], 0.38, displayZ);
quadraticBezier(
chocolate.position,
flightPoint,
flightControl,
flightEnd,
eased
);
const arc = Math.sin(Math.PI * eased);
chocolate.rotation.y = arc * 0.48 * (index % 2 === 0 ? 1 : -1);
chocolate.rotation.z = arc * 0.035 * (index % 2 === 0 ? 1 : -1);
const expansion = 1 + arc * 0.055;
chocolate.scale.set(0.84 * expansion, 0.84 * expansion, 0.84 * expansion);
if (releaseProgress >= 1) {
chocolate.position.copy(flightEnd);
chocolate.rotation.set(0, 0, 0);
chocolate.scale.set(0.84, 0.84, 0.84);
}
}
});
}
function updateInterface() {
let phase = 0;
let status = "Four cavities are ready for filling.";
let label = "Ready";
if (animationTime >= SET_START && animationTime < RELEASE_START) {
phase = 1;
status = "The tempered chocolate is cooling and setting.";
label = "Setting";
} else if (animationTime >= RELEASE_START && animationTime < TOTAL_TIME) {
phase = 2;
status = "Releasing the finished forms onto the cooling pads.";
label = "Releasing";
} else if (animationTime >= TOTAL_TIME) {
phase = 3;
status = "Batch complete. Four matched chocolates are ready.";
label = "Complete";
} else if (animationTime > 0) {
const filledCount = shapeDefinitions.filter((_, index) => {
return (
animationTime >=
FILL_START + index * FILL_STAGGER + FILL_DURATION * 0.72
);
}).length;
status = `Filling cavity ${filledCount} of 4 with tempered chocolate.`;
label = "Filling";
}
const steps = [...document.querySelectorAll(".step")];
steps.forEach((step, index) => {
step.classList.toggle("active", index === phase);
step.classList.toggle("done", index < phase);
});
const releasedCount = shapeDefinitions.filter((_, index) => {
return (
animationTime >=
RELEASE_START + index * RELEASE_STAGGER + RELEASE_DURATION * 0.9
);
}).length;
shapeRows.forEach((row, index) => {
const fillProgress = clamp01(
(animationTime - FILL_START - index * FILL_STAGGER) / FILL_DURATION
);
const releaseProgress = clamp01(
(animationTime - RELEASE_START - index * RELEASE_STAGGER) /
RELEASE_DURATION
);
row.classList.toggle("filled", fillProgress > 0.5);
row.classList.toggle("released", releaseProgress > 0.92);
});
const progress = clamp01(animationTime / TOTAL_TIME);
progressEl.style.width = `${progress * 100}%`;
progressPercentEl.textContent = `${Math.round(progress * 100)}%`;
progressLabelEl.textContent = label;
statusEl.textContent = status;
if (completed) {
primaryText.textContent = "Make another batch";
primaryIcon.textContent = "↺";
} else if (paused) {
primaryText.textContent = "Resume process";
primaryIcon.textContent = "▶";
} else if (running) {
primaryText.textContent = "Pause process";
primaryIcon.textContent = "Ⅱ";
} else {
primaryText.textContent = "Start production";
primaryIcon.textContent = "▶";
}
progressLabelEl.title = `${releasedCount} / 4 released`;
}
function startBatch() {
animationTime = 0;
running = true;
paused = false;
completed = false;
updateProduction(animationTime);
updateInterface();
}
function resetBatch() {
animationTime = 0;
running = false;
paused = false;
completed = false;
updateProduction(animationTime);
updateInterface();
}
primaryButton.addEventListener("click", () => {
if (completed) {
startBatch();
} else if (running) {
running = false;
paused = true;
} else if (paused) {
running = true;
paused = false;
} else {
startBatch();
}
updateInterface();
});
resetButton.addEventListener("click", resetBatch);
window.addEventListener("keydown", (event) => {
if (event.code === "Space" && event.target === document.body) {
event.preventDefault();
primaryButton.click();
}
if (event.key.toLowerCase() === "r") {
resetBatch();
}
});
// Direct camera controls: orbit, pan and zoom without addons.
let pointerActive = false;
let pointerButton = 0;
let lastPointerX = 0;
let lastPointerY = 0;
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const cameraRight = new THREE.Vector3();
const cameraUp = new THREE.Vector3();
const cameraOffset = new THREE.Vector3();
const spherical = new THREE.Spherical();
function refreshCamera() {
cameraOffset.copy(camera.position).sub(cameraTarget);
spherical.setFromVector3(cameraOffset);
camera.position.copy(cameraTarget).add(cameraOffset);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function orbitCamera(deltaX, deltaY) {
cameraOffset.copy(camera.position).sub(cameraTarget);
spherical.setFromVector3(cameraOffset);
spherical.theta -= deltaX * 0.006;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi - deltaY * 0.005,
0.35,
1.36
);
cameraOffset.setFromSpherical(spherical);
camera.position.copy(cameraTarget).add(cameraOffset);
refreshCamera();
}
function panCamera(deltaX, deltaY) {
const distance = camera.position.distanceTo(cameraTarget);
cameraRight.setFromMatrixColumn(camera.matrix, 0);
cameraUp.setFromMatrixColumn(camera.matrix, 1);
cameraTarget.addScaledVector(cameraRight, -deltaX * distance * 0.0012);
cameraTarget.addScaledVector(cameraUp, deltaY * distance * 0.0012);
cameraTarget.x = THREE.MathUtils.clamp(cameraTarget.x, -4, 4);
cameraTarget.y = THREE.MathUtils.clamp(cameraTarget.y, -1, 2.4);
cameraTarget.z = THREE.MathUtils.clamp(cameraTarget.z, -3, 3);
refreshCamera();
}
function updateTooltip(event) {
pointer.x = (event.clientX / window.innerWidth) * 2 - 1;
pointer.y = -(event.clientY / window.innerHeight) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const visibleMeshes = chocolateMeshes.filter((mesh) => mesh.visible);
const hits = raycaster.intersectObjects(visibleMeshes, false);
if (hits.length) {
const data = hits[0].object.userData;
tooltip.querySelector("strong").textContent = data.name;
tooltip.querySelector("span").textContent = data.meta;
tooltip.style.display = "block";
const maxLeft = window.innerWidth - 170;
const maxTop = window.innerHeight - 85;
tooltip.style.left = `${Math.min(event.clientX, maxLeft)}px`;
tooltip.style.top = `${Math.min(event.clientY, maxTop)}px`;
} else {
tooltip.style.display = "none";
}
}
canvas.addEventListener("pointerdown", (event) => {
pointerActive = true;
pointerButton = event.button;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
tooltip.style.display = "none";
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerActive) {
updateTooltip(event);
return;
}
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
if (pointerButton === 2 || event.shiftKey) {
panCamera(deltaX, deltaY);
} else {
orbitCamera(deltaX, deltaY);
}
});
function endPointer(event) {
pointerActive = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("pointerleave", () => {
if (!pointerActive) tooltip.style.display = "none";
});
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraOffset.copy(camera.position).sub(cameraTarget);
const distance = cameraOffset.length();
const nextDistance = THREE.MathUtils.clamp(
distance * Math.exp(event.deltaY * 0.001),
7.2,
22
);
cameraOffset.setLength(nextDistance);
camera.position.copy(cameraTarget).add(cameraOffset);
refreshCamera();
},
{ passive: false }
);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.fov = window.innerWidth < 760 ? 49 : 37;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
});
let lastFrame = performance.now();
function animate(now) {
const delta = Math.min((now - lastFrame) / 1000, 0.05);
lastFrame = now;
if (running) {
animationTime += delta;
if (animationTime >= TOTAL_TIME) {
animationTime = TOTAL_TIME;
running = false;
paused = false;
completed = true;
}
}
updateProduction(animationTime);
updateInterface();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
if (window.innerWidth < 760) {
camera.fov = 49;
camera.position.set(9.5, 8.4, 14.4);
camera.updateProjectionMatrix();
}
updateProduction(0);
updateInterface();
requestAnimationFrame(animate);
</script>
</body>
</html>
```