Prompt specification
Build or customize the Three.js 3D scene "Factory quality classification 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: Factory quality classification exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/factory-quality-classification-exhibit-x1779
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a voxel factory-quality exhibit with two production lines. Each line ends at a tray of fictional products, with shape markers identifying defects independently of product color. Beside the individual trays, show a combined tray or counter that includes every item once. Clicking a line changes the reference set used for the defect proportion; selecting both restores the overall proportion. Keep the numerators and denominators physically countable and label the dataset synthetic. Arrange unequal line sizes so the overall percentage is visibly a weighted result rather than a simple average of the two displayed percentages.
Working Three.js Starter (factory-quality-classification-exhibit-x1779):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Factory — Synthetic Quality Exhibit</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(11, 18, 30, 0.88);
--border: rgba(120, 207, 255, 0.28);
--cyan: #70dcff;
--amber: #ffc857;
--green: #85e89b;
--muted: #a9b7c9;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #101827;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
#panel {
position: fixed;
z-index: 10;
top: 18px;
left: 18px;
width: min(380px, calc(100vw - 36px));
padding: 18px;
color: #edf7ff;
background: var(--panel);
border: 1px solid var(--border);
border-radius: 16px;
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
backdrop-filter: blur(14px);
user-select: none;
}
.eyebrow {
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 5px 0 4px;
font-size: 25px;
line-height: 1.05;
letter-spacing: -0.03em;
}
.subtitle {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.synthetic {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 12px;
padding: 6px 9px;
color: #ffe6a6;
background: rgba(255, 200, 87, 0.11);
border: 1px solid rgba(255, 200, 87, 0.3);
border-radius: 999px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.synthetic::before {
content: "";
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--amber);
box-shadow: 0 0 12px rgba(255, 200, 87, 0.8);
}
.divider {
height: 1px;
margin: 15px 0;
background: rgba(255, 255, 255, 0.1);
}
.section-label {
margin-bottom: 8px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.buttons {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 7px;
}
button {
min-height: 39px;
padding: 8px 9px;
color: #dce8f4;
background: rgba(255, 255, 255, 0.055);
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 9px;
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition: 150ms ease;
}
button:hover {
background: rgba(112, 220, 255, 0.12);
border-color: rgba(112, 220, 255, 0.45);
}
button.active {
color: #07111d;
background: var(--cyan);
border-color: var(--cyan);
box-shadow: 0 0 20px rgba(112, 220, 255, 0.22);
}
#both.active {
background: var(--green);
border-color: var(--green);
box-shadow: 0 0 20px rgba(133, 232, 155, 0.2);
}
.readout {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
align-items: end;
margin-top: 13px;
padding: 13px;
background: rgba(0, 0, 0, 0.22);
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 12px;
}
#ref-name {
margin-bottom: 3px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
#ref-ratio {
font-size: 29px;
font-weight: 850;
letter-spacing: -0.05em;
}
#ref-percent {
color: var(--amber);
font-size: 25px;
font-weight: 850;
}
.formula {
margin-top: 11px;
color: #d6e2ef;
font-size: 12px;
line-height: 1.55;
}
.formula strong {
color: var(--amber);
}
.legend {
display: flex;
align-items: center;
gap: 15px;
margin-top: 13px;
color: var(--muted);
font-size: 11px;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.diamond {
width: 12px;
height: 12px;
border: 2px solid #fff;
transform: rotate(45deg);
}
.cube {
width: 12px;
height: 12px;
background: #71a7ff;
border: 2px solid #b8d2ff;
border-radius: 2px;
}
#help {
position: fixed;
z-index: 9;
right: 16px;
bottom: 15px;
padding: 8px 11px;
color: #b9c8d9;
background: rgba(8, 14, 24, 0.72);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 9px;
font-size: 11px;
pointer-events: none;
}
@media (max-width: 700px) {
#panel {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 13px;
}
h1 { font-size: 21px; }
.subtitle { font-size: 11px; }
.divider { margin: 11px 0; }
#help { display: none; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive 3D voxel factory quality exhibit"></canvas>
<section id="panel">
<div class="eyebrow">Exhibit 02 / Quality Lab</div>
<h1>Voxel Factory</h1>
<p class="subtitle">
Click either conveyor or tray to change the active reference dataset.
Select both lines for the weighted overall result.
</p>
<div class="synthetic">Synthetic dataset</div>
<div class="divider"></div>
<div class="section-label">Reference set</div>
<div class="buttons">
<button id="choose-a" type="button">Line A</button>
<button id="choose-b" type="button">Line B</button>
<button id="both" type="button">Both</button>
</div>
<div class="readout">
<div>
<div id="ref-name">Both lines · overall</div>
<div id="ref-ratio">5 / 17</div>
</div>
<div id="ref-percent">29.4%</div>
</div>
<div class="formula">
A: <strong>3 / 12 = 25.0%</strong><br />
B: <strong>2 / 5 = 40.0%</strong><br />
Both: <strong>(3 + 2) / (12 + 5) = 29.4%</strong><br />
The simple mean, 32.5%, is not used.
</div>
<div class="legend">
<div class="legend-item"><span class="diamond"></span>Diamond marker = defect</div>
<div class="legend-item"><span class="cube"></span>Block = one unit</div>
</div>
</section>
<div id="help">Drag: orbit · Wheel: zoom · Click line: select reference · R: reset view</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x101827);
scene.fog = new THREE.Fog(0x101827, 42, 78);
const camera = new THREE.OrthographicCamera(-16, 16, 10, -10, 0.1, 120);
const cameraTarget = new THREE.Vector3(0, 0, -1.5);
const cameraSpherical = new THREE.Spherical(36, 0.83, 0.72);
let cameraZoom = 1;
scene.add(new THREE.HemisphereLight(0xc9e9ff, 0x172033, 2.0));
const sun = new THREE.DirectionalLight(0xfff2d5, 3.25);
sun.position.set(-12, 21, 15);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -22;
sun.shadow.camera.right = 22;
sun.shadow.camera.top = 20;
sun.shadow.camera.bottom = -20;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 60;
sun.shadow.bias = -0.00035;
scene.add(sun);
const cyanLight = new THREE.PointLight(0x50d8ff, 22, 24, 2);
cyanLight.position.set(8, 7, -1);
scene.add(cyanLight);
const amberLight = new THREE.PointLight(0xff9d43, 18, 20, 2);
amberLight.position.set(-10, 5, 3);
scene.add(amberLight);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x07111d,
transparent: true,
opacity: 0.38
});
const material = {
platform: new THREE.MeshStandardMaterial({ color: 0x182438, roughness: 0.82, metalness: 0.12 }),
platformEdge: new THREE.MeshStandardMaterial({ color: 0x263952, roughness: 0.7 }),
wall: new THREE.MeshStandardMaterial({ color: 0x1b2a3d, roughness: 0.9 }),
dark: new THREE.MeshStandardMaterial({ color: 0x111b29, roughness: 0.58, metalness: 0.55 }),
belt: new THREE.MeshStandardMaterial({ color: 0x202b38, roughness: 0.92 }),
slat: new THREE.MeshStandardMaterial({ color: 0x425164, roughness: 0.72, metalness: 0.35 }),
silver: new THREE.MeshStandardMaterial({ color: 0x9aabba, roughness: 0.42, metalness: 0.72 }),
cream: new THREE.MeshStandardMaterial({ color: 0xdfe8e8, roughness: 0.68 }),
cyan: new THREE.MeshStandardMaterial({
color: 0x4cc9f0, roughness: 0.45, metalness: 0.15,
emissive: 0x173847, emissiveIntensity: 0.55
}),
amber: new THREE.MeshStandardMaterial({
color: 0xffb703, roughness: 0.48, metalness: 0.12,
emissive: 0x563500, emissiveIntensity: 0.5
}),
green: new THREE.MeshStandardMaterial({
color: 0x80d79b, roughness: 0.5, metalness: 0.1,
emissive: 0x173e25, emissiveIntensity: 0.45
}),
blueZone: new THREE.MeshStandardMaterial({ color: 0x243e58, roughness: 0.8 }),
greenZone: new THREE.MeshStandardMaterial({ color: 0x294536, roughness: 0.8 }),
window: new THREE.MeshStandardMaterial({
color: 0x83d8ef,
emissive: 0x3aaac7,
emissiveIntensity: 1.6,
roughness: 0.25
})
};
const palette = [
0x4cc9f0, 0xffb703, 0x90be6d, 0xf72585, 0x9b5de5, 0x00b4d8
];
const markers = [];
const beacons = [];
const clickables = [];
function addBox(parent, w, h, d, mat, x = 0, y = 0, z = 0, outlined = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
if (outlined) {
const edges = new THREE.LineSegments(new THREE.EdgesGeometry(mesh.geometry), edgeMaterial);
mesh.add(edges);
}
return mesh;
}
function roundedRect(ctx, x, y, w, h, r) {
const radius = Math.min(r, w * 0.5, h * 0.5);
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.arcTo(x + w, y, x + w, y + h, radius);
ctx.arcTo(x + w, y + h, x, y + h, radius);
ctx.arcTo(x, y + h, x, y, radius);
ctx.arcTo(x, y, x + w, y, radius);
ctx.closePath();
}
function createTextPlaque(lines, worldWidth, worldHeight, position, parent = scene) {
const canvas = document.createElement("canvas");
canvas.width = 1200;
canvas.height = 300;
const ctx = canvas.getContext("2d");
const gradient = ctx.createLinearGradient(0, 0, canvas.width, canvas.height);
gradient.addColorStop(0, "#122236");
gradient.addColorStop(1, "#0a1320");
ctx.fillStyle = gradient;
roundedRect(ctx, 8, 8, canvas.width - 16, canvas.height - 16, 28);
ctx.fill();
ctx.strokeStyle = lines.accent || "#70dcff";
ctx.lineWidth = 7;
ctx.stroke();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
let y = canvas.height * 0.5 - ((lines.length - 1) * 42) / 2;
for (const line of lines) {
ctx.fillStyle = line.color || "#eef8ff";
ctx.font = `${line.bold === false ? 500 : 800} ${line.size || 48}px system-ui, sans-serif`;
ctx.fillText(line.text, canvas.width * 0.5, y);
y += line.gap || 72;
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
toneMapped: false
}));
sprite.scale.set(worldWidth, worldHeight, 1);
sprite.position.set(position[0], position[1], position[2]);
sprite.renderOrder = 6;
parent.add(sprite);
return sprite;
}
function drawDiamond(ctx, x, y, size, color) {
ctx.save();
ctx.translate(x, y);
ctx.rotate(Math.PI / 4);
ctx.strokeStyle = color;
ctx.lineWidth = 5;
ctx.strokeRect(-size / 2, -size / 2, size, size);
ctx.restore();
}
function drawCountBoard(board, data) {
const ctx = board.ctx;
const w = board.canvas.width;
const h = board.canvas.height;
ctx.clearRect(0, 0, w, h);
const gradient = ctx.createLinearGradient(0, 0, w, h);
gradient.addColorStop(0, "#14263a");
gradient.addColorStop(0.58, "#0c1725");
gradient.addColorStop(1, "#08111d");
ctx.fillStyle = gradient;
roundedRect(ctx, 7, 7, w - 14, h - 14, 30);
ctx.fill();
ctx.strokeStyle = data.accent || "#70dcff";
ctx.lineWidth = 8;
ctx.stroke();
ctx.textAlign = "left";
ctx.textBaseline = "middle";
ctx.fillStyle = data.accent || "#70dcff";
ctx.font = "800 43px system-ui, sans-serif";
ctx.fillText(data.title, 54, 66);
ctx.fillStyle = "#b8c7d8";
ctx.font = "600 25px system-ui, sans-serif";
ctx.fillText(data.note, 55, 112);
ctx.textAlign = "center";
ctx.fillStyle = "#ffffff";
ctx.font = "900 91px system-ui, sans-serif";
ctx.fillText(`${data.defects} / ${data.total}`, 475, 193);
ctx.textAlign = "right";
ctx.fillStyle = data.accent || "#70dcff";
ctx.font = "900 68px system-ui, sans-serif";
ctx.fillText(data.percent, 1145, 193);
ctx.textAlign = "left";
ctx.fillStyle = "#aebdd0";
ctx.font = "750 22px system-ui, sans-serif";
ctx.fillText("DEFECT TOKENS", 55, 271);
const diamondSize = 28;
const diamondGap = 14;
const diamondTotal = data.defects * diamondSize + Math.max(0, data.defects - 1) * diamondGap;
let dx = (w - diamondTotal) / 2 + diamondSize / 2;
for (let i = 0; i < data.defects; i++) {
drawDiamond(ctx, dx, 321, diamondSize, "#fff6cf");
dx += diamondSize + diamondGap;
}
ctx.fillStyle = "#aebdd0";
ctx.font = "750 22px system-ui, sans-serif";
ctx.fillText("UNIT TOKENS", 55, 396);
const squareSize = 26;
const squareGap = 9;
const squareTotal = data.total * squareSize + Math.max(0, data.total - 1) * squareGap;
let sx = (w - squareTotal) / 2 + squareSize / 2;
for (let i = 0; i < data.total; i++) {
ctx.fillStyle = i < data.defects ? "#ffe6a6" : "#86bfff";
ctx.fillRect(sx - squareSize / 2, 422, squareSize, squareSize);
ctx.strokeStyle = "#07111d";
ctx.lineWidth = 3;
ctx.strokeRect(sx - squareSize / 2, 422, squareSize, squareSize);
sx += squareSize + squareGap;
}
if (data.comparison) {
ctx.textAlign = "center";
ctx.fillStyle = "#ffc857";
ctx.font = "750 23px system-ui, sans-serif";
ctx.fillText(data.comparison, w / 2, 554);
}
board.texture.needsUpdate = true;
}
function createCountBoard(worldWidth, worldHeight, position, data, parent = scene) {
const canvas = document.createElement("canvas");
canvas.width = 1200;
canvas.height = 600;
const ctx = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
toneMapped: false
}));
sprite.scale.set(worldWidth, worldHeight, 1);
sprite.position.set(position[0], position[1], position[2]);
sprite.renderOrder = 7;
parent.add(sprite);
const board = { canvas, ctx, texture, sprite };
drawCountBoard(board, data);
return board;
}
// Display platform and factory shell.
const platform = addBox(scene, 30, 0.55, 18.5, material.platform, 0, -0.3, -0.6);
platform.receiveShadow = true;
addBox(scene, 30.3, 0.18, 18.8, material.platformEdge, 0, -0.58, -0.6, false);
const grid = new THREE.GridHelper(30, 30, 0x41617c, 0x263d54);
grid.position.set(0, 0.012, -0.6);
grid.material.transparent = true;
grid.material.opacity = 0.42;
scene.add(grid);
const outsideFloor = new THREE.Mesh(
new THREE.PlaneGeometry(160, 160),
new THREE.MeshStandardMaterial({ color: 0x0c1420, roughness: 1 })
);
outsideFloor.rotation.x = -Math.PI / 2;
outsideFloor.position.y = -0.7;
outsideFloor.receiveShadow = true;
scene.add(outsideFloor);
addBox(scene, 30, 5.2, 0.5, material.wall, 0, 2.55, -9.75);
addBox(scene, 30.3, 0.25, 0.75, material.silver, 0, 5.25, -9.7, false);
for (const x of [-11.5, -8, -4.5, 4.5, 8, 11.5]) {
addBox(scene, 2.3, 1.65, 0.08, material.window, x, 3.5, -9.45, false);
addBox(scene, 0.08, 1.7, 0.12, material.silver, x, 3.5, -9.37, false);
addBox(scene, 2.35, 0.08, 0.12, material.silver, x, 3.5, -9.37, false);
}
addBox(scene, 23, 0.42, 0.55, material.dark, 0, 1.35, -9.28);
for (const x of [-8, -4, 0, 4, 8]) {
addBox(scene, 0.14, 0.8, 0.14, material.silver, x, 1.9, -9.05, false);
}
createTextPlaque([
{ text: "VOXEL WORKS // SYNTHETIC QC EXHIBIT", size: 53 },
{ text: "TWO UNEQUAL DATASETS • LINE A = 12 • LINE B = 5", size: 26, color: "#93b2c9", gap: 72 }
], 12.4, 2.15, [0, 5.8, -9.55]);
function createProduct(globalIndex, isDefect, sourceLabel) {
const group = new THREE.Group();
const color = palette[(globalIndex * 2 + Math.floor(globalIndex / 4)) % palette.length];
const bodyMaterial = new THREE.MeshStandardMaterial({
color,
roughness: 0.48,
metalness: 0.14,
emissive: new THREE.Color(color).multiplyScalar(0.055)
});
const body = addBox(group, 0.64, 0.62, 0.64, bodyMaterial, 0, 0.73, 0);
const capMaterial = new THREE.MeshStandardMaterial({
color: new THREE.Color(color).lerp(new THREE.Color(0xffffff), 0.28),
roughness: 0.42,
metalness: 0.18
});
addBox(group, 0.36, 0.22, 0.36, capMaterial, 0, 1.15, 0);
addBox(group, 0.19, 0.12, 0.035, material.dark, 0, 0.77, 0.337, false);
group.userData.sourceLabel = sourceLabel;
group.userData.globalIndex = globalIndex;
if (isDefect) {
const marker = new THREE.Group();
marker.position.y = 1.76;
const wire = new THREE.Mesh(
new THREE.OctahedronGeometry(0.31, 0),
new THREE.MeshBasicMaterial({
color: 0xfff8da,
wireframe: true,
toneMapped: false
})
);
const inner = new THREE.Mesh(
new THREE.OctahedronGeometry(0.25, 0),
new THREE.MeshBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.2,
depthWrite: false,
toneMapped: false
})
);
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.025, 0.25, 6),
material.cream
);
stem.position.y = -0.27;
marker.add(wire, inner, stem);
group.add(marker);
markers.push({ group: marker, phase: globalIndex * 0.71 });
}
return group;
}
function createTray(width, depth) {
const group = new THREE.Group();
addBox(group, width, 0.34, depth, material.dark, 0, 0.2, 0);
const rimMaterial = new THREE.MeshStandardMaterial({
color: 0x5c7188,
roughness: 0.52,
metalness: 0.35
});
addBox(group, width, 0.22, 0.16, rimMaterial, 0, 0.47, depth / 2 - 0.08);
addBox(group, width, 0.22, 0.16, rimMaterial, 0, 0.47, -depth / 2 + 0.08);
addBox(group, 0.16, 0.22, depth, rimMaterial, -width / 2 + 0.08, 0.47, 0);
addBox(group, 0.16, 0.22, depth, rimMaterial, width / 2 - 0.08, 0.47, 0);
return { group, rimMaterial };
}
function createConveyor(key, x, startZ, endZ) {
const group = new THREE.Group();
group.position.x = x;
const length = startZ - endZ;
const centerZ = (startZ + endZ) / 2;
const accent = key === "A" ? material.amber : material.green;
const railMaterial = new THREE.MeshStandardMaterial({
color: key === "A" ? 0xd88919 : 0x4ca868,
roughness: 0.45,
metalness: 0.24,
emissive: key === "A" ? 0x7a4400 : 0x174c28,
emissiveIntensity: 0.45
});
addBox(group, 2.45, 0.28, length, material.dark, 0, 0.58, centerZ);
addBox(group, 2.02, 0.14, length, material.belt, 0, 0.8, centerZ, false);
for (let z = endZ + 0.22; z < startZ; z += 0.48) {
addBox(group, 1.9, 0.045, 0.16, material.slat, 0, 0.9, z, false);
}
addBox(group, 0.16, 0.28, length, railMaterial, -1.2, 1.03, centerZ);
addBox(group, 0.16, 0.28, length, railMaterial, 1.2, 1.03, centerZ);
const supportCount = Math.max(3, Math.floor(length / 2));
for (let i = 0; i < supportCount; i++) {
const z = endZ + 0.35 + i * ((length - 0.7) / Math.max(1, supportCount - 1));
addBox(group, 0.22, 0.62, 0.22, material.silver, -0.93, 0.25, z);
addBox(group, 0.22, 0.62, 0.22, material.silver, 0.93, 0.25, z);
}
// Voxel scanner gantry.
const scannerZ = endZ + 1.2;
addBox(group, 0.3, 1.85, 0.42, accent, -1.25, 1.67, scannerZ);
addBox(group, 0.3, 1.85, 0.42, accent, 1.25, 1.67, scannerZ);
addBox(group, 2.8, 0.34, 0.48, accent, 0, 2.58, scannerZ);
addBox(group, 1.35, 0.48, 0.85, material.dark, 0, 2.27, scannerZ);
addBox(group, 0.85, 0.12, 0.5, material.cyan, 0, 1.99, scannerZ, false);
const beaconMaterial = new THREE.MeshBasicMaterial({
color: key === "A" ? 0xffc857 : 0x85e89b,
toneMapped: false
});
const beacon = new THREE.Mesh(new THREE.CylinderGeometry(0.16, 0.16, 0.28, 8), beaconMaterial);
beacon.position.set(0, 2.88, scannerZ);
group.add(beacon);
beacons.push({ mesh: beacon, phase: key === "A" ? 0 : Math.PI });
// Discharge chute into the tray.
addBox(group, 1.85, 0.18, 0.85, material.slat, 0, 0.75, endZ + 0.3);
const label = createTextPlaque([
{ text: `LINE ${key}`, size: 58, color: key === "A" ? "#ffe09b" : "#b8f5c5" }
], 3.8, 0.95, [0, 3.25, startZ - 0.35], group);
const beltOutline = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(2.72, 0.05, length + 0.28)),
new THREE.LineBasicMaterial({
color: 0x70dcff,
transparent: true,
opacity: 0.75,
depthWrite: false
})
);
beltOutline.position.set(0, 0.06, centerZ);
group.add(beltOutline);
scene.add(group);
return { group, railMaterial, beltOutline };
}
const lineA = createConveyor("A", -9.0, 4.4, -2.55);
const lineB = createConveyor("B", -1.8, 2.0, -2.55);
const trayA = createTray(5.7, 5.6);
trayA.group.position.set(-9.0, 0, -5.35);
scene.add(trayA.group);
const trayB = createTray(6.2, 2.9);
trayB.group.position.set(-1.8, 0, -4.0);
scene.add(trayB.group);
const combinedTray = createTray(8.4, 5.6);
combinedTray.group.position.set(6.4, 0, -5.35);
scene.add(combinedTray.group);
// Individual Line A tray: 12 items, defects at indices 2, 6, and 10.
const aDefects = new Set([2, 6, 10]);
for (let row = 0; row < 3; row++) {
for (let col = 0; col < 4; col++) {
const index = row * 4 + col;
const item = createProduct(index, aDefects.has(index), "A");
item.position.set(
(col - 1.5) * 1.27,
0,
(row - 1) * 1.58
);
trayA.group.add(item);
}
}
// Individual Line B tray: 5 items, defects at indices 1 and 3.
const bDefects = new Set([1, 3]);
for (let col = 0; col < 5; col++) {
const item = createProduct(12 + col, bDefects.has(col), "B");
item.position.set((col - 2) * 1.11, 0, 0);
trayB.group.add(item);
}
// Combined tray: all 17 items exactly once.
// First two rows = all 12 A items; third row = all 5 B items.
addBox(combinedTray.group, 7.85, 0.035, 2.75, material.blueZone, 0, 0.392, -0.72, false);
addBox(combinedTray.group, 7.85, 0.035, 1.28, material.greenZone, 0, 0.392, 1.45, false);
addBox(combinedTray.group, 7.85, 0.08, 0.07, material.silver, 0, 0.47, 0.74);
const combinedDefects = new Set([2, 6, 10, 13, 15]);
for (let index = 0; index < 17; index++) {
const row = Math.floor(index / 6);
const rowStart = row * 6;
const rowCount = row === 2 ? 5 : 6;
const col = index - rowStart;
const item = createProduct(index, combinedDefects.has(index), index < 12 ? "A" : "B");
item.position.set(
(col - (rowCount - 1) / 2) * 1.28,
0,
[-1.45, 0, 1.45][row]
);
combinedTray.group.add(item);
}
createTextPlaque([
{ text: "A × 12", size: 43, color: "#9fd8ff" }
], 2.05, 0.62, [-2.85, 0.78, -2.45], combinedTray.group);
createTextPlaque([
{ text: "B × 5", size: 43, color: "#b8f5c5" }
], 1.75, 0.62, [2.85, 0.78, 2.45], combinedTray.group);
const trayAOutline = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(5.92, 0.08, 5.82)),
new THREE.LineBasicMaterial({ color: 0x70dcff, transparent: true, opacity: 0.75 })
);
trayAOutline.position.set(-9, 0.04, -5.35);
scene.add(trayAOutline);
const trayBOutline = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(6.42, 0.08, 3.12)),
new THREE.LineBasicMaterial({ color: 0x70dcff, transparent: true, opacity: 0.75 })
);
trayBOutline.position.set(-1.8, 0.04, -4);
scene.add(trayBOutline);
function addSupport(x, z, height) {
addBox(scene, 0.14, height, 0.14, material.silver, x, height / 2, z, false);
addBox(scene, 0.7, 0.08, 0.7, material.dark, x, 0.04, z, false);
}
addSupport(-13.25, -5.35, 1.75);
addSupport(-10.75, -5.35, 1.75);
addSupport(-0.9, -4.0, 1.55);
addSupport(1.9, -4.0, 1.55);
addSupport(10.4, -5.35, 1.75);
addSupport(13.6, -5.35, 1.75);
const boardA = createCountBoard(4.65, 2.3, [-12.0, 3.15, -5.35], {
title: "LINE A · DEFECT COUNT",
note: "12 individual units · 3 marked defects",
defects: 3,
total: 12,
percent: "25.0%",
accent: "#ffc857"
});
const boardB = createCountBoard(4.65, 2.3, [0.5, 2.85, -4.0], {
title: "LINE B · DEFECT COUNT",
note: "5 individual units · 2 marked defects",
defects: 2,
total: 5,
percent: "40.0%",
accent: "#85e89b"
});
const overallBoard = createCountBoard(5.45, 2.72, [12.0, 3.25, -5.35], {
title: "COMBINED · EVERY ITEM ONCE",
note: "12 A + 5 B = 17 units · weighted result",
defects: 5,
total: 17,
percent: "29.4%",
accent: "#70dcff",
comparison: "29.4% weighted ≠ 32.5% simple average"
});
const dynamicBoard = createCountBoard(9.0, 3.55, [0.4, 3.75, -8.75], {
title: "ACTIVE REFERENCE · BOTH LINES",
note: "12 + 5 = 17 units · overall weighted reference",
defects: 5,
total: 17,
percent: "29.4%",
accent: "#70dcff",
comparison: "Numerator 5 and denominator 17 are both physically countable"
});
createTextPlaque([
{ text: "SYNTHETIC DATASET", size: 54, color: "#ffe09b" },
{ text: "17 FICTIONAL VOXEL-CELL UNITS • NO REAL PRODUCTION DATA", size: 24, color: "#a9bbcd", gap: 78 }
], 8.8, 2.05, [5.0, 2.0, 6.15]);
addSupport(1.45, 6.15, 1.05);
addSupport(8.55, 6.15, 1.05);
createTextPlaque([
{ text: "DIAMOND MARKER = DEFECT", size: 40, color: "#fff4c8" },
{ text: "PRODUCT COLOR IS DECORATIVE", size: 23, color: "#9fb2c5", gap: 72 }
], 7.4, 1.45, [6.2, 1.55, 4.85]);
const legendMarker = new THREE.Mesh(
new THREE.OctahedronGeometry(0.31, 0),
new THREE.MeshBasicMaterial({ color: 0xfff8da, wireframe: true, toneMapped: false })
);
legendMarker.position.set(2.35, 1.05, 4.85);
scene.add(legendMarker);
const legendCube = addBox(scene, 0.5, 0.5, 0.5, material.cyan, 10.05, 1.0, 4.85);
// Small decorative factory stacks.
for (let i = 0; i < 4; i++) {
addBox(scene, 0.9, 0.75, 0.9, i % 2 ? material.amber : material.dark,
11.5 + (i % 2) * 1.05, 0.38 + Math.floor(i / 2) * 0.78, 1.9);
}
function tagSelectable(root, key) {
root.traverse(object => {
if (object.isMesh || object.isSprite || object.isLineSegments) {
object.userData.lineKey = key;
clickables.push(object);
}
});
}
tagSelectable(lineA.group, "A");
tagSelectable(trayA.group, "A");
tagSelectable(boardA.sprite, "A");
tagSelectable(lineB.group, "B");
tagSelectable(trayB.group, "B");
tagSelectable(boardB.sprite, "B");
let selection = new Set(["A", "B"]);
const refName = document.querySelector("#ref-name");
const refRatio = document.querySelector("#ref-ratio");
const refPercent = document.querySelector("#ref-percent");
const chooseA = document.querySelector("#choose-a");
const chooseB = document.querySelector("#choose-b");
const bothButton = document.querySelector("#both");
function referenceData() {
const hasA = selection.has("A");
const hasB = selection.has("B");
const defects = (hasA ? 3 : 0) + (hasB ? 2 : 0);
const total = (hasA ? 12 : 0) + (hasB ? 5 : 0);
const percent = total ? (defects / total * 100).toFixed(1) + "%" : "—";
return { hasA, hasB, defects, total, percent };
}
function updateSelectionVisuals() {
lineA.railMaterial.emissiveIntensity = selection.has("A") ? 0.95 : 0.08;
lineB.railMaterial.emissiveIntensity = selection.has("B") ? 0.95 : 0.08;
lineA.beltOutline.material.opacity = selection.has("A") ? 0.95 : 0.12;
lineB.beltOutline.material.opacity = selection.has("B") ? 0.95 : 0.12;
trayAOutline.material.opacity = selection.has("A") ? 0.95 : 0.12;
trayBOutline.material.opacity = selection.has("B") ? 0.95 : 0.12;
}
function setSelection(nextSelection) {
selection = new Set(nextSelection);
const data = referenceData();
let name;
if (data.hasA && data.hasB) {
name = "Both lines · overall";
} else if (data.hasA) {
name = "Line A only";
} else {
name = "Line B only";
}
refName.textContent = name;
refRatio.textContent = `${data.defects} / ${data.total}`;
refPercent.textContent = data.percent;
chooseA.classList.toggle("active", data.hasA);
chooseB.classList.toggle("active", data.hasB);
bothButton.classList.toggle("active", data.hasA && data.hasB);
chooseA.setAttribute("aria-pressed", String(data.hasA));
chooseB.setAttribute("aria-pressed", String(data.hasB));
bothButton.setAttribute("aria-pressed", String(data.hasA && data.hasB));
drawCountBoard(dynamicBoard, {
title: `ACTIVE REFERENCE · ${name.toUpperCase()}`,
note: data.hasA && data.hasB
? "12 + 5 = 17 units · overall weighted reference"
: data.hasA
? "Line A only · denominator contains 12 units"
: "Line B only · denominator contains 5 units",
defects: data.defects,
total: data.total,
percent: data.percent,
accent: data.hasA && data.hasB ? "#70dcff" : data.hasA ? "#ffc857" : "#85e89b",
comparison: data.hasA && data.hasB
? "Numerator 5 and denominator 17 are both physically countable"
: "Diamond markers and unit blocks make the fraction directly countable"
});
updateSelectionVisuals();
}
chooseA.addEventListener("click", () => setSelection(["A"]));
chooseB.addEventListener("click", () => setSelection(["B"]));
bothButton.addEventListener("click", () => setSelection(["A", "B"]));
setSelection(["A", "B"]);
// Direct camera controls, implemented without add-ons.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = false;
let pointerMoved = false;
let lastX = 0;
let lastY = 0;
function updateCamera() {
camera.position.setFromSpherical(cameraSpherical).add(cameraTarget);
camera.lookAt(cameraTarget);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
}
function resetCamera() {
cameraSpherical.set(36, 0.83, 0.72);
cameraZoom = 1;
updateCamera();
}
function hitTest(clientX, clientY) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
return raycaster.intersectObjects(clickables, false)[0] || null;
}
canvas.addEventListener("pointerdown", event => {
pointerDown = true;
pointerMoved = false;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (pointerDown) {
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
if (Math.abs(dx) + Math.abs(dy) > 3) pointerMoved = true;
cameraSpherical.theta -= dx * 0.006;
cameraSpherical.phi = THREE.MathUtils.clamp(
cameraSpherical.phi + dy * 0.005,
0.48,
1.22
);
lastX = event.clientX;
lastY = event.clientY;
updateCamera();
canvas.style.cursor = "grabbing";
} else {
const hit = hitTest(event.clientX, event.clientY);
canvas.style.cursor = hit ? "pointer" : "grab";
}
});
canvas.addEventListener("pointerup", event => {
if (pointerDown && !pointerMoved) {
const hit = hitTest(event.clientX, event.clientY);
if (hit && hit.object.userData.lineKey) {
const key = hit.object.userData.lineKey;
// Both -> isolate clicked line.
// One selected line -> clicking it cycles to the other.
// One selected line -> clicking the other selects both.
if (selection.size === 2) {
setSelection([key]);
} else if (selection.has(key)) {
setSelection([key === "A" ? "B" : "A"]);
} else {
setSelection(["A", "B"]);
}
}
}
pointerDown = false;
pointerMoved = false;
canvas.style.cursor = "grab";
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
pointerDown = false;
pointerMoved = false;
canvas.style.cursor = "grab";
});
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(cameraZoom - event.deltaY * 0.0009, 0.68, 1.8);
updateCamera();
}, { passive: false });
window.addEventListener("keydown", event => {
if (event.key.toLowerCase() === "r") resetCamera();
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewWidth = 31;
const viewHeight = Math.max(18.2, viewWidth / aspect);
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
window.addEventListener("resize", resize);
resize();
updateCamera();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const t = clock.getElapsedTime();
for (const marker of markers) {
marker.group.rotation.y = t * 0.85 + marker.phase;
marker.group.rotation.z = Math.sin(t * 1.2 + marker.phase) * 0.12;
const pulse = 1 + Math.sin(t * 3.1 + marker.phase) * 0.07;
marker.group.scale.setScalar(pulse);
}
for (const beacon of beacons) {
beacon.mesh.material.opacity = 0.72 + Math.sin(t * 4 + beacon.phase) * 0.28;
beacon.mesh.material.transparent = true;
}
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```