Prompt specification
Build or customize the Three.js 3D scene "Trace one geometric diagram across copies" 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: Trace one geometric diagram across copies
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/trace-one-geometric-diagram-across-copies-x2328
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing Abbasid Baghdad's translation and copying workshops. Let users compare successive copies of an illustrative geometric diagram. Highlight a misplaced line and show how checking against a reference can preserve the intended relationship. Voxel style.
Working Three.js Starter (trace-one-geometric-diagram-across-copies-x2328):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Abbasid Baghdad — Geometry Across Copies</title>
<style>
:root {
--ink: #13282d;
--deep: #0c1820;
--panel: rgba(13, 28, 35, 0.9);
--line: rgba(218, 196, 145, 0.22);
--parchment: #ead9ad;
--muted: #aebbb8;
--gold: #d6a65a;
--mint: #70d5b3;
--orange: #f0784e;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--deep);
color: var(--parchment);
font-family: "Trebuchet MS", "Segoe UI", sans-serif;
}
button, input { font: inherit; }
#app, #scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active { cursor: grabbing; }
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 43%, transparent 32%, rgba(4, 11, 16, 0.28) 75%, rgba(4, 11, 16, 0.72) 100%);
z-index: 2;
}
header {
position: fixed;
z-index: 5;
top: 24px;
left: 28px;
max-width: 520px;
pointer-events: none;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.8);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
color: var(--gold);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 24px;
height: 4px;
background: var(--gold);
box-shadow: 7px 0 0 rgba(214, 166, 90, 0.35);
}
h1 {
margin: 9px 0 7px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(29px, 3.2vw, 48px);
font-weight: 500;
line-height: 1.02;
letter-spacing: -0.035em;
}
header p {
max-width: 450px;
margin: 0;
color: #c4ceca;
font-size: 13px;
line-height: 1.55;
}
.interpretive {
display: inline-block;
margin-top: 10px;
padding: 5px 8px;
border: 1px solid rgba(214, 166, 90, 0.35);
color: #c9b78f;
font-size: 9px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.controls {
position: fixed;
z-index: 6;
top: 188px;
left: 28px;
width: 300px;
padding: 17px;
border: 1px solid var(--line);
border-radius: 3px;
background: linear-gradient(145deg, rgba(17, 36, 43, 0.94), rgba(9, 21, 28, 0.9));
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.36);
backdrop-filter: blur(14px);
}
.controls::before,
.story::before {
content: "";
position: absolute;
top: -1px;
left: -1px;
width: 28px;
height: 4px;
background: var(--gold);
}
.control-label {
margin-bottom: 9px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.tabs {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 5px;
margin-bottom: 15px;
}
.tabs button {
min-width: 0;
padding: 9px 4px;
border: 1px solid rgba(234, 217, 173, 0.15);
border-radius: 2px;
background: rgba(255, 255, 255, 0.035);
color: #aab8b6;
font-size: 10px;
font-weight: 800;
cursor: pointer;
transition: 160ms ease;
}
.tabs button:hover {
border-color: rgba(214, 166, 90, 0.55);
color: var(--parchment);
}
.tabs button.active {
border-color: var(--gold);
background: rgba(214, 166, 90, 0.14);
color: #f0dba8;
}
.switch-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 11px 0;
border-top: 1px solid rgba(234, 217, 173, 0.1);
color: #c4ceca;
font-size: 12px;
}
.switch {
position: relative;
width: 39px;
height: 21px;
flex: 0 0 auto;
}
.switch input {
position: absolute;
opacity: 0;
}
.switch span {
position: absolute;
inset: 0;
border: 1px solid rgba(234, 217, 173, 0.25);
border-radius: 20px;
background: #17252b;
cursor: pointer;
transition: 180ms ease;
}
.switch span::after {
content: "";
position: absolute;
top: 3px;
left: 3px;
width: 13px;
height: 13px;
border-radius: 50%;
background: #84928f;
transition: 180ms ease;
}
.switch input:checked + span {
border-color: rgba(240, 120, 78, 0.7);
background: rgba(240, 120, 78, 0.18);
}
.switch input:checked + span::after {
transform: translateX(18px);
background: var(--orange);
box-shadow: 0 0 12px rgba(240, 120, 78, 0.65);
}
.primary {
width: 100%;
margin-top: 5px;
padding: 12px 13px;
border: 1px solid var(--gold);
border-radius: 2px;
background: linear-gradient(135deg, rgba(214, 166, 90, 0.22), rgba(214, 166, 90, 0.08));
color: #f3dfb5;
font-size: 11px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition: 180ms ease;
}
.primary:hover {
background: rgba(214, 166, 90, 0.27);
transform: translateY(-1px);
}
.primary.consulted {
border-color: var(--mint);
background: rgba(112, 213, 179, 0.13);
color: #a8ebd5;
}
.lineage {
display: grid;
gap: 9px;
margin-top: 17px;
padding-top: 14px;
border-top: 1px solid rgba(234, 217, 173, 0.1);
}
.lineage-step {
display: grid;
grid-template-columns: 24px 1fr;
gap: 9px;
align-items: start;
color: #899895;
font-size: 10px;
line-height: 1.35;
}
.lineage-step b {
display: grid;
place-items: center;
width: 22px;
height: 22px;
border: 1px solid rgba(234, 217, 173, 0.18);
color: #aebbb8;
font-size: 9px;
}
.lineage-step strong {
display: block;
margin-bottom: 2px;
color: #c8d0cc;
font-size: 10px;
letter-spacing: 0.04em;
}
.lineage-step.active b {
border-color: var(--gold);
color: var(--gold);
}
.lineage-step.correct b {
border-color: var(--mint);
color: var(--mint);
}
.hint {
margin-top: 14px;
color: #778784;
font-size: 9px;
line-height: 1.45;
}
.object-label {
position: fixed;
z-index: 4;
left: 0;
top: 0;
transform: translate(-50%, -50%);
padding: 6px 9px;
border-left: 3px solid var(--gold);
background: rgba(8, 18, 24, 0.84);
color: #e7d8b5;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.13em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
box-shadow: 0 7px 22px rgba(0, 0, 0, 0.3);
transition: opacity 200ms ease;
}
.object-label.ref {
border-left-color: var(--mint);
color: #b9e8d9;
}
.object-label.copy2 {
border-left-color: #6da99a;
}
.story {
position: fixed;
z-index: 6;
left: 50%;
bottom: 22px;
width: min(760px, calc(100vw - 48px));
min-height: 92px;
padding: 17px 20px 16px;
transform: translateX(-50%);
border: 1px solid var(--line);
border-radius: 3px;
background: linear-gradient(120deg, rgba(11, 25, 32, 0.94), rgba(16, 33, 40, 0.88));
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.4);
backdrop-filter: blur(12px);
}
.story-top {
display: flex;
justify-content: space-between;
gap: 20px;
margin-bottom: 7px;
}
#story-title {
color: var(--gold);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.14em;
text-transform: uppercase;
}
#story-status {
color: #83918e;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
white-space: nowrap;
}
#story-copy {
margin: 0;
color: #d5d8cc;
font-family: Georgia, "Times New Roman", serif;
font-size: 15px;
line-height: 1.45;
}
#story-copy .orange { color: #ff9a75; }
#story-copy .mint { color: #8ce2c3; }
#story-copy .gold { color: #e5bd76; }
.legend {
position: fixed;
z-index: 5;
right: 24px;
bottom: 24px;
display: grid;
gap: 7px;
padding: 12px 14px;
border: 1px solid rgba(234, 217, 173, 0.13);
background: rgba(8, 18, 24, 0.74);
color: #a8b3af;
font-size: 9px;
pointer-events: none;
}
.legend div {
display: flex;
align-items: center;
gap: 8px;
}
.swatch {
width: 17px;
height: 7px;
background: var(--gold);
box-shadow: 0 0 7px rgba(214, 166, 90, 0.35);
}
.swatch.orange { background: var(--orange); }
.swatch.mint { background: var(--mint); }
.swatch.ink { background: #496765; }
#loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
background: #0c1820;
color: var(--parchment);
transition: opacity 600ms ease, visibility 600ms ease;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
.loading-box {
width: 230px;
text-align: center;
}
.loading-box .blocks {
display: flex;
justify-content: center;
gap: 5px;
margin-bottom: 16px;
}
.loading-box .blocks i {
width: 12px;
height: 12px;
background: var(--gold);
animation: load 900ms infinite ease-in-out;
}
.loading-box .blocks i:nth-child(2) { animation-delay: 120ms; }
.loading-box .blocks i:nth-child(3) { animation-delay: 240ms; }
.loading-box p {
margin: 0;
color: #aab7b3;
font-size: 10px;
letter-spacing: 0.15em;
text-transform: uppercase;
}
@keyframes load {
0%, 100% { transform: translateY(0); opacity: 0.4; }
50% { transform: translateY(-8px); opacity: 1; }
}
@media (max-width: 900px) {
header {
top: 17px;
left: 18px;
}
header p, .interpretive {
display: none;
}
.controls {
top: 92px;
left: 14px;
width: 270px;
padding: 13px;
}
.lineage, .hint {
display: none;
}
.legend {
display: none;
}
.story {
bottom: 12px;
width: calc(100vw - 24px);
}
}
@media (max-width: 560px) {
.controls {
top: auto;
right: 12px;
bottom: 134px;
width: auto;
}
.control-label, .switch-row {
display: none;
}
.tabs {
margin-bottom: 0;
}
.primary {
margin-top: 8px;
padding: 9px;
}
header h1 {
max-width: 300px;
font-size: 28px;
}
.object-label {
display: none;
}
.story {
min-height: 105px;
padding: 13px 15px;
}
#story-copy {
font-size: 13px;
}
}
</style>
</head>
<body>
<main id="app">
<div id="scene" aria-label="Interactive 3D comparison of successive manuscript copies"></div>
<div class="vignette"></div>
<header>
<div class="eyebrow">Baghdad · House of Wisdom · c. 9th century</div>
<h1>One diagram, two copies</h1>
<p>
Enter an imagined Abbasid translation and copying workshop. Compare a
geometric construction, expose a shifted line, and use an exemplar to
restore the intended relationship.
</p>
<span class="interpretive">Interpretive reconstruction · not a facsimile</span>
</header>
<aside class="controls" aria-label="Manuscript controls">
<div class="control-label">Choose a folio</div>
<div class="tabs" role="tablist" aria-label="Manuscript views">
<button class="active" data-view="compare" aria-selected="true">Both</button>
<button data-view="copy1" aria-selected="false">Copy I</button>
<button data-view="copy2" aria-selected="false">Copy II</button>
<button data-view="reference" aria-selected="false">Reference</button>
</div>
<label class="switch-row">
<span>Highlight the misplaced line</span>
<span class="switch">
<input id="highlight" type="checkbox" checked />
<span aria-hidden="true"></span>
</span>
</label>
<button id="consult" class="primary">Consult the reference</button>
<div class="lineage" aria-label="Copying sequence">
<div class="lineage-step active" id="step-one">
<b>01</b>
<div><strong>Copy I</strong>The diagonal is shifted inward by one grid module.</div>
</div>
<div class="lineage-step" id="step-check">
<b>02</b>
<div><strong>Collation</strong>The exemplar confirms that AC joins opposite corners.</div>
</div>
<div class="lineage-step" id="step-two">
<b>03</b>
<div><strong>Copy II</strong>The corrected line preserves the square's symmetry.</div>
</div>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Select a tablet to inspect it</div>
</aside>
<div id="label-copy1" class="object-label">Copy I · unchecked</div>
<div id="label-copy2" class="object-label copy2">Copy II · corrected</div>
<div id="label-reference" class="object-label ref">Reference exemplar</div>
<section class="story" aria-live="polite">
<div class="story-top">
<span id="story-title">Successive copies</span>
<span id="story-status">Geometric diagram · square ABCD</span>
</div>
<p id="story-copy">
The orange diagonal in Copy I does not meet opposite vertices A and C.
In Copy II, the line has been checked and restored to the intended axis.
</p>
</section>
<aside class="legend" aria-label="Diagram legend">
<div><span class="swatch"></span> Reference construction</div>
<div><span class="swatch orange"></span> Misplaced line</div>
<div><span class="swatch mint"></span> Corrected relationship</div>
<div><span class="swatch ink"></span> Shared square geometry</div>
</aside>
<div id="loading">
<div class="loading-box">
<div class="blocks"><i></i><i></i><i></i></div>
<p>Assembling the workshop</p>
</div>
</div>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x101b24);
scene.fog = new THREE.FogExp2(0x101b24, 0.028);
const camera = new THREE.PerspectiveCamera(42, innerWidth / innerHeight, 0.1, 90);
const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: "high-performance" });
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.8));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
sceneHost.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xffefd0, 0x18303a, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe0aa, 3.2);
sun.position.set(-7, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -16;
sun.shadow.camera.right = 16;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.00035;
scene.add(sun);
const coolFill = new THREE.DirectionalLight(0x78b9c3, 1.1);
coolFill.position.set(8, 6, 4);
scene.add(coolFill);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const matrix = new THREE.Matrix4();
const quaternion = new THREE.Quaternion();
const tempPosition = new THREE.Vector3();
const tempScale = new THREE.Vector3();
function voxelColor(value) {
return value instanceof THREE.Color ? value : new THREE.Color(value);
}
class VoxelBatch {
constructor() {
this.blocks = [];
}
add(x, y, z, sx, sy, sz, color) {
this.blocks.push({
x, y, z, sx, sy, sz,
color: voxelColor(color)
});
}
build(parent, castShadow = true, receiveShadow = true) {
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.92,
metalness: 0.02
});
const mesh = new THREE.InstancedMesh(geometry, material, this.blocks.length);
this.blocks.forEach((block, i) => {
tempPosition.set(block.x, block.y, block.z);
tempScale.set(block.sx, block.sy, block.sz);
matrix.compose(tempPosition, quaternion, tempScale);
mesh.setMatrixAt(i, matrix);
mesh.setColorAt(i, block.color);
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
}
// Voxel palace, courtyard, plinths, and patterned floor.
const architecture = new VoxelBatch();
const sand = [0xb48658, 0xc29565, 0xa9784e, 0xd0a572, 0x9c6f4c];
const coolSand = [0x9f8060, 0xb1906d, 0x8e7258];
for (let x = -12; x <= 12; x++) {
for (let z = -9; z <= 8; z++) {
const path = Math.abs(x) <= 2 && z > -6;
const stage = Math.abs(x) <= 7 && Math.abs(z - 1) <= 2;
let color;
if (path) color = new THREE.Color(0x4d7775).multiplyScalar(0.75 + ((x + z) % 3) * 0.05);
else if (stage) color = new THREE.Color(0x766a53);
else color = new THREE.Color(sand[(x * 7 + z * 3 + 40) % sand.length]);
architecture.add(x, -0.26, z, 0.98, 0.28, 0.98, color);
}
}
// Stepped central arch and rear wall.
for (let x = -11; x <= 11; x++) {
const ax = Math.abs(x);
const openingHeight = ax < 1 ? 4.35 : ax < 2 ? 3.65 : 0;
for (let y = 0; y < 7; y++) {
if (y < openingHeight) continue;
const edge = y < openingHeight + 1 && openingHeight > 0;
const color = edge ? 0xd0a36b : sand[(x + y * 2 + 25) % sand.length];
architecture.add(x, y + 0.25, -6.5, 0.98, 0.98, 0.72, color);
}
}
// Flanking voxel towers.
for (const side of [-1, 1]) {
const towerX = side * 9.2;
for (let x = -1; x <= 1; x++) {
for (let y = 0; y < 9; y++) {
for (let z = -1; z <= 1; z++) {
const windowOpening =
y > 3 && y < 6 &&
(Math.abs(x) === 1 || z === 1) &&
!(Math.abs(x) === 1 && z === 0);
if (windowOpening) continue;
const color = coolSand[(x + y + z + 10) % coolSand.length];
architecture.add(towerX + x * 0.98, y + 0.28, -5.55 + z * 0.9, 0.94, 0.94, 0.86, color);
}
}
}
for (let x = -2; x <= 2; x++) {
architecture.add(towerX + x * 0.98, 9.25, -5.55, 0.92, 0.65, 2.5, 0xc29a68);
}
}
// Central battlement.
for (let x = -5; x <= 5; x++) {
if (x % 2 === 0) {
architecture.add(x, 7.45, -6.5, 0.82, 0.72, 0.85, 0xc69d6b);
}
}
// Exhibit plinths and reference shelf.
for (const x of [-3.15, 3.15]) {
architecture.add(x, 0.3, 1.2, 4.85, 0.55, 1.35, 0x675c49);
architecture.add(x, 0.59, 1.2, 4.45, 0.12, 1.05, 0x9b805b);
architecture.add(x, 0.68, 1.38, 3.95, 0.10, 0.15, 0xd0aa6d);
}
architecture.add(0, 4.56, -2.7, 3.65, 0.18, 1.05, 0x79674e);
architecture.build(scene);
// Warm lanterns built from cubes.
function makeLantern(x, y, z) {
const group = new THREE.Group();
const frameMat = new THREE.MeshStandardMaterial({ color: 0x6c452a, roughness: 0.7 });
const glowMat = new THREE.MeshBasicMaterial({ color: 0xffc96c });
const top = new THREE.Mesh(unitBox, frameMat);
top.scale.set(0.48, 0.10, 0.48);
top.position.y = 0.45;
group.add(top);
const bottom = top.clone();
bottom.position.y = -0.45;
group.add(bottom);
for (const px of [-0.18, 0.18]) {
for (const pz of [-0.18, 0.18]) {
const post = new THREE.Mesh(unitBox, frameMat);
post.scale.set(0.055, 0.83, 0.055);
post.position.set(px, 0, pz);
group.add(post);
}
}
const glow = new THREE.Mesh(unitBox, glowMat);
glow.scale.set(0.22, 0.50, 0.22);
group.add(glow);
const light = new THREE.PointLight(0xffb95c, 12, 6, 2);
light.position.y = 0;
group.add(light);
group.position.set(x, y, z);
scene.add(group);
}
makeLantern(-5.35, 3.8, 0.3);
makeLantern(5.35, 3.8, 0.3);
// Floating dust motes.
const dustCount = 260;
const dustPositions = new Float32Array(dustCount * 3);
for (let i = 0; i < dustCount; i++) {
dustPositions[i * 3] = (Math.sin(i * 12.71) * 0.5 + 0.5) * 20 - 10;
dustPositions[i * 3 + 1] = (Math.sin(i * 7.13) * 0.5 + 0.5) * 8 + 0.4;
dustPositions[i * 3 + 2] = (Math.sin(i * 4.37) * 0.5 + 0.5) * 12 - 4;
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute("position", new THREE.BufferAttribute(dustPositions, 3));
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xe8c990,
size: 0.035,
transparent: true,
opacity: 0.42,
depthWrite: false
})
);
scene.add(dust);
function makePolyline(points, color, options = {}) {
const voxel = options.voxel ?? 0.095;
const opacity = options.opacity ?? 1;
const emissiveIntensity = options.emissiveIntensity ?? 0;
const positions = [];
const keys = new Set();
for (let s = 0; s < points.length - 1; s++) {
const a = points[s];
const b = points[s + 1];
const distance = Math.hypot(b.x - a.x, b.y - a.y);
const steps = Math.max(1, Math.ceil(distance / (voxel * 0.54)));
for (let i = 0; i <= steps; i++) {
const t = i / steps;
const grid = voxel * 0.5;
const x = Math.round((a.x + (b.x - a.x) * t) / grid) * grid;
const y = Math.round((a.y + (b.y - a.y) * t) / grid) * grid;
const key = `${x.toFixed(4)},${y.toFixed(4)}`;
if (!keys.has(key)) {
keys.add(key);
positions.push([x, y]);
}
}
}
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0.02,
transparent: true,
opacity,
depthWrite: opacity > 0.9,
depthTest: options.depthTest ?? true,
emissive: new THREE.Color(color),
emissiveIntensity
});
const mesh = new THREE.InstancedMesh(unitBox, material, positions.length);
positions.forEach(([x, y], i) => {
matrix.compose(
new THREE.Vector3(x, y, options.z ?? 0.36),
quaternion,
new THREE.Vector3(voxel * 0.96, voxel * 0.96, voxel * 0.72)
);
mesh.setMatrixAt(i, matrix);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.renderOrder = options.renderOrder ?? 0;
return { mesh, material };
}
function makeLabelSprite(letter, color = "#26464a") {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.beginPath();
ctx.arc(64, 64, 51, 0, Math.PI * 2);
ctx.fillStyle = "#ead8a9";
ctx.fill();
ctx.lineWidth = 8;
ctx.strokeStyle = color;
ctx.stroke();
ctx.fillStyle = color;
ctx.font = "bold 58px Georgia";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(letter, 64, 67);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(0.39, 0.39, 1);
sprite.renderOrder = 20;
return sprite;
}
function makeTargetMarker(color, z = 0.49) {
const group = new THREE.Group();
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.9,
depthTest: false,
depthWrite: false
});
const offsets = [
[-0.12, -0.12], [0.12, -0.12],
[-0.12, 0.12], [0.12, 0.12]
];
offsets.forEach(([x, y]) => {
const cube = new THREE.Mesh(unitBox, material);
cube.scale.set(0.07, 0.07, 0.07);
cube.position.set(x, y, z);
group.add(cube);
});
group.userData.material = material;
group.visible = false;
group.renderOrder = 15;
return group;
}
function makeTablet(kind) {
const group = new THREE.Group();
const isReference = kind === "reference";
const isCopy1 = kind === "copy1";
const panelColors = {
copy1: 0xd2b77f,
copy2: 0xc9c69a,
reference: 0xd8c69d
};
const panelMaterial = new THREE.MeshStandardMaterial({
color: panelColors[kind],
roughness: 0.93,
metalness: 0
});
const panel = new THREE.Mesh(new THREE.BoxGeometry(4.35, 4.35, 0.34), panelMaterial);
panel.castShadow = true;
panel.receiveShadow = true;
panel.userData.view = kind;
group.add(panel);
// Pixel-brick frame.
const frame = new VoxelBatch();
const frameColor = isReference ? 0x7b6749 : (isCopy1 ? 0x785a39 : 0x526b62);
for (let i = 0; i < 17; i++) {
const p = -2.04 + i * 0.255;
frame.add(p, 2.06, 0.23, 0.235, 0.20, 0.16, frameColor);
frame.add(p, -2.06, 0.23, 0.235, 0.20, 0.16, frameColor);
frame.add(2.06, p, 0.23, 0.20, 0.235, 0.16, frameColor);
frame.add(-2.06, p, 0.23, 0.20, 0.235, 0.16, frameColor);
}
frame.build(group);
const square = [
{ x: -1.45, y: 1.45 },
{ x: 1.45, y: 1.45 },
{ x: 1.45, y: -1.45 },
{ x: -1.45, y: -1.45 },
{ x: -1.45, y: 1.45 }
];
makePolyline(square, 0x355957, { voxel: 0.095, z: 0.38 });
const circle = [];
for (let i = 0; i <= 32; i++) {
const angle = (i / 32) * Math.PI * 2;
circle.push({
x: Math.cos(angle) * 1.34,
y: Math.sin(angle) * 1.34
});
}
makePolyline(circle, 0x7d927d, {
voxel: 0.068,
opacity: 0.56,
z: 0.39
});
let errorMaterial = null;
let correctMaterial = null;
let ghostMaterial = null;
const targetMarkers = [];
const wrongMarker = null;
if (isCopy1) {
const wrong = [
{ x: -1.08, y: 1.08 },
{ x: 1.08, y: -1.08 }
];
const errorLine = makePolyline(wrong, 0xef7047, {
voxel: 0.115,
emissiveIntensity: 0.52,
z: 0.48
});
group.add(errorLine.mesh);
errorMaterial = errorLine.material;
const intended = [
{ x: -1.45, y: 1.45 },
{ x: 1.45, y: -1.45 }
];
const ghost = makePolyline(intended, 0x71e0ba, {
voxel: 0.12,
opacity: 0,
emissiveIntensity: 0.75,
z: 0.53,
depthTest: false,
renderOrder: 12
});
group.add(ghost.mesh);
ghostMaterial = ghost.material;
const aMarker = makeTargetMarker(0x70dfb9);
aMarker.position.set(-1.45, 1.45, 0);
group.add(aMarker);
targetMarkers.push(aMarker);
const cMarker = makeTargetMarker(0x70dfb9);
cMarker.position.set(1.45, -1.45, 0);
group.add(cMarker);
targetMarkers.push(cMarker);
const wrongEnd = makeTargetMarker(0xef7047, 0.57);
wrongEnd.position.set(1.08, -1.08, 0);
group.add(wrongEnd);
} else {
const intended = [
{ x: -1.45, y: 1.45 },
{ x: 1.45, y: -1.45 }
];
const color = isReference ? 0xd69d4f : 0x287d70;
const line = makePolyline(intended, color, {
voxel: 0.115,
emissiveIntensity: isReference ? 0.18 : 0.10,
z: 0.48
});
group.add(line.mesh);
correctMaterial = line.material;
}
// A small central construction mark.
const center = makePolyline([
{ x: -0.10, y: -0.10 },
{ x: 0.10, y: -0.10 },
{ x: 0.10, y: 0.10 },
{ x: -0.10, y: 0.10 },
{ x: -0.10, y: -0.10 }
], 0x355957, { voxel: 0.07, z: 0.43 });
group.add(center.mesh);
const labelPositions = {
A: [-1.58, 1.58],
B: [1.58, 1.58],
C: [1.58, -1.58],
D: [-1.58, -1.58]
};
Object.entries(labelPositions).forEach(([letter, [x, y]]) => {
const sprite = makeLabelSprite(letter);
sprite.position.set(x, y, 0.56);
group.add(sprite);
});
return {
group,
panel,
errorMaterial,
correctMaterial,
ghostMaterial,
targetMarkers,
wrongMarker
};
}
const copy1 = makeTablet("copy1");
const copy2 = makeTablet("copy2");
const reference = makeTablet("reference");
copy1.group.position.set(-3.15, 2.72, 1.2);
copy2.group.position.set(3.15, 2.72, 1.2);
reference.group.position.set(0, 6.12, -2.7);
reference.group.scale.setScalar(0.72);
scene.add(copy1.group, copy2.group, reference.group);
// Custom camera controls; no addons are used.
const orbit = { yaw: 0.035, pitch: 0.27 };
const cameraTarget = new THREE.Vector3(0, 2.85, 0);
const desiredTarget = cameraTarget.clone();
let desiredRadius = innerWidth < 700 ? 17.0 : 14.4;
let cameraRadius = desiredRadius;
const viewSettings = {
compare: { target: new THREE.Vector3(0, 2.85, 0), radius: innerWidth < 700 ? 17.0 : 14.4 },
copy1: { target: new THREE.Vector3(-3.15, 2.72, 1.2), radius: innerWidth < 700 ? 11.5 : 8.2 },
copy2: { target: new THREE.Vector3(3.15, 2.72, 1.2), radius: innerWidth < 700 ? 11.5 : 8.2 },
reference: { target: new THREE.Vector3(0, 6.05, -2.7), radius: innerWidth < 700 ? 10.5 : 7.2 }
};
let currentView = "compare";
let checkActive = false;
let highlightActive = true;
let ghostOpacity = 0;
let targetOpacity = 0;
const tabs = [...document.querySelectorAll(".tabs button")];
const consultButton = document.getElementById("consult");
const highlightInput = document.getElementById("highlight");
const storyTitle = document.getElementById("story-title");
const storyCopy = document.getElementById("story-copy");
const storyStatus = document.getElementById("story-status");
const stepOne = document.getElementById("step-one");
const stepCheck = document.getElementById("step-check");
const stepTwo = document.getElementById("step-two");
function updateStory() {
stepOne.classList.toggle("active", !checkActive && currentView !== "copy2");
stepCheck.classList.toggle("active", checkActive);
stepTwo.classList.toggle("active", currentView === "copy2" || currentView === "compare");
if (checkActive) {
storyTitle.textContent = "Collation finding";
storyStatus.textContent = "Reference consulted";
storyCopy.innerHTML =
'The exemplar confirms that diagonal <span class="gold">AC must join opposite vertices</span>. ' +
'The mint guide exposes the intended axis; Copy I’s <span class="orange">orange line sits one grid module inward</span>.';
} else if (currentView === "copy1") {
storyTitle.textContent = "Copy I · unchecked";
storyStatus.textContent = "Discrepancy visible";
storyCopy.innerHTML =
'The <span class="orange">orange diagonal</span> begins and ends away from A and C. ' +
'Its parallel offset breaks the square’s intended symmetry.';
} else if (currentView === "copy2") {
storyTitle.textContent = "Copy II · collated";
storyStatus.textContent = "Relationship preserved";
storyCopy.innerHTML =
'After comparison with the exemplar, the diagonal meets <span class="mint">A and C exactly</span>. ' +
'The corrected copy preserves the geometric relationship rather than merely its appearance.';
} else if (currentView === "reference") {
storyTitle.textContent = "Reference exemplar";
storyStatus.textContent = "The governing diagram";
storyCopy.innerHTML =
'The exemplar establishes the intended relationship: a single diagonal from <span class="gold">A to C</span>. ' +
'Copying could preserve it only when the new line was checked against this model.';
} else {
storyTitle.textContent = "Successive copies";
storyStatus.textContent = "Geometric diagram · square ABCD";
storyCopy.innerHTML =
'The <span class="orange">orange diagonal</span> in Copy I does not meet opposite vertices A and C. ' +
'In Copy II, the line has been checked and restored to the intended axis.';
}
}
function setView(view) {
currentView = view;
const setting = viewSettings[view];
desiredTarget.copy(setting.target);
desiredRadius = setting.radius;
tabs.forEach(button => {
const active = button.dataset.view === view;
button.classList.toggle("active", active);
button.setAttribute("aria-selected", String(active));
});
updateStory();
}
tabs.forEach(button => {
button.addEventListener("click", () => setView(button.dataset.view));
});
consultButton.addEventListener("click", () => {
checkActive = !checkActive;
consultButton.classList.toggle("consulted", checkActive);
consultButton.textContent = checkActive ? "Reference consulted ✓" : "Consult the reference";
if (checkActive) {
highlightInput.checked = true;
highlightActive = true;
}
updateStory();
});
highlightInput.addEventListener("change", () => {
highlightActive = highlightInput.checked;
});
// Raycast tablet selection.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = null;
let pointerMoved = false;
renderer.domElement.addEventListener("pointerdown", event => {
pointerDown = { x: event.clientX, y: event.clientY };
pointerMoved = false;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointerDown) return;
const dx = event.clientX - pointerDown.x;
const dy = event.clientY - pointerDown.y;
if (Math.abs(dx) + Math.abs(dy) > 4) pointerMoved = true;
orbit.yaw -= dx * 0.0045;
orbit.pitch = THREE.MathUtils.clamp(orbit.pitch + dy * 0.0035, 0.08, 0.67);
pointerDown.x = event.clientX;
pointerDown.y = event.clientY;
});
renderer.domElement.addEventListener("pointerup", event => {
if (pointerDown && !pointerMoved) {
pointer.x = (event.clientX / innerWidth) * 2 - 1;
pointer.y = -(event.clientY / innerHeight) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(
[copy1.panel, copy2.panel, reference.panel],
false
);
if (hits.length) setView(hits[0].object.userData.view);
}
pointerDown = null;
});
renderer.domElement.addEventListener("pointercancel", () => { pointerDown = null; });
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
desiredRadius = THREE.MathUtils.clamp(
desiredRadius + event.deltaY * 0.008,
currentView === "compare" ? 9.5 : 5.3,
21
);
}, { passive: false });
addEventListener("keydown", event => {
if (event.target instanceof HTMLInputElement) return;
if (event.code === "Space") {
event.preventDefault();
consultButton.click();
}
if (event.key === "ArrowLeft") setView(currentView === "copy2" ? "copy1" : "compare");
if (event.key === "ArrowRight") setView(currentView === "copy1" ? "copy2" : "compare");
});
// Projected HTML labels.
const labelCopy1 = document.getElementById("label-copy1");
const labelCopy2 = document.getElementById("label-copy2");
const labelReference = document.getElementById("label-reference");
const projected = new THREE.Vector3();
function placeLabel(element, object, localAnchor) {
projected.copy(localAnchor);
object.localToWorld(projected);
projected.project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
element.style.visibility = visible ? "visible" : "hidden";
}
function onResize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.8));
renderer.setSize(innerWidth, innerHeight);
const compact = innerWidth < 700;
viewSettings.compare.radius = compact ? 17 : 14.4;
viewSettings.copy1.radius = compact ? 11.5 : 8.2;
viewSettings.copy2.radius = compact ? 11.5 : 8.2;
viewSettings.reference.radius = compact ? 10.5 : 7.2;
if (currentView === "compare") desiredRadius = viewSettings.compare.radius;
}
addEventListener("resize", onResize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
const delta = Math.min(clock.getDelta(), 0.04);
// Smooth focus and orbit.
cameraTarget.lerp(desiredTarget, 1 - Math.pow(0.001, delta));
cameraRadius += (desiredRadius - cameraRadius) * 0.075;
const horizontal = Math.cos(orbit.pitch);
camera.position.set(
cameraTarget.x + cameraRadius * Math.sin(orbit.yaw) * horizontal,
cameraTarget.y + cameraRadius * Math.sin(orbit.pitch),
cameraTarget.z + cameraRadius * Math.cos(orbit.yaw) * horizontal
);
camera.lookAt(cameraTarget);
// Highlight behavior.
if (copy1.errorMaterial) {
copy1.errorMaterial.emissiveIntensity = highlightActive
? 0.52 + Math.sin(time * 4.2) * 0.12
: 0.025;
copy1.errorMaterial.opacity = highlightActive ? 1 : 0.48;
}
// Collation overlay.
const desiredGhost = checkActive ? 0.88 : 0;
const desiredTargetOpacity = checkActive ? 0.95 : 0;
ghostOpacity += (desiredGhost - ghostOpacity) * 0.075;
targetOpacity += (desiredTargetOpacity - targetOpacity) * 0.075;
if (copy1.ghostMaterial) {
copy1.ghostMaterial.opacity = ghostOpacity;
copy1.ghostMaterial.emissiveIntensity = 0.55 + Math.sin(time * 3.5) * 0.16;
copy1.ghostMaterial.visible = ghostOpacity > 0.008;
}
copy1.targetMarkers.forEach(marker => {
marker.visible = targetOpacity > 0.01;
marker.userData.material.opacity = targetOpacity;
const pulse = 1 + Math.sin(time * 4.5) * 0.12;
marker.scale.setScalar(pulse);
});
// Corrected copy has a quiet living shimmer.
if (copy2.correctMaterial) {
copy2.correctMaterial.emissiveIntensity = 0.10 + Math.sin(time * 2.1) * 0.035;
}
if (reference.correctMaterial) {
reference.correctMaterial.emissiveIntensity = checkActive
? 0.58 + Math.sin(time * 3.2) * 0.13
: 0.16;
}
// Reference becomes slightly more prominent during consultation.
const desiredScale = 0.72 * (checkActive ? 1.07 : 1);
reference.group.scale.lerp(
new THREE.Vector3(desiredScale, desiredScale, desiredScale),
0.045
);
// Dust rises and wraps around the workshop.
const positions = dustGeometry.attributes.position.array;
for (let i = 0; i < dustCount; i++) {
positions[i * 3 + 1] += delta * (0.035 + (i % 5) * 0.007);
positions[i * 3] += Math.sin(time * 0.35 + i) * delta * 0.004;
if (positions[i * 3 + 1] > 8.5) positions[i * 3 + 1] = 0.4;
}
dustGeometry.attributes.position.needsUpdate = true;
placeLabel(labelCopy1, copy1.group, new THREE.Vector3(0, -2.47, 0.3));
placeLabel(labelCopy2, copy2.group, new THREE.Vector3(0, -2.47, 0.3));
placeLabel(labelReference, reference.group, new THREE.Vector3(0, 1.72, 0.25));
labelCopy1.style.opacity = (currentView === "compare" || currentView === "copy1") ? "1" : "0";
labelCopy2.style.opacity = (currentView === "compare" || currentView === "copy2") ? "1" : "0";
labelReference.style.opacity = (currentView === "compare" || currentView === "reference") ? "1" : "0.45";
renderer.render(scene, camera);
}
updateStory();
animate();
requestAnimationFrame(() => {
setTimeout(() => document.getElementById("loading").classList.add("hidden"), 250);
});
</script>
</body>
</html>
```