Prompt specification
Build or customize the Three.js 3D scene "Two-Color Registration Table" 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: Two-Color Registration Table
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/two-color-registration-table-x3334
Scene Description Prompt:
Make a low-poly Three.js scene in a self-contained HTML file using cdnjs: two-color registration table. Animate two printing blocks aligned over one paper sheet with registration pegs. Shift one block to show misregistration while keeping the layering order visible.
Working Three.js Starter (two-color-registration-table-x3334):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Two-Color Registration Table</title>
<style>
:root {
--ink: #20252c;
--muted: #737980;
--cyan: #00a9c6;
--magenta: #ef277f;
--paper: #f6f0e4;
--glass: rgba(248, 246, 239, 0.86);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #ded8ce;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid rgba(32, 37, 44, 0.14);
background: var(--glass);
box-shadow: 0 14px 40px rgba(37, 33, 28, 0.12);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#heading {
top: 22px;
left: 22px;
padding: 18px 20px 16px;
border-radius: 4px;
max-width: 390px;
}
.eyebrow {
margin-bottom: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 34px);
line-height: 0.98;
letter-spacing: -0.045em;
text-transform: uppercase;
}
#heading p {
margin: 11px 0 0;
max-width: 330px;
color: #5f656b;
font-size: 12px;
line-height: 1.5;
}
#legend {
top: 22px;
right: 22px;
width: 244px;
padding: 15px 16px;
border-radius: 4px;
}
.legend-row {
display: grid;
grid-template-columns: 34px 1fr;
gap: 10px;
align-items: center;
padding: 9px 0;
}
.legend-row + .legend-row {
border-top: 1px solid rgba(32, 37, 44, 0.1);
}
.swatch {
height: 27px;
border-radius: 2px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.cyan {
background: var(--cyan);
}
.magenta {
background: var(--magenta);
}
.legend-title {
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend-note {
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
#controls {
bottom: 22px;
left: 22px;
right: 22px;
display: flex;
align-items: center;
gap: 18px;
padding: 13px 15px;
border-radius: 4px;
}
.status {
min-width: 174px;
}
.status-line {
display: flex;
align-items: center;
gap: 8px;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 0 4px rgba(0, 169, 198, 0.13);
}
#offset {
margin-top: 5px;
color: var(--muted);
font-size: 10px;
font-variant-numeric: tabular-nums;
}
#timeline {
position: relative;
flex: 1;
height: 4px;
overflow: hidden;
border-radius: 99px;
background: rgba(32, 37, 44, 0.12);
}
#progress {
position: absolute;
inset: 0 auto 0 0;
width: 0;
background: linear-gradient(90deg, var(--cyan), var(--magenta));
}
.buttons {
display: flex;
gap: 7px;
}
button {
border: 1px solid rgba(32, 37, 44, 0.18);
border-radius: 2px;
padding: 9px 12px;
background: rgba(255, 255, 255, 0.65);
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
}
button:hover {
background: #fff;
}
button:active {
transform: translateY(1px);
}
#hint {
position: fixed;
z-index: 9;
right: 24px;
bottom: 94px;
color: rgba(32, 37, 44, 0.62);
font-size: 10px;
letter-spacing: 0.06em;
text-transform: uppercase;
pointer-events: none;
}
@media (max-width: 720px) {
#heading {
top: 12px;
left: 12px;
max-width: calc(100vw - 24px);
padding: 13px 15px;
}
#heading p {
display: none;
}
#legend {
top: auto;
right: 12px;
bottom: 91px;
width: 190px;
padding: 9px 11px;
}
.legend-row {
padding: 6px 0;
}
#controls {
right: 12px;
bottom: 12px;
left: 12px;
gap: 10px;
padding: 11px;
}
.status {
min-width: 126px;
}
.status-line {
font-size: 9px;
}
#timeline {
display: none;
}
button {
padding: 9px;
font-size: 9px;
}
#hint {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<header id="heading" class="panel">
<div class="eyebrow">Pressroom study / 02 inks</div>
<h1>Two-color<br>registration</h1>
<p>
An exploded press view showing cyan beneath magenta. The upper block
shifts off the registration pegs to expose the misregistered ink layers.
</p>
</header>
<aside id="legend" class="panel">
<div class="legend-row">
<div class="swatch cyan"></div>
<div>
<div class="legend-title">01 · Cyan underlay</div>
<div class="legend-note">Fixed to the sheet</div>
</div>
</div>
<div class="legend-row">
<div class="swatch magenta"></div>
<div>
<div class="legend-title">02 · Magenta overlay</div>
<div class="legend-note">Always printed over cyan</div>
</div>
</div>
</aside>
<div id="controls" class="panel">
<div class="status">
<div class="status-line">
<span id="status-dot"></span>
<span id="status-text">Registered</span>
</div>
<div id="offset">0.0 mm offset</div>
</div>
<div id="timeline"><div id="progress"></div></div>
<div class="buttons">
<button id="play" type="button">Pause</button>
<button id="replay" type="button">Replay</button>
<button id="reset-view" type="button">Reset view</button>
</div>
</div>
<div id="hint">Drag to orbit · Scroll to zoom</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 stage = document.querySelector("#stage");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xded8ce);
scene.fog = new THREE.Fog(0xded8ce, 20, 36);
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.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-8, 8, 6, -6, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0.42, 0);
const view = {
radius: 13.5,
theta: 0.72,
phi: 0.91
};
function updateCamera() {
const sinPhi = Math.sin(view.phi);
camera.position.set(
cameraTarget.x + view.radius * sinPhi * Math.sin(view.theta),
cameraTarget.y + view.radius * Math.cos(view.phi),
cameraTarget.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(cameraTarget);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
// Keep the table visible on narrow displays.
const halfHeight = Math.max(5.35, 6.6 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xfff9ed, 0x5d6470, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff4de, 3.8);
keyLight.position.set(-5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 28;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb8dfff, 1.6);
fillLight.position.set(7, 5, -7);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xffc4dc, 0.75);
rimLight.position.set(-6, 3, -6);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Materials and reusable geometry helpers
// -------------------------------------------------------------------------
const COLORS = {
cyan: 0x00a9c6,
magenta: 0xef277f,
ink: 0x20252c,
tableTop: 0xbdb5a8,
tableEdge: 0x343b43,
platen: 0x272e36,
paper: 0xf6f0e4,
metal: 0xa7adb0,
metalDark: 0x525a60
};
function standard(color, roughness = 0.72, metalness = 0) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness,
flatShading: true
});
}
function addBox(parent, width, height, depth, material, x, y, z) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
segments,
material,
x,
y,
z
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeLabel(text, accent) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 150;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(27, 31, 37, 0.92)";
context.beginPath();
context.roundRect(4, 4, 632, 142, 16);
context.fill();
context.strokeStyle = accent;
context.lineWidth = 7;
context.stroke();
context.fillStyle = accent;
context.fillRect(28, 31, 12, 88);
context.fillStyle = "#ffffff";
context.font = "800 38px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 340, 76);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(2.35, 0.55, 1);
sprite.renderOrder = 20;
return sprite;
}
// -------------------------------------------------------------------------
// Registration table and press bed
// -------------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
standard(0xc9c3b8, 0.95)
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.72;
floor.receiveShadow = true;
scene.add(floor);
const table = new THREE.Group();
scene.add(table);
const tableTopMaterial = standard(COLORS.tableTop, 0.86);
const tableEdgeMaterial = standard(COLORS.tableEdge, 0.78);
const legMaterial = standard(0x424a52, 0.72, 0.18);
addBox(table, 9.45, 0.34, 7.15, tableEdgeMaterial, 0, -0.19, 0);
addBox(table, 9.28, 0.24, 6.98, tableTopMaterial, 0, -0.005, 0);
for (const x of [-3.75, 3.75]) {
for (const z of [-2.55, 2.55]) {
addBox(table, 0.42, 1.5, 0.42, legMaterial, x, -0.98, z);
addBox(
table,
0.5,
0.1,
0.5,
tableEdgeMaterial,
x,
-1.69,
z
);
}
}
addBox(table, 7.8, 0.18, 0.22, legMaterial, 0, -1.18, -2.55);
addBox(table, 7.8, 0.18, 0.22, legMaterial, 0, -1.18, 2.55);
const platen = addBox(
table,
7.95,
0.15,
5.75,
standard(COLORS.platen, 0.66, 0.22),
0,
0.105,
0
);
// Subtle bed border.
const borderMaterial = standard(0x56616a, 0.72, 0.15);
addBox(table, 7.65, 0.025, 0.035, borderMaterial, 0, 0.195, -2.69);
addBox(table, 7.65, 0.025, 0.035, borderMaterial, 0, 0.195, 2.69);
addBox(table, 0.035, 0.025, 5.38, borderMaterial, -3.82, 0.195, 0);
addBox(table, 0.035, 0.025, 5.38, borderMaterial, 3.82, 0.195, 0);
// Front ruler ticks.
const tickMaterial = standard(0xa7b0b4, 0.7, 0.1);
for (let i = -9; i <= 9; i++) {
const length = i % 3 === 0 ? 0.22 : 0.12;
addBox(
table,
0.025,
0.018,
length,
tickMaterial,
i * 0.39,
0.197,
2.53
);
}
// One paper sheet.
const paperGeometry = new THREE.BoxGeometry(6.82, 0.045, 4.68);
const paper = new THREE.Mesh(paperGeometry, standard(COLORS.paper, 0.94));
paper.position.set(0, 0.205, 0);
paper.receiveShadow = true;
paper.castShadow = true;
scene.add(paper);
const paperEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(paperGeometry),
new THREE.LineBasicMaterial({
color: 0xaaa394,
transparent: true,
opacity: 0.42
})
);
paperEdges.position.copy(paper.position);
scene.add(paperEdges);
// -------------------------------------------------------------------------
// Registration pegs and printed targets
// -------------------------------------------------------------------------
const pegPositions = [
[-3.04, -2.02],
[3.04, -2.02],
[-3.04, 2.02],
[3.04, 2.02]
];
const metalMaterial = standard(COLORS.metal, 0.38, 0.72);
const darkMetalMaterial = standard(COLORS.metalDark, 0.5, 0.55);
const cyanTargetMaterial = standard(COLORS.cyan, 0.56);
const magentaTargetMaterial = standard(COLORS.magenta, 0.56);
function horizontalRing(radius, width, material, x, y, z) {
const mesh = new THREE.Mesh(
new THREE.RingGeometry(radius - width, radius, 24),
material
);
mesh.rotation.x = -Math.PI / 2;
mesh.position.set(x, y, z);
mesh.receiveShadow = true;
return mesh;
}
for (const [x, z] of pegPositions) {
const targetGroup = new THREE.Group();
targetGroup.position.set(x, 0, z);
scene.add(targetGroup);
targetGroup.add(
horizontalRing(0.31, 0.055, cyanTargetMaterial, 0, 0.235, 0)
);
targetGroup.add(
horizontalRing(
0.225,
0.052,
magentaTargetMaterial,
0.045,
0.239,
0.025
)
);
addCylinder(
targetGroup,
0.075,
0.09,
0.44,
8,
metalMaterial,
0,
0.445,
0
);
addCylinder(
targetGroup,
0.14,
0.14,
0.075,
8,
darkMetalMaterial,
0,
0.265,
0
);
addCylinder(
targetGroup,
0.11,
0.14,
0.18,
8,
metalMaterial,
0,
0.69,
0
);
}
// -------------------------------------------------------------------------
// Printed artwork: cyan under magenta
// -------------------------------------------------------------------------
function createInkArtwork(color, y, name) {
const group = new THREE.Group();
group.name = name;
group.position.y = y;
const material = standard(color, 0.57);
const ring = new THREE.Mesh(
new THREE.RingGeometry(0.64, 0.91, 24),
material
);
ring.rotation.x = -Math.PI / 2;
group.add(ring);
const horizontal = new THREE.Mesh(
new THREE.BoxGeometry(2.48, 0.012, 0.15),
material
);
group.add(horizontal);
const vertical = new THREE.Mesh(
new THREE.BoxGeometry(0.15, 0.012, 2.48),
material
);
group.add(vertical);
const center = new THREE.Mesh(
new THREE.CylinderGeometry(0.19, 0.19, 0.014, 12),
material
);
group.add(center);
scene.add(group);
return group;
}
const cyanArtwork = createInkArtwork(COLORS.cyan, 0.239, "Cyan underprint");
const magentaArtwork = createInkArtwork(
COLORS.magenta,
0.255,
"Magenta overprint"
);
// -------------------------------------------------------------------------
// Exploded printing blocks
// -------------------------------------------------------------------------
function createPrintingBlock(color, labelText, labelColor) {
const group = new THREE.Group();
const frameMaterial = standard(color, 0.5, 0.08);
const undersideMaterial = standard(color, 0.66);
const handleMaterial = standard(0xe5ded0, 0.58);
const handleDarkMaterial = standard(0x343a40, 0.6, 0.15);
// Open rectangular printing frame.
addBox(group, 5.02, 0.24, 0.28, frameMaterial, 0, 0, -1.52);
addBox(group, 5.02, 0.24, 0.28, frameMaterial, 0, 0, 1.52);
addBox(group, 0.28, 0.24, 2.76, frameMaterial, -2.64, 0, 0);
addBox(group, 0.28, 0.24, 2.76, frameMaterial, 2.64, 0, 0);
// Dark relief layer under the colored frame.
addBox(group, 4.85, 0.07, 0.14, handleDarkMaterial, 0, -0.155, -1.52);
addBox(group, 4.85, 0.07, 0.14, handleDarkMaterial, 0, -0.155, 1.52);
addBox(group, 0.14, 0.07, 2.62, handleDarkMaterial, -2.64, -0.155, 0);
addBox(group, 0.14, 0.07, 2.62, handleDarkMaterial, 2.64, -0.155, 0);
// Matching relief artwork on the underside.
const reliefRing = new THREE.Mesh(
new THREE.RingGeometry(0.66, 0.86, 24),
undersideMaterial
);
reliefRing.rotation.x = -Math.PI / 2;
reliefRing.position.y = -0.17;
group.add(reliefRing);
const reliefBarX = new THREE.Mesh(
new THREE.BoxGeometry(2.3, 0.035, 0.12),
undersideMaterial
);
reliefBarX.position.y = -0.17;
group.add(reliefBarX);
const reliefBarZ = new THREE.Mesh(
new THREE.BoxGeometry(0.12, 0.035, 2.3),
undersideMaterial
);
reliefBarZ.position.y = -0.17;
group.add(reliefBarZ);
// Handle toward the rear of the block, keeping the artwork visible.
addCylinder(group, 0.09, 0.11, 0.48, 8, handleMaterial, -0.92, 0.37, 0.82);
addCylinder(group, 0.09, 0.11, 0.48, 8, handleMaterial, 0.92, 0.37, 0.82);
addBox(group, 2.12, 0.17, 0.2, handleMaterial, 0, 0.66, 0.82);
addBox(group, 0.18, 0.18, 0.23, handleDarkMaterial, -0.92, 0.64, 0.82);
addBox(group, 0.18, 0.18, 0.23, handleDarkMaterial, 0.92, 0.64, 0.82);
// Four registration tabs connect the frame corners to the peg positions.
const cornerPairs = [
[[-2.64, -1.52], [-3.04, -2.02]],
[[2.64, -1.52], [3.04, -2.02]],
[[-2.64, 1.52], [-3.04, 2.02]],
[[2.64, 1.52], [3.04, 2.02]]
];
for (const [[ax, az], [bx, bz]] of cornerPairs) {
const dx = bx - ax;
const dz = bz - az;
const length = Math.hypot(dx, dz);
const tab = new THREE.Mesh(
new THREE.BoxGeometry(length, 0.09, 0.13),
undersideMaterial
);
tab.position.set((ax + bx) / 2, -0.12, (az + bz) / 2);
tab.rotation.y = -Math.atan2(dz, dx);
tab.castShadow = true;
group.add(tab);
}
const label = makeLabel(labelText, labelColor);
label.position.set(3.5, 0.16, -0.6);
group.add(label);
return group;
}
const cyanBlock = createPrintingBlock(
COLORS.cyan,
"01 CYAN / UNDER",
"#00c2df"
);
cyanBlock.position.set(0, 0.98, 0);
scene.add(cyanBlock);
const magentaBlock = createPrintingBlock(
COLORS.magenta,
"02 MAGENTA / OVER",
"#ff4b9c"
);
magentaBlock.position.set(0, 1.72, 0);
scene.add(magentaBlock);
// Thin guides make the vertical layer order explicit.
const guideMaterial = new THREE.LineDashedMaterial({
color: 0x5e6469,
transparent: true,
opacity: 0.45,
dashSize: 0.12,
gapSize: 0.09
});
const guideGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-3.55, 0.24, 0),
new THREE.Vector3(-3.55, 1.87, 0)
]);
const guide = new THREE.Line(guideGeometry, guideMaterial);
guide.computeLineDistances();
scene.add(guide);
// Offset measurement arrow on the sheet.
const offsetArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(0, 0.275, 0),
0.001,
0x30363c,
0.16,
0.1
);
offsetArrow.visible = false;
scene.add(offsetArrow);
const targetPoint = new THREE.Mesh(
new THREE.RingGeometry(0.055, 0.095, 12),
new THREE.MeshBasicMaterial({
color: 0x30363c,
side: THREE.DoubleSide
})
);
targetPoint.rotation.x = -Math.PI / 2;
targetPoint.position.y = 0.276;
scene.add(targetPoint);
// -------------------------------------------------------------------------
// Custom camera controls: orbit, pinch, and wheel zoom
// -------------------------------------------------------------------------
const activePointers = new Map();
let lastPinchDistance = 0;
function pointerDistance() {
const values = [...activePointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 2) {
lastPinchDistance = pointerDistance();
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!activePointers.has(event.pointerId)) return;
const previous = activePointers.get(event.pointerId);
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 1) {
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
view.theta -= dx * 0.006;
view.phi = THREE.MathUtils.clamp(
view.phi + dy * 0.005,
0.48,
1.24
);
updateCamera();
} else if (activePointers.size === 2) {
const distance = pointerDistance();
if (lastPinchDistance > 0 && distance > 0) {
view.radius = THREE.MathUtils.clamp(
view.radius * (lastPinchDistance / distance),
8.5,
21
);
updateCamera();
}
lastPinchDistance = distance;
}
});
function endPointer(event) {
activePointers.delete(event.pointerId);
if (activePointers.size < 2) {
lastPinchDistance = 0;
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius * Math.exp(event.deltaY * 0.001),
8.5,
21
);
updateCamera();
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Registration animation
// -------------------------------------------------------------------------
const duration = 10;
let cycleStart = performance.now();
let paused = false;
let pausedAt = 0;
const playButton = document.querySelector("#play");
const replayButton = document.querySelector("#replay");
const resetViewButton = document.querySelector("#reset-view");
const statusText = document.querySelector("#status-text");
const statusDot = document.querySelector("#status-dot");
const offsetText = document.querySelector("#offset");
const progress = document.querySelector("#progress");
function smoothstep(value) {
const x = THREE.MathUtils.clamp(value, 0, 1);
return x * x * (3 - 2 * x);
}
function togglePlayback() {
const now = performance.now();
if (paused) {
cycleStart += now - pausedAt;
paused = false;
playButton.textContent = "Pause";
} else {
pausedAt = now;
paused = true;
playButton.textContent = "Resume";
}
}
playButton.addEventListener("click", togglePlayback);
replayButton.addEventListener("click", () => {
cycleStart = performance.now();
paused = false;
playButton.textContent = "Pause";
});
resetViewButton.addEventListener("click", () => {
view.radius = 13.5;
view.theta = 0.72;
view.phi = 0.91;
updateCamera();
});
const maximumShift = 0.74;
const shiftDirection = new THREE.Vector3();
function animate(now) {
const elapsed = paused
? (pausedAt - cycleStart) / 1000
: (now - cycleStart) / 1000;
const time = ((elapsed % duration) + duration) % duration;
// Registered hold → slide out → misregistered hold → return.
const outward = smoothstep((time - 1.25) / 2.25);
const inward = smoothstep((time - 6.25) / 2.25);
const shiftAmount = outward * (1 - inward);
const shiftX = maximumShift * shiftAmount;
const shiftZ = maximumShift * 0.22 * shiftAmount;
// The upper magenta block moves; cyan remains registered.
magentaBlock.position.x = shiftX;
magentaBlock.position.z = shiftZ;
magentaBlock.position.y = 1.72 - shiftAmount * 0.07;
// Magenta ink always remains above the cyan ink layer.
magentaArtwork.position.x = shiftX;
magentaArtwork.position.z = shiftZ;
// Draw the registration error vector.
const magnitude = Math.hypot(shiftX, shiftZ);
offsetArrow.visible = magnitude > 0.012;
if (offsetArrow.visible) {
shiftDirection.set(shiftX, 0, shiftZ).normalize();
offsetArrow.setDirection(shiftDirection);
offsetArrow.setLength(magnitude, 0.16, 0.105);
}
// Interface status.
const errorMM = (shiftAmount * 3.2).toFixed(1);
offsetText.textContent = `${errorMM} mm offset`;
if (shiftAmount < 0.015) {
statusText.textContent = "Registered";
statusDot.style.background = "var(--cyan)";
statusDot.style.boxShadow = "0 0 0 4px rgba(0, 169, 198, 0.13)";
} else if (shiftAmount > 0.985) {
statusText.textContent = "Misregistered";
statusDot.style.background = "var(--magenta)";
statusDot.style.boxShadow = "0 0 0 4px rgba(239, 39, 127, 0.14)";
} else {
statusText.textContent = "Shifting";
statusDot.style.background = "#d69c33";
statusDot.style.boxShadow = "0 0 0 4px rgba(214, 156, 51, 0.14)";
}
progress.style.width = `${(time / duration) * 100}%`;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```