Prompt specification
Build or customize the Three.js 3D scene "Card reader lifting selected loom threads" 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: Card reader lifting selected loom threads
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/card-reader-lifting-selected-loom-threads-x2498
Scene Description Prompt:
Make a cutaway Three.js scene in a self-contained HTML file using cdnjs: Card reader lifting selected loom threads. Create a simplified Jacquard-inspired mechanism where one card determines which warp threads rise. Show the direct correspondence between hole positions and selected thread groups.
Working Three.js Starter (card-reader-lifting-selected-loom-threads-x2498):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Jacquard Card Reader — Cutaway Study</title>
<style>
:root {
color-scheme: dark;
--accent: #63e6d2;
--panel: rgba(8, 20, 30, 0.78);
--line: rgba(132, 208, 216, 0.22);
--text: #e9f5f4;
--muted: #91abb4;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 42%, #132735 0%, #08131d 48%, #050b11 100%);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
color: var(--text);
}
.title {
position: absolute;
top: 28px;
left: 30px;
width: min(440px, calc(100vw - 60px));
}
.eyebrow {
margin-bottom: 10px;
color: var(--accent);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 42px);
font-weight: 650;
letter-spacing: -0.045em;
line-height: 1.03;
text-shadow: 0 3px 22px rgba(0, 0, 0, 0.35);
}
.subtitle {
max-width: 400px;
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.controls {
position: absolute;
top: 28px;
right: 30px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
min-height: 38px;
padding: 0 14px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(10, 26, 37, 0.82);
color: var(--text);
font: inherit;
font-size: 12px;
font-weight: 650;
cursor: pointer;
backdrop-filter: blur(12px);
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
button:hover {
border-color: rgba(99, 230, 210, 0.65);
background: rgba(19, 45, 57, 0.92);
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
.status {
position: absolute;
left: 30px;
bottom: 28px;
width: min(460px, calc(100vw - 60px));
padding: 16px 17px;
border: 1px solid var(--line);
border-radius: 13px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(14px);
}
.status-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
}
.status-label {
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.17em;
text-transform: uppercase;
}
#rowReadout {
margin-top: 4px;
font-size: 15px;
font-weight: 650;
}
#countReadout {
color: var(--accent);
font-size: 12px;
font-weight: 700;
white-space: nowrap;
}
.groups {
display: grid;
grid-template-columns: repeat(8, minmax(0, 1fr));
gap: 6px;
margin-top: 13px;
}
.group-chip {
display: flex;
min-width: 0;
align-items: center;
justify-content: center;
gap: 5px;
padding: 6px 2px;
border: 1px solid rgba(255, 255, 255, 0.07);
border-radius: 6px;
color: #6f8993;
font-size: 10px;
font-weight: 800;
transition:
color 180ms ease,
border-color 180ms ease,
background 180ms ease;
}
.group-chip::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--group-color);
content: "";
opacity: 0.32;
}
.group-chip.active {
border-color: color-mix(in srgb, var(--group-color), transparent 55%);
background: color-mix(in srgb, var(--group-color), transparent 91%);
color: var(--text);
}
.group-chip.active::before {
opacity: 1;
box-shadow: 0 0 9px var(--group-color);
}
.hint {
position: absolute;
right: 30px;
bottom: 30px;
max-width: 280px;
color: rgba(197, 220, 224, 0.66);
font-size: 11px;
line-height: 1.55;
text-align: right;
}
.hint strong {
color: rgba(231, 248, 247, 0.9);
font-weight: 650;
}
.key {
display: inline-block;
margin-right: 6px;
color: var(--accent);
}
@media (max-width: 720px) {
.title {
top: 20px;
left: 20px;
}
.subtitle {
max-width: 300px;
font-size: 12px;
}
.controls {
top: auto;
right: 20px;
bottom: 20px;
}
.status {
left: 20px;
bottom: 20px;
width: calc(100vw - 40px);
padding-right: 110px;
}
.groups {
grid-template-columns: repeat(4, 1fr);
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="hud">
<header class="title">
<div class="eyebrow">Mechanical Study 01 · Cutaway</div>
<h1>Jacquard Card Reader</h1>
<p class="subtitle">
A punched card scans beneath the read head. Each hole aligns with one
colored warp group and activates its lifter.
</p>
</header>
<div class="controls">
<button id="pauseButton" type="button">Pause scan</button>
<button id="nextButton" type="button">Next row</button>
</div>
<section class="status">
<div class="status-row">
<div>
<div class="status-label">Current card row</div>
<div id="rowReadout">Row 01 / 05</div>
</div>
<div id="countReadout">4 groups lifted</div>
</div>
<div id="groupChips" class="groups"></div>
</section>
<div class="hint">
<span class="key">Drag</span> orbit camera<br>
<span class="key">Wheel</span> zoom<br>
<span class="key">Click card</span> choose a row
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const mount = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
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;
mount.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111b);
scene.fog = new THREE.FogExp2(0x07111b, 0.022);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 2.45, 0);
const orbit = {
radius: 17.5,
theta: 2.42,
phi: 1.17
};
function applyCamera() {
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);
}
applyCamera();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0x9fd9e4, 0x14212a, 1.55));
const keyLight = new THREE.DirectionalLight(0xfff0d4, 3.1);
keyLight.position.set(7, 12, -8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 11;
keyLight.shadow.camera.bottom = -11;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 32;
keyLight.shadow.bias = -0.00015;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x58d9d2, 2.1);
rimLight.position.set(-8, 7, 7);
scene.add(rimLight);
const readerLight = new THREE.PointLight(0x54f0dc, 12, 9, 2);
readerLight.position.set(0, 6.1, 0);
scene.add(readerLight);
const warmLight = new THREE.PointLight(0xff9f63, 7, 7, 2);
warmLight.position.set(5, 3.5, -4);
scene.add(warmLight);
// -------------------------------------------------------------------------
// Materials and shared geometry
// -------------------------------------------------------------------------
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0x203847,
metalness: 0.78,
roughness: 0.28
});
const darkMetalMaterial = new THREE.MeshStandardMaterial({
color: 0x0d202b,
metalness: 0.72,
roughness: 0.35
});
const silverMaterial = new THREE.MeshStandardMaterial({
color: 0xb5c9cb,
metalness: 0.86,
roughness: 0.2
});
const accentMaterial = new THREE.MeshStandardMaterial({
color: 0x54d8c7,
emissive: 0x123d3a,
emissiveIntensity: 0.35,
metalness: 0.48,
roughness: 0.25
});
const glassMaterial = new THREE.MeshPhysicalMaterial({
color: 0x8de8e0,
transparent: true,
opacity: 0.09,
roughness: 0.12,
metalness: 0,
side: THREE.DoubleSide,
depthWrite: false
});
const cardMaterial = new THREE.MeshStandardMaterial({
color: 0xe4d4af,
roughness: 0.76,
metalness: 0.02
});
const cardEdgeMaterial = new THREE.MeshStandardMaterial({
color: 0xb59e77,
roughness: 0.82,
metalness: 0
});
const unitCylinder = new THREE.CylinderGeometry(1, 1, 1, 10, 1, false);
const up = new THREE.Vector3(0, 1, 0);
const tempDirection = new THREE.Vector3();
function addBox(width, height, depth, x, y, z, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function positionCylinder(mesh, a, b, radius) {
tempDirection.subVectors(b, a);
const length = Math.max(tempDirection.length(), 0.0001);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(up, tempDirection.normalize());
mesh.scale.set(radius, length, radius);
}
function cylinderBetween(a, b, radius, material, castShadow = true) {
const mesh = new THREE.Mesh(unitCylinder, material);
positionCylinder(mesh, a, b, radius);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function makeLabelSprite(text, color = "#dff8f4", width = 1.5) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 144;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "rgba(5, 17, 25, 0.86)";
ctx.fillRect(8, 8, 496, 128);
ctx.strokeStyle = "rgba(99, 230, 210, 0.5)";
ctx.lineWidth = 4;
ctx.strokeRect(8, 8, 496, 128);
ctx.fillStyle = color;
ctx.font = "600 44px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 74);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(width, width * 144 / 512, 1);
sprite.renderOrder = 20;
return sprite;
}
// -------------------------------------------------------------------------
// Floor and cutaway loom frame
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0x091721,
roughness: 0.92,
metalness: 0.05
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.12;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(32, 64, 0x326b72, 0x15333e);
grid.position.y = -0.105;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
addBox(9.3, 0.34, 10.2, 0, 0.12, 0, frameMaterial);
addBox(9.65, 0.15, 10.5, 0, -0.08, 0, darkMetalMaterial);
for (const x of [-4.45, 4.45]) {
for (const z of [-4.45, 4.45]) {
addBox(0.38, 5.25, 0.38, x, 2.75, z, frameMaterial);
addBox(0.72, 0.2, 0.72, x, 0.37, z, darkMetalMaterial);
}
addBox(0.36, 0.36, 9.25, x, 5.47, 0, frameMaterial);
addBox(0.26, 0.25, 9.15, x, 0.72, 0, darkMetalMaterial);
}
// The front upper crossbeam is intentionally omitted for the cutaway view.
addBox(9.25, 0.36, 0.36, 0, 5.47, 4.45, frameMaterial);
cylinderBetween(
new THREE.Vector3(-4.42, 0.65, 4.42),
new THREE.Vector3(-4.42, 5.35, 4.42),
0.075,
silverMaterial
);
cylinderBetween(
new THREE.Vector3(4.42, 0.65, 4.42),
new THREE.Vector3(4.42, 5.35, 4.42),
0.075,
silverMaterial
);
// Back and front rollers.
for (const z of [-4.13, 4.13]) {
const roller = new THREE.Mesh(
new THREE.CylinderGeometry(0.25, 0.25, 8.15, 36),
silverMaterial
);
roller.rotation.z = Math.PI / 2;
roller.position.set(0, 1.55, z);
roller.castShadow = true;
scene.add(roller);
for (const x of [-4.15, 4.15]) {
const cap = new THREE.Mesh(
new THREE.CylinderGeometry(0.38, 0.38, 0.15, 24),
accentMaterial
);
cap.rotation.z = Math.PI / 2;
cap.position.set(x, 1.55, z);
scene.add(cap);
}
}
// A short woven cloth leaves the front roller.
const cloth = addBox(
7.9,
1.1,
0.07,
0,
0.96,
-4.37,
new THREE.MeshStandardMaterial({
color: 0x375e64,
roughness: 0.92,
metalness: 0.02
})
);
cloth.receiveShadow = true;
// -------------------------------------------------------------------------
// Card reader housing — front and top covers removed
// -------------------------------------------------------------------------
const READER_Y = 4.68;
const CARD_Y = 4.68;
const CARD_WIDTH = 7.9;
const CARD_DEPTH = 3.3;
const CARD_THICKNESS = 0.1;
const GROUP_COUNT = 8;
const ROW_COUNT = 5;
const GROUP_SPACING = 0.9;
const ROW_SPACING = 0.57;
const HOLE_RADIUS = 0.115;
for (const x of [-4.08, 4.08]) {
addBox(0.2, 0.2, 4.05, x, READER_Y, 0, frameMaterial);
}
for (const z of [-1.98, 1.98]) {
addBox(8.35, 0.2, 0.2, 0, READER_Y, z, frameMaterial);
}
// Remaining transparent enclosure walls make the cutaway readable.
addBox(8.05, 0.82, 0.035, 0, 4.94, 1.98, glassMaterial, false);
addBox(0.035, 0.82, 3.9, -4.08, 4.94, 0, glassMaterial, false);
// Fixed read-head comb.
addBox(7.85, 0.11, 0.09, 0, 4.17, -0.13, darkMetalMaterial);
addBox(7.85, 0.11, 0.09, 0, 4.17, 0.13, darkMetalMaterial);
const scanLine = new THREE.Mesh(
new THREE.BoxGeometry(7.8, 0.018, 0.025),
new THREE.MeshBasicMaterial({
color: 0x76fff0,
transparent: true,
opacity: 0.8
})
);
scanLine.position.set(0, CARD_Y + 0.125, 0);
scene.add(scanLine);
const readerLabel = makeLabelSprite("CUTAWAY CARD READER", "#bffdf4", 2.75);
readerLabel.position.set(0, 6.03, 0);
scene.add(readerLabel);
// -------------------------------------------------------------------------
// Warp groups, color mapping, and punched card
// -------------------------------------------------------------------------
const groupHex = [
0xff7869,
0xffb84f,
0x78df9b,
0x4fd8e8,
0xa991ff,
0xf07bc6,
0xc8df58,
0x619cff
];
const groupColors = groupHex.map((hex) => new THREE.Color(hex));
const mutedThreadColor = new THREE.Color(0x35515f);
const patterns = [
[1, 0, 1, 0, 1, 0, 0, 1],
[0, 1, 1, 0, 0, 1, 1, 0],
[1, 1, 0, 1, 0, 0, 1, 1],
[0, 0, 1, 1, 1, 1, 0, 0],
[1, 0, 0, 1, 0, 1, 1, 0]
];
const groupX = Array.from(
{ length: GROUP_COUNT },
(_, index) => (index - (GROUP_COUNT - 1) / 2) * GROUP_SPACING
);
const rowY = Array.from(
{ length: ROW_COUNT },
(_, index) =>
((ROW_COUNT - 1) / 2 - index) * ROW_SPACING
);
// Card outline with genuine circular punched holes.
const cardShape = new THREE.Shape();
cardShape.moveTo(-CARD_WIDTH / 2, -CARD_DEPTH / 2);
cardShape.lineTo(CARD_WIDTH / 2, -CARD_DEPTH / 2);
cardShape.lineTo(CARD_WIDTH / 2, CARD_DEPTH / 2);
cardShape.lineTo(-CARD_WIDTH / 2, CARD_DEPTH / 2);
cardShape.closePath();
const holeDefinitions = [];
for (let row = 0; row < ROW_COUNT; row++) {
for (let column = 0; column < GROUP_COUNT; column++) {
if (!patterns[row][column]) continue;
const hole = new THREE.Path();
hole.absarc(
groupX[column],
rowY[row],
HOLE_RADIUS,
0,
Math.PI * 2,
true
);
cardShape.holes.push(hole);
holeDefinitions.push({ row, column });
}
}
const cardGeometry = new THREE.ExtrudeGeometry(cardShape, {
depth: CARD_THICKNESS,
steps: 1,
bevelEnabled: true,
bevelSegments: 1,
bevelSize: 0.012,
bevelThickness: 0.012,
curveSegments: 12
});
const cardMesh = new THREE.Mesh(
cardGeometry,
[cardMaterial, cardEdgeMaterial]
);
cardMesh.rotation.x = -Math.PI / 2;
cardMesh.position.set(0, CARD_Y, rowY[0]);
cardMesh.castShadow = true;
cardMesh.receiveShadow = true;
scene.add(cardMesh);
// Colored rings around actual holes strengthen the column-to-thread mapping.
const holeRingGeometry = new THREE.TorusGeometry(
HOLE_RADIUS + 0.014,
0.017,
6,
20
);
const holeRings = holeDefinitions.map(({ row, column }) => {
const material = new THREE.MeshBasicMaterial({
color: groupColors[column],
transparent: true,
opacity: 0.32,
depthWrite: false
});
const ring = new THREE.Mesh(holeRingGeometry, material);
ring.rotation.x = Math.PI / 2;
ring.position.set(
groupX[column],
CARD_Y + CARD_THICKNESS + 0.012,
cardMesh.position.z - rowY[row]
);
ring.userData.row = row;
ring.userData.column = column;
scene.add(ring);
return ring;
});
// -------------------------------------------------------------------------
// Warp bundles and lifting mechanisms
// -------------------------------------------------------------------------
const BASE_WARP_Y = 1.55;
const MAX_LIFT = 1.85;
const THREAD_SEGMENTS = 22;
const STRANDS_PER_GROUP = 3;
const groups = [];
for (let groupIndex = 0; groupIndex < GROUP_COUNT; groupIndex++) {
const threadMaterial = new THREE.MeshStandardMaterial({
color: mutedThreadColor,
roughness: 0.48,
metalness: 0.18,
emissive: 0x000000,
emissiveIntensity: 0
});
const threadBundle = [];
for (let strand = 0; strand < STRANDS_PER_GROUP; strand++) {
const strandOffset = (strand - 1) * 0.065;
const segments = [];
for (let segment = 0; segment < THREAD_SEGMENTS; segment++) {
const mesh = new THREE.Mesh(unitCylinder, threadMaterial);
mesh.castShadow = false;
mesh.receiveShadow = true;
scene.add(mesh);
segments.push(mesh);
}
threadBundle.push({
x: groupX[groupIndex] + strandOffset,
segments
});
}
// The group-colored signal filament runs directly below the matching hole.
const signalMaterial = new THREE.LineDashedMaterial({
color: groupColors[groupIndex],
transparent: true,
opacity: 0.08,
dashSize: 0.085,
gapSize: 0.065,
depthWrite: false
});
const signalGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(groupX[groupIndex], 4.02, 0.2),
new THREE.Vector3(groupX[groupIndex], 1.58, 0.2)
]);
const signalLine = new THREE.Line(signalGeometry, signalMaterial);
signalLine.computeLineDistances();
scene.add(signalLine);
// The rod physically connects the read head to the moving warp hook.
const lifterRod = new THREE.Mesh(unitCylinder, silverMaterial);
lifterRod.castShadow = true;
scene.add(lifterRod);
const hookMaterial = new THREE.MeshStandardMaterial({
color: groupColors[groupIndex],
emissive: groupColors[groupIndex],
emissiveIntensity: 0.08,
roughness: 0.25,
metalness: 0.55
});
const hook = new THREE.Mesh(
new THREE.TorusGeometry(0.115, 0.027, 8, 22),
hookMaterial
);
hook.position.set(groupX[groupIndex], BASE_WARP_Y - 0.08, 0);
hook.castShadow = true;
scene.add(hook);
// Colored read pin and illuminated tip.
const pinGroup = new THREE.Group();
pinGroup.position.set(groupX[groupIndex], 4.54, 0);
const pinShaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.044, 0.044, 0.72, 10),
silverMaterial
);
pinShaft.castShadow = true;
pinGroup.add(pinShaft);
const tipMaterial = new THREE.MeshStandardMaterial({
color: groupColors[groupIndex],
emissive: groupColors[groupIndex],
emissiveIntensity: 0.05,
roughness: 0.22,
metalness: 0.35
});
const pinTip = new THREE.Mesh(
new THREE.SphereGeometry(0.082, 14, 10),
tipMaterial
);
pinTip.position.y = -0.38;
pinGroup.add(pinTip);
scene.add(pinGroup);
const groupLabel = makeLabelSprite(
`G${groupIndex + 1}`,
`#${groupHex[groupIndex].toString(16).padStart(6, "0")}`,
0.56
);
groupLabel.position.set(groupX[groupIndex], 4.96, -1.68);
scene.add(groupLabel);
groups.push({
lift: 0,
threadMaterial,
threadBundle,
signalMaterial,
lifterRod,
hook,
hookMaterial,
pinGroup,
tipMaterial
});
}
const warpLabel = makeLabelSprite("WARP LIFTERS", "#d6f2ef", 1.65);
warpLabel.position.set(4.35, 3.65, 0);
scene.add(warpLabel);
// -------------------------------------------------------------------------
// HUD
// -------------------------------------------------------------------------
const rowReadout = document.getElementById("rowReadout");
const countReadout = document.getElementById("countReadout");
const groupChipsContainer = document.getElementById("groupChips");
const pauseButton = document.getElementById("pauseButton");
const nextButton = document.getElementById("nextButton");
const groupChips = groupHex.map((hex, index) => {
const chip = document.createElement("div");
chip.className = "group-chip";
chip.style.setProperty("--group-color", `#${hex.toString(16).padStart(6, "0")}`);
chip.textContent = `G${index + 1}`;
groupChipsContainer.appendChild(chip);
return chip;
});
let currentRow = 0;
let targetRow = 0;
let autoScan = true;
let nextScanTime = 3.2;
function updateHUD() {
rowReadout.textContent =
`Row ${String(currentRow + 1).padStart(2, "0")} / ${String(ROW_COUNT).padStart(2, "0")}`;
const selectedCount = patterns[currentRow].reduce(
(sum, value) => sum + value,
0
);
countReadout.textContent = `${selectedCount} group${selectedCount === 1 ? "" : "s"} lifted`;
groupChips.forEach((chip, index) => {
chip.classList.toggle("active", Boolean(patterns[currentRow][index]));
});
}
updateHUD();
pauseButton.addEventListener("click", () => {
autoScan = !autoScan;
pauseButton.textContent = autoScan ? "Pause scan" : "Resume scan";
});
nextButton.addEventListener("click", () => {
targetRow = (targetRow + 1) % ROW_COUNT;
nextScanTime = performance.now() / 1000 + 3.2;
});
// -------------------------------------------------------------------------
// Direct camera controls — no external controls addon
// -------------------------------------------------------------------------
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
let dragging = false;
let dragDistance = 0;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
dragDistance = 0;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
dragDistance += Math.abs(deltaX) + Math.abs(deltaY);
orbit.theta -= deltaX * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + deltaY * 0.005,
0.48,
1.47
);
previousX = event.clientX;
previousY = event.clientY;
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (dragDistance < 6) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObject(cardMesh, false)[0];
if (hit) {
const localPoint = cardMesh.worldToLocal(hit.point.clone());
let nearestRow = 0;
let nearestDistance = Infinity;
for (let row = 0; row < ROW_COUNT; row++) {
const distance = Math.abs(localPoint.y - rowY[row]);
if (distance < nearestDistance) {
nearestDistance = distance;
nearestRow = row;
}
}
targetRow = nearestRow;
nextScanTime = performance.now() / 1000 + 3.2;
}
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.012,
10.5,
25
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
orbit.radius = 17.5;
orbit.theta = 2.42;
orbit.phi = 1.17;
});
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function damp(current, target, lambda, deltaTime) {
return THREE.MathUtils.lerp(
current,
target,
1 - Math.exp(-lambda * deltaTime)
);
}
function nearestRowToCard() {
let nearest = 0;
let nearestDistance = Infinity;
for (let row = 0; row < ROW_COUNT; row++) {
const distance = Math.abs(cardMesh.position.z - rowY[row]);
if (distance < nearestDistance) {
nearestDistance = distance;
nearest = row;
}
}
return nearest;
}
function animate() {
const deltaTime = Math.min(clock.getDelta(), 0.05);
const elapsedTime = clock.elapsedTime;
if (autoScan && elapsedTime >= nextScanTime) {
targetRow = (targetRow + 1) % ROW_COUNT;
nextScanTime = elapsedTime + 3.2;
}
// The punched card slides under the stationary read head.
cardMesh.position.z = damp(
cardMesh.position.z,
rowY[targetRow],
2.7,
deltaTime
);
const detectedRow = nearestRowToCard();
if (detectedRow !== currentRow) {
currentRow = detectedRow;
updateHUD();
}
for (let groupIndex = 0; groupIndex < GROUP_COUNT; groupIndex++) {
const group = groups[groupIndex];
const selected = Boolean(patterns[currentRow][groupIndex]);
const liftTarget = selected ? 1 : 0;
group.lift = damp(group.lift, liftTarget, 5.4, deltaTime);
const liftAmount = group.lift * MAX_LIFT;
const liftRatio = group.lift;
// Thread color shifts from muted to the matching group color.
group.threadMaterial.color
.copy(mutedThreadColor)
.lerp(groupColors[groupIndex], 0.08 + liftRatio * 0.92);
group.threadMaterial.emissive.copy(groupColors[groupIndex]);
group.threadMaterial.emissiveIntensity = liftRatio * 0.2;
group.hookMaterial.emissiveIntensity = 0.05 + liftRatio * 0.55;
group.signalMaterial.opacity = selected ? 0.58 : 0.07;
// The read pin descends only when its matching hole is under the head.
const pinTargetY = selected ? 4.38 : 4.54;
group.pinGroup.position.y = damp(
group.pinGroup.position.y,
pinTargetY,
10,
deltaTime
);
group.tipMaterial.emissiveIntensity = selected ? 2.2 : 0.04;
// Hook follows the center of the rising thread bundle.
const hookY = BASE_WARP_Y + liftAmount - 0.08;
group.hook.position.y = hookY;
group.hook.rotation.z = Math.sin(elapsedTime * 2 + groupIndex) * 0.025;
positionCylinder(
group.lifterRod,
new THREE.Vector3(groupX[groupIndex], 4.0, 0),
new THREE.Vector3(groupX[groupIndex], hookY + 0.055, 0),
0.021
);
// Update each segmented thread. The raised center forms the open shed.
for (const strand of group.threadBundle) {
for (let segment = 0; segment < THREAD_SEGMENTS; segment++) {
const t0 = segment / THREAD_SEGMENTS;
const t1 = (segment + 1) / THREAD_SEGMENTS;
const z0 = -4.08 + t0 * 8.16;
const z1 = -4.08 + t1 * 8.16;
const shoulder0 = Math.exp(-Math.pow(Math.abs(z0) / 0.76, 2));
const shoulder1 = Math.exp(-Math.pow(Math.abs(z1) / 0.76, 2));
const y0 = BASE_WARP_Y + liftAmount * shoulder0;
const y1 = BASE_WARP_Y + liftAmount * shoulder1;
const mesh = strand.segments[segment];
mesh.position.set(
strand.x,
(y0 + y1) * 0.5,
(z0 + z1) * 0.5
);
tempDirection.set(0, y1 - y0, z1 - z0).normalize();
mesh.quaternion.setFromUnitVectors(up, tempDirection);
const length = Math.hypot(y1 - y0, z1 - z0);
mesh.scale.set(0.021, length, 0.021);
}
}
}
// Rings travel with the card; the nearest row becomes the active row.
for (const ring of holeRings) {
const { row, column } = ring.userData;
ring.position.z = cardMesh.position.z - rowY[row];
const active = row === currentRow;
const targetOpacity = active ? 0.98 : 0.3;
const targetScale = active ? 1.18 : 1;
ring.material.opacity = damp(
ring.material.opacity,
targetOpacity,
10,
deltaTime
);
const scale = damp(ring.scale.x, targetScale, 10, deltaTime);
ring.scale.setScalar(scale);
// A subtle pulse makes the currently read holes easy to follow.
const pulse = active ? 1 + Math.sin(elapsedTime * 5 + column) * 0.08 : 1;
ring.scale.setScalar(scale * pulse);
}
applyCamera();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
</script>
</body>
</html>
```