Prompt specification
Build or customize the Three.js 3D scene "Elbow lever with paired muscle cords" 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: Elbow lever with paired muscle cords
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/elbow-lever-with-paired-muscle-cords-x0977
Scene Description Prompt:
Elbow lever with paired muscle cords. Build a simplified humerus, forearm hinge, and two elastic-looking muscle cords on opposite sides; show attachment points and avoid depicting muscles as pushing rods. Please build this with Three.js from cdnjs in one self-contained HTML file, using a 3D cutaway.
Working Three.js Starter (elbow-lever-with-paired-muscle-cords-x0977):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Elbow Lever — Paired Tensile Muscle Cords</title>
<style>
:root {
color-scheme: dark;
--bg: #07131d;
--panel: rgba(9, 24, 36, 0.9);
--line: rgba(159, 207, 222, 0.18);
--text: #eaf5f7;
--muted: #9bb3bd;
--flexor: #ff7168;
--extensor: #b86cff;
--bone: #f0ddba;
--gold: #e7bc68;
}
* {
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;
}
body::before {
content: "";
position: fixed;
inset: 0;
pointer-events: none;
z-index: 1;
background:
radial-gradient(circle at 45% 42%, transparent 28%, rgba(1, 8, 14, 0.38) 100%),
linear-gradient(180deg, rgba(16, 47, 61, 0.12), transparent 42%);
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
#leaders {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
z-index: 2;
pointer-events: none;
}
#leaders line {
stroke-width: 1;
stroke-dasharray: 3 4;
opacity: 0.72;
}
#labels {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
}
.callout {
position: absolute;
min-width: 138px;
max-width: 220px;
padding: 8px 11px;
transform: translate(-50%, -50%);
border: 1px solid var(--line);
border-left: 3px solid var(--accent, #8acbd6);
border-radius: 8px;
background: rgba(5, 17, 27, 0.83);
box-shadow: 0 10px 28px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(8px);
white-space: nowrap;
}
.callout b {
display: block;
color: var(--text);
font-size: 12px;
font-weight: 700;
letter-spacing: 0.015em;
}
.callout span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.panel {
position: fixed;
top: 20px;
right: 20px;
z-index: 10;
width: min(342px, calc(100vw - 40px));
padding: 18px;
border: 1px solid var(--line);
border-radius: 15px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.34);
backdrop-filter: blur(14px);
}
.eyebrow {
color: #7dcbd5;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 5px 0 4px;
color: var(--text);
font-size: 22px;
line-height: 1.15;
letter-spacing: -0.025em;
}
.subtitle {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.divider {
height: 1px;
margin: 15px 0;
background: var(--line);
}
.row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.row label {
color: var(--text);
font-size: 12px;
font-weight: 650;
}
.value {
color: var(--gold);
font-variant-numeric: tabular-nums;
font-size: 13px;
font-weight: 800;
}
input[type="range"] {
width: 100%;
margin: 12px 0 5px;
accent-color: var(--gold);
cursor: pointer;
}
.buttons {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 7px;
margin-top: 12px;
}
button {
min-height: 34px;
padding: 7px 8px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255, 255, 255, 0.035);
color: var(--text);
font: inherit;
font-size: 10px;
font-weight: 700;
cursor: pointer;
transition: background 140ms ease, border-color 140ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.08);
border-color: rgba(159, 207, 222, 0.38);
}
button.active {
border-color: rgba(231, 188, 104, 0.6);
background: rgba(231, 188, 104, 0.13);
color: #ffe1a9;
}
.check {
display: flex;
align-items: center;
gap: 8px;
margin-top: 11px;
color: var(--muted);
font-size: 11px;
cursor: pointer;
}
.check input {
accent-color: var(--gold);
}
.legend {
display: grid;
gap: 8px;
margin-top: 13px;
}
.legend-item {
display: flex;
align-items: center;
gap: 9px;
color: var(--muted);
font-size: 10px;
}
.swatch {
width: 20px;
height: 4px;
flex: 0 0 auto;
border-radius: 99px;
background: var(--swatch);
box-shadow: 0 0 10px color-mix(in srgb, var(--swatch) 55%, transparent);
}
.dot {
width: 9px;
height: 9px;
margin-left: 5px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--swatch);
box-shadow: 0 0 0 3px color-mix(in srgb, var(--swatch) 18%, transparent);
}
.note {
margin: 13px 0 0;
padding: 10px;
border: 1px solid rgba(231, 188, 104, 0.2);
border-radius: 9px;
background: rgba(231, 188, 104, 0.055);
color: #c7d2d5;
font-size: 10px;
line-height: 1.48;
}
.note strong {
color: #f0cc8b;
}
#status {
margin-top: 11px;
color: #c4d5da;
font-size: 10px;
line-height: 1.45;
}
.hint {
position: fixed;
left: 20px;
bottom: 18px;
z-index: 4;
padding: 8px 10px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(5, 17, 27, 0.66);
color: var(--muted);
font-size: 10px;
pointer-events: none;
backdrop-filter: blur(7px);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: var(--bg);
color: #a8c7cf;
font-size: 12px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 720px) {
.panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
padding: 13px;
}
h1 {
font-size: 18px;
}
.subtitle,
.divider,
.legend,
.note {
display: none;
}
.buttons {
margin-top: 8px;
}
.hint {
top: 10px;
bottom: auto;
left: 10px;
}
.callout.detail {
display: none !important;
}
.callout {
min-width: 112px;
padding: 6px 8px;
}
.callout b {
font-size: 10px;
}
.callout span {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene"></canvas>
<svg id="leaders" aria-hidden="true">
<line id="leadFlexor"></line>
<line id="leadExtensor"></line>
<line id="leadFlexInsert"></line>
<line id="leadExtInsert"></line>
<line id="leadHinge"></line>
</svg>
<div id="labels">
<div id="labelFlexor" class="callout" style="--accent: var(--flexor)">
<b>Biceps-like flexor cord</b>
<span>Pulls the radial insertion toward its origin</span>
</div>
<div id="labelExtensor" class="callout" style="--accent: var(--extensor)">
<b>Triceps-like extensor cord</b>
<span>Pulls the olecranon insertion toward its origin</span>
</div>
<div id="labelFlexInsert" class="callout detail" style="--accent: var(--flexor)">
<b>Radial insertion</b>
<span>Attachment point on the moving forearm</span>
</div>
<div id="labelExtInsert" class="callout detail" style="--accent: var(--extensor)">
<b>Olecranon insertion</b>
<span>Attachment point on the moving forearm</span>
</div>
<div id="labelHinge" class="callout detail" style="--accent: var(--gold)">
<b>Elbow hinge</b>
<span>Flexion and extension axis</span>
</div>
</div>
<aside class="panel">
<div class="eyebrow">3D anatomical cutaway</div>
<h1>Elbow lever</h1>
<p class="subtitle">
A simplified humerus and forearm hinge with paired, elastic muscle cords
anchored on opposing sides.
</p>
<div class="divider"></div>
<div class="row">
<label for="flex">Elbow flexion</label>
<span id="angleValue" class="value">28°</span>
</div>
<input
id="flex"
type="range"
min="0"
max="110"
step="1"
value="28"
aria-label="Elbow flexion angle"
>
<div class="buttons">
<button id="auto" class="active">Auto flex</button>
<button id="neutral">Neutral</button>
<button id="resetView">Reset view</button>
</div>
<label class="check">
<input id="cutaway" type="checkbox" checked>
Show translucent tissue and cut surfaces
</label>
<div class="divider"></div>
<div class="legend">
<div class="legend-item">
<span class="swatch" style="--swatch: var(--flexor)"></span>
Flexor cord · shortens during flexion
</div>
<div class="legend-item">
<span class="swatch" style="--swatch: var(--extensor)"></span>
Extensor cord · yields during flexion
</div>
<div class="legend-item">
<span class="dot" style="--swatch: #f7d994"></span>
Attachment points
</div>
<div class="legend-item">
<span class="swatch" style="--swatch: var(--bone)"></span>
Humerus, radius and ulna
</div>
</div>
<p class="note">
<strong>Tension members only.</strong> Both cords pull between their
attachment points. They are not rigid push rods and cannot transmit
compression into the forearm.
</p>
<div id="status" aria-live="polite">
Flexion coordinated tension
</div>
</aside>
<div class="hint">Drag to orbit · wheel/pinch to zoom · double-click to reset</div>
<div id="loading">Loading anatomical cutaway…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
const canvas = $("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131d);
scene.fog = new THREE.FogExp2(0x07131d, 0.045);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Custom orbit state and controls; no examples/addons are imported.
const orbit = {
theta: 0.64,
phi: 1.22,
radius: 9.5,
target: new THREE.Vector3(0, 0.15, 0)
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.cos(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.sin(orbit.theta)
);
camera.lookAt(orbit.target);
camera.updateMatrixWorld();
}
function resetCamera() {
orbit.theta = 0.64;
orbit.phi = 1.22;
orbit.radius = 9.5;
orbit.target.set(0, 0.15, 0);
updateCamera();
}
updateCamera();
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.006,
0.38,
2.72
);
updateCamera();
});
const endDrag = (event) => {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
};
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
5.2,
15
);
updateCamera();
}, { passive: false });
canvas.addEventListener("dblclick", resetCamera);
// Lighting
scene.add(new THREE.HemisphereLight(0xb9e5ef, 0x18202c, 2.0));
const keyLight = new THREE.DirectionalLight(0xfff0d8, 3.0);
keyLight.position.set(4.5, 7, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -6;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x4fb9dc, 2.2);
rimLight.position.set(-5, 2, -4);
scene.add(rimLight);
const warmFill = new THREE.PointLight(0xff866f, 18, 12, 2);
warmFill.position.set(2.5, 0.5, 3.5);
scene.add(warmFill);
// Subtle floor grid
const grid = new THREE.GridHelper(16, 32, 0x31596a, 0x17313e);
grid.position.y = -2.92;
grid.material.transparent = true;
grid.material.opacity = 0.28;
grid.material.depthWrite = false;
scene.add(grid);
// Materials
const boneMaterial = new THREE.MeshStandardMaterial({
color: 0xf0ddba,
roughness: 0.65,
metalness: 0.02
});
const boneAccentMaterial = new THREE.MeshStandardMaterial({
color: 0xd8bc91,
roughness: 0.72,
metalness: 0.01
});
const jointMaterial = new THREE.MeshStandardMaterial({
color: 0xe8c99b,
roughness: 0.48,
metalness: 0.03
});
const hingeMaterial = new THREE.MeshStandardMaterial({
color: 0xe7bc68,
roughness: 0.32,
metalness: 0.25,
emissive: 0x3d2607,
emissiveIntensity: 0.28
});
const tissueMaterial = new THREE.MeshPhysicalMaterial({
color: 0xe49a91,
roughness: 0.48,
transparent: true,
opacity: 0.15,
side: THREE.DoubleSide,
depthWrite: false
});
const cutMaterial = new THREE.MeshPhysicalMaterial({
color: 0xf29a9a,
roughness: 0.52,
transparent: true,
opacity: 0.26,
side: THREE.DoubleSide,
depthWrite: false
});
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x765f46,
transparent: true,
opacity: 0.24
});
const anatomy = new THREE.Group();
scene.add(anatomy);
const upperArm = new THREE.Group();
const forearm = new THREE.Group();
anatomy.add(upperArm, forearm);
// The forearm rotates around the local Z axis at the elbow.
const upperTissue = new THREE.Group();
const forearmTissue = new THREE.Group();
upperArm.add(upperTissue);
forearm.add(forearmTissue);
function addLathe(profile, material, position = null) {
const geometry = new THREE.LatheGeometry(profile, 36);
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
if (position) mesh.position.copy(position);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry, 28),
edgeMaterial
);
mesh.add(edges);
return mesh;
}
function addSphere(radius, material, position, scale = null) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(radius, 28, 20),
material
);
mesh.position.copy(position);
if (scale) mesh.scale.copy(scale);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
// Simplified humerus: long shaft with expanded proximal and distal ends.
const humerusProfile = [
new THREE.Vector2(0.12, 0.03),
new THREE.Vector2(0.40, 0.10),
new THREE.Vector2(0.45, 0.27),
new THREE.Vector2(0.28, 0.48),
new THREE.Vector2(0.20, 0.67),
new THREE.Vector2(0.18, 2.04),
new THREE.Vector2(0.24, 2.34),
new THREE.Vector2(0.39, 2.56),
new THREE.Vector2(0.37, 2.76),
new THREE.Vector2(0.13, 2.87)
];
upperArm.add(addLathe(humerusProfile, boneMaterial));
// Distal humeral condyles.
upperArm.add(
addSphere(
0.29,
jointMaterial,
new THREE.Vector3(-0.19, 0.09, 0.01),
new THREE.Vector3(1.0, 0.86, 0.96)
)
);
upperArm.add(
addSphere(
0.29,
jointMaterial,
new THREE.Vector3(0.19, 0.09, 0.01),
new THREE.Vector3(1.0, 0.86, 0.96)
)
);
// Proximal shoulder region.
upperArm.add(
addSphere(
0.39,
boneAccentMaterial,
new THREE.Vector3(0, 2.78, -0.01),
new THREE.Vector3(1.05, 0.82, 0.94)
)
);
// Ulna: enlarged proximal olecranon region tapering toward the wrist.
const ulnaProfile = [
new THREE.Vector2(0.11, -2.49),
new THREE.Vector2(0.18, -2.40),
new THREE.Vector2(0.15, -2.17),
new THREE.Vector2(0.11, -0.76),
new THREE.Vector2(0.16, -0.36),
new THREE.Vector2(0.29, -0.17),
new THREE.Vector2(0.24, -0.05),
new THREE.Vector2(0.09, 0.02)
];
forearm.add(
addLathe(
ulnaProfile,
boneMaterial,
new THREE.Vector3(-0.17, 0, -0.08)
)
);
// Radius with a small disc-shaped head near the elbow.
const radiusProfile = [
new THREE.Vector2(0.13, -2.61),
new THREE.Vector2(0.20, -2.53),
new THREE.Vector2(0.16, -2.35),
new THREE.Vector2(0.105, -0.61),
new THREE.Vector2(0.13, -0.39),
new THREE.Vector2(0.18, -0.25),
new THREE.Vector2(0.10, -0.16)
];
forearm.add(
addLathe(
radiusProfile,
boneAccentMaterial,
new THREE.Vector3(0.23, 0, 0.12)
)
);
forearm.add(
addSphere(
0.19,
jointMaterial,
new THREE.Vector3(0.23, -0.28, 0.12),
new THREE.Vector3(1, 0.78, 1)
)
);
// Posterior olecranon process, used as the extensor cord insertion.
forearm.add(
addSphere(
0.27,
boneMaterial,
new THREE.Vector3(-0.39, -0.32, -0.14),
new THREE.Vector3(1.42, 0.65, 0.72)
)
);
// Gold ring identifies the hinge without turning it into a mechanical strut.
const hingeRing = new THREE.Mesh(
new THREE.TorusGeometry(0.31, 0.052, 14, 52),
hingeMaterial
);
hingeRing.position.set(0, 0.01, 0.02);
hingeRing.castShadow = true;
anatomy.add(hingeRing);
// A translucent shell with the camera-facing quadrant removed.
function makeCutShell(parent, radiusTop, radiusBottom, height, centerY) {
const geometry = new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
48,
1,
true,
Math.PI / 2,
Math.PI * 1.5
);
const shell = new THREE.Mesh(geometry, tissueMaterial);
shell.position.y = centerY;
shell.renderOrder = 1;
parent.add(shell);
function cutFace(theta, radius) {
const radial = new THREE.Vector3(
Math.sin(theta),
0,
Math.cos(theta)
);
const face = new THREE.Mesh(
new THREE.PlaneGeometry(0.09, height),
cutMaterial
);
face.position.set(
radial.x * radius,
centerY,
radial.z * radius
);
face.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
radial
);
face.renderOrder = 2;
parent.add(face);
}
cutFace(Math.PI / 2, (radiusTop + radiusBottom) * 0.5);
cutFace(Math.PI * 2, (radiusTop + radiusBottom) * 0.5);
}
makeCutShell(upperTissue, 0.70, 0.55, 2.72, 1.48);
makeCutShell(forearmTissue, 0.48, 0.30, 2.50, -1.35);
// Flexible, tapered tube with visible longitudinal fiber strands.
class ElasticCord {
constructor(color, radius, segments = 46, radialSegments = 10) {
this.color = new THREE.Color(color);
this.radius = radius;
this.segments = segments;
this.radialSegments = radialSegments;
this.group = new THREE.Group();
scene.add(this.group);
const vertexCount = (segments + 1) * (radialSegments + 1);
this.positions = new Float32Array(vertexCount * 3);
this.normals = new Float32Array(vertexCount * 3);
const uvs = new Float32Array(vertexCount * 2);
const indices = [];
for (let i = 0; i <= segments; i++) {
for (let j = 0; j <= radialSegments; j++) {
const index = i * (radialSegments + 1) + j;
uvs[index * 2] = i / segments;
uvs[index * 2 + 1] = j / radialSegments;
}
}
for (let i = 0; i < segments; i++) {
for (let j = 0; j < radialSegments; j++) {
const a = i * (radialSegments + 1) + j;
const b = (i + 1) * (radialSegments + 1) + j;
const c = (i + 1) * (radialSegments + 1) + j + 1;
const d = i * (radialSegments + 1) + j + 1;
indices.push(a, b, d, b, c, d);
}
}
this.geometry = new THREE.BufferGeometry();
this.geometry.setAttribute(
"position",
new THREE.BufferAttribute(this.positions, 3)
.setUsage(THREE.DynamicDrawUsage)
);
this.geometry.setAttribute(
"normal",
new THREE.BufferAttribute(this.normals, 3)
.setUsage(THREE.DynamicDrawUsage)
);
this.geometry.setAttribute("uv", new THREE.BufferAttribute(uvs, 2));
this.geometry.setIndex(indices);
this.material = new THREE.MeshPhysicalMaterial({
color: this.color,
roughness: 0.37,
metalness: 0,
clearcoat: 0.58,
clearcoatRoughness: 0.42,
emissive: this.color.clone().multiplyScalar(0.08),
emissiveIntensity: 0.15,
side: THREE.DoubleSide
});
this.mesh = new THREE.Mesh(this.geometry, this.material);
this.mesh.castShadow = true;
this.mesh.receiveShadow = true;
this.mesh.frustumCulled = false;
this.group.add(this.mesh);
this.strandMaterial = new THREE.LineBasicMaterial({
color: this.color.clone().lerp(new THREE.Color(0xffffff), 0.58),
transparent: true,
opacity: 0.58
});
this.strands = [];
for (let s = 0; s < 3; s++) {
const positions = new Float32Array((segments + 1) * 3);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3)
.setUsage(THREE.DynamicDrawUsage)
);
const line = new THREE.Line(geometry, this.strandMaterial);
line.frustumCulled = false;
this.group.add(line);
this.strands.push(line);
}
}
update(points, tension) {
const curve = new THREE.CatmullRomCurve3(
points,
false,
"centripetal"
);
const frames = curve.computeFrenetFrames(
this.segments,
false
);
const positionAttribute = this.geometry.getAttribute("position");
const normalAttribute = this.geometry.getAttribute("normal");
const point = new THREE.Vector3();
const radial = new THREE.Vector3();
for (let i = 0; i <= this.segments; i++) {
const t = i / this.segments;
curve.getPointAt(t, point);
const normal = frames.normals[i];
const binormal = frames.binormals[i];
const bellyT = THREE.MathUtils.clamp((t - 0.04) / 0.92, 0, 1);
const belly = Math.pow(Math.sin(Math.PI * bellyT), 0.72);
const taper = 0.32 + 0.68 * belly;
const tensionThinning = 1 - 0.13 * tension;
const localRadius = this.radius * taper * tensionThinning;
for (let j = 0; j <= this.radialSegments; j++) {
const angle = (j / this.radialSegments) * Math.PI * 2;
const cos = Math.cos(angle);
const sin = Math.sin(angle);
radial
.copy(normal)
.multiplyScalar(cos)
.addScaledVector(binormal, sin)
.normalize();
const index = i * (this.radialSegments + 1) + j;
const offset = index * 3;
positionAttribute.array[offset] =
point.x + radial.x * localRadius;
positionAttribute.array[offset + 1] =
point.y + radial.y * localRadius;
positionAttribute.array[offset + 2] =
point.z + radial.z * localRadius;
normalAttribute.array[offset] = radial.x;
normalAttribute.array[offset + 1] = radial.y;
normalAttribute.array[offset + 2] = radial.z;
}
}
positionAttribute.needsUpdate = true;
normalAttribute.needsUpdate = true;
this.geometry.computeBoundingSphere();
// Subtle helical surface strands reinforce the elastic-fiber look.
for (let s = 0; s < this.strands.length; s++) {
const line = this.strands[s];
const attribute = line.geometry.getAttribute("position");
for (let i = 0; i <= this.segments; i++) {
const t = i / this.segments;
curve.getPointAt(t, point);
const normal = frames.normals[i];
const binormal = frames.binormals[i];
const bellyT = THREE.MathUtils.clamp((t - 0.04) / 0.92, 0, 1);
const belly = Math.pow(Math.sin(Math.PI * bellyT), 0.72);
const localRadius =
this.radius *
(0.32 + 0.68 * belly) *
(1 - 0.13 * tension) *
1.025;
const angle =
s * (Math.PI * 2 / 3) + t * Math.PI * 2.15;
const cos = Math.cos(angle);
const sin = Math.sin(angle);
const offset = i * 3;
attribute.array[offset] =
point.x + localRadius * (normal.x * cos + binormal.x * sin);
attribute.array[offset + 1] =
point.y + localRadius * (normal.y * cos + binormal.y * sin);
attribute.array[offset + 2] =
point.z + localRadius * (normal.z * cos + binormal.z * sin);
}
attribute.needsUpdate = true;
line.geometry.computeBoundingSphere();
}
this.material.emissiveIntensity = 0.10 + tension * 0.32;
}
}
const flexorCord = new ElasticCord(0xff7168, 0.135);
const extensorCord = new ElasticCord(0xb86cff, 0.125);
// Attachment markers
function makeAttachmentMarker(color) {
const group = new THREE.Group();
const core = new THREE.Mesh(
new THREE.SphereGeometry(0.085, 20, 14),
new THREE.MeshStandardMaterial({
color,
roughness: 0.28,
metalness: 0.08,
emissive: color,
emissiveIntensity: 0.22,
depthTest: false
})
);
core.renderOrder = 20;
group.add(core);
const halo = new THREE.Mesh(
new THREE.SphereGeometry(0.15, 20, 14),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.16,
depthWrite: false,
depthTest: false
})
);
halo.renderOrder = 19;
group.add(halo);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.145, 0.012, 8, 36),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.8,
depthTest: false
})
);
ring.renderOrder = 20;
group.add(ring);
scene.add(group);
return { group, ring };
}
const flexorOriginMarker = makeAttachmentMarker(0xff7168);
const flexorInsertMarker = makeAttachmentMarker(0xff7168);
const extensorOriginMarker = makeAttachmentMarker(0xb86cff);
const extensorInsertMarker = makeAttachmentMarker(0xb86cff);
// Hinge-angle guide
const arcPositions = new Float32Array(33 * 3);
const arcGeometry = new THREE.BufferGeometry();
arcGeometry.setAttribute(
"position",
new THREE.BufferAttribute(arcPositions, 3)
.setUsage(THREE.DynamicDrawUsage)
);
const arc = new THREE.Line(
arcGeometry,
new THREE.LineBasicMaterial({
color: 0xe7bc68,
transparent: true,
opacity: 0.52
})
);
arc.frustumCulled = false;
scene.add(arc);
const arcTip = new THREE.Mesh(
new THREE.SphereGeometry(0.045, 14, 10),
new THREE.MeshBasicMaterial({ color: 0xe7bc68 })
);
scene.add(arcTip);
// Local attachment coordinates
const flexorOriginLocal = new THREE.Vector3(0.43, 2.48, 0.22);
const flexorInsertLocal = new THREE.Vector3(0.29, -1.32, 0.13);
const extensorOriginLocal = new THREE.Vector3(-0.54, 2.56, -0.20);
const extensorInsertLocal = new THREE.Vector3(-0.58, -0.34, -0.17);
function buildCordPoints(origin, insertion, side) {
const delta = insertion.clone().sub(origin);
const p0 = origin.clone();
const p1 = origin.clone()
.addScaledVector(delta, 0.27)
.add(new THREE.Vector3(side * 0.22, 0.015, 0));
const p2 = origin.clone()
.addScaledVector(delta, 0.70)
.add(new THREE.Vector3(side * 0.36, 0.075, 0));
const p3 = insertion.clone();
return [p0, p1, p2, p3];
}
// Motion state
const state = {
flex: 28,
auto: true,
phase: 0,
direction: 1,
showTissue: true
};
function setAuto(enabled) {
state.auto = enabled;
$("auto").classList.toggle("active", enabled);
$("auto").textContent = enabled ? "Auto flex" : "Auto off";
}
$("auto").addEventListener("click", () => setAuto(!state.auto));
$("neutral").addEventListener("click", () => {
setAuto(false);
state.flex = 0;
state.direction = -1;
$("flex").value = "0";
});
$("resetView").addEventListener("click", resetCamera);
$("flex").addEventListener("input", (event) => {
const next = Number(event.target.value);
state.direction = next > state.flex ? 1 : -1;
state.flex = next;
setAuto(false);
});
$("cutaway").addEventListener("change", (event) => {
state.showTissue = event.target.checked;
upperTissue.visible = state.showTissue;
forearmTissue.visible = state.showTissue;
});
// DOM label positioning
function positionLabel(labelId, lineId, worldPosition, offsetX, offsetY) {
const label = $(labelId);
const line = $(lineId);
if (!state.showTissue && labelId === "labelHinge") {
// Keep the hinge label visible regardless of tissue visibility.
}
const projected = worldPosition.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
if (!visible) {
label.style.display = "none";
line.style.display = "none";
return;
}
label.style.display = "block";
line.style.display = "block";
const anchorX = (projected.x * 0.5 + 0.5) * window.innerWidth;
const anchorY = (-projected.y * 0.5 + 0.5) * window.innerHeight;
const mobile = window.innerWidth < 720;
const mobileOffsetX = offsetX * 0.66;
const mobileOffsetY = offsetY * 0.72;
const labelX = THREE.MathUtils.clamp(
anchorX + (mobile ? mobileOffsetX : offsetX),
mobile ? 75 : 125,
window.innerWidth - (mobile ? 75 : 125)
);
const labelY = THREE.MathUtils.clamp(
anchorY + (mobile ? mobileOffsetY : offsetY),
65,
window.innerHeight - 100
);
label.style.left = `${labelX}px`;
label.style.top = `${labelY}px`;
line.setAttribute("x1", anchorX);
line.setAttribute("y1", anchorY);
line.setAttribute("x2", labelX);
line.setAttribute("y2", labelY);
}
const world = {
flexorOrigin: new THREE.Vector3(),
flexorInsert: new THREE.Vector3(),
extensorOrigin: new THREE.Vector3(),
extensorInsert: new THREE.Vector3(),
flexorMid: new THREE.Vector3(),
extensorMid: new THREE.Vector3(),
hinge: new THREE.Vector3(0, 0.02, 0.02)
};
let lastStatus = "";
function updateStatus(flexorTension, extensorTension) {
let text;
if (state.auto && Math.abs(Math.cos(state.phase)) < 0.08) {
text = "Mid-stroke · flexor and extensor cords share tension";
} else if (state.direction > 0) {
text =
"Flexion · flexor cord shortens and pulls; " +
"extensor cord yields";
} else {
text =
"Extension · extensor cord shortens and pulls; " +
"flexor cord yields";
}
if (text !== lastStatus) {
$("status").textContent = text;
lastStatus = text;
}
}
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (state.auto) {
state.phase += delta * 0.72;
const wave = (Math.sin(state.phase) + 1) * 0.5;
state.flex = wave * 110;
state.direction = Math.cos(state.phase) >= 0 ? 1 : -1;
$("flex").value = String(Math.round(state.flex));
}
forearm.rotation.z = THREE.MathUtils.degToRad(state.flex);
$("angleValue").textContent = `${Math.round(state.flex)}°`;
upperArm.updateWorldMatrix(true, true);
forearm.updateWorldMatrix(true, true);
anatomy.updateWorldMatrix(true, true);
world.flexorOrigin.copy(
upperArm.localToWorld(flexorOriginLocal.clone())
);
world.flexorInsert.copy(
forearm.localToWorld(flexorInsertLocal.clone())
);
world.extensorOrigin.copy(
upperArm.localToWorld(extensorOriginLocal.clone())
);
world.extensorInsert.copy(
forearm.localToWorld(extensorInsertLocal.clone())
);
const flexorPoints = buildCordPoints(
world.flexorOrigin,
world.flexorInsert,
1
);
const extensorPoints = buildCordPoints(
world.extensorOrigin,
world.extensorInsert,
-1
);
world.flexorMid.copy(flexorPoints[2]);
world.extensorMid.copy(extensorPoints[2]);
const strokeActivity = state.auto
? 0.42 + Math.abs(Math.cos(state.phase)) * 0.48
: 0.58;
const flexorTension = state.direction > 0
? strokeActivity
: 0.24;
const extensorTension = state.direction < 0
? strokeActivity
: 0.24;
flexorCord.update(flexorPoints, flexorTension);
extensorCord.update(extensorPoints, extensorTension);
flexorOriginMarker.group.position.copy(world.flexorOrigin);
flexorInsertMarker.group.position.copy(world.flexorInsert);
extensorOriginMarker.group.position.copy(world.extensorOrigin);
extensorInsertMarker.group.position.copy(world.extensorInsert);
for (const marker of [
flexorOriginMarker,
flexorInsertMarker,
extensorOriginMarker,
extensorInsertMarker
]) {
marker.ring.quaternion.copy(camera.quaternion);
}
// Update the flexion guide arc.
const arcAngle = THREE.MathUtils.degToRad(state.flex);
for (let i = 0; i <= 32; i++) {
const angle = arcAngle * (i / 32);
arcPositions[i * 3] = Math.sin(angle) * 0.95;
arcPositions[i * 3 + 1] = -Math.cos(angle) * 0.95;
arcPositions[i * 3 + 2] = -0.42;
}
arcGeometry.getAttribute("position").needsUpdate = true;
arc.geometry.computeBoundingSphere();
arcTip.position.set(
Math.sin(arcAngle) * 0.95,
-Math.cos(arcAngle) * 0.95,
-0.42
);
positionLabel(
"labelFlexor",
"leadFlexor",
world.flexorMid,
145,
-62
);
positionLabel(
"labelExtensor",
"leadExtensor",
world.extensorMid,
-145,
-62
);
positionLabel(
"labelFlexInsert",
"leadFlexInsert",
world.flexorInsert,
142,
58
);
positionLabel(
"labelExtInsert",
"leadExtInsert",
world.extensorInsert,
-142,
62
);
positionLabel(
"labelHinge",
"leadHinge",
world.hinge,
108,
72
);
updateStatus(flexorTension, extensorTension);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
}
window.addEventListener("resize", resize);
$("loading").style.display = "none";
animate();
</script>
</body>
</html>
```