Prompt specification
Build or customize the Three.js 3D scene "Picture frame glue-up table" 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: Picture frame glue-up table
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/picture-frame-glue-up-table-x0255
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing padded clamp jaws. Arrange four frame rails, corner guides, clamps, and protective pads; animate assembly into a rectangle while diagonals remain visible for checking squareness. Stylized solid forms.
Working Three.js Starter (picture-frame-glue-up-table-x0255):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Padded Clamp Jaw Assembly</title>
<style>
:root {
color-scheme: dark;
--bg: #0b141c;
--panel: rgba(15, 27, 36, 0.82);
--border: rgba(157, 205, 216, 0.18);
--text: #e9f3f4;
--muted: #91a9b1;
--cyan: #53dcff;
--coral: #ff7896;
--green: #78e0b5;
--orange: #ef744d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#viewport {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
z-index: 5;
pointer-events: none;
}
.info-panel {
top: 24px;
left: 24px;
width: min(340px, calc(100vw - 48px));
padding: 20px;
border: 1px solid var(--border);
border-radius: 18px;
background:
linear-gradient(135deg, rgba(255, 255, 255, 0.045), transparent),
var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(16px);
}
.eyebrow {
margin-bottom: 7px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: var(--text);
font-size: clamp(21px, 3vw, 29px);
font-weight: 720;
line-height: 1.08;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 18px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.status-row {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 16px;
color: #cfe0e4;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.status-dot {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 0 5px rgba(239, 116, 77, 0.12);
animation: pulse 1.25s ease-in-out infinite;
}
.status-dot.done {
background: var(--green);
box-shadow: 0 0 0 5px rgba(120, 224, 181, 0.12);
animation: none;
}
@keyframes pulse {
50% {
opacity: 0.45;
transform: scale(0.8);
}
}
.progress-track {
height: 4px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.08);
}
#progressFill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--orange), var(--cyan));
transition: width 0.08s linear;
}
.progress-label {
display: flex;
justify-content: space-between;
margin-top: 7px;
color: #708993;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-top: 17px;
}
.metric {
padding: 11px 12px;
border: 1px solid rgba(255, 255, 255, 0.065);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
}
.metric-label {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.metric-value {
color: var(--text);
font-size: 18px;
font-variant-numeric: tabular-nums;
font-weight: 720;
}
.controls {
right: 24px;
bottom: 24px;
display: flex;
gap: 9px;
pointer-events: auto;
}
button {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
min-height: 40px;
padding: 0 15px;
border: 1px solid var(--border);
border-radius: 11px;
background: rgba(17, 31, 40, 0.86);
color: var(--text);
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
backdrop-filter: blur(12px);
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
button:hover {
border-color: rgba(83, 220, 255, 0.45);
background: rgba(28, 48, 59, 0.92);
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
button.primary {
border-color: rgba(83, 220, 255, 0.28);
background: rgba(38, 105, 121, 0.54);
}
.legend {
top: 24px;
right: 24px;
padding: 13px 15px;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--panel);
color: var(--muted);
font-size: 9px;
line-height: 1.9;
letter-spacing: 0.05em;
backdrop-filter: blur(14px);
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
white-space: nowrap;
}
.swatch {
width: 15px;
height: 4px;
border-radius: 99px;
background: var(--color);
box-shadow: 0 0 9px color-mix(in srgb, var(--color) 45%, transparent);
}
.hint {
left: 24px;
bottom: 24px;
color: rgba(194, 216, 221, 0.58);
font-size: 10px;
letter-spacing: 0.04em;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: var(--bg);
color: var(--muted);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
.info-panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px;
}
.subtitle {
display: none;
}
.metrics {
margin-top: 12px;
}
.legend {
display: none;
}
.controls {
right: 12px;
bottom: 12px;
}
.hint {
display: none;
}
button {
padding: 0 12px;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<section class="hud info-panel">
<div class="eyebrow">Assembly inspection demo</div>
<h1>Padded Clamp Jaws</h1>
<p class="subtitle">
Four rails align into a rectangular frame while corner guides seat,
protective pads close, and both diagonals remain visible for inspection.
</p>
<div class="status-row">
<span id="statusDot" class="status-dot"></span>
<span id="statusText">Rails approaching</span>
</div>
<div class="progress-track">
<div id="progressFill"></div>
</div>
<div class="progress-label">
<span>Assembly progress</span>
<span id="progressText">0%</span>
</div>
<div class="metrics">
<div class="metric">
<span class="metric-label">Corner angle</span>
<span id="angleValue" class="metric-value">—</span>
</div>
<div class="metric">
<span class="metric-label">Diagonal Δ</span>
<span id="deltaValue" class="metric-value">—</span>
</div>
</div>
</section>
<aside class="hud legend">
<div class="legend-row">
<span class="swatch" style="--color:#329b96"></span>
Frame rails
</div>
<div class="legend-row">
<span class="swatch" style="--color:#d7b45d"></span>
Corner guides
</div>
<div class="legend-row">
<span class="swatch" style="--color:#ef744d"></span>
Clamp bodies
</div>
<div class="legend-row">
<span class="swatch" style="--color:#26333d"></span>
Protective rubber pads
</div>
<div class="legend-row">
<span class="swatch" style="--color:#53dcff"></span>
Live diagonals
</div>
</aside>
<div class="hud controls">
<button id="replayButton" class="primary" type="button">
<span aria-hidden="true">↻</span> Replay assembly
</button>
<button id="resetButton" type="button" title="Reset camera">
<span aria-hidden="true">⌖</span> Reset view
</button>
</div>
<div class="hud hint">
Drag to orbit · Scroll or pinch to zoom · Double-click to reset
</div>
<div id="loading">Loading assembly…</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 statusText = document.getElementById("statusText");
const statusDot = document.getElementById("statusDot");
const progressFill = document.getElementById("progressFill");
const progressText = document.getElementById("progressText");
const angleValue = document.getElementById("angleValue");
const deltaValue = document.getElementById("deltaValue");
const replayButton = document.getElementById("replayButton");
const resetButton = document.getElementById("resetButton");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b141c);
scene.fog = new THREE.FogExp2(0x0b141c, 0.018);
const camera = new THREE.PerspectiveCamera(
42,
viewport.clientWidth / viewport.clientHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(viewport.clientWidth, viewport.clientHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.13;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D animation of a padded clamp-jaw frame assembly"
);
viewport.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xc8e7ff, 0x17232c, 2.1);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.8);
keyLight.position.set(5.5, 8.5, 10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x67d9ff, 1.65);
fillLight.position.set(-7, 3, 6);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xff865f, 1.15);
rimLight.position.set(5, -3, -6);
scene.add(rimLight);
const palette = {
rail: 0x329b96,
railHighlight: 0x78d8cf,
railEnd: 0x226a69,
guide: 0xd7b45d,
guideLight: 0xf2d487,
clamp: 0xef744d,
clampLight: 0xffa06f,
pad: 0x26333d,
padGroove: 0x60727d,
metal: 0xa9b9bf,
darkMetal: 0x26343c,
cyan: 0x53dcff,
coral: 0xff7896
};
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.55,
metalness: 0.08,
...options
});
}
const materials = {
rail: standardMaterial(palette.rail, {
roughness: 0.43,
metalness: 0.2
}),
railHighlight: standardMaterial(palette.railHighlight, {
roughness: 0.38,
metalness: 0.16
}),
railEnd: standardMaterial(palette.railEnd, {
roughness: 0.48,
metalness: 0.24
}),
guide: standardMaterial(palette.guide, {
roughness: 0.4,
metalness: 0.28
}),
guideLight: standardMaterial(palette.guideLight, {
roughness: 0.35,
metalness: 0.22
}),
clamp: standardMaterial(palette.clamp, {
roughness: 0.43,
metalness: 0.12
}),
clampLight: standardMaterial(palette.clampLight, {
roughness: 0.4,
metalness: 0.1
}),
pad: new THREE.MeshPhysicalMaterial({
color: palette.pad,
roughness: 0.94,
metalness: 0,
clearcoat: 0.08,
clearcoatRoughness: 0.9
}),
padGroove: standardMaterial(palette.padGroove, {
roughness: 0.85,
metalness: 0.04
}),
metal: standardMaterial(palette.metal, {
roughness: 0.28,
metalness: 0.78
}),
darkMetal: standardMaterial(palette.darkMetal, {
roughness: 0.42,
metalness: 0.64
})
};
// Rounded, solid geometry made entirely with Three.js core geometry.
function roundedBoxGeometry(width, height, depth, radius = 0.1) {
const w = width;
const h = height;
const r = Math.max(0.001, Math.min(radius, w * 0.49, h * 0.49));
const bevel = Math.min(depth * 0.18, r * 0.25, 0.045);
const shape = new THREE.Shape();
shape.moveTo(-w / 2 + r, -h / 2);
shape.lineTo(w / 2 - r, -h / 2);
shape.quadraticCurveTo(w / 2, -h / 2, w / 2, -h / 2 + r);
shape.lineTo(w / 2, h / 2 - r);
shape.quadraticCurveTo(w / 2, h / 2, w / 2 - r, h / 2);
shape.lineTo(-w / 2 + r, h / 2);
shape.quadraticCurveTo(-w / 2, h / 2, -w / 2, h / 2 - r);
shape.lineTo(-w / 2, -h / 2 + r);
shape.quadraticCurveTo(-w / 2, -h / 2, -w / 2 + r, -h / 2);
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: Math.max(0.01, depth - bevel * 2),
bevelEnabled: bevel > 0,
bevelThickness: bevel,
bevelSize: bevel,
bevelSegments: 2,
curveSegments: 8,
steps: 1
});
geometry.center();
geometry.computeVertexNormals();
return geometry;
}
function mesh(geometry, material, parent, position = [0, 0, 0]) {
const object = new THREE.Mesh(geometry, material);
object.position.set(...position);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
// Floor and faint technical grid.
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(32, 32),
standardMaterial(0x111d26, {
roughness: 0.93,
metalness: 0.02
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -4.8;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(28, 28, 0x29434d, 0x192a33);
grid.position.y = -4.78;
grid.material.transparent = true;
grid.material.opacity = 0.36;
scene.add(grid);
// Background calibration rings.
const ringMaterial = new THREE.MeshBasicMaterial({
color: 0x31505c,
transparent: true,
opacity: 0.32,
depthWrite: false
});
for (const radius of [4.8, 5.35]) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(radius, 0.018, 8, 120),
ringMaterial
);
ring.position.z = -1.45;
scene.add(ring);
}
const tickGeometry = new THREE.BoxGeometry(0.19, 0.026, 0.018);
for (let i = 0; i < 24; i++) {
const angle = (i / 24) * Math.PI * 2;
const tick = new THREE.Mesh(tickGeometry, ringMaterial);
tick.position.set(
Math.cos(angle) * 5.35,
Math.sin(angle) * 5.35,
-1.43
);
tick.rotation.z = angle;
scene.add(tick);
}
const FRAME = {
leftX: -3.45,
rightX: 3.45,
topY: 2.35,
bottomY: -2.35,
horizontalLength: 7.4,
verticalLength: 4.7
};
const rails = [];
const guides = [];
const clamps = [];
function createRail({
kind,
length,
finalPosition,
finalRotation,
startPosition,
startRotation,
delay
}) {
const group = new THREE.Group();
mesh(
roundedBoxGeometry(length, 0.46, 0.52, 0.14),
materials.rail,
group
);
mesh(
roundedBoxGeometry(length - 0.48, 0.065, 0.035, 0.025),
materials.railHighlight,
group,
[0, 0, 0.278]
);
for (const side of [-1, 1]) {
mesh(
roundedBoxGeometry(0.17, 0.54, 0.58, 0.075),
materials.railEnd,
group,
[side * (length * 0.5 - 0.07), 0, 0]
);
}
group.position.copy(startPosition);
group.rotation.z = startRotation;
group.userData = {
kind,
startPosition: startPosition.clone(),
finalPosition: finalPosition.clone(),
startRotation,
finalRotation,
delay
};
scene.add(group);
rails.push(group);
return group;
}
createRail({
kind: "top",
length: FRAME.horizontalLength,
finalPosition: new THREE.Vector3(0, FRAME.topY, 0),
finalRotation: 0,
startPosition: new THREE.Vector3(0.35, 4.4, 0),
startRotation: 0.13,
delay: 0.08
});
createRail({
kind: "bottom",
length: FRAME.horizontalLength,
finalPosition: new THREE.Vector3(0, FRAME.bottomY, 0),
finalRotation: 0,
startPosition: new THREE.Vector3(-0.45, -4.4, 0),
startRotation: -0.14,
delay: 0.2
});
createRail({
kind: "left",
length: FRAME.verticalLength,
finalPosition: new THREE.Vector3(FRAME.leftX, 0, 0),
finalRotation: Math.PI / 2,
startPosition: new THREE.Vector3(-5.35, 0.3, 0),
startRotation: Math.PI / 2 + 0.22,
delay: 0.34
});
createRail({
kind: "right",
length: FRAME.verticalLength,
finalPosition: new THREE.Vector3(FRAME.rightX, 0, 0),
finalRotation: -Math.PI / 2,
startPosition: new THREE.Vector3(5.35, -0.3, 0),
startRotation: -Math.PI / 2 - 0.2,
delay: 0.48
});
function createCornerGuide(sx, sy, index) {
const group = new THREE.Group();
// Two inward-facing arms form an L-shaped guide.
mesh(
roundedBoxGeometry(1.05, 0.27, 0.64, 0.09),
materials.guide,
group,
[-sx * 0.47, 0, 0.04]
);
mesh(
roundedBoxGeometry(0.27, 1.05, 0.64, 0.09),
materials.guide,
group,
[0, -sy * 0.47, 0.04]
);
mesh(
roundedBoxGeometry(0.5, 0.5, 0.7, 0.1),
materials.guideLight,
group,
[0, 0, 0.04]
);
const boltGeometry = new THREE.CylinderGeometry(
0.105,
0.105,
0.09,
24
);
for (const boltPosition of [
[-sx * 0.21, 0, 0.42],
[0, -sy * 0.21, 0.42]
]) {
const bolt = mesh(
boltGeometry,
materials.darkMetal,
group,
boltPosition
);
bolt.rotation.x = Math.PI / 2;
const slot = mesh(
new THREE.BoxGeometry(0.12, 0.025, 0.018),
materials.metal,
group,
[boltPosition[0], boltPosition[1], 0.47]
);
slot.rotation.z = index % 2 ? 0.55 : -0.55;
}
const finalPosition = new THREE.Vector3(
sx * FRAME.rightX,
sy * FRAME.topY,
0
);
const startPosition = finalPosition.clone().add(
new THREE.Vector3(sx * 1.35, sy * 1.35, 0)
);
group.position.copy(startPosition);
group.rotation.z = sx * sy * 0.18;
group.userData = {
startPosition,
finalPosition,
startRotation: group.rotation.z,
finalRotation: 0,
delay: 1.18 + index * 0.13
};
scene.add(group);
guides.push(group);
}
createCornerGuide(-1, 1, 0);
createCornerGuide(1, 1, 1);
createCornerGuide(1, -1, 2);
createCornerGuide(-1, -1, 3);
function createClamp({
index,
finalPosition,
finalRotation,
startPosition,
startRotation,
delay
}) {
const group = new THREE.Group();
// Main C-shaped clamp body.
mesh(
roundedBoxGeometry(0.36, 1.28, 0.72, 0.12),
materials.clamp,
group,
[-0.66, 0, 0]
);
mesh(
roundedBoxGeometry(0.12, 0.65, 0.735, 0.04),
materials.clampLight,
group,
[-0.86, 0, 0.01]
);
const upperJaw = new THREE.Group();
const lowerJaw = new THREE.Group();
group.add(upperJaw, lowerJaw);
for (const jaw of [upperJaw, lowerJaw]) {
mesh(
roundedBoxGeometry(1.28, 0.24, 0.72, 0.09),
materials.clamp,
jaw,
[0.03, 0, 0]
);
}
// Protective rubber pad on the inner face of each jaw.
function createPad(parent, exposedSide) {
const pad = mesh(
roundedBoxGeometry(0.66, 0.11, 0.63, 0.045),
materials.pad,
parent,
[0.1, exposedSide * 0.12, 0.015]
);
for (let i = -1; i <= 1; i++) {
mesh(
new THREE.BoxGeometry(0.025, 0.014, 0.46),
materials.padGroove,
parent,
[0.1 + i * 0.16, exposedSide * 0.064, 0.015]
);
}
return pad;
}
createPad(upperJaw, -1);
createPad(lowerJaw, 1);
// Central threaded screw.
mesh(
new THREE.CylinderGeometry(0.09, 0.09, 0.96, 20),
materials.metal,
group,
[0.49, 0.12, 0.36]
);
for (let i = 0; i < 6; i++) {
const thread = new THREE.Mesh(
new THREE.TorusGeometry(0.105, 0.013, 6, 24),
materials.darkMetal
);
thread.position.set(0.49, -0.22 + i * 0.13, 0.36);
thread.rotation.x = Math.PI / 2;
thread.castShadow = true;
group.add(thread);
}
// T-handle spins as the clamp tightens.
const handle = new THREE.Group();
handle.position.set(0.49, 0.68, 0.36);
group.add(handle);
const handleBar = mesh(
new THREE.CylinderGeometry(0.055, 0.055, 0.76, 16),
materials.darkMetal,
handle
);
handleBar.rotation.z = Math.PI / 2;
for (const side of [-1, 1]) {
const knob = mesh(
new THREE.SphereGeometry(0.105, 18, 12),
materials.clampLight,
handle,
[side * 0.39, 0, 0]
);
knob.scale.y = 0.72;
}
group.position.copy(startPosition);
group.rotation.z = startRotation;
group.userData = {
index,
upperJaw,
lowerJaw,
handle,
startPosition: startPosition.clone(),
finalPosition: finalPosition.clone(),
startRotation,
finalRotation,
delay
};
scene.add(group);
clamps.push(group);
}
createClamp({
index: 0,
finalPosition: new THREE.Vector3(1.55, FRAME.topY, 0),
finalRotation: 0,
startPosition: new THREE.Vector3(1.55, 4.52, 0),
startRotation: 0.2,
delay: 2.25
});
createClamp({
index: 1,
finalPosition: new THREE.Vector3(-1.55, FRAME.bottomY, 0),
finalRotation: Math.PI,
startPosition: new THREE.Vector3(-1.55, -4.45, 0),
startRotation: Math.PI - 0.2,
delay: 2.36
});
createClamp({
index: 2,
finalPosition: new THREE.Vector3(FRAME.leftX, 0.85, 0),
finalRotation: Math.PI / 2,
startPosition: new THREE.Vector3(-5.62, 1.05, 0),
startRotation: Math.PI / 2 + 0.24,
delay: 2.47
});
createClamp({
index: 3,
finalPosition: new THREE.Vector3(FRAME.rightX, -0.85, 0),
finalRotation: -Math.PI / 2,
startPosition: new THREE.Vector3(5.62, -1.05, 0),
startRotation: -Math.PI / 2 - 0.24,
delay: 2.58
});
// Live inspection diagonals.
const diagonalMaterials = [
new THREE.MeshBasicMaterial({
color: palette.cyan,
transparent: true,
opacity: 0.62,
depthTest: false,
depthWrite: false,
fog: false
}),
new THREE.MeshBasicMaterial({
color: palette.coral,
transparent: true,
opacity: 0.62,
depthTest: false,
depthWrite: false,
fog: false
})
];
const diagonalGeometry = new THREE.BoxGeometry(1, 1, 1);
const diagonalA = new THREE.Mesh(diagonalGeometry, diagonalMaterials[0]);
const diagonalB = new THREE.Mesh(diagonalGeometry, diagonalMaterials[1]);
diagonalA.renderOrder = 20;
diagonalB.renderOrder = 20;
scene.add(diagonalA, diagonalB);
const endpointGeometry = new THREE.SphereGeometry(0.105, 18, 12);
const endpoints = [];
for (let i = 0; i < 4; i++) {
const endpoint = new THREE.Mesh(
endpointGeometry,
diagonalMaterials[i % 2]
);
endpoint.renderOrder = 21;
scene.add(endpoint);
endpoints.push(endpoint);
}
const centerMarker = new THREE.Mesh(
new THREE.OctahedronGeometry(0.14),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.9,
depthTest: false,
depthWrite: false,
fog: false
})
);
centerMarker.renderOrder = 22;
scene.add(centerMarker);
function updateDiagonal(object, a, b) {
const dx = b.x - a.x;
const dy = b.y - a.y;
const length = Math.hypot(dx, dy);
object.position.set(
(a.x + b.x) * 0.5,
(a.y + b.y) * 0.5,
0.61
);
object.rotation.z = Math.atan2(dy, dx);
object.scale.set(Math.max(length, 0.001), 0.045, 0.035);
}
const clamp01 = (value) => Math.max(0, Math.min(1, value));
const easeInOutCubic = (value) =>
value < 0.5
? 4 * value * value * value
: 1 - Math.pow(-2 * value + 2, 3) / 2;
function cross2(ax, ay, bx, by) {
return ax * by - ay * bx;
}
function intersectRails(railA, railB) {
const directionA = {
x: Math.cos(railA.rotation.z),
y: Math.sin(railA.rotation.z)
};
const directionB = {
x: Math.cos(railB.rotation.z),
y: Math.sin(railB.rotation.z)
};
const difference = {
x: railB.position.x - railA.position.x,
y: railB.position.y - railA.position.y
};
const denominator = cross2(
directionA.x,
directionA.y,
directionB.x,
directionB.y
);
if (Math.abs(denominator) < 0.00001) {
return {
x: (railA.position.x + railB.position.x) * 0.5,
y: (railA.position.y + railB.position.y) * 0.5
};
}
const amount = cross2(
difference.x,
difference.y,
directionB.x,
directionB.y
) / denominator;
return {
x: railA.position.x + directionA.x * amount,
y: railA.position.y + directionA.y * amount
};
}
function distance2D(a, b) {
return Math.hypot(b.x - a.x, b.y - a.y);
}
function getFrameCorners() {
const top = rails.find((rail) => rail.userData.kind === "top");
const bottom = rails.find((rail) => rail.userData.kind === "bottom");
const left = rails.find((rail) => rail.userData.kind === "left");
const right = rails.find((rail) => rail.userData.kind === "right");
return {
topLeft: intersectRails(top, left),
topRight: intersectRails(top, right),
bottomRight: intersectRails(bottom, right),
bottomLeft: intersectRails(bottom, left)
};
}
function getCornerAngle(corners) {
const first = {
x: corners.topRight.x - corners.topLeft.x,
y: corners.topRight.y - corners.topLeft.y
};
const second = {
x: corners.bottomLeft.x - corners.topLeft.x,
y: corners.bottomLeft.y - corners.topLeft.y
};
const firstLength = Math.hypot(first.x, first.y);
const secondLength = Math.hypot(second.x, second.y);
if (!firstLength || !secondLength) {
return NaN;
}
const cosine = clamp01(
(first.x * second.x + first.y * second.y) /
(firstLength * secondLength)
);
return THREE.MathUtils.radToDeg(Math.acos(cosine));
}
// Direct camera controls: no examples/addons modules are used.
const orbit = {
theta: 0.57,
phi: 1.13,
radius: window.innerWidth < 700 ? 18.5 : 15.6,
target: new THREE.Vector3(0, -0.15, 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.theta = 0.57;
orbit.phi = 1.13;
orbit.radius = window.innerWidth < 700 ? 18.5 : 15.6;
updateCamera();
}
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
orbit.theta -= deltaX * 0.0055;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - deltaY * 0.0045,
0.42,
1.5
);
previousPointerX = event.clientX;
previousPointerY = event.clientY;
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
9.5,
24
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
resetButton.addEventListener("click", resetCamera);
const ASSEMBLY_DURATION = 4.8;
let assemblyStart = performance.now();
replayButton.addEventListener("click", () => {
assemblyStart = performance.now();
statusDot.classList.remove("done");
});
function setAssemblyPose() {
for (const rail of rails) {
rail.position.copy(rail.userData.startPosition);
rail.rotation.z = rail.userData.startRotation;
}
for (const guide of guides) {
guide.position.copy(guide.userData.startPosition);
guide.rotation.z = guide.userData.startRotation;
}
for (const clamp of clamps) {
clamp.position.copy(clamp.userData.startPosition);
clamp.rotation.z = clamp.userData.startRotation;
clamp.userData.upperJaw.position.y = 0.62;
clamp.userData.lowerJaw.position.y = -0.62;
clamp.userData.handle.rotation.y = -Math.PI * 1.5;
}
}
setAssemblyPose();
function animate(now) {
const elapsed = (now - assemblyStart) / 1000;
const overallProgress = clamp01(elapsed / ASSEMBLY_DURATION);
// Rails glide and rotate into their final rectangular positions.
for (const rail of rails) {
const localProgress = easeInOutCubic(
clamp01((elapsed - rail.userData.delay) / 3.05)
);
rail.position.lerpVectors(
rail.userData.startPosition,
rail.userData.finalPosition,
localProgress
);
rail.rotation.z = THREE.MathUtils.lerp(
rail.userData.startRotation,
rail.userData.finalRotation,
localProgress
);
}
// Corner guides settle after the rails are nearly aligned.
for (const guide of guides) {
const localProgress = easeInOutCubic(
clamp01((elapsed - guide.userData.delay) / 2.0)
);
guide.position.lerpVectors(
guide.userData.startPosition,
guide.userData.finalPosition,
localProgress
);
guide.rotation.z = THREE.MathUtils.lerp(
guide.userData.startRotation,
guide.userData.finalRotation,
localProgress
);
}
// Clamps approach, rotate into place, and close their padded jaws.
for (const clamp of clamps) {
const localProgress = easeInOutCubic(
clamp01((elapsed - clamp.userData.delay) / 2.2)
);
clamp.position.lerpVectors(
clamp.userData.startPosition,
clamp.userData.finalPosition,
localProgress
);
clamp.rotation.z = THREE.MathUtils.lerp(
clamp.userData.startRotation,
clamp.userData.finalRotation,
localProgress
);
const tightening = easeInOutCubic(
clamp01((localProgress - 0.36) / 0.64)
);
clamp.userData.upperJaw.position.y = THREE.MathUtils.lerp(
0.62,
0.39,
tightening
);
clamp.userData.lowerJaw.position.y = THREE.MathUtils.lerp(
-0.62,
-0.39,
tightening
);
clamp.userData.handle.rotation.y = THREE.MathUtils.lerp(
-Math.PI * 1.5,
0,
tightening
);
}
// The diagonals continuously connect the current rail intersections.
const corners = getFrameCorners();
updateDiagonal(diagonalA, corners.topLeft, corners.bottomRight);
updateDiagonal(diagonalB, corners.topRight, corners.bottomLeft);
endpoints[0].position.set(corners.topLeft.x, corners.topLeft.y, 0.62);
endpoints[1].position.set(corners.topRight.x, corners.topRight.y, 0.62);
endpoints[2].position.set(corners.bottomRight.x, corners.bottomRight.y, 0.62);
endpoints[3].position.set(corners.bottomLeft.x, corners.bottomLeft.y, 0.62);
centerMarker.position.set(
(corners.topLeft.x + corners.bottomRight.x) * 0.5,
(corners.topLeft.y + corners.bottomRight.y) * 0.5,
0.66
);
const diagonalOne = distance2D(corners.topLeft, corners.bottomRight);
const diagonalTwo = distance2D(corners.topRight, corners.bottomLeft);
const averageDiagonal =
(diagonalOne + diagonalTwo) * 0.5 || 1;
const diagonalDelta =
(Math.abs(diagonalOne - diagonalTwo) / averageDiagonal) * 100;
const angle = getCornerAngle(corners);
const completed = elapsed >= ASSEMBLY_DURATION;
const pulse = completed
? 0.72 + Math.sin(now * 0.0025) * 0.07
: 0.55 + overallProgress * 0.12;
diagonalMaterials[0].opacity = pulse;
diagonalMaterials[1].opacity = pulse;
centerMarker.rotation.y = now * 0.0012;
progressFill.style.width = `${(overallProgress * 100).toFixed(1)}%`;
progressText.textContent = `${Math.round(overallProgress * 100)}%`;
angleValue.textContent = Number.isFinite(angle)
? `${angle.toFixed(1)}°`
: "—";
deltaValue.textContent = `${diagonalDelta.toFixed(2)}%`;
if (completed) {
statusText.textContent = "Rectangle verified";
statusDot.classList.add("done");
} else if (elapsed < 1.25) {
statusText.textContent = "Rails approaching";
} else if (elapsed < 2.35) {
statusText.textContent = "Guides seating";
} else if (elapsed < 4.65) {
statusText.textContent = "Protective pads closing";
} else {
statusText.textContent = "Verifying squareness";
}
renderer.render(scene, camera);
}
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
camera.aspect = width / height;
camera.fov = width < 700 ? 48 : 42;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height, false);
}
window.addEventListener("resize", resize);
resize();
updateCamera();
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
loading.classList.add("hidden");
});
</script>
</body>
</html>
```