Prompt specification
Build or customize the Three.js 3D scene "Nested chair clearance study" 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: Nested chair clearance study
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/nested-chair-clearance-study-x0177
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: nested chair clearance study. Show two simple chairs suspended just before stacking, with leg spacing and seat offsets highlighted; the upper chair must fit without intersecting the lower frame. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (nested-chair-clearance-study-x0177):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Chair Clearance Study</title>
<style>
:root {
color-scheme: dark;
--bg: #07111d;
--panel: rgba(8, 18, 30, 0.82);
--line: rgba(165, 210, 230, 0.18);
--muted: #8da7b8;
--text: #e8f4f8;
--lower: #52dfcf;
--upper: #ffb454;
--pass: #66efad;
--fail: #ff6b79;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.title {
position: fixed;
top: 22px;
left: 24px;
pointer-events: none;
max-width: min(520px, calc(100vw - 48px));
z-index: 5;
}
.eyebrow {
color: var(--upper);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 6px;
font-size: clamp(23px, 3.2vw, 38px);
line-height: 1.04;
letter-spacing: -0.035em;
}
.subtitle {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.panel {
position: fixed;
top: 20px;
right: 20px;
z-index: 10;
width: 290px;
padding: 16px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(14px);
}
.status {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding-bottom: 13px;
margin-bottom: 12px;
border-bottom: 1px solid var(--line);
}
.status-title {
font-size: 12px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.badge {
flex: 0 0 auto;
padding: 6px 9px;
border: 1px solid rgba(102, 239, 173, 0.4);
border-radius: 999px;
background: rgba(102, 239, 173, 0.12);
color: var(--pass);
font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
}
.badge.fail {
border-color: rgba(255, 107, 121, 0.5);
background: rgba(255, 107, 121, 0.12);
color: var(--fail);
}
.row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 16px;
padding: 6px 0;
color: var(--muted);
font-size: 12px;
}
.row strong {
color: var(--text);
font: 700 12px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
white-space: nowrap;
}
.row .lower {
color: var(--lower);
}
.row .upper {
color: var(--upper);
}
.divider {
height: 1px;
margin: 11px 0;
background: var(--line);
}
.control-label {
display: flex;
justify-content: space-between;
margin: 2px 0 7px;
color: var(--muted);
font-size: 11px;
}
input[type="range"] {
width: 100%;
margin: 3px 0 12px;
accent-color: var(--upper);
cursor: pointer;
}
button {
width: 100%;
padding: 11px 12px;
border: 1px solid rgba(255, 180, 84, 0.45);
border-radius: 10px;
background: rgba(255, 180, 84, 0.13);
color: #ffd39c;
font: 800 11px/1 ui-sans-serif, system-ui, sans-serif;
letter-spacing: 0.06em;
text-transform: uppercase;
cursor: pointer;
transition: background 150ms ease, transform 150ms ease;
}
button:hover {
background: rgba(255, 180, 84, 0.22);
}
button:active {
transform: translateY(1px);
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 9px 14px;
margin-top: 12px;
color: var(--muted);
font-size: 10px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 14px;
height: 6px;
border-radius: 2px;
background: currentColor;
}
.help {
position: fixed;
left: 22px;
bottom: 18px;
z-index: 5;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(8, 18, 30, 0.68);
color: var(--muted);
font-size: 11px;
pointer-events: none;
}
.help kbd {
color: var(--text);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.loading {
position: fixed;
inset: 0;
z-index: 50;
display: grid;
place-items: center;
background: var(--bg);
color: var(--muted);
font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.16em;
text-transform: uppercase;
}
@media (max-width: 760px) {
.title {
top: 16px;
left: 16px;
}
.subtitle {
max-width: 270px;
}
.panel {
top: auto;
right: 12px;
bottom: 12px;
width: min(290px, calc(100vw - 24px));
padding: 13px;
}
.help {
display: none;
}
.legend,
.divider {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene"></canvas>
<header class="title">
<div class="eyebrow">Voxel / Stack Lab</div>
<h1>Nested Chair Clearance</h1>
<p class="subtitle">
Outboard leg nesting with a forward-shifted upper seat. The live AABB test checks every upper-chair block against every lower-chair block.
</p>
</header>
<aside class="panel">
<div class="status">
<div>
<div class="status-title" id="stateLabel">Suspended / Pass</div>
<div style="margin-top:5px;color:var(--muted);font-size:10px" id="intersectionLabel">0 intersections detected</div>
</div>
<div class="badge" id="statusBadge">PASS</div>
</div>
<div class="row">
<span>Lower leg centers</span>
<strong class="lower">1.40 m</strong>
</div>
<div class="row">
<span>Upper leg centers</span>
<strong class="upper">2.04 m</strong>
</div>
<div class="row">
<span>Side frame gap</span>
<strong>0.16 m</strong>
</div>
<div class="row">
<span>Seat forward offset</span>
<strong class="upper">+0.22 m</strong>
</div>
<div class="row">
<span>Seat / back depth gap</span>
<strong>0.11 m</strong>
</div>
<div class="row">
<span>Minimum AABB gap</span>
<strong id="clearanceMetric">0.04 m</strong>
</div>
<div class="divider"></div>
<div class="control-label">
<span>Upper-chair lift</span>
<strong id="liftValue" style="color:var(--upper)">0.30 m</strong>
</div>
<input id="liftSlider" type="range" min="0" max="0.60" step="0.01" value="0.30" />
<button id="nestButton" type="button">Lower into nest</button>
<div class="legend">
<span style="color:var(--lower)"><i class="swatch"></i>Lower chair</span>
<span style="color:var(--upper)"><i class="swatch"></i>Upper chair</span>
<span><i class="swatch"></i>Dashed = plan footprint</span>
</div>
</aside>
<div class="help">
<kbd>Drag</kbd> orbit <kbd>Wheel</kbd> zoom <kbd>R</kbd> reset <kbd>Space</kbd> nest
</div>
<div class="loading" id="loading">Loading voxel clearance study…</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 liftSlider = document.querySelector("#liftSlider");
const liftValue = document.querySelector("#liftValue");
const nestButton = document.querySelector("#nestButton");
const stateLabel = document.querySelector("#stateLabel");
const intersectionLabel = document.querySelector("#intersectionLabel");
const statusBadge = document.querySelector("#statusBadge");
const clearanceMetric = document.querySelector("#clearanceMetric");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
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(0x07111d);
scene.fog = new THREE.Fog(0x07111d, 12, 25);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Custom orbit implementation; no examples/addons are loaded.
const orbit = {
target: new THREE.Vector3(0, 2.55, 0),
radius: 8.8,
theta: 0.67,
phi: 1.08,
dragging: false,
pointerId: null,
lastX: 0,
lastY: 0
};
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);
}
function resetCamera() {
orbit.target.set(0, 2.55, 0);
orbit.radius = window.innerWidth < 700 ? 10.2 : 8.8;
orbit.theta = 0.67;
orbit.phi = 1.08;
updateCamera();
}
resetCamera();
canvas.addEventListener("pointerdown", (event) => {
orbit.dragging = true;
orbit.pointerId = event.pointerId;
orbit.lastX = event.clientX;
orbit.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!orbit.dragging || event.pointerId !== orbit.pointerId) return;
const dx = event.clientX - orbit.lastX;
const dy = event.clientY - orbit.lastY;
orbit.lastX = event.clientX;
orbit.lastY = event.clientY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi - dy * 0.005, 0.34, 1.48);
updateCamera();
});
function endDrag(event) {
if (event.pointerId !== orbit.pointerId) return;
orbit.dragging = false;
orbit.pointerId = null;
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
5.2,
15
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.code === "KeyR") resetCamera();
if (event.code === "Space") {
event.preventDefault();
toggleNest();
}
});
const hemi = new THREE.HemisphereLight(0xb9dcff, 0x152131, 2.25);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff1da, 3.4);
key.position.set(5.5, 10, 6.5);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -7;
key.shadow.camera.right = 7;
key.shadow.camera.top = 9;
key.shadow.camera.bottom = -3;
key.shadow.camera.near = 1;
key.shadow.camera.far = 24;
key.shadow.bias = -0.00035;
scene.add(key);
const rim = new THREE.DirectionalLight(0x58a8ff, 1.6);
rim.position.set(-5, 5, -4);
scene.add(rim);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x0a1622,
roughness: 1,
metalness: 0
});
const ground = new THREE.Mesh(
new THREE.BoxGeometry(30, 0.1, 30),
groundMaterial
);
ground.position.y = -0.08;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(24, 48, 0x284355, 0x152a39);
grid.position.y = -0.025;
grid.material.transparent = true;
grid.material.opacity = 0.55;
scene.add(grid);
const lowerMaterial = new THREE.MeshStandardMaterial({
color: 0x47d8c7,
roughness: 0.72,
metalness: 0.04
});
const lowerSeatMaterial = new THREE.MeshStandardMaterial({
color: 0x64e6d4,
roughness: 0.65,
metalness: 0.03
});
const lowerDarkMaterial = new THREE.MeshStandardMaterial({
color: 0x187e83,
roughness: 0.78,
metalness: 0.04
});
const upperMaterial = new THREE.MeshStandardMaterial({
color: 0xffa844,
roughness: 0.7,
metalness: 0.04
});
const upperSeatMaterial = new THREE.MeshStandardMaterial({
color: 0xffc064,
roughness: 0.64,
metalness: 0.03
});
const upperDarkMaterial = new THREE.MeshStandardMaterial({
color: 0xb95837,
roughness: 0.78,
metalness: 0.04
});
const markerLowerMaterial = new THREE.MeshBasicMaterial({
color: 0x64f4df,
depthTest: false
});
const markerUpperMaterial = new THREE.MeshBasicMaterial({
color: 0xffc86b,
depthTest: false
});
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const collisionParts = [];
function addBlock(parent, size, position, material, owner = null) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
if (owner) {
collisionParts.push({ owner, object: mesh });
}
return mesh;
}
const lowerGroup = new THREE.Group();
const upperGroup = new THREE.Group();
scene.add(lowerGroup, upperGroup);
// The upper chair is shifted forward by 0.22 m.
upperGroup.position.z = 0.22;
// Lower chair: narrow seat and 1.40 m leg-center spacing.
addBlock(lowerGroup, [1.80, 0.20, 1.24], [0, 2.10, 0], lowerSeatMaterial, "lower");
for (const x of [-0.70, 0.70]) {
for (const z of [-0.52, 0.52]) {
addBlock(lowerGroup, [0.16, 2.00, 0.16], [x, 1.00, z], lowerMaterial, "lower");
}
}
for (const x of [-0.70, 0.70]) {
addBlock(lowerGroup, [0.16, 0.16, 1.04], [x, 0.78, 0], lowerDarkMaterial, "lower");
}
for (const x of [-0.70, 0.70]) {
addBlock(lowerGroup, [0.16, 1.48, 0.16], [x, 2.82, -0.62], lowerMaterial, "lower");
}
for (const y of [2.55, 3.25]) {
addBlock(lowerGroup, [1.56, 0.16, 0.16], [0, y, -0.62], lowerDarkMaterial, "lower");
}
// Upper chair: wider outboard frame, with a 2.04 m leg-center spacing.
// Its lower seat edge overlaps the lower back vertically, so the 0.22 m
// forward offset and 0.11 m depth separation are essential.
addBlock(upperGroup, [2.30, 0.20, 1.30], [0, 3.58, 0], upperSeatMaterial, "upper");
for (const x of [-1.02, 1.02]) {
for (const z of [-0.72, 0.40]) {
addBlock(upperGroup, [0.16, 2.28, 0.16], [x, 2.34, z], upperMaterial, "upper");
}
}
for (const x of [-1.02, 1.02]) {
addBlock(upperGroup, [0.16, 0.16, 1.12], [x, 0.72, -0.16], upperDarkMaterial, "upper");
}
for (const x of [-1.02, 1.02]) {
addBlock(upperGroup, [0.16, 1.60, 0.16], [x, 4.28, -0.64], upperMaterial, "upper");
}
for (const y of [4.00, 4.78]) {
addBlock(upperGroup, [2.20, 0.16, 0.16], [0, y, -0.64], upperDarkMaterial, "upper");
}
function makeLabel(text, color = "#d9eef4", width = 2.2) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 720;
labelCanvas.height = 120;
const context = labelCanvas.getContext("2d");
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width / 6, 1);
sprite.renderOrder = 20;
sprite.userData.context = context;
sprite.userData.texture = texture;
sprite.userData.color = color;
setLabel(sprite, text, color);
return sprite;
}
function setLabel(sprite, text, color = sprite.userData.color) {
const ctx = sprite.userData.context;
const texture = sprite.userData.texture;
ctx.clearRect(0, 0, 720, 120);
ctx.fillStyle = "rgba(5, 14, 24, 0.88)";
ctx.fillRect(0, 0, 720, 120);
ctx.strokeStyle = color;
ctx.globalAlpha = 0.8;
ctx.lineWidth = 3;
ctx.strokeRect(2, 2, 716, 116);
ctx.globalAlpha = 1;
ctx.fillStyle = color;
ctx.font = "700 34px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 360, 61, 675);
texture.needsUpdate = true;
}
function makeLine(parent, points, color, opacity = 0.9, dashed = false) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map((point) => new THREE.Vector3(...point))
);
const material = dashed
? new THREE.LineDashedMaterial({
color,
dashSize: 0.10,
gapSize: 0.07,
transparent: true,
opacity,
depthTest: false,
depthWrite: false
})
: new THREE.LineBasicMaterial({
color,
transparent: true,
opacity,
depthTest: false,
depthWrite: false
});
const line = new THREE.Line(geometry, material);
line.renderOrder = 12;
if (dashed) line.computeLineDistances();
parent.add(line);
return line;
}
function setLinePoints(line, points) {
const attribute = line.geometry.getAttribute("position");
const values = new Float32Array(points.length * 3);
points.forEach((point, index) => {
values[index * 3] = point[0];
values[index * 3 + 1] = point[1];
values[index * 3 + 2] = point[2];
});
attribute.array.set(values);
attribute.needsUpdate = true;
line.geometry.computeBoundingSphere();
if (line.material.isLineDashedMaterial) line.computeLineDistances();
}
function addDimensionTick(parent, position, axis, color) {
const size = axis === "x" ? [0.035, 0.18, 0.035] : [0.18, 0.035, 0.035];
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.9,
depthTest: false,
depthWrite: false
});
const tick = new THREE.Mesh(unitBox, material);
tick.scale.set(...size);
tick.position.set(...position);
tick.renderOrder = 15;
parent.add(tick);
return tick;
}
// Plan-view footprints make the nesting strategy easy to read.
makeLine(scene, [
[-0.70, 0.045, -0.52],
[ 0.70, 0.045, -0.52],
[ 0.70, 0.045, 0.52],
[-0.70, 0.045, 0.52],
[-0.70, 0.045, -0.52]
], 0x52dfcf, 0.7, true);
makeLine(scene, [
[-1.02, 0.050, -0.50],
[ 1.02, 0.050, -0.50],
[ 1.02, 0.050, 0.62],
[-1.02, 0.050, 0.62],
[-1.02, 0.050, -0.50]
], 0xffb454, 0.7, true);
// Lower leg-center dimension.
makeLine(lowerGroup, [
[-0.70, 0.25, 0.79],
[ 0.70, 0.25, 0.79]
], 0x52dfcf);
addDimensionTick(lowerGroup, [-0.70, 0.25, 0.79], "x", 0x52dfcf);
addDimensionTick(lowerGroup, [ 0.70, 0.25, 0.79], "x", 0x52dfcf);
const lowerDimensionLabel = makeLabel("LOWER LEG CENTERS 1.40 m", "#64f4df", 2.55);
lowerDimensionLabel.position.set(0, 0.51, 1.03);
lowerGroup.add(lowerDimensionLabel);
// Upper leg-center dimension, attached to the moving upper chair.
makeLine(upperGroup, [
[-1.02, 1.26, 0.82],
[ 1.02, 1.26, 0.82]
], 0xffb454);
addDimensionTick(upperGroup, [-1.02, 1.26, 0.82], "x", 0xffb454);
addDimensionTick(upperGroup, [ 1.02, 1.26, 0.82], "x", 0xffb454);
const upperDimensionLabel = makeLabel("UPPER LEG CENTERS 2.04 m", "#ffc86b", 2.65);
upperDimensionLabel.position.set(0, 1.53, 1.07);
upperGroup.add(upperDimensionLabel);
// Seat center markers.
const lowerSeatMarker = addBlock(
scene,
[0.09, 0.025, 0.09],
[0, 2.215, 0],
markerLowerMaterial
);
lowerSeatMarker.renderOrder = 14;
const upperSeatMarker = addBlock(
upperGroup,
[0.09, 0.025, 0.09],
[0, 3.695, 0],
markerUpperMaterial
);
upperSeatMarker.renderOrder = 14;
// Projected seat-offset dimension.
const lowerProjection = makeLine(scene, [
[0, 2.215, 0],
[1.43, 2.215, 0]
], 0x52dfcf, 0.55, true);
const projectedRiser = makeLine(scene, [
[1.43, 2.215, 0],
[1.43, 3.695, 0.22]
], 0x7fb3c1, 0.42, true);
const upperProjection = makeLine(scene, [
[0, 3.695, 0.22],
[1.43, 3.695, 0.22]
], 0xffb454, 0.62, true);
const offsetDimension = makeLine(scene, [
[1.43, 3.695, 0],
[1.43, 3.695, 0.22]
], 0xffb454);
const offsetTick0 = addDimensionTick(scene, [1.43, 3.695, 0], "z", 0xffb454);
const offsetTick1 = addDimensionTick(scene, [1.43, 3.695, 0.22], "z", 0xffb454);
const offsetLabel = makeLabel("SEAT OFFSET +0.22 m", "#ffc86b", 2.25);
offsetLabel.position.set(1.83, 3.91, 0.11);
scene.add(offsetLabel);
// Depth separation between the lower back and the shifted upper seat.
makeLine(scene, [
[-1.38, 3.59, -0.54],
[-1.38, 3.59, -0.43]
], 0xffb454);
addDimensionTick(scene, [-1.38, 3.59, -0.54], "z", 0xffb454);
addDimensionTick(scene, [-1.38, 3.59, -0.43], "z", 0xffb454);
const backGapLabel = makeLabel("0.11 m BACK GAP", "#ffc86b", 1.72);
backGapLabel.position.set(-1.72, 3.82, -0.485);
scene.add(backGapLabel);
let currentLift = 0.30;
let targetLift = 0.30;
function axisGap(minA, maxA, minB, maxB) {
if (maxA < minB) return minB - maxA;
if (maxB < minA) return minA - maxB;
return 0;
}
function testClearance() {
scene.updateMatrixWorld(true);
const lowerBoxes = [];
const upperBoxes = [];
for (const part of collisionParts) {
const box = new THREE.Box3().setFromObject(part.object);
if (part.owner === "lower") lowerBoxes.push(box);
else upperBoxes.push(box);
}
let intersections = 0;
let minimumGap = Infinity;
for (const lower of lowerBoxes) {
for (const upper of upperBoxes) {
if (lower.intersectsBox(upper)) intersections++;
const dx = axisGap(lower.min.x, lower.max.x, upper.min.x, upper.max.x);
const dy = axisGap(lower.min.y, lower.max.y, upper.min.y, upper.max.y);
const dz = axisGap(lower.min.z, lower.max.z, upper.min.z, upper.max.z);
const gap = Math.hypot(dx, dy, dz);
minimumGap = Math.min(minimumGap, gap);
}
}
return { intersections, minimumGap };
}
function updateStatus() {
const result = testClearance();
const passed = result.intersections === 0;
statusBadge.textContent = passed ? "PASS" : "FAIL";
statusBadge.classList.toggle("fail", !passed);
stateLabel.textContent = currentLift > 0.015
? "Suspended / Pass"
: "Nested / Pass";
if (!passed) {
stateLabel.textContent = "Geometry Conflict";
}
intersectionLabel.textContent = `${result.intersections} intersection${result.intersections === 1 ? "" : "s"} detected`;
clearanceMetric.textContent = `${result.minimumGap.toFixed(2)} m`;
liftValue.textContent = `${currentLift.toFixed(2)} m`;
liftSlider.value = currentLift.toFixed(2);
if (Math.abs(currentLift - targetLift) > 0.008) {
nestButton.textContent = targetLift < currentLift ? "Lowering…" : "Raising…";
} else {
nestButton.textContent = targetLift < 0.015
? "Raise to inspection"
: "Lower into nest";
}
}
function toggleNest() {
targetLift = targetLift < 0.015 ? 0.30 : 0;
}
nestButton.addEventListener("click", toggleNest);
liftSlider.addEventListener("input", () => {
currentLift = Number(liftSlider.value);
targetLift = currentLift;
});
function updateOffsetAnnotation() {
const y = 3.695 + currentLift;
setLinePoints(lowerProjection, [
[0, 2.215, 0],
[1.43, 2.215, 0]
]);
setLinePoints(projectedRiser, [
[1.43, 2.215, 0],
[1.43, y, 0.22]
]);
setLinePoints(upperProjection, [
[0, y, 0.22],
[1.43, y, 0.22]
]);
setLinePoints(offsetDimension, [
[1.43, y, 0],
[1.43, y, 0.22]
]);
offsetTick0.position.y = y;
offsetTick1.position.y = y;
offsetLabel.position.y = y + 0.215;
}
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (Math.abs(currentLift - targetLift) > 0.0001) {
const damping = 1 - Math.exp(-dt * 6.2);
currentLift += (targetLift - currentLift) * damping;
if (Math.abs(currentLift - targetLift) < 0.0001) {
currentLift = targetLift;
}
}
upperGroup.position.y = currentLift;
updateOffsetAnnotation();
updateStatus();
renderer.render(scene, camera);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height, false);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
updateOffsetAnnotation();
updateStatus();
renderer.render(scene, camera);
document.querySelector("#loading").remove();
animate();
</script>
</body>
</html>
```