Prompt specification
Build or customize the Three.js 3D scene "Courtyard Mosaic Restoration Study" 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: Courtyard Mosaic Restoration Study
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/courtyard-mosaic-restoration-study-x3307
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a fictional courtyard with intact and missing mosaic regions. Distinguish evidence-supported repeats from speculative infill using removable transparent placeholders. Voxel style.
Working Three.js Starter (courtyard-mosaic-restoration-study-x3307):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>The Asteria Court — Voxel Mosaic Reconstruction</title>
<style>
:root {
color-scheme: light;
--ink: #263238;
--muted: #667177;
--paper: rgba(249, 246, 237, 0.9);
--line: rgba(38, 50, 56, 0.14);
--evidence: #38cbd1;
--hypothesis: #f2a83b;
--shadow: 0 14px 40px rgba(54, 45, 32, 0.14);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
background:
radial-gradient(circle at 50% 18%, #fffaf0 0, #eee5d3 48%, #d7cbb6 100%);
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 3;
}
.card {
pointer-events: auto;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.75);
box-shadow: var(--shadow);
backdrop-filter: blur(14px) saturate(1.1);
-webkit-backdrop-filter: blur(14px) saturate(1.1);
}
#title-card {
position: absolute;
top: 22px;
left: 22px;
width: min(420px, calc(100vw - 44px));
padding: 18px 20px 16px;
border-radius: 18px;
}
.eyebrow {
margin-bottom: 7px;
color: #927344;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 3vw, 35px);
font-weight: 500;
line-height: 1.05;
letter-spacing: -0.025em;
}
#title-card p {
margin: 10px 0 0;
max-width: 360px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
#layer-card {
position: absolute;
top: 22px;
right: 22px;
width: 292px;
padding: 16px;
border-radius: 18px;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.panel-heading span:last-child {
color: #9b8663;
font-size: 9px;
letter-spacing: 0.08em;
}
.layer {
display: grid;
grid-template-columns: 17px 13px 1fr auto;
align-items: center;
gap: 8px;
min-height: 39px;
border-top: 1px solid var(--line);
font-size: 12px;
cursor: pointer;
}
.layer input {
width: 15px;
height: 15px;
margin: 0;
accent-color: #394c51;
}
.swatch {
width: 12px;
height: 12px;
border-radius: 3px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.swatch.intact {
background:
linear-gradient(90deg, #243d52 50%, #c15c47 50%),
#d9cbaa;
}
.swatch.evidence { background: rgba(56, 203, 209, 0.58); }
.swatch.hypothesis { background: rgba(242, 168, 59, 0.62); }
.layer b {
color: #7b8589;
font-size: 10px;
font-weight: 700;
}
.mini-button {
padding: 4px 7px;
border: 1px solid var(--line);
border-radius: 7px;
background: rgba(255,255,255,0.65);
color: #647075;
font: 700 9px/1.2 inherit;
cursor: pointer;
}
.mini-button:hover {
background: #fff;
color: #263238;
}
.tool-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
margin-top: 12px;
}
.button {
min-height: 34px;
padding: 8px 10px;
border: 1px solid rgba(38, 50, 56, 0.13);
border-radius: 9px;
background: rgba(255, 255, 255, 0.68);
color: #364348;
font: 700 10px/1.2 inherit;
cursor: pointer;
transition: transform 120ms ease, background 120ms ease;
}
.button:hover {
transform: translateY(-1px);
background: #fff;
}
.button.primary {
border-color: #35474c;
background: #35474c;
color: #fffdf6;
}
.button.primary:hover { background: #25373b; }
#inspect-card {
position: absolute;
left: 22px;
bottom: 22px;
width: min(370px, calc(100vw - 44px));
padding: 15px 17px;
border-radius: 16px;
}
#inspect-title {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 6px;
font-family: Georgia, "Times New Roman", serif;
font-size: 17px;
}
#inspect-title::before {
content: "";
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 2px;
background: #859197;
}
#inspect-text {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
#inspect-meta {
margin-top: 8px;
color: #927344;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
#camera-card {
position: absolute;
right: 22px;
bottom: 22px;
display: flex;
gap: 5px;
padding: 8px;
border-radius: 14px;
}
#camera-card button {
width: 36px;
height: 34px;
padding: 0;
border: 0;
border-radius: 8px;
background: transparent;
color: #435156;
font: 700 16px/1 inherit;
cursor: pointer;
}
#camera-card button:hover { background: rgba(38,50,56,0.08); }
#camera-card button.wide { width: auto; padding: 0 11px; font-size: 10px; }
#hint {
position: absolute;
left: 50%;
bottom: 25px;
transform: translateX(-50%);
padding: 7px 11px;
border-radius: 999px;
background: rgba(248,245,236,0.72);
color: #707a7e;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
white-space: nowrap;
}
#labels {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.region-tag {
position: absolute;
transform: translate(-50%, -50%);
padding: 6px 9px;
border: 1px solid rgba(255,255,255,0.75);
border-radius: 8px;
box-shadow: 0 7px 18px rgba(45,40,30,0.13);
color: #fff;
font-size: 8px;
font-weight: 900;
letter-spacing: 0.11em;
text-transform: uppercase;
white-space: nowrap;
transition: opacity 160ms ease;
}
.region-tag.evidence { background: rgba(27, 132, 139, 0.88); }
.region-tag.hypothesis { background: rgba(164, 99, 20, 0.9); }
.region-tag::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 15px;
background: currentColor;
opacity: 0.55;
}
@media (max-width: 760px) {
#title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
#title-card p { display: none; }
#layer-card {
top: auto;
right: 12px;
bottom: 79px;
width: 245px;
padding: 12px;
}
#inspect-card {
left: 12px;
bottom: 12px;
width: calc(100vw - 281px);
min-width: 170px;
padding: 11px 12px;
}
#inspect-text { font-size: 10px; }
#inspect-meta { display: none; }
#camera-card {
right: 12px;
bottom: 12px;
}
#hint { display: none; }
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="labels" aria-hidden="true">
<div id="tag-a" class="region-tag evidence">A · Evidence-supported repeat</div>
<div id="tag-b" class="region-tag hypothesis">B · Speculative infill</div>
</div>
<main id="hud">
<header id="title-card" class="card">
<div class="eyebrow">Digital conservation study</div>
<h1>The Asteria Court</h1>
<p>
A fictional voxel courtyard reconstructed from surviving mosaic tesserae.
Translucent overlays are interpretive and can be removed cell by cell.
</p>
</header>
<aside id="layer-card" class="card">
<div class="panel-heading">
<span>Reconstruction layers</span>
<span id="surviving-total">— intact</span>
</div>
<label class="layer">
<input id="evidence-toggle" type="checkbox" checked>
<span class="swatch intact"></span>
<span>Surviving mosaic</span>
<b id="surviving-count">—</b>
</label>
<label class="layer">
<input id="hypothesis-toggle" type="checkbox" checked>
<span class="swatch evidence"></span>
<span>Evidence-supported repeats</span>
<b id="evidence-count">—</b>
</label>
<label class="layer">
<input id="speculation-toggle" type="checkbox" checked>
<span class="swatch hypothesis"></span>
<span>Speculative infill</span>
<b id="speculation-count">—</b>
</label>
<div class="tool-grid">
<button id="authentic-view" class="button">Authentic view</button>
<button id="undo" class="button">Undo removal</button>
<button id="clear-a" class="button">Clear repeat A</button>
<button id="clear-b" class="button">Clear infill B</button>
<button id="restore-all" class="button primary" style="grid-column: 1 / -1">
Restore all placeholders
</button>
</div>
</aside>
<section id="inspect-card" class="card" aria-live="polite">
<div id="inspect-title">Reconstruction key</div>
<p id="inspect-text">
Cyan cells repeat a pattern supported by the intact opposite quadrant.
Amber cells are hypothetical completions with no surviving parallel.
Click either overlay to remove it.
</p>
<div id="inspect-meta">Drag to orbit · Scroll to zoom · Click a cell to remove</div>
</section>
<nav id="camera-card" class="card" aria-label="Camera controls">
<button id="rotate-left" title="Rotate left" aria-label="Rotate left">↶</button>
<button id="zoom-out" title="Zoom out" aria-label="Zoom out">−</button>
<button id="zoom-in" title="Zoom in" aria-label="Zoom in">+</button>
<button id="rotate-right" title="Rotate right" aria-label="Rotate right">↷</button>
<button id="top-view" class="wide" title="Top-down view">Plan</button>
<button id="reset-view" class="wide" title="Reset camera">Reset</button>
</nav>
<div id="hint">Drag to orbit · Scroll to zoom · Click translucent mosaic cells</div>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Scene and renderer
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xe7ddc9, 42, 76);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
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.08;
renderer.domElement.setAttribute("aria-label", "Interactive voxel courtyard");
document.getElementById("scene").appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-16, 16, 16, -16, 0.1, 100);
const cameraState = {
yaw: 0.73,
pitch: 0.66,
zoom: 1,
target: new THREE.Vector3(0, 0.4, 0)
};
const hemisphere = new THREE.HemisphereLight(0xfff5df, 0x746a5c, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffedc9, 3.4);
sun.position.set(-12, 23, 14);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -22;
sun.shadow.camera.right = 22;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -22;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 60;
sun.shadow.bias = -0.0004;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x91bfd0, 0.65);
fill.position.set(18, 9, -12);
scene.add(fill);
// ---------------------------------------------------------------------
// Deterministic helpers and reusable voxel materials
// ---------------------------------------------------------------------
let randomSeed = 90817;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
const geometryCache = new Map();
const materialCache = new Map();
function boxGeometry(w, h, d) {
const key = `${w}|${h}|${d}`;
if (!geometryCache.has(key)) {
geometryCache.set(key, new THREE.BoxGeometry(w, h, d));
}
return geometryCache.get(key);
}
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0.015
})
);
}
return materialCache.get(color);
}
function block(w, h, d, x, y, z, color, castShadow = true) {
const mesh = new THREE.Mesh(boxGeometry(w, h, d), material(color));
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
// ---------------------------------------------------------------------
// Voxel courtyard architecture
// ---------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
new THREE.MeshStandardMaterial({
color: 0xd9cfba,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.72;
ground.receiveShadow = true;
scene.add(ground);
block(27, 0.7, 27, 0, -0.35, 0, 0xb8aa8e);
block(25.7, 0.12, 25.7, 0, -0.03, 0, 0xd5c7a8);
const stoneColors = [0xc9b996, 0xd3c4a3, 0xb9aa89, 0xd8c8a6, 0xc1af8c];
function wallBrick(w, h, d, x, y, z) {
const color = stoneColors[Math.floor(random() * stoneColors.length)];
const mesh = block(w, h, d, x, y, z, color);
mesh.rotation.y = (random() - 0.5) * 0.008;
return mesh;
}
// Rear wall with a central doorway.
for (let row = 0; row < 4; row++) {
const offset = row % 2 ? 0.9 : 0;
for (let x = -13.1 + offset; x < 13.1; x += 1.8) {
const doorway = Math.abs(x) < 2.7 && row < 3;
if (doorway) continue;
if (row === 3 && random() < 0.15) continue;
wallBrick(1.72, 0.72, 1.05, x, 0.38 + row * 0.77, -13.15);
}
}
// Side walls.
for (const side of [-1, 1]) {
for (let row = 0; row < 3; row++) {
const offset = row % 2 ? 0.9 : 0;
for (let z = -12.2 + offset; z < 12.4; z += 1.8) {
if (row === 2 && z > 7 && random() < 0.28) continue;
if (row === 2 && random() < 0.09) continue;
wallBrick(1.05, 0.72, 1.72, side * 13.15, 0.38 + row * 0.77, z);
}
}
}
// Low front wall, leaving an entrance.
for (let x = -12.8; x < 13; x += 1.8) {
if (Math.abs(x) < 2.7) continue;
wallBrick(1.72, 0.72, 1.05, x, 0.38, 13.15);
}
// Door recess and stepped voxel arch.
block(4.7, 3.0, 0.12, 0, 1.5, -12.58, 0x30383a);
block(0.78, 2.8, 1.25, -2.45, 1.4, -12.9, 0xd4c4a2);
block(0.78, 2.8, 1.25, 2.45, 1.4, -12.9, 0xd4c4a2);
block(1.2, 0.72, 1.28, -1.5, 2.95, -12.9, 0xd4c4a2);
block(1.2, 0.72, 1.28, 1.5, 2.95, -12.9, 0xd4c4a2);
block(1.2, 0.72, 1.28, -0.5, 3.35, -12.9, 0xe0d0ab);
block(1.2, 0.72, 1.28, 0.5, 3.35, -12.9, 0xe0d0ab);
// Entrance steps.
block(6.2, 0.24, 1.0, 0, -0.12, 14.05, 0xc9b996);
block(6.8, 0.3, 1.0, 0, -0.30, 14.95, 0xbdae91);
block(7.4, 0.38, 1.0, 0, -0.48, 15.85, 0xb1a183);
// Rear colonnade.
function column(x, z) {
block(1.75, 0.38, 1.75, x, 0.19, z, 0xbcae8e);
block(1.22, 0.28, 1.22, x, 0.50, z, 0xd5c5a3);
block(0.94, 2.75, 0.94, x, 1.98, z, 0xd0be9c);
block(1.16, 0.3, 1.16, x, 3.45, z, 0xbbaa88);
block(1.7, 0.38, 1.7, x, 3.77, z, 0xd8c7a4);
}
column(-9.3, -9.3);
column(9.3, -9.3);
// Small block-built planters.
function planter(x, z) {
block(1.45, 0.75, 1.45, x, 0.38, z, 0xb17d52);
block(1.12, 0.16, 1.12, x, 0.83, z, 0x4e6e4f);
block(0.7, 0.9, 0.7, x, 1.25, z, 0x526f4e);
block(1.0, 0.7, 0.95, x + 0.15, 1.65, z - 0.08, 0x668258);
block(0.55, 0.55, 0.55, x - 0.28, 2.1, z + 0.08, 0x789160);
}
planter(-11.65, -4.8);
planter(11.65, -4.8);
// Survey pins.
for (const x of [-12.25, 12.25]) {
for (const z of [-12.25, 12.25]) {
block(0.09, 1.05, 0.09, x, 0.52, z, 0x5f6969, false);
block(0.45, 0.28, 0.07, x + 0.18, 0.98, z, 0xe3b554, false);
}
}
// ---------------------------------------------------------------------
// Mosaic pattern and archaeological masks
// ---------------------------------------------------------------------
const N = 24;
const CELL = 0.92;
const HALF = (N - 1) / 2;
const COLORS = {
cream: 0xe3d3ad,
sand: 0xc7b58e,
navy: 0x263e54,
teal: 0x4d8985,
terra: 0xb85c47,
gold: 0xd4a84f,
dark: 0x30383b
};
function rosetteColor(i, j, cx, cz) {
const dx = i - cx;
const dz = j - cz;
const r = Math.hypot(dx, dz);
if (r > 2.55) return null;
if (r > 2.08) return COLORS.navy;
if (r < 0.62) return COLORS.gold;
const angle = Math.atan2(dz, dx);
if (Math.abs(Math.sin(angle * 8)) > 0.72) return COLORS.terra;
return COLORS.teal;
}
function mosaicColor(i, j) {
// Alternating perimeter band.
if (i === 0 || j === 0 || i === N - 1 || j === N - 1) {
return (i + j) % 2 ? COLORS.navy : COLORS.terra;
}
if (i === 1 || j === 1 || i === N - 2 || j === N - 2) {
return (i + j) % 2 ? COLORS.gold : COLORS.cream;
}
// Central medallion.
const dx = i - 11.5;
const dz = j - 11.5;
const r = Math.hypot(dx, dz);
const angle = Math.atan2(dz, dx);
if (r < 5.75) {
if (r > 5.3) return COLORS.navy;
if (r < 1.05) return COLORS.gold;
if (r > 4.72 && r < 5.05) return COLORS.cream;
if (r > 3.9 && r < 4.18) return COLORS.terra;
if (Math.abs(Math.sin(angle * 8)) > 0.84 && r < 4.55) {
return COLORS.terra;
}
if (Math.abs(dx) + Math.abs(dz) < 0.72) return COLORS.gold;
return r < 3.3 ? COLORS.teal : COLORS.navy;
}
// Four repeated corner rosettes.
const rosettes = [
[5, 5], [18, 5], [5, 18], [18, 18]
];
for (const [cx, cz] of rosettes) {
const color = rosetteColor(i, j, cx, cz);
if (color !== null) return color;
}
// Axial cream bands connecting the corner motifs.
if (Math.abs(i - 11.5) < 0.38 || Math.abs(j - 11.5) < 0.38) {
return COLORS.cream;
}
// Small lozenges between the medallion and the corners.
const lozenge = Math.abs((i - 11.5) / 5.2) +
Math.abs((j - 11.5) / 5.2);
if (lozenge > 0.78 && lozenge < 0.9) return COLORS.terra;
return (i + j) % 2 ? COLORS.sand : COLORS.cream;
}
// Region A mirrors the intact upper-left rosette into the lower-left.
const evidenceMask = [];
for (let i = 0; i < N; i++) {
for (let j = 0; j < N; j++) {
const dx = (i - 5) / 1.05;
const dz = j - 18;
if (dx * dx + dz * dz <= 10.6) {
if (!(i === 8 && j === 18) && !(i === 7 && j === 20)) {
evidenceMask.push({ i, j });
}
}
}
}
// Region B is an irregular, unattributed loss through the medallion.
const speculationMask = [];
for (let i = 0; i < N; i++) {
for (let j = 0; j < N; j++) {
const inside = i >= 14 && i <= 20 && j >= 13 && j <= 18;
const cutCorner =
(i === 14 && (j === 13 || j === 18)) ||
(i === 20 && (j === 13 || j === 18)) ||
(i === 19 && j === 18);
if (inside && !cutCorner) speculationMask.push({ i, j });
}
}
const evidenceSet = new Set(evidenceMask.map(({ i, j }) => `${i},${j}`));
const speculationSet = new Set(speculationMask.map(({ i, j }) => `${i},${j}`));
function cellWorld(i) {
return (i - HALF) * CELL;
}
// Surviving tesserae, drawn as one instanced voxel mesh.
const survivingEntries = [];
for (let i = 0; i < N; i++) {
for (let j = 0; j < N; j++) {
const key = `${i},${j}`;
if (evidenceSet.has(key) || speculationSet.has(key)) continue;
survivingEntries.push({ i, j });
}
}
const tileGeometry = new THREE.BoxGeometry(CELL * 0.88, 0.12, CELL * 0.88);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.8,
metalness: 0.015,
vertexColors: true
});
const survivingMesh = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
survivingEntries.length
);
const dummy = new THREE.Object3D();
survivingEntries.forEach((entry, index) => {
dummy.position.set(cellWorld(entry.i), 0.09, cellWorld(entry.j));
dummy.updateMatrix();
survivingMesh.setMatrixAt(index, dummy.matrix);
survivingMesh.setColorAt(index, new THREE.Color(mosaicColor(entry.i, entry.j)));
});
survivingMesh.instanceMatrix.needsUpdate = true;
survivingMesh.instanceColor.needsUpdate = true;
survivingMesh.receiveShadow = true;
survivingMesh.castShadow = false;
scene.add(survivingMesh);
// ---------------------------------------------------------------------
// Removable transparent interpretation layers
// ---------------------------------------------------------------------
const removed = new Set();
const removalHistory = [];
function evidencePlaceholderColor(i, j) {
const source = new THREE.Color(mosaicColor(i, j - 13));
const luminance = (source.r + source.g + source.b) / 3;
return new THREE.Color().setHSL(
0.49,
0.78,
0.33 + luminance * 0.34
);
}
function speculationPlaceholderColor(i, j) {
const hash = ((i * 37 + j * 19) % 17) / 17;
return new THREE.Color().setHSL(0.09, 0.88, 0.38 + hash * 0.25);
}
function createPlaceholderLayer(type, mask, colorForCell) {
const entries = mask.map(({ i, j }) => ({
i,
j,
type,
key: `${type}:${i},${j}`
}));
const material = new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: type === "evidence" ? 0.56 : 0.58,
depthWrite: false,
vertexColors: true,
side: THREE.DoubleSide
});
const mesh = new THREE.InstancedMesh(tileGeometry, material, entries.length);
mesh.renderOrder = type === "evidence" ? 5 : 4;
mesh.frustumCulled = false;
mesh.userData.type = type;
mesh.userData.entries = entries;
mesh.userData.visibleEntries = [];
scene.add(mesh);
return mesh;
}
const evidenceMesh = createPlaceholderLayer(
"evidence",
evidenceMask,
evidencePlaceholderColor
);
const speculationMesh = createPlaceholderLayer(
"speculation",
speculationMask,
speculationPlaceholderColor
);
function syncPlaceholder(mesh, colorForCell) {
const visibleEntries = [];
for (const entry of mesh.userData.entries) {
if (removed.has(entry.key)) continue;
dummy.position.set(cellWorld(entry.i), 0.17, cellWorld(entry.j));
dummy.updateMatrix();
const index = visibleEntries.length;
mesh.setMatrixAt(index, dummy.matrix);
mesh.setColorAt(index, colorForCell(entry.i, entry.j));
visibleEntries.push(entry);
}
mesh.count = visibleEntries.length;
mesh.userData.visibleEntries = visibleEntries;
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.computeBoundingSphere();
}
syncPlaceholder(evidenceMesh, evidencePlaceholderColor);
syncPlaceholder(speculationMesh, speculationPlaceholderColor);
const placeholderMeshes = [evidenceMesh, speculationMesh];
// Hover outline.
const highlight = new THREE.Mesh(
new THREE.BoxGeometry(CELL * 0.94, 0.17, CELL * 0.94),
new THREE.MeshBasicMaterial({
color: 0xffffff,
wireframe: true,
transparent: true,
opacity: 0.95,
depthTest: false
})
);
highlight.visible = false;
highlight.renderOrder = 20;
scene.add(highlight);
// ---------------------------------------------------------------------
// Interface and layer state
// ---------------------------------------------------------------------
const evidenceToggle = document.getElementById("evidence-toggle");
const speculationToggle = document.getElementById("speculation-toggle");
const survivingCount = document.getElementById("surviving-count");
const evidenceCount = document.getElementById("evidence-count");
const speculationCount = document.getElementById("speculation-count");
const survivingTotal = document.getElementById("surviving-total");
const inspectTitle = document.getElementById("inspect-title");
const inspectText = document.getElementById("inspect-text");
const inspectMeta = document.getElementById("inspect-meta");
function countVisible(mesh) {
return mesh.userData.visibleEntries.length;
}
function updateCounts() {
survivingCount.textContent = survivingEntries.length;
survivingTotal.textContent = `${survivingEntries.length} intact`;
evidenceCount.textContent = `${countVisible(evidenceMesh)}/${evidenceMesh.userData.entries.length}`;
speculationCount.textContent = `${countVisible(speculationMesh)}/${speculationMesh.userData.entries.length}`;
}
function setInspection(title, text, meta = "") {
inspectTitle.textContent = title;
inspectText.textContent = text;
inspectMeta.textContent = meta;
}
function inspectEntry(entry) {
highlight.visible = true;
highlight.position.set(cellWorld(entry.i), 0.19, cellWorld(entry.j));
highlight.material.color.set(entry.type === "evidence" ? 0x137c83 : 0xa56517);
if (entry.type === "evidence") {
setInspection(
"Evidence-supported repeat",
"This cell repeats the intact upper-left rosette and its adjoining ground pattern. It is a supported reconstruction overlay, not surviving tessera.",
"Region A · interpretive repeat · click to remove"
);
} else {
setInspection(
"Speculative infill",
"No equivalent pattern survives at this loss. This amber cell is a hypothetical completion and should not be treated as evidence of the original design.",
"Region B · hypothesis only · click to remove"
);
}
}
updateCounts();
evidenceToggle.addEventListener("change", () => {
evidenceMesh.visible = evidenceToggle.checked;
document.getElementById("tag-a").style.opacity =
evidenceToggle.checked ? "1" : "0";
updateCounts();
});
speculationToggle.addEventListener("change", () => {
speculationMesh.visible = speculationToggle.checked;
document.getElementById("tag-b").style.opacity =
speculationToggle.checked ? "1" : "0";
updateCounts();
});
function clearLayer(mesh, colorForCell) {
const keys = mesh.userData.entries
.filter(entry => !removed.has(entry.key))
.map(entry => entry.key);
if (!keys.length) return;
keys.forEach(key => removed.add(key));
removalHistory.push(keys);
syncPlaceholder(mesh, colorForCell);
updateCounts();
setInspection(
"Interpretation removed",
"The translucent layer has been removed, exposing only the surviving courtyard substrate and missing tesserae.",
"Use Undo removal or Restore all placeholders"
);
}
document.getElementById("clear-a").addEventListener("click", () => {
clearLayer(evidenceMesh, evidencePlaceholderColor);
});
document.getElementById("clear-b").addEventListener("click", () => {
clearLayer(speculationMesh, speculationPlaceholderColor);
});
document.getElementById("undo").addEventListener("click", () => {
const batch = removalHistory.pop();
if (!batch) return;
batch.forEach(key => removed.delete(key));
syncPlaceholder(evidenceMesh, evidencePlaceholderColor);
syncPlaceholder(speculationMesh, speculationPlaceholderColor);
updateCounts();
setInspection(
"Removal undone",
"The most recently removed interpretive cells have been restored.",
"Click any translucent cell to remove it again"
);
});
document.getElementById("authentic-view").addEventListener("click", () => {
evidenceToggle.checked = false;
speculationToggle.checked = false;
evidenceMesh.visible = false;
speculationMesh.visible = false;
document.getElementById("tag-a").style.opacity = "0";
document.getElementById("tag-b").style.opacity = "0";
updateCounts();
setInspection(
"Authentic view",
"All interpretive overlays are hidden. What remains visible is the surviving mosaic and the physical losses in its substrate.",
"No reconstruction is shown"
);
});
document.getElementById("restore-all").addEventListener("click", () => {
removed.clear();
removalHistory.length = 0;
evidenceToggle.checked = true;
speculationToggle.checked = true;
evidenceMesh.visible = true;
speculationMesh.visible = true;
document.getElementById("tag-a").style.opacity = "1";
document.getElementById("tag-b").style.opacity = "1";
syncPlaceholder(evidenceMesh, evidencePlaceholderColor);
syncPlaceholder(speculationMesh, speculationPlaceholderColor);
updateCounts();
setInspection(
"All placeholders restored",
"Evidence-supported repeats and speculative infill are again visible as separate transparent layers.",
"Click a tile to remove it"
);
});
// ---------------------------------------------------------------------
// Direct camera controls — no external controls module
// ---------------------------------------------------------------------
function updateCamera() {
const radius = 36;
const horizontal = radius * Math.cos(cameraState.pitch);
camera.position.set(
cameraState.target.x + horizontal * Math.sin(cameraState.yaw),
cameraState.target.y + radius * Math.sin(cameraState.pitch),
cameraState.target.z + horizontal * Math.cos(cameraState.yaw)
);
camera.zoom = cameraState.zoom;
camera.lookAt(cameraState.target);
camera.updateProjectionMatrix();
}
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));
const halfWidth = Math.max(13, 13 / Math.max(aspect, 0.65));
camera.left = -halfWidth;
camera.right = halfWidth;
camera.top = halfWidth / aspect;
camera.bottom = -halfWidth / aspect;
updateCamera();
}
window.addEventListener("resize", resize);
resize();
document.getElementById("rotate-left").addEventListener("click", () => {
cameraState.yaw -= 0.2;
updateCamera();
});
document.getElementById("rotate-right").addEventListener("click", () => {
cameraState.yaw += 0.2;
updateCamera();
});
document.getElementById("zoom-in").addEventListener("click", () => {
cameraState.zoom = THREE.MathUtils.clamp(cameraState.zoom * 1.12, 0.65, 2.3);
updateCamera();
});
document.getElementById("zoom-out").addEventListener("click", () => {
cameraState.zoom = THREE.MathUtils.clamp(cameraState.zoom / 1.12, 0.65, 2.3);
updateCamera();
});
document.getElementById("top-view").addEventListener("click", () => {
cameraState.yaw = 0;
cameraState.pitch = 1.48;
cameraState.zoom = 1.03;
updateCamera();
});
document.getElementById("reset-view").addEventListener("click", () => {
cameraState.yaw = 0.73;
cameraState.pitch = 0.66;
cameraState.zoom = 1;
updateCamera();
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
2.3
);
updateCamera();
}, { passive: false });
// ---------------------------------------------------------------------
// Picking and removal
// ---------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let dragging = false;
let moved = false;
let lastX = 0;
let lastY = 0;
let startX = 0;
let startY = 0;
function updatePointer(event) {
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;
}
function pickPlaceholder() {
raycaster.setFromCamera(pointer, camera);
const visibleMeshes = placeholderMeshes.filter(mesh => mesh.visible);
const hits = raycaster.intersectObjects(visibleMeshes, false);
if (!hits.length) return null;
const hit = hits[0];
const entry = hit.object.userData.visibleEntries[hit.instanceId];
return entry ? { entry, object: hit.object } : null;
}
renderer.domElement.addEventListener("pointerdown", event => {
if (event.button !== 0) return;
dragging = true;
moved = false;
startX = lastX = event.clientX;
startY = lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
updatePointer(event);
if (dragging) {
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
if (Math.hypot(event.clientX - startX, event.clientY - startY) > 4) {
moved = true;
}
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.0045,
0.28,
1.49
);
lastX = event.clientX;
lastY = event.clientY;
updateCamera();
renderer.domElement.style.cursor = "grabbing";
return;
}
const picked = pickPlaceholder();
if (picked) {
renderer.domElement.style.cursor = "pointer";
inspectEntry(picked.entry);
} else {
renderer.domElement.style.cursor = "grab";
highlight.visible = false;
}
});
renderer.domElement.addEventListener("pointerup", event => {
if (!dragging) return;
updatePointer(event);
const wasDrag = moved;
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
renderer.domElement.style.cursor = "grab";
if (wasDrag) return;
const picked = pickPlaceholder();
if (!picked) return;
const { entry, object } = picked;
removed.add(entry.key);
removalHistory.push([entry.key]);
if (object === evidenceMesh) {
syncPlaceholder(evidenceMesh, evidencePlaceholderColor);
} else {
syncPlaceholder(speculationMesh, speculationPlaceholderColor);
}
highlight.visible = false;
updateCounts();
setInspection(
"Placeholder removed",
entry.type === "evidence"
? "This evidence-supported repeat has been removed. The underlying loss is now visible."
: "This speculative infill has been removed. The underlying loss is now visible.",
"Undo removal is available in the layer panel"
);
});
renderer.domElement.addEventListener("pointerleave", () => {
if (!dragging) {
highlight.visible = false;
renderer.domElement.style.cursor = "grab";
}
});
renderer.domElement.addEventListener("contextmenu", event => {
event.preventDefault();
});
window.addEventListener("keydown", event => {
if (event.target instanceof HTMLInputElement) return;
if (event.key === "ArrowLeft") {
cameraState.yaw -= 0.12;
updateCamera();
} else if (event.key === "ArrowRight") {
cameraState.yaw += 0.12;
updateCamera();
} else if (event.key === "+" || event.key === "=") {
cameraState.zoom = THREE.MathUtils.clamp(cameraState.zoom * 1.1, 0.65, 2.3);
updateCamera();
} else if (event.key === "-") {
cameraState.zoom = THREE.MathUtils.clamp(cameraState.zoom / 1.1, 0.65, 2.3);
updateCamera();
}
});
// ---------------------------------------------------------------------
// Projected region labels
// ---------------------------------------------------------------------
const tagA = document.getElementById("tag-a");
const tagB = document.getElementById("tag-b");
const projected = new THREE.Vector3();
function placeTag(element, x, z) {
projected.set(x, 0.65, z).project(camera);
const visible = projected.z > -1 && projected.z < 1 &&
Math.abs(projected.x) < 1.15 && Math.abs(projected.y) < 1.15;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const screenX = (projected.x * 0.5 + 0.5) * window.innerWidth;
const screenY = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${screenX}px`;
element.style.top = `${screenY - 18}px`;
}
function animate() {
requestAnimationFrame(animate);
placeTag(tagA, cellWorld(5), cellWorld(18));
placeTag(tagB, cellWorld(17), cellWorld(15));
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```