Prompt specification
Build or customize the Three.js 3D scene "Joint-angle and muscle-length comparison" 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: Joint-angle and muscle-length comparison
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/joint-angle-and-muscle-length-comparison-x1014
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows proprioception. Animate a simple elbow model while a nearby symbolic sensor indicator changes with muscle length; distinguish the proxy signal from direct angle measurement. A 3D cutaway view.
Working Three.js Starter (joint-angle-and-muscle-length-comparison-x1014):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Elbow Proprioception — Muscle Proxy vs. Direct Angle</title>
<style>
:root {
color-scheme: dark;
--bg: #07111b;
--panel: rgba(10, 21, 34, 0.78);
--panel-strong: rgba(9, 19, 31, 0.92);
--border: rgba(173, 211, 235, 0.16);
--text: #eaf5ff;
--muted: #8da7b9;
--cyan: #59d8ff;
--orange: #ff9a68;
--red: #df4b59;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 55% 40%, #11283a 0%, #07111b 58%, #040a11 100%);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#stage,
#stage canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#stage canvas {
display: block;
cursor: grab;
touch-action: none;
}
#stage canvas.dragging {
cursor: grabbing;
}
.glass {
background: var(--panel);
border: 1px solid var(--border);
box-shadow:
0 18px 60px rgba(0, 0, 0, 0.26),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
backdrop-filter: blur(18px) saturate(125%);
-webkit-backdrop-filter: blur(18px) saturate(125%);
}
.intro {
position: fixed;
z-index: 5;
top: 24px;
left: 26px;
max-width: 390px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 14px var(--cyan);
}
h1 {
margin: 10px 0 7px;
font-size: clamp(24px, 3vw, 39px);
font-weight: 650;
line-height: 0.98;
letter-spacing: -0.045em;
}
.intro p {
margin: 0;
max-width: 350px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 14px;
margin-top: 15px;
color: #b9ccd8;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 7px;
}
.legend i {
width: 9px;
height: 9px;
border-radius: 3px;
box-shadow: 0 0 12px currentColor;
}
.legend .muscle-key {
color: var(--red);
background: var(--red);
}
.legend .direct-key {
color: var(--cyan);
background: var(--cyan);
}
.measurement {
position: fixed;
z-index: 6;
top: 24px;
right: 24px;
width: 242px;
padding: 18px;
border-radius: 18px;
}
.panel-label {
color: var(--cyan);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.measurement-body {
display: flex;
align-items: center;
gap: 14px;
margin-top: 10px;
}
.dial {
position: relative;
width: 78px;
height: 78px;
flex: 0 0 78px;
}
.dial svg {
width: 100%;
height: 100%;
overflow: visible;
}
.dial-track {
fill: none;
stroke: rgba(89, 216, 255, 0.13);
stroke-width: 6;
}
.dial-progress {
fill: none;
stroke: var(--cyan);
stroke-width: 6;
stroke-linecap: round;
stroke-dasharray: 201;
stroke-dashoffset: 201;
filter: drop-shadow(0 0 5px rgba(89, 216, 255, 0.6));
}
.needle {
transform-origin: 46px 46px;
}
.angle-number {
margin-top: 2px;
font-variant-numeric: tabular-nums;
font-size: 34px;
font-weight: 650;
letter-spacing: -0.05em;
}
.angle-number small {
color: var(--cyan);
font-size: 17px;
}
.source {
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid rgba(255, 255, 255, 0.07);
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.source strong {
display: block;
margin-bottom: 3px;
color: #c6d8e3;
font-size: 9px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#leader {
position: fixed;
z-index: 4;
inset: 0;
width: 100%;
height: 100%;
overflow: visible;
pointer-events: none;
}
#leader line {
stroke: var(--orange);
stroke-width: 1;
stroke-dasharray: 4 5;
opacity: 0.75;
}
#leader circle {
fill: var(--orange);
stroke: rgba(255, 255, 255, 0.8);
stroke-width: 1.5;
filter: drop-shadow(0 0 7px var(--orange));
}
.sensor-card {
position: fixed;
z-index: 7;
width: 246px;
padding: 15px 16px 14px;
border-radius: 15px;
pointer-events: none;
transform: translateZ(0);
}
.sensor-head {
display: flex;
align-items: center;
justify-content: space-between;
color: var(--orange);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.sensor-symbol {
display: flex;
align-items: center;
gap: 7px;
}
.sensor-symbol i {
width: 8px;
height: 8px;
border: 2px solid var(--orange);
border-radius: 50%;
box-shadow: 0 0 12px var(--orange);
}
.sensor-card h2 {
margin: 10px 0 3px;
font-size: 15px;
font-weight: 650;
letter-spacing: -0.02em;
}
.sensor-subtitle {
color: var(--muted);
font-size: 10px;
}
.proxy-value {
margin-top: 11px;
font-size: 29px;
font-weight: 650;
font-variant-numeric: tabular-nums;
letter-spacing: -0.045em;
}
.proxy-value small {
margin-left: 3px;
color: var(--muted);
font-size: 10px;
font-weight: 600;
letter-spacing: 0.04em;
}
.meter {
display: grid;
grid-template-columns: repeat(12, 1fr);
gap: 3px;
height: 9px;
margin-top: 10px;
}
.meter i {
border-radius: 2px;
background: rgba(255, 154, 104, 0.13);
transition: background 80ms linear, box-shadow 80ms linear;
}
.meter i.active {
background: var(--orange);
box-shadow: 0 0 7px rgba(255, 154, 104, 0.45);
}
.proxy-note {
margin: 11px 0 0;
color: var(--muted);
font-size: 9px;
line-height: 1.5;
}
.proxy-note strong {
color: #ffd1b9;
font-weight: 700;
}
.scope {
position: fixed;
z-index: 5;
left: 24px;
bottom: 24px;
width: 330px;
padding: 15px 17px 13px;
border-radius: 17px;
pointer-events: none;
}
.scope-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
font-size: 11px;
font-weight: 700;
}
.not-equal {
color: var(--muted);
font-size: 10px;
font-weight: 500;
}
.plot-row {
display: grid;
grid-template-columns: 120px 1fr;
align-items: center;
gap: 10px;
margin-top: 8px;
}
.plot-label {
color: #b9cbd7;
font-size: 9px;
line-height: 1.35;
}
.plot-label b {
display: block;
margin-top: 2px;
color: var(--text);
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.plot-label span {
display: inline-block;
width: 7px;
height: 7px;
margin-right: 5px;
border-radius: 50%;
}
.plot-label .angle-dot {
background: var(--cyan);
box-shadow: 0 0 7px var(--cyan);
}
.plot-label .length-dot {
background: var(--orange);
box-shadow: 0 0 7px var(--orange);
}
.plot {
display: block;
width: 100%;
height: 42px;
overflow: visible;
}
.plot .grid {
stroke: rgba(255, 255, 255, 0.08);
stroke-width: 1;
}
.plot polyline {
fill: none;
stroke-width: 1.8;
stroke-linecap: round;
stroke-linejoin: round;
}
#angleTrace {
stroke: var(--cyan);
filter: drop-shadow(0 0 3px rgba(89, 216, 255, 0.5));
}
#lengthTrace {
stroke: var(--orange);
filter: drop-shadow(0 0 3px rgba(255, 154, 104, 0.45));
}
.scope-foot {
margin-top: 9px;
padding-top: 9px;
border-top: 1px solid rgba(255, 255, 255, 0.07);
color: var(--muted);
font-size: 9px;
line-height: 1.45;
}
.controls {
position: fixed;
z-index: 8;
left: 50%;
bottom: 24px;
display: flex;
align-items: center;
gap: 13px;
width: min(510px, calc(100vw - 32px));
padding: 11px 13px;
border-radius: 17px;
transform: translateX(-50%);
}
.control-button {
height: 36px;
padding: 0 13px;
border: 1px solid rgba(255, 255, 255, 0.11);
border-radius: 10px;
background: rgba(255, 255, 255, 0.055);
color: var(--text);
cursor: pointer;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.05em;
text-transform: uppercase;
transition: background 150ms, border-color 150ms;
}
.control-button:hover {
border-color: rgba(89, 216, 255, 0.35);
background: rgba(89, 216, 255, 0.09);
}
#playPause {
min-width: 76px;
color: var(--cyan);
}
.slider-wrap {
display: flex;
flex: 1;
align-items: center;
gap: 10px;
min-width: 100px;
}
.slider-wrap label {
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
input[type="range"] {
width: 100%;
height: 4px;
border-radius: 999px;
appearance: none;
background: linear-gradient(
to right,
var(--cyan) 0%,
var(--cyan) var(--fill, 0%),
rgba(255, 255, 255, 0.12) var(--fill, 0%),
rgba(255, 255, 255, 0.12) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
border: 3px solid #0c1b29;
border-radius: 50%;
appearance: none;
background: var(--cyan);
box-shadow: 0 0 9px rgba(89, 216, 255, 0.7);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #0c1b29;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 9px rgba(89, 216, 255, 0.7);
}
.hint {
position: fixed;
z-index: 4;
right: 26px;
bottom: 99px;
color: rgba(170, 195, 211, 0.66);
font-size: 9px;
letter-spacing: 0.05em;
pointer-events: none;
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #07111b;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 350ms;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
.scope {
display: none;
}
.hint {
display: none;
}
.measurement {
width: 196px;
}
.measurement-body {
gap: 8px;
}
.dial {
width: 64px;
height: 64px;
flex-basis: 64px;
}
.angle-number {
font-size: 28px;
}
}
@media (max-width: 620px) {
.intro {
top: 14px;
left: 14px;
max-width: calc(100vw - 205px);
}
h1 {
font-size: 21px;
}
.intro p,
.legend {
display: none;
}
.measurement {
top: 14px;
right: 12px;
width: 164px;
padding: 13px;
}
.measurement-body {
margin-top: 7px;
}
.dial {
display: none;
}
.angle-number {
font-size: 27px;
}
.source {
display: none;
}
.sensor-card {
width: 205px;
padding: 12px;
}
.sensor-card h2 {
font-size: 13px;
}
.proxy-note {
font-size: 8px;
}
.controls {
bottom: 12px;
gap: 8px;
padding: 9px;
}
.control-button {
padding: 0 9px;
}
#resetView {
display: none;
}
.slider-wrap label {
display: none;
}
}
</style>
</head>
<body>
<div id="stage" aria-label="Interactive 3D cutaway elbow model"></div>
<svg id="leader" aria-hidden="true">
<line id="leaderLine" x1="0" y1="0" x2="0" y2="0"></line>
<circle id="leaderDot" cx="0" cy="0" r="4"></circle>
</svg>
<header class="intro">
<div class="eyebrow">
<span class="live-dot"></span>
Live proprioception model
</div>
<h1>Elbow<br>proprioception</h1>
<p>
A 3D cutaway comparing a muscle-length proxy with a direct joint-angle
measurement. They are related cues, but they are not the same signal.
</p>
<div class="legend">
<span><i class="muscle-key"></i> Muscle / proxy</span>
<span><i class="direct-key"></i> Joint / direct</span>
</div>
</header>
<aside class="measurement glass" aria-label="Direct angle measurement">
<div class="panel-label">Direct angle measurement</div>
<div class="measurement-body">
<div class="dial" aria-hidden="true">
<svg viewBox="0 0 92 92">
<circle class="dial-track" cx="46" cy="46" r="32"></circle>
<circle
id="dialProgress"
class="dial-progress"
cx="46"
cy="46"
r="32"
transform="rotate(-90 46 46)"
></circle>
<g class="needle" id="angleNeedle">
<line
x1="46"
y1="46"
x2="46"
y2="17"
stroke="#59d8ff"
stroke-width="2.2"
stroke-linecap="round"
></line>
<circle cx="46" cy="46" r="4" fill="#59d8ff"></circle>
</g>
</svg>
</div>
<div>
<div class="angle-number">
<span id="directAngle">0</span><small>°</small>
</div>
<div class="source">
<strong>Rotary joint encoder</strong>
Measures elbow rotation directly in degrees.
</div>
</div>
</div>
</aside>
<div id="sensorPopover" class="sensor-card glass" aria-live="polite">
<div class="sensor-head">
<span class="sensor-symbol"><i></i> Symbolic sensor</span>
<span>Proxy</span>
</div>
<h2>Muscle-length proxy</h2>
<div class="sensor-subtitle">Estimated from the simulated muscle path</div>
<div class="proxy-value">
<span id="proxyLength">—</span><small>model mm</small>
</div>
<div class="meter" id="proxyMeter" aria-hidden="true"></div>
<p class="proxy-note">
<strong>From:</strong> changing muscle-path length.<br>
<strong>Not:</strong> a direct reading of joint angle.
</p>
</div>
<section class="scope glass" aria-label="Separate signal plots">
<div class="scope-title">
<span>Two different quantities</span>
<span class="not-equal">separate scales / separate sources</span>
</div>
<div class="plot-row">
<div class="plot-label">
<span class="angle-dot"></span>Direct angle
<b id="scopeAngle">0°</b>
</div>
<svg class="plot" viewBox="0 0 260 42" preserveAspectRatio="none">
<path class="grid" d="M0 10H260 M0 21H260 M0 32H260"></path>
<polyline id="angleTrace" points=""></polyline>
</svg>
</div>
<div class="plot-row">
<div class="plot-label">
<span class="length-dot"></span>Muscle proxy
<b id="scopeLength">— mm</b>
</div>
<svg class="plot" viewBox="0 0 260 42" preserveAspectRatio="none">
<path class="grid" d="M0 10H260 M0 21H260 M0 32H260"></path>
<polyline id="lengthTrace" points=""></polyline>
</svg>
</div>
<div class="scope-foot">
The cyan trace is an encoder angle. The orange trace is an estimated
musculotendinous path length and must not be interpreted as degrees.
</div>
</section>
<div class="controls glass">
<button id="playPause" class="control-button" type="button">Pause</button>
<div class="slider-wrap">
<label for="angleSlider">Scrub</label>
<input
id="angleSlider"
type="range"
min="0"
max="145"
step="0.1"
value="12"
aria-label="Scrub elbow flexion"
>
</div>
<button id="resetView" class="control-button" type="button">Reset view</button>
</div>
<div class="hint">Drag to orbit · scroll or pinch to zoom · double-click to reset</div>
<div id="loading">Initializing 3D model…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// DOM references and constants
// ---------------------------------------------------------------------
const stage = document.querySelector("#stage");
const loading = document.querySelector("#loading");
const directAngleEl = document.querySelector("#directAngle");
const scopeAngleEl = document.querySelector("#scopeAngle");
const scopeLengthEl = document.querySelector("#scopeLength");
const proxyLengthEl = document.querySelector("#proxyLength");
const sensorPopover = document.querySelector("#sensorPopover");
const leaderLine = document.querySelector("#leaderLine");
const leaderDot = document.querySelector("#leaderDot");
const angleNeedle = document.querySelector("#angleNeedle");
const dialProgress = document.querySelector("#dialProgress");
const angleSlider = document.querySelector("#angleSlider");
const playPause = document.querySelector("#playPause");
const resetView = document.querySelector("#resetView");
const angleTrace = document.querySelector("#angleTrace");
const lengthTrace = document.querySelector("#lengthTrace");
const proxyMeter = document.querySelector("#proxyMeter");
const MAX_ANGLE = 145;
const HISTORY_SIZE = 95;
const Z_AXIS = new THREE.Vector3(0, 0, 1);
for (let i = 0; i < 12; i++) {
proxyMeter.appendChild(document.createElement("i"));
}
const meterSegments = [...proxyMeter.children];
// ---------------------------------------------------------------------
// Renderer, scene, and camera
// ---------------------------------------------------------------------
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.1;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111b);
scene.fog = new THREE.FogExp2(0x07111b, 0.035);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Camera controls implemented locally, without OrbitControls.
const cameraState = {
target: new THREE.Vector3(0.12, -0.05, 0),
theta: 0.37,
phi: 1.22,
radius: 7.6
};
function updateCamera() {
const { target, theta, phi, radius } = cameraState;
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + radius * sinPhi * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(target);
}
function resetCamera() {
cameraState.theta = 0.37;
cameraState.phi = 1.22;
cameraState.radius = 7.6;
updateCamera();
}
updateCamera();
// ---------------------------------------------------------------------
// Lighting
// ---------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xbfeaff, 0x182233, 1.9));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(4.5, 7, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -5;
keyLight.shadow.camera.right = 5;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -5;
scene.add(keyLight);
const cyanRim = new THREE.PointLight(0x45c9ff, 18, 9, 2);
cyanRim.position.set(3.4, -0.8, 3.2);
scene.add(cyanRim);
const warmRim = new THREE.PointLight(0xff684e, 13, 7, 2);
warmRim.position.set(-2.8, 1.8, 2.2);
scene.add(warmRim);
// ---------------------------------------------------------------------
// Ground and backdrop
// ---------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.CylinderGeometry(2.8, 2.95, 0.12, 96),
new THREE.MeshStandardMaterial({
color: 0x0b1722,
roughness: 0.8,
metalness: 0.15
})
);
floor.position.y = -3.14;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(7, 28, 0x285069, 0x142a3a);
grid.position.y = -3.065;
grid.material.transparent = true;
grid.material.opacity = 0.38;
scene.add(grid);
const backdropRing = new THREE.Mesh(
new THREE.TorusGeometry(3.15, 0.009, 6, 160),
new THREE.MeshBasicMaterial({
color: 0x2e637c,
transparent: true,
opacity: 0.26
})
);
backdropRing.position.set(0.1, 0.1, -1.25);
scene.add(backdropRing);
// ---------------------------------------------------------------------
// Materials
// ---------------------------------------------------------------------
const skinMaterial = new THREE.MeshPhysicalMaterial({
color: 0xd59682,
roughness: 0.42,
metalness: 0,
transparent: true,
opacity: 0.145,
side: THREE.DoubleSide,
depthWrite: false
});
const cutEdgeMaterial = new THREE.LineBasicMaterial({
color: 0xffb499,
transparent: true,
opacity: 0.66
});
const boneMaterial = new THREE.MeshStandardMaterial({
color: 0xf0dfc1,
roughness: 0.56,
metalness: 0.02
});
const jointMaterial = new THREE.MeshStandardMaterial({
color: 0xe9d7b8,
roughness: 0.38,
metalness: 0.05
});
const muscleMaterial = new THREE.MeshStandardMaterial({
color: 0xc83e4e,
roughness: 0.48,
metalness: 0,
emissive: 0x3b050b,
emissiveIntensity: 0.28
});
const tendonMaterial = new THREE.MeshStandardMaterial({
color: 0xf5d8bd,
roughness: 0.62
});
const encoderMaterial = new THREE.MeshStandardMaterial({
color: 0x44c8ef,
emissive: 0x0c7191,
emissiveIntensity: 1.5,
roughness: 0.28,
metalness: 0.2
});
// ---------------------------------------------------------------------
// Cutaway shell helper
// ---------------------------------------------------------------------
function createCutawayShell({
topRadius,
bottomRadius,
height,
y,
thetaStart = Math.PI * 0.22,
thetaLength = Math.PI * 1.56
}) {
const group = new THREE.Group();
group.position.y = y;
const geometry = new THREE.CylinderGeometry(
topRadius,
bottomRadius,
height,
64,
1,
true,
thetaStart,
thetaLength
);
const shell = new THREE.Mesh(geometry, skinMaterial);
shell.renderOrder = 4;
group.add(shell);
const edgePoints = [];
for (const theta of [thetaStart, thetaStart + thetaLength]) {
const bottomR = bottomRadius;
const topR = topRadius;
edgePoints.push(
new THREE.Vector3(
Math.sin(theta) * bottomR,
-height / 2,
Math.cos(theta) * bottomR
),
new THREE.Vector3(
Math.sin(theta) * topR,
height / 2,
Math.cos(theta) * topR
)
);
}
const edgeGeometry = new THREE.BufferGeometry().setFromPoints(edgePoints);
group.add(new THREE.LineSegments(edgeGeometry, cutEdgeMaterial));
return group;
}
// ---------------------------------------------------------------------
// Upper arm
// ---------------------------------------------------------------------
scene.add(
createCutawayShell({
topRadius: 0.49,
bottomRadius: 0.39,
height: 2.55,
y: 1.43
})
);
const humerus = new THREE.Mesh(
new THREE.CylinderGeometry(0.145, 0.195, 2.3, 28),
boneMaterial
);
humerus.position.y = 1.4;
humerus.castShadow = true;
scene.add(humerus);
const shoulderBone = new THREE.Mesh(
new THREE.SphereGeometry(0.25, 32, 24),
boneMaterial
);
shoulderBone.position.set(0, 2.5, 0);
shoulderBone.scale.set(1, 0.78, 1);
shoulderBone.castShadow = true;
scene.add(shoulderBone);
const elbowBone = new THREE.Mesh(
new THREE.SphereGeometry(0.235, 32, 24),
jointMaterial
);
elbowBone.position.set(0, 0.02, 0);
elbowBone.castShadow = true;
scene.add(elbowBone);
const shoulderSkin = new THREE.Mesh(
new THREE.SphereGeometry(0.43, 40, 28),
skinMaterial
);
shoulderSkin.position.set(0, 2.56, 0);
shoulderSkin.scale.set(1, 0.62, 1);
shoulderSkin.renderOrder = 4;
scene.add(shoulderSkin);
// ---------------------------------------------------------------------
// Forearm: rotates around the elbow
// ---------------------------------------------------------------------
const forearm = new THREE.Group();
scene.add(forearm);
forearm.add(
createCutawayShell({
topRadius: 0.365,
bottomRadius: 0.285,
height: 3.02,
y: -1.57
})
);
const radiusBone = new THREE.Mesh(
new THREE.CylinderGeometry(0.075, 0.105, 2.78, 24),
boneMaterial
);
radiusBone.position.set(0.135, -1.55, 0.035);
radiusBone.castShadow = true;
forearm.add(radiusBone);
const ulnaBone = new THREE.Mesh(
new THREE.CylinderGeometry(0.095, 0.115, 2.78, 24),
boneMaterial
);
ulnaBone.position.set(-0.13, -1.55, -0.025);
ulnaBone.castShadow = true;
forearm.add(ulnaBone);
for (const x of [0.135, -0.13]) {
const wrist = new THREE.Mesh(
new THREE.SphereGeometry(0.13, 24, 18),
boneMaterial
);
wrist.position.set(x, -2.91, 0);
wrist.scale.set(1, 0.78, 1);
wrist.castShadow = true;
forearm.add(wrist);
}
const jointRing = new THREE.Mesh(
new THREE.TorusGeometry(0.245, 0.043, 12, 48),
jointMaterial
);
jointRing.position.z = 0.06;
jointRing.castShadow = true;
scene.add(jointRing);
// ---------------------------------------------------------------------
// Direct joint encoder and angular arc
// ---------------------------------------------------------------------
const encoder = new THREE.Mesh(
new THREE.CylinderGeometry(0.09, 0.09, 0.055, 32),
encoderMaterial
);
encoder.rotation.x = Math.PI / 2;
encoder.position.set(0, 0, 0.29);
scene.add(encoder);
const angleArcPoints = [];
for (let i = 0; i <= 90; i++) {
const a = THREE.MathUtils.degToRad((i / 90) * MAX_ANGLE);
angleArcPoints.push(
new THREE.Vector3(Math.sin(a) * 1.27, -Math.cos(a) * 1.27, 0.34)
);
}
const angleArc = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(angleArcPoints),
new THREE.LineBasicMaterial({
color: 0x59d8ff,
transparent: true,
opacity: 0.65
})
);
scene.add(angleArc);
const baseline = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0, 0.34),
new THREE.Vector3(0, -1.27, 0.34)
]),
new THREE.LineDashedMaterial({
color: 0x59d8ff,
transparent: true,
opacity: 0.25,
dashSize: 0.07,
gapSize: 0.055
})
);
baseline.computeLineDistances();
scene.add(baseline);
const angleMarker = new THREE.Mesh(
new THREE.SphereGeometry(0.055, 18, 12),
encoderMaterial
);
scene.add(angleMarker);
// ---------------------------------------------------------------------
// Dynamic muscle / musculotendinous path
// ---------------------------------------------------------------------
const attachmentShoulder = new THREE.Vector3(0.14, 2.25, 0.25);
const attachmentBelly = new THREE.Vector3(0.34, 1.47, 0.38);
const attachmentElbow = new THREE.Vector3(0.28, 0.39, 0.40);
const forearmInsertionLocal = new THREE.Vector3(0.18, -0.86, 0.28);
const TUBE_SEGMENTS = 52;
const TUBE_RADIAL = 12;
function createTubeGeometry() {
const geometry = new THREE.BufferGeometry();
const vertexCount = (TUBE_SEGMENTS + 1) * (TUBE_RADIAL + 1);
geometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(vertexCount * 3), 3)
.setUsage(THREE.DynamicDrawUsage)
);
geometry.setAttribute(
"normal",
new THREE.BufferAttribute(new Float32Array(vertexCount * 3), 3)
.setUsage(THREE.DynamicDrawUsage)
);
const indices = [];
for (let i = 0; i < TUBE_SEGMENTS; i++) {
for (let j = 0; j < TUBE_RADIAL; j++) {
const a = i * (TUBE_RADIAL + 1) + j;
const b = (i + 1) * (TUBE_RADIAL + 1) + j;
const c = a + 1;
const d = b + 1;
indices.push(a, b, c, b, d, c);
}
}
geometry.setIndex(indices);
return geometry;
}
const muscleGeometry = createTubeGeometry();
const muscleMesh = new THREE.Mesh(muscleGeometry, muscleMaterial);
muscleMesh.castShadow = true;
muscleMesh.frustumCulled = false;
scene.add(muscleMesh);
const tendonGeometry = createTubeGeometry();
const tendonMesh = new THREE.Mesh(tendonGeometry, tendonMaterial);
tendonMesh.castShadow = true;
tendonMesh.frustumCulled = false;
scene.add(tendonMesh);
function updateTube(geometry, curve, radiusFunction) {
const position = geometry.attributes.position.array;
const normal = geometry.attributes.normal.array;
const referenceAxis = new THREE.Vector3(0, 0, 1);
let pointer = 0;
for (let i = 0; i <= TUBE_SEGMENTS; i++) {
const t = i / TUBE_SEGMENTS;
const center = curve.getPoint(t);
const tangent = curve.getTangent(t).normalize();
const n = new THREE.Vector3().crossVectors(tangent, referenceAxis);
if (n.lengthSq() < 0.0001) {
n.crossVectors(tangent, new THREE.Vector3(1, 0, 0));
}
n.normalize();
const binormal = new THREE.Vector3()
.crossVectors(tangent, n)
.normalize();
const radius = radiusFunction(t);
for (let j = 0; j <= TUBE_RADIAL; j++) {
const theta = (j / TUBE_RADIAL) * Math.PI * 2;
const cos = Math.cos(theta);
const sin = Math.sin(theta);
const nx = n.x * cos + binormal.x * sin;
const ny = n.y * cos + binormal.y * sin;
const nz = n.z * cos + binormal.z * sin;
position[pointer] = center.x + nx * radius;
normal[pointer] = nx;
pointer++;
position[pointer] = center.y + ny * radius;
normal[pointer] = ny;
pointer++;
position[pointer] = center.z + nz * radius;
normal[pointer] = nz;
pointer++;
}
}
geometry.attributes.position.needsUpdate = true;
geometry.attributes.normal.needsUpdate = true;
geometry.computeBoundingSphere();
}
function makeMuscleCurve(angleDegrees) {
const angle = THREE.MathUtils.degToRad(angleDegrees);
const insertion = forearmInsertionLocal
.clone()
.applyAxisAngle(Z_AXIS, angle);
return new THREE.CatmullRomCurve3(
[
attachmentShoulder.clone(),
attachmentBelly.clone(),
attachmentElbow.clone(),
insertion
],
false,
"catmullrom",
0.35
);
}
function measureCurveLength(curve, count = 90) {
let length = 0;
let previous = curve.getPoint(0);
for (let i = 1; i <= count; i++) {
const next = curve.getPoint(i / count);
length += next.distanceTo(previous);
previous = next;
}
return length;
}
const pathAtExtension = measureCurveLength(makeMuscleCurve(0));
const pathAtMaximum = measureCurveLength(makeMuscleCurve(MAX_ANGLE));
const pathRange = {
min: Math.min(pathAtExtension, pathAtMaximum),
max: Math.max(pathAtExtension, pathAtMaximum)
};
// ---------------------------------------------------------------------
// Symbolic proprioceptive sensor
// ---------------------------------------------------------------------
const sensorGroup = new THREE.Group();
scene.add(sensorGroup);
const sensorBody = new THREE.Mesh(
new THREE.CylinderGeometry(0.105, 0.105, 0.07, 32),
new THREE.MeshStandardMaterial({
color: 0x172431,
roughness: 0.3,
metalness: 0.55,
emissive: 0x4b1608,
emissiveIntensity: 0.35
})
);
sensorBody.rotation.x = Math.PI / 2;
sensorGroup.add(sensorBody);
const sensorFace = new THREE.Mesh(
new THREE.CircleGeometry(0.067, 28),
new THREE.MeshBasicMaterial({ color: 0xff9a68 })
);
sensorFace.position.z = 0.038;
sensorGroup.add(sensorFace);
const pulseMaterial = new THREE.MeshBasicMaterial({
color: 0xff9a68,
transparent: true,
opacity: 0.6,
side: THREE.DoubleSide,
depthWrite: false
});
const pulseRing = new THREE.Mesh(
new THREE.TorusGeometry(0.16, 0.009, 8, 48),
pulseMaterial
);
pulseRing.position.z = 0.04;
sensorGroup.add(pulseRing);
// A small spindle-like marker embedded in the muscle belly.
const spindle = new THREE.Mesh(
new THREE.SphereGeometry(0.052, 18, 12),
new THREE.MeshStandardMaterial({
color: 0xffa36e,
emissive: 0x7b260d,
emissiveIntensity: 1.1,
roughness: 0.4
})
);
scene.add(spindle);
// ---------------------------------------------------------------------
// State and signal history
// ---------------------------------------------------------------------
let playing = true;
let simulationTime = 0;
let currentAngle = 12;
let currentProxyLength = pathAtExtension * 78;
let currentCurve = makeMuscleCurve(currentAngle);
let sensorWorldPosition = new THREE.Vector3();
const angleHistory = [];
const lengthHistory = [];
function setPlaying(value) {
playing = value;
playPause.textContent = playing ? "Pause" : "Play";
playPause.setAttribute("aria-pressed", String(!playing));
}
playPause.addEventListener("click", () => setPlaying(!playing));
angleSlider.addEventListener("input", () => {
currentAngle = Number(angleSlider.value);
setPlaying(false);
});
resetView.addEventListener("click", resetCamera);
window.addEventListener("keydown", event => {
if (event.code === "Space") {
event.preventDefault();
setPlaying(!playing);
}
if (event.key.toLowerCase() === "r") {
resetCamera();
}
if (event.key === "ArrowRight") {
currentAngle = Math.min(MAX_ANGLE, currentAngle + 2);
setPlaying(false);
}
if (event.key === "ArrowLeft") {
currentAngle = Math.max(0, currentAngle - 2);
setPlaying(false);
}
});
// ---------------------------------------------------------------------
// Direct pointer camera controls
// ---------------------------------------------------------------------
const pointers = new Map();
let pinchDistance = 0;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
canvas.classList.add("dragging");
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
canvas.addEventListener("pointermove", event => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
if (pointers.size === 1) {
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.006,
0.48,
1.56
);
} else if (pointers.size === 2) {
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
const [a, b] = [...pointers.values()];
const nextDistance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0 && nextDistance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (pinchDistance / nextDistance),
4.7,
11.5
);
}
pinchDistance = nextDistance;
updateCamera();
return;
}
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
if (pointers.size === 0) canvas.classList.remove("dragging");
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
4.7,
11.5
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
// ---------------------------------------------------------------------
// UI update helpers
// ---------------------------------------------------------------------
function tracePoints(values, min, max) {
if (values.length < 2) return "";
return values
.map((value, index) => {
const x = (index / (HISTORY_SIZE - 1)) * 260;
const normalized = (value - min) / Math.max(0.0001, max - min);
const y = 39 - THREE.MathUtils.clamp(normalized, 0, 1) * 35;
return `${x.toFixed(2)},${y.toFixed(2)}`;
})
.join(" ");
}
function updateReadouts() {
const roundedAngle = Math.round(currentAngle);
const roundedLength = Math.round(currentProxyLength);
directAngleEl.textContent = roundedAngle;
scopeAngleEl.textContent = `${roundedAngle}°`;
scopeLengthEl.textContent = `${roundedLength} mm`;
proxyLengthEl.textContent = roundedLength;
angleSlider.value = currentAngle.toFixed(1);
const sliderFill = (currentAngle / MAX_ANGLE) * 100;
angleSlider.style.setProperty("--fill", `${sliderFill}%`);
angleNeedle.setAttribute(
"transform",
`rotate(${currentAngle} 46 46)`
);
const circumference = 2 * Math.PI * 32;
dialProgress.style.strokeDasharray = `${circumference}`;
dialProgress.style.strokeDashoffset = `${
circumference * (1 - currentAngle / MAX_ANGLE)
}`;
const normalizedLength =
(currentProxyLength / 78 - pathRange.min) /
Math.max(0.0001, pathRange.max - pathRange.min);
meterSegments.forEach((segment, index) => {
const active = index / meterSegments.length < normalizedLength;
segment.classList.toggle("active", active);
});
angleTrace.setAttribute(
"points",
tracePoints(angleHistory, 0, MAX_ANGLE)
);
lengthTrace.setAttribute(
"points",
tracePoints(
lengthHistory,
pathRange.min * 78 * 0.94,
pathRange.max * 78 * 1.04
)
);
}
function updateSensorCard() {
const projected = sensorWorldPosition.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
if (!visible) {
sensorPopover.style.visibility = "hidden";
leaderLine.style.display = "none";
leaderDot.style.display = "none";
return;
}
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
const cardWidth = sensorPopover.offsetWidth || 246;
const cardHeight = sensorPopover.offsetHeight || 190;
let cardX = x + 32;
let cardY = y - 28;
let attachX = cardX;
if (cardX + cardWidth > window.innerWidth - 14) {
cardX = x - cardWidth - 32;
attachX = cardX + cardWidth;
}
cardX = THREE.MathUtils.clamp(cardX, 12, window.innerWidth - cardWidth - 12);
cardY = THREE.MathUtils.clamp(
cardY,
86,
window.innerHeight - cardHeight - 96
);
sensorPopover.style.visibility = "visible";
sensorPopover.style.left = `${cardX}px`;
sensorPopover.style.top = `${cardY}px`;
leaderLine.style.display = "";
leaderDot.style.display = "";
leaderLine.setAttribute("x1", x);
leaderLine.setAttribute("y1", y);
leaderLine.setAttribute("x2", attachX);
leaderLine.setAttribute("y2", cardY + 28);
leaderDot.setAttribute("cx", x);
leaderDot.setAttribute("cy", y);
}
// ---------------------------------------------------------------------
// Model update
// ---------------------------------------------------------------------
function updateModel() {
const radians = THREE.MathUtils.degToRad(currentAngle);
forearm.rotation.z = radians;
currentCurve = makeMuscleCurve(currentAngle);
const flexFraction = currentAngle / MAX_ANGLE;
const bulge = 1 + flexFraction * 0.26;
updateTube(
muscleGeometry,
currentCurve,
t => {
if (t < 0.7) {
const belly = Math.sin((t / 0.7) * Math.PI);
return (0.028 + 0.19 * Math.pow(belly, 0.72)) * bulge;
}
const tendonT = (t - 0.7) / 0.3;
return THREE.MathUtils.lerp(0.029, 0.022, tendonT);
}
);
const tendonCurve = new THREE.CatmullRomCurve3([
attachmentElbow.clone(),
currentCurve.getPoint(0.81),
currentCurve.getPoint(1)
]);
updateTube(
tendonGeometry,
tendonCurve,
t => THREE.MathUtils.lerp(0.031, 0.021, t)
);
const pathLength = measureCurveLength(currentCurve);
currentProxyLength = pathLength * 78;
const sensorPoint = currentCurve.getPoint(0.29);
sensorGroup.position.copy(sensorPoint);
sensorGroup.quaternion.copy(camera.quaternion);
spindle.position.copy(currentCurve.getPoint(0.36));
spindle.scale.setScalar(1 + flexFraction * 0.13);
const markerAngle = radians;
angleMarker.position.set(
Math.sin(markerAngle) * 1.27,
-Math.cos(markerAngle) * 1.27,
0.38
);
}
// ---------------------------------------------------------------------
// Resize and main loop
// ---------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
let historyAccumulator = 0;
let uiAccumulator = 0;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
simulationTime += delta;
if (playing) {
const cycle = (1 - Math.cos(simulationTime * 0.68)) * 0.5;
currentAngle = 12 + (MAX_ANGLE - 12) * cycle;
}
updateModel();
const pulse = 0.5 + 0.5 * Math.sin(simulationTime * 4.2);
pulseRing.scale.setScalar(1 + pulse * 0.42);
pulseMaterial.opacity = 0.72 - pulse * 0.42;
historyAccumulator += delta;
if (historyAccumulator > 0.035) {
historyAccumulator = 0;
angleHistory.push(currentAngle);
lengthHistory.push(currentProxyLength);
if (angleHistory.length > HISTORY_SIZE) angleHistory.shift();
if (lengthHistory.length > HISTORY_SIZE) lengthHistory.shift();
}
uiAccumulator += delta;
if (uiAccumulator > 0.025) {
uiAccumulator = 0;
updateReadouts();
}
updateSensorCard();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateModel();
updateReadouts();
renderer.render(scene, camera);
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 400);
animate();
</script>
</body>
</html>
```