Prompt specification
Build or customize the Three.js 3D scene "Microscope field of view and specimen scan coverage" 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: Microscope field of view and specimen scan coverage
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/microscope-field-of-view-and-specimen-scan-coverage-x2508
Scene Description Prompt:
I'd like to see this as a low-poly Three.js scene: Microscope field of view and specimen scan coverage. Let users scan a gridded specimen through a historical microscope model with selectable field diameters. Mark observed tiles, count overlapping scans, and compare coverage while keeping specimen detail and resolution fixed. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (microscope-field-of-view-and-specimen-scan-coverage-x2508):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#101613" />
<title>Field Notes — Microscope Specimen Survey</title>
<style>
:root {
color-scheme: dark;
--bg: #101613;
--panel: rgba(17, 25, 22, 0.88);
--panel-strong: rgba(13, 20, 18, 0.95);
--line: rgba(226, 220, 196, 0.14);
--line-strong: rgba(226, 220, 196, 0.24);
--text: #ece7d7;
--muted: #98a39a;
--brass: #c9a766;
--brass-light: #e0c58e;
--teal: #6fd0ba;
--teal-dark: #2e7566;
--amber: #e4ac60;
--danger: #df816d;
--shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button {
font: inherit;
}
button:focus-visible {
outline: 2px solid var(--teal);
outline-offset: 2px;
}
#scene {
position: fixed;
inset: 0;
background:
radial-gradient(circle at 50% 40%, #26362f 0%, #15201c 48%, #0c110f 100%);
}
#scene canvas {
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
.vignette {
position: fixed;
inset: 0;
z-index: 1;
pointer-events: none;
background:
linear-gradient(180deg, rgba(6, 10, 8, 0.6), transparent 18%, transparent 78%, rgba(6, 10, 8, 0.78)),
radial-gradient(circle at 50% 48%, transparent 40%, rgba(4, 7, 6, 0.34) 100%);
}
.topbar {
position: fixed;
z-index: 10;
top: 0;
left: 0;
right: 0;
min-height: 72px;
padding: 12px 20px;
display: flex;
align-items: center;
gap: 22px;
background: linear-gradient(180deg, rgba(10, 15, 13, 0.96), rgba(10, 15, 13, 0.55));
border-bottom: 1px solid var(--line);
backdrop-filter: blur(16px);
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 240px;
}
.brand-mark {
position: relative;
width: 38px;
height: 38px;
flex: 0 0 auto;
border: 1px solid var(--brass);
border-radius: 50%;
box-shadow: inset 0 0 0 5px rgba(201, 167, 102, 0.06);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
inset: 7px;
border: 1px solid rgba(201, 167, 102, 0.7);
transform: rotate(45deg);
}
.brand-mark::after {
inset: 13px;
border-radius: 50%;
background: var(--teal);
border: 0;
box-shadow: 0 0 12px rgba(111, 208, 186, 0.7);
}
.eyebrow {
color: var(--brass);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.brand-title {
margin-top: 2px;
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
line-height: 1.05;
letter-spacing: 0.02em;
}
.header-rule {
height: 36px;
width: 1px;
background: var(--line-strong);
}
.header-context {
min-width: 0;
}
.header-context strong {
display: block;
font-family: Georgia, "Times New Roman", serif;
font-size: 15px;
font-weight: 500;
}
.header-context span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 11px;
}
.source-lock {
margin-left: auto;
display: flex;
align-items: center;
gap: 10px;
padding: 9px 12px;
border: 1px solid rgba(111, 208, 186, 0.28);
border-radius: 6px;
background: rgba(50, 112, 96, 0.09);
color: var(--teal);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
white-space: nowrap;
}
.lock-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 10px rgba(111, 208, 186, 0.7);
}
.top-actions,
.mobile-actions {
display: flex;
align-items: center;
gap: 8px;
}
.mobile-actions {
display: none;
}
.ghost-button,
.small-button {
border: 1px solid var(--line-strong);
color: var(--text);
background: rgba(255, 255, 255, 0.035);
border-radius: 5px;
cursor: pointer;
transition: 160ms ease;
}
.ghost-button {
padding: 9px 11px;
font-size: 11px;
}
.ghost-button:hover,
.small-button:hover {
border-color: rgba(201, 167, 102, 0.6);
background: rgba(201, 167, 102, 0.08);
color: var(--brass-light);
}
.panel {
position: fixed;
z-index: 8;
top: 88px;
bottom: 62px;
width: 306px;
overflow: auto;
padding: 18px;
border: 1px solid var(--line);
border-radius: 10px;
background:
linear-gradient(145deg, rgba(29, 39, 34, 0.7), transparent 38%),
var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
scrollbar-width: thin;
scrollbar-color: rgba(201, 167, 102, 0.35) transparent;
}
.left-panel {
left: 18px;
}
.right-panel {
right: 18px;
width: 318px;
}
.panel::-webkit-scrollbar {
width: 5px;
}
.panel::-webkit-scrollbar-thumb {
border-radius: 4px;
background: rgba(201, 167, 102, 0.3);
}
.panel-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 10px;
margin-bottom: 14px;
}
.panel-heading h2 {
margin: 3px 0 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
font-weight: 500;
}
.catalog-number {
color: var(--brass);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
white-space: nowrap;
}
.instrument-card {
padding: 13px;
margin-bottom: 18px;
border: 1px solid var(--line);
border-radius: 7px;
background: rgba(255, 255, 255, 0.025);
}
.instrument-card strong {
display: block;
margin-bottom: 4px;
font-family: Georgia, "Times New Roman", serif;
font-size: 15px;
font-weight: 500;
}
.instrument-card p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.section {
padding-top: 16px;
margin-top: 16px;
border-top: 1px solid var(--line);
}
.section:first-of-type {
padding-top: 0;
margin-top: 0;
border-top: 0;
}
.section-title {
margin-bottom: 10px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.field-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 7px;
}
.field-button {
position: relative;
padding: 11px 10px 10px;
text-align: left;
color: var(--text);
border: 1px solid var(--line-strong);
border-radius: 6px;
background: rgba(255, 255, 255, 0.025);
cursor: pointer;
transition: 160ms ease;
}
.field-button strong {
display: block;
font-family: Georgia, "Times New Roman", serif;
font-size: 18px;
font-weight: 500;
}
.field-button span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.field-button:hover {
border-color: rgba(201, 167, 102, 0.48);
}
.field-button.active {
border-color: var(--brass);
background: linear-gradient(135deg, rgba(201, 167, 102, 0.16), rgba(201, 167, 102, 0.04));
box-shadow: inset 0 0 0 1px rgba(201, 167, 102, 0.1);
}
.field-button.active::after {
content: "";
position: absolute;
top: 10px;
right: 10px;
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--brass-light);
box-shadow: 0 0 8px rgba(224, 197, 142, 0.55);
}
.field-note {
display: flex;
align-items: center;
gap: 8px;
margin-top: 9px;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.field-note svg {
flex: 0 0 auto;
width: 14px;
height: 14px;
stroke: var(--teal);
}
.resolution-lock {
margin-top: 14px;
padding: 11px;
border-left: 2px solid var(--teal-dark);
background: rgba(46, 117, 102, 0.08);
}
.resolution-lock strong {
display: block;
margin-bottom: 4px;
color: var(--teal);
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.resolution-lock p {
margin: 0;
color: #aab8af;
font-size: 10px;
line-height: 1.5;
}
.target-card {
display: grid;
grid-template-columns: 1fr auto;
gap: 12px;
align-items: center;
padding: 11px;
border: 1px solid var(--line);
border-radius: 6px;
background: rgba(0, 0, 0, 0.12);
}
.target-card span {
display: block;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.target-card strong {
display: block;
margin-top: 3px;
font-size: 13px;
font-weight: 600;
}
.target-reticle {
position: relative;
width: 34px;
height: 34px;
border: 1px solid rgba(111, 208, 186, 0.6);
border-radius: 50%;
}
.target-reticle::before,
.target-reticle::after {
content: "";
position: absolute;
background: var(--teal);
}
.target-reticle::before {
width: 16px;
height: 1px;
left: 8px;
top: 16px;
}
.target-reticle::after {
width: 1px;
height: 16px;
left: 16px;
top: 8px;
}
.button-row {
display: flex;
gap: 8px;
margin-top: 11px;
}
.primary-button,
.secondary-button,
.small-button {
border-radius: 5px;
cursor: pointer;
transition: 160ms ease;
}
.primary-button {
flex: 1;
padding: 12px 14px;
border: 1px solid var(--brass);
background: linear-gradient(135deg, #c9a766, #a98247);
color: #171711;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.11em;
text-transform: uppercase;
box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
}
.primary-button:hover {
filter: brightness(1.08);
transform: translateY(-1px);
}
.primary-button:active {
transform: translateY(0);
}
.secondary-button {
padding: 10px 12px;
border: 1px solid var(--line-strong);
background: rgba(255, 255, 255, 0.035);
color: var(--text);
font-size: 10px;
font-weight: 700;
}
.secondary-button:hover {
border-color: rgba(201, 167, 102, 0.55);
color: var(--brass-light);
}
.wide-button {
width: 100%;
margin-top: 8px;
}
.micro-note {
margin: 9px 0 0;
color: var(--muted);
font-size: 9px;
line-height: 1.5;
}
.ledger {
display: grid;
gap: 7px;
}
.ledger-row {
display: grid;
grid-template-columns: 24px 1fr auto;
gap: 8px;
align-items: center;
padding: 8px 9px;
border: 1px solid rgba(255, 255, 255, 0.055);
border-radius: 5px;
background: rgba(0, 0, 0, 0.1);
font-size: 10px;
}
.ledger-index {
color: var(--brass);
font-family: Georgia, "Times New Roman", serif;
font-size: 13px;
}
.ledger-position {
color: var(--text);
}
.ledger-overlap {
color: var(--amber);
font-size: 9px;
white-space: nowrap;
}
.metrics-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.metric {
min-height: 92px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 7px;
background: rgba(255, 255, 255, 0.025);
}
.metric span {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.metric strong {
display: block;
margin-top: 7px;
font-family: Georgia, "Times New Roman", serif;
font-size: 25px;
font-weight: 500;
line-height: 1;
}
.metric small {
display: block;
margin-top: 7px;
color: var(--muted);
font-size: 9px;
line-height: 1.35;
}
.metric.teal strong {
color: var(--teal);
}
.metric.amber strong {
color: var(--amber);
}
.progress-block {
margin-top: 11px;
}
.progress-label {
display: flex;
justify-content: space-between;
margin-bottom: 6px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.progress-track {
height: 5px;
overflow: hidden;
border-radius: 4px;
background: rgba(255, 255, 255, 0.07);
}
.progress-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: var(--teal);
box-shadow: 0 0 10px rgba(111, 208, 186, 0.35);
transition: width 300ms ease;
}
.progress-fill.amber {
background: var(--amber);
box-shadow: 0 0 10px rgba(228, 172, 96, 0.35);
}
.comparison-table {
width: 100%;
border-collapse: collapse;
font-size: 10px;
}
.comparison-table th {
padding: 0 0 8px;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.08em;
text-align: right;
text-transform: uppercase;
}
.comparison-table th:first-child,
.comparison-table td:first-child {
text-align: left;
}
.comparison-table td {
padding: 8px 0;
border-top: 1px solid rgba(255, 255, 255, 0.055);
color: #b7c0b8;
text-align: right;
}
.comparison-table tr.selected td {
color: var(--brass-light);
}
.comparison-table tr.selected td:first-child {
font-weight: 800;
}
.baseline-empty {
padding: 13px;
border: 1px dashed var(--line-strong);
border-radius: 6px;
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
.baseline-card {
padding: 13px;
border: 1px solid rgba(111, 208, 186, 0.22);
border-radius: 7px;
background: rgba(46, 117, 102, 0.07);
}
.baseline-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 10px;
}
.baseline-top strong {
color: var(--teal);
font-size: 9px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.baseline-values {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.baseline-values span {
display: block;
color: var(--muted);
font-size: 8px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.baseline-values strong {
display: block;
margin-top: 3px;
font-family: Georgia, "Times New Roman", serif;
font-size: 19px;
font-weight: 500;
}
.baseline-delta {
margin-top: 10px;
padding-top: 9px;
border-top: 1px solid rgba(111, 208, 186, 0.15);
color: var(--teal);
font-size: 10px;
}
.baseline-actions {
display: flex;
gap: 6px;
margin-top: 9px;
}
.small-button {
padding: 6px 9px;
font-size: 9px;
}
.scene-footer {
position: fixed;
z-index: 7;
left: 0;
right: 0;
bottom: 0;
min-height: 48px;
padding: 10px 20px;
display: flex;
align-items: center;
justify-content: center;
gap: 18px;
border-top: 1px solid var(--line);
background: linear-gradient(0deg, rgba(8, 12, 10, 0.92), rgba(8, 12, 10, 0.46));
color: var(--muted);
font-size: 10px;
backdrop-filter: blur(12px);
}
.scene-footer span {
display: inline-flex;
align-items: center;
gap: 7px;
}
.key {
display: inline-grid;
min-width: 22px;
height: 21px;
place-items: center;
padding: 0 6px;
border: 1px solid var(--line-strong);
border-bottom-color: rgba(255, 255, 255, 0.35);
border-radius: 4px;
color: var(--text);
background: rgba(255, 255, 255, 0.045);
font-size: 9px;
}
.toast {
position: fixed;
z-index: 20;
left: 50%;
bottom: 70px;
max-width: min(440px, calc(100vw - 32px));
padding: 11px 15px;
border: 1px solid rgba(201, 167, 102, 0.35);
border-radius: 6px;
background: var(--panel-strong);
box-shadow: var(--shadow);
color: var(--text);
font-size: 11px;
line-height: 1.4;
opacity: 0;
pointer-events: none;
transform: translate(-50%, 10px);
transition: 220ms ease;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 1120px) {
.left-panel {
width: 280px;
}
.right-panel {
width: 286px;
}
.header-context,
.header-rule {
display: none;
}
}
@media (max-width: 860px) {
.topbar {
min-height: 66px;
padding: 10px 12px;
gap: 10px;
}
.brand {
min-width: 0;
flex: 1;
}
.brand-mark {
width: 32px;
height: 32px;
}
.brand-title {
font-size: 16px;
}
.source-lock,
.top-actions {
display: none;
}
.mobile-actions {
display: flex;
}
.panel {
top: 76px;
bottom: 58px;
width: min(330px, calc(100vw - 24px));
display: none;
}
body.controls-open .left-panel,
body.metrics-open .right-panel {
display: block;
}
.scene-footer {
justify-content: flex-start;
overflow: hidden;
white-space: nowrap;
}
.scene-footer .desktop-hint {
display: none;
}
}
@media (max-width: 520px) {
.brand .eyebrow {
display: none;
}
.brand-title {
font-size: 14px;
}
.mobile-actions .ghost-button {
padding: 8px 9px;
font-size: 10px;
}
.scene-footer {
gap: 12px;
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive 3D historical microscope and gridded specimen"></div>
<div class="vignette"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<div class="eyebrow">The Field Note</div>
<div class="brand-title">Specimen Survey</div>
</div>
</div>
<div class="header-rule"></div>
<div class="header-context">
<strong>Historical instrument No. 14</strong>
<span>Achromatic microscope · c. 1887 · fixed survey resolution</span>
</div>
<div class="source-lock" title="The specimen source and tile grid do not change with field diameter">
<span class="lock-dot"></span>
Resolution locked · 1024²
</div>
<div class="top-actions">
<button class="ghost-button" id="stageViewBtn" title="Move the camera closer to the specimen stage">Stage view</button>
<button class="ghost-button" id="standViewBtn" title="Reset the camera to the full instrument">Full stand</button>
</div>
<div class="mobile-actions">
<button class="ghost-button" id="controlsBtn">Controls</button>
<button class="ghost-button" id="metricsBtn">Metrics</button>
</div>
</header>
<aside class="panel left-panel" id="controlPanel">
<div class="panel-heading">
<div>
<div class="eyebrow">Acquisition</div>
<h2>Survey controls</h2>
</div>
<div class="catalog-number">FIELD / 01</div>
</div>
<div class="instrument-card">
<strong>No. 14 Achromatic Stand</strong>
<p>Brass body, rack-and-pinion focus, fixed 10× observation setting. The condenser stop changes only the illuminated field.</p>
</div>
<section class="section">
<div class="section-title">Select field diameter</div>
<div class="field-grid" id="fieldButtons">
<button class="field-button" data-mm="1" aria-pressed="false">
<strong>1.0 mm</strong>
<span>Narrow field</span>
</button>
<button class="field-button active" data-mm="1.5" aria-pressed="true">
<strong>1.5 mm</strong>
<span>Medium field</span>
</button>
<button class="field-button" data-mm="2" aria-pressed="false">
<strong>2.0 mm</strong>
<span>Broad field</span>
</button>
<button class="field-button" data-mm="3" aria-pressed="false">
<strong>3.0 mm</strong>
<span>Survey field</span>
</button>
</div>
<div class="field-note">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<circle cx="12" cy="12" r="8"></circle>
<path d="M12 4v16M4 12h16"></path>
</svg>
<span id="fieldNoteText">Approximately 9 center-anchored tiles are marked per scan.</span>
</div>
<div class="resolution-lock">
<strong>Source & resolution lock</strong>
<p>1024 × 1024 px specimen source · 12 × 12 tiles · 0.5 mm pitch. Only the field stop changes; specimen detail does not.</p>
</div>
</section>
<section class="section">
<div class="section-title">Scan target</div>
<div class="target-card">
<div>
<span>Reticle position</span>
<strong id="targetText">Row 07 · Col 07</strong>
</div>
<div class="target-reticle" aria-hidden="true"></div>
</div>
<div class="button-row">
<button class="primary-button" id="scanBtn">Scan field</button>
<button class="secondary-button" id="pinBtn">Pin baseline</button>
</div>
<button class="secondary-button wide-button" id="resetSurveyBtn">Clear specimen observations</button>
<p class="micro-note">Click the slide to position the reticle. Double-click to scan immediately.</p>
</section>
<section class="section">
<div class="section-title">Observation ledger</div>
<div class="ledger" id="ledger"></div>
</section>
</aside>
<aside class="panel right-panel" id="metricsPanel">
<div class="panel-heading">
<div>
<div class="eyebrow">Coverage</div>
<h2>Scan report</h2>
</div>
<div class="catalog-number">REPORT / A</div>
</div>
<div class="metrics-grid">
<div class="metric teal">
<span>Specimen coverage</span>
<strong id="coverageValue">0.0%</strong>
<small id="coverageDetail">0 / 144 unique tiles</small>
</div>
<div class="metric amber">
<span>Overlapping scans</span>
<strong id="overlapScansValue">0</strong>
<small id="overlapScansDetail">0 scan events repeated coverage</small>
</div>
<div class="metric">
<span>Repeated tiles</span>
<strong id="repeatedValue">0</strong>
<small id="repeatedDetail">0% of observed area</small>
</div>
<div class="metric">
<span>Observations</span>
<strong id="scanCountValue">0</strong>
<small id="lastScanDetail">Awaiting first scan</small>
</div>
</div>
<div class="progress-block">
<div class="progress-label">
<span>Unique coverage</span>
<span id="coverageProgressText">0 / 144</span>
</div>
<div class="progress-track">
<div class="progress-fill" id="coverageProgress"></div>
</div>
</div>
<div class="progress-block">
<div class="progress-label">
<span>Repeated area</span>
<span id="overlapProgressText">0 tiles</span>
</div>
<div class="progress-track">
<div class="progress-fill amber" id="overlapProgress"></div>
</div>
</div>
<section class="section">
<div class="section-title">Field comparison</div>
<table class="comparison-table">
<thead>
<tr>
<th>Diameter</th>
<th>Area</th>
<th>Tiles*</th>
</tr>
</thead>
<tbody id="comparisonRows"></tbody>
</table>
<p class="micro-note">*Center-anchored estimate. Geometric area uses a 6 mm specimen at the same fixed pixel resolution.</p>
</section>
<section class="section">
<div class="section-title">Live coverage comparison</div>
<div class="baseline-empty" id="baselineEmpty">
Pin the current observation set as a baseline. Change the field diameter and scan again to compare actual coverage.
</div>
<div class="baseline-card" id="baselineCard" hidden>
<div class="baseline-top">
<strong id="baselineLabel">Pinned baseline</strong>
<button class="small-button" id="clearBaselineBtn">Clear</button>
</div>
<div class="baseline-values">
<div>
<span>Baseline</span>
<strong id="baselineCoverage">0.0%</strong>
</div>
<div>
<span>Live</span>
<strong id="liveCoverage">0.0%</strong>
</div>
</div>
<div class="baseline-delta" id="baselineDelta">+0.0 percentage points</div>
<div class="baseline-actions">
<button class="small-button" id="restoreBaselineBtn">Restore pinned observations</button>
</div>
</div>
</section>
</aside>
<footer class="scene-footer">
<span><span class="key">Drag</span> Orbit</span>
<span><span class="key">Wheel</span> Zoom</span>
<span class="desktop-hint"><span class="key">Click</span> Choose target</span>
<span class="desktop-hint"><span class="key">S</span> Scan</span>
<span class="desktop-hint"><span class="key">F</span> Stage view</span>
</footer>
<div class="toast" id="toast" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (selector) => document.querySelector(selector);
const $$ = (selector) => [...document.querySelectorAll(selector)];
const GRID_SIZE = 12;
const TILE_COUNT = GRID_SIZE * GRID_SIZE;
const TILE_PITCH_MM = 0.5;
const SPECIMEN_SIZE_MM = 6;
const SPECIMEN_WORLD_SIZE = 3.6;
const TILE_WORLD_SIZE = SPECIMEN_WORLD_SIZE / GRID_SIZE;
const GRID_Y = 2.184;
const fieldOptions = [1, 1.5, 2, 3];
const state = {
fieldMm: 1.5,
counts: new Uint16Array(TILE_COUNT),
scans: 0,
overlapScans: 0,
history: [],
baseline: null,
target: { row: 6, col: 6 },
lastScan: null
};
// ---------------------------------------------------------------------
// Renderer and scene
// ---------------------------------------------------------------------
const sceneHost = $("#scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x101613);
scene.fog = new THREE.Fog(0x101613, 14, 28);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 80);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xf1e5c5, 0x17231d, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffdfaa, 3.2);
keyLight.position.set(5.5, 9, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 24;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x79d6c1, 1.4);
rimLight.position.set(-5, 4, -5);
scene.add(rimLight);
const warmFill = new THREE.PointLight(0xffbd71, 1.2, 12, 2);
warmFill.position.set(4, 3.5, 3);
scene.add(warmFill);
// ---------------------------------------------------------------------
// Materials
// ---------------------------------------------------------------------
const materials = {
brass: new THREE.MeshStandardMaterial({
color: 0xb88c43,
metalness: 0.76,
roughness: 0.3,
flatShading: true
}),
brassLight: new THREE.MeshStandardMaterial({
color: 0xd6b56c,
metalness: 0.66,
roughness: 0.27,
flatShading: true
}),
brassDark: new THREE.MeshStandardMaterial({
color: 0x6d5127,
metalness: 0.68,
roughness: 0.38,
flatShading: true
}),
black: new THREE.MeshStandardMaterial({
color: 0x161c19,
metalness: 0.33,
roughness: 0.55,
flatShading: true
}),
blackSoft: new THREE.MeshStandardMaterial({
color: 0x252c28,
metalness: 0.2,
roughness: 0.72,
flatShading: true
}),
wood: new THREE.MeshStandardMaterial({
color: 0x3c2b20,
metalness: 0.03,
roughness: 0.86,
flatShading: true
}),
table: new THREE.MeshStandardMaterial({
color: 0x242b25,
metalness: 0.02,
roughness: 0.93,
flatShading: true
}),
glass: new THREE.MeshPhysicalMaterial({
color: 0xdce9de,
metalness: 0,
roughness: 0.16,
transparent: true,
opacity: 0.16,
transmission: 0.1,
side: THREE.DoubleSide,
depthWrite: false
}),
lens: new THREE.MeshStandardMaterial({
color: 0x2f7774,
metalness: 0.25,
roughness: 0.18,
emissive: 0x123c38,
emissiveIntensity: 0.7
})
};
function addMesh(geometry, material, parent = scene) {
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBox(width, height, depth, material, x, y, z, parent = scene) {
const mesh = addMesh(new THREE.BoxGeometry(width, height, depth), material, parent);
mesh.position.set(x, y, z);
return mesh;
}
// ---------------------------------------------------------------------
// Fixed 1024px specimen source
// ---------------------------------------------------------------------
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value += 0x6D2B79F5;
let t = value;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
function createSpecimenTexture() {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 1024;
const ctx = canvas.getContext("2d");
const random = seededRandom(1887);
const gradient = ctx.createLinearGradient(0, 0, 1024, 1024);
gradient.addColorStop(0, "#efe3c2");
gradient.addColorStop(0.5, "#dfd1aa");
gradient.addColorStop(1, "#cbb78c");
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 1024, 1024);
// Fine paper fibers remain part of the fixed source.
ctx.lineWidth = 1;
for (let i = 0; i < 150; i++) {
const x = random() * 1024;
const y = random() * 1024;
const length = 25 + random() * 110;
const angle = random() * Math.PI;
ctx.strokeStyle = `rgba(91, 76, 48, ${0.025 + random() * 0.04})`;
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(x + Math.cos(angle) * length, y + Math.sin(angle) * length);
ctx.stroke();
}
// Low-poly tissue cells.
for (let i = 0; i < 115; i++) {
const x = random() * 1024;
const y = random() * 1024;
const radius = 13 + random() * 44;
const sides = 6 + Math.floor(random() * 4);
const rotation = random() * Math.PI;
ctx.beginPath();
for (let p = 0; p < sides; p++) {
const angle = rotation + (p / sides) * Math.PI * 2;
const r = radius * (0.72 + random() * 0.35);
const px = x + Math.cos(angle) * r;
const py = y + Math.sin(angle) * r;
if (p === 0) ctx.moveTo(px, py);
else ctx.lineTo(px, py);
}
ctx.closePath();
const warm = random() > 0.48;
ctx.fillStyle = warm
? `rgba(142, 83, 45, ${0.055 + random() * 0.10})`
: `rgba(80, 107, 70, ${0.05 + random() * 0.095})`;
ctx.strokeStyle = warm
? `rgba(116, 65, 36, ${0.14 + random() * 0.12})`
: `rgba(61, 88, 54, ${0.13 + random() * 0.11})`;
ctx.lineWidth = 1.2 + random() * 1.7;
ctx.fill();
ctx.stroke();
if (random() > 0.34) {
ctx.beginPath();
ctx.arc(
x + (random() - 0.5) * radius * 0.45,
y + (random() - 0.5) * radius * 0.45,
2.5 + random() * 6,
0,
Math.PI * 2
);
ctx.fillStyle = `rgba(84, 47, 31, ${0.13 + random() * 0.16})`;
ctx.fill();
}
}
// A few darker tissue regions give the field an archival character.
for (let i = 0; i < 14; i++) {
const x = random() * 1024;
const y = random() * 1024;
const radius = 35 + random() * 80;
const radial = ctx.createRadialGradient(x, y, 0, x, y, radius);
radial.addColorStop(0, "rgba(100, 54, 33, 0.11)");
radial.addColorStop(1, "rgba(100, 54, 33, 0)");
ctx.fillStyle = radial;
ctx.fillRect(x - radius, y - radius, radius * 2, radius * 2);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
texture.minFilter = THREE.LinearMipmapLinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.needsUpdate = true;
return texture;
}
const specimenTexture = createSpecimenTexture();
const specimenMaterial = new THREE.MeshStandardMaterial({
map: specimenTexture,
color: 0xffffff,
roughness: 0.88,
metalness: 0,
side: THREE.FrontSide
});
// ---------------------------------------------------------------------
// Table and low-poly microscope
// ---------------------------------------------------------------------
const table = addMesh(
new THREE.CylinderGeometry(6.3, 6.5, 0.38, 32),
materials.table
);
table.position.y = -0.22;
table.receiveShadow = true;
const tableEdge = addMesh(
new THREE.TorusGeometry(6.28, 0.055, 6, 48),
materials.brassDark
);
tableEdge.rotation.x = Math.PI / 2;
tableEdge.position.y = -0.02;
tableEdge.scale.set(1, 1, 1);
const base = addMesh(
new THREE.CylinderGeometry(1.5, 1.8, 0.38, 10),
materials.blackSoft
);
base.position.set(0, 0.29, -0.12);
base.scale.z = 0.74;
const baseTop = addMesh(
new THREE.CylinderGeometry(1.23, 1.42, 0.15, 10),
materials.brassDark
);
baseTop.position.set(0, 0.53, -0.12);
baseTop.scale.z = 0.74;
const baseRim = addMesh(
new THREE.CylinderGeometry(1.48, 1.49, 0.045, 32),
materials.brass
);
baseRim.position.set(0, 0.48, -0.12);
baseRim.scale.z = 0.74;
[-1, 1].forEach((x) => {
const foot = addMesh(new THREE.SphereGeometry(0.19, 10, 6), materials.brassDark);
foot.position.set(x * 1.05, 0.06, 0.45);
foot.scale.set(1.15, 0.55, 1.1);
});
addBox(0.64, 3.55, 0.66, materials.black, 0, 2.25, -1.14);
addBox(0.76, 0.18, 0.76, materials.brassDark, 0, 4.08, -1.14);
addBox(0.55, 0.52, 1.32, materials.black, 0, 3.35, -0.67);
// Rack-and-pinion focus knobs.
[-1, 1].forEach((side) => {
const knob = addMesh(
new THREE.CylinderGeometry(0.27, 0.27, 0.21, 12),
materials.brass
);
knob.rotation.z = Math.PI / 2;
knob.position.set(side * 0.43, 2.73, -1.12);
});
// Stage and support.
addBox(2.85, 0.16, 2.25, materials.black, 0, 2.02, 0);
addBox(3.02, 0.08, 2.4, materials.brassDark, 0, 1.92, 0);
const aperture = addMesh(
new THREE.CylinderGeometry(0.62, 0.62, 0.035, 24),
materials.black
);
aperture.position.set(0, 2.108, 0);
// Stage clips.
addBox(0.18, 0.06, 0.72, materials.brass, -1.35, 2.14, 0.32);
addBox(0.18, 0.06, 0.72, materials.brass, 1.35, 2.14, 0.32);
// Glass slide and specimen.
const glassSlide = addMesh(
new THREE.PlaneGeometry(SPECIMEN_WORLD_SIZE + 0.16, SPECIMEN_WORLD_SIZE + 0.16),
materials.glass
);
glassSlide.rotation.x = -Math.PI / 2;
glassSlide.position.y = 2.145;
const specimenMesh = addMesh(
new THREE.PlaneGeometry(SPECIMEN_WORLD_SIZE, SPECIMEN_WORLD_SIZE),
specimenMaterial
);
specimenMesh.rotation.x = -Math.PI / 2;
specimenMesh.position.y = 2.16;
specimenMesh.castShadow = false;
// Slide border.
const borderMaterial = new THREE.MeshBasicMaterial({
color: 0xc8d4ca,
transparent: true,
opacity: 0.32
});
const halfSpec = SPECIMEN_WORLD_SIZE / 2 + 0.04;
const borderY = 2.177;
addBox(SPECIMEN_WORLD_SIZE + 0.16, 0.012, 0.018, borderMaterial, 0, borderY, -halfSpec).castShadow = false;
addBox(SPECIMEN_WORLD_SIZE + 0.16, 0.012, 0.018, borderMaterial, 0, borderY, halfSpec).castShadow = false;
addBox(0.018, 0.012, SPECIMEN_WORLD_SIZE + 0.16, borderMaterial, -halfSpec, borderY, 0).castShadow = false;
addBox(0.018, 0.012, SPECIMEN_WORLD_SIZE + 0.16, borderMaterial, halfSpec, borderY, 0).castShadow = false;
// Objective turret.
const turret = addMesh(
new THREE.CylinderGeometry(0.58, 0.58, 0.2, 12),
materials.brass
);
turret.position.set(0, 2.88, 0);
const objectivePositions = [
[0, 2.58, 0.16],
[-0.34, 2.62, -0.1],
[0.34, 2.61, -0.1]
];
objectivePositions.forEach((position, index) => {
const length = index === 0 ? 0.48 : 0.37 + index * 0.08;
const barrel = addMesh(
new THREE.CylinderGeometry(0.15, 0.17, length, 10),
index === 0 ? materials.brassLight : materials.brass
);
barrel.position.set(...position);
const lens = addMesh(
new THREE.CylinderGeometry(0.125, 0.125, 0.026, 12),
materials.lens
);
lens.position.set(position[0], position[1] - length / 2 - 0.012, position[2]);
});
// Body tube and focus collar.
const bodyTube = addMesh(
new THREE.CylinderGeometry(0.34, 0.41, 1.5, 10),
materials.black
);
bodyTube.position.set(0, 3.72, 0);
const lowerCollar = addMesh(
new THREE.CylinderGeometry(0.47, 0.47, 0.18, 12),
materials.brass
);
lowerCollar.position.set(0, 3.04, 0);
const upperCollar = addMesh(
new THREE.CylinderGeometry(0.39, 0.39, 0.14, 12),
materials.brassDark
);
upperCollar.position.set(0, 4.39, 0);
const eyepiece = addMesh(
new THREE.CylinderGeometry(0.25, 0.31, 0.53, 10),
materials.blackSoft
);
eyepiece.position.set(0, 4.68, 0);
const eyeRim = addMesh(
new THREE.CylinderGeometry(0.28, 0.28, 0.07, 12),
materials.brass
);
eyeRim.position.set(0, 4.97, 0);
// Mirror below the stage.
const mirror = addMesh(
new THREE.CylinderGeometry(0.48, 0.48, 0.055, 20),
materials.brassLight
);
mirror.rotation.x = Math.PI / 2;
mirror.position.set(0, 1.28, 0.48);
const mirrorArm = addMesh(
new THREE.CylinderGeometry(0.045, 0.045, 0.75, 8),
materials.brassDark
);
mirrorArm.position.set(0, 1.1, 0.15);
mirrorArm.rotation.x = -0.42;
// Instrument plaque.
const plaqueCanvas = document.createElement("canvas");
plaqueCanvas.width = 512;
plaqueCanvas.height = 160;
const plaqueCtx = plaqueCanvas.getContext("2d");
plaqueCtx.fillStyle = "#d3bf8f";
plaqueCtx.fillRect(0, 0, 512, 160);
plaqueCtx.strokeStyle = "#5e4928";
plaqueCtx.lineWidth = 8;
plaqueCtx.strokeRect(8, 8, 496, 144);
plaqueCtx.fillStyle = "#302719";
plaqueCtx.textAlign = "center";
plaqueCtx.font = "bold 48px Georgia";
plaqueCtx.fillText("No. 14", 256, 68);
plaqueCtx.font = "23px Georgia";
plaqueCtx.fillText("ACHROMATIC · 1887", 256, 112);
const plaqueTexture = new THREE.CanvasTexture(plaqueCanvas);
plaqueTexture.colorSpace = THREE.SRGBColorSpace;
const plaque = addMesh(
new THREE.PlaneGeometry(0.92, 0.29),
new THREE.MeshBasicMaterial({ map: plaqueTexture })
);
plaque.position.set(0, 3.28, -0.802);
// ---------------------------------------------------------------------
// Survey grid, observed tiles and optical field
// ---------------------------------------------------------------------
function buildGridLines() {
const positions = [];
const half = SPECIMEN_WORLD_SIZE / 2;
for (let i = 0; i <= GRID_SIZE; i++) {
const p = -half + i * TILE_WORLD_SIZE;
const major = i % 3 === 0;
positions.push(p, GRID_Y, -half, p, GRID_Y, half);
positions.push(-half, GRID_Y, p, half, GRID_Y, p);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
const material = new THREE.LineBasicMaterial({
color: 0x31453d,
transparent: true,
opacity: 0.35,
depthWrite: false
});
const lines = new THREE.LineSegments(geometry, material);
lines.renderOrder = 3;
scene.add(lines);
}
buildGridLines();
const tileGeometry = new THREE.PlaneGeometry(
TILE_WORLD_SIZE * 0.91,
TILE_WORLD_SIZE * 0.91
);
tileGeometry.rotateX(-Math.PI / 2);
const observedMaterial = new THREE.MeshBasicMaterial({
color: 0x57c5ac,
transparent: true,
opacity: 0.27,
depthWrite: false,
side: THREE.DoubleSide
});
const overlapMaterial = new THREE.MeshBasicMaterial({
color: 0xe4a552,
transparent: true,
opacity: 0.38,
depthWrite: false,
side: THREE.DoubleSide
});
const observedTiles = new THREE.InstancedMesh(
tileGeometry,
observedMaterial,
TILE_COUNT
);
const overlappedTiles = new THREE.InstancedMesh(
tileGeometry,
overlapMaterial,
TILE_COUNT
);
observedTiles.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
overlappedTiles.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
observedTiles.frustumCulled = false;
overlappedTiles.frustumCulled = false;
observedTiles.renderOrder = 4;
overlappedTiles.renderOrder = 5;
observedTiles.position.y = GRID_Y + 0.008;
overlappedTiles.position.y = GRID_Y + 0.011;
scene.add(observedTiles, overlappedTiles);
const fieldPreviewMaterial = new THREE.MeshBasicMaterial({
color: 0x8ee0cb,
transparent: true,
opacity: 0.68,
side: THREE.DoubleSide,
depthWrite: false
});
const fieldPreviewGeometry = new THREE.RingGeometry(0.965, 1, 64);
fieldPreviewGeometry.rotateX(-Math.PI / 2);
const fieldPreview = new THREE.Mesh(
fieldPreviewGeometry,
fieldPreviewMaterial
);
fieldPreview.position.y = GRID_Y + 0.025;
fieldPreview.renderOrder = 7;
scene.add(fieldPreview);
const targetMarker = new THREE.Mesh(
new THREE.RingGeometry(0.065, 0.092, 24),
new THREE.MeshBasicMaterial({
color: 0xe9d29a,
side: THREE.DoubleSide,
depthWrite: false
})
);
targetMarker.rotation.x = -Math.PI / 2;
targetMarker.position.y = GRID_Y + 0.035;
targetMarker.renderOrder = 8;
scene.add(targetMarker);
const hoverMarker = new THREE.Mesh(
new THREE.RingGeometry(0.09, 0.105, 24),
new THREE.MeshBasicMaterial({
color: 0xb9d6ca,
transparent: true,
opacity: 0.5,
side: THREE.DoubleSide,
depthWrite: false
})
);
hoverMarker.rotation.x = -Math.PI / 2;
hoverMarker.position.y = GRID_Y + 0.033;
hoverMarker.visible = false;
scene.add(hoverMarker);
// A translucent cone makes the selected field visible from the objective.
const beamMaterial = new THREE.MeshBasicMaterial({
color: 0xf2d58e,
transparent: true,
opacity: 0.075,
side: THREE.DoubleSide,
depthWrite: false
});
const beam = new THREE.Mesh(
new THREE.ConeGeometry(1, 1, 24, 1, true),
beamMaterial
);
beam.renderOrder = 2;
scene.add(beam);
const objectiveApex = new THREE.Vector3(0, 2.31, 0.16);
const yAxis = new THREE.Vector3(0, 1, 0);
function tileCenter(row, col) {
return {
x: -SPECIMEN_WORLD_SIZE / 2 + (col + 0.5) * TILE_WORLD_SIZE,
z: SPECIMEN_WORLD_SIZE / 2 - (row + 0.5) * TILE_WORLD_SIZE
};
}
function updateTargetVisuals() {
const center = tileCenter(state.target.row, state.target.col);
targetMarker.position.x = center.x;
targetMarker.position.z = center.z;
fieldPreview.position.x = center.x;
fieldPreview.position.z = center.z;
const radius = state.fieldMm * (SPECIMEN_WORLD_SIZE / SPECIMEN_SIZE_MM) / 2;
fieldPreview.scale.set(radius, radius, radius);
const targetPoint = new THREE.Vector3(center.x, GRID_Y + 0.03, center.z);
const direction = new THREE.Vector3().subVectors(objectiveApex, targetPoint);
const length = direction.length();
direction.normalize();
beam.position.copy(objectiveApex).add(targetPoint).multiplyScalar(0.5);
beam.quaternion.setFromUnitVectors(yAxis, direction);
beam.scale.set(radius, length, radius);
$("#targetText").textContent =
`Row ${String(state.target.row + 1).padStart(2, "0")} · Col ${String(state.target.col + 1).padStart(2, "0")}`;
}
function updateTileInstances() {
const dummy = new THREE.Object3D();
for (let row = 0; row < GRID_SIZE; row++) {
for (let col = 0; col < GRID_SIZE; col++) {
const index = row * GRID_SIZE + col;
const center = tileCenter(row, col);
const count = state.counts[index];
dummy.position.set(center.x, 0, center.z);
dummy.scale.setScalar(count === 1 ? 1 : 0);
dummy.updateMatrix();
observedTiles.setMatrixAt(index, dummy.matrix);
dummy.scale.setScalar(count >= 2 ? 1 : 0);
dummy.updateMatrix();
overlappedTiles.setMatrixAt(index, dummy.matrix);
}
}
observedTiles.instanceMatrix.needsUpdate = true;
overlappedTiles.instanceMatrix.needsUpdate = true;
}
// ---------------------------------------------------------------------
// Scan logic and metrics
// ---------------------------------------------------------------------
function getFootprint(row, col, fieldMm) {
const tiles = [];
// A 1 mm diameter field has a 1 mm radius, or two 0.5 mm grid pitches.
const radiusInTiles = fieldMm / TILE_PITCH_MM;
for (let r = 0; r < GRID_SIZE; r++) {
for (let c = 0; c < GRID_SIZE; c++) {
const distance = Math.hypot(r - row, c - col);
if (distance <= radiusInTiles + 1e-6) {
tiles.push({ row: r, col: c, index: r * GRID_SIZE + c });
}
}
}
return tiles;
}
function countUniqueTiles(counts) {
let unique = 0;
for (const count of counts) if (count > 0) unique++;
return unique;
}
function countRepeatedTiles(counts) {
let repeated = 0;
for (const count of counts) if (count >= 2) repeated++;
return repeated;
}
function countRedundantHits(counts) {
let redundant = 0;
for (const count of counts) if (count > 1) redundant += count - 1;
return redundant;
}
const scanAnimations = [];
function animateScan(row, col, fieldMm) {
const center = tileCenter(row, col);
const radius = fieldMm * (SPECIMEN_WORLD_SIZE / SPECIMEN_SIZE_MM) / 2;
const geometry = new THREE.RingGeometry(0.93, 1, 64);
geometry.rotateX(-Math.PI / 2);
const material = new THREE.MeshBasicMaterial({
color: 0xffdf9b,
transparent: true,
opacity: 0.85,
side: THREE.DoubleSide,
depthWrite: false
});
const pulse = new THREE.Mesh(geometry, material);
pulse.position.set(center.x, GRID_Y + 0.045, center.z);
pulse.scale.setScalar(0.02);
pulse.renderOrder = 10;
scene.add(pulse);
scanAnimations.push({
mesh: pulse,
radius,
start: performance.now(),
duration: 850
});
}
function applyScan(row, col, fieldMm, silent = false) {
const footprint = getFootprint(row, col, fieldMm);
let repeated = 0;
let newlyObserved = 0;
for (const tile of footprint) {
if (state.counts[tile.index] > 0) repeated++;
else newlyObserved++;
state.counts[tile.index]++;
}
state.scans++;
if (repeated > 0) state.overlapScans++;
const scanRecord = {
row,
col,
fieldMm,
repeated,
newlyObserved
};
state.history.push(scanRecord);
state.lastScan = scanRecord;
if (!silent) {
animateScan(row, col, fieldMm);
showToast(
`Field scanned: ${newlyObserved} new tile${newlyObserved === 1 ? "" : "s"}` +
`${repeated ? `, ${repeated} repeated` : ", no repeated area"}.`
);
}
updateTileInstances();
updateUI();
}
function scanCurrentTarget() {
applyScan(state.target.row, state.target.col, state.fieldMm);
}
function resetSurvey() {
state.counts.fill(0);
state.scans = 0;
state.overlapScans = 0;
state.history.length = 0;
state.lastScan = null;
state.baseline = null;
updateTileInstances();
updateUI();
showToast("Observation set cleared. The specimen source and coordinate grid remain unchanged.");
}
function pinBaseline() {
state.baseline = {
counts: Array.from(state.counts),
scans: state.scans,
overlapScans: state.overlapScans,
fieldMm: state.fieldMm,
coverage: countUniqueTiles(state.counts) / TILE_COUNT * 100
};
updateUI();
showToast("Current coverage pinned. Change the field diameter and continue scanning to compare.");
}
function restoreBaseline() {
if (!state.baseline) return;
state.counts = new Uint16Array(state.baseline.counts);
state.scans = state.baseline.scans;
state.overlapScans = state.baseline.overlapScans;
state.history.length = 0;
state.lastScan = null;
updateTileInstances();
updateUI();
showToast("Pinned observation set restored.");
}
function updateUI() {
const unique = countUniqueTiles(state.counts);
const repeated = countRepeatedTiles(state.counts);
const redundant = countRedundantHits(state.counts);
const coverage = unique / TILE_COUNT * 100;
const repeatedPercent = unique ? repeated / unique * 100 : 0;
$("#coverageValue").textContent = `${coverage.toFixed(1)}%`;
$("#coverageDetail").textContent = `${unique} / ${TILE_COUNT} unique tiles`;
$("#coverageProgress").style.width = `${coverage}%`;
$("#coverageProgressText").textContent = `${unique} / ${TILE_COUNT}`;
$("#overlapScansValue").textContent = state.overlapScans;
$("#overlapScansDetail").textContent =
`${state.overlapScans} scan event${state.overlapScans === 1 ? "" : "s"} repeated coverage`;
$("#repeatedValue").textContent = repeated;
$("#repeatedDetail").textContent = `${repeatedPercent.toFixed(1)}% of observed area`;
$("#overlapProgress").style.width = `${repeated / TILE_COUNT * 100}%`;
$("#overlapProgressText").textContent = `${repeated} tiles`;
$("#scanCountValue").textContent = state.scans;
if (state.lastScan) {
$("#lastScanDetail").textContent =
`${state.lastScan.newlyObserved} new · ${state.lastScan.repeated} repeated`;
} else {
$("#lastScanDetail").textContent = "Awaiting first scan";
}
renderLedger();
if (state.baseline) {
$("#baselineEmpty").hidden = true;
$("#baselineCard").hidden = false;
$("#baselineLabel").textContent = `Baseline · ${state.baseline.fieldMm.toFixed(1)} mm field`;
$("#baselineCoverage").textContent = `${state.baseline.coverage.toFixed(1)}%`;
$("#liveCoverage").textContent = `${coverage.toFixed(1)}%`;
const delta = coverage - state.baseline.coverage;
const deltaText = `${delta >= 0 ? "+" : ""}${delta.toFixed(1)} percentage points`;
$("#baselineDelta").textContent =
`${deltaText} · ${state.scans - state.baseline.scans} additional scans`;
} else {
$("#baselineEmpty").hidden = false;
$("#baselineCard").hidden = true;
}
}
function renderLedger() {
const ledger = $("#ledger");
ledger.innerHTML = "";
if (!state.history.length) {
const empty = document.createElement("div");
empty.className = "baseline-empty";
empty.textContent = "No observations yet.";
ledger.appendChild(empty);
return;
}
state.history.slice(-4).reverse().forEach((entry, reverseIndex) => {
const row = document.createElement("div");
row.className = "ledger-row";
const index = document.createElement("span");
index.className = "ledger-index";
index.textContent = String(state.history.length - reverseIndex).padStart(2, "0");
const position = document.createElement("span");
position.className = "ledger-position";
position.textContent =
`R${String(entry.row + 1).padStart(2, "0")} C${String(entry.col + 1).padStart(2, "0")} · ${entry.fieldMm.toFixed(1)} mm`;
const overlap = document.createElement("span");
overlap.className = "ledger-overlap";
overlap.textContent = `${entry.repeated} repeat`;
row.append(index, position, overlap);
ledger.appendChild(row);
});
}
function centerTileCount(fieldMm) {
return getFootprint(6, 6, fieldMm).length;
}
function buildComparisonTable() {
const rows = $("#comparisonRows");
rows.innerHTML = "";
fieldOptions.forEach((mm) => {
const area = Math.min(100, Math.PI * Math.pow(mm / 2, 2) /
(SPECIMEN_SIZE_MM * SPECIMEN_SIZE_MM) * 100);
const row = document.createElement("tr");
row.dataset.mm = mm;
if (mm === state.fieldMm) row.classList.add("selected");
row.innerHTML = `
<td>${mm.toFixed(1)} mm</td>
<td>${area.toFixed(1)}%</td>
<td>≈${centerTileCount(mm)}</td>
`;
rows.appendChild(row);
});
}
function updateFieldUI() {
$$(".field-button").forEach((button) => {
const active = Number(button.dataset.mm) === state.fieldMm;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
$$("#comparisonRows tr").forEach((row) => {
row.classList.toggle("selected", Number(row.dataset.mm) === state.fieldMm);
});
const estimate = centerTileCount(state.fieldMm);
$("#fieldNoteText").textContent =
`Approximately ${estimate} center-anchored tiles are marked per scan.`;
updateTargetVisuals();
}
// ---------------------------------------------------------------------
// Camera controls implemented directly without addons
// ---------------------------------------------------------------------
const orbit = {
theta: 0.76,
phi: 1.02,
radius: 10.5,
target: new THREE.Vector3(0, 2.25, 0)
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
function setCameraView(view) {
if (view === "stage") {
orbit.theta = 0.55;
orbit.phi = 0.68;
orbit.radius = 6.6;
orbit.target.set(0, 2.18, 0);
} else {
orbit.theta = 0.76;
orbit.phi = 1.02;
orbit.radius = 10.5;
orbit.target.set(0, 2.25, 0);
}
updateCamera();
}
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = null;
let dragging = false;
function pickSpecimen(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;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObject(specimenMesh, false);
return hits.length ? hits[0].point : null;
}
function pointToTile(point) {
const half = SPECIMEN_WORLD_SIZE / 2;
const col = THREE.MathUtils.clamp(
Math.floor((point.x + half) / TILE_WORLD_SIZE),
0,
GRID_SIZE - 1
);
const row = THREE.MathUtils.clamp(
Math.floor((half - point.z) / TILE_WORLD_SIZE),
0,
GRID_SIZE - 1
);
return { row, col };
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
pointerDown = {
x: event.clientX,
y: event.clientY,
lastX: event.clientX,
lastY: event.clientY,
moved: 0
};
dragging = false;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (pointerDown) {
const dx = event.clientX - pointerDown.lastX;
const dy = event.clientY - pointerDown.lastY;
pointerDown.moved += Math.abs(dx) + Math.abs(dy);
if (pointerDown.moved > 4) dragging = true;
if (dragging) {
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi - dy * 0.005, 0.22, 1.46);
updateCamera();
}
pointerDown.lastX = event.clientX;
pointerDown.lastY = event.clientY;
hoverMarker.visible = false;
return;
}
const point = pickSpecimen(event);
if (point) {
const tile = pointToTile(point);
const center = tileCenter(tile.row, tile.col);
hoverMarker.position.x = center.x;
hoverMarker.position.z = center.z;
hoverMarker.visible = true;
renderer.domElement.style.cursor = "crosshair";
} else {
hoverMarker.visible = false;
renderer.domElement.style.cursor = "grab";
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (pointerDown && !dragging) {
const point = pickSpecimen(event);
if (point) {
state.target = pointToTile(point);
updateTargetVisuals();
}
}
pointerDown = null;
dragging = false;
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = null;
dragging = false;
});
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
const factor = Math.exp(event.deltaY * 0.001);
orbit.radius = THREE.MathUtils.clamp(orbit.radius * factor, 4.4, 17);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", (event) => {
const point = pickSpecimen(event);
if (!point) return;
state.target = pointToTile(point);
updateTargetVisuals();
scanCurrentTarget();
});
// ---------------------------------------------------------------------
// Interface events
// ---------------------------------------------------------------------
$$(".field-button").forEach((button) => {
button.addEventListener("click", () => {
state.fieldMm = Number(button.dataset.mm);
updateFieldUI();
showToast(`${state.fieldMm.toFixed(1)} mm field selected. Source detail remains fixed.`);
});
});
$("#scanBtn").addEventListener("click", scanCurrentTarget);
$("#resetSurveyBtn").addEventListener("click", resetSurvey);
$("#pinBtn").addEventListener("click", pinBaseline);
$("#clearBaselineBtn").addEventListener("click", () => {
state.baseline = null;
updateUI();
showToast("Pinned baseline cleared.");
});
$("#restoreBaselineBtn").addEventListener("click", restoreBaseline);
$("#stageViewBtn").addEventListener("click", () => setCameraView("stage"));
$("#standViewBtn").addEventListener("click", () => setCameraView("stand"));
$("#controlsBtn").addEventListener("click", () => {
document.body.classList.toggle("controls-open");
document.body.classList.remove("metrics-open");
});
$("#metricsBtn").addEventListener("click", () => {
document.body.classList.toggle("metrics-open");
document.body.classList.remove("controls-open");
});
window.addEventListener("keydown", (event) => {
if (event.key === "Escape") {
document.body.classList.remove("controls-open", "metrics-open");
return;
}
if (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement) return;
if (event.key.toLowerCase() === "s") scanCurrentTarget();
if (event.key.toLowerCase() === "f") setCameraView("stage");
if (event.key.toLowerCase() === "r") setCameraView("stand");
});
let toastTimer;
function showToast(message) {
const toast = $("#toast");
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 3200);
}
// ---------------------------------------------------------------------
// Resize and animation loop
// ---------------------------------------------------------------------
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
}
window.addEventListener("resize", resize);
function animate(now) {
requestAnimationFrame(animate);
for (let i = scanAnimations.length - 1; i >= 0; i--) {
const animation = scanAnimations[i];
const progress = THREE.MathUtils.clamp(
(now - animation.start) / animation.duration,
0,
1
);
const eased = 1 - Math.pow(1 - progress, 3);
animation.mesh.scale.setScalar(
Math.max(0.02, animation.radius * eased)
);
animation.mesh.material.opacity = 0.82 * (1 - progress);
if (progress >= 1) {
scene.remove(animation.mesh);
animation.mesh.geometry.dispose();
animation.mesh.material.dispose();
scanAnimations.splice(i, 1);
}
}
renderer.render(scene, camera);
}
// ---------------------------------------------------------------------
// Initialize with a small demonstration observation set
// ---------------------------------------------------------------------
buildComparisonTable();
updateFieldUI();
updateCamera();
resize();
applyScan(4, 5, 1.5, true);
applyScan(6, 6, 1.5, true);
applyScan(7, 7, 2, true);
updateUI();
requestAnimationFrame(animate);
setTimeout(() => {
showToast("Demonstration observations loaded. Click the slide to place a new scan.");
}, 500);
</script>
</body>
</html>
```