Prompt specification
Build or customize the Three.js 3D scene "Nesting table edge alignment" 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: Nesting table edge alignment
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/nesting-table-edge-alignment-x0205
Scene Description Prompt:
I'd like to see this as a stylized Three.js scene: nesting table edge alignment. Arrange three small tables with progressively lower tops and narrower frames; slide the middle one halfway under the largest to reveal the required clearances. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (nesting-table-edge-alignment-x0205):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Nesting Table — Edge Alignment Study</title>
<style>
:root {
--ink: #203234;
--muted: #667476;
--paper: #f4f1e9;
--coral: #e46f4f;
--teal: #247b73;
--line: rgba(32, 50, 52, 0.16);
--panel: rgba(248, 246, 239, 0.82);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
}
body {
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
background:
radial-gradient(circle at 47% 32%, #fbf9f3 0%, #efede5 43%, #dcd9d0 100%);
}
body::after {
content: "";
position: fixed;
inset: 0;
z-index: 20;
pointer-events: none;
opacity: 0.13;
background-image:
repeating-linear-gradient(
0deg,
rgba(30, 45, 45, 0.025) 0,
rgba(30, 45, 45, 0.025) 1px,
transparent 1px,
transparent 3px
);
mix-blend-mode: multiply;
}
#viewport,
#annotations,
#tags {
position: fixed;
inset: 0;
}
#viewport {
z-index: 1;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
#viewport canvas.grabbing { cursor: grabbing; }
#annotations,
#tags {
z-index: 4;
pointer-events: none;
}
#guides {
width: 100%;
height: 100%;
overflow: visible;
}
#annotations.is-hidden {
opacity: 0;
visibility: hidden;
}
.annotation {
position: absolute;
z-index: 5;
min-width: 72px;
padding: 6px 9px 5px;
transform: translate(-50%, -50%);
border: 1px solid rgba(255, 255, 255, 0.85);
border-radius: 8px;
color: var(--ink);
background: rgba(249, 247, 241, 0.9);
box-shadow: 0 7px 22px rgba(29, 42, 43, 0.12);
backdrop-filter: blur(8px);
text-align: center;
white-space: nowrap;
}
.annotation::before {
content: "";
display: block;
width: 18px;
height: 2px;
margin: 0 auto 4px;
border-radius: 2px;
background: var(--annotation-color, var(--coral));
}
.annotation strong {
display: block;
font-size: 13px;
line-height: 1;
letter-spacing: -0.02em;
}
.annotation span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.14em;
}
.table-tag {
position: absolute;
z-index: 3;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 9px;
transform: translate(-50%, -50%);
border: 1px solid rgba(32, 50, 52, 0.12);
border-radius: 999px;
color: var(--ink);
background: rgba(250, 248, 242, 0.84);
box-shadow: 0 5px 18px rgba(29, 42, 43, 0.08);
backdrop-filter: blur(7px);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
white-space: nowrap;
}
.table-tag::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--tag-color);
box-shadow: 0 0 0 3px color-mix(in srgb, var(--tag-color) 18%, transparent);
}
header {
position: fixed;
top: 28px;
left: 30px;
z-index: 10;
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: var(--teal);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.21em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(28px, 4vw, 52px);
font-weight: 720;
line-height: 0.94;
letter-spacing: -0.055em;
}
header p {
max-width: 330px;
margin: 12px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.controls {
position: fixed;
top: 28px;
right: 28px;
z-index: 12;
display: flex;
gap: 7px;
padding: 5px;
border: 1px solid rgba(32, 50, 52, 0.12);
border-radius: 12px;
background: rgba(248, 246, 239, 0.72);
box-shadow: 0 10px 30px rgba(29, 42, 43, 0.07);
backdrop-filter: blur(12px);
}
.controls button {
border: 0;
border-radius: 8px;
padding: 9px 12px;
color: var(--ink);
background: transparent;
font: inherit;
font-size: 10px;
font-weight: 780;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition: background 160ms ease, color 160ms ease;
}
.controls button:hover,
.controls button[aria-pressed="true"] {
color: #f9f7f0;
background: var(--ink);
}
.specs {
position: fixed;
left: 50%;
bottom: 22px;
z-index: 10;
width: min(720px, calc(100vw - 32px));
transform: translateX(-50%);
border: 1px solid rgba(32, 50, 52, 0.13);
border-radius: 15px;
background: var(--panel);
box-shadow: 0 15px 45px rgba(29, 42, 43, 0.09);
backdrop-filter: blur(14px);
overflow: hidden;
}
.specs-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
padding: 12px 16px;
border-bottom: 1px solid var(--line);
}
.specs-title {
display: flex;
align-items: baseline;
gap: 9px;
}
.specs-title strong {
font-size: 11px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.specs-title span {
color: var(--muted);
font-size: 10px;
}
.legend {
display: flex;
gap: 14px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.legend i {
display: inline-block;
width: 14px;
height: 2px;
margin-right: 5px;
vertical-align: middle;
background: currentColor;
}
.legend .coral { color: var(--coral); }
.legend .teal { color: var(--teal); }
.table-rows {
display: grid;
grid-template-columns: repeat(3, 1fr);
}
.table-row {
display: grid;
grid-template-columns: 28px 1fr auto;
grid-template-rows: auto auto;
column-gap: 8px;
padding: 12px 15px 13px;
border-right: 1px solid var(--line);
}
.table-row:last-child { border-right: 0; }
.row-index {
grid-row: 1 / 3;
align-self: center;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
}
.row-name {
font-size: 12px;
font-weight: 760;
}
.row-size {
color: var(--muted);
font-variant-numeric: tabular-nums;
font-size: 9px;
line-height: 1.4;
text-align: right;
}
.row-detail {
grid-column: 2 / 4;
margin-top: 4px;
color: var(--muted);
font-size: 9px;
font-variant-numeric: tabular-nums;
}
.specs-foot {
display: flex;
justify-content: space-between;
gap: 16px;
padding: 9px 16px;
border-top: 1px solid var(--line);
color: var(--muted);
background: rgba(255, 255, 255, 0.2);
font-size: 9px;
line-height: 1.4;
}
.clearances {
color: var(--ink);
font-weight: 700;
font-variant-numeric: tabular-nums;
}
#loading {
position: fixed;
inset: 0;
z-index: 50;
display: grid;
place-items: center;
color: var(--muted);
background: #efede5;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 350ms ease, visibility 350ms ease;
}
body.ready #loading {
opacity: 0;
visibility: hidden;
}
@media (max-width: 760px) {
header { top: 20px; left: 20px; }
header p { display: none; }
h1 { font-size: 30px; }
.controls {
top: 18px;
right: 16px;
}
.controls button {
padding: 8px 9px;
font-size: 8px;
}
.specs {
bottom: 12px;
width: calc(100vw - 24px);
}
.specs-title span,
.legend,
.specs-foot .interaction-hint {
display: none;
}
.table-row {
grid-template-columns: 20px 1fr;
padding: 10px 8px;
}
.row-size {
grid-column: 2;
grid-row: 2;
text-align: left;
}
.row-detail { display: none; }
.specs-foot { justify-content: center; }
}
</style>
</head>
<body>
<div id="viewport"></div>
<div id="annotations">
<svg id="guides" aria-hidden="true"></svg>
</div>
<div id="tags" aria-hidden="true"></div>
<header>
<div class="eyebrow">Edge alignment study / 03</div>
<h1>Nesting<br>tables.</h1>
<p>
Three descending frames share one rear datum. Each smaller top overlaps
the next by exactly half its width.
</p>
</header>
<nav class="controls" aria-label="Scene controls">
<button id="orbitView" type="button">Orbit</button>
<button id="planView" type="button">Plan</button>
<button id="guideToggle" type="button" aria-pressed="true">Guides</button>
</nav>
<section class="specs" aria-label="Table specifications">
<div class="specs-head">
<div class="specs-title">
<strong>Progressive nest</strong>
<span>Relative model dimensions</span>
</div>
<div class="legend">
<span class="coral"><i></i>Clearance / tuck</span>
<span class="teal"><i></i>Shared datum</span>
</div>
</div>
<div class="table-rows">
<div class="table-row">
<span class="row-index">01</span>
<span class="row-name">Large</span>
<span class="row-size">4.80 × 3.50</span>
<span class="row-detail">Top 3.20 · Frame 4.15 × 2.72</span>
</div>
<div class="table-row">
<span class="row-index">02</span>
<span class="row-name">Middle</span>
<span class="row-size">3.70 × 2.70</span>
<span class="row-detail">Top 2.48 · Frame 3.08 × 2.08</span>
</div>
<div class="table-row">
<span class="row-index">03</span>
<span class="row-name">Small</span>
<span class="row-size">2.75 × 2.10</span>
<span class="row-detail">Top 1.83 · Frame 2.28 × 1.72</span>
</div>
</div>
<div class="specs-foot">
<span class="clearances" id="clearanceSummary"></span>
<span class="interaction-hint">Drag to orbit · Wheel to zoom · Shift-drag to pan</span>
</div>
</section>
<div id="loading">Building alignment 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 viewport = document.getElementById("viewport");
const annotationsRoot = document.getElementById("annotations");
const tagsRoot = document.getElementById("tags");
const guidesSvg = document.getElementById("guides");
const guideToggle = document.getElementById("guideToggle");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
35,
window.innerWidth / window.innerHeight,
0.1,
100
);
const state = {
theta: -0.62,
phi: 0.86,
radius: 13.2,
target: new THREE.Vector3(-0.45, 1.15, 0),
goal: null
};
let zoomFactor = 1;
let guidesVisible = true;
function fitRadius() {
return Math.max(13.2, 12.0 / camera.aspect);
}
function applyCamera() {
const sinPhi = Math.sin(state.phi);
camera.position.set(
state.target.x + state.radius * sinPhi * Math.sin(state.theta),
state.target.y + state.radius * Math.cos(state.phi),
state.target.z + state.radius * sinPhi * Math.cos(state.theta)
);
camera.lookAt(state.target);
camera.updateMatrixWorld();
}
// Lighting
const hemisphere = new THREE.HemisphereLight(0xfff8eb, 0x687371, 2.15);
scene.add(hemisphere);
const key = new THREE.DirectionalLight(0xfff1d8, 4.4);
key.position.set(-5, 10, 7);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -9;
key.shadow.camera.right = 9;
key.shadow.camera.top = 8;
key.shadow.camera.bottom = -8;
key.shadow.camera.near = 1;
key.shadow.camera.far = 28;
key.shadow.bias = -0.00035;
key.shadow.normalBias = 0.025;
scene.add(key);
const fill = new THREE.DirectionalLight(0xc9e5e2, 1.65);
fill.position.set(7, 5, -6);
scene.add(fill);
const rim = new THREE.DirectionalLight(0xffd8c4, 1.15);
rim.position.set(-6, 3, -7);
scene.add(rim);
// Ground
const ground = new THREE.Mesh(
new THREE.CircleGeometry(8.6, 128),
new THREE.MeshStandardMaterial({
color: 0xe8e4da,
roughness: 0.96,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.025;
ground.receiveShadow = true;
scene.add(ground);
const groundRing = new THREE.Mesh(
new THREE.RingGeometry(8.52, 8.58, 160),
new THREE.MeshBasicMaterial({
color: 0xb9bbb2,
transparent: true,
opacity: 0.3,
side: THREE.DoubleSide
})
);
groundRing.rotation.x = -Math.PI / 2;
groundRing.position.y = -0.018;
scene.add(groundRing);
const tableDefinitions = [
{
id: "01",
name: "LARGE",
w: 4.8,
d: 3.5,
h: 3.2,
t: 0.26,
frameW: 4.15,
frameD: 2.72,
x: 1.0,
z: 0.0,
color: 0xddbd8e,
guide: "#e46f4f",
tagAnchor: new THREE.Vector3(3.38, 2.18, 1.45),
tagOffset: [42, -5]
},
{
id: "02",
name: "MIDDLE",
w: 3.7,
d: 2.7,
h: 2.48,
t: 0.26,
frameW: 3.08,
frameD: 2.08,
x: -1.4,
z: -0.4,
color: 0xc98266,
guide: "#e46f4f",
tagAnchor: new THREE.Vector3(0.43, 1.62, 0.88),
tagOffset: [38, 7]
},
{
id: "03",
name: "SMALL",
w: 2.75,
d: 2.1,
h: 1.83,
t: 0.26,
frameW: 2.28,
frameD: 1.72,
x: -3.25,
z: -0.7,
color: 0x8fa68e,
guide: "#247b73",
tagAnchor: new THREE.Vector3(-2.08, 1.02, 0.28),
tagOffset: [30, 15]
}
];
const [large, middle, small] = tableDefinitions;
const backDatum = -1.75;
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0x26393b,
roughness: 0.42,
metalness: 0.48
});
const footMaterial = new THREE.MeshStandardMaterial({
color: 0x9f7047,
roughness: 0.38,
metalness: 0.62
});
function roundedRectShape(w, d, radius) {
const hw = w / 2;
const hd = d / 2;
const r = Math.min(radius, hw, hd);
const s = new THREE.Shape();
s.moveTo(-hw + r, -hd);
s.lineTo(hw - r, -hd);
s.quadraticCurveTo(hw, -hd, hw, -hd + r);
s.lineTo(hw, hd - r);
s.quadraticCurveTo(hw, hd, hw - r, hd);
s.lineTo(-hw + r, hd);
s.quadraticCurveTo(-hw, hd, -hw, hd - r);
s.lineTo(-hw, -hd + r);
s.quadraticCurveTo(-hw, -hd, -hw + r, -hd);
return s;
}
function roundedSlab(w, d, h, radius, material) {
const bevel = Math.min(0.035, h * 0.14);
const geometry = new THREE.ExtrudeGeometry(
roundedRectShape(w, d, radius),
{
depth: Math.max(0.01, h - bevel * 2),
steps: 1,
curveSegments: 14,
bevelEnabled: true,
bevelSegments: 3,
bevelSize: bevel,
bevelThickness: bevel
}
);
geometry.translate(0, 0, -h / 2);
geometry.rotateX(-Math.PI / 2);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function box(w, h, d, material) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
material
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function cylinderBetween(a, b, radius, material) {
const direction = b.clone().sub(a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius * 1.04, length, 16),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function createTable(def) {
const group = new THREE.Group();
group.position.set(def.x, 0, def.z);
const topMaterial = new THREE.MeshPhysicalMaterial({
color: def.color,
roughness: 0.52,
metalness: 0.02,
clearcoat: 0.12,
clearcoatRoughness: 0.68
});
const top = roundedSlab(def.w, def.d, def.t, 0.28, topMaterial);
top.position.y = def.h - def.t / 2;
group.add(top);
const underlip = roundedSlab(
def.w - 0.12,
def.d - 0.12,
0.075,
0.22,
frameMaterial
);
underlip.position.y = def.h - def.t - 0.025;
group.add(underlip);
const frameY = def.h - def.t - 0.155;
const rail = 0.105;
const frontRail = box(def.frameW, rail, rail, frameMaterial);
frontRail.position.set(0, frameY, def.frameD / 2);
group.add(frontRail);
const backRail = frontRail.clone();
backRail.position.z = -def.frameD / 2;
group.add(backRail);
const sideRail = box(rail, rail, def.frameD, frameMaterial);
sideRail.position.set(def.frameW / 2, frameY, 0);
group.add(sideRail);
const oppositeSideRail = sideRail.clone();
oppositeSideRail.position.x = -def.frameW / 2;
group.add(oppositeSideRail);
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
const topPoint = new THREE.Vector3(
sx * def.frameW / 2,
frameY - 0.015,
sz * def.frameD / 2
);
const bottomPoint = new THREE.Vector3(
sx * (def.frameW / 2 + 0.13),
0.065,
sz * (def.frameD / 2 + 0.13)
);
group.add(
cylinderBetween(topPoint, bottomPoint, 0.062, frameMaterial)
);
const foot = new THREE.Mesh(
new THREE.SphereGeometry(0.071, 14, 10),
footMaterial
);
foot.position.copy(bottomPoint);
foot.position.y = 0.035;
foot.castShadow = true;
group.add(foot);
}
}
const stretcher = box(
def.frameW + 0.24,
0.065,
0.065,
frameMaterial
);
stretcher.position.set(
0,
0.39,
def.frameD / 2 + 0.13
);
group.add(stretcher);
scene.add(group);
return group;
}
tableDefinitions.forEach(createTable);
// Three-dimensional guide group: shared datum and frame footprints.
const guideRoot = new THREE.Group();
scene.add(guideRoot);
function dashedLine(points, color, opacity = 0.55, dashSize = 0.11) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineDashedMaterial({
color,
dashSize,
gapSize: dashSize * 0.72,
transparent: true,
opacity,
depthWrite: false
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
line.renderOrder = 7;
return line;
}
for (const table of tableDefinitions) {
const left = table.x - table.w / 2;
const right = table.x + table.w / 2;
guideRoot.add(
dashedLine(
[
new THREE.Vector3(left, table.h + 0.018, backDatum),
new THREE.Vector3(right, table.h + 0.018, backDatum)
],
0x247b73,
0.75,
0.095
)
);
const hw = table.frameW / 2;
const hd = table.frameD / 2;
guideRoot.add(
dashedLine(
[
new THREE.Vector3(table.x - hw, 0.012, table.z - hd),
new THREE.Vector3(table.x + hw, 0.012, table.z - hd),
new THREE.Vector3(table.x + hw, 0.012, table.z + hd),
new THREE.Vector3(table.x - hw, 0.012, table.z + hd),
new THREE.Vector3(table.x - hw, 0.012, table.z - hd)
],
table.guide,
0.32,
0.075
)
);
}
// SVG dimension annotations projected directly from scene coordinates.
const annotations = [];
const tableTags = [];
const SVG_NS = "http://www.w3.org/2000/svg";
function svgElement(name, attributes = {}) {
const element = document.createElementNS(SVG_NS, name);
for (const [key, value] of Object.entries(attributes)) {
element.setAttribute(key, value);
}
return element;
}
function createAnnotation({
p1,
p2,
value,
label,
color = "#e46f4f",
offset = [0, 0],
line = true
}) {
const group = svgElement("g");
const dimension = svgElement("line", {
stroke: color,
"stroke-width": 1.25,
"stroke-linecap": "round",
"stroke-dasharray": "4 4"
});
const tick1 = svgElement("line", {
stroke: color,
"stroke-width": 1.3,
"stroke-linecap": "round"
});
const tick2 = svgElement("line", {
stroke: color,
"stroke-width": 1.3,
"stroke-linecap": "round"
});
group.append(dimension, tick1, tick2);
guidesSvg.appendChild(group);
const html = document.createElement("div");
html.className = "annotation";
html.style.setProperty("--annotation-color", color);
html.innerHTML = `<strong>${value}</strong><span>${label}</span>`;
annotationsRoot.appendChild(html);
annotations.push({
p1: p1.clone(),
p2: p2.clone(),
color,
offset,
line,
dimension,
tick1,
tick2,
html
});
}
function createTag(anchor, text, color, offset) {
const element = document.createElement("div");
element.className = "table-tag";
element.style.setProperty("--tag-color", color);
element.textContent = text;
tagsRoot.appendChild(element);
tableTags.push({
anchor: anchor.clone(),
offset,
element
});
}
for (const table of tableDefinitions) {
createTag(
table.tagAnchor,
`${table.id} ${table.name}`,
table.guide,
table.tagOffset
);
}
const largeUnder = large.h - large.t;
const middleUnder = middle.h - middle.t;
const largeLeft = large.x - large.w / 2;
const middleRight = middle.x + middle.w / 2;
const middleLeft = middle.x - middle.w / 2;
const smallRight = small.x + small.w / 2;
createAnnotation({
p1: new THREE.Vector3(-0.72, middle.h, -0.96),
p2: new THREE.Vector3(-0.72, largeUnder, -0.96),
value: (largeUnder - middle.h).toFixed(2),
label: "TOP CLEARANCE",
color: "#e46f4f",
offset: [52, -4]
});
createAnnotation({
p1: new THREE.Vector3(largeLeft, large.h + 0.075, 0.3),
p2: new THREE.Vector3(middleRight, large.h + 0.075, 0.3),
value: (middleRight - largeLeft).toFixed(2),
label: "50% TUCKED",
color: "#e46f4f",
offset: [0, 24]
});
createAnnotation({
p1: new THREE.Vector3(-2.55, small.h, -1.05),
p2: new THREE.Vector3(-2.55, middleUnder, -1.05),
value: (middleUnder - small.h).toFixed(2),
label: "TOP CLEARANCE",
color: "#e46f4f",
offset: [-48, 0]
});
createAnnotation({
p1: new THREE.Vector3(middleLeft, middle.h + 0.075, 0.0),
p2: new THREE.Vector3(smallRight, middle.h + 0.075, 0.0),
value: (smallRight - middleLeft).toFixed(2),
label: "50% TUCKED",
color: "#e46f4f",
offset: [0, 23]
});
createAnnotation({
p1: new THREE.Vector3(2.92, large.h + 0.02, backDatum),
p2: new THREE.Vector3(3.28, large.h + 0.02, backDatum),
value: "SHARED",
label: "REAR DATUM",
color: "#247b73",
offset: [64, -14]
});
document.getElementById("clearanceSummary").textContent =
`Vertical clearance L → M ${(largeUnder - middle.h).toFixed(2)}` +
` · M → S ${(middleUnder - small.h).toFixed(2)}` +
" · Rear edges aligned";
function projectPoint(point) {
const projected = point.clone().project(camera);
return {
x: (projected.x * 0.5 + 0.5) * window.innerWidth,
y: (-projected.y * 0.5 + 0.5) * window.innerHeight,
visible: projected.z > -1 && projected.z < 1
};
}
function updateAnnotations() {
for (const annotation of annotations) {
const a = projectPoint(annotation.p1);
const b = projectPoint(annotation.p2);
if (!a.visible || !b.visible) {
annotation.html.style.display = "none";
annotation.dimension.style.display = "none";
annotation.tick1.style.display = "none";
annotation.tick2.style.display = "none";
continue;
}
annotation.html.style.display = "";
annotation.dimension.style.display = annotation.line ? "" : "none";
annotation.tick1.style.display = annotation.line ? "" : "none";
annotation.tick2.style.display = annotation.line ? "" : "none";
const dx = b.x - a.x;
const dy = b.y - a.y;
const length = Math.hypot(dx, dy) || 1;
const nx = -dy / length;
const ny = dx / length;
const tick = 5;
annotation.dimension.setAttribute("x1", a.x);
annotation.dimension.setAttribute("y1", a.y);
annotation.dimension.setAttribute("x2", b.x);
annotation.dimension.setAttribute("y2", b.y);
annotation.tick1.setAttribute("x1", a.x - nx * tick);
annotation.tick1.setAttribute("y1", a.y - ny * tick);
annotation.tick1.setAttribute("x2", a.x + nx * tick);
annotation.tick1.setAttribute("y2", a.y + ny * tick);
annotation.tick2.setAttribute("x1", b.x - nx * tick);
annotation.tick2.setAttribute("y1", b.y - ny * tick);
annotation.tick2.setAttribute("x2", b.x + nx * tick);
annotation.tick2.setAttribute("y2", b.y + ny * tick);
annotation.html.style.left =
`${(a.x + b.x) / 2 + annotation.offset[0]}px`;
annotation.html.style.top =
`${(a.y + b.y) / 2 + annotation.offset[1]}px`;
}
for (const tag of tableTags) {
const p = projectPoint(tag.anchor);
tag.element.style.display = p.visible ? "" : "none";
tag.element.style.left = `${p.x + tag.offset[0]}px`;
tag.element.style.top = `${p.y + tag.offset[1]}px`;
}
}
// Direct camera controls: orbit, pan and zoom without addons.
const canvas = renderer.domElement;
const pointers = new Map();
let lastPinchDistance = 0;
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
canvas.addEventListener("pointerdown", event => {
if (event.pointerType === "mouse" && event.button !== 0) return;
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
state.goal = null;
canvas.classList.add("grabbing");
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
lastPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
canvas.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
if (event.shiftKey) {
const view = state.target.clone().sub(camera.position).normalize();
const right = new THREE.Vector3()
.crossVectors(view, camera.up)
.normalize();
const up = new THREE.Vector3()
.crossVectors(right, view)
.normalize();
state.target.addScaledVector(
right,
-dx * state.radius * 0.0013
);
state.target.addScaledVector(
up,
dy * state.radius * 0.0013
);
} else {
state.theta -= dx * 0.006;
state.phi = clamp(state.phi + dy * 0.005, 0.06, 1.43);
}
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (lastPinchDistance > 0) {
zoomFactor = clamp(
zoomFactor * (lastPinchDistance / distance),
0.58,
2.1
);
state.radius = fitRadius() * zoomFactor;
}
lastPinchDistance = distance;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) lastPinchDistance = 0;
if (pointers.size === 0) canvas.classList.remove("grabbing");
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("lostpointercapture", endPointer);
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
state.goal = null;
zoomFactor = clamp(
zoomFactor * Math.exp(event.deltaY * 0.001),
0.58,
2.1
);
state.radius = fitRadius() * zoomFactor;
},
{ passive: false }
);
function transitionTo(theta, phi, target, radiusMultiplier = 1) {
state.goal = {
theta,
phi,
target: target.clone(),
radius: fitRadius() * radiusMultiplier
};
}
document.getElementById("orbitView").addEventListener("click", () => {
transitionTo(
-0.62,
0.86,
new THREE.Vector3(-0.45, 1.15, 0)
);
});
document.getElementById("planView").addEventListener("click", () => {
transitionTo(
0,
0.06,
new THREE.Vector3(-0.45, 0.42, 0)
);
});
guideToggle.addEventListener("click", () => {
guidesVisible = !guidesVisible;
guideRoot.visible = guidesVisible;
annotationsRoot.classList.toggle("is-hidden", !guidesVisible);
guideToggle.setAttribute("aria-pressed", String(guidesVisible));
guideToggle.textContent = guidesVisible ? "Guides" : "Guides off";
});
window.addEventListener("keydown", event => {
if (event.key.toLowerCase() === "r") {
transitionTo(
-0.62,
0.86,
new THREE.Vector3(-0.45, 1.15, 0)
);
}
if (event.key.toLowerCase() === "t") {
transitionTo(
0,
0.06,
new THREE.Vector3(-0.45, 0.42, 0)
);
}
if (event.key.toLowerCase() === "g") {
guideToggle.click();
}
});
function resize() {
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);
guidesSvg.setAttribute("viewBox", `0 0 ${width} ${height}`);
if (!state.goal) {
state.radius = fitRadius() * zoomFactor;
} else {
state.goal.radius = fitRadius() * state.goal.radius / fitRadius();
}
}
window.addEventListener("resize", resize);
resize();
state.radius = fitRadius();
applyCamera();
function lerpAngle(current, target, amount) {
const delta = THREE.MathUtils.euclideanModulo(
target - current + Math.PI,
Math.PI * 2
) - Math.PI;
return current + delta * amount;
}
let previousTime = performance.now();
let firstFrame = true;
renderer.setAnimationLoop(time => {
const dt = Math.min((time - previousTime) / 1000, 0.05);
previousTime = time;
if (state.goal) {
const amount = 1 - Math.exp(-dt * 8);
state.theta = lerpAngle(
state.theta,
state.goal.theta,
amount
);
state.phi = THREE.MathUtils.lerp(
state.phi,
state.goal.phi,
amount
);
state.target.lerp(state.goal.target, amount);
state.radius = THREE.MathUtils.lerp(
state.radius,
state.goal.radius,
amount
);
if (
Math.abs(state.goal.phi - state.phi) < 0.001 &&
state.target.distanceTo(state.goal.target) < 0.001
) {
state.goal = null;
}
}
applyCamera();
updateAnnotations();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
document.body.classList.add("ready");
}
});
</script>
</body>
</html>
```