Prompt specification
Build or customize the Three.js 3D scene "Meal ingredient task grouping" 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: Meal ingredient task grouping
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/meal-ingredient-task-grouping-x3905
Scene Description Prompt:
Group stylized vegetables, bread, and plates on task mats, distinguishing prepared ingredients from untouched ones. Three.js from cdnjs; one HTML file.
Working Three.js Starter (meal-ingredient-task-grouping-x3905):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Kitchen Prep Station</title>
<style>
:root {
--ink: #26332c;
--paper: #f5f0e8;
--mint: #91c6ac;
--amber: #efc36b;
--coral: #e79a84;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 30% 15%, #fffdf8 0%, #f5f0e8 48%, #e7dfd4 100%);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
canvas.dragging {
cursor: grabbing;
}
.ui {
position: fixed;
z-index: 10;
pointer-events: none;
}
.intro {
top: 26px;
left: 28px;
max-width: 360px;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
padding: 7px 11px;
border: 1px solid rgba(38, 51, 44, 0.14);
border-radius: 999px;
background: rgba(255, 255, 255, 0.68);
backdrop-filter: blur(12px);
color: #657168;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: #74a98e;
content: "";
box-shadow: 0 0 0 4px rgba(116, 169, 142, 0.15);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 4vw, 54px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.intro p {
max-width: 320px;
margin: 12px 0 0;
color: #6b756e;
font-size: 13px;
line-height: 1.55;
}
.legend {
top: 28px;
right: 28px;
width: 220px;
padding: 16px;
border: 1px solid rgba(38, 51, 44, 0.1);
border-radius: 18px;
background: rgba(255, 255, 255, 0.72);
box-shadow: 0 16px 45px rgba(73, 58, 39, 0.1);
backdrop-filter: blur(16px);
}
.legend-title {
margin-bottom: 12px;
color: #7b847e;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
padding: 7px 0;
font-size: 12px;
font-weight: 650;
}
.swatch {
width: 12px;
height: 12px;
flex: 0 0 auto;
border-radius: 4px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
}
.swatch.whole {
background: var(--mint);
}
.swatch.prepared {
background: var(--amber);
}
.swatch.plated {
background: var(--coral);
}
.legend-row span:last-child {
margin-left: auto;
color: #929990;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.controls {
bottom: 22px;
left: 50%;
display: flex;
align-items: center;
gap: 8px;
padding: 7px;
border: 1px solid rgba(38, 51, 44, 0.1);
border-radius: 999px;
background: rgba(255, 255, 255, 0.76);
box-shadow: 0 12px 34px rgba(73, 58, 39, 0.1);
backdrop-filter: blur(16px);
transform: translateX(-50%);
white-space: nowrap;
}
.key {
padding: 7px 10px;
border-radius: 999px;
background: #f0ece5;
color: #707a73;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
}
.reset {
pointer-events: auto;
padding: 8px 13px;
border: 0;
border-radius: 999px;
background: #33433a;
color: white;
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition: transform 160ms ease, background 160ms ease;
}
.reset:hover {
background: #26352d;
transform: translateY(-1px);
}
@media (max-width: 720px) {
.intro {
top: 18px;
left: 18px;
}
.intro p {
display: none;
}
.legend {
top: 18px;
right: 18px;
width: 172px;
padding: 12px;
}
.legend-row span:last-child {
display: none;
}
.controls {
bottom: 14px;
}
}
</style>
</head>
<body>
<div id="app"></div>
<section class="ui intro">
<div class="eyebrow">Kitchen task board</div>
<h1>Prep station</h1>
<p>
Whole ingredients, cut components, and finished plates are sorted across
three color-coded task mats.
</p>
</section>
<aside class="ui legend">
<div class="legend-title">Readiness key</div>
<div class="legend-row">
<i class="swatch whole"></i>
Untouched
<span>Whole</span>
</div>
<div class="legend-row">
<i class="swatch prepared"></i>
Prepared
<span>Cut</span>
</div>
<div class="legend-row">
<i class="swatch plated"></i>
Plated
<span>Served</span>
</div>
</aside>
<div class="ui controls">
<div class="key">Drag to orbit</div>
<div class="key">Scroll to zoom</div>
<button class="reset" id="reset">Reset view</button>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.getElementById("app");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf3eee6);
scene.fog = new THREE.Fog(0xf3eee6, 24, 43);
const camera = new THREE.PerspectiveCamera(
36,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance",
});
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;
app.appendChild(renderer.domElement);
// ---------- Materials ----------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0,
...options,
});
const M = {
tableEdge: material(0x855737, { roughness: 0.8 }),
floor: material(0xe7dfd4, { roughness: 1 }),
matWhole: material(0x91c6ac, { roughness: 0.95 }),
matPrepared: material(0xefc36b, { roughness: 0.95 }),
matPlated: material(0xe79a84, { roughness: 0.95 }),
matBorder: material(0x496052, { roughness: 0.9 }),
carrot: material(0xef7c25),
carrotLight: material(0xf79d42),
carrotLeaf: material(0x4e934a),
eggplant: material(0x56336f, { roughness: 0.5 }),
eggplantInside: material(0xf0dfc5),
pepperRed: material(0xd94c3d, { roughness: 0.42 }),
pepperGreen: material(0x5b973f, { roughness: 0.45 }),
pepperYellow: material(0xe9b83d, { roughness: 0.45 }),
tomato: material(0xe34a3c, { roughness: 0.43 }),
tomatoInside: material(0xf37865),
cucumber: material(0x3f8147, { roughness: 0.55 }),
cucumberInside: material(0xb9d47d),
lettuce: material(0x70ad51, {
roughness: 0.9,
side: THREE.DoubleSide,
}),
lettuceLight: material(0x93c96b, {
roughness: 0.9,
side: THREE.DoubleSide,
}),
bread: material(0xc78645, { roughness: 0.86 }),
breadCrust: material(0xa96835, { roughness: 0.88 }),
breadInside: material(0xf1d3a0, { roughness: 0.92 }),
breadScore: material(0xf4dcb2, { roughness: 0.9 }),
plate: material(0xfaf8f1, { roughness: 0.28 }),
plateShade: material(0xe8e4da, { roughness: 0.36 }),
seed: material(0xf2d99d, { roughness: 0.8 }),
};
// ---------- Procedural textures ----------
function createWoodTexture() {
const canvas = document.createElement("canvas");
canvas.width = canvas.height = 512;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#c98f5e";
ctx.fillRect(0, 0, 512, 512);
for (let i = 0; i < 105; i++) {
const y = Math.random() * 512;
const amplitude = 2 + Math.random() * 8;
ctx.beginPath();
ctx.moveTo(-10, y);
for (let x = 0; x <= 522; x += 12) {
const wave =
Math.sin(x * 0.024 + i * 0.4) * amplitude +
Math.sin(x * 0.059 + i) * amplitude * 0.25;
ctx.lineTo(x, y + wave);
}
ctx.strokeStyle = `rgba(89, 48, 25, ${0.025 + Math.random() * 0.055})`;
ctx.lineWidth = 0.6 + Math.random() * 1.4;
ctx.stroke();
}
for (let i = 0; i < 13; i++) {
const x = Math.random() * 512;
const y = Math.random() * 512;
const rx = 8 + Math.random() * 28;
const ry = 2 + Math.random() * 7;
ctx.strokeStyle = "rgba(89, 48, 25, 0.12)";
ctx.lineWidth = 1.5;
ctx.beginPath();
ctx.ellipse(x, y, rx, ry, Math.random() * 0.4, 0, Math.PI * 2);
ctx.stroke();
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(0.08, 0.08);
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function createLabelTexture(number, title, accent) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 220;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "rgba(255,255,255,0.72)";
ctx.beginPath();
ctx.roundRect(10, 20, 1004, 180, 70);
ctx.fill();
ctx.fillStyle = accent;
ctx.beginPath();
ctx.roundRect(42, 58, 112, 104, 40);
ctx.fill();
ctx.fillStyle = "#ffffff";
ctx.font = "800 54px Arial";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(number, 98, 112);
ctx.fillStyle = "#304039";
ctx.textAlign = "left";
ctx.font = "800 55px Arial";
ctx.fillText(title.toUpperCase(), 194, 111);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
M.table = material(0xffffff, {
map: createWoodTexture(),
roughness: 0.78,
});
// ---------- Geometry helpers ----------
function roundedRectShape(width, depth, radius) {
const x = -width / 2;
const y = -depth / 2;
const r = Math.min(radius, width / 2, depth / 2);
const shape = new THREE.Shape();
shape.moveTo(x + r, y);
shape.lineTo(x + width - r, y);
shape.quadraticCurveTo(x + width, y, x + width, y + r);
shape.lineTo(x + width, y + depth - r);
shape.quadraticCurveTo(
x + width,
y + depth,
x + width - r,
y + depth
);
shape.lineTo(x + r, y + depth);
shape.quadraticCurveTo(x, y + depth, x, y + depth - r);
shape.lineTo(x, y + r);
shape.quadraticCurveTo(x, y, x + r, y);
return shape;
}
function roundedSlab(width, depth, height, radius, mat) {
const geometry = new THREE.ExtrudeGeometry(
roundedRectShape(width, depth, radius),
{
depth: height,
bevelEnabled: true,
bevelSegments: 3,
bevelSize: Math.min(0.055, height * 0.22),
bevelThickness: Math.min(0.035, height * 0.18),
curveSegments: 10,
steps: 1,
}
);
geometry.rotateX(-Math.PI / 2);
const mesh = new THREE.Mesh(geometry, mat);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function mesh(geometry, mat, cast = true, receive = true) {
const object = new THREE.Mesh(geometry, mat);
object.castShadow = cast;
object.receiveShadow = receive;
return object;
}
function createLeaf(mat = M.lettuce, scale = 1) {
const shape = new THREE.Shape();
shape.moveTo(0, -0.43);
shape.bezierCurveTo(-0.29, -0.24, -0.32, 0.17, 0, 0.43);
shape.bezierCurveTo(0.32, 0.17, 0.29, -0.24, 0, -0.43);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.035,
bevelEnabled: true,
bevelSize: 0.015,
bevelThickness: 0.012,
bevelSegments: 2,
curveSegments: 8,
});
geometry.center();
geometry.rotateX(-Math.PI / 2);
const leaf = mesh(geometry, mat);
leaf.scale.setScalar(scale);
return leaf;
}
// ---------- Table, floor, and task mats ----------
const floor = mesh(
new THREE.PlaneGeometry(80, 80),
M.floor,
false,
true
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -3.18;
scene.add(floor);
const table = roundedSlab(15.7, 8.25, 0.52, 0.42, M.table);
table.position.y = -0.58;
scene.add(table);
const tableTrim = roundedSlab(15.85, 8.4, 0.2, 0.45, M.tableEdge);
tableTrim.position.y = -0.7;
scene.add(tableTrim);
const legGeometry = new THREE.CylinderGeometry(0.18, 0.25, 2.55, 14);
for (const x of [-6.7, 6.7]) {
for (const z of [-3.05, 3.05]) {
const leg = mesh(legGeometry, M.tableEdge);
leg.position.set(x, -1.89, z);
scene.add(leg);
}
}
const matData = [
{ x: -5.1, color: M.matWhole, number: "01", title: "Untouched", accent: "#78aa91" },
{ x: 0, color: M.matPrepared, number: "02", title: "Prepared", accent: "#d49a36" },
{ x: 5.1, color: M.matPlated, number: "03", title: "Plated", accent: "#d26f5c" },
];
for (const data of matData) {
const border = roundedSlab(4.52, 5.83, 0.065, 0.22, M.matBorder);
border.position.set(data.x, 0.005, 0);
scene.add(border);
const taskMat = roundedSlab(4.38, 5.69, 0.07, 0.19, data.color);
taskMat.position.set(data.x, 0.052, 0);
scene.add(taskMat);
const label = new THREE.Mesh(
new THREE.PlaneGeometry(3.72, 0.72),
new THREE.MeshBasicMaterial({
map: createLabelTexture(data.number, data.title, data.accent),
transparent: true,
depthWrite: false,
toneMapped: false,
})
);
label.rotation.x = -Math.PI / 2;
label.position.set(data.x, 0.145, -2.13);
scene.add(label);
}
// ---------- Whole ingredients ----------
function createCarrot() {
const group = new THREE.Group();
const body = mesh(
new THREE.ConeGeometry(0.19, 0.92, 20),
M.carrot
);
body.rotation.z = -Math.PI / 2;
body.position.x = 0.08;
group.add(body);
for (let i = 0; i < 5; i++) {
const leaf = createLeaf(M.carrotLeaf, 0.38);
leaf.position.set(-0.48 + Math.random() * 0.06, 0.02 + i * 0.014, 0);
leaf.rotation.y = (i / 5) * Math.PI * 2;
leaf.rotation.z = -0.2;
group.add(leaf);
}
return group;
}
function createEggplant() {
const group = new THREE.Group();
const body = mesh(new THREE.SphereGeometry(0.52, 32, 20), M.eggplant);
body.scale.set(0.9, 0.88, 1.48);
body.position.y = 0.47;
group.add(body);
const cap = mesh(new THREE.SphereGeometry(0.22, 16, 10), M.pepperGreen);
cap.scale.set(1, 0.55, 0.8);
cap.position.set(0, 0.67, -0.66);
group.add(cap);
const stem = mesh(
new THREE.CylinderGeometry(0.07, 0.1, 0.28, 10),
M.pepperGreen
);
stem.rotation.x = Math.PI / 2;
stem.position.set(0, 0.72, -0.81);
group.add(stem);
for (let i = 0; i < 4; i++) {
const leaf = createLeaf(M.pepperGreen, 0.31);
leaf.position.set(0, 0.69, -0.7);
leaf.rotation.y = (i / 4) * Math.PI * 2 + 0.25;
group.add(leaf);
}
return group;
}
function createPepper() {
const group = new THREE.Group();
const lobePositions = [
[-0.22, 0.42, 0.03],
[0.22, 0.42, 0.03],
[0, 0.43, -0.22],
];
for (const [x, y, z] of lobePositions) {
const lobe = mesh(new THREE.SphereGeometry(0.38, 24, 18), M.pepperRed);
lobe.scale.set(0.9, 1.05, 0.82);
lobe.position.set(x, y, z);
group.add(lobe);
}
const stem = mesh(
new THREE.CylinderGeometry(0.07, 0.09, 0.3, 10),
M.pepperGreen
);
stem.position.y = 0.95;
group.add(stem);
const cap = mesh(new THREE.SphereGeometry(0.19, 16, 10), M.pepperGreen);
cap.scale.set(1.15, 0.42, 1);
cap.position.y = 0.8;
group.add(cap);
return group;
}
function createTomato() {
const group = new THREE.Group();
const body = mesh(new THREE.SphereGeometry(0.39, 28, 20), M.tomato);
body.scale.y = 0.86;
body.position.y = 0.37;
group.add(body);
for (let i = 0; i < 5; i++) {
const leaf = createLeaf(M.pepperGreen, 0.24);
leaf.position.y = 0.68;
leaf.rotation.y = (i / 5) * Math.PI * 2;
group.add(leaf);
}
return group;
}
function createZucchini() {
const group = new THREE.Group();
const body = mesh(
new THREE.CylinderGeometry(0.27, 0.31, 1.28, 24),
M.cucumber
);
body.rotation.x = Math.PI / 2;
body.position.y = 0.3;
group.add(body);
for (let i = 0; i < 6; i++) {
const stripe = mesh(
new THREE.TorusGeometry(0.282, 0.018, 8, 28),
M.cucumberInside
);
stripe.position.set(0, 0.3, -0.5 + i * 0.2);
group.add(stripe);
}
const stem = mesh(
new THREE.CylinderGeometry(0.1, 0.12, 0.18, 10),
M.pepperGreen
);
stem.rotation.x = Math.PI / 2;
stem.position.set(0, 0.3, -0.7);
group.add(stem);
return group;
}
function createLoaf() {
const group = new THREE.Group();
const body = mesh(new THREE.SphereGeometry(1, 36, 22), M.bread);
body.scale.set(1.05, 0.43, 0.53);
body.position.y = 0.36;
group.add(body);
for (let i = 0; i < 4; i++) {
const score = mesh(
new THREE.BoxGeometry(0.48, 0.035, 0.075),
M.breadScore
);
score.position.set(-0.58 + i * 0.39, 0.74, 0);
score.rotation.y = -0.5;
group.add(score);
}
return group;
}
const carrot = createCarrot();
carrot.position.set(-4.28, 0.13, 0.58);
carrot.rotation.y = -0.28;
scene.add(carrot);
const eggplant = createEggplant();
eggplant.position.set(-5.57, 0.1, -0.08);
eggplant.rotation.y = 0.28;
scene.add(eggplant);
const pepper = createPepper();
pepper.position.set(-5.72, 0.1, 1.63);
pepper.rotation.y = -0.2;
scene.add(pepper);
const tomato = createTomato();
tomato.position.set(-4.64, 0.1, 1.79);
scene.add(tomato);
const zucchini = createZucchini();
zucchini.position.set(-6.62, 0.1, 1.08);
zucchini.rotation.y = 0.38;
scene.add(zucchini);
const loaf = createLoaf();
loaf.position.set(-3.78, 0.1, -1.38);
loaf.rotation.y = -0.16;
scene.add(loaf);
// ---------- Prepared ingredients ----------
function createCoin(outerMat, innerMat, radius = 0.27) {
const group = new THREE.Group();
const outer = mesh(
new THREE.CylinderGeometry(radius, radius, 0.1, 28),
outerMat
);
outer.position.y = 0.05;
group.add(outer);
const inner = mesh(
new THREE.CylinderGeometry(radius * 0.78, radius * 0.78, 0.105, 28),
innerMat
);
inner.position.y = 0.055;
group.add(inner);
return group;
}
function createBreadSlice() {
const group = new THREE.Group();
const crust = roundedSlab(1.02, 0.84, 0.13, 0.16, M.breadCrust);
group.add(crust);
const inside = roundedSlab(0.86, 0.68, 0.035, 0.12, M.breadInside);
inside.position.y = 0.12;
group.add(inside);
const poreGeometry = new THREE.SphereGeometry(0.045, 10, 8);
for (let i = 0; i < 5; i++) {
const pore = mesh(poreGeometry, M.bread);
pore.scale.set(1.3, 0.16, 0.65);
pore.position.set(
-0.25 + Math.random() * 0.5,
0.16,
-0.18 + Math.random() * 0.36
);
group.add(pore);
}
return group;
}
function createTomatoWedge() {
const group = new THREE.Group();
const shape = new THREE.Shape();
shape.moveTo(0, 0);
shape.lineTo(0.43, 0);
shape.quadraticCurveTo(0.42, 0.39, 0, 0.43);
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.15,
bevelEnabled: true,
bevelSize: 0.035,
bevelThickness: 0.025,
bevelSegments: 2,
curveSegments: 8,
});
geometry.rotateX(-Math.PI / 2);
const wedge = mesh(geometry, M.tomato);
group.add(wedge);
for (let i = 0; i < 2; i++) {
const seed = mesh(new THREE.SphereGeometry(0.035, 10, 8), M.seed);
seed.scale.y = 0.25;
seed.position.set(0.16 + i * 0.11, 0.155, 0.16 - i * 0.07);
group.add(seed);
}
return group;
}
function createPepperStrip() {
const strip = mesh(
new THREE.CylinderGeometry(0.065, 0.085, 0.64, 8),
M.pepperRed
);
strip.rotation.x = Math.PI / 2;
return strip;
}
const breadStack = new THREE.Group();
for (let i = 0; i < 3; i++) {
const slice = createBreadSlice();
slice.position.set(i * 0.06, i * 0.115, i * 0.04);
slice.rotation.y = -0.18 + i * 0.14;
breadStack.add(slice);
}
breadStack.position.set(-0.91, 0.12, -1.48);
scene.add(breadStack);
const carrotCoins = new THREE.Group();
for (let i = 0; i < 7; i++) {
const coin = createCoin(M.carrot, M.carrotLight, 0.25);
coin.position.set(
Math.sin(i * 1.8) * 0.35,
0.01 + i * 0.012,
Math.cos(i * 1.8) * 0.31
);
coin.rotation.y = i * 0.67;
carrotCoins.add(coin);
}
carrotCoins.position.set(-0.82, 0.12, 0.24);
scene.add(carrotCoins);
const eggplantCoins = new THREE.Group();
for (let i = 0; i < 4; i++) {
const coin = createCoin(M.eggplant, M.eggplantInside, 0.32);
coin.position.set((i % 2) * 0.56, i * 0.018, Math.floor(i / 2) * 0.5);
coin.rotation.y = i * 0.33;
eggplantCoins.add(coin);
}
eggplantCoins.position.set(0.18, 0.12, -1.45);
scene.add(eggplantCoins);
const cucumberCoins = new THREE.Group();
for (let i = 0; i < 5; i++) {
const coin = createCoin(M.cucumber, M.cucumberInside, 0.29);
coin.position.set(
Math.cos(i * 1.45) * 0.38,
i * 0.016,
Math.sin(i * 1.45) * 0.38
);
cucumberCoins.add(coin);
}
cucumberCoins.position.set(0.67, 0.12, 1.02);
scene.add(cucumberCoins);
const tomatoWedges = new THREE.Group();
for (let i = 0; i < 4; i++) {
const wedge = createTomatoWedge();
wedge.position.set(
Math.cos(i * 1.7) * 0.27,
i * 0.012,
Math.sin(i * 1.7) * 0.25
);
wedge.rotation.y = i * 0.75;
tomatoWedges.add(wedge);
}
tomatoWedges.position.set(0.86, 0.12, 0.02);
scene.add(tomatoWedges);
const pepperStrips = new THREE.Group();
for (let i = 0; i < 5; i++) {
const strip = createPepperStrip();
strip.position.set(
Math.cos(i * 1.6) * 0.34,
0.075 + i * 0.014,
Math.sin(i * 1.6) * 0.33
);
strip.rotation.y = i * 0.7;
pepperStrips.add(strip);
}
pepperStrips.position.set(-0.29, 0.12, 1.62);
scene.add(pepperStrips);
// ---------- Plates and plated food ----------
function createPlate() {
const group = new THREE.Group();
const base = mesh(
new THREE.CylinderGeometry(0.78, 0.7, 0.11, 48),
M.plate
);
base.position.y = 0.055;
group.add(base);
const inner = mesh(
new THREE.CylinderGeometry(0.63, 0.63, 0.035, 48),
M.plate
);
inner.position.y = 0.12;
group.add(inner);
const rim = mesh(
new THREE.TorusGeometry(0.7, 0.075, 12, 48),
M.plate
);
rim.rotation.x = Math.PI / 2;
rim.position.y = 0.115;
group.add(rim);
return group;
}
const saladPlate = createPlate();
saladPlate.position.set(3.96, 0.12, -0.42);
scene.add(saladPlate);
for (let i = 0; i < 7; i++) {
const leaf = createLeaf(i % 2 ? M.lettuce : M.lettuceLight, 0.65);
leaf.position.set(
Math.cos(i * 1.35) * 0.23,
0.21 + (i % 3) * 0.025,
Math.sin(i * 1.35) * 0.22
);
leaf.rotation.y = i * 0.77;
leaf.rotation.z = (i % 2 ? 1 : -1) * 0.08;
saladPlate.add(leaf);
}
for (let i = 0; i < 4; i++) {
const wedge = createTomatoWedge();
wedge.position.set(
Math.cos(i * 1.6) * 0.28,
0.29,
Math.sin(i * 1.6) * 0.26
);
wedge.rotation.y = i * 0.8;
wedge.scale.setScalar(0.72);
saladPlate.add(wedge);
}
for (let i = 0; i < 3; i++) {
const coin = createCoin(M.carrot, M.carrotLight, 0.16);
coin.position.set(-0.32 + i * 0.3, 0.3, -0.25 + (i % 2) * 0.18);
coin.rotation.y = i;
saladPlate.add(coin);
}
const cucumberOnPlate = createCoin(
M.cucumber,
M.cucumberInside,
0.18
);
cucumberOnPlate.position.set(0.31, 0.29, 0.25);
saladPlate.add(cucumberOnPlate);
const bruschettaPlate = createPlate();
bruschettaPlate.position.set(6.15, 0.12, 1.08);
scene.add(bruschettaPlate);
for (let i = 0; i < 2; i++) {
const slice = createBreadSlice();
slice.scale.setScalar(0.9);
slice.position.set(-0.16 + i * 0.22, 0.14 + i * 0.06, i * 0.1);
slice.rotation.y = -0.28 + i * 0.48;
bruschettaPlate.add(slice);
}
const platedTomato = createTomatoWedge();
platedTomato.position.set(0.12, 0.3, -0.23);
platedTomato.rotation.y = 0.5;
platedTomato.scale.setScalar(0.82);
bruschettaPlate.add(platedTomato);
const plateStack = new THREE.Group();
for (let i = 0; i < 3; i++) {
const plate = createPlate();
plate.position.y = i * 0.12;
plate.scale.setScalar(0.87);
plateStack.add(plate);
}
plateStack.position.set(6.26, 0.12, -1.38);
scene.add(plateStack);
// ---------- Lighting ----------
scene.add(new THREE.HemisphereLight(0xfffbef, 0x7c877b, 2.1));
const keyLight = new THREE.DirectionalLight(0xfff4dc, 3.1);
keyLight.position.set(-5.5, 11, 7.5);
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.0002;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc9e4ff, 1.05);
fillLight.position.set(8, 6, -7);
scene.add(fillLight);
const warmLight = new THREE.PointLight(0xffc979, 12, 18, 2);
warmLight.position.set(0, 7, 4);
scene.add(warmLight);
// ---------- Custom orbit camera controls ----------
const cameraState = {
target: new THREE.Vector3(0, 0.35, 0),
radius: 18.2,
theta: 0.57,
phi: 0.73,
};
const defaultCameraState = {
radius: 18.2,
theta: 0.57,
phi: 0.73,
};
function updateCamera() {
const { target, radius, theta, phi } = cameraState;
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + radius * sinPhi * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(target);
}
function resetCamera() {
cameraState.radius = defaultCameraState.radius;
cameraState.theta = defaultCameraState.theta;
cameraState.phi = defaultCameraState.phi;
updateCamera();
}
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.classList.add("dragging");
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.38,
1.27
);
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (
event.pointerId !== undefined &&
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();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
11.5,
27
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("reset").addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
const step = 0.07;
if (event.key === "ArrowLeft") {
cameraState.theta += step;
} else if (event.key === "ArrowRight") {
cameraState.theta -= step;
} else if (event.key === "ArrowUp") {
cameraState.phi = Math.max(0.38, cameraState.phi - step);
} else if (event.key === "ArrowDown") {
cameraState.phi = Math.min(1.27, cameraState.phi + step);
} else if (event.key.toLowerCase() === "r") {
resetCamera();
} else {
return;
}
updateCamera();
});
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
updateCamera();
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```