Prompt specification
Build or customize the Three.js 3D scene "Three Chutes With Unequal Gates" 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: Three Chutes With Unequal Gates
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/three-chutes-with-unequal-gates-x3181
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing production bottlenecks and queues. Construct three sequential bead chutes with visible gate timers. Make the narrowest processing stage geometrically distinct while keeping the bead count conserved across containers. A 3D cutaway view.
Working Three.js Starter (three-chutes-with-unequal-gates-x3181):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Production Bottlenecks & Queues</title>
<style>
:root {
color-scheme: dark;
--bg: #071019;
--panel: rgba(8, 20, 31, 0.88);
--border: rgba(142, 194, 218, 0.2);
--text: #eaf6ff;
--muted: #87a6b7;
--cyan: #55dcff;
--amber: #ffb44d;
--violet: #b38cff;
--green: #63e6a7;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.overlay {
position: fixed;
inset: 0;
pointer-events: none;
}
.topbar {
position: absolute;
top: 24px;
left: 28px;
right: 28px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20px;
}
.eyebrow {
margin-bottom: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 43px);
line-height: 0.96;
letter-spacing: -0.045em;
font-weight: 760;
text-transform: uppercase;
text-shadow: 0 6px 30px rgba(0, 0, 0, 0.5);
}
.subtitle {
margin-top: 11px;
max-width: 560px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
letter-spacing: 0.04em;
}
.metric {
min-width: 230px;
padding: 15px 18px;
border: 1px solid var(--border);
border-radius: 13px;
background: var(--panel);
backdrop-filter: blur(14px);
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.28);
}
.metric-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 16px;
}
.metric strong {
font-size: 29px;
font-weight: 720;
letter-spacing: -0.04em;
}
.metric small {
color: var(--muted);
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.conservation {
margin-top: 8px;
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.conservation.bad {
color: #ff617d;
}
.timer-panel {
position: absolute;
left: 28px;
bottom: 28px;
display: grid;
grid-template-columns: repeat(3, minmax(175px, 205px));
gap: 10px;
}
.stage-card {
position: relative;
overflow: hidden;
padding: 14px 15px 13px;
border: 1px solid var(--border);
border-radius: 12px;
background: var(--panel);
backdrop-filter: blur(14px);
box-shadow: 0 15px 45px rgba(0, 0, 0, 0.26);
}
.stage-card::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 3px;
background: var(--stage-color);
box-shadow: 0 0 20px var(--stage-color);
}
.stage-head {
display: flex;
justify-content: space-between;
gap: 10px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.stage-head .status {
color: var(--stage-color);
}
.stage-name {
margin-top: 9px;
font-size: 13px;
font-weight: 760;
letter-spacing: 0.035em;
text-transform: uppercase;
}
.stage-value {
margin-top: 5px;
font-variant-numeric: tabular-nums;
font-size: 27px;
font-weight: 650;
letter-spacing: -0.045em;
}
.progress {
height: 3px;
margin-top: 9px;
overflow: hidden;
border-radius: 3px;
background: rgba(255, 255, 255, 0.07);
}
.progress > div {
width: 0;
height: 100%;
border-radius: inherit;
background: var(--stage-color);
box-shadow: 0 0 12px var(--stage-color);
transition: width 80ms linear;
}
.ledger {
position: absolute;
right: 28px;
bottom: 28px;
width: 215px;
padding: 15px 17px;
border: 1px solid var(--border);
border-radius: 12px;
background: var(--panel);
backdrop-filter: blur(14px);
box-shadow: 0 15px 45px rgba(0, 0, 0, 0.26);
}
.ledger-title {
margin-bottom: 11px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.ledger-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 7px;
color: #c7dbe7;
font-size: 11px;
}
.ledger-row strong {
color: var(--text);
font-variant-numeric: tabular-nums;
}
.ledger-rule {
height: 1px;
margin: 11px 0;
background: var(--border);
}
.controls {
position: absolute;
top: 146px;
right: 28px;
display: flex;
gap: 7px;
pointer-events: auto;
}
button {
appearance: none;
border: 1px solid var(--border);
border-radius: 8px;
padding: 9px 12px;
background: rgba(9, 23, 34, 0.84);
color: #dff4ff;
font: inherit;
font-size: 10px;
font-weight: 760;
letter-spacing: 0.1em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(10px);
}
button:hover {
border-color: rgba(85, 220, 255, 0.6);
color: white;
background: rgba(17, 43, 57, 0.92);
}
.camera-hint {
position: absolute;
right: 28px;
bottom: 208px;
color: rgba(172, 203, 218, 0.62);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.cutaway-badge {
position: absolute;
top: 28px;
left: 50%;
transform: translateX(-50%);
padding: 8px 11px;
border: 1px solid rgba(85, 220, 255, 0.22);
border-radius: 999px;
background: rgba(8, 22, 32, 0.68);
color: #9cd5e6;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
@media (max-width: 900px) {
.topbar {
top: 17px;
left: 17px;
right: 17px;
}
.metric {
min-width: 170px;
}
.subtitle,
.cutaway-badge,
.camera-hint {
display: none;
}
.controls {
top: 108px;
right: 17px;
}
.timer-panel {
left: 17px;
right: 17px;
bottom: 17px;
grid-template-columns: repeat(3, 1fr);
}
.ledger {
display: none;
}
.stage-card {
padding: 12px;
}
}
@media (max-width: 600px) {
.metric {
position: absolute;
top: 78px;
right: 0;
min-width: 145px;
padding: 10px 12px;
}
.metric strong {
font-size: 23px;
}
.metric small {
font-size: 8px;
}
.timer-panel {
gap: 6px;
}
.stage-card {
min-width: 0;
padding: 10px;
}
.stage-head {
font-size: 7px;
}
.stage-name {
font-size: 10px;
}
.stage-value {
font-size: 20px;
}
.controls {
top: 146px;
}
}
</style>
</head>
<body>
<canvas id="scene"></canvas>
<div class="overlay">
<div class="topbar">
<div>
<div class="eyebrow">Manufacturing telemetry / Line 03</div>
<h1>Production<br />Bottlenecks</h1>
<div class="subtitle">
Live serial-transfer simulation. Three timed gates feed a conserved
population of beads through wide, constrained, and accumulation stages.
</div>
</div>
<div class="metric">
<div class="metric-row">
<strong id="bead-total">42</strong>
<small>Beads tracked</small>
</div>
<div id="conservation" class="conservation">● Population conserved</div>
</div>
</div>
<div class="cutaway-badge">3D process cutaway</div>
<div class="controls">
<button id="pause-button" type="button">Pause</button>
<button id="reset-button" type="button">Reset flow</button>
<button id="camera-button" type="button">Reset view</button>
</div>
<div class="timer-panel">
<div class="stage-card" id="stage-card-0" style="--stage-color: #ffb44d">
<div class="stage-head">
<span>Gate 01</span>
<span class="status" id="stage-status-0">ARMED</span>
</div>
<div class="stage-name">Wide feed</div>
<div class="stage-value" id="stage-value-0">04.0s</div>
<div class="progress"><div id="stage-progress-0"></div></div>
</div>
<div class="stage-card" id="stage-card-1" style="--stage-color: #55dcff">
<div class="stage-head">
<span>Gate 02</span>
<span class="status" id="stage-status-1">ARMED</span>
</div>
<div class="stage-name">Narrow / 0.68m</div>
<div class="stage-value" id="stage-value-1">03.2s</div>
<div class="progress"><div id="stage-progress-1"></div></div>
</div>
<div class="stage-card" id="stage-card-2" style="--stage-color: #b38cff">
<div class="stage-head">
<span>Gate 03</span>
<span class="status" id="stage-status-2">ARMED</span>
</div>
<div class="stage-name">Accumulation</div>
<div class="stage-value" id="stage-value-2">05.0s</div>
<div class="progress"><div id="stage-progress-2"></div></div>
</div>
</div>
<div class="ledger">
<div class="ledger-title">Container ledger</div>
<div class="ledger-row"><span>Source hopper</span><strong id="count-source">42</strong></div>
<div class="ledger-row"><span>Buffer A</span><strong id="count-buffer-a">0</strong></div>
<div class="ledger-row"><span>Buffer B</span><strong id="count-buffer-b">0</strong></div>
<div class="ledger-row"><span>Finished bin</span><strong id="count-finished">0</strong></div>
<div class="ledger-rule"></div>
<div class="ledger-row"><span>In transit</span><strong id="count-transit">0</strong></div>
<div class="ledger-row"><span>Population change</span><strong id="count-delta">0</strong></div>
</div>
<div class="camera-hint">Drag: orbit · Wheel: zoom · Right drag: pan</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Core setup
// -------------------------------------------------------------------------
const BEAD_COUNT = 42;
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071019);
scene.fog = new THREE.FogExp2(0x071019, 0.018);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemi = new THREE.HemisphereLight(0xbfe9ff, 0x152030, 1.7);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xffffff, 3.0);
key.position.set(-7, 14, 9);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -18;
key.shadow.camera.right = 18;
key.shadow.camera.top = 12;
key.shadow.camera.bottom = -12;
key.shadow.camera.near = 1;
key.shadow.camera.far = 45;
key.shadow.bias = -0.00025;
scene.add(key);
const rim = new THREE.DirectionalLight(0x55dcff, 1.2);
rim.position.set(10, 7, -8);
scene.add(rim);
const warm = new THREE.PointLight(0xffa64d, 24, 16, 2);
warm.position.set(-8, 6, 3);
scene.add(warm);
const cyan = new THREE.PointLight(0x38d9ff, 34, 12, 2);
cyan.position.set(-1.8, 5.3, 0.5);
scene.add(cyan);
const violet = new THREE.PointLight(0xa678ff, 22, 13, 2);
violet.position.set(6, 4.7, 1.2);
scene.add(violet);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x101d27,
roughness: 0.78,
metalness: 0.18
});
const floor = new THREE.Mesh(
new THREE.BoxGeometry(27.5, 0.45, 10.8),
floorMaterial
);
floor.position.set(-1.2, -0.38, -1.0);
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(27, 27, 0x315060, 0x1a2b37);
grid.position.set(-1.2, -0.145, -1.0);
grid.material.opacity = 0.36;
grid.material.transparent = true;
scene.add(grid);
const wallMaterial = new THREE.MeshStandardMaterial({
color: 0x10212d,
roughness: 0.72,
metalness: 0.22
});
const backWall = new THREE.Mesh(
new THREE.BoxGeometry(27.5, 5.4, 0.18),
wallMaterial
);
backWall.position.set(-1.2, 2.35, -5.75);
backWall.receiveShadow = true;
scene.add(backWall);
const leftWall = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 2.0, 9.8),
wallMaterial
);
leftWall.position.set(-14.85, 0.65, -1.0);
scene.add(leftWall);
const cutMaterial = new THREE.MeshStandardMaterial({
color: 0xffa54d,
emissive: 0x512400,
emissiveIntensity: 0.55,
roughness: 0.55,
metalness: 0.35
});
const frontCut = new THREE.Mesh(
new THREE.BoxGeometry(27.5, 0.12, 0.13),
cutMaterial
);
frontCut.position.set(-1.2, -0.13, 4.38);
scene.add(frontCut);
const steel = new THREE.MeshStandardMaterial({
color: 0x526776,
roughness: 0.38,
metalness: 0.75
});
const darkSteel = new THREE.MeshStandardMaterial({
color: 0x172733,
roughness: 0.45,
metalness: 0.72
});
function cylinderBetween(a, b, radius, material, segments = 12) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, segments),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
// Factory service pipes along the back wall.
for (const [y, color] of [
[3.45, 0x376a7a],
[2.85, 0x8b4e28],
[2.25, 0x44616c]
]) {
const pipeMaterial = new THREE.MeshStandardMaterial({
color,
roughness: 0.45,
metalness: 0.65
});
cylinderBetween(
new THREE.Vector3(-13.8, y, -5.37),
new THREE.Vector3(11.4, y, -5.37),
0.09,
pipeMaterial
);
}
// -------------------------------------------------------------------------
// Canvas-based world labels and timer displays
// -------------------------------------------------------------------------
function roundedRect(ctx, x, y, w, h, r) {
const radius = Math.min(r, w * 0.5, h * 0.5);
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.arcTo(x + w, y, x + w, y + h, radius);
ctx.arcTo(x + w, y + h, x, y + h, radius);
ctx.arcTo(x, y + h, x, y, radius);
ctx.arcTo(x, y, x + w, y, radius);
ctx.closePath();
}
function createBoard({
width = 512,
height = 170,
color = "#55dcff",
scaleWidth = 2.8,
scaleHeight = 0.95
} = {}) {
const boardCanvas = document.createElement("canvas");
boardCanvas.width = width;
boardCanvas.height = height;
const ctx = boardCanvas.getContext("2d");
const texture = new THREE.CanvasTexture(boardCanvas);
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(scaleWidth, scaleHeight, 1);
sprite.renderOrder = 20;
return { canvas: boardCanvas, ctx, texture, sprite };
}
function drawBoardBackground(ctx, color, width, height) {
ctx.clearRect(0, 0, width, height);
ctx.save();
ctx.shadowColor = "rgba(0,0,0,0.55)";
ctx.shadowBlur = 18;
ctx.shadowOffsetY = 7;
roundedRect(ctx, 7, 7, width - 14, height - 14, 18);
ctx.fillStyle = "rgba(6, 17, 25, 0.94)";
ctx.fill();
ctx.restore();
roundedRect(ctx, 7, 7, width - 14, height - 14, 18);
ctx.strokeStyle = color;
ctx.globalAlpha = 0.78;
ctx.lineWidth = 3;
ctx.stroke();
ctx.globalAlpha = 1;
ctx.fillStyle = color;
roundedRect(ctx, 7, 7, 11, height - 14, 5);
ctx.fill();
}
function makeStaticLabel(
title,
subtitle,
color = "#91c7da",
scaleWidth = 2.6,
scaleHeight = 0.8
) {
const board = createBoard({
color,
scaleWidth,
scaleHeight
});
const { ctx, canvas: c, texture } = board;
drawBoardBackground(ctx, color, c.width, c.height);
ctx.textAlign = "left";
ctx.fillStyle = "#edfaff";
ctx.font = "700 31px system-ui";
ctx.fillText(title, 34, 65);
ctx.fillStyle = color;
ctx.font = "700 20px system-ui";
ctx.fillText(subtitle, 35, 106);
texture.needsUpdate = true;
return board.sprite;
}
const factorySign = makeStaticLabel(
"SERIAL BEAD LINE / 03",
"CUTAWAY PROCESS VIEW",
"#55dcff",
5.4,
1.0
);
factorySign.position.set(-2.3, 4.65, -5.45);
scene.add(factorySign);
// -------------------------------------------------------------------------
// Containers
// -------------------------------------------------------------------------
function makeContainer(name, position, size, accent) {
const group = new THREE.Group();
group.position.copy(position);
scene.add(group);
const glass = new THREE.MeshPhysicalMaterial({
color: accent,
transparent: true,
opacity: 0.15,
roughness: 0.15,
metalness: 0.05,
transmission: 0.15,
depthWrite: false,
side: THREE.DoubleSide
});
const edge = new THREE.LineBasicMaterial({
color: accent,
transparent: true,
opacity: 0.8
});
const bottom = new THREE.Mesh(
new THREE.BoxGeometry(size.x, 0.12, size.z),
new THREE.MeshStandardMaterial({
color: 0x213744,
roughness: 0.45,
metalness: 0.55
})
);
bottom.position.y = -size.y * 0.5;
bottom.receiveShadow = true;
group.add(bottom);
const front = new THREE.Mesh(
new THREE.BoxGeometry(size.x, size.y, 0.045),
glass
);
front.position.z = size.z * 0.5;
group.add(front);
const back = front.clone();
back.position.z = -size.z * 0.5;
group.add(back);
const side = new THREE.Mesh(
new THREE.BoxGeometry(0.045, size.y, size.z),
glass
);
side.position.x = size.x * 0.5;
group.add(side);
const otherSide = side.clone();
otherSide.position.x = -size.x * 0.5;
group.add(otherSide);
const outline = new THREE.LineSegments(
new THREE.EdgesGeometry(
new THREE.BoxGeometry(size.x, size.y, size.z)
),
edge
);
group.add(outline);
const board = createBoard({
color: `#${new THREE.Color(accent).getHexString()}`,
scaleWidth: 2.25,
scaleHeight: 0.72
});
board.sprite.position.set(0, size.y * 0.5 + 0.55, size.z * 0.5 + 0.15);
group.add(board.sprite);
const container = {
name,
group,
size,
accent,
items: [],
board
};
return container;
}
const source = makeContainer(
"SOURCE HOPPER",
new THREE.Vector3(-12.0, 6.0, -2.2),
new THREE.Vector3(1.8, 1.8, 3.0),
0x5ccfff
);
const bufferA = makeContainer(
"BUFFER A",
new THREE.Vector3(-5.45, 4.65, -2.2),
new THREE.Vector3(1.45, 1.5, 2.8),
0xffb44d
);
const bufferB = makeContainer(
"BUFFER B",
new THREE.Vector3(1.85, 3.72, -2.2),
new THREE.Vector3(1.35, 1.4, 2.8),
0x55dcff
);
const finished = makeContainer(
"FINISHED BIN",
new THREE.Vector3(9.4, 2.55, -2.2),
new THREE.Vector3(1.9, 2.0, 3.1),
0xb38cff
);
const containers = [source, bufferA, bufferB, finished];
function updateContainerBoard(container) {
const { ctx, canvas: c, texture } = container.board;
const color = `#${new THREE.Color(container.accent).getHexString()}`;
drawBoardBackground(ctx, color, c.width, c.height);
ctx.textAlign = "left";
ctx.fillStyle = "#e9f7ff";
ctx.font = "700 28px system-ui";
ctx.fillText(container.name, 33, 62);
ctx.fillStyle = color;
ctx.font = "700 32px system-ui";
ctx.fillText(`COUNT ${String(container.items.length).padStart(2, "0")}`, 33, 111);
texture.needsUpdate = true;
}
function layoutContainer(container) {
const columns = 4;
const rows = 6;
const perLayer = columns * rows;
container.items.forEach((bead, index) => {
const layer = Math.floor(index / perLayer);
const inLayer = index % perLayer;
const col = inLayer % columns;
const row = Math.floor(inLayer / columns);
const x = (col - (columns - 1) * 0.5) *
(container.size.x / (columns + 0.7));
const z = (row - (rows - 1) * 0.5) *
(container.size.z / (rows + 0.7));
const y = -container.size.y * 0.5 + 0.22 + layer * 0.27;
bead.mesh.position.set(
container.group.position.x + x,
container.group.position.y + y,
container.group.position.z + z
);
});
}
// Elevated source hopper supports.
for (const x of [-12.65, -11.35]) {
cylinderBetween(
new THREE.Vector3(x, -0.1, -2.2),
new THREE.Vector3(x, 5.05, -2.2),
0.10,
steel
);
}
// -------------------------------------------------------------------------
// Three sequential chute stages
// -------------------------------------------------------------------------
const stageDefinitions = [
{
name: "01 / WIDE FEED",
shortName: "WIDE FEED",
color: 0xffb44d,
css: "#ffb44d",
start: new THREE.Vector3(-10.9, 5.65, -2.2),
end: new THREE.Vector3(-6.6, 5.0, -2.2),
width: 1.75,
hold: 4.0,
open: 1.6,
speed: 0.30,
feed: 0.22,
narrow: false
},
{
name: "02 / PRECISION",
shortName: "PRECISION",
color: 0x55dcff,
css: "#55dcff",
start: new THREE.Vector3(-4.65, 4.75, -2.2),
end: new THREE.Vector3(1.05, 4.05, -2.2),
width: 0.68,
hold: 3.2,
open: 1.0,
speed: 0.11,
feed: 0.62,
narrow: true
},
{
name: "03 / ACCUMULATION",
shortName: "ACCUMULATION",
color: 0xb38cff,
css: "#b38cff",
start: new THREE.Vector3(2.65, 3.8, -2.2),
end: new THREE.Vector3(8.25, 3.0, -2.2),
width: 1.6,
hold: 5.0,
open: 1.8,
speed: 0.24,
feed: 0.32,
narrow: false
}
];
function makeStage(def, index) {
const direction = new THREE.Vector3().subVectors(def.end, def.start);
const length = direction.length();
const unitDirection = direction.clone().normalize();
const normal = new THREE.Vector3(
-unitDirection.y,
unitDirection.x,
0
).normalize();
const quaternion = new THREE.Quaternion().setFromUnitVectors(
new THREE.Vector3(1, 0, 0),
unitDirection
);
const group = new THREE.Group();
group.position.copy(def.start).add(def.end).multiplyScalar(0.5);
group.quaternion.copy(quaternion);
scene.add(group);
const bedMaterial = new THREE.MeshStandardMaterial({
color: def.narrow ? 0x183b49 : 0x293945,
roughness: 0.42,
metalness: 0.68,
emissive: def.color,
emissiveIntensity: def.narrow ? 0.12 : 0.035
});
const bed = new THREE.Mesh(
new THREE.BoxGeometry(length, 0.16, def.width),
bedMaterial
);
bed.castShadow = true;
bed.receiveShadow = true;
group.add(bed);
const railMaterial = new THREE.MeshStandardMaterial({
color: def.color,
emissive: def.color,
emissiveIntensity: def.narrow ? 0.55 : 0.22,
roughness: 0.28,
metalness: 0.68
});
for (const side of [-1, 1]) {
const rail = new THREE.Mesh(
new THREE.BoxGeometry(length, 0.34, 0.10),
railMaterial
);
rail.position.set(0, 0.19, side * (def.width * 0.5 + 0.045));
rail.castShadow = true;
group.add(rail);
}
// Gate assembly.
const gateT = 0.82;
const gatePosition = new THREE.Vector3().lerpVectors(
def.start,
def.end,
gateT
);
const gateGroup = new THREE.Group();
gateGroup.position.copy(gatePosition);
gateGroup.quaternion.copy(quaternion);
scene.add(gateGroup);
const gateBar = new THREE.Mesh(
new THREE.BoxGeometry(0.12, 0.86, def.width + 0.16),
new THREE.MeshStandardMaterial({
color: def.color,
emissive: def.color,
emissiveIntensity: 0.48,
roughness: 0.3,
metalness: 0.72
})
);
gateBar.position.y = 0.55;
gateBar.castShadow = true;
gateGroup.add(gateBar);
for (const side of [-1, 1]) {
const post = new THREE.Mesh(
new THREE.BoxGeometry(0.20, 1.55, 0.16),
steel
);
post.position.set(0, 0.61, side * (def.width * 0.5 + 0.16));
post.castShadow = true;
gateGroup.add(post);
}
const led = new THREE.Mesh(
new THREE.SphereGeometry(0.10, 12, 8),
new THREE.MeshBasicMaterial({ color: 0xff526c })
);
led.position.set(0.03, 1.47, 0);
gateGroup.add(led);
// Structural legs.
for (const t of [0.18, 0.78]) {
const p = new THREE.Vector3().lerpVectors(def.start, def.end, t);
for (const side of [-1, 1]) {
cylinderBetween(
new THREE.Vector3(p.x, -0.1, p.z + side * def.width * 0.48),
new THREE.Vector3(p.x, p.y - 0.18, p.z + side * def.width * 0.48),
0.075,
steel
);
}
}
// The middle stage is an enclosed, narrow precision channel.
if (def.narrow) {
const tunnelMaterial = new THREE.MeshPhysicalMaterial({
color: 0x62e4ff,
transparent: true,
opacity: 0.10,
roughness: 0.1,
metalness: 0.0,
transmission: 0.18,
depthWrite: false
});
const tunnel = new THREE.Mesh(
new THREE.BoxGeometry(1.55, 0.92, def.width + 0.44),
tunnelMaterial
);
tunnel.position.set(-0.15, 0.48, 0);
group.add(tunnel);
const tunnelEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(
new THREE.BoxGeometry(1.55, 0.92, def.width + 0.44)
),
new THREE.LineBasicMaterial({
color: 0x55dcff,
transparent: true,
opacity: 0.8
})
);
tunnelEdges.position.copy(tunnel.position);
group.add(tunnelEdges);
for (const side of [-1, 1]) {
const gantry = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 1.8, 0.15),
railMaterial
);
gantry.position.set(-0.15, 0.85, side * 0.68);
gantry.castShadow = true;
group.add(gantry);
}
const gantryTop = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 0.15, 1.50),
railMaterial
);
gantryTop.position.set(-0.15, 1.69, 0);
group.add(gantryTop);
const scanner = new THREE.Mesh(
new THREE.BoxGeometry(0.045, 0.035, def.width + 0.12),
new THREE.MeshBasicMaterial({
color: 0x9af3ff,
transparent: true,
opacity: 0.95
})
);
scanner.position.set(-0.15, 0.33, 0);
group.add(scanner);
const precisionLabel = makeStaticLabel(
"BOTTLENECK",
"0.68 m PRECISION CHANNEL",
"#55dcff",
2.65,
0.72
);
const labelPosition = new THREE.Vector3()
.lerpVectors(def.start, def.end, 0.50)
.add(new THREE.Vector3(0, 1.25, 1.55));
precisionLabel.position.copy(labelPosition);
scene.add(precisionLabel);
}
// In-world timer board.
const timerBoard = createBoard({
color: def.css,
scaleWidth: 2.55,
scaleHeight: 0.91
});
const timerPosition = new THREE.Vector3()
.lerpVectors(def.start, def.end, 0.47)
.add(new THREE.Vector3(0, 2.03, 1.10));
timerBoard.sprite.position.copy(timerPosition);
scene.add(timerBoard.sprite);
return {
...def,
index,
group,
gateGroup,
gateBar,
led,
normal,
length,
gateT,
timerBoard,
phase: "hold",
remaining: def.hold,
openAmount: 0,
feedTimer: 0.08 + index * 0.08,
chuteBeads: [],
serial: 0
};
}
const stages = stageDefinitions.map(makeStage);
// Flow arrows on the floor.
for (const x of [-8.4, 4.6]) {
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.25, 0.8, 3),
new THREE.MeshBasicMaterial({
color: 0x3b8399,
transparent: true,
opacity: 0.45
})
);
arrow.rotation.x = Math.PI * 0.5;
arrow.position.set(x, 0.01, 2.55);
scene.add(arrow);
}
// -------------------------------------------------------------------------
// Beads: one fixed population, moved between containers and chutes
// -------------------------------------------------------------------------
const beadGeometry = new THREE.SphereGeometry(0.115, 14, 10);
const beadMaterials = [
0xffb44d,
0x55dcff,
0xff6684,
0xb38cff,
0xd9f4ff
].map(color =>
new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.22,
roughness: 0.25,
metalness: 0.38
})
);
let beads = [];
function createBead(index) {
const mesh = new THREE.Mesh(
beadGeometry,
beadMaterials[index % beadMaterials.length]
);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return {
id: index,
mesh,
location: "source",
t: 0,
laneOffset: 0
};
}
function resetSimulation() {
for (const bead of beads) {
scene.remove(bead.mesh);
}
beads = [];
for (const container of containers) {
container.items.length = 0;
}
for (let i = 0; i < BEAD_COUNT; i++) {
const bead = createBead(i);
beads.push(bead);
source.items.push(bead);
}
for (const stage of stages) {
stage.chuteBeads.length = 0;
stage.phase = "hold";
stage.remaining = stage.hold;
stage.openAmount = 0;
stage.feedTimer = 0.08 + stage.index * 0.08;
stage.serial = 0;
stage.gateBar.position.y = 0.55;
stage.led.material.color.setHex(0xff526c);
}
for (const container of containers) {
layoutContainer(container);
updateContainerBoard(container);
}
}
resetSimulation();
// -------------------------------------------------------------------------
// Gate and queue simulation
// -------------------------------------------------------------------------
function updateGates(dt) {
for (const stage of stages) {
if (stage.phase === "hold") {
stage.remaining -= dt;
if (stage.remaining <= 0) {
stage.phase = "open";
stage.remaining = stage.open;
}
} else {
stage.remaining -= dt;
if (stage.remaining <= 0) {
stage.phase = "hold";
stage.remaining = stage.hold;
}
}
const target = stage.phase === "open" ? 1 : 0;
stage.openAmount +=
(target - stage.openAmount) * Math.min(1, dt * 8);
stage.gateBar.position.y = THREE.MathUtils.lerp(
0.55,
1.48,
stage.openAmount
);
stage.led.material.color.setHex(
stage.phase === "open" ? 0x63e6a7 : 0xff526c
);
}
}
function previousContainer(stageIndex) {
return [source, bufferA, bufferB][stageIndex];
}
function nextContainer(stageIndex) {
return [bufferA, bufferB, finished][stageIndex];
}
function feedStages(dt) {
for (const stage of stages) {
stage.feedTimer -= dt;
if (
stage.feedTimer <= 0 &&
stage.chuteBeads.length < 22
) {
const feed = previousContainer(stage.index);
if (feed.items.length > 0) {
const bead = feed.items.shift();
bead.location = `chute-${stage.index}`;
bead.t = 0;
const laneCount = stage.narrow ? 1 : 2;
bead.laneOffset =
(stage.serial % laneCount - (laneCount - 1) * 0.5) *
(stage.narrow ? 0 : 0.17);
stage.serial++;
stage.chuteBeads.push(bead);
layoutContainer(feed);
updateContainerBoard(feed);
}
stage.feedTimer = stage.feed;
}
}
}
function updateChutes(dt) {
for (const stage of stages) {
const sorted = stage.chuteBeads
.slice()
.sort((a, b) => b.t - a.t);
const spacing = stage.narrow ? 0.27 : 0.29;
let leadT = Infinity;
for (const bead of sorted) {
// Beads already past the gate continue into the next container.
const gateLimit =
stage.phase === "open" || bead.t >= stage.gateT
? 1.045
: stage.gateT;
const allowed = Math.min(
gateLimit,
Math.max(0, leadT - spacing)
);
bead.t = Math.min(
bead.t + stage.speed * dt,
allowed
);
leadT = bead.t;
}
const finishedBeads = stage.chuteBeads.filter(
bead => bead.t >= 0.999
);
if (finishedBeads.length > 0) {
const destination = nextContainer(stage.index);
for (const bead of finishedBeads) {
const indexInStage = stage.chuteBeads.indexOf(bead);
if (indexInStage !== -1) {
stage.chuteBeads.splice(indexInStage, 1);
}
bead.location = `container-${stage.index + 1}`;
destination.items.push(bead);
}
layoutContainer(destination);
updateContainerBoard(destination);
}
}
}
function updateBeadPositions() {
for (const stage of stages) {
for (const bead of stage.chuteBeads) {
const position = new THREE.Vector3().lerpVectors(
stage.start,
stage.end,
bead.t
);
position.addScaledVector(stage.normal, 0.235);
position.z += bead.laneOffset;
bead.mesh.position.copy(position);
}
}
}
// -------------------------------------------------------------------------
// UI and in-world timer boards
// -------------------------------------------------------------------------
const stageValueElements = [
document.querySelector("#stage-value-0"),
document.querySelector("#stage-value-1"),
document.querySelector("#stage-value-2")
];
const stageStatusElements = [
document.querySelector("#stage-status-0"),
document.querySelector("#stage-status-1"),
document.querySelector("#stage-status-2")
];
const stageProgressElements = [
document.querySelector("#stage-progress-0"),
document.querySelector("#stage-progress-1"),
document.querySelector("#stage-progress-2")
];
function drawStageTimer(stage) {
const { ctx, canvas: c, texture } = stage.timerBoard;
const width = c.width;
const height = c.height;
drawBoardBackground(ctx, stage.css, width, height);
ctx.textAlign = "left";
ctx.fillStyle = "#eaf8ff";
ctx.font = "700 27px system-ui";
ctx.fillText(stage.name, 34, 51);
const isOpen = stage.phase === "open";
const value = Math.max(0, stage.remaining).toFixed(1);
ctx.fillStyle = isOpen ? "#63e6a7" : stage.css;
ctx.font = "750 50px system-ui";
ctx.fillText(`${value}s`, 33, 112);
ctx.textAlign = "right";
ctx.font = "800 20px system-ui";
ctx.fillText(isOpen ? "OPEN" : "HOLD", width - 33, 49);
ctx.fillStyle = "#91adbc";
ctx.font = "700 15px system-ui";
ctx.fillText(isOpen ? "RELEASING" : "GATE ARMED", width - 33, 111);
texture.needsUpdate = true;
}
function updateUI() {
for (const stage of stages) {
const value = Math.max(0, stage.remaining).toFixed(1);
stageValueElements[stage.index].textContent = `${value}s`;
stageStatusElements[stage.index].textContent =
stage.phase === "open" ? "RELEASING" : "ARMED";
stageStatusElements[stage.index].style.color =
stage.phase === "open" ? "#63e6a7" : stage.css;
const progress =
stage.phase === "hold"
? 1 - stage.remaining / stage.hold
: 1 - stage.remaining / stage.open;
stageProgressElements[stage.index].style.width =
`${THREE.MathUtils.clamp(progress, 0, 1) * 100}%`;
drawStageTimer(stage);
}
const inTransit = stages.reduce(
(sum, stage) => sum + stage.chuteBeads.length,
0
);
const counted =
source.items.length +
bufferA.items.length +
bufferB.items.length +
finished.items.length +
inTransit;
document.querySelector("#bead-total").textContent = counted;
document.querySelector("#count-source").textContent = source.items.length;
document.querySelector("#count-buffer-a").textContent = bufferA.items.length;
document.querySelector("#count-buffer-b").textContent = bufferB.items.length;
document.querySelector("#count-finished").textContent = finished.items.length;
document.querySelector("#count-transit").textContent = inTransit;
document.querySelector("#count-delta").textContent =
counted - BEAD_COUNT > 0
? `+${counted - BEAD_COUNT}`
: counted - BEAD_COUNT;
const conservation = document.querySelector("#conservation");
conservation.classList.toggle("bad", counted !== BEAD_COUNT);
conservation.textContent =
counted === BEAD_COUNT
? "● Population conserved"
: "● Conservation error";
}
// -------------------------------------------------------------------------
// Direct camera controls: orbit, zoom, pan
// -------------------------------------------------------------------------
const orbit = {
theta: 0.34,
phi: 1.08,
radius: 27,
target: new THREE.Vector3(-1.25, 3.1, -2.1)
};
const defaultOrbit = {
theta: orbit.theta,
phi: orbit.phi,
radius: orbit.radius,
target: orbit.target.clone()
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.cos(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.sin(orbit.theta)
);
camera.lookAt(orbit.target);
}
updateCamera();
let dragging = false;
let panMode = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", event => {
dragging = true;
panMode = event.button === 2;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (panMode) {
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
0
);
const up = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
1
);
const scale = orbit.radius * 0.0013;
orbit.target.addScaledVector(right, -dx * scale);
orbit.target.addScaledVector(up, dy * scale);
} else {
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.005,
0.38,
1.42
);
}
updateCamera();
});
function stopDragging(event) {
dragging = false;
panMode = false;
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
14,
42
);
updateCamera();
},
{ passive: false }
);
document.querySelector("#camera-button").addEventListener("click", () => {
orbit.theta = defaultOrbit.theta;
orbit.phi = defaultOrbit.phi;
orbit.radius = defaultOrbit.radius;
orbit.target.copy(defaultOrbit.target);
updateCamera();
});
// -------------------------------------------------------------------------
// Controls and animation loop
// -------------------------------------------------------------------------
let paused = false;
let uiAccumulator = 0;
document.querySelector("#pause-button").addEventListener("click", event => {
paused = !paused;
event.currentTarget.textContent = paused ? "Resume" : "Pause";
});
document.querySelector("#reset-button").addEventListener("click", () => {
resetSimulation();
updateUI();
});
window.addEventListener("resize", () => {
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
camera.aspect = window.innerWidth / window.innerHeight;
camera.fov = window.innerWidth < 700 ? 52 : 43;
camera.updateProjectionMatrix();
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (!paused) {
updateGates(dt);
feedStages(dt);
updateChutes(dt);
}
updateBeadPositions();
uiAccumulator += dt;
if (uiAccumulator >= 0.08) {
uiAccumulator = 0;
updateUI();
}
renderer.render(scene, camera);
}
updateUI();
animate();
</script>
</body>
</html>
```