Prompt specification
Build or customize the Three.js 3D scene "Bread batch identity markers" 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: Bread batch identity markers
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/bread-batch-identity-markers-x0485
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring bakery production batches. Display three trays of small loaves with different batch tags and equal tray capacity; preserve individual counts so batch arrivals can be tracked visually. Voxel style.
Working Three.js Starter (bread-batch-identity-markers-x0485):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Batchline 03 — Voxel Bakery</title>
<style>
:root {
--ink: #24312d;
--muted: #718078;
--paper: #f4f0e6;
--panel: rgba(251, 249, 243, 0.93);
--line: rgba(36, 49, 45, 0.12);
--orange: #e47c45;
--green: #588d72;
--shadow: 0 18px 55px rgba(54, 56, 46, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e4d8;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.brand {
position: fixed;
z-index: 4;
top: 25px;
left: 28px;
max-width: 430px;
pointer-events: none;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
color: #52645c;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.live-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #69a67d;
box-shadow: 0 0 0 4px rgba(105, 166, 125, 0.15);
}
.brand h1 {
margin: 0;
font-size: clamp(31px, 4vw, 52px);
font-weight: 850;
letter-spacing: -0.055em;
line-height: 0.98;
}
.brand h1 span {
color: var(--orange);
}
.brand p {
margin: 10px 0 0;
color: #607068;
font-size: 13px;
font-weight: 550;
}
.panel {
position: fixed;
z-index: 5;
top: 20px;
right: 20px;
bottom: 20px;
width: 330px;
overflow: auto;
padding: 20px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 22px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(18px) saturate(1.1);
scrollbar-width: thin;
scrollbar-color: #c7c7bb transparent;
}
.panel-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding-bottom: 17px;
border-bottom: 1px solid var(--line);
}
.panel-header strong {
display: block;
font-size: 13px;
letter-spacing: -0.01em;
}
.panel-header small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
.status-pill {
display: inline-flex;
align-items: center;
gap: 6px;
flex: 0 0 auto;
padding: 7px 9px;
border: 1px solid rgba(88, 141, 114, 0.22);
border-radius: 999px;
background: rgba(88, 141, 114, 0.1);
color: #48755f;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
}
.status-pill::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: #5b9a75;
}
.summary {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin: 16px 0 20px;
}
.metric {
min-height: 88px;
padding: 13px;
border: 1px solid var(--line);
border-radius: 15px;
background: rgba(255, 255, 255, 0.48);
}
.metric-label {
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.metric-value {
margin-top: 8px;
font-size: 27px;
font-weight: 820;
letter-spacing: -0.045em;
}
.metric-value small {
color: #8a938d;
font-size: 14px;
font-weight: 650;
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin: 0 0 9px;
color: #56665e;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.section-heading span {
color: #969e98;
font-size: 8px;
font-weight: 650;
letter-spacing: 0.04em;
text-transform: none;
}
.batch-list {
display: grid;
gap: 7px;
}
.batch-card {
--batch-color: #df8358;
width: 100%;
padding: 11px 12px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.44);
color: var(--ink);
text-align: left;
cursor: pointer;
transition:
border-color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
.batch-card:hover {
transform: translateY(-1px);
border-color: rgba(36, 49, 45, 0.25);
}
.batch-card.selected {
border-color: color-mix(in srgb, var(--batch-color), transparent 32%);
background: color-mix(in srgb, var(--batch-color), white 87%);
box-shadow: inset 3px 0 0 var(--batch-color);
}
.batch-card-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.batch-identity {
display: flex;
align-items: center;
gap: 8px;
}
.batch-swatch {
width: 9px;
height: 9px;
border-radius: 2px;
background: var(--batch-color);
box-shadow: 0 0 0 3px color-mix(in srgb, var(--batch-color), transparent 83%);
}
.batch-tag {
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.04em;
}
.batch-product {
margin-left: 17px;
color: var(--muted);
font-size: 9px;
font-weight: 650;
}
.batch-count {
flex: 0 0 auto;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 11px;
font-weight: 800;
}
.batch-count.full {
color: #bd5948;
}
.progress {
height: 4px;
margin-top: 9px;
overflow: hidden;
border-radius: 99px;
background: rgba(36, 49, 45, 0.08);
}
.progress-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: var(--batch-color);
transition: width 280ms cubic-bezier(0.22, 1, 0.36, 1);
}
.action-card {
margin-top: 16px;
padding: 14px;
border: 1px solid var(--line);
border-radius: 15px;
background: rgba(255, 255, 255, 0.52);
}
.selected-line {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.selected-line span {
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.1em;
}
.selected-line strong {
font-size: 12px;
letter-spacing: 0.02em;
}
#selectedMeta {
margin: 7px 0 12px;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.action-button {
min-height: 39px;
padding: 9px 10px;
border: 1px solid transparent;
border-radius: 10px;
background: var(--ink);
color: #fff;
cursor: pointer;
font-size: 10px;
font-weight: 750;
transition:
transform 120ms ease,
opacity 120ms ease,
background 120ms ease;
}
.action-button:hover:not(:disabled) {
transform: translateY(-1px);
background: #34453f;
}
.action-button.secondary {
border-color: var(--line);
background: #f8f6ef;
color: var(--ink);
}
.action-button.secondary:hover:not(:disabled) {
background: #fffdf8;
}
.action-button:disabled {
cursor: not-allowed;
opacity: 0.35;
}
.capacity-note {
margin-top: 9px;
color: #8a928d;
font-size: 9px;
text-align: center;
}
.ledger {
margin-top: 18px;
}
.ledger-list {
display: grid;
gap: 1px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 13px;
background: var(--line);
}
.ledger-row {
display: grid;
grid-template-columns: 7px 1fr auto;
align-items: center;
gap: 8px;
min-height: 43px;
padding: 8px 10px;
background: rgba(255, 255, 255, 0.54);
}
.ledger-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--event-color, var(--orange));
}
.ledger-main strong {
display: block;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
font-weight: 800;
}
.ledger-main span {
display: block;
margin-top: 2px;
overflow: hidden;
color: var(--muted);
font-size: 8px;
text-overflow: ellipsis;
white-space: nowrap;
}
.ledger-time {
color: #89918c;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 8px;
}
.controls-hint {
display: flex;
justify-content: space-between;
gap: 12px;
margin-top: 15px;
padding-top: 13px;
border-top: 1px solid var(--line);
color: #8a928d;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 8px;
line-height: 1.5;
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #e9e4d8;
color: #647169;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 820px) {
.brand {
top: 17px;
left: 18px;
}
.brand p {
display: none;
}
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 43vh;
padding: 15px;
border-radius: 18px;
}
.summary {
margin: 12px 0 15px;
}
.metric {
min-height: 72px;
}
.controls-hint {
display: none;
}
}
@media (max-height: 650px) and (min-width: 821px) {
.panel {
padding: 15px;
}
.summary {
margin: 12px 0;
}
.metric {
min-height: 74px;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<header class="brand">
<div class="eyebrow">
<span class="live-dot"></span>
Bakery operations / live
</div>
<h1>Batchline <span>03</span></h1>
<p>Voxel production floor · three synchronized trays</p>
</header>
<aside class="panel" aria-label="Batch production controls">
<div class="panel-header">
<div>
<strong>Production overview</strong>
<small>Equal tray capacity · 12 units</small>
</div>
<span class="status-pill">RUNNING</span>
</div>
<section class="summary" aria-label="Production summary">
<div class="metric">
<div class="metric-label">Units on line</div>
<div class="metric-value">
<span id="totalCount">0</span><small> / 36</small>
</div>
</div>
<div class="metric">
<div class="metric-label">Line utilization</div>
<div class="metric-value" id="utilization">0%</div>
</div>
</section>
<div class="section-heading">
Batch queue
<span>click to select</span>
</div>
<div id="batchList" class="batch-list"></div>
<section class="action-card" aria-label="Arrival controls">
<div class="selected-line">
<span>Selected tray</span>
<strong id="selectedTitle">—</strong>
</div>
<p id="selectedMeta">Select a tray to receive units.</p>
<div class="actions">
<button id="arriveOne" class="action-button" type="button">
+ Receive 1
</button>
<button id="arriveFour" class="action-button secondary" type="button">
+ Receive ×4
</button>
</div>
<div id="capacityNote" class="capacity-note">Capacity is tracked from individual loaf records.</div>
</section>
<section class="ledger" aria-label="Arrival ledger">
<div class="section-heading">
Arrival ledger
<span id="eventCount">0 events</span>
</div>
<div id="arrivalLog" class="ledger-list"></div>
</section>
<div class="controls-hint">
<span>DRAG · orbit</span>
<span>SCROLL · zoom</span>
<span>CLICK · select</span>
</div>
</aside>
<div id="loading">Starting production line…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const CAPACITY = 12;
const TOTAL_CAPACITY = CAPACITY * 3;
const viewport = document.querySelector("#viewport");
const loading = document.querySelector("#loading");
// -------------------------------------------------------------------------
// Scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e4d8);
scene.fog = new THREE.Fog(0xe9e4d8, 20, 38);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
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.12;
viewport.appendChild(renderer.domElement);
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional bakery batch production scene"
);
const hemisphere = new THREE.HemisphereLight(0xfff8e8, 0x87928c, 2.2);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff4df, 3.1);
keyLight.position.set(-5, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb8d4d0, 1.15);
fillLight.position.set(8, 5, -5);
scene.add(fillLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
new THREE.MeshStandardMaterial({
color: 0xe7e1d4,
roughness: 0.94,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(42, 42, 0xc9c1b2, 0xd8d1c4);
grid.position.y = 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.45;
grid.material.depthWrite = false;
scene.add(grid);
// -------------------------------------------------------------------------
// Shared geometry and materials
// -------------------------------------------------------------------------
const shared = {
loafBase: new THREE.BoxGeometry(0.58, 0.3, 0.42),
loafTop: new THREE.BoxGeometry(0.49, 0.09, 0.35),
score: new THREE.BoxGeometry(0.055, 0.026, 0.25),
slot: new THREE.BoxGeometry(0.68, 0.025, 0.53),
trayBase: new THREE.BoxGeometry(3.25, 0.18, 2.35),
trayInsert: new THREE.BoxGeometry(3.02, 0.05, 2.12),
trayRimX: new THREE.BoxGeometry(3.38, 0.18, 0.12),
trayRimZ: new THREE.BoxGeometry(0.12, 0.18, 2.48),
conveyor: new THREE.BoxGeometry(3.58, 0.25, 2.68),
leg: new THREE.BoxGeometry(0.18, 0.67, 0.18),
foot: new THREE.BoxGeometry(0.44, 0.09, 0.4)
};
const material = {
conveyor: new THREE.MeshStandardMaterial({
color: 0x56605b,
roughness: 0.58,
metalness: 0.42
}),
conveyorSide: new THREE.MeshStandardMaterial({
color: 0x87918b,
roughness: 0.4,
metalness: 0.52
}),
tray: new THREE.MeshStandardMaterial({
color: 0x7c8881,
roughness: 0.48,
metalness: 0.48
}),
insert: new THREE.MeshStandardMaterial({
color: 0xc9c3b5,
roughness: 0.9,
metalness: 0
}),
slot: new THREE.MeshStandardMaterial({
color: 0xb8b1a3,
roughness: 0.9
}),
dark: new THREE.MeshStandardMaterial({
color: 0x36423d,
roughness: 0.66,
metalness: 0.2
})
};
const slots = [];
const slotX = [-1.08, -0.36, 0.36, 1.08];
const slotZ = [-0.69, 0, 0.69];
for (const z of slotZ) {
for (const x of slotX) {
slots.push({ x, z });
}
}
const pickables = [];
const batches = [
{
id: "R-104",
product: "Dark rye",
shortProduct: "RYE",
initialCount: 8,
color: 0xdb7951,
loaves: []
},
{
id: "S-208",
product: "Spelt loaf",
shortProduct: "SPELT",
initialCount: 6,
color: 0xd5a13e,
loaves: []
},
{
id: "H-316",
product: "Honey oat",
shortProduct: "HONEY",
initialCount: 10,
color: 0xb98545,
loaves: []
}
];
let selectedBatchId = batches[0].id;
let eventSequence = 1000;
const arrivalLedger = [];
// -------------------------------------------------------------------------
// Utility functions
// -------------------------------------------------------------------------
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + width - r, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + r);
ctx.lineTo(x + width, y + height - r);
ctx.quadraticCurveTo(x + width, y + height, x + width - r, y + height);
ctx.lineTo(x + r, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function registerPickable(mesh, batchId) {
mesh.userData.batchId = batchId;
pickables.push(mesh);
}
function createBatchMaterials(batch) {
const base = new THREE.Color(batch.color);
const lighter = base.clone().lerp(new THREE.Color(0xffd38e), 0.38);
const darker = base.clone().multiplyScalar(0.62);
batch.materials = {
base: new THREE.MeshStandardMaterial({
color: base,
roughness: 0.88,
metalness: 0
}),
top: new THREE.MeshStandardMaterial({
color: lighter,
roughness: 0.82,
metalness: 0
}),
score: new THREE.MeshStandardMaterial({
color: darker,
roughness: 0.95,
metalness: 0
})
};
}
function createBatchLabel(batch) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 160;
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.position.set(0, 1.76, 0);
sprite.scale.set(2.68, 0.84, 1);
sprite.renderOrder = 20;
batch.label = { canvas, context: canvas.getContext("2d"), texture, sprite };
updateBatchLabel(batch);
}
function updateBatchLabel(batch) {
const { canvas, context, texture } = batch.label;
const count = batch.loaves.length;
const color = `#${new THREE.Color(batch.color).getHexString()}`;
context.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(context, 4, 4, 504, 152, 26);
context.fillStyle = "rgba(31, 43, 39, 0.94)";
context.fill();
context.strokeStyle = color;
context.lineWidth = 6;
context.stroke();
context.fillStyle = color;
context.fillRect(27, 28, 12, 104);
context.fillStyle = "#ffffff";
context.font = "800 38px ui-monospace, SFMono-Regular, Menlo, monospace";
context.textBaseline = "top";
context.fillText(batch.id, 61, 27);
context.fillStyle = "#b8c1bb";
context.font = "700 19px ui-monospace, SFMono-Regular, Menlo, monospace";
context.fillText(batch.shortProduct, 61, 80);
context.textAlign = "right";
context.fillStyle = "#ffffff";
context.font = "850 49px ui-monospace, SFMono-Regular, Menlo, monospace";
context.fillText(String(count).padStart(2, "0"), 469, 31);
context.fillStyle = color;
context.font = "750 18px ui-monospace, SFMono-Regular, Menlo, monospace";
context.fillText(`/ ${CAPACITY}`, 469, 92);
texture.needsUpdate = true;
}
function createStation(batch, index) {
const station = new THREE.Group();
station.position.x = (index - 1) * 3.8;
scene.add(station);
const conveyor = new THREE.Mesh(shared.conveyor, material.conveyor);
conveyor.position.y = 0.66;
conveyor.castShadow = true;
conveyor.receiveShadow = true;
station.add(conveyor);
for (const x of [-1.37, 1.37]) {
const side = new THREE.Mesh(
new THREE.BoxGeometry(0.12, 0.34, 2.72),
material.conveyorSide
);
side.position.set(x, 0.68, 0);
side.castShadow = true;
station.add(side);
}
for (const x of [-1.35, 1.35]) {
for (const z of [-0.88, 0.88]) {
const leg = new THREE.Mesh(shared.leg, material.dark);
leg.position.set(x, 0.34, z);
leg.castShadow = true;
station.add(leg);
const foot = new THREE.Mesh(shared.foot, material.dark);
foot.position.set(x, 0.05, z);
foot.castShadow = true;
station.add(foot);
}
}
const selection = new THREE.Mesh(
new THREE.BoxGeometry(3.78, 0.06, 2.88),
new THREE.MeshBasicMaterial({
color: new THREE.Color(batch.color),
transparent: true,
opacity: 0.3,
depthWrite: false
})
);
selection.position.y = 0.505;
selection.visible = false;
station.add(selection);
const tray = new THREE.Group();
tray.position.y = 0.85;
station.add(tray);
const trayBase = new THREE.Mesh(shared.trayBase, material.tray);
trayBase.castShadow = true;
trayBase.receiveShadow = true;
tray.add(trayBase);
registerPickable(trayBase, batch.id);
const insert = new THREE.Mesh(shared.trayInsert, material.insert);
insert.position.y = 0.115;
insert.receiveShadow = true;
tray.add(insert);
registerPickable(insert, batch.id);
const rimFront = new THREE.Mesh(shared.trayRimX, material.tray);
rimFront.position.set(0, 0.07, 1.24);
rimFront.castShadow = true;
tray.add(rimFront);
const rimBack = rimFront.clone();
rimBack.position.z = -1.24;
tray.add(rimBack);
for (const x of [-1.63, 1.63]) {
const rim = new THREE.Mesh(shared.trayRimZ, material.tray);
rim.position.set(x, 0.07, 0);
rim.castShadow = true;
tray.add(rim);
}
for (const slot of slots) {
const slotMesh = new THREE.Mesh(shared.slot, material.slot);
slotMesh.position.set(slot.x, 0.15, slot.z);
slotMesh.receiveShadow = true;
tray.add(slotMesh);
registerPickable(slotMesh, batch.id);
}
const beaconMaterial = new THREE.MeshStandardMaterial({
color: 0x6aa77f,
emissive: 0x6aa77f,
emissiveIntensity: 0.55,
roughness: 0.35
});
const beacon = new THREE.Mesh(
new THREE.BoxGeometry(0.15, 0.15, 0.15),
beaconMaterial
);
beacon.position.set(1.43, 1.13, -1.05);
beacon.castShadow = true;
tray.add(beacon);
batch.station = station;
batch.tray = tray;
batch.selection = selection;
batch.beacon = beacon;
batch.beaconMaterial = beaconMaterial;
createBatchLabel(batch);
tray.add(batch.label.sprite);
}
function createLoaf(batch, index, animate = true) {
const group = new THREE.Group();
const slot = slots[index];
const base = new THREE.Mesh(shared.loafBase, batch.materials.base);
base.position.y = 0.15;
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
const top = new THREE.Mesh(shared.loafTop, batch.materials.top);
top.position.set(0, 0.335, 0);
top.castShadow = true;
group.add(top);
for (const x of [-0.15, 0, 0.15]) {
const score = new THREE.Mesh(shared.score, batch.materials.score);
score.position.set(x, 0.392, 0);
score.castShadow = true;
group.add(score);
}
for (const child of group.children) {
registerPickable(child, batch.id);
}
const baseY = 0.16;
group.position.set(slot.x, baseY, slot.z);
group.scale.setScalar(animate ? 0.001 : 1);
group.userData.arrivalStart = animate ? performance.now() : -1000;
group.userData.baseY = baseY;
batch.tray.add(group);
const serialNumber = String(index + 1).padStart(3, "0");
batch.loaves.push({
serial: `${batch.id}-${serialNumber}`,
serialNumber,
group
});
return group;
}
function updateBatchStatus(batch) {
const count = batch.loaves.length;
const free = CAPACITY - count;
if (free === 0) {
batch.beaconMaterial.color.setHex(0xd25e50);
batch.beaconMaterial.emissive.setHex(0xd25e50);
} else if (free <= 2) {
batch.beaconMaterial.color.setHex(0xe0a23d);
batch.beaconMaterial.emissive.setHex(0xe0a23d);
} else {
batch.beaconMaterial.color.setHex(0x6aa77f);
batch.beaconMaterial.emissive.setHex(0x6aa77f);
}
batch.beaconMaterial.emissiveIntensity =
0.45 + Math.sin(performance.now() * 0.004) * 0.16;
}
// -------------------------------------------------------------------------
// Background bakery props
// -------------------------------------------------------------------------
function createBackgroundProps() {
const crateMaterial = new THREE.MeshStandardMaterial({
color: 0xb99d70,
roughness: 0.9
});
const crateLight = new THREE.MeshStandardMaterial({
color: 0xd0b585,
roughness: 0.9
});
for (let i = 0; i < 8; i++) {
const crate = new THREE.Mesh(
new THREE.BoxGeometry(1.15, 0.72, 0.9),
i % 2 ? crateMaterial : crateLight
);
crate.position.set(-6.2 + i * 1.75, 0.38 + (i % 2) * 0.75, -5.2);
crate.castShadow = true;
crate.receiveShadow = true;
scene.add(crate);
const band = new THREE.Mesh(
new THREE.BoxGeometry(1.18, 0.08, 0.94),
material.dark
);
band.position.copy(crate.position);
band.position.y += 0.17;
scene.add(band);
}
const rail = new THREE.Mesh(
new THREE.BoxGeometry(14.5, 0.13, 0.13),
material.conveyorSide
);
rail.position.set(0, 0.08, -4.58);
rail.castShadow = true;
scene.add(rail);
}
// -------------------------------------------------------------------------
// UI
// -------------------------------------------------------------------------
const batchListElement = document.querySelector("#batchList");
const arrivalLogElement = document.querySelector("#arrivalLog");
const totalCountElement = document.querySelector("#totalCount");
const utilizationElement = document.querySelector("#utilization");
const selectedTitleElement = document.querySelector("#selectedTitle");
const selectedMetaElement = document.querySelector("#selectedMeta");
const arriveOneButton = document.querySelector("#arriveOne");
const arriveFourButton = document.querySelector("#arriveFour");
const capacityNoteElement = document.querySelector("#capacityNote");
const eventCountElement = document.querySelector("#eventCount");
function createBatchCards() {
batchListElement.innerHTML = "";
for (const batch of batches) {
const color = `#${new THREE.Color(batch.color).getHexString()}`;
const card = document.createElement("button");
card.type = "button";
card.className = "batch-card";
card.dataset.batchId = batch.id;
card.style.setProperty("--batch-color", color);
card.innerHTML = `
<div class="batch-card-top">
<div>
<div class="batch-identity">
<span class="batch-swatch"></span>
<span class="batch-tag">${batch.id}</span>
</div>
<div class="batch-product">${batch.product}</div>
</div>
<span class="batch-count" data-count="${batch.id}">0 / ${CAPACITY}</span>
</div>
<div class="progress">
<div class="progress-fill" data-fill="${batch.id}"></div>
</div>
`;
card.addEventListener("click", () => selectBatch(batch.id));
batchListElement.appendChild(card);
}
}
function updateUI() {
const total = batches.reduce(
(sum, batch) => sum + batch.loaves.length,
0
);
totalCountElement.textContent = total;
utilizationElement.textContent = `${Math.round(
(total / TOTAL_CAPACITY) * 100
)}%`;
for (const batch of batches) {
const count = batch.loaves.length;
const card = batchListElement.querySelector(
`[data-batch-id="${batch.id}"]`
);
const countElement = batchListElement.querySelector(
`[data-count="${batch.id}"]`
);
const fillElement = batchListElement.querySelector(
`[data-fill="${batch.id}"]`
);
card.classList.toggle("selected", batch.id === selectedBatchId);
countElement.textContent = `${count} / ${CAPACITY}`;
countElement.classList.toggle("full", count === CAPACITY);
fillElement.style.width = `${(count / CAPACITY) * 100}%`;
}
const selected = batches.find(
(batch) => batch.id === selectedBatchId
);
const free = CAPACITY - selected.loaves.length;
selectedTitleElement.textContent = selected.id;
selectedMetaElement.textContent =
`${selected.product} · ${free} open slot${free === 1 ? "" : "s"} · ` +
`${selected.loaves.length} individual units recorded`;
arriveOneButton.disabled = free === 0;
arriveFourButton.disabled = free < 4;
capacityNoteElement.textContent =
free === 0
? "Tray full — capacity limit reached."
: free < 4
? `${free} slots remain. The ×4 action requires four open slots.`
: `${free} slots remain. Counts update from individual loaf records.`;
eventCountElement.textContent = `${arrivalLedger.length} events`;
arrivalLogElement.innerHTML = arrivalLedger
.slice(0, 7)
.map((entry) => {
const batch = batches.find((item) => item.id === entry.batchId);
const color = `#${new THREE.Color(batch.color).getHexString()}`;
return `
<div class="ledger-row" style="--event-color:${color}">
<span class="ledger-dot"></span>
<div class="ledger-main">
<strong>${entry.eventId} · ${entry.batchId} · ${entry.qty} UNIT${entry.qty === 1 ? "" : "S"}</strong>
<span title="${entry.serialRange}">${entry.serialRange}</span>
</div>
<span class="ledger-time">${entry.time}</span>
</div>
`;
})
.join("");
}
function selectBatch(batchId) {
selectedBatchId = batchId;
for (const batch of batches) {
batch.selection.visible = batch.id === selectedBatchId;
}
updateUI();
}
function receiveUnits(quantity) {
const batch = batches.find(
(item) => item.id === selectedBatchId
);
const free = CAPACITY - batch.loaves.length;
if (quantity <= 0 || free < quantity) {
return;
}
const firstIndex = batch.loaves.length;
const now = performance.now();
for (let i = 0; i < quantity; i++) {
createLoaf(batch, firstIndex + i, true);
batch.loaves[batch.loaves.length - 1].group.userData.arrivalStart =
now + i * 55;
}
eventSequence += 1;
const firstSerial = String(firstIndex + 1).padStart(3, "0");
const lastSerial = String(firstIndex + quantity).padStart(3, "0");
arrivalLedger.unshift({
eventId: `E-${eventSequence}`,
batchId: batch.id,
qty: quantity,
serialRange:
firstSerial === lastSerial
? `${batch.id}-${firstSerial}`
: `${batch.id}-${firstSerial} → ${batch.id}-${lastSerial}`,
time: new Date().toLocaleTimeString([], {
hour: "2-digit",
minute: "2-digit",
second: "2-digit"
})
});
updateBatchLabel(batch);
updateUI();
}
arriveOneButton.addEventListener("click", () => receiveUnits(1));
arriveFourButton.addEventListener("click", () => receiveUnits(4));
// -------------------------------------------------------------------------
// Direct camera controls — no external controls addon
// -------------------------------------------------------------------------
const cameraState = {
yaw: 0.08,
targetYaw: 0.08,
pitch: 0.55,
targetPitch: 0.55,
distance: 14.8,
targetDistance: 14.8,
target: new THREE.Vector3(0, 0.8, 0)
};
const pointer = {
active: false,
id: null,
x: 0,
y: 0,
startX: 0,
startY: 0,
moved: false
};
const raycaster = new THREE.Raycaster();
const mouse = new THREE.Vector2();
function updateCamera() {
cameraState.yaw +=
(cameraState.targetYaw - cameraState.yaw) * 0.12;
cameraState.pitch +=
(cameraState.targetPitch - cameraState.pitch) * 0.12;
cameraState.distance +=
(cameraState.targetDistance - cameraState.distance) * 0.12;
const horizontal =
cameraState.distance * Math.cos(cameraState.pitch);
camera.position.set(
cameraState.target.x + Math.sin(cameraState.yaw) * horizontal,
cameraState.target.y + Math.sin(cameraState.pitch) * cameraState.distance,
cameraState.target.z + Math.cos(cameraState.yaw) * horizontal
);
camera.lookAt(cameraState.target);
}
function pickBatch(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
mouse.x = ((clientX - rect.left) / rect.width) * 2 - 1;
mouse.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(mouse, camera);
const hits = raycaster.intersectObjects(pickables, false);
if (hits.length) {
selectBatch(hits[0].object.userData.batchId);
}
}
renderer.domElement.addEventListener("pointerdown", (event) => {
pointer.active = true;
pointer.id = event.pointerId;
pointer.x = pointer.startX = event.clientX;
pointer.y = pointer.startY = event.clientY;
pointer.moved = false;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointer.active || event.pointerId !== pointer.id) {
return;
}
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (
Math.abs(event.clientX - pointer.startX) +
Math.abs(event.clientY - pointer.startY) >
4
) {
pointer.moved = true;
}
cameraState.targetYaw -= dx * 0.006;
cameraState.targetPitch = THREE.MathUtils.clamp(
cameraState.targetPitch + dy * 0.0045,
0.28,
1.12
);
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!pointer.active || event.pointerId !== pointer.id) {
return;
}
if (!pointer.moved) {
pickBatch(event.clientX, event.clientY);
}
pointer.active = false;
pointer.id = null;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointer.active = false;
pointer.id = null;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.targetDistance = THREE.MathUtils.clamp(
cameraState.targetDistance + event.deltaY * 0.009,
8,
22
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraState.targetYaw = 0.08;
cameraState.targetPitch = 0.55;
cameraState.targetDistance = 14.8;
});
renderer.domElement.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraState.targetYaw -= 0.12;
break;
case "ArrowRight":
cameraState.targetYaw += 0.12;
break;
case "ArrowUp":
cameraState.targetPitch = THREE.MathUtils.clamp(
cameraState.targetPitch - 0.08,
0.28,
1.12
);
break;
case "ArrowDown":
cameraState.targetPitch = THREE.MathUtils.clamp(
cameraState.targetPitch + 0.08,
0.28,
1.12
);
break;
case "+":
case "=":
cameraState.targetDistance = Math.max(
8,
cameraState.targetDistance - 1
);
break;
case "-":
cameraState.targetDistance = Math.min(
22,
cameraState.targetDistance + 1
);
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
}
});
// -------------------------------------------------------------------------
// Initialization
// -------------------------------------------------------------------------
createBackgroundProps();
batches.forEach((batch, index) => {
createBatchMaterials(batch);
createStation(batch, index);
});
createBatchCards();
for (const batch of batches) {
for (let i = 0; i < batch.initialCount; i++) {
createLoaf(batch, i, false);
}
eventSequence += 1;
const firstSerial = String(1).padStart(3, "0");
const lastSerial = String(batch.initialCount).padStart(3, "0");
arrivalLedger.push({
eventId: `E-${eventSequence}`,
batchId: batch.id,
qty: batch.initialCount,
serialRange:
batch.initialCount === 1
? `${batch.id}-${firstSerial}`
: `${batch.id}-${firstSerial} → ${batch.id}-${lastSerial}`,
time: new Date().toLocaleTimeString([], {
hour: "2-digit",
minute: "2-digit",
second: "2-digit"
})
});
updateBatchLabel(batch);
}
arrivalLedger.reverse();
selectBatch(selectedBatchId);
updateUI();
updateCamera();
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
let firstFrame = true;
renderer.setAnimationLoop((time) => {
updateCamera();
for (const batch of batches) {
updateBatchStatus(batch);
for (const loaf of batch.loaves) {
const group = loaf.group;
const elapsed = time - group.userData.arrivalStart;
if (elapsed >= 0 && elapsed < 520) {
const t = THREE.MathUtils.clamp(elapsed / 520, 0, 1);
const eased = 1 - Math.pow(1 - t, 3);
const overshoot = Math.sin(t * Math.PI) * 0.1;
group.scale.setScalar(Math.max(0.001, eased + overshoot));
group.position.y =
group.userData.baseY + (1 - eased) * 0.48;
} else if (group.scale.x !== 1) {
group.scale.setScalar(1);
group.position.y = group.userData.baseY;
}
}
}
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
loading.classList.add("hidden");
}
});
</script>
</body>
</html>
```