Prompt specification
Build or customize the Three.js 3D scene "Change a sorting key and compare groups" 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: Change a sorting key and compare groups
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/change-a-sorting-key-and-compare-groups-x2520
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing punched-card data processing. Let users sort the same fictional cards by two different fields. Show that record contents remain unchanged while their grouping and order differ. Low-poly.
Working Three.js Starter (change-a-sorting-key-and-compare-groups-x2520):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Punch / Sort — Punched-Card Data Processing</title>
<style>
:root {
--ink: #15363b;
--ink-deep: #0d292e;
--paper: #f2e8cf;
--paper-light: #fff8e8;
--orange: #ee7048;
--gold: #e5b64f;
--teal: #4ba99f;
--active-accent: #ee7048;
--line: rgba(21, 54, 59, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9d2c1;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body::after {
content: "";
position: fixed;
inset: 0;
pointer-events: none;
opacity: 0.055;
z-index: 20;
background-image:
repeating-radial-gradient(circle at 20% 30%, #15363b 0 0.5px, transparent 0.8px 4px),
repeating-radial-gradient(circle at 80% 70%, #15363b 0 0.4px, transparent 0.7px 5px);
mix-blend-mode: multiply;
}
canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
cursor: grab;
touch-action: none;
}
canvas:active {
cursor: grabbing;
}
.hero {
position: fixed;
top: 28px;
left: 32px;
z-index: 5;
pointer-events: none;
user-select: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--ink);
font: 700 11px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.18em;
}
.eyebrow-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 0 4px rgba(238, 112, 72, 0.16);
}
h1 {
margin: 0;
font-size: clamp(34px, 4vw, 58px);
line-height: 0.88;
letter-spacing: -0.075em;
font-weight: 900;
}
h1 span {
color: var(--orange);
font-weight: 400;
margin: 0 0.05em;
}
.hero p {
margin: 12px 0 0;
color: rgba(21, 54, 59, 0.72);
font-size: 13px;
font-weight: 650;
letter-spacing: 0.01em;
}
.controls {
position: fixed;
z-index: 6;
top: 28px;
right: 30px;
width: 334px;
padding: 16px;
border: 1px solid rgba(255, 248, 232, 0.72);
border-radius: 16px;
background: rgba(248, 241, 222, 0.88);
box-shadow:
0 18px 48px rgba(20, 49, 53, 0.13),
inset 0 1px 0 rgba(255, 255, 255, 0.75);
backdrop-filter: blur(16px) saturate(1.1);
}
.control-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 11px;
font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.16em;
}
.control-heading span:last-child {
color: rgba(21, 54, 59, 0.5);
font-weight: 700;
}
.switcher {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
padding: 5px;
border-radius: 12px;
background: rgba(21, 54, 59, 0.08);
}
.sort-button {
position: relative;
min-height: 56px;
padding: 10px 10px 9px;
border: 1px solid transparent;
border-radius: 9px;
color: var(--ink);
background: transparent;
cursor: pointer;
text-align: left;
transition:
color 180ms ease,
background 180ms ease,
transform 180ms ease,
box-shadow 180ms ease;
}
.sort-button:hover:not(:disabled) {
background: rgba(255, 248, 232, 0.58);
}
.sort-button.active {
color: var(--paper-light);
background: var(--ink);
box-shadow: 0 5px 13px rgba(21, 54, 59, 0.2);
}
.sort-button strong {
display: block;
font-size: 13px;
font-weight: 900;
letter-spacing: 0.07em;
}
.sort-button small {
display: block;
margin-top: 4px;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.06em;
opacity: 0.62;
}
.sort-button .number {
position: absolute;
top: 8px;
right: 9px;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
opacity: 0.42;
}
.control-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid var(--line);
}
.status {
display: flex;
align-items: center;
gap: 7px;
font: 800 9px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.08em;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 3px rgba(75, 169, 159, 0.14);
}
body.processing .status-dot {
background: var(--orange);
animation: statusPulse 650ms ease-in-out infinite alternate;
}
@keyframes statusPulse {
to {
box-shadow: 0 0 0 6px rgba(238, 112, 72, 0.08);
transform: scale(1.22);
}
}
.text-button {
padding: 0;
border: 0;
color: rgba(21, 54, 59, 0.7);
background: none;
cursor: pointer;
font: 800 9px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.08em;
}
.text-button:hover {
color: var(--orange);
}
.ledger {
position: fixed;
z-index: 6;
left: 30px;
right: 30px;
bottom: 23px;
display: grid;
grid-template-columns: minmax(0, 1.4fr) minmax(285px, 0.6fr);
min-height: 188px;
overflow: hidden;
border: 1px solid rgba(242, 232, 207, 0.16);
border-radius: 18px;
color: var(--paper);
background: rgba(13, 41, 46, 0.95);
box-shadow: 0 22px 65px rgba(17, 43, 47, 0.28);
backdrop-filter: blur(18px);
}
.order-panel {
padding: 18px 21px 16px;
min-width: 0;
}
.section-heading {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 13px;
font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.15em;
}
.active-key {
padding: 5px 7px;
border-radius: 5px;
color: var(--ink-deep);
background: var(--active-accent);
font-size: 9px;
letter-spacing: 0.1em;
transition: background 300ms ease;
}
.group-grid {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 10px;
}
.group-cell {
position: relative;
min-height: 66px;
padding: 9px 10px 9px 13px;
overflow: hidden;
border: 1px solid rgba(242, 232, 207, 0.13);
border-radius: 9px;
background: rgba(255, 255, 255, 0.035);
}
.group-cell::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 4px;
background: var(--group-color);
}
.group-name {
display: block;
overflow: hidden;
color: rgba(242, 232, 207, 0.62);
font: 800 9px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.08em;
text-overflow: ellipsis;
white-space: nowrap;
}
.group-records {
display: flex;
align-items: center;
gap: 7px;
margin-top: 9px;
font: 900 16px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.group-arrow {
color: rgba(242, 232, 207, 0.32);
font-size: 11px;
}
.sequence-row {
display: flex;
align-items: center;
gap: 16px;
margin-top: 13px;
padding-top: 11px;
border-top: 1px solid rgba(242, 232, 207, 0.1);
}
.sequence-label {
flex: 0 0 auto;
color: rgba(242, 232, 207, 0.46);
font: 800 9px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.13em;
}
.sequence {
display: flex;
align-items: center;
gap: 7px;
min-width: 0;
overflow: hidden;
font: 800 11px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
white-space: nowrap;
}
.sequence .record-token {
padding: 4px 6px;
border-radius: 4px;
color: var(--paper);
background: rgba(242, 232, 207, 0.09);
}
.sequence .separator {
color: rgba(242, 232, 207, 0.28);
}
.integrity {
display: flex;
flex-direction: column;
padding: 18px 20px 15px;
border-left: 1px solid rgba(242, 232, 207, 0.13);
background: rgba(255, 255, 255, 0.025);
}
.integrity .section-heading {
justify-content: space-between;
}
.lock {
color: var(--teal);
font-size: 9px;
letter-spacing: 0.09em;
}
.record-summary {
display: flex;
align-items: baseline;
gap: 10px;
margin-bottom: 9px;
}
.record-summary strong {
color: var(--active-accent);
font: 900 24px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
transition: color 300ms ease;
}
.record-summary span {
color: rgba(242, 232, 207, 0.72);
font-size: 11px;
font-weight: 750;
}
.record-fields {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px 14px;
}
.field {
display: flex;
justify-content: space-between;
gap: 8px;
padding-bottom: 4px;
border-bottom: 1px solid rgba(242, 232, 207, 0.08);
font: 700 9px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.field span {
color: rgba(242, 232, 207, 0.38);
letter-spacing: 0.07em;
}
.field strong {
color: rgba(242, 232, 207, 0.87);
letter-spacing: 0.03em;
}
.hash-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: auto;
padding-top: 9px;
color: rgba(242, 232, 207, 0.42);
font: 700 8px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.11em;
}
.hash-value {
color: var(--paper);
letter-spacing: 0.08em;
}
.hash-value.flash {
animation: hashFlash 750ms ease;
}
@keyframes hashFlash {
35% {
color: var(--active-accent);
text-shadow: 0 0 14px rgba(238, 112, 72, 0.65);
}
}
.tips {
position: fixed;
z-index: 5;
left: 34px;
bottom: 224px;
display: flex;
gap: 17px;
color: rgba(21, 54, 59, 0.54);
font: 800 9px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.08em;
pointer-events: none;
}
.tips span::before {
content: "◆";
margin-right: 7px;
color: var(--orange);
font-size: 7px;
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
color: var(--ink);
background: #d9d2c1;
font: 800 11px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.14em;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
.hero {
top: 19px;
left: 19px;
}
.hero p {
display: none;
}
.controls {
top: 16px;
right: 16px;
width: 284px;
}
.ledger {
left: 15px;
right: 15px;
bottom: 15px;
grid-template-columns: 1fr;
max-height: 45vh;
overflow-y: auto;
}
.integrity {
border-top: 1px solid rgba(242, 232, 207, 0.13);
border-left: 0;
}
.tips {
display: none;
}
}
@media (max-width: 620px) {
.hero .eyebrow {
font-size: 8px;
}
h1 {
font-size: 31px;
}
.controls {
top: 82px;
width: 250px;
padding: 12px;
}
.control-heading span:last-child {
display: none;
}
.group-grid {
grid-template-columns: 1fr;
}
.group-cell {
min-height: 54px;
}
.sequence-row {
align-items: flex-start;
flex-direction: column;
gap: 8px;
}
.sequence {
max-width: 100%;
overflow-x: auto;
padding-bottom: 3px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly punched-card sorting scene"></canvas>
<header class="hero">
<div class="eyebrow">
<span class="eyebrow-dot"></span>
PAYLOAD PROCESSING / UNIT 07
</div>
<h1>PUNCH<span>/</span>SORT</h1>
<p>Six records. Two keys. Zero mutations.</p>
</header>
<section class="controls" aria-label="Sorting controls">
<div class="control-heading">
<span>CHOOSE SORT FIELD</span>
<span>PAYLOAD LOCKED</span>
</div>
<div class="switcher" role="group" aria-label="Sort cards by field">
<button
class="sort-button active"
id="sort-crew"
type="button"
aria-pressed="true"
>
<span class="number">01</span>
<strong>CREW</strong>
<small>A → B → C</small>
</button>
<button
class="sort-button"
id="sort-priority"
type="button"
aria-pressed="false"
>
<span class="number">02</span>
<strong>PRIORITY</strong>
<small>01 → 02 → 03</small>
</button>
</div>
<div class="control-row">
<div class="status" aria-live="polite">
<span class="status-dot"></span>
<span id="status-text">SORTED / CREW</span>
</div>
<button class="text-button" id="reset-view" type="button">RESET VIEW</button>
</div>
</section>
<div class="tips" aria-hidden="true">
<span>DRAG TO ORBIT</span>
<span>SCROLL TO ZOOM</span>
<span>CLICK A CARD</span>
</div>
<section class="ledger" aria-label="Active card order and payload integrity">
<div class="order-panel">
<div class="section-heading">
<span>ACTIVE ORDER</span>
<span class="active-key" id="active-key">CREW</span>
</div>
<div class="group-grid" id="group-grid"></div>
<div class="sequence-row">
<span class="sequence-label">SEQUENCE</span>
<div class="sequence" id="sequence"></div>
</div>
</div>
<aside class="integrity">
<div class="section-heading">
<span>PAYLOAD INTEGRITY</span>
<span class="lock">● LOCKED</span>
</div>
<div id="selected-record"></div>
<div class="hash-row">
<span>CONTENT HASH</span>
<strong class="hash-value" id="content-hash">--------</strong>
</div>
</aside>
</section>
<div id="loading">LOADING THREE.JS CORE…</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 loading = document.querySelector("#loading");
const groupGrid = document.querySelector("#group-grid");
const sequenceElement = document.querySelector("#sequence");
const activeKeyElement = document.querySelector("#active-key");
const selectedRecordElement = document.querySelector("#selected-record");
const hashElement = document.querySelector("#content-hash");
const statusText = document.querySelector("#status-text");
const crewButton = document.querySelector("#sort-crew");
const priorityButton = document.querySelector("#sort-priority");
const SECTION_COLORS = {
HELIOS: "#e5b64f",
AURORA: "#4ba99f",
VEGA: "#df755d"
};
const PRIORITY_COLORS = {
1: "#ee7048",
2: "#e5b64f",
3: "#4ba99f"
};
// The exact same six records are reused for every sort.
// Only their order and grouping change.
const records = [
{
id: "101",
name: "ADA VALE",
crew: "CREW A",
section: "HELIOS",
priority: 3,
value: 480
},
{
id: "102",
name: "BO CHEN",
crew: "CREW A",
section: "HELIOS",
priority: 2,
value: 220
},
{
id: "103",
name: "CY BELL",
crew: "CREW B",
section: "AURORA",
priority: 1,
value: 760
},
{
id: "104",
name: "DARA KNOX",
crew: "CREW B",
section: "AURORA",
priority: 2,
value: 590
},
{
id: "105",
name: "ELIO MOSS",
crew: "CREW C",
section: "VEGA",
priority: 1,
value: 310
},
{
id: "106",
name: "FEN ROY",
crew: "CREW C",
section: "VEGA",
priority: 3,
value: 640
}
];
const recordById = new Map(records.map(record => [record.id, record]));
function contentHash() {
const canonical = records
.map(record =>
[
record.id,
record.name,
record.crew,
record.section,
record.priority,
record.value
].join(":")
)
.join("|");
let hash = 2166136261;
for (let i = 0; i < canonical.length; i++) {
hash ^= canonical.charCodeAt(i);
hash = Math.imul(hash, 16777619);
}
return (hash >>> 0).toString(16).padStart(8, "0").toUpperCase();
}
const stableHash = contentHash();
hashElement.textContent = stableHash;
// ----- Renderer and 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);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#d9d2c1");
scene.fog = new THREE.Fog("#d9d2c1", 19, 35);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraTarget = new THREE.Vector3(0, 1.65, 0);
const defaultCamera = {
theta: -0.035,
phi: 1.245,
radius: 17.6
};
const desiredCamera = { ...defaultCamera };
const currentCamera = { ...defaultCamera };
function updateCamera() {
const sinPhi = Math.sin(currentCamera.phi);
const cosPhi = Math.cos(currentCamera.phi);
camera.position.set(
cameraTarget.x +
currentCamera.radius * sinPhi * Math.sin(currentCamera.theta),
cameraTarget.y + currentCamera.radius * cosPhi,
cameraTarget.z +
currentCamera.radius * sinPhi * Math.cos(currentCamera.theta)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
Object.assign(desiredCamera, defaultCamera);
}
// ----- Lighting ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xfff3d8,
0x17363b,
1.75
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(
0xffefd1,
2.7
);
keyLight.position.set(-5.5, 10.5, 8.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -6;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0008;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(
0x8fcac5,
1.05
);
fillLight.position.set(8, 5, -5);
scene.add(fillLight);
// ----- Helpers -------------------------------------------------------------
function roundedRect(context, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
context.beginPath();
context.moveTo(x + r, y);
context.arcTo(x + width, y, x + width, y + height, r);
context.arcTo(x + width, y + height, x, y + height, r);
context.arcTo(x, y + height, x, y, r);
context.arcTo(x, y, x + width, y, r);
context.closePath();
}
function makeCanvasTexture(canvasElement) {
const texture = new THREE.CanvasTexture(canvasElement);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
4,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function makeCardTexture(record) {
const cardCanvas = document.createElement("canvas");
cardCanvas.width = 512;
cardCanvas.height = 700;
const context = cardCanvas.getContext("2d");
const sectionColor = SECTION_COLORS[record.section];
const priorityColor = PRIORITY_COLORS[record.priority];
context.fillStyle = "#f4ead1";
context.fillRect(0, 0, 512, 700);
// Perforation strip and colored section band.
context.fillStyle = "#d8c9a6";
context.fillRect(0, 0, 72, 700);
context.fillStyle = sectionColor;
context.fillRect(72, 0, 440, 12);
context.fillStyle = "#15363b";
context.font = "700 17px monospace";
context.fillText("PUNCH / 07", 101, 55);
context.font = "900 57px monospace";
context.fillText(record.id, 100, 132);
context.font = "800 25px monospace";
context.fillText(record.name, 101, 171);
context.strokeStyle = "rgba(21,54,59,0.30)";
context.lineWidth = 2;
context.beginPath();
context.moveTo(100, 198);
context.lineTo(475, 198);
context.stroke();
const rows = [
["CREW", record.crew],
["SECTION", record.section],
["LEDGER", `${record.value} CR`]
];
rows.forEach((row, index) => {
const y = 250 + index * 80;
context.fillStyle = "rgba(21,54,59,0.45)";
context.font = "700 15px monospace";
context.fillText(row[0], 101, y);
context.fillStyle = "#15363b";
context.font = "900 26px monospace";
context.fillText(row[1], 101, y + 33);
context.strokeStyle = "rgba(21,54,59,0.14)";
context.lineWidth = 2;
context.beginPath();
context.moveTo(101, y + 52);
context.lineTo(475, y + 52);
context.stroke();
});
// Priority is a record field, not a sorting-time mutation.
context.fillStyle = priorityColor;
roundedRect(context, 358, 222, 117, 80, 13);
context.fill();
context.fillStyle = "#15363b";
context.textAlign = "center";
context.font = "700 13px monospace";
context.fillText("PRIORITY", 416.5, 247);
context.font = "900 36px monospace";
context.fillText(`0${record.priority}`, 416.5, 285);
context.textAlign = "left";
context.fillStyle = "rgba(21,54,59,0.42)";
context.font = "700 14px monospace";
context.fillText("PAYLOAD RECORD", 101, 622);
context.fillText("FIELDS LOCKED", 101, 649);
// Tiny printed batch marks.
context.fillStyle = "#15363b";
for (let i = 0; i < 22; i++) {
if ((i * 7 + Number(record.id)) % 4 !== 0) {
context.fillRect(365 + i * 4.2, 640, 1.5, 12);
}
}
return makeCanvasTexture(cardCanvas);
}
function makeGroupLabelTexture(title, subtitle, accentColor) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 640;
labelCanvas.height = 150;
const context = labelCanvas.getContext("2d");
roundedRect(context, 7, 7, 626, 136, 24);
context.fillStyle = "#15363b";
context.fill();
context.fillStyle = accentColor;
roundedRect(context, 18, 18, 13, 114, 6);
context.fill();
context.fillStyle = "#fff8e8";
context.font = "900 42px monospace";
context.fillText(title, 53, 66);
context.fillStyle = "rgba(255,248,232,0.55)";
context.font = "700 19px monospace";
context.fillText(subtitle.toUpperCase(), 55, 105);
return makeCanvasTexture(labelCanvas);
}
function makeBox(
width,
height,
depth,
color,
position,
options = {}
) {
const geometry = new THREE.BoxGeometry(width, height, depth);
const material = new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.86,
metalness: options.metalness ?? 0,
flatShading: true,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
return mesh;
}
// ----- Low-poly processing platform ----------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(70, 70),
new THREE.MeshStandardMaterial({
color: "#d9d2c1",
roughness: 1,
flatShading: true
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.7;
ground.receiveShadow = true;
scene.add(ground);
const stage = new THREE.Mesh(
new THREE.CylinderGeometry(10.7, 11.35, 0.62, 8),
new THREE.MeshStandardMaterial({
color: "#193f44",
roughness: 0.78,
flatShading: true
})
);
stage.position.y = -0.4;
stage.rotation.y = Math.PI / 8;
stage.castShadow = true;
stage.receiveShadow = true;
scene.add(stage);
const stageTop = new THREE.Mesh(
new THREE.CylinderGeometry(10.55, 10.7, 0.08, 8),
new THREE.MeshStandardMaterial({
color: "#ded4bd",
roughness: 0.95,
flatShading: true
})
);
stageTop.position.y = -0.05;
stageTop.rotation.y = Math.PI / 8;
stageTop.receiveShadow = true;
scene.add(stageTop);
const backPlate = makeBox(
13.55,
3.65,
0.3,
"#15363b",
[0, 1.72, -3.45]
);
scene.add(backPlate);
const groupCenters = [-4.35, 0, 4.35];
groupCenters.forEach((center, index) => {
const panel = makeBox(
4.18,
3.46,
0.12,
index === 1 ? "#1d464b" : "#1a4146",
[center, 1.68, -3.25],
{ castShadow: false }
);
scene.add(panel);
const panelEdge = new THREE.LineSegments(
new THREE.EdgesGeometry(panel.geometry),
new THREE.LineBasicMaterial({
color: 0x6a9997,
transparent: true,
opacity: 0.24
})
);
panelEdge.position.copy(panel.position);
panelEdge.position.z += 0.065;
scene.add(panelEdge);
const tray = makeBox(
4.28,
0.12,
2.05,
"#b7aa8d",
[center, -0.01, 0.1],
{ roughness: 1 }
);
scene.add(tray);
const trayRail = makeBox(
4.12,
0.04,
0.12,
"#355b5e",
[center, 0.07, 1.03],
{ castShadow: false }
);
scene.add(trayRail);
});
const topBeam = makeBox(
14.1,
0.28,
0.44,
"#102f34",
[0, 3.48, -3.43]
);
scene.add(topBeam);
// A small low-poly sorter/rotor at the input side.
const rotor = new THREE.Group();
rotor.position.set(-7.25, 1.1, -1.95);
rotor.rotation.y = 0.2;
scene.add(rotor);
const rotorHousing = new THREE.Mesh(
new THREE.CylinderGeometry(1.05, 1.16, 0.38, 8),
new THREE.MeshStandardMaterial({
color: "#e5b64f",
roughness: 0.75,
flatShading: true
})
);
rotorHousing.rotation.x = Math.PI / 2;
rotorHousing.castShadow = true;
rotor.add(rotorHousing);
const rotorCore = new THREE.Mesh(
new THREE.CylinderGeometry(0.72, 0.72, 0.43, 8),
new THREE.MeshStandardMaterial({
color: "#15363b",
roughness: 0.7,
flatShading: true
})
);
rotorCore.rotation.x = Math.PI / 2;
rotor.add(rotorCore);
for (let i = 0; i < 4; i++) {
const spoke = makeBox(
1.16,
0.11,
0.08,
"#f0c966",
[0, 0, 0.25],
{ castShadow: false }
);
spoke.rotation.z = (i * Math.PI) / 4;
rotor.add(spoke);
}
const rotorHub = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.22, 0),
new THREE.MeshStandardMaterial({
color: "#ee7048",
emissive: "#ee7048",
emissiveIntensity: 0.22,
flatShading: true
})
);
rotorHub.position.z = 0.3;
rotor.add(rotorHub);
// Input card hopper.
const hopper = new THREE.Group();
hopper.position.set(-6.25, 0.05, -0.2);
hopper.rotation.y = 0.22;
scene.add(hopper);
hopper.add(
makeBox(
2.55,
0.24,
2.15,
"#264d51",
[0, 0.03, 0]
)
);
for (let i = 0; i < 5; i++) {
const stackCard = makeBox(
2.05,
0.075,
2.68,
i % 2 ? "#cabd9d" : "#e5d8b9",
[0, 0.24 + i * 0.085, 0],
{ roughness: 1 }
);
stackCard.rotation.y = (i - 2) * 0.012;
hopper.add(stackCard);
}
const hopperLip = makeBox(
2.65,
0.42,
0.16,
"#ee7048",
[0, 0.32, 1.03]
);
hopper.add(hopperLip);
// ----- Punched cards -------------------------------------------------------
const cards = new Map();
const pickables = [];
const cardEdgeMaterial = new THREE.MeshStandardMaterial({
color: "#b9aa88",
roughness: 1,
flatShading: true
});
const selectionMaterial = new THREE.LineBasicMaterial({
color: 0xee7048,
transparent: true,
opacity: 0.98,
depthTest: false
});
records.forEach((record, index) => {
const group = new THREE.Group();
group.userData.recordId = record.id;
group.userData.baseRotationZ = index % 2 === 0 ? -0.012 : 0.012;
const faceMaterial = new THREE.MeshStandardMaterial({
map: makeCardTexture(record),
color: 0xffffff,
roughness: 0.96,
metalness: 0,
flatShading: true
});
const body = new THREE.Mesh(
new THREE.BoxGeometry(2.05, 2.82, 0.12),
[
cardEdgeMaterial,
cardEdgeMaterial,
cardEdgeMaterial,
cardEdgeMaterial,
faceMaterial,
cardEdgeMaterial
]
);
body.castShadow = true;
body.receiveShadow = true;
body.userData.recordId = record.id;
group.add(body);
pickables.push(body);
// Raised perforation rims and dark holes.
const holeRimMaterial = new THREE.MeshStandardMaterial({
color: "#aa9a77",
roughness: 1,
flatShading: true
});
const holeMaterial = new THREE.MeshBasicMaterial({
color: "#17363b"
});
for (let holeIndex = 0; holeIndex < 9; holeIndex++) {
const y = -1.08 + holeIndex * 0.27;
const rim = new THREE.Mesh(
new THREE.CircleGeometry(0.115, 10),
holeRimMaterial
);
rim.position.set(-0.82, y, 0.066);
group.add(rim);
const hole = new THREE.Mesh(
new THREE.CircleGeometry(0.072, 10),
holeMaterial
);
hole.position.set(-0.82, y, 0.068);
group.add(hole);
}
// Small fixed priority marker. It is part of the original record.
const marker = makeBox(
0.16,
0.16,
0.055,
PRIORITY_COLORS[record.priority],
[0.83, 0.96, 0.09],
{ castShadow: false }
);
group.add(marker);
const selectionFrame = new THREE.LineSegments(
new THREE.EdgesGeometry(
new THREE.BoxGeometry(2.14, 2.91, 0.16)
),
selectionMaterial
);
selectionFrame.position.z = 0.015;
selectionFrame.visible = false;
selectionFrame.renderOrder = 10;
group.add(selectionFrame);
group.userData.selectionFrame = selectionFrame;
cards.set(record.id, group);
scene.add(group);
});
// ----- Dynamic group headings ----------------------------------------------
const groupLabels = groupCenters.map(center => {
const material = new THREE.SpriteMaterial({
map: makeGroupLabelTexture("GROUP", "WAITING", "#ee7048"),
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.position.set(center, 3.68, 0.2);
sprite.scale.set(3.18, 0.75, 1);
sprite.renderOrder = 8;
scene.add(sprite);
return sprite;
});
// ----- Sorting and UI ------------------------------------------------------
let activeSort = "crew";
let selectedId = "101";
let tweens = [];
let sorting = false;
function buildGroups(sortField) {
const map = new Map();
records.forEach(record => {
const key =
sortField === "crew"
? record.crew
: String(record.priority).padStart(2, "0");
if (!map.has(key)) {
map.set(key, []);
}
map.get(key).push(record);
});
return Array.from(map.entries())
.sort((a, b) => a[0].localeCompare(b[0]))
.map(([key, groupedRecords]) => ({
key,
records: groupedRecords.slice().sort((a, b) =>
a.id.localeCompare(b.id)
)
}));
}
function groupColor(group, index) {
if (activeSort === "crew") {
const section = group.records[0].section;
return SECTION_COLORS[section];
}
return PRIORITY_COLORS[Number(group.key)];
}
function groupTitle(group) {
return activeSort === "crew"
? group.key
: `PRIORITY ${group.key}`;
}
function groupSubtitle(group) {
return activeSort === "crew"
? `${group.records[0].section} / ${group.records.length} RECORDS`
: `${group.records.length} RECORDS / ${group.records[0].name.split(" ")[0]} FIRST`;
}
function updateLedger(groups) {
activeKeyElement.textContent = activeSort.toUpperCase();
groupGrid.innerHTML = groups
.map(group => {
const color = groupColor(group);
const recordsMarkup = group.records
.map((record, index) => {
const arrow =
index > 0
? '<span class="group-arrow">→</span>'
: "";
return `${arrow}<span>${record.id}</span>`;
})
.join("");
return `
<div class="group-cell" style="--group-color:${color}">
<span class="group-name">${groupTitle(group)}</span>
<div class="group-records">${recordsMarkup}</div>
</div>
`;
})
.join("");
const allRecords = groups.flatMap(group => group.records);
sequenceElement.innerHTML = allRecords
.map((record, index) => {
const separator = index
? '<span class="separator">→</span>'
: "";
return `${separator}<span class="record-token">${record.id}</span>`;
})
.join("");
document.documentElement.style.setProperty(
"--active-accent",
activeSort === "crew"
? SECTION_COLORS[groups[0].records[0].section]
: PRIORITY_COLORS[1]
);
updateSelectedRecord();
}
function updateSelectedRecord() {
const record = recordById.get(selectedId);
if (!record) {
return;
}
selectedRecordElement.innerHTML = `
<div class="record-summary">
<strong>${record.id}</strong>
<span>${record.name}</span>
</div>
<div class="record-fields">
<div class="field"><span>CREW</span><strong>${record.crew}</strong></div>
<div class="field"><span>PRIORITY</span><strong>0${record.priority}</strong></div>
<div class="field"><span>SECTION</span><strong>${record.section}</strong></div>
<div class="field"><span>VALUE</span><strong>${record.value} CR</strong></div>
</div>
`;
}
function selectRecord(id) {
selectedId = id;
cards.forEach((card, cardId) => {
card.userData.selectionFrame.visible = cardId === id;
});
updateSelectedRecord();
}
function easeInOutCubic(value) {
return value < 0.5
? 4 * value * value * value
: 1 - Math.pow(-2 * value + 2, 3) / 2;
}
function sortCards(sortField, immediate = false) {
activeSort = sortField;
const groups = buildGroups(sortField);
groups.forEach((group, groupIndex) => {
const sprite = groupLabels[groupIndex];
const oldTexture = sprite.material.map;
sprite.material.map = makeGroupLabelTexture(
groupTitle(group),
groupSubtitle(group),
groupColor(group, groupIndex)
);
sprite.material.needsUpdate = true;
oldTexture.dispose();
});
tweens = [];
const now = performance.now();
const duration = 1150;
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
let cardIndex = 0;
groups.forEach((group, groupIndex) => {
group.records.forEach((record, recordIndex) => {
const card = cards.get(record.id);
const withinGroupOffset =
(recordIndex - (group.records.length - 1) / 2) * 2.18;
const targetPosition = new THREE.Vector3(
groupCenters[groupIndex] + withinGroupOffset,
1.57,
0.26 + recordIndex * 0.035
);
const targetRotation = new THREE.Euler(
0,
0,
card.userData.baseRotationZ
);
if (immediate || reducedMotion) {
card.position.copy(targetPosition);
card.rotation.copy(targetRotation);
} else {
tweens.push({
card,
start: performance.now(),
delay: cardIndex * 58,
duration,
fromPosition: card.position.clone(),
toPosition: targetPosition,
fromRotation: card.rotation.clone(),
toRotation: targetRotation,
arcDirection: cardIndex % 2 === 0 ? 1 : -1
});
}
cardIndex++;
});
});
updateLedger(groups);
if (!immediate) {
sorting = true;
document.body.classList.add("processing");
statusText.textContent = `ROUTING / ${sortField.toUpperCase()}`;
window.setTimeout(() => {
sorting = false;
document.body.classList.remove("processing");
statusText.textContent = `SORTED / ${sortField.toUpperCase()}`;
hashElement.classList.remove("flash");
void hashElement.offsetWidth;
hashElement.classList.add("flash");
}, duration + 180);
}
}
function setActiveButton(sortField) {
const crewIsActive = sortField === "crew";
crewButton.classList.toggle("active", crewIsActive);
priorityButton.classList.toggle("active", !crewIsActive);
crewButton.setAttribute("aria-pressed", String(crewIsActive));
priorityButton.setAttribute("aria-pressed", String(!crewIsActive));
}
crewButton.addEventListener("click", () => {
if (sorting || activeSort === "crew") {
return;
}
setActiveButton("crew");
sortCards("crew");
});
priorityButton.addEventListener("click", () => {
if (sorting || activeSort === "priority") {
return;
}
setActiveButton("priority");
sortCards("priority");
});
document.querySelector("#reset-view").addEventListener("click", resetCamera);
canvas.addEventListener("dblclick", resetCamera);
// ----- Direct camera controls ----------------------------------------------
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
let pointerDown = null;
let dragging = false;
function recordAt(clientX, clientY) {
const bounds = canvas.getBoundingClientRect();
pointer.x = ((clientX - bounds.left) / bounds.width) * 2 - 1;
pointer.y = -((clientY - bounds.top) / bounds.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const intersection = raycaster.intersectObjects(pickables, false)[0];
return intersection ? intersection.object.userData.recordId : null;
}
canvas.addEventListener("pointerdown", event => {
if (event.button !== 0) {
return;
}
pointerDown = {
x: event.clientX,
y: event.clientY,
pointerId: event.pointerId
};
dragging = false;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (pointerDown) {
const totalDistance = Math.hypot(
event.clientX - pointerDown.x,
event.clientY - pointerDown.y
);
if (totalDistance > 4) {
dragging = true;
}
if (dragging) {
const deltaX = event.clientX - pointerDown.x;
const deltaY = event.clientY - pointerDown.y;
desiredCamera.theta = THREE.MathUtils.clamp(
desiredCamera.theta - deltaX * 0.006,
-0.85,
0.85
);
desiredCamera.phi = THREE.MathUtils.clamp(
desiredCamera.phi - deltaY * 0.005,
0.82,
1.48
);
pointerDown.x = event.clientX;
pointerDown.y = event.clientY;
canvas.style.cursor = "grabbing";
}
return;
}
canvas.style.cursor = recordAt(event.clientX, event.clientY)
? "pointer"
: "grab";
});
canvas.addEventListener("pointerup", event => {
if (pointerDown && !dragging) {
const id = recordAt(event.clientX, event.clientY);
if (id) {
selectRecord(id);
}
}
if (pointerDown) {
try {
canvas.releasePointerCapture(pointerDown.pointerId);
} catch {
// The pointer may already have been released by the browser.
}
}
pointerDown = null;
dragging = false;
canvas.style.cursor = "grab";
});
canvas.addEventListener("pointercancel", () => {
pointerDown = null;
dragging = false;
canvas.style.cursor = "grab";
});
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
desiredCamera.radius = THREE.MathUtils.clamp(
desiredCamera.radius + event.deltaY * 0.012,
12.5,
24
);
},
{ passive: false }
);
// ----- Resize and animation ------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
camera.aspect = aspect;
camera.fov = aspect < 1 ? 58 : 38;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
sortCards("crew", true);
selectRecord(selectedId);
updateCamera();
function animate(now) {
requestAnimationFrame(animate);
// Smooth camera damping.
currentCamera.theta = THREE.MathUtils.lerp(
currentCamera.theta,
desiredCamera.theta,
0.1
);
currentCamera.phi = THREE.MathUtils.lerp(
currentCamera.phi,
desiredCamera.phi,
0.1
);
currentCamera.radius = THREE.MathUtils.lerp(
currentCamera.radius,
desiredCamera.radius,
0.1
);
updateCamera();
// Sorting animation with a forward arc.
for (let index = tweens.length - 1; index >= 0; index--) {
const tween = tweens[index];
const elapsed = now - tween.start - tween.delay;
if (elapsed < 0) {
continue;
}
const progress = THREE.MathUtils.clamp(
elapsed / tween.duration,
0,
1
);
const eased = easeInOutCubic(progress);
const arc = Math.sin(progress * Math.PI);
tween.card.position.lerpVectors(
tween.fromPosition,
tween.toPosition,
eased
);
tween.card.position.y += arc * 1.15;
tween.card.position.z += arc * 1.05;
tween.card.rotation.x = THREE.MathUtils.lerp(
tween.fromRotation.x,
tween.toRotation.x,
eased
);
tween.card.rotation.y = THREE.MathUtils.lerp(
tween.fromRotation.y,
tween.toRotation.y,
eased
) + arc * 0.16 * tween.arcDirection;
tween.card.rotation.z = THREE.MathUtils.lerp(
tween.fromRotation.z,
tween.toRotation.z,
eased
);
if (progress >= 1) {
tween.card.position.copy(tween.toPosition);
tween.card.rotation.copy(tween.toRotation);
tweens.splice(index, 1);
}
}
rotor.rotation.z += 0.0025;
rotorHub.material.emissiveIntensity =
0.18 + Math.sin(now * 0.004) * 0.12;
renderer.render(scene, camera);
if (!loading.classList.contains("hidden")) {
loading.classList.add("hidden");
}
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```