Prompt specification
Build or customize the Three.js 3D scene "Cable tie locking head section" 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: Cable tie locking head section
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/cable-tie-locking-head-section-x0245
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows locking cable ties. Display a toothed strap entering a cutaway locking head; show the flexible pawl touching the teeth and leave the open tail long enough to inspect. Voxel style.
Working Three.js Starter (cable-tie-locking-head-section-x0245):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Locking Cable Tie — Voxel Cutaway</title>
<style>
:root {
color-scheme: dark;
--bg: #09111b;
--panel: rgba(12, 23, 35, 0.84);
--line: rgba(145, 193, 216, 0.22);
--text: #e9f5fb;
--muted: #8ca6b6;
--teal: #51e0cf;
--orange: #ffab50;
--cut: #ffd27a;
}
* {
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;
color: var(--text);
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas.dragging {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.title-block {
position: absolute;
top: 28px;
left: 30px;
max-width: 420px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
color: var(--teal);
font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 26px;
height: 2px;
background: var(--teal);
box-shadow: 8px 0 0 rgba(81, 224, 207, 0.35);
}
h1 {
margin: 0;
font-size: clamp(28px, 4vw, 48px);
line-height: 0.98;
letter-spacing: -0.045em;
text-transform: uppercase;
text-shadow: 0 2px 20px rgba(0, 0, 0, 0.3);
}
.subtitle {
margin-top: 13px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
letter-spacing: 0.025em;
}
.status {
position: absolute;
top: 28px;
right: 30px;
display: flex;
align-items: center;
gap: 9px;
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 4px;
background: var(--panel);
backdrop-filter: blur(12px);
color: #cde5ee;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 12px rgba(81, 224, 207, 0.9);
}
.bottom-left {
position: absolute;
left: 30px;
bottom: 27px;
display: flex;
flex-direction: column;
gap: 13px;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.legend-item,
.hint {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 9px 11px;
border: 1px solid var(--line);
border-radius: 4px;
background: var(--panel);
backdrop-filter: blur(12px);
color: #b9ced9;
font: 600 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.swatch {
width: 9px;
height: 9px;
background: var(--teal);
box-shadow: 0 0 9px rgba(81, 224, 207, 0.35);
}
.swatch.orange {
background: var(--orange);
box-shadow: 0 0 9px rgba(255, 171, 80, 0.35);
}
.hint {
color: #7893a4;
border-color: transparent;
background: transparent;
padding-left: 0;
}
.controls {
position: absolute;
right: 30px;
bottom: 27px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 4px;
padding: 10px 13px;
background: var(--panel);
backdrop-filter: blur(12px);
color: #c8dce7;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.09em;
text-transform: uppercase;
cursor: pointer;
transition: border-color 150ms ease, color 150ms ease, transform 150ms ease;
}
button:hover {
color: #ffffff;
border-color: rgba(81, 224, 207, 0.65);
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid var(--teal);
outline-offset: 3px;
}
#annotation-lines {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 3;
overflow: visible;
}
#annotation-lines path {
fill: none;
stroke: rgba(163, 209, 225, 0.52);
stroke-width: 1;
stroke-dasharray: 3 4;
}
#annotation-lines circle {
fill: #d7f7ff;
stroke: rgba(81, 224, 207, 0.65);
stroke-width: 2;
}
.callout {
position: fixed;
z-index: 4;
min-width: 132px;
padding: 9px 11px;
border-left: 2px solid var(--teal);
background: rgba(9, 19, 29, 0.88);
box-shadow: 0 8px 26px rgba(0, 0, 0, 0.2);
backdrop-filter: blur(8px);
pointer-events: none;
transform: translate(-50%, -50%);
transition: opacity 120ms ease;
}
.callout.orange {
border-left-color: var(--orange);
}
.callout strong {
display: block;
color: #e9f7fc;
font: 800 10px/1.25 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.callout span {
display: block;
margin-top: 4px;
color: #829cac;
font-size: 10px;
line-height: 1.3;
}
body.labels-off .callout,
body.labels-off #annotation-lines {
opacity: 0;
}
@media (max-width: 760px) {
.title-block {
top: 20px;
left: 18px;
right: 18px;
}
.status {
top: auto;
right: 18px;
bottom: 76px;
}
.bottom-left {
left: 18px;
bottom: 18px;
}
.hint {
display: none;
}
.controls {
right: 18px;
bottom: 18px;
}
.legend-item {
padding: 8px;
}
.callout {
display: none;
}
#annotation-lines {
opacity: 0.45;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<svg id="annotation-lines" aria-hidden="true"></svg>
<div class="callout" id="callout-tail">
<strong>Open tail</strong>
<span>Long section remains accessible for inspection</span>
</div>
<div class="callout orange" id="callout-pawl">
<strong>Flexible pawl</strong>
<span>Stepped lever bears against the teeth</span>
</div>
<div class="callout orange" id="callout-contact">
<strong>Tooth contact</strong>
<span>Positive locking engagement</span>
</div>
<div class="hud">
<header class="title-block">
<div class="eyebrow">Mechanism study / 01</div>
<h1>Locking<br>Cable Tie</h1>
<div class="subtitle">
Voxel cutaway showing the toothed strap, flexible locking pawl,
and the extended open tail.
</div>
</header>
<div class="status">
<span class="status-dot"></span>
Pawl latched
</div>
<div class="bottom-left">
<div class="legend">
<div class="legend-item">
<span class="swatch"></span>
Toothed strap
</div>
<div class="legend-item">
<span class="swatch orange"></span>
Locking pawl
</div>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
</div>
<div class="controls">
<button id="toggle-labels" type="button">Labels</button>
<button id="reset-view" type="button">Reset view</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";
const container = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
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.16;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Interactive voxel cutaway of a locking cable tie");
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x09111b);
scene.fog = new THREE.FogExp2(0x09111b, 0.024);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Custom orbit state.
const orbit = {
target: new THREE.Vector3(-1.55, 0.08, 0),
spherical: new THREE.Spherical(11.5, 1.22, 0.38),
dragging: false,
pointerX: 0,
pointerY: 0
};
function updateCamera() {
orbit.spherical.phi = THREE.MathUtils.clamp(orbit.spherical.phi, 0.28, 1.46);
orbit.spherical.radius = THREE.MathUtils.clamp(orbit.spherical.radius, 6.3, 23);
orbit.spherical.makeSafe();
const offset = new THREE.Vector3().setFromSpherical(orbit.spherical);
camera.position.copy(orbit.target).add(offset);
camera.lookAt(orbit.target);
}
function resetCamera() {
orbit.target.set(-1.55, 0.08, 0);
orbit.spherical.set(11.5, 1.22, 0.38);
updateCamera();
}
updateCamera();
// Lighting.
const hemisphere = new THREE.HemisphereLight(0xb8e8ff, 0x17212a, 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xe9f7ff, 3.4);
keyLight.position.set(-3.5, 7.5, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 22;
keyLight.shadow.bias = -0.0003;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x4de9d5, 1.25);
rimLight.position.set(5, 2.5, -5);
scene.add(rimLight);
const pawlLight = new THREE.PointLight(0xff9c42, 2.1, 5, 2);
pawlLight.position.set(1.4, 1.3, 2.1);
scene.add(pawlLight);
// Materials.
const materials = {
strap: new THREE.MeshStandardMaterial({
color: 0x36bcae,
roughness: 0.63,
metalness: 0.06,
flatShading: true
}),
teeth: new THREE.MeshStandardMaterial({
color: 0x7ce9dc,
roughness: 0.52,
metalness: 0.04,
flatShading: true
}),
strapSide: new THREE.MeshStandardMaterial({
color: 0x1d756f,
roughness: 0.7,
metalness: 0.04
}),
head: new THREE.MeshStandardMaterial({
color: 0x2c4053,
roughness: 0.76,
metalness: 0.12,
flatShading: true
}),
headAlt: new THREE.MeshStandardMaterial({
color: 0x344b60,
roughness: 0.72,
metalness: 0.12,
flatShading: true
}),
headDark: new THREE.MeshStandardMaterial({
color: 0x142331,
roughness: 0.86,
metalness: 0.08
}),
cut: new THREE.MeshStandardMaterial({
color: 0xffcf73,
roughness: 0.48,
metalness: 0.16,
flatShading: true
}),
pawl: new THREE.MeshStandardMaterial({
color: 0xffa044,
roughness: 0.5,
metalness: 0.08,
flatShading: true
}),
pawlDark: new THREE.MeshStandardMaterial({
color: 0xc96f2d,
roughness: 0.6,
metalness: 0.08,
flatShading: true
}),
contact: new THREE.MeshBasicMaterial({
color: 0xd9ffff,
transparent: true,
opacity: 0.82
}),
pedestal: new THREE.MeshStandardMaterial({
color: 0x101c27,
roughness: 0.92,
metalness: 0.02
}),
pedestalTop: new THREE.MeshStandardMaterial({
color: 0x172735,
roughness: 0.88,
metalness: 0.03
}),
floor: new THREE.MeshStandardMaterial({
color: 0x09121b,
roughness: 0.96,
metalness: 0
})
};
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const unitEdges = new THREE.EdgesGeometry(unitBox);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x071017,
transparent: true,
opacity: 0.58
});
function block(
width,
height,
depth,
material,
x,
y,
z,
parent = scene,
outlined = false
) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
if (outlined) {
const outline = new THREE.LineSegments(unitEdges, edgeMaterial);
mesh.add(outline);
}
return mesh;
}
// Ground and display plinth.
const floor = new THREE.Mesh(new THREE.PlaneGeometry(40, 40), materials.floor);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.66;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(30, 30, 0x285064, 0x142d39);
grid.position.y = -0.645;
grid.material.transparent = true;
grid.material.opacity = 0.32;
scene.add(grid);
block(9.6, 0.22, 2.2, materials.pedestal, -2.0, -0.52, 0, scene, true);
block(9.3, 0.04, 1.95, materials.pedestalTop, -2.0, -0.39, 0);
// Main toothed strap. Its free tail extends far to the left.
block(7.5, 0.18, 1.0, materials.strap, -2.35, 0, 0, scene, true);
// Dark side rails help define the strap edge.
block(7.3, 0.055, 0.025, materials.strapSide, -2.35, -0.005, 0.512);
block(7.3, 0.055, 0.025, materials.strapSide, -2.35, -0.005, -0.512);
// Voxel teeth: each tooth is made from two offset blocks.
const teethGroup = new THREE.Group();
scene.add(teethGroup);
const toothStart = -5.82;
const toothEnd = 1.08;
const toothSpacing = 0.30;
for (let x = toothStart; x <= toothEnd + 0.001; x += toothSpacing) {
block(
0.16,
0.055,
0.76,
materials.teeth,
x,
0.1175,
0,
teethGroup
);
block(
0.07,
0.075,
0.76,
materials.teeth,
x + 0.035,
0.1825,
0,
teethGroup
);
}
// Cutaway locking head, assembled from a grid of voxel-like blocks.
const headGroup = new THREE.Group();
scene.add(headGroup);
// Lower rail.
for (let i = 0; i < 8; i++) {
block(
0.198,
0.22,
1.18,
i % 2 ? materials.headAlt : materials.head,
0.69 + i * 0.21,
-0.29,
0,
headGroup
);
}
// Back wall.
for (let row = 0; row < 4; row++) {
for (let col = 0; col < 8; col++) {
block(
0.198,
0.198,
0.18,
(row + col) % 3 === 0 ? materials.headAlt : materials.head,
0.69 + col * 0.21,
-0.19 + row * 0.21,
-0.58,
headGroup
);
}
}
// Right wall.
for (let row = 0; row < 4; row++) {
for (let col = 0; col < 5; col++) {
block(
0.18,
0.198,
0.198,
(row + col) % 2 ? materials.head : materials.headAlt,
2.38,
-0.18 + row * 0.21,
-0.47 + col * 0.25,
headGroup
);
}
}
// Partial top cover; the front and upper-middle are intentionally cut away.
for (let i = 0; i < 6; i++) {
block(
0.198,
0.17,
0.46,
i % 2 ? materials.headAlt : materials.head,
1.11 + i * 0.21,
0.63,
-0.37,
headGroup
);
}
block(0.18, 0.17, 0.93, materials.head, 2.38, 0.63, 0.08, headGroup);
// Entrance cheeks, leaving the strap channel open.
block(0.22, 0.42, 0.18, materials.head, 0.58, 0.12, -0.49, headGroup);
block(0.22, 0.42, 0.18, materials.headAlt, 0.58, 0.12, 0.49, headGroup);
// Amber cross-sections emphasize where the housing has been cut.
block(1.68, 0.065, 0.07, materials.cut, 1.48, 0.55, -0.475, headGroup);
block(0.07, 0.72, 0.07, materials.cut, 2.275, 0.12, -0.475, headGroup);
block(1.73, 0.065, 0.07, materials.cut, 1.48, -0.365, -0.39, headGroup);
// Dark cavity floor beneath the inserted strap.
block(1.54, 0.07, 0.98, materials.headDark, 1.47, -0.15, 0, headGroup);
// Flexible pawl and pivot.
const pawlGroup = new THREE.Group();
scene.add(pawlGroup);
// Fixed pivot housing.
block(0.34, 0.25, 0.79, materials.pawlDark, 1.88, 0.82, 0, headGroup);
// Square axle caps.
block(0.13, 0.13, 0.09, materials.cut, 1.88, 0.82, 0.43, headGroup);
block(0.13, 0.13, 0.09, materials.cut, 1.88, 0.82, -0.43, headGroup);
// Stepped flexible lever. The lowest segment touches a tooth at x ≈ 0.81.
block(0.31, 0.15, 0.54, materials.pawl, 0.81, 0.295, 0, pawlGroup);
block(0.34, 0.15, 0.56, materials.pawl, 1.00, 0.405, 0, pawlGroup);
block(0.36, 0.15, 0.58, materials.pawl, 1.22, 0.515, 0, pawlGroup);
block(0.40, 0.15, 0.60, materials.pawl, 1.46, 0.625, 0, pawlGroup);
block(0.43, 0.15, 0.64, materials.pawlDark, 1.70, 0.735, 0, pawlGroup);
// Small stepped transition blocks imply flexing rather than a smooth wedge.
block(0.15, 0.07, 0.51, materials.pawlDark, 0.88, 0.375, 0, pawlGroup);
block(0.15, 0.07, 0.53, materials.pawlDark, 1.10, 0.485, 0, pawlGroup);
block(0.15, 0.07, 0.55, materials.pawlDark, 1.33, 0.595, 0, pawlGroup);
// Contact marker surrounding the engaged tooth.
const contactFrame = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(0.18, 0.14, 0.18)),
new THREE.LineBasicMaterial({
color: 0xeaffff,
transparent: true,
opacity: 0.9
})
);
contactFrame.position.set(0.81, 0.235, 0);
scene.add(contactFrame);
// Four tiny voxel sparks emphasize the pressure point.
const sparkGeometry = new THREE.BoxGeometry(0.055, 0.055, 0.055);
const sparkMaterial = new THREE.MeshBasicMaterial({
color: 0xc7ffff,
transparent: true,
opacity: 0.82
});
const sparks = [
[-0.13, 0.02, 0],
[0.13, 0.02, 0],
[0, 0.14, 0],
[0, -0.10, 0]
];
sparks.forEach(([x, y, z]) => {
const spark = new THREE.Mesh(sparkGeometry, sparkMaterial);
spark.position.set(0.81 + x, 0.235 + y, z);
scene.add(spark);
});
// Decorative voxel depth markers in the distant background.
const backgroundMaterial = new THREE.MeshStandardMaterial({
color: 0x112331,
roughness: 1,
metalness: 0
});
[
[-5.8, -0.25, -3.8, 0.34],
[-5.1, 0.05, -4.5, 0.22],
[3.9, -0.12, -3.4, 0.28],
[4.6, 0.18, -4.2, 0.18]
].forEach(([x, y, z, size]) => {
block(size, size, size, backgroundMaterial, x, y, z);
});
// SVG annotation leaders.
const annotationSvg = document.getElementById("annotation-lines");
const svgNS = "http://www.w3.org/2000/svg";
const annotations = [
{
element: document.getElementById("callout-tail"),
anchor: new THREE.Vector3(-3.45, 0.13, 0.05),
offset: new THREE.Vector2(-45, 95)
},
{
element: document.getElementById("callout-pawl"),
anchor: new THREE.Vector3(1.40, 0.69, 0.16),
offset: new THREE.Vector2(105, -70)
},
{
element: document.getElementById("callout-contact"),
anchor: new THREE.Vector3(0.81, 0.235, 0.12),
offset: new THREE.Vector2(-145, 65)
}
];
annotations.forEach((annotation) => {
annotation.path = document.createElementNS(svgNS, "path");
annotation.dot = document.createElementNS(svgNS, "circle");
annotation.dot.setAttribute("r", "3");
annotationSvg.appendChild(annotation.path);
annotationSvg.appendChild(annotation.dot);
});
function updateAnnotations() {
const width = window.innerWidth;
const height = window.innerHeight;
annotations.forEach((annotation) => {
const projected = annotation.anchor.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
annotation.element.style.opacity = visible ? "1" : "0";
annotation.path.style.opacity = visible ? "1" : "0";
annotation.dot.style.opacity = visible ? "1" : "0";
if (!visible) return;
const sx = (projected.x * 0.5 + 0.5) * width;
const sy = (-projected.y * 0.5 + 0.5) * height;
const labelX = THREE.MathUtils.clamp(
sx + annotation.offset.x,
92,
width - 92
);
const labelY = THREE.MathUtils.clamp(
sy + annotation.offset.y,
100,
height - 90
);
const elbowX = sx + annotation.offset.x * 0.32;
const elbowY = labelY;
annotation.path.setAttribute(
"d",
`M ${sx.toFixed(1)} ${sy.toFixed(1)}
L ${elbowX.toFixed(1)} ${elbowY.toFixed(1)}
L ${labelX.toFixed(1)} ${labelY.toFixed(1)}`
);
annotation.dot.setAttribute("cx", sx.toFixed(1));
annotation.dot.setAttribute("cy", sy.toFixed(1));
annotation.element.style.left = `${labelX}px`;
annotation.element.style.top = `${labelY}px`;
});
}
// Custom pointer controls.
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
orbit.dragging = true;
orbit.pointerX = event.clientX;
orbit.pointerY = event.clientY;
canvas.classList.add("dragging");
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!orbit.dragging) return;
const dx = event.clientX - orbit.pointerX;
const dy = event.clientY - orbit.pointerY;
orbit.pointerX = event.clientX;
orbit.pointerY = event.clientY;
orbit.spherical.theta -= dx * 0.006;
orbit.spherical.phi -= dy * 0.006;
updateCamera();
});
function endDrag(event) {
orbit.dragging = false;
canvas.classList.remove("dragging");
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.spherical.radius *= Math.exp(event.deltaY * 0.001);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
document.getElementById("reset-view").addEventListener("click", resetCamera);
document.getElementById("toggle-labels").addEventListener("click", () => {
document.body.classList.toggle("labels-off");
});
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
// Pull the camera back on narrow displays so the full tail remains visible.
if (camera.aspect < 0.8 && orbit.spherical.radius < 17) {
orbit.spherical.radius = 17;
updateCamera();
}
}
window.addEventListener("resize", onResize);
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
// Gentle contact pulse without moving the pawl away from the tooth.
const pulse = 0.72 + Math.sin(elapsed * 3.2) * 0.18;
contactFrame.material.opacity = pulse;
sparkMaterial.opacity = 0.55 + pulse * 0.32;
updateAnnotations();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```