Prompt specification
Build or customize the Three.js 3D scene "Sensor Bias Produces a Wrong Decision" 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: Sensor Bias Produces a Wrong Decision
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/sensor-bias-produces-a-wrong-decision-x3976
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Create a toy resource controller with adjustable measurement bias. Show the resulting accounting error and compare it with a corrected sensor under the same true system state.
Working Three.js Starter (sensor-bias-produces-a-wrong-decision-x3976):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Resource Ledger Lab</title>
<style>
:root {
--bg: #08111d;
--panel: rgba(12, 23, 38, 0.86);
--panel-border: rgba(148, 163, 184, 0.18);
--text: #eef6ff;
--muted: #91a4b8;
--teal: #5eead4;
--cyan: #38bdf8;
--coral: #fb7185;
--amber: #fbbf24;
--green: #4ade80;
}
* {
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;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.topbar {
position: fixed;
z-index: 10;
top: 0;
left: 0;
right: 0;
min-height: 78px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
padding: 17px 24px;
background: linear-gradient(
to bottom,
rgba(5, 12, 22, 0.95),
rgba(5, 12, 22, 0.72) 72%,
transparent
);
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
}
.brand-mark {
position: relative;
width: 38px;
height: 38px;
border: 1px solid rgba(94, 234, 212, 0.55);
border-radius: 11px;
background:
linear-gradient(135deg, rgba(94, 234, 212, 0.2), transparent),
rgba(94, 234, 212, 0.05);
box-shadow: inset 0 0 22px rgba(94, 234, 212, 0.08);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
border-radius: 3px;
background: var(--teal);
}
.brand-mark::before {
width: 7px;
height: 7px;
left: 9px;
bottom: 9px;
box-shadow: 12px 0 0 rgba(94, 234, 212, 0.55);
}
.brand-mark::after {
width: 22px;
height: 4px;
left: 8px;
top: 9px;
}
.eyebrow {
margin: 0 0 4px;
color: var(--teal);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(17px, 2vw, 23px);
font-weight: 760;
letter-spacing: -0.025em;
}
.header-actions {
display: flex;
align-items: center;
gap: 10px;
pointer-events: auto;
}
.status-pill,
.view-button {
min-height: 34px;
border: 1px solid var(--panel-border);
border-radius: 999px;
background: rgba(9, 19, 33, 0.8);
color: var(--text);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.status-pill {
display: flex;
align-items: center;
gap: 8px;
padding: 0 13px;
color: #cbd5e1;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--amber);
box-shadow: 0 0 12px currentColor;
}
.status-dot.aligned {
background: var(--green);
}
.view-button {
padding: 0 14px;
cursor: pointer;
transition:
border-color 160ms ease,
background 160ms ease;
}
.view-button:hover {
border-color: rgba(94, 234, 212, 0.5);
background: rgba(94, 234, 212, 0.09);
}
.panel {
position: fixed;
z-index: 9;
border: 1px solid var(--panel-border);
border-radius: 18px;
background:
linear-gradient(145deg, rgba(17, 31, 49, 0.94), rgba(7, 16, 29, 0.91));
box-shadow:
0 22px 60px rgba(0, 0, 0, 0.28),
inset 0 1px 0 rgba(255, 255, 255, 0.025);
backdrop-filter: blur(18px);
}
.control-panel {
top: 98px;
left: 24px;
width: min(340px, calc(100vw - 48px));
padding: 21px;
}
.comparison-panel {
top: 98px;
right: 24px;
width: min(370px, calc(100vw - 48px));
padding: 21px;
}
h2 {
margin: 0;
font-size: 20px;
line-height: 1.2;
letter-spacing: -0.03em;
}
.description {
margin: 9px 0 20px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.bias-readout {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 12px;
margin: 20px 0 10px;
}
.bias-readout strong {
color: var(--amber);
font-size: 34px;
line-height: 1;
font-variant-numeric: tabular-nums;
}
.bias-readout span {
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
input[type="range"] {
--fill: 50%;
width: 100%;
height: 7px;
margin: 10px 0 7px;
appearance: none;
border-radius: 999px;
outline: none;
background:
linear-gradient(
to right,
var(--amber) 0,
var(--amber) var(--fill),
rgba(148, 163, 184, 0.2) var(--fill),
rgba(148, 163, 184, 0.2) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 19px;
height: 19px;
appearance: none;
border: 3px solid #111c2b;
border-radius: 50%;
background: #fff3bf;
box-shadow: 0 0 0 1px var(--amber);
}
input[type="range"]::-moz-range-thumb {
width: 15px;
height: 15px;
border: 3px solid #111c2b;
border-radius: 50%;
background: #fff3bf;
box-shadow: 0 0 0 1px var(--amber);
}
.range-labels {
display: flex;
justify-content: space-between;
color: #718499;
font-size: 10px;
font-weight: 650;
}
.presets {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
margin: 16px 0 18px;
}
.preset {
min-height: 30px;
border: 1px solid rgba(148, 163, 184, 0.16);
border-radius: 8px;
background: rgba(148, 163, 184, 0.05);
color: #aebed0;
font-size: 10px;
font-weight: 750;
cursor: pointer;
transition: 150ms ease;
}
.preset:hover,
.preset.active {
border-color: rgba(251, 191, 36, 0.45);
background: rgba(251, 191, 36, 0.1);
color: #fde68a;
}
.truth-card {
display: flex;
align-items: center;
gap: 12px;
padding: 13px;
border: 1px solid rgba(94, 234, 212, 0.18);
border-radius: 12px;
background: rgba(94, 234, 212, 0.055);
}
.truth-icon {
display: grid;
flex: 0 0 34px;
width: 34px;
height: 34px;
place-items: center;
border-radius: 9px;
background: rgba(94, 234, 212, 0.12);
color: var(--teal);
font-size: 16px;
}
.truth-copy {
min-width: 0;
flex: 1;
}
.truth-copy small {
display: block;
margin-bottom: 3px;
color: #7fa49f;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.truth-copy strong {
font-size: 13px;
}
.truth-card > strong {
color: var(--teal);
font-size: 18px;
font-variant-numeric: tabular-nums;
}
.math-box {
margin-top: 13px;
padding: 12px 13px;
border-radius: 11px;
background: rgba(2, 8, 18, 0.36);
color: #8498ad;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
line-height: 1.8;
}
.math-box b {
color: #cbd5e1;
font-weight: 650;
}
.compare-header,
.compare-row {
display: grid;
grid-template-columns: 1fr auto 61px;
align-items: center;
gap: 10px;
}
.compare-header {
margin: 22px 0 7px;
padding: 0 2px 8px;
border-bottom: 1px solid rgba(148, 163, 184, 0.12);
color: #6f8297;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.compare-header span:nth-child(2),
.compare-header span:nth-child(3) {
text-align: right;
}
.compare-row {
min-height: 48px;
padding: 7px 2px;
border-bottom: 1px solid rgba(148, 163, 184, 0.08);
}
.metric-label {
display: flex;
align-items: center;
gap: 9px;
color: #bdcbd9;
font-size: 12px;
font-weight: 650;
}
.metric-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 10px rgba(94, 234, 212, 0.35);
}
.metric-dot.raw {
background: var(--amber);
box-shadow: 0 0 10px rgba(251, 191, 36, 0.35);
}
.metric-dot.fixed {
background: var(--green);
box-shadow: 0 0 10px rgba(74, 222, 128, 0.35);
}
.metric-value {
text-align: right;
font-size: 15px;
font-weight: 760;
font-variant-numeric: tabular-nums;
}
.metric-delta {
text-align: right;
color: #718499;
font-size: 11px;
font-weight: 700;
font-variant-numeric: tabular-nums;
}
.metric-delta.bad {
color: var(--coral);
}
.metric-delta.good {
color: var(--green);
}
.error-card {
position: relative;
overflow: hidden;
margin-top: 17px;
padding: 16px;
border: 1px solid rgba(251, 113, 133, 0.2);
border-radius: 13px;
background:
radial-gradient(circle at 100% 0, rgba(251, 113, 133, 0.12), transparent 50%),
rgba(251, 113, 133, 0.055);
}
.error-card.negative {
border-color: rgba(96, 165, 250, 0.24);
background:
radial-gradient(circle at 100% 0, rgba(96, 165, 250, 0.12), transparent 50%),
rgba(96, 165, 250, 0.055);
}
.error-card.balanced {
border-color: rgba(74, 222, 128, 0.24);
background:
radial-gradient(circle at 100% 0, rgba(74, 222, 128, 0.12), transparent 50%),
rgba(74, 222, 128, 0.055);
}
.error-card small {
color: #9aacbd;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.error-main {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
margin-top: 6px;
}
.error-main strong {
color: var(--coral);
font-size: 27px;
letter-spacing: -0.04em;
font-variant-numeric: tabular-nums;
}
.error-card.negative .error-main strong {
color: #60a5fa;
}
.error-card.balanced .error-main strong {
color: var(--green);
}
.error-direction {
color: #9aacbd;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.bar-chart {
margin-top: 18px;
}
.bar-row {
margin: 12px 0;
}
.bar-label {
display: flex;
justify-content: space-between;
margin-bottom: 6px;
color: #8ea0b4;
font-size: 9px;
font-weight: 700;
}
.bar-track {
position: relative;
height: 7px;
overflow: visible;
border-radius: 999px;
background: rgba(148, 163, 184, 0.11);
}
.bar-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: var(--teal);
transition: width 220ms ease;
}
.bar-fill.raw {
background: linear-gradient(90deg, #d97706, var(--amber));
}
.bar-fill.fixed {
background: linear-gradient(90deg, #16a34a, var(--green));
}
.truth-marker {
position: absolute;
top: -4px;
bottom: -4px;
left: 66.667%;
width: 1px;
background: rgba(226, 232, 240, 0.65);
}
.truth-marker::before {
content: "";
position: absolute;
top: -2px;
left: -2px;
width: 5px;
height: 5px;
border-radius: 50%;
background: #e2e8f0;
}
.correction-note {
display: flex;
align-items: flex-start;
gap: 9px;
margin-top: 18px;
padding-top: 15px;
border-top: 1px solid rgba(148, 163, 184, 0.12);
color: #8ea0b4;
font-size: 10px;
line-height: 1.55;
}
.correction-note .check {
color: var(--green);
font-size: 14px;
line-height: 1;
}
.correction-note b {
color: #d7e3ef;
}
.scene-hint {
position: fixed;
z-index: 5;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
padding: 8px 13px;
border: 1px solid rgba(148, 163, 184, 0.13);
border-radius: 999px;
background: rgba(5, 12, 22, 0.65);
color: #718499;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.11em;
text-transform: uppercase;
pointer-events: none;
white-space: nowrap;
}
@media (max-width: 920px) {
.control-panel {
width: 300px;
left: 14px;
}
.comparison-panel {
width: 320px;
right: 14px;
}
.topbar {
padding-inline: 14px;
}
}
@media (max-width: 700px) {
.topbar {
min-height: 68px;
}
.header-actions .status-pill {
display: none;
}
.control-panel {
top: 76px;
left: 12px;
width: min(290px, calc(100vw - 24px));
padding: 15px;
}
.control-panel .description,
.math-box {
display: none;
}
.bias-readout {
margin-top: 13px;
}
.comparison-panel {
top: auto;
right: 12px;
bottom: 12px;
width: min(310px, calc(100vw - 24px));
padding: 15px;
}
.comparison-panel h2,
.bar-chart,
.correction-note {
display: none;
}
.compare-header {
margin-top: 12px;
}
.scene-hint {
display: none;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive low-poly resource accounting scene"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<p class="eyebrow">Accounting systems / Toy lab 01</p>
<h1>Resource Ledger Lab</h1>
</div>
</div>
<div class="header-actions">
<div class="status-pill">
<span id="statusDot" class="status-dot"></span>
<span id="statusText">Drift detected</span>
</div>
<button id="resetView" class="view-button" type="button">Reset view</button>
</div>
</header>
<aside class="panel control-panel">
<p class="eyebrow">Control 01</p>
<h2>Measurement bias</h2>
<p class="description">
Shift the raw controller while the physical resource state remains locked.
Both sensors observe the same reservoir.
</p>
<div class="bias-readout">
<strong id="biasValue">+15.0%</strong>
<span>Controller offset</span>
</div>
<input
id="bias"
type="range"
min="-30"
max="30"
step="0.5"
value="15"
aria-label="Measurement bias percentage"
/>
<div class="range-labels">
<span>−30% under-report</span>
<span>0%</span>
<span>+30% over-report</span>
</div>
<div class="presets" aria-label="Bias presets">
<button class="preset" data-bias="-15" type="button">−15%</button>
<button class="preset" data-bias="0" type="button">0%</button>
<button class="preset active" data-bias="15" type="button">+15%</button>
<button class="preset" data-bias="30" type="button">+30%</button>
</div>
<div class="truth-card">
<div class="truth-icon" aria-hidden="true">▣</div>
<div class="truth-copy">
<small>Locked true system state</small>
<strong>12 crates × 5 units</strong>
</div>
<strong>60.0</strong>
</div>
<div class="math-box">
<b>raw</b> = true × (1 + bias)<br />
<b>error</b> = raw − true<br />
<b>corrected</b> = raw − estimated bias
</div>
</aside>
<aside class="panel comparison-panel">
<p class="eyebrow">Output 02</p>
<h2>Same stock. Two reports.</h2>
<div class="compare-header">
<span>Signal</span>
<span>Units</span>
<span>Vs truth</span>
</div>
<div class="compare-row">
<div class="metric-label">
<span class="metric-dot"></span>
True state
</div>
<div class="metric-value">60.0</div>
<div class="metric-delta">—</div>
</div>
<div class="compare-row">
<div class="metric-label">
<span class="metric-dot raw"></span>
Raw controller
</div>
<div id="rawValue" class="metric-value">69.0</div>
<div id="rawDelta" class="metric-delta bad">+9.0</div>
</div>
<div class="compare-row">
<div class="metric-label">
<span class="metric-dot fixed"></span>
Corrected sensor
</div>
<div id="correctedValue" class="metric-value">60.0</div>
<div id="correctedDelta" class="metric-delta good">0.0</div>
</div>
<div id="errorCard" class="error-card">
<small>Resulting accounting error</small>
<div class="error-main">
<strong id="errorValue">+9.0 units</strong>
<span id="errorDirection" class="error-direction">Over-reported</span>
</div>
</div>
<div class="bar-chart" aria-label="Comparison of reported units">
<div class="bar-row">
<div class="bar-label">
<span>TRUE STATE</span>
<span>60.0</span>
</div>
<div class="bar-track">
<div id="truthBar" class="bar-fill"></div>
<span class="truth-marker" title="True state marker"></span>
</div>
</div>
<div class="bar-row">
<div class="bar-label">
<span>RAW CONTROLLER</span>
<span id="rawBarValue">69.0</span>
</div>
<div class="bar-track">
<div id="rawBar" class="bar-fill raw"></div>
<span class="truth-marker"></span>
</div>
</div>
<div class="bar-row">
<div class="bar-label">
<span>CORRECTED SENSOR</span>
<span id="fixedBarValue">60.0</span>
</div>
<div class="bar-track">
<div id="fixedBar" class="bar-fill fixed"></div>
<span class="truth-marker"></span>
</div>
</div>
</div>
<div class="correction-note">
<span class="check">✓</span>
<span>
<b>Compensation restores the ledger.</b>
The corrected sensor subtracts the controller’s estimated
<span id="estimatedBias">15.0</span>-unit bias and matches the same
true 60-unit state.
</span>
</div>
</aside>
<div class="scene-hint">Drag to orbit · Scroll to zoom</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const TRUE_UNITS = 60;
const MAX_DISPLAY_UNITS = 90;
const ERROR_SCALE = 18;
const biasInput = document.querySelector("#bias");
const biasValue = document.querySelector("#biasValue");
const rawValue = document.querySelector("#rawValue");
const rawDelta = document.querySelector("#rawDelta");
const correctedValue = document.querySelector("#correctedValue");
const correctedDelta = document.querySelector("#correctedDelta");
const errorCard = document.querySelector("#errorCard");
const errorValue = document.querySelector("#errorValue");
const errorDirection = document.querySelector("#errorDirection");
const statusDot = document.querySelector("#statusDot");
const statusText = document.querySelector("#statusText");
const estimatedBias = document.querySelector("#estimatedBias");
const rawBarValue = document.querySelector("#rawBarValue");
const fixedBarValue = document.querySelector("#fixedBarValue");
const truthBar = document.querySelector("#truthBar");
const rawBar = document.querySelector("#rawBar");
const fixedBar = document.querySelector("#fixedBar");
const presetButtons = [...document.querySelectorAll(".preset")];
const sceneHost = document.querySelector("#scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x08111d);
scene.fog = new THREE.Fog(0x08111d, 14, 27);
const camera = new THREE.PerspectiveCamera(
40,
innerWidth / innerHeight,
0.1,
60
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
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.12;
sceneHost.appendChild(renderer.domElement);
const hemiLight = new THREE.HemisphereLight(0xb9dcff, 0x182335, 2.25);
scene.add(hemiLight);
const sun = new THREE.DirectionalLight(0xfff4dc, 3.3);
sun.position.set(5, 10, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -11;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 28;
sun.shadow.bias = -0.0003;
scene.add(sun);
const rimLight = new THREE.PointLight(0x38bdf8, 24, 14, 2);
rimLight.position.set(-6, 4, -4);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xfb7185, 14, 12, 2);
warmLight.position.set(6, 3, 4);
scene.add(warmLight);
const standard = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.08,
flatShading: true,
...options
});
const materials = {
floor: standard(0x111f30),
floorTop: standard(0x17283a),
dark: standard(0x19283a),
darker: standard(0x0b1522),
teal: standard(0x35d6c0),
tealDark: standard(0x167e7a),
cyan: standard(0x38bdf8),
green: standard(0x4ade80),
coral: standard(0xfb7185),
amber: standard(0xfbbf24),
cream: standard(0xd8e2ea),
steel: standard(0x8092a4, { metalness: 0.35 }),
pipe: standard(0x50677e, { metalness: 0.45 })
};
function addMesh(geometry, material, position, parent = scene) {
const mesh = new THREE.Mesh(geometry, material);
if (position) mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeTextSprite(initialText, accent = "#5eead4", width = 3.15) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width / 4, 1);
sprite.renderOrder = 30;
function setText(text, nextAccent = accent) {
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(7, 16, 29, 0.92)";
context.beginPath();
context.roundRect(4, 4, 504, 120, 22);
context.fill();
context.strokeStyle = nextAccent;
context.lineWidth = 3;
context.stroke();
context.fillStyle = nextAccent;
context.fillRect(27, 53, 7, 22);
context.fillStyle = "#edf7ff";
context.font = "700 39px system-ui, sans-serif";
context.textAlign = "left";
context.textBaseline = "middle";
context.fillText(text, 52, 65, 425);
texture.needsUpdate = true;
}
setText(initialText, accent);
sprite.userData.setText = setText;
return sprite;
}
// Low-poly display platform.
addMesh(
new THREE.CylinderGeometry(8.6, 9.05, 0.52, 12),
materials.floor,
[0, -0.35, 0]
);
addMesh(
new THREE.CylinderGeometry(8.48, 8.48, 0.08, 12),
materials.floorTop,
[0, -0.05, 0]
);
const grid = new THREE.GridHelper(16, 16, 0x4b6b83, 0x294155);
grid.position.y = 0.005;
grid.material.transparent = true;
grid.material.opacity = 0.23;
scene.add(grid);
// Decorative perimeter blocks.
const rockGeometry = new THREE.DodecahedronGeometry(0.55, 0);
const rockMaterials = [
standard(0x233a4c),
standard(0x2b4657),
standard(0x1c3446)
];
[
[-6.7, -3.8],
[-5.8, -4.7],
[5.9, -4.3],
[7.0, -3.2],
[-7.1, 2.8],
[6.8, 3.1]
].forEach(([x, z], index) => {
const rock = addMesh(
rockGeometry,
rockMaterials[index % rockMaterials.length],
[x, 0.24, z]
);
rock.rotation.set(index * 0.6, index, 0.4);
rock.scale.set(1.4, 0.75 + (index % 2) * 0.25, 1);
});
// Central true-state reservoir.
addMesh(
new THREE.CylinderGeometry(2.18, 2.28, 0.48, 12),
materials.dark,
[0, 0.24, 0]
);
addMesh(
new THREE.CylinderGeometry(1.94, 2.04, 0.12, 12),
materials.tealDark,
[0, 0.53, 0]
);
const tankGlass = new THREE.Mesh(
new THREE.CylinderGeometry(2.18, 2.18, 2.15, 12, 1, true),
new THREE.MeshStandardMaterial({
color: 0x5eead4,
transparent: true,
opacity: 0.095,
roughness: 0.35,
side: THREE.DoubleSide,
depthWrite: false
})
);
tankGlass.position.y = 1.62;
scene.add(tankGlass);
const tankRingGeometry = new THREE.TorusGeometry(2.18, 0.065, 4, 12);
for (const y of [0.56, 2.68]) {
const ring = addMesh(tankRingGeometry, materials.tealDark, [0, y, 0]);
ring.rotation.x = Math.PI / 2;
}
const postGeometry = new THREE.CylinderGeometry(0.055, 0.055, 2.2, 6);
for (let i = 0; i < 4; i++) {
const angle = Math.PI / 4 + i * Math.PI / 2;
addMesh(
postGeometry,
materials.steel,
[Math.cos(angle) * 2.03, 1.62, Math.sin(angle) * 2.03]
);
}
// Twelve visible crates represent 60 true units.
const actualCrates = [];
const crateGeometry = new THREE.BoxGeometry(0.69, 0.62, 0.69);
const crateEdgeGeometry = new THREE.EdgesGeometry(crateGeometry);
for (let row = 0; row < 3; row++) {
for (let column = 0; column < 4; column++) {
const x = (column - 1.5) * 0.83;
const z = (row - 1) * 0.83;
const crate = addMesh(crateGeometry, materials.teal, [x, 0.9, z]);
actualCrates.push(crate);
const edges = new THREE.LineSegments(
crateEdgeGeometry,
new THREE.LineBasicMaterial({
color: 0xb8fff5,
transparent: true,
opacity: 0.42
})
);
edges.position.copy(crate.position);
scene.add(edges);
}
}
const truthLabel = makeTextSprite("TRUE STATE · 60 U", "#5eead4", 3.25);
truthLabel.position.set(0, 3.38, 0);
scene.add(truthLabel);
function createSensorStation(x, color, title) {
const group = new THREE.Group();
group.position.x = x;
scene.add(group);
addMesh(
new THREE.CylinderGeometry(1.04, 1.12, 0.28, 8),
materials.dark,
[0, 0.13, 0],
group
);
addMesh(
new THREE.CylinderGeometry(0.13, 0.17, 1.2, 8),
materials.steel,
[0, 0.84, 0],
group
);
addMesh(
new THREE.BoxGeometry(0.82, 0.58, 0.62),
materials.dark,
[0, 1.58, 0],
group
);
const lensMaterial = standard(color, {
emissive: color,
emissiveIntensity: 0.8,
roughness: 0.25
});
const lens = addMesh(
new THREE.CylinderGeometry(0.19, 0.19, 0.08, 10),
lensMaterial,
[x < 0 ? 0.44 : -0.44, 1.58, 0],
group
);
lens.rotation.z = Math.PI / 2;
const light = addMesh(
new THREE.SphereGeometry(0.09, 8, 6),
lensMaterial,
[0, 1.98, 0],
group
);
const rail = addMesh(
new THREE.BoxGeometry(0.84, 0.07, 0.08),
materials.steel,
[0, 2.13, 0],
group
);
rail.castShadow = false;
const marker = addMesh(
new THREE.SphereGeometry(0.105, 8, 6),
lensMaterial.clone(),
[0, 2.13, 0.08],
group
);
const titleSprite = makeTextSprite(title, color, 2.7);
titleSprite.position.set(x, 3.25, 0);
scene.add(titleSprite);
const readout = makeTextSprite("READING 0.0", color, 2.5);
readout.position.set(x, 2.67, 0);
scene.add(readout);
return { group, lensMaterial, light, marker, readout };
}
const rawStation = createSensorStation(
-3.45,
"#fbbf24",
"RAW CONTROLLER"
);
const correctedStation = createSensorStation(
3.45,
"#4ade80",
"CORRECTED SENSOR"
);
function createBeam(start, end, color) {
const geometry = new THREE.CylinderGeometry(0.035, 0.38, 1, 8, 1, true);
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.11,
depthWrite: false,
side: THREE.DoubleSide
});
const beam = new THREE.Mesh(geometry, material);
const direction = end.clone().sub(start);
const length = direction.length();
const midpoint = start.clone().add(end).multiplyScalar(0.5);
beam.position.copy(midpoint);
beam.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
beam.scale.y = length;
scene.add(beam);
return beam;
}
const rawBeam = createBeam(
new THREE.Vector3(-3.02, 1.58, 0),
new THREE.Vector3(-1.78, 1.3, 0),
0xfbbf24
);
const correctedBeam = createBeam(
new THREE.Vector3(3.02, 1.58, 0),
new THREE.Vector3(1.78, 1.3, 0),
0x4ade80
);
// Ledger error dock.
const errorDock = new THREE.Group();
errorDock.position.z = 2.85;
scene.add(errorDock);
addMesh(
new THREE.BoxGeometry(3.55, 0.18, 1.2),
materials.dark,
[0, 0.1, 0],
errorDock
);
const dockLabel = makeTextSprite("LEDGER DRIFT", "#fb7185", 2.7);
dockLabel.position.set(0, 1.65, 2.85);
scene.add(dockLabel);
const errorCells = [];
const errorCubeGeometry = new THREE.BoxGeometry(0.48, 0.48, 0.48);
const errorEdgesGeometry = new THREE.EdgesGeometry(errorCubeGeometry);
for (let i = 0; i < 6; i++) {
const cell = new THREE.Group();
cell.position.set((i - 2.5) * 0.53, 0.45, 2.85);
scene.add(cell);
const solid = addMesh(
errorCubeGeometry,
materials.coral,
[0, 0, 0],
cell
);
const wire = new THREE.LineSegments(
errorEdgesGeometry,
new THREE.LineBasicMaterial({
color: 0x60a5fa,
transparent: true,
opacity: 0.9
})
);
cell.add(wire);
errorCells.push({
group: cell,
solid,
wire,
scale: 0,
target: 0
});
}
const balancedTile = addMesh(
new THREE.BoxGeometry(1.25, 0.08, 0.82),
materials.green,
[0, 0.23, 2.85]
);
balancedTile.visible = false;
// Small industrial pipes in the background.
const pipeMaterial = materials.pipe;
const horizontalPipe = addMesh(
new THREE.CylinderGeometry(0.13, 0.13, 4.1, 8),
pipeMaterial,
[-4.3, 0.52, -3.1]
);
horizontalPipe.rotation.z = Math.PI / 2;
const verticalPipe = addMesh(
new THREE.CylinderGeometry(0.13, 0.13, 1.55, 8),
pipeMaterial,
[-2.35, 1.25, -3.1]
);
addMesh(
new THREE.CylinderGeometry(0.13, 0.13, 3.7, 8),
pipeMaterial,
[4.2, 0.52, -3.3]
);
// Direct, dependency-free orbit controls.
const desiredCamera = {
yaw: 0.62,
pitch: 0.58,
distance: 13.2
};
const currentCamera = {
yaw: desiredCamera.yaw,
pitch: desiredCamera.pitch,
distance: desiredCamera.distance
};
const cameraTarget = new THREE.Vector3(0, 1.25, 0.45);
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
desiredCamera.yaw -= dx * 0.006;
desiredCamera.pitch = THREE.MathUtils.clamp(
desiredCamera.pitch + dy * 0.0045,
0.25,
1.08
);
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredCamera.distance = THREE.MathUtils.clamp(
desiredCamera.distance * Math.exp(event.deltaY * 0.001),
8,
19
);
},
{ passive: false }
);
document.querySelector("#resetView").addEventListener("click", () => {
desiredCamera.yaw = 0.62;
desiredCamera.pitch = 0.58;
desiredCamera.distance = 13.2;
});
function signed(value, decimals = 1) {
const rounded = Number(value.toFixed(decimals));
return `${rounded > 0 ? "+" : ""}${rounded.toFixed(decimals)}`;
}
function updateScene(biasPercent) {
const bias = biasPercent / 100;
const rawUnits = TRUE_UNITS * (1 + bias);
const error = rawUnits - TRUE_UNITS;
const correctedUnits = rawUnits - TRUE_UNITS * bias;
biasValue.textContent = signed(biasPercent) + "%";
rawValue.textContent = rawUnits.toFixed(1);
rawDelta.textContent = signed(error);
rawDelta.classList.toggle("bad", Math.abs(error) > 0.01);
correctedValue.textContent = correctedUnits.toFixed(1);
correctedDelta.textContent = signed(correctedUnits - TRUE_UNITS);
correctedDelta.classList.add("good");
errorValue.textContent = `${signed(error)} units`;
const isBalanced = Math.abs(error) < 0.01;
const isNegative = error < -0.01;
errorCard.classList.toggle("negative", isNegative);
errorCard.classList.toggle("balanced", isBalanced);
errorDirection.textContent = isBalanced
? "Balanced"
: isNegative
? "Under-reported"
: "Over-reported";
statusDot.classList.toggle("aligned", isBalanced);
statusText.textContent = isBalanced ? "Reports aligned" : "Drift detected";
estimatedBias.textContent = Math.abs(TRUE_UNITS * bias).toFixed(1);
rawBarValue.textContent = rawUnits.toFixed(1);
fixedBarValue.textContent = correctedUnits.toFixed(1);
const toWidth = (value) =>
`${Math.max(0, Math.min(100, (value / MAX_DISPLAY_UNITS) * 100))}%`;
truthBar.style.width = toWidth(TRUE_UNITS);
rawBar.style.width = toWidth(rawUnits);
fixedBar.style.width = toWidth(correctedUnits);
const rawColor = isBalanced ? "#4ade80" : isNegative ? "#60a5fa" : "#fbbf24";
rawStation.lensMaterial.color.set(rawColor);
rawStation.lensMaterial.emissive.set(rawColor);
rawStation.marker.material.color.set(rawColor);
rawStation.marker.material.emissive.set(rawColor);
rawStation.marker.position.x = THREE.MathUtils.clamp(bias * 1.55, -0.45, 0.45);
rawStation.readout.userData.setText(`RAW ${rawUnits.toFixed(1)}`, rawColor);
rawBeam.material.color.set(rawColor);
correctedStation.readout.userData.setText(
`FIXED ${correctedUnits.toFixed(1)}`,
"#4ade80"
);
const dockColor = isBalanced
? "#4ade80"
: isNegative
? "#60a5fa"
: "#fb7185";
dockLabel.userData.setText(
isBalanced
? "LEDGER BALANCED"
: `LEDGER ${signed(error)}`,
dockColor
);
const chunkSize = Math.abs(error) / 6;
errorCells.forEach((cell, index) => {
const portion = THREE.MathUtils.clamp(chunkSize - index, 0, 1);
cell.target = portion;
cell.solid.visible = error > 0.01;
cell.wire.visible = error < -0.01;
if (error > 0.01) {
cell.solid.material.color.set("#fb7185");
}
});
balancedTile.visible = isBalanced;
const sliderPercent =
((Number(biasInput.value) - Number(biasInput.min)) /
(Number(biasInput.max) - Number(biasInput.min))) *
100;
biasInput.style.setProperty("--fill", `${sliderPercent}%`);
presetButtons.forEach((button) => {
button.classList.toggle(
"active",
Number(button.dataset.bias) === Number(biasInput.value)
);
});
}
biasInput.addEventListener("input", () => {
updateScene(Number(biasInput.value));
});
presetButtons.forEach((button) => {
button.addEventListener("click", () => {
biasInput.value = button.dataset.bias;
updateScene(Number(biasInput.value));
});
});
updateScene(Number(biasInput.value));
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
currentCamera.yaw = THREE.MathUtils.lerp(
currentCamera.yaw,
desiredCamera.yaw,
0.09
);
currentCamera.pitch = THREE.MathUtils.lerp(
currentCamera.pitch,
desiredCamera.pitch,
0.09
);
currentCamera.distance = THREE.MathUtils.lerp(
currentCamera.distance,
desiredCamera.distance,
0.09
);
const { yaw, pitch, distance } = currentCamera;
camera.position.set(
cameraTarget.x + distance * Math.sin(yaw) * Math.cos(pitch),
cameraTarget.y + distance * Math.sin(pitch),
cameraTarget.z + distance * Math.cos(yaw) * Math.cos(pitch)
);
camera.lookAt(cameraTarget);
rawBeam.material.opacity = 0.09 + Math.sin(elapsed * 2.1) * 0.025;
correctedBeam.material.opacity = 0.1 + Math.sin(elapsed * 2.1 + 1.5) * 0.025;
rawStation.light.scale.setScalar(1 + Math.sin(elapsed * 3.3) * 0.08);
correctedStation.light.scale.setScalar(1 + Math.sin(elapsed * 3.3 + 1) * 0.08);
errorCells.forEach((cell, index) => {
cell.scale = THREE.MathUtils.lerp(cell.scale, cell.target, 0.12);
cell.group.visible = cell.scale > 0.005;
cell.group.scale.setScalar(Math.max(0.001, cell.scale));
if (cell.solid.visible) {
cell.solid.rotation.y = elapsed * 0.22 + index * 0.14;
}
});
balancedTile.material.emissive = new THREE.Color(0x14532d);
balancedTile.material.emissiveIntensity =
0.35 + Math.sin(elapsed * 2.6) * 0.15;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```