Prompt specification
Build or customize the Three.js 3D scene "Historical data-processing room workflow" 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: Historical data-processing room workflow
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/historical-data-processing-room-workflow-x2519
Scene Description Prompt:
Follow fictional punched cards through a low-poly historical keypunch room, separating preparation, sorting, storage, and tallying. Build one HTML file using Three.js from cdnjs.
Working Three.js Starter (historical-data-processing-room-workflow-x2519):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>The Keypunch Room — 1954</title>
<style>
:root {
--ink: #293535;
--muted: #64706c;
--paper: #f2ead7;
--paper-solid: #fff9e9;
--teal: #286c68;
--teal-dark: #174b49;
--rust: #b6543f;
--gold: #d3a54f;
--line: rgba(41, 53, 53, 0.2);
--shadow: 0 16px 45px rgba(35, 39, 34, 0.17);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cfc3a9;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
#masthead {
position: absolute;
top: 26px;
left: 28px;
width: min(460px, calc(100vw - 56px));
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 9px;
color: var(--teal-dark);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 31px;
height: 2px;
background: var(--rust);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(34px, 4.4vw, 64px);
font-weight: 500;
line-height: 0.94;
letter-spacing: -0.045em;
}
#masthead p {
max-width: 400px;
margin: 13px 0 0;
color: #4e5a56;
font-size: 13px;
line-height: 1.5;
}
#story {
position: absolute;
top: 24px;
right: 24px;
width: min(330px, calc(100vw - 48px));
padding: 21px 22px 19px;
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 3px;
background: rgba(255, 249, 233, 0.9);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
pointer-events: auto;
}
#story.pulse {
animation: storyPulse 0.45s ease;
}
@keyframes storyPulse {
0% { transform: translateY(4px); opacity: 0.65; }
100% { transform: translateY(0); opacity: 1; }
}
.story-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
margin-bottom: 12px;
}
#story-index {
color: var(--rust);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.fiction-stamp {
padding: 4px 7px;
border: 1px solid rgba(182, 84, 63, 0.45);
color: var(--rust);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
transform: rotate(-2deg);
}
#story h2 {
margin: 0 0 8px;
font-family: Georgia, "Times New Roman", serif;
font-size: 27px;
font-weight: 500;
letter-spacing: -0.025em;
}
#story-text {
min-height: 64px;
margin: 0;
color: #53605b;
font-size: 12px;
line-height: 1.55;
}
.record-card {
display: grid;
grid-template-columns: 1fr auto;
gap: 6px 14px;
margin-top: 17px;
padding-top: 13px;
border-top: 1px solid var(--line);
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.record-card span:nth-child(odd) {
color: #7a827c;
}
.record-card span:nth-child(even) {
color: var(--ink);
font-weight: 750;
text-align: right;
}
#labels {
position: absolute;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.stage-label {
position: absolute;
min-width: 118px;
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.6);
border-radius: 2px;
background: rgba(31, 67, 65, 0.88);
box-shadow: 0 8px 24px rgba(19, 39, 37, 0.18);
color: #fff6dc;
cursor: pointer;
pointer-events: auto;
text-align: left;
transform: translate(-50%, -100%);
transition: background 160ms ease, transform 160ms ease;
}
.stage-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 15px;
background: rgba(255, 246, 220, 0.75);
}
.stage-label:hover,
.stage-label.active {
background: rgba(176, 78, 57, 0.94);
}
.stage-label:hover {
transform: translate(-50%, calc(-100% - 3px));
}
.stage-label b {
display: block;
margin-bottom: 2px;
color: #d9bd76;
font-size: 9px;
letter-spacing: 0.16em;
}
.stage-label span {
display: block;
font-family: Georgia, "Times New Roman", serif;
font-size: 15px;
}
#card-tag {
position: absolute;
padding: 6px 9px;
border-left: 3px solid var(--rust);
border-radius: 1px;
background: rgba(255, 249, 233, 0.94);
box-shadow: 0 8px 25px rgba(32, 39, 35, 0.16);
color: var(--ink);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.11em;
text-transform: uppercase;
transform: translate(-50%, -100%);
white-space: nowrap;
}
#stage-nav {
position: absolute;
left: 28px;
bottom: 112px;
display: flex;
gap: 6px;
flex-wrap: wrap;
max-width: min(700px, calc(100vw - 56px));
pointer-events: auto;
}
#stage-nav button {
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 2px;
background: rgba(246, 238, 219, 0.84);
box-shadow: 0 7px 20px rgba(40, 47, 42, 0.1);
color: #52605a;
cursor: pointer;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: 160ms ease;
}
#stage-nav button:hover,
#stage-nav button.active {
border-color: var(--teal);
background: var(--teal);
color: #fff8df;
}
#dock {
position: absolute;
left: 50%;
bottom: 24px;
display: grid;
grid-template-columns: 42px minmax(220px, 560px) 56px auto;
align-items: center;
gap: 14px;
width: min(850px, calc(100vw - 48px));
padding: 13px 15px;
border: 1px solid rgba(255, 255, 255, 0.6);
border-radius: 3px;
background: rgba(255, 249, 233, 0.91);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
transform: translateX(-50%);
pointer-events: auto;
}
#play {
width: 42px;
height: 42px;
border: 0;
border-radius: 50%;
background: var(--teal);
color: #fff8df;
cursor: pointer;
font-size: 15px;
transition: transform 150ms ease, background 150ms ease;
}
#play:hover {
background: var(--rust);
transform: scale(1.05);
}
.timeline-wrap {
min-width: 0;
}
.timeline-labels {
display: flex;
justify-content: space-between;
margin-bottom: 7px;
color: #78817a;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
#timeline {
width: 100%;
height: 4px;
margin: 0;
border-radius: 10px;
outline: none;
background: linear-gradient(
90deg,
var(--teal) 0%,
var(--teal) var(--progress, 0%),
#d5cdbb var(--progress, 0%),
#d5cdbb 100%
);
cursor: pointer;
appearance: none;
}
#timeline::-webkit-slider-thumb {
width: 14px;
height: 14px;
border: 3px solid var(--paper-solid);
border-radius: 50%;
background: var(--rust);
box-shadow: 0 1px 4px rgba(35, 35, 30, 0.28);
appearance: none;
}
#timeline::-moz-range-thumb {
width: 10px;
height: 10px;
border: 3px solid var(--paper-solid);
border-radius: 50%;
background: var(--rust);
box-shadow: 0 1px 4px rgba(35, 35, 30, 0.28);
}
#percent {
color: var(--teal-dark);
font-size: 11px;
font-weight: 850;
text-align: right;
}
.dock-options {
display: flex;
align-items: center;
gap: 12px;
white-space: nowrap;
}
.switch {
display: flex;
align-items: center;
gap: 7px;
color: #56635d;
cursor: pointer;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.switch input {
width: 15px;
height: 15px;
accent-color: var(--teal);
}
#reset {
border: 0;
background: transparent;
color: var(--rust);
cursor: pointer;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#hint {
position: absolute;
right: 26px;
bottom: 27px;
color: rgba(38, 52, 49, 0.74);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.05em;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
}
#legend {
position: absolute;
left: 28px;
top: 157px;
display: flex;
align-items: center;
gap: 8px;
color: rgba(42, 56, 53, 0.75);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
#legend::before {
content: "";
width: 24px;
height: 3px;
background: var(--rust);
box-shadow: 0 0 0 2px rgba(182, 84, 63, 0.12);
}
@media (max-width: 850px) {
#story {
top: auto;
right: 14px;
bottom: 103px;
width: 290px;
padding: 15px 17px;
}
#story-text {
min-height: 0;
}
.record-card,
#legend,
#hint {
display: none;
}
#masthead {
top: 18px;
left: 18px;
}
#masthead p {
max-width: 290px;
font-size: 11px;
}
#stage-nav {
left: 18px;
bottom: 98px;
max-width: calc(100vw - 330px);
}
#stage-nav button {
padding: 7px 8px;
font-size: 8px;
}
#dock {
bottom: 12px;
grid-template-columns: 38px minmax(150px, 1fr) 45px;
width: calc(100vw - 24px);
padding: 10px;
}
.dock-options {
display: none;
}
}
@media (max-width: 590px) {
h1 {
font-size: 36px;
}
#masthead p {
display: none;
}
#story {
right: 12px;
bottom: 92px;
width: 255px;
}
#story h2 {
font-size: 22px;
}
#story-text {
font-size: 11px;
}
#stage-nav {
right: 12px;
left: 12px;
bottom: auto;
top: 98px;
max-width: none;
}
#stage-nav button {
flex: 1 1 auto;
}
.stage-label {
min-width: 90px;
padding: 6px 8px;
}
.stage-label span {
font-size: 12px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly 1950s keypunch room"></canvas>
<div class="ui">
<header id="masthead">
<div class="eyebrow">Personnel Archive · Room 04 · 1954</div>
<h1>The Keypunch Room</h1>
<p>
Follow one fictional payroll card as it moves from preparation to sorting,
temporary storage, and final tally.
</p>
</header>
<aside id="story" aria-live="polite">
<div class="story-top">
<div id="story-index">01 / Preparation</div>
<div class="fiction-stamp">Fictional Record</div>
</div>
<h2 id="story-title">Preparation</h2>
<p id="story-text"></p>
<div class="record-card">
<span>Card</span><span>04721</span>
<span>Employee</span><span>A. Moreno</span>
<span>Transaction</span><span>Payroll · 8</span>
<span>Destination</span><span>District 3</span>
</div>
</aside>
<div id="labels">
<button class="stage-label" data-stage="prep">
<b>01</b><span>Preparation</span>
</button>
<button class="stage-label" data-stage="sort">
<b>02</b><span>Sorting</span>
</button>
<button class="stage-label" data-stage="storage">
<b>03</b><span>Storage</span>
</button>
<button class="stage-label" data-stage="tally">
<b>04</b><span>Tallying</span>
</button>
<div id="card-tag">04721 · Payroll</div>
</div>
<div id="legend">Fictional punch-card route</div>
<nav id="stage-nav" aria-label="Explore processing stages">
<button id="overview" class="active">Overview</button>
<button data-stage="prep">01 · Prepare</button>
<button data-stage="sort">02 · Sort</button>
<button data-stage="storage">03 · Store</button>
<button data-stage="tally">04 · Tally</button>
</nav>
<section id="dock" aria-label="Card journey controls">
<button id="play" aria-label="Pause card journey">Ⅱ</button>
<div class="timeline-wrap">
<div class="timeline-labels">
<span>Preparation</span>
<span>Sorting</span>
<span>Storage</span>
<span>Tallying</span>
</div>
<input
id="timeline"
type="range"
min="0"
max="1000"
value="40"
aria-label="Position along the card journey"
/>
</div>
<output id="percent">4%</output>
<div class="dock-options">
<label class="switch">
<input id="follow" type="checkbox" />
Follow card
</label>
<button id="reset">Reset</button>
</div>
</section>
<div id="hint">Drag to orbit · Wheel to zoom · Right-drag to pan</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const story = document.querySelector("#story");
const storyIndex = document.querySelector("#story-index");
const storyTitle = document.querySelector("#story-title");
const storyText = document.querySelector("#story-text");
const playButton = document.querySelector("#play");
const timeline = document.querySelector("#timeline");
const percentOutput = document.querySelector("#percent");
const followInput = document.querySelector("#follow");
const overviewButton = document.querySelector("#overview");
const resetButton = document.querySelector("#reset");
const cardTag = document.querySelector("#card-tag");
const stageLabelElements = [...document.querySelectorAll(".stage-label")];
const stageNavButtons = [...document.querySelectorAll("#stage-nav [data-stage]")];
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcfc3a9);
scene.fog = new THREE.Fog(0xcfc3a9, 20, 37);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
80
);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const reducedMotion = matchMedia("(prefers-reduced-motion: reduce)").matches;
const clock = new THREE.Clock();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const hitTargets = [];
const M = {
wall: mat(0xd7c9af),
wallLow: mat(0x71827a),
wood: mat(0xa87845),
woodDark: mat(0x6e4d32),
woodLight: mat(0xc6985c),
teal: mat(0x397b75),
tealDark: mat(0x204e4b),
tealLight: mat(0x6f9a8c),
green: mat(0x687a54),
rust: mat(0xa84d3c),
cream: mat(0xe7dcc1),
paper: mat(0xf0e8d0),
ink: mat(0x283331),
black: mat(0x171d1b),
brass: mat(0xb89249, 0.65),
blue: mat(0x718d91),
pink: mat(0xc78875),
olive: mat(0x8d8d62),
glass: new THREE.MeshStandardMaterial({
color: 0xaac6c2,
roughness: 0.35,
transparent: true,
opacity: 0.72,
emissive: 0x6e9992,
emissiveIntensity: 0.18
})
};
function mat(color, metalness = 0) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness,
flatShading: true
});
}
function box(parent, size, material, position = [0, 0, 0]) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(
parent,
radiusTop,
radiusBottom,
height,
material,
position = [0, 0, 0],
segments = 8
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
material
);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function torus(parent, radius, tube, material, position = [0, 0, 0]) {
const mesh = new THREE.Mesh(
new THREE.TorusGeometry(radius, tube, 6, 12),
material
);
mesh.position.set(...position);
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderBetween(a, b, radius, material, parent = scene) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const mesh = cylinder(
parent,
radius,
radius,
direction.length(),
material,
[0, 0, 0],
6
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
function canvasTexture(draw, width = 512, height = 128) {
const c = document.createElement("canvas");
c.width = width;
c.height = height;
const ctx = c.getContext("2d");
draw(ctx, width, height);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function wallSign(parent, title, subtitle, width, height, position) {
const texture = canvasTexture((ctx, w, h) => {
ctx.fillStyle = "#204e4b";
ctx.fillRect(0, 0, w, h);
ctx.fillStyle = "#d3a54f";
ctx.fillRect(0, 0, 17, h);
ctx.strokeStyle = "rgba(255,255,255,.2)";
ctx.strokeRect(29, 17, w - 49, h - 34);
ctx.fillStyle = "#fff3cf";
ctx.textAlign = "center";
ctx.font = "bold 36px Georgia";
ctx.fillText(title, w / 2 + 5, h / 2 - 3);
ctx.fillStyle = "#d7c9a8";
ctx.font = "bold 16px Arial";
ctx.fillText(subtitle, w / 2 + 5, h / 2 + 29);
});
const material = new THREE.MeshStandardMaterial({
map: texture,
roughness: 0.84
});
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
material
);
mesh.position.set(...position);
parent.add(mesh);
return mesh;
}
function floorNumber(number, position) {
const texture = canvasTexture((ctx, w, h) => {
ctx.clearRect(0, 0, w, h);
ctx.fillStyle = "rgba(255,245,215,.7)";
ctx.textAlign = "center";
ctx.font = "bold 112px Georgia";
ctx.fillText(number, w / 2, h * 0.8);
}, 256, 256);
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(1.2, 1.2),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
mesh.rotation.x = -Math.PI / 2;
mesh.position.set(...position);
scene.add(mesh);
}
// Lighting
scene.add(new THREE.HemisphereLight(0xfff3d0, 0x5b6d67, 1.65));
const sun = new THREE.DirectionalLight(0xffefc9, 3.1);
sun.position.set(-5, 12, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0005;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9fc6c2, 0.65);
fill.position.set(10, 7, -5);
scene.add(fill);
function buildRoom() {
box(scene, [22.4, 0.28, 12.2], M.woodDark, [0, -0.2, 0]);
const floorMaterials = [
mat(0xb28a56),
mat(0xb9905b),
mat(0xa97f4f),
mat(0xc09660),
mat(0xb58b58)
];
for (let i = 0; i < 22; i++) {
box(
scene,
[0.985, 0.045, 12],
floorMaterials[i % floorMaterials.length],
[-10.5 + i, -0.015, 0]
);
}
const rugColors = [0x718c83, 0x9f8664, 0x718474, 0x9f765d];
const rugXs = [-7.0, -2.4, 3.0, 7.0];
rugXs.forEach((x, index) => {
box(
scene,
[4.45, 0.065, 6.65],
mat(rugColors[index]),
[x, 0.035, 0.05]
);
floorNumber(`0${index + 1}`, [x, 0.075, 2.55]);
});
box(scene, [22.3, 5.25, 0.28], M.wall, [0, 2.45, -5.85]);
box(scene, [0.28, 5.25, 12], M.wall, [-11.15, 2.45, 0]);
box(scene, [22.1, 1.35, 0.1], M.wallLow, [0, 0.64, -5.66]);
box(scene, [0.1, 1.35, 11.8], M.wallLow, [-10.96, 0.64, 0]);
box(scene, [22.2, 0.18, 0.18], M.woodDark, [0, 4.88, -5.45]);
box(scene, [0.18, 0.18, 11.9], M.woodDark, [-10.88, 4.88, 0]);
// High windows.
[-5, 0, 5].forEach((x) => {
box(scene, [2.65, 1.35, 0.08], M.glass, [x, 4.05, -5.66]);
box(scene, [2.86, 0.11, 0.14], M.cream, [x, 4.73, -5.58]);
box(scene, [2.86, 0.11, 0.14], M.cream, [x, 3.37, -5.58]);
box(scene, [0.11, 1.45, 0.14], M.cream, [x - 1.38, 4.05, -5.58]);
box(scene, [0.11, 1.45, 0.14], M.cream, [x + 1.38, 4.05, -5.58]);
box(scene, [0.08, 1.38, 0.15], M.cream, [x, 4.05, -5.56]);
});
// Wall signs.
wallSign(scene, "PREPARATION", "ALIGN · KEY · VERIFY", 2.85, 0.72, [-7, 3.15, -5.65]);
wallSign(scene, "SORTING", "CODE · ROUTE · VERIFY", 2.85, 0.72, [-2.4, 3.15, -5.65]);
wallSign(scene, "STORAGE", "TEMPORARY CARD FILE", 2.85, 0.72, [3, 3.15, -5.65]);
wallSign(scene, "TALLYING", "ADD · BALANCE · POST", 2.85, 0.72, [7, 3.15, -5.65]);
// Clock.
const clockGroup = new THREE.Group();
clockGroup.position.set(-0.25, 3.72, -5.52);
scene.add(clockGroup);
const clockFace = cylinder(clockGroup, 0.33, 0.33, 0.08, M.cream, [0, 0, 0], 16);
clockFace.rotation.x = Math.PI / 2;
const clockRim = torus(clockGroup, 0.34, 0.035, M.brass, [0, 0, 0.055]);
box(clockGroup, [0.025, 0.22, 0.025], M.ink, [0, 0.08, 0.085]);
const minute = box(clockGroup, [0.022, 0.28, 0.025], M.rust, [0, 0, 0.09]);
minute.rotation.z = -0.65;
// Notice board.
box(scene, [2.25, 1.18, 0.08], M.woodDark, [9.1, 2.18, -5.57]);
box(scene, [2.08, 1.01, 0.03], M.olive, [9.1, 2.18, -5.51]);
const calendarTexture = canvasTexture((ctx, w, h) => {
ctx.fillStyle = "#e9dfc4";
ctx.fillRect(0, 0, w, h);
ctx.fillStyle = "#294d4a";
ctx.fillRect(0, 0, w, 37);
ctx.fillStyle = "#fff3cf";
ctx.font = "bold 24px Arial";
ctx.fillText("OCTOBER 1954", 18, 27);
ctx.fillStyle = "#52605a";
ctx.font = "bold 18px Arial";
for (let row = 0; row < 3; row++) {
for (let col = 0; col < 8; col++) {
ctx.fillText(String(row * 8 + col + 1), 20 + col * 42, 78 + row * 34);
}
}
}, 384, 192);
const calendar = new THREE.Mesh(
new THREE.PlaneGeometry(1.72, 0.86),
new THREE.MeshStandardMaterial({ map: calendarTexture })
);
calendar.position.set(9.1, 2.19, -5.47);
scene.add(calendar);
// Pendant lights.
[-7, -2.4, 3, 7].forEach((x, index) => {
cylinderBetween([x, 4.85, -0.15], [x, 4.28, -0.15], 0.018, M.ink);
const shade = new THREE.Mesh(
new THREE.ConeGeometry(0.43, 0.38, 10, 1, true),
index % 2 ? M.rust : M.tealDark
);
shade.position.set(x, 4.12, -0.15);
shade.castShadow = true;
scene.add(shade);
const bulb = cylinder(
scene,
0.09,
0.09,
0.15,
new THREE.MeshStandardMaterial({
color: 0xffe5a8,
emissive: 0xffc55f,
emissiveIntensity: 1.5
}),
[x, 3.91, -0.15],
8
);
bulb.castShadow = false;
const light = new THREE.PointLight(0xffd99a, 13, 6.5, 2);
light.position.set(x, 3.75, -0.15);
scene.add(light);
});
}
function addStationHitbox(stage, x, z) {
const material = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
});
const hitbox = new THREE.Mesh(
new THREE.BoxGeometry(4.25, 3.1, 3.8),
material
);
hitbox.position.set(x, 1.55, z);
hitbox.userData.stage = stage;
scene.add(hitbox);
hitTargets.push(hitbox);
}
function addCardStack(parent, x, y, z, count = 5, color = M.paper) {
for (let i = 0; i < count; i++) {
const card = box(
parent,
[0.72, 0.022, 0.46],
color,
[x + (i % 2) * 0.018, y + i * 0.025, z]
);
card.rotation.y = (i % 2 ? 1 : -1) * 0.015;
}
}
function buildPreparation() {
const group = new THREE.Group();
group.position.set(-7, 0, -0.25);
scene.add(group);
box(group, [4.0, 0.16, 1.7], M.woodLight, [0, 1.25, 0]);
box(group, [3.5, 0.35, 1.45], M.woodDark, [0, 0.92, 0]);
[-1.75, 1.75].forEach((x) => {
[-0.62, 0.62].forEach((z) => {
box(group, [0.16, 1.1, 0.16], M.woodDark, [x, 0.55, z]);
});
});
addCardStack(group, -1.35, 1.36, 0.24, 8);
addCardStack(group, -1.22, 1.36, -0.32, 5);
const tray = box(group, [0.8, 0.12, 0.58], M.tealDark, [-1.25, 1.4, 0.62]);
tray.rotation.y = -0.08;
addCardStack(group, -1.25, 1.48, 0.62, 3);
// Forms and pencils.
const form = box(group, [0.68, 0.03, 0.85], M.paper, [-0.62, 1.35, 0.28]);
form.rotation.y = 0.12;
const pencil = cylinder(
group,
0.025,
0.025,
0.55,
M.rust,
[-0.2, 1.36, 0.44],
6
);
pencil.rotation.z = Math.PI / 2;
pencil.rotation.y = 0.3;
const machine = new THREE.Group();
machine.position.set(0.35, 1.34, -0.1);
group.add(machine);
box(machine, [1.35, 0.32, 1.12], M.tealDark, [0, 0.16, 0]);
box(machine, [1.14, 0.68, 0.68], M.teal, [0, 0.73, -0.21]);
box(machine, [1.27, 0.1, 0.53], M.ink, [0, 0.39, 0.37]);
box(machine, [1.25, 0.08, 0.61], M.woodLight, [0, 0.49, 0.38]);
const keyMaterials = [M.cream, M.rust, M.brass];
for (let row = 0; row < 3; row++) {
for (let col = 0; col < 6; col++) {
box(
machine,
[0.13, 0.075, 0.12],
keyMaterials[(row + col) % 3],
[-0.47 + col * 0.19, 0.57 + row * 0.012, 0.18 + row * 0.16]
);
}
}
const punchHead = new THREE.Group();
punchHead.position.set(0.43, 0.95, 0.05);
machine.add(punchHead);
cylinder(punchHead, 0.115, 0.13, 0.35, M.brass, [0, 0, 0], 8);
cylinder(punchHead, 0.045, 0.045, 0.38, M.ink, [0, -0.23, 0], 8);
const lever = new THREE.Group();
lever.position.set(-0.45, 0.57, 0.25);
lever.rotation.z = -0.32;
machine.add(lever);
cylinderBetween([0, 0, 0], [0, 0.75, 0], 0.025, M.ink, lever);
box(lever, [0.28, 0.12, 0.12], M.woodDark, [0, 0.77, 0]);
wallSign(
group,
"KEYPUNCH 03",
"MODEL 26 · FICTIONAL",
1.2,
0.3,
[0.15, 0.79, 0.14]
);
addStationHitbox("prep", -7, -0.25);
return { punchHead, lever };
}
function buildSorting() {
const group = new THREE.Group();
group.position.set(-2.4, 0, -0.65);
scene.add(group);
box(group, [2.8, 1.7, 1.25], M.teal, [0, 0.85, 0]);
box(group, [2.95, 0.16, 1.38], M.ink, [0, 0.08, 0]);
box(group, [2.58, 1.3, 0.055], M.ink, [0, 0.87, 0.65]);
const tabColors = [M.rust, M.gold || M.brass, M.blue, M.green];
for (let row = 0; row < 3; row++) {
for (let col = 0; col < 4; col++) {
const x = -0.9 + col * 0.6;
const y = 0.45 + row * 0.39;
box(group, [0.51, 0.3, 0.035], M.black, [x, y, 0.69]);
box(
group,
[0.37, 0.065, 0.04],
tabColors[(row + col) % tabColors.length],
[x, y + 0.055, 0.715]
);
box(group, [0.08, 0.12, 0.05], M.paper, [x - 0.11, y - 0.06, 0.72]);
}
}
const topDeck = box(group, [3.0, 0.16, 1.45], M.tealDark, [0, 1.73, 0]);
topDeck.rotation.z = 0.045;
const rotor = new THREE.Group();
rotor.position.set(0, 2.17, -0.08);
group.add(rotor);
const drum = cylinder(rotor, 0.49, 0.49, 1.85, M.tealDark, [0, 0, 0], 12);
drum.rotation.z = Math.PI / 2;
[-0.94, 0.94].forEach((x) => {
const cap = cylinder(rotor, 0.51, 0.51, 0.08, M.brass, [x, 0, 0], 12);
cap.rotation.z = Math.PI / 2;
});
for (let i = 0; i < 6; i++) {
const spoke = box(rotor, [0.055, 0.82, 0.055], M.cream, [0, 0, 0]);
spoke.rotation.x = (i / 6) * Math.PI;
}
const chute = box(group, [1.12, 0.12, 1.3], M.ink, [0.82, 1.62, 0.38]);
chute.rotation.x = 0.28;
addCardStack(group, -0.95, 1.84, 0.45, 4);
box(group, [0.68, 0.15, 0.45], M.cream, [0.85, 1.84, 0.46]);
addStationHitbox("sort", -2.4, -0.65);
return { rotor };
}
function buildStorage() {
const group = new THREE.Group();
group.position.set(3, 0, -0.7);
scene.add(group);
const cabinetX = -0.65;
box(group, [1.45, 2.35, 1.15], M.tealDark, [cabinetX, 1.175, 0]);
box(group, [1.56, 0.12, 1.25], M.woodDark, [cabinetX, 2.39, 0]);
const drawerGroups = [];
for (let i = 0; i < 5; i++) {
const drawer = new THREE.Group();
drawer.position.set(cabinetX, 0.3 + i * 0.42, 0.58);
group.add(drawer);
box(drawer, [1.25, 0.34, 0.09], M.teal, [0, 0, 0]);
box(drawer, [0.34, 0.055, 0.07], M.brass, [0, 0, 0.075]);
box(drawer, [0.24, 0.08, 0.02], M.paper, [-0.39, 0, 0.057]);
drawerGroups.push(drawer);
}
// Open card rack.
box(group, [1.42, 2.35, 0.1], M.woodDark, [1.0, 1.17, -0.45]);
[-0.03, 0.03].forEach((x) => {
box(group, [0.12, 2.35, 0.78], M.woodDark, [1 + x, 1.17, -0.08]);
});
for (let row = 0; row < 4; row++) {
const y = 0.25 + row * 0.55;
box(group, [1.38, 0.08, 0.78], M.woodLight, [1, y, -0.08]);
for (let col = 0; col < 3; col++) {
box(
group,
[0.31, 0.38, 0.54],
row % 2 ? M.cream : M.paper,
[0.65 + col * 0.36, y + 0.23, -0.06]
);
box(
group,
[0.11, 0.09, 0.02],
row % 2 ? M.rust : M.teal,
[0.65 + col * 0.36, y + 0.32, 0.22]
);
}
}
box(group, [0.92, 0.34, 0.75], M.rust, [0.65, 2.57, -0.1]);
addCardStack(group, 0.65, 2.75, -0.1, 5);
addStationHitbox("storage", 3, -0.7);
return { drawerGroups };
}
function buildTallying() {
const group = new THREE.Group();
group.position.set(7, 0, -0.55);
scene.add(group);
box(group, [3.55, 0.16, 1.85], M.woodLight, [0, 1.17, 0]);
[-1.55, 1.55].forEach((x) => {
box(group, [0.17, 1.05, 1.4], M.woodDark, [x, 0.53, 0]);
});
const machine = new THREE.Group();
machine.position.set(-0.35, 1.25, -0.1);
group.add(machine);
box(machine, [2.25, 1.25, 1.18], M.green, [0, 0.63, 0]);
box(machine, [2.38, 0.14, 1.28], M.tealDark, [0, 1.3, 0]);
box(machine, [1.78, 0.11, 0.55], M.ink, [-0.1, 0.31, 0.67]);
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 9; col++) {
box(
machine,
[0.12, 0.07, 0.12],
row === 0 ? M.cream : M.rust,
[-0.83 + col * 0.19, 0.42 + row * 0.09, 0.5 + row * 0.18]
);
}
}
box(machine, [0.7, 0.35, 0.07], M.black, [-0.28, 1.0, 0.61]);
for (let i = 0; i < 4; i++) {
box(
machine,
[0.08, 0.15, 0.02],
M.brass,
[-0.5 + i * 0.15, 1.0, 0.66]
);
}
const wheel = new THREE.Group();
wheel.position.set(0.98, 0.84, 0.67);
machine.add(wheel);
torus(wheel, 0.36, 0.075, M.brass);
cylinder(wheel, 0.11, 0.11, 0.11, M.rust, [0, 0, 0], 10);
for (let i = 0; i < 4; i++) {
const spoke = box(wheel, [0.035, 0.65, 0.035], M.cream, [0, 0, 0]);
spoke.rotation.z = (i / 4) * Math.PI;
}
const roll = new THREE.Group();
roll.position.set(-0.88, 1.63, -0.12);
machine.add(roll);
const rollMesh = cylinder(roll, 0.25, 0.25, 0.78, M.paper, [0, 0, 0], 12);
rollMesh.rotation.z = Math.PI / 2;
const paperSheet = box(roll, [0.62, 0.05, 0.55], M.paper, [0, -0.37, 0.12]);
paperSheet.rotation.x = 0.15;
const hopper = box(machine, [0.85, 0.15, 0.78], M.ink, [0.45, 1.47, -0.12]);
hopper.rotation.z = -0.13;
addCardStack(machine, 0.45, 1.58, -0.12, 6);
// Wall chart behind the tabulator.
box(scene, [2.65, 1.7, 0.08], M.woodDark, [7.1, 2.18, -3.95]);
box(scene, [2.48, 1.53, 0.04], M.cream, [7.1, 2.18, -3.89]);
for (let i = 0; i < 5; i++) {
box(
scene,
[1.55 - i * 0.17, 0.035, 0.025],
i % 2 ? M.rust : M.teal,
[7.0, 1.72 + i * 0.19, -3.855]
);
}
addStationHitbox("tally", 7, -0.55);
return { wheel, roll };
}
function buildClerk() {
const clerk = new THREE.Group();
clerk.position.set(-3.85, 0, -2.85);
clerk.rotation.y = -0.15;
scene.add(clerk);
cylinder(clerk, 0.16, 0.2, 0.72, M.ink, [-0.18, 0.37, 0], 7);
cylinder(clerk, 0.16, 0.2, 0.72, M.ink, [0.18, 0.37, 0], 7);
box(clerk, [0.15, 0.7, 0.16], M.ink, [-0.18, 0.06, 0.08]);
box(clerk, [0.15, 0.7, 0.16], M.ink, [0.18, 0.06, 0.08]);
box(clerk, [0.74, 0.92, 0.38], M.blue, [0, 1.15, 0]);
cylinder(clerk, 0.12, 0.12, 0.16, M.cream, [0, 1.68, 0], 8);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.29, 10, 7),
M.cream
);
head.position.set(0, 1.99, 0.01);
head.scale.set(0.9, 1.05, 0.88);
head.castShadow = true;
clerk.add(head);
const hair = new THREE.Mesh(
new THREE.SphereGeometry(0.3, 10, 6, 0, Math.PI * 2, 0, Math.PI / 2),
M.woodDark
);
hair.position.set(0, 2.06, 0);
hair.scale.set(0.94, 0.75, 0.92);
hair.castShadow = true;
clerk.add(hair);
const leftArm = box(clerk, [0.18, 0.73, 0.18], M.blue, [-0.43, 1.22, 0.19]);
leftArm.rotation.x = -0.72;
const rightArm = box(clerk, [0.18, 0.73, 0.18], M.blue, [0.43, 1.22, 0.19]);
rightArm.rotation.x = -0.72;
box(clerk, [0.28, 0.1, 0.26], M.cream, [-0.43, 0.88, 0.53]);
box(clerk, [0.28, 0.1, 0.26], M.cream, [0.43, 0.88, 0.53]);
// Stool.
cylinder(clerk, 0.38, 0.38, 0.12, M.woodDark, [0, 0.73, -0.6], 10);
cylinder(clerk, 0.06, 0.06, 0.73, M.ink, [0, 0.36, -0.6], 7);
}
buildRoom();
const preparation = buildPreparation();
const sorting = buildSorting();
const storage = buildStorage();
const tallying = buildTallying();
buildClerk();
// The route follows the card through the four rooms.
const routePoints = [
new THREE.Vector3(-8.25, 1.74, 0.48),
new THREE.Vector3(-7.2, 2.08, 0.15),
new THREE.Vector3(-6.15, 2.38, -0.36),
new THREE.Vector3(-4.45, 2.2, -0.1),
new THREE.Vector3(-2.4, 2.74, -0.65),
new THREE.Vector3(-0.7, 2.25, -0.1),
new THREE.Vector3(1.45, 2.48, -0.7),
new THREE.Vector3(2.45, 2.68, -0.7),
new THREE.Vector3(3.65, 2.36, -0.7),
new THREE.Vector3(5.1, 2.12, -0.22),
new THREE.Vector3(6.5, 2.48, -0.65),
new THREE.Vector3(7.48, 2.86, -0.67),
new THREE.Vector3(8.05, 2.14, 0.35)
];
const routeCurve = new THREE.CatmullRomCurve3(
routePoints,
false,
"catmullrom",
0.35
);
const routeMaterial = new THREE.MeshStandardMaterial({
color: 0xb6543f,
emissive: 0x7d2d24,
emissiveIntensity: 0.2,
roughness: 0.6
});
const routeTube = new THREE.Mesh(
new THREE.TubeGeometry(routeCurve, 180, 0.026, 6, false),
routeMaterial
);
scene.add(routeTube);
const routeHalo = new THREE.Mesh(
new THREE.TubeGeometry(routeCurve, 180, 0.065, 6, false),
new THREE.MeshBasicMaterial({
color: 0xd3a54f,
transparent: true,
opacity: 0.12,
depthWrite: false
})
);
scene.add(routeHalo);
function makeCard(detailed = false, opacity = 1) {
const group = new THREE.Group();
const paperMaterial = new THREE.MeshStandardMaterial({
color: opacity < 1 ? 0xfff0ca : 0xeee2c0,
roughness: 0.92,
transparent: opacity < 1,
opacity,
depthWrite: opacity === 1
});
const body = box(group, [0.78, 0.035, 0.48], paperMaterial, [0, 0, 0]);
body.castShadow = opacity === 1;
const stripeMaterial = new THREE.MeshStandardMaterial({
color: opacity < 1 ? 0xb6543f : 0xb6543f,
roughness: 0.8,
transparent: opacity < 1,
opacity: opacity * 0.9,
depthWrite: opacity === 1
});
box(group, [0.75, 0.012, 0.075], stripeMaterial, [0, 0.025, -0.17]);
if (detailed) {
const holeMaterial = new THREE.MeshStandardMaterial({
color: 0x171b18,
roughness: 1
});
const holeLocations = [
[-0.27, 0.055], [-0.18, 0.055], [-0.09, 0.055],
[0, 0.055], [0.09, 0.055], [0.18, 0.055],
[-0.27, 0.14], [-0.18, 0.14], [-0.09, 0.14],
[0, 0.14], [0.09, 0.14], [0.18, 0.14]
];
holeLocations.forEach(([x, z]) => {
box(group, [0.034, 0.012, 0.034], holeMaterial, [x, 0.025, z]);
});
box(group, [0.11, 0.012, 0.035], holeMaterial, [0.27, 0.025, -0.19]);
}
return group;
}
const card = makeCard(true);
scene.add(card);
const trail = [];
for (let i = 0; i < 10; i++) {
const ghost = makeCard(false, 0.2 - i * 0.015);
scene.add(ghost);
trail.push(ghost);
}
const routePulse = new THREE.Mesh(
new THREE.SphereGeometry(0.075, 8, 6),
new THREE.MeshBasicMaterial({ color: 0xffd783 })
);
scene.add(routePulse);
// Dust motes.
const dustCount = 130;
const dustPositions = new Float32Array(dustCount * 3);
for (let i = 0; i < dustCount; i++) {
dustPositions[i * 3] = (Math.random() - 0.5) * 21;
dustPositions[i * 3 + 1] = 0.4 + Math.random() * 4.5;
dustPositions[i * 3 + 2] = (Math.random() - 0.5) * 10;
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute(
"position",
new THREE.BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xffedbd,
size: 0.027,
transparent: true,
opacity: 0.48,
depthWrite: false
})
);
scene.add(dust);
const stages = {
prep: {
index: "01 / Preparation",
title: "Preparation",
text: "A clerk aligns the fictional transfer request, hand-punches the office, department, and sequence fields, then checks that every column is readable before the card enters the room.",
x: -7,
z: -0.25,
focus: 0.08,
theta: 0.38
},
sort: {
index: "02 / Sorting",
title: "Sorting",
text: "The punched transaction code is compared with the day's run sheet. Colored tabs and the sorter's compartments route the card toward the temporary district file.",
x: -2.4,
z: -0.65,
focus: 0.31,
theta: 0.46
},
storage: {
index: "03 / Storage",
title: "Storage",
text: "Card 04721 waits in the temporary file while clerks balance departmental totals. Its distinctive corner cut identifies the employee, pay period, and correction sequence.",
x: 3,
z: -0.7,
focus: 0.54,
theta: 0.53
},
tally: {
index: "04 / Tallying",
title: "Tallying",
text: "The card is fed into the accounting machine. Its punched columns become batch totals, then the operator compares the result with the payroll sheet before posting the entry.",
x: 7,
z: -0.55,
focus: 0.82,
theta: 0.66
}
};
let activeStage = "prep";
let progress = 0.04;
let playing = !reducedMotion;
function stageForProgress(value) {
if (value < 0.24) return "prep";
if (value < 0.47) return "sort";
if (value < 0.69) return "storage";
return "tally";
}
function setActiveStage(key) {
if (activeStage === key && storyTitle.textContent) return;
activeStage = key;
const stage = stages[key];
storyIndex.textContent = stage.index;
storyTitle.textContent = stage.title;
storyText.textContent = stage.text;
stageLabelElements.forEach((element) => {
element.classList.toggle("active", element.dataset.stage === key);
});
stageNavButtons.forEach((element) => {
element.classList.toggle("active", element.dataset.stage === key);
});
overviewButton.classList.remove("active");
story.classList.remove("pulse");
void story.offsetWidth;
story.classList.add("pulse");
}
// Custom orbit / pan / zoom controls.
const cameraTarget = new THREE.Vector3(0, 1.1, 0);
const cameraGoalTarget = cameraTarget.clone();
const orbit = {
radius: 18,
theta: 0.62,
phi: 0.94
};
const orbitGoal = {
radius: orbit.radius,
theta: orbit.theta,
phi: orbit.phi
};
const pointerState = {
active: false,
button: 0,
x: 0,
y: 0,
startX: 0,
startY: 0,
moved: false
};
function updateCamera(dt) {
const smoothing = 1 - Math.exp(-dt * 5.5);
cameraTarget.lerp(cameraGoalTarget, smoothing);
orbit.radius = THREE.MathUtils.lerp(
orbit.radius,
orbitGoal.radius,
smoothing
);
orbit.theta = THREE.MathUtils.lerp(
orbit.theta,
orbitGoal.theta,
smoothing
);
orbit.phi = THREE.MathUtils.lerp(
orbit.phi,
orbitGoal.phi,
smoothing
);
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
cameraTarget.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
cameraTarget.y + orbit.radius * Math.cos(orbit.phi),
cameraTarget.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(cameraTarget);
}
function focusStage(key) {
const stage = stages[key];
followInput.checked = false;
progress = stage.focus;
playing = false;
updatePlayButton();
cameraGoalTarget.set(stage.x, 1.35, stage.z);
orbitGoal.radius = 7.9;
orbitGoal.theta = stage.theta;
orbitGoal.phi = 1.0;
setActiveStage(key);
}
function focusOverview() {
followInput.checked = false;
cameraGoalTarget.set(0, 1.05, 0);
orbitGoal.radius = 18;
orbitGoal.theta = 0.62;
orbitGoal.phi = 0.94;
overviewButton.classList.add("active");
stageLabelElements.forEach((element) => element.classList.remove("active"));
stageNavButtons.forEach((element) => element.classList.remove("active"));
}
function updatePlayButton() {
playButton.textContent = playing ? "Ⅱ" : "▶";
playButton.setAttribute(
"aria-label",
playing ? "Pause card journey" : "Play card journey"
);
}
stageLabelElements.forEach((element) => {
element.addEventListener("click", () => focusStage(element.dataset.stage));
});
stageNavButtons.forEach((element) => {
element.addEventListener("click", () => focusStage(element.dataset.stage));
});
overviewButton.addEventListener("click", focusOverview);
playButton.addEventListener("click", () => {
if (!playing && progress > 0.985) progress = 0;
playing = !playing;
updatePlayButton();
});
timeline.addEventListener("input", () => {
progress = Number(timeline.value) / 1000;
playing = false;
updatePlayButton();
});
followInput.addEventListener("change", () => {
if (followInput.checked) {
playing = true;
orbitGoal.radius = 8.6;
orbitGoal.phi = 1.02;
orbitGoal.theta = 0.56;
} else {
const stage = stages[activeStage];
cameraGoalTarget.set(stage.x, 1.35, stage.z);
orbitGoal.radius = 7.9;
}
updatePlayButton();
});
resetButton.addEventListener("click", () => {
progress = 0;
playing = false;
followInput.checked = false;
focusOverview();
updatePlayButton();
});
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
pointerState.active = true;
pointerState.button = event.button;
pointerState.x = event.clientX;
pointerState.y = event.clientY;
pointerState.startX = event.clientX;
pointerState.startY = event.clientY;
pointerState.moved = false;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerState.active) return;
const dx = event.clientX - pointerState.x;
const dy = event.clientY - pointerState.y;
pointerState.x = event.clientX;
pointerState.y = event.clientY;
const totalDistance = Math.hypot(
event.clientX - pointerState.startX,
event.clientY - pointerState.startY
);
if (totalDistance > 5) pointerState.moved = true;
if (pointerState.button === 2) {
const right = new THREE.Vector3(
Math.cos(orbit.theta),
0,
-Math.sin(orbit.theta)
);
const forward = new THREE.Vector3(
-Math.sin(orbit.theta),
0,
-Math.cos(orbit.theta)
);
cameraGoalTarget.addScaledVector(right, -dx * 0.018);
cameraGoalTarget.addScaledVector(forward, -dy * 0.018);
} else {
orbitGoal.theta -= dx * 0.006;
orbitGoal.phi = THREE.MathUtils.clamp(
orbitGoal.phi - dy * 0.005,
0.28,
1.43
);
}
});
canvas.addEventListener("pointerup", (event) => {
pointerState.active = false;
if (!pointerState.moved && pointerState.button === 0) {
pointer.x = (event.clientX / innerWidth) * 2 - 1;
pointer.y = -(event.clientY / innerHeight) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(hitTargets, false);
if (hits.length) focusStage(hits[0].object.userData.stage);
}
});
canvas.addEventListener("pointercancel", () => {
pointerState.active = false;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbitGoal.radius = THREE.MathUtils.clamp(
orbitGoal.radius * Math.exp(event.deltaY * 0.001),
4.5,
27
);
},
{ passive: false }
);
const labelAnchors = {
prep: new THREE.Vector3(-7, 3.0, -0.25),
sort: new THREE.Vector3(-2.4, 3.0, -0.65),
storage: new THREE.Vector3(3, 3.0, -0.7),
tally: new THREE.Vector3(7, 3.0, -0.55)
};
const projected = new THREE.Vector3();
function positionLabel(element, position) {
projected.copy(position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.2 &&
projected.x < 1.2 &&
projected.y > -1.2 &&
projected.y < 1.2;
element.style.display = visible ? "block" : "none";
if (!visible) return;
element.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
addEventListener("resize", resize);
updatePlayButton();
setActiveStage("prep");
const cardPosition = new THREE.Vector3();
const tangent = new THREE.Vector3();
const desiredTarget = new THREE.Vector3();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
if (playing) {
progress = (progress + dt * 0.042) % 1;
}
cardPosition.copy(routeCurve.getPointAt(progress));
tangent.copy(routeCurve.getTangentAt(progress));
const yaw = Math.atan2(-tangent.z, tangent.x);
card.position.copy(cardPosition);
card.position.y += Math.sin(elapsed * 2.5 + progress * 22) * 0.035;
card.rotation.set(
Math.sin(elapsed * 1.4) * 0.035,
yaw,
Math.cos(elapsed * 1.2) * 0.025
);
trail.forEach((ghost, index) => {
const trailProgress = (progress - (index + 1) * 0.009 + 1) % 1;
ghost.position.copy(routeCurve.getPointAt(trailProgress));
const trailTangent = routeCurve.getTangentAt(trailProgress);
ghost.rotation.y = Math.atan2(-trailTangent.z, trailTangent.x);
const scale = 0.82 - index * 0.035;
ghost.scale.setScalar(scale);
});
routePulse.position.copy(routeCurve.getPointAt((progress + 0.022) % 1));
routePulse.scale.setScalar(0.75 + Math.sin(elapsed * 5) * 0.18);
setActiveStage(stageForProgress(progress));
if (followInput.checked) {
desiredTarget.set(cardPosition.x, 1.25, cardPosition.z);
cameraGoalTarget.lerp(desiredTarget, 1 - Math.exp(-dt * 2.2));
}
// Working machinery.
const punchStrength = activeStage === "prep" ? 1 : 0.22;
preparation.punchHead.position.y =
0.96 + Math.sin(elapsed * 4.2) * 0.055 * punchStrength;
preparation.lever.rotation.z =
-0.32 + Math.sin(elapsed * 1.7) * 0.08 * punchStrength;
sorting.rotor.rotation.x += dt * 0.55;
tallying.wheel.rotation.z -= dt * (activeStage === "tally" ? 1.2 : 0.2);
tallying.roll.rotation.x += dt * 0.35;
storage.drawerGroups[2].position.z =
0.58 + Math.sin(elapsed * 0.65) * 0.055;
dust.rotation.y = elapsed * 0.008;
updateCamera(dt);
Object.entries(labelAnchors).forEach(([key, anchor]) => {
const element = stageLabelElements.find(
(label) => label.dataset.stage === key
);
positionLabel(element, anchor);
});
positionLabel(
cardTag,
cardPosition.clone().add(new THREE.Vector3(0, 0.36, 0))
);
timeline.value = Math.round(progress * 1000);
timeline.style.setProperty("--progress", `${progress * 100}%`);
percentOutput.value = `${Math.round(progress * 100)}%`;
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```