Prompt specification
Build or customize the Three.js 3D scene "Soup preparation mise en place" 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: Soup preparation mise en place
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/soup-preparation-mise-en-place-x0127
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this stylized scene: Arrange chopped onion, carrots, beans, pot, and compost bowl on a kitchen counter; ingredients move into separate destinations according to edible and discarded portions.
Working Three.js Starter (soup-preparation-mise-en-place-x0127):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Kitchen Portion Sorter</title>
<style>
:root {
--ink: #213b35;
--muted: #60766f;
--cream: #fffaf0;
--green: #287b68;
--green-dark: #1d5f50;
--orange: #e8793f;
--brown: #8c6548;
--shadow: 0 18px 50px rgba(36, 58, 51, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce7df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
.intro {
position: fixed;
top: 26px;
left: 28px;
z-index: 5;
max-width: min(410px, calc(100vw - 56px));
pointer-events: none;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 7px 11px;
border: 1px solid rgba(33, 59, 53, 0.13);
border-radius: 999px;
background: rgba(255, 250, 240, 0.78);
backdrop-filter: blur(12px);
color: var(--green-dark);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.eyebrow::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 0 4px rgba(232, 121, 63, 0.13);
content: "";
}
h1 {
margin: 13px 0 7px;
font-size: clamp(29px, 4.5vw, 48px);
line-height: 0.98;
letter-spacing: -0.045em;
}
.intro p {
max-width: 390px;
margin: 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.control-card {
position: fixed;
right: 24px;
bottom: 24px;
z-index: 6;
width: min(355px, calc(100vw - 48px));
padding: 17px;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 21px;
background: rgba(255, 250, 240, 0.88);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-bottom: 14px;
}
.legend-item {
display: flex;
align-items: center;
gap: 9px;
min-width: 0;
padding: 9px 10px;
border-radius: 12px;
background: rgba(33, 59, 53, 0.055);
color: var(--ink);
font-size: 11px;
font-weight: 750;
}
.swatch {
flex: 0 0 auto;
width: 11px;
height: 11px;
border-radius: 50%;
}
.swatch.edible {
background: var(--green);
}
.swatch.scrap {
background: var(--brown);
}
.legend-item span:last-child {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.progress-track {
height: 7px;
overflow: hidden;
margin: 0 0 14px;
border-radius: 999px;
background: rgba(33, 59, 53, 0.1);
}
#progress {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--green), #54aa83, var(--orange));
transition: width 0.1s linear;
}
#status {
min-height: 38px;
margin: 0 0 12px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.actions {
display: flex;
gap: 9px;
}
button {
min-height: 45px;
border: 0;
border-radius: 13px;
font: inherit;
font-size: 13px;
font-weight: 800;
cursor: pointer;
transition: transform 0.18s ease, opacity 0.18s ease, background 0.18s ease;
}
button:hover:not(:disabled) {
transform: translateY(-2px);
}
button:active:not(:disabled) {
transform: translateY(0);
}
button:focus-visible {
outline: 3px solid rgba(232, 121, 63, 0.32);
outline-offset: 3px;
}
button:disabled {
cursor: default;
opacity: 0.48;
}
#sort {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
gap: 9px;
padding: 0 16px;
background: var(--green);
color: white;
box-shadow: 0 8px 18px rgba(40, 123, 104, 0.23);
}
#sort:hover:not(:disabled) {
background: var(--green-dark);
}
#sort svg {
width: 17px;
height: 17px;
}
#reset {
width: 45px;
padding: 0;
border: 1px solid rgba(33, 59, 53, 0.12);
background: rgba(255, 255, 255, 0.65);
color: var(--ink);
}
.hint {
margin-top: 11px;
color: #71847e;
font-size: 10px;
text-align: center;
letter-spacing: 0.02em;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #dce7df;
color: var(--green-dark);
font-size: 13px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 0.45s ease, visibility 0.45s ease;
}
#loading.hidden {
visibility: hidden;
opacity: 0;
}
@media (max-width: 680px) {
.intro {
top: 18px;
left: 18px;
}
.intro p {
display: none;
}
h1 {
max-width: 260px;
}
.control-card {
right: 14px;
bottom: 14px;
width: calc(100vw - 28px);
}
.legend {
margin-bottom: 10px;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<header class="intro">
<div class="eyebrow">Kitchen sorting study</div>
<h1>Good food.<br>Clear scraps.</h1>
<p>
Watch chopped onion, carrots, and beans separate into edible portions for the
cooking pot and discarded pieces for compost.
</p>
</header>
<section class="control-card" aria-label="Sorting controls">
<div class="legend">
<div class="legend-item">
<span class="swatch edible"></span>
<span>Edible → Pot</span>
</div>
<div class="legend-item">
<span class="swatch scrap"></span>
<span>Scraps → Compost</span>
</div>
</div>
<div class="progress-track" aria-hidden="true">
<div id="progress"></div>
</div>
<p id="status" aria-live="polite">
Press sort to send food-safe portions to the pot and peelings, tops, and ends to compost.
</p>
<div class="actions">
<button id="sort" type="button">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M4 7h12M13 4l3 3-3 3M20 17H8M11 14l-3 3 3 3"
stroke="currentColor" stroke-width="2" stroke-linecap="round"
stroke-linejoin="round"/>
</svg>
<span>Sort portions</span>
</button>
<button id="reset" type="button" aria-label="Reset the scene" title="Reset scene">
<svg viewBox="0 0 24 24" width="19" height="19" fill="none" aria-hidden="true">
<path d="M4 4v6h6M5.5 15.5a8 8 0 1 0 .6-8.7L4 10"
stroke="currentColor" stroke-width="2" stroke-linecap="round"
stroke-linejoin="round"/>
</svg>
</button>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Space to sort</div>
</section>
<div id="loading">Preparing the kitchen…</div>
<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 sortButton = document.querySelector("#sort");
const sortButtonText = sortButton.querySelector("span");
const resetButton = document.querySelector("#reset");
const progressBar = document.querySelector("#progress");
const status = document.querySelector("#status");
const loading = document.querySelector("#loading");
// ---------------------------------------------------------------------
// Renderer, scene, camera, and lights
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce7df);
scene.fog = new THREE.Fog(0xdce7df, 18, 34);
const renderer = new THREE.WebGLRenderer({ antialias: true });
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.08;
stage.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
60
);
const cameraTarget = new THREE.Vector3(0, 0.7, 0);
let cameraYaw = 0.72;
let cameraPitch = 1.02;
let cameraRadius = 13.3;
let desiredYaw = cameraYaw;
let desiredPitch = cameraPitch;
let desiredRadius = cameraRadius;
function updateCamera() {
const horizontal = Math.sin(cameraPitch) * cameraRadius;
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * horizontal,
cameraTarget.y + Math.cos(cameraPitch) * cameraRadius,
cameraTarget.z + Math.cos(cameraYaw) * horizontal
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xfff7e8, 0x6e8b7c, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff3d5, 4.1);
sun.position.set(-5, 10, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 28;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9dce1, 1.3);
fill.position.set(8, 5, -5);
scene.add(fill);
// ---------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------
let seed = 24831;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0,
...options
});
}
function shadow(mesh, cast = true, receive = true) {
mesh.castShadow = cast;
mesh.receiveShadow = receive;
return mesh;
}
function box(width, height, depth, mat, x, y, z) {
const mesh = shadow(new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
));
mesh.position.set(x, y, z);
scene.add(mesh);
return mesh;
}
function cylinder(radius, height, mat, x, y, z, segments = 24) {
const mesh = shadow(new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, segments),
mat
));
mesh.position.set(x, y, z);
scene.add(mesh);
return mesh;
}
function roundedRect(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 makeLabel(title, subtitle, accent, width = 1.75) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 176;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.shadowColor = "rgba(24, 45, 39, 0.18)";
ctx.shadowBlur = 18;
ctx.shadowOffsetY = 8;
roundedRect(ctx, 12, 12, 616, 142, 28);
ctx.fillStyle = "rgba(255, 250, 240, 0.96)";
ctx.fill();
ctx.shadowColor = "transparent";
ctx.strokeStyle = accent;
ctx.lineWidth = 6;
roundedRect(ctx, 12, 12, 616, 142, 28);
ctx.stroke();
ctx.fillStyle = accent;
roundedRect(ctx, 30, 34, 12, 96, 6);
ctx.fill();
ctx.textAlign = "left";
ctx.textBaseline = "middle";
ctx.fillStyle = "#213b35";
ctx.font = "800 38px system-ui, sans-serif";
ctx.fillText(title.toUpperCase(), 62, 68);
ctx.fillStyle = "#60766f";
ctx.font = "700 22px system-ui, sans-serif";
ctx.fillText(subtitle.toUpperCase(), 62, 113);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
}));
sprite.scale.set(width, width * 176 / 640, 1);
sprite.renderOrder = 20;
return sprite;
}
// ---------------------------------------------------------------------
// Stylized kitchen
// ---------------------------------------------------------------------
const wallMat = material(0xe7eee5);
const groutMat = material(0xd4dfd4);
const counterMat = material(0xe8d5b5, { roughness: 0.84 });
const counterEdgeMat = material(0xc7a985);
const cabinetMat = material(0x52796d);
const cabinetInsetMat = material(0x60887b);
const brassMat = material(0xc8994f, { roughness: 0.42, metalness: 0.45 });
// Back wall and tile lines.
box(12.8, 6.5, 0.22, wallMat, 0, 3.0, -3.12);
for (let x = -6; x <= 6; x += 1.2) {
box(0.022, 6.2, 0.025, groutMat, x, 3.05, -2.995);
}
for (let y = 0.25; y < 6.2; y += 1.05) {
box(12.5, 0.022, 0.025, groutMat, 0, y, -2.99);
}
// Counter top and cabinetry.
box(12.4, 0.32, 6.25, counterMat, 0, -0.16, 0);
box(12.48, 0.12, 6.32, counterEdgeMat, 0, -0.34, 0);
box(12.1, 2.7, 5.95, cabinetMat, 0, -1.7, -0.04);
for (let i = -2; i <= 2; i++) {
const x = i * 2.35;
box(2.18, 2.25, 0.09, cabinetInsetMat, x, -1.58, 2.94);
box(0.52, 0.075, 0.11, brassMat, x, -0.62, 3.02);
}
// Simple shelf and kitchen jars.
const shelfMat = material(0xb77c4f);
box(3.5, 0.14, 0.6, shelfMat, -3.8, 3.55, -2.66);
const jarGlass = material(0xd7e8df, {
transparent: true,
opacity: 0.72,
roughness: 0.28
});
const jarLid = material(0xe7b86c);
const jarFill = material(0xd59545);
[
[-4.75, 0.52, 0.42],
[-3.8, 0.67, 0.55],
[-2.82, 0.48, 0.38]
].forEach(([x, radius, height], index) => {
cylinder(radius, height, jarGlass, x, 3.65 + height / 2, -2.64, 18);
cylinder(radius + 0.04, 0.09, jarLid, x, 3.66 + height, -2.64, 18);
cylinder(radius * 0.78, height * 0.58, jarFill, x, 3.62 + height * 0.29, -2.64, 18);
});
// Large preparation board.
const boardMat = material(0xc98d5b);
const boardInsetMat = material(0xdfa871);
box(5.8, 0.12, 2.35, boardMat, -1.65, 0.07, 0.72);
box(5.48, 0.025, 2.08, boardInsetMat, -1.65, 0.142, 0.72);
// Small dishes beneath each ingredient pile.
const dishMat = material(0xf3ead7, { roughness: 0.6 });
const dishInnerMat = material(0xe6ddca, { roughness: 0.7 });
[
[-3.7, 0.56],
[-1.65, 0.56],
[0.02, 0.56]
].forEach(([x, z]) => {
box(1.42, 0.07, 1.13, dishMat, x, 0.19, z);
box(1.25, 0.035, 0.97, dishInnerMat, x, 0.235, z);
});
// ---------------------------------------------------------------------
// Destination vessels
// ---------------------------------------------------------------------
const potX = 2.45;
const potZ = -0.72;
const potBaseY = 0.03;
const potMat = material(0x267d77, { roughness: 0.38, metalness: 0.12 });
const potRimMat = material(0xf2d9b6, { roughness: 0.45 });
const potInteriorMat = material(0x253d38, { roughness: 0.5 });
const potProfile = [
new THREE.Vector2(0.55, 0),
new THREE.Vector2(0.68, 0.05),
new THREE.Vector2(0.83, 0.38),
new THREE.Vector2(0.92, 0.88),
new THREE.Vector2(0.89, 1.03),
new THREE.Vector2(0.84, 1.08)
];
const potBody = shadow(new THREE.Mesh(
new THREE.LatheGeometry(potProfile, 48),
potMat
));
potBody.position.set(potX, potBaseY, potZ);
scene.add(potBody);
const potBottom = shadow(new THREE.Mesh(
new THREE.CylinderGeometry(0.57, 0.55, 0.08, 40),
potMat
));
potBottom.position.set(potX, potBaseY + 0.04, potZ);
scene.add(potBottom);
const potRim = shadow(new THREE.Mesh(
new THREE.TorusGeometry(0.865, 0.065, 10, 48),
potRimMat
));
potRim.rotation.x = Math.PI / 2;
potRim.position.set(potX, potBaseY + 1.08, potZ);
scene.add(potRim);
const soup = shadow(new THREE.Mesh(
new THREE.CylinderGeometry(0.77, 0.77, 0.06, 48),
potInteriorMat
));
soup.position.set(potX, potBaseY + 0.76, potZ);
scene.add(soup);
[-1, 1].forEach((side) => {
const handle = shadow(new THREE.Mesh(
new THREE.TorusGeometry(0.28, 0.055, 8, 24, Math.PI),
potRimMat
));
handle.rotation.y = Math.PI / 2;
handle.rotation.z = side > 0 ? -Math.PI / 2 : Math.PI / 2;
handle.position.set(potX + side * 0.95, potBaseY + 0.76, potZ);
scene.add(handle);
});
const compostX = 4.45;
const compostZ = 0.86;
const compostBaseY = 0.03;
const compostMat = material(0xa66e4c, { roughness: 0.76 });
const compostRimMat = material(0x744c38);
const soilMat = material(0x49362a);
const compostProfile = [
new THREE.Vector2(0.34, 0),
new THREE.Vector2(0.47, 0.06),
new THREE.Vector2(0.68, 0.38),
new THREE.Vector2(0.76, 0.68),
new THREE.Vector2(0.73, 0.77),
new THREE.Vector2(0.68, 0.8)
];
const compostBody = shadow(new THREE.Mesh(
new THREE.LatheGeometry(compostProfile, 40),
compostMat
));
compostBody.position.set(compostX, compostBaseY, compostZ);
scene.add(compostBody);
const compostBottom = shadow(new THREE.Mesh(
new THREE.CylinderGeometry(0.36, 0.34, 0.08, 32),
compostMat
));
compostBottom.position.set(compostX, compostBaseY + 0.04, compostZ);
scene.add(compostBottom);
const compostRim = shadow(new THREE.Mesh(
new THREE.TorusGeometry(0.715, 0.065, 10, 40),
compostRimMat
));
compostRim.rotation.x = Math.PI / 2;
compostRim.position.set(compostX, compostBaseY + 0.79, compostZ);
scene.add(compostRim);
const compostFill = shadow(new THREE.Mesh(
new THREE.CylinderGeometry(0.62, 0.62, 0.07, 36),
soilMat
));
compostFill.position.set(compostX, compostBaseY + 0.51, compostZ);
scene.add(compostFill);
for (let i = 0; i < 12; i++) {
const angle = random() * Math.PI * 2;
const radius = random() * 0.47;
const chip = shadow(new THREE.Mesh(
new THREE.DodecahedronGeometry(0.055 + random() * 0.035, 0),
material(i % 3 === 0 ? 0x73513a : 0x49362a)
));
chip.position.set(
compostX + Math.cos(angle) * radius,
compostBaseY + 0.58,
compostZ + Math.sin(angle) * radius
);
chip.rotation.set(random() * 3, random() * 3, random() * 3);
scene.add(chip);
}
// Pulsing destination rings.
const potHaloMat = new THREE.MeshBasicMaterial({
color: 0x52c99d,
transparent: true,
opacity: 0,
side: THREE.DoubleSide,
depthWrite: false
});
const potHalo = new THREE.Mesh(
new THREE.RingGeometry(0.95, 1.07, 64),
potHaloMat
);
potHalo.rotation.x = -Math.PI / 2;
potHalo.position.set(potX, 0.015, potZ);
scene.add(potHalo);
const compostHaloMat = new THREE.MeshBasicMaterial({
color: 0xe0a55c,
transparent: true,
opacity: 0,
side: THREE.DoubleSide,
depthWrite: false
});
const compostHalo = new THREE.Mesh(
new THREE.RingGeometry(0.8, 0.92, 64),
compostHaloMat
);
compostHalo.rotation.x = -Math.PI / 2;
compostHalo.position.set(compostX, 0.015, compostZ);
scene.add(compostHalo);
// ---------------------------------------------------------------------
// Ingredient geometry
// ---------------------------------------------------------------------
const onionMat = material(0xf8efcf);
const onionCenterMat = material(0xfff9e9);
const carrotMat = material(0xf17a2d);
const carrotEndMat = material(0xffa14a);
const beanMat = material(0x398a4b);
const beanLineMat = material(0x246837);
const leafMat = material(0x4e9c43);
const onionSkinMat = material(0xd9ad61);
function makeOnionPiece() {
const group = new THREE.Group();
const outer = shadow(new THREE.Mesh(
new THREE.CylinderGeometry(0.205, 0.19, 0.12, 12),
onionMat
));
group.add(outer);
const center = shadow(new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.12, 0.125, 12),
onionCenterMat
));
center.position.y = 0.006;
group.add(center);
const notch = shadow(new THREE.Mesh(
new THREE.BoxGeometry(0.018, 0.014, 0.19),
onionSkinMat
));
notch.position.set(0.05, 0.068, 0);
notch.rotation.y = 0.35;
group.add(notch);
return group;
}
function makeCarrotPiece() {
const group = new THREE.Group();
const body = shadow(new THREE.Mesh(
new THREE.CylinderGeometry(0.135, 0.165, 0.42, 8),
carrotMat
));
body.rotation.z = Math.PI / 2;
group.add(body);
const end = shadow(new THREE.Mesh(
new THREE.CylinderGeometry(0.135, 0.135, 0.018, 8),
carrotEndMat
));
end.rotation.z = Math.PI / 2;
end.position.x = 0.215;
group.add(end);
return group;
}
function makeBeanPiece() {
const group = new THREE.Group();
const pod = shadow(new THREE.Mesh(
new THREE.CapsuleGeometry(0.085, 0.52, 4, 8),
beanMat
));
pod.rotation.z = Math.PI / 2;
group.add(pod);
const seam = shadow(new THREE.Mesh(
new THREE.BoxGeometry(0.43, 0.015, 0.014),
beanLineMat
));
seam.position.y = 0.079;
group.add(seam);
return group;
}
function makeOnionSkin() {
const group = new THREE.Group();
for (let i = 0; i < 2; i++) {
const skin = shadow(new THREE.Mesh(
new THREE.TorusGeometry(0.13 - i * 0.025, 0.018, 5, 16, Math.PI * 1.55),
onionSkinMat
));
skin.rotation.x = Math.PI / 2;
skin.rotation.z = i * 0.8;
skin.position.y = 0.025 + i * 0.025;
group.add(skin);
}
return group;
}
function makeCarrotTop() {
const group = new THREE.Group();
for (let i = 0; i < 3; i++) {
const leaf = shadow(new THREE.Mesh(
new THREE.ConeGeometry(0.055, 0.43, 5),
leafMat
));
leaf.rotation.z = Math.PI / 2 + (i - 1) * 0.18;
leaf.rotation.x = (i - 1) * 0.3;
leaf.position.x = 0.19;
leaf.position.y = i * 0.015;
group.add(leaf);
}
return group;
}
function makeBeanEnd() {
const group = new THREE.Group();
const end = shadow(new THREE.Mesh(
new THREE.CapsuleGeometry(0.065, 0.13, 3, 7),
beanMat
));
end.rotation.z = Math.PI / 2;
group.add(end);
const pale = shadow(new THREE.Mesh(
new THREE.CylinderGeometry(0.058, 0.058, 0.02, 7),
material(0xbad279)
));
pale.rotation.z = Math.PI / 2;
pale.position.x = 0.085;
group.add(pale);
return group;
}
// ---------------------------------------------------------------------
// Build the piles
// ---------------------------------------------------------------------
const pieces = [];
const ingredientCenters = {
onion: -3.7,
carrot: -1.65,
beans: 0.02
};
function addPiece(type, edible, index, count, factory) {
const group = factory();
const centerX = ingredientCenters[type];
const x = centerX + ((index % 3) - 1) * 0.27 + (random() - 0.5) * 0.08;
const z = edible
? 0.43 + (Math.floor(index / 3) - 0.5) * 0.22 + (random() - 0.5) * 0.06
: 1.23 + (index % 2) * 0.17;
const y = edible ? 0.29 + random() * 0.04 : 0.23 + random() * 0.035;
group.position.set(x, y, z);
group.rotation.set(
(random() - 0.5) * 0.16,
random() * Math.PI * 2,
(random() - 0.5) * 0.16
);
scene.add(group);
const angle = random() * Math.PI * 2;
const radius = edible
? 0.12 + random() * 0.48
: 0.08 + random() * 0.4;
const destination = edible
? new THREE.Vector3(
potX + Math.cos(angle) * radius,
potBaseY + 0.83 + random() * 0.035,
potZ + Math.sin(angle) * radius
)
: new THREE.Vector3(
compostX + Math.cos(angle) * radius,
compostBaseY + 0.59 + random() * 0.035,
compostZ + Math.sin(angle) * radius
);
pieces.push({
group,
type,
edible,
start: group.position.clone(),
startRotation: group.rotation.clone(),
destination,
delay: 0,
duration: 1.12,
arrived: false
});
}
for (let i = 0; i < 6; i++) addPiece("onion", true, i, 6, makeOnionPiece);
for (let i = 0; i < 6; i++) addPiece("carrot", true, i, 6, makeCarrotPiece);
for (let i = 0; i < 5; i++) addPiece("beans", true, i, 5, makeBeanPiece);
for (let i = 0; i < 3; i++) addPiece("onion", false, i, 3, makeOnionSkin);
for (let i = 0; i < 3; i++) addPiece("carrot", false, i, 3, makeCarrotTop);
for (let i = 0; i < 3; i++) addPiece("beans", false, i, 3, makeBeanEnd);
// Scene labels.
const onionLabel = makeLabel("Onion", "chopped", "#d29a42", 1.48);
onionLabel.position.set(-3.7, 0.72, 1.65);
scene.add(onionLabel);
const carrotLabel = makeLabel("Carrot", "chopped", "#df6e2d", 1.48);
carrotLabel.position.set(-1.65, 0.72, 1.65);
scene.add(carrotLabel);
const beanLabel = makeLabel("Beans", "chopped", "#3d8850", 1.48);
beanLabel.position.set(0.02, 0.72, 1.65);
scene.add(beanLabel);
const potLabel = makeLabel("Cooking pot", "edible portions", "#267d77", 2.12);
potLabel.position.set(potX, 1.74, potZ);
scene.add(potLabel);
const compostLabel = makeLabel("Compost", "discarded scraps", "#9a6548", 2.12);
compostLabel.position.set(compostX, 1.39, compostZ);
scene.add(compostLabel);
// ---------------------------------------------------------------------
// Sorting state and animation
// ---------------------------------------------------------------------
let mode = "idle";
let sortStart = 0;
let totalSortTime = 1;
let potPulse = 0;
let compostPulse = 0;
const ediblePieces = pieces.filter(piece => piece.edible);
const scrapPieces = pieces.filter(piece => !piece.edible);
ediblePieces.forEach((piece, index) => {
piece.delay = index * 0.105;
});
scrapPieces.forEach((piece, index) => {
piece.delay = 1.65 + index * 0.105;
});
totalSortTime = Math.max(...pieces.map(piece => piece.delay + piece.duration));
function easeInOutCubic(t) {
return t < 0.5
? 4 * t * t * t
: 1 - Math.pow(-2 * t + 2, 3) / 2;
}
function startSorting() {
if (mode === "sorting") return;
mode = "sorting";
sortStart = performance.now();
sortButton.disabled = true;
resetButton.disabled = false;
sortButtonText.textContent = "Sorting…";
status.textContent = "Separating edible portions from peels, tops, and trimmed ends…";
progressBar.style.width = "0%";
pieces.forEach(piece => {
piece.arrived = false;
});
}
function resetScene() {
mode = "idle";
sortButton.disabled = false;
resetButton.disabled = true;
sortButtonText.textContent = "Sort portions";
status.textContent =
"Press sort to send food-safe portions to the pot and peelings, tops, and ends to compost.";
progressBar.style.width = "0%";
pieces.forEach(piece => {
piece.group.position.copy(piece.start);
piece.group.rotation.copy(piece.startRotation);
piece.arrived = false;
});
potPulse = 0;
compostPulse = 0;
}
function updatePieces(now) {
if (mode !== "sorting" && mode !== "done") return;
const elapsed = (now - sortStart) / 1000;
pieces.forEach(piece => {
const raw = THREE.MathUtils.clamp(
(elapsed - piece.delay) / piece.duration,
0,
1
);
if (raw <= 0) return;
const eased = easeInOutCubic(raw);
const arcHeight = piece.edible ? 2.15 : 1.75;
const side = piece.edible ? 0.16 : -0.14;
piece.group.position.x = THREE.MathUtils.lerp(
piece.start.x,
piece.destination.x,
eased
);
piece.group.position.z = THREE.MathUtils.lerp(
piece.start.z,
piece.destination.z,
eased
);
piece.group.position.y = THREE.MathUtils.lerp(
piece.start.y,
piece.destination.y,
eased
) + Math.sin(raw * Math.PI) * arcHeight;
piece.group.position.x += Math.sin(raw * Math.PI) * side;
piece.group.rotation.x =
piece.startRotation.x + raw * (piece.edible ? 4.8 : 5.7);
piece.group.rotation.y =
piece.startRotation.y + raw * (piece.edible ? 3.1 : 5.3);
piece.group.rotation.z =
piece.startRotation.z + raw * (piece.edible ? 2.7 : 4.6);
if (raw >= 0.995 && !piece.arrived) {
piece.arrived = true;
if (piece.edible) potPulse = 1;
else compostPulse = 1;
}
});
const percent = THREE.MathUtils.clamp(elapsed / totalSortTime, 0, 1) * 100;
progressBar.style.width = `${percent}%`;
if (mode === "sorting" && elapsed >= totalSortTime + 0.05) {
mode = "done";
sortButton.disabled = true;
sortButtonText.textContent = "Portions sorted";
status.textContent =
"Perfect separation: edible pieces are in the pot, while peels, tops, and ends are ready for compost.";
progressBar.style.width = "100%";
}
}
sortButton.addEventListener("click", startSorting);
resetButton.addEventListener("click", resetScene);
resetButton.disabled = true;
window.addEventListener("keydown", event => {
if (event.code === "Space" && event.target.tagName !== "BUTTON") {
event.preventDefault();
startSorting();
}
if (event.key.toLowerCase() === "r" && event.target.tagName !== "BUTTON") {
resetScene();
}
});
// ---------------------------------------------------------------------
// Custom orbit and zoom controls — no external control modules
// ---------------------------------------------------------------------
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 deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
desiredYaw -= deltaX * 0.006;
desiredPitch = THREE.MathUtils.clamp(
desiredPitch + deltaY * 0.005,
0.48,
1.34
);
});
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("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
desiredRadius = THREE.MathUtils.clamp(
desiredRadius + event.deltaY * 0.009,
8.2,
18
);
}, { passive: false });
// ---------------------------------------------------------------------
// Resize and render loop
// ---------------------------------------------------------------------
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
renderer.setAnimationLoop(now => {
cameraYaw = THREE.MathUtils.lerp(cameraYaw, desiredYaw, 0.09);
cameraPitch = THREE.MathUtils.lerp(cameraPitch, desiredPitch, 0.09);
cameraRadius = THREE.MathUtils.lerp(cameraRadius, desiredRadius, 0.09);
updateCamera();
updatePieces(now);
potPulse = Math.max(0, potPulse - 0.025);
compostPulse = Math.max(0, compostPulse - 0.025);
const potScale = 1 + (1 - potPulse) * 0.12;
const compostScale = 1 + (1 - compostPulse) * 0.12;
potHalo.scale.setScalar(potScale);
compostHalo.scale.setScalar(compostScale);
potHaloMat.opacity = potPulse * 0.72;
compostHaloMat.opacity = compostPulse * 0.72;
renderer.render(scene, camera);
});
loading.classList.add("hidden");
</script>
</body>
</html>
```