Prompt specification
Build or customize the Three.js 3D scene "Shapes Beside a Size Threshold Gate" 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: Shapes Beside a Size Threshold Gate
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/shapes-beside-a-size-threshold-gate-x2041
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing object widths and an aperture threshold. Model cubes and cylinders with measured widths approaching a fixed aperture. Show classification by geometry and distinguish width from object type or color. Stylized solid forms.
Working Three.js Starter (shapes-beside-a-size-threshold-gate-x2041):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Aperture Geometry Lab</title>
<style>
:root {
color-scheme: dark;
--bg: #080e19;
--panel: #101827;
--panel-2: #151f31;
--line: #26344b;
--text: #f1f5ff;
--muted: #94a2ba;
--accent: #79d5cf;
--accent-dark: #163f43;
--amber: #f5c873;
--blocked: #ff9e7d;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#app {
display: grid;
grid-template-rows: auto minmax(0, 1fr);
min-height: 100vh;
}
header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 28px;
padding: 22px 28px;
border-bottom: 1px solid var(--line);
background:
radial-gradient(circle at 85% 20%, rgba(121, 213, 207, 0.08), transparent 28%),
#0c1321;
}
.eyebrow {
margin-bottom: 6px;
color: var(--accent);
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(1.45rem, 2.5vw, 2.15rem);
line-height: 1.05;
letter-spacing: -0.035em;
}
header p {
max-width: 760px;
margin: 8px 0 0;
color: var(--muted);
font-size: 0.92rem;
line-height: 1.5;
}
.header-tags {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
}
.header-tag {
padding: 8px 10px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(255, 255, 255, 0.025);
color: var(--muted);
font-size: 0.73rem;
font-weight: 700;
white-space: nowrap;
}
main {
display: grid;
grid-template-columns: minmax(0, 1fr) 390px;
min-height: 0;
}
#viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #0b1220;
}
#scene {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
#scene.dragging {
cursor: grabbing;
}
#labels {
position: absolute;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
transform: translate(-50%, -100%);
display: none;
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 9px;
background: rgba(9, 16, 29, 0.88);
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.26);
backdrop-filter: blur(10px);
white-space: nowrap;
}
#objectLabel {
min-width: 154px;
text-align: center;
}
#objectLabel .label-shape {
display: block;
margin-bottom: 3px;
color: var(--accent);
font-size: 0.66rem;
font-weight: 900;
letter-spacing: 0.14em;
text-transform: uppercase;
}
#objectLabel strong {
display: block;
font-size: 1rem;
}
#objectLabel em {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 0.69rem;
font-style: normal;
font-weight: 700;
}
#gateLabel {
border-color: rgba(245, 200, 115, 0.38);
color: var(--amber);
font-size: 0.7rem;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.viewport-top {
position: absolute;
top: 18px;
left: 18px;
right: 18px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
pointer-events: none;
}
.scene-hint {
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.11);
border-radius: 8px;
background: rgba(7, 13, 24, 0.64);
color: var(--muted);
font-size: 0.72rem;
line-height: 1.45;
backdrop-filter: blur(8px);
}
.scene-hint kbd {
padding: 2px 5px;
border: 1px solid #3a4962;
border-radius: 4px;
background: #182438;
color: var(--text);
font-size: 0.65rem;
}
.current-status {
min-width: 185px;
padding: 10px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(9, 16, 29, 0.82);
box-shadow: 0 14px 34px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(10px);
}
.current-status .status-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-bottom: 4px;
}
#currentShape {
color: var(--accent);
font-size: 0.68rem;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#currentWidth {
font-size: 0.88rem;
}
#currentDecision {
color: var(--muted);
font-size: 0.73rem;
font-weight: 750;
}
.current-status[data-state="fit"] {
border-color: rgba(121, 213, 207, 0.5);
}
.current-status[data-state="fit"] #currentDecision {
color: var(--accent);
}
.current-status[data-state="blocked"] {
border-color: rgba(255, 158, 125, 0.48);
}
.current-status[data-state="blocked"] #currentDecision {
color: var(--blocked);
}
.scene-legend {
position: absolute;
bottom: 18px;
left: 18px;
display: flex;
flex-wrap: wrap;
gap: 10px 15px;
max-width: min(650px, calc(100% - 36px));
padding: 11px 13px;
border: 1px solid rgba(255, 255, 255, 0.11);
border-radius: 10px;
background: rgba(7, 13, 24, 0.76);
color: var(--muted);
font-size: 0.72rem;
backdrop-filter: blur(10px);
pointer-events: none;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 7px;
}
.shape-icon {
display: inline-block;
flex: 0 0 auto;
width: 15px;
height: 15px;
background: var(--accent);
}
.shape-icon.cube {
border-radius: 3px;
}
.shape-icon.cylinder {
width: 14px;
height: 14px;
border-radius: 50%;
}
.material-swatch {
width: 15px;
height: 15px;
border-radius: 50%;
background: var(--accent);
}
.amber-swatch {
width: 19px;
height: 3px;
border-radius: 2px;
background: var(--amber);
}
aside {
min-height: 0;
overflow-y: auto;
border-left: 1px solid var(--line);
background: var(--panel);
scrollbar-color: #34435e transparent;
}
.panel-section {
padding: 20px;
border-bottom: 1px solid var(--line);
}
.section-title {
margin: 0 0 13px;
color: var(--muted);
font-size: 0.7rem;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.threshold-row {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 16px;
}
.threshold-number {
color: var(--amber);
font-size: 2.15rem;
font-weight: 850;
letter-spacing: -0.05em;
line-height: 1;
}
.threshold-number small {
margin-left: 4px;
color: var(--muted);
font-size: 0.8rem;
font-weight: 700;
letter-spacing: 0;
}
.threshold-label {
color: var(--muted);
font-size: 0.74rem;
font-weight: 700;
}
input[type="range"] {
width: 100%;
margin: 17px 0 8px;
accent-color: var(--amber);
cursor: pointer;
}
.range-labels {
display: flex;
justify-content: space-between;
color: #64738d;
font-size: 0.68rem;
}
.buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 16px;
}
.button {
min-height: 38px;
padding: 9px 11px;
border: 1px solid #33425b;
border-radius: 8px;
background: #182338;
color: var(--text);
font-size: 0.78rem;
font-weight: 800;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
.button:hover {
border-color: #50627f;
background: #202d46;
}
.button:active {
transform: translateY(1px);
}
.button.primary {
border-color: rgba(121, 213, 207, 0.55);
background: var(--accent-dark);
color: #d8fffa;
}
.rule-card {
padding: 14px;
border: 1px solid rgba(245, 200, 115, 0.24);
border-radius: 10px;
background: rgba(245, 200, 115, 0.055);
}
.rule-formula {
margin-bottom: 7px;
color: var(--amber);
font-size: 0.9rem;
font-weight: 850;
}
.rule-card p {
margin: 0;
color: var(--muted);
font-size: 0.76rem;
line-height: 1.55;
}
.geometry-summary {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.geometry-card {
padding: 12px;
border: 1px solid var(--line);
border-radius: 9px;
background: var(--panel-2);
}
.geometry-card .name {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: var(--text);
font-size: 0.78rem;
font-weight: 800;
}
.geometry-card .count {
color: var(--accent);
font-size: 0.72rem;
font-weight: 850;
}
.table-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 11px;
}
.table-heading .section-title {
margin: 0;
}
.pair-note {
color: #73829c;
font-size: 0.66rem;
}
#specimenList {
display: grid;
gap: 6px;
}
.spec-row {
width: 100%;
padding: 10px;
border: 1px solid transparent;
border-radius: 8px;
background: #121c2d;
text-align: left;
cursor: pointer;
transition:
border-color 140ms ease,
background 140ms ease;
}
.spec-row:hover {
border-color: #34445f;
background: #172338;
}
.spec-row.selected {
border-color: rgba(121, 213, 207, 0.6);
background: rgba(121, 213, 207, 0.075);
}
.spec-row.pair-start {
margin-top: 4px;
}
.spec-row-top {
display: grid;
grid-template-columns: 18px 1fr auto auto;
align-items: center;
gap: 8px;
margin-bottom: 8px;
}
.geometry-name {
color: #cbd5e7;
font-size: 0.75rem;
font-weight: 750;
}
.spec-width {
color: var(--text);
font-size: 0.75rem;
font-weight: 850;
font-variant-numeric: tabular-nums;
}
.fit-badge {
min-width: 53px;
padding: 3px 6px;
border: 1px solid #3b4b66;
border-radius: 999px;
color: var(--muted);
font-size: 0.6rem;
font-weight: 900;
letter-spacing: 0.06em;
text-align: center;
}
.fit-badge.fit {
border-color: rgba(121, 213, 207, 0.38);
color: var(--accent);
}
.fit-badge.blocked {
border-color: rgba(255, 158, 125, 0.36);
color: var(--blocked);
}
.width-track {
position: relative;
height: 5px;
border-radius: 999px;
background: #26334a;
overflow: visible;
}
.width-fill {
position: absolute;
inset: 0 auto 0 0;
border-radius: 999px;
background: var(--accent);
}
.width-fill.over {
background: repeating-linear-gradient(
135deg,
#71809a 0,
#71809a 4px,
#4d5b72 4px,
#4d5b72 8px
);
}
.threshold-marker {
position: absolute;
top: -3px;
width: 2px;
height: 11px;
border-radius: 2px;
background: var(--amber);
transform: translateX(-1px);
}
.panel-note {
margin: 0;
color: #73829b;
font-size: 0.7rem;
line-height: 1.55;
}
@media (max-width: 980px) {
body {
overflow: auto;
}
header {
align-items: flex-start;
flex-direction: column;
padding: 20px;
}
.header-tags {
justify-content: flex-start;
}
main {
grid-template-columns: 1fr;
}
#viewport {
height: 64vh;
min-height: 480px;
}
aside {
overflow: visible;
border-top: 1px solid var(--line);
border-left: 0;
}
}
@media (max-width: 600px) {
header {
padding: 17px;
}
header p {
font-size: 0.83rem;
}
.header-tags {
display: none;
}
#viewport {
height: 58vh;
min-height: 430px;
}
.viewport-top {
top: 12px;
left: 12px;
right: 12px;
}
.scene-hint {
display: none;
}
.current-status {
margin-left: auto;
min-width: 170px;
}
.scene-legend {
right: 12px;
bottom: 12px;
left: 12px;
gap: 8px 12px;
}
.panel-section {
padding: 17px;
}
}
</style>
</head>
<body>
<div id="app">
<header>
<div>
<div class="eyebrow">Geometry Lab / Aperture 03</div>
<h1>Shape is reported. Width decides.</h1>
<p>
Matched cubes and cylinders approach a fixed opening. Their geometry is
classified separately, while the aperture test uses only the measured
horizontal width.
</p>
</div>
<div class="header-tags" aria-label="Experiment properties">
<span class="header-tag">6 matched-width pairs</span>
<span class="header-tag">12 solid specimens</span>
<span class="header-tag">One scalar decision</span>
</div>
</header>
<main>
<section id="viewport" aria-label="Interactive 3D aperture demonstration">
<canvas
id="scene"
tabindex="0"
aria-label="3D scene. Drag to orbit, scroll to zoom, or use arrow keys."
></canvas>
<div id="labels" aria-hidden="true">
<div id="objectLabel" class="world-label"></div>
<div id="gateLabel" class="world-label"></div>
</div>
<div class="viewport-top">
<div class="scene-hint">
<kbd>Drag</kbd> orbit · <kbd>Wheel</kbd> zoom<br />
<kbd>←</kbd><kbd>→</kbd><kbd>↑</kbd><kbd>↓</kbd> rotate · <kbd>R</kbd> reset
</div>
<div
id="currentStatus"
class="current-status"
data-state="measure"
aria-live="polite"
>
<div class="status-top">
<span id="currentShape">Cube</span>
<strong id="currentWidth">0.64 m</strong>
</div>
<div id="currentDecision">Approaching aperture</div>
</div>
</div>
<div class="scene-legend">
<span class="legend-item">
<i class="shape-icon cube"></i> Cube geometry
</span>
<span class="legend-item">
<i class="shape-icon cylinder"></i> Cylinder geometry
</span>
<span class="legend-item">
<i class="material-swatch"></i> Constant material color
</span>
<span class="legend-item">
<i class="amber-swatch"></i> Measured opening width
</span>
</div>
</section>
<aside aria-label="Aperture controls and specimen measurements">
<section class="panel-section">
<h2 class="section-title">Fixed aperture threshold</h2>
<div class="threshold-row">
<div>
<div class="threshold-label">Opening width</div>
<div class="threshold-number">
<span id="thresholdValue">1.20</span><small>m</small>
</div>
</div>
<div class="threshold-label">Drag to retune</div>
</div>
<input
id="threshold"
type="range"
min="0.80"
max="1.80"
step="0.01"
value="1.20"
aria-label="Aperture width in meters"
>
<div class="range-labels">
<span>0.80 m</span>
<span>1.80 m</span>
</div>
<div class="buttons">
<button id="playButton" class="button primary" type="button">
Pause
</button>
<button id="nextButton" class="button" type="button">
Next specimen
</button>
<button id="resetCamera" class="button" type="button">
Reset view
</button>
</div>
</section>
<section class="panel-section">
<h2 class="section-title">Decision rule</h2>
<div class="rule-card">
<div id="ruleFormula" class="rule-formula">
Fit ⇔ measured width ≤ 1.20 m
</div>
<p>
Width is measured along the horizontal X axis. Cube versus cylinder
is a geometry label, and material color is constant; neither changes
the aperture result.
</p>
</div>
</section>
<section class="panel-section">
<h2 class="section-title">Classification by geometry</h2>
<div class="geometry-summary">
<div class="geometry-card">
<div class="name">
<i class="shape-icon cube"></i>
Cubes
</div>
<div id="cubeCount" class="count">3 / 5 fit</div>
</div>
<div class="geometry-card">
<div class="name">
<i class="shape-icon cylinder"></i>
Cylinders
</div>
<div id="cylinderCount" class="count">3 / 5 fit</div>
</div>
</div>
</section>
<section class="panel-section">
<div class="table-heading">
<h2 class="section-title">Geometry + measured width</h2>
<span class="pair-note">Rows separated into pairs</span>
</div>
<div id="specimenList" aria-label="Specimen classification list"></div>
</section>
<section class="panel-section">
<p class="panel-note">
Each adjacent cube/cylinder pair has exactly the same measured width.
The amber marker is the current aperture threshold. Select any row to
replay that specimen.
</p>
</section>
</aside>
</main>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const canvas = document.getElementById("scene");
const thresholdInput = document.getElementById("threshold");
const thresholdValue = document.getElementById("thresholdValue");
const ruleFormula = document.getElementById("ruleFormula");
const specimenList = document.getElementById("specimenList");
const objectLabel = document.getElementById("objectLabel");
const gateLabel = document.getElementById("gateLabel");
const currentStatus = document.getElementById("currentStatus");
const currentShape = document.getElementById("currentShape");
const currentWidth = document.getElementById("currentWidth");
const currentDecision = document.getElementById("currentDecision");
const playButton = document.getElementById("playButton");
const cubeCount = document.getElementById("cubeCount");
const cylinderCount = document.getElementById("cylinderCount");
const MAX_SCALE = 1.8;
const EPSILON = 0.000001;
const START_Z = 6.2;
const EXIT_Z = -6.4;
const APPROACH_DURATION = 3.25;
let threshold = Number(thresholdInput.value);
const state = {
index: 0,
phase: "approach",
phaseTime: 0,
z: START_Z,
playing: true,
speed: 1
};
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b1220);
scene.fog = new THREE.Fog(0x0b1220, 17, 36);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 80);
const cameraState = {
yaw: 0.62,
pitch: 0.43,
radius: 14.5,
target: new THREE.Vector3(0, 0.95, -0.1)
};
function updateCamera() {
const { yaw, pitch, radius, target } = cameraState;
camera.position.set(
target.x + radius * Math.sin(yaw) * Math.cos(pitch),
target.y + radius * Math.sin(pitch),
target.z + radius * Math.cos(yaw) * Math.cos(pitch)
);
camera.lookAt(target);
}
function resetCamera() {
cameraState.yaw = 0.62;
cameraState.pitch = 0.43;
cameraState.radius = 14.5;
cameraState.target.set(0, 0.95, -0.1);
updateCamera();
}
// ---------------------------------------------------------------------
// Lighting and environment
// ---------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xc7e7ff, 0x111827, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(5.5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 11;
keyLight.shadow.camera.bottom = -11;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x79d5cf, 1.35);
rimLight.position.set(-7, 4, -8);
scene.add(rimLight);
const amberLight = new THREE.PointLight(0xf5c873, 1.1, 8, 2);
amberLight.position.set(0, 3, 1.5);
scene.add(amberLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(46, 46),
new THREE.MeshStandardMaterial({
color: 0x0c1525,
roughness: 0.92,
metalness: 0.04
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.015;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(40, 40, 0x31425f, 0x1a2941);
grid.position.y = 0.002;
grid.material.transparent = true;
grid.material.opacity = 0.36;
scene.add(grid);
// ---------------------------------------------------------------------
// Conveyor track
// ---------------------------------------------------------------------
const trackMaterial = new THREE.MeshStandardMaterial({
color: 0x111d30,
roughness: 0.74,
metalness: 0.22
});
const track = new THREE.Mesh(
new THREE.BoxGeometry(2.75, 0.055, 15.4),
trackMaterial
);
track.position.set(0, 0.025, 0);
track.receiveShadow = true;
scene.add(track);
const railMaterial = new THREE.MeshStandardMaterial({
color: 0x40516b,
roughness: 0.45,
metalness: 0.7
});
for (const x of [-1.43, 1.43]) {
const rail = new THREE.Mesh(
new THREE.BoxGeometry(0.035, 0.035, 15.2),
railMaterial
);
rail.position.set(x, 0.075, 0);
scene.add(rail);
}
const centerLineMaterial = new THREE.MeshBasicMaterial({
color: 0x46627c,
transparent: true,
opacity: 0.58
});
const centerLine = new THREE.Mesh(
new THREE.BoxGeometry(0.018, 0.008, 14.8),
centerLineMaterial
);
centerLine.position.set(0, 0.061, 0);
scene.add(centerLine);
const markerMaterial = new THREE.MeshBasicMaterial({
color: 0x6f819b,
transparent: true,
opacity: 0.28
});
for (let z = 6.4; z >= -6.4; z -= 1.05) {
const marker = new THREE.Mesh(
new THREE.BoxGeometry(2.5, 0.008, 0.018),
markerMaterial
);
marker.position.set(0, 0.064, z);
scene.add(marker);
}
// ---------------------------------------------------------------------
// Fixed aperture frame
// ---------------------------------------------------------------------
const gate = new THREE.Group();
scene.add(gate);
const gateMaterial = new THREE.MeshStandardMaterial({
color: 0x617087,
metalness: 0.72,
roughness: 0.3
});
const postGeometry = new THREE.BoxGeometry(0.18, 2.55, 0.36);
const topGeometry = new THREE.BoxGeometry(1, 0.18, 0.36);
const footGeometry = new THREE.BoxGeometry(0.42, 0.13, 0.62);
const leftPost = new THREE.Mesh(postGeometry, gateMaterial);
const rightPost = new THREE.Mesh(postGeometry, gateMaterial);
const topBar = new THREE.Mesh(topGeometry, gateMaterial);
const leftFoot = new THREE.Mesh(footGeometry, gateMaterial);
const rightFoot = new THREE.Mesh(footGeometry, gateMaterial);
leftPost.position.y = 1.275;
rightPost.position.y = 1.275;
topBar.position.y = 2.64;
leftFoot.position.y = 0.065;
rightFoot.position.y = 0.065;
for (const mesh of [
leftPost,
rightPost,
topBar,
leftFoot,
rightFoot
]) {
mesh.castShadow = true;
mesh.receiveShadow = true;
gate.add(mesh);
}
const thresholdGlowMaterial = new THREE.MeshStandardMaterial({
color: 0xf5c873,
emissive: 0xf5c873,
emissiveIntensity: 1.25,
roughness: 0.35,
metalness: 0.2
});
const thresholdGlow = new THREE.Mesh(
new THREE.BoxGeometry(1, 0.026, 0.38),
thresholdGlowMaterial
);
thresholdGlow.position.y = 2.49;
gate.add(thresholdGlow);
const gateDimensionGeometry = new THREE.BufferGeometry();
gateDimensionGeometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(18), 3)
);
const gateDimension = new THREE.LineSegments(
gateDimensionGeometry,
new THREE.LineBasicMaterial({
color: 0xf5c873,
transparent: true,
opacity: 0.95,
depthTest: false
})
);
gateDimension.renderOrder = 12;
scene.add(gateDimension);
function updateGate() {
const half = threshold / 2;
leftPost.position.x = -(half + 0.09);
rightPost.position.x = half + 0.09;
leftFoot.position.x = -(half + 0.09);
rightFoot.position.x = half + 0.09;
topBar.scale.x = threshold + 0.36;
thresholdGlow.scale.x = threshold;
const points = [
[-half, 2.96, 0],
[half, 2.96, 0],
[-half, 2.84, 0],
[-half, 3.08, 0],
[half, 2.84, 0],
[half, 3.08, 0]
];
const attribute = gateDimension.geometry.getAttribute("position");
points.forEach((point, index) => {
attribute.setXYZ(index, point[0], point[1], point[2]);
});
attribute.needsUpdate = true;
gateDimension.geometry.computeBoundingSphere();
gateLabel.innerHTML =
`Fixed aperture · ${threshold.toFixed(2)} m · width test`;
}
// ---------------------------------------------------------------------
// Matched specimen pairs
// ---------------------------------------------------------------------
const specimenMaterial = new THREE.MeshStandardMaterial({
color: 0x79c9c5,
roughness: 0.34,
metalness: 0.08
});
const specimenEdgeMaterial = new THREE.LineBasicMaterial({
color: 0xd6fffa,
transparent: true,
opacity: 0.46
});
const measurementMaterial = new THREE.LineBasicMaterial({
color: 0xf5c873,
transparent: true,
opacity: 0.95,
depthTest: false
});
const specimenWidths = [0.64, 0.84, 1.04, 1.24, 1.44, 1.64];
const specimens = [];
function makeMeasurementGeometry(width) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(18), 3)
);
const line = new THREE.LineSegments(
geometry,
measurementMaterial
);
line.renderOrder = 11;
line.visible = false;
scene.add(line);
return line;
}
function updateMeasurement(specimen, z) {
const half = specimen.width / 2;
const points = [
[-half, 0.115, z],
[half, 0.115, z],
[-half, 0.115, z],
[-half, 0.25, z],
[half, 0.115, z],
[half, 0.25, z]
];
const attribute = specimen.measurement.geometry.getAttribute("position");
points.forEach((point, index) => {
attribute.setXYZ(index, point[0], point[1], point[2]);
});
attribute.needsUpdate = true;
specimen.measurement.geometry.computeBoundingSphere();
}
for (const width of specimenWidths) {
for (const shape of ["cube", "cylinder"]) {
const geometry =
shape === "cube"
? new THREE.BoxGeometry(width, width, width)
: new THREE.CylinderGeometry(
width / 2,
width / 2,
width * 0.82,
40,
1,
false
);
const mesh = new THREE.Mesh(geometry, specimenMaterial);
mesh.castShadow = true;
mesh.receiveShadow = true;
const height = shape === "cube" ? width : width * 0.82;
const depth = width;
mesh.position.y = height / 2 + 0.07;
const group = new THREE.Group();
group.add(mesh);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry, 24),
specimenEdgeMaterial
);
edges.position.copy(mesh.position);
group.add(edges);
group.visible = false;
scene.add(group);
const specimen = {
index: specimens.length,
shape,
shapeName: shape === "cube" ? "Cube" : "Cylinder",
width,
height,
depth,
group,
mesh,
measurement: makeMeasurementGeometry(width)
};
specimens.push(specimen);
}
}
function specimenFits(specimen) {
return specimen.width <= threshold + EPSILON;
}
// ---------------------------------------------------------------------
// UI and classification
// ---------------------------------------------------------------------
function shortDecision(specimen) {
if (state.phase === "approach") return "Approaching";
if (state.phase === "decision") {
return specimenFits(specimen) ? "Fits aperture" : "Exceeds opening";
}
if (state.phase === "pass") return "Fit confirmed";
return "Blocked at gate";
}
function updateOverlayCopy() {
const specimen = specimens[state.index];
const decision = shortDecision(specimen);
currentShape.textContent = specimen.shapeName;
currentWidth.textContent = `${specimen.width.toFixed(2)} m`;
currentDecision.textContent = decision;
currentStatus.dataset.state =
state.phase === "pass"
? "fit"
: state.phase === "block"
? "blocked"
: "measure";
objectLabel.innerHTML = `
<span class="label-shape">${specimen.shapeName}</span>
<strong>${specimen.width.toFixed(2)} m wide</strong>
<em>${decision}</em>
`;
}
function markActiveRow() {
document.querySelectorAll(".spec-row").forEach((row) => {
row.classList.toggle(
"selected",
Number(row.dataset.index) === state.index
);
});
}
function renderTable() {
specimenList.innerHTML = specimens
.map((specimen) => {
const fits = specimenFits(specimen);
const fillWidth = (specimen.width / MAX_SCALE) * 100;
const markerPosition = (threshold / MAX_SCALE) * 100;
return `
<button
class="spec-row ${specimen.index % 2 === 0 ? "pair-start" : ""}"
type="button"
data-index="${specimen.index}"
aria-label="Replay ${specimen.shapeName}, width ${specimen.width.toFixed(2)} meters"
>
<div class="spec-row-top">
<i class="shape-icon ${specimen.shape}"></i>
<span class="geometry-name">${specimen.shapeName}</span>
<span class="spec-width">${specimen.width.toFixed(2)} m</span>
<span class="fit-badge ${fits ? "fit" : "blocked"}">
${fits ? "FIT" : "BLOCKED"}
</span>
</div>
<div class="width-track">
<div
class="width-fill ${fits ? "" : "over"}"
style="width:${fillWidth}%"
></div>
<div
class="threshold-marker"
style="left:${markerPosition}%"
title="Aperture threshold"
></div>
</div>
</button>
`;
})
.join("");
specimenList.querySelectorAll(".spec-row").forEach((row) => {
row.addEventListener("click", () => {
selectSpecimen(Number(row.dataset.index));
});
});
markActiveRow();
}
function renderSummary() {
const cubes = specimens.filter((item) => item.shape === "cube");
const cylinders = specimens.filter((item) => item.shape === "cylinder");
const cubeFits = cubes.filter(specimenFits).length;
const cylinderFits = cylinders.filter(specimenFits).length;
cubeCount.textContent = `${cubeFits} / ${cubes.length} fit`;
cylinderCount.textContent = `${cylinderFits} / ${cylinders.length} fit`;
}
function updateThreshold() {
threshold = Number(thresholdInput.value);
thresholdValue.textContent = threshold.toFixed(2);
ruleFormula.textContent =
`Fit ⇔ measured width ≤ ${threshold.toFixed(2)} m`;
updateGate();
renderTable();
renderSummary();
updateOverlayCopy();
if (["decision", "pass", "block"].includes(state.phase)) {
state.phase = "decision";
state.phaseTime = 0;
state.z = 0;
updateOverlayCopy();
}
}
function selectSpecimen(index) {
state.index = (index + specimens.length) % specimens.length;
state.phase = "approach";
state.phaseTime = 0;
state.z = START_Z;
specimens.forEach((specimen, specimenIndex) => {
specimen.group.visible = specimenIndex === state.index;
specimen.measurement.visible = specimenIndex === state.index;
});
const active = specimens[state.index];
active.group.position.z = START_Z;
updateMeasurement(active, START_Z);
updateOverlayCopy();
markActiveRow();
}
function updatePlayButton() {
playButton.textContent = state.playing ? "Pause" : "Play";
}
thresholdInput.addEventListener("input", updateThreshold);
playButton.addEventListener("click", () => {
state.playing = !state.playing;
updatePlayButton();
});
document.getElementById("nextButton").addEventListener("click", () => {
selectSpecimen(state.index + 1);
state.playing = true;
updatePlayButton();
});
document.getElementById("resetCamera").addEventListener("click", resetCamera);
// ---------------------------------------------------------------------
// Direct camera controls: no examples/addons are used
// ---------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.yaw -= deltaX * 0.005;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + deltaY * 0.004,
0.18,
1.08
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("pointerleave", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
8,
24
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
canvas.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (["arrowleft", "arrowright", "arrowup", "arrowdown", "+", "=", "-", "r"].includes(key)) {
event.preventDefault();
}
if (key === "arrowleft") cameraState.yaw -= 0.08;
if (key === "arrowright") cameraState.yaw += 0.08;
if (key === "arrowup") cameraState.pitch += 0.06;
if (key === "arrowdown") cameraState.pitch -= 0.06;
if (key === "+" || key === "=") cameraState.radius -= 0.7;
if (key === "-") cameraState.radius += 0.7;
if (key === "r") resetCamera();
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch,
0.18,
1.08
);
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius,
8,
24
);
updateCamera();
});
// ---------------------------------------------------------------------
// Projection helpers for DOM labels
// ---------------------------------------------------------------------
const projected = new THREE.Vector3();
function positionWorldLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.35 &&
Math.abs(projected.y) < 1.35;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * viewport.clientWidth;
const y = (-projected.y * 0.5 + 0.5) * viewport.clientHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function updateLabels() {
const specimen = specimens[state.index];
positionWorldLabel(
objectLabel,
new THREE.Vector3(
0,
specimen.height + 0.46,
state.z
)
);
positionWorldLabel(
gateLabel,
new THREE.Vector3(0, 3.28, 0)
);
}
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function smoothStep(value) {
return value * value * (3 - 2 * value);
}
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (state.playing) {
const specimen = specimens[state.index];
if (state.phase === "approach") {
state.phaseTime += dt * state.speed;
const progress = THREE.MathUtils.clamp(
state.phaseTime / APPROACH_DURATION,
0,
1
);
state.z = THREE.MathUtils.lerp(
START_Z,
0,
smoothStep(progress)
);
if (progress >= 1) {
state.phase = "decision";
state.phaseTime = 0;
state.z = 0;
updateOverlayCopy();
}
} else if (state.phase === "decision") {
state.phaseTime += dt;
state.z = 0;
if (state.phaseTime >= 0.72) {
state.phase = specimenFits(specimen) ? "pass" : "block";
state.phaseTime = 0;
updateOverlayCopy();
}
} else if (state.phase === "pass") {
state.phaseTime += dt;
const progress = THREE.MathUtils.clamp(
state.phaseTime / 2.15,
0,
1
);
state.z = THREE.MathUtils.lerp(0, EXIT_Z, progress);
if (progress >= 1) {
selectSpecimen(state.index + 1);
}
} else if (state.phase === "block") {
state.phaseTime += dt;
const contactZ = 0.18 + specimen.depth / 2;
const moveProgress = THREE.MathUtils.clamp(
state.phaseTime / 0.34,
0,
1
);
state.z = THREE.MathUtils.lerp(
0,
contactZ,
smoothStep(moveProgress)
);
if (state.phaseTime >= 1.2) {
selectSpecimen(state.index + 1);
}
}
}
const active = specimens[state.index];
active.group.position.z = state.z;
updateMeasurement(active, state.z);
updateCamera();
renderer.render(scene, camera);
updateLabels();
}
// ---------------------------------------------------------------------
// Resize and initialization
// ---------------------------------------------------------------------
function resize() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(viewport);
window.addEventListener("resize", resize);
updateGate();
renderTable();
renderSummary();
selectSpecimen(0);
updatePlayButton();
updateCamera();
resize();
animate();
</script>
</body>
</html>
```