Prompt specification
Build or customize the Three.js 3D scene "Weekly meal preparation 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: Weekly meal preparation counter
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/weekly-meal-preparation-counter-x0143
Scene Description Prompt:
Make a stylized Three.js scene in a self-contained HTML file using cdnjs: weekly meal preparation counter. Arrange ingredients, containers, date markers, and refrigerator shelves; a short sequence portions meals into labeled boxes and keeps each meal's components consistently grouped.
Working Three.js Starter (weekly-meal-preparation-counter-x0143):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Weekly Meal Prep</title>
<style>
:root {
--ink: #243b3a;
--muted: #657775;
--paper: rgba(255, 255, 255, 0.86);
--line: rgba(36, 59, 58, 0.12);
--mint: #62ad91;
--orange: #e9875d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8eee8;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--line);
background: var(--paper);
box-shadow: 0 14px 38px rgba(35, 61, 56, 0.12);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#heading {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 18px 20px 16px;
border-radius: 20px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: var(--mint);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 35px);
line-height: 1;
letter-spacing: -0.045em;
}
.subtitle {
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
#controls {
top: 22px;
right: 22px;
display: flex;
gap: 8px;
padding: 8px;
border-radius: 15px;
}
button {
border: 0;
border-radius: 10px;
padding: 10px 13px;
background: #edf3ef;
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition:
transform 150ms ease,
background 150ms ease;
}
button:hover {
transform: translateY(-1px);
background: #dfece5;
}
button:active {
transform: translateY(0);
}
button.primary {
background: var(--ink);
color: white;
}
#timeline {
right: 22px;
bottom: 22px;
left: 22px;
max-width: 920px;
margin: 0 auto;
padding: 13px 15px 12px;
border-radius: 18px;
}
.timeline-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
margin-bottom: 10px;
}
#status {
display: flex;
align-items: center;
gap: 9px;
min-width: 0;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.status-dot {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 0 5px rgba(233, 135, 93, 0.13);
}
#hint {
flex: 0 0 auto;
color: var(--muted);
font-size: 11px;
}
.days {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: 7px;
}
.day {
position: relative;
overflow: hidden;
min-width: 0;
padding: 9px 10px 8px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.55);
transition:
border-color 180ms ease,
background 180ms ease,
transform 180ms ease;
}
.day::after {
position: absolute;
right: 0;
bottom: 0;
left: 0;
height: 3px;
background: var(--mint);
content: "";
opacity: 0;
transform: scaleX(0);
transform-origin: left;
transition: 180ms ease;
}
.day.active {
border-color: rgba(98, 173, 145, 0.65);
background: white;
transform: translateY(-2px);
}
.day.active::after {
opacity: 1;
transform: scaleX(1);
}
.day.done {
background: rgba(98, 173, 145, 0.12);
}
.day-name {
display: block;
font-size: 11px;
font-weight: 850;
}
.day-date {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.progress-track {
height: 3px;
overflow: hidden;
margin-top: 10px;
border-radius: 999px;
background: #dfe8e2;
}
#progress {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--mint), var(--orange));
}
@media (max-width: 700px) {
#heading {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.subtitle {
display: none;
}
#controls {
top: 104px;
right: 12px;
}
#timeline {
right: 12px;
bottom: 12px;
left: 12px;
}
#hint {
display: none;
}
.day {
padding: 8px 5px;
text-align: center;
}
.day-date {
font-size: 9px;
}
}
</style>
</head>
<body>
<main id="stage" aria-label="Animated weekly meal preparation scene"></main>
<section id="heading" class="panel">
<div class="eyebrow">Kitchen operations · Week 25</div>
<h1>Weekly meal prep</h1>
<p class="subtitle">
Five balanced lunches, portioned in a consistent grain–protein–greens–sauce
order and labeled for the week.
</p>
</section>
<nav id="controls" class="panel" aria-label="Scene controls">
<button id="pause" class="primary" type="button">Pause</button>
<button id="replay" type="button">Replay</button>
<button id="view" type="button">View</button>
</nav>
<section id="timeline" class="panel" aria-label="Meal preparation timeline">
<div class="timeline-head">
<div id="status">
<span class="status-dot"></span>
<span id="statusText">Preparing Monday</span>
</div>
<div id="hint">Drag to orbit · Scroll or pinch to zoom</div>
</div>
<div class="days">
<div class="day" data-day="0">
<span class="day-name">MON</span>
<span class="day-date">17 JUN</span>
</div>
<div class="day" data-day="1">
<span class="day-name">TUE</span>
<span class="day-date">18 JUN</span>
</div>
<div class="day" data-day="2">
<span class="day-name">WED</span>
<span class="day-date">19 JUN</span>
</div>
<div class="day" data-day="3">
<span class="day-name">THU</span>
<span class="day-date">20 JUN</span>
</div>
<div class="day" data-day="4">
<span class="day-name">FRI</span>
<span class="day-date">21 JUN</span>
</div>
</div>
<div class="progress-track"><div id="progress"></div></div>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const statusText = document.querySelector("#statusText");
const progressEl = document.querySelector("#progress");
const pauseButton = document.querySelector("#pause");
const replayButton = document.querySelector("#replay");
const viewButton = document.querySelector("#view");
const dayElements = [...document.querySelectorAll(".day")];
// ---------------------------------------------------------------------
// Renderer, scene and camera
// ---------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance",
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.domElement.setAttribute("aria-label", "Three-dimensional meal prep counter");
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#e8eee8");
scene.fog = new THREE.Fog("#e8eee8", 19, 38);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100,
);
const cameraTarget = new THREE.Vector3(0.25, 1.55, -0.1);
let cameraYaw = 0.47;
let cameraPitch = 0.43;
let cameraRadius = 15.8;
const cameraPresets = [
{
yaw: 0.47,
pitch: 0.43,
radius: 15.8,
target: new THREE.Vector3(0.25, 1.55, -0.1),
},
{
yaw: 0.2,
pitch: 0.66,
radius: 15.2,
target: new THREE.Vector3(0.1, 1.4, -0.25),
},
{
yaw: 0.78,
pitch: 0.32,
radius: 12.6,
target: new THREE.Vector3(3.65, 2.65, -1.15),
},
];
let presetIndex = 0;
function updateCamera() {
const horizontal = cameraRadius * Math.cos(cameraPitch);
camera.position.set(
cameraTarget.x + horizontal * Math.sin(cameraYaw),
cameraTarget.y + cameraRadius * Math.sin(cameraPitch),
cameraTarget.z + horizontal * Math.cos(cameraYaw),
);
camera.lookAt(cameraTarget);
}
updateCamera();
// ---------------------------------------------------------------------
// Direct camera controls: no external controls module is used.
// ---------------------------------------------------------------------
const pointers = new Map();
let dragging = false;
let previousX = 0;
let previousY = 0;
let previousPinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
});
if (pointers.size === 1) {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
previousPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
});
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (previousPinchDistance > 0 && distance > 0) {
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * (previousPinchDistance / distance),
8,
24,
);
updateCamera();
}
previousPinchDistance = distance;
} else if (dragging) {
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
cameraYaw -= dx * 0.005;
cameraPitch = THREE.MathUtils.clamp(
cameraPitch + dy * 0.004,
0.12,
1.02,
);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
dragging = pointers.size > 0;
previousPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.012,
8,
24,
);
updateCamera();
},
{ passive: false },
);
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
togglePause();
}
if (event.key === "ArrowLeft") cameraYaw += 0.08;
if (event.key === "ArrowRight") cameraYaw -= 0.08;
if (event.key === "ArrowUp") cameraPitch += 0.05;
if (event.key === "ArrowDown") cameraPitch -= 0.05;
cameraPitch = THREE.MathUtils.clamp(cameraPitch, 0.12, 1.02);
updateCamera();
});
viewButton.addEventListener("click", () => {
presetIndex = (presetIndex + 1) % cameraPresets.length;
const preset = cameraPresets[presetIndex];
cameraYaw = preset.yaw;
cameraPitch = preset.pitch;
cameraRadius = preset.radius;
cameraTarget.copy(preset.target);
updateCamera();
});
// ---------------------------------------------------------------------
// Lighting
// ---------------------------------------------------------------------
scene.add(new THREE.HemisphereLight("#f5fbff", "#b6a98d", 2.0));
const keyLight = new THREE.DirectionalLight("#fff3dc", 3.8);
keyLight.position.set(-6, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight("#b9e3e0", 1.5);
fillLight.position.set(8, 5, 2);
scene.add(fillLight);
// ---------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------
const SURFACE = 1.38;
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.72,
metalness: options.metalness ?? 0,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
emissive: options.emissive ?? "#000000",
emissiveIntensity: options.emissiveIntensity ?? 0,
side: options.side ?? THREE.FrontSide,
});
}
function addBox(
parent,
size,
position,
material,
options = {},
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material,
);
mesh.position.set(position[0], position[1], position[2]);
if (options.rotation) {
mesh.rotation.set(
options.rotation[0],
options.rotation[1],
options.rotation[2],
);
}
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
position,
material,
options = {},
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
options.segments ?? 24,
),
material,
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
parent.add(mesh);
return mesh;
}
function addSphere(
parent,
radius,
position,
material,
scale = [1, 1, 1],
) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(radius, 16, 10),
material,
);
mesh.position.set(position[0], position[1], position[2]);
mesh.scale.set(scale[0], scale[1], scale[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRectPath(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function textTexture(
title,
subtitle = "",
background = "#ffffff",
foreground = "#243b3a",
width = 512,
height = 192,
) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, width, height);
if (background !== "transparent") {
roundedRectPath(
ctx,
7,
7,
width - 14,
height - 14,
Math.max(12, height * 0.15),
);
ctx.fillStyle = background;
ctx.fill();
ctx.lineWidth = Math.max(2, height * 0.025);
ctx.strokeStyle = "rgba(36,59,58,0.12)";
ctx.stroke();
}
ctx.fillStyle = foreground;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
if (subtitle) {
ctx.font = `800 ${Math.round(height * 0.38)}px system-ui, sans-serif`;
ctx.fillText(title, width / 2, height * 0.39);
ctx.globalAlpha = 0.7;
ctx.font = `650 ${Math.round(height * 0.19)}px system-ui, sans-serif`;
ctx.fillText(subtitle, width / 2, height * 0.73);
ctx.globalAlpha = 1;
} else {
ctx.font = `800 ${Math.round(height * 0.49)}px system-ui, sans-serif`;
ctx.fillText(title, width / 2, height / 2);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy(),
);
return texture;
}
function addLabel(
parent,
title,
subtitle,
width,
height,
position,
options = {},
) {
const texture = textTexture(
title,
subtitle,
options.background ?? "#ffffff",
options.foreground ?? "#243b3a",
options.textureWidth ?? 512,
options.textureHeight ?? 192,
);
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
toneMapped: false,
depthWrite: false,
}),
);
mesh.position.set(position[0], position[1], position[2]);
parent.add(mesh);
return mesh;
}
function easeOutCubic(value) {
return 1 - Math.pow(1 - value, 3);
}
function easeInOutCubic(value) {
return value < 0.5
? 4 * value * value * value
: 1 - Math.pow(-2 * value + 2, 3) / 2;
}
// ---------------------------------------------------------------------
// Room and counter
// ---------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(42, 42),
standardMaterial("#d8dfd6", { roughness: 0.95 }),
);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
scene.add(floor);
addBox(
scene,
[19, 8, 0.22],
[0, 4, -4.35],
standardMaterial("#edf0e7"),
);
const counterBase = standardMaterial("#416d67");
const counterTop = standardMaterial("#d9b27e", { roughness: 0.82 });
const counterEdge = standardMaterial("#efd3a8");
const cabinet = standardMaterial("#527d76");
addBox(scene, [11.6, 1.14, 4.05], [0, 0.6, 0.25], counterBase);
addBox(scene, [11.8, 0.18, 4.4], [0, 1.29, 0.25], counterTop);
addBox(scene, [11.86, 0.1, 4.46], [0, 1.17, 0.25], counterEdge);
[-3.8, 0, 3.8].forEach((x, index) => {
addBox(
scene,
[3.45, 0.83, 0.08],
[x, 0.58, 2.31],
cabinet,
);
addBox(
scene,
[0.72, 0.07, 0.09],
[x, 0.82, 2.39],
standardMaterial("#d7c8a6", { metalness: 0.35 }),
);
if (index === 1) {
addLabel(
scene,
"PREP STATION",
"MON — FRI",
2.2,
0.54,
[x, 0.48, 2.365],
{
background: "transparent",
foreground: "#eef6f1",
textureHeight: 160,
},
);
}
});
addLabel(
scene,
"WEEKLY PREP",
"5 balanced meals · ready to chill",
4.3,
1.18,
[-1.25, 3.95, -4.225],
{
background: "#f9fbf6",
foreground: "#31534d",
},
);
// ---------------------------------------------------------------------
// Open refrigerator and shelves
// ---------------------------------------------------------------------
const fridge = new THREE.Group();
fridge.position.set(4.45, 0, -1.8);
scene.add(fridge);
const fridgeShell = standardMaterial("#f2f5ee");
const fridgeInside = standardMaterial("#d9ecea");
const fridgeTrim = standardMaterial("#88aaa4", { metalness: 0.15 });
addBox(fridge, [3.15, 5.25, 0.18], [0, 2.62, -1.28], fridgeInside);
addBox(fridge, [0.18, 5.25, 2.55], [-1.52, 2.62, 0], fridgeShell);
addBox(fridge, [0.18, 5.25, 2.55], [1.52, 2.62, 0], fridgeShell);
addBox(fridge, [3.2, 0.2, 2.65], [0, 5.3, 0], fridgeShell);
addBox(fridge, [3.2, 0.18, 2.65], [0, 0.08, 0], fridgeShell);
addBox(fridge, [0.09, 4.55, 0.12], [-1.38, 2.55, 1.26], fridgeTrim);
addBox(fridge, [0.09, 4.55, 0.12], [1.38, 2.55, 1.26], fridgeTrim);
addLabel(
fridge,
"CHILLED",
"READY FOR THE WEEK",
2.35,
0.48,
[0, 5.28, 1.34],
{
background: "#31534d",
foreground: "#eff8f3",
textureHeight: 150,
},
);
const shelfGlass = standardMaterial("#b9d8d4", {
transparent: true,
opacity: 0.55,
roughness: 0.25,
metalness: 0.05,
});
const shelfLevels = [1.92, 3.08, 4.23];
shelfLevels.forEach((level, shelfIndex) => {
addBox(
fridge,
[2.87, 0.07, 2.2],
[0, level, -0.02],
shelfGlass,
);
addBox(
fridge,
[2.92, 0.06, 0.08],
[0, level, 1.08],
fridgeTrim,
);
for (let itemIndex = 0; itemIndex < 3; itemIndex++) {
const x = -0.92 + itemIndex * 0.92;
const containerGroup = new THREE.Group();
containerGroup.position.set(x, level + 0.04, -0.15);
fridge.add(containerGroup);
const bodyMaterial = standardMaterial(
["#f2d39f", "#d9e8d6", "#f4c4b8"][(shelfIndex + itemIndex) % 3],
{ transparent: true, opacity: 0.88 },
);
addBox(
containerGroup,
[0.67, 0.36, 0.66],
[0, 0.18, 0],
bodyMaterial,
);
addBox(
containerGroup,
[0.7, 0.08, 0.69],
[0, 0.39, 0],
standardMaterial("#f9faf3"),
);
addBox(
containerGroup,
[0.42, 0.12, 0.38],
[-0.12, 0.48, 0],
standardMaterial("#62a96e"),
);
addBox(
containerGroup,
[0.15, 0.1, 0.36],
[0.19, 0.47, 0],
standardMaterial("#d77b5e"),
);
addLabel(
containerGroup,
["MON", "TUE", "WED", "THU", "FRI"][
(shelfIndex * 3 + itemIndex) % 5
],
"",
0.42,
0.16,
[0, 0.2, 0.337],
{
background: "#ffffff",
foreground: "#31534d",
textureWidth: 384,
textureHeight: 144,
},
);
}
});
const fridgeLight = new THREE.PointLight("#d6ffff", 22, 8, 2);
fridgeLight.position.set(0, 4.9, 0.8);
fridge.add(fridgeLight);
// ---------------------------------------------------------------------
// Ingredient bowls and prep tools
// ---------------------------------------------------------------------
const grainMaterial = standardMaterial("#edc774", { roughness: 0.88 });
const proteinMaterial = standardMaterial("#cf6f5c", { roughness: 0.7 });
const greensMaterial = standardMaterial("#5ca36c", { roughness: 0.78 });
const sauceMaterial = standardMaterial("#f0ae3f", { roughness: 0.55 });
const bowlMaterial = standardMaterial("#f8f3e8");
const steelMaterial = standardMaterial("#a9b8b3", {
metalness: 0.55,
roughness: 0.3,
});
function addIngredientBowl(x, z, label, type, color) {
const group = new THREE.Group();
group.position.set(x, SURFACE, z);
scene.add(group);
addCylinder(group, 0.35, 0.28, 0.23, [0, 0.12, 0], bowlMaterial);
addCylinder(
group,
0.3,
0.3,
0.025,
[0, 0.245, 0],
standardMaterial(color),
);
if (type === "grain") {
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
addSphere(
group,
0.065,
[Math.cos(angle) * 0.13, 0.28, Math.sin(angle) * 0.11],
grainMaterial,
[1.5, 0.5, 0.85],
);
}
} else if (type === "greens") {
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
const leaf = addSphere(
group,
0.12,
[Math.cos(angle) * 0.12, 0.29, Math.sin(angle) * 0.11],
greensMaterial,
[0.6, 0.25, 1.4],
);
leaf.rotation.y = -angle;
}
} else if (type === "protein") {
for (let i = 0; i < 3; i++) {
const strip = new THREE.Mesh(
new THREE.CapsuleGeometry(0.065, 0.24, 4, 8),
proteinMaterial,
);
strip.position.set((i - 1) * 0.09, 0.29, 0);
strip.rotation.x = Math.PI / 2;
strip.castShadow = true;
group.add(strip);
}
} else {
addCylinder(
group,
0.13,
0.13,
0.15,
[0, 0.31, 0],
sauceMaterial,
);
}
addBox(
group,
[0.58, 0.22, 0.05],
[0, 0.35, 0.33],
standardMaterial("#fffdf4"),
);
addLabel(
group,
label,
"",
0.51,
0.16,
[0, 0.35, 0.36],
{
background: "transparent",
foreground: "#31534d",
textureWidth: 384,
textureHeight: 144,
},
);
}
addIngredientBowl(-5.25, -1.08, "GRAIN", "grain", "#e7bd68");
addIngredientBowl(-4.25, -1.08, "GREENS", "greens", "#4c915d");
addIngredientBowl(-3.25, -1.08, "PROTEIN", "protein", "#c96554");
addIngredientBowl(-2.25, -1.08, "SAUCE", "sauce", "#eea637");
const utensilGroup = new THREE.Group();
utensilGroup.position.set(-5.55, SURFACE, 1.15);
scene.add(utensilGroup);
addCylinder(
utensilGroup,
0.22,
0.18,
0.42,
[0, 0.21, 0],
steelMaterial,
);
[-0.12, 0.02, 0.14].forEach((x, index) => {
const handle = addBox(
utensilGroup,
[0.055, 0.7, 0.055],
[x, 0.65, 0],
standardMaterial(index === 1 ? "#e58a64" : "#668f87"),
{ rotation: [0, 0, (index - 1) * 0.12] },
);
if (index !== 1) {
addBox(
utensilGroup,
[0.16, 0.14, 0.055],
[x, 1.0, 0],
steelMaterial,
);
}
});
// ---------------------------------------------------------------------
// Meal portions, source trays and destination boxes
// ---------------------------------------------------------------------
const days = [
{ short: "MON", date: "17 JUN" },
{ short: "TUE", date: "18 JUN" },
{ short: "WED", date: "19 JUN" },
{ short: "THU", date: "20 JUN" },
{ short: "FRI", date: "21 JUN" },
];
const sourcePositions = [
new THREE.Vector3(-4.85, SURFACE + 0.08, 0.13),
new THREE.Vector3(-3.55, SURFACE + 0.08, 0.13),
new THREE.Vector3(-2.25, SURFACE + 0.08, 0.13),
new THREE.Vector3(-4.22, SURFACE + 0.08, 1.18),
new THREE.Vector3(-2.88, SURFACE + 0.08, 1.18),
];
const boxPositions = [-0.6, 0.85, 2.3, 3.75, 5.2].map(
(x) => new THREE.Vector3(x, SURFACE + 0.03, 1.53),
);
const sourceOffsets = {
grain: new THREE.Vector3(-0.18, 0, -0.17),
protein: new THREE.Vector3(0.18, 0, 0.08),
greens: new THREE.Vector3(-0.17, 0, 0.18),
sauce: new THREE.Vector3(0.18, 0, -0.17),
};
// All five meals use the same fixed compartment positions.
const targetOffsets = {
grain: new THREE.Vector3(-0.29, 0.17, -0.23),
protein: new THREE.Vector3(0.29, 0.14, 0.22),
greens: new THREE.Vector3(-0.29, 0.15, 0.23),
sauce: new THREE.Vector3(0.29, 0.12, -0.23),
};
function makeTray(x, z, material) {
const tray = new THREE.Group();
tray.position.set(x, SURFACE + 0.01, z);
scene.add(tray);
addBox(
tray,
[0.95, 0.055, 0.95],
[0, 0.03, 0],
material,
);
addBox(
tray,
[0.95, 0.09, 0.045],
[0, 0.075, -0.455],
material,
);
addBox(
tray,
[0.95, 0.09, 0.045],
[0, 0.075, 0.455],
material,
);
addBox(
tray,
[0.045, 0.09, 0.91],
[-0.455, 0.075, 0],
material,
);
addBox(
tray,
[0.045, 0.09, 0.91],
[0.455, 0.075, 0],
material,
);
return tray;
}
function createGrainPortion() {
const group = new THREE.Group();
const positions = [
[0, 0, 0],
[-0.1, 0.015, -0.04],
[0.1, 0.01, -0.05],
[-0.08, 0.025, 0.08],
[0.09, 0.02, 0.07],
[0, 0.04, 0.12],
[-0.11, 0, 0.03],
];
positions.forEach((position) => {
addSphere(
group,
0.105,
position,
grainMaterial,
[1.05, 0.56, 0.84],
);
});
return group;
}
function createProteinPortion() {
const group = new THREE.Group();
for (let i = 0; i < 3; i++) {
const strip = new THREE.Mesh(
new THREE.CapsuleGeometry(0.065, 0.22, 4, 8),
proteinMaterial,
);
strip.position.set((i - 1) * 0.085, 0, 0);
strip.rotation.x = Math.PI / 2;
strip.rotation.z = (i - 1) * 0.09;
strip.castShadow = true;
group.add(strip);
}
return group;
}
function createGreensPortion() {
const group = new THREE.Group();
for (let i = 0; i < 5; i++) {
const angle = (i / 5) * Math.PI * 2;
const leaf = addSphere(
group,
0.115,
[Math.cos(angle) * 0.065, 0.01, Math.sin(angle) * 0.065],
greensMaterial,
[0.58, 0.24, 1.35],
);
leaf.rotation.y = -angle;
leaf.rotation.z = 0.14;
}
return group;
}
function createSaucePortion() {
const group = new THREE.Group();
addCylinder(
group,
0.115,
0.095,
0.13,
[0, 0, 0],
sauceMaterial,
);
addCylinder(
group,
0.12,
0.12,
0.025,
[0, 0.075, 0],
standardMaterial("#f6c55c"),
);
return group;
}
function createMealBox(index) {
const root = new THREE.Group();
root.position.copy(boxPositions[index]);
scene.add(root);
const wallMaterial = standardMaterial("#f7f3e8");
const dividerMaterial = standardMaterial("#b8c9bf");
addBox(root, [1.24, 0.08, 1.03], [0, 0.04, 0], wallMaterial);
addBox(root, [1.24, 0.34, 0.06], [0, 0.25, -0.485], wallMaterial);
addBox(root, [1.24, 0.25, 0.06], [0, 0.205, 0.485], wallMaterial);
addBox(root, [0.06, 0.34, 0.91], [-0.59, 0.25, 0], wallMaterial);
addBox(root, [0.06, 0.34, 0.91], [0.59, 0.25, 0], wallMaterial);
// Cross dividers make the four-part grouping explicit.
addBox(
root,
[0.035, 0.3, 0.92],
[0, 0.23, 0],
dividerMaterial,
);
addBox(
root,
[1.16, 0.3, 0.035],
[0, 0.23, 0],
dividerMaterial,
);
addLabel(
root,
`${days[index].short} · ${days[index].date.split(" ")[0]}`,
"",
0.88,
0.2,
[0, 0.2, 0.519],
{
background: "#ffffff",
foreground: "#31534d",
textureWidth: 512,
textureHeight: 128,
},
);
const lid = new THREE.Group();
root.add(lid);
addBox(
lid,
[1.27, 0.075, 1.06],
[0, 0, 0],
standardMaterial(index % 2 === 0 ? "#eef2df" : "#f2eee4"),
);
addBox(
lid,
[0.16, 0.085, 0.78],
[-0.46, 0.005, 0],
standardMaterial(index % 2 === 0 ? "#77ad83" : "#e79a72"),
);
// Date marker standing behind the box.
const marker = new THREE.Group();
marker.position.set(boxPositions[index].x, 0, 0.77);
scene.add(marker);
const markerMaterial = standardMaterial("#fffdf3", {
emissive: "#62ad91",
emissiveIntensity: 0,
});
addBox(
marker,
[1.12, 0.62, 0.08],
[0, 2.14, 0],
markerMaterial,
);
addBox(
marker,
[0.12, 0.3, 0.08],
[0, 1.76, 0],
standardMaterial("#79988e"),
);
addLabel(
marker,
days[index].short,
days[index].date,
0.99,
0.51,
[0, 2.14, 0.045],
{
background: "transparent",
foreground: "#31534d",
textureHeight: 220,
},
);
return { root, lid, marker, markerMaterial };
}
const meals = [];
days.forEach((day, index) => {
const trayMaterial = standardMaterial("#d9e4dc", {
emissive: "#62ad91",
emissiveIntensity: 0,
});
const tray = makeTray(
sourcePositions[index].x,
sourcePositions[index].z,
trayMaterial,
);
addLabel(
tray,
day.short,
"",
0.55,
0.16,
[0, 0.075, 0.482],
{
background: "transparent",
foreground: "#31534d",
textureWidth: 384,
textureHeight: 144,
},
);
const group = new THREE.Group();
group.position.copy(sourcePositions[index]);
scene.add(group);
const parts = {
grain: createGrainPortion(),
protein: createProteinPortion(),
greens: createGreensPortion(),
sauce: createSaucePortion(),
};
Object.entries(parts).forEach(([name, part]) => {
part.position.copy(sourceOffsets[name]);
group.add(part);
});
const destination = createMealBox(index);
meals.push({
index,
group,
parts,
tray,
trayMaterial,
source: sourcePositions[index].clone(),
destination: boxPositions[index].clone(),
lid: destination.lid,
marker: destination.marker,
markerMaterial: destination.markerMaterial,
});
});
// ---------------------------------------------------------------------
// Meal preparation animation
// ---------------------------------------------------------------------
const MEAL_DURATION = 2.35;
const TOTAL_MEAL_TIME = MEAL_DURATION * meals.length;
const CYCLE_DURATION = TOTAL_MEAL_TIME + 3.0;
let elapsed = 0;
let playing = true;
const clock = new THREE.Clock();
function resetMeal(meal) {
meal.group.position.copy(meal.source);
meal.group.rotation.set(0, 0, 0);
Object.entries(meal.parts).forEach(([name, part]) => {
part.position.copy(sourceOffsets[name]);
part.rotation.set(0, 0, 0);
});
meal.lid.visible = false;
meal.lid.position.set(0, 0.86, -0.58);
meal.lid.rotation.set(-0.08, 0, 0);
meal.marker.scale.setScalar(1);
meal.markerMaterial.emissiveIntensity = 0;
meal.trayMaterial.emissiveIntensity = 0;
}
function setPackedMeal(meal) {
meal.group.position.copy(meal.destination);
meal.group.rotation.set(0, 0, 0);
Object.entries(meal.parts).forEach(([name, part]) => {
part.position.copy(targetOffsets[name]);
part.rotation.set(0, 0, 0);
});
meal.lid.visible = true;
meal.lid.position.set(0, 0.465, 0);
meal.lid.rotation.set(0, 0, 0);
meal.marker.scale.setScalar(1.03);
meal.markerMaterial.emissiveIntensity = 0.1;
meal.trayMaterial.emissiveIntensity = 0;
}
function updateMeal(meal, localTime) {
if (localTime < 0) {
resetMeal(meal);
return;
}
if (localTime >= MEAL_DURATION) {
setPackedMeal(meal);
return;
}
const progress = THREE.MathUtils.clamp(
localTime / MEAL_DURATION,
0,
1,
);
meal.marker.scale.setScalar(1.055);
meal.markerMaterial.emissiveIntensity = 0.25;
meal.trayMaterial.emissiveIntensity = 0.22;
// First carry the grouped portion from its dated prep tray.
if (progress < 0.22) {
const moveProgress = easeInOutCubic(progress / 0.22);
meal.group.position.lerpVectors(
meal.source,
meal.destination,
moveProgress,
);
meal.group.position.y += Math.sin(moveProgress * Math.PI) * 0.58;
Object.entries(meal.parts).forEach(([name, part]) => {
part.position.copy(sourceOffsets[name]);
});
} else {
meal.group.position.copy(meal.destination);
// Then settle every component into its matching quadrant.
const portionProgress = easeOutCubic(
THREE.MathUtils.clamp((progress - 0.22) / 0.58, 0, 1),
);
Object.entries(meal.parts).forEach(([name, part]) => {
part.position.lerpVectors(
sourceOffsets[name],
targetOffsets[name],
portionProgress,
);
part.position.y += Math.sin(portionProgress * Math.PI) * 0.18;
});
}
// The lid drops into place only after the food is grouped.
if (progress < 0.43) {
meal.lid.visible = false;
} else {
meal.lid.visible = true;
const lidProgress = easeOutCubic(
THREE.MathUtils.clamp((progress - 0.43) / 0.36, 0, 1),
);
meal.lid.position.set(
0,
THREE.MathUtils.lerp(0.86, 0.465, lidProgress),
THREE.MathUtils.lerp(-0.58, 0, lidProgress),
);
meal.lid.rotation.x = THREE.MathUtils.lerp(
-0.08,
0,
lidProgress,
);
}
}
function updateTimeline(time) {
const activeMeal = Math.min(
meals.length - 1,
Math.floor(time / MEAL_DURATION),
);
const local = time - activeMeal * MEAL_DURATION;
const isPacking = time < TOTAL_MEAL_TIME && local >= 0;
dayElements.forEach((element, index) => {
const done =
time >= TOTAL_MEAL_TIME ||
(time >= (index + 1) * MEAL_DURATION);
element.classList.toggle(
"active",
isPacking && index === activeMeal,
);
element.classList.toggle("done", done);
});
if (time < TOTAL_MEAL_TIME) {
statusText.textContent =
`Portioning ${days[activeMeal].short} · ${days[activeMeal].date}`;
} else {
statusText.textContent = "Ready for the week";
}
progressEl.style.width = `${(time / CYCLE_DURATION) * 100}%`;
}
function togglePause() {
playing = !playing;
pauseButton.textContent = playing ? "Pause" : "Resume";
}
pauseButton.addEventListener("click", togglePause);
replayButton.addEventListener("click", () => {
elapsed = 0;
meals.forEach(resetMeal);
playing = true;
pauseButton.textContent = "Pause";
});
// ---------------------------------------------------------------------
// Resize and render loop
// ---------------------------------------------------------------------
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
if (window.innerWidth < 700) {
camera.fov = 47;
cameraRadius = Math.max(cameraRadius, 17.5);
} else {
camera.fov = 38;
}
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
updateCamera();
}
window.addEventListener("resize", resize);
resize();
meals.forEach(resetMeal);
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) {
elapsed = (elapsed + delta) % CYCLE_DURATION;
}
meals.forEach((meal, index) => {
const localTime = elapsed - index * MEAL_DURATION;
updateMeal(meal, localTime);
});
updateTimeline(elapsed);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```