Prompt specification
Build or customize the Three.js 3D scene "Classification-rule tradeoff 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: Classification-rule tradeoff exhibit
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/classification-rule-tradeoff-exhibit-x1096
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring produce grading. Create fictional grading standards based on size and shape; users change thresholds and compare accepted counts, alternate-use stock, and discarded units without equating appearance with nutritional quality. Low-poly.
Working Three.js Starter (classification-rule-tradeoff-exhibit-x1096):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Produce Grading Lab</title>
<style>
:root {
color-scheme: dark;
--bg: #08111d;
--panel: rgba(13, 23, 37, 0.92);
--panel-soft: rgba(255, 255, 255, 0.045);
--border: rgba(175, 210, 236, 0.16);
--text: #eaf3fa;
--muted: #93a8ba;
--accepted: #58d6a4;
--alternate: #f3b957;
--discarded: #8b99aa;
--cyan: #75d8f2;
--danger: #ff8e83;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
outline: none;
}
#scene canvas:active {
cursor: grabbing;
}
#scene canvas:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: -4px;
}
.brand {
position: fixed;
z-index: 5;
top: 22px;
left: 24px;
width: min(440px, calc(100vw - 430px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 8px;
height: 8px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 15px currentColor;
content: "";
}
.brand h1 {
margin: 0;
font-size: clamp(25px, 3vw, 43px);
line-height: 0.98;
letter-spacing: -0.045em;
}
.brand p {
max-width: 430px;
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.brand-actions {
display: flex;
gap: 8px;
margin-top: 15px;
pointer-events: auto;
}
.small-button,
.pin-button {
border: 1px solid var(--border);
border-radius: 9px;
background: rgba(13, 23, 37, 0.8);
padding: 8px 11px;
cursor: pointer;
transition:
border-color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
.small-button:hover,
.pin-button:hover {
border-color: rgba(117, 216, 242, 0.55);
background: rgba(24, 42, 59, 0.95);
}
.small-button:active,
.pin-button:active {
transform: translateY(1px);
}
.panel {
position: fixed;
z-index: 10;
top: 20px;
right: 20px;
bottom: 20px;
width: 376px;
overflow-y: auto;
border: 1px solid var(--border);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
backdrop-filter: blur(18px);
scrollbar-width: thin;
scrollbar-color: #34485b transparent;
}
.panel-inner {
padding: 20px;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
}
.panel-heading h2 {
margin: 0;
font-size: 18px;
letter-spacing: -0.02em;
}
.live-badge {
flex: 0 0 auto;
border: 1px solid rgba(88, 214, 164, 0.35);
border-radius: 999px;
background: rgba(88, 214, 164, 0.09);
padding: 5px 8px;
color: var(--accepted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.intro {
margin: 0 0 19px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.section-title {
margin: 0 0 11px;
color: #c9d8e4;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.presets {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-bottom: 17px;
}
.preset {
border: 1px solid var(--border);
border-radius: 999px;
background: transparent;
padding: 6px 10px;
color: var(--muted);
font-size: 11px;
cursor: pointer;
}
.preset:hover,
.preset.active {
border-color: rgba(117, 216, 242, 0.45);
background: rgba(117, 216, 242, 0.08);
color: var(--text);
}
.control {
margin-bottom: 16px;
}
.control-label {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
font-size: 12px;
font-weight: 700;
}
.control-label output {
color: var(--cyan);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 0;
border-radius: 999px;
outline: none;
background:
linear-gradient(
90deg,
var(--cyan) 0 var(--fill, 50%),
rgba(255, 255, 255, 0.1) var(--fill, 50%) 100%
);
appearance: none;
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
border: 3px solid #102131;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 0 1px rgba(117, 216, 242, 0.55);
appearance: none;
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 3px solid #102131;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 0 1px rgba(117, 216, 242, 0.55);
}
.range-ends {
display: flex;
justify-content: space-between;
margin-top: 5px;
color: #6e8396;
font-size: 9px;
}
.rule-box {
margin: 4px 0 20px;
border-left: 2px solid var(--cyan);
border-radius: 0 8px 8px 0;
background: rgba(117, 216, 242, 0.055);
padding: 9px 10px;
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
.rule-box strong {
color: #dce9f3;
font-weight: 650;
}
.metric-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-bottom: 12px;
}
.metric {
min-width: 0;
border: 1px solid var(--border);
border-radius: 11px;
background: var(--panel-soft);
padding: 10px;
}
.metric span {
display: block;
overflow: hidden;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.04em;
text-overflow: ellipsis;
text-transform: uppercase;
white-space: nowrap;
}
.metric strong {
display: block;
margin-top: 5px;
font-size: 25px;
line-height: 1;
font-variant-numeric: tabular-nums;
}
.metric small {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 9px;
}
.metric.accepted strong {
color: var(--accepted);
}
.metric.alternate strong {
color: var(--alternate);
}
.metric.discarded strong {
color: var(--discarded);
}
.stack {
display: flex;
height: 9px;
overflow: hidden;
margin-bottom: 19px;
border-radius: 999px;
background: rgba(255, 255, 255, 0.06);
}
.stack span {
height: 100%;
transition: width 220ms ease;
}
#acceptedBar {
background: var(--accepted);
}
#alternateBar {
background: var(--alternate);
}
#discardedBar {
background: var(--discarded);
}
.comparison {
border-top: 1px solid var(--border);
padding-top: 17px;
}
.comparison-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 9px;
}
.comparison-heading h3 {
margin: 0;
font-size: 12px;
}
#pinnedLabel {
color: var(--muted);
font-size: 9px;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 11px;
}
th,
td {
border-bottom: 1px solid rgba(255, 255, 255, 0.07);
padding: 8px 4px;
text-align: right;
font-variant-numeric: tabular-nums;
}
thead th {
color: #71889b;
font-size: 9px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
th:first-child {
text-align: left;
}
tbody th {
color: #bacbd8;
font-weight: 600;
}
.comparison-summary {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin: 9px 0 12px;
color: var(--muted);
font-size: 10px;
}
#delta {
font-weight: 800;
}
#delta.positive {
color: var(--accepted);
}
#delta.negative {
color: var(--danger);
}
.pin-button {
width: 100%;
padding: 10px;
font-size: 11px;
font-weight: 750;
}
.note {
display: flex;
gap: 9px;
margin-top: 18px;
border: 1px solid rgba(243, 185, 87, 0.23);
border-radius: 11px;
background: rgba(243, 185, 87, 0.06);
padding: 11px;
color: #c7bda8;
font-size: 10px;
line-height: 1.5;
}
.note-icon {
flex: 0 0 auto;
color: var(--alternate);
font-size: 14px;
line-height: 1;
}
.legend {
position: fixed;
z-index: 5;
bottom: 24px;
left: 24px;
display: flex;
flex-wrap: wrap;
gap: 8px;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
border: 1px solid var(--border);
border-radius: 999px;
background: rgba(8, 17, 29, 0.78);
padding: 7px 10px;
color: #b9c9d6;
font-size: 10px;
backdrop-filter: blur(10px);
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
}
.hint {
position: fixed;
z-index: 5;
bottom: 25px;
left: 50%;
transform: translateX(-50%);
color: rgba(186, 207, 222, 0.62);
font-size: 10px;
pointer-events: none;
white-space: nowrap;
}
#tooltip {
position: fixed;
z-index: 30;
display: none;
min-width: 190px;
border: 1px solid rgba(117, 216, 242, 0.38);
border-radius: 10px;
background: rgba(8, 17, 29, 0.96);
box-shadow: 0 12px 35px rgba(0, 0, 0, 0.38);
padding: 10px 12px;
pointer-events: none;
backdrop-filter: blur(12px);
}
#tooltip .tooltip-title {
margin-bottom: 6px;
color: var(--text);
font-size: 11px;
font-weight: 800;
}
#tooltip .tooltip-row {
display: flex;
justify-content: space-between;
gap: 20px;
color: var(--muted);
font-size: 10px;
line-height: 1.65;
}
#tooltip .tooltip-row b {
color: #dce9f3;
font-weight: 650;
}
@media (max-width: 900px) {
.brand {
width: calc(100vw - 410px);
}
.hint {
display: none;
}
}
@media (max-width: 760px) {
.brand {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
}
.brand h1 {
font-size: 28px;
}
.brand p,
.brand-actions {
display: none;
}
.panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 49vh;
border-radius: 15px;
}
.panel-inner {
padding: 15px;
}
.intro,
.rule-box {
display: none;
}
.presets {
margin-bottom: 12px;
}
.control {
margin-bottom: 12px;
}
.legend {
top: 100px;
bottom: auto;
left: 14px;
gap: 5px;
}
.legend-item {
padding: 5px 8px;
font-size: 9px;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive low-poly produce grading scene"></main>
<header class="brand">
<div class="eyebrow">Fictional handling standard</div>
<h1>Produce<br>Grading Lab</h1>
<p>
Tune size and shape thresholds, then inspect how a fictional sorting stream
distributes a fixed batch of 72 low-poly produce units.
</p>
<div class="brand-actions">
<button id="resetView" class="small-button" type="button">Reset camera</button>
</div>
</header>
<aside class="panel" aria-label="Grading controls and results">
<div class="panel-inner">
<div class="panel-heading">
<h2>Threshold controls</h2>
<span class="live-badge">Live batch</span>
</div>
<p class="intro">
The standard is invented for this demonstration. It models only
size and shape suitability for a hypothetical packing process.
</p>
<h3 class="section-title">Quick standards</h3>
<div class="presets">
<button class="preset" type="button" data-size="7.4" data-shape="6">Strict</button>
<button class="preset active" type="button" data-size="6.2" data-shape="10">Balanced</button>
<button class="preset" type="button" data-size="5.1" data-shape="15">Relaxed</button>
</div>
<div class="control">
<label class="control-label" for="sizeRange">
<span>Minimum fictional size</span>
<output id="sizeOutput" for="sizeRange">6.2 cm</output>
</label>
<input id="sizeRange" type="range" min="4.5" max="9" step="0.1" value="6.2">
<div class="range-ends"><span>4.5 cm</span><span>9.0 cm</span></div>
</div>
<div class="control">
<label class="control-label" for="shapeRange">
<span>Maximum shape deviation</span>
<output id="shapeOutput" for="shapeRange">10%</output>
</label>
<input id="shapeRange" type="range" min="2" max="20" step="0.5" value="10">
<div class="range-ends"><span>2% regular</span><span>20% irregular</span></div>
</div>
<div class="rule-box">
<strong>Accepted:</strong> size ≥ <span id="ruleSize">6.2</span> cm and
shape deviation ≤ <span id="ruleShape">10</span>%.<br>
<strong>Alternate-use band:</strong> at least 85% of the size floor and
no more than 135% of the shape allowance.
</div>
<h3 class="section-title">Batch distribution</h3>
<div class="metric-grid">
<div class="metric accepted">
<span>Accepted</span>
<strong id="acceptedCount">—</strong>
<small id="acceptedPct">—% of batch</small>
</div>
<div class="metric alternate">
<span>Alternate stock</span>
<strong id="alternateCount">—</strong>
<small id="alternatePct">—% of batch</small>
</div>
<div class="metric discarded">
<span>Discarded units</span>
<strong id="discardedCount">—</strong>
<small id="discardedPct">—% of batch</small>
</div>
</div>
<div class="stack" aria-label="Batch distribution bar">
<span id="acceptedBar"></span>
<span id="alternateBar"></span>
<span id="discardedBar"></span>
</div>
<section class="comparison">
<div class="comparison-heading">
<h3>Compare against a pinned result</h3>
<span id="pinnedLabel">Balanced baseline</span>
</div>
<table>
<thead>
<tr>
<th>Category</th>
<th>Current</th>
<th>Pinned</th>
</tr>
</thead>
<tbody>
<tr>
<th>Accepted</th>
<td id="currentAccepted">—</td>
<td id="pinnedAccepted">—</td>
</tr>
<tr>
<th>Alternate</th>
<td id="currentAlternate">—</td>
<td id="pinnedAlternate">—</td>
</tr>
<tr>
<th>Discarded</th>
<td id="currentDiscarded">—</td>
<td id="pinnedDiscarded">—</td>
</tr>
</tbody>
</table>
<div class="comparison-summary">
<span>Accepted-count difference</span>
<span id="delta">+0</span>
</div>
<button id="pinComparison" class="pin-button" type="button">
Pin current result for comparison
</button>
</section>
<div class="note">
<span class="note-icon">◆</span>
<span>
<strong>Appearance is not a nutrition or safety measure.</strong>
Size, shape, and visible appearance do not establish nutritional
quality, freshness, safety, or edibility. “Discarded” means excluded
only from this fictional grading stream.
</span>
</div>
</div>
</aside>
<div class="legend" aria-label="Category legend">
<div class="legend-item">
<span class="dot" style="background: var(--accepted)"></span>Accepted
</div>
<div class="legend-item">
<span class="dot" style="background: var(--alternate)"></span>Alternate-use
</div>
<div class="legend-item">
<span class="dot" style="background: var(--discarded)"></span>Discarded
</div>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Click a unit to inspect</div>
<div id="tooltip" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// DOM references
// -------------------------------------------------------------------------
const sceneRoot = document.getElementById("scene");
const sizeRange = document.getElementById("sizeRange");
const shapeRange = document.getElementById("shapeRange");
const sizeOutput = document.getElementById("sizeOutput");
const shapeOutput = document.getElementById("shapeOutput");
const ruleSize = document.getElementById("ruleSize");
const ruleShape = document.getElementById("ruleShape");
const tooltip = document.getElementById("tooltip");
const thresholds = {
size: Number(sizeRange.value),
shape: Number(shapeRange.value)
};
const TOTAL_UNITS = 72;
// -------------------------------------------------------------------------
// Renderer, camera, and lighting
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"3D produce grading scene. Drag to orbit, scroll to zoom, and click a unit to inspect."
);
sceneRoot.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x08111d);
scene.fog = new THREE.Fog(0x08111d, 24, 45);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const orbit = {
target: new THREE.Vector3(0.8, 0.55, 0),
theta: 0.62,
phi: 0.98,
radius: 19.5
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xb8d9ef, 0x172033, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff1d7, 3.3);
keyLight.position.set(-7, 13, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 11;
keyLight.shadow.camera.bottom = -11;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x5ac8ef, 1.8);
rimLight.position.set(8, 7, -9);
scene.add(rimLight);
const warmFill = new THREE.PointLight(0xffb96d, 16, 18, 2);
warmFill.position.set(4, 3, 6);
scene.add(warmFill);
// -------------------------------------------------------------------------
// Materials and reusable geometry
// -------------------------------------------------------------------------
function makeMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.76,
metalness: 0.04,
flatShading: true,
...options
});
}
const materials = {
floor: makeMaterial(0x0b1522, { roughness: 0.96 }),
frame: makeMaterial(0x1b2a3d),
frameEdge: makeMaterial(0x30445a),
belt: makeMaterial(0x0d1520, { roughness: 0.96 }),
beltMark: new THREE.MeshBasicMaterial({
color: 0x31546a,
transparent: true,
opacity: 0.36
}),
rail: makeMaterial(0x536b7c, { metalness: 0.28 }),
leg: makeMaterial(0x162334),
stem: makeMaterial(0x5a3d2b),
scanner: new THREE.MeshBasicMaterial({
color: 0x69dcf6,
transparent: true,
opacity: 0.13,
depthWrite: false
})
};
const statusMaterials = {
accepted: {
body: makeMaterial(0x58d6a4, {
emissive: 0x0b3829,
emissiveIntensity: 0.16
}),
pad: new THREE.MeshBasicMaterial({
color: 0x58d6a4,
transparent: true,
opacity: 0.62
})
},
alternate: {
body: makeMaterial(0xf3b957, {
emissive: 0x3b2606,
emissiveIntensity: 0.14
}),
pad: new THREE.MeshBasicMaterial({
color: 0xf3b957,
transparent: true,
opacity: 0.62
})
},
discarded: {
body: makeMaterial(0x8b99aa, {
emissive: 0x111820,
emissiveIntensity: 0.08
}),
pad: new THREE.MeshBasicMaterial({
color: 0x8b99aa,
transparent: true,
opacity: 0.52
})
}
};
function addBox(width, height, depth, x, y, z, material, 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;
}
// -------------------------------------------------------------------------
// Environment, conveyor, and collection trays
// -------------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(34, 30),
materials.floor
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.1;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(30, 30, 0x2c465c, 0x193044);
grid.position.y = -1.085;
grid.material.transparent = true;
grid.material.opacity = 0.23;
scene.add(grid);
addBox(17.4, 0.62, 6.9, 0, 0.17, 0, materials.frame);
addBox(16.5, 0.16, 6.15, 0, 0.56, 0, materials.belt);
for (const z of [-3.28, 3.28]) {
addBox(17.5, 0.34, 0.18, 0, 0.83, z, materials.frameEdge);
}
for (const x of [-7.2, -3.6, 0, 3.6, 7.2]) {
for (const z of [-2.8, 2.8]) {
addBox(0.32, 1.25, 0.32, x, -0.49, z, materials.leg);
}
}
// Decorative rollers under the belt.
const rollerGeometry = new THREE.CylinderGeometry(0.22, 0.22, 6.1, 10);
const rollerMaterial = makeMaterial(0x263a4c, { metalness: 0.3 });
for (let x = -7.7; x <= 7.8; x += 1.3) {
const roller = new THREE.Mesh(rollerGeometry, rollerMaterial);
roller.rotation.x = Math.PI / 2;
roller.position.set(x, 0.38, 0);
roller.castShadow = true;
scene.add(roller);
}
// Moving belt seams.
const beltSeams = [];
const seamGeometry = new THREE.BoxGeometry(0.025, 0.018, 5.85);
for (let i = 0; i < 12; i++) {
const seam = new THREE.Mesh(seamGeometry, materials.beltMark);
seam.position.set(-8 + i * 1.45, 0.648, 0);
scene.add(seam);
beltSeams.push(seam);
}
function makeTextSprite(text, color = "#dcecf7") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(8, 17, 29, 0.92)";
context.fillRect(8, 16, 496, 96);
context.strokeStyle = color;
context.globalAlpha = 0.55;
context.lineWidth = 4;
context.strokeRect(8, 16, 496, 96);
context.globalAlpha = 1;
context.fillStyle = color;
context.font = "700 37px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 66);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(2.65, 0.66, 1);
return sprite;
}
function makeTray(x, label, status) {
const group = new THREE.Group();
group.position.set(x, 0, -4.5);
const trayMaterial = makeMaterial(
new THREE.Color(statusMaterials[status].body.color).multiplyScalar(0.43),
{ metalness: 0.12 }
);
addBox(2.35, 0.16, 1.45, 0, -0.95, 0, trayMaterial, group);
addBox(2.35, 0.58, 0.12, 0, -0.59, 0.66, trayMaterial, group);
addBox(2.35, 0.58, 0.12, 0, -0.59, -0.66, trayMaterial, group);
addBox(0.12, 0.58, 1.2, -1.11, -0.59, 0, trayMaterial, group);
addBox(0.12, 0.58, 1.2, 1.11, -0.59, 0, trayMaterial, group);
const sprite = makeTextSprite(
label,
`#${statusMaterials[status].body.color.getHexString()}`
);
sprite.position.set(0, 0.2, 0);
group.add(sprite);
scene.add(group);
}
makeTray(-3.2, "ACCEPTED", "accepted");
makeTray(0, "ALTERNATE", "alternate");
makeTray(3.2, "DISCARDED", "discarded");
// Translucent scanning gate.
const scannerGroup = new THREE.Group();
const scannerBeam = new THREE.Mesh(
new THREE.BoxGeometry(0.075, 2.65, 6.2),
materials.scanner
);
scannerBeam.position.y = 1.86;
scannerGroup.add(scannerBeam);
const scannerLabel = makeTextSprite("SIZE + SHAPE SCAN", "#75d8f2");
scannerLabel.scale.set(1.9, 0.48, 1);
scannerLabel.position.set(0, 3.0, 0);
scannerGroup.add(scannerLabel);
scene.add(scannerGroup);
// -------------------------------------------------------------------------
// Deterministic produce batch
// -------------------------------------------------------------------------
function mulberry32(seed) {
return function () {
let t = seed += 0x6D2B79F5;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = mulberry32(20250318);
const items = [];
const pickableBodies = [];
const bodyGeometry = new THREE.IcosahedronGeometry(0.39, 1);
const padGeometry = new THREE.CircleGeometry(0.33, 10);
const stemGeometry = new THREE.CylinderGeometry(0.035, 0.052, 0.18, 5);
const ringGeometry = new THREE.TorusGeometry(0.49, 0.025, 4, 18);
for (let row = 0; row < 6; row++) {
for (let column = 0; column < 12; column++) {
const id = row * 12 + column + 1;
const data = {
id,
size: 4.6 + random() * 4.8,
deviation: 1.0 + random() * 20.0,
status: "discarded",
group: null,
body: null,
pad: null,
ring: null
};
const group = new THREE.Group();
const x = -6.45 + column * 1.17;
const z = -2.38 + row * 0.95;
group.position.set(x, 0.665, z);
const pad = new THREE.Mesh(
padGeometry,
statusMaterials.discarded.pad
);
pad.rotation.x = -Math.PI / 2;
pad.position.y = 0.012;
group.add(pad);
const body = new THREE.Mesh(
bodyGeometry,
statusMaterials.discarded.body
);
body.position.y = 0.45;
body.castShadow = true;
body.receiveShadow = true;
body.userData.item = data;
const widthChange = 1 + data.deviation * 0.008;
const heightChange = 1 - data.deviation * 0.006;
body.scale.set(
widthChange,
heightChange,
1 + Math.sin(id * 1.73) * 0.055
);
group.add(body);
const stem = new THREE.Mesh(stemGeometry, materials.stem);
stem.position.y = 0.87;
stem.rotation.z = (random() - 0.5) * 0.18;
stem.castShadow = true;
group.add(stem);
const ring = new THREE.Mesh(
ringGeometry,
new THREE.MeshBasicMaterial({ color: 0xf4fbff })
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.026;
ring.visible = false;
group.add(ring);
const visualScale = data.size / 7;
group.scale.setScalar(visualScale);
data.group = group;
data.body = body;
data.pad = pad;
data.ring = ring;
items.push(data);
pickableBodies.push(body);
scene.add(group);
}
}
// -------------------------------------------------------------------------
// Fictional grading logic
// -------------------------------------------------------------------------
function classify(item) {
const accepted =
item.size >= thresholds.size &&
item.deviation <= thresholds.shape;
if (accepted) return "accepted";
const alternate =
item.size >= thresholds.size * 0.85 &&
item.deviation <= thresholds.shape * 1.35;
return alternate ? "alternate" : "discarded";
}
function getCounts() {
const counts = {
accepted: 0,
alternate: 0,
discarded: 0
};
for (const item of items) {
item.status = classify(item);
counts[item.status]++;
item.body.material = statusMaterials[item.status].body;
item.pad.material = statusMaterials[item.status].pad;
}
return counts;
}
const initialCounts = getCounts();
let pinnedResult = {
...initialCounts,
size: thresholds.size,
shape: thresholds.shape,
name: "Balanced baseline"
};
// -------------------------------------------------------------------------
// Interface updates
// -------------------------------------------------------------------------
function setRangeFill(input) {
const minimum = Number(input.min);
const maximum = Number(input.max);
const percentage =
((Number(input.value) - minimum) / (maximum - minimum)) * 100;
input.style.setProperty("--fill", `${percentage}%`);
}
function updatePresetState() {
document.querySelectorAll(".preset").forEach((button) => {
const matches =
Number(button.dataset.size) === thresholds.size &&
Number(button.dataset.shape) === thresholds.shape;
button.classList.toggle("active", matches);
});
}
function updateComparison(counts) {
document.getElementById("currentAccepted").textContent = counts.accepted;
document.getElementById("currentAlternate").textContent = counts.alternate;
document.getElementById("currentDiscarded").textContent = counts.discarded;
document.getElementById("pinnedAccepted").textContent = pinnedResult.accepted;
document.getElementById("pinnedAlternate").textContent = pinnedResult.alternate;
document.getElementById("pinnedDiscarded").textContent = pinnedResult.discarded;
document.getElementById("pinnedLabel").textContent =
`${pinnedResult.name} · ${pinnedResult.size.toFixed(1)} cm / ${pinnedResult.shape.toFixed(1)}%`;
const difference = counts.accepted - pinnedResult.accepted;
const deltaElement = document.getElementById("delta");
deltaElement.textContent = `${difference >= 0 ? "+" : ""}${difference} units`;
deltaElement.classList.toggle("positive", difference >= 0);
deltaElement.classList.toggle("negative", difference < 0);
}
function updateUI(counts) {
sizeOutput.textContent = `${thresholds.size.toFixed(1)} cm`;
shapeOutput.textContent = `${thresholds.shape.toFixed(1)}%`;
ruleSize.textContent = thresholds.size.toFixed(1);
ruleShape.textContent = thresholds.shape.toFixed(1);
setRangeFill(sizeRange);
setRangeFill(shapeRange);
updatePresetState();
document.getElementById("acceptedCount").textContent = counts.accepted;
document.getElementById("alternateCount").textContent = counts.alternate;
document.getElementById("discardedCount").textContent = counts.discarded;
const percent = (value) => `${((value / TOTAL_UNITS) * 100).toFixed(0)}%`;
document.getElementById("acceptedPct").textContent =
`${percent(counts.accepted)} of batch`;
document.getElementById("alternatePct").textContent =
`${percent(counts.alternate)} of batch`;
document.getElementById("discardedPct").textContent =
`${percent(counts.discarded)} of batch`;
document.getElementById("acceptedBar").style.width =
`${(counts.accepted / TOTAL_UNITS) * 100}%`;
document.getElementById("alternateBar").style.width =
`${(counts.alternate / TOTAL_UNITS) * 100}%`;
document.getElementById("discardedBar").style.width =
`${(counts.discarded / TOTAL_UNITS) * 100}%`;
updateComparison(counts);
if (selectedItem) updateTooltipContent(selectedItem);
}
function applyThresholds() {
thresholds.size = Number(sizeRange.value);
thresholds.shape = Number(shapeRange.value);
const counts = getCounts();
updateUI(counts);
}
sizeRange.addEventListener("input", applyThresholds);
shapeRange.addEventListener("input", applyThresholds);
document.querySelectorAll(".preset").forEach((button) => {
button.addEventListener("click", () => {
sizeRange.value = button.dataset.size;
shapeRange.value = button.dataset.shape;
applyThresholds();
});
});
document.getElementById("pinComparison").addEventListener("click", () => {
const counts = {
accepted: Number(document.getElementById("currentAccepted").textContent),
alternate: Number(document.getElementById("currentAlternate").textContent),
discarded: Number(document.getElementById("currentDiscarded").textContent)
};
pinnedResult = {
...counts,
size: thresholds.size,
shape: thresholds.shape,
name: "Pinned result"
};
updateComparison(counts);
document.getElementById("pinComparison").textContent =
"Current result pinned ✓";
});
// -------------------------------------------------------------------------
// Camera controls implemented without addons
// -------------------------------------------------------------------------
let dragging = false;
let pointerId = null;
let lastPointerX = 0;
let lastPointerY = 0;
let pointerTravel = 0;
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let selectedItem = null;
function raycastAt(clientX, clientY) {
const bounds = renderer.domElement.getBoundingClientRect();
pointer.x = ((clientX - bounds.left) / bounds.width) * 2 - 1;
pointer.y = -((clientY - bounds.top) / bounds.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
return raycaster.intersectObjects(pickableBodies, false)[0] || null;
}
function updateTooltipContent(item) {
const label =
item.status === "accepted"
? "Accepted"
: item.status === "alternate"
? "Alternate-use stock"
: "Discarded from this fictional stream";
const color =
item.status === "accepted"
? "#58d6a4"
: item.status === "alternate"
? "#f3b957"
: "#aebbc8";
tooltip.innerHTML = `
<div class="tooltip-title" style="color:${color}">Unit ${item.id} · ${label}</div>
<div class="tooltip-row"><span>Fictional size</span><b>${item.size.toFixed(1)} cm</b></div>
<div class="tooltip-row"><span>Shape deviation</span><b>${item.deviation.toFixed(1)}%</b></div>
`;
}
function showTooltip(item, clientX, clientY) {
updateTooltipContent(item);
tooltip.style.display = "block";
const maxX = window.innerWidth - 220;
const maxY = window.innerHeight - 100;
tooltip.style.left = `${Math.min(clientX + 15, maxX)}px`;
tooltip.style.top = `${Math.min(clientY + 15, maxY)}px`;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerId = event.pointerId;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
pointerTravel = 0;
renderer.domElement.setPointerCapture(pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (dragging) {
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
pointerTravel += Math.abs(deltaX) + Math.abs(deltaY);
orbit.theta -= deltaX * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - deltaY * 0.005,
0.52,
1.36
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
} else {
const hit = raycastAt(event.clientX, event.clientY);
renderer.domElement.style.cursor = hit ? "pointer" : "grab";
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!dragging) return;
dragging = false;
if (renderer.domElement.hasPointerCapture(pointerId)) {
renderer.domElement.releasePointerCapture(pointerId);
}
if (pointerTravel < 6) {
const hit = raycastAt(event.clientX, event.clientY);
if (hit) {
if (selectedItem) selectedItem.ring.visible = false;
selectedItem = hit.object.userData.item;
selectedItem.ring.visible = true;
showTooltip(selectedItem, event.clientX, event.clientY);
} else {
if (selectedItem) selectedItem.ring.visible = false;
selectedItem = null;
tooltip.style.display = "none";
}
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
12,
26
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("keydown", (event) => {
const key = event.key;
if (key === "ArrowLeft") orbit.theta -= 0.09;
else if (key === "ArrowRight") orbit.theta += 0.09;
else if (key === "ArrowUp") orbit.phi -= 0.07;
else if (key === "ArrowDown") orbit.phi += 0.07;
else if (key === "+" || key === "=") orbit.radius -= 0.8;
else if (key === "-" || key === "_") orbit.radius += 0.8;
else return;
orbit.phi = THREE.MathUtils.clamp(orbit.phi, 0.52, 1.36);
orbit.radius = THREE.MathUtils.clamp(orbit.radius, 12, 26);
updateCamera();
event.preventDefault();
});
document.getElementById("resetView").addEventListener("click", () => {
orbit.target.set(0.8, 0.55, 0);
orbit.theta = 0.62;
orbit.phi = 0.98;
orbit.radius = 19.5;
updateCamera();
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function onResize() {
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, false);
}
window.addEventListener("resize", onResize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
for (const seam of beltSeams) {
seam.position.x += delta * 0.55;
if (seam.position.x > 8.15) seam.position.x = -8.15;
}
scannerGroup.position.x = -8.05 + ((elapsed * 1.35) % 16.1);
materials.scanner.opacity = 0.105 + Math.sin(elapsed * 4) * 0.025;
if (selectedItem) {
selectedItem.ring.material.opacity = 0.78;
selectedItem.ring.scale.setScalar(
1 + Math.sin(elapsed * 4) * 0.035
);
}
renderer.render(scene, camera);
}
applyThresholds();
animate();
</script>
</body>
</html>
```