Prompt specification
Build or customize the Three.js 3D scene "Print Edition Variation Explorer" 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: Print Edition Variation Explorer
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/print-edition-variation-explorer-x3336
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts relief printing, mirrored marks, and registration. Create a tabletop press with adjustable alignment and ink coverage parameters. Compare resulting geometric impressions without portraying random defects as historical evidence. Voxel style.
Working Three.js Starter (print-edition-variation-explorer-x3336):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Relief Registration Lab</title>
<style>
:root {
color-scheme: light;
--ink: #20232c;
--muted: #666a76;
--paper: #f3eee2;
--panel: rgba(250, 247, 238, 0.95);
--line: rgba(32, 35, 44, 0.15);
--green: #3b9b75;
--magenta: #a34778;
--cyan: #32a9b7;
--accent: #e36f51;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9d2c4;
color: var(--ink);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
button,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
background: var(--panel);
border: 1px solid rgba(32, 35, 44, 0.17);
box-shadow: 0 14px 45px rgba(42, 35, 27, 0.16);
backdrop-filter: blur(12px);
}
#brand {
top: 18px;
left: 18px;
width: 318px;
padding: 16px 18px;
border-left: 7px solid var(--accent);
}
#brand h1 {
margin: 0 0 5px;
font-size: 18px;
letter-spacing: 0.04em;
}
#brand p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
#controls {
top: 126px;
left: 18px;
width: 318px;
max-height: calc(100vh - 144px);
padding: 17px 18px;
overflow-y: auto;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin: 0 0 13px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.badge {
padding: 4px 7px;
border: 1px solid var(--line);
background: rgba(32, 35, 44, 0.045);
color: var(--muted);
font-size: 9px;
letter-spacing: 0.06em;
}
.control {
margin: 0 0 17px;
}
.control label {
display: flex;
justify-content: space-between;
gap: 10px;
margin-bottom: 7px;
font-size: 11px;
font-weight: 700;
}
output {
color: var(--accent);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 20px;
margin: 0;
accent-color: var(--accent);
cursor: ew-resize;
}
.range-ends {
display: flex;
justify-content: space-between;
margin-top: 2px;
color: #888b94;
font-size: 9px;
}
.divider {
height: 1px;
margin: 16px 0;
background: var(--line);
}
.check {
display: flex;
align-items: center;
gap: 8px;
margin: 13px 0;
color: #454954;
font-size: 10px;
line-height: 1.4;
}
.check input {
accent-color: var(--green);
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 14px;
}
button {
min-height: 38px;
padding: 9px 10px;
border: 1px solid rgba(32, 35, 44, 0.23);
background: transparent;
color: var(--ink);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.05em;
cursor: pointer;
}
button:hover:not(:disabled) {
background: rgba(32, 35, 44, 0.07);
}
button.primary {
border-color: var(--accent);
background: var(--accent);
color: #fffaf2;
}
button.primary:hover:not(:disabled) {
background: #cf6045;
}
button:disabled {
cursor: wait;
opacity: 0.55;
}
.note {
margin: 14px 0 0;
padding: 11px 12px;
border: 1px solid rgba(59, 155, 117, 0.3);
background: rgba(59, 155, 117, 0.07);
color: #405b50;
font-size: 9px;
line-height: 1.55;
}
#comparison {
right: 18px;
bottom: 18px;
width: 366px;
padding: 15px;
}
#comparison .section-title {
margin-bottom: 10px;
}
.comparison-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.mini {
min-width: 0;
border: 1px solid var(--line);
background: #eee7d9;
}
.mini-title {
display: flex;
justify-content: space-between;
gap: 5px;
padding: 7px 8px;
border-bottom: 1px solid var(--line);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.06em;
}
.mini canvas {
display: block;
width: 100%;
height: auto;
aspect-ratio: 300 / 210;
}
.metrics {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
margin-top: 10px;
}
.metric {
min-width: 0;
padding: 8px 6px;
border: 1px solid var(--line);
text-align: center;
background: rgba(255, 255, 255, 0.25);
}
.metric strong {
display: block;
overflow: hidden;
color: var(--ink);
font-size: 12px;
text-overflow: ellipsis;
white-space: nowrap;
}
.metric span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 8px;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 11px;
margin-top: 10px;
color: var(--muted);
font-size: 9px;
}
.legend span::before {
content: "";
display: inline-block;
width: 8px;
height: 8px;
margin-right: 5px;
background: var(--color);
vertical-align: -1px;
}
#camera-hint {
position: fixed;
z-index: 5;
right: 18px;
top: 18px;
padding: 9px 11px;
border: 1px solid rgba(32, 35, 44, 0.16);
background: rgba(250, 247, 238, 0.82);
color: #5d6069;
font-size: 9px;
pointer-events: none;
}
#status {
position: fixed;
z-index: 8;
left: 50%;
bottom: 18px;
transform: translateX(-50%);
padding: 8px 12px;
border: 1px solid rgba(32, 35, 44, 0.16);
background: rgba(250, 247, 238, 0.9);
color: #4f535d;
font-size: 9px;
letter-spacing: 0.04em;
pointer-events: none;
}
@media (max-width: 900px) {
#brand {
width: 285px;
}
#controls {
width: 285px;
}
#comparison {
width: 320px;
}
.mini canvas {
max-height: 145px;
}
}
@media (max-width: 680px) {
#brand {
top: 10px;
left: 10px;
width: calc(100% - 20px);
}
#controls {
top: auto;
left: 10px;
bottom: 10px;
width: calc(100% - 20px);
max-height: 38vh;
padding: 13px;
}
#comparison {
top: 104px;
right: 10px;
bottom: auto;
width: 245px;
padding: 10px;
}
.metrics {
grid-template-columns: repeat(2, 1fr);
}
.mini canvas {
max-height: 100px;
}
#camera-hint,
#status {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel relief printing press"></canvas>
<header id="brand" class="panel">
<h1>RELIEF / REGISTRATION LAB</h1>
<p>
A synthetic tabletop platen press. The raised matrix is mirror-reversed;
the resulting paper impression returns to a readable orientation.
</p>
</header>
<aside id="controls" class="panel" aria-label="Press parameters">
<div class="section-title">
<span>Plate alignment</span>
<span class="badge">Live geometry</span>
</div>
<div class="control">
<label for="alignment-x">
<span>Horizontal offset</span>
<output id="alignment-x-value">+0.0 mm</output>
</label>
<input id="alignment-x" type="range" min="-8" max="8" step="0.1" value="0">
<div class="range-ends"><span>−8 mm</span><span>+8 mm</span></div>
</div>
<div class="control">
<label for="alignment-y">
<span>Vertical offset</span>
<output id="alignment-y-value">+0.0 mm</output>
</label>
<input id="alignment-y" type="range" min="-8" max="8" step="0.1" value="0">
<div class="range-ends"><span>−8 mm</span><span>+8 mm</span></div>
</div>
<div class="control">
<label for="angle">
<span>Plate rotation</span>
<output id="angle-value">+0.0°</output>
</label>
<input id="angle" type="range" min="-8" max="8" step="0.1" value="0">
<div class="range-ends"><span>−8°</span><span>+8°</span></div>
</div>
<div class="divider"></div>
<div class="section-title">
<span>Ink coverage</span>
<span class="badge">Uniform lay-down</span>
</div>
<div class="control">
<label for="coverage">
<span>Synthetic ink film</span>
<output id="coverage-value">78%</output>
</label>
<input id="coverage" type="range" min="0" max="100" step="1" value="78">
<div class="range-ends"><span>Dry</span><span>Full</span></div>
</div>
<label class="check">
<input id="overlay" type="checkbox" checked>
Show the fixed target as a translucent overlay on the result board
</label>
<div class="button-row">
<button id="center" type="button">CENTER MATRIX</button>
<button id="print" class="primary" type="button">MAKE IMPRESSION</button>
</div>
<p class="note">
<strong>Evidence note:</strong> this is a controlled geometric simulation.
No random wear, broken type, stains, or defects are generated, and the
comparison should not be treated as historical evidence.
</p>
</aside>
<section id="comparison" class="panel" aria-label="Impression comparison">
<div class="section-title">
<span>Impression comparison</span>
<span class="badge">Deterministic</span>
</div>
<div class="comparison-grid">
<div class="mini">
<div class="mini-title"><span>FIXED TARGET</span><span>GREEN</span></div>
<canvas id="target-preview" width="300" height="210"></canvas>
</div>
<div class="mini">
<div class="mini-title"><span>RESULT + TARGET</span><span>INK</span></div>
<canvas id="result-preview" width="300" height="210"></canvas>
</div>
</div>
<div class="metrics">
<div class="metric">
<strong id="metric-offset">0.0</strong>
<span>Offset mm</span>
</div>
<div class="metric">
<strong id="metric-angle">0.0°</strong>
<span>Angle</span>
</div>
<div class="metric">
<strong id="metric-overlap">100%</strong>
<span>Cell overlap</span>
</div>
<div class="metric">
<strong id="metric-coverage">78%</strong>
<span>Coverage</span>
</div>
</div>
<div class="legend">
<span style="--color: var(--green)">Target</span>
<span style="--color: var(--magenta)">Actual impression</span>
<span style="--color: var(--cyan)">Registration</span>
</div>
</section>
<div id="camera-hint">DRAG TO ORBIT · WHEEL TO ZOOM · DOUBLE-CLICK TO RESET VIEW</div>
<div id="status" role="status" aria-live="polite">Ready for a controlled impression.</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 renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd9d2c4);
scene.fog = new THREE.Fog(0xd9d2c4, 18, 35);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const target = new THREE.Vector3(0.1, 2.45, 0.15);
const cameraState = {
radius: 15.8,
theta: 0.58,
phi: 1.02
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
target.x + cameraState.radius * sinPhi * Math.sin(cameraState.theta),
target.y + cameraState.radius * Math.cos(cameraState.phi),
target.z + cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(target);
}
updateCamera();
// Camera controls are intentionally implemented without Three.js addons.
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.005,
0.48,
1.43
);
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
8.5,
24
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
cameraState.radius = 15.8;
cameraState.theta = 0.58;
cameraState.phi = 1.02;
});
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
if (event.key === "ArrowLeft") cameraState.theta -= 0.08;
if (event.key === "ArrowRight") cameraState.theta += 0.08;
if (event.key === "ArrowUp") {
cameraState.phi = THREE.MathUtils.clamp(cameraState.phi - 0.05, 0.48, 1.43);
}
if (event.key === "ArrowDown") {
cameraState.phi = THREE.MathUtils.clamp(cameraState.phi + 0.05, 0.48, 1.43);
}
});
const hemisphere = new THREE.HemisphereLight(0xfff7e8, 0x6c7180, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff1d9, 3.2);
keyLight.position.set(7, 12, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb8d7df, 1.0);
fillLight.position.set(-8, 6, -5);
scene.add(fillLight);
const materials = {
floor: new THREE.MeshStandardMaterial({
color: 0xc9c0b0,
roughness: 0.95
}),
table: new THREE.MeshStandardMaterial({
color: 0x9a6949,
roughness: 0.82
}),
tableEdge: new THREE.MeshStandardMaterial({
color: 0x714b36,
roughness: 0.9
}),
frame: new THREE.MeshStandardMaterial({
color: 0x344b50,
roughness: 0.64,
metalness: 0.12
}),
frameDark: new THREE.MeshStandardMaterial({
color: 0x24373b,
roughness: 0.7,
metalness: 0.08
}),
bed: new THREE.MeshStandardMaterial({
color: 0xc1a078,
roughness: 0.88
}),
platen: new THREE.MeshStandardMaterial({
color: 0x424a50,
roughness: 0.55,
metalness: 0.18
}),
paper: new THREE.MeshStandardMaterial({
color: 0xf5eddd,
roughness: 0.98
}),
target: new THREE.MeshStandardMaterial({
color: 0x3b9b75,
roughness: 0.8,
transparent: true,
opacity: 0.9,
depthWrite: false
}),
targetGhost: new THREE.MeshStandardMaterial({
color: 0x4fa57d,
roughness: 0.9,
transparent: true,
opacity: 0.25,
depthWrite: false
}),
ink: new THREE.MeshStandardMaterial({
color: 0x7d315f,
roughness: 0.92,
transparent: true,
opacity: 0.78,
depthWrite: false
}),
matrix: new THREE.MeshStandardMaterial({
color: 0xe36f51,
roughness: 0.58,
metalness: 0.08
}),
registration: new THREE.MeshStandardMaterial({
color: 0x32a9b7,
roughness: 0.7,
emissive: 0x0b3439,
emissiveIntensity: 0.14
}),
board: new THREE.MeshStandardMaterial({
color: 0xe8dfcd,
roughness: 0.92
}),
boardTarget: new THREE.MeshStandardMaterial({
color: 0xddd9ca,
roughness: 0.93
})
};
function box(parent, width, height, depth, x, y, z, material, rotationY = 0) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.rotation.y = rotationY;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Deterministic asymmetric geometric matrix. It is deliberately synthetic.
const motifRows = [
" ####### ",
" # # ",
" # # # ",
" # # ",
" ####### ",
" ### ",
" ## ## ",
" ### "
];
const motifColumns = motifRows[0].length;
const cellSize = 0.28;
const motifCells = [];
motifRows.forEach((row, rowIndex) => {
[...row].forEach((character, columnIndex) => {
if (character !== "#") return;
motifCells.push({
column: columnIndex,
row: rowIndex,
x: (columnIndex - (motifColumns - 1) / 2) * cellSize,
z: (rowIndex - (motifRows.length - 1) / 2) * cellSize
});
});
});
function createMotif(material, mirrored = false) {
const group = new THREE.Group();
const geometry = new THREE.BoxGeometry(
cellSize * 0.9,
0.09,
cellSize * 0.9
);
const mesh = new THREE.InstancedMesh(
geometry,
material,
motifCells.length
);
const matrix = new THREE.Matrix4();
motifCells.forEach((cell, index) => {
matrix.makeTranslation(
mirrored ? -cell.x : cell.x,
0,
cell.z
);
mesh.setMatrixAt(index, matrix);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
group.userData.motifMesh = mesh;
return group;
}
function addRegistration(parent, width, depth, y, centerZ = 0) {
const arm = 0.34;
const thickness = 0.055;
const corners = [
[-width / 2, -depth / 2],
[ width / 2, -depth / 2],
[-width / 2, depth / 2],
[ width / 2, depth / 2]
];
corners.forEach(([x, z]) => {
box(
parent,
arm,
0.035,
thickness,
x,
y,
z + centerZ,
materials.registration
);
box(
parent,
thickness,
0.035,
arm,
x,
y,
z + centerZ,
materials.registration
);
});
}
function createBoardLabel(text, color) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 96;
const context = labelCanvas.getContext("2d");
context.fillStyle = "#293338";
context.fillRect(0, 0, 512, 96);
context.fillStyle = color;
context.fillRect(0, 0, 12, 96);
context.fillStyle = "#f7f0e3";
context.font = "bold 34px monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 262, 49);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(2.55, 0.48),
new THREE.MeshBasicMaterial({ map: texture })
);
mesh.rotation.x = -Math.PI / 2;
return mesh;
}
// Room and table.
box(scene, 32, 0.2, 32, 0, -0.12, 0, materials.floor);
box(scene, 15, 0.35, 8, 0, 1.45, 0, materials.table);
box(scene, 15.2, 0.14, 8.2, 0, 1.27, 0, materials.tableEdge);
[-6.5, 6.5].forEach((x) => {
[-3.2, 3.2].forEach((z) => {
box(scene, 0.48, 1.28, 0.48, x, 0.68, z, materials.tableEdge);
});
});
// Tabletop relief platen press.
const press = new THREE.Group();
press.position.x = -4.15;
scene.add(press);
box(press, 4.45, 0.28, 3.2, 0, 1.79, 0, materials.frameDark);
box(press, 4.15, 0.18, 3.0, 0, 1.98, 0, materials.bed);
box(press, 3.68, 0.12, 2.85, 0, 2.08, 0.2, materials.platen);
[-1.87, 1.87].forEach((x) => {
box(press, 0.48, 3.05, 0.65, x, 3.34, -0.72, materials.frame);
box(press, 0.7, 0.18, 0.85, x, 1.92, -0.72, materials.frameDark);
});
box(press, 4.35, 0.5, 1.45, 0, 4.87, -0.38, materials.frame);
box(press, 3.72, 0.22, 0.48, 0, 4.56, -0.38, materials.frameDark);
// Voxel screw and lever.
box(press, 0.48, 1.12, 0.48, 0, 5.46, -0.42, materials.frameDark);
box(press, 2.3, 0.26, 0.38, 0, 6.04, -0.42, materials.frame);
box(press, 0.28, 0.28, 0.28, -1.25, 6.04, -0.42, materials.frameDark);
box(press, 0.28, 0.28, 0.28, 1.25, 6.04, -0.42, materials.frameDark);
box(press, 0.36, 0.36, 2.65, 0, 5.74, 0.85, materials.frame, 0);
// Platen is offset backward enough to expose the front of the matrix.
const platen = new THREE.Group();
platen.position.set(0, 4.04, -0.48);
press.add(platen);
box(platen, 3.55, 0.5, 2.35, 0, 0, 0, materials.platen);
box(platen, 3.2, 0.13, 2.05, 0, 0.31, 0, materials.frameDark);
// Fixed registration around the plate.
addRegistration(press, 3.42, 2.55, 2.155, 0.2);
// The raised matrix itself is mirrored.
const plateMotion = new THREE.Group();
plateMotion.position.set(0, 2.205, 0.2);
press.add(plateMotion);
const mirroredMatrix = createMotif(materials.matrix, true);
mirroredMatrix.position.y = 0.045;
plateMotion.add(mirroredMatrix);
// Output sheet, initially under the platen.
const printSheet = new THREE.Group();
printSheet.position.set(0, 2.16, 0.3);
press.add(printSheet);
box(printSheet, 3.45, 0.035, 2.15, 0, 0.018, 0, materials.paper);
const paperPrinted = createMotif(materials.ink, false);
paperPrinted.position.y = 0.075;
paperPrinted.visible = false;
printSheet.add(paperPrinted);
// Fixed target board.
const targetBoard = new THREE.Group();
targetBoard.position.set(1.05, 1.72, 0.25);
scene.add(targetBoard);
box(targetBoard, 3.45, 0.16, 3.0, 0, 0, 0, materials.boardTarget);
addRegistration(targetBoard, 3.08, 2.62, 0.105);
const targetMotion = createMotif(materials.target, false);
targetMotion.position.y = 0.14;
targetBoard.add(targetMotion);
const targetLabel = createBoardLabel("FIXED TARGET", "#66c197");
targetLabel.position.set(0, 0.095, 1.24);
targetBoard.add(targetLabel);
// Result board with an optional fixed-target ghost overlay.
const resultBoard = new THREE.Group();
resultBoard.position.set(4.85, 1.72, 0.25);
scene.add(resultBoard);
box(resultBoard, 3.45, 0.16, 3.0, 0, 0, 0, materials.board);
addRegistration(resultBoard, 3.08, 2.62, 0.105);
const resultGhost = createMotif(materials.targetGhost, false);
resultGhost.position.y = 0.14;
resultBoard.add(resultGhost);
const resultMotion = createMotif(materials.ink, false);
resultMotion.position.y = 0.15;
resultBoard.add(resultMotion);
const resultLabel = createBoardLabel("RESULT / OVERLAY", "#d68ab0");
resultLabel.position.set(0, 0.095, 1.24);
resultBoard.add(resultLabel);
const state = {
x: 0,
y: 0,
angle: 0,
coverage: 78,
overlay: true
};
const elements = {
x: document.querySelector("#alignment-x"),
y: document.querySelector("#alignment-y"),
angle: document.querySelector("#angle"),
coverage: document.querySelector("#coverage"),
overlay: document.querySelector("#overlay"),
xValue: document.querySelector("#alignment-x-value"),
yValue: document.querySelector("#alignment-y-value"),
angleValue: document.querySelector("#angle-value"),
coverageValue: document.querySelector("#coverage-value"),
metricOffset: document.querySelector("#metric-offset"),
metricAngle: document.querySelector("#metric-angle"),
metricOverlap: document.querySelector("#metric-overlap"),
metricCoverage: document.querySelector("#metric-coverage"),
targetPreview: document.querySelector("#target-preview"),
resultPreview: document.querySelector("#result-preview"),
status: document.querySelector("#status"),
print: document.querySelector("#print")
};
const MM_TO_WORLD = 0.045;
function signed(value, digits = 1) {
const clean = Math.abs(value) < 0.0001 ? 0 : value;
return `${clean >= 0 ? "+" : ""}${clean.toFixed(digits)}`;
}
function computeCellOverlap() {
const occupied = new Set(
motifCells.map((cell) => `${cell.column},${cell.row}`)
);
const angle = THREE.MathUtils.degToRad(state.angle);
const cosine = Math.cos(angle);
const sine = Math.sin(angle);
const offsetX = state.x * MM_TO_WORLD;
const offsetZ = -state.y * MM_TO_WORLD;
let matches = 0;
motifCells.forEach((cell) => {
const worldX = cosine * cell.x + sine * cell.z + offsetX;
const worldZ = -sine * cell.x + cosine * cell.z + offsetZ;
const localX = cosine * worldX - sine * worldZ;
const localZ = sine * worldX + cosine * worldZ;
const column = Math.round(
localX / cellSize + (motifColumns - 1) / 2
);
const row = Math.round(
localZ / cellSize + (motifRows.length - 1) / 2
);
if (occupied.has(`${column},${row}`)) matches += 1;
});
return Math.round((matches / motifCells.length) * 100);
}
function drawMiniPreview(canvasElement, isResult) {
const context = canvasElement.getContext("2d");
const width = canvasElement.width;
const height = canvasElement.height;
context.clearRect(0, 0, width, height);
context.fillStyle = "#eee7d9";
context.fillRect(0, 0, width, height);
// Fine drafting grid.
context.strokeStyle = "rgba(55, 60, 65, 0.075)";
context.lineWidth = 1;
for (let x = 0; x <= width; x += 20) {
context.beginPath();
context.moveTo(x, 0);
context.lineTo(x, height);
context.stroke();
}
for (let y = 0; y <= height; y += 20) {
context.beginPath();
context.moveTo(0, y);
context.lineTo(width, y);
context.stroke();
}
// Fixed registration crosses.
context.strokeStyle = "#32a9b7";
context.lineWidth = 3;
const marginX = 20;
const marginY = 20;
const crossSize = 12;
[
[marginX, marginY],
[width - marginX, marginY],
[marginX, height - marginY],
[width - marginX, height - marginY]
].forEach(([x, y]) => {
context.beginPath();
context.moveTo(x - crossSize, y);
context.lineTo(x + crossSize, y);
context.moveTo(x, y - crossSize);
context.lineTo(x, y + crossSize);
context.stroke();
});
const previewCell = 20;
const centerX = width / 2;
const centerY = height / 2;
const angle = THREE.MathUtils.degToRad(state.angle);
const cosine = Math.cos(angle);
const sine = Math.sin(angle);
function drawMotif(transformed, color, alpha) {
context.save();
context.globalAlpha = alpha;
context.fillStyle = color;
motifCells.forEach((cell) => {
const baseX = (cell.column - (motifColumns - 1) / 2) * previewCell;
const baseY = (cell.row - (motifRows.length - 1) / 2) * previewCell;
let x = baseX;
let y = baseY;
if (transformed) {
const rotatedX = cosine * baseX + sine * baseY;
const rotatedY = -sine * baseX + cosine * baseY;
x = rotatedX + state.x * 4;
y = rotatedY - state.y * 4;
}
context.fillRect(
Math.round(centerX + x - previewCell / 2 + 1),
Math.round(centerY + y - previewCell / 2 + 1),
previewCell - 2,
previewCell - 2
);
});
context.restore();
}
if (isResult && state.overlay) {
drawMotif(false, "#3b9b75", 0.25);
}
if (isResult) {
drawMotif(true, "#7d315f", state.coverage / 100);
} else {
drawMotif(false, "#3b9b75", 0.9);
}
}
function updateScene() {
state.x = Number(elements.x.value);
state.y = Number(elements.y.value);
state.angle = Number(elements.angle.value);
state.coverage = Number(elements.coverage.value);
state.overlay = elements.overlay.checked;
const angle = THREE.MathUtils.degToRad(state.angle);
const offsetX = state.x * MM_TO_WORLD;
const offsetZ = -state.y * MM_TO_WORLD;
plateMotion.position.set(offsetX, 2.205, 0.2 + offsetZ);
plateMotion.rotation.y = angle;
resultMotion.position.set(offsetX, 0.15, offsetZ);
resultMotion.rotation.y = angle;
paperPrinted.position.set(offsetX, 0.075, offsetZ);
paperPrinted.rotation.y = angle;
materials.ink.opacity = state.coverage / 100;
resultMotion.visible = state.coverage > 0;
paperPrinted.visible = paperPrinted.visible && state.coverage > 0;
resultGhost.visible = state.overlay;
elements.xValue.textContent = `${signed(state.x)} mm`;
elements.yValue.textContent = `${signed(state.y)} mm`;
elements.angleValue.textContent = `${signed(state.angle)}°`;
elements.coverageValue.textContent = `${state.coverage}%`;
const offsetMagnitude = Math.hypot(state.x, state.y);
const overlap = computeCellOverlap();
elements.metricOffset.textContent = offsetMagnitude.toFixed(1);
elements.metricAngle.textContent = `${signed(state.angle)}°`;
elements.metricOverlap.textContent = `${overlap}%`;
elements.metricCoverage.textContent = `${state.coverage}%`;
drawMiniPreview(elements.targetPreview, false);
drawMiniPreview(elements.resultPreview, true);
}
[elements.x, elements.y, elements.angle, elements.coverage].forEach(
(input) => input.addEventListener("input", updateScene)
);
elements.overlay.addEventListener("change", updateScene);
document.querySelector("#center").addEventListener("click", () => {
elements.x.value = "0";
elements.y.value = "0";
elements.angle.value = "0";
updateScene();
elements.status.textContent = "Matrix centered on the fixed registration marks.";
});
let pressElapsed = null;
function smoothstep(value) {
const t = THREE.MathUtils.clamp(value, 0, 1);
return t * t * (3 - 2 * t);
}
elements.print.addEventListener("click", () => {
pressElapsed = 0;
elements.print.disabled = true;
elements.status.textContent = "Platen descending…";
printSheet.position.z = 0.3;
paperPrinted.visible = false;
});
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (pressElapsed !== null) {
pressElapsed += delta;
let pressAmount = 0;
if (pressElapsed < 0.44) {
pressAmount = smoothstep(pressElapsed / 0.44);
} else if (pressElapsed < 0.66) {
pressAmount = 1;
} else if (pressElapsed < 1.08) {
pressAmount = 1 - smoothstep((pressElapsed - 0.66) / 0.42);
}
platen.position.y = THREE.MathUtils.lerp(4.04, 2.47, pressAmount);
if (pressElapsed > 0.66) {
const slide = smoothstep((pressElapsed - 0.66) / 0.42);
printSheet.position.z = THREE.MathUtils.lerp(0.3, 2.85, slide);
}
if (pressElapsed >= 1.08) {
pressElapsed = null;
platen.position.y = 4.04;
printSheet.position.z = 2.85;
paperPrinted.visible = state.coverage > 0;
elements.print.disabled = false;
elements.status.textContent =
"Impression complete. Compare the readable result with the fixed target.";
} else if (pressElapsed > 0.44 && pressElapsed <= 0.66) {
elements.status.textContent = "Plate contact — recording controlled ink coverage.";
} else if (pressElapsed > 0.66) {
elements.status.textContent = "Platen lifting — advancing the printed sheet.";
}
}
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
window.addEventListener("resize", () => {
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
});
updateScene();
animate();
</script>
</body>
</html>
```