Prompt specification
Build or customize the Three.js 3D scene "Ratchet Pawl Release Lever Assembly" 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: Ratchet Pawl Release Lever Assembly
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/ratchet-pawl-release-lever-assembly-x2053
Scene Description Prompt:
Show a low-poly ratchet's release lever lifting its hinged pawl, creating clearance for reverse rotation. One HTML file using Three.js from cdnjs.
Working Three.js Starter (ratchet-pawl-release-lever-assembly-x2053):
```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 Ratchet Release</title>
<style>
:root {
--accent: #ffb84d;
--panel: rgba(10, 18, 30, 0.82);
--border: rgba(255, 255, 255, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #08111e;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: #eef7ff;
}
canvas {
display: block;
touch-action: none;
}
#vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 45%, transparent 42%, rgba(0, 0, 0, 0.42) 100%);
z-index: 2;
}
#resetFade {
position: fixed;
inset: 0;
pointer-events: none;
background: #08111e;
opacity: 0;
z-index: 5;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 6;
}
header {
position: absolute;
top: 24px;
left: 26px;
max-width: min(440px, calc(100vw - 52px));
}
.eyebrow {
margin-bottom: 8px;
color: #8da4bb;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 4vw, 38px);
line-height: 1.03;
letter-spacing: -0.04em;
}
header p {
max-width: 410px;
margin: 12px 0 0;
color: #a9bacb;
font-size: 13px;
line-height: 1.55;
}
#status {
position: absolute;
top: 25px;
right: 25px;
display: flex;
align-items: center;
gap: 10px;
padding: 10px 14px;
border: 1px solid var(--border);
border-radius: 999px;
background: var(--panel);
backdrop-filter: blur(12px);
color: #dce9f5;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.13em;
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.22);
}
#statusDot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 14px var(--accent);
}
.panel {
position: absolute;
left: 50%;
bottom: 22px;
width: min(760px, calc(100vw - 32px));
transform: translateX(-50%);
display: grid;
grid-template-columns: 1fr auto;
gap: 18px;
align-items: center;
padding: 14px 16px;
border: 1px solid var(--border);
border-radius: 18px;
background: var(--panel);
backdrop-filter: blur(16px);
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
pointer-events: auto;
}
.steps {
display: flex;
gap: 16px;
align-items: center;
min-width: 0;
}
.step {
display: flex;
align-items: center;
gap: 7px;
color: #64798e;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
white-space: nowrap;
transition: color 180ms ease;
}
.step::before {
content: "";
width: 8px;
height: 8px;
border: 1px solid currentColor;
border-radius: 50%;
}
.step.active {
color: var(--accent);
}
.step.active::before {
background: var(--accent);
box-shadow: 0 0 12px var(--accent);
}
#progressTrack {
height: 3px;
margin-top: 11px;
overflow: hidden;
border-radius: 3px;
background: rgba(255, 255, 255, 0.09);
}
#progressBar {
width: 0;
height: 100%;
border-radius: inherit;
background: var(--accent);
box-shadow: 0 0 10px var(--accent);
}
button {
border: 0;
border-radius: 11px;
padding: 12px 16px;
background: var(--accent);
color: #17202c;
font: inherit;
font-size: 12px;
font-weight: 900;
letter-spacing: 0.04em;
cursor: pointer;
box-shadow: 0 8px 25px rgba(255, 184, 77, 0.18);
transition: transform 150ms ease, filter 150ms ease;
}
button:hover {
filter: brightness(1.08);
transform: translateY(-1px);
}
button:active {
transform: translateY(1px);
}
.tag {
position: fixed;
z-index: 7;
padding: 7px 10px;
transform: translate(-50%, -50%);
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 8px;
background: rgba(7, 15, 26, 0.82);
color: #dbe9f7;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.13em;
white-space: nowrap;
pointer-events: none;
opacity: 0;
transition: opacity 160ms ease;
backdrop-filter: blur(8px);
}
#gapTag {
color: #ffd48d;
border-color: rgba(255, 184, 77, 0.4);
}
.help {
position: absolute;
right: 25px;
bottom: 102px;
color: #71869a;
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 700px) {
header {
top: 17px;
left: 18px;
}
header p {
display: none;
}
#status {
top: 16px;
right: 16px;
}
.panel {
grid-template-columns: 1fr;
gap: 10px;
bottom: 12px;
}
.steps {
justify-content: space-between;
gap: 8px;
}
.step {
font-size: 8px;
letter-spacing: 0.04em;
}
button {
width: 100%;
}
.help {
display: none;
}
}
</style>
</head>
<body>
<div id="vignette"></div>
<div id="resetFade"></div>
<div class="hud">
<header>
<div class="eyebrow">Mechanical study · Low-poly assembly</div>
<h1>Ratchet Release Lever</h1>
<p>
The reverse load catches against the hinged pawl. Lifting the release lever
raises the pawl from the tooth and gives the wheel clearance to rotate freely.
</p>
</header>
<div id="status">
<span id="statusDot"></span>
<span id="statusText">REVERSE BLOCKED</span>
</div>
<div id="leverTag" class="tag">RELEASE LEVER</div>
<div id="pawlTag" class="tag">HINGED PAWL</div>
<div id="gapTag" class="tag">PAWL CLEARANCE</div>
<div class="help">Drag to orbit · Scroll to zoom · Click the lever</div>
<div class="panel">
<div>
<div class="steps">
<div id="step1" class="step active">1 · BLOCKED</div>
<div id="step2" class="step">2 · LIFT PAWL</div>
<div id="step3" class="step">3 · REVERSE</div>
</div>
<div id="progressTrack"><div id="progressBar"></div></div>
</div>
<button id="replay" type="button">REPLAY CYCLE</button>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x08111e);
scene.fog = new THREE.Fog(0x08111e, 13, 24);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const target = new THREE.Vector3(0.55, -0.05, 0);
let cameraTheta = 0.58;
let cameraPhi = 1.08;
let cameraRadius = 11.7;
function updateCamera() {
cameraPhi = THREE.MathUtils.clamp(cameraPhi, 0.55, 1.48);
cameraRadius = THREE.MathUtils.clamp(cameraRadius, 7.3, 17);
camera.position.set(
target.x + cameraRadius * Math.sin(cameraPhi) * Math.sin(cameraTheta),
target.y + cameraRadius * Math.cos(cameraPhi),
target.z + cameraRadius * Math.sin(cameraPhi) * Math.cos(cameraTheta)
);
camera.lookAt(target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xbad8ff, 0x182333, 1.65);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff1d6, 4.2);
keyLight.position.set(5, 8, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -6;
keyLight.shadow.bias = -0.0008;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x4fc8ff, 2.4);
rimLight.position.set(-5, 3, -6);
scene.add(rimLight);
const fillLight = new THREE.PointLight(0xffb84d, 12, 12, 2);
fillLight.position.set(4, 1, 4);
scene.add(fillLight);
const materials = {
frame: new THREE.MeshStandardMaterial({
color: 0x23384c,
roughness: 0.62,
metalness: 0.72,
flatShading: true
}),
dark: new THREE.MeshStandardMaterial({
color: 0x101b29,
roughness: 0.58,
metalness: 0.78,
flatShading: true
}),
steel: new THREE.MeshStandardMaterial({
color: 0x8fa9bd,
roughness: 0.3,
metalness: 0.9,
flatShading: true
}),
gear: new THREE.MeshStandardMaterial({
color: 0x45c6c8,
roughness: 0.34,
metalness: 0.78,
flatShading: true
}),
gearSide: new THREE.MeshStandardMaterial({
color: 0x167d88,
roughness: 0.43,
metalness: 0.72,
flatShading: true
}),
pawl: new THREE.MeshStandardMaterial({
color: 0xffb84d,
roughness: 0.35,
metalness: 0.67,
flatShading: true
}),
lever: new THREE.MeshStandardMaterial({
color: 0xff6f4e,
roughness: 0.42,
metalness: 0.5,
flatShading: true
}),
grip: new THREE.MeshStandardMaterial({
color: 0x172231,
roughness: 0.9,
metalness: 0.05,
flatShading: true
})
};
// -------------------------------------------------------------------------
// Helpers
// -------------------------------------------------------------------------
function polar(radius, angle) {
return new THREE.Vector2(
radius * Math.cos(angle),
radius * Math.sin(angle)
);
}
function extrudedShape(shape, depth, frontMaterial, sideMaterial = frontMaterial) {
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
bevelEnabled: true,
bevelSegments: 1,
bevelSize: 0.035,
bevelThickness: 0.025,
curveSegments: 1,
steps: 1
});
geometry.translate(0, 0, -depth / 2);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, [frontMaterial, sideMaterial]);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function makeBeam(start, end, radius, material, segments = 6) {
const direction = new THREE.Vector3().subVectors(end, start);
const geometry = new THREE.CylinderGeometry(
radius,
radius,
direction.length(),
segments
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function makeAxleCylinder(radius, depth, material, radialSegments = 12) {
const geometry = new THREE.CylinderGeometry(
radius,
radius,
depth,
radialSegments
);
geometry.rotateX(Math.PI / 2);
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
// -------------------------------------------------------------------------
// Base and support frame
// -------------------------------------------------------------------------
const base = new THREE.Mesh(
new THREE.BoxGeometry(7.8, 0.28, 2.8),
materials.dark
);
base.position.set(0.25, -2.28, -0.15);
base.castShadow = true;
base.receiveShadow = true;
scene.add(base);
const baseInset = new THREE.Mesh(
new THREE.BoxGeometry(7.2, 0.08, 2.25),
materials.frame
);
baseInset.position.set(0.25, -2.1, -0.15);
baseInset.receiveShadow = true;
scene.add(baseInset);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0x091522,
roughness: 0.92,
metalness: 0.08
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -2.44;
ground.receiveShadow = true;
scene.add(ground);
const axleSupportTop = new THREE.Vector3(0, 0, -0.72);
const axleSupportBottom = new THREE.Vector3(0, -2.04, -0.72);
scene.add(makeBeam(axleSupportBottom, axleSupportTop, 0.22, materials.frame));
const pawlSupportTop = new THREE.Vector3(2.25, 1.72, -0.72);
const pawlSupportBottom = new THREE.Vector3(3.12, -2.04, -0.72);
scene.add(makeBeam(pawlSupportBottom, pawlSupportTop, 0.16, materials.frame));
const leverSupportTop = new THREE.Vector3(3.4, 1.75, -0.72);
const leverSupportBottom = new THREE.Vector3(3.65, -2.04, -0.72);
scene.add(makeBeam(leverSupportBottom, leverSupportTop, 0.16, materials.frame));
const rearCrossbar = makeBeam(
new THREE.Vector3(-0.85, -2.04, -0.72),
new THREE.Vector3(3.8, -2.04, -0.72),
0.13,
materials.frame
);
scene.add(rearCrossbar);
// -------------------------------------------------------------------------
// Low-poly ratchet wheel
// -------------------------------------------------------------------------
const wheel = new THREE.Group();
scene.add(wheel);
const toothCount = 12;
const toothStep = (Math.PI * 2) / toothCount;
const rootRadius = 1.57;
const tipRadius = 1.94;
const gearShape = new THREE.Shape();
for (let i = 0; i < toothCount; i++) {
const a = (i + 0.5) * toothStep;
const points = [
polar(rootRadius, a),
polar(rootRadius, a + toothStep * 0.12),
polar(tipRadius, a + toothStep * 0.25),
polar(tipRadius, a + toothStep * 0.38),
polar(rootRadius, a + toothStep * 0.38)
];
points.forEach((point, index) => {
if (i === 0 && index === 0) {
gearShape.moveTo(point.x, point.y);
} else {
gearShape.lineTo(point.x, point.y);
}
});
}
gearShape.closePath();
const gearMesh = extrudedShape(
gearShape,
0.52,
materials.gear,
materials.gearSide
);
wheel.add(gearMesh);
const hub = makeAxleCylinder(0.5, 0.82, materials.steel, 12);
wheel.add(hub);
const axleCap = makeAxleCylinder(0.22, 0.95, materials.dark, 10);
axleCap.position.z = 0.05;
wheel.add(axleCap);
const axleNut = makeAxleCylinder(0.16, 1.04, materials.pawl, 6);
axleNut.position.z = 0.03;
wheel.add(axleNut);
// Raised radial ribs give the wheel a readable low-poly construction.
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
const rib = new THREE.Mesh(
new THREE.BoxGeometry(0.82, 0.105, 0.09),
materials.steel
);
rib.position.set(
Math.cos(angle) * 0.76,
Math.sin(angle) * 0.76,
0.32
);
rib.rotation.z = angle;
rib.castShadow = true;
wheel.add(rib);
const bolt = makeAxleCylinder(0.075, 0.11, materials.dark, 6);
bolt.position.set(
Math.cos(angle + 0.2) * 0.62,
Math.sin(angle + 0.2) * 0.62,
0.4
);
wheel.add(bolt);
}
// -------------------------------------------------------------------------
// Hinged pawl
// -------------------------------------------------------------------------
const pawlPivot = new THREE.Vector3(2.25, 1.72, 0.31);
const pawl = new THREE.Group();
pawl.position.copy(pawlPivot);
scene.add(pawl);
const pawlShape = new THREE.Shape();
pawlShape.moveTo(-0.96, -0.13);
pawlShape.lineTo(-0.76, -0.30);
pawlShape.lineTo(-0.10, -0.18);
pawlShape.lineTo(0.08, -0.18);
pawlShape.lineTo(0.64, 0.00);
pawlShape.lineTo(0.64, 0.19);
pawlShape.lineTo(0.08, 0.18);
pawlShape.lineTo(-0.10, 0.16);
pawlShape.lineTo(-0.79, 0.08);
pawlShape.lineTo(-0.98, 0.02);
pawlShape.closePath();
const pawlMesh = extrudedShape(pawlShape, 0.38, materials.pawl);
pawl.add(pawlMesh);
const pawlPin = makeAxleCylinder(0.18, 0.54, materials.steel, 10);
pawlPin.position.z = 0.12;
scene.add(pawlPin);
const pawlWasher = makeAxleCylinder(0.24, 0.07, materials.dark, 10);
pawlWasher.position.copy(pawlPivot);
pawlWasher.position.z = 0.55;
scene.add(pawlWasher);
// -------------------------------------------------------------------------
// Bell-crank release lever
// -------------------------------------------------------------------------
const leverPivot = new THREE.Vector3(3.4, 1.75, 0.62);
const lever = new THREE.Group();
lever.position.copy(leverPivot);
scene.add(lever);
const leverShape = new THREE.Shape();
leverShape.moveTo(-0.78, -0.10);
leverShape.lineTo(-0.12, -0.14);
leverShape.lineTo(0.03, -0.12);
leverShape.lineTo(1.43, -0.27);
leverShape.lineTo(1.76, -0.58);
leverShape.lineTo(1.91, -0.50);
leverShape.lineTo(1.91, 0.20);
leverShape.lineTo(1.55, 0.16);
leverShape.lineTo(0.02, 0.12);
leverShape.lineTo(-0.78, 0.10);
leverShape.closePath();
const leverMesh = extrudedShape(leverShape, 0.28, materials.lever);
lever.add(leverMesh);
const gripGeometry = new THREE.CylinderGeometry(0.17, 0.17, 0.62, 8);
gripGeometry.rotateZ(Math.PI / 2);
const grip = new THREE.Mesh(gripGeometry, materials.grip);
grip.position.set(1.77, -0.27, 0);
grip.castShadow = true;
lever.add(grip);
const leverPin = makeAxleCylinder(0.2, 0.65, materials.steel, 10);
leverPin.position.copy(leverPivot);
leverPin.position.z += 0.04;
scene.add(leverPin);
const leverWasher = makeAxleCylinder(0.25, 0.07, materials.dark, 10);
leverWasher.position.copy(leverPivot);
leverWasher.position.z += 0.2;
scene.add(leverWasher);
// -------------------------------------------------------------------------
// Clearance and reverse-direction indicators
// -------------------------------------------------------------------------
const clearanceArrow = new THREE.ArrowHelper(
new THREE.Vector3(0, 1, 0),
new THREE.Vector3(1.35, 1.45, 0.88),
0.12,
0xffc15e,
0.11,
0.075
);
clearanceArrow.line.material.transparent = true;
clearanceArrow.cone.material.transparent = true;
clearanceArrow.visible = false;
scene.add(clearanceArrow);
const clearanceRingMaterial = new THREE.MeshBasicMaterial({
color: 0xffc15e,
transparent: true,
opacity: 0,
depthWrite: false
});
const clearanceRing = new THREE.Mesh(
new THREE.TorusGeometry(0.22, 0.018, 5, 24),
clearanceRingMaterial
);
clearanceRing.position.set(1.34, 1.64, 0.75);
scene.add(clearanceRing);
const reverseArrowMaterial = new THREE.MeshBasicMaterial({
color: 0x6ee7ff,
transparent: true,
opacity: 0,
depthWrite: false
});
const reverseArc = new THREE.Mesh(
new THREE.TorusGeometry(2.38, 0.035, 5, 48, 2.12),
reverseArrowMaterial
);
reverseArc.rotation.z = 0.48;
reverseArc.position.z = 0.72;
scene.add(reverseArc);
const reverseHeadMaterial = new THREE.MeshBasicMaterial({
color: 0x6ee7ff,
transparent: true,
opacity: 0,
depthWrite: false
});
const reverseHead = new THREE.Mesh(
new THREE.ConeGeometry(0.13, 0.38, 6),
reverseHeadMaterial
);
const reverseHeadAngle = 0.48;
reverseHead.position.set(
Math.cos(reverseHeadAngle) * 2.38,
Math.sin(reverseHeadAngle) * 2.38,
0.72
);
reverseHead.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
new THREE.Vector3(
Math.sin(reverseHeadAngle),
-Math.cos(reverseHeadAngle),
0
).normalize()
);
scene.add(reverseHead);
// -------------------------------------------------------------------------
// Animation state
// -------------------------------------------------------------------------
const cycleDuration = 8.6;
let cycleStart = performance.now() + 450;
const statusText = document.getElementById("statusText");
const statusDot = document.getElementById("statusDot");
const progressBar = document.getElementById("progressBar");
const resetFade = document.getElementById("resetFade");
const replayButton = document.getElementById("replay");
const steps = [
document.getElementById("step1"),
document.getElementById("step2"),
document.getElementById("step3")
];
const leverTag = document.getElementById("leverTag");
const pawlTag = document.getElementById("pawlTag");
const gapTag = document.getElementById("gapTag");
function clamp01(value) {
return Math.max(0, Math.min(1, value));
}
function smooth01(value) {
const x = clamp01(value);
return x * x * (3 - 2 * x);
}
function restartCycle() {
cycleStart = performance.now();
}
replayButton.addEventListener("click", restartCycle);
addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
restartCycle();
}
});
function setActiveStep(index) {
steps.forEach((step, i) => {
step.classList.toggle("active", i === index);
});
}
function setStatus(text, color) {
statusText.textContent = text;
document.documentElement.style.setProperty("--accent", color);
}
// -------------------------------------------------------------------------
// Direct camera controls and lever picking
// -------------------------------------------------------------------------
let dragging = false;
let moved = false;
let lastPointerX = 0;
let lastPointerY = 0;
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
moved = false;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
if (Math.abs(dx) + Math.abs(dy) > 2) {
moved = true;
}
cameraTheta -= dx * 0.006;
cameraPhi -= dy * 0.005;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (!moved) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObject(lever, true);
if (hits.length) {
restartCycle();
}
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius += event.deltaY * 0.008;
updateCamera();
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Screen-space annotation placement
// -------------------------------------------------------------------------
function projectTag(element, worldPosition, opacity = 1) {
const projected = worldPosition.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
element.style.opacity = visible ? opacity : 0;
if (visible) {
element.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
}
}
// -------------------------------------------------------------------------
// Main animation
// -------------------------------------------------------------------------
function animate(now) {
requestAnimationFrame(animate);
const t = ((now - cycleStart) / 1000) % cycleDuration;
let wheelAngle = 0;
let releaseAmount = 0;
let reverseAmount = 0;
let fadeOpacity = 0;
if (t < 1.25) {
// A tiny attempted reverse movement emphasizes the caught tooth.
wheelAngle = -0.012 * ((t % 0.42) / 0.42);
releaseAmount = 0;
setStatus("REVERSE BLOCKED", "#ff6f4e");
setActiveStep(0);
} else if (t < 2.35) {
releaseAmount = smooth01((t - 1.25) / 1.1);
setStatus("RELEASE LEVER LIFTING", "#ffb84d");
setActiveStep(1);
} else if (t < 6.65) {
releaseAmount = 1;
reverseAmount = clamp01((t - 2.35) / 4.3);
const easedReverse =
reverseAmount * 0.18 + smooth01(reverseAmount) * 0.82;
wheelAngle = -2.25 * easedReverse;
setStatus("REVERSE ROTATION CLEAR", "#6ee7ff");
setActiveStep(2);
} else if (t < 7.7) {
releaseAmount = 1 - smooth01((t - 6.65) / 1.05);
wheelAngle = -2.25;
setStatus("PAWL RE-ENGAGING", "#ffb84d");
setActiveStep(1);
} else {
// Reset happens beneath a short dark transition.
wheelAngle = 0;
releaseAmount = 0;
fadeOpacity = 0.9;
setStatus("CYCLE RESET", "#8298ac");
setActiveStep(0);
}
if (t < 0.3) {
fadeOpacity = Math.max(fadeOpacity, 0.9 * (1 - smooth01(t / 0.3)));
}
wheel.rotation.z = wheelAngle;
const leverAngle = THREE.MathUtils.degToRad(24) * releaseAmount;
const pawlAngle = THREE.MathUtils.degToRad(-18) * releaseAmount;
lever.rotation.z = leverAngle;
pawl.rotation.z = pawlAngle;
// Indicators
const clearanceOpacity = smooth01((releaseAmount - 0.05) * 1.8);
clearanceArrow.visible = clearanceOpacity > 0.01;
clearanceArrow.setLength(
0.12 + releaseAmount * 0.32,
0.11 + releaseAmount * 0.025,
0.075 + releaseAmount * 0.02
);
clearanceArrow.line.material.opacity = clearanceOpacity * 0.9;
clearanceArrow.cone.material.opacity = clearanceOpacity;
clearanceRingMaterial.opacity = clearanceOpacity * 0.8;
clearanceRing.scale.setScalar(0.8 + releaseAmount * 0.55);
const reverseOpacity = smooth01((reverseAmount - 0.02) * 5);
reverseArrowMaterial.opacity = reverseOpacity * 0.82;
reverseHeadMaterial.opacity = reverseOpacity;
resetFade.style.opacity = fadeOpacity;
progressBar.style.width = `${(t / cycleDuration) * 100}%`;
// Projected labels
const leverWorld = lever.localToWorld(
new THREE.Vector3(1.2, -0.18, 0.18)
);
const pawlWorld = pawl.localToWorld(
new THREE.Vector3(-0.38, 0.18, 0.3)
);
const gapWorld = new THREE.Vector3(1.35, 1.95, 0.86);
projectTag(leverTag, leverWorld, 0.9);
projectTag(pawlTag, pawlWorld, 0.82);
projectTag(gapTag, gapWorld, clearanceOpacity * 0.95);
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
updateCamera();
});
</script>
</body>
</html>
```