Prompt specification
Build or customize the Three.js 3D scene "Kitchen transformation sorting 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: Kitchen transformation sorting exhibit
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/kitchen-transformation-sorting-exhibit-x0104
Scene Description Prompt:
Sort low-poly egg cooking, ice melting, and bread slicing by reversibility, with animations showing each transformation. Use Three.js from cdnjs in standalone HTML.
Working Three.js Starter (kitchen-transformation-sorting-exhibit-x0104):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Can You Put It Back? — Three.js Transformation Lab</title>
<style>
:root {
--paper: #f2efe5;
--ink: #17221d;
--muted: #69736d;
--line: rgba(23, 34, 29, 0.14);
--egg: #ec6a3b;
--ice: #3d94c5;
--bread: #bc812d;
--white: #fffdf7;
}
* {
box-sizing: border-box;
}
html {
scroll-behavior: smooth;
}
body {
margin: 0;
color: var(--ink);
background:
radial-gradient(circle at 10% 10%, rgba(236, 106, 59, 0.10), transparent 30rem),
radial-gradient(circle at 95% 40%, rgba(61, 148, 197, 0.10), transparent 34rem),
var(--paper);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
min-height: 100vh;
}
button {
font: inherit;
}
.shell {
width: min(1500px, calc(100% - 36px));
margin: 0 auto;
}
.hero {
padding: 54px 0 34px;
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
gap: 28px;
align-items: end;
}
.eyebrow {
margin-bottom: 14px;
color: var(--muted);
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
max-width: 900px;
font-size: clamp(2.8rem, 7vw, 6.9rem);
line-height: 0.9;
letter-spacing: -0.07em;
font-weight: 850;
}
.hero-copy {
max-width: 700px;
margin: 24px 0 0;
color: var(--muted);
font-size: clamp(1rem, 1.6vw, 1.2rem);
line-height: 1.65;
}
.hero-actions {
display: flex;
gap: 10px;
padding-bottom: 3px;
}
.control-button {
border: 1px solid var(--line);
background: rgba(255, 253, 247, 0.72);
color: var(--ink);
border-radius: 999px;
padding: 11px 17px;
cursor: pointer;
font-weight: 750;
transition:
transform 160ms ease,
background 160ms ease,
border-color 160ms ease;
}
.control-button:hover {
transform: translateY(-2px);
background: var(--white);
border-color: rgba(23, 34, 29, 0.28);
}
.control-button.primary {
color: #fff;
background: var(--ink);
border-color: var(--ink);
}
.ranking-note {
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
border-top: 1px solid var(--line);
border-bottom: 1px solid var(--line);
padding: 15px 0;
margin-bottom: 22px;
color: var(--muted);
font-size: 0.82rem;
}
.ranking-note strong {
color: var(--ink);
}
.ladder {
display: flex;
align-items: center;
gap: 8px;
flex-wrap: wrap;
}
.ladder-item {
display: inline-flex;
align-items: center;
gap: 7px;
white-space: nowrap;
}
.ladder-item::before {
content: "";
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--dot);
}
.ladder-arrow {
opacity: 0.45;
}
.labs {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 18px;
padding-bottom: 46px;
}
.lab {
--accent: var(--egg);
overflow: hidden;
border: 1px solid var(--line);
border-radius: 24px;
background: rgba(255, 253, 247, 0.78);
box-shadow: 0 18px 50px rgba(31, 45, 38, 0.07);
}
.lab[data-lab="ice"] {
--accent: var(--ice);
}
.lab[data-lab="bread"] {
--accent: var(--bread);
}
.lab-head {
min-height: 65px;
padding: 16px 18px;
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
border-bottom: 1px solid var(--line);
}
.rank {
display: flex;
align-items: center;
gap: 10px;
font-size: 0.68rem;
font-weight: 850;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.rank-number {
display: grid;
place-items: center;
width: 31px;
height: 31px;
color: #fff;
background: var(--accent);
border-radius: 9px;
font-size: 0.8rem;
letter-spacing: 0;
}
.badge {
padding: 7px 10px;
border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
color: color-mix(in srgb, var(--accent) 80%, #111);
background: color-mix(in srgb, var(--accent) 9%, transparent);
border-radius: 999px;
font-size: 0.63rem;
font-weight: 850;
letter-spacing: 0.07em;
text-transform: uppercase;
text-align: center;
}
.viewport {
position: relative;
isolation: isolate;
height: clamp(300px, 31vw, 430px);
overflow: hidden;
background: #e7ece6;
}
.lab[data-lab="ice"] .viewport {
background: #dfeaf0;
}
.lab[data-lab="bread"] .viewport {
background: #eee5d5;
}
canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.phase {
position: absolute;
z-index: 2;
top: 15px;
left: 15px;
max-width: calc(100% - 30px);
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 9px;
background: rgba(255, 253, 247, 0.72);
backdrop-filter: blur(8px);
color: #334039;
font-size: 0.62rem;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
.control-hint {
position: absolute;
z-index: 2;
right: 14px;
bottom: 14px;
padding: 7px 9px;
border-radius: 999px;
background: rgba(23, 34, 29, 0.68);
color: rgba(255, 255, 255, 0.88);
font-size: 0.61rem;
letter-spacing: 0.025em;
pointer-events: none;
}
.progress-track {
position: absolute;
z-index: 3;
bottom: 0;
left: 0;
right: 0;
height: 4px;
background: rgba(255, 255, 255, 0.25);
}
.progress-fill {
display: block;
height: 100%;
width: 0;
background: var(--accent);
}
.lab-copy {
padding: 21px 21px 22px;
}
.lab-copy h2 {
margin: 0 0 9px;
font-size: 1.45rem;
letter-spacing: -0.035em;
}
.lab-copy p {
min-height: 74px;
margin: 0;
color: var(--muted);
font-size: 0.91rem;
line-height: 1.55;
}
.score-row {
display: flex;
justify-content: space-between;
align-items: center;
gap: 18px;
margin-top: 20px;
padding-top: 17px;
border-top: 1px solid var(--line);
}
.score-label {
color: var(--muted);
font-size: 0.63rem;
font-weight: 850;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.score {
display: flex;
gap: 5px;
}
.score span {
width: 28px;
height: 8px;
border-radius: 999px;
background: rgba(23, 34, 29, 0.11);
}
.score span.on {
background: var(--accent);
}
.replay {
margin-top: 18px;
width: 100%;
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 11px;
background: transparent;
color: var(--ink);
cursor: pointer;
font-size: 0.72rem;
font-weight: 800;
transition:
background 160ms ease,
transform 160ms ease;
}
.replay:hover {
background: rgba(23, 34, 29, 0.055);
transform: translateY(-1px);
}
footer {
padding: 0 0 44px;
color: var(--muted);
font-size: 0.78rem;
line-height: 1.65;
}
footer strong {
color: var(--ink);
}
@media (max-width: 1050px) {
.labs {
grid-template-columns: 1fr;
}
.viewport {
height: min(62vw, 520px);
min-height: 340px;
}
.lab-copy p {
min-height: 0;
}
}
@media (max-width: 700px) {
.shell {
width: min(100% - 20px, 1500px);
}
.hero {
grid-template-columns: 1fr;
padding-top: 35px;
}
.hero-actions {
padding: 0;
}
.ranking-note {
align-items: flex-start;
flex-direction: column;
}
.viewport {
min-height: 300px;
}
.control-hint {
display: none;
}
}
</style>
</head>
<body>
<div class="shell">
<header class="hero">
<div>
<div class="eyebrow">Transformation index / Three kitchen states</div>
<h1>Can you put<br />it back?</h1>
<p class="hero-copy">
Three low-poly transformations, ordered from least to most reversible.
Drag each scene to inspect it, then watch the process run forward—and,
where possible, backward.
</p>
</div>
<div class="hero-actions">
<button class="control-button" id="pauseAll">Pause all</button>
<button class="control-button primary" id="replayAll">Replay all</button>
</div>
</header>
<div class="ranking-note">
<span>
<strong>Ranking criterion:</strong> whether the visible end state can be
mechanically or physically undone.
</span>
<div class="ladder" aria-label="Reversibility ranking">
<span class="ladder-item" style="--dot: var(--egg)">Cook</span>
<span class="ladder-arrow">→</span>
<span class="ladder-item" style="--dot: var(--ice)">Melt</span>
<span class="ladder-arrow">→</span>
<span class="ladder-item" style="--dot: var(--bread)">Slice</span>
</div>
</div>
<main class="labs">
<article class="lab" data-lab="egg">
<div class="lab-head">
<div class="rank">
<span class="rank-number">01</span>
<span>Least reversible</span>
</div>
<span class="badge">Irreversible</span>
</div>
<div class="viewport">
<canvas
id="eggCanvas"
role="img"
aria-label="Animated low-poly egg changing from raw to cooked"
></canvas>
<div class="phase" id="eggPhase">Shell opens</div>
<div class="control-hint">Drag to orbit · Scroll to zoom</div>
<div class="progress-track">
<span class="progress-fill" id="eggProgress"></span>
</div>
</div>
<div class="lab-copy">
<h2>Cooking an egg</h2>
<p>
Heat changes the egg’s proteins and structure. Cooling it later
cannot restore the original raw texture or chemistry.
</p>
<div class="score-row">
<span class="score-label">Reversibility</span>
<div class="score" aria-label="One out of three">
<span class="on"></span><span></span><span></span>
</div>
</div>
<button class="replay" data-replay="eggCanvas">Replay egg transformation</button>
</div>
</article>
<article class="lab" data-lab="ice">
<div class="lab-head">
<div class="rank">
<span class="rank-number">02</span>
<span>Conditionally reversible</span>
</div>
<span class="badge">Reversible by freezing</span>
</div>
<div class="viewport">
<canvas
id="iceCanvas"
role="img"
aria-label="Animated low-poly ice cube melting and refreezing"
></canvas>
<div class="phase" id="icePhase">Frozen cube</div>
<div class="control-hint">Drag to orbit · Scroll to zoom</div>
<div class="progress-track">
<span class="progress-fill" id="iceProgress"></span>
</div>
</div>
<div class="lab-copy">
<h2>Melting ice</h2>
<p>
The solid-to-liquid change can be reversed by freezing. The water
may not recreate every original crystal or surface detail.
</p>
<div class="score-row">
<span class="score-label">Reversibility</span>
<div class="score" aria-label="Two out of three">
<span class="on"></span><span class="on"></span><span></span>
</div>
</div>
<button class="replay" data-replay="iceCanvas">Replay ice transformation</button>
</div>
</article>
<article class="lab" data-lab="bread">
<div class="lab-head">
<div class="rank">
<span class="rank-number">03</span>
<span>Most reversible</span>
</div>
<span class="badge">Reversible by reassembly</span>
</div>
<div class="viewport">
<canvas
id="breadCanvas"
role="img"
aria-label="Animated low-poly bread loaf being sliced and reassembled"
></canvas>
<div class="phase" id="breadPhase">Whole loaf</div>
<div class="control-hint">Drag to orbit · Scroll to zoom</div>
<div class="progress-track">
<span class="progress-fill" id="breadProgress"></span>
</div>
</div>
<div class="lab-copy">
<h2>Slicing bread</h2>
<p>
The pieces can be moved back together without undoing a chemical
change. The loaf remains sliced, so the crumb is not made seamless.
</p>
<div class="score-row">
<span class="score-label">Reversibility</span>
<div class="score" aria-label="Three out of three">
<span class="on"></span><span class="on"></span><span class="on"></span>
</div>
</div>
<button class="replay" data-replay="breadCanvas">Replay bread transformation</button>
</div>
</article>
</main>
<footer>
<strong>Note:</strong> “Reversible” here describes undoing the visible
transformation, not restoring the object’s microscopic or material
continuity. Every scene uses only the Three.js core ES module.
</footer>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const TAU = Math.PI * 2;
const labs = [];
const clamp01 = (x) => Math.max(0, Math.min(1, x));
const smooth = (min, max, x) =>
THREE.MathUtils.smoothstep(x, min, max);
const fract = (x) => x - Math.floor(x);
/*
* Small custom orbit implementation.
* No camera-control addons are imported.
*/
class DirectOrbit {
constructor(camera, element, options) {
this.camera = camera;
this.element = element;
this.target = options.target.clone();
this.radius = options.radius;
this.yaw = options.yaw ?? 0.35;
this.pitch = options.pitch ?? 0.42;
this.dragging = false;
this.pointerX = 0;
this.pointerY = 0;
element.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
this.dragging = true;
this.pointerX = event.clientX;
this.pointerY = event.clientY;
element.setPointerCapture(event.pointerId);
});
element.addEventListener("pointermove", (event) => {
if (!this.dragging) return;
const dx = event.clientX - this.pointerX;
const dy = event.clientY - this.pointerY;
this.pointerX = event.clientX;
this.pointerY = event.clientY;
this.yaw -= dx * 0.006;
this.pitch = THREE.MathUtils.clamp(
this.pitch + dy * 0.005,
0.12,
1.08
);
});
const stopDragging = (event) => {
this.dragging = false;
if (element.hasPointerCapture(event.pointerId)) {
element.releasePointerCapture(event.pointerId);
}
};
element.addEventListener("pointerup", stopDragging);
element.addEventListener("pointercancel", stopDragging);
element.addEventListener(
"wheel",
(event) => {
event.preventDefault();
this.radius = THREE.MathUtils.clamp(
this.radius + event.deltaY * 0.004,
3.0,
8.5
);
},
{ passive: false }
);
element.addEventListener("dblclick", () => {
this.radius = options.radius;
this.yaw = options.yaw ?? 0.35;
this.pitch = options.pitch ?? 0.42;
});
this.update();
}
update() {
const horizontal = this.radius * Math.cos(this.pitch);
this.camera.position.set(
this.target.x + horizontal * Math.sin(this.yaw),
this.target.y + this.radius * Math.sin(this.pitch),
this.target.z + horizontal * Math.cos(this.yaw)
);
this.camera.lookAt(this.target);
}
}
function createLab(canvas, config) {
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(config.background);
scene.fog = new THREE.Fog(config.background, 8, 16);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 50);
const hemisphere = new THREE.HemisphereLight(
0xfff9e9,
0x53665e,
2.25
);
scene.add(hemisphere);
const key = new THREE.DirectionalLight(0xfff4d8, 4.1);
key.position.set(4, 7, 5);
key.castShadow = true;
key.shadow.mapSize.set(1024, 1024);
key.shadow.camera.left = -5;
key.shadow.camera.right = 5;
key.shadow.camera.top = 5;
key.shadow.camera.bottom = -5;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 20;
key.shadow.bias = -0.0008;
scene.add(key);
const rim = new THREE.DirectionalLight(0xc7e5ff, 1.5);
rim.position.set(-5, 3, -4);
scene.add(rim);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(20, 20),
new THREE.MeshStandardMaterial({
color: config.ground,
roughness: 0.95,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = config.groundY ?? 0;
ground.receiveShadow = true;
scene.add(ground);
const controls = new DirectOrbit(camera, canvas, {
target: config.target,
radius: config.radius,
yaw: config.yaw,
pitch: config.pitch
});
const lab = {
canvas,
renderer,
scene,
camera,
controls,
elapsed: 0,
duration: config.duration,
update: () => {}
};
const resize = () => {
const rect = canvas.parentElement.getBoundingClientRect();
const width = Math.max(1, Math.floor(rect.width));
const height = Math.max(1, Math.floor(rect.height));
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
};
const observer = new ResizeObserver(resize);
observer.observe(canvas.parentElement);
resize();
lab.observer = observer;
return lab;
}
function shadow(mesh, cast = true, receive = false) {
mesh.castShadow = cast;
mesh.receiveShadow = receive;
return mesh;
}
/*
* 01 — Cooking an egg
*/
function buildEggLab() {
const canvas = document.querySelector("#eggCanvas");
const phase = document.querySelector("#eggPhase");
const progress = document.querySelector("#eggProgress");
const lab = createLab(canvas, {
background: 0xe4e9e1,
ground: 0xd9dfd5,
target: new THREE.Vector3(0.1, 0.62, 0),
radius: 4.9,
yaw: 0.38,
pitch: 0.42,
duration: 8
});
const pan = shadow(
new THREE.Mesh(
new THREE.CylinderGeometry(1.18, 1.28, 0.11, 16),
new THREE.MeshStandardMaterial({
color: 0x303936,
roughness: 0.55,
metalness: 0.72,
flatShading: true
})
)
);
pan.position.y = 0.055;
lab.scene.add(pan);
const rim = shadow(
new THREE.Mesh(
new THREE.TorusGeometry(1.13, 0.045, 6, 32),
new THREE.MeshStandardMaterial({
color: 0x202725,
roughness: 0.45,
metalness: 0.8,
flatShading: true
})
)
);
rim.rotation.x = Math.PI / 2;
rim.position.y = 0.12;
lab.scene.add(rim);
const handle = shadow(
new THREE.Mesh(
new THREE.BoxGeometry(1.05, 0.12, 0.25),
new THREE.MeshStandardMaterial({
color: 0x2a312e,
roughness: 0.6,
metalness: 0.65
})
)
);
handle.position.set(1.72, 0.08, 0);
handle.rotation.z = -0.04;
lab.scene.add(handle);
const heatRing = new THREE.Mesh(
new THREE.TorusGeometry(1.37, 0.024, 5, 32),
new THREE.MeshBasicMaterial({
color: 0xff7b39,
transparent: true,
opacity: 0,
depthWrite: false
})
);
heatRing.rotation.x = Math.PI / 2;
heatRing.position.y = 0.07;
lab.scene.add(heatRing);
const shellMaterial = new THREE.MeshStandardMaterial({
color: 0xf1dfbd,
roughness: 0.82,
flatShading: true,
side: THREE.DoubleSide,
transparent: true,
opacity: 1
});
const shellLeft = shadow(
new THREE.Mesh(
new THREE.SphereGeometry(0.58, 10, 6, 0, Math.PI),
shellMaterial
)
);
const shellRight = shadow(
new THREE.Mesh(
new THREE.SphereGeometry(0.58, 10, 6, Math.PI, Math.PI),
shellMaterial
)
);
const shellGroup = new THREE.Group();
shellGroup.position.y = 0.82;
shellGroup.scale.set(0.82, 1.25, 0.82);
shellGroup.add(shellLeft, shellRight);
lab.scene.add(shellGroup);
const rawWhite = new THREE.Color(0xd9eef0);
const cookedWhite = new THREE.Color(0xfff5d9);
const rawYolk = new THREE.Color(0xf1bd38);
const cookedYolk = new THREE.Color(0xeb8b22);
const whiteMaterial = new THREE.MeshStandardMaterial({
color: rawWhite,
roughness: 0.28,
metalness: 0,
flatShading: true,
transparent: true,
opacity: 0.9
});
const white = shadow(
new THREE.Mesh(
new THREE.IcosahedronGeometry(1, 1),
whiteMaterial
)
);
white.position.y = 0.23;
white.scale.set(0.49, 0.25, 0.42);
lab.scene.add(white);
const lobes = [];
const lobePositions = [
[-0.28, 0.19, 0.13],
[0.27, 0.19, 0.12],
[-0.12, 0.18, -0.25],
[0.17, 0.19, -0.21]
];
lobePositions.forEach((position, index) => {
const lobe = shadow(
new THREE.Mesh(
new THREE.IcosahedronGeometry(1, 0),
whiteMaterial
)
);
lobe.position.set(...position);
lobe.scale.set(0.23, 0.12, 0.19);
lobe.rotation.y = index * 0.7;
lab.scene.add(lobe);
lobes.push(lobe);
});
const yolkMaterial = new THREE.MeshStandardMaterial({
color: rawYolk,
roughness: 0.3,
flatShading: true
});
const yolk = shadow(
new THREE.Mesh(
new THREE.DodecahedronGeometry(0.31, 0),
yolkMaterial
)
);
yolk.position.y = 0.39;
yolk.scale.set(1, 0.72, 1);
lab.scene.add(yolk);
const steam = [];
for (let i = 0; i < 7; i++) {
const material = new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0,
depthWrite: false
});
const puff = new THREE.Mesh(
new THREE.OctahedronGeometry(0.09, 0),
material
);
puff.visible = false;
lab.scene.add(puff);
steam.push(puff);
}
lab.update = (time) => {
const split = smooth(0.12, 1.18, time);
const cooked = smooth(1.1, 4.35, time);
shellLeft.position.x = -split * 0.85;
shellRight.position.x = split * 0.85;
shellLeft.position.y = split * 0.12;
shellRight.position.y = split * 0.12;
shellLeft.rotation.z = -split * 1.15;
shellRight.rotation.z = split * 1.15;
shellLeft.rotation.y = split * 0.35;
shellRight.rotation.y = -split * 0.35;
shellMaterial.opacity = 1 - smooth(0.76, 1.25, time);
shellGroup.visible = time < 1.3;
whiteMaterial.color.copy(rawWhite).lerp(cookedWhite, cooked);
whiteMaterial.opacity = 0.9 + cooked * 0.1;
whiteMaterial.roughness = 0.28 + cooked * 0.55;
const puffScale = 1 + cooked * 0.09;
white.scale.set(
0.49 * puffScale,
0.25 * (1 + cooked * 0.22),
0.42 * puffScale
);
yolkMaterial.color.copy(rawYolk).lerp(cookedYolk, cooked);
yolk.position.y = 0.39 + cooked * 0.035;
yolk.rotation.y = time * 0.16;
heatRing.material.opacity = cooked * 0.34;
heatRing.scale.setScalar(1 + Math.sin(time * 7) * 0.025);
steam.forEach((puff, index) => {
const active = time > 3.25 && time < 7.35;
puff.visible = active;
if (!active) return;
const life = fract(time * 0.31 + index * 0.17);
const angle = index * 2.15 + time * 0.45;
puff.position.set(
Math.sin(angle) * (0.12 + life * 0.22),
0.87 + life * 1.0,
Math.cos(angle * 0.8) * 0.16
);
const size = 0.45 + life * 1.55;
puff.scale.set(size, size * 1.25, size);
puff.rotation.set(life, life * 0.7, 0);
puff.material.opacity =
Math.sin(life * Math.PI) *
0.52 *
smooth(3.25, 4.0, time) *
(1 - smooth(6.8, 7.35, time));
});
const fadeIn = smooth(0, 0.3, time);
const fadeOut = 1 - smooth(7.35, 8, time);
canvas.style.opacity = String(Math.max(0.04, fadeIn * fadeOut));
if (time < 1.2) {
phase.textContent = "Shell opens";
} else if (time < 4.35) {
phase.textContent = "Heat sets the proteins";
} else {
phase.textContent = "Cooked · no reverse";
}
progress.style.width = `${(time / lab.duration) * 100}%`;
};
return lab;
}
/*
* 02 — Melting and refreezing ice
*/
function buildIceLab() {
const canvas = document.querySelector("#iceCanvas");
const phase = document.querySelector("#icePhase");
const progress = document.querySelector("#iceProgress");
const lab = createLab(canvas, {
background: 0xdce9ef,
ground: 0xd1e0e5,
target: new THREE.Vector3(0, 0.45, 0),
radius: 4.35,
yaw: -0.38,
pitch: 0.4,
duration: 8
});
const tray = shadow(
new THREE.Mesh(
new THREE.CylinderGeometry(1.55, 1.62, 0.13, 12),
new THREE.MeshStandardMaterial({
color: 0x9fc7d3,
roughness: 0.38,
metalness: 0.08,
flatShading: true
})
),
true,
true
);
tray.position.y = 0.065;
lab.scene.add(tray);
const trayRim = shadow(
new THREE.Mesh(
new THREE.TorusGeometry(1.5, 0.055, 6, 36),
new THREE.MeshStandardMaterial({
color: 0xc5e1e8,
roughness: 0.25,
metalness: 0.05,
flatShading: true
})
)
);
trayRim.rotation.x = Math.PI / 2;
trayRim.position.y = 0.14;
lab.scene.add(trayRim);
const iceGroup = new THREE.Group();
const iceMaterial = new THREE.MeshStandardMaterial({
color: 0x83cbe8,
roughness: 0.18,
metalness: 0.03,
flatShading: true,
transparent: true,
opacity: 0.82
});
const iceCube = shadow(
new THREE.Mesh(
new THREE.BoxGeometry(0.92, 0.92, 0.92),
iceMaterial
)
);
iceGroup.add(iceCube);
const iceEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(
new THREE.BoxGeometry(0.92, 0.92, 0.92)
),
new THREE.LineBasicMaterial({
color: 0xd8f4ff,
transparent: true,
opacity: 0.9
})
);
iceGroup.add(iceEdges);
lab.scene.add(iceGroup);
const puddleMaterial = new THREE.MeshStandardMaterial({
color: 0x55b7df,
roughness: 0.12,
metalness: 0.04,
transparent: true,
opacity: 0.62,
depthWrite: false,
side: THREE.DoubleSide,
flatShading: true
});
const puddle = new THREE.Mesh(
new THREE.CircleGeometry(1, 12),
puddleMaterial
);
puddle.rotation.x = -Math.PI / 2;
puddle.position.y = 0.138;
lab.scene.add(puddle);
const droplets = [];
for (let i = 0; i < 8; i++) {
const material = new THREE.MeshBasicMaterial({
color: 0x6fc8ea,
transparent: true,
opacity: 0.76,
depthWrite: false
});
const drop = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.065, 0),
material
);
lab.scene.add(drop);
droplets.push(drop);
}
lab.update = (time) => {
let melt = 0;
if (time < 3.55) {
melt = smooth(0.5, 3.4, time);
} else if (time < 7.1) {
melt = 1 - smooth(4.05, 7.05, time);
}
const cubeScale = 1 - melt * 0.92;
const horizontalScale = 1 - melt * 0.58;
iceGroup.scale.set(
horizontalScale,
cubeScale,
horizontalScale
);
iceGroup.position.y = 0.14 + 0.46 * cubeScale;
iceGroup.rotation.y = time * 0.12;
iceGroup.visible = melt < 0.985;
iceMaterial.opacity = 0.82 - melt * 0.16;
iceEdges.material.opacity = 0.9 - melt * 0.2;
const puddleScale = 0.05 + melt * 1.18;
puddle.scale.set(
puddleScale * 1.22,
puddleScale * 0.78,
1
);
puddle.rotation.z = time * 0.04;
droplets.forEach((drop, index) => {
const active = time > 0.45 && time < 4.05;
drop.visible = active;
if (!active) return;
const life = fract(time * 0.52 + index * 0.137);
const angle = index * 2.31 + 0.4;
drop.position.set(
Math.cos(angle) * (0.45 + melt * 0.68),
1.02 - life * 0.95,
Math.sin(angle) * (0.42 + melt * 0.55)
);
drop.scale.setScalar(0.65 + life * 0.55);
drop.material.opacity = (1 - life) * 0.8;
});
if (time < 0.55) {
phase.textContent = "Frozen cube";
} else if (time < 3.55) {
phase.textContent = "Melting into a puddle";
} else if (time < 4.05) {
phase.textContent = "Liquid state";
} else if (time < 7.1) {
phase.textContent = "Refreezing";
} else {
phase.textContent = "Frozen again";
}
progress.style.width = `${(time / lab.duration) * 100}%`;
};
return lab;
}
/*
* 03 — Slicing and reassembling bread
*/
function buildBreadLab() {
const canvas = document.querySelector("#breadCanvas");
const phase = document.querySelector("#breadPhase");
const progress = document.querySelector("#breadProgress");
const lab = createLab(canvas, {
background: 0xeee4d3,
ground: 0xe4d7c1,
target: new THREE.Vector3(0, 0.65, 0),
radius: 5.6,
yaw: 0.28,
pitch: 0.37,
duration: 8
});
const crumbMaterial = new THREE.MeshStandardMaterial({
color: 0xf1d49a,
roughness: 0.95,
flatShading: true
});
const crustMaterial = new THREE.MeshStandardMaterial({
color: 0xb66d28,
roughness: 0.86,
flatShading: true
});
const scoreMaterial = new THREE.MeshStandardMaterial({
color: 0xe0b875,
roughness: 0.95,
flatShading: true
});
const slices = [];
const sliceCount = 5;
const sliceWidth = 0.5;
for (let i = 0; i < sliceCount; i++) {
const slice = new THREE.Group();
const center = shadow(
new THREE.Mesh(
new THREE.BoxGeometry(0.49, 0.62, 1.16),
crumbMaterial
)
);
slice.add(center);
const topCrust = shadow(
new THREE.Mesh(
new THREE.BoxGeometry(0.51, 0.12, 1.19),
crustMaterial
)
);
topCrust.position.y = 0.34;
slice.add(topCrust);
[-1, 1].forEach((side) => {
const sideCrust = shadow(
new THREE.Mesh(
new THREE.BoxGeometry(0.035, 0.64, 1.18),
crustMaterial
)
);
sideCrust.position.x = side * 0.255;
slice.add(sideCrust);
});
[-0.28, 0.24].forEach((z, scoreIndex) => {
const mark = new THREE.Mesh(
new THREE.BoxGeometry(0.29, 0.014, 0.035),
scoreMaterial
);
mark.position.set(0, 0.407, z + scoreIndex * 0.04);
mark.rotation.y = scoreIndex === 0 ? -0.18 : 0.18;
slice.add(mark);
});
slice.position.x = (i - (sliceCount - 1) / 2) * sliceWidth;
slice.position.y = 0.54;
lab.scene.add(slice);
slices.push(slice);
}
const cutLines = [];
for (let i = 0; i < sliceCount - 1; i++) {
const line = new THREE.Mesh(
new THREE.BoxGeometry(0.018, 0.014, 1.12),
new THREE.MeshBasicMaterial({
color: 0x8c4c1e,
transparent: true,
opacity: 0.85
})
);
line.position.set(
(i - (sliceCount - 2) / 2) * sliceWidth,
0.955,
0
);
line.visible = false;
lab.scene.add(line);
cutLines.push(line);
}
const knife = new THREE.Group();
const blade = shadow(
new THREE.Mesh(
new THREE.BoxGeometry(0.045, 0.5, 1.02),
new THREE.MeshStandardMaterial({
color: 0xdce3e5,
roughness: 0.23,
metalness: 0.72,
flatShading: true
})
)
);
knife.add(blade);
const handle = shadow(
new THREE.Mesh(
new THREE.BoxGeometry(0.14, 0.28, 0.48),
new THREE.MeshStandardMaterial({
color: 0x483528,
roughness: 0.72,
flatShading: true
})
)
);
handle.position.y = 0.38;
knife.add(handle);
lab.scene.add(knife);
const crumbs = [];
const crumbLayout = [
[-0.82, 0.22],
[-0.61, -0.31],
[-0.24, 0.38],
[0.08, -0.24],
[0.31, 0.31],
[0.52, -0.38],
[0.83, 0.18],
[-0.39, -0.43],
[0.18, 0.44]
];
crumbLayout.forEach(([x, z]) => {
const material = new THREE.MeshBasicMaterial({
color: 0xc89554,
transparent: true,
opacity: 0
});
const crumb = new THREE.Mesh(
new THREE.TetrahedronGeometry(0.055),
material
);
crumb.userData.baseX = x;
crumb.userData.baseZ = z;
lab.scene.add(crumb);
crumbs.push(crumb);
});
lab.update = (time) => {
const cutting = smooth(0.6, 2.2, time);
const retract = smooth(2.2, 2.85, time);
const separation =
smooth(2.3, 3.6, time) *
(1 - smooth(5.4, 6.8, time));
knife.position.x = -1.15 + cutting * 2.3;
knife.position.y = 1.8 - cutting * 0.63 + retract * 0.7;
knife.rotation.z = -0.03 - retract * 0.03;
slices.forEach((slice, index) => {
const baseX = (index - 2) * sliceWidth;
const offset = (index - 2) * 0.26;
slice.position.x = baseX + offset * separation;
slice.position.z =
(index % 2 === 0 ? -1 : 1) * 0.055 * separation;
slice.position.y =
0.54 + Math.sin(index * 1.7) * 0.015 * separation;
slice.rotation.y = (index - 2) * 0.035 * separation;
});
cutLines.forEach((line, index) => {
line.visible = time > 0.85 + index * 0.34;
});
crumbs.forEach((crumb, index) => {
const active = time > 1.8 && time < 6.65;
crumb.visible = active;
if (!active) return;
const life = fract(time * 0.48 + index * 0.13);
crumb.position.set(
crumb.userData.baseX + life * 0.12,
0.99 - life * 0.48,
crumb.userData.baseZ + Math.sin(index) * life * 0.08
);
crumb.rotation.set(life * 3, life * 4, life * 2);
crumb.material.opacity =
Math.sin(life * Math.PI) *
0.82 *
(1 - smooth(5.8, 6.65, time));
});
if (time < 0.6) {
phase.textContent = "Whole loaf";
} else if (time < 2.3) {
phase.textContent = "Cutting into slices";
} else if (time < 5.4) {
phase.textContent = "Slices separated";
} else if (time < 6.8) {
phase.textContent = "Reassembling";
} else {
phase.textContent = "Reassembled · still sliced";
}
progress.style.width = `${(time / lab.duration) * 100}%`;
};
return lab;
}
labs.push(buildEggLab());
labs.push(buildIceLab());
labs.push(buildBreadLab());
const pauseButton = document.querySelector("#pauseAll");
const replayButton = document.querySelector("#replayAll");
let paused = false;
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume all" : "Pause all";
});
replayButton.addEventListener("click", () => {
labs.forEach((lab) => {
lab.elapsed = 0;
lab.update(0);
});
});
document.querySelectorAll("[data-replay]").forEach((button) => {
button.addEventListener("click", () => {
const lab = labs.find(
(entry) => entry.canvas.id === button.dataset.replay
);
if (lab) {
lab.elapsed = 0;
lab.update(0);
}
});
});
let previous = performance.now();
function animate(now) {
const delta = Math.min((now - previous) / 1000, 0.05);
previous = now;
labs.forEach((lab) => {
lab.controls.update();
if (!paused) {
lab.elapsed = (lab.elapsed + delta) % lab.duration;
lab.update(lab.elapsed);
}
lab.renderer.render(lab.scene, lab.camera);
});
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```