Prompt specification
Build or customize the Three.js 3D scene "Workshop Acceptance 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 Acceptance Inspection Table
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/workshop-acceptance-inspection-table-x2047
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows measurement uncertainty, resolution, and bias. Build a toy inspection station comparing measured dimensions with declared tolerances. Show uncertain borderline decisions rather than pretending every reading perfectly identifies the true size. Voxel style.
Working Three.js Starter (workshop-acceptance-inspection-table-x2047):
```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="#080c14" />
<title>Voxel Tolerance Lab — Measurement Uncertainty</title>
<style>
:root {
--bg: #080c14;
--panel: rgba(13, 19, 29, 0.9);
--panel-solid: #0d131d;
--line: rgba(159, 199, 219, 0.17);
--line-strong: rgba(159, 199, 219, 0.3);
--text: #e9f2f5;
--muted: #8ea3ad;
--cyan: #68e3e5;
--cyan-dark: #237f8a;
--amber: #ffbd66;
--amber-dark: #7b4d1f;
--green: #78e3a3;
--red: #ff7d70;
--purple: #b89cff;
--mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
--sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: var(--sans);
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#app {
position: relative;
width: 100vw;
height: 100vh;
overflow: hidden;
isolation: isolate;
}
#scene {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.vignette {
position: absolute;
inset: 0;
pointer-events: none;
z-index: 1;
background:
radial-gradient(circle at 50% 46%, transparent 42%, rgba(2, 5, 10, 0.42) 100%),
linear-gradient(180deg, rgba(2, 5, 10, 0.12), transparent 20%, transparent 80%, rgba(2, 5, 10, 0.4));
}
.scanlines {
position: absolute;
inset: 0;
pointer-events: none;
z-index: 2;
opacity: 0.12;
background: repeating-linear-gradient(
180deg,
transparent 0,
transparent 3px,
rgba(137, 226, 234, 0.055) 4px
);
mix-blend-mode: screen;
}
.topbar {
position: absolute;
top: 18px;
left: 22px;
right: 22px;
z-index: 10;
min-height: 54px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
pointer-events: none;
}
.brand,
.top-actions {
pointer-events: auto;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 250px;
text-shadow: 0 2px 15px #000;
}
.brand-mark {
width: 34px;
height: 34px;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
gap: 3px;
transform: rotate(-8deg);
}
.brand-mark i {
display: block;
background: var(--cyan);
box-shadow: 0 0 14px rgba(104, 227, 229, 0.38);
}
.brand-mark i:nth-child(1) { opacity: 0.35; }
.brand-mark i:nth-child(2) { opacity: 0.65; }
.brand-mark i:nth-child(3) { opacity: 0.35; }
.brand-mark i:nth-child(4) { opacity: 0.7; }
.brand-mark i:nth-child(5) { opacity: 1; }
.brand-mark i:nth-child(6) { opacity: 0.55; }
.brand-mark i:nth-child(7) { opacity: 0.25; }
.brand-mark i:nth-child(8) { opacity: 0.8; }
.brand-mark i:nth-child(9) { opacity: 0.3; }
.brand h1 {
margin: 0;
font-family: var(--mono);
font-size: 15px;
font-weight: 700;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.brand p {
margin: 3px 0 0;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.04em;
}
.top-actions {
display: flex;
align-items: center;
gap: 8px;
flex-wrap: wrap;
justify-content: flex-end;
}
.model-pill,
.button,
.icon-button {
border: 1px solid var(--line-strong);
background: rgba(11, 18, 28, 0.82);
backdrop-filter: blur(12px);
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
}
.model-pill {
display: flex;
align-items: center;
gap: 8px;
padding: 9px 11px;
color: #b8c9cf;
font-family: var(--mono);
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.model-dot {
width: 7px;
height: 7px;
background: var(--green);
box-shadow: 0 0 10px var(--green);
animation: pulse 2s infinite;
}
@keyframes pulse {
0%, 100% { opacity: 0.55; }
50% { opacity: 1; }
}
.button,
.icon-button {
min-height: 36px;
padding: 0 13px;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
cursor: pointer;
color: #d8e5e9;
font-family: var(--mono);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.07em;
text-transform: uppercase;
transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}
.button:hover,
.icon-button:hover {
border-color: rgba(104, 227, 229, 0.65);
background: rgba(25, 44, 54, 0.92);
transform: translateY(-1px);
}
.button:active,
.icon-button:active {
transform: translateY(0);
}
.button.primary {
color: #061014;
border-color: var(--cyan);
background: var(--cyan);
}
.button.primary:hover {
background: #92eeee;
}
.button.small {
min-height: 30px;
padding: 0 10px;
font-size: 9px;
}
.icon-button {
width: 36px;
padding: 0;
font-size: 15px;
}
.panel {
position: absolute;
z-index: 8;
background: var(--panel);
border: 1px solid var(--line);
box-shadow: 0 22px 70px rgba(0, 0, 0, 0.38);
backdrop-filter: blur(16px);
pointer-events: auto;
}
.left-panel {
top: 90px;
left: 22px;
width: 286px;
max-height: calc(100vh - 132px);
overflow: auto;
}
.right-panel {
top: 90px;
right: 22px;
width: 350px;
max-height: calc(100vh - 132px);
overflow: auto;
}
.panel::-webkit-scrollbar {
width: 5px;
}
.panel::-webkit-scrollbar-thumb {
background: rgba(104, 227, 229, 0.25);
}
.panel-section {
padding: 16px;
border-bottom: 1px solid var(--line);
}
.panel-section:last-child {
border-bottom: 0;
}
.eyebrow {
margin: 0 0 7px;
color: var(--cyan);
font-family: var(--mono);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.part-title {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 10px;
}
.part-title h2 {
margin: 0;
font-size: 23px;
line-height: 1;
letter-spacing: -0.04em;
}
.part-code {
margin-top: 6px;
color: var(--muted);
font-family: var(--mono);
font-size: 10px;
}
.status-chip {
padding: 5px 7px;
border: 1px solid rgba(255, 189, 102, 0.35);
background: rgba(255, 189, 102, 0.08);
color: var(--amber);
font-family: var(--mono);
font-size: 8px;
letter-spacing: 0.1em;
text-transform: uppercase;
white-space: nowrap;
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 11px;
color: #c6d5da;
font-family: var(--mono);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.section-heading span:last-child {
color: var(--muted);
font-weight: 500;
}
.dimension-list {
display: grid;
gap: 6px;
}
.dimension-button {
width: 100%;
padding: 10px;
display: grid;
grid-template-columns: 1fr auto;
gap: 4px 8px;
text-align: left;
border: 1px solid transparent;
background: rgba(255, 255, 255, 0.025);
cursor: pointer;
transition: 150ms ease;
}
.dimension-button:hover {
background: rgba(104, 227, 229, 0.055);
border-color: rgba(104, 227, 229, 0.2);
}
.dimension-button.active {
background: rgba(104, 227, 229, 0.09);
border-color: rgba(104, 227, 229, 0.42);
box-shadow: inset 3px 0 0 var(--cyan);
}
.dimension-name {
color: #dce8eb;
font-size: 11px;
font-weight: 650;
}
.dimension-value {
color: #fff;
font-family: var(--mono);
font-size: 11px;
text-align: right;
}
.dimension-meta {
grid-column: 1 / -1;
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
color: var(--muted);
font-family: var(--mono);
font-size: 8px;
}
.state-pill {
display: inline-flex;
align-items: center;
gap: 5px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.state-pill::before {
content: "";
width: 5px;
height: 5px;
background: currentColor;
}
.state-pill.uncertain { color: var(--amber); }
.state-pill.pass { color: var(--green); }
.state-pill.fail { color: var(--red); }
.spec-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.spec-cell {
min-height: 58px;
padding: 9px 10px;
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.02);
}
.spec-cell.wide {
grid-column: 1 / -1;
}
.cell-label {
display: block;
margin-bottom: 6px;
color: var(--muted);
font-family: var(--mono);
font-size: 8px;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.cell-value {
color: #eaf5f7;
font-family: var(--mono);
font-size: 13px;
font-weight: 650;
}
.sample-actions {
display: flex;
gap: 6px;
margin-bottom: 10px;
}
.sample-actions .button {
flex: 1;
}
.history-wrap {
position: relative;
height: 62px;
margin-top: 10px;
overflow: hidden;
border: 1px solid var(--line);
background:
linear-gradient(rgba(104, 227, 229, 0.04) 1px, transparent 1px),
linear-gradient(90deg, rgba(104, 227, 229, 0.04) 1px, transparent 1px),
rgba(0, 0, 0, 0.12);
background-size: 24px 20px;
}
#historyPlot {
width: 100%;
height: 100%;
display: block;
}
.layer-list {
display: grid;
gap: 8px;
}
.layer-toggle {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
color: #b9c9cf;
font-size: 10px;
cursor: pointer;
}
.layer-toggle span {
display: flex;
align-items: center;
gap: 8px;
}
.layer-dot {
width: 7px;
height: 7px;
background: var(--cyan);
}
.layer-dot.amber { background: var(--amber); }
.layer-dot.coral { background: var(--red); }
.layer-dot.green { background: var(--green); }
.switch {
position: relative;
width: 28px;
height: 15px;
flex: 0 0 auto;
}
.switch input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.switch i {
position: absolute;
inset: 0;
border: 1px solid var(--line-strong);
background: rgba(255, 255, 255, 0.06);
}
.switch i::after {
content: "";
position: absolute;
width: 9px;
height: 9px;
top: 2px;
left: 2px;
background: #83969f;
transition: 150ms ease;
}
.switch input:checked + i {
border-color: rgba(104, 227, 229, 0.65);
background: rgba(104, 227, 229, 0.12);
}
.switch input:checked + i::after {
left: 15px;
background: var(--cyan);
}
.decision-panel {
padding: 18px;
background:
linear-gradient(145deg, rgba(255, 189, 102, 0.055), transparent 42%),
var(--panel);
}
.decision-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 12px;
}
.decision-badge {
padding: 6px 8px;
border: 1px solid currentColor;
background: rgba(255, 189, 102, 0.07);
color: var(--amber);
font-family: var(--mono);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.decision-badge.pass {
color: var(--green);
background: rgba(120, 227, 163, 0.07);
}
.decision-badge.fail {
color: var(--red);
background: rgba(255, 125, 112, 0.07);
}
.decision-title {
margin: 0;
font-size: 25px;
line-height: 1.08;
letter-spacing: -0.045em;
}
.decision-sub {
margin: 8px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.probability-row {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 14px;
margin: 18px 0 8px;
}
.probability-value {
font-family: var(--mono);
font-size: 30px;
font-weight: 750;
color: var(--amber);
line-height: 1;
}
.probability-label {
max-width: 155px;
color: var(--muted);
font-size: 9px;
line-height: 1.45;
text-align: right;
}
.probability-track {
position: relative;
height: 8px;
overflow: hidden;
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.04);
}
.probability-fill {
width: 0;
height: 100%;
background: linear-gradient(90deg, #b37a33, var(--amber));
box-shadow: 0 0 18px rgba(255, 189, 102, 0.35);
transition: width 350ms ease;
}
.probability-half {
position: absolute;
top: 0;
bottom: 0;
left: 50%;
width: 1px;
background: rgba(255, 255, 255, 0.36);
}
.interval-box {
margin-top: 17px;
padding: 12px;
border: 1px solid var(--line);
background: rgba(0, 0, 0, 0.13);
}
.interval-topline {
display: flex;
justify-content: space-between;
gap: 10px;
margin-bottom: 10px;
color: var(--muted);
font-family: var(--mono);
font-size: 8px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.interval-scale {
position: relative;
height: 28px;
margin: 0 4px;
}
.interval-axis {
position: absolute;
left: 0;
right: 0;
top: 13px;
height: 1px;
background: var(--line-strong);
}
.allowed-zone {
position: absolute;
top: 8px;
height: 11px;
left: 40%;
width: 20%;
border: 1px solid rgba(120, 227, 163, 0.55);
background: rgba(120, 227, 163, 0.16);
}
.ci-bar {
position: absolute;
top: 10px;
height: 7px;
left: 30%;
width: 40%;
min-width: 2px;
background: var(--amber);
box-shadow: 0 0 10px rgba(255, 189, 102, 0.25);
}
.center-dot {
position: absolute;
top: 6px;
left: 50%;
width: 2px;
height: 15px;
background: #fff;
}
.interval-legend {
display: flex;
justify-content: space-between;
margin-top: 2px;
color: #6f858f;
font-family: var(--mono);
font-size: 7px;
}
.interval-text {
margin-top: 10px;
color: #e6eff2;
font-family: var(--mono);
font-size: 11px;
line-height: 1.45;
}
.overlap-text {
margin-top: 4px;
color: var(--amber);
font-size: 9px;
line-height: 1.45;
}
.truth-readout {
display: none;
margin-top: 10px;
padding: 8px 9px;
border-left: 2px solid var(--green);
background: rgba(120, 227, 163, 0.06);
color: #bfeacf;
font-family: var(--mono);
font-size: 9px;
}
.truth-readout.visible {
display: block;
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.metric {
min-height: 61px;
padding: 9px 10px;
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.02);
}
.metric-label {
display: block;
margin-bottom: 7px;
color: var(--muted);
font-family: var(--mono);
font-size: 8px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.metric-value {
color: #edf7f9;
font-family: var(--mono);
font-size: 14px;
font-weight: 650;
}
.metric-value.amber { color: var(--amber); }
.metric-value.cyan { color: var(--cyan); }
.metric-value.coral { color: var(--red); }
.metric-value.green { color: var(--green); }
.budget-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
padding: 8px 0;
border-bottom: 1px dashed rgba(159, 199, 219, 0.11);
font-size: 10px;
}
.budget-row:last-child {
border-bottom: 0;
}
.budget-row span:first-child {
color: var(--muted);
}
.budget-row span:last-child {
color: #dce8eb;
font-family: var(--mono);
font-size: 9px;
}
.caveat {
margin: 0;
padding: 12px;
border-left: 2px solid var(--amber);
background: rgba(255, 189, 102, 0.055);
color: #aebdc3;
font-size: 9px;
line-height: 1.55;
}
.caveat strong {
color: var(--amber);
}
.bottom-strip {
position: absolute;
z-index: 7;
left: 326px;
right: 390px;
bottom: 20px;
min-height: 38px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
padding: 0 14px;
border: 1px solid var(--line);
background: rgba(8, 13, 21, 0.76);
backdrop-filter: blur(12px);
color: var(--muted);
font-family: var(--mono);
font-size: 8px;
letter-spacing: 0.05em;
pointer-events: none;
}
.legend {
display: flex;
align-items: center;
gap: 13px;
flex-wrap: wrap;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
white-space: nowrap;
}
.legend-swatch {
width: 8px;
height: 8px;
background: var(--cyan);
}
.legend-swatch.amber { background: var(--amber); }
.legend-swatch.green { background: var(--green); }
.legend-swatch.coral { background: var(--red); }
.world-labels {
position: absolute;
inset: 0;
z-index: 4;
pointer-events: none;
overflow: hidden;
}
.world-label {
position: absolute;
left: 0;
top: 0;
padding: 4px 6px;
border: 1px solid rgba(104, 227, 229, 0.25);
background: rgba(5, 11, 18, 0.82);
color: #b9d7dc;
font-family: var(--mono);
font-size: 8px;
white-space: nowrap;
transform: translate(-50%, -50%);
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.32);
}
.world-label.amber {
color: var(--amber);
border-color: rgba(255, 189, 102, 0.35);
}
.world-label.green {
color: var(--green);
border-color: rgba(120, 227, 163, 0.35);
}
.world-label.title {
color: #e7f6f8;
font-weight: 700;
letter-spacing: 0.08em;
}
.toast {
position: absolute;
z-index: 20;
left: 50%;
bottom: 74px;
max-width: min(460px, calc(100vw - 30px));
padding: 10px 14px;
border: 1px solid rgba(104, 227, 229, 0.35);
background: rgba(8, 15, 23, 0.94);
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.4);
color: #dcebed;
font-family: var(--mono);
font-size: 9px;
text-align: center;
transform: translate(-50%, 12px);
opacity: 0;
pointer-events: none;
transition: 220ms ease;
}
.toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
.loading {
position: absolute;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: var(--bg);
transition: opacity 350ms ease, visibility 350ms ease;
}
.loading.hide {
opacity: 0;
visibility: hidden;
}
.loading-content {
text-align: center;
font-family: var(--mono);
color: var(--muted);
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.loading-blocks {
display: flex;
justify-content: center;
gap: 5px;
margin-bottom: 18px;
}
.loading-blocks i {
width: 12px;
height: 12px;
background: var(--cyan);
animation: loadBlocks 900ms infinite alternate;
}
.loading-blocks i:nth-child(2) { animation-delay: 120ms; }
.loading-blocks i:nth-child(3) { animation-delay: 240ms; }
.loading-blocks i:nth-child(4) { animation-delay: 360ms; }
@keyframes loadBlocks {
from { opacity: 0.2; transform: translateY(4px); }
to { opacity: 1; transform: translateY(-4px); }
}
@media (max-width: 980px) {
.left-panel {
width: 255px;
}
.right-panel {
width: 315px;
}
.bottom-strip {
left: 294px;
right: 354px;
}
.model-pill {
display: none;
}
}
@media (max-width: 760px) {
.topbar {
top: 10px;
left: 10px;
right: 10px;
align-items: flex-start;
}
.brand p {
display: none;
}
.top-actions {
gap: 5px;
}
.button {
min-height: 32px;
padding: 0 9px;
font-size: 8px;
}
.icon-button {
width: 32px;
min-height: 32px;
}
.left-panel {
top: auto;
left: 10px;
bottom: 10px;
width: calc(50% - 15px);
max-height: 43vh;
}
.right-panel {
top: 56px;
right: 10px;
width: calc(50% - 15px);
max-height: calc(100vh - 66px);
}
.bottom-strip {
display: none;
}
.panel-section {
padding: 12px;
}
.decision-panel {
padding: 13px;
}
.decision-title {
font-size: 20px;
}
.probability-value {
font-size: 25px;
}
}
</style>
</head>
<body>
<div id="app">
<canvas id="scene" aria-label="Interactive 3D voxel inspection station"></canvas>
<div class="vignette"></div>
<div class="scanlines"></div>
<header class="topbar">
<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>
<h1>Tolerance / Lab</h1>
<p>Voxel inspection cell · uncertainty-aware metrology</p>
</div>
</div>
<div class="top-actions">
<div class="model-pill">
<span class="model-dot"></span>
<span>Model online · n = <span id="topSampleCount">5</span></span>
</div>
<button class="button primary" id="sampleBatch" title="Take eight simulated readings">
+ 8 readings
</button>
<button class="button" id="truthButton">Reveal truth</button>
<button class="icon-button" id="resetCamera" title="Reset camera" aria-label="Reset camera">⌂</button>
</div>
</header>
<section class="panel left-panel" aria-label="Workpiece and measurement controls">
<div class="panel-section">
<p class="eyebrow">Active workpiece</p>
<div class="part-title">
<div>
<h2>WP–042</h2>
<div class="part-code">VOX-SHAFT / REV C / CELL 03</div>
</div>
<div class="status-chip">Simulated</div>
</div>
</div>
<div class="panel-section">
<div class="section-heading">
<span>Declared characteristics</span>
<span>3 dimensions</span>
</div>
<div class="dimension-list" id="dimensionList"></div>
</div>
<div class="panel-section">
<div class="section-heading">
<span>Specification</span>
<span id="specDimensionCode">DIM–01</span>
</div>
<div class="spec-grid">
<div class="spec-cell">
<span class="cell-label">Nominal</span>
<span class="cell-value" id="specNominal">50.000 mm</span>
</div>
<div class="spec-cell">
<span class="cell-label">Tolerance</span>
<span class="cell-value" id="specTol">± 0.350 mm</span>
</div>
<div class="spec-cell wide">
<span class="cell-label">Lower / upper limits</span>
<span class="cell-value" id="specLimits">49.650 / 50.350 mm</span>
</div>
</div>
</div>
<div class="panel-section">
<div class="section-heading">
<span>Reading history</span>
<span id="sampleCount">5 readings</span>
</div>
<div class="sample-actions">
<button class="button small" id="sampleOne">+ 1 reading</button>
<button class="button small" id="sampleBatchSmall">+ 8 readings</button>
<button class="button small" id="resetSamples">Reset</button>
</div>
<div class="history-wrap">
<svg id="historyPlot" viewBox="0 0 250 62" preserveAspectRatio="none"></svg>
</div>
</div>
<div class="panel-section">
<div class="section-heading">
<span>Visual layers</span>
<span>Live</span>
</div>
<div class="layer-list">
<label class="layer-toggle">
<span><i class="layer-dot amber"></i>Uncertainty field</span>
<span class="switch"><input type="checkbox" id="uncertaintyToggle" checked /><i></i></span>
</label>
<label class="layer-toggle">
<span><i class="layer-dot coral"></i>Raw vs. corrected estimate</span>
<span class="switch"><input type="checkbox" id="biasToggle" checked /><i></i></span>
</label>
<label class="layer-toggle">
<span><i class="layer-dot green"></i>Reference truth</span>
<span class="switch"><input type="checkbox" id="truthToggle" /><i></i></span>
</label>
</div>
</div>
</section>
<section class="panel right-panel" aria-label="Measurement decision">
<div class="decision-panel">
<div class="decision-head">
<p class="eyebrow" id="decisionDimension">DIM–01 · OVERALL LENGTH</p>
<span class="decision-badge" id="statusBadge">INDETERMINATE</span>
</div>
<h2 class="decision-title" id="decisionTitle">Borderline — not conclusive</h2>
<p class="decision-sub" id="decisionSub">
The plausible interval crosses a declared limit. A point estimate cannot establish conformity.
</p>
<div class="probability-row">
<div class="probability-value" id="probabilityValue">69%</div>
<div class="probability-label">
plausible mass inside limits<br />
normal measurement model
</div>
</div>
<div class="probability-track">
<div class="probability-fill" id="probabilityFill"></div>
<div class="probability-half"></div>
</div>
<div class="interval-box">
<div class="interval-topline">
<span>95% plausible interval</span>
<span>deviation rail</span>
</div>
<div class="interval-scale">
<div class="interval-axis"></div>
<div class="allowed-zone" id="allowedZone"></div>
<div class="ci-bar" id="ciBar"></div>
<div class="center-dot" id="centerDot"></div>
</div>
<div class="interval-legend">
<span>LOWER LIMIT</span>
<span>ESTIMATE</span>
<span>UPPER LIMIT</span>
</div>
<div class="interval-text" id="ciText">49.999 — 50.557 mm</div>
<div class="overlap-text" id="overlapText">Upper-limit overlap: 0.207 mm</div>
<div class="truth-readout" id="truthReadout">Simulator reference truth: —</div>
</div>
</div>
<div class="panel-section">
<div class="section-heading">
<span>Measurement result</span>
<span>Bias corrected</span>
</div>
<div class="metric-grid">
<div class="metric">
<span class="metric-label">Raw mean</span>
<span class="metric-value" id="metricRaw">50.328 mm</span>
</div>
<div class="metric">
<span class="metric-label">Corrected</span>
<span class="metric-value cyan" id="metricCorrected">50.278 mm</span>
</div>
<div class="metric">
<span class="metric-label">Expanded U95</span>
<span class="metric-value amber" id="metricUncertainty">± 0.279 mm</span>
</div>
<div class="metric">
<span class="metric-label">Resolution</span>
<span class="metric-value" id="metricResolution">0.020 mm</span>
</div>
<div class="metric">
<span class="metric-label">Known bias</span>
<span class="metric-value coral" id="metricBias">+0.050 mm</span>
</div>
<div class="metric">
<span class="metric-label">Sample count</span>
<span class="metric-value green" id="metricCount">n = 5</span>
</div>
</div>
</div>
<div class="panel-section">
<div class="section-heading">
<span>Uncertainty budget</span>
<span>standard uncertainty</span>
</div>
<div class="budget-row">
<span>Repeatability σ / √n</span>
<span id="budgetRepeat">0.076 mm</span>
</div>
<div class="budget-row">
<span>Fixed / calibration u</span>
<span id="budgetFixed">0.120 mm</span>
</div>
<div class="budget-row">
<span>Quantization r / √12</span>
<span id="budgetQuant">0.006 mm</span>
</div>
<div class="budget-row">
<span>Combined standard u</span>
<span id="budgetCombined">0.142 mm</span>
</div>
</div>
<div class="panel-section">
<p class="caveat">
<strong>Not every reading identifies the true size.</strong>
Conformity is only conclusive when the full plausible interval lies
inside—or entirely outside—the declared limits. This toy model assumes
a normal measurement distribution and does not replace a calibrated
decision rule.
</p>
</div>
</section>
<div class="world-labels" id="worldLabels" aria-hidden="true">
<span class="world-label title" id="labelGauge">OVERALL LENGTH · DECISION RAIL</span>
<span class="world-label green" id="labelLow">LOW</span>
<span class="world-label" id="labelNominal">NOM</span>
<span class="world-label green" id="labelHigh">HIGH</span>
<span class="world-label amber" id="labelEstimate">EST</span>
<span class="world-label green" id="labelTruth">TRUTH</span>
</div>
<div class="bottom-strip">
<div class="legend">
<span class="legend-item"><i class="legend-swatch"></i>Voxel / geometry</span>
<span class="legend-item"><i class="legend-swatch amber"></i>Estimate + uncertainty</span>
<span class="legend-item"><i class="legend-swatch green"></i>Declared limits</span>
<span class="legend-item"><i class="legend-swatch coral"></i>Raw estimate</span>
</div>
<span>DRAG TO ORBIT · SCROLL TO ZOOM</span>
</div>
<div class="toast" id="toast" role="status" aria-live="polite"></div>
<div class="loading" id="loading">
<div class="loading-content">
<div class="loading-blocks"><i></i><i></i><i></i><i></i></div>
Initializing voxel inspection cell
</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";
const $ = (id) => document.getElementById(id);
const clamp = (v, a, b) => Math.max(a, Math.min(b, v));
const dimensions = [
{
id: "length",
code: "DIM–01",
name: "Overall length",
shortName: "OVERALL LENGTH",
nominal: 50.000,
tolerance: 0.350,
repeatability: 0.170,
fixedU: 0.120,
resolution: 0.020,
bias: 0.050,
trueValue: 50.290,
axis: "x",
geometry: { a: -5.5, b: 4.5 },
initial: [50.32, 50.36, 50.30, 50.34, 50.32]
},
{
id: "diameter",
code: "DIM–02",
name: "Outer diameter",
shortName: "OUTER DIAMETER",
nominal: 20.000,
tolerance: 0.160,
repeatability: 0.060,
fixedU: 0.045,
resolution: 0.010,
bias: -0.020,
trueValue: 19.900,
axis: "y",
geometry: { a: 0.5, b: 5.5 },
initial: [19.88, 19.90, 19.86, 19.89, 19.88]
},
{
id: "collar",
code: "DIM–03",
name: "Collar width",
shortName: "COLLAR WIDTH",
nominal: 12.000,
tolerance: 0.100,
repeatability: 0.045,
fixedU: 0.035,
resolution: 0.010,
bias: 0.020,
trueValue: 12.130,
axis: "x",
geometry: { a: 0.5, b: 2.5 },
initial: [12.14, 12.16, 12.14, 12.15, 12.16]
}
];
for (const d of dimensions) {
d.readings = [...d.initial];
d.lower = d.nominal - d.tolerance;
d.upper = d.nominal + d.tolerance;
}
let currentId = "length";
let showTruth = false;
let toastTimer = null;
const state = {
uncertainty: true,
bias: true
};
const dimensionRows = {};
function currentDimension() {
return dimensions.find((d) => d.id === currentId);
}
function quantize(value, step) {
return Math.round(value / step) * step;
}
function sampleStandardDeviation(values) {
if (values.length < 2) return 0;
const mean = values.reduce((sum, v) => sum + v, 0) / values.length;
const variance = values.reduce((sum, v) => sum + (v - mean) ** 2, 0) / (values.length - 1);
return Math.sqrt(variance);
}
function normalCdf(z) {
const sign = z < 0 ? -1 : 1;
const x = Math.abs(z) / Math.sqrt(2);
const t = 1 / (1 + 0.3275911 * x);
const y = 1 - (((((1.061405429 * t - 1.453152027) * t) + 1.421413741) * t
- 0.284496736) * t + 0.254829592) * t * Math.exp(-x * x);
return 0.5 * (1 + sign * y);
}
function calculate(d) {
const n = d.readings.length;
const rawMean = d.readings.reduce((sum, v) => sum + v, 0) / n;
const sampleSD = sampleStandardDeviation(d.readings);
const corrected = rawMean - d.bias;
const randomU = Math.max(d.repeatability, sampleSD) / Math.sqrt(n);
const quantU = d.resolution / Math.sqrt(12);
const combinedU = Math.sqrt(randomU ** 2 + d.fixedU ** 2 + quantU ** 2);
const expandedU = 1.96 * combinedU;
const ciLow = corrected - expandedU;
const ciHigh = corrected + expandedU;
const probability = clamp(
(normalCdf((d.upper - corrected) / combinedU)
- normalCdf((d.lower - corrected) / combinedU)) * 100,
0,
100
);
let stateName = "uncertain";
if (ciLow >= d.lower && ciHigh <= d.upper) stateName = "pass";
else if (ciHigh < d.lower || ciLow > d.upper) stateName = "fail";
const crossed = [];
if (ciLow < d.lower && ciHigh > d.lower) crossed.push("lower");
if (ciLow < d.upper && ciHigh > d.upper) crossed.push("upper");
let overlapText;
if (!crossed.length) {
overlapText = "No limit overlap: interval is fully inside or fully outside.";
} else {
const parts = crossed.map((which) => {
const limit = which === "lower" ? d.lower : d.upper;
const depth = which === "lower" ? d.lower - ciLow : ciHigh - d.upper;
return `${which}-limit overlap: ${depth.toFixed(3)} mm`;
});
overlapText = parts.join(" · ");
}
const margin = corrected >= d.lower && corrected <= d.upper
? Math.min(corrected - d.lower, d.upper - corrected)
: Math.min(Math.abs(corrected - d.lower), Math.abs(corrected - d.upper));
return {
n,
rawMean,
sampleSD,
corrected,
randomU,
quantU,
combinedU,
expandedU,
ciLow,
ciHigh,
probability,
stateName,
crossed,
overlapText,
margin
};
}
function formatSigned(value, digits = 3) {
return `${value >= 0 ? "+" : "−"}${Math.abs(value).toFixed(digits)}`;
}
function showToast(message) {
$("toast").textContent = message;
$("toast").classList.add("visible");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => $("toast").classList.remove("visible"), 2600);
}
function buildDimensionList() {
const list = $("dimensionList");
list.innerHTML = "";
for (const d of dimensions) {
const button = document.createElement("button");
button.className = "dimension-button";
button.innerHTML = `
<span class="dimension-name">${d.name}</span>
<span class="dimension-value"></span>
<span class="dimension-meta">
<span class="dimension-interval"></span>
<span class="state-pill"></span>
</span>
`;
button.addEventListener("click", () => selectDimension(d.id));
list.appendChild(button);
dimensionRows[d.id] = {
button,
value: button.querySelector(".dimension-value"),
interval: button.querySelector(".dimension-interval"),
state: button.querySelector(".state-pill")
};
}
}
function updateDimensionRows() {
for (const d of dimensions) {
const c = calculate(d);
const row = dimensionRows[d.id];
row.button.classList.toggle("active", d.id === currentId);
row.value.textContent = `${c.rawMean.toFixed(3)} mm`;
row.interval.textContent = `U95 ±${c.expandedU.toFixed(3)}`;
row.state.className = `state-pill ${c.stateName}`;
row.state.textContent = c.stateName === "uncertain"
? "Borderline"
: c.stateName === "pass" ? "Confirmed" : "Outside";
}
}
function updateHistory(d) {
const values = d.readings;
if (!values.length) return;
let min = Math.min(...values);
let max = Math.max(...values);
const pad = Math.max((max - min) * 0.25, d.resolution * 1.5);
min -= pad;
max += pad;
const x = (i) => values.length === 1 ? 125 : 10 + (i / (values.length - 1)) * 230;
const y = (v) => 8 + ((max - v) / (max - min)) * 46;
const points = values.map((v, i) => `${x(i).toFixed(1)},${y(v).toFixed(1)}`).join(" ");
const circles = values.map((v, i) =>
`<circle cx="${x(i).toFixed(1)}" cy="${y(v).toFixed(1)}" r="2.2" fill="#68e3e5" />`
).join("");
const nominalY = y(d.nominal);
$("historyPlot").innerHTML = `
<line x1="7" y1="${nominalY}" x2="243" y2="${nominalY}"
stroke="rgba(120,227,163,.42)" stroke-dasharray="3 4" />
<polyline points="${points}" fill="none" stroke="#68e3e5" stroke-width="1.7" />
${circles}
`;
}
function updateUI() {
const d = currentDimension();
const c = calculate(d);
$("decisionDimension").textContent = `${d.code} · ${d.shortName}`;
$("specDimensionCode").textContent = d.code;
$("specNominal").textContent = `${d.nominal.toFixed(3)} mm`;
$("specTol").textContent = `± ${d.tolerance.toFixed(3)} mm`;
$("specLimits").textContent = `${d.lower.toFixed(3)} / ${d.upper.toFixed(3)} mm`;
$("sampleCount").textContent = `${c.n} reading${c.n === 1 ? "" : "s"}`;
$("topSampleCount").textContent = c.n;
const badge = $("statusBadge");
badge.className = `decision-badge ${c.stateName}`;
badge.textContent = c.stateName === "uncertain"
? "INDETERMINATE"
: c.stateName === "pass" ? "CONFIRMED PASS" : "CONFIRMED FAIL";
if (c.stateName === "pass") {
$("decisionTitle").textContent = "Within declared limits";
$("decisionSub").textContent = "The full 95% plausible interval is inside the specification.";
} else if (c.stateName === "fail") {
$("decisionTitle").textContent = "Outside declared limits";
$("decisionSub").textContent = "The full 95% plausible interval lies outside the specification.";
} else {
$("decisionTitle").textContent = "Borderline — not conclusive";
$("decisionSub").textContent = "The plausible interval crosses a declared limit. A point estimate cannot establish conformity.";
}
$("probabilityValue").textContent = `${Math.round(c.probability)}%`;
$("probabilityFill").style.width = `${c.probability}%`;
$("probabilityFill").style.background = c.stateName === "pass"
? "linear-gradient(90deg, #347e58, #78e3a3)"
: c.stateName === "fail"
? "linear-gradient(90deg, #813a35, #ff7d70)"
: "linear-gradient(90deg, #b37a33, #ffbd66)";
$("ciText").textContent = `${c.ciLow.toFixed(3)} — ${c.ciHigh.toFixed(3)} mm`;
$("overlapText").textContent = c.overlapText;
const scaleMin = d.nominal - d.tolerance * 1.7;
const scaleMax = d.nominal + d.tolerance * 1.7;
const pct = (v) => clamp((v - scaleMin) / (scaleMax - scaleMin) * 100, 0, 100);
const lowPct = pct(d.lower);
const highPct = pct(d.upper);
const ciLowPct = pct(c.ciLow);
const ciHighPct = pct(c.ciHigh);
const centerPct = pct(c.corrected);
$("allowedZone").style.left = `${lowPct}%`;
$("allowedZone").style.width = `${highPct - lowPct}%`;
$("ciBar").style.left = `${ciLowPct}%`;
$("ciBar").style.width = `${Math.max(ciHighPct - ciLowPct, 0.5)}%`;
$("centerDot").style.left = `${centerPct}%`;
$("metricRaw").textContent = `${c.rawMean.toFixed(3)} mm`;
$("metricCorrected").textContent = `${c.corrected.toFixed(3)} mm`;
$("metricUncertainty").textContent = `± ${c.expandedU.toFixed(3)} mm`;
$("metricResolution").textContent = `${d.resolution.toFixed(3)} mm`;
$("metricBias").textContent = `${formatSigned(d.bias)} mm`;
$("metricCount").textContent = `n = ${c.n}`;
$("budgetRepeat").textContent = `${c.randomU.toFixed(3)} mm`;
$("budgetFixed").textContent = `${d.fixedU.toFixed(3)} mm`;
$("budgetQuant").textContent = `${c.quantU.toFixed(3)} mm`;
$("budgetCombined").textContent = `${c.combinedU.toFixed(3)} mm`;
$("truthReadout").classList.toggle("visible", showTruth);
$("truthReadout").textContent = `Simulator reference truth: ${d.trueValue.toFixed(3)} mm`;
updateDimensionRows();
updateHistory(d);
updateTruthVisibility();
}
// ---------------------------------------------------------------------
// Three.js scene
// ---------------------------------------------------------------------
const canvas = $("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x080c14);
scene.fog = new THREE.Fog(0x080c14, 18, 42);
const camera = new THREE.PerspectiveCamera(42, window.innerWidth / window.innerHeight, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 2.7, 0);
const cameraSpherical = new THREE.Spherical(21.5, 1.04, 0.82);
const targetSpherical = cameraSpherical.clone();
function applyCamera() {
const offset = new THREE.Vector3().setFromSpherical(cameraSpherical);
camera.position.copy(cameraTarget).add(offset);
camera.lookAt(cameraTarget);
}
applyCamera();
const hemi = new THREE.HemisphereLight(0xb9e8ff, 0x15131b, 2.1);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff0d9, 3.2);
key.position.set(7, 14, 8);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -14;
key.shadow.camera.right = 14;
key.shadow.camera.top = 14;
key.shadow.camera.bottom = -14;
key.shadow.camera.near = 1;
key.shadow.camera.far = 35;
key.shadow.bias = -0.0004;
scene.add(key);
const cyanLight = new THREE.PointLight(0x48dce5, 22, 15, 2);
cyanLight.position.set(-5, 6, 5);
scene.add(cyanLight);
const amberLight = new THREE.PointLight(0xff9f4b, 16, 13, 2);
amberLight.position.set(6, 5, -4);
scene.add(amberLight);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.95,
metalness: 0.05
});
const floor = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.92, 0.12, 0.92),
floorMaterial,
23 * 23
);
const dummy = new THREE.Object3D();
const color = new THREE.Color();
let floorIndex = 0;
for (let x = -11; x <= 11; x++) {
for (let z = -11; z <= 11; z++) {
dummy.position.set(x, -0.12, z);
dummy.updateMatrix();
floor.setMatrixAt(floorIndex, dummy.matrix);
const checker = (x + z) % 2 === 0;
color.set(checker ? 0x101924 : 0x0c141e);
floor.setColorAt(floorIndex, color);
floorIndex++;
}
}
floor.receiveShadow = true;
floor.instanceMatrix.needsUpdate = true;
floor.instanceColor.needsUpdate = true;
scene.add(floor);
function makeBlock(width, height, depth, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(width, height, depth), material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const platformMaterial = new THREE.MeshStandardMaterial({
color: 0x172432,
roughness: 0.66,
metalness: 0.36
});
const railMaterial = new THREE.MeshStandardMaterial({
color: 0x315162,
roughness: 0.4,
metalness: 0.65
});
const supportMaterial = new THREE.MeshStandardMaterial({
color: 0xb97036,
roughness: 0.58,
metalness: 0.28,
flatShading: true
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x111821,
roughness: 0.82,
metalness: 0.25
});
makeBlock(13.5, 0.35, 6.4, platformMaterial, 0, 0.18, 0);
makeBlock(13.8, 0.18, 0.36, railMaterial, 0, 0.46, -2.45);
makeBlock(13.8, 0.18, 0.36, railMaterial, 0, 0.46, 2.45);
for (const x of [-3.8, 1.5, 3.9]) {
makeBlock(0.8, 0.55, 4.8, darkMaterial, x, 0.63, 0);
makeBlock(1.25, 0.25, 4.25, supportMaterial, x, 1.0, 0);
}
const wallMaterial = new THREE.MeshStandardMaterial({
color: 0x111c27,
roughness: 0.8,
metalness: 0.15
});
for (let x = -9; x <= 9; x += 2) {
makeBlock(1.8, 3.2, 0.7, wallMaterial, x, 1.5, -8.2);
}
// Voxel workpiece: shaft, enlarged collar and nose.
const partGroup = new THREE.Group();
partGroup.position.y = 3.0;
scene.add(partGroup);
const voxelMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.48,
metalness: 0.2,
flatShading: true,
vertexColors: true
});
const voxelPositions = [];
for (let x = -5; x <= 0; x++) {
for (let y = -1; y <= 1; y++) {
for (let z = -1; z <= 1; z++) {
voxelPositions.push({ x, y, z, type: "shaft" });
}
}
}
for (let x = 1; x <= 2; x++) {
for (let y = -2; y <= 2; y++) {
for (let z = -2; z <= 2; z++) {
if (Math.abs(y) + Math.abs(z) <= 3) {
voxelPositions.push({ x, y, z, type: "collar" });
}
}
}
}
for (let x = 3; x <= 4; x++) {
for (let y = -1; y <= 1; y++) {
for (let z = -1; z <= 1; z++) {
voxelPositions.push({ x, y, z, type: "nose" });
}
}
}
const part = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.94, 0.94, 0.94),
voxelMaterial,
voxelPositions.length
);
voxelPositions.forEach((p, i) => {
dummy.position.set(p.x, p.y, p.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
part.setMatrixAt(i, dummy.matrix);
if (p.type === "collar") color.set(0xd58c49);
else if (p.type === "nose") color.set(0x69d7d6);
else color.set(0x347e8d);
const shade = 0.88 + ((p.x + p.y * 3 + p.z * 7 + 20) % 5) * 0.035;
color.multiplyScalar(shade);
part.setColorAt(i, color);
});
part.castShadow = true;
part.receiveShadow = true;
part.instanceMatrix.needsUpdate = true;
part.instanceColor.needsUpdate = true;
partGroup.add(part);
// Inspection head and voxel beam.
const sensor = new THREE.Group();
scene.add(sensor);
const sensorDark = new THREE.MeshStandardMaterial({
color: 0x17212d,
roughness: 0.4,
metalness: 0.55
});
const sensorCyan = new THREE.MeshStandardMaterial({
color: 0x65e6e7,
emissive: 0x1b9297,
emissiveIntensity: 1.3,
roughness: 0.3,
metalness: 0.3
});
makeBlock(0.28, 1.3, 0.28, sensorDark, 0, 6.4, 1.6, sensor);
makeBlock(1.15, 0.5, 1.05, sensorDark, 0, 7.05, 1.6, sensor);
makeBlock(0.72, 0.14, 0.72, sensorCyan, 0, 6.74, 1.6, sensor);
const beamMaterial = new THREE.MeshBasicMaterial({
color: 0x67e5e7,
transparent: true,
opacity: 0.09,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const beam = new THREE.Mesh(new THREE.BoxGeometry(0.65, 3.1, 0.65), beamMaterial);
beam.position.set(0, 5.1, 1.6);
sensor.add(beam);
const scanMaterial = new THREE.MeshBasicMaterial({
color: 0x5be3e5,
transparent: true,
opacity: 0.045,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const scanBar = new THREE.Mesh(new THREE.BoxGeometry(0.035, 5.15, 5.15), scanMaterial);
scanBar.position.set(-2, 3, 0);
scene.add(scanBar);
// Decision rail: a 1D comparison of declared limits and measurement uncertainty.
const gaugeGroup = new THREE.Group();
gaugeGroup.position.set(0, 7.75, -2.6);
scene.add(gaugeGroup);
const annotationGroup = new THREE.Group();
scene.add(annotationGroup);
const cloudGroup = new THREE.Group();
scene.add(cloudGroup);
let gaugeCloud = null;
let gaugeCloudMaterial = null;
let partCloudMaterial = null;
let gaugeRawMarker = null;
let gaugeTruthMarker = null;
let gaugeBiasLine = null;
let labelAnchors = {};
const gaugeRailMaterial = new THREE.MeshStandardMaterial({
color: 0x263847,
roughness: 0.46,
metalness: 0.52
});
const gaugeAllowedMaterial = new THREE.MeshStandardMaterial({
color: 0x4dba7a,
emissive: 0x143d29,
emissiveIntensity: 0.8,
transparent: true,
opacity: 0.34
});
const gaugeAmberMaterial = new THREE.MeshStandardMaterial({
color: 0xffb75e,
emissive: 0x7a3f0d,
emissiveIntensity: 0.9,
transparent: true,
opacity: 0.82
});
const gaugeWhiteMaterial = new THREE.MeshStandardMaterial({
color: 0xe9f8f8,
emissive: 0x7ea6aa,
emissiveIntensity: 0.5
});
const gaugeRedMaterial = new THREE.MeshStandardMaterial({
color: 0xff786d,
emissive: 0x681d18,
emissiveIntensity: 0.8
});
const gaugeGreenMaterial = new THREE.MeshStandardMaterial({
color: 0x78e3a3,
emissive: 0x246b40,
emissiveIntensity: 0.8
});
function clearGroup(group) {
while (group.children.length) {
const child = group.children.pop();
child.traverse?.((obj) => {
if (obj.geometry) obj.geometry.dispose();
if (obj.material) {
const materials = Array.isArray(obj.material) ? obj.material : [obj.material];
for (const material of materials) material.dispose();
}
});
}
}
function mapToGauge(value, d) {
return ((value - d.nominal) / d.tolerance) * 2.6;
}
function createGauge() {
clearGroup(gaugeGroup);
const d = currentDimension();
const c = calculate(d);
makeBlock(8.2, 0.13, 0.72, gaugeRailMaterial, 0, 0, 0, gaugeGroup);
makeBlock(5.2, 0.16, 0.44, gaugeAllowedMaterial, 0, 0.04, 0, gaugeGroup);
for (let x = -4; x <= 4; x += 1) {
const tick = makeBlock(0.045, 0.35, 0.52, gaugeWhiteMaterial, x, 0.05, 0, gaugeGroup);
tick.scale.y = x === 0 ? 1.35 : 0.65;
}
makeBlock(0.07, 0.65, 0.56, gaugeGreenMaterial, -2.6, 0.08, 0, gaugeGroup);
makeBlock(0.07, 0.65, 0.56, gaugeGreenMaterial, 2.6, 0.08, 0, gaugeGroup);
const intervalLow = mapToGauge(c.ciLow, d);
const intervalHigh = mapToGauge(c.ciHigh, d);
const intervalCenter = (intervalLow + intervalHigh) / 2;
const intervalWidth = Math.max(intervalHigh - intervalLow, 0.04);
makeBlock(intervalWidth, 0.19, 0.26, gaugeAmberMaterial, intervalCenter, 0.18, 0, gaugeGroup);
const correctedPosition = mapToGauge(c.corrected, d);
makeBlock(0.13, 0.72, 0.42, gaugeAmberMaterial, correctedPosition, 0.26, 0, gaugeGroup);
const rawPosition = mapToGauge(c.rawMean, d);
gaugeRawMarker = makeBlock(0.1, 0.55, 0.38, gaugeRedMaterial, rawPosition, 0.32, 0, gaugeGroup);
gaugeBiasLine = makeBlock(
Math.max(Math.abs(rawPosition - correctedPosition), 0.025),
0.035,
0.035,
gaugeRedMaterial,
(rawPosition + correctedPosition) / 2,
0.55,
0,
gaugeGroup
);
const truthPosition = mapToGauge(d.trueValue, d);
gaugeTruthMarker = makeBlock(0.16, 0.9, 0.5, gaugeGreenMaterial, truthPosition, 0.35, 0, gaugeGroup);
const cloudCount = 140;
gaugeCloudMaterial = new THREE.MeshBasicMaterial({
color: 0xffc46f,
transparent: true,
opacity: 0.58,
depthWrite: false
});
gaugeCloud = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.055, 0.055, 0.055),
gaugeCloudMaterial,
cloudCount
);
for (let i = 0; i < cloudCount; i++) {
const t = (i + 0.5) / cloudCount;
const jitter = (Math.random() - 0.5) * 0.25;
dummy.position.set(
intervalLow + (intervalHigh - intervalLow) * t,
0.2 + Math.random() * 0.55,
jitter
);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
gaugeCloud.setMatrixAt(i, dummy.matrix);
}
gaugeCloud.instanceMatrix.needsUpdate = true;
gaugeGroup.add(gaugeCloud);
labelAnchors = {
gauge: new THREE.Vector3(0, 0.95, 0),
low: new THREE.Vector3(-2.6, 0.38, 0),
nominal: new THREE.Vector3(0, 0.38, 0),
high: new THREE.Vector3(2.6, 0.38, 0),
estimate: new THREE.Vector3(correctedPosition, 0.72, 0),
truth: new THREE.Vector3(truthPosition, 0.9, 0)
};
$("labelGauge").textContent = `${d.shortName} · DECISION RAIL`;
$("labelLow").textContent = `LOW ${d.lower.toFixed(3)}`;
$("labelNominal").textContent = `NOM ${d.nominal.toFixed(3)}`;
$("labelHigh").textContent = `HIGH ${d.upper.toFixed(3)}`;
$("labelEstimate").textContent = `EST ${c.corrected.toFixed(3)}`;
$("labelTruth").textContent = `TRUTH ${d.trueValue.toFixed(3)}`;
updateTruthVisibility();
}
function createAnnotation() {
clearGroup(annotationGroup);
const d = currentDimension();
const lineMaterial = new THREE.LineBasicMaterial({
color: 0x72e9ea,
transparent: true,
opacity: 0.9
});
const pointMaterial = new THREE.MeshStandardMaterial({
color: 0x72e9ea,
emissive: 0x1c7f84,
emissiveIntensity: 1.1
});
const points = [];
if (d.axis === "x") {
const { a, b } = d.geometry;
const y = 5.95;
points.push(
new THREE.Vector3(a, y, 0),
new THREE.Vector3(b, y, 0),
new THREE.Vector3(a, y, 0),
new THREE.Vector3(a, 5.25, 0),
new THREE.Vector3(b, y, 0),
new THREE.Vector3(b, 5.25, 0)
);
makeBlock(0.22, 0.22, 0.22, pointMaterial, a, y, 0, annotationGroup);
makeBlock(0.22, 0.22, 0.22, pointMaterial, b, y, 0, annotationGroup);
for (const [x, direction] of [[a, 1], [b, -1]]) {
for (let i = 0; i < 3; i++) {
const arrow = makeBlock(
0.11,
0.11,
0.11,
pointMaterial,
x + direction * (0.18 + i * 0.14),
y,
0,
annotationGroup
);
arrow.scale.y = 1.4 - i * 0.25;
arrow.scale.z = 1.4 - i * 0.25;
}
}
} else {
const { a, b } = d.geometry;
const x = 1.5;
const z = 3.15;
points.push(
new THREE.Vector3(x, a, z),
new THREE.Vector3(x, b, z),
new THREE.Vector3(x, a, z),
new THREE.Vector3(x, a, 0),
new THREE.Vector3(x, b, z),
new THREE.Vector3(x, b, 0)
);
makeBlock(0.22, 0.22, 0.22, pointMaterial, x, a, z, annotationGroup);
makeBlock(0.22, 0.22, 0.22, pointMaterial, x, b, z, annotationGroup);
for (const [y, direction] of [[a, 1], [b, -1]]) {
for (let i = 0; i < 3; i++) {
const arrow = makeBlock(
0.11,
0.11,
0.11,
pointMaterial,
x,
y + direction * (0.18 + i * 0.14),
z,
annotationGroup
);
arrow.scale.x = 1.4 - i * 0.25;
arrow.scale.z = 1.4 - i * 0.25;
}
}
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
annotationGroup.add(new THREE.LineSegments(geometry, lineMaterial));
}
function createPartCloud() {
clearGroup(cloudGroup);
const d = currentDimension();
const count = 190;
partCloudMaterial = new THREE.MeshBasicMaterial({
color: 0xffbd66,
transparent: true,
opacity: 0.48,
depthWrite: false
});
const cloud = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.065, 0.065, 0.065),
partCloudMaterial,
count
);
for (let i = 0; i < count; i++) {
let x, y, z;
if (d.axis === "x") {
const { a, b } = d.geometry;
const end = i % 2 === 0 ? a : b;
const angle = Math.random() * Math.PI * 2;
const radius = Math.sqrt(Math.random()) * 2.15;
x = end + (Math.random() - 0.5) * 0.34;
y = 3 + Math.sin(angle) * radius;
z = Math.cos(angle) * radius;
} else {
const { a, b } = d.geometry;
const end = i % 2 === 0 ? a : b;
const angle = Math.random() * Math.PI * 2;
const radius = Math.sqrt(Math.random()) * 2.1;
x = 1.5 + Math.cos(angle) * radius;
y = end + (Math.random() - 0.5) * 0.34;
z = Math.sin(angle) * radius;
}
dummy.position.set(x, y, z);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
cloud.setMatrixAt(i, dummy.matrix);
}
cloud.instanceMatrix.needsUpdate = true;
cloud.frustumCulled = false;
cloudGroup.add(cloud);
}
function updateTruthVisibility() {
if (gaugeTruthMarker) gaugeTruthMarker.visible = showTruth;
if (gaugeRawMarker) gaugeRawMarker.visible = state.bias;
if (gaugeBiasLine) gaugeBiasLine.visible = state.bias;
if (gaugeCloud) gaugeCloud.visible = state.uncertainty;
if (partCloudMaterial) partCloudMaterial.opacity = state.uncertainty ? 0.48 : 0;
$("truthButton").textContent = showTruth ? "Hide truth" : "Reveal truth";
$("truthToggle").checked = showTruth;
}
function selectDimension(id) {
currentId = id;
createAnnotation();
createPartCloud();
createGauge();
updateUI();
const d = currentDimension();
const c = calculate(d);
showToast(`${d.name}: ${c.rawMean.toFixed(3)} mm · ${c.stateName.toUpperCase()}`);
}
function randomNormal() {
let u = 0;
let v = 0;
while (u === 0) u = Math.random();
while (v === 0) v = Math.random();
return Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
}
function addSamples(count) {
const d = currentDimension();
for (let i = 0; i < count; i++) {
const trueMeasurement = d.trueValue + d.bias + randomNormal() * d.repeatability;
d.readings.push(quantize(trueMeasurement, d.resolution));
}
createGauge();
updateUI();
const c = calculate(d);
showToast(
`${count} reading${count === 1 ? "" : "s"} added · U95 ±${c.expandedU.toFixed(3)} mm · ${c.stateName.toUpperCase()}`
);
}
function resetSamples() {
const d = currentDimension();
d.readings = [...d.initial];
createGauge();
updateUI();
showToast(`${d.name} history reset.`);
}
// ---------------------------------------------------------------------
// Direct camera controls — no Three.js addons.
// ---------------------------------------------------------------------
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
targetSpherical.theta -= dx * 0.006;
targetSpherical.phi = clamp(targetSpherical.phi - dy * 0.005, 0.28, 1.46);
});
function endDrag(event) {
dragging = false;
canvas.style.cursor = "grab";
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.style.cursor = "grab";
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
targetSpherical.radius = clamp(targetSpherical.radius * Math.exp(event.deltaY * 0.001), 11, 34);
}, { passive: false });
function resetCamera() {
targetSpherical.set(21.5, 1.04, 0.82);
showToast("Camera reset.");
}
// ---------------------------------------------------------------------
// UI events
// ---------------------------------------------------------------------
$("sampleBatch").addEventListener("click", () => addSamples(8));
$("sampleBatchSmall").addEventListener("click", () => addSamples(8));
$("sampleOne").addEventListener("click", () => addSamples(1));
$("resetSamples").addEventListener("click", resetSamples);
$("resetCamera").addEventListener("click", resetCamera);
$("truthButton").addEventListener("click", () => {
showTruth = !showTruth;
updateTruthVisibility();
showToast(showTruth
? "Reference truth revealed for simulator comparison."
: "Reference truth hidden.");
});
$("truthToggle").addEventListener("change", (event) => {
showTruth = event.target.checked;
updateTruthVisibility();
});
$("uncertaintyToggle").addEventListener("change", (event) => {
state.uncertainty = event.target.checked;
updateTruthVisibility();
});
$("biasToggle").addEventListener("change", (event) => {
state.bias = event.target.checked;
updateTruthVisibility();
});
// ---------------------------------------------------------------------
// Projected HTML labels, implemented without CSS2DRenderer.
// ---------------------------------------------------------------------
function projectLabel(element, localPosition) {
const world = localPosition.clone();
gaugeGroup.localToWorld(world);
world.project(camera);
const visible = world.z > -1 && world.z < 1;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (world.x * 0.5 + 0.5) * window.innerWidth;
const y = (-world.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function updateLabels() {
if (!labelAnchors.gauge) return;
projectLabel($("labelGauge"), labelAnchors.gauge);
projectLabel($("labelLow"), labelAnchors.low);
projectLabel($("labelNominal"), labelAnchors.nominal);
projectLabel($("labelHigh"), labelAnchors.high);
projectLabel($("labelEstimate"), labelAnchors.estimate);
projectLabel($("labelTruth"), labelAnchors.truth);
$("labelTruth").style.display = showTruth ? "block" : "none";
}
// ---------------------------------------------------------------------
// Animation and resize
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const elapsed = clock.getElapsedTime();
const damping = 0.09;
cameraSpherical.theta += (targetSpherical.theta - cameraSpherical.theta) * damping;
cameraSpherical.phi += (targetSpherical.phi - cameraSpherical.phi) * damping;
cameraSpherical.radius += (targetSpherical.radius - cameraSpherical.radius) * damping;
applyCamera();
const sweep = Math.sin(elapsed * 0.52) * 0.5 + 0.5;
scanBar.position.x = -5.2 + sweep * 9.4;
beamMaterial.opacity = 0.065 + (Math.sin(elapsed * 4.2) * 0.5 + 0.5) * 0.055;
scanMaterial.opacity = 0.028 + (Math.sin(elapsed * 2.8) * 0.5 + 0.5) * 0.035;
if (gaugeCloudMaterial) {
gaugeCloudMaterial.opacity = state.uncertainty
? 0.42 + (Math.sin(elapsed * 3.2) * 0.5 + 0.5) * 0.22
: 0;
}
if (partCloudMaterial) {
partCloudMaterial.opacity = state.uncertainty
? 0.38 + (Math.sin(elapsed * 2.6 + 0.8) * 0.5 + 0.5) * 0.2
: 0;
}
cyanLight.intensity = 19 + (Math.sin(elapsed * 1.8) * 0.5 + 0.5) * 6;
amberLight.intensity = 13 + (Math.sin(elapsed * 1.3 + 1.2) * 0.5 + 0.5) * 5;
renderer.render(scene, camera);
updateLabels();
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
// ---------------------------------------------------------------------
// Start
// ---------------------------------------------------------------------
buildDimensionList();
createAnnotation();
createPartCloud();
createGauge();
updateUI();
setTimeout(() => $("loading").classList.add("hide"), 350);
</script>
</body>
</html>
```