Prompt specification
Build or customize the Three.js 3D scene "Robot positioning resolution exhibit" 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: Robot positioning resolution exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/robot-positioning-resolution-exhibit-x1875
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts finite precision, quantization, and rounding. Compose a fictional linear actuator with continuous target and quantized command positions; distinguish resolution, accuracy, and repeatability rather than treating them as synonyms. Voxel style.
Working Three.js Starter (robot-positioning-resolution-exhibit-x1875):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Finite Precision — Voxel Linear Actuator</title>
<style>
:root {
color-scheme: dark;
--bg: #090e1b;
--panel: rgba(15, 23, 42, 0.88);
--panel-edge: rgba(148, 163, 184, 0.22);
--text: #e8eef9;
--muted: #95a4bd;
--target: #ffd166;
--command: #45d7e8;
--actual: #ff6b6b;
--repeat: #f48fb1;
--grid: #25324a;
}
* { 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;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
#hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.topbar {
position: absolute;
top: 20px;
left: 22px;
right: 22px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 18px;
}
.brand {
max-width: 720px;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.7);
}
.eyebrow {
color: var(--command);
font: 700 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 5px;
font-size: clamp(23px, 3vw, 43px);
line-height: 0.98;
letter-spacing: -0.045em;
}
.subtitle {
margin: 0;
max-width: 650px;
color: #bdc8da;
font-size: 13px;
line-height: 1.45;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 13px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 5px 8px;
border: 1px solid var(--panel-edge);
border-radius: 6px;
background: rgba(9, 14, 27, 0.68);
color: #d6dfef;
font: 600 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.swatch {
width: 8px;
height: 8px;
background: currentColor;
box-shadow: 0 0 10px currentColor;
}
.target-color { color: var(--target); }
.command-color { color: var(--command); }
.actual-color { color: var(--actual); }
.repeat-color { color: var(--repeat); }
.control-panel {
width: 304px;
padding: 14px;
border: 1px solid var(--panel-edge);
border-radius: 10px;
background: var(--panel);
box-shadow: 0 14px 50px rgba(0, 0, 0, 0.35);
backdrop-filter: blur(14px);
pointer-events: auto;
}
.panel-title {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 9px;
color: #dce6f6;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.target-readout {
display: flex;
align-items: baseline;
justify-content: space-between;
margin: 8px 0 7px;
}
#targetValue {
color: var(--target);
font: 700 25px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.target-unit {
color: var(--muted);
font-size: 11px;
}
input[type="range"] {
width: 100%;
margin: 0;
accent-color: var(--target);
cursor: pointer;
}
.button-row {
display: flex;
gap: 7px;
margin: 9px 0 11px;
}
button {
border: 1px solid rgba(148, 163, 184, 0.28);
border-radius: 6px;
background: #18243a;
color: #dbe6f5;
padding: 7px 9px;
font: 600 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
cursor: pointer;
}
button:hover {
border-color: var(--command);
color: var(--command);
}
.telemetry {
border-top: 1px solid rgba(148, 163, 184, 0.17);
padding-top: 8px;
font: 11px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.telemetry-row {
display: flex;
justify-content: space-between;
gap: 12px;
}
.telemetry-row span:first-child { color: var(--muted); }
.telemetry-row b { font-weight: 700; }
.cyan { color: var(--command); }
.coral { color: var(--actual); }
.gold { color: var(--target); }
.format-note {
margin-top: 8px;
color: #7f8da4;
font-size: 9px;
line-height: 1.4;
}
#cards {
position: absolute;
left: 18px;
right: 18px;
bottom: 18px;
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 12px;
}
.card {
min-height: 158px;
padding: 14px 15px;
border: 1px solid var(--panel-edge);
border-radius: 10px;
background: var(--panel);
box-shadow: 0 12px 35px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
}
.card.resolution { border-top: 2px solid var(--command); }
.card.accuracy { border-top: 2px solid var(--actual); }
.card.repeatability { border-top: 2px solid var(--repeat); }
.card-kicker {
color: var(--muted);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.metric {
margin: 8px 0 3px;
font: 700 clamp(20px, 2.3vw, 29px)/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.metric.resolution-value { color: var(--command); }
.metric.accuracy-value { color: var(--actual); }
.metric.repeatability-value { color: var(--repeat); }
.metric-note {
color: #c3cee0;
font-size: 11px;
line-height: 1.4;
}
.card-note {
margin-top: 9px;
color: #8493aa;
font-size: 10px;
line-height: 1.45;
}
.mini-chart {
position: relative;
height: 29px;
margin-top: 9px;
border-bottom: 1px solid rgba(148, 163, 184, 0.25);
}
.resolution-cells {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 3px;
height: 22px;
align-items: end;
}
.resolution-cells i {
height: 10px;
background: rgba(69, 215, 232, 0.28);
border: 1px solid rgba(69, 215, 232, 0.55);
}
.resolution-cells i:nth-child(2) { height: 14px; }
.resolution-cells i:nth-child(3) { height: 18px; }
.resolution-cells i:nth-child(4) { height: 22px; background: var(--command); }
.accuracy-chart .axis {
position: absolute;
left: 4%;
right: 4%;
top: 14px;
height: 1px;
background: #55627a;
}
.accuracy-chart .truth,
.accuracy-chart .actual-dot {
position: absolute;
top: 7px;
width: 3px;
height: 15px;
transform: translateX(-50%);
}
.accuracy-chart .truth { left: 50%; background: var(--target); }
.accuracy-chart .actual-dot { left: 50%; background: var(--actual); }
.accuracy-chart .caption {
position: absolute;
top: 22px;
color: #738299;
font: 8px/1 ui-monospace, monospace;
}
.accuracy-chart .caption.target { left: calc(50% - 22px); }
.accuracy-chart .caption.output { left: calc(50% + 18px); }
.repeat-chart .center-line {
position: absolute;
left: 50%;
top: 3px;
bottom: 4px;
width: 1px;
background: rgba(244, 143, 177, 0.4);
}
.repeat-chart .sample {
position: absolute;
top: 9px;
width: 5px;
height: 5px;
border-radius: 50%;
background: var(--repeat);
transform: translate(-50%, -50%);
box-shadow: 0 0 5px rgba(244, 143, 177, 0.45);
}
.repeat-chart .mean {
position: absolute;
left: 50%;
top: 3px;
bottom: 3px;
width: 2px;
background: white;
transform: translateX(-50%);
opacity: 0.75;
}
.world-label {
position: absolute;
z-index: 4;
padding: 5px 7px;
border: 1px solid currentColor;
border-radius: 5px;
background: rgba(8, 13, 25, 0.86);
box-shadow: 0 4px 18px rgba(0, 0, 0, 0.4);
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.05em;
white-space: nowrap;
transform: translate(-50%, -100%);
pointer-events: none;
}
.world-label.target {
color: var(--target);
border-color: rgba(255, 209, 102, 0.55);
}
.world-label.command {
color: var(--command);
border-color: rgba(69, 215, 232, 0.55);
}
.world-label.actual {
color: var(--actual);
border-color: rgba(255, 107, 107, 0.55);
}
.world-label.scope {
color: var(--repeat);
border-color: rgba(244, 143, 177, 0.55);
}
.ruler-label {
color: #8290a7;
border: 0;
background: transparent;
box-shadow: none;
font-size: 8px;
transform: translate(-50%, -50%);
}
.camera-hint {
position: absolute;
left: 50%;
bottom: 190px;
transform: translateX(-50%);
color: rgba(194, 207, 226, 0.62);
font: 9px/1 ui-monospace, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 760px) {
.topbar {
top: 10px;
left: 10px;
right: 10px;
}
h1 { font-size: 23px; }
.subtitle, .legend { display: none; }
.control-panel {
position: absolute;
top: 60px;
right: 10px;
width: 220px;
padding: 10px;
}
#targetValue { font-size: 19px; }
.telemetry { font-size: 9px; }
.format-note { display: none; }
#cards {
left: 7px;
right: 7px;
bottom: 7px;
gap: 5px;
}
.card {
min-height: 145px;
padding: 9px 8px;
}
.card-kicker { font-size: 8px; }
.metric { font-size: 17px; }
.metric-note { font-size: 9px; }
.card-note { display: none; }
.mini-chart { margin-top: 7px; }
.camera-hint { display: none; }
.world-label { font-size: 8px; }
}
</style>
</head>
<body>
<div id="hud">
<div class="topbar">
<div class="brand">
<div class="eyebrow">AX-6 / finite precision laboratory</div>
<h1>THE ACTUATOR THINKS IN STEPS.</h1>
<p class="subtitle">
A continuous target is rounded onto a finite command grid.
Resolution describes the grid; accuracy describes target error;
repeatability describes the spread of repeated returns.
</p>
<div class="legend">
<span class="target-color"><i class="swatch"></i>CONTINUOUS TARGET</span>
<span class="command-color"><i class="swatch"></i>QUANTIZED COMMAND</span>
<span class="actual-color"><i class="swatch"></i>ACTUAL MEAN</span>
<span class="repeat-color"><i class="swatch"></i>REPEATABILITY SPREAD</span>
</div>
</div>
<div class="control-panel">
<div class="panel-title">
<span>Continuous input</span>
<span id="targetCode">T = 7.370</span>
</div>
<div class="target-readout">
<span id="targetValue">7.370</span>
<span class="target-unit">millimetres</span>
</div>
<input
id="targetSlider"
type="range"
min="0"
max="10"
step="0.005"
value="7.37"
aria-label="Continuous target position"
>
<div class="button-row">
<button id="halfwayButton" title="7.125 is exactly halfway between two codes">
HALFWAY CASE
</button>
<button id="resetCamera">RESET VIEW</button>
</div>
<div class="telemetry">
<div class="telemetry-row">
<span>raw target</span>
<b id="rawTarget">7.370000</b>
</div>
<div class="telemetry-row">
<span>round(T / Δ)</span>
<b id="codeValue">29</b>
</div>
<div class="telemetry-row">
<span>command</span>
<b id="commandValue" class="cyan">7.250 mm</b>
</div>
<div class="telemetry-row">
<span>quantization error</span>
<b id="quantErrorValue" class="gold">−0.120 mm</b>
</div>
<div class="telemetry-row">
<span>actual mean</span>
<b id="actualValue" class="coral">7.220 mm</b>
</div>
</div>
<div class="format-note">
Fictional command format: 6-bit payload, unsigned fixed-point,
Δ = 0.25 mm. Rounding is nearest; exact ties round to even.
A constant −0.03 mm calibration bias is added to the output.
</div>
</div>
</div>
<div class="camera-hint">drag to orbit · scroll / pinch to dolly</div>
<div id="cards">
<section class="card resolution">
<div class="card-kicker">01 / Resolution</div>
<div class="metric resolution-value">0.25 mm</div>
<div class="metric-note">Smallest representable command step.</div>
<div class="mini-chart resolution-cells">
<i></i><i></i><i></i><i></i>
</div>
<div class="card-note">
This is what the finite command format can express.
Fine resolution does not guarantee fine physical motion.
</div>
</section>
<section class="card accuracy">
<div class="card-kicker">02 / Accuracy</div>
<div id="accuracyMetric" class="metric accuracy-value">0.150 mm</div>
<div class="metric-note">Absolute error of the mean output from target.</div>
<div class="mini-chart accuracy-chart">
<div class="axis"></div>
<div class="truth"></div>
<div id="accuracyDot" class="actual-dot"></div>
<div class="caption target">TARGET</div>
<div class="caption output">OUTPUT</div>
</div>
<div id="accuracyBreakdown" class="card-note">
Quantization −0.120 + bias −0.030 = −0.150 mm.
</div>
</section>
<section class="card repeatability">
<div class="card-kicker">03 / Repeatability</div>
<div class="metric repeatability-value">±0.030 mm</div>
<div class="metric-note">Return-to-return spread for the same command.</div>
<div id="repeatChart" class="mini-chart repeat-chart">
<div class="center-line"></div>
<div class="mean"></div>
</div>
<div class="card-note">
This measures consistency, not target accuracy.
A device can repeat the same wrong position perfectly.
</div>
</section>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and lighting
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.domElement.setAttribute(
"aria-label",
"Voxel linear actuator demonstrating quantization, accuracy, and repeatability"
);
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x090e1b);
scene.fog = new THREE.Fog(0x090e1b, 18, 38);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
100
);
scene.add(new THREE.HemisphereLight(0xc7ddff, 0x111728, 2.0));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(5, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x36d8ee, 13, 12, 2);
cyanLight.position.set(-2, 4, -3);
scene.add(cyanLight);
const goldLight = new THREE.PointLight(0xffc857, 10, 10, 2);
goldLight.position.set(4, 3, 4);
scene.add(goldLight);
// -------------------------------------------------------------------------
// Materials and voxel construction helpers
// -------------------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.12,
flatShading: true,
...options
});
const mats = {
floor: material(0x101827),
base: material(0x27344a),
deck: material(0x34445f),
rail: material(0x9baac0, { metalness: 0.55, roughness: 0.35 }),
housing: material(0x233451),
housingDark: material(0x162239),
coral: material(0xff6666, { emissive: 0x5b1010, emissiveIntensity: 0.5 }),
target: material(0xffd166, { emissive: 0x5a3900, emissiveIntensity: 0.8 }),
command: material(0x45d7e8, { emissive: 0x073c45, emissiveIntensity: 0.8 }),
repeat: material(0xf48fb1, { emissive: 0x54162c, emissiveIntensity: 0.65 }),
white: material(0xf4f7ff, { emissive: 0x444444, emissiveIntensity: 0.25 }),
grid: material(0x26334a),
dark: material(0x111827)
};
function box(w, h, d, mat, x = 0, y = 0, z = 0, outline = false) {
const geometry = new THREE.BoxGeometry(w, h, d);
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
if (outline) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry),
new THREE.LineBasicMaterial({
color: 0xaebbd0,
transparent: true,
opacity: 0.34
})
);
mesh.add(edges);
}
scene.add(mesh);
return mesh;
}
function outlinedBox(w, h, d, mat, x, y, z) {
return box(w, h, d, mat, x, y, z, true);
}
// -------------------------------------------------------------------------
// Floor and voxel grid
// -------------------------------------------------------------------------
outlinedBox(21, 0.42, 11, mats.floor, 0, -0.58, 0);
for (let x = -10; x <= 10; x += 1) {
box(0.018, 0.012, 10.7, mats.grid, x, -0.36, 0);
}
for (let z = -5; z <= 5; z += 1) {
box(20.7, 0.012, 0.018, mats.grid, 0, -0.36, z);
}
// -------------------------------------------------------------------------
// Fictional linear actuator
// -------------------------------------------------------------------------
outlinedBox(14.7, 0.38, 2.35, mats.base, 0, 0, 0);
outlinedBox(14.25, 0.16, 1.98, mats.deck, 0, 0.27, 0);
outlinedBox(12.15, 0.20, 0.66, mats.rail, 0, 0.55, 0);
// Rail end stops.
for (const x of [-5.95, 5.95]) {
outlinedBox(0.42, 0.72, 1.18, mats.housingDark, x, 0.72, 0);
outlinedBox(0.24, 0.22, 1.36, mats.coral, x, 1.15, 0);
}
// Motor / gearbox housing.
outlinedBox(1.70, 1.30, 1.62, mats.housing, -6.18, 1.05, 0);
outlinedBox(1.35, 0.28, 1.82, mats.housingDark, -6.18, 1.84, 0);
outlinedBox(0.42, 1.05, 1.85, mats.coral, -6.86, 1.04, 0);
for (let i = 0; i < 6; i++) {
box(0.10, 0.92, 1.72, mats.housingDark, -6.62 + i * 0.17, 1.08, 0);
}
// Support feet.
for (const x of [-6.30, 5.70]) {
outlinedBox(1.20, 0.28, 2.45, mats.housingDark, x, -0.06, 0);
}
// Rod is rescaled to connect the housing and moving carriage.
const rod = box(1, 0.17, 0.27, mats.rail, -2.5, 0.92, 0);
const rodStart = -5.34;
// Moving carriage.
const carriage = new THREE.Group();
scene.add(carriage);
function groupBox(group, w, h, d, mat, x, y, z, outline = false) {
const geometry = new THREE.BoxGeometry(w, h, d);
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
if (outline) {
mesh.add(
new THREE.LineSegments(
new THREE.EdgesGeometry(geometry),
new THREE.LineBasicMaterial({
color: 0xffb1b1,
transparent: true,
opacity: 0.48
})
)
);
}
group.add(mesh);
return mesh;
}
groupBox(carriage, 1.18, 0.78, 1.20, mats.coral, 0, 0.98, 0, true);
groupBox(carriage, 0.92, 0.25, 0.94, mats.housingDark, 0, 1.49, 0, true);
groupBox(carriage, 0.30, 0.30, 0.30, mats.coral, 0, 1.78, 0);
// Front ruler: one world unit equals one millimetre.
for (let i = 0; i <= 40; i++) {
const mm = i * 0.25;
const x = -5 + mm;
const major = i % 4 === 0;
const medium = i % 2 === 0;
box(
major ? 0.055 : 0.026,
major ? 0.19 : medium ? 0.13 : 0.09,
0.055,
major ? mats.white : mats.rail,
x,
0.47,
1.27
);
}
// -------------------------------------------------------------------------
// Finite command grid: forty-one representable commands
// -------------------------------------------------------------------------
const STEP = 0.25;
const CALIBRATION_BIAS = -0.03;
const commandCells = [];
for (let i = 0; i <= 40; i++) {
const x = -5 + i * STEP;
const cellMaterial = mats.command.clone();
const cell = box(
0.17,
0.16,
0.26,
cellMaterial,
x,
3.15,
-1.40
);
commandCells.push(cell);
}
// A bracket around one representable code.
const resolutionBracket = new THREE.Group();
scene.add(resolutionBracket);
groupBox(
resolutionBracket,
0.25,
0.035,
0.035,
mats.command,
0,
2.87,
-1.40
);
groupBox(
resolutionBracket,
0.035,
0.17,
0.035,
mats.command,
-0.125,
2.82,
-1.40
);
groupBox(
resolutionBracket,
0.035,
0.17,
0.035,
mats.command,
0.125,
2.82,
-1.40
);
// -------------------------------------------------------------------------
// Continuous target marker
// -------------------------------------------------------------------------
const targetMarker = new THREE.Group();
scene.add(targetMarker);
for (let i = 0; i < 10; i++) {
groupBox(
targetMarker,
0.095,
0.22,
0.095,
mats.target,
0,
0.58 + i * 0.25,
1.55
);
}
groupBox(targetMarker, 0.42, 0.22, 0.32, mats.target, 0, 3.00, 1.55);
groupBox(targetMarker, 0.22, 0.16, 0.48, mats.target, 0, 0.47, 1.55);
// -------------------------------------------------------------------------
// Quantized command marker
// -------------------------------------------------------------------------
const commandMarker = new THREE.Group();
scene.add(commandMarker);
for (let i = 0; i < 10; i++) {
groupBox(
commandMarker,
0.095,
0.22,
0.095,
mats.command,
0,
0.66 + i * 0.25,
-1.40
);
}
groupBox(commandMarker, 0.42, 0.22, 0.32, mats.command, 0, 3.24, -1.40);
// -------------------------------------------------------------------------
// Accuracy bridge: exact target-to-mean gap
// -------------------------------------------------------------------------
const accuracyBridge = new THREE.Group();
scene.add(accuracyBridge);
const accuracyLine = groupBox(
accuracyBridge,
1,
0.045,
0.045,
mats.coral,
0,
2.52,
1.55
);
const accuracyCapA = groupBox(
accuracyBridge,
0.045,
0.19,
0.045,
mats.coral,
0,
2.52,
1.55
);
const accuracyCapB = groupBox(
accuracyBridge,
0.045,
0.19,
0.045,
mats.coral,
0,
2.52,
1.55
);
// -------------------------------------------------------------------------
// Repeatability scope: magnified return samples
// -------------------------------------------------------------------------
const scopeGroup = new THREE.Group();
scene.add(scopeGroup);
const scopePlate = new THREE.Mesh(
new THREE.BoxGeometry(2.55, 2.30, 0.18),
mats.housingDark
);
scopePlate.position.set(7.12, 1.57, -1.72);
scopePlate.castShadow = true;
scopePlate.receiveShadow = true;
scopeGroup.add(scopePlate);
const scopeEdge = new THREE.LineSegments(
new THREE.EdgesGeometry(scopePlate.geometry),
new THREE.LineBasicMaterial({
color: 0xf48fb1,
transparent: true,
opacity: 0.42
})
);
scopePlate.add(scopeEdge);
groupBox(
scopeGroup,
1.34,
0.025,
0.04,
mats.rail,
7.12,
0.98,
-1.60
);
for (const x of [6.43, 7.81]) {
groupBox(
scopeGroup,
0.035,
0.21,
0.04,
mats.rail,
x,
0.98,
-1.60
);
}
const returnOffsets = [
-0.030, 0.030, -0.024, 0.024, -0.018, 0.018,
-0.012, 0.012, -0.006, 0.006, 0.000, 0.027,
-0.027, 0.015, -0.015, 0.009, -0.009, 0.003,
-0.003, -0.021
];
returnOffsets.forEach((offset, i) => {
const verticalJitter = ((i * 7) % 5 - 2) * 0.055;
groupBox(
scopeGroup,
0.065,
0.065,
0.065,
mats.repeat,
7.12 + offset * 8.5,
1.01 + verticalJitter,
-1.57
);
});
// Mean marker in the scope.
groupBox(scopeGroup, 0.035, 0.80, 0.045, mats.white, 7.12, 1.03, -1.53);
// Scope spread bracket.
groupBox(scopeGroup, 0.028, 0.43, 0.03, mats.repeat, 6.865, 1.00, -1.51);
groupBox(scopeGroup, 0.028, 0.43, 0.03, mats.repeat, 7.375, 1.00, -1.51);
groupBox(scopeGroup, 0.54, 0.028, 0.03, mats.repeat, 7.12, 0.77, -1.51);
// -------------------------------------------------------------------------
// HTML world labels
// -------------------------------------------------------------------------
const labels = [];
function worldLabel(className, anchor, offsetX = 0, offsetY = 0) {
const element = document.createElement("div");
element.className = `world-label ${className}`;
document.getElementById("hud").appendChild(element);
const item = {
element,
anchor: anchor.clone(),
offsetX,
offsetY
};
labels.push(item);
return item;
}
const targetLabel = worldLabel(
"target",
new THREE.Vector3(),
-47,
-8
);
const commandLabel = worldLabel(
"command",
new THREE.Vector3(),
44,
-8
);
const actualLabel = worldLabel(
"actual",
new THREE.Vector3(),
37,
5
);
const scopeLabel = worldLabel(
"scope",
new THREE.Vector3(7.12, 2.68, -1.55),
0,
0
);
scopeLabel.element.textContent = "REPEATABILITY · ×8.5 SCOPE";
const rulerLabels = [];
for (const mm of [0, 2.5, 5, 7.5, 10]) {
const item = worldLabel(
"ruler-label",
new THREE.Vector3(-5 + mm, 0.25, 1.30),
0,
0
);
item.element.textContent = `${mm.toFixed(mm % 1 ? 1 : 0)} mm`;
rulerLabels.push(item);
}
// -------------------------------------------------------------------------
// Numerical model and UI
// -------------------------------------------------------------------------
const MIN = 0;
const MAX = 10;
let target = 7.37;
let commandCode = 29;
let command = 7.25;
let actualMean = 7.22;
let quantizationError = -0.12;
let accuracyError = -0.15;
function roundTiesToEven(value) {
const lower = Math.floor(value);
const fraction = value - lower;
if (fraction > 0.5) return lower + 1;
if (fraction < 0.5) return lower;
return lower % 2 === 0 ? lower : lower + 1;
}
const slider = document.getElementById("targetSlider");
const targetValue = document.getElementById("targetValue");
const targetCode = document.getElementById("targetCode");
const rawTarget = document.getElementById("rawTarget");
const codeValue = document.getElementById("codeValue");
const commandValue = document.getElementById("commandValue");
const quantErrorValue = document.getElementById("quantErrorValue");
const actualValue = document.getElementById("actualValue");
const accuracyMetric = document.getElementById("accuracyMetric");
const accuracyDot = document.getElementById("accuracyDot");
const accuracyBreakdown = document.getElementById("accuracyBreakdown");
const repeatChart = document.getElementById("repeatChart");
function signed(value, digits = 3) {
const rounded = Math.abs(value) < 0.0005 ? 0 : value;
const sign = rounded < 0 ? "−" : "+";
return `${sign}${Math.abs(rounded).toFixed(digits)}`;
}
returnOffsets.forEach((offset) => {
const dot = document.createElement("i");
dot.className = "sample";
dot.style.left = `${50 + offset * 1000}%`;
repeatChart.appendChild(dot);
});
function updateModel() {
target = THREE.MathUtils.clamp(Number(slider.value), MIN, MAX);
commandCode = roundTiesToEven((target - MIN) / STEP);
command = MIN + commandCode * STEP;
quantizationError = command - target;
actualMean = command + CALIBRATION_BIAS;
accuracyError = actualMean - target;
targetValue.textContent = target.toFixed(3);
targetCode.textContent = `T = ${target.toFixed(3)}`;
rawTarget.textContent = target.toFixed(6);
codeValue.textContent = String(commandCode);
commandValue.textContent = `${command.toFixed(3)} mm`;
quantErrorValue.textContent = `${signed(quantizationError)} mm`;
actualValue.textContent = `${actualMean.toFixed(3)} mm`;
accuracyMetric.textContent = `${Math.abs(accuracyError).toFixed(3)} mm`;
const chartPercent = THREE.MathUtils.clamp(
50 + accuracyError * 200,
4,
96
);
accuracyDot.style.left = `${chartPercent}%`;
accuracyBreakdown.textContent =
`Quantization ${signed(quantizationError)} + bias ` +
`${signed(CALIBRATION_BIAS)} = ${signed(accuracyError)} mm.`;
const targetX = MIN + target;
const commandX = MIN + command;
const actualX = MIN + actualMean;
targetMarker.position.x = targetX;
commandMarker.position.x = commandX;
resolutionBracket.position.x = commandX;
commandCells.forEach((cell, i) => {
const selected = i === commandCode;
cell.scale.y = selected ? 2.25 : 1;
cell.material.color.setHex(selected ? 0x72f4ff : 0x245a67);
cell.material.emissive.setHex(selected ? 0x0b8794 : 0x04171d);
cell.material.emissiveIntensity = selected ? 1.0 : 0.25;
});
const gap = Math.abs(accuracyError);
const midpoint = (targetX + actualX) * 0.5;
accuracyLine.position.x = midpoint;
accuracyLine.scale.x = Math.max(gap, 0.015);
accuracyCapA.position.x = targetX;
accuracyCapB.position.x = actualX;
targetLabel.anchor.set(targetX, 3.28, 1.55);
commandLabel.anchor.set(commandX, 3.54, -1.40);
targetLabel.element.innerHTML =
`CONTINUOUS TARGET ${target.toFixed(3)} mm`;
commandLabel.element.innerHTML =
`QUANTIZED COMMAND ${command.toFixed(3)} mm`;
}
slider.addEventListener("input", updateModel);
document.getElementById("halfwayButton").addEventListener("click", () => {
slider.value = "7.125";
updateModel();
});
updateModel();
// -------------------------------------------------------------------------
// Direct camera controls: orbit, dolly, and pinch
// -------------------------------------------------------------------------
const cameraState = {
yaw: -0.12,
pitch: 0.38,
distance: 18.7,
target: new THREE.Vector3(0.25, 1.18, 0)
};
const defaultCamera = {
yaw: cameraState.yaw,
pitch: cameraState.pitch,
distance: cameraState.distance
};
function updateCamera() {
const cp = Math.cos(cameraState.pitch);
const sp = Math.sin(cameraState.pitch);
camera.position.set(
cameraState.target.x + cameraState.distance * cp * Math.sin(cameraState.yaw),
cameraState.target.y + cameraState.distance * sp,
cameraState.target.z + cameraState.distance * cp * Math.cos(cameraState.yaw)
);
camera.lookAt(cameraState.target);
}
updateCamera();
document.getElementById("resetCamera").addEventListener("click", () => {
cameraState.yaw = defaultCamera.yaw;
cameraState.pitch = defaultCamera.pitch;
cameraState.distance = defaultCamera.distance;
updateCamera();
});
const pointers = new Map();
let previousPinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
previousPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.005,
0.13,
1.08
);
updateCamera();
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (previousPinchDistance > 0) {
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance * (previousPinchDistance / distance),
10,
30
);
updateCamera();
}
previousPinchDistance = distance;
}
});
function removePointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", removePointer);
renderer.domElement.addEventListener("pointercancel", removePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance * Math.exp(event.deltaY * 0.001),
10,
30
);
updateCamera();
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
scopeGroup.visible = innerWidth > 760;
scopeLabel.element.style.display = innerWidth > 760 ? "block" : "none";
}
addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
let carriageX = MIN + actualMean;
function updateWorldLabels() {
for (const item of labels) {
const projected = item.anchor.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.25 &&
projected.x < 1.25 &&
projected.y > -1.25 &&
projected.y < 1.25;
item.element.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * innerWidth + item.offsetX;
const y = (-projected.y * 0.5 + 0.5) * innerHeight + item.offsetY;
item.element.style.left = `${x}px`;
item.element.style.top = `${y}px`;
}
}
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const desiredX = MIN + actualMean;
// The carriage settles toward the mean output; the command itself snaps.
carriageX = THREE.MathUtils.lerp(
carriageX,
desiredX,
1 - Math.exp(-9 * dt)
);
carriage.position.x = carriageX;
const rodEnd = Math.max(rodStart + 0.05, carriageX - 0.46);
const rodLength = rodEnd - rodStart;
rod.scale.x = rodLength;
rod.position.x = rodStart + rodLength * 0.5;
actualLabel.anchor.set(carriageX, 2.12, 0);
actualLabel.element.innerHTML =
`ACTUAL MEAN ${actualMean.toFixed(3)} mm`;
updateWorldLabels();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```