Prompt specification
Build or customize the Three.js 3D scene "Bakery production scheduling diorama" 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: Bakery production scheduling diorama
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/bakery-production-scheduling-diorama-x1903
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: bakery production scheduling diorama. Compose fictional mixing, proofing, baking, and packing stations with synthetic task durations; show shared-resource contention without presenting real food-production instructions. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (bakery-production-scheduling-diorama-x1903):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Batch / Block — Bakery Scheduling Diorama</title>
<style>
:root {
--ink: #26332f;
--muted: #738078;
--paper: #fffaf2;
--line: #ded8cd;
--mint: #24a69f;
--gold: #e5ad43;
--orange: #e97645;
--purple: #9273c8;
--red: #dc554e;
--shadow: 0 18px 50px rgba(55, 48, 38, 0.15);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #f3eee4;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button { font: inherit; }
#stage {
position: fixed;
inset: 0 420px 0 0;
overflow: hidden;
background:
radial-gradient(circle at 30% 18%, rgba(255,255,255,.9), transparent 42%),
#f3eee4;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#stage canvas:active { cursor: grabbing; }
.brand {
position: fixed;
left: 24px;
top: 22px;
z-index: 5;
pointer-events: none;
max-width: 500px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
color: #65736c;
font-size: 10px;
font-weight: 800;
letter-spacing: .16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 9px;
height: 9px;
border-radius: 2px;
background: var(--mint);
box-shadow: 13px 0 0 var(--gold), 26px 0 0 var(--orange);
margin-right: 26px;
}
h1 {
margin: 8px 0 5px;
font-size: clamp(23px, 2.3vw, 35px);
line-height: 1;
letter-spacing: -.045em;
}
.brand p {
margin: 0;
color: #718078;
font-size: 12px;
line-height: 1.45;
}
.scene-tools {
position: fixed;
left: 24px;
top: 126px;
z-index: 7;
display: flex;
gap: 7px;
}
.tool {
border: 1px solid rgba(67, 75, 68, .13);
background: rgba(255, 252, 247, .88);
color: #4e5e56;
border-radius: 10px;
padding: 8px 10px;
cursor: pointer;
box-shadow: 0 5px 18px rgba(58, 50, 40, .07);
font-size: 11px;
font-weight: 700;
backdrop-filter: blur(8px);
transition: transform .15s, background .15s;
}
.tool:hover {
transform: translateY(-1px);
background: #fffdf9;
}
.scene-metrics {
position: fixed;
left: 24px;
bottom: 78px;
z-index: 5;
display: flex;
gap: 9px;
pointer-events: none;
}
.scene-metric {
min-width: 112px;
padding: 11px 13px;
border-radius: 13px;
border: 1px solid rgba(67, 75, 68, .12);
background: rgba(255, 252, 247, .88);
box-shadow: 0 8px 24px rgba(58, 50, 40, .08);
backdrop-filter: blur(10px);
}
.scene-metric span {
display: block;
color: #7b867f;
font-size: 9px;
font-weight: 800;
letter-spacing: .12em;
text-transform: uppercase;
}
.scene-metric strong {
display: block;
margin-top: 4px;
font-size: 18px;
letter-spacing: -.03em;
}
.station-switcher {
position: fixed;
left: 24px;
bottom: 22px;
z-index: 7;
display: flex;
align-items: center;
gap: 6px;
padding: 7px;
border: 1px solid rgba(67, 75, 68, .12);
border-radius: 14px;
background: rgba(255, 252, 247, .9);
box-shadow: var(--shadow);
backdrop-filter: blur(10px);
}
.station-switcher button {
border: 0;
border-radius: 9px;
padding: 8px 10px;
background: transparent;
color: #617068;
cursor: pointer;
font-size: 10px;
font-weight: 800;
}
.station-switcher button:hover,
.station-switcher button.active {
background: #edf0eb;
color: var(--ink);
}
.station-switcher .hint {
padding: 0 8px 0 5px;
color: #8b958f;
font-size: 10px;
white-space: nowrap;
}
#panel {
position: fixed;
right: 20px;
top: 20px;
bottom: 20px;
z-index: 10;
width: 380px;
display: flex;
flex-direction: column;
overflow: hidden;
border: 1px solid rgba(67, 75, 68, .14);
border-radius: 22px;
background: rgba(255, 252, 247, .95);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.panel-head {
padding: 20px 20px 15px;
border-bottom: 1px solid #ebe5da;
}
.panel-title-row {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.panel-kicker {
color: #8b958f;
font-size: 9px;
font-weight: 800;
letter-spacing: .15em;
text-transform: uppercase;
}
.panel-title {
margin-top: 4px;
font-size: 20px;
font-weight: 800;
letter-spacing: -.04em;
}
.clock {
min-width: 62px;
padding: 7px 9px;
border-radius: 10px;
background: #26332f;
color: #f9f5e9;
text-align: right;
font-variant-numeric: tabular-nums;
font-size: 12px;
font-weight: 800;
}
.clock small {
display: block;
margin-top: 2px;
color: #aebbb5;
font-size: 8px;
letter-spacing: .12em;
}
.status-line {
display: flex;
align-items: center;
gap: 7px;
margin-top: 12px;
color: #66746c;
font-size: 10px;
font-weight: 700;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #49ad82;
box-shadow: 0 0 0 4px rgba(73, 173, 130, .12);
}
.status-line.hot .status-dot {
background: var(--red);
box-shadow: 0 0 0 4px rgba(220, 85, 78, .12);
animation: pulse 1s infinite;
}
@keyframes pulse {
50% { transform: scale(.72); opacity: .55; }
}
.station-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
padding: 14px 16px;
border-bottom: 1px solid #ebe5da;
}
.station-card {
min-width: 0;
padding: 9px 8px;
border-radius: 11px;
background: #f3f0e9;
border: 1px solid #e9e3d8;
}
.station-card .name {
display: flex;
align-items: center;
gap: 5px;
overflow: hidden;
color: #68766f;
font-size: 8px;
font-weight: 800;
letter-spacing: .07em;
text-transform: uppercase;
white-space: nowrap;
}
.station-card .name i {
flex: 0 0 auto;
width: 7px;
height: 7px;
border-radius: 2px;
}
.station-card strong {
display: block;
margin-top: 6px;
font-size: 15px;
letter-spacing: -.03em;
}
.station-card small {
display: block;
margin-top: 2px;
color: #8c958f;
font-size: 8px;
}
.station-card .mini-meter {
height: 3px;
margin-top: 7px;
overflow: hidden;
border-radius: 3px;
background: #ddd9d0;
}
.station-card .mini-meter span {
display: block;
height: 100%;
border-radius: inherit;
transition: width .2s;
}
.schedule-area {
min-height: 0;
flex: 1;
display: flex;
flex-direction: column;
padding: 15px 16px 0;
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
}
.section-heading strong {
font-size: 11px;
letter-spacing: .01em;
}
.section-heading span {
color: #8a948e;
font-size: 9px;
}
#gantt {
position: relative;
min-height: 170px;
flex: 1;
overflow: auto;
padding-right: 4px;
scrollbar-width: thin;
scrollbar-color: #d7d1c7 transparent;
}
.chart-head,
.gantt-row {
display: grid;
grid-template-columns: 94px minmax(190px, 1fr);
min-width: 284px;
}
.chart-head {
position: sticky;
top: 0;
z-index: 4;
padding-bottom: 7px;
background: rgba(255, 252, 247, .98);
}
.head-label {
padding-left: 2px;
color: #8c958f;
font-size: 8px;
font-weight: 800;
letter-spacing: .12em;
}
.time-axis {
position: relative;
height: 18px;
color: #929b95;
font-size: 8px;
}
.time-axis span {
position: absolute;
top: 0;
transform: translateX(-50%);
}
.time-axis span:first-child { transform: none; }
.time-axis span:last-child { transform: translateX(-100%); }
.gantt-row {
min-height: 28px;
align-items: center;
}
.row-label {
display: flex;
align-items: center;
gap: 6px;
min-width: 0;
color: #59675f;
font-size: 9px;
font-weight: 700;
}
.row-label i {
width: 5px;
height: 13px;
flex: 0 0 auto;
border-radius: 2px;
}
.track {
position: relative;
height: 18px;
overflow: hidden;
border-radius: 4px;
background:
repeating-linear-gradient(
90deg,
rgba(68, 78, 71, .055) 0,
rgba(68, 78, 71, .055) 1px,
transparent 1px,
transparent calc(100% / 6)
),
#efede7;
}
.wait {
position: absolute;
top: 4px;
height: 10px;
border-radius: 2px;
background: repeating-linear-gradient(
135deg,
rgba(220, 85, 78, .38) 0,
rgba(220, 85, 78, .38) 2px,
rgba(220, 85, 78, .08) 2px,
rgba(220, 85, 78, .08) 5px
);
}
.bar {
position: absolute;
top: 2px;
height: 14px;
min-width: 3px;
overflow: hidden;
border-radius: 3px;
box-shadow: inset 0 -2px 0 rgba(0,0,0,.08);
}
.bar span {
display: block;
padding: 2px 4px;
color: rgba(255,255,255,.94);
font-size: 7px;
font-weight: 800;
line-height: 10px;
white-space: nowrap;
}
.load-row {
display: grid;
grid-template-columns: 94px minmax(190px, 1fr);
align-items: center;
min-width: 284px;
margin-top: 8px;
padding-top: 8px;
border-top: 1px solid #e8e3da;
}
.load-label {
color: #6b7871;
font-size: 8px;
font-weight: 800;
letter-spacing: .08em;
}
.load-track {
display: grid;
grid-template-columns: repeat(60, 1fr);
gap: 1px;
height: 9px;
padding: 2px;
border-radius: 4px;
background: #ebe8e1;
}
.load-track i {
border-radius: 1px;
background: #d8ddd7;
}
.load-track i.l1 { background: #9ccdb5; }
.load-track i.l2 { background: #e6bf67; }
.load-track i.l3 { background: #df665c; }
.playhead {
position: absolute;
z-index: 3;
top: 26px;
bottom: 19px;
width: 1px;
pointer-events: none;
background: #26332f;
box-shadow: 0 0 0 1px rgba(255,255,255,.5);
}
.playhead::before {
content: "";
position: absolute;
top: -3px;
left: -3px;
width: 7px;
height: 7px;
border-radius: 2px;
background: #26332f;
}
.legend-row {
display: flex;
flex-wrap: wrap;
gap: 12px;
padding: 9px 16px;
color: #7e8983;
font-size: 8px;
font-weight: 700;
border-top: 1px solid #ebe5da;
}
.legend-row span {
display: flex;
align-items: center;
gap: 5px;
}
.legend-row i {
width: 9px;
height: 9px;
border-radius: 2px;
}
.legend-row .wait-key {
background: repeating-linear-gradient(135deg, #dc554e 0 2px, #f5d7d3 2px 5px);
}
.disclaimer {
padding: 11px 16px 15px;
color: #8b948e;
background: #f5f1e9;
font-size: 8px;
line-height: 1.45;
}
.disclaimer strong {
color: #6d7972;
}
@media (max-width: 1050px) {
#stage { inset: 0 0 45% 0; }
#panel {
left: 12px;
right: 12px;
top: auto;
bottom: 12px;
width: auto;
height: calc(45% - 12px);
border-radius: 18px;
}
.brand { left: 16px; top: 15px; }
.brand p { display: none; }
.scene-tools { left: 16px; top: 92px; }
.scene-metrics { left: 16px; bottom: 16px; }
.scene-metric { min-width: 92px; padding: 8px 10px; }
.scene-metric strong { font-size: 15px; }
.station-switcher { display: none; }
.panel-head { padding: 13px 16px 10px; }
.panel-title { font-size: 16px; }
.station-grid { padding: 9px 12px; }
.schedule-area { padding: 10px 12px 0; }
}
@media (max-width: 620px) {
.scene-metrics { display: none; }
.tool { padding: 7px 8px; font-size: 9px; }
.panel-title { font-size: 14px; }
.station-card { padding: 7px 5px; }
.station-card .name { font-size: 7px; }
.station-card small { display: none; }
.legend-row { display: none; }
}
</style>
</head>
<body>
<div id="stage" aria-label="Interactive voxel bakery scheduling scene"></div>
<header class="brand">
<div class="eyebrow">Synthetic operations lab</div>
<h1>Batch / Block</h1>
<p>Bakery production scheduling diorama · fictional queues and shared-resource contention</p>
</header>
<nav class="scene-tools" aria-label="Scene controls">
<button class="tool" id="overviewBtn">Overview</button>
<button class="tool" id="topBtn">Top view</button>
<button class="tool" id="pauseBtn">Pause clock</button>
<button class="tool" id="speedBtn">1× speed</button>
<button class="tool" id="labelsBtn">Labels on</button>
</nav>
<div class="scene-metrics" aria-live="polite">
<div class="scene-metric">
<span>Shared crew</span>
<strong id="metricCrew">0 / 3</strong>
</div>
<div class="scene-metric">
<span>Waiting jobs</span>
<strong id="metricQueue">0</strong>
</div>
<div class="scene-metric">
<span>Peak wait</span>
<strong id="metricWait">0m</strong>
</div>
</div>
<nav class="station-switcher" aria-label="Focus a station">
<button class="active" data-station="all">All</button>
<button data-station="mix">Mixing</button>
<button data-station="proof">Proofing</button>
<button data-station="bake">Baking</button>
<button data-station="pack">Packing</button>
<span class="hint">Drag to orbit · scroll to zoom</span>
</nav>
<aside id="panel">
<div class="panel-head">
<div class="panel-title-row">
<div>
<div class="panel-kicker">Dispatch board</div>
<div class="panel-title">Synthetic schedule</div>
</div>
<div class="clock">
<span id="simClock">00:00</span>
<small>SIM TIME</small>
</div>
</div>
<div class="status-line" id="statusLine">
<i class="status-dot"></i>
<span id="statusText">Shared crew is available</span>
</div>
</div>
<div class="station-grid" id="stationGrid"></div>
<section class="schedule-area">
<div class="section-heading">
<strong>Task duration timeline</strong>
<span id="timelineHint">60 synthetic minutes</span>
</div>
<div id="gantt"></div>
</section>
<div class="legend-row">
<span><i style="background:#24a69f"></i>Mixing</span>
<span><i style="background:#e5ad43"></i>Proofing</span>
<span><i style="background:#e97645"></i>Baking</span>
<span><i style="background:#9273c8"></i>Packing</span>
<span><i class="wait-key"></i>Contention wait</span>
</div>
<div class="disclaimer">
<strong>Fictional scheduling model.</strong> All task durations, arrivals,
queue logic, and resource pools are synthetic. This visualization is not
a food-production procedure or operating instruction.
</div>
</aside>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
const stage = document.getElementById('stage');
const renderer = new THREE.WebGLRenderer({ antialias: true });
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.08;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf3eee4);
scene.fog = new THREE.Fog(0xf3eee4, 48, 82);
const camera = new THREE.OrthographicCamera(-20, 20, 15, -15, 0.1, 120);
const cameraTarget = new THREE.Vector3(-1, 1, 0);
const desiredTarget = cameraTarget.clone();
let cameraTheta = 0.64;
let cameraPhi = 0.79;
let desiredTheta = cameraTheta;
let desiredPhi = cameraPhi;
const hemi = new THREE.HemisphereLight(0xfff8e8, 0x927b68, 2.45);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1d4, 3.25);
sun.position.set(-15, 28, 17);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -25;
sun.shadow.camera.right = 25;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.bias = -0.00035;
scene.add(sun);
const rim = new THREE.DirectionalLight(0xb7d8d4, 1.1);
rim.position.set(18, 10, -18);
scene.add(rim);
const geometryCache = new Map();
const materialCache = new Map();
function getGeometry(w, h, d) {
const key = `${w}|${h}|${d}`;
if (!geometryCache.has(key)) {
geometryCache.set(key, new THREE.BoxGeometry(w, h, d));
}
return geometryCache.get(key);
}
function getMaterial(color, roughness = 0.78, metalness = 0) {
const key = `${color}|${roughness}|${metalness}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({ color, roughness, metalness })
);
}
return materialCache.get(key);
}
function box(parent, size, pos, color, options = {}) {
const mesh = new THREE.Mesh(
getGeometry(...size),
options.material || getMaterial(
color,
options.roughness ?? 0.78,
options.metalness ?? 0
)
);
mesh.position.set(...pos);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function makeLabel(title, subtitle, accent = '#24a69f', width = 5.2) {
const canvas = document.createElement('canvas');
canvas.width = 512;
canvas.height = 156;
const ctx = canvas.getContext('2d');
const r = 24;
const x = 8, y = 8, w = 496, h = 140;
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
ctx.fillStyle = 'rgba(255,252,247,0.96)';
ctx.fill();
ctx.strokeStyle = 'rgba(50,62,56,0.15)';
ctx.lineWidth = 4;
ctx.stroke();
ctx.fillStyle = accent;
ctx.fillRect(8, 8, 496, 17);
ctx.fillStyle = '#26332f';
ctx.font = '800 49px system-ui, sans-serif';
ctx.fillText(title, 30, 84);
ctx.fillStyle = '#748079';
ctx.font = '700 25px system-ui, sans-serif';
ctx.fillText(subtitle, 30, 122);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * 156 / 512, 1);
sprite.renderOrder = 20;
return sprite;
}
const labelGroup = new THREE.Group();
scene.add(labelGroup);
const stations = {
mix: {
id: 'mix', name: 'Mixing', short: 'MIX', color: 0x24a69f,
css: '#24a69f', capacity: 2, resource: 'mixers',
position: new THREE.Vector3(-10.5, 0, -5.1),
focus: new THREE.Vector3(-10.5, 1, -5.1)
},
proof: {
id: 'proof', name: 'Proofing', short: 'PRF', color: 0xe5ad43,
css: '#e5ad43', capacity: 3, resource: 'proofer trays',
position: new THREE.Vector3(-3.2, 0, -8),
focus: new THREE.Vector3(-3.2, 1, -8)
},
bake: {
id: 'bake', name: 'Baking', short: 'BAK', color: 0xe97645,
css: '#e97645', capacity: 2, resource: 'oven decks',
position: new THREE.Vector3(4.1, 0, -6.5),
focus: new THREE.Vector3(4.1, 1, -6.5)
},
pack: {
id: 'pack', name: 'Packing', short: 'PAK', color: 0x9273c8,
css: '#9273c8', capacity: 2, resource: 'pack tables',
position: new THREE.Vector3(10, 0, 3.6),
focus: new THREE.Vector3(10, 1, 3.6)
}
};
const stationGroups = {};
const statusLamps = {};
function stationZone(id, width, depth) {
const station = stations[id];
const group = new THREE.Group();
group.userData.station = id;
group.position.copy(station.position);
scene.add(group);
stationGroups[id] = group;
box(group, [width + .45, .18, depth + .45], [0, .12, 0], station.color);
box(group, [width, .18, depth], [0, .23, 0], 0xfff7e8);
const label = makeLabel(
station.name,
`${station.resource} · ${station.capacity} shared slots`,
station.css,
4.9
);
label.position.set(0, 4.65, 0);
labelGroup.add(label);
const lamps = [];
const board = new THREE.Group();
board.position.set(-width / 2 + 1.25, 1.1, depth / 2 - .2);
group.add(board);
box(board, [2.15, .75, .22], [0, 0, 0], 0x40504a);
for (let i = 0; i < station.capacity; i++) {
const mat = new THREE.MeshStandardMaterial({
color: 0x6cc99d,
emissive: 0x2d6f50,
emissiveIntensity: .25,
roughness: .55
});
const lamp = box(
board,
[.28, .28, .12],
[-.72 + i * .47, 0, .17],
0xffffff,
{ material: mat }
);
lamps.push({ mesh: lamp, material: mat });
}
statusLamps[id] = lamps;
return group;
}
// Raised voxel foundation and tiled floor.
box(scene, [34, 1, 24], [0, -.65, 0], 0xcbb998);
box(scene, [33.7, .32, 23.7], [0, -.08, 0], 0xeadcc4);
const tileColors = [0xf2e6d1, 0xeee0c8, 0xf6ead6, 0xeadcc5];
for (let x = 0; x < 16; x++) {
for (let z = 0; z < 11; z++) {
box(
scene,
[1.96, .09, 1.96],
[-15.5 + x * 2, .12, -10.5 + z * 2],
tileColors[(x + z * 3) % tileColors.length],
{ castShadow: false }
);
}
}
// Cutaway walls.
box(scene, [33.5, 5.5, .42], [0, 2.85, -11.7], 0xe9ddc9);
box(scene, [.42, 5.5, 23.5], [-16.6, 2.85, 0], 0xe3d6c1);
box(scene, [33.6, .18, .55], [0, .62, -11.43], 0xb98d72);
box(scene, [.55, .18, 23.5], [-16.35, .62, 0], 0xb98d72);
// Wall windows.
function backWindow(x) {
const g = new THREE.Group();
g.position.set(x, 3.15, -11.42);
scene.add(g);
box(g, [2.6, 2.15, .18], [0, 0, 0], 0x607d79);
box(g, [2.28, 1.84, .12], [0, 0, .08], 0xbcd7d2);
box(g, [.12, 1.9, .15], [0, 0, .18], 0xf7edda);
box(g, [2.35, .12, .15], [0, 0, .18], 0xf7edda);
box(g, [2.95, .18, .48], [0, -1.15, .15], 0xc49376);
}
[-12, -5.5, 1, 7.5, 13.5].forEach(backWindow);
// Wall shelving and decorative blocks.
const wallShelf = new THREE.Group();
wallShelf.position.set(-9.2, 2.1, -11.15);
scene.add(wallShelf);
box(wallShelf, [6.6, .16, .55], [0, 0, 0], 0x8e654f);
box(wallShelf, [6.6, .16, .55], [0, 1.55, 0], 0x8e654f);
[
[-2.4, .45, 0, .55, .75, .42, 0x9abf9c],
[-1.3, .45, 0, .7, .75, .42, 0xe2b65b],
[.1, .45, 0, .5, .75, .42, 0xd67d5b],
[1.4, .45, 0, .75, .75, .42, 0x78a7a2],
[-1.7, 2, 0, .55, .7, .42, 0xb08a6a],
[-.5, 2, 0, .7, .7, .42, 0x78a7a2],
[.8, 2, 0, .5, .7, .42, 0xe2b65b]
].forEach(v => box(wallShelf, v.slice(0, 3), v.slice(3, 6), v[6]));
// Voxel wall clock.
const clockGroup = new THREE.Group();
clockGroup.position.set(11.8, 3.7, -11.3);
scene.add(clockGroup);
box(clockGroup, [1.45, 1.45, .2], [0, 0, 0], 0x40504a);
box(clockGroup, [1.12, 1.12, .12], [0, 0, .14], 0xfff7e7);
box(clockGroup, [.07, .45, .08], [0, .18, .25], 0x40504a);
box(clockGroup, [.38, .07, .08], [.16, 0, .25], 0x40504a);
// Mixing zone.
const mixGroup = stationZone('mix', 9.2, 8.2);
box(mixGroup, [7.2, 1.25, 2.1], [0, .95, -1.35], 0xb67c60);
box(mixGroup, [7.45, .2, 2.3], [0, 1.67, -1.35], 0xf3dfbd);
const mixers = [];
function createMixer(x, color) {
const g = new THREE.Group();
g.position.set(x, 1.78, -1.35);
mixGroup.add(g);
box(g, [1.75, .45, 1.45], [0, .2, 0], 0x45534f);
box(g, [1.28, 1.5, 1.02], [-.45, 1.15, 0], color);
box(g, [1.65, .55, 1.35], [-.12, 1.9, 0], color);
box(g, [1.1, .55, 1.02], [-.12, 1.33, .3], 0xe8ddc8);
box(g, [.22, .32, .18], [.42, 1.92, .62], 0x26332f);
box(g, [.32, .12, .12], [.57, 1.92, .62], 0x26332f);
const whisk = new THREE.Group();
whisk.position.set(-.12, 1.42, .58);
g.add(whisk);
box(whisk, [.11, .65, .11], [0, 0, 0], 0xd9e0d8);
box(whisk, [.55, .1, .1], [0, -.25, 0], 0xd9e0d8);
box(whisk, [.1, .55, .1], [.23, -.25, 0], 0xd9e0d8);
mixers.push(whisk);
}
createMixer(-1.9, 0x399e96);
createMixer(1.25, 0x4caea4);
// Ingredient bins and abstract blocks.
box(mixGroup, [2.6, .75, 1.45], [2.3, .6, 2.1], 0x8f6c56);
box(mixGroup, [2.75, .14, 1.55], [2.3, 1.02, 2.1], 0xc6a27a);
box(mixGroup, [.55, .42, .55], [1.55, 1.28, 2.05], 0xe8c56d);
box(mixGroup, [.52, .38, .52], [2.25, 1.26, 2.05], 0xcf7756);
box(mixGroup, [.48, .4, .48], [2.9, 1.27, 2.05], 0x86aaa0);
// Proofing zone.
const proofGroup = stationZone('proof', 8.2, 7.2);
const rack = new THREE.Group();
rack.position.set(.2, 0, -1.4);
proofGroup.add(rack);
[-3.1, 3.1].forEach(x => {
box(rack, [.18, 3.7, .2], [x, 1.9, 0], 0x8a684e);
box(rack, [.18, 3.7, .2], [x, 1.9, -1.15], 0x8a684e);
});
for (let row = 0; row < 3; row++) {
const y = .85 + row * 1.05;
box(rack, [6.35, .14, 1.45], [0, y, -.57], 0xb58b62);
for (let col = 0; col < 3; col++) {
const x = -2.05 + col * 2.05;
box(rack, [1.62, .16, 1.04], [x, y + .12, -.57], 0xe4d3b4);
box(rack, [.67, .35, .66], [x, y + .38, -.57],
[0xe7c46f, 0xc9825e, 0x8cb2a5][(row + col) % 3]);
}
}
box(proofGroup, [1.45, 1.15, 1.25], [-2.7, .8, 2], 0xc79758);
box(proofGroup, [1.1, .35, .95], [-2.7, 1.52, 2], 0x9fb8a0);
box(proofGroup, [1.2, .8, 1], [2.7, .7, 2], 0x7faaa1);
// Baking zone.
const bakeGroup = stationZone('bake', 10.2, 8.8);
box(bakeGroup, [5.8, 3.2, 3.2], [-.7, 1.95, -1.8], 0x9e5f4d);
box(bakeGroup, [5.2, .45, 3.35], [-.7, 3.72, -1.8], 0xb86b53);
box(bakeGroup, [4.7, .45, 3.35], [-.7, 4.15, -1.8], 0xc77a5e);
box(bakeGroup, [1.25, 1.8, 1.15], [-.4, 5.25, -2.3], 0x76675d);
box(bakeGroup, [1.5, .25, 1.4], [-.4, 6.18, -2.3], 0x56635d);
const ovenDoor = new THREE.MeshStandardMaterial({
color: 0xe97645,
emissive: 0xe85d2d,
emissiveIntensity: 1.15,
roughness: .58
});
box(bakeGroup, [4.25, 2.25, .18], [-.7, 1.85, -.12], 0x3e403c);
box(bakeGroup, [3.65, 1.7, .12], [-.7, 1.85, -.01], 0xffffff, {
material: ovenDoor
});
box(bakeGroup, [.16, 1.85, .22], [-2.59, 1.85, .04], 0x2f3531);
box(bakeGroup, [.16, 1.85, .22], [1.19, 1.85, .04], 0x2f3531);
box(bakeGroup, [3.85, .16, .22], [-.7, 2.85, .04], 0x2f3531);
box(bakeGroup, [3.85, .16, .22], [-.7, .85, .04], 0x2f3531);
box(bakeGroup, [1.1, .4, .18], [-.7, 3.25, .03], 0x37403b);
box(bakeGroup, [3.5, .18, 1.4], [3.25, .55, -1.9], 0x9f7255);
for (let i = 0; i < 3; i++) {
box(bakeGroup, [.85, .7, .8], [2.25 + i, 1, -1.8],
[0xd7a85b, 0xb87950, 0xdfc087][i]);
}
// Packing zone.
const packGroup = stationZone('pack', 9.1, 8.2);
box(packGroup, [5.4, 1.2, 2.5], [-.4, .9, -.7], 0xa57d5d);
box(packGroup, [5.7, .2, 2.75], [-.4, 1.6, -.7], 0xe7cfac);
box(packGroup, [1.2, .75, .9], [-2, 2.05, -.7], 0x8067a8);
box(packGroup, [.95, .7, .85], [-.65, 2, -.7], 0xc99658);
box(packGroup, [1.25, .8, 1], [1.1, 2.05, -.7], 0x6da198);
box(packGroup, [1.2, .15, .2], [-.65, 2.42, -.7], 0xf0d9a6);
box(packGroup, [1.8, .35, .8], [2.35, .55, 2], 0x765b4d);
// Conveyors.
box(scene, [24, .35, 1.38], [0, .52, -.55], 0x3b4641);
box(scene, [24.2, .18, .12], [0, .77, -1.28], 0x9a755b);
box(scene, [24.2, .18, .12], [0, .77, .18], 0x9a755b);
for (let x = -11.5; x <= 11.5; x += .72) {
box(scene, [.12, .08, 1.15], [x, .73, -.55], 0x68726d);
}
box(scene, [1.38, .35, 4.6], [10, .52, 1.65], 0x3b4641);
box(scene, [.12, .18, 4.7], [9.28, .77, 1.65], 0x9a755b);
box(scene, [.12, .18, 4.7], [10.72, .77, 1.65], 0x9a755b);
const movingPackages = [];
for (let i = 0; i < 5; i++) {
const g = new THREE.Group();
scene.add(g);
const color = [0xd7a85b, 0xb87950, 0x7faaa1, 0x9d83bf, 0xe3bf70][i];
box(g, [.68, .62, .68], [0, 0, 0], color);
box(g, [.13, .66, .69], [0, 0, 0], 0xf0d8a7);
movingPackages.push(g);
}
// Shared crew hub.
const hub = new THREE.Group();
hub.position.set(0, 0, 3.35);
scene.add(hub);
box(hub, [3.3, .42, 3.3], [0, .35, 0], 0xb88567);
box(hub, [2.8, .24, 2.8], [0, .65, 0], 0xe8d8bd);
box(hub, [.22, 2.8, .22], [0, 2, 0], 0x4b5a54);
box(hub, [3.25, .62, .3], [0, 3.15, 0], 0x40504a);
const hubLabel = makeLabel(
'Shared Crew',
'3 workers · cross-station capacity',
'#40504a',
4.1
);
hubLabel.position.set(0, 4.15, 0);
labelGroup.add(hubLabel);
const crewLamps = [];
for (let i = 0; i < 3; i++) {
const mat = new THREE.MeshStandardMaterial({
color: 0x65c28e,
emissive: 0x2f7650,
emissiveIntensity: .3
});
const lamp = box(hub, [.42, .42, .18], [-.85 + i * .85, 3.16, .2],
0xffffff, { material: mat });
crewLamps.push({ mesh: lamp, material: mat });
}
const contentionBeacon = new THREE.Group();
contentionBeacon.position.set(0, 4.85, 0);
hub.add(contentionBeacon);
const beaconMat = new THREE.MeshStandardMaterial({
color: 0xdc554e,
emissive: 0xcc342f,
emissiveIntensity: .7
});
box(contentionBeacon, [.65, .65, .65], [0, 0, 0], 0xffffff, {
material: beaconMat
});
box(contentionBeacon, [.1, .26, .1], [0, .04, .36], 0xfff5e6);
box(contentionBeacon, [.1, .1, .1], [0, -.19, .36], 0xfff5e6);
function createWorker(color, parent, position, scale = 1) {
const g = new THREE.Group();
g.position.set(...position);
g.scale.setScalar(scale);
parent.add(g);
box(g, [.25, .48, .28], [-.18, .28, 0], 0x40504a);
box(g, [.25, .48, .28], [.18, .28, 0], 0x40504a);
box(g, [.78, .75, .48], [0, .9, 0], color);
box(g, [.22, .6, .22], [-.48, .86, 0], color);
box(g, [.22, .6, .22], [.48, .86, 0], color);
box(g, [.45, .43, .43], [0, 1.55, 0], 0xd9aa82);
box(g, [.5, .18, .48], [0, 1.82, 0], 0xf8f0dd);
box(g, [.56, .12, .52], [0, 1.93, 0], 0xfff9ea);
return g;
}
const staticWorkers = [
createWorker(0x4d9d92, mixGroup, [2.9, 0, 1.4], .88),
createWorker(0xd5a348, proofGroup, [2.9, 0, 2.1], .86),
createWorker(0xd66d48, bakeGroup, [3.35, 0, 2.3], .9),
createWorker(0x8a72b2, packGroup, [-2.4, 0, 2.4], .86)
];
const sharedWorkers = [
createWorker(0x486e68, hub, [-1.8, .7, .6], .82),
createWorker(0xbd7f58, hub, [0, .7, 1.9], .82),
createWorker(0x647ca8, hub, [1.8, .7, .6], .82)
];
// Crates, sacks, and floor props.
function crate(x, z, color = 0x9d7657) {
const g = new THREE.Group();
g.position.set(x, 0, z);
scene.add(g);
box(g, [1.6, .8, 1.4], [0, .65, 0], color);
box(g, [1.75, .13, 1.5], [0, 1.09, 0], 0xbc946d);
box(g, [.16, .85, 1.48], [-.55, .67, 0], 0x765b47);
box(g, [.16, .85, 1.48], [.55, .67, 0], 0x765b47);
}
crate(-14.2, 3.4);
crate(-14.1, 5.2, 0xb08761);
crate(14, -4.2, 0x7f9b8c);
crate(13.7, -2.6, 0xb68d5e);
// Abstract sacks.
[[-14.5, -9.5, 0xd9c497], [-12.9, -9.4, 0xe2d2aa]].forEach(([x, z, c]) => {
box(scene, [1.15, 1.25, 1.05], [x, .85, z], c);
box(scene, [.72, .25, .72], [x, 1.6, z], c);
box(scene, [.3, .25, .3], [x, 1.83, z], 0x7b6853);
});
// -------------------------------------------------------------------------
// Deterministic synthetic scheduling model.
// -------------------------------------------------------------------------
const horizon = 60;
const crewCapacity = 3;
const tasks = [
{ id: 'M-101', station: 'mix', arrival: 0, duration: 8 },
{ id: 'M-102', station: 'mix', arrival: 1, duration: 7 },
{ id: 'P-201', station: 'proof', arrival: 3, duration: 10 },
{ id: 'P-202', station: 'proof', arrival: 4, duration: 9 },
{ id: 'M-103', station: 'mix', arrival: 8, duration: 6 },
{ id: 'B-301', station: 'bake', arrival: 9, duration: 12 },
{ id: 'P-203', station: 'proof', arrival: 9, duration: 8 },
{ id: 'B-302', station: 'bake', arrival: 10, duration: 11 },
{ id: 'P-204', station: 'proof', arrival: 13, duration: 7 },
{ id: 'M-104', station: 'mix', arrival: 16, duration: 9 },
{ id: 'B-303', station: 'bake', arrival: 18, duration: 10 },
{ id: 'K-401', station: 'pack', arrival: 20, duration: 6 },
{ id: 'K-402', station: 'pack', arrival: 21, duration: 5 },
{ id: 'K-403', station: 'pack', arrival: 22, duration: 7 },
{ id: 'M-105', station: 'mix', arrival: 26, duration: 8 },
{ id: 'P-205', station: 'proof', arrival: 27, duration: 6 },
{ id: 'B-304', station: 'bake', arrival: 29, duration: 9 },
{ id: 'K-404', station: 'pack', arrival: 32, duration: 6 }
].sort((a, b) => a.arrival - b.arrival);
const resourceOccupancy = {};
Object.values(stations).forEach(station => {
resourceOccupancy[station.id] = Array(horizon).fill(0);
});
const crewOccupancy = Array(horizon).fill(0);
function fits(occupancy, capacity, start, duration) {
for (let t = start; t < start + duration; t++) {
if (t < 0 || t >= horizon || occupancy[t] >= capacity) return false;
}
return true;
}
tasks.forEach(task => {
const station = stations[task.station];
let start = task.arrival;
while (start <= horizon - task.duration) {
const resourceOk = fits(
resourceOccupancy[task.station],
station.capacity,
start,
task.duration
);
const crewOk = fits(
crewOccupancy,
crewCapacity,
start,
task.duration
);
if (resourceOk && crewOk) break;
start++;
}
task.start = Math.min(start, horizon - task.duration);
task.end = task.start + task.duration;
task.wait = task.start - task.arrival;
for (let t = task.start; t < task.end; t++) {
resourceOccupancy[task.station][t]++;
crewOccupancy[t]++;
}
});
const peakWait = Math.max(...tasks.map(task => task.wait));
// Task tokens float above their active station.
const taskTokens = tasks.map(task => {
const g = new THREE.Group();
const color = stations[task.station].color;
box(g, [.58, .58, .58], [0, 0, 0], color);
box(g, [.62, .13, .62], [0, .12, 0], 0xffefd1);
box(g, [.13, .62, .62], [0, 0, 0], 0xffefd1);
scene.add(g);
return g;
});
// -------------------------------------------------------------------------
// DOM schedule board.
// -------------------------------------------------------------------------
const gantt = document.getElementById('gantt');
const stationGrid = document.getElementById('stationGrid');
const simClock = document.getElementById('simClock');
const metricCrew = document.getElementById('metricCrew');
const metricQueue = document.getElementById('metricQueue');
const metricWait = document.getElementById('metricWait');
const statusLine = document.getElementById('statusLine');
const statusText = document.getElementById('statusText');
const stationOrder = ['mix', 'proof', 'bake', 'pack'];
const sortedForChart = [...tasks].sort((a, b) => {
const stationDifference = stationOrder.indexOf(a.station) - stationOrder.indexOf(b.station);
return stationDifference || a.arrival - b.arrival;
});
function buildGantt() {
let html = `
<div class="chart-head">
<div class="head-label">JOB</div>
<div class="time-axis">
${[0, 10, 20, 30, 40, 50, 60].map(t =>
`<span style="left:${t / horizon * 100}%">${t}</span>`
).join('')}
</div>
</div>
`;
sortedForChart.forEach(task => {
const station = stations[task.station];
const waitWidth = task.wait / horizon * 100;
const left = task.start / horizon * 100;
const width = task.duration / horizon * 100;
html += `
<div class="gantt-row" title="${task.id}: ${task.duration} synthetic minutes, ${task.wait} minute wait">
<div class="row-label">
<i style="background:${station.css}"></i>
<span>${task.id}</span>
</div>
<div class="track">
${task.wait > 0 ? `<div class="wait" style="left:${task.arrival / horizon * 100}%;width:${waitWidth}%"></div>` : ''}
<div class="bar" style="left:${left}%;width:${width}%;background:${station.css}">
<span>${task.duration}m</span>
</div>
</div>
</div>
`;
});
html += `
<div class="load-row">
<div class="load-label">CREW LOAD</div>
<div class="load-track" id="loadTrack">
${Array.from({ length: horizon }, (_, i) =>
`<i class="${crewOccupancy[i] >= 3 ? 'l3' : crewOccupancy[i] === 2 ? 'l2' : crewOccupancy[i] === 1 ? 'l1' : ''}"></i>`
).join('')}
</div>
</div>
<div class="playhead" id="playhead"></div>
`;
gantt.innerHTML = html;
}
function buildStationCards() {
stationGrid.innerHTML = stationOrder.map(id => {
const station = stations[id];
return `
<div class="station-card" id="card-${id}">
<div class="name"><i style="background:${station.css}"></i>${station.short}</div>
<strong id="active-${id}">0/${station.capacity}</strong>
<small id="queue-${id}">0 waiting</small>
<div class="mini-meter"><span id="meter-${id}" style="width:0%;background:${station.css}"></span></div>
</div>
`;
}).join('');
}
buildGantt();
buildStationCards();
// -------------------------------------------------------------------------
// Camera controls implemented directly.
// -------------------------------------------------------------------------
let pointerDown = false;
let pointerMoved = false;
let lastX = 0;
let lastY = 0;
renderer.domElement.addEventListener('pointerdown', event => {
pointerDown = true;
pointerMoved = false;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener('pointermove', event => {
if (!pointerDown) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
if (Math.abs(dx) + Math.abs(dy) > 2) pointerMoved = true;
desiredTheta -= dx * .006;
desiredPhi = THREE.MathUtils.clamp(desiredPhi + dy * .005, .16, 1.32);
lastX = event.clientX;
lastY = event.clientY;
});
renderer.domElement.addEventListener('pointerup', event => {
pointerDown = false;
if (!pointerMoved) selectByPointer(event);
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener('pointercancel', () => {
pointerDown = false;
});
renderer.domElement.addEventListener('wheel', event => {
event.preventDefault();
camera.zoom = THREE.MathUtils.clamp(
camera.zoom * Math.exp(-event.deltaY * .001),
.62,
2.2
);
camera.updateProjectionMatrix();
}, { passive: false });
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function selectByPointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(scene.children, true);
for (const hit of hits) {
let object = hit.object;
while (object) {
if (object.userData.station) {
focusStation(object.userData.station);
return;
}
object = object.parent;
}
}
}
function focusStation(id) {
document.querySelectorAll('.station-switcher button').forEach(button => {
button.classList.toggle('active', button.dataset.station === id);
});
if (id === 'all') {
desiredTarget.set(-1, 1, 0);
desiredTheta = .64;
desiredPhi = .79;
camera.zoom = .98;
} else {
desiredTarget.copy(stations[id].focus);
desiredTheta = .52;
desiredPhi = .76;
camera.zoom = 1.38;
}
camera.updateProjectionMatrix();
}
document.querySelectorAll('.station-switcher button').forEach(button => {
button.addEventListener('click', () => focusStation(button.dataset.station));
});
document.getElementById('overviewBtn').addEventListener('click', () => focusStation('all'));
document.getElementById('topBtn').addEventListener('click', () => {
focusStation('all');
desiredPhi = .16;
desiredTheta = 0;
camera.zoom = .92;
camera.updateProjectionMatrix();
});
let paused = false;
let speed = 1;
document.getElementById('pauseBtn').addEventListener('click', event => {
paused = !paused;
event.currentTarget.textContent = paused ? 'Resume clock' : 'Pause clock';
});
document.getElementById('speedBtn').addEventListener('click', event => {
speed = speed === 1 ? 2 : speed === 2 ? .5 : 1;
event.currentTarget.textContent = `${speed}× speed`;
});
document.getElementById('labelsBtn').addEventListener('click', event => {
labelGroup.visible = !labelGroup.visible;
event.currentTarget.textContent = labelGroup.visible ? 'Labels on' : 'Labels off';
});
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
const aspect = width / Math.max(height, 1);
const vertical = Math.max(24, 38 / aspect);
camera.left = -vertical * aspect / 2;
camera.right = vertical * aspect / 2;
camera.top = vertical / 2;
camera.bottom = -vertical / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
window.addEventListener('resize', resize);
resize();
// -------------------------------------------------------------------------
// Live simulation and rendering.
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let simElapsed = 0;
let lastUiUpdate = 0;
function pad(value) {
return String(value).padStart(2, '0');
}
function activeTasksAt(minute) {
return tasks.filter(task => minute >= task.start && minute < task.end);
}
function queuedTasksAt(minute) {
return tasks.filter(task => minute >= task.arrival && minute < task.start);
}
function updateUi(minute) {
const floorMinute = Math.floor(minute);
const active = activeTasksAt(floorMinute);
const queued = queuedTasksAt(floorMinute);
const activeCrew = active.length;
simClock.textContent = `${pad(floorMinute)}:${pad(Math.floor((minute % 1) * 60))}`;
metricCrew.textContent = `${activeCrew} / ${crewCapacity}`;
metricQueue.textContent = String(queued.length);
metricWait.textContent = `${peakWait}m`;
const hot = activeCrew >= crewCapacity || queued.length > 0;
statusLine.classList.toggle('hot', hot);
statusText.textContent = hot
? `${queued.length} waiting · shared crew ${activeCrew}/${crewCapacity}`
: `Shared crew is available · ${activeCrew}/${crewCapacity} active`;
stationOrder.forEach(id => {
const station = stations[id];
const stationActive = active.filter(task => task.station === id).length;
const stationQueue = queued.filter(task => task.station === id).length;
document.getElementById(`active-${id}`).textContent = `${stationActive}/${station.capacity}`;
document.getElementById(`queue-${id}`).textContent = `${stationQueue} waiting`;
document.getElementById(`meter-${id}`).style.width =
`${Math.min(100, stationActive / station.capacity * 100)}%`;
});
const playhead = document.getElementById('playhead');
if (playhead) {
const labelWidth = 94;
const trackWidth = Math.max(190, gantt.clientWidth - labelWidth - 8);
playhead.style.left = `${labelWidth + trackWidth * minute / horizon}px`;
}
}
function updateLamps(minute) {
const floorMinute = Math.floor(minute);
const active = activeTasksAt(floorMinute);
stationOrder.forEach(id => {
const station = stations[id];
const stationActive = active.filter(task => task.station === id).length;
statusLamps[id].forEach((lamp, index) => {
const occupied = index < stationActive;
const saturated = stationActive >= station.capacity;
lamp.material.color.setHex(occupied ? (saturated ? 0xdc554e : 0xe5ad43) : 0x65bd8f);
lamp.material.emissive.setHex(occupied ? (saturated ? 0x8b2724 : 0x8d641d) : 0x2f7650);
lamp.material.emissiveIntensity = occupied ? .8 : .22;
});
});
const crewActive = active.length;
crewLamps.forEach((lamp, index) => {
const occupied = index < crewActive;
const saturated = crewActive >= crewCapacity;
lamp.material.color.setHex(occupied ? (saturated ? 0xdc554e : 0xe5ad43) : 0x65bd8f);
lamp.material.emissive.setHex(occupied ? (saturated ? 0x8b2724 : 0x8d641d) : 0x2f7650);
lamp.material.emissiveIntensity = occupied ? .9 : .2;
});
}
function updateTokens(minute, time) {
const floorMinute = Math.floor(minute);
const active = activeTasksAt(floorMinute);
tasks.forEach((task, index) => {
const token = taskTokens[index];
const isActive = minute >= task.start && minute < task.end;
token.visible = isActive;
if (!isActive) return;
const station = stations[task.station];
const stationTasks = active.filter(item => item.station === task.station);
const localIndex = stationTasks.findIndex(item => item.id === task.id);
const offset = (localIndex - (stationTasks.length - 1) / 2) * .85;
const progress = THREE.MathUtils.clamp(
(minute - task.start) / task.duration, 0, 1
);
token.position.set(
station.position.x + offset,
2.05 + Math.sin(time * 3 + index) * .12,
station.position.z + 2.0
);
token.rotation.y = time * .7 + index;
token.scale.setScalar(.9 + Math.sin(progress * Math.PI) * .12);
});
}
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), .05);
const elapsed = clock.elapsedTime;
if (!paused) simElapsed += delta * speed;
const minute = (simElapsed % horizon);
cameraTheta += (desiredTheta - cameraTheta) * .09;
cameraPhi += (desiredPhi - cameraPhi) * .09;
cameraTarget.lerp(desiredTarget, .09);
const radius = 36;
camera.position.set(
cameraTarget.x + radius * Math.sin(cameraPhi) * Math.sin(cameraTheta),
cameraTarget.y + radius * Math.cos(cameraPhi),
cameraTarget.z + radius * Math.sin(cameraPhi) * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
mixers.forEach((whisk, index) => {
whisk.rotation.y = elapsed * (2.6 + index * .5);
});
movingPackages.forEach((pkg, index) => {
const progress = (elapsed * .12 + index / movingPackages.length) % 1;
const x = -11.6 + progress * 23.2;
pkg.position.set(x, 1.1, -.55);
pkg.rotation.y = Math.sin(elapsed + index) * .08;
});
sharedWorkers.forEach((worker, index) => {
const phase = elapsed * .42 + index * 2.1;
worker.position.x = Math.sin(phase) * .55;
worker.position.z = .7 + (index - 1) * .7 + Math.cos(phase) * .25;
worker.rotation.y = Math.atan2(Math.cos(phase), -Math.sin(phase));
});
staticWorkers.forEach((worker, index) => {
worker.position.y = Math.sin(elapsed * 2 + index) * .025;
});
const queued = queuedTasksAt(Math.floor(minute));
contentionBeacon.visible = queued.length > 0 || activeTasksAt(Math.floor(minute)).length >= crewCapacity;
contentionBeacon.rotation.y = elapsed * 1.2;
contentionBeacon.position.y = 4.8 + Math.sin(elapsed * 3) * .12;
updateTokens(minute, elapsed);
updateLamps(minute);
if (elapsed - lastUiUpdate > .15) {
updateUi(minute);
lastUiUpdate = elapsed;
}
renderer.render(scene, camera);
}
updateUi(0);
animate();
</script>
</body>
</html>
```