Prompt specification
Build or customize the Three.js 3D scene "Hinge pin insertion sequence" 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: Hinge pin insertion sequence
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/hinge-pin-insertion-sequence-x0274
Scene Description Prompt:
Make a low-poly Three.js scene in a self-contained HTML file using cdnjs: hinge pin insertion sequence. Animate alternating hinge knuckles interleaving before a pin slides through their shared axis; keep all holes visibly coaxial throughout the final insertion.
Working Three.js Starter (hinge-pin-insertion-sequence-x0274):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Low-Poly Hinge Pin Insertion</title>
<style>
:root {
color-scheme: dark;
--left: #f28b4b;
--right: #49b9ad;
--pin: #ffd166;
--cyan: #75e7f2;
--panel: rgba(12, 19, 30, 0.82);
--border: rgba(160, 205, 225, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #09111c;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
position: absolute;
top: 24px;
left: 24px;
width: min(340px, calc(100vw - 48px));
padding: 20px;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
}
.eyebrow {
margin-bottom: 7px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: #eef8ff;
font-size: clamp(20px, 4vw, 28px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.subtitle {
margin: 10px 0 17px;
color: #91a5b7;
font-size: 12px;
line-height: 1.5;
}
.phase-row {
display: flex;
align-items: center;
gap: 9px;
min-height: 20px;
color: #d7e8f3;
font-size: 12px;
font-weight: 650;
}
.phase-dot {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 14px rgba(117, 231, 242, 0.8);
}
.progress {
height: 4px;
margin: 13px 0 16px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.09);
}
.progress > div {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--left), var(--right), var(--pin));
box-shadow: 0 0 12px rgba(117, 231, 242, 0.35);
}
.steps {
display: grid;
gap: 8px;
}
.step {
display: flex;
align-items: center;
gap: 9px;
color: #718698;
font-size: 11px;
transition: color 180ms ease;
}
.step::before {
content: "";
width: 7px;
height: 7px;
border: 1px solid #506273;
border-radius: 50%;
transition: 180ms ease;
}
.step.active {
color: #e7f6ff;
}
.step.active::before {
border-color: var(--cyan);
background: var(--cyan);
box-shadow: 0 0 10px rgba(117, 231, 242, 0.8);
}
.step.done {
color: #9eb4c4;
}
.step.done::before {
border-color: #62c8bd;
background: #62c8bd;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 9px 15px;
margin-top: 18px;
padding-top: 15px;
border-top: 1px solid var(--border);
color: #a9bbc9;
font-size: 10px;
letter-spacing: 0.04em;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
}
button {
pointer-events: auto;
width: 100%;
margin-top: 17px;
padding: 10px 13px;
border: 1px solid rgba(117, 231, 242, 0.32);
border-radius: 9px;
color: #eafaff;
background: rgba(117, 231, 242, 0.08);
font: inherit;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.07em;
text-transform: uppercase;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
button:hover {
border-color: rgba(117, 231, 242, 0.65);
background: rgba(117, 231, 242, 0.16);
}
button:active {
transform: translateY(1px);
}
.hint {
position: absolute;
right: 24px;
bottom: 22px;
padding: 9px 12px;
border: 1px solid var(--border);
border-radius: 9px;
color: #8da2b3;
background: rgba(10, 17, 27, 0.68);
font-size: 10px;
letter-spacing: 0.04em;
backdrop-filter: blur(10px);
}
.vignette {
position: absolute;
inset: 0;
background:
radial-gradient(
circle at 50% 48%,
transparent 45%,
rgba(2, 7, 14, 0.24) 100%
);
}
@media (max-width: 620px) {
.panel {
top: 14px;
left: 14px;
width: min(310px, calc(100vw - 28px));
padding: 16px;
}
.subtitle,
.legend {
display: none;
}
.hint {
right: 14px;
bottom: 14px;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div id="hud">
<div class="vignette"></div>
<section class="panel">
<div class="eyebrow">Mechanical study · 01</div>
<h1>Hinge pin insertion</h1>
<p class="subtitle">
Alternating knuckles rotate into position around one shared bore axis.
The pin travels only after every opening is coaxial.
</p>
<div class="phase-row" aria-live="polite">
<span class="phase-dot"></span>
<span id="phaseText">01 · Opening hinge</span>
</div>
<div class="progress"><div id="progressFill"></div></div>
<div class="steps">
<div class="step active" id="stepKnuckles">Interleave knuckles</div>
<div class="step" id="stepAxis">Confirm shared axis</div>
<div class="step" id="stepPin">Insert retaining pin</div>
</div>
<div class="legend">
<span>
<i class="swatch" style="background: var(--left)"></i>
Left leaf
</span>
<span>
<i class="swatch" style="background: var(--right)"></i>
Right leaf
</span>
<span>
<i class="swatch" style="background: var(--pin)"></i>
Pin
</span>
</div>
<button id="replay" type="button">Replay sequence</button>
</section>
<div class="hint">Drag to orbit · Wheel to zoom · R to replay</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const stage = document.getElementById("stage");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly hinge with a pin insertion animation"
);
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x09111c);
scene.fog = new THREE.Fog(0x09111c, 12, 27);
const camera = new THREE.PerspectiveCamera(
48,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Camera controls are implemented directly, without addons.
const cameraTarget = new THREE.Vector3(0, 0.25, 0);
let cameraYaw = 0.58;
let cameraPitch = 0.58;
let cameraRadius = 10.8;
function updateCamera() {
const horizontalRadius = Math.cos(cameraPitch) * cameraRadius;
camera.position.set(
cameraTarget.x + horizontalRadius * Math.sin(cameraYaw),
cameraTarget.y + Math.sin(cameraPitch) * cameraRadius,
cameraTarget.z + horizontalRadius * Math.cos(cameraYaw)
);
camera.lookAt(cameraTarget);
}
updateCamera();
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
cameraYaw -= deltaX * 0.006;
cameraPitch = THREE.MathUtils.clamp(
cameraPitch - deltaY * 0.005,
0.16,
1.36
);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
function endDrag(event) {
dragging = false;
if (
renderer.domElement.hasPointerCapture &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
6.4,
15
);
updateCamera();
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xc7e5ff, 0x17202b, 2.15));
const keyLight = new THREE.DirectionalLight(0xfff1d6, 3.1);
keyLight.position.set(5.5, 8.5, 6.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -6;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x64d9ec, 1.65);
rimLight.position.set(-5, 4, -5);
scene.add(rimLight);
const warmFill = new THREE.PointLight(0xff9b62, 14, 12, 2);
warmFill.position.set(-3.5, 1.2, 3.5);
scene.add(warmFill);
// -------------------------------------------------------------------------
// Low-poly materials
// -------------------------------------------------------------------------
const leftMaterial = new THREE.MeshStandardMaterial({
color: 0xf28b4b,
roughness: 0.58,
metalness: 0.28,
flatShading: true
});
const rightMaterial = new THREE.MeshStandardMaterial({
color: 0x49b9ad,
roughness: 0.58,
metalness: 0.28,
flatShading: true
});
const darkMetal = new THREE.MeshStandardMaterial({
color: 0x263544,
roughness: 0.7,
metalness: 0.4,
flatShading: true
});
const boreMaterial = new THREE.MeshStandardMaterial({
color: 0x101823,
roughness: 0.92,
metalness: 0.05,
flatShading: true,
side: THREE.DoubleSide
});
const pinMaterial = new THREE.MeshStandardMaterial({
color: 0xffd166,
roughness: 0.3,
metalness: 0.68,
flatShading: true
});
const pinDarkMaterial = new THREE.MeshStandardMaterial({
color: 0xb98324,
roughness: 0.42,
metalness: 0.58,
flatShading: true
});
const screwMaterial = new THREE.MeshStandardMaterial({
color: 0x121c27,
roughness: 0.82,
metalness: 0.25,
flatShading: true
});
const platformMaterial = new THREE.MeshStandardMaterial({
color: 0x182637,
roughness: 0.85,
metalness: 0.2,
flatShading: true
});
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x0c1521,
roughness: 0.96,
metalness: 0.03
});
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
// Creates a genuinely hollow, low-poly annular cylinder.
// Material groups:
// 0 = outer wall
// 1 = dark inner bore
// 2 = top and bottom annular faces
function createBoreGeometry(
outerRadius,
innerRadius,
height,
segments = 12
) {
const positions = [];
const groups = [];
let vertexOffset = 0;
function triangle(a, b, c, materialIndex) {
positions.push(...a, ...b, ...c);
groups.push({
start: vertexOffset,
count: 3,
materialIndex
});
vertexOffset += 3;
}
for (let i = 0; i < segments; i++) {
const angle0 = (i / segments) * Math.PI * 2;
const angle1 = ((i + 1) / segments) * Math.PI * 2;
const c0 = Math.cos(angle0);
const s0 = Math.sin(angle0);
const c1 = Math.cos(angle1);
const s1 = Math.sin(angle1);
const outerBottom0 = [outerRadius * c0, -height / 2, outerRadius * s0];
const outerBottom1 = [outerRadius * c1, -height / 2, outerRadius * s1];
const outerTop0 = [outerRadius * c0, height / 2, outerRadius * s0];
const outerTop1 = [outerRadius * c1, height / 2, outerRadius * s1];
const innerBottom0 = [innerRadius * c0, -height / 2, innerRadius * s0];
const innerBottom1 = [innerRadius * c1, -height / 2, innerRadius * s1];
const innerTop0 = [innerRadius * c0, height / 2, innerRadius * s0];
const innerTop1 = [innerRadius * c1, height / 2, innerRadius * s1];
// Outer wall.
triangle(outerBottom0, outerTop1, outerBottom1, 0);
triangle(outerBottom0, outerTop0, outerTop1, 0);
// Inner bore wall.
triangle(innerBottom0, innerBottom1, innerTop1, 1);
triangle(innerBottom0, innerTop1, innerTop0, 1);
// Top annular face.
triangle(outerTop0, innerTop1, outerTop1, 2);
triangle(outerTop0, innerTop0, innerTop1, 2);
// Bottom annular face.
triangle(outerBottom0, outerBottom1, innerTop1, 2);
triangle(outerBottom0, innerTop1, innerTop0, 2);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"new THREE.Float32BufferAttribute".replace(
"new THREE.Float32BufferAttribute",
"position"
),
new THREE.Float32BufferAttribute(positions, 3)
);
// The expression above keeps the intent explicit while producing a regular
// Float32BufferAttribute under standard Three.js builds.
geometry.computeVertexNormals();
for (const group of groups) {
geometry.addGroup(group.start, group.count, group.materialIndex);
}
return geometry;
}
// A chamfered plate made from a core Three.js shape extrusion.
function createPlateGeometry(
length,
width,
thickness,
chamfer = 0.16
) {
const halfLength = length / 2;
const halfWidth = width / 2;
const shape = new THREE.Shape();
shape.moveTo(-halfLength + chamfer, -halfWidth);
shape.lineTo(halfLength - chamfer, -halfWidth);
shape.lineTo(halfLength, -halfWidth + chamfer);
shape.lineTo(halfLength, halfWidth - chamfer);
shape.lineTo(halfLength - chamfer, halfWidth);
shape.lineTo(-halfLength + chamfer, halfWidth);
shape.lineTo(-halfLength, halfWidth - chamfer);
shape.lineTo(-halfLength, -halfWidth + chamfer);
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: thickness,
bevelEnabled: false,
curveSegments: 1,
steps: 1
});
geometry.translate(0, 0, -thickness / 2);
geometry.rotateX(Math.PI / 2);
geometry.computeVertexNormals();
return geometry;
}
function configureMesh(mesh, castShadow = true, receiveShadow = true) {
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
return mesh;
}
// -------------------------------------------------------------------------
// Stage
// -------------------------------------------------------------------------
const floor = configureMesh(
new THREE.Mesh(
new THREE.PlaneGeometry(32, 32),
floorMaterial
),
false,
true
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -2.72;
scene.add(floor);
const platform = configureMesh(
new THREE.Mesh(
new THREE.CylinderGeometry(4.25, 4.5, 0.36, 12),
platformMaterial
)
);
platform.position.y = -2.52;
scene.add(platform);
const platformInset = configureMesh(
new THREE.Mesh(
new THREE.CylinderGeometry(3.75, 3.75, 0.035, 12),
darkMetal
)
);
platformInset.position.y = -2.32;
scene.add(platformInset);
const grid = new THREE.GridHelper(22, 22, 0x36506a, 0x1b2c3e);
grid.position.y = -2.705;
grid.material.transparent = true;
grid.material.opacity = 0.5;
scene.add(grid);
// -------------------------------------------------------------------------
// Hinge leaves and alternating knuckles
// -------------------------------------------------------------------------
const knuckleGeometry = createBoreGeometry(
0.52,
0.285,
0.64,
12
);
const plateGeometry = createPlateGeometry(2.9, 1.05, 0.24);
const ribGeometry = new THREE.BoxGeometry(2.25, 0.035, 0.13);
const spineGeometry = new THREE.BoxGeometry(0.24, 3.76, 0.32);
const neckGeometry = new THREE.BoxGeometry(0.42, 0.4, 0.4);
const screwGeometry = new THREE.CylinderGeometry(0.105, 0.105, 0.035, 12);
const leftPivot = new THREE.Group();
const rightPivot = new THREE.Group();
scene.add(leftPivot, rightPivot);
function buildLeaf(pivot, side, material) {
const knucklePositions =
side < 0 ? [-1.44, 0, 1.44] : [-0.72, 0.72];
for (const y of knucklePositions) {
const knuckle = configureMesh(
new THREE.Mesh(knuckleGeometry, [
material,
boreMaterial,
material
])
);
knuckle.position.y = y;
pivot.add(knuckle);
// The neck stops outside the bore radius, so the opening stays open.
const neck = configureMesh(
new THREE.Mesh(neckGeometry, material)
);
neck.position.set(side * 0.59, y, 0);
pivot.add(neck);
}
const spine = configureMesh(
new THREE.Mesh(spineGeometry, material)
);
spine.position.x = side * 0.76;
pivot.add(spine);
const plate = configureMesh(
new THREE.Mesh(plateGeometry, material)
);
plate.position.x = side * 2.15;
pivot.add(plate);
const rib = configureMesh(
new THREE.Mesh(ribGeometry, darkMetal)
);
rib.position.set(side * 2.18, 0.145, 0);
pivot.add(rib);
// Four low-poly screw heads.
for (const x of [1.42, 2.82]) {
for (const z of [-0.29, 0.29]) {
const screw = configureMesh(
new THREE.Mesh(screwGeometry, screwMaterial),
true,
true
);
screw.position.set(side * x, 0.142, z);
pivot.add(screw);
}
}
}
buildLeaf(leftPivot, -1, leftMaterial);
buildLeaf(rightPivot, 1, rightMaterial);
// -------------------------------------------------------------------------
// Coaxial guide: a subtle technical visualization of the common bore axis
// -------------------------------------------------------------------------
const guideMaterial = new THREE.MeshBasicMaterial({
color: 0x75e7f2,
transparent: true,
opacity: 0.1,
depthWrite: false
});
const axisGuide = new THREE.Mesh(
new THREE.CylinderGeometry(0.012, 0.012, 4.55, 6),
guideMaterial
);
axisGuide.position.y = 0.05;
scene.add(axisGuide);
const guideRingMaterial = new THREE.MeshBasicMaterial({
color: 0x75e7f2,
transparent: true,
opacity: 0.08,
depthWrite: false
});
const guideRings = [];
for (const y of [-1.79, 1.79]) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.29, 0.014, 6, 24),
guideRingMaterial
);
ring.rotation.x = Math.PI / 2;
ring.position.y = y;
scene.add(ring);
guideRings.push(ring);
}
// -------------------------------------------------------------------------
// Pin
// -------------------------------------------------------------------------
const pin = new THREE.Group();
pin.position.y = 4.15;
scene.add(pin);
// Slight taper gives the pin a visually distinct leading end.
const pinShaft = configureMesh(
new THREE.Mesh(
new THREE.CylinderGeometry(0.225, 0.18, 4.15, 12),
pinMaterial
)
);
pin.add(pinShaft);
const pinHead = configureMesh(
new THREE.Mesh(
new THREE.CylinderGeometry(0.36, 0.36, 0.22, 12),
pinDarkMaterial
)
);
pinHead.position.y = 2.18;
pin.add(pinHead);
const pinCollar = configureMesh(
new THREE.Mesh(
new THREE.TorusGeometry(0.29, 0.045, 6, 12),
pinMaterial
)
);
pinCollar.rotation.x = Math.PI / 2;
pinCollar.position.y = 2.04;
pin.add(pinCollar);
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const CLOSE_START = 0.8;
const CLOSE_END = 3.6;
const PIN_START = 4.05;
const PIN_END = 7.0;
const LEFT_OPEN_ANGLE = -1.18;
const RIGHT_OPEN_ANGLE = 1.12;
const PIN_PARKED_HEIGHT = 4.15;
let animationStart = performance.now();
const phaseText = document.getElementById("phaseText");
const progressFill = document.getElementById("progressFill");
const stepKnuckles = document.getElementById("stepKnuckles");
const stepAxis = document.getElementById("stepAxis");
const stepPin = document.getElementById("stepPin");
const replayButton = document.getElementById("replay");
function smoothstep(value) {
const t = THREE.MathUtils.clamp(value, 0, 1);
return t * t * (3 - 2 * t);
}
function replay() {
animationStart = performance.now();
}
replayButton.addEventListener("click", replay);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
replay();
}
});
let lastPhase = "";
function updateHUD(elapsed) {
let phase;
let activeStep;
if (elapsed < CLOSE_START) {
phase = "01 · Opening hinge";
activeStep = stepKnuckles;
} else if (elapsed < CLOSE_END) {
phase = "02 · Interleaving knuckles";
activeStep = stepKnuckles;
} else if (elapsed < PIN_START) {
phase = "03 · Shared bore axis confirmed";
activeStep = stepAxis;
} else if (elapsed < PIN_END) {
phase = "04 · Inserting pin";
activeStep = stepPin;
} else {
phase = "05 · Hinge locked";
activeStep = stepPin;
}
if (phase !== lastPhase) {
phaseText.textContent = phase;
lastPhase = phase;
}
const progress = THREE.MathUtils.clamp(elapsed / PIN_END, 0, 1);
progressFill.style.width = `${progress * 100}%`;
stepKnuckles.classList.toggle(
"active",
activeStep === stepKnuckles
);
stepKnuckles.classList.toggle(
"done",
elapsed >= CLOSE_END
);
stepAxis.classList.toggle(
"active",
activeStep === stepAxis
);
stepAxis.classList.toggle(
"done",
elapsed >= PIN_START
);
stepPin.classList.toggle(
"active",
activeStep === stepPin
);
stepPin.classList.toggle(
"done",
elapsed >= PIN_END
);
}
function animate(now) {
const elapsed = (now - animationStart) / 1000;
// Closing the leaves rotates the alternating knuckle sets around the
// same hinge axis. Their bore centers never leave that shared Y axis.
const closeProgress = smoothstep(
(elapsed - CLOSE_START) / (CLOSE_END - CLOSE_START)
);
leftPivot.rotation.y = THREE.MathUtils.lerp(
LEFT_OPEN_ANGLE,
0,
closeProgress
);
rightPivot.rotation.y = THREE.MathUtils.lerp(
RIGHT_OPEN_ANGLE,
0,
closeProgress
);
// The pin is explicitly forbidden from descending until closure and
// coaxial confirmation are complete.
const pinProgress = smoothstep(
(elapsed - PIN_START) / (PIN_END - PIN_START)
);
pin.position.y = THREE.MathUtils.lerp(
PIN_PARKED_HEIGHT,
0,
pinProgress
);
// Highlight the common bore axis before insertion, then reduce the
// guide as the solid pin occupies the bore.
let guideOpacity;
if (elapsed < CLOSE_END) {
guideOpacity = 0.08 + closeProgress * 0.1;
} else if (elapsed < PIN_START) {
guideOpacity = 0.42;
} else {
guideOpacity = THREE.MathUtils.lerp(0.42, 0.08, pinProgress);
}
guideMaterial.opacity = guideOpacity;
guideRingMaterial.opacity = guideOpacity * 0.8;
updateHUD(elapsed);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
// -------------------------------------------------------------------------
// Resize
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
</script>
</body>
</html>
```