Prompt specification
Build or customize the Three.js 3D scene "Finger joint chain around a handle" 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: Finger joint chain around a handle
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/finger-joint-chain-around-a-handle-x0985
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows hand grips. Model one schematic finger with three phalanges curling around a cylindrical handle; preserve joint spacing and keep all segments outside the solid handle. A 3D cutaway view.
Working Three.js Starter (finger-joint-chain-around-a-handle-x0985):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Schematic Finger Grip — 3D Cutaway</title>
<style>
:root {
color-scheme: dark;
--bg: #071014;
--panel: rgba(10, 24, 29, 0.82);
--line: rgba(151, 222, 219, 0.18);
--text: #e8f4f1;
--muted: #8fa8a7;
--cyan: #74e6d5;
--amber: #ffb56b;
--coral: #e78d76;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 68% 36%, #153238 0%, #09171b 35%, #050d10 76%);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
header {
position: fixed;
top: 28px;
left: 32px;
z-index: 5;
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: var(--cyan);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(26px, 3vw, 42px);
font-weight: 550;
letter-spacing: -0.045em;
line-height: 1;
}
header p {
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
letter-spacing: 0.02em;
}
.panel {
position: fixed;
z-index: 10;
top: 104px;
left: 32px;
width: 294px;
padding: 18px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(18px);
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 14px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.status {
display: inline-flex;
align-items: center;
gap: 6px;
color: var(--cyan);
letter-spacing: 0.08em;
}
.status::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 10px currentColor;
content: "";
}
.metric {
display: flex;
align-items: baseline;
justify-content: space-between;
padding: 10px 0;
border-bottom: 1px solid rgba(151, 222, 219, 0.1);
}
.metric span {
color: var(--muted);
font-size: 11px;
}
.metric strong {
font-size: 13px;
font-weight: 600;
letter-spacing: 0.02em;
}
.metric strong.safe {
color: var(--cyan);
}
.control {
margin-top: 17px;
}
.control-label {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
color: var(--muted);
font-size: 11px;
}
.control-label output {
color: var(--text);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
margin: 0;
accent-color: var(--cyan);
cursor: pointer;
}
.presets {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 6px;
margin-top: 10px;
}
button {
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.025);
color: var(--muted);
font: inherit;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.06em;
cursor: pointer;
transition:
color 160ms ease,
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
button:hover {
color: var(--text);
border-color: rgba(116, 230, 213, 0.42);
background: rgba(116, 230, 213, 0.07);
}
button:active {
transform: translateY(1px);
}
.preset.active {
border-color: rgba(116, 230, 213, 0.55);
background: rgba(116, 230, 213, 0.12);
color: var(--cyan);
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 16px;
}
.button-row button {
min-height: 36px;
padding: 0 9px;
}
.button-row button.active {
border-color: rgba(255, 181, 107, 0.5);
background: rgba(255, 181, 107, 0.1);
color: var(--amber);
}
.note {
margin: 15px 0 0;
padding-top: 13px;
border-top: 1px solid rgba(151, 222, 219, 0.1);
color: #78918f;
font-size: 10px;
line-height: 1.55;
}
.legend {
position: fixed;
z-index: 5;
right: 30px;
bottom: 28px;
display: flex;
gap: 18px;
align-items: center;
padding: 11px 14px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(7, 17, 20, 0.64);
color: var(--muted);
font-size: 10px;
letter-spacing: 0.04em;
backdrop-filter: blur(12px);
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--coral);
}
.swatch.core {
background: var(--amber);
}
.swatch.measure {
background: var(--cyan);
}
.hint {
position: fixed;
z-index: 5;
right: 30px;
top: 30px;
color: #78918f;
font-size: 10px;
letter-spacing: 0.06em;
text-transform: uppercase;
pointer-events: none;
}
.segment-label {
position: fixed;
z-index: 4;
padding: 5px 8px;
border: 1px solid rgba(231, 141, 118, 0.32);
border-radius: 6px;
background: rgba(28, 19, 19, 0.72);
color: #f3b29e;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
pointer-events: none;
transform: translate(12px, -50%);
backdrop-filter: blur(8px);
}
.segment-label::before {
position: absolute;
top: 50%;
left: -12px;
width: 12px;
height: 1px;
background: rgba(231, 141, 118, 0.5);
content: "";
}
#loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
background: #071014;
color: var(--cyan);
font-size: 10px;
letter-spacing: 0.18em;
text-transform: uppercase;
}
@media (max-width: 760px) {
header {
top: 20px;
left: 20px;
}
header p,
.hint,
.legend {
display: none;
}
.panel {
top: auto;
right: 14px;
bottom: 14px;
left: 14px;
width: auto;
padding: 14px;
}
.metric:nth-of-type(2),
.metric:nth-of-type(3) {
display: none;
}
.segment-label {
display: none !important;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div id="loading">Building grip model…</div>
<header>
<div class="eyebrow">Biomechanics / Study 03</div>
<h1>Finger / Grip</h1>
<p>One schematic finger. Three rigid spans. No handle intersection.</p>
</header>
<aside class="panel">
<div class="panel-title">
Grip analysis
<span class="status">Verified</span>
</div>
<div class="metric">
<span>Wrap angle</span>
<strong id="angleMetric">142°</strong>
</div>
<div class="metric">
<span>Joint spacing</span>
<strong>41 / 32 / 25 mm</strong>
</div>
<div class="metric">
<span>Minimum clearance</span>
<strong id="clearanceMetric" class="safe">0.0 mm</strong>
</div>
<div class="metric">
<span>Handle envelope</span>
<strong>Ø 54 mm</strong>
</div>
<div class="control">
<div class="control-label">
<span>Wrap angle</span>
<output id="angleOutput">142°</output>
</div>
<input
id="angleSlider"
type="range"
min="112"
max="148"
step="1"
value="142"
aria-label="Finger wrap angle"
/>
<div class="presets">
<button class="preset" data-angle="112">Open</button>
<button class="preset" data-angle="128">Tip</button>
<button class="preset active" data-angle="142">Power</button>
<button class="preset" data-angle="148">Full</button>
</div>
</div>
<div class="button-row">
<button id="cutawayButton" class="active" aria-pressed="true">
Cutaway on
</button>
<button id="resetButton">Reset view</button>
</div>
<p class="note">
The three phalanx lengths remain fixed while the wrap changes. The
articulation is solved around a collision-checked radial envelope.
</p>
</aside>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<div class="legend">
<div class="legend-item"><span class="swatch"></span>Phalanges</div>
<div class="legend-item"><span class="swatch core"></span>Handle core</div>
<div class="legend-item"><span class="swatch measure"></span>Joint spacing</div>
</div>
<div id="proximalLabel" class="segment-label">Proximal</div>
<div id="middleLabel" class="segment-label">Middle</div>
<div id="distalLabel" class="segment-label">Distal</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const loading = document.querySelector("#loading");
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x071014, 0.026);
const camera = new THREE.PerspectiveCamera(
34,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, 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 3D cutaway of a finger gripping a cylindrical handle"
);
stage.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xc9f5f4, 0x101518, 1.7);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff3df, 3.2);
key.position.set(4.5, 6.5, 5.5);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -6;
key.shadow.camera.right = 6;
key.shadow.camera.top = 6;
key.shadow.camera.bottom = -6;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 20;
key.shadow.bias = -0.0004;
scene.add(key);
const rim = new THREE.DirectionalLight(0x4ce3d1, 2.1);
rim.position.set(-4, 2.5, -5);
scene.add(rim);
const warmFill = new THREE.PointLight(0xff9f62, 9, 8, 2);
warmFill.position.set(2.8, 1.2, 3.3);
scene.add(warmFill);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(24, 24),
new THREE.MeshStandardMaterial({
color: 0x081316,
roughness: 0.95,
metalness: 0.02
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.62;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(14, 28, 0x24474b, 0x10282d);
grid.position.y = -1.61;
grid.material.transparent = true;
grid.material.opacity = 0.42;
scene.add(grid);
// Scene scale: one unit represents 30 mm.
const MM_PER_UNIT = 30;
const HANDLE_RADIUS = 0.9;
const HANDLE_LENGTH = 4.25;
const CORE_RADIUS = 0.49;
const FINGER_RADIAL_THICKNESS = 0.125;
const FINGER_AXIAL_THICKNESS = 0.18;
const FINGER_X = 0.28;
// Fixed center-to-center joint spacing.
const SEGMENT_LENGTHS = [1.36, 1.05, 0.82];
const outerMaterial = new THREE.MeshStandardMaterial({
color: 0x1a4b4d,
roughness: 0.52,
metalness: 0.16,
side: THREE.DoubleSide
});
const cutMaterial = new THREE.MeshStandardMaterial({
color: 0xffad68,
roughness: 0.4,
metalness: 0.3,
side: THREE.DoubleSide
});
const innerMaterial = new THREE.MeshStandardMaterial({
color: 0x12383a,
roughness: 0.65,
metalness: 0.12,
side: THREE.DoubleSide
});
const coreMaterial = new THREE.MeshStandardMaterial({
color: 0xb96e45,
roughness: 0.3,
metalness: 0.7
});
const fullHandleMaterial = new THREE.MeshStandardMaterial({
color: 0x1a4b4d,
roughness: 0.5,
metalness: 0.16
});
function makeOuterSurface(
radius,
length,
startAngle,
sweepAngle,
segments,
inward = false
) {
const positions = [];
const normals = [];
const uvs = [];
const indices = [];
for (let i = 0; i < segments; i++) {
const t0 = i / segments;
const t1 = (i + 1) / segments;
const a0 = startAngle + sweepAngle * t0;
const a1 = startAngle + sweepAngle * t1;
const r0 = new THREE.Vector3(0, Math.cos(a0), Math.sin(a0));
const r1 = new THREE.Vector3(0, Math.cos(a1), Math.sin(a1));
const n0 = r0.clone().multiplyScalar(inward ? -1 : 1);
const n1 = r1.clone().multiplyScalar(inward ? -1 : 1);
const base = positions.length / 3;
positions.push(
-length / 2, r0.y * radius, r0.z * radius,
length / 2, r0.y * radius, r0.z * radius,
-length / 2, r1.y * radius, r1.z * radius,
length / 2, r1.y * radius, r1.z * radius
);
normals.push(
n0.x, n0.y, n0.z,
n0.x, n0.y, n0.z,
n1.x, n1.y, n1.z,
n1.x, n1.y, n1.z
);
uvs.push(t0, 0, t0, 1, t1, 0, t1, 1);
if (inward) {
indices.push(
base, base + 1, base + 2,
base + 1, base + 3, base + 2
);
} else {
indices.push(
base, base + 2, base + 1,
base + 1, base + 2, base + 3
);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"normal",
new THREE.Float32BufferAttribute(normals, 3)
);
geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
geometry.setIndex(indices);
geometry.computeBoundingSphere();
return geometry;
}
function makeAnnularEnds(
outerRadius,
innerRadius,
length,
startAngle,
sweepAngle,
segments
) {
const positions = [];
const normals = [];
const uvs = [];
const indices = [];
for (const side of [-1, 1]) {
for (let i = 0; i < segments; i++) {
const a0 = startAngle + sweepAngle * (i / segments);
const a1 = startAngle + sweepAngle * ((i + 1) / segments);
const base = positions.length / 3;
positions.push(
side * length / 2, innerRadius * Math.cos(a0), innerRadius * Math.sin(a0),
side * length / 2, outerRadius * Math.cos(a0), outerRadius * Math.sin(a0),
side * length / 2, outerRadius * Math.cos(a1), outerRadius * Math.sin(a1),
side * length / 2, innerRadius * Math.cos(a1), innerRadius * Math.sin(a1)
);
for (let n = 0; n < 4; n++) {
normals.push(side, 0, 0);
}
uvs.push(0, 0, 1, 0, 1, 1, 0, 1);
indices.push(base, base + 1, base + 2, base, base + 2, base + 3);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"normal",
new THREE.Float32BufferAttribute(normals, 3)
);
geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
geometry.setIndex(indices);
geometry.computeBoundingSphere();
return geometry;
}
function makeRadialFaces(
outerRadius,
innerRadius,
length,
startAngle,
sweepAngle
) {
const positions = [];
const normals = [];
const uvs = [];
const indices = [];
const angles = [startAngle, startAngle + sweepAngle];
for (const angle of angles) {
const radial = new THREE.Vector3(
0,
Math.cos(angle),
Math.sin(angle)
);
const tangent = new THREE.Vector3(
0,
-Math.sin(angle),
Math.cos(angle)
);
const base = positions.length / 3;
positions.push(
-length / 2, radial.y * innerRadius, radial.z * innerRadius,
length / 2, radial.y * innerRadius, radial.z * innerRadius,
-length / 2, radial.y * outerRadius, radial.z * outerRadius,
length / 2, radial.y * outerRadius, radial.z * outerRadius
);
for (let n = 0; n < 4; n++) {
normals.push(tangent.x, tangent.y, tangent.z);
}
uvs.push(0, 0, 1, 0, 0, 1, 1, 1);
indices.push(base, base + 1, base + 2, base + 1, base + 3, base + 2);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"normal",
new THREE.Float32BufferAttribute(normals, 3)
);
geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
geometry.setIndex(indices);
geometry.computeBoundingSphere();
return geometry;
}
function makeCutawayHandle() {
const group = new THREE.Group();
// A 120-degree front/upper wedge is removed from the outer handle.
const startAngle = THREE.MathUtils.degToRad(115);
const sweepAngle = THREE.MathUtils.degToRad(240);
const segments = 112;
const outer = new THREE.Mesh(
makeOuterSurface(
HANDLE_RADIUS,
HANDLE_LENGTH,
startAngle,
sweepAngle,
segments
),
outerMaterial
);
outer.castShadow = true;
outer.receiveShadow = true;
group.add(outer);
const inner = new THREE.Mesh(
makeOuterSurface(
CORE_RADIUS,
HANDLE_LENGTH,
startAngle,
sweepAngle,
segments,
true
),
innerMaterial
);
inner.receiveShadow = true;
group.add(inner);
const ends = new THREE.Mesh(
makeAnnularEnds(
HANDLE_RADIUS,
CORE_RADIUS,
HANDLE_LENGTH,
startAngle,
sweepAngle,
segments
),
cutMaterial
);
ends.castShadow = true;
group.add(ends);
const radialFaces = new THREE.Mesh(
makeRadialFaces(
HANDLE_RADIUS,
CORE_RADIUS,
HANDLE_LENGTH,
startAngle,
sweepAngle
),
cutMaterial
);
radialFaces.castShadow = true;
group.add(radialFaces);
// Axial core exposed by the cutaway.
const core = new THREE.Mesh(
new THREE.CylinderGeometry(
CORE_RADIUS,
CORE_RADIUS,
HANDLE_LENGTH * 0.995,
64
),
coreMaterial
);
core.rotation.z = Math.PI / 2;
core.castShadow = true;
core.receiveShadow = true;
group.add(core);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0xffd49a,
transparent: true,
opacity: 0.8
});
for (const angle of [startAngle, startAngle + sweepAngle]) {
const y = Math.cos(angle);
const z = Math.sin(angle);
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(
-HANDLE_LENGTH / 2,
CORE_RADIUS * y,
CORE_RADIUS * z
),
new THREE.Vector3(
HANDLE_LENGTH / 2,
CORE_RADIUS * y,
CORE_RADIUS * z
)
]);
group.add(new THREE.Line(geometry, edgeMaterial));
for (const x of [-HANDLE_LENGTH / 2, HANDLE_LENGTH / 2]) {
const radialGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(x, CORE_RADIUS * y, CORE_RADIUS * z),
new THREE.Vector3(x, HANDLE_RADIUS * y, HANDLE_RADIUS * z)
]);
group.add(new THREE.Line(radialGeometry, edgeMaterial));
}
}
return group;
}
const cutawayHandle = makeCutawayHandle();
scene.add(cutawayHandle);
const fullHandle = new THREE.Mesh(
new THREE.CylinderGeometry(
HANDLE_RADIUS,
HANDLE_RADIUS,
HANDLE_LENGTH,
64
),
fullHandleMaterial
);
fullHandle.rotation.z = Math.PI / 2;
fullHandle.castShadow = true;
fullHandle.receiveShadow = true;
fullHandle.visible = false;
scene.add(fullHandle);
const axisGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-2.55, 0, 0),
new THREE.Vector3(2.55, 0, 0)
]);
const axis = new THREE.Line(
axisGeometry,
new THREE.LineDashedMaterial({
color: 0x8ab4b1,
transparent: true,
opacity: 0.28,
dashSize: 0.08,
gapSize: 0.055
})
);
axis.computeLineDistances();
scene.add(axis);
const fingerGroup = new THREE.Group();
scene.add(fingerGroup);
const skinMaterial = new THREE.MeshStandardMaterial({
color: 0xe58d75,
roughness: 0.66,
metalness: 0.02
});
const jointMaterial = new THREE.MeshStandardMaterial({
color: 0xa84f50,
roughness: 0.6,
metalness: 0.03
});
const tendonMaterial = new THREE.MeshStandardMaterial({
color: 0xffd0b2,
roughness: 0.56,
metalness: 0.02
});
const markerMaterial = new THREE.MeshStandardMaterial({
color: 0x78f3df,
emissive: 0x235d55,
emissiveIntensity: 0.65,
roughness: 0.35,
metalness: 0.15
});
const measurementMaterial = new THREE.LineDashedMaterial({
color: 0x79f3e1,
transparent: true,
opacity: 0.78,
dashSize: 0.055,
gapSize: 0.045,
depthTest: false
});
const labelElements = [
{
element: document.querySelector("#proximalLabel"),
anchor: new THREE.Vector3()
},
{
element: document.querySelector("#middleLabel"),
anchor: new THREE.Vector3()
},
{
element: document.querySelector("#distalLabel"),
anchor: new THREE.Vector3()
}
];
function solveCenterlineRadius(totalAngleDegrees) {
const target = THREE.MathUtils.degToRad(totalAngleDegrees);
let low = Math.max(...SEGMENT_LENGTHS) * 0.5 + 0.0001;
let high = 10;
// Total angular travel decreases as the radius increases.
for (let iteration = 0; iteration < 64; iteration++) {
const radius = (low + high) * 0.5;
let angle = 0;
for (const length of SEGMENT_LENGTHS) {
angle += 2 * Math.asin(length / (2 * radius));
}
if (angle > target) {
low = radius;
} else {
high = radius;
}
}
return (low + high) * 0.5;
}
function orientationAlong(direction) {
const localX = new THREE.Vector3(1, 0, 0);
const localZ = new THREE.Vector3()
.crossVectors(localX, direction)
.normalize();
const matrix = new THREE.Matrix4().makeBasis(
localX,
direction,
localZ
);
return new THREE.Quaternion().setFromRotationMatrix(matrix);
}
function clearFingerGroup() {
const geometries = new Set();
fingerGroup.traverse((object) => {
if (object.geometry) geometries.add(object.geometry);
});
fingerGroup.clear();
geometries.forEach((geometry) => geometry.dispose());
}
function buildFinger(totalAngleDegrees) {
clearFingerGroup();
const centerlineRadius = solveCenterlineRadius(totalAngleDegrees);
const deltas = SEGMENT_LENGTHS.map(
(length) => 2 * Math.asin(length / (2 * centerlineRadius))
);
let angle = THREE.MathUtils.degToRad(-8);
const joints = [
new THREE.Vector3(
FINGER_X,
centerlineRadius * Math.cos(angle),
centerlineRadius * Math.sin(angle)
)
];
for (const delta of deltas) {
angle += delta;
joints.push(
new THREE.Vector3(
FINGER_X,
centerlineRadius * Math.cos(angle),
centerlineRadius * Math.sin(angle)
)
);
}
const jointSphereGeometry = new THREE.SphereGeometry(1, 24, 18);
const jointRingGeometry = new THREE.TorusGeometry(
FINGER_RADIAL_THICKNESS,
0.017,
10,
40
);
jointRingGeometry.rotateY(Math.PI / 2);
// Exact center-to-center joint markers.
for (const joint of joints) {
const jointMesh = new THREE.Mesh(
jointSphereGeometry,
jointMaterial
);
jointMesh.position.copy(joint);
jointMesh.scale.set(
FINGER_AXIAL_THICKNESS,
FINGER_RADIAL_THICKNESS,
FINGER_RADIAL_THICKNESS
);
jointMesh.castShadow = true;
fingerGroup.add(jointMesh);
const collar = new THREE.Mesh(
jointRingGeometry,
jointMaterial
);
collar.position.copy(joint);
collar.castShadow = true;
fingerGroup.add(collar);
}
for (let i = 0; i < SEGMENT_LENGTHS.length; i++) {
const p0 = joints[i];
const p1 = joints[i + 1];
const direction = new THREE.Vector3().subVectors(p1, p0).normalize();
const midpoint = new THREE.Vector3()
.addVectors(p0, p1)
.multiplyScalar(0.5);
const quaternion = orientationAlong(direction);
const length = SEGMENT_LENGTHS[i];
// Tapered-looking phalanx body with spherical joint overlap.
const bodyLength = length - 0.2;
const bodyGeometry = new THREE.CylinderGeometry(
1,
1,
bodyLength,
24,
1,
false
);
const body = new THREE.Mesh(bodyGeometry, skinMaterial);
body.position.copy(midpoint);
body.quaternion.copy(quaternion);
body.scale.set(
FINGER_AXIAL_THICKNESS,
1,
FINGER_RADIAL_THICKNESS
);
body.castShadow = true;
body.receiveShadow = true;
fingerGroup.add(body);
// Tendon detail on the camera-facing axial surface.
const tendonGeometry = new THREE.CylinderGeometry(
0.018,
0.018,
length - 0.13,
10
);
const tendon = new THREE.Mesh(tendonGeometry, tendonMaterial);
tendon.position.copy(midpoint);
tendon.position.x += FINGER_AXIAL_THICKNESS + 0.006;
tendon.quaternion.copy(quaternion);
tendon.castShadow = true;
fingerGroup.add(tendon);
// Cyan dashed span: exact center-to-center joint spacing.
const measureA = p0.clone();
const measureB = p1.clone();
measureA.x = 0.505;
measureB.x = 0.505;
const measureGeometry = new THREE.BufferGeometry().setFromPoints([
measureA,
measureB
]);
const measureLine = new THREE.Line(
measureGeometry,
measurementMaterial
);
measureLine.computeLineDistances();
measureLine.renderOrder = 10;
fingerGroup.add(measureLine);
for (const point of [measureA, measureB]) {
const marker = new THREE.Mesh(
new THREE.SphereGeometry(0.032, 12, 10),
markerMaterial
);
marker.position.copy(point);
marker.renderOrder = 11;
fingerGroup.add(marker);
}
labelElements[i].anchor.copy(midpoint);
labelElements[i].anchor.x = 0.57;
}
// Exact clearance test for the solid cylindrical handle envelope.
let minimumClearance = Infinity;
for (const length of SEGMENT_LENGTHS) {
const distanceFromAxisToChord = Math.sqrt(
centerlineRadius * centerlineRadius -
(length * length) / 4
);
const clearance =
distanceFromAxisToChord -
FINGER_RADIAL_THICKNESS -
HANDLE_RADIUS;
minimumClearance = Math.min(minimumClearance, clearance);
}
// The slider is bounded to preserve a positive physical clearance.
if (minimumClearance <= 0) {
console.warn("Collision guard activated.", minimumClearance);
}
document.querySelector("#angleMetric").textContent =
`${totalAngleDegrees}°`;
document.querySelector("#angleOutput").textContent =
`${totalAngleDegrees}°`;
const clearanceMM = minimumClearance * MM_PER_UNIT;
const clearanceElement =
document.querySelector("#clearanceMetric");
clearanceElement.textContent = `${clearanceMM.toFixed(1)} mm`;
clearanceElement.style.color =
clearanceMM > 0 ? "var(--cyan)" : "var(--coral)";
}
const slider = document.querySelector("#angleSlider");
const presetButtons = [...document.querySelectorAll(".preset")];
function setWrapAngle(value, activePreset = null) {
const angle = Number(value);
slider.value = angle;
buildFinger(angle);
presetButtons.forEach((button) => {
const active = Number(button.dataset.angle) === Number(activePreset);
button.classList.toggle("active", active);
});
}
slider.addEventListener("input", () => {
setWrapAngle(slider.value);
});
presetButtons.forEach((button) => {
button.addEventListener("click", () => {
setWrapAngle(button.dataset.angle, button.dataset.angle);
});
});
let cutawayEnabled = true;
const cutawayButton = document.querySelector("#cutawayButton");
cutawayButton.addEventListener("click", () => {
cutawayEnabled = !cutawayEnabled;
cutawayHandle.visible = cutawayEnabled;
fullHandle.visible = !cutawayEnabled;
cutawayButton.classList.toggle("active", cutawayEnabled);
cutawayButton.setAttribute(
"aria-pressed",
String(cutawayEnabled)
);
cutawayButton.textContent = cutawayEnabled
? "Cutaway on"
: "Cutaway off";
});
// Custom orbit controls: no examples/addons are imported.
const target = new THREE.Vector3(0, 0.02, 0);
const defaultSpherical = new THREE.Spherical(8.45, 1.18, 0.91);
const spherical = defaultSpherical.clone();
const targetSpherical = defaultSpherical.clone();
function updateCamera() {
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
}
updateCamera();
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
targetSpherical.theta -= dx * 0.006;
targetSpherical.phi = THREE.MathUtils.clamp(
targetSpherical.phi + dy * 0.006,
0.32,
Math.PI - 0.32
);
});
function stopDragging(event) {
dragging = false;
if (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();
targetSpherical.radius = THREE.MathUtils.clamp(
targetSpherical.radius * Math.exp(event.deltaY * 0.001),
4.5,
13
);
},
{ passive: false }
);
function resetView() {
targetSpherical.copy(defaultSpherical);
}
renderer.domElement.addEventListener("dblclick", resetView);
document.querySelector("#resetButton").addEventListener("click", resetView);
const projected = new THREE.Vector3();
function updateLabels() {
const width = renderer.domElement.clientWidth;
const height = renderer.domElement.clientHeight;
for (const label of labelElements) {
projected.copy(label.anchor).project(camera);
const visible =
projected.z >= -1 &&
projected.z <= 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
label.element.style.display = visible ? "block" : "none";
label.element.style.left =
`${(projected.x * 0.5 + 0.5) * width}px`;
label.element.style.top =
`${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
function onResize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
addEventListener("resize", onResize);
buildFinger(142);
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const smoothing = 1 - Math.exp(-8 * delta);
spherical.radius = THREE.MathUtils.lerp(
spherical.radius,
targetSpherical.radius,
smoothing
);
spherical.theta = THREE.MathUtils.lerp(
spherical.theta,
targetSpherical.theta,
smoothing
);
spherical.phi = THREE.MathUtils.lerp(
spherical.phi,
targetSpherical.phi,
smoothing
);
updateCamera();
updateLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
loading.remove();
</script>
</body>
</html>
```