Prompt specification
Build or customize the Three.js 3D scene "Family pizza order table" 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: Family pizza order table
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/family-pizza-order-table-x0135
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a scene with diners, plates, and pizzas with separate topping patterns; distribute requested fractions while a shared display shows the remaining portion of each original pizza. Stylized solid forms.
Working Three.js Starter (family-pizza-order-table-x0135):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Pizza Commons</title>
<style>
:root {
--ink: #26352d;
--muted: #718078;
--cream: #f4efe5;
--panel: #fffaf1;
--line: #dfd8ca;
--tomato: #dc5b40;
--green: #55745b;
--gold: #d9a441;
--shadow: 0 18px 45px rgba(57, 48, 34, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: var(--cream);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button,
select {
font: inherit;
}
button {
cursor: pointer;
}
#app {
display: flex;
flex-direction: column;
height: 100vh;
}
header {
min-height: 76px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 14px 22px;
border-bottom: 1px solid rgba(85, 116, 91, 0.14);
background: rgba(255, 250, 241, 0.92);
backdrop-filter: blur(12px);
z-index: 5;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
}
.brand-mark {
width: 43px;
height: 43px;
display: grid;
place-items: center;
border-radius: 14px;
background: var(--tomato);
color: white;
font-size: 23px;
box-shadow: 0 8px 20px rgba(220, 91, 64, 0.25);
transform: rotate(-5deg);
}
.brand h1 {
margin: 0;
font-size: 19px;
line-height: 1.05;
letter-spacing: -0.02em;
}
.brand p {
margin: 4px 0 0;
color: var(--muted);
font-size: 12px;
}
.header-status {
display: flex;
align-items: center;
gap: 8px;
padding: 9px 13px;
border: 1px solid #dce3d7;
border-radius: 999px;
background: #f0f5ec;
color: #48604c;
font-size: 12px;
font-weight: 750;
white-space: nowrap;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #6e9a66;
box-shadow: 0 0 0 4px rgba(110, 154, 102, 0.12);
}
main {
min-height: 0;
flex: 1;
display: grid;
grid-template-columns: minmax(0, 1fr) 360px;
gap: 12px;
padding: 12px;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
border: 1px solid rgba(92, 77, 54, 0.12);
border-radius: 25px;
background: #eee8dc;
box-shadow: var(--shadow);
}
#viewport {
position: absolute;
inset: 0;
}
#sceneCanvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.scene-title {
position: absolute;
top: 18px;
left: 18px;
padding: 12px 14px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 16px;
background: rgba(255, 250, 241, 0.78);
backdrop-filter: blur(9px);
pointer-events: none;
box-shadow: 0 10px 30px rgba(54, 44, 31, 0.09);
}
.scene-title strong {
display: block;
font-size: 13px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.scene-title span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 11px;
}
.camera-tools {
position: absolute;
right: 16px;
bottom: 16px;
display: flex;
align-items: center;
gap: 8px;
}
.camera-hint,
#resetView {
border: 1px solid rgba(255, 255, 255, 0.6);
border-radius: 12px;
background: rgba(255, 250, 241, 0.8);
color: var(--ink);
backdrop-filter: blur(9px);
box-shadow: 0 8px 22px rgba(54, 44, 31, 0.08);
font-size: 11px;
font-weight: 700;
}
.camera-hint {
padding: 10px 12px;
pointer-events: none;
}
#resetView {
padding: 10px 12px;
}
#resetView:hover {
background: white;
}
aside {
min-height: 0;
overflow-y: auto;
padding: 18px;
border: 1px solid rgba(92, 77, 54, 0.12);
border-radius: 25px;
background: var(--panel);
box-shadow: var(--shadow);
scrollbar-width: thin;
scrollbar-color: #c8c1b4 transparent;
}
.aside-section + .aside-section {
margin-top: 24px;
padding-top: 22px;
border-top: 1px solid var(--line);
}
.section-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 10px;
margin-bottom: 13px;
}
.section-heading h2 {
margin: 0;
font-size: 15px;
letter-spacing: -0.015em;
}
.section-heading p {
margin: 4px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
.mini-label {
padding: 5px 7px;
border-radius: 7px;
background: #edf2e9;
color: #5b705d;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
.display-row {
padding: 11px 0;
}
.display-row + .display-row {
border-top: 1px dashed #ddd5c7;
}
.display-row-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 7px;
}
.pizza-name {
display: flex;
align-items: center;
gap: 8px;
font-size: 12px;
font-weight: 800;
}
.pizza-swatch {
width: 10px;
height: 10px;
border: 2px solid rgba(0, 0, 0, 0.08);
border-radius: 50%;
}
.remaining-label {
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
.progress-track {
height: 7px;
overflow: hidden;
border-radius: 99px;
background: #e9e3d8;
}
.progress-fill {
height: 100%;
border-radius: inherit;
transition: width 500ms cubic-bezier(0.22, 1, 0.36, 1);
}
.display-detail {
display: flex;
justify-content: space-between;
margin-top: 5px;
color: #8a918b;
font-size: 9px;
}
#orderList {
display: grid;
gap: 10px;
}
.order-card {
padding: 12px;
border: 1px solid #e3ddcf;
border-radius: 16px;
background: #fffdf8;
transition: border-color 180ms ease, box-shadow 180ms ease;
}
.order-card.pending {
border-color: color-mix(in srgb, var(--accent) 48%, #e3ddcf);
box-shadow: 0 7px 20px color-mix(in srgb, var(--accent) 10%, transparent);
}
.diner-top {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 11px;
}
.avatar {
width: 31px;
height: 31px;
display: grid;
place-items: center;
flex: 0 0 auto;
border-radius: 50%;
background: var(--accent);
color: white;
font-size: 11px;
font-weight: 850;
}
.diner-name {
flex: 1;
min-width: 0;
}
.diner-name strong {
display: block;
font-size: 12px;
}
.diner-name span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
.request-status {
padding: 4px 6px;
border-radius: 6px;
background: #edf3e9;
color: #557158;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.request-status.pending {
background: #f8ead9;
color: #a76b2f;
}
.field-label {
display: block;
margin-bottom: 6px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.pizza-select {
width: 100%;
height: 36px;
padding: 0 10px;
border: 1px solid #ded7c9;
border-radius: 10px;
outline: none;
background: #fffcf5;
color: var(--ink);
font-size: 11px;
font-weight: 700;
}
.pizza-select:focus {
border-color: var(--green);
box-shadow: 0 0 0 3px rgba(85, 116, 91, 0.1);
}
.fraction-label {
margin-top: 11px;
}
.fraction-buttons {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 6px;
}
.fraction-button {
height: 34px;
border: 1px solid #ded7c9;
border-radius: 9px;
background: #fffcf5;
color: #647068;
font-size: 12px;
font-weight: 850;
transition: 150ms ease;
}
.fraction-button:hover {
border-color: #aeb9ab;
transform: translateY(-1px);
}
.fraction-button.active {
border-color: var(--green);
background: var(--green);
color: white;
box-shadow: 0 5px 12px rgba(85, 116, 91, 0.18);
}
.action-row {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
margin-top: 16px;
}
.primary-button,
.secondary-button {
min-height: 44px;
border-radius: 12px;
font-size: 11px;
font-weight: 850;
}
.primary-button {
border: 0;
background: var(--tomato);
color: white;
box-shadow: 0 8px 18px rgba(220, 91, 64, 0.2);
}
.primary-button:hover {
background: #ca4e35;
transform: translateY(-1px);
}
.secondary-button {
padding: 0 13px;
border: 1px solid #ded7c9;
background: #fffcf5;
color: var(--ink);
}
.secondary-button:hover {
background: #f6f0e5;
}
.note {
margin: 11px 1px 0;
color: #89918a;
font-size: 9px;
line-height: 1.55;
}
#toast {
position: absolute;
left: 50%;
bottom: 18px;
max-width: calc(100% - 30px);
padding: 11px 15px;
border-radius: 12px;
background: #29392f;
color: white;
font-size: 11px;
font-weight: 750;
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.2);
opacity: 0;
pointer-events: none;
transform: translate(-50%, 12px);
transition: 220ms ease;
}
#toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
#toast.error {
background: #a94332;
}
@media (max-width: 900px) {
body {
overflow: auto;
}
#app {
height: auto;
min-height: 100vh;
}
main {
grid-template-columns: 1fr;
}
#stage {
height: 64vh;
min-height: 480px;
}
aside {
overflow: visible;
}
}
@media (max-width: 560px) {
header {
padding: 12px 14px;
}
.brand p,
.header-status {
display: none;
}
main {
padding: 8px;
}
#stage {
min-height: 450px;
border-radius: 19px;
}
aside {
border-radius: 19px;
}
.camera-hint {
display: none;
}
}
</style>
</head>
<body>
<div id="app">
<header>
<div class="brand">
<div class="brand-mark">🍕</div>
<div>
<h1>Pizza Commons</h1>
<p>A shared table for split slices and simple requests</p>
</div>
</div>
<div class="header-status">
<span class="status-dot"></span>
<span id="tableStatus">3 originals · 3 diners · 1 shared table</span>
</div>
</header>
<main>
<section id="stage" aria-label="Interactive 3D pizza dining scene">
<div id="viewport">
<canvas id="sceneCanvas" aria-label="Three-dimensional restaurant scene"></canvas>
</div>
<div class="scene-title">
<strong>Shared table</strong>
<span>Portions are cut directly from the original pizzas</span>
</div>
<div class="camera-tools">
<div class="camera-hint">Drag to orbit · Scroll to zoom</div>
<button id="resetView" type="button">Reset view</button>
</div>
<div id="toast" role="status" aria-live="polite"></div>
</section>
<aside>
<section class="aside-section">
<div class="section-heading">
<div>
<h2>Shared display</h2>
<p>What remains of each original pizza.</p>
</div>
<span class="mini-label">Live</span>
</div>
<div id="displayList"></div>
</section>
<section class="aside-section">
<div class="section-heading">
<div>
<h2>Requested portions</h2>
<p>Choose a pizza and the fraction each diner wants.</p>
</div>
</div>
<div id="orderList"></div>
<div class="action-row">
<button id="distribute" class="primary-button" type="button">
Distribute portions
</button>
<button id="resetDisplay" class="secondary-button" type="button">
Reset
</button>
</div>
<p class="note">
Each original is divided into eight equal slices. Redistributing replaces
the current table portions while preserving the remaining shared display.
</p>
</section>
</aside>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#sceneCanvas");
const viewport = document.querySelector("#viewport");
const displayList = document.querySelector("#displayList");
const orderList = document.querySelector("#orderList");
const distributeButton = document.querySelector("#distribute");
const resetDisplayButton = document.querySelector("#resetDisplay");
const resetViewButton = document.querySelector("#resetView");
const toast = document.querySelector("#toast");
const tableStatus = document.querySelector("#tableStatus");
const PIZZAS = [
{
name: "Pepperoni",
color: "#d9573d",
pattern: "pepperoni"
},
{
name: "Margherita",
color: "#62805b",
pattern: "margherita"
},
{
name: "Garden",
color: "#d1a33c",
pattern: "garden"
}
];
const DINERS = [
{ name: "Maya", initials: "MY", color: "#d96d50" },
{ name: "Theo", initials: "TH", color: "#65816a" },
{ name: "June", initials: "JU", color: "#c29a42" }
];
const orders = {
Maya: { pizza: 0, ratio: 0.5 },
Theo: { pizza: 1, ratio: 0.25 },
June: { pizza: 2, ratio: 0.5 }
};
let allocations = null;
let toastTimer;
const animations = [];
// ---------------------------------------------------------------------
// Renderer, scene, and lighting
// ---------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#eee8dc");
scene.fog = new THREE.Fog("#eee8dc", 19, 34);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 100);
const hemisphere = new THREE.HemisphereLight("#fff7df", "#9a9b85", 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight("#fff2d2", 3.4);
keyLight.position.set(-5, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight("#d8e7e4", 1.35);
fillLight.position.set(8, 7, 2);
scene.add(fillLight);
const warmLight = new THREE.PointLight("#ffd18c", 12, 12, 2);
warmLight.position.set(0, 5, 0.5);
scene.add(warmLight);
const material = (color, roughness = 0.78, metalness = 0) =>
new THREE.MeshStandardMaterial({ color, roughness, metalness });
const MAT = {
floor: material("#dfd8ca"),
wall: material("#eee8dc"),
wallLower: material("#d4dccf"),
wood: material("#a86f43"),
woodDark: material("#754a31"),
table: material("#e7d3aa"),
tableEdge: material("#c8a979"),
pedestal: material("#b88755"),
cream: material("#fff8e9"),
plate: material("#f7f0df"),
plateRim: material("#d8cfbd"),
hair: material("#43342b"),
skin: material("#dca67e"),
eyes: material("#302820"),
pants: material("#46524b"),
crust: material("#cf8842"),
cheese: material("#efc86e"),
sauce: material("#c84e36"),
pepperoni: material("#bd3e2e"),
pepperoniDark: material("#a93025"),
basil: material("#3f7c49"),
tomato: material("#d84732"),
pepper: material("#e1ae35"),
mushroom: material("#eadcbd"),
mushroomCap: material("#b58a62"),
olive: material("#303a2d"),
water: material("#9fc5c8")
};
function mesh(geometry, mat, cast = true, receive = true) {
const object = new THREE.Mesh(geometry, mat);
object.castShadow = cast;
object.receiveShadow = receive;
scene.add(object);
return object;
}
// Room.
const floor = mesh(new THREE.PlaneGeometry(40, 40), MAT.floor, false, true);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.02;
const backWall = mesh(new THREE.PlaneGeometry(31, 14), MAT.wall, false, true);
backWall.position.set(0, 6.5, -7.4);
const lowerWall = mesh(new THREE.BoxGeometry(31, 1.35, 0.16), MAT.wallLower, false, true);
lowerWall.position.set(0, 0.65, -7.22);
// ---------------------------------------------------------------------
// Shared display counter and backboard
// ---------------------------------------------------------------------
const counter = mesh(new THREE.BoxGeometry(12.9, 0.44, 2.75), MAT.wood);
counter.position.set(0, 0.22, -5.1);
const counterTop = mesh(new THREE.BoxGeometry(13.15, 0.12, 2.95), MAT.woodDark);
counterTop.position.set(0, 0.46, -5.1);
const backboard = mesh(new THREE.BoxGeometry(13.1, 2.65, 0.22), MAT.woodDark);
backboard.position.set(0, 1.73, -6.42);
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 makeLabel(text, background = "#fff6df", foreground = "#34463a", width = 2.1) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 128;
const ctx = labelCanvas.getContext("2d");
roundedRectPath(ctx, 8, 8, 496, 112, 28);
ctx.fillStyle = background;
ctx.fill();
ctx.strokeStyle = "rgba(55, 45, 30, 0.12)";
ctx.lineWidth = 4;
ctx.stroke();
ctx.fillStyle = foreground;
ctx.font = "800 42px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 67);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({ map: texture, transparent: true, depthWrite: false })
);
sprite.scale.set(width, width * 0.25, 1);
return sprite;
}
const sharedSign = makeLabel("SHARED DISPLAY", "#f8e8c9", "#6d482c", 2.65);
sharedSign.position.set(0, 2.7, -6.23);
scene.add(sharedSign);
const displayPizzas = [];
PIZZAS.forEach((pizza, index) => {
const x = [-4.15, 0, 4.15][index];
const spot = mesh(
new THREE.CylinderGeometry(1.31, 1.31, 0.035, 48),
MAT.woodDark,
false,
true
);
spot.position.set(x, 0.54, -5.05);
const group = new THREE.Group();
group.position.set(x, 0.58, -5.05);
group.rotation.y = -0.18;
scene.add(group);
const wedges = [];
for (let i = 0; i < 8; i++) {
const wedge = createPizzaWedge(pizza.pattern, (i / 8) * Math.PI * 2, Math.PI / 4, 1.08);
group.add(wedge);
wedges.push(wedge);
}
const label = makeLabel(pizza.name.toUpperCase(), "#fff7df", "#34463a", 1.8);
label.position.set(x, 2.05, -5.04);
scene.add(label);
displayPizzas.push({ group, wedges });
});
// ---------------------------------------------------------------------
// Pizza construction
// ---------------------------------------------------------------------
function sectorGeometry(radius, start, length, depth = 0.11) {
const shape = new THREE.Shape();
const segments = Math.max(6, Math.ceil((length / (Math.PI * 2)) * 48));
shape.moveTo(0, 0);
for (let i = 0; i <= segments; i++) {
const angle = start + (length * i) / segments;
shape.lineTo(
Math.cos(angle) * radius,
-Math.sin(angle) * radius
);
}
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
bevelEnabled: true,
bevelSize: 0.016,
bevelThickness: 0.012,
bevelSegments: 1,
curveSegments: 12,
steps: 1
});
geometry.rotateX(-Math.PI / 2);
return geometry;
}
function addCrust(group, start, length, radius) {
const isFull = Math.abs(length - Math.PI * 2) < 0.001;
const segments = Math.max(8, Math.ceil((length / (Math.PI * 2)) * 56));
const points = [];
for (let i = 0; i < segments; i++) {
const angle = start + (length * i) / segments;
points.push(
new THREE.Vector3(
Math.cos(angle) * radius,
0.12,
Math.sin(angle) * radius
)
);
}
const curve = new THREE.CatmullRomCurve3(points, isFull, "centripetal");
const crustGeometry = new THREE.TubeGeometry(
curve,
isFull ? 64 : Math.max(10, Math.ceil(segments * 1.5)),
0.073,
7,
isFull
);
const crust = new THREE.Mesh(crustGeometry, MAT.crust);
crust.castShadow = true;
crust.receiveShadow = true;
group.add(crust);
}
function addTopping(group, pattern, angle, radius, index) {
const x = Math.cos(angle) * radius;
const z = Math.sin(angle) * radius;
if (pattern === "pepperoni") {
const topping = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.13, 0.035, 18),
index % 3 === 0 ? MAT.pepperoniDark : MAT.pepperoni
);
topping.position.set(x, 0.135, z);
topping.rotation.y = angle;
topping.castShadow = true;
group.add(topping);
return;
}
if (pattern === "margherita") {
if (index % 2 === 0) {
const leaf = new THREE.Mesh(new THREE.SphereGeometry(0.13, 10, 7), MAT.basil);
leaf.position.set(x, 0.145, z);
leaf.scale.set(1.1, 0.17, 0.58);
leaf.rotation.y = -angle + index * 0.4;
leaf.castShadow = true;
group.add(leaf);
} else {
const tomato = new THREE.Mesh(
new THREE.CylinderGeometry(0.095, 0.095, 0.04, 16),
MAT.tomato
);
tomato.position.set(x, 0.14, z);
tomato.castShadow = true;
group.add(tomato);
}
return;
}
const variant = index % 3;
if (variant === 0) {
const pepper = new THREE.Mesh(new THREE.BoxGeometry(0.26, 0.035, 0.075), MAT.pepper);
pepper.position.set(x, 0.145, z);
pepper.rotation.y = -angle + index * 0.17;
pepper.castShadow = true;
group.add(pepper);
} else if (variant === 1) {
const mushroom = new THREE.Group();
mushroom.position.set(x, 0.13, z);
mushroom.rotation.y = -angle;
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.055, 0.085, 10),
MAT.mushroom
);
stem.position.y = 0.035;
stem.castShadow = true;
mushroom.add(stem);
const cap = new THREE.Mesh(new THREE.SphereGeometry(0.105, 10, 7), MAT.mushroomCap);
cap.scale.set(1, 0.48, 0.72);
cap.position.y = 0.085;
cap.castShadow = true;
mushroom.add(cap);
group.add(mushroom);
} else {
const olive = new THREE.Mesh(new THREE.SphereGeometry(0.08, 10, 7), MAT.olive);
olive.position.set(x, 0.14, z);
olive.scale.y = 0.45;
olive.castShadow = true;
group.add(olive);
}
}
function createPizzaWedge(pattern, start, length, radius = 1.08) {
const group = new THREE.Group();
const cheese = new THREE.Mesh(
sectorGeometry(radius, start, length),
MAT.cheese
);
cheese.castShadow = true;
cheese.receiveShadow = true;
group.add(cheese);
addCrust(group, start, length, radius);
const toppingCount = Math.max(2, Math.round((length / (Math.PI * 2)) * 18));
for (let i = 0; i < toppingCount; i++) {
const angle =
start +
length * ((i + 0.5) / toppingCount) +
Math.sin(i * 2.31 + start) * length * 0.045;
const toppingRadius = 0.39 + ((i * 37 + Math.round(start * 10)) % 5) * 0.085;
addTopping(group, pattern, angle, toppingRadius, i);
}
return group;
}
// ---------------------------------------------------------------------
// Table, plates, cups, and diners
// ---------------------------------------------------------------------
const table = new THREE.Group();
table.position.z = 0.35;
scene.add(table);
const tableTop = new THREE.Mesh(
new THREE.CylinderGeometry(3.3, 3.3, 0.25, 64),
MAT.table
);
tableTop.position.y = 1.53;
tableTop.castShadow = true;
tableTop.receiveShadow = true;
table.add(tableTop);
const tableEdge = new THREE.Mesh(
new THREE.TorusGeometry(3.23, 0.12, 8, 64),
MAT.tableEdge
);
tableEdge.rotation.x = Math.PI / 2;
tableEdge.position.y = 1.53;
tableEdge.castShadow = true;
table.add(tableEdge);
const pedestal = new THREE.Mesh(
new THREE.CylinderGeometry(0.58, 0.82, 1.38, 32),
MAT.pedestal
);
pedestal.position.y = 0.71;
pedestal.castShadow = true;
table.add(pedestal);
const tableBase = new THREE.Mesh(
new THREE.CylinderGeometry(1.4, 1.55, 0.2, 40),
MAT.pedestal
);
tableBase.position.y = 0.1;
tableBase.castShadow = true;
table.add(tableBase);
const platePositions = [
new THREE.Vector3(-2.55, 1.69, 0.95),
new THREE.Vector3(2.55, 1.69, 0.95),
new THREE.Vector3(-1.15, 1.69, -1.83)
];
const plates = [];
platePositions.forEach((position, index) => {
const plate = new THREE.Group();
plate.position.copy(position);
scene.add(plate);
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.82, 0.74, 0.08, 48),
MAT.plate
);
base.castShadow = true;
base.receiveShadow = true;
plate.add(base);
const rim = new THREE.Mesh(
new THREE.TorusGeometry(0.69, 0.045, 8, 48),
MAT.plateRim
);
rim.rotation.x = Math.PI / 2;
rim.position.y = 0.055;
rim.castShadow = true;
plate.add(rim);
const delivery = new THREE.Group();
delivery.position.y = 0.105;
plate.add(delivery);
const napkin = new THREE.Mesh(
new THREE.BoxGeometry(0.28, 0.025, 0.38),
MAT.cream
);
napkin.position.set(-0.48, 0.06, 0.34);
napkin.rotation.y = 0.35;
plate.add(napronSafe(napkin));
plates.push({ plate, delivery });
const cupPosition = [
new THREE.Vector3(-3.05, 1.85, 1.68),
new THREE.Vector3(3.04, 1.85, 1.68),
new THREE.Vector3(-1.9, 1.85, -2.25)
][index];
const cup = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.115, 0.35, 16),
MAT.water
);
cup.position.copy(cupPosition);
cup.castShadow = true;
scene.add(cup);
});
function napronSafe(object) {
return object;
}
function cylinderBetween(start, end, radius, mat) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(radius, radius, length, 12);
const object = new THREE.Mesh(geometry, mat);
object.position.copy(start).add(end).multiplyScalar(0.5);
object.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
object.castShadow = true;
object.receiveShadow = true;
return object;
}
function createDiner(diner, index) {
const positions = [
new THREE.Vector3(-4.05, 0, 1.0),
new THREE.Vector3(4.05, 0, 1.0),
new THREE.Vector3(-1.35, 0, -3.35)
];
const group = new THREE.Group();
group.position.copy(positions[index]);
group.lookAt(new THREE.Vector3(0, 0, 0.35));
scene.add(group);
const shirt = material(diner.color);
const chair = new THREE.Mesh(
new THREE.BoxGeometry(0.9, 0.12, 0.72),
MAT.woodDark
);
chair.position.set(0, 0.68, -0.53);
chair.castShadow = true;
group.add(chair);
const chairBack = new THREE.Mesh(
new THREE.BoxGeometry(0.9, 1.0, 0.12),
MAT.woodDark
);
chairBack.position.set(0, 1.25, -0.83);
chairBack.castShadow = true;
group.add(chairBack);
const torso = new THREE.Mesh(
new THREE.CapsuleGeometry(0.36, 0.63, 6, 14),
shirt
);
torso.position.set(0, 1.31, 0);
torso.castShadow = true;
group.add(torso);
const lap = new THREE.Mesh(new THREE.SphereGeometry(0.43, 16, 10), MAT.pants);
lap.position.set(0, 0.87, 0.28);
lap.scale.set(1, 0.55, 0.8);
lap.castShadow = true;
group.add(lap);
const head = new THREE.Mesh(new THREE.SphereGeometry(0.31, 20, 14), MAT.skin);
head.position.set(0, 2.28, 0.08);
head.castShadow = true;
group.add(head);
const hair = new THREE.Mesh(new THREE.SphereGeometry(0.34, 18, 12), MAT.hair);
hair.position.set(0, 2.48, -0.015);
hair.scale.set(1, 0.61, 1);
hair.castShadow = true;
group.add(hair);
[-0.11, 0.11].forEach((x) => {
const eye = new THREE.Mesh(new THREE.SphereGeometry(0.025, 10, 8), MAT.eyes);
eye.position.set(x, 2.29, 0.355);
group.add(eye);
});
const nose = new THREE.Mesh(new THREE.SphereGeometry(0.055, 10, 8), MAT.skin);
nose.position.set(0, 2.22, 0.38);
nose.scale.set(0.8, 0.75, 1);
group.add(nose);
const leftHand = new THREE.Vector3(-0.53, 1.13, 0.92);
const rightHand = new THREE.Vector3(0.53, 1.13, 0.92);
group.add(
cylinderBetween(
new THREE.Vector3(-0.32, 1.59, 0.02),
leftHand,
0.105,
shirt
)
);
group.add(
cylinderBetween(
new THREE.Vector3(0.32, 1.59, 0.02),
rightHand,
0.105,
shirt
)
);
[leftHand, rightHand].forEach((position) => {
const hand = new THREE.Mesh(new THREE.SphereGeometry(0.12, 12, 8), MAT.skin);
hand.position.copy(position);
hand.castShadow = true;
group.add(hand);
});
const label = makeLabel(diner.name.toUpperCase(), diner.color, "#ffffff", 1.3);
label.position.set(0, 3.02, 0);
group.add(label);
}
DINERS.forEach(createDiner);
// Small centerpiece.
const vase = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.17, 0.35, 16),
material("#8ea596")
);
vase.position.set(0.2, 1.84, 0.2);
vase.castShadow = true;
scene.add(vase);
for (let i = 0; i < 5; i++) {
const leaf = new THREE.Mesh(new THREE.SphereGeometry(0.15, 10, 7), MAT.basil);
const angle = (i / 5) * Math.PI * 2;
leaf.position.set(
0.2 + Math.cos(angle) * 0.16,
2.08 + (i % 2) * 0.08,
0.2 + Math.sin(angle) * 0.16
);
leaf.scale.set(0.6, 1.4, 0.35);
leaf.rotation.z = Math.cos(angle) * 0.5;
leaf.rotation.x = Math.sin(angle) * 0.5;
leaf.castShadow = true;
scene.add(leaf);
}
// ---------------------------------------------------------------------
// Distribution logic
// ---------------------------------------------------------------------
function getRequestedTotals() {
const totals = [0, 0, 0];
for (const diner of DINERS) {
const request = orders[diner.name];
totals[request.pizza] += Math.round(request.ratio * 8);
}
return totals;
}
function clearDelivery(group) {
while (group.children.length) {
const child = group.children[0];
group.remove(child);
child.traverse((object) => {
if (object.geometry) {
object.geometry.dispose();
}
});
}
}
function applyDistribution(animate = true) {
const totals = getRequestedTotals();
displayPizzas.forEach((pizza, index) => {
pizza.wedges.forEach((wedge, wedgeIndex) => {
wedge.visible = wedgeIndex >= totals[index];
});
});
plates.forEach(({ delivery }) => clearDelivery(delivery));
DINERS.forEach((diner, index) => {
const request = orders[diner.name];
const portion = createPizzaWedge(
PIZZAS[request.pizza].pattern,
-Math.PI * request.ratio,
Math.PI * 2 * request.ratio,
1.02
);
portion.rotation.y = index * 0.75;
portion.scale.setScalar(animate ? 0.01 : 0.68);
plates[index].delivery.add(portion);
if (animate) {
animations.push({
object: portion,
start: performance.now(),
duration: 650,
target: 0.68
});
}
});
updateUI();
}
function serveDistribution() {
const totals = getRequestedTotals();
const excessive = totals.findIndex((total) => total > 8);
if (excessive !== -1) {
const shortBy = totals[excessive] - 8;
showToast(
`${PIZZAS[excessive].name} needs ${shortBy} fewer slice${shortBy === 1 ? "" : "s"}.`,
true
);
return;
}
allocations = Object.fromEntries(
DINERS.map((diner) => [
diner.name,
{ ...orders[diner.name] }
])
);
applyDistribution(true);
showToast("Portions distributed · shared display updated.");
}
function resetDisplay() {
allocations = null;
displayPizzas.forEach((pizza) => {
pizza.wedges.forEach((wedge) => {
wedge.visible = true;
});
});
plates.forEach(({ delivery }) => clearDelivery(delivery));
updateUI();
showToast("Shared display reset to three whole pizzas.");
}
// ---------------------------------------------------------------------
// Interface
// ---------------------------------------------------------------------
orderList.innerHTML = DINERS.map(
(diner) => `
<article class="order-card" data-diner="${diner.name}" style="--accent:${diner.color}">
<div class="diner-top">
<div class="avatar">${diner.initials}</div>
<div class="diner-name">
<strong>${diner.name}</strong>
<span>Requested portion</span>
</div>
<span class="request-status">Served</span>
</div>
<span class="field-label">Original pizza</span>
<select class="pizza-select" aria-label="${diner.name} pizza choice">
${PIZZAS.map(
(pizza, index) =>
`<option value="${index}">${pizza.name}</option>`
).join("")}
</select>
<span class="field-label fraction-label">Fraction requested</span>
<div class="fraction-buttons" role="group" aria-label="${diner.name} fraction">
<button class="fraction-button" type="button" data-ratio="0.25">¼</button>
<button class="fraction-button" type="button" data-ratio="0.5">½</button>
<button class="fraction-button" type="button" data-ratio="0.75">¾</button>
<button class="fraction-button" type="button" data-ratio="1">1</button>
</div>
</article>
`
).join("");
document.querySelectorAll(".order-card").forEach((card) => {
const dinerName = card.dataset.diner;
const select = card.querySelector(".pizza-select");
const buttons = [...card.querySelectorAll(".fraction-button")];
select.addEventListener("change", () => {
orders[dinerName].pizza = Number(select.value);
updateUI();
});
buttons.forEach((button) => {
button.addEventListener("click", () => {
orders[dinerName].ratio = Number(button.dataset.ratio);
updateUI();
});
});
});
function updateUI() {
const totals = getRequestedTotals();
displayList.innerHTML = PIZZAS.map((pizza, index) => {
const used = totals[index];
const remaining = 8 - used;
const percent = (remaining / 8) * 100;
return `
<div class="display-row">
<div class="display-row-top">
<div class="pizza-name">
<span class="pizza-swatch" style="background:${pizza.color}"></span>
${pizza.name}
</div>
<span class="remaining-label">${percent}% left</span>
</div>
<div class="progress-track">
<div
class="progress-fill"
style="width:${percent}%;background:${pizza.color}"
></div>
</div>
<div class="display-detail">
<span>${remaining} of 8 slices remaining</span>
<span>${percent === 0 ? "Served out" : `${used} portion slice${used === 1 ? "" : "s"} served`}</span>
</div>
</div>
`;
}).join("");
document.querySelectorAll(".order-card").forEach((card) => {
const dinerName = card.dataset.diner;
const request = orders[dinerName];
const allocated = allocations?.[dinerName];
const isPending =
!allocated ||
allocated.pizza !== request.pizza ||
allocated.ratio !== request.ratio;
card.classList.toggle("pending", isPending);
const status = card.querySelector(".request-status");
status.textContent = isPending ? "Pending" : "Served";
status.classList.toggle("pending", isPending);
card.querySelector(".pizza-select").value = request.pizza;
card.querySelectorAll(".fraction-button").forEach((button) => {
button.classList.toggle(
"active",
Number(button.dataset.ratio) === request.ratio
);
});
});
const servedPizzas = totals.filter((total) => total > 0).length;
tableStatus.textContent =
`${servedPizzas} pizza${servedPizzas === 1 ? "" : "s"} in use · 3 requested portions`;
}
function showToast(message, error = false) {
clearTimeout(toastTimer);
toast.textContent = message;
toast.classList.toggle("error", error);
toast.classList.add("visible");
toastTimer = setTimeout(() => {
toast.classList.remove("visible");
}, 3200);
}
distributeButton.addEventListener("click", serveDistribution);
resetDisplayButton.addEventListener("click", resetDisplay);
// ---------------------------------------------------------------------
// Camera controls implemented directly without addons
// ---------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 0.8, -1.05),
yaw: 0.36,
pitch: 0.69,
distance: 20.5,
desiredYaw: 0.36,
desiredPitch: 0.69,
desiredDistance: 20.5
};
function resetCamera() {
cameraState.desiredYaw = 0.36;
cameraState.desiredPitch = 0.69;
cameraState.desiredDistance = 20.5;
}
resetViewButton.addEventListener("click", resetCamera);
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.desiredYaw -= deltaX * 0.006;
cameraState.desiredPitch = THREE.MathUtils.clamp(
cameraState.desiredPitch + deltaY * 0.0045,
0.32,
1.15
);
});
function endDrag(event) {
dragging = false;
canvas.style.cursor = "grab";
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("pointerleave", () => {
dragging = false;
canvas.style.cursor = "grab";
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.desiredDistance = THREE.MathUtils.clamp(
cameraState.desiredDistance + event.deltaY * 0.012,
13,
28
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
canvas.style.cursor = "grab";
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / Math.max(height, 1);
camera.updateProjectionMatrix();
}
new ResizeObserver(resize).observe(viewport);
resize();
// ---------------------------------------------------------------------
// Animation loop
// ---------------------------------------------------------------------
function animate(time) {
requestAnimationFrame(animate);
cameraState.yaw = THREE.MathUtils.lerp(
cameraState.yaw,
cameraState.desiredYaw,
0.075
);
cameraState.pitch = THREE.MathUtils.lerp(
cameraState.pitch,
cameraState.desiredPitch,
0.075
);
cameraState.distance = THREE.MathUtils.lerp(
cameraState.distance,
cameraState.desiredDistance,
0.08
);
const horizontal =
cameraState.distance * Math.sin(cameraState.pitch);
camera.position.set(
cameraState.target.x + horizontal * Math.sin(cameraState.yaw),
cameraState.target.y + cameraState.distance * Math.cos(cameraState.pitch),
cameraState.target.z + horizontal * Math.cos(cameraState.yaw)
);
camera.lookAt(cameraState.target);
for (let i = animations.length - 1; i >= 0; i--) {
const animation = animations[i];
const progress = Math.min(
1,
(time - animation.start) / animation.duration
);
const eased = 1 - Math.pow(1 - progress, 3);
const overshoot = 1 + Math.sin(progress * Math.PI) * 0.045;
animation.object.scale.setScalar(
animation.target * eased * overshoot
);
if (progress >= 1) {
animation.object.scale.setScalar(animation.target);
animations.splice(i, 1);
}
}
renderer.render(scene, camera);
}
// Populate the table with the initial requests.
allocations = Object.fromEntries(
DINERS.map((diner) => [
diner.name,
{ ...orders[diner.name] }
])
);
applyDistribution(true);
requestAnimationFrame(animate);
</script>
</body>
</html>
```