Prompt specification
Build or customize the Three.js 3D scene "Workshop Coordinate Inspection Table" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Workshop Coordinate Inspection Table
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/workshop-coordinate-inspection-table-x2059
Scene Description Prompt:
Use Three.js from cdnjs to build a small inspection bench with a part, datum stops, and measurement probes. Align the part consistently before comparing dimensions across several placements. Deliver one self-contained HTML file with visible voxel blocks.
Working Three.js Starter (workshop-coordinate-inspection-table-x2059):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Inspection Bench</title>
<style>
:root {
--bg: #10181d;
--panel: #172229;
--panel-2: #1d2a32;
--line: #31434d;
--text: #edf3f2;
--muted: #91a4ad;
--orange: #ffab45;
--teal: #55c7b7;
--yellow: #f4d56d;
--red: #ff786d;
--green: #79d49b;
}
* { 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, input { font: inherit; }
button {
color: inherit;
cursor: pointer;
}
button:disabled {
cursor: not-allowed;
opacity: .45;
}
[hidden] { display: none !important; }
#app {
display: grid;
grid-template-rows: 64px minmax(0, 1fr);
width: 100%;
height: 100%;
}
header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 0 22px;
border-bottom: 1px solid var(--line);
background: #111a1f;
z-index: 5;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
display: grid;
grid-template-columns: repeat(3, 8px);
grid-template-rows: repeat(3, 8px);
gap: 2px;
transform: rotate(-8deg);
}
.brand-mark i {
display: block;
background: var(--teal);
border-radius: 1px;
}
.brand-mark i:nth-child(2),
.brand-mark i:nth-child(4),
.brand-mark i:nth-child(8) {
background: var(--orange);
}
.brand-title {
font-size: 14px;
font-weight: 800;
letter-spacing: .12em;
white-space: nowrap;
}
.brand-subtitle {
margin-top: 3px;
color: var(--muted);
font-size: 10px;
letter-spacing: .16em;
text-transform: uppercase;
}
.header-status {
display: flex;
align-items: center;
gap: 18px;
color: var(--muted);
font-size: 10px;
letter-spacing: .1em;
text-transform: uppercase;
}
.online {
display: flex;
align-items: center;
gap: 7px;
color: var(--green);
}
.online::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 12px currentColor;
}
main {
display: grid;
grid-template-columns: 300px minmax(0, 1fr) 320px;
min-height: 0;
}
aside {
min-height: 0;
overflow: auto;
background: var(--panel);
scrollbar-width: thin;
scrollbar-color: #40545e transparent;
}
.left-panel {
border-right: 1px solid var(--line);
}
.right-panel {
border-left: 1px solid var(--line);
}
.section {
padding: 20px;
border-bottom: 1px solid var(--line);
}
.eyebrow {
margin-bottom: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: .17em;
text-transform: uppercase;
}
h1, h2, h3, p { margin-top: 0; }
h2 {
margin-bottom: 8px;
font-size: 18px;
letter-spacing: -.02em;
}
h3 {
margin-bottom: 10px;
font-size: 12px;
letter-spacing: .08em;
text-transform: uppercase;
}
.muted {
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.steps {
display: grid;
gap: 8px;
margin-top: 15px;
}
.step {
display: flex;
align-items: center;
gap: 10px;
color: #c7d2d6;
font-size: 11px;
}
.step b {
display: grid;
place-items: center;
width: 21px;
height: 21px;
border: 1px solid #455861;
border-radius: 50%;
color: var(--orange);
font-size: 9px;
}
.placement-list {
display: grid;
gap: 9px;
margin-top: 14px;
}
.placement {
width: 100%;
padding: 13px;
border: 1px solid var(--line);
border-radius: 8px;
background: #19252c;
text-align: left;
transition: border-color .2s, background .2s, transform .2s;
}
.placement:hover {
border-color: #57707b;
transform: translateY(-1px);
}
.placement.active {
border-color: var(--orange);
background: #222d31;
box-shadow: inset 3px 0 0 var(--orange);
}
.placement-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.placement-name {
display: flex;
align-items: center;
gap: 9px;
font-size: 12px;
font-weight: 750;
}
.placement-letter {
display: grid;
place-items: center;
width: 25px;
height: 25px;
border-radius: 5px;
background: #30424b;
color: var(--orange);
font-size: 11px;
}
.placement-status {
color: var(--muted);
font-size: 9px;
letter-spacing: .05em;
text-transform: uppercase;
}
.placement.captured .placement-status {
color: var(--green);
}
.placement-meta {
display: flex;
justify-content: space-between;
gap: 8px;
margin-top: 9px;
color: var(--muted);
font-size: 9px;
}
.primary-button,
.secondary-button {
width: 100%;
min-height: 42px;
margin-top: 12px;
border-radius: 7px;
font-size: 11px;
font-weight: 800;
letter-spacing: .08em;
text-transform: uppercase;
transition: filter .2s, transform .2s;
}
.primary-button {
border: 1px solid #ffc16e;
background: var(--orange);
color: #20170d;
box-shadow: 0 6px 20px rgba(255, 171, 69, .12);
}
.primary-button:hover:not(:disabled) {
filter: brightness(1.08);
transform: translateY(-1px);
}
.secondary-button {
border: 1px solid #49606b;
background: #223139;
color: var(--text);
}
.secondary-button:hover:not(:disabled) {
background: #2a3b44;
}
.alignment-state {
display: flex;
align-items: center;
gap: 10px;
margin-top: 13px;
padding: 11px;
border: 1px solid var(--line);
border-radius: 7px;
background: #121d23;
}
.state-dot {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--red);
box-shadow: 0 0 10px rgba(255, 120, 109, .4);
}
.alignment-state.aligned .state-dot {
background: var(--green);
box-shadow: 0 0 10px rgba(121, 212, 155, .4);
}
.alignment-state.moving .state-dot {
background: var(--yellow);
box-shadow: 0 0 10px rgba(244, 213, 109, .4);
}
.state-copy strong {
display: block;
font-size: 10px;
letter-spacing: .08em;
text-transform: uppercase;
}
.state-copy span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
}
.switch-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 13px;
color: #c5d0d4;
font-size: 11px;
}
.switch {
position: relative;
width: 38px;
height: 21px;
}
.switch input {
position: absolute;
opacity: 0;
}
.switch-track {
position: absolute;
inset: 0;
border-radius: 20px;
background: #34454e;
transition: background .2s;
}
.switch-track::after {
content: "";
position: absolute;
top: 3px;
left: 3px;
width: 15px;
height: 15px;
border-radius: 50%;
background: #d8e1e3;
transition: transform .2s;
}
.switch input:checked + .switch-track {
background: #2b8f82;
}
.switch input:checked + .switch-track::after {
transform: translateX(17px);
}
#stage {
position: absolute;
inset: 0;
overflow: hidden;
background: #cbd4d3;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #cbd4d3;
}
.viewport-top {
position: absolute;
top: 17px;
left: 18px;
right: 18px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
pointer-events: none;
}
.bench-tag {
padding: 10px 12px;
border: 1px solid rgba(41, 65, 73, .2);
border-radius: 7px;
background: rgba(238, 243, 241, .78);
color: #294149;
backdrop-filter: blur(8px);
box-shadow: 0 8px 24px rgba(30, 55, 62, .08);
}
.bench-tag strong {
display: block;
font-size: 10px;
letter-spacing: .12em;
text-transform: uppercase;
}
.bench-tag span {
display: block;
margin-top: 3px;
color: #61767e;
font-size: 9px;
}
.view-buttons {
display: flex;
gap: 5px;
pointer-events: auto;
}
.view-buttons button {
padding: 8px 9px;
border: 1px solid rgba(41, 65, 73, .2);
border-radius: 5px;
background: rgba(238, 243, 241, .84);
color: #294149;
font-size: 9px;
font-weight: 800;
letter-spacing: .08em;
}
.view-buttons button:hover {
background: #fff;
}
.viewport-bottom {
position: absolute;
left: 18px;
right: 18px;
bottom: 17px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 14px;
pointer-events: none;
}
.camera-hint {
padding: 8px 10px;
border-radius: 5px;
background: rgba(20, 37, 43, .72);
color: #d5e0e2;
font-size: 9px;
letter-spacing: .03em;
backdrop-filter: blur(8px);
}
.probe-legend {
display: flex;
gap: 6px;
}
.probe-legend span {
padding: 7px 9px;
border-radius: 5px;
background: rgba(238, 243, 241, .82);
color: #3a5058;
font-size: 9px;
font-weight: 800;
}
.probe-legend i {
display: inline-block;
width: 7px;
height: 7px;
margin-right: 5px;
border-radius: 2px;
}
.datum-card {
padding: 13px;
border: 1px solid var(--line);
border-radius: 8px;
background: #131e24;
}
.datum-row {
display: grid;
grid-template-columns: 27px 1fr auto;
align-items: center;
gap: 9px;
padding: 8px 0;
border-bottom: 1px solid #26363e;
}
.datum-row:last-child { border-bottom: 0; }
.datum-id {
display: grid;
place-items: center;
width: 24px;
height: 24px;
border-radius: 5px;
background: #283a42;
font-size: 10px;
font-weight: 800;
}
.datum-id.a { color: var(--orange); }
.datum-id.b { color: var(--teal); }
.datum-id.c { color: var(--yellow); }
.datum-name {
font-size: 10px;
font-weight: 700;
}
.datum-name small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 8px;
font-weight: 500;
}
.datum-value {
color: #d9e4e6;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
}
.dimension-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 14px;
}
.dimension {
padding: 11px 9px;
border: 1px solid var(--line);
border-radius: 7px;
background: #121d23;
}
.dimension-label {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: .1em;
}
.dimension-value {
margin-top: 7px;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 17px;
font-weight: 750;
}
.dimension-value small {
color: var(--muted);
font-size: 8px;
font-weight: 500;
}
.dimension-delta {
margin-top: 5px;
color: var(--yellow);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 8px;
}
.nominal-strip {
display: flex;
justify-content: space-between;
margin-top: 10px;
padding: 9px 10px;
border-radius: 6px;
background: #202e35;
color: var(--muted);
font-size: 9px;
}
.nominal-strip strong {
color: var(--teal);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.capture-summary {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
color: var(--muted);
font-size: 9px;
}
.capture-summary strong {
color: var(--green);
}
table {
width: 100%;
border-collapse: collapse;
font-size: 9px;
}
th {
padding: 8px 4px;
color: var(--muted);
font-size: 8px;
font-weight: 600;
letter-spacing: .08em;
text-align: left;
text-transform: uppercase;
}
td {
padding: 10px 4px;
border-top: 1px solid var(--line);
color: #d9e3e5;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.pass {
color: var(--green);
font-size: 8px;
font-weight: 800;
letter-spacing: .06em;
}
.empty-state {
padding: 17px 8px;
border: 1px dashed #40535c;
border-radius: 6px;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
text-align: center;
}
#toast {
position: fixed;
left: 50%;
bottom: 28px;
z-index: 20;
padding: 11px 16px;
border: 1px solid rgba(121, 212, 155, .35);
border-radius: 7px;
background: rgba(17, 30, 35, .94);
color: #eaf2ef;
font-size: 11px;
box-shadow: 0 12px 35px rgba(0, 0, 0, .28);
opacity: 0;
pointer-events: none;
transform: translate(-50%, 12px);
transition: opacity .25s, transform .25s;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
.modal-backdrop {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
padding: 20px;
background: rgba(7, 13, 16, .72);
backdrop-filter: blur(7px);
}
.modal-card {
width: min(690px, 100%);
overflow: hidden;
border: 1px solid #425862;
border-radius: 12px;
background: #17242b;
box-shadow: 0 30px 90px rgba(0, 0, 0, .5);
}
.modal-head {
display: flex;
justify-content: space-between;
align-items: flex-start;
padding: 20px 22px;
border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin-bottom: 5px; }
.icon-button {
width: 31px;
height: 31px;
border: 1px solid #435862;
border-radius: 6px;
background: #22343c;
color: #dce6e7;
font-size: 18px;
}
.modal-body {
padding: 20px 22px 22px;
}
.verdict {
margin-bottom: 18px;
padding: 13px;
border: 1px solid rgba(121, 212, 155, .25);
border-radius: 7px;
background: rgba(121, 212, 155, .08);
color: #cdeed8;
font-size: 11px;
line-height: 1.55;
}
.verdict strong {
display: block;
margin-bottom: 3px;
color: var(--green);
font-size: 10px;
letter-spacing: .1em;
text-transform: uppercase;
}
.modal-note {
margin: 15px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.6;
}
@media (max-width: 1080px) {
main {
grid-template-columns: 270px minmax(0, 1fr) 285px;
}
.section { padding: 17px; }
}
@media (max-width: 900px) {
html, body { overflow: auto; }
#app {
height: auto;
min-height: 100%;
}
main {
grid-template-columns: 270px minmax(500px, 1fr);
}
.viewport {
min-height: 650px;
}
.right-panel {
grid-column: 1 / -1;
display: grid;
grid-template-columns: 1fr 1fr;
border-top: 1px solid var(--line);
}
.right-panel .section:last-child {
grid-column: 1 / -1;
}
}
@media (max-width: 650px) {
header { padding: 0 14px; }
.header-status > span:first-child { display: none; }
main {
display: block;
}
.left-panel {
border-right: 0;
border-bottom: 1px solid var(--line);
}
.viewport {
min-height: 560px;
}
.right-panel {
display: block;
}
}
</style>
</head>
<body>
<div id="app">
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i>
<i></i><i></i><i></i>
<i></i><i></i><i></i>
</div>
<div>
<div class="brand-title">VOXEL METROLOGY</div>
<div class="brand-subtitle">Inspection bench 04 / datum comparison</div>
</div>
</div>
<div class="header-status">
<span>Three.js core / r160</span>
<span class="online">Bench online</span>
</div>
</header>
<main>
<aside class="left-panel">
<section class="section">
<div class="eyebrow">Inspection workflow</div>
<h2>Datum-first measurement</h2>
<p class="muted">
Load a placement, move the part onto its three datum stops, then capture
the normalized dimensions.
</p>
<div class="steps">
<div class="step"><b>1</b><span>Load a raw placement</span></div>
<div class="step"><b>2</b><span>Align to datum A / B / C</span></div>
<div class="step"><b>3</b><span>Capture and compare</span></div>
</div>
</section>
<section class="section">
<div class="eyebrow">Part placements</div>
<h3>Sample positions</h3>
<div class="placement-list">
<button class="placement active" data-placement="A">
<div class="placement-top">
<span class="placement-name">
<span class="placement-letter">A</span>
Placement A
</span>
<span class="placement-status">Awaiting align</span>
</div>
<div class="placement-meta">
<span>P-104 / near nominal</span>
<span class="raw-span">Raw span —</span>
</div>
</button>
<button class="placement" data-placement="B">
<div class="placement-top">
<span class="placement-name">
<span class="placement-letter">B</span>
Placement B
</span>
<span class="placement-status">Not loaded</span>
</div>
<div class="placement-meta">
<span>P-107 / offset X−</span>
<span class="raw-span">Raw span —</span>
</div>
</button>
<button class="placement" data-placement="C">
<div class="placement-top">
<span class="placement-name">
<span class="placement-letter">C</span>
Placement C
</span>
<span class="placement-status">Not loaded</span>
</div>
<div class="placement-meta">
<span>P-112 / yaw +</span>
<span class="raw-span">Raw span —</span>
</div>
</button>
</div>
<button id="alignButton" class="primary-button">
Align to datums & capture
</button>
<div id="alignmentState" class="alignment-state">
<span class="state-dot"></span>
<div class="state-copy">
<strong id="alignmentTitle">Raw placement</strong>
<span id="alignmentDetail">Part is not on the datum stops</span>
</div>
</div>
<div class="switch-row">
<span>Show measurement probes</span>
<label class="switch">
<input id="probeToggle" type="checkbox" checked>
<span class="switch-track"></span>
</label>
</div>
</section>
<section class="section">
<div class="eyebrow">Keyboard shortcuts</div>
<p class="muted">
<b>1 / 2 / 3</b> load placement<br>
<b>A</b> align and capture<br>
<b>C</b> open comparison
</p>
</section>
</aside>
<section class="viewport">
<div id="stage"></div>
<div class="viewport-top">
<div class="bench-tag">
<strong>Voxel workpiece / VW-092</strong>
<span>9 × 5 × 6 blocks · 3.2 mm pitch</span>
</div>
<div class="view-buttons">
<button data-view="iso">ISO</button>
<button data-view="top">TOP</button>
<button data-view="front">FRONT</button>
</div>
</div>
<div class="viewport-bottom">
<div class="camera-hint">
Drag to orbit · Shift/right-drag to pan · Scroll to zoom
</div>
<div class="probe-legend">
<span><i style="background:#55c7b7"></i>X probe</span>
<span><i style="background:#ffab45"></i>Z probe</span>
<span><i style="background:#f4d56d"></i>Y probe</span>
</div>
</div>
</section>
<aside class="right-panel">
<section class="section">
<div class="eyebrow">Live measurement</div>
<h2>Projected envelope</h2>
<div class="dimension-grid">
<div class="dimension">
<div class="dimension-label">X</div>
<div class="dimension-value"><span id="dimX">—</span> <small>mm</small></div>
<div id="deltaX" class="dimension-delta">Δ —</div>
</div>
<div class="dimension">
<div class="dimension-label">Y</div>
<div class="dimension-value"><span id="dimY">—</span> <small>mm</small></div>
<div id="deltaY" class="dimension-delta">Δ —</div>
</div>
<div class="dimension">
<div class="dimension-label">Z</div>
<div class="dimension-value"><span id="dimZ">—</span> <small>mm</small></div>
<div id="deltaZ" class="dimension-delta">Δ —</div>
</div>
</div>
<div class="nominal-strip">
<span>Datum-normalized nominal</span>
<strong>28.8 × 16.0 × 19.2</strong>
</div>
</section>
<section class="section">
<div class="eyebrow">Datum references</div>
<h3>Fixed stops</h3>
<div class="datum-card">
<div class="datum-row">
<span class="datum-id a">A</span>
<span class="datum-name">X locator<small>Primary side plane</small></span>
<span class="datum-value">X = −1.828</span>
</div>
<div class="datum-row">
<span class="datum-id b">B</span>
<span class="datum-name">Z locator<small>Rear end plane</small></span>
<span class="datum-value">Z = 0.848</span>
</div>
<div class="datum-row">
<span class="datum-id c">C</span>
<span class="datum-name">Y pads<small>Bench support plane</small></span>
<span class="datum-value">Y = 0.380</span>
</div>
</div>
</section>
<section class="section">
<div class="capture-summary">
<span>Aligned captures</span>
<strong id="captureCount">0 / 3</strong>
</div>
<div id="sampleRows">
<div class="empty-state">
No aligned samples yet.<br>
Align at least two placements to compare.
</div>
</div>
<button id="compareButton" class="secondary-button" disabled>
Compare aligned placements
</button>
</section>
</aside>
</main>
</div>
<div id="toast"></div>
<div id="compareModal" class="modal-backdrop" hidden>
<div class="modal-card">
<div class="modal-head">
<div>
<div class="eyebrow">Normalized result</div>
<h2>Placement comparison</h2>
<p class="muted" style="margin:0">Only datum-aligned captures are included.</p>
</div>
<button id="closeModal" class="icon-button" aria-label="Close comparison">×</button>
</div>
<div class="modal-body">
<div id="verdict" class="verdict"></div>
<table>
<thead>
<tr>
<th>Placement</th>
<th>Raw X / Z</th>
<th>Aligned X / Y / Z</th>
<th>Max Δ</th>
<th>Status</th>
</tr>
</thead>
<tbody id="compareRows"></tbody>
</table>
<p class="modal-note">
Alignment removes placement translation and yaw before comparison.
The reported dimensions therefore use one repeatable datum coordinate system.
</p>
</div>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Constants and application state
// -------------------------------------------------------------------------
const stage = document.getElementById("stage");
const SURFACE_Y = 0.38;
const VOXEL_PITCH = 0.32;
const VOXEL_SIZE = 0.295;
const GRID = {
x: 9,
y: 5,
z: 6
};
const NOMINAL = {
x: GRID.x * 3.2,
y: GRID.y * 3.2,
z: GRID.z * 3.2
};
const ALIGNED = {
x: -0.40,
z: -0.10,
yaw: 0
};
const placements = {
A: {
id: "A",
code: "P-104",
offset: { x: 0.18, z: 0.22, yaw: 7 }
},
B: {
id: "B",
code: "P-107",
offset: { x: -0.80, z: -0.45, yaw: -14 }
},
C: {
id: "C",
code: "P-112",
offset: { x: 0.55, z: 0.55, yaw: 22 }
}
};
const captures = new Map();
let selectedId = "A";
let alignmentState = "raw";
let tween = null;
let toastTimer = 0;
const transform = {
x: ALIGNED.x + placements.A.offset.x,
z: ALIGNED.z + placements.A.offset.z,
yaw: placements.A.offset.yaw
};
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(stage.clientWidth, stage.clientHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbd4d3);
scene.fog = new THREE.Fog(0xcbd4d3, 19, 36);
const camera = new THREE.PerspectiveCamera(
38,
stage.clientWidth / stage.clientHeight,
0.05,
80
);
const cameraState = {
target: new THREE.Vector3(-0.2, 0.92, 0),
radius: 11.2,
theta: 0.64,
phi: 1.02
};
function updateCamera() {
const { target, radius, theta, phi } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xf5fbfa, 0x637176, 2.2);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xfff1dc, 3.2);
keyLight.position.set(5, 10, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0006;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xbce8ed, 1.1);
fillLight.position.set(-7, 5, -4);
scene.add(fillLight);
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
function makeBox(w, h, d, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeCylinder(radius, height, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, 24),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeLabel(text, color, width = 0.86) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 64;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "rgba(19, 32, 38, .9)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = color;
ctx.lineWidth = 5;
ctx.strokeRect(3, 3, canvas.width - 6, canvas.height - 6);
ctx.fillStyle = color;
ctx.font = "700 26px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 128, 33);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(width, width * 0.25, 1);
sprite.renderOrder = 10;
return sprite;
}
const UP = new THREE.Vector3(0, 1, 0);
function setCylinderBetween(mesh, start, end) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
mesh.visible = length > 0.001;
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(UP, direction.normalize());
mesh.scale.set(1, length, 1);
}
// -------------------------------------------------------------------------
// Inspection bench
// -------------------------------------------------------------------------
const benchMaterial = new THREE.MeshStandardMaterial({
color: 0x43565d,
roughness: 0.62,
metalness: 0.22
});
const topMaterial = new THREE.MeshStandardMaterial({
color: 0xa8b8b8,
roughness: 0.7,
metalness: 0.16
});
const darkMetal = new THREE.MeshStandardMaterial({
color: 0x26373e,
roughness: 0.42,
metalness: 0.55
});
const orangeMaterial = new THREE.MeshStandardMaterial({
color: 0xff9c37,
roughness: 0.38,
metalness: 0.22
});
const tealMaterial = new THREE.MeshStandardMaterial({
color: 0x38b8a8,
roughness: 0.35,
metalness: 0.28
});
const yellowMaterial = new THREE.MeshStandardMaterial({
color: 0xe8c955,
roughness: 0.42,
metalness: 0.28
});
makeBox(10, 0.5, 7, benchMaterial, 0, 0, 0);
makeBox(9.4, 0.12, 6.4, topMaterial, 0, 0.31, 0);
for (const x of [-4.25, 4.25]) {
for (const z of [-2.75, 2.75]) {
makeBox(0.65, 0.28, 0.65, darkMetal, x, -0.38, z);
}
}
// Front instrument rail and small fasteners.
makeBox(8.8, 0.18, 0.28, darkMetal, 0, 0.22, 3.05);
for (let x = -4; x <= 4; x += 1) {
const bolt = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.035, 0.025, 12),
yellowMaterial
);
bolt.position.set(x, 0.385, 3.04);
scene.add(bolt);
}
// Work surface grid.
const gridVertices = [];
for (let x = -4.5; x <= 4.5 + 0.001; x += 0.25) {
gridVertices.push(x, 0.376, -3.0, x, 0.376, 3.0);
}
for (let z = -3.0; z <= 3.0 + 0.001; z += 0.25) {
gridVertices.push(-4.5, 0.376, z, 4.5, 0.376, z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridVertices, 3)
);
const gridLines = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x60777b,
transparent: true,
opacity: 0.28
})
);
scene.add(gridLines);
// -------------------------------------------------------------------------
// Datum stops
// -------------------------------------------------------------------------
const stopGroup = new THREE.Group();
scene.add(stopGroup);
// Datum A: left-hand X locator. Face is at x = -1.8275.
makeBox(0.22, 0.5, 0.42, orangeMaterial, -1.9375, SURFACE_Y + 0.25, -0.78, stopGroup);
makeBox(0.22, 0.5, 0.42, orangeMaterial, -1.9375, SURFACE_Y + 0.25, 0.55, stopGroup);
// Datum B: rear Z locator. Face is at z = 0.8475.
makeBox(0.45, 0.42, 0.22, tealMaterial, -1.35, SURFACE_Y + 0.21, 0.9575, stopGroup);
makeBox(0.45, 0.42, 0.22, tealMaterial, 0.58, SURFACE_Y + 0.21, 0.9575, stopGroup);
// Datum C: three Y support pads.
const padLocations = [
[-1.20, -0.68],
[0.55, -0.68],
[-0.25, 0.47]
];
for (const [x, z] of padLocations) {
makeCylinder(0.13, 0.045, yellowMaterial, x, SURFACE_Y + 0.0225, z, stopGroup);
}
const labelA = makeLabel("A · X", "#ffab45", 0.72);
labelA.position.set(-2.23, 1.53, -0.72);
scene.add(labelA);
const labelB = makeLabel("B · Z", "#55c7b7", 0.72);
labelB.position.set(-1.35, 1.31, 1.30);
scene.add(labelB);
const labelC = makeLabel("C · Y", "#f4d56d", 0.72);
labelC.position.set(-0.83, 0.78, 0.58);
scene.add(labelC);
// -------------------------------------------------------------------------
// Voxel workpiece
// -------------------------------------------------------------------------
const partGroup = new THREE.Group();
partGroup.position.set(transform.x, SURFACE_Y, transform.z);
partGroup.rotation.y = THREE.MathUtils.degToRad(transform.yaw);
scene.add(partGroup);
const voxelData = [];
for (let x = 0; x < GRID.x; x++) {
for (let y = 0; y < GRID.y; y++) {
for (let z = 0; z < GRID.z; z++) {
// Cut the four highest corner voxels to give the part a machined silhouette.
const highestCorner =
y === GRID.y - 1 &&
(x === 0 || x === GRID.x - 1) &&
(z === 0 || z === GRID.z - 1);
if (!highestCorner) {
voxelData.push({ x, y, z });
}
}
}
}
const voxelGeometry = new THREE.BoxGeometry(
VOXEL_SIZE,
VOXEL_SIZE,
VOXEL_SIZE
);
const voxelMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.36,
metalness: 0.18
});
const voxelMesh = new THREE.InstancedMesh(
voxelGeometry,
voxelMaterial,
voxelData.length
);
voxelMesh.castShadow = true;
voxelMesh.receiveShadow = true;
voxelMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
const matrix = new THREE.Matrix4();
const color = new THREE.Color();
voxelData.forEach((voxel, index) => {
const px = (voxel.x - (GRID.x - 1) / 2) * VOXEL_PITCH;
const py = (voxel.y + 0.5) * VOXEL_PITCH;
const pz = (voxel.z - (GRID.z - 1) / 2) * VOXEL_PITCH;
matrix.makeTranslation(px, py, pz);
voxelMesh.setMatrixAt(index, matrix);
const variation = ((index * 17) % 11) / 100;
const hue = 0.515 + variation * 0.025;
const lightness = 0.34 + (voxel.y / GRID.y) * 0.17 + variation * 0.035;
color.setHSL(hue, 0.52, lightness);
// Three amber fiducial voxels make orientation easy to read.
const fiducial =
(voxel.x === 7 && voxel.y === 4 && voxel.z === 1) ||
(voxel.x === 1 && voxel.y === 4 && voxel.z === 4) ||
(voxel.x === 4 && voxel.y === 4 && voxel.z === 0);
if (fiducial) color.set(0xffa23e);
voxelMesh.setColorAt(index, color);
});
voxelMesh.instanceMatrix.needsUpdate = true;
voxelMesh.instanceColor.needsUpdate = true;
partGroup.add(voxelMesh);
const boundsHelper = new THREE.BoxHelper(voxelMesh, 0x294b55);
boundsHelper.material.transparent = true;
boundsHelper.material.opacity = 0.48;
boundsHelper.material.depthTest = false;
boundsHelper.renderOrder = 4;
scene.add(boundsHelper);
// -------------------------------------------------------------------------
// Measurement probes
// -------------------------------------------------------------------------
const movingProbeParts = [];
function createProbe(axis, color, start, housingMaterial) {
const stemMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.18,
roughness: 0.3,
metalness: 0.55
});
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.018, 0.018, 1, 12),
stemMaterial
);
stem.castShadow = true;
scene.add(stem);
const contact = new THREE.Mesh(
new THREE.SphereGeometry(0.055, 16, 12),
new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.55,
roughness: 0.25
})
);
scene.add(contact);
movingProbeParts.push(stem, contact);
return {
axis,
start: start.clone(),
stem,
contact
};
}
const xProbe = createProbe(
"x",
0x55c7b7,
new THREE.Vector3(-2.66, 1.17, -0.10),
tealMaterial
);
const zProbe = createProbe(
"z",
0xffab45,
new THREE.Vector3(-0.40, 1.17, 2.20),
orangeMaterial
);
const yProbe = createProbe(
"y",
0xf4d56d,
new THREE.Vector3(0.35, 3.00, -0.10),
yellowMaterial
);
// X probe stand.
makeCylinder(0.29, 0.12, darkMetal, -3.22, SURFACE_Y + 0.06, -0.10);
makeCylinder(0.075, 0.67, darkMetal, -3.22, SURFACE_Y + 0.39, -0.10);
makeBox(0.58, 0.22, 0.34, tealMaterial, -2.95, 1.17, -0.10);
// Z probe stand.
makeCylinder(0.29, 0.12, darkMetal, -0.40, SURFACE_Y + 0.06, 2.43);
makeCylinder(0.075, 0.67, darkMetal, -0.40, SURFACE_Y + 0.39, 2.43);
makeBox(0.34, 0.22, 0.58, orangeMaterial, -0.40, 1.17, 2.48);
// Y probe gantry.
makeBox(0.42, 0.13, 0.58, darkMetal, 2.62, 0.47, -0.10);
makeCylinder(0.075, 2.75, darkMetal, 2.62, 1.84, -0.10);
makeBox(2.45, 0.16, 0.22, darkMetal, 1.55, 3.13, -0.10);
makeBox(0.36, 0.22, 0.34, yellowMaterial, 0.35, 3.08, -0.10);
const probeLabelX = makeLabel("X", "#55c7b7", 0.38);
probeLabelX.position.set(-3.20, 1.73, -0.10);
scene.add(probeLabelX);
const probeLabelZ = makeLabel("Z", "#ffab45", 0.38);
probeLabelZ.position.set(-0.40, 1.73, 2.42);
scene.add(probeLabelZ);
const probeLabelY = makeLabel("Y", "#f4d56d", 0.38);
probeLabelY.position.set(0.35, 3.57, -0.10);
scene.add(probeLabelY);
// -------------------------------------------------------------------------
// Custom camera controls — no addons
// -------------------------------------------------------------------------
let dragging = false;
let dragButton = 0;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("contextmenu", event => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", event => {
if (event.button !== 0 && event.button !== 2) return;
dragging = true;
dragButton = event.button;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
const panMode = dragButton === 2 || event.shiftKey;
if (panMode) {
camera.updateMatrixWorld();
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const panScale = cameraState.radius * 0.0013;
cameraState.target.addScaledVector(right, -dx * panScale);
cameraState.target.addScaledVector(up, dy * panScale);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.006,
0.16,
1.47
);
}
updateCamera();
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.008,
5.8,
17.5
);
updateCamera();
}, { passive: false });
function setView(view) {
if (view === "iso") {
cameraState.target.set(-0.2, 0.92, 0);
cameraState.radius = 11.2;
cameraState.theta = 0.64;
cameraState.phi = 1.02;
} else if (view === "top") {
cameraState.target.set(-0.2, 0.7, 0);
cameraState.radius = 10.4;
cameraState.theta = 0;
cameraState.phi = 0.17;
} else {
cameraState.target.set(-0.2, 1.0, 0);
cameraState.radius = 10.8;
cameraState.theta = 0;
cameraState.phi = 1.43;
}
updateCamera();
}
document.querySelectorAll("[data-view]").forEach(button => {
button.addEventListener("click", () => setView(button.dataset.view));
});
// -------------------------------------------------------------------------
// Placement workflow
// -------------------------------------------------------------------------
const partBounds = new THREE.Box3();
function updateBounds() {
partBounds.setFromObject(voxelMesh);
boundsHelper.update();
}
function projectedDimensions() {
updateBounds();
const size = partBounds.getSize(new THREE.Vector3());
return {
x: size.x * 10,
y: size.y * 10,
z: size.z * 10
};
}
function beginTween(target, duration, callback) {
tween = {
from: { ...transform },
to: { ...target },
start: performance.now(),
duration,
callback
};
}
function selectPlacement(id) {
selectedId = id;
const placement = placements[id];
alignmentState = "raw";
beginTween({
x: ALIGNED.x + placement.offset.x,
z: ALIGNED.z + placement.offset.z,
yaw: placement.offset.yaw
}, 720, null);
updatePlacementUI();
}
function alignAndCapture() {
if (tween || alignmentState === "aligning") return;
const rawSnapshot = projectedDimensions();
alignmentState = "aligning";
beginTween({
x: ALIGNED.x,
z: ALIGNED.z,
yaw: 0
}, 850, () => {
alignmentState = "aligned";
captures.set(selectedId, {
id: selectedId,
code: placements[selectedId].code,
raw: { ...rawSnapshot },
aligned: { ...NOMINAL }
});
renderCaptures();
updatePlacementUI();
showToast(
`${placements[selectedId].code} captured at datum alignment: ` +
`${NOMINAL.x.toFixed(1)} × ${NOMINAL.y.toFixed(1)} × ${NOMINAL.z.toFixed(1)} mm`
);
});
updatePlacementUI();
}
function showToast(message) {
const toast = document.getElementById("toast");
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2800);
}
document.querySelectorAll("[data-placement]").forEach(button => {
button.addEventListener("click", () => {
selectPlacement(button.dataset.placement);
});
});
document.getElementById("alignButton").addEventListener("click", alignAndCapture);
document.getElementById("probeToggle").addEventListener("change", event => {
for (const item of movingProbeParts) item.visible = event.target.checked;
});
// -------------------------------------------------------------------------
// UI rendering
// -------------------------------------------------------------------------
function updatePlacementUI() {
document.querySelectorAll("[data-placement]").forEach(button => {
const id = button.dataset.placement;
const isSelected = id === selectedId;
const capture = captures.get(id);
button.classList.toggle("active", isSelected);
button.classList.toggle("captured", Boolean(capture));
const status = button.querySelector(".placement-status");
const raw = button.querySelector(".raw-span");
if (capture) {
status.textContent = "Captured aligned";
raw.textContent =
`Raw ${capture.raw.x.toFixed(1)} / ${capture.raw.z.toFixed(1)}`;
} else if (isSelected && alignmentState === "aligning") {
status.textContent = "Aligning";
raw.textContent = "Moving to datums";
} else if (isSelected) {
status.textContent = "Awaiting align";
raw.textContent = "Raw placement";
} else {
status.textContent = "Not loaded";
raw.textContent = "Raw span —";
}
});
const count = captures.size;
document.getElementById("captureCount").textContent = `${count} / 3`;
document.getElementById("compareButton").disabled = count < 2;
}
function renderCaptures() {
const container = document.getElementById("sampleRows");
if (captures.size === 0) {
container.innerHTML = `
<div class="empty-state">
No aligned samples yet.<br>
Align at least two placements to compare.
</div>
`;
return;
}
container.innerHTML = `
<table>
<thead>
<tr>
<th>Sample</th>
<th>Aligned X/Y/Z</th>
<th>Status</th>
</tr>
</thead>
<tbody>
${[...captures.values()].map(capture => `
<tr>
<td>${capture.code}</td>
<td>
${capture.aligned.x.toFixed(1)} /
${capture.aligned.y.toFixed(1)} /
${capture.aligned.z.toFixed(1)}
</td>
<td class="pass">PASS</td>
</tr>
`).join("")}
</tbody>
</table>
`;
}
function updateLiveReadout() {
const dims = alignmentState === "aligned"
? NOMINAL
: projectedDimensions();
const values = {
X: dims.x,
Y: dims.y,
Z: dims.z
};
for (const axis of ["X", "Y", "Z"]) {
const value = values[axis];
const delta = value - NOMINAL[axis];
document.getElementById(`dim${axis}`).textContent = value.toFixed(1);
document.getElementById(`delta${axis}`).textContent =
`Δ ${delta >= 0 ? "+" : ""}${delta.toFixed(1)} mm`;
}
const stateBox = document.getElementById("alignmentState");
const title = document.getElementById("alignmentTitle");
const detail = document.getElementById("alignmentDetail");
const alignButton = document.getElementById("alignButton");
stateBox.classList.remove("aligned", "moving");
if (alignmentState === "aligned") {
stateBox.classList.add("aligned");
title.textContent = "Datum aligned";
detail.textContent = "A / B / C contacts established";
} else if (alignmentState === "aligning") {
stateBox.classList.add("moving");
title.textContent = "Aligning";
detail.textContent = "Removing translation and yaw error";
} else {
title.textContent = "Raw placement";
const dx = (transform.x - ALIGNED.x) * 10;
const dz = (transform.z - ALIGNED.z) * 10;
detail.textContent = `Datum offset X ${dx.toFixed(1)} / Z ${dz.toFixed(1)} mm`;
}
alignButton.disabled = Boolean(tween) || alignmentState === "aligning";
}
// -------------------------------------------------------------------------
// Probe placement
// -------------------------------------------------------------------------
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function updateProbes() {
updateBounds();
const center = partBounds.getCenter(new THREE.Vector3());
const size = partBounds.getSize(new THREE.Vector3());
const xEnd = new THREE.Vector3(
partBounds.min.x,
center.y,
clamp(-0.10, partBounds.min.z + 0.08, partBounds.max.z - 0.08)
);
const zEnd = new THREE.Vector3(
clamp(-0.40, partBounds.min.x + 0.08, partBounds.max.x - 0.08),
center.y,
partBounds.max.z
);
const yX = clamp(0.35, partBounds.min.x + 0.08, partBounds.max.x - 0.08);
const yZ = clamp(-0.10, partBounds.min.z + 0.08, partBounds.max.z - 0.08);
const yStart = new THREE.Vector3(yX, 3.00, yZ);
const yEnd = new THREE.Vector3(yX, partBounds.max.y, yZ);
setCylinderBetween(xProbe.stem, xProbe.start, xEnd);
setCylinderBetween(zProbe.stem, zProbe.start, zEnd);
setCylinderBetween(yProbe.stem, yStart, yEnd);
xProbe.contact.position.copy(xEnd);
zProbe.contact.position.copy(zEnd);
yProbe.contact.position.copy(yEnd);
// Keep probe tips just above the visible surface.
if (size.y > 0) {
xProbe.contact.position.y += 0.018;
zProbe.contact.position.y += 0.018;
yProbe.contact.position.y -= 0.018;
}
}
// -------------------------------------------------------------------------
// Comparison modal
// -------------------------------------------------------------------------
const compareModal = document.getElementById("compareModal");
const compareRows = document.getElementById("compareRows");
const verdict = document.getElementById("verdict");
function openComparison() {
if (captures.size < 2) return;
compareRows.innerHTML = [...captures.values()].map(capture => {
const maxDelta = Math.max(
Math.abs(capture.aligned.x - NOMINAL.x),
Math.abs(capture.aligned.y - NOMINAL.y),
Math.abs(capture.aligned.z - NOMINAL.z)
);
return `
<tr>
<td>${capture.code} / ${capture.id}</td>
<td>${capture.raw.x.toFixed(1)} / ${capture.raw.z.toFixed(1)}</td>
<td>
${capture.aligned.x.toFixed(1)} /
${capture.aligned.y.toFixed(1)} /
${capture.aligned.z.toFixed(1)}
</td>
<td>${maxDelta.toFixed(2)}</td>
<td class="pass">PASS</td>
</tr>
`;
}).join("");
verdict.innerHTML = `
<strong>Datum normalization: pass</strong>
${captures.size} aligned placement${captures.size === 1 ? "" : "s"} are
within ±0.02 mm of the normalized nominal envelope.
Raw placement offsets no longer affect the comparison.
`;
compareModal.hidden = false;
}
document.getElementById("compareButton").addEventListener("click", openComparison);
document.getElementById("closeModal").addEventListener("click", () => {
compareModal.hidden = true;
});
compareModal.addEventListener("click", event => {
if (event.target === compareModal) compareModal.hidden = true;
});
window.addEventListener("keydown", event => {
if (event.target instanceof HTMLInputElement) return;
if (event.key === "Escape") compareModal.hidden = true;
if (event.key === "1") selectPlacement("A");
if (event.key === "2") selectPlacement("B");
if (event.key === "3") selectPlacement("C");
if (event.key.toLowerCase() === "a") alignAndCapture();
if (event.key.toLowerCase() === "c") openComparison();
});
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
const resizeObserver = new ResizeObserver(() => {
const width = stage.clientWidth;
const height = stage.clientHeight;
if (!width || !height) return;
renderer.setSize(width, height);
camera.aspect = width / height;
camera.updateProjectionMatrix();
});
resizeObserver.observe(stage);
function animate(now) {
if (tween) {
const t = THREE.MathUtils.clamp(
(now - tween.start) / tween.duration,
0,
1
);
const eased = 1 - Math.pow(1 - t, 3);
transform.x = THREE.MathUtils.lerp(tween.from.x, tween.to.x, eased);
transform.z = THREE.MathUtils.lerp(tween.from.z, tween.to.z, eased);
transform.yaw = THREE.MathUtils.lerp(tween.from.yaw, tween.to.yaw, eased);
partGroup.position.set(transform.x, SURFACE_Y, transform.z);
partGroup.rotation.y = THREE.MathUtils.degToRad(transform.yaw);
if (t >= 1) {
const callback = tween.callback;
tween = null;
if (callback) callback();
updatePlacementUI();
}
}
updateProbes();
updateLiveReadout();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updatePlacementUI();
updateLiveReadout();
requestAnimationFrame(animate);
</script>
</body>
</html>
```