Prompt specification
Build or customize the Three.js 3D scene "Fresh batch meets a queue" 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: Fresh batch meets a queue
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/fresh-batch-meets-a-queue-x0486
Scene Description Prompt:
A low-poly bakery queue: count loaves only as customers receive them or fresh trays reach display. Three.js from cdnjs, one HTML file.
Working Three.js Starter (fresh-batch-meets-a-queue-x0486):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Proof & Crumb — Low-Poly Bakery Queue</title>
<style>
:root {
--cream: #fff8eb;
--paper: rgba(255, 250, 239, 0.88);
--ink: #3e2b21;
--muted: #806b5b;
--gold: #d99132;
--green: #467765;
--burgundy: #9e4d45;
--line: rgba(74, 48, 34, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e6d4ba;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.grain {
position: fixed;
inset: 0;
pointer-events: none;
opacity: 0.16;
z-index: 2;
background-image:
radial-gradient(circle at 20% 30%, rgba(255,255,255,.65) 0 1px, transparent 1px),
radial-gradient(circle at 70% 60%, rgba(61,37,24,.35) 0 .8px, transparent 1px);
background-size: 13px 17px, 19px 23px;
mix-blend-mode: soft-light;
}
.ui {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
}
.brand {
position: absolute;
top: 24px;
left: 26px;
width: min(390px, calc(100vw - 52px));
padding: 18px 20px 17px;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 18px;
box-shadow: 0 16px 44px rgba(72, 43, 25, 0.14);
backdrop-filter: blur(14px);
}
.brand-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.eyebrow {
color: var(--burgundy);
font-size: 10px;
font-weight: 800;
letter-spacing: .19em;
text-transform: uppercase;
}
.live {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 5px 8px;
border: 1px solid rgba(70, 119, 101, .2);
border-radius: 999px;
background: rgba(70, 119, 101, .09);
color: var(--green);
font-size: 9px;
font-weight: 800;
letter-spacing: .1em;
}
.live::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 4px rgba(70, 119, 101, .1);
}
h1 {
margin: 5px 0 3px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 4vw, 43px);
font-weight: 600;
line-height: 1;
letter-spacing: -.035em;
}
.subtitle {
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.stats {
position: absolute;
top: 24px;
right: 26px;
width: min(390px, calc(100vw - 52px));
padding: 17px;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 18px;
box-shadow: 0 16px 44px rgba(72, 43, 25, 0.14);
backdrop-filter: blur(14px);
}
.metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.metric {
min-width: 0;
padding: 11px 10px 10px;
background: rgba(255, 255, 255, .44);
border: 1px solid var(--line);
border-radius: 12px;
}
.metric-label {
display: block;
overflow: hidden;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: .1em;
text-overflow: ellipsis;
white-space: nowrap;
}
.metric strong {
display: block;
margin-top: 3px;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
font-size: 29px;
font-weight: 600;
line-height: 1;
}
.metric:nth-child(1) strong {
color: var(--gold);
}
.metric:nth-child(2) strong {
color: var(--burgundy);
}
.metric:nth-child(3) strong {
color: var(--green);
}
.flow-state {
display: flex;
align-items: center;
gap: 8px;
margin-top: 11px;
color: var(--muted);
font-size: 10px;
line-height: 1.3;
}
.flow-state::before {
content: "";
flex: 0 0 auto;
width: 7px;
height: 7px;
border: 2px solid var(--gold);
border-radius: 50%;
}
.rule-card {
position: absolute;
left: 26px;
bottom: 25px;
width: min(330px, calc(100vw - 52px));
padding: 15px 17px;
background: rgba(62, 43, 33, .89);
color: #fff8eb;
border-radius: 15px;
box-shadow: 0 14px 35px rgba(62, 43, 33, .18);
}
.rule-card strong {
display: block;
margin-bottom: 5px;
font-family: Georgia, "Times New Roman", serif;
font-size: 17px;
font-weight: 500;
}
.rule-card p {
margin: 0;
color: rgba(255, 248, 235, .72);
font-size: 11px;
line-height: 1.5;
}
.feed {
position: absolute;
left: 50%;
bottom: 25px;
width: min(390px, calc(100vw - 52px));
transform: translateX(-50%);
padding: 12px 14px;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, .62);
border-radius: 15px;
box-shadow: 0 14px 35px rgba(72, 43, 25, .12);
backdrop-filter: blur(12px);
}
.feed-title {
margin-bottom: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: .15em;
text-transform: uppercase;
}
#event-list {
display: grid;
gap: 6px;
}
.event {
display: grid;
grid-template-columns: 8px 1fr auto;
align-items: center;
gap: 8px;
min-height: 26px;
}
.event-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--gold);
}
.event-dot.received {
background: var(--burgundy);
}
.event strong,
.event small {
display: block;
}
.event strong {
font-size: 10px;
font-weight: 750;
line-height: 1.2;
}
.event small {
color: var(--muted);
font-size: 9px;
line-height: 1.2;
}
.event time {
color: #a49383;
font-size: 9px;
font-variant-numeric: tabular-nums;
}
.empty-feed {
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.controls {
position: absolute;
right: 26px;
bottom: 25px;
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 9px;
pointer-events: auto;
}
.button-row {
display: flex;
gap: 8px;
}
button {
border: 0;
border-radius: 11px;
padding: 11px 14px;
cursor: pointer;
color: var(--cream);
background: var(--ink);
box-shadow: 0 7px 18px rgba(62, 43, 33, .18);
font-size: 11px;
font-weight: 750;
transition: transform .16s ease, opacity .16s ease, background .16s ease;
}
button:hover:not(:disabled) {
transform: translateY(-2px);
background: #553a2c;
}
button:active:not(:disabled) {
transform: translateY(0);
}
button:disabled {
cursor: default;
opacity: .45;
}
button.secondary {
color: var(--ink);
background: rgba(255, 248, 235, .9);
border: 1px solid var(--line);
}
button.secondary:hover:not(:disabled) {
background: #fffdf8;
}
.hint {
color: rgba(62, 43, 33, .7);
font-size: 9px;
font-weight: 700;
letter-spacing: .05em;
text-shadow: 0 1px 0 rgba(255,255,255,.45);
}
@media (max-width: 820px) {
.brand {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 13px 15px;
}
.brand .subtitle {
display: none;
}
.stats {
top: 126px;
left: 14px;
right: 14px;
width: auto;
padding: 11px;
}
.metric {
padding: 8px;
}
.metric strong {
font-size: 23px;
}
.flow-state {
margin-top: 8px;
}
.rule-card {
display: none;
}
.feed {
left: 14px;
right: 14px;
bottom: 78px;
width: auto;
transform: none;
}
.controls {
right: 14px;
bottom: 18px;
}
.hint {
display: none;
}
}
@media (max-width: 520px) {
.feed {
display: none;
}
.button-row {
flex-direction: column;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="grain"></div>
<main class="ui">
<header class="brand">
<div class="brand-top">
<div class="eyebrow">Neighborhood Bakery</div>
<div class="live" id="live-state">LIVE</div>
</div>
<h1>Proof & Crumb</h1>
<div class="subtitle">A warm little queue, one carefully counted loaf at a time.</div>
</header>
<section class="stats" aria-label="Live loaf counts" aria-live="polite">
<div class="metrics">
<div class="metric">
<span class="metric-label">ON DISPLAY</span>
<strong id="display-count">0</strong>
</div>
<div class="metric">
<span class="metric-label">RECEIVED</span>
<strong id="received-count">0</strong>
</div>
<div class="metric" title="On display plus received, without double-counting">
<span class="metric-label">TOTAL COUNTED</span>
<strong id="total-count">0</strong>
</div>
</div>
<div class="flow-state" id="flow-state">
Counting only at display arrival and customer handoff
</div>
</section>
<aside class="rule-card">
<strong>Count at the meaningful moment.</strong>
<p>
A loaf is added when a fresh tray reaches the display. It moves from
display to received only when it reaches the customer’s hand.
</p>
</aside>
<section class="feed" aria-label="Loaf counting activity">
<div class="feed-title">Counting activity</div>
<div id="event-list">
<div class="empty-feed">Waiting for the first fresh tray to reach the display…</div>
</div>
</section>
<div class="controls">
<div class="button-row">
<button id="fresh-button" type="button">Send fresh tray</button>
<button id="pause-button" class="secondary" type="button">Pause</button>
<button id="camera-button" class="secondary" type="button">Reset view</button>
</div>
<div class="hint">DRAG TO ORBIT · SCROLL TO ZOOM</div>
</div>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, camera, and direct camera controls
// ------------------------------------------------------------
const sceneContainer = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
sceneContainer.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8d8c0);
scene.fog = new THREE.Fog(0xe8d8c0, 18, 34);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraTarget = new THREE.Vector3(0, 1.25, -0.6);
const cameraSpherical = new THREE.Spherical(13.8, 1.16, 0.62);
const defaultCamera = {
radius: cameraSpherical.radius,
phi: cameraSpherical.phi,
theta: cameraSpherical.theta
};
function updateCamera() {
cameraSpherical.phi = THREE.MathUtils.clamp(
cameraSpherical.phi,
0.65,
1.42
);
cameraSpherical.radius = THREE.MathUtils.clamp(
cameraSpherical.radius,
8,
20
);
camera.position.setFromSpherical(cameraSpherical).add(cameraTarget);
camera.lookAt(cameraTarget);
}
updateCamera();
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraSpherical.theta -= dx * 0.006;
cameraSpherical.phi -= dy * 0.005;
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraSpherical.radius += event.deltaY * 0.008;
updateCamera();
},
{ passive: false }
);
document.getElementById("camera-button").addEventListener("click", () => {
cameraSpherical.radius = defaultCamera.radius;
cameraSpherical.phi = defaultCamera.phi;
cameraSpherical.theta = defaultCamera.theta;
updateCamera();
});
// ------------------------------------------------------------
// Lighting and materials
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xfff4dd, 0x76523b, 2.25));
const sunlight = new THREE.DirectionalLight(0xffe1ad, 3.1);
sunlight.position.set(-5, 9, 6);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(2048, 2048);
sunlight.shadow.camera.left = -10;
sunlight.shadow.camera.right = 10;
sunlight.shadow.camera.top = 10;
sunlight.shadow.camera.bottom = -10;
sunlight.shadow.camera.near = 0.5;
sunlight.shadow.camera.far = 30;
sunlight.shadow.bias = -0.0004;
scene.add(sunlight);
const displayLight = new THREE.PointLight(0xffbf67, 10, 7, 2);
displayLight.position.set(2, 2.7, -1.1);
scene.add(displayLight);
const world = new THREE.Group();
scene.add(world);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
flatShading: true,
...options
});
}
const cream = material(0xf4e5cc);
const darkWood = material(0x6b412c);
const midWood = material(0xa46b42);
const green = material(0x416e5d);
const darkGreen = material(0x294a40);
const burgundy = material(0x914b43);
const gold = material(0xd8a047, { metalness: 0.18, roughness: 0.5 });
const charcoal = material(0x322b28);
const glass = new THREE.MeshPhysicalMaterial({
color: 0xfff9ed,
transparent: true,
opacity: 0.14,
roughness: 0.06,
metalness: 0,
side: THREE.DoubleSide,
depthWrite: false
});
function mesh(geometry, mat, x, y, z, parent = world) {
const object = new THREE.Mesh(geometry, mat);
object.position.set(x, y, z);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function box(w, h, d, mat, x, y, z, parent = world) {
return mesh(new THREE.BoxGeometry(w, h, d), mat, x, y, z, parent);
}
function cylinderBetween(a, b, radius, mat, parent = world, segments = 8) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const object = mesh(
new THREE.CylinderGeometry(radius, radius, length, segments),
mat,
0,
0,
0,
parent
);
object.position.copy(a).add(b).multiplyScalar(0.5);
object.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return object;
}
// ------------------------------------------------------------
// Bakery interior
// ------------------------------------------------------------
const floorMaterials = [
material(0xc99762),
material(0xd09b66),
material(0xbf8956),
material(0xd4a06c)
];
for (let i = 0; i < 16; i++) {
const plank = box(
1.48,
0.06,
17,
floorMaterials[i % floorMaterials.length],
-11.25 + i * 1.5,
-0.035,
0
);
plank.castShadow = false;
}
box(24, 7, 0.22, cream, 0, 3.4, -4.55);
box(0.22, 7, 10, cream, -7.5, 3.4, 0.4);
box(24, 0.18, 0.12, darkWood, 0, 0.1, -4.4);
box(0.12, 0.18, 10, darkWood, -7.36, 0.1, 0.4);
// Window
const sky = material(0xa9cdd1, { roughness: 0.95 });
box(3.45, 2.55, 0.05, sky, -4.7, 3.12, -4.39);
const sun = mesh(
new THREE.CircleGeometry(0.5, 20),
material(0xf7cb68, { emissive: 0x6a3d08, emissiveIntensity: 0.16 }),
-5.55,
3.65,
-4.34
);
sun.castShadow = false;
box(0.13, 2.72, 0.14, midWood, -6.48, 3.12, -4.29);
box(0.13, 2.72, 0.14, midWood, -2.92, 3.12, -4.29);
box(3.68, 0.13, 0.14, midWood, -4.7, 1.78, -4.29);
box(3.68, 0.13, 0.14, midWood, -4.7, 4.46, -4.29);
box(0.12, 2.55, 0.13, midWood, -4.7, 3.12, -4.28);
// Oven
box(2.25, 2.05, 1.45, burgundy, -5.0, 1.02, -3.37);
box(1.72, 1.24, 0.08, charcoal, -5.0, 0.98, -2.60);
box(1.38, 0.82, 0.10, material(0x38211b), -5.0, 0.88, -2.54);
box(1.18, 0.08, 0.09, gold, -5.0, 1.54, -2.48);
box(0.72, 0.22, 0.62, darkWood, -5.0, 2.17, -3.35);
// Prep table
box(3.4, 0.16, 1.05, midWood, 3.35, 1.03, -3.33);
box(0.18, 1.0, 0.18, darkWood, 1.86, 0.5, -3.58);
box(0.18, 1.0, 0.18, darkWood, 4.83, 0.5, -3.58);
box(0.18, 1.0, 0.18, darkWood, 1.86, 0.5, -3.08);
box(0.18, 1.0, 0.18, darkWood, 4.83, 0.5, -3.08);
// Shelf and jars
box(2.2, 0.12, 0.58, darkWood, 5.65, 1.35, -4.12);
box(2.2, 0.12, 0.58, darkWood, 5.65, 2.54, -4.12);
const jarMaterials = [
material(0xc9b487),
material(0xd8c79e),
material(0xa7774d),
material(0xe0d4b6)
];
for (let i = 0; i < 4; i++) {
const jar = mesh(
new THREE.CylinderGeometry(0.19, 0.22, 0.48, 8),
jarMaterials[i],
4.83 + i * 0.53,
1.65,
-4.06
);
mesh(
new THREE.CylinderGeometry(0.21, 0.21, 0.06, 8),
darkWood,
jar.position.x,
1.93,
jar.position.z
);
}
for (let i = 0; i < 3; i++) {
mesh(
new THREE.CylinderGeometry(0.18, 0.2, 0.44, 8),
jarMaterials[(i + 1) % jarMaterials.length],
5.03 + i * 0.58,
2.83,
-4.06
);
}
// Flour sacks
for (let i = 0; i < 2; i++) {
const sack = mesh(
new THREE.DodecahedronGeometry(0.52, 0),
material(i ? 0xd9c49b : 0xcbb489),
-0.3 + i * 0.9,
0.49,
-3.25
);
sack.scale.set(0.9, 1.15, 0.8);
}
// Display counter
box(5.0, 1.25, 1.36, green, 2.0, 0.625, -1.55);
box(5.25, 0.17, 1.57, midWood, 2.0, 1.34, -1.55);
box(4.82, 0.12, 0.08, gold, 2.0, 1.42, -0.76);
for (let i = 0; i < 5; i++) {
box(0.78, 0.83, 0.05, darkGreen, 0.35 + i * 0.82, 0.68, -0.85);
}
// Glass display frame
box(4.95, 1.0, 0.035, glass, 2.0, 1.96, -0.755);
box(0.045, 1.18, 0.045, gold, -0.45, 1.96, -0.755);
box(0.045, 1.18, 0.045, gold, 4.45, 1.96, -0.755);
box(5.0, 0.045, 0.045, gold, 2.0, 2.55, -0.755);
// Cash register
box(0.48, 0.25, 0.40, burgundy, 4.02, 1.55, -1.36);
const registerScreen = box(
0.38,
0.27,
0.035,
material(0x314c46, { emissive: 0x10231f, emissiveIntensity: 0.3 }),
4.02,
1.83,
-1.38
);
registerScreen.rotation.x = -0.18;
// Pendant lights
for (const x of [-1.4, 1.8, 5.0]) {
cylinderBetween(
new THREE.Vector3(x, 5.6, -0.45),
new THREE.Vector3(x, 4.45, -0.45),
0.025,
charcoal
);
mesh(
new THREE.ConeGeometry(0.48, 0.46, 12, 1, true),
material(0x31584e, { side: THREE.DoubleSide }),
x,
4.28,
-0.45
);
mesh(
new THREE.SphereGeometry(0.10, 8, 6),
material(0xffd990, { emissive: 0xffb43d, emissiveIntensity: 1.1 }),
x,
4.13,
-0.45
);
}
// Queue floor markers
const queueSpots = [
new THREE.Vector3(-0.95, 0, 1.05),
new THREE.Vector3(-2.40, 0, 1.05),
new THREE.Vector3(-3.85, 0, 1.05),
new THREE.Vector3(-5.30, 0, 1.05)
];
const markerMaterial = new THREE.MeshBasicMaterial({
color: 0xd99b42,
transparent: true,
opacity: 0.42
});
const markerRingMaterial = new THREE.MeshBasicMaterial({
color: 0x9f6428,
transparent: true,
opacity: 0.55
});
for (const spot of queueSpots) {
const marker = mesh(
new THREE.CircleGeometry(0.34, 24),
markerMaterial,
spot.x,
0.011,
spot.z
);
marker.rotation.x = -Math.PI / 2;
marker.castShadow = false;
const ring = mesh(
new THREE.TorusGeometry(0.31, 0.018, 6, 24),
markerRingMaterial,
spot.x,
0.018,
spot.z
);
ring.rotation.x = -Math.PI / 2;
ring.castShadow = false;
}
const serviceMarker = mesh(
new THREE.CircleGeometry(0.43, 24),
new THREE.MeshBasicMaterial({
color: 0x9e4d45,
transparent: true,
opacity: 0.34
}),
-0.18,
0.014,
0.03
);
serviceMarker.rotation.x = -Math.PI / 2;
serviceMarker.castShadow = false;
// ------------------------------------------------------------
// Canvas-generated signs
// ------------------------------------------------------------
function makeTextTexture(title, subtitle, background, foreground) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 320;
const context = canvas.getContext("2d");
context.fillStyle = background;
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = foreground;
context.globalAlpha = 0.24;
context.lineWidth = 8;
context.strokeRect(16, 16, canvas.width - 32, canvas.height - 32);
context.globalAlpha = 1;
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = foreground;
context.font = "600 76px Georgia";
context.fillText(title, 512, 124);
if (subtitle) {
context.globalAlpha = 0.76;
context.font = "700 28px Arial";
context.letterSpacing = "4px";
context.fillText(subtitle, 512, 220);
context.globalAlpha = 1;
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
const bakerySign = mesh(
new THREE.PlaneGeometry(5.25, 1.45),
new THREE.MeshBasicMaterial({
map: makeTextTexture(
"FRESH FROM THE OVEN",
"SMALL BATCH • BIG HEART",
"#31584e",
"#fff2d9"
)
}),
2.0,
3.72,
-4.38
);
bakerySign.castShadow = false;
const pickupSign = mesh(
new THREE.PlaneGeometry(3.75, 0.58),
new THREE.MeshBasicMaterial({
map: makeTextTexture(
"PICKUP",
"",
"#294a40",
"#f4d79e"
)
}),
2.0,
0.74,
-0.81
);
pickupSign.castShadow = false;
const menuSign = mesh(
new THREE.PlaneGeometry(2.75, 2.0),
new THREE.MeshBasicMaterial({
map: makeTextTexture(
"TODAY",
"COUNTRY LOAF 6\nSEEDED LOAF 7\nMILK LOAF 5",
"#493126",
"#f7e5c7"
)
}),
-1.65,
2.65,
-4.38
);
menuSign.castShadow = false;
// ------------------------------------------------------------
// Low-poly people
// ------------------------------------------------------------
function makePerson(options = {}) {
const group = new THREE.Group();
const coat = material(options.coat ?? 0x8a6d9c);
const skin = material(options.skin ?? 0xc98f68);
const hair = material(options.hair ?? 0x3f2b23);
const trousers = material(options.trousers ?? 0x3e4853);
const shoes = material(options.shoes ?? 0x322a27);
box(0.18, 0.67, 0.20, trousers, 0, 0.36, -0.15, group);
box(0.18, 0.67, 0.20, trousers, 0, 0.36, 0.15, group);
box(0.36, 0.12, 0.27, shoes, 0.035, 0.07, -0.15, group);
box(0.36, 0.12, 0.27, shoes, 0.035, 0.07, 0.15, group);
mesh(
new THREE.CylinderGeometry(0.29, 0.36, 0.88, 6),
coat,
0,
1.13,
0,
group
);
cylinderBetween(
new THREE.Vector3(0, 1.55, -0.33),
new THREE.Vector3(0.025, 0.91, -0.39),
0.075,
coat,
group,
6
);
cylinderBetween(
new THREE.Vector3(0, 1.55, 0.33),
new THREE.Vector3(-0.015, 0.91, 0.39),
0.075,
coat,
group,
6
);
mesh(
new THREE.SphereGeometry(0.085, 7, 5),
skin,
0.035,
0.79,
-0.40,
group
);
mesh(
new THREE.SphereGeometry(0.085, 7, 5),
skin,
-0.005,
0.79,
0.40,
group
);
cylinderBetween(
new THREE.Vector3(0, 1.53, 0),
new THREE.Vector3(0, 1.66, 0),
0.09,
skin,
group,
6
);
mesh(
new THREE.DodecahedronGeometry(0.28, 0),
skin,
0,
1.84,
0,
group
);
const hairCap = mesh(
new THREE.DodecahedronGeometry(0.29, 0),
hair,
-0.035,
2.02,
-0.015,
group
);
hairCap.scale.set(0.93, 0.62, 1.0);
mesh(
new THREE.SphereGeometry(0.024, 5, 4),
charcoal,
0.255,
1.89,
-0.085,
group
);
mesh(
new THREE.SphereGeometry(0.024, 5, 4),
charcoal,
0.255,
1.89,
0.085,
group
);
mesh(
new THREE.SphereGeometry(0.045, 6, 4),
skin,
0.285,
1.80,
0,
group
);
if (options.apron !== false) {
box(
0.045,
0.62,
0.43,
material(options.apronColor ?? 0xbe7655),
0.305,
1.10,
0,
group
);
}
if (options.chef) {
mesh(
new THREE.CylinderGeometry(0.21, 0.22, 0.19, 8),
cream,
0,
2.14,
0,
group
);
mesh(
new THREE.SphereGeometry(0.16, 7, 5),
cream,
-0.08,
2.27,
0,
group
);
mesh(
new THREE.SphereGeometry(0.15, 7, 5),
cream,
0.08,
2.28,
0.04,
group
);
}
return group;
}
function addPaperBag(customer) {
const bag = new THREE.Group();
const kraft = material(0xb98554);
box(0.25, 0.30, 0.18, kraft, 0, 0.15, 0, bag);
box(0.20, 0.035, 0.15, material(0xd5a56e), 0, 0.315, 0, bag);
const handle = mesh(
new THREE.TorusGeometry(0.075, 0.014, 6, 12, Math.PI),
darkWood,
0,
0.32,
0,
bag
);
handle.rotation.z = Math.PI / 2;
bag.position.set(0.38, 0.69, 0.27);
customer.group.add(bag);
}
// ------------------------------------------------------------
// Loaves and trays
// ------------------------------------------------------------
const loafColors = [
material(0xc98235),
material(0xd59842),
material(0xb96e2f),
material(0xe0aa54)
];
const scoreMaterial = material(0xf3d59b);
function makeLoaf(index) {
const group = new THREE.Group();
const type = index % 3;
if (type === 1) {
const baguette = mesh(
new THREE.CapsuleGeometry(0.115, 0.40, 3, 6),
loafColors[index % loafColors.length],
0,
0.19,
0,
group
);
baguette.rotation.z = Math.PI / 2;
baguette.scale.set(1, 1.05, 0.94);
} else {
const body = mesh(
new THREE.DodecahedronGeometry(type === 2 ? 0.24 : 0.255, 0),
loafColors[index % loafColors.length],
0,
0.18,
0,
group
);
body.scale.set(
type === 2 ? 1.24 : 1.0,
type === 2 ? 0.65 : 0.73,
type === 2 ? 0.82 : 0.94
);
}
for (let i = -1; i <= 1; i++) {
const score = box(
0.18,
0.018,
0.03,
scoreMaterial,
i * 0.045,
0.355 - Math.abs(i) * 0.012,
i * 0.073,
group
);
score.rotation.y = i * 0.22;
}
return group;
}
function makeTray() {
const group = new THREE.Group();
box(1.18, 0.065, 0.90, darkWood, 0, 0, 0, group);
box(1.12, 0.025, 0.82, material(0xd1a96c), 0, 0.045, 0, group);
box(1.18, 0.08, 0.045, midWood, 0, 0.06, -0.44, group);
box(1.18, 0.08, 0.045, midWood, 0, 0.06, 0.44, group);
box(0.045, 0.08, 0.86, midWood, -0.57, 0.06, 0, group);
box(0.045, 0.08, 0.86, midWood, 0.57, 0.06, 0, group);
const loafPositions = [
[-0.28, 0.20],
[0.28, -0.20],
[0.00, 0.21]
];
const loaves = loafPositions.map((position, index) => {
const loaf = makeLoaf(index);
loaf.position.set(position[0], 0.07, position[1]);
group.add(loaf);
return loaf;
});
return { group, loaves };
}
// ------------------------------------------------------------
// Count state
//
// Important:
// - A tray is NOT counted when it is created or carried.
// - It is counted only when it reaches the display.
// - A loaf is marked received only when it reaches the customer.
// ------------------------------------------------------------
let displayedLoaves = 0;
let receivedLoaves = 0;
const displayCountElement = document.getElementById("display-count");
const receivedCountElement = document.getElementById("received-count");
const totalCountElement = document.getElementById("total-count");
const flowStateElement = document.getElementById("flow-state");
function updateCounts() {
displayCountElement.textContent = displayedLoaves;
receivedCountElement.textContent = receivedLoaves;
totalCountElement.textContent = displayedLoaves + receivedLoaves;
}
let simulationTime = 0;
function formatTime(seconds) {
const minutes = Math.floor(seconds / 60);
const remainder = Math.floor(seconds % 60);
return `${String(minutes).padStart(2, "0")}:${String(remainder).padStart(2, "0")}`;
}
function logEvent(title, detail, type = "display") {
const list = document.getElementById("event-list");
list.innerHTML = "";
const row = document.createElement("div");
row.className = "event";
row.innerHTML = `
<span class="event-dot ${type}"></span>
<div>
<strong>${title}</strong>
<small>${detail}</small>
</div>
<time>${formatTime(simulationTime)}</time>
`;
list.appendChild(row);
}
// ------------------------------------------------------------
// Customer queue
// ------------------------------------------------------------
const customers = [];
const queuedCustomers = [];
let servingCustomer = null;
const customerColors = [
0x7a6c9d,
0xbd6651,
0x497d79,
0xc28a3f,
0x5c718f,
0x8e6b5b,
0x69906c
];
const skinColors = [
0xc98f68,
0x8f5b3e,
0xe0ae83,
0x6f4633,
0xd49a71
];
const hairColors = [0x3b2a22, 0x65432d, 0x252321, 0x9b693f];
function reindexQueue() {
queuedCustomers.forEach((customer, index) => {
customer.queueIndex = index;
});
}
function addCustomer(colorIndex = customers.length) {
const group = makePerson({
coat: customerColors[colorIndex % customerColors.length],
skin: skinColors[colorIndex % skinColors.length],
hair: hairColors[colorIndex % hairColors.length],
apron: false
});
const customer = {
group,
status: "queued",
queueIndex: queuedCustomers.length,
serveElapsed: 0,
serviceStart: new THREE.Vector3(),
transfer: null,
received: false,
exitElapsed: 0,
exitCurve: null,
hasBag: false
};
group.position.set(-6.2, 0, 1.05);
scene.add(group);
customers.push(customer);
queuedCustomers.push(customer);
reindexQueue();
return customer;
}
for (let i = 0; i < 4; i++) {
addCustomer(i);
}
function startNextCustomer() {
if (servingCustomer || queuedCustomers.length === 0) return;
const available = availableLoaves.length;
if (available === 0) return;
const customer = queuedCustomers.shift();
reindexQueue();
customer.status = "serving";
customer.serveElapsed = 0;
customer.serviceStart.copy(customer.group.position);
servingCustomer = customer;
}
function receiveLoaf(customer) {
if (customer.received) return;
customer.received = true;
// This is the only place a customer receipt changes counts.
displayedLoaves = Math.max(0, displayedLoaves - 1);
receivedLoaves += 1;
updateCounts();
logEvent(
"Customer received a loaf",
"+1 received · moved out of display stock",
"received"
);
if (!customer.hasBag) {
addPaperBag(customer);
customer.hasBag = true;
}
}
const servicePosition = new THREE.Vector3(-0.18, 0, 0.03);
function updateCustomers(delta) {
// Waiting customers move toward their queue slots.
for (const customer of queuedCustomers) {
const target = queueSpots[
Math.min(customer.queueIndex, queueSpots.length - 1)
];
customer.group.position.lerp(target, 1 - Math.exp(-delta * 4.5));
}
if (servingCustomer) {
const customer = servingCustomer;
customer.serveElapsed += delta;
const approach = THREE.MathUtils.clamp(customer.serveElapsed / 0.78, 0, 1);
const easedApproach = 1 - Math.pow(1 - approach, 3);
customer.group.position.lerpVectors(
customer.serviceStart,
servicePosition,
easedApproach
);
if (!customer.transfer && customer.serveElapsed >= 0.78) {
const loaf = availableLoaves.shift();
if (loaf) {
const trayRecord = loaf.userData.trayRecord;
if (trayRecord) {
trayRecord.loaves = trayRecord.loaves.filter(item => item !== loaf);
if (trayRecord.loaves.length === 0) {
const recordIndex = trayRecords.indexOf(trayRecord);
if (recordIndex !== -1) trayRecords.splice(recordIndex, 1);
scene.remove(trayRecord.group);
}
}
scene.updateMatrixWorld(true);
scene.attach(loaf);
loaf.userData.trayRecord = null;
customer.transfer = {
loaf,
elapsed: 0,
duration: 1.05,
start: loaf.position.clone()
};
}
}
if (customer.transfer) {
const transfer = customer.transfer;
transfer.elapsed += delta;
const t = THREE.MathUtils.clamp(
transfer.elapsed / transfer.duration,
0,
1
);
const eased = t * t * (3 - 2 * t);
customer.group.updateMatrixWorld(true);
const end = customer.group.localToWorld(
new THREE.Vector3(0.39, 0.98, 0.12)
);
const position = new THREE.Vector3().lerpVectors(
transfer.start,
end,
eased
);
position.y += Math.sin(t * Math.PI) * 0.65;
transfer.loaf.position.copy(position);
transfer.loaf.rotation.y += delta * 2.5;
if (t >= 1) {
// The receipt event happens only now, when the loaf reaches
// the customer's hand.
receiveLoaf(customer);
scene.remove(transfer.loaf);
customer.transfer = null;
customer.status = "exiting";
customer.exitElapsed = 0;
customer.exitCurve = new THREE.CatmullRomCurve3([
customer.group.position.clone(),
new THREE.Vector3(1.25, 0, 0.42),
new THREE.Vector3(3.65, 0, 1.35),
new THREE.Vector3(6.20, 0, 2.15)
]);
servingCustomer = null;
}
}
}
// Customers walk away after receiving their loaf.
for (let i = customers.length - 1; i >= 0; i--) {
const customer = customers[i];
if (customer.status === "exiting" && customer.exitCurve) {
customer.exitElapsed += delta;
const t = THREE.MathUtils.clamp(customer.exitElapsed / 3.4, 0, 1);
customer.group.position.copy(customer.exitCurve.getPoint(t));
if (t >= 1) {
scene.remove(customer.group);
customers.splice(i, 1);
}
}
}
}
// ------------------------------------------------------------
// Fresh tray delivery
// ------------------------------------------------------------
const trayRecords = [];
const availableLoaves = [];
let freshState = null;
const freshButton = document.getElementById("fresh-button");
const workerStart = new THREE.Vector3(4.75, 0, -3.24);
const workerTarget = new THREE.Vector3(2.0, 0, -2.66);
const displaySlots = [
new THREE.Vector3(0.67, 1.43, -1.52),
new THREE.Vector3(2.00, 1.43, -1.52),
new THREE.Vector3(3.33, 1.43, -1.52)
];
function chooseDisplaySlot() {
const occupied = new Set(trayRecords.map(record => record.slot));
for (let i = 0; i < displaySlots.length; i++) {
if (!occupied.has(i)) return i;
}
// Very rare overflow: place another tray slightly higher.
return 0;
}
function startFreshTray(source = "Manual") {
if (freshState) return;
const tray = makeTray();
const worker = makePerson({
coat: 0xf4ead6,
trousers: 0x6b6259,
shoes: 0x403a35,
skin: 0xc78c66,
hair: 0x513326,
apron: false,
chef: true
});
worker.position.copy(workerStart);
worker.rotation.y = -Math.PI / 2;
world.add(worker);
const anchor = new THREE.Group();
anchor.position.set(0, 1.06, 0.40);
worker.add(anchor);
anchor.add(tray.group);
tray.group.position.set(0, 0, 0);
freshState = {
phase: "walk",
elapsed: 0,
worker,
tray: tray.group,
trayLoaves: tray.loaves,
source,
trayStart: null,
slot: null
};
freshButton.disabled = true;
}
freshButton.addEventListener("click", () => startFreshTray("Manual"));
function updateFreshTray(delta) {
if (!freshState) return;
freshState.elapsed += delta;
if (freshState.phase === "walk") {
const t = THREE.MathUtils.clamp(freshState.elapsed / 2.25, 0, 1);
const eased = t * t * (3 - 2 * t);
freshState.worker.position.lerpVectors(
workerStart,
workerTarget,
eased
);
if (t >= 1) {
freshState.phase = "place";
freshState.elapsed = 0;
freshState.worker.updateMatrixWorld(true);
scene.attach(freshState.tray);
freshState.trayStart = freshState.tray.position.clone();
freshState.slot = chooseDisplaySlot();
}
} else if (freshState.phase === "place") {
const t = THREE.MathUtils.clamp(freshState.elapsed / 0.42, 0, 1);
const eased = t * t * (3 - 2 * t);
const slotPosition = displaySlots[freshState.slot].clone();
if (trayRecords.length >= displaySlots.length) {
slotPosition.y += 0.26 * Math.floor(trayRecords.length / displaySlots.length);
}
freshState.tray.position.lerpVectors(
freshState.trayStart,
slotPosition,
eased
);
freshState.tray.rotation.y = (1 - eased) * 0.16;
if (t >= 1) {
// The tray has now physically reached the display.
// Only now are its loaves added to the count.
const record = {
group: freshState.tray,
loaves: freshState.trayLoaves,
slot: freshState.slot
};
trayRecords.push(record);
for (const loaf of record.loaves) {
loaf.userData.trayRecord = record;
availableLoaves.push(loaf);
}
displayedLoaves += record.loaves.length;
updateCounts();
logEvent(
"Fresh tray reached the display",
`+${record.loaves.length} loaves · tray arrival counted`
);
freshState.phase = "return";
freshState.elapsed = 0;
}
} else if (freshState.phase === "return") {
const t = THREE.MathUtils.clamp(freshState.elapsed / 2.4, 0, 1);
const eased = t * t * (3 - 2 * t);
freshState.worker.position.lerpVectors(
workerTarget,
workerStart,
eased
);
if (t >= 1) {
world.remove(freshState.worker);
freshState = null;
freshButton.disabled = false;
}
}
}
// ------------------------------------------------------------
// Simulation flow
// ------------------------------------------------------------
let freshCooldown = 0.8;
let spawnCooldown = 3.8;
let paused = false;
function updateSimulation(delta) {
updateFreshTray(delta);
updateCustomers(delta);
// Automatically deliver another tray when visible stock is low.
if (!freshState) {
freshCooldown -= delta;
if (freshCooldown <= 0) {
if (
queuedCustomers.length > 0 &&
availableLoaves.length <= 1
) {
startFreshTray("Automatic");
freshCooldown = 5.5;
} else {
freshCooldown = 1.2;
}
}
}
// Keep the queue pleasantly occupied.
spawnCooldown -= delta;
if (
spawnCooldown <= 0 &&
customers.length < 8 &&
queuedCustomers.length < queueSpots.length
) {
addCustomer(customers.length);
spawnCooldown = 3.8;
}
startNextCustomer();
}
// ------------------------------------------------------------
// UI controls and status
// ------------------------------------------------------------
const pauseButton = document.getElementById("pause-button");
const liveState = document.getElementById("live-state");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
liveState.textContent = paused ? "PAUSED" : "LIVE";
liveState.style.color = paused ? "#9e4d45" : "#467765";
});
let lastFlowState = "";
function updateFlowState() {
let text = "Counting only at display arrival and customer handoff";
if (
freshState &&
(freshState.phase === "walk" || freshState.phase === "place")
) {
text = "Fresh tray in transit · not counted until shelf arrival";
} else if (
servingCustomer &&
servingCustomer.transfer &&
!servingCustomer.received
) {
text = "Handoff in progress · receipt is not counted yet";
} else if (freshState && freshState.phase === "return") {
text = "Fresh tray counted · baker is returning to the prep table";
}
if (text !== lastFlowState) {
flowStateElement.textContent = text;
lastFlowState = text;
}
}
// ------------------------------------------------------------
// Main loop
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) {
simulationTime += delta;
updateSimulation(delta);
}
updateFlowState();
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
updateCounts();
animate();
</script>
</body>
</html>
```