Prompt specification
Build or customize the Three.js 3D scene "Mechanical sorter routing three sample cards" 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: Mechanical sorter routing three sample cards
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/mechanical-sorter-routing-three-sample-cards-x2518
Scene Description Prompt:
A voxel punched-card sorter sends fictional records into three bins according to one encoded field. Use Three.js from cdnjs, one HTML file.
Working Three.js Starter (mechanical-sorter-routing-three-sample-cards-x2518):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#07111d" />
<title>Voxel Record Sorter</title>
<style>
:root {
--bg: #07111d;
--panel: rgba(10, 23, 36, 0.88);
--panel-border: rgba(130, 181, 205, 0.18);
--text: #e6f2f5;
--muted: #7895a4;
--cyan: #39e6c5;
--amber: #ffc857;
--pink: #ff5d8f;
--shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
}
* {
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,
select,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.brand {
position: fixed;
top: 24px;
left: 26px;
z-index: 3;
display: flex;
align-items: flex-start;
gap: 14px;
pointer-events: none;
}
.brand-mark {
display: grid;
grid-template-columns: repeat(3, 5px);
grid-template-rows: repeat(3, 5px);
gap: 4px;
margin-top: 4px;
}
.brand-mark i {
display: block;
background: var(--cyan);
box-shadow: 0 0 10px rgba(57, 230, 197, 0.5);
}
.brand-mark i:nth-child(2),
.brand-mark i:nth-child(3),
.brand-mark i:nth-child(6),
.brand-mark i:nth-child(9) {
opacity: 0.25;
}
.eyebrow,
.panel-title,
.label,
.status,
.mini-label {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
text-transform: uppercase;
letter-spacing: 0.14em;
}
.eyebrow {
margin: 0 0 7px;
color: var(--cyan);
font-size: 10px;
font-weight: 700;
}
h1 {
margin: 0;
font-size: clamp(22px, 2.5vw, 36px);
line-height: 1;
letter-spacing: -0.045em;
font-weight: 760;
}
.brand p {
margin: 9px 0 0;
color: var(--muted);
font-size: 12px;
letter-spacing: 0.02em;
}
.status {
position: fixed;
top: 27px;
right: 28px;
z-index: 3;
display: flex;
align-items: center;
gap: 9px;
padding: 9px 12px;
border: 1px solid var(--panel-border);
background: rgba(8, 19, 31, 0.72);
color: #a9c1cc;
font-size: 10px;
font-weight: 700;
pointer-events: none;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 12px var(--cyan);
animation: pulse 1.8s infinite;
}
.status.paused .status-dot {
background: var(--amber);
box-shadow: 0 0 12px var(--amber);
animation: none;
}
@keyframes pulse {
50% {
opacity: 0.35;
}
}
.record-card {
position: fixed;
z-index: 3;
top: 25px;
left: 50%;
width: min(330px, calc(100vw - 32px));
padding: 15px 17px;
transform: translateX(-50%);
background: var(--panel);
border: 1px solid var(--panel-border);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 0 100%);
pointer-events: none;
}
.record-card::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 74px;
height: 2px;
background: var(--cyan);
box-shadow: 0 0 14px var(--cyan);
}
.record-card.hit {
animation: record-hit 0.45s ease-out;
}
@keyframes record-hit {
0% {
border-color: rgba(57, 230, 197, 0.9);
transform: translateX(-50%) scale(1.015);
}
100% {
border-color: var(--panel-border);
transform: translateX(-50%) scale(1);
}
}
.record-top {
display: flex;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
}
.record-id {
color: var(--cyan);
font: 700 10px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
}
.record-state {
color: var(--muted);
font: 600 9px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.1em;
}
.record-name {
margin: 0;
font-size: 17px;
letter-spacing: -0.02em;
}
.record-meta {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 11px;
}
.record-chip {
padding: 4px 7px;
border: 1px solid rgba(130, 181, 205, 0.14);
color: #91aab6;
font: 600 9px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.04em;
}
.record-chip.encoded {
color: #07111d;
background: var(--cyan);
border-color: var(--cyan);
}
.panel {
position: fixed;
z-index: 4;
bottom: 24px;
padding: 17px;
background: var(--panel);
border: 1px solid var(--panel-border);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
}
.controls {
left: 26px;
width: 285px;
clip-path: polygon(0 0, 100% 0, 100% calc(100% - 11px), calc(100% - 11px) 100%, 0 100%);
}
.bins-panel {
right: 26px;
width: 286px;
clip-path: polygon(11px 0, 100% 0, 100% 100%, 0 100%, 0 11px);
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 15px;
color: #9db5c0;
font-size: 10px;
font-weight: 700;
}
.panel-title .mono {
color: #496675;
}
.field-label {
display: block;
margin-bottom: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
}
select {
width: 100%;
height: 38px;
padding: 0 34px 0 11px;
appearance: none;
color: var(--text);
background:
linear-gradient(45deg, transparent 50%, var(--cyan) 50%) calc(100% - 15px) 16px / 5px 5px no-repeat,
linear-gradient(135deg, var(--cyan) 50%, transparent 50%) calc(100% - 10px) 16px / 5px 5px no-repeat,
#0c1d2b;
border: 1px solid rgba(130, 181, 205, 0.18);
border-radius: 0;
outline: none;
font: 600 11px ui-monospace, SFMono-Regular, Menlo, monospace;
}
select:focus {
border-color: rgba(57, 230, 197, 0.55);
}
.range-row {
display: flex;
align-items: center;
gap: 12px;
margin: 16px 0;
}
.range-row label {
flex: 0 0 auto;
color: var(--muted);
font-size: 9px;
font-weight: 700;
}
input[type="range"] {
width: 100%;
height: 3px;
accent-color: var(--cyan);
cursor: pointer;
}
.range-value {
flex: 0 0 32px;
color: var(--cyan);
text-align: right;
font: 700 10px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.bit-key {
display: flex;
align-items: center;
gap: 7px;
margin: 3px 0 14px;
color: var(--muted);
font: 600 9px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.bit {
display: grid;
width: 23px;
height: 23px;
place-items: center;
border: 1px solid rgba(130, 181, 205, 0.18);
color: #91aab6;
}
.bit.hole {
color: #06121c;
background: var(--cyan);
border-color: var(--cyan);
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
button {
min-height: 38px;
padding: 8px 10px;
color: #cfe0e5;
background: rgba(18, 39, 54, 0.82);
border: 1px solid rgba(130, 181, 205, 0.18);
border-radius: 0;
cursor: pointer;
font: 700 9px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
transition:
border-color 160ms ease,
color 160ms ease,
background 160ms ease;
}
button:hover {
color: white;
background: rgba(27, 56, 73, 0.9);
border-color: rgba(57, 230, 197, 0.45);
}
button.primary {
color: #07111d;
background: var(--cyan);
border-color: var(--cyan);
}
button.primary:hover {
background: #6ff5dc;
}
button.active {
color: var(--cyan);
border-color: rgba(57, 230, 197, 0.5);
}
.camera-help {
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid rgba(130, 181, 205, 0.1);
color: #587481;
font: 600 8px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.05em;
}
.bin-summary {
display: flex;
justify-content: space-between;
align-items: flex-end;
margin-bottom: 14px;
}
.summary-value {
font-size: 30px;
line-height: 0.9;
font-weight: 760;
letter-spacing: -0.05em;
}
.summary-label {
margin-top: 6px;
color: var(--muted);
font-size: 8px;
font-weight: 700;
letter-spacing: 0.12em;
}
.summary-rate {
color: var(--muted);
font: 600 9px ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: right;
}
.bin-list {
display: grid;
gap: 8px;
}
.bin-row {
display: grid;
grid-template-columns: 9px 1fr auto;
align-items: center;
gap: 10px;
padding: 9px 10px;
background: rgba(255, 255, 255, 0.025);
border: 1px solid rgba(130, 181, 205, 0.09);
}
.bin-color {
width: 7px;
height: 22px;
background: var(--bin-color);
box-shadow: 0 0 12px color-mix(in srgb, var(--bin-color) 50%, transparent);
}
.bin-name {
font: 700 10px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
}
.bin-index {
margin-top: 3px;
color: #587481;
font: 600 8px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.bin-count {
color: var(--bin-color);
font: 700 16px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.progress-track {
height: 3px;
margin-top: 13px;
overflow: hidden;
background: rgba(130, 181, 205, 0.1);
}
.progress-fill {
width: 0;
height: 100%;
background: var(--cyan);
box-shadow: 0 0 12px rgba(57, 230, 197, 0.7);
transition: width 180ms linear;
}
.hint {
position: fixed;
z-index: 2;
left: 50%;
bottom: 24px;
transform: translateX(-50%);
padding: 8px 11px;
color: #526f7c;
background: rgba(7, 17, 29, 0.65);
border: 1px solid rgba(130, 181, 205, 0.1);
font: 600 8px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
pointer-events: none;
}
@media (max-width: 950px) {
.record-card {
top: 112px;
}
.hint {
display: none;
}
}
@media (max-width: 720px) {
.brand {
top: 17px;
left: 17px;
}
.brand p,
.status {
display: none;
}
.record-card {
top: 93px;
width: calc(100vw - 34px);
}
.controls {
left: 12px;
bottom: 12px;
width: calc(50vw - 18px);
padding: 12px;
}
.bins-panel {
right: 12px;
bottom: 12px;
width: calc(50vw - 18px);
padding: 12px;
}
.bit-key,
.camera-help,
.summary-rate {
display: none;
}
.range-row {
gap: 6px;
}
.bin-row {
grid-template-columns: 6px 1fr auto;
gap: 6px;
padding: 7px;
}
.bin-name {
font-size: 8px;
}
}
@media (max-width: 480px) {
.controls,
.bins-panel {
width: calc(100vw - 24px);
}
.bins-panel {
display: none;
}
.controls {
right: 12px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive 3D voxel record sorting machine"></canvas>
<header class="brand">
<div class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i>
<i></i><i></i><i></i>
<i></i><i></i><i></i>
</div>
<div>
<p class="eyebrow">Punch / Route 03</p>
<h1>Voxel Record Sorter</h1>
<p>One encoded field. Three punch weights. Three destinations.</p>
</div>
</header>
<div class="status" id="status">
<span class="status-dot"></span>
<span id="statusText">System running</span>
</div>
<section class="record-card" id="recordCard" aria-live="polite">
<div class="record-top">
<span class="record-id" id="recordId">AWAITING INPUT</span>
<span class="record-state" id="recordState">Reader idle</span>
</div>
<h2 class="record-name" id="recordName">Queue initialized</h2>
<div class="record-meta" id="recordMeta"></div>
</section>
<aside class="panel controls">
<div class="panel-title">
<span>Control deck</span>
<span class="mono">SYS—03</span>
</div>
<label class="field-label" for="fieldSelect">Encoded field</label>
<select id="fieldSelect">
<option value="priority">Priority</option>
<option value="department">Department</option>
<option value="region">Region</option>
</select>
<div class="range-row">
<label for="speed">Throughput</label>
<input id="speed" type="range" min="0.5" max="2" value="1" step="0.25" />
<span class="range-value" id="speedValue">1.0×</span>
</div>
<div class="bit-key" aria-label="Three bit encoding">
<span>WEIGHT</span>
<span class="bit hole">1</span>
<span class="bit hole">2</span>
<span class="bit hole">4</span>
<span>PUNCH = 1</span>
</div>
<div class="button-row">
<button class="primary" id="pauseButton">Pause</button>
<button id="batchButton">New batch</button>
<button class="active" id="punchButton">Punches on</button>
<button id="cameraButton">Reset view</button>
</div>
<div class="camera-help">
Drag: orbit · wheel: zoom · shift-drag: pan<br />
Double-click: reset camera
</div>
</aside>
<aside class="panel bins-panel">
<div class="panel-title">
<span>Routing manifest</span>
<span class="mono">LIVE</span>
</div>
<div class="bin-summary">
<div>
<div class="summary-value" id="sortedCount">00 / 12</div>
<div class="summary-label">Records sorted</div>
</div>
<div class="summary-rate" id="rateText">31.6 / MIN<br />NOMINAL</div>
</div>
<div class="bin-list">
<div class="bin-row" style="--bin-color: var(--cyan)">
<span class="bin-color"></span>
<div>
<div class="bin-name" id="binName0">LOW</div>
<div class="bin-index">BIN / 01</div>
</div>
<span class="bin-count" id="binCount0">00</span>
</div>
<div class="bin-row" style="--bin-color: var(--amber)">
<span class="bin-color"></span>
<div>
<div class="bin-name" id="binName1">MEDIUM</div>
<div class="bin-index">BIN / 02</div>
</div>
<span class="bin-count" id="binCount1">00</span>
</div>
<div class="bin-row" style="--bin-color: var(--pink)">
<span class="bin-color"></span>
<div>
<div class="bin-name" id="binName2">HIGH</div>
<div class="bin-index">BIN / 03</div>
</div>
<span class="bin-count" id="binCount2">00</span>
</div>
</div>
<div class="progress-track">
<div class="progress-fill" id="progressFill"></div>
</div>
</aside>
<div class="hint">THREE.JS CORE / PROCEDURAL CARDS / LOCAL SIMULATION</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const ui = {
field: document.querySelector("#fieldSelect"),
speed: document.querySelector("#speed"),
speedValue: document.querySelector("#speedValue"),
pause: document.querySelector("#pauseButton"),
batch: document.querySelector("#batchButton"),
punches: document.querySelector("#punchButton"),
camera: document.querySelector("#cameraButton"),
status: document.querySelector("#status"),
statusText: document.querySelector("#statusText"),
recordCard: document.querySelector("#recordCard"),
recordId: document.querySelector("#recordId"),
recordState: document.querySelector("#recordState"),
recordName: document.querySelector("#recordName"),
recordMeta: document.querySelector("#recordMeta"),
sorted: document.querySelector("#sortedCount"),
rate: document.querySelector("#rateText"),
progress: document.querySelector("#progressFill"),
binNames: [
document.querySelector("#binName0"),
document.querySelector("#binName1"),
document.querySelector("#binName2")
],
binCounts: [
document.querySelector("#binCount0"),
document.querySelector("#binCount1"),
document.querySelector("#binCount2")
]
};
const BIN_COLORS = [0x39e6c5, 0xffc857, 0xff5d8f];
const BIN_CSS = ["#39e6c5", "#ffc857", "#ff5d8f"];
const FIELD_DEFS = {
priority: {
label: "Priority",
values: ["LOW", "MEDIUM", "HIGH"]
},
department: {
label: "Department",
values: ["ARCHIVE", "RESEARCH", "SOFTWARE"]
},
region: {
label: "Region",
values: ["PACIFIC", "EURO", "AMER"]
}
};
const RECORDS = [
{
id: "VR-1042",
name: "Lyra Quell",
priority: "HIGH",
department: "RESEARCH",
region: "AMER",
note: "Relay archive"
},
{
id: "VR-1043",
name: "Orion Vale",
priority: "MEDIUM",
department: "ARCHIVE",
region: "EURO",
note: "Moon index"
},
{
id: "VR-1044",
name: "Mira Sol",
priority: "LOW",
department: "SOFTWARE",
region: "PACIFIC",
note: "Telemetry patch"
},
{
id: "VR-1045",
name: "Cass Aster",
priority: "HIGH",
department: "SOFTWARE",
region: "EURO",
note: "Vector compiler"
},
{
id: "VR-1046",
name: "Niko Wren",
priority: "MEDIUM",
department: "RESEARCH",
region: "PACIFIC",
note: "Orbital survey"
},
{
id: "VR-1047",
name: "Eden Flux",
priority: "LOW",
department: "ARCHIVE",
region: "AMER",
note: "Glass ledger"
},
{
id: "VR-1048",
name: "Zia North",
priority: "HIGH",
department: "RESEARCH",
region: "PACIFIC",
note: "Deep relay"
},
{
id: "VR-1049",
name: "Rune Calder",
priority: "MEDIUM",
department: "SOFTWARE",
region: "AMER",
note: "Circuit atlas"
},
{
id: "VR-1050",
name: "Sable Pike",
priority: "LOW",
department: "ARCHIVE",
region: "EURO",
note: "Paper cache"
},
{
id: "VR-1051",
name: "Vera Mosaic",
priority: "HIGH",
department: "ARCHIVE",
region: "EURO",
note: "Signal vault"
},
{
id: "VR-1052",
name: "Juno Sparks",
priority: "MEDIUM",
department: "RESEARCH",
region: "AMER",
note: "Field study"
},
{
id: "VR-1053",
name: "Ari Ember",
priority: "LOW",
department: "SOFTWARE",
region: "PACIFIC",
note: "Maintenance log"
}
];
let selectedField = "priority";
let speed = 1;
let paused = false;
let showPunches = true;
let simulationTime = 0;
let cards = [];
let sortedTotal = 0;
let binCounts = [0, 0, 0];
let scanActivity = 0;
let scanColor = new THREE.Color(BIN_COLORS[0]);
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);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111d);
scene.fog = new THREE.FogExp2(0x07111d, 0.027);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const orbit = {
radius: 16.2,
theta: 0.68,
phi: 1.04,
target: new THREE.Vector3(0, 1.05, 0)
};
function resetCamera() {
orbit.radius = 16.2;
orbit.theta = 0.68;
orbit.phi = 1.04;
orbit.target.set(0, 1.05, 0);
}
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xbcecff, 0x10202d, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(-4, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x2b8dff, 1.8);
rimLight.position.set(6, 5, -8);
scene.add(rimLight);
const cyanLight = new THREE.PointLight(0x39e6c5, 16, 10, 2);
cyanLight.position.set(-3, 4, 4);
scene.add(cyanLight);
const standard = (color, roughness = 0.72, metalness = 0.12) =>
new THREE.MeshStandardMaterial({
color,
roughness,
metalness
});
const basic = (color, opacity = 1) =>
new THREE.MeshBasicMaterial({
color,
transparent: opacity < 1,
opacity,
depthWrite: opacity >= 1
});
function box(
width,
height,
depth,
material,
x = 0,
y = 0,
z = 0,
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Ground and technical grid.
box(
28,
0.25,
18,
standard(0x081723, 0.92, 0.05),
0,
-0.17,
0
);
const grid = new THREE.GridHelper(28, 28, 0x1a4053, 0x102634);
grid.position.y = -0.035;
grid.material.transparent = true;
grid.material.opacity = 0.58;
scene.add(grid);
// Conveyor.
const conveyor = new THREE.Group();
scene.add(conveyor);
const deckMaterial = standard(0x182a37, 0.76, 0.28);
const deckEdgeMaterial = standard(0x2a4655, 0.62, 0.36);
const rollerMaterial = standard(0x527180, 0.48, 0.55);
const railMaterial = standard(0x193544, 0.64, 0.4);
box(8.2, 0.34, 2.08, deckMaterial, -2.65, 1.05, 0, conveyor);
box(7.95, 0.06, 1.72, standard(0x0b1720, 0.95, 0.02), -2.65, 1.25, 0, conveyor);
for (let x = -6.35; x <= 1.05; x += 0.43) {
box(0.14, 0.12, 1.82, rollerMaterial, x, 1.34, 0, conveyor);
}
box(8.15, 0.15, 0.13, railMaterial, -2.65, 1.47, 1.1, conveyor);
box(8.15, 0.15, 0.13, railMaterial, -2.65, 1.47, -1.1, conveyor);
for (const x of [-6.0, -3.25, -0.5]) {
for (const z of [-0.83, 0.83]) {
box(0.2, 1.05, 0.2, deckEdgeMaterial, x, 0.52, z, conveyor);
box(0.42, 0.09, 0.38, railMaterial, x, 0.05, z, conveyor);
}
}
// Reader arch.
const reader = new THREE.Group();
reader.position.x = 0.25;
scene.add(reader);
const readerMaterial = standard(0x274858, 0.56, 0.44);
const readerDark = standard(0x0c1923, 0.74, 0.28);
box(0.28, 1.5, 0.25, readerMaterial, 0, 1.98, 1.15, reader);
box(0.28, 1.5, 0.25, readerMaterial, 0, 1.98, -1.15, reader);
box(0.52, 0.27, 2.55, readerMaterial, 0, 2.72, 0, reader);
box(0.32, 0.12, 1.8, readerDark, 0, 2.54, 0, reader);
const readerLampMaterial = basic(0x39e6c5);
box(0.12, 0.08, 1.35, readerLampMaterial, 0, 2.55, 0, reader);
const scanBeamMaterial = new THREE.MeshBasicMaterial({
color: 0x39e6c5,
transparent: true,
opacity: 0.08,
depthWrite: false,
side: THREE.DoubleSide,
blending: THREE.AdditiveBlending
});
const scanBeam = new THREE.Mesh(
new THREE.PlaneGeometry(2.0, 1.55),
scanBeamMaterial
);
scanBeam.rotation.x = -Math.PI / 2;
scanBeam.position.set(0.25, 1.42, 0);
scene.add(scanBeam);
const scanPoint = new THREE.PointLight(0x39e6c5, 5, 5, 2);
scanPoint.position.set(0.25, 2.5, 0);
scene.add(scanPoint);
const scanStrip = box(
0.035,
0.025,
1.68,
basic(0x39e6c5),
0.25,
1.405,
0
);
// Route tracks.
const binPositions = [-2.55, 0, 2.55];
const routeP0 = new THREE.Vector3(0.3, 1.32, 0);
const routeP2s = binPositions.map(
(z) => new THREE.Vector3(4.15, 1.32, z)
);
function quadraticPoint(p0, p1, p2, t, target) {
const inv = 1 - t;
target.set(
inv * inv * p0.x + 2 * inv * t * p1.x + t * t * p2.x,
inv * inv * p0.y + 2 * inv * t * p1.y + t * t * p2.y,
inv * inv * p0.z + 2 * inv * t * p1.z + t * t * p2.z
);
return target;
}
for (let bin = 0; bin < 3; bin++) {
const p1 = new THREE.Vector3(1.65, 1.32, binPositions[bin] * 0.38);
const p2 = routeP2s[bin];
const segmentGeometry = new THREE.BoxGeometry(1, 0.055, 0.15);
const routeMaterial = standard(BIN_COLORS[bin], 0.68, 0.25);
for (let s = 0; s < 25; s++) {
const a = quadraticPoint(
routeP0,
p1,
p2,
s / 25,
new THREE.Vector3()
);
const b = quadraticPoint(
routeP0,
p1,
p2,
(s + 1) / 25,
new THREE.Vector3()
);
const midpoint = a.clone().add(b).multiplyScalar(0.5);
const direction = b.clone().sub(a);
const segment = new THREE.Mesh(segmentGeometry, routeMaterial);
segment.position.copy(midpoint);
segment.rotation.y = Math.atan2(-direction.z, direction.x);
segment.receiveShadow = true;
scene.add(segment);
}
}
// Bins.
const bins = [];
function roundedRect(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.arcTo(x + width, y, x + width, y + height, radius);
ctx.arcTo(x + width, y + height, x, y + height, radius);
ctx.arcTo(x, y + height, x, y, radius);
ctx.arcTo(x, y, x + width, y, radius);
ctx.closePath();
}
function createBinLabel(text, color, parent) {
const spriteCanvas = document.createElement("canvas");
spriteCanvas.width = 512;
spriteCanvas.height = 128;
const ctx = spriteCanvas.getContext("2d");
ctx.clearRect(0, 0, 512, 128);
roundedRect(ctx, 8, 8, 496, 112, 12);
ctx.fillStyle = "rgba(7, 17, 29, 0.92)";
ctx.fill();
ctx.lineWidth = 4;
ctx.strokeStyle = color;
ctx.stroke();
ctx.fillStyle = color;
ctx.font = "700 42px ui-monospace, monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 64);
const texture = new THREE.CanvasTexture(spriteCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(2.45, 0.61, 1);
sprite.position.set(-0.1, 2.38, 0);
sprite.renderOrder = 4;
parent.add(sprite);
return sprite;
}
function updateBinLabel(bin, text, color) {
const oldSprite = bins[bin].label;
const oldTexture = oldSprite.material.map;
bins[bin].label = createBinLabel(text, color, bins[bin].group);
bins[bin].group.remove(oldSprite);
oldTexture.dispose();
oldSprite.material.dispose();
}
for (let i = 0; i < 3; i++) {
const group = new THREE.Group();
group.position.set(4.95, 0, binPositions[i]);
scene.add(group);
const bodyMaterial = standard(0x122735, 0.8, 0.22);
const trimMaterial = standard(BIN_COLORS[i], 0.58, 0.28);
box(2.15, 0.17, 2.15, bodyMaterial, 0, 0.19, 0, group);
box(0.16, 1.34, 2.12, bodyMaterial, 1.0, 0.91, 0, group);
box(2.12, 1.34, 0.16, bodyMaterial, 0, 0.91, 1.0, group);
box(2.12, 1.34, 0.16, bodyMaterial, 0, 0.91, -1.0, group);
box(0.14, 0.42, 2.12, bodyMaterial, -1.0, 0.48, 0, group);
box(0.13, 0.1, 2.18, trimMaterial, 1.02, 1.61, 0, group);
box(2.15, 0.1, 0.13, trimMaterial, 0, 1.61, 1.01, group);
box(2.15, 0.1, 0.13, trimMaterial, 0, 1.61, -1.01, group);
box(0.1, 0.07, 2.12, trimMaterial, -1.02, 0.71, 0, group);
box(0.28, 0.42, 0.28, bodyMaterial, 0.83, 1.79, -0.78, group);
box(
0.11,
0.11,
0.11,
basic(BIN_COLORS[i]),
0.83,
2.03,
-0.78,
group
);
const light = new THREE.PointLight(BIN_COLORS[i], 0.5, 4.2, 2);
light.position.set(0, 1.2, 0);
group.add(light);
const label = createBinLabel(
`0${i + 1} / ${FIELD_DEFS[selectedField].values[i]}`,
BIN_CSS[i],
group
);
bins.push({ group, light, label });
}
// Card geometry.
const cardBaseGeometry = new THREE.BoxGeometry(1.9, 0.12, 1.15);
const cardEdgeGeometry = new THREE.BoxGeometry(1.74, 0.025, 0.045);
const holeGeometry = new THREE.BoxGeometry(0.18, 0.035, 0.18);
const serialGeometry = new THREE.BoxGeometry(0.055, 0.025, 0.18);
const cardBaseMaterial = standard(0xd9e0d3, 0.86, 0.02);
const cardEdgeMaterial = standard(0x718d8b, 0.76, 0.08);
const holeMaterial = standard(0x081118, 0.98, 0.0);
const serialMaterial = standard(0x435c61, 0.82, 0.02);
function fieldValue(record) {
return record[selectedField];
}
function createCard(record, index) {
const group = new THREE.Group();
const base = new THREE.Mesh(cardBaseGeometry, cardBaseMaterial);
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
box(
1.75,
0.022,
0.04,
cardEdgeMaterial,
0,
0.072,
0.43,
group
);
for (let s = 0; s < 7; s++) {
const serial = new THREE.Mesh(serialGeometry, serialMaterial);
serial.position.set(-0.32 + s * 0.105, 0.074, 0.22);
group.add(serial);
}
const valueIndex = FIELD_DEFS[selectedField].values.indexOf(
fieldValue(record)
);
const punchMask = valueIndex + 1;
const holes = [];
for (let bit = 0; bit < 3; bit++) {
if (punchMask & (1 << bit)) {
const hole = new THREE.Mesh(holeGeometry, holeMaterial);
hole.position.set(-0.55 + bit * 0.55, 0.075, -0.25);
hole.castShadow = true;
group.add(hole);
holes.push(hole);
}
}
group.visible = false;
scene.add(group);
return {
group,
record,
bin: valueIndex,
holes,
start: 0.18 + index * 1.88,
scanned: false,
routed: false,
counted: false,
landing: null
};
}
function removeCards() {
for (const card of cards) {
scene.remove(card.group);
}
cards = [];
}
function buildBatch(shuffle = true) {
removeCards();
simulationTime = 0;
sortedTotal = 0;
binCounts = [0, 0, 0];
scanActivity = 0;
const order = RECORDS.map((record, index) => ({ record, index }));
if (shuffle) {
for (let i = order.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[order[i], order[j]] = [order[j], order[i]];
}
}
cards = order.map((item, index) => createCard(item.record, index));
ui.sorted.textContent = `00 / ${String(cards.length).padStart(2, "0")}`;
ui.progress.style.width = "0%";
for (let i = 0; i < 3; i++) {
ui.binCounts[i].textContent = "00";
}
ui.recordId.textContent = "AWAITING INPUT";
ui.recordState.textContent = "Reader idle";
ui.recordName.textContent = "Queue initialized";
ui.recordMeta.innerHTML = "";
}
function updateFieldLabels() {
const def = FIELD_DEFS[selectedField];
for (let i = 0; i < 3; i++) {
ui.binNames[i].textContent = def.values[i];
updateBinLabel(
i,
`0${i + 1} / ${def.values[i]}`,
BIN_CSS[i]
);
}
}
function triggerScan(card) {
const value = fieldValue(card.record);
ui.recordId.textContent = `${card.record.id} / ${value}`;
ui.recordState.textContent = "Punch field decoded";
ui.recordName.textContent = card.record.name;
const chips = [
`<span class="record-chip encoded">${FIELD_DEFS[selectedField].label}: ${value}</span>`
];
for (const [key, value] of Object.entries(card.record)) {
if (
key !== "id" &&
key !== "name" &&
key !== "note" &&
key !== selectedField
) {
chips.push(
`<span class="record-chip">${key}: ${value}</span>`
);
}
}
chips.push(`<span class="record-chip">${card.record.note}</span>`);
ui.recordMeta.innerHTML = chips.join("");
ui.recordCard.classList.remove("hit");
void ui.recordCard.offsetWidth;
ui.recordCard.classList.add("hit");
scanActivity = 1;
scanColor.setHex(BIN_COLORS[card.bin]);
}
const tempPosition = new THREE.Vector3();
const tempNext = new THREE.Vector3();
const tempDirection = new THREE.Vector3();
function updateCards() {
const beltDuration = 3.55;
const routeDuration = 1.9;
const dropDuration = 0.86;
let activeScan = 0;
let activeScanColor = null;
for (const card of cards) {
const t = simulationTime - card.start;
if (t < 0) {
card.group.visible = false;
continue;
}
card.group.visible = true;
if (t < beltDuration) {
const p = t / beltDuration;
const eased = p * p * (3 - 2 * p);
card.group.position.set(
THREE.MathUtils.lerp(-6.25, 0.25, eased),
1.48,
0
);
card.group.rotation.set(0, 0, 0);
card.group.scale.setScalar(1);
if (t >= beltDuration - 0.34 && !card.scanned) {
card.scanned = true;
triggerScan(card);
}
if (t >= beltDuration - 0.34 && t <= beltDuration + 0.25) {
activeScan = 1;
activeScanColor = card.bin;
}
} else if (t < beltDuration + routeDuration) {
const p = (t - beltDuration) / routeDuration;
const eased = p * p * (3 - 2 * p);
const binZ = binPositions[card.bin];
const p0 = routeP0;
const p1 = new THREE.Vector3(1.65, 1.32, binZ * 0.38);
const p2 = routeP2s[card.bin];
quadraticPoint(p0, p1, p2, eased, tempPosition);
quadraticPoint(
p0,
p1,
p2,
Math.min(1, eased + 0.01),
tempNext
);
tempDirection.copy(tempNext).sub(tempPosition);
card.group.position.copy(tempPosition);
card.group.position.y = 1.48 + Math.sin(Math.PI * eased) * 0.2;
card.group.rotation.y = Math.atan2(
-tempDirection.z,
tempDirection.x
);
card.group.rotation.z = Math.sin(p * Math.PI * 2) * 0.035;
card.group.scale.setScalar(THREE.MathUtils.lerp(1, 0.72, eased));
if (!card.routed) {
card.routed = true;
const slot = binCounts[card.bin];
card.landing = new THREE.Vector3(
4.7 + ((slot % 2) * 0.2 - 0.1),
0.37,
binZ + (((slot % 3) - 1) * 0.22)
);
}
} else if (t < beltDuration + routeDuration + dropDuration) {
const p =
(t - beltDuration - routeDuration) / dropDuration;
const start = new THREE.Vector3(4.15, 1.48, binPositions[card.bin]);
const end = card.landing || new THREE.Vector3(4.7, 0.37, binPositions[card.bin]);
card.group.position.lerpVectors(start, end, p);
card.group.position.y += Math.sin(Math.PI * p) * 0.12;
card.group.rotation.x = p * 0.72;
card.group.rotation.z = p * 0.48;
card.group.scale.setScalar(0.72);
} else {
if (!card.counted) {
card.counted = true;
sortedTotal += 1;
binCounts[card.bin] += 1;
bins[card.bin].light.intensity = 4.2;
}
card.group.visible = false;
}
}
scanActivity = Math.max(scanActivity * 0.91, activeScan);
if (activeScanColor !== null) {
scanColor.setHex(BIN_COLORS[activeScanColor]);
}
scanBeamMaterial.color.copy(scanColor);
scanStrip.material.color.copy(scanColor);
readerLampMaterial.color.copy(scanColor);
scanPoint.color.copy(scanColor);
scanBeamMaterial.opacity = 0.055 + scanActivity * 0.46;
scanPoint.intensity = 4 + scanActivity * 13;
}
function updateUI() {
for (let i = 0; i < 3; i++) {
ui.binCounts[i].textContent = String(binCounts[i]).padStart(2, "0");
bins[i].light.intensity *= 0.91;
}
ui.sorted.textContent =
`${String(sortedTotal).padStart(2, "0")} / ${String(cards.length).padStart(2, "0")}`;
ui.progress.style.width = `${(sortedTotal / cards.length) * 100}%`;
const cardsPerMinute = (60 / 1.88) * speed;
ui.rate.innerHTML = `${cardsPerMinute.toFixed(1)} / MIN<br />${
paused ? "PAUSED" : "NOMINAL"
}`;
}
// Custom camera controls. No external controls addon is used.
const pointers = new Map();
let dragging = false;
let panMode = false;
let previousX = 0;
let previousY = 0;
let pinchDistance = 0;
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
dragging = true;
panMode = event.button === 2 || event.shiftKey;
previousX = event.clientX;
previousY = event.clientY;
} else if (pointers.size === 2) {
const values = [...pointers.values()];
pinchDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const values = [...pointers.values()];
const distance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (pinchDistance > 0) {
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * (pinchDistance / distance),
9,
25
);
}
pinchDistance = distance;
return;
}
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();
camera.getWorldDirection(right);
right.cross(camera.up).normalize();
const scale = orbit.radius * 0.0013;
orbit.target.addScaledVector(right, -dx * scale);
orbit.target.y += dy * scale;
orbit.target.x = THREE.MathUtils.clamp(
orbit.target.x,
-5,
5
);
orbit.target.z = THREE.MathUtils.clamp(
orbit.target.z,
-4,
4
);
orbit.target.y = THREE.MathUtils.clamp(
orbit.target.y,
0,
3
);
} else {
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + dy * 0.005,
0.48,
1.42
);
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 0) {
dragging = false;
panMode = false;
pinchDistance = 0;
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
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),
9,
25
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
// UI events.
ui.field.addEventListener("change", () => {
selectedField = ui.field.value;
updateFieldLabels();
buildBatch(true);
});
ui.speed.addEventListener("input", () => {
speed = Number(ui.speed.value);
ui.speedValue.textContent = `${speed.toFixed(1)}×`;
});
ui.pause.addEventListener("click", () => {
paused = !paused;
ui.pause.textContent = paused ? "Resume" : "Pause";
ui.pause.classList.toggle("primary", paused);
ui.status.classList.toggle("paused", paused);
ui.statusText.textContent = paused ? "System paused" : "System running";
});
ui.batch.addEventListener("click", () => {
buildBatch(true);
});
ui.punches.addEventListener("click", () => {
showPunches = !showPunches;
ui.punches.textContent = showPunches ? "Punches on" : "Punches off";
ui.punches.classList.toggle("active", showPunches);
for (const card of cards) {
for (const hole of card.holes) {
hole.visible = showPunches;
}
}
});
ui.camera.addEventListener("click", resetCamera);
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
updateFieldLabels();
buildBatch(true);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) {
simulationTime += delta * speed;
}
updateCards();
updateUI();
updateCamera();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```