Prompt specification
Build or customize the Three.js 3D scene "Breakfast assembly counter" 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: Breakfast assembly counter
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/breakfast-assembly-counter-x0103
Scene Description Prompt:
Create a standalone stylized scene in one HTML file using Three.js from cdnjs. Build a breakfast counter with eggs, toast, fruit, and three plates; animate servings assembling in order and keep shell fragments visually separate from the food areas.
Working Three.js Starter (breakfast-assembly-counter-x0103):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Breakfast Assembly</title>
<style>
:root {
--ink: #243e3a;
--muted: #6b7b73;
--cream: #fffaf0;
--accent: #e56f4d;
--sage: #91aa8c;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #efe4d7;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.title-block {
position: absolute;
top: clamp(24px, 5vw, 64px);
left: clamp(24px, 5vw, 72px);
max-width: 420px;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 9px;
margin-bottom: 14px;
padding: 7px 11px;
border: 1px solid rgba(36, 62, 58, 0.15);
border-radius: 999px;
background: rgba(255, 250, 240, 0.66);
backdrop-filter: blur(10px);
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px rgba(229, 111, 77, 0.13);
content: "";
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(38px, 5vw, 70px);
font-weight: 500;
line-height: 0.95;
letter-spacing: -0.045em;
}
.subtitle {
max-width: 350px;
margin: 18px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.65;
}
.sequence {
position: absolute;
bottom: clamp(22px, 4vw, 48px);
left: clamp(24px, 5vw, 72px);
width: min(360px, calc(100vw - 48px));
padding: 16px 18px;
border: 1px solid rgba(36, 62, 58, 0.12);
border-radius: 18px;
background: rgba(255, 250, 240, 0.82);
box-shadow: 0 18px 50px rgba(68, 52, 38, 0.11);
backdrop-filter: blur(16px);
}
.sequence-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
margin-bottom: 12px;
}
#status {
overflow: hidden;
color: var(--ink);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-overflow: ellipsis;
text-transform: uppercase;
white-space: nowrap;
}
#time {
flex: none;
color: var(--muted);
font-size: 10px;
font-variant-numeric: tabular-nums;
}
.steps {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.step {
padding-top: 9px;
border-top: 3px solid rgba(36, 62, 58, 0.1);
color: #9aa39c;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: color 250ms ease, border-color 250ms ease;
}
.step.active {
border-color: var(--accent);
color: var(--ink);
}
.step.done {
border-color: var(--sage);
color: #637b68;
}
.progress {
height: 3px;
margin-top: 14px;
overflow: hidden;
border-radius: 99px;
background: rgba(36, 62, 58, 0.08);
}
#progress-fill {
width: 0%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--accent), #efb45f);
transition: width 80ms linear;
}
.controls {
position: absolute;
right: clamp(24px, 5vw, 72px);
bottom: clamp(24px, 4vw, 48px);
display: flex;
gap: 9px;
pointer-events: auto;
}
button {
min-height: 42px;
padding: 0 17px;
border: 1px solid rgba(36, 62, 58, 0.14);
border-radius: 999px;
background: rgba(255, 250, 240, 0.88);
box-shadow: 0 10px 30px rgba(68, 52, 38, 0.1);
color: var(--ink);
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.05em;
text-transform: uppercase;
backdrop-filter: blur(12px);
transition: transform 150ms ease, background 150ms ease;
}
button:hover {
transform: translateY(-2px);
background: #fffdf7;
}
button:active {
transform: translateY(0);
}
.camera-hint {
position: absolute;
right: clamp(24px, 5vw, 72px);
top: clamp(24px, 4vw, 48px);
color: rgba(36, 62, 58, 0.56);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 760px) {
.title-block {
top: 22px;
}
.subtitle,
.camera-hint {
display: none;
}
h1 {
font-size: 42px;
}
.sequence {
bottom: 78px;
padding: 13px 15px;
}
.controls {
right: 24px;
bottom: 22px;
}
}
</style>
</head>
<body>
<div class="hud">
<div class="title-block">
<div class="eyebrow">Morning ritual · 08:12</div>
<h1>A little breakfast,<br />assembled.</h1>
<p class="subtitle">
Three complete servings build themselves from left to right.
Eggshells take a separate route to the disposal dish.
</p>
</div>
<div class="camera-hint">Drag to orbit · Scroll to zoom</div>
<div class="sequence">
<div class="sequence-header">
<div id="status">Starting the first serving</div>
<div id="time">0.0 / 11.5 s</div>
</div>
<div class="steps">
<div class="step active" data-step="0">01 · Toast</div>
<div class="step" data-step="1">02 · Egg</div>
<div class="step" data-step="2">03 · Fruit</div>
</div>
<div class="progress"><div id="progress-fill"></div></div>
</div>
<div class="controls">
<button id="pause" type="button">Pause</button>
<button id="replay" type="button">Replay</button>
</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, scene, camera
// ---------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xefe4d7);
scene.fog = new THREE.Fog(0xefe4d7, 20, 36);
const camera = new THREE.PerspectiveCamera(
37,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.body.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xfff5dd, 0x718879, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffedcf, 4.2);
sun.position.set(-5, 11, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 9;
sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.0003;
scene.add(sun);
const fill = new THREE.PointLight(0xffb987, 20, 18, 2);
fill.position.set(7, 5, 3);
scene.add(fill);
// ---------------------------------------------------------------------------
// Materials and reusable geometry helpers
// ---------------------------------------------------------------------------
const material = (color, roughness = 0.72, extra = {}) =>
new THREE.MeshStandardMaterial({ color, roughness, ...extra });
const mats = {
counter: material(0xd8b887),
cabinet: material(0x49655c),
cabinetDark: material(0x314b44),
wall: material(0xf2e7d8),
floor: material(0xd9c7b1),
plate: material(0xfffaf0, 0.38),
crust: material(0xb96f35),
bread: material(0xe9bb70),
butter: material(0xffd979, 0.42),
eggWhite: material(0xfffbec, 0.48),
yolk: material(0xf5aa28, 0.35),
pepper: material(0x49352d),
strawberry: material(0xda4f43, 0.48),
green: material(0x5f8b55),
blueberry: material(0x536486, 0.5),
orange: material(0xf5a13c, 0.55),
orangeCenter: material(0xffd06b, 0.6),
shell: material(0xf0d3a7, 0.82),
shellInside: material(0xe9a38d, 0.78),
glass: material(0xaac9c4, 0.2, {
transparent: true,
opacity: 0.2,
depthWrite: false
}),
brass: material(0xb88a4d, 0.42, {
metalness: 0.55
}),
terracotta: material(0xb9684d)
};
function roundedRectShape(width, height, radius) {
const x = -width / 2;
const y = -height / 2;
const s = new THREE.Shape();
s.moveTo(x + radius, y);
s.lineTo(x + width - radius, y);
s.quadraticCurveTo(x + width, y, x + width, y + radius);
s.lineTo(x + width, y + height - radius);
s.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
s.lineTo(x + radius, y + height);
s.quadraticCurveTo(x, y + height, x, y + height - radius);
s.lineTo(x, y + radius);
s.quadraticCurveTo(x, y, x + radius, y);
return s;
}
function horizontalExtrude(shape, depth, bevel = 0.04) {
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
bevelEnabled: bevel > 0,
bevelSize: bevel,
bevelThickness: bevel,
bevelSegments: 3,
curveSegments: 12,
steps: 1
});
geometry.rotateX(-Math.PI / 2);
return geometry;
}
function canvasTexture(text, background = "#31534d", foreground = "#fffaf0") {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = background;
ctx.beginPath();
ctx.roundRect(8, 8, 1008, 240, 42);
ctx.fill();
ctx.fillStyle = foreground;
ctx.font = "800 76px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 512, 132);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function makeLabel(text, width, height, background, foreground) {
const texture = canvasTexture(text, background, foreground);
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
side: THREE.DoubleSide
})
);
return mesh;
}
// ---------------------------------------------------------------------------
// Counter, wall, floor and environment
// ---------------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(50, 40),
mats.floor
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.82;
floor.receiveShadow = true;
scene.add(floor);
const wall = new THREE.Mesh(
new THREE.BoxGeometry(20, 7.2, 0.25),
mats.wall
);
wall.position.set(0, 1.75, -3.75);
wall.receiveShadow = true;
scene.add(wall);
const cabinet = new THREE.Mesh(
new THREE.BoxGeometry(17.3, 1.25, 6.35),
mats.cabinet
);
cabinet.position.set(0, -1.18, 0);
cabinet.castShadow = true;
cabinet.receiveShadow = true;
scene.add(cabinet);
const toeKick = new THREE.Mesh(
new THREE.BoxGeometry(17.35, 0.18, 6.4),
mats.cabinetDark
);
toeKick.position.set(0, -1.79, 0.05);
scene.add(toeKick);
const counterShape = roundedRectShape(18, 7, 0.42);
const counterGeometry = horizontalExtrude(counterShape, 0.45, 0.075);
counterGeometry.translate(0, -0.51, 0);
const counter = new THREE.Mesh(counterGeometry, mats.counter);
counter.castShadow = true;
counter.receiveShadow = true;
scene.add(counter);
// Cabinet handles.
for (const x of [-5.8, -1.9, 1.9, 5.8]) {
const handle = new THREE.Mesh(
new THREE.CapsuleGeometry(0.035, 0.55, 4, 10),
mats.brass
);
handle.rotation.z = Math.PI / 2;
handle.position.set(x, -0.89, 3.2);
handle.castShadow = true;
scene.add(handle);
}
// Back-wall tile seams.
for (let x = -8; x <= 8; x += 2) {
const seam = new THREE.Mesh(
new THREE.BoxGeometry(0.018, 4.7, 0.015),
material(0xdfd1c0)
);
seam.position.set(x, 1.35, -3.605);
scene.add(seam);
}
for (let y = -0.75; y < 4; y += 1.15) {
const seam = new THREE.Mesh(
new THREE.BoxGeometry(18, 0.018, 0.015),
material(0xdfd1c0)
);
seam.position.set(0, y, -3.603);
scene.add(seam);
}
// Small plant for depth.
const plant = new THREE.Group();
plant.position.set(-7.05, 0.02, -1.72);
const pot = new THREE.Mesh(
new THREE.CylinderGeometry(0.46, 0.34, 0.62, 24),
mats.terracotta
);
pot.position.y = 0.31;
pot.castShadow = true;
plant.add(pot);
const stemMaterial = material(0x466f4d);
for (let i = 0; i < 7; i++) {
const angle = (i / 7) * Math.PI * 2;
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.018, 0.025, 1.25, 7),
stemMaterial
);
stem.position.set(
Math.cos(angle) * 0.16,
1.0,
Math.sin(angle) * 0.16
);
stem.rotation.z = Math.cos(angle) * 0.22;
stem.rotation.x = Math.sin(angle) * 0.22;
plant.add(stem);
const leaf = new THREE.Mesh(
new THREE.SphereGeometry(0.34, 14, 9),
material(i % 2 ? 0x648d59 : 0x759c65)
);
leaf.scale.set(0.48, 1.18, 0.17);
leaf.position.set(
Math.cos(angle) * 0.3,
1.53 + (i % 2) * 0.12,
Math.sin(angle) * 0.3
);
leaf.rotation.set(0.45, -angle, Math.cos(angle) * 0.45);
leaf.castShadow = true;
plant.add(leaf);
}
scene.add(plant);
// A small ceramic mug behind the serving area.
const mug = new THREE.Group();
mug.position.set(-6.2, 0.02, 1.05);
const mugBody = new THREE.Mesh(
new THREE.CylinderGeometry(0.34, 0.29, 0.58, 24),
material(0xe8a15f)
);
mugBody.position.y = 0.29;
mugBody.castShadow = true;
mug.add(mugBody);
const coffee = new THREE.Mesh(
new THREE.CircleGeometry(0.29, 24),
material(0x593a28, 0.3)
);
coffee.rotation.x = -Math.PI / 2;
coffee.position.y = 0.585;
mug.add(coffee);
const handle = new THREE.Mesh(
new THREE.TorusGeometry(0.22, 0.055, 10, 24),
material(0xe8a15f)
);
handle.position.set(0.34, 0.32, 0);
handle.rotation.y = Math.PI / 2;
mug.add(handle);
scene.add(mug);
// ---------------------------------------------------------------------------
// Plate and food geometry
// ---------------------------------------------------------------------------
const plateProfile = [
new THREE.Vector2(0, 0.03),
new THREE.Vector2(0.58, 0.03),
new THREE.Vector2(0.8, 0.06),
new THREE.Vector2(0.96, 0.13),
new THREE.Vector2(1.05, 0.21),
new THREE.Vector2(1.08, 0.25),
new THREE.Vector2(1.04, 0.29),
new THREE.Vector2(0.96, 0.25),
new THREE.Vector2(0.78, 0.16),
new THREE.Vector2(0.58, 0.13),
new THREE.Vector2(0, 0.13)
];
const plateGeometry = new THREE.LatheGeometry(plateProfile, 64);
const plateX = [-3.85, -0.55, 2.75];
const rimColors = [0xd77b5d, 0x6f9683, 0xd4a24c];
function createPlate(x, accent, index) {
const group = new THREE.Group();
group.position.set(x, 0.035, 0.3);
const plate = new THREE.Mesh(plateGeometry, mats.plate);
plate.castShadow = true;
plate.receiveShadow = true;
group.add(plate);
const rim = new THREE.Mesh(
new THREE.TorusGeometry(1.035, 0.032, 8, 64),
material(accent, 0.48)
);
rim.rotation.x = Math.PI / 2;
rim.position.y = 0.255;
rim.castShadow = true;
group.add(rim);
const mat = new THREE.Mesh(
new THREE.CircleGeometry(1.3, 64),
material(index === 1 ? 0xe8ddbd : 0xe6d1b5)
);
mat.rotation.x = -Math.PI / 2;
mat.position.set(x, 0.012, 0.3);
mat.receiveShadow = true;
scene.add(mat);
const number = makeLabel(
`0${index + 1}`,
0.58,
0.25,
accent === 0xd4a24c ? "#d4a24c" : "#31534d",
"#fffaf0"
);
number.rotation.x = -Math.PI / 2;
number.position.set(x, 0.025, 1.73);
scene.add(number);
scene.add(group);
}
plateX.forEach((x, i) => createPlate(x, rimColors[i], i));
function toastShape(width, height) {
const s = new THREE.Shape();
s.moveTo(-width / 2, -height / 2);
s.lineTo(width / 2, -height / 2);
s.lineTo(width / 2, height * 0.08);
s.quadraticCurveTo(width / 2, height * 0.42, 0, height / 2);
s.quadraticCurveTo(-width / 2, height * 0.42, -width / 2, height * 0.08);
s.closePath();
return s;
}
function createToast() {
const group = new THREE.Group();
const crust = new THREE.Mesh(
horizontalExtrude(toastShape(0.8, 0.8), 0.12, 0.035),
mats.crust
);
crust.castShadow = true;
crust.receiveShadow = true;
group.add(crust);
const inner = new THREE.Mesh(
horizontalExtrude(toastShape(0.69, 0.68), 0.045, 0.025),
mats.bread
);
inner.position.y = 0.115;
inner.castShadow = true;
group.add(inner);
const butter = new THREE.Mesh(
new THREE.BoxGeometry(0.2, 0.045, 0.19),
mats.butter
);
butter.position.set(0.02, 0.19, 0);
butter.rotation.y = 0.16;
butter.castShadow = true;
group.add(butter);
// A few restrained toast speckles.
const speckleMaterial = material(0xa96531);
const positions = [
[-0.19, 0.05],
[0.14, -0.16],
[-0.08, 0.24],
[0.24, 0.13],
[-0.25, -0.13]
];
for (const [x, z] of positions) {
const speck = new THREE.Mesh(
new THREE.CircleGeometry(0.014, 8),
speckleMaterial
);
speck.rotation.x = -Math.PI / 2;
speck.position.set(x, 0.163, z);
group.add(speck);
}
return group;
}
function eggWhiteGeometry() {
const shape = new THREE.Shape();
const segments = 44;
for (let i = 0; i <= segments; i++) {
const angle = (i / segments) * Math.PI * 2;
const radius =
1 +
0.075 * Math.sin(angle * 3 + 0.4) +
0.045 * Math.sin(angle * 5 - 0.8);
const x = Math.cos(angle) * radius;
const y = Math.sin(angle) * radius;
if (i === 0) shape.moveTo(x, y);
else shape.lineTo(x, y);
}
shape.closePath();
const geometry = new THREE.ShapeGeometry(shape, 12);
geometry.rotateX(-Math.PI / 2);
geometry.scale(0.38, 1, 0.35);
return geometry;
}
function createEgg() {
const group = new THREE.Group();
const white = new THREE.Mesh(eggWhiteGeometry(), mats.eggWhite);
white.position.y = 0.018;
white.castShadow = true;
white.receiveShadow = true;
group.add(white);
const yolk = new THREE.Mesh(
new THREE.SphereGeometry(0.19, 28, 18),
mats.yolk
);
yolk.scale.set(1, 0.36, 1);
yolk.position.set(0.035, 0.085, -0.02);
yolk.castShadow = true;
group.add(yolk);
const highlight = new THREE.Mesh(
new THREE.SphereGeometry(0.045, 12, 8),
material(0xffd979, 0.4)
);
highlight.scale.set(1, 0.22, 0.75);
highlight.position.set(0.08, 0.145, -0.065);
group.add(highlight);
for (const [x, z] of [
[-0.18, -0.08],
[0.2, 0.12],
[-0.08, 0.17]
]) {
const pepper = new THREE.Mesh(
new THREE.SphereGeometry(0.012, 6, 5),
mats.pepper
);
pepper.position.set(x, 0.035, z);
group.add(pepper);
}
return group;
}
function createStrawberry() {
const group = new THREE.Group();
const body = new THREE.Mesh(
new THREE.SphereGeometry(1, 18, 12),
mats.strawberry
);
body.scale.set(0.18, 0.25, 0.16);
body.position.y = 0.19;
body.castShadow = true;
group.add(body);
for (let i = 0; i < 5; i++) {
const angle = (i / 5) * Math.PI * 2;
const leaf = new THREE.Mesh(
new THREE.SphereGeometry(0.075, 8, 6),
mats.green
);
leaf.scale.set(0.55, 0.16, 1.45);
leaf.position.set(
Math.cos(angle) * 0.075,
0.43,
Math.sin(angle) * 0.075
);
leaf.rotation.y = -angle;
leaf.rotation.z = 0.18;
group.add(leaf);
}
const seedMaterial = material(0xf4c56d);
for (let i = 0; i < 7; i++) {
const angle = i * 2.4;
const seed = new THREE.Mesh(
new THREE.SphereGeometry(0.012, 5, 4),
seedMaterial
);
seed.position.set(
Math.cos(angle) * 0.1,
0.18 + (i % 3) * 0.07,
Math.sin(angle) * 0.09
);
group.add(seed);
}
return group;
}
function createBlueberry() {
const group = new THREE.Group();
const berry = new THREE.Mesh(
new THREE.SphereGeometry(0.115, 16, 10),
mats.blueberry
);
berry.scale.y = 0.88;
berry.position.y = 0.105;
berry.castShadow = true;
group.add(berry);
const crown = new THREE.Mesh(
new THREE.TorusGeometry(0.045, 0.009, 5, 12),
material(0x303b59)
);
crown.rotation.x = Math.PI / 2;
crown.position.y = 0.205;
group.add(crown);
return group;
}
function createOrangeSlice() {
const group = new THREE.Group();
const wedgeShape = new THREE.Shape();
wedgeShape.moveTo(0, 0);
wedgeShape.lineTo(0.23, 0);
wedgeShape.absarc(0, 0, 0.23, 0, Math.PI, false);
wedgeShape.lineTo(0, 0);
const wedge = new THREE.Mesh(
horizontalExtrude(wedgeShape, 0.075, 0.012),
mats.orange
);
wedge.castShadow = true;
group.add(wedge);
const innerShape = new THREE.Shape();
innerShape.moveTo(0, 0);
innerShape.lineTo(0.19, 0);
innerShape.absarc(0, 0, 0.19, 0, Math.PI, false);
innerShape.lineTo(0, 0);
const inner = new THREE.Mesh(
horizontalExtrude(innerShape, 0.018, 0.006),
mats.orangeCenter
);
inner.position.y = 0.073;
group.add(inner);
return group;
}
// ---------------------------------------------------------------------------
// Separate shell station and divider
// ---------------------------------------------------------------------------
const shellStation = new THREE.Group();
shellStation.position.set(6.35, 0, 0.28);
const shellMat = new THREE.Mesh(
new THREE.CircleGeometry(0.98, 48),
material(0xa9c4b9)
);
shellMat.rotation.x = -Math.PI / 2;
shellMat.position.y = 0.017;
shellMat.scale.set(1.1, 0.87, 1);
shellMat.receiveShadow = true;
shellStation.add(shellMat);
const shellBowlProfile = [
new THREE.Vector2(0, 0.02),
new THREE.Vector2(0.43, 0.02),
new THREE.Vector2(0.62, 0.06),
new THREE.Vector2(0.74, 0.16),
new THREE.Vector2(0.79, 0.23),
new THREE.Vector2(0.75, 0.27),
new THREE.Vector2(0.64, 0.17),
new THREE.Vector2(0.42, 0.1),
new THREE.Vector2(0, 0.1)
];
const shellBowl = new THREE.Mesh(
new THREE.LatheGeometry(shellBowlProfile, 48),
mats.terracotta
);
shellBowl.castShadow = true;
shellBowl.receiveShadow = true;
shellStation.add(shellBowl);
const shellSign = makeLabel(
"SHELL DISPOSAL",
2.35,
0.55,
"#31534d",
"#fffaf0"
);
shellSign.position.set(0, 0.68, -1.05);
shellStation.add(shellSign);
const signPostLeft = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.025, 0.6, 8),
mats.brass
);
signPostLeft.position.set(-0.95, 0.29, -1.05);
shellStation.add(signPostLeft);
const signPostRight = signPostLeft.clone();
signPostRight.position.x = 0.95;
shellStation.add(signPostRight);
scene.add(shellStation);
// A transparent divider physically separates food and shell zones.
const divider = new THREE.Group();
divider.position.set(5.08, 0, 0.18);
const pane = new THREE.Mesh(
new THREE.BoxGeometry(0.045, 1.12, 2.35),
mats.glass
);
pane.position.y = 0.6;
divider.add(pane);
for (const z of [-1.18, 1.18]) {
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.035, 1.25, 10),
mats.brass
);
post.position.set(0, 0.62, z);
post.castShadow = true;
divider.add(post);
}
scene.add(divider);
// ---------------------------------------------------------------------------
// Animated serving objects
// ---------------------------------------------------------------------------
const animatedRoots = [];
const actions = [];
const cycleLength = 3.85;
const timelineDuration = 11.5;
function createWholeShell() {
const group = new THREE.Group();
const shell = new THREE.Mesh(
new THREE.SphereGeometry(0.34, 24, 16),
mats.shell
);
shell.scale.y = 1.32;
shell.castShadow = true;
group.add(shell);
const speckleMaterial = material(0xb58d61);
for (let i = 0; i < 12; i++) {
const angle = i * 2.399;
const latitude = -0.55 + (i % 4) * 0.34;
const speck = new THREE.Mesh(
new THREE.SphereGeometry(0.017, 6, 5),
speckleMaterial
);
speck.position.set(
Math.cos(angle) * Math.cos(latitude) * 0.335,
Math.sin(latitude) * 0.445,
Math.sin(angle) * Math.cos(latitude) * 0.335
);
group.add(speck);
}
return group;
}
function createShellHalf() {
const group = new THREE.Group();
const outer = new THREE.Mesh(
new THREE.SphereGeometry(
0.34,
22,
12,
0,
Math.PI * 2,
Math.PI / 2,
Math.PI / 2
),
mats.shell
);
outer.castShadow = true;
group.add(outer);
const inside = new THREE.Mesh(
new THREE.SphereGeometry(
0.305,
20,
10,
0,
Math.PI * 2,
Math.PI / 2,
Math.PI / 2
),
mats.shellInside
);
inside.position.y = 0.008;
group.add(inside);
const rim = new THREE.Mesh(
new THREE.TorusGeometry(0.322, 0.018, 7, 32),
mats.shellInside
);
rim.rotation.x = Math.PI / 2;
rim.position.y = 0.006;
group.add(rim);
return group;
}
const servings = [];
for (let i = 0; i < 3; i++) {
const baseX = plateX[i];
const baseZ = 0.3;
const toast = createToast();
const toastTarget = new THREE.Vector3(baseX - 0.29, 0.205, baseZ + 0.08);
const toastRotation = -0.12 + i * 0.08;
toast.rotation.y = toastRotation;
const wholeShell = createWholeShell();
const shellA = createShellHalf();
const shellB = createShellHalf();
const egg = createEgg();
const eggTarget = new THREE.Vector3(baseX + 0.29, 0.205, baseZ - 0.25);
const strawberry = createStrawberry();
const blueberry = createBlueberry();
const orange = createOrangeSlice();
const fruitTargets = [
new THREE.Vector3(baseX + 0.43, 0.225, baseZ + 0.43),
new THREE.Vector3(baseX + 0.68, 0.225, baseZ + 0.2),
new THREE.Vector3(baseX + 0.19, 0.225, baseZ + 0.58)
];
const fruitRotations = [0.1, -0.85, 0.35];
[
toast,
wholeShell,
shellA,
shellB,
egg,
strawberry,
blueberry,
orange
].forEach((object) => {
object.visible = false;
animatedRoots.push(object);
scene.add(object);
});
servings.push({
toast,
toastTarget,
toastRotation,
wholeShell,
shellA,
shellB,
egg,
eggTarget,
strawberry,
blueberry,
orange,
fruitTargets,
fruitRotations
});
}
// ---------------------------------------------------------------------------
// Easing and timeline
// ---------------------------------------------------------------------------
const clamp01 = (v) => Math.min(1, Math.max(0, v));
const lerp = THREE.MathUtils.lerp;
function easeOutCubic(t) {
return 1 - Math.pow(1 - t, 3);
}
function easeInCubic(t) {
return t * t * t;
}
function easeInOutCubic(t) {
return t < 0.5
? 4 * t * t * t
: 1 - Math.pow(-2 * t + 2, 3) / 2;
}
function easeOutBack(t) {
const c1 = 1.70158;
const c3 = c1 + 1;
return 1 + c3 * Math.pow(t - 1, 3) + c1 * Math.pow(t - 1, 2);
}
function addAction(start, duration, update) {
actions.push({ start, duration, update });
}
servings.forEach((serving, index) => {
const start = index * cycleLength;
// Toast descends and settles first.
addAction(start, 0.95, (p) => {
const q = clamp01(p / 0.8);
const drop = easeOutCubic(q);
serving.toast.visible = true;
serving.toast.position.set(
serving.toastTarget.x,
lerp(3.25, serving.toastTarget.y, drop),
serving.toastTarget.z
);
serving.toast.rotation.y =
serving.toastRotation - 0.45 * (1 - drop);
const scale = lerp(0.84, 1, drop);
serving.toast.scale.setScalar(scale);
if (p > 0.8) {
const bounce = Math.sin(((p - 0.8) / 0.2) * Math.PI);
serving.toast.position.y += bounce * 0.055;
}
});
// The intact egg shell lowers toward the plate.
addAction(start + 0.95, 0.6, (p) => {
const q = easeOutCubic(p);
serving.wholeShell.visible = true;
serving.shellA.visible = false;
serving.shellB.visible = false;
serving.wholeShell.position.set(
serving.eggTarget.x,
lerp(3.45, serving.eggTarget.y + 1.25, q),
serving.eggTarget.z
);
serving.wholeShell.rotation.y = p * Math.PI * 0.4;
});
// Shell fragments immediately leave the food area and travel over the divider.
addAction(start + 1.55, 1.35, (p) => {
const q = easeInOutCubic(p);
serving.wholeShell.visible = false;
serving.shellA.visible = true;
serving.shellB.visible = true;
const startAX = serving.eggTarget.x - 0.12;
const startBX = serving.eggTarget.x + 0.12;
const startY = serving.eggTarget.y + 1.25;
const endAX = 6.02 + (index % 2) * 0.08;
const endBX = 6.68 - (index % 2) * 0.05;
const endAZ = 0.02 + index * 0.1;
const endBZ = 0.52 - index * 0.05;
serving.shellA.position.set(
lerp(startAX, endAX, q),
lerp(startY, 0.4, p) + Math.sin(Math.PI * p) * 1.42,
lerp(serving.eggTarget.z, endAZ, q)
);
serving.shellB.position.set(
lerp(startBX, endBX, q),
lerp(startY, 0.43, p) + Math.sin(Math.PI * p) * 1.28,
lerp(serving.eggTarget.z, endBZ, q)
);
serving.shellA.rotation.set(
0.3 + p * 1.25,
-0.4 - p * 1.6,
0.48 + p * 0.65
);
serving.shellB.rotation.set(
-0.2 - p * 1.05,
0.5 + p * 1.45,
-0.55 - p * 0.55
);
const shellScale = 0.72;
serving.shellA.scale.setScalar(shellScale);
serving.shellB.scale.setScalar(shellScale);
});
// The edible fried egg drops onto the plate.
addAction(start + 1.55, 0.85, (p) => {
serving.egg.visible = true;
const landing = clamp01(p / 0.76);
const y =
landing < 0.72
? lerp(
serving.eggTarget.y + 1.25,
serving.eggTarget.y,
easeInCubic(landing / 0.72)
)
: lerp(
serving.eggTarget.y - 0.055,
serving.eggTarget.y,
easeOutBack((landing - 0.72) / 0.28)
);
serving.egg.position.set(
serving.eggTarget.x,
y,
serving.eggTarget.z
);
serving.egg.rotation.y = -0.25 + p * 0.25;
serving.egg.scale.setScalar(lerp(0.92, 1, easeOutCubic(p)));
});
// Fruit pieces arrive one after another.
const fruitObjects = [
serving.strawberry,
serving.blueberry,
serving.orange
];
fruitObjects.forEach((fruit, fruitIndex) => {
const fruitStart = start + 2.35 + fruitIndex * 0.14;
const target = serving.fruitTargets[fruitIndex];
addAction(fruitStart, 0.9, (p) => {
fruit.visible = true;
const q = easeOutCubic(p);
const startY = 2.8 + fruitIndex * 0.35;
fruit.position.set(
lerp(target.x + 0.22, target.x, q),
lerp(startY, target.y, q) + Math.sin(Math.PI * p) * 0.75,
lerp(target.z - 0.18, target.z, q)
);
fruit.rotation.y =
serving.fruitRotations[fruitIndex] + (1 - q) * 1.2;
fruit.rotation.z = (1 - q) * 0.25;
fruit.scale.setScalar(lerp(0.7, 1, q));
});
});
});
// ---------------------------------------------------------------------------
// Custom camera controls implemented directly in this file
// ---------------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 0.55, 0),
theta: 0.57,
phi: 1.02,
radius: 16.5,
thetaVelocity: 0,
phiVelocity: 0
};
const defaultCamera = { ...cameraState };
function updateCamera() {
cameraState.theta += cameraState.thetaVelocity;
cameraState.phi += cameraState.phiVelocity;
cameraState.thetaVelocity *= 0.9;
cameraState.phiVelocity *= 0.9;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi,
0.58,
1.25
);
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius,
11,
23
);
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y +
cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.0045,
0.58,
1.25
);
cameraState.thetaVelocity = -dx * 0.0012;
cameraState.phiVelocity = -dy * 0.0008;
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius *= Math.exp(event.deltaY * 0.001);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraState.theta = defaultCamera.theta;
cameraState.phi = defaultCamera.phi;
cameraState.radius = defaultCamera.radius;
cameraState.thetaVelocity = 0;
cameraState.phiVelocity = 0;
});
// ---------------------------------------------------------------------------
// Playback controls
// ---------------------------------------------------------------------------
let timelineTime = 0;
let playing = true;
const pauseButton = document.getElementById("pause");
const replayButton = document.getElementById("replay");
const status = document.getElementById("status");
const timeLabel = document.getElementById("time");
const progressFill = document.getElementById("progress-fill");
const stepElements = [...document.querySelectorAll(".step")];
pauseButton.addEventListener("click", () => {
playing = !playing;
pauseButton.textContent = playing ? "Pause" : "Resume";
});
replayButton.addEventListener("click", () => {
timelineTime = 0;
playing = true;
pauseButton.textContent = "Pause";
animatedRoots.forEach((object) => {
object.visible = false;
});
});
function updateUI() {
progressFill.style.width = `${(timelineTime / timelineDuration) * 100}%`;
timeLabel.textContent = `${timelineTime.toFixed(1)} / ${timelineDuration.toFixed(1)} s`;
if (timelineTime >= timelineDuration - 0.05) {
status.textContent = "Three servings ready · shells separated";
stepElements.forEach((element) => {
element.classList.remove("active");
element.classList.add("done");
});
return;
}
const servingIndex = Math.min(2, Math.floor(timelineTime / cycleLength));
const local = timelineTime - servingIndex * cycleLength;
let message;
let activeStep;
if (local < 0.95) {
message = `0${servingIndex + 1} · Toast lands on the plate`;
activeStep = 0;
} else if (local < 2.35) {
message = `0${servingIndex + 1} · Egg opens · shells route right`;
activeStep = 1;
} else {
message = `0${servingIndex + 1} · Fruit joins the serving`;
activeStep = 2;
}
status.textContent = message;
stepElements.forEach((element, index) => {
element.classList.toggle("active", index === activeStep);
element.classList.toggle(
"done",
index < activeStep ||
(servingIndex > 2 && index === activeStep)
);
});
}
// ---------------------------------------------------------------------------
// Render loop
// ---------------------------------------------------------------------------
let previousTime = performance.now();
function animate(now) {
const delta = Math.min(0.05, (now - previousTime) / 1000);
previousTime = now;
if (playing) {
timelineTime = Math.min(
timelineDuration,
timelineTime + delta
);
}
for (const action of actions) {
if (timelineTime < action.start) continue;
const progress = clamp01(
(timelineTime - action.start) / action.duration
);
action.update(progress);
}
updateCamera();
updateUI();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
</script>
</body>
</html>
```