Prompt specification
Build or customize the Three.js 3D scene "Community Bicycle Assembly Cooperative" 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: Community Bicycle Assembly Cooperative
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/community-bicycle-assembly-cooperative-x3147
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing division of labor across production stations. Build three compact workbenches for wheels, frames, and final assembly. Convey unfinished parts between stations and make mismatched arrival rates create visible waiting piles. Voxel style.
Working Three.js Starter (community-bicycle-assembly-cooperative-x3147):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flowcraft — Division of Labor</title>
<style>
:root {
--ink: #17202d;
--muted: #758095;
--panel: #121a27;
--panel-2: #1b2535;
--line: #2b374b;
--paper: #e9e4d8;
--teal: #19b7a5;
--amber: #f4a524;
--coral: #f06464;
--white: #f8fafc;
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, input { font: inherit; }
.app {
height: 100%;
display: grid;
grid-template-rows: 72px minmax(0, 1fr);
}
header {
z-index: 5;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 25px;
color: var(--white);
background: var(--ink);
border-bottom: 1px solid #334054;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
width: 35px;
height: 35px;
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 3px;
transform: rotate(-4deg);
}
.brand-mark i {
display: block;
background: var(--teal);
border-radius: 2px;
}
.brand-mark i:nth-child(2) { background: var(--amber); }
.brand-mark i:nth-child(3) { background: var(--coral); }
.brand-mark i:nth-child(4) { background: #6d7b91; }
.brand-name {
font-size: 15px;
font-weight: 850;
letter-spacing: .16em;
}
.brand-name span {
margin-left: 8px;
padding: 3px 7px;
border: 1px solid #4d5b70;
border-radius: 4px;
color: #aab5c7;
font-size: 10px;
letter-spacing: .12em;
}
.header-right {
display: flex;
align-items: center;
gap: 20px;
}
.simulation-state {
display: flex;
align-items: center;
gap: 8px;
color: #bac4d3;
font-size: 12px;
font-weight: 700;
letter-spacing: .07em;
text-transform: uppercase;
}
.live-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 5px rgb(25 183 165 / 12%);
animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
50% { box-shadow: 0 0 0 8px rgb(25 183 165 / 4%); }
}
main {
min-height: 0;
display: grid;
grid-template-columns: 300px minmax(0, 1fr);
}
aside {
z-index: 4;
overflow-y: auto;
padding: 26px 23px;
color: var(--white);
background: var(--panel);
border-right: 1px solid #303b4d;
}
.eyebrow {
margin-bottom: 10px;
color: var(--teal);
font-size: 10px;
font-weight: 850;
letter-spacing: .18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 27px;
line-height: 1.08;
letter-spacing: -.035em;
}
.intro {
margin: 12px 0 20px;
color: #9ca8ba;
font-size: 12px;
line-height: 1.6;
}
.section-title {
margin: 22px 0 10px;
color: #7e8ca1;
font-size: 9px;
font-weight: 800;
letter-spacing: .18em;
text-transform: uppercase;
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.metric {
min-height: 78px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 8px;
background: var(--panel-2);
}
.metric.wide { grid-column: 1 / -1; }
.metric-label {
display: block;
margin-bottom: 8px;
color: #8794a8;
font-size: 9px;
font-weight: 750;
letter-spacing: .07em;
text-transform: uppercase;
}
.metric strong {
font-size: 23px;
line-height: 1;
font-variant-numeric: tabular-nums;
}
.metric strong small {
color: #7f8b9d;
font-size: 10px;
font-weight: 600;
}
.metric.alert {
border-color: rgb(240 100 100 / 42%);
background: rgb(240 100 100 / 7%);
}
.metric.alert strong { color: #ff9a9a; }
.station-control {
padding: 13px 0 12px;
border-bottom: 1px solid var(--line);
}
.station-control:first-of-type { padding-top: 2px; }
.control-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
}
.control-name {
display: flex;
align-items: center;
gap: 8px;
font-size: 11px;
font-weight: 750;
}
.control-name i {
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--station-color);
}
.control-value {
color: #dce3ed;
font-size: 10px;
font-weight: 800;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 4px;
display: block;
margin: 0;
appearance: none;
border-radius: 3px;
outline: none;
background: #344155;
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 14px;
height: 14px;
appearance: none;
border: 3px solid var(--panel);
border-radius: 50%;
background: var(--station-color);
box-shadow: 0 0 0 1px var(--station-color);
}
input[type="range"]::-moz-range-thumb {
width: 10px;
height: 10px;
border: 3px solid var(--panel);
border-radius: 50%;
background: var(--station-color);
box-shadow: 0 0 0 1px var(--station-color);
}
.buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 18px;
}
.button {
min-height: 39px;
border: 1px solid #3a4659;
border-radius: 6px;
color: #dce4ef;
background: #202b3c;
font-size: 10px;
font-weight: 800;
letter-spacing: .07em;
text-transform: uppercase;
cursor: pointer;
transition: .16s ease;
}
.button:hover {
border-color: #637188;
background: #283548;
transform: translateY(-1px);
}
.button.primary {
color: #082c29;
border-color: var(--teal);
background: var(--teal);
}
.speed-row {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 4px;
margin-top: 8px;
padding: 4px;
border: 1px solid var(--line);
border-radius: 7px;
background: #0d141f;
}
.speed-button {
padding: 7px 4px;
border: 0;
border-radius: 4px;
color: #7f8ca0;
background: transparent;
font-size: 10px;
font-weight: 800;
cursor: pointer;
}
.speed-button.active {
color: #fff;
background: #314057;
}
.flow-key {
display: grid;
gap: 8px;
}
.flow-row {
display: grid;
grid-template-columns: 11px 1fr;
align-items: center;
gap: 9px;
color: #9eabbd;
font-size: 10px;
}
.flow-row i {
width: 9px;
height: 9px;
border-radius: 2px;
background: var(--flow-color);
}
.tip {
margin-top: 20px;
padding: 12px;
border-left: 3px solid var(--amber);
color: #aeb9c9;
background: rgb(244 165 36 / 6%);
font-size: 10px;
line-height: 1.55;
}
#viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: var(--paper);
}
#viewport canvas {
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#viewport canvas:active { cursor: grabbing; }
.view-tools {
position: absolute;
z-index: 3;
top: 17px;
right: 18px;
display: flex;
align-items: center;
gap: 9px;
}
.view-hint {
padding: 8px 10px;
border: 1px solid rgb(23 32 45 / 12%);
border-radius: 5px;
color: #6f786f;
background: rgb(255 255 255 / 58%);
backdrop-filter: blur(8px);
font-size: 9px;
font-weight: 700;
letter-spacing: .06em;
text-transform: uppercase;
}
.view-reset {
padding: 8px 10px;
border: 1px solid rgb(23 32 45 / 14%);
border-radius: 5px;
color: #4f5a67;
background: rgb(255 255 255 / 68%);
font-size: 9px;
font-weight: 800;
cursor: pointer;
}
.scene-hud {
position: absolute;
z-index: 3;
top: 18px;
left: 18px;
display: flex;
gap: 7px;
}
.hud-chip {
min-width: 87px;
padding: 9px 11px;
border: 1px solid rgb(23 32 45 / 12%);
border-radius: 6px;
background: rgb(255 255 255 / 65%);
backdrop-filter: blur(9px);
}
.hud-chip span {
display: block;
color: #7e837e;
font-size: 8px;
font-weight: 800;
letter-spacing: .11em;
text-transform: uppercase;
}
.hud-chip strong {
display: block;
margin-top: 3px;
font-size: 15px;
font-variant-numeric: tabular-nums;
}
.station-tag {
position: absolute;
z-index: 2;
width: 138px;
padding: 9px 10px;
border: 1px solid rgb(23 32 45 / 13%);
border-top: 3px solid var(--tag-color);
border-radius: 5px;
background: rgb(255 255 255 / 88%);
box-shadow: 0 7px 22px rgb(30 37 43 / 9%);
backdrop-filter: blur(8px);
pointer-events: none;
transform: translate(-50%, -100%);
}
.station-tag b {
display: block;
color: #29313d;
font-size: 10px;
letter-spacing: .09em;
}
.station-tag small {
display: block;
margin-top: 4px;
color: #7c8389;
font-size: 8px;
line-height: 1.3;
}
.wait-badge {
display: inline-block;
margin-top: 6px;
padding: 3px 5px;
border-radius: 3px;
color: #9a5525;
background: #fff0d7;
font-size: 8px;
font-weight: 850;
letter-spacing: .05em;
}
.wait-badge.clear {
color: #28746c;
background: #dff5f1;
}
.floor-legend {
position: absolute;
z-index: 3;
right: 18px;
bottom: 17px;
display: flex;
gap: 13px;
padding: 9px 12px;
border: 1px solid rgb(23 32 45 / 11%);
border-radius: 5px;
color: #707872;
background: rgb(255 255 255 / 55%);
backdrop-filter: blur(7px);
font-size: 8px;
font-weight: 750;
letter-spacing: .06em;
text-transform: uppercase;
}
.floor-legend span {
display: flex;
align-items: center;
gap: 5px;
}
.floor-legend i {
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--legend-color);
}
@media (max-width: 900px) {
html, body { height: auto; min-height: 100%; overflow: auto; }
.app { min-height: 100vh; grid-template-rows: 64px auto; }
header { padding: 0 15px; }
.brand-name span { display: none; }
main { display: block; }
aside {
padding: 20px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px 22px;
overflow: visible;
}
aside > .intro-block,
aside > .tip { grid-column: 1 / -1; }
aside .section-title { margin-top: 10px; }
#viewport { height: 68vh; min-height: 520px; }
.view-hint { display: none; }
}
@media (max-width: 580px) {
aside { display: block; }
.station-control { padding-top: 12px; }
.scene-hud { top: 12px; left: 12px; }
.hud-chip { min-width: 70px; padding: 7px 8px; }
.view-tools { top: 12px; right: 12px; }
.floor-legend { right: 10px; bottom: 10px; gap: 7px; }
.station-tag { width: 112px; }
}
</style>
</head>
<body>
<div class="app">
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true"><i></i><i></i><i></i><i></i></div>
<div class="brand-name">FLOWCRAFT <span>LAB / 03</span></div>
</div>
<div class="header-right">
<div class="simulation-state">
<span class="live-dot" id="liveDot"></span>
<span id="lineStatus">Simulation running</span>
</div>
</div>
</header>
<main>
<aside>
<div class="intro-block">
<div class="eyebrow">Production system</div>
<h1>Division<br>of labor</h1>
<p class="intro">
Each station has its own pace. Unfinished kits travel by conveyor,
and mismatched rates become visible queues.
</p>
</div>
<div>
<div class="section-title">Live metrics</div>
<div class="metric-grid">
<div class="metric alert">
<span class="metric-label">Wheel kits waiting</span>
<strong id="wheelWait">5</strong>
</div>
<div class="metric alert">
<span class="metric-label">Frame kits waiting</span>
<strong id="frameWait">4</strong>
</div>
<div class="metric wide">
<span class="metric-label">Completed bicycles</span>
<strong id="completed">0 <small>units</small></strong>
</div>
</div>
</div>
<div>
<div class="section-title">Station capacities</div>
<div class="station-control" style="--station-color: var(--teal)">
<div class="control-heading">
<span class="control-name"><i></i>01 · Wheel kits</span>
<span class="control-value" id="wheelRateLabel">72 / min</span>
</div>
<input id="wheelRate" type="range" min="36" max="96" step="6" value="72"
aria-label="Wheel station output rate">
</div>
<div class="station-control" style="--station-color: var(--amber)">
<div class="control-heading">
<span class="control-name"><i></i>02 · Frame builds</span>
<span class="control-value" id="frameRateLabel">42 / min</span>
</div>
<input id="frameRate" type="range" min="24" max="72" step="6" value="42"
aria-label="Frame station processing rate">
</div>
<div class="station-control" style="--station-color: var(--coral)">
<div class="control-heading">
<span class="control-name"><i></i>03 · Final assembly</span>
<span class="control-value" id="assemblyRateLabel">26 / min</span>
</div>
<input id="assemblyRate" type="range" min="12" max="48" step="6" value="26"
aria-label="Assembly station processing rate">
</div>
</div>
<div>
<div class="section-title">Playback</div>
<div class="buttons">
<button class="button primary" id="pauseButton">Pause line</button>
<button class="button" id="resetButton">Reset demo</button>
</div>
<div class="speed-row">
<button class="speed-button" data-speed="0.5">0.5×</button>
<button class="speed-button active" data-speed="1">1×</button>
<button class="speed-button" data-speed="2">2×</button>
<button class="speed-button" data-speed="4">4×</button>
</div>
</div>
<div>
<div class="section-title">Material flow</div>
<div class="flow-key">
<div class="flow-row" style="--flow-color: var(--teal)">
<i></i><span>Wheel station → frame station</span>
</div>
<div class="flow-row" style="--flow-color: var(--amber)">
<i></i><span>Frame station → assembly station</span>
</div>
<div class="flow-row" style="--flow-color: var(--coral)">
<i></i><span>Assembly station → finished output</span>
</div>
</div>
</div>
<div class="tip">
<strong>Try this:</strong> raise Wheel kits to 96/min while leaving
Final assembly at 26/min. The conveyor will outrun the downstream
benches and the waiting piles will grow.
</div>
</aside>
<section id="viewport" aria-label="Interactive 3D production line">
<div class="scene-hud">
<div class="hud-chip">
<span>Line state</span>
<strong id="hudState">Running</strong>
</div>
<div class="hud-chip">
<span>Output</span>
<strong id="hudOutput">0</strong>
</div>
</div>
<div class="view-tools">
<div class="view-hint">Drag to orbit · scroll to zoom</div>
<button class="view-reset" id="viewReset">Reset view</button>
</div>
<div class="station-tag" id="tag0" style="--tag-color: var(--teal)">
<b>01 / WHEELS</b>
<small>72 kits per minute</small>
<span class="wait-badge clear">PRODUCING</span>
</div>
<div class="station-tag" id="tag1" style="--tag-color: var(--amber)">
<b>02 / FRAMES</b>
<small>42 builds per minute</small>
<span class="wait-badge">5 WHEEL KITS WAITING</span>
</div>
<div class="station-tag" id="tag2" style="--tag-color: var(--coral)">
<b>03 / ASSEMBLY</b>
<small>26 bicycles per minute</small>
<span class="wait-badge">4 FRAME KITS WAITING</span>
</div>
<div class="floor-legend">
<span><i style="--legend-color: var(--teal)"></i>Wheel kit</span>
<span><i style="--legend-color: var(--amber)"></i>Frame kit</span>
<span><i style="--legend-color: var(--coral)"></i>Finished bike</span>
</div>
</section>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e4d8);
scene.fog = new THREE.Fog(0xe9e4d8, 36, 65);
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;
viewport.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-16, 16, 12, -12, 0.1, 100);
const cameraTarget = new THREE.Vector3(1.4, 0.9, 0);
let cameraTheta = 0.20;
let cameraPhi = 0.76;
let cameraZoom = 1;
scene.add(new THREE.HemisphereLight(0xfffbef, 0x847968, 2.0));
const sun = new THREE.DirectionalLight(0xfff4df, 3.0);
sun.position.set(-8, 20, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 16;
sun.shadow.camera.bottom = -16;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const rim = new THREE.DirectionalLight(0xb8d8ff, 1.1);
rim.position.set(14, 8, -10);
scene.add(rim);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const material = (color, roughness = 0.82, metalness = 0.0) =>
new THREE.MeshStandardMaterial({ color, roughness, metalness });
const MAT = {
floor: material(0xd8d1c2),
floorEdge: material(0xbeb5a3),
grid: material(0xc7bfae),
cream: material(0xf3ead8),
white: material(0xf7f4eb),
dark: material(0x263241),
darker: material(0x18212d),
steel: material(0x9aa6ae, 0.48, 0.35),
rubber: material(0x20252c),
wood: material(0xa77b50),
woodLight: material(0xc49b6c),
teal: material(0x19b7a5),
tealDark: material(0x087d74),
amber: material(0xf4a524),
amberDark: material(0xb86f12),
coral: material(0xf06464),
coralDark: material(0xb83c45),
skin: material(0xe2ad82),
screen: material(0x62e2d5, 0.3),
yellow: material(0xf5d047),
blue: material(0x4f7fba)
};
function box(parent, w, h, d, mat, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeGroup(parent = scene) {
const group = new THREE.Group();
parent.add(group);
return group;
}
// ---------- World and floor ----------
box(scene, 38, 0.5, 13.5, MAT.floor, 1.5, -0.31, 0);
box(scene, 38.4, 0.18, 13.8, MAT.floorEdge, 1.5, -0.55, 0);
for (let x = -16; x <= 19; x += 2) {
box(scene, 0.025, 0.012, 12.6, MAT.grid, x, -0.047, 0);
}
for (let z = -6; z <= 6; z += 2) {
box(scene, 37, 0.012, 0.025, MAT.grid, 1.5, -0.047, z);
}
const stationData = [
{ x: -8.5, accent: MAT.teal, dark: MAT.tealDark, name: "WHEELS", rate: 72 },
{ x: 0, accent: MAT.amber, dark: MAT.amberDark, name: "FRAMES", rate: 42 },
{ x: 8.5, accent: MAT.coral, dark: MAT.coralDark, name: "ASSEMBLY", rate: 26 }
];
for (const station of stationData) {
box(scene, 5.1, 0.045, 4.45, MAT.cream, station.x, 0.005, 0.05);
for (let i = 0; i < 6; i++) {
box(
scene, 0.22, 0.035, 0.08, MAT.yellow,
station.x - 2.0 + i * 0.8, 0.045, 2.28
);
}
}
// ---------- Conveyor belts ----------
const belts = [];
function createBelt(x1, x2, accent) {
const root = makeGroup();
const length = x2 - x1;
const center = (x1 + x2) * 0.5;
box(root, length + 0.15, 0.32, 1.42, MAT.darker, center, 1.20, 0);
box(root, length, 0.13, 1.23, MAT.dark, center, 1.42, 0);
box(root, length, 0.13, 0.13, accent, center, 1.54, 0.76);
box(root, length, 0.13, 0.13, accent, center, 1.54, -0.76);
const supportCount = Math.max(2, Math.round(length / 2.2));
for (let i = 0; i <= supportCount; i++) {
const x = x1 + (length * i) / supportCount;
box(root, 0.18, 1.0, 0.18, MAT.steel, x, 0.55, -0.55);
box(root, 0.18, 1.0, 0.18, MAT.steel, x, 0.55, 0.55);
box(root, 0.30, 0.08, 1.45, MAT.dark, x, 0.08, 0);
}
const slats = [];
const slatCount = Math.max(10, Math.floor(length / 0.52));
for (let i = 0; i < slatCount; i++) {
const slat = box(
root, 0.11, 0.035, 1.10, MAT.steel,
x1 + 0.18 + (i * (length - 0.36)) / slatCount, 1.505, 0
);
slat.userData.baseX = slat.position.x;
slats.push(slat);
}
const belt = { x1, x2, length, slats, offset: 0 };
belts.push(belt);
return belt;
}
const wheelBelt = createBelt(-6.4, -2.3, MAT.teal);
const frameBelt = createBelt(2.3, 6.4, MAT.amber);
const outputBelt = createBelt(10.6, 14.3, MAT.coral);
// Output dock.
const dock = makeGroup();
box(dock, 1.2, 0.35, 2.2, MAT.dark, 14.65, 0.2, 0);
box(dock, 0.16, 2.2, 0.16, MAT.coralDark, 14.15, 1.25, -0.9);
box(dock, 0.16, 2.2, 0.16, MAT.coralDark, 14.15, 1.25, 0.9);
box(dock, 0.18, 0.24, 2.0, MAT.coral, 14.15, 2.37, 0);
// ---------- Voxel workbenches ----------
const workers = [];
const machineArms = [];
function createWorker(x, z, shirt) {
const root = makeGroup();
root.position.set(x, 0.08, z);
box(root, 0.19, 0.57, 0.23, MAT.darker, -0.16, 0.31, 0);
box(root, 0.19, 0.57, 0.23, MAT.darker, 0.16, 0.31, 0);
box(root, 0.26, 0.13, 0.37, MAT.rubber, -0.16, 0.065, 0.06);
box(root, 0.26, 0.13, 0.37, MAT.rubber, 0.16, 0.065, 0.06);
box(root, 0.61, 0.67, 0.36, shirt, 0, 0.93, 0);
box(root, 0.43, 0.42, 0.39, MAT.skin, 0, 1.49, 0);
box(root, 0.51, 0.16, 0.46, shirt, 0, 1.75, 0);
box(root, 0.55, 0.08, 0.16, shirt, 0, 1.66, 0.24);
const leftArm = makeGroup(root);
leftArm.position.set(-0.39, 1.18, 0);
box(leftArm, 0.17, 0.55, 0.19, shirt, 0, -0.23, 0);
box(leftArm, 0.17, 0.16, 0.18, MAT.skin, 0, -0.54, 0);
const rightArm = makeGroup(root);
rightArm.position.set(0.39, 1.18, 0);
box(rightArm, 0.17, 0.55, 0.19, shirt, 0, -0.23, 0);
box(rightArm, 0.17, 0.16, 0.18, MAT.skin, 0, -0.54, 0);
workers.push({ root, leftArm, rightArm });
return root;
}
function createStation(index) {
const s = stationData[index];
const root = makeGroup();
// Bench.
box(root, 4.25, 0.25, 2.65, MAT.woodLight, s.x, 1.43, 0);
box(root, 4.05, 0.10, 2.45, MAT.cream, s.x, 1.59, 0);
for (const dx of [-1.75, 1.75]) {
for (const dz of [-0.95, 0.95]) {
box(root, 0.25, 1.26, 0.25, MAT.dark, s.x + dx, 0.68, dz);
}
}
box(root, 3.65, 0.15, 1.95, MAT.wood, s.x, 0.48, 0);
box(root, 4.24, 0.19, 0.10, s.accent, s.x, 1.34, 1.34);
box(root, 1.1, 0.10, 0.10, s.accent, s.x + 1.4, 1.48, 1.12);
// Workstation machinery.
if (index === 0) {
box(root, 1.25, 0.34, 0.95, s.dark, s.x - 0.75, 1.82, -0.25);
box(root, 0.16, 0.95, 0.18, MAT.steel, s.x - 1.12, 2.32, -0.25);
box(root, 0.16, 0.95, 0.18, MAT.steel, s.x - 0.38, 2.32, -0.25);
box(root, 0.90, 0.16, 0.20, s.accent, s.x - 0.75, 2.72, -0.25);
for (const dx of [-0.18, 0.18]) {
for (const dz of [-0.18, 0.18]) {
box(root, 0.20, 0.42, 0.20, MAT.rubber, s.x - 0.75 + dx, 2.31, -0.25 + dz);
}
}
} else if (index === 1) {
box(root, 1.3, 0.27, 0.85, s.dark, s.x - 0.7, 1.77, -0.2);
box(root, 0.18, 1.05, 0.18, MAT.steel, s.x - 1.18, 2.25, -0.2);
box(root, 0.18, 1.05, 0.18, MAT.steel, s.x - 0.22, 2.25, -0.2);
box(root, 1.18, 0.18, 0.18, s.accent, s.x - 0.7, 2.75, -0.2);
} else {
box(root, 1.45, 0.25, 0.88, s.dark, s.x - 0.65, 1.76, -0.25);
box(root, 0.16, 1.1, 0.16, MAT.steel, s.x - 1.22, 2.22, -0.25);
box(root, 0.16, 1.1, 0.16, MAT.steel, s.x - 0.08, 2.22, -0.25);
box(root, 1.35, 0.18, 0.18, s.accent, s.x - 0.65, 2.75, -0.25);
}
// Animated machine arm.
const arm = makeGroup(root);
arm.position.set(s.x + 0.35, 2.35, -0.25);
box(arm, 0.18, 0.68, 0.18, MAT.steel, 0, -0.28, 0);
box(arm, 0.42, 0.18, 0.25, s.accent, 0, -0.65, 0);
machineArms.push(arm);
// Tool board and monitor.
box(root, 0.72, 0.50, 0.08, MAT.dark, s.x + 1.22, 2.05, -0.78);
box(root, 0.58, 0.35, 0.025, MAT.screen, s.x + 1.22, 2.06, -0.725);
box(root, 0.10, 0.28, 0.10, MAT.steel, s.x + 1.22, 1.73, -0.78);
// Status beacon.
box(root, 0.09, 0.72, 0.09, MAT.steel, s.x - 1.82, 1.96, -0.95);
const beacon = box(root, 0.22, 0.22, 0.22, s.accent, s.x - 1.82, 2.38, -0.95);
// Small parts and tools on the bench.
box(root, 0.52, 0.18, 0.36, MAT.blue, s.x + 0.72, 1.76, 0.55);
box(root, 0.10, 0.10, 0.62, MAT.steel, s.x - 0.25, 1.72, 0.61);
createWorker(s.x, -2.05, s.accent);
s.beacon = beacon;
s.arm = arm;
}
stationData.forEach((_, i) => createStation(i));
// ---------- Cargo kit models ----------
function makeWheelKit(scale = 1) {
const root = makeGroup();
root.scale.setScalar(scale);
box(root, 0.72, 0.20, 0.48, MAT.tealDark, 0, 0.10, 0);
box(root, 0.78, 0.08, 0.12, MAT.teal, 0, 0.22, 0);
for (const x of [-0.29, 0.29]) {
for (const z of [-0.18, 0.18]) {
box(root, 0.15, 0.31, 0.18, MAT.rubber, x, 0.28, z);
box(root, 0.075, 0.09, 0.19, MAT.steel, x, 0.28, z);
}
}
return root;
}
function makeFrameKit(scale = 1) {
const root = makeGroup();
root.scale.setScalar(scale);
box(root, 0.82, 0.10, 0.43, MAT.amberDark, 0, 0.05, 0);
box(root, 0.13, 0.57, 0.13, MAT.amber, -0.29, 0.37, 0);
box(root, 0.13, 0.57, 0.13, MAT.amber, 0.29, 0.37, 0);
box(root, 0.68, 0.13, 0.13, MAT.amber, 0, 0.66, 0);
box(root, 0.57, 0.10, 0.10, MAT.amber, 0, 0.39, 0);
for (const x of [-0.32, 0.32]) {
box(root, 0.14, 0.26, 0.24, MAT.rubber, x, 0.18, 0);
}
return root;
}
function makeBike(scale = 1) {
const root = makeGroup();
root.scale.setScalar(scale);
for (const x of [-0.46, 0.46]) {
box(root, 0.31, 0.36, 0.13, MAT.rubber, x, 0.20, 0);
box(root, 0.11, 0.11, 0.145, MAT.steel, x, 0.20, 0);
}
box(root, 0.82, 0.12, 0.12, MAT.coral, 0, 0.33, 0);
box(root, 0.12, 0.54, 0.12, MAT.coral, -0.27, 0.48, 0);
box(root, 0.12, 0.48, 0.12, MAT.coral, 0.30, 0.45, 0);
box(root, 0.32, 0.12, 0.18, MAT.dark, -0.19, 0.76, 0);
box(root, 0.12, 0.39, 0.12, MAT.steel, 0.43, 0.58, 0);
box(root, 0.33, 0.09, 0.12, MAT.dark, 0.43, 0.78, 0);
box(root, 0.30, 0.08, 0.25, MAT.amber, 0.03, 0.68, 0);
return root;
}
// ---------- Visible waiting piles ----------
function createPallet(x, z) {
const root = makeGroup();
root.position.set(x, 0, z);
box(root, 1.72, 0.13, 1.42, MAT.wood, 0, 0.22, 0);
for (const dx of [-0.62, 0, 0.62]) {
box(root, 0.14, 0.18, 1.38, MAT.woodLight, dx, 0.33, 0);
}
for (const dx of [-0.72, 0.72]) {
for (const dz of [-0.5, 0.5]) {
box(root, 0.18, 0.15, 0.18, MAT.woodLight, dx, 0.08, dz);
}
}
return root;
}
const framePallet = createPallet(-2.72, 2.65);
const assemblyPallet = createPallet(5.88, 2.65);
const framePileRoot = makeGroup(framePallet);
const assemblyPileRoot = makeGroup(assemblyPallet);
framePileRoot.position.y = 0.38;
assemblyPileRoot.position.y = 0.38;
let queueWheelKits = 5;
let queueFrameKits = 4;
let renderedWheelQueue = -1;
let renderedFrameQueue = -1;
let completed = 0;
function clearGroup(group) {
while (group.children.length) group.remove(group.children[0]);
}
function renderPile(root, count, type) {
clearGroup(root);
const visible = Math.min(count, 16);
for (let i = 0; i < visible; i++) {
const layer = Math.floor(i / 4);
const within = i % 4;
const col = within % 2;
const row = Math.floor(within / 2);
const kit = type === "wheel" ? makeWheelKit(0.72) : makeFrameKit(0.72);
kit.position.set(
col === 0 ? -0.43 : 0.43,
layer * 0.43,
row === 0 ? -0.33 : 0.33
);
root.add(kit);
}
const extras = Math.min(Math.max(0, count - 16), 8);
for (let i = 0; i < extras; i++) {
box(
root, 0.55, 0.31, 0.48,
type === "wheel" ? MAT.tealDark : MAT.amberDark,
-0.42 + (i % 2) * 0.84,
0.16 + Math.floor(i / 2) * 0.33,
0
);
}
}
function refreshQueues() {
if (queueWheelKits !== renderedWheelQueue) {
renderPile(framePileRoot, queueWheelKits, "wheel");
renderedWheelQueue = queueWheelKits;
}
if (queueFrameKits !== renderedFrameQueue) {
renderPile(assemblyPileRoot, queueFrameKits, "frame");
renderedFrameQueue = queueFrameKits;
}
}
// ---------- Conveyor transit ----------
const transits = [[], [], []];
const transitDurations = [2.5, 2.5, 2.15];
function spawnTransit(beltIndex, type, progress = 0) {
const belt = [wheelBelt, frameBelt, outputBelt][beltIndex];
const cargo = type === "wheel" ? makeWheelKit(0.86)
: type === "frame" ? makeFrameKit(0.86)
: makeBike(0.9);
cargo.position.set(
belt.x1 + 0.24 + progress * (belt.length - 0.48),
1.55,
0
);
scene.add(cargo);
transits[beltIndex].push({ cargo, progress, type });
}
function updateTransit(beltIndex, dt) {
const belt = [wheelBelt, frameBelt, outputBelt][beltIndex];
for (let i = transits[beltIndex].length - 1; i >= 0; i--) {
const item = transits[beltIndex][i];
item.progress += dt / transitDurations[beltIndex];
if (item.progress >= 1) {
scene.remove(item.cargo);
transits[beltIndex].splice(i, 1);
if (beltIndex === 0) queueWheelKits++;
if (beltIndex === 1) queueFrameKits++;
if (beltIndex === 2) completed++;
} else {
item.cargo.position.x =
belt.x1 + 0.24 + item.progress * (belt.length - 0.48);
}
}
}
// ---------- Simulation ----------
let running = true;
let simulationSpeed = 1;
const rates = [72, 42, 26];
const timers = [0, 0, 0];
function processStations(dt) {
// Station 1 always has raw wheel production.
timers[0] += dt;
const wheelInterval = 60 / rates[0];
if (timers[0] >= wheelInterval) {
timers[0] -= wheelInterval;
spawnTransit(0, "wheel");
}
// Station 2 consumes wheel kits when available.
timers[1] = Math.min(timers[1] + dt, 60 / rates[1]);
if (queueWheelKits > 0 && timers[1] >= 60 / rates[1]) {
queueWheelKits--;
timers[1] = 0;
spawnTransit(1, "frame");
}
// Station 3 consumes frame kits when available.
timers[2] = Math.min(timers[2] + dt, 60 / rates[2]);
if (queueFrameKits > 0 && timers[2] >= 60 / rates[2]) {
queueFrameKits--;
timers[2] = 0;
spawnTransit(2, "bike");
}
}
function resetSimulation() {
for (const beltTransits of transits) {
for (const item of beltTransits) scene.remove(item.cargo);
beltTransits.length = 0;
}
queueWheelKits = 5;
queueFrameKits = 4;
completed = 0;
timers.fill(0);
spawnTransit(0, "wheel", 0.12);
spawnTransit(0, "wheel", 0.48);
spawnTransit(0, "wheel", 0.80);
spawnTransit(1, "frame", 0.23);
spawnTransit(1, "frame", 0.67);
spawnTransit(2, "bike", 0.45);
renderedWheelQueue = -1;
renderedFrameQueue = -1;
refreshQueues();
updateUI();
}
// ---------- UI ----------
const wheelRateInput = document.getElementById("wheelRate");
const frameRateInput = document.getElementById("frameRate");
const assemblyRateInput = document.getElementById("assemblyRate");
const pauseButton = document.getElementById("pauseButton");
const lineStatus = document.getElementById("lineStatus");
const liveDot = document.getElementById("liveDot");
function bindRate(input, index) {
input.addEventListener("input", () => {
rates[index] = Number(input.value);
updateUI();
});
}
bindRate(wheelRateInput, 0);
bindRate(frameRateInput, 1);
bindRate(assemblyRateInput, 2);
pauseButton.addEventListener("click", () => {
running = !running;
pauseButton.textContent = running ? "Pause line" : "Resume line";
pauseButton.classList.toggle("primary", running);
updateUI();
});
document.getElementById("resetButton").addEventListener("click", resetSimulation);
document.querySelectorAll(".speed-button").forEach(button => {
button.addEventListener("click", () => {
simulationSpeed = Number(button.dataset.speed);
document.querySelectorAll(".speed-button").forEach(b => {
b.classList.toggle("active", b === button);
});
});
});
const tags = [
document.getElementById("tag0"),
document.getElementById("tag1"),
document.getElementById("tag2")
];
const tagPositions = [
new THREE.Vector3(-8.5, 3.65, -1.65),
new THREE.Vector3(0, 3.65, -1.65),
new THREE.Vector3(8.5, 3.65, -1.65)
];
function updateUI() {
document.getElementById("wheelRateLabel").textContent = `${rates[0]} / min`;
document.getElementById("frameRateLabel").textContent = `${rates[1]} / min`;
document.getElementById("assemblyRateLabel").textContent = `${rates[2]} / min`;
document.getElementById("wheelWait").textContent = queueWheelKits;
document.getElementById("frameWait").textContent = queueFrameKits;
document.getElementById("completed").innerHTML = `${completed} <small>units</small>`;
document.getElementById("hudOutput").textContent = completed;
document.getElementById("hudState").textContent = running ? "Running" : "Paused";
const assemblyPressure = queueFrameKits;
const framePressure = queueWheelKits;
let status;
if (assemblyPressure >= 6) status = "Backlog at final assembly";
else if (framePressure >= 7) status = "Backlog at frame station";
else status = "Simulation running";
lineStatus.textContent = running ? status : "Simulation paused";
liveDot.style.background = running ? "var(--teal)" : "var(--amber)";
tags[0].querySelector("small").textContent = `${rates[0]} kits per minute`;
tags[1].querySelector("small").textContent = `${rates[1]} builds per minute`;
tags[2].querySelector("small").textContent = `${rates[2]} bicycles per minute`;
const badge0 = tags[0].querySelector(".wait-badge");
badge0.textContent = "PRODUCING";
badge0.classList.add("clear");
const badge1 = tags[1].querySelector(".wait-badge");
badge1.textContent = queueWheelKits
? `${queueWheelKits} WHEEL KITS WAITING`
: "INPUT CLEAR";
badge1.classList.toggle("clear", queueWheelKits === 0);
const badge2 = tags[2].querySelector(".wait-badge");
badge2.textContent = queueFrameKits
? `${queueFrameKits} FRAME KITS WAITING`
: "INPUT CLEAR";
badge2.classList.toggle("clear", queueFrameKits === 0);
}
// ---------- Custom camera controls ----------
function updateCamera() {
const distance = 34;
camera.position.set(
cameraTarget.x + Math.sin(cameraTheta) * Math.cos(cameraPhi) * distance,
cameraTarget.y + Math.sin(cameraPhi) * distance,
cameraTarget.z + Math.cos(cameraTheta) * Math.cos(cameraPhi) * distance
);
camera.lookAt(cameraTarget);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resetView() {
cameraTheta = 0.20;
cameraPhi = 0.76;
cameraZoom = 1;
updateCamera();
}
document.getElementById("viewReset").addEventListener("click", resetView);
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(cameraPhi + dy * 0.004, 0.42, 1.05);
updateCamera();
});
renderer.domElement.addEventListener("pointerup", event => {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * (event.deltaY > 0 ? 0.92 : 1.08),
0.65,
1.75
);
updateCamera();
}, { passive: false });
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
if (!width || !height) return;
const aspect = width / height;
const frustumHeight = Math.max(16.5, 32 / aspect);
camera.left = -frustumHeight * aspect * 0.5;
camera.right = frustumHeight * aspect * 0.5;
camera.top = frustumHeight * 0.5;
camera.bottom = -frustumHeight * 0.5;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
new ResizeObserver(resize).observe(viewport);
function updateLabels() {
for (let i = 0; i < tags.length; i++) {
const projected = tagPositions[i].clone().project(camera);
const x = (projected.x * 0.5 + 0.5) * viewport.clientWidth;
const y = (-projected.y * 0.5 + 0.5) * viewport.clientHeight;
tags[i].style.left = `${x}px`;
tags[i].style.top = `${y}px`;
}
}
// ---------- Animation loop ----------
const clock = new THREE.Clock();
let elapsed = 0;
let uiTimer = 0;
function animate() {
requestAnimationFrame(animate);
const realDt = Math.min(clock.getDelta(), 0.05);
const simDt = running ? realDt * simulationSpeed : 0;
elapsed += simDt;
if (simDt > 0) {
processStations(simDt);
updateTransit(0, simDt);
updateTransit(1, simDt);
updateTransit(2, simDt);
refreshQueues();
for (const belt of belts) {
belt.offset = (belt.offset + simDt * 0.95) % (belt.length - 0.36);
for (const slat of belt.slats) {
const next = slat.userData.baseX + belt.offset;
slat.position.x =
next > belt.x2 - 0.18
? next - (belt.length - 0.36)
: next;
}
}
}
workers.forEach((worker, i) => {
const active =
i === 0 ||
(i === 1 && queueWheelKits > 0) ||
(i === 2 && queueFrameKits > 0);
const swing = active ? Math.sin(elapsed * 7 + i * 1.7) * 0.48 : -0.12;
worker.leftArm.rotation.x = swing;
worker.rightArm.rotation.x = -swing * 0.85;
worker.root.position.y = 0.08 + (active ? Math.abs(Math.sin(elapsed * 3.5 + i)) * 0.025 : 0);
});
machineArms.forEach((arm, i) => {
const active =
i === 0 ||
(i === 1 && queueWheelKits > 0) ||
(i === 2 && queueFrameKits > 0);
arm.rotation.x = active ? Math.sin(elapsed * 4.2 + i) * 0.22 : -0.08;
});
stationData.forEach((station, i) => {
const active =
i === 0 ||
(i === 1 && queueWheelKits > 0) ||
(i === 2 && queueFrameKits > 0);
const scale = active ? 1 + Math.sin(elapsed * 6 + i) * 0.08 : 0.82;
station.beacon.scale.setScalar(scale);
});
uiTimer += realDt;
if (uiTimer > 0.15) {
updateUI();
uiTimer = 0;
}
updateLabels();
renderer.render(scene, camera);
}
resize();
resetView();
resetSimulation();
animate();
</script>
</body>
</html>
```