Prompt specification
Build or customize the Three.js 3D scene "Delivery Hub Growth Experiment" 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: Delivery Hub Growth Experiment
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/delivery-hub-growth-experiment-x3196
Scene Description Prompt:
A voxel delivery hub with adjustable arrivals and fixed doors, showing congestion above capacity. Three.js from cdnjs, one HTML file.
Working Three.js Starter (delivery-hub-growth-experiment-x3196):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Delivery Hub</title>
<style>
:root {
--bg: #07111c;
--panel: rgba(10, 23, 36, 0.88);
--border: rgba(148, 184, 208, 0.16);
--text: #e8f2f8;
--muted: #8ea8b8;
--cyan: #38d9c5;
--amber: #ffb84d;
--red: #ff5d68;
--safe: 44.85%;
--warn: 72%;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.glass {
background: var(--panel);
border: 1px solid var(--border);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
}
.brand {
position: fixed;
z-index: 5;
top: 22px;
left: 24px;
pointer-events: none;
}
.brand-row {
display: flex;
align-items: center;
gap: 12px;
}
.brand-mark {
position: relative;
width: 38px;
height: 38px;
border: 1px solid rgba(56, 217, 197, 0.45);
border-radius: 10px;
background: rgba(56, 217, 197, 0.08);
box-shadow: inset 0 0 20px rgba(56, 217, 197, 0.08);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
background: var(--cyan);
border-radius: 2px;
}
.brand-mark::before {
width: 16px;
height: 16px;
left: 10px;
top: 10px;
transform: rotate(45deg);
}
.brand-mark::after {
width: 5px;
height: 5px;
left: 16px;
top: 16px;
background: #d9fff8;
}
.brand h1 {
margin: 0;
font-size: 18px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.brand p {
margin: 5px 0 0;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.control-panel {
position: fixed;
z-index: 6;
left: 22px;
bottom: 22px;
width: 330px;
padding: 20px;
border-radius: 18px;
}
.eyebrow {
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin: 6px 0 20px;
font-size: 14px;
font-weight: 650;
}
.live-badge {
display: inline-flex;
align-items: center;
gap: 6px;
color: var(--cyan);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.live-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 10px currentColor;
animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
50% {
opacity: 0.35;
}
}
.rate-heading {
display: flex;
align-items: flex-end;
justify-content: space-between;
margin-bottom: 13px;
}
.rate-heading label {
font-size: 12px;
font-weight: 650;
}
.rate-value {
color: var(--cyan);
font-size: 24px;
font-weight: 760;
line-height: 1;
}
.rate-value small {
margin-left: 4px;
color: var(--muted);
font-size: 10px;
font-weight: 600;
text-transform: uppercase;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 0;
appearance: none;
-webkit-appearance: none;
border-radius: 999px;
background: linear-gradient(
to right,
var(--cyan) 0%,
var(--cyan) var(--safe),
var(--amber) var(--safe),
var(--amber) var(--warn),
var(--red) var(--warn),
var(--red) 100%
);
outline: none;
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 18px;
height: 18px;
appearance: none;
-webkit-appearance: none;
border: 4px solid #d9fff8;
border-radius: 50%;
background: #143c43;
box-shadow: 0 0 0 4px rgba(56, 217, 197, 0.15);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 4px solid #d9fff8;
border-radius: 50%;
background: #143c43;
box-shadow: 0 0 0 4px rgba(56, 217, 197, 0.15);
}
.range-labels {
display: flex;
justify-content: space-between;
margin-top: 9px;
color: #708a9a;
font-size: 9px;
font-weight: 650;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.capacity-marker {
position: relative;
height: 19px;
margin-top: 2px;
}
.capacity-marker::before {
content: "";
position: absolute;
left: var(--safe);
top: 4px;
height: 11px;
border-left: 1px dashed rgba(255, 184, 77, 0.65);
}
.capacity-marker span {
position: absolute;
left: var(--safe);
top: 8px;
transform: translateX(-50%);
color: var(--amber);
font-size: 8px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
white-space: nowrap;
}
.presets {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 15px;
}
.preset {
padding: 8px 5px;
color: var(--muted);
border: 1px solid var(--border);
border-radius: 8px;
background: rgba(255, 255, 255, 0.025);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.04em;
cursor: pointer;
transition: 160ms ease;
}
.preset:hover,
.preset.active {
color: var(--text);
border-color: rgba(56, 217, 197, 0.45);
background: rgba(56, 217, 197, 0.08);
}
.divider {
height: 1px;
margin: 18px 0;
background: var(--border);
}
.dock-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.dock-copy strong {
display: block;
margin-bottom: 4px;
font-size: 12px;
}
.dock-copy small {
color: var(--muted);
font-size: 10px;
}
.door-chips {
display: flex;
gap: 5px;
}
.door-chip {
display: grid;
width: 27px;
height: 27px;
place-items: center;
color: var(--cyan);
border: 1px solid rgba(56, 217, 197, 0.22);
border-radius: 6px;
background: rgba(56, 217, 197, 0.06);
font-size: 9px;
font-weight: 800;
}
.actions {
display: grid;
grid-template-columns: 1fr 1fr 0.8fr;
gap: 8px;
margin-top: 18px;
}
.action-button {
padding: 10px 8px;
color: var(--text);
border: 1px solid var(--border);
border-radius: 9px;
background: rgba(255, 255, 255, 0.035);
font-size: 10px;
font-weight: 700;
cursor: pointer;
transition: 160ms ease;
}
.action-button:hover {
border-color: rgba(56, 217, 197, 0.4);
background: rgba(56, 217, 197, 0.08);
}
.action-button.primary {
color: #041713;
border-color: var(--cyan);
background: var(--cyan);
}
.telemetry {
position: fixed;
z-index: 5;
top: 22px;
right: 22px;
width: 302px;
padding: 18px;
border-radius: 18px;
}
.status-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 16px;
}
.status-pill {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
color: var(--cyan);
border: 1px solid rgba(56, 217, 197, 0.24);
border-radius: 999px;
background: rgba(56, 217, 197, 0.07);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.status-pill.warning {
color: var(--amber);
border-color: rgba(255, 184, 77, 0.3);
background: rgba(255, 184, 77, 0.08);
}
.status-pill.danger {
color: var(--red);
border-color: rgba(255, 93, 104, 0.36);
background: rgba(255, 93, 104, 0.1);
}
.clock {
color: #718b9b;
font-variant-numeric: tabular-nums;
font-size: 10px;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.metric {
min-height: 74px;
padding: 12px;
border: 1px solid rgba(148, 184, 208, 0.1);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
}
.metric-label {
margin-bottom: 8px;
color: var(--muted);
font-size: 9px;
font-weight: 650;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric-value {
font-size: 23px;
font-weight: 740;
font-variant-numeric: tabular-nums;
line-height: 1;
}
.metric-value small {
color: var(--muted);
font-size: 9px;
font-weight: 600;
}
.metric.danger .metric-value {
color: var(--red);
}
.utilization {
margin-top: 17px;
}
.utilization-head {
display: flex;
justify-content: space-between;
margin-bottom: 8px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.utilization-head strong {
color: var(--text);
font-size: 10px;
}
.util-track {
height: 7px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.07);
}
.util-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: var(--cyan);
transition: width 180ms ease, background 180ms ease;
}
.status-detail {
min-height: 30px;
margin-top: 11px;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.door-queues {
display: grid;
gap: 8px;
margin-top: 10px;
}
.queue-row {
display: grid;
grid-template-columns: 27px 1fr 18px;
align-items: center;
gap: 8px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
}
.queue-track {
height: 5px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.055);
}
.queue-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: var(--cyan);
transition: width 180ms ease;
}
.queue-count {
text-align: right;
color: var(--text);
font-variant-numeric: tabular-nums;
}
.help {
position: fixed;
z-index: 4;
right: 24px;
bottom: 22px;
color: rgba(173, 198, 212, 0.55);
font-size: 9px;
font-weight: 650;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
.toast {
position: fixed;
z-index: 10;
left: 50%;
bottom: 28px;
padding: 11px 16px;
color: #fff;
border: 1px solid rgba(255, 93, 104, 0.35);
border-radius: 999px;
background: rgba(67, 16, 24, 0.92);
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
font-size: 11px;
font-weight: 650;
opacity: 0;
transform: translate(-50%, 12px);
transition: 220ms ease;
pointer-events: none;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 760px) {
.brand {
top: 12px;
left: 12px;
}
.brand h1 {
font-size: 14px;
}
.brand p {
display: none;
}
.telemetry {
top: 70px;
right: 10px;
width: 210px;
padding: 12px;
}
.metrics {
gap: 6px;
}
.metric {
min-height: 59px;
padding: 9px;
}
.metric-value {
font-size: 18px;
}
.door-queues {
display: none;
}
.status-detail {
display: none;
}
.control-panel {
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
padding: 15px;
}
.section-title,
.divider,
.dock-copy small,
.capacity-marker,
.help {
display: none;
}
.rate-heading {
margin-bottom: 10px;
}
.presets {
margin-top: 10px;
}
.dock-row {
margin-top: 14px;
}
.actions {
margin-top: 12px;
}
}
@media (max-height: 690px) and (min-width: 761px) {
.control-panel {
padding: 15px;
}
.section-title {
margin-bottom: 12px;
}
.divider {
margin: 12px 0;
}
.presets,
.actions {
margin-top: 10px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="brand">
<div class="brand-row">
<div class="brand-mark"></div>
<div>
<h1>Voxel Delivery Hub</h1>
<p>Live logistics simulation</p>
</div>
</div>
</header>
<section class="control-panel glass" aria-label="Simulation controls">
<div class="eyebrow">Flow control</div>
<div class="section-title">
<span>Arrival rate</span>
<span class="live-badge"><span class="live-dot"></span>Live</span>
</div>
<div class="rate-heading">
<label for="arrivalRate">Incoming parcels</label>
<div class="rate-value">
<span id="rateValue">126</span>
<small>/ min</small>
</div>
</div>
<input
id="arrivalRate"
type="range"
min="30"
max="360"
step="6"
value="126"
aria-label="Arrival rate in parcels per minute"
/>
<div class="range-labels">
<span>30 / min</span>
<span>360 / min</span>
</div>
<div class="capacity-marker"><span>Capacity</span></div>
<div class="presets" aria-label="Arrival rate presets">
<button class="preset" data-rate="90">Calm</button>
<button class="preset active" data-rate="126">Balanced</button>
<button class="preset" data-rate="240">Surge</button>
</div>
<div class="divider"></div>
<div class="dock-row">
<div class="dock-copy">
<strong>Dock topology</strong>
<small>Fixed at 4 service doors</small>
</div>
<div class="door-chips" aria-label="Four fixed service doors">
<span class="door-chip">01</span>
<span class="door-chip">02</span>
<span class="door-chip">03</span>
<span class="door-chip">04</span>
</div>
</div>
<div class="actions">
<button id="pauseButton" class="action-button primary">Pause</button>
<button id="resetButton" class="action-button">Reset</button>
<button id="viewButton" class="action-button">View</button>
</div>
</section>
<aside class="telemetry glass" aria-label="Live hub telemetry">
<div class="status-row">
<span id="statusPill" class="status-pill">
<span class="live-dot"></span>
<span id="statusText">Nominal</span>
</span>
<span id="clock" class="clock">00:00</span>
</div>
<div class="metrics">
<div class="metric">
<div class="metric-label">Arrival rate</div>
<div class="metric-value"><span id="arrivalMetric">126</span> <small>/m</small></div>
</div>
<div class="metric">
<div class="metric-label">Fixed capacity</div>
<div class="metric-value"><span id="capacityMetric">178</span> <small>/m</small></div>
</div>
<div class="metric" id="backlogMetricBox">
<div class="metric-label">Backlog</div>
<div class="metric-value"><span id="backlogMetric">8</span> <small>parcels</small></div>
</div>
<div class="metric">
<div class="metric-label">Processed</div>
<div class="metric-value"><span id="processedMetric">0</span></div>
</div>
</div>
<div class="utilization">
<div class="utilization-head">
<span>Capacity utilization</span>
<strong id="utilizationText">71%</strong>
</div>
<div class="util-track">
<div id="utilizationFill" class="util-fill"></div>
</div>
</div>
<div id="statusDetail" class="status-detail">
Flow is below the fixed dock capacity.
</div>
<div class="door-queues">
<div class="queue-row">
<span>DOCK 01</span>
<div class="queue-track"><div id="queue0" class="queue-fill"></div></div>
<span id="queueCount0" class="queue-count">0</span>
</div>
<div class="queue-row">
<span>DOCK 02</span>
<div class="queue-track"><div id="queue1" class="queue-fill"></div></div>
<span id="queueCount1" class="queue-count">0</span>
</div>
<div class="queue-row">
<span>DOCK 03</span>
<div class="queue-track"><div id="queue2" class="queue-fill"></div></div>
<span id="queueCount2" class="queue-count">0</span>
</div>
<div class="queue-row">
<span>DOCK 04</span>
<div class="queue-track"><div id="queue3" class="queue-fill"></div></div>
<span id="queueCount3" class="queue-count">0</span>
</div>
</div>
</aside>
<div class="help">Drag to orbit · Scroll to zoom · Double-click to reset view</div>
<div id="toast" class="toast">Congestion detected — the backlog is now growing.</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Configuration
// -------------------------------------------------------------------------
const DOOR_COUNT = 4;
const SERVICE_SECONDS = 1.35;
const CAPACITY_PER_SECOND = DOOR_COUNT / SERVICE_SECONDS;
const CAPACITY_PER_MINUTE = Math.round(CAPACITY_PER_SECOND * 60);
const MAX_ACTIVE_PARCELS = 24;
const DOOR_X = [-7.5, -2.5, 2.5, 7.5];
const sceneHost = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111c);
scene.fog = new THREE.Fog(0x07111c, 38, 72);
const camera = new THREE.PerspectiveCamera(
36,
window.innerWidth / window.innerHeight,
0.1,
120
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
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;
sceneHost.appendChild(renderer.domElement);
// -------------------------------------------------------------------------
// Camera controls, implemented directly without external addons
// -------------------------------------------------------------------------
const cameraState = {
yaw: 0.62,
pitch: 0.58,
distance: 39,
target: new THREE.Vector3(0, 1.8, 0)
};
function updateCamera() {
const { yaw, pitch, distance, target } = cameraState;
camera.position.set(
target.x + distance * Math.cos(pitch) * Math.sin(yaw),
target.y + distance * Math.sin(pitch),
target.z + distance * Math.cos(pitch) * Math.cos(yaw)
);
camera.lookAt(target);
}
function resetCamera() {
cameraState.yaw = 0.62;
cameraState.pitch = 0.58;
cameraState.distance = 39;
cameraState.target.set(0, 1.8, 0);
updateCamera();
}
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraState.yaw -= dx * 0.005;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.004,
0.25,
1.08
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance + event.deltaY * 0.025,
25,
58
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
updateCamera();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xa9dcff, 0x14202a, 1.55));
const sun = new THREE.DirectionalLight(0xffefd2, 2.5);
sun.position.set(13, 24, 17);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.0003;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x40a8ff, 1.1);
rimLight.position.set(-18, 11, -12);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Materials and geometry helpers
// -------------------------------------------------------------------------
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.74,
metalness: 0.05,
...options
});
}
function addBox(width, height, depth, x, y, z, material, parent = scene, cast = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(width, height, depth), material);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(radius, height, x, y, z, material, parent = scene, segments = 12) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, segments),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeTextTexture(text, options = {}) {
const {
foreground = "#dffaff",
background = "rgba(0,0,0,0)",
border = null,
fontSize = 70,
letterSpacing = 5
} = options;
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
if (background !== "rgba(0,0,0,0)") {
context.fillStyle = background;
context.fillRect(0, 0, canvas.width, canvas.height);
}
if (border) {
context.strokeStyle = border;
context.lineWidth = 8;
context.strokeRect(8, 8, canvas.width - 16, canvas.height - 16);
}
context.fillStyle = foreground;
context.font = `700 ${fontSize}px ui-sans-serif, system-ui, sans-serif`;
context.textAlign = "center";
context.textBaseline = "middle";
if (context.letterSpacing !== undefined) {
context.letterSpacing = `${letterSpacing}px`;
}
context.fillText(text, canvas.width / 2, canvas.height / 2 + 3);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
return texture;
}
function makeLabel(text, width, height, options = {}) {
const texture = makeTextTexture(text, options);
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide
});
return new THREE.Mesh(new THREE.PlaneGeometry(width, height), material);
}
const mat = {
platform: standardMaterial(0x111f2b),
platformEdge: standardMaterial(0x1d3342),
gridLine: new THREE.LineBasicMaterial({
color: 0x284152,
transparent: true,
opacity: 0.42
}),
road: standardMaterial(0x0b1721),
warehouse: standardMaterial(0x2b4050),
warehouseDark: standardMaterial(0x1a2b38),
warehouseTrim: standardMaterial(0x3f5969),
roof: standardMaterial(0x38505f, { metalness: 0.18 }),
window: standardMaterial(0x71d8ef, {
emissive: 0x1f7184,
emissiveIntensity: 0.55,
roughness: 0.3
}),
belt: standardMaterial(0x152b35, {
emissive: 0x09212a,
emissiveIntensity: 0.5
}),
beltEdge: standardMaterial(0x29424f),
beltStripe: standardMaterial(0x2ccdb9, {
emissive: 0x167d72,
emissiveIntensity: 0.55
}),
yellow: standardMaterial(0xf4b849),
dark: standardMaterial(0x0a1219),
rubber: standardMaterial(0x10161b),
white: standardMaterial(0xd7e8ec),
teal: standardMaterial(0x2ac7b7),
overflow: standardMaterial(0x481e29, {
emissive: 0x5b101c,
emissiveIntensity: 0.28
})
};
// -------------------------------------------------------------------------
// Platform and yard
// -------------------------------------------------------------------------
addBox(34, 0.9, 26, 0, -0.48, 0, mat.platform);
addBox(34.2, 0.2, 26.2, 0, -0.98, 0, mat.platformEdge);
const grid = new THREE.GridHelper(32, 32, 0x2a4b5d, 0x1b3442);
grid.position.y = 0.005;
grid.material.transparent = true;
grid.material.opacity = 0.42;
scene.add(grid);
// Road strips
addBox(33, 0.025, 2.4, 0, 0.03, 10.6, mat.road, scene, false);
addBox(2.1, 0.025, 24, 15.0, 0.035, 0.7, mat.road, scene, false);
for (let x = -14; x < 15; x += 2.8) {
addBox(1.1, 0.03, 0.08, x, 0.06, 10.6, mat.white, scene, false);
}
// -------------------------------------------------------------------------
// Warehouse
// -------------------------------------------------------------------------
addBox(22, 6.2, 10, 0, 3.1, -5, mat.warehouse);
addBox(23, 0.48, 11, 0, 6.35, -5, mat.roof);
addBox(23.4, 0.2, 11.4, 0, 6.7, -5, mat.warehouseTrim);
// Upper rooftop modules
addBox(4.8, 1.1, 3.1, -5.7, 7.15, -6.1, mat.warehouseDark);
addBox(3.1, 0.9, 2.4, 4.8, 7.05, -6.5, mat.warehouseTrim);
addBox(1.5, 0.6, 1.8, 8.6, 7.05, -4.0, mat.warehouseDark);
// Rooftop vents
for (const x of [-8.1, -3.3, 1.5, 6.3]) {
addCylinder(0.46, 0.65, x, 7.15, -3.7, mat.warehouseTrim);
addBox(0.95, 0.08, 0.95, x, 7.51, -3.7, mat.dark);
}
// Front windows
for (const x of [-9.8, 9.8]) {
for (const y of [2.3, 4.15]) {
addBox(0.75, 1.0, 0.06, x, y, 0.08, mat.window, scene, false);
}
}
const warehouseSign = makeLabel("VOXEL // HUB", 8.8, 1.3, {
foreground: "#cffff7",
background: "rgba(8,25,34,0.95)",
border: "rgba(56,217,197,0.45)",
fontSize: 76,
letterSpacing: 11
});
warehouseSign.position.set(0, 4.85, 0.12);
scene.add(warehouseSign);
// Warning beacon
const beaconMaterial = standardMaterial(0x4a1b22, {
emissive: 0xff394f,
emissiveIntensity: 0.08
});
const beacon = addBox(0.42, 0.42, 0.42, 10.6, 7.15, -1.2, beaconMaterial);
addCylinder(0.08, 0.9, 10.6, 6.55, -1.2, mat.dark);
// Door data
const doors = DOOR_X.map((x, index) => {
const opening = addBox(
3.0,
3.65,
0.16,
x,
1.87,
0.09,
standardMaterial(0x071017)
);
addBox(0.22, 4.05, 0.32, x - 1.61, 2.0, 0.2, mat.warehouseTrim);
addBox(0.22, 4.05, 0.32, x + 1.61, 2.0, 0.2, mat.warehouseTrim);
addBox(3.42, 0.22, 0.32, x, 3.95, 0.2, mat.warehouseTrim);
addBox(3.3, 0.12, 0.65, x, 0.11, 0.4, mat.dark);
for (const side of [-1, 1]) {
addBox(0.28, 0.7, 0.25, x + side * 1.76, 0.72, 0.25, mat.yellow);
}
const numberLabel = makeLabel(`0${index + 1}`, 0.8, 0.45, {
foreground: "#8ee9df",
fontSize: 84
});
numberLabel.position.set(x, 4.3, 0.19);
scene.add(numberLabel);
const indicatorMaterial = standardMaterial(0x38d9c5, {
emissive: 0x38d9c5,
emissiveIntensity: 1.2
});
addBox(0.26, 0.26, 0.16, x + 1.25, 3.53, 0.31, indicatorMaterial);
return {
index,
x,
opening,
queue: [],
serviceEntity: null,
indicatorMaterial
};
});
// Red warning wash in front of the building
const congestionWashMaterial = new THREE.MeshBasicMaterial({
color: 0xff304c,
transparent: true,
opacity: 0,
depthWrite: false,
side: THREE.DoubleSide
});
const congestionWash = new THREE.Mesh(
new THREE.PlaneGeometry(22, 4),
congestionWashMaterial
);
congestionWash.rotation.x = -Math.PI / 2;
congestionWash.position.set(0, 0.075, 1.75);
scene.add(congestionWash);
// -------------------------------------------------------------------------
// Conveyors
// -------------------------------------------------------------------------
const conveyorCenterX = -2.85;
const conveyorLength = 25.7;
const conveyorZ = 6.5;
addBox(conveyorLength, 0.34, 1.8, conveyorCenterX, 0.17, conveyorZ, mat.belt);
addBox(conveyorLength, 0.28, 0.12, conveyorCenterX, 0.42, conveyorZ - 0.88, mat.beltEdge);
addBox(conveyorLength, 0.28, 0.12, conveyorCenterX, 0.42, conveyorZ + 0.88, mat.beltEdge);
const mainSlats = [];
for (let i = 0; i < 34; i++) {
const slat = addBox(
0.09,
0.035,
1.57,
-15.4 + i * 0.76,
0.365,
conveyorZ,
mat.beltStripe,
scene,
false
);
mainSlats.push(slat);
}
const branchSlats = [];
for (const doorX of DOOR_X) {
addBox(1.58, 0.28, 6.25, doorX, 0.14, 3.25, mat.belt);
addBox(0.12, 0.28, 6.25, doorX - 0.79, 0.4, 3.25, mat.beltEdge);
addBox(0.12, 0.28, 6.25, doorX + 0.79, 0.4, 3.25, mat.beltEdge);
const slats = [];
for (let i = 0; i < 8; i++) {
const slat = addBox(
1.35,
0.035,
0.08,
doorX,
0.31,
0.38 + i * 0.82,
mat.beltStripe,
scene,
false
);
slats.push(slat);
}
branchSlats.push(slats);
}
const inboundLabel = makeLabel("INBOUND", 4.1, 0.75, {
foreground: "#578092",
fontSize: 84,
letterSpacing: 10
});
inboundLabel.rotation.x = -Math.PI / 2;
inboundLabel.position.set(-11.4, 0.075, 8.0);
scene.add(inboundLabel);
// Overflow holding area
addBox(8.1, 0.055, 4.4, -11.9, 0.04, 9.45, mat.overflow, scene, false);
addBox(8.2, 0.08, 0.1, -11.9, 0.075, 7.25, mat.overflow, scene, false);
addBox(8.2, 0.08, 0.1, -11.9, 0.075, 11.65, mat.overflow, scene, false);
const overflowLabel = makeLabel("OVERFLOW HOLD", 6.8, 0.65, {
foreground: "#ff7e86",
fontSize: 72,
letterSpacing: 8
});
overflowLabel.rotation.x = -Math.PI / 2;
overflowLabel.position.set(-11.9, 0.082, 12.0);
scene.add(overflowLabel);
// -------------------------------------------------------------------------
// Parcel assets
// -------------------------------------------------------------------------
const crateBodyGeometry = new THREE.BoxGeometry(1, 0.78, 1);
const crateTapeGeometry = new THREE.BoxGeometry(0.16, 0.82, 1.03);
const crateLabelGeometry = new THREE.BoxGeometry(0.42, 0.035, 0.3);
const parcelMaterials = [
standardMaterial(0x2da9c7),
standardMaterial(0x48c7aa),
standardMaterial(0xf2aa43),
standardMaterial(0x5d7fe8),
standardMaterial(0xd96965)
];
const tapeMaterial = standardMaterial(0xe6d5a7);
const parcelLabelMaterial = standardMaterial(0xf1f5ea);
function makeParcel(materialIndex = 0) {
const group = new THREE.Group();
const body = new THREE.Mesh(
crateBodyGeometry,
parcelMaterials[materialIndex % parcelMaterials.length]
);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const tape = new THREE.Mesh(crateTapeGeometry, tapeMaterial);
tape.castShadow = true;
group.add(tape);
const label = new THREE.Mesh(crateLabelGeometry, parcelLabelMaterial);
label.position.set(0.24, 0.405, 0.15);
label.castShadow = true;
group.add(label);
return group;
}
// -------------------------------------------------------------------------
// Forklift decoration
// -------------------------------------------------------------------------
const forklift = new THREE.Group();
scene.add(forklift);
addBox(1.8, 0.55, 1.35, 0, 0.55, 0, mat.yellow, forklift);
addBox(0.85, 0.8, 1.15, -0.35, 1.12, 0, mat.yellow, forklift);
addBox(0.75, 0.55, 1.02, -0.35, 1.52, 0, mat.dark, forklift);
addBox(0.16, 2.25, 0.16, 0.82, 1.25, -0.48, mat.dark, forklift);
addBox(0.16, 2.25, 0.16, 0.82, 1.25, 0.48, mat.dark, forklift);
addBox(0.12, 0.12, 1.45, 1.02, 0.28, 0, mat.dark, forklift);
addBox(0.85, 0.09, 0.14, 1.38, 0.24, -0.43, mat.dark, forklift);
addBox(0.85, 0.09, 0.14, 1.38, 0.24, 0.43, mat.dark, forklift);
for (const x of [-0.58, 0.58]) {
for (const z of [-0.7, 0.7]) {
const wheel = addCylinder(0.34, 0.22, x, 0.35, z, mat.rubber, forklift);
wheel.rotation.x = Math.PI / 2;
}
}
forklift.position.set(12.8, 0.03, 8.2);
forklift.rotation.y = Math.PI * 0.5;
// -------------------------------------------------------------------------
// Simulation state
// -------------------------------------------------------------------------
let arrivalPerMinute = 126;
let arrivalPerSecond = arrivalPerMinute / 60;
let running = true;
let simulationTime = 0;
let spawnAccumulator = 0;
let entityId = 0;
let totalArrived = 0;
let totalProcessed = 0;
let activeCount = 0;
let wasCongested = false;
const overflowParcels = [];
function chooseDoor() {
let best = doors[0];
for (const door of doors) {
if (door.queue.length < best.queue.length) best = door;
}
return best;
}
function createActiveParcel(door, seedPosition = null) {
const id = entityId++;
const group = makeParcel(id);
scene.add(group);
const mainOffset = ((id % 3) - 1) * 0.3;
const dockOffset = ((id % 3) - 1) * 0.25;
const entity = {
id,
group,
door,
state: "x",
progress: 0,
mainOffset,
dockOffset,
materialIndex: id
};
if (seedPosition) {
entity.state = "z";
group.position.set(
door.x + dockOffset,
0.4,
seedPosition.z
);
} else {
group.position.set(-15.25, 0.4, conveyorZ + mainOffset);
}
door.queue.push(entity);
activeCount++;
return entity;
}
function spawnArrival() {
totalArrived++;
if (activeCount < MAX_ACTIVE_PARCELS) {
createActiveParcel(chooseDoor());
}
}
function removeEntity(entity) {
const index = entity.door.queue.indexOf(entity);
if (index !== -1) entity.door.queue.splice(index, 1);
scene.remove(entity.group);
activeCount--;
}
function seedInitialFlow() {
for (let i = 0; i < 8; i++) {
const door = doors[i % DOOR_COUNT];
const row = Math.floor(i / DOOR_COUNT);
createActiveParcel(door, { z: 1.62 + row * 0.83 });
totalArrived++;
}
}
function resetSimulation() {
for (const door of doors) {
for (const entity of [...door.queue]) {
scene.remove(entity.group);
}
door.queue.length = 0;
door.serviceEntity = null;
}
for (const parcel of overflowParcels) scene.remove(parcel);
overflowParcels.length = 0;
simulationTime = 0;
spawnAccumulator = 0;
entityId = 0;
totalArrived = 0;
totalProcessed = 0;
activeCount = 0;
wasCongested = false;
}
function updateDoors(dt) {
for (const door of doors) {
if (door.serviceEntity) {
const entity = door.serviceEntity;
entity.progress += dt / SERVICE_SECONDS;
const progress = Math.min(entity.progress, 1);
const eased = progress * progress * (3 - 2 * progress);
entity.group.position.z = THREE.MathUtils.lerp(1.62, -0.35, eased);
const shrink = progress > 0.78
? 1 - ((progress - 0.78) / 0.22) * 0.3
: 1;
entity.group.scale.setScalar(shrink);
if (entity.progress >= 1) {
removeEntity(entity);
totalProcessed++;
door.serviceEntity = null;
}
}
const waiting = door.queue.filter((entity) => entity !== door.serviceEntity);
waiting.forEach((entity, index) => {
if (entity.state === "x") {
const targetX = door.x + entity.dockOffset;
const distance = targetX - entity.group.position.x;
if (Math.abs(distance) < 0.04) {
entity.group.position.x = targetX;
entity.state = "z";
} else {
entity.group.position.x += Math.sign(distance) * Math.min(
Math.abs(distance),
5.2 * dt
);
}
}
if (entity.state === "z") {
const slotOffset = door.serviceEntity ? 1 : 0;
const targetZ = 1.62 + (index + slotOffset) * 0.83;
const distance = targetZ - entity.group.position.z;
if (Math.abs(distance) < 0.025) {
entity.group.position.z = targetZ;
} else {
entity.group.position.z += Math.sign(distance) * Math.min(
Math.abs(distance),
3.9 * dt
);
}
if (
!door.serviceEntity &&
index === 0 &&
entity.group.position.z <= 1.64
) {
entity.state = "service";
entity.progress = 0;
door.serviceEntity = entity;
}
}
});
}
}
function updateSimulation(dt) {
simulationTime += dt;
spawnAccumulator += dt * arrivalPerSecond;
while (spawnAccumulator >= 1) {
spawnArrival();
spawnAccumulator -= 1;
}
updateDoors(dt);
}
// -------------------------------------------------------------------------
// Overflow visualization
// -------------------------------------------------------------------------
function syncOverflowParcels() {
const backlog = Math.max(0, totalArrived - totalProcessed);
const overflowCount = Math.max(0, backlog - MAX_ACTIVE_PARCELS);
const target = Math.min(48, overflowCount);
while (overflowParcels.length < target) {
const index = overflowParcels.length;
const parcel = makeParcel(index + 3);
const layer = Math.floor(index / 24);
const cell = index % 24;
const column = cell % 6;
const row = Math.floor(cell / 6);
parcel.position.set(
-14.85 + column * 1.18,
0.47 + layer * 0.82,
8.45 + row * 0.98
);
parcel.rotation.y = ((index % 3) - 1) * 0.035;
scene.add(parcel);
overflowParcels.push(parcel);
}
while (overflowParcels.length > target) {
const parcel = overflowParcels.pop();
scene.remove(parcel);
}
}
// -------------------------------------------------------------------------
// UI and telemetry
// -------------------------------------------------------------------------
const ui = {
rateSlider: document.getElementById("arrivalRate"),
rateValue: document.getElementById("rateValue"),
arrivalMetric: document.getElementById("arrivalMetric"),
capacityMetric: document.getElementById("capacityMetric"),
backlogMetric: document.getElementById("backlogMetric"),
backlogMetricBox: document.getElementById("backlogMetricBox"),
processedMetric: document.getElementById("processedMetric"),
statusPill: document.getElementById("statusPill"),
statusText: document.getElementById("statusText"),
statusDetail: document.getElementById("statusDetail"),
utilizationText: document.getElementById("utilizationText"),
utilizationFill: document.getElementById("utilizationFill"),
clock: document.getElementById("clock"),
pauseButton: document.getElementById("pauseButton"),
resetButton: document.getElementById("resetButton"),
viewButton: document.getElementById("viewButton"),
toast: document.getElementById("toast"),
presetButtons: [...document.querySelectorAll(".preset")],
queues: doors.map((_, index) => ({
fill: document.getElementById(`queue${index}`),
count: document.getElementById(`queueCount${index}`)
}))
};
ui.capacityMetric.textContent = CAPACITY_PER_MINUTE;
function setArrivalRate(value, announce = false) {
arrivalPerMinute = Number(value);
arrivalPerSecond = arrivalPerMinute / 60;
ui.rateSlider.value = String(arrivalPerMinute);
ui.rateValue.textContent = String(arrivalPerMinute);
ui.arrivalMetric.textContent = String(arrivalPerMinute);
for (const button of ui.presetButtons) {
button.classList.toggle(
"active",
Math.abs(Number(button.dataset.rate) - arrivalPerMinute) < 1
);
}
if (announce) showToast(`Arrival rate set to ${arrivalPerMinute} parcels per minute.`);
}
ui.rateSlider.addEventListener("input", (event) => {
setArrivalRate(event.target.value);
});
for (const button of ui.presetButtons) {
button.addEventListener("click", () => {
setArrivalRate(button.dataset.rate, true);
});
}
ui.pauseButton.addEventListener("click", () => {
running = !running;
ui.pauseButton.textContent = running ? "Pause" : "Resume";
});
ui.resetButton.addEventListener("click", () => {
resetSimulation();
ui.pauseButton.textContent = "Pause";
running = true;
showToast("Simulation reset.");
});
ui.viewButton.addEventListener("click", resetCamera);
let toastTimer = null;
function showToast(message) {
ui.toast.textContent = message;
ui.toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => ui.toast.classList.remove("show"), 2600);
}
function updateUI() {
const ratio = arrivalPerSecond / CAPACITY_PER_SECOND;
const backlog = Math.max(0, totalArrived - totalProcessed);
const congested = ratio > 1.01;
const recovering = backlog > 3 && ratio <= 1.01;
let status = "Nominal";
let color = "#38d9c5";
let detail = "Flow is below the fixed dock capacity.";
if (congested) {
status = "Congested";
color = "#ff5d68";
const excess = Math.round(arrivalPerMinute - CAPACITY_PER_MINUTE);
detail = `${excess} parcels/min above capacity. Backlog is growing.`;
} else if (recovering) {
status = "Recovering";
color = "#ffb84d";
detail = "Arrivals are within capacity while the existing backlog drains.";
} else if (ratio > 0.82) {
status = "Loaded";
color = "#ffb84d";
detail = "Near fixed dock capacity; little spare service headroom.";
}
ui.statusText.textContent = status;
ui.statusPill.style.color = color;
ui.statusPill.style.borderColor = `${color}55`;
ui.statusPill.style.background = `${color}12`;
ui.statusDetail.textContent = detail;
ui.backlogMetric.textContent = String(backlog);
ui.processedMetric.textContent = String(totalProcessed);
ui.backlogMetricBox.classList.toggle("danger", congested);
const utilization = Math.round(ratio * 100);
ui.utilizationText.textContent = `${utilization}%`;
ui.utilizationFill.style.width = `${Math.min(utilization, 100)}%`;
ui.utilizationFill.style.background = color;
const minutes = Math.floor(simulationTime / 60);
const seconds = Math.floor(simulationTime % 60);
ui.clock.textContent =
`${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
for (let i = 0; i < doors.length; i++) {
const count = doors[i].queue.length;
const fill = ui.queues[i].fill;
fill.style.width = `${Math.min(100, (count / 6) * 100)}%`;
fill.style.background = congested ? "#ff5d68" : count > 3 ? "#ffb84d" : "#38d9c5";
ui.queues[i].count.textContent = String(count);
}
if (congested && !wasCongested) {
showToast("Congestion detected — the backlog is now growing.");
}
wasCongested = congested;
// Scene warning colors
const warningIntensity = congested ? 0.75 + Math.sin(simulationTime * 6) * 0.25 : 0.08;
beaconMaterial.emissiveIntensity = warningIntensity;
beacon.scale.setScalar(congested ? 1 + Math.sin(simulationTime * 6) * 0.08 : 1);
congestionWashMaterial.opacity = congested ? 0.075 + Math.sin(simulationTime * 4) * 0.025 : 0;
mat.belt.emissive.setHex(congested ? 0x6f1723 : 0x09212a);
mat.belt.emissiveIntensity = congested ? 0.9 : 0.5;
mat.beltStripe.emissive.setHex(congested ? 0xff334d : 0x167d72);
mat.beltStripe.emissiveIntensity = congested ? 1.2 : 0.55;
mat.overflow.emissiveIntensity = congested ? 0.65 : 0.28;
for (const door of doors) {
const doorColor = congested ? 0xff4055 : door.queue.length ? 0xffb84d : 0x38d9c5;
door.indicatorMaterial.color.setHex(doorColor);
door.indicatorMaterial.emissive.setHex(doorColor);
door.indicatorMaterial.emissiveIntensity = door.queue.length ? 1.45 : 0.75;
}
}
// -------------------------------------------------------------------------
// Ambient animation
// -------------------------------------------------------------------------
function animateConveyors(dt) {
for (const slat of mainSlats) {
slat.position.x += dt * 2.6;
if (slat.position.x > 10.05) slat.position.x -= 25.6;
}
for (const slats of branchSlats) {
for (const slat of slats) {
slat.position.z -= dt * 2.1;
if (slat.position.z < 0.32) slat.position.z += 6.56;
}
}
}
function animateAmbient() {
forklift.position.z = 8.1 + Math.sin(simulationTime * 0.42) * 0.55;
forklift.position.y = 0.03 + Math.sin(simulationTime * 1.7) * 0.008;
}
// -------------------------------------------------------------------------
// Main loop
// -------------------------------------------------------------------------
seedInitialFlow();
setArrivalRate(arrivalPerMinute);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (running) {
updateSimulation(dt);
animateConveyors(dt);
}
animateAmbient();
syncOverflowParcels();
updateUI();
renderer.render(scene, camera);
}
animate();
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space" && event.target === document.body) {
event.preventDefault();
ui.pauseButton.click();
}
});
</script>
</body>
</html>
```