Prompt specification
Build or customize the Three.js 3D scene "Elbow moment-arm teaching model" 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 moment-arm teaching model
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/elbow-moment-arm-teaching-model-x0980
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring antagonistic elbow muscles. Let users vary a toy attachment distance and external load; display torque relationships separately from the stylized anatomy and label calculated values as model quantities. Low-poly.
Working Three.js Starter (elbow-moment-arm-teaching-model-x0980):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Elbow Lab — Antagonistic Muscle Model</title>
<style>
:root {
--bg: #e9eef4;
--panel: #f8fafc;
--card: #ffffff;
--ink: #182331;
--muted: #64748b;
--line: #dbe3ec;
--cyan: #08a8bd;
--cyan-soft: #dff7fa;
--pink: #d84f83;
--pink-soft: #fce7ef;
--orange: #e98224;
--orange-soft: #fff0df;
--green: #19865b;
--green-soft: #e1f5eb;
--shadow: 0 8px 24px rgba(25, 42, 64, 0.09);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
border: 0;
}
header {
height: 76px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 0 25px;
background: #14202d;
color: white;
border-bottom: 1px solid rgba(255, 255, 255, 0.09);
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
width: 40px;
height: 40px;
display: grid;
place-items: center;
border: 1px solid rgba(255, 255, 255, 0.18);
border-radius: 11px;
background: rgba(255, 255, 255, 0.07);
flex: 0 0 auto;
}
.brand-mark svg {
width: 25px;
height: 25px;
}
.brand h1 {
margin: 0;
font-size: 17px;
line-height: 1.2;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.brand p {
margin: 4px 0 0;
color: #aab8c8;
font-size: 12px;
}
.header-note {
padding: 7px 11px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 999px;
color: #c8d3df;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.11em;
text-transform: uppercase;
white-space: nowrap;
}
main {
height: calc(100vh - 76px);
display: grid;
grid-template-columns: minmax(0, 1fr) 390px;
}
#viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #e8eef4;
}
#viewport canvas {
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#viewport canvas:active {
cursor: grabbing;
}
.scene-heading {
position: absolute;
top: 20px;
left: 20px;
z-index: 3;
max-width: 310px;
pointer-events: none;
}
.eyebrow {
margin: 0 0 7px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.scene-heading h2 {
margin: 0;
font-size: 21px;
letter-spacing: -0.025em;
}
.scene-heading .sub {
margin: 5px 0 0;
color: var(--muted);
font-size: 12px;
}
.view-tools {
position: absolute;
z-index: 4;
top: 18px;
right: 18px;
display: flex;
gap: 8px;
}
.view-tools button {
padding: 9px 12px;
border: 1px solid rgba(34, 51, 71, 0.13);
border-radius: 9px;
background: rgba(255, 255, 255, 0.88);
color: #334155;
box-shadow: 0 3px 12px rgba(30, 50, 70, 0.07);
font-size: 11px;
font-weight: 750;
cursor: pointer;
backdrop-filter: blur(8px);
}
.view-tools button:hover {
background: white;
transform: translateY(-1px);
}
.view-tools button.active {
color: #087e8e;
border-color: rgba(8, 168, 189, 0.35);
}
.scene-legend {
position: absolute;
left: 20px;
bottom: 20px;
z-index: 3;
display: flex;
flex-wrap: wrap;
gap: 7px;
max-width: calc(100% - 40px);
pointer-events: none;
}
.legend-chip {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 8px 10px;
border: 1px solid rgba(34, 51, 71, 0.1);
border-radius: 9px;
background: rgba(255, 255, 255, 0.84);
color: #475569;
box-shadow: 0 3px 12px rgba(30, 50, 70, 0.05);
font-size: 10px;
font-weight: 700;
backdrop-filter: blur(8px);
}
.dot {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
}
.dot.cyan {
background: var(--cyan);
}
.dot.pink {
background: var(--pink);
}
.dot.orange {
background: var(--orange);
}
.orbit-hint {
position: absolute;
right: 18px;
bottom: 18px;
z-index: 3;
color: #738196;
font-size: 10px;
pointer-events: none;
}
aside {
min-height: 0;
overflow-y: auto;
padding: 20px;
background: var(--panel);
border-left: 1px solid var(--line);
scrollbar-width: thin;
scrollbar-color: #b9c5d2 transparent;
}
.model-badge {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 14px;
}
.model-badge h2 {
margin: 0;
font-size: 16px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.model-badge span {
padding: 6px 8px;
border-radius: 999px;
background: var(--orange-soft);
color: #a75a18;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
.model-intro {
margin: 0 0 15px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.card {
margin-bottom: 13px;
padding: 16px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--card);
box-shadow: var(--shadow);
}
.card-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin: 0 0 14px;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.card-title small {
color: #94a3b8;
font-size: 9px;
letter-spacing: 0.04em;
}
.control + .control {
margin-top: 18px;
}
.control-label {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
}
.control-label label {
color: #334155;
font-size: 12px;
font-weight: 700;
}
.control-label output {
color: #0f172a;
font-size: 13px;
font-weight: 850;
font-variant-numeric: tabular-nums;
}
.range-wrap {
display: flex;
align-items: center;
gap: 9px;
}
.range-wrap span {
width: 20px;
color: #94a3b8;
font-size: 10px;
font-weight: 800;
text-align: center;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 7px 0;
border-radius: 999px;
outline: none;
background: #dce5ee;
appearance: none;
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
border: 3px solid white;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 1px 7px rgba(8, 118, 135, 0.35);
appearance: none;
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid white;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 1px 7px rgba(8, 118, 135, 0.35);
}
#loadRange::-webkit-slider-thumb {
background: var(--orange);
box-shadow: 0 1px 7px rgba(184, 91, 17, 0.3);
}
#loadRange::-moz-range-thumb {
background: var(--orange);
}
.input-caption {
margin: 7px 0 0;
color: #94a3b8;
font-size: 10px;
line-height: 1.4;
}
.balance-equation {
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: center;
gap: 7px;
margin-bottom: 15px;
padding: 11px;
border-radius: 10px;
background: #f4f7fa;
color: #526174;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11px;
text-align: center;
}
.balance-equation strong {
color: #1f2d3c;
font-size: 13px;
}
.torque-row + .torque-row {
margin-top: 12px;
}
.torque-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 5px;
font-size: 10px;
}
.torque-name {
display: flex;
align-items: center;
gap: 7px;
color: #526174;
font-weight: 700;
}
.torque-value {
color: #1e293b;
font-weight: 850;
font-variant-numeric: tabular-nums;
}
.bar-track {
height: 7px;
overflow: hidden;
border-radius: 999px;
background: #edf1f5;
}
.bar {
width: 0;
height: 100%;
border-radius: inherit;
transition: width 160ms ease;
}
.bar.cyan {
background: linear-gradient(90deg, #62ccd9, var(--cyan));
}
.bar.pink {
background: linear-gradient(90deg, #ed8db1, var(--pink));
}
.bar.orange {
background: linear-gradient(90deg, #f4ad62, var(--orange));
}
.net-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 15px;
padding-top: 13px;
border-top: 1px solid var(--line);
font-size: 11px;
}
.net-row span {
color: #526174;
font-weight: 700;
}
.net-row strong {
padding: 5px 8px;
border-radius: 7px;
background: var(--green-soft);
color: var(--green);
font-size: 12px;
font-variant-numeric: tabular-nums;
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.metric {
min-width: 0;
padding: 10px;
border: 1px solid #e6ebf1;
border-radius: 9px;
background: #fafbfd;
}
.metric span {
display: block;
margin-bottom: 5px;
color: #8492a6;
font-size: 9px;
font-weight: 750;
line-height: 1.3;
text-transform: uppercase;
}
.metric strong {
display: block;
color: #243244;
font-size: 13px;
font-variant-numeric: tabular-nums;
}
.pair-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.pair {
padding: 11px;
border-radius: 10px;
}
.pair.flexor {
border: 1px solid #bfe9ee;
background: var(--cyan-soft);
}
.pair.extensor {
border: 1px solid #f1c4d6;
background: var(--pink-soft);
}
.pair strong {
display: block;
font-size: 12px;
}
.pair span {
display: block;
margin-top: 3px;
color: #64748b;
font-size: 9px;
line-height: 1.4;
}
.formula {
margin-top: 10px;
padding: 10px;
border-left: 3px solid #8fa1b5;
border-radius: 0 8px 8px 0;
background: #f4f7fa;
color: #415168;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
line-height: 1.55;
}
.assumptions {
margin: 0;
padding-left: 17px;
color: #64748b;
font-size: 10px;
line-height: 1.6;
}
.assumptions li + li {
margin-top: 4px;
}
.disclaimer {
margin: 13px 2px 0;
color: #8a97a8;
font-size: 9px;
line-height: 1.5;
text-align: center;
}
@media (max-width: 900px) {
html,
body {
overflow: auto;
}
header {
height: auto;
min-height: 76px;
padding: 13px 16px;
}
.header-note {
display: none;
}
main {
height: auto;
display: block;
}
#viewport {
height: 62vh;
min-height: 480px;
}
aside {
overflow: visible;
border-top: 1px solid var(--line);
border-left: 0;
}
.scene-heading {
top: 15px;
left: 15px;
}
.scene-heading h2 {
font-size: 17px;
}
.view-tools {
top: 13px;
right: 12px;
}
.view-tools button {
padding: 8px 9px;
font-size: 10px;
}
.orbit-hint {
display: none;
}
}
@media (max-width: 520px) {
.brand p {
display: none;
}
.brand h1 {
font-size: 14px;
}
.scene-legend {
left: 12px;
bottom: 12px;
}
.legend-chip {
padding: 6px 8px;
font-size: 9px;
}
}
</style>
</head>
<body>
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<svg viewBox="0 0 32 32" fill="none">
<path d="M7 21L14 8L18 17L25 6"
stroke="#67d3df" stroke-width="2.4"
stroke-linecap="round" stroke-linejoin="round"/>
<circle cx="7" cy="21" r="2.5" fill="#f0a765"/>
<circle cx="25" cy="6" r="2.5" fill="#ef82ad"/>
</svg>
</div>
<div>
<h1>Elbow Lab</h1>
<p>Antagonistic flexor–extensor torque model</p>
</div>
</div>
<div class="header-note">Low-poly anatomy · quasi-static model</div>
</header>
<main>
<section id="viewport" aria-label="Interactive low-poly elbow anatomy">
<div class="scene-heading">
<p class="eyebrow">Stylized anatomy · not to scale</p>
<h2>Antagonistic elbow pair</h2>
<p class="sub">Biceps flexes while triceps opposes.</p>
</div>
<div class="view-tools">
<button id="guidesButton" class="active" type="button">Guides on</button>
<button id="resetViewButton" type="button">Reset view</button>
</div>
<div class="scene-legend" aria-hidden="true">
<div class="legend-chip">
<span class="dot cyan"></span>Biceps · flexion
</div>
<div class="legend-chip">
<span class="dot pink"></span>Triceps · extension
</div>
<div class="legend-chip">
<span class="dot orange"></span>Toy load
</div>
</div>
<div class="orbit-hint">Drag to orbit · scroll to zoom</div>
</section>
<aside aria-label="Calculated model quantities">
<div class="model-badge">
<h2>Model quantities</h2>
<span>Calculated · not measured</span>
</div>
<p class="model-intro">
Change the toy’s attachment distance and external load. All numerical
torque results are calculated separately from the schematic anatomy.
</p>
<section class="card">
<h3 class="card-title">
Model inputs
<small>Two variables</small>
</h3>
<div class="control">
<div class="control-label">
<label for="distanceRange">Toy attachment distance, d</label>
<output id="distanceOut" for="distanceRange">18 cm</output>
</div>
<div class="range-wrap">
<span>5</span>
<input id="distanceRange" type="range"
min="5" max="30" step="1" value="18"
aria-label="Toy attachment distance in centimeters">
<span>30</span>
</div>
<p class="input-caption">
Horizontal elbow-to-attachment distance along the modeled forearm.
</p>
</div>
<div class="control">
<div class="control-label">
<label for="loadRange">External load, W</label>
<output id="loadOut" for="loadRange">8 N</output>
</div>
<div class="range-wrap">
<span>0</span>
<input id="loadRange" type="range"
min="0" max="20" step="0.5" value="8"
aria-label="External load in newtons">
<span>20</span>
</div>
<p class="input-caption">
Downward force applied at the toy attachment.
</p>
</div>
</section>
<section class="card">
<h3 class="card-title">
Torque relationship
<small>Flexion positive</small>
</h3>
<div class="balance-equation" aria-label="Static balance equation">
<span>τ<sub>B</sub></span>
<strong>=</strong>
<span>τ<sub>T</sub> + τ<sub>load</sub></span>
</div>
<div class="torque-row">
<div class="torque-head">
<span class="torque-name">
<i class="dot cyan"></i>Biceps flexion torque
</span>
<span id="tauBValue" class="torque-value">1.65 N·m</span>
</div>
<div class="bar-track">
<div id="tauBBar" class="bar cyan"></div>
</div>
</div>
<div class="torque-row">
<div class="torque-head">
<span class="torque-name">
<i class="dot pink"></i>Triceps extension torque
</span>
<span id="tauTValue" class="torque-value">0.21 N·m</span>
</div>
<div class="bar-track">
<div id="tauTBar" class="bar pink"></div>
</div>
</div>
<div class="torque-row">
<div class="torque-head">
<span class="torque-name">
<i class="dot orange"></i>Load extension torque
</span>
<span id="tauLoadValue" class="torque-value">1.44 N·m</span>
</div>
<div class="bar-track">
<div id="tauLoadBar" class="bar orange"></div>
</div>
</div>
<div class="net-row">
<span>Net elbow moment</span>
<strong id="netValue">0.00 N·m</strong>
</div>
</section>
<section class="card">
<h3 class="card-title">
Model estimates
<small>Constant moment arms</small>
</h3>
<div class="metric-grid">
<div class="metric">
<span>Load torque τ<sub>load</sub></span>
<strong id="loadTorqueMetric">1.44 N·m</strong>
</div>
<div class="metric">
<span>Biceps force F<sub>B</sub></span>
<strong id="bicepsForceMetric">47.2 N</strong>
</div>
<div class="metric">
<span>Triceps force F<sub>T</sub></span>
<strong id="tricepsForceMetric">11.8 N</strong>
</div>
<div class="metric">
<span>Biceps moment arm r<sub>B</sub></span>
<strong>3.50 cm</strong>
</div>
<div class="metric">
<span>Triceps moment arm r<sub>T</sub></span>
<strong>1.80 cm</strong>
</div>
<div class="metric">
<span>Antagonist ratio k</span>
<strong>0.25</strong>
</div>
</div>
<div class="formula">
τ<sub>load</sub> = Wd<br>
F<sub>T</sub> = kF<sub>B</sub><br>
F<sub>B</sub> = Wd / (r<sub>B</sub> − kr<sub>T</sub>)<br>
τ<sub>net</sub> = τ<sub>B</sub> − τ<sub>T</sub> − τ<sub>load</sub>
</div>
</section>
<section class="card">
<h3 class="card-title">Antagonistic pair</h3>
<div class="pair-row">
<div class="pair flexor">
<strong>Biceps</strong>
<span>Flexor. Generates the positive torque needed to balance the load and triceps.</span>
</div>
<div class="pair extensor">
<strong>Triceps</strong>
<span>Extensor. Opposes flexion and adds to the load’s extension moment.</span>
</div>
</div>
</section>
<section class="card">
<h3 class="card-title">Model assumptions</h3>
<ul class="assumptions">
<li>The forearm is horizontal and the external force is vertical.</li>
<li>The elbow is the moment center; the shoulder and arm gravity are ignored.</li>
<li>Muscle moment arms remain constant.</li>
<li>Triceps force is 25% of biceps force, representing co-contraction.</li>
<li>Static equilibrium is solved; acceleration and tissue elasticity are omitted.</li>
</ul>
</section>
<p class="disclaimer">
Educational model only. Muscle size and torque are illustrative, not
anatomically measured or suitable for clinical inference.
</p>
</aside>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Scene setup
// ------------------------------------------------------------
const viewport = document.getElementById("viewport");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8eef4);
const camera = new THREE.PerspectiveCamera(
38,
1,
0.1,
100
);
const cameraTarget = new THREE.Vector3(-0.05, 0.88, 0);
let cameraTheta = 0.34;
let cameraPhi = 1.27;
let cameraRadius = 4.7;
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + cameraRadius * sinPhi * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
scene.add(new THREE.HemisphereLight(0xf7fbff, 0x7d8a9d, 2.0));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.0);
keyLight.position.set(3.5, 6.0, 4.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -4;
keyLight.shadow.camera.right = 4;
keyLight.shadow.camera.top = 4;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9dcff, 1.2);
fillLight.position.set(-4, 2.5, -3);
scene.add(fillLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(18, 18),
new THREE.MeshStandardMaterial({
color: 0xe7edf3,
roughness: 0.95,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.66;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(12, 24, 0xbdc9d6, 0xd6dfe8);
grid.position.y = -0.652;
grid.material.transparent = true;
grid.material.opacity = 0.52;
scene.add(grid);
const anatomy = new THREE.Group();
scene.add(anatomy);
const guides = new THREE.Group();
const labels = new THREE.Group();
scene.add(guides, labels);
// ------------------------------------------------------------
// Materials
// ------------------------------------------------------------
const materials = {
bone: new THREE.MeshStandardMaterial({
color: 0xe4c9a2,
roughness: 0.86,
metalness: 0,
flatShading: true
}),
boneDark: new THREE.MeshStandardMaterial({
color: 0xc9aa82,
roughness: 0.9,
flatShading: true
}),
joint: new THREE.MeshStandardMaterial({
color: 0x34485d,
roughness: 0.66,
flatShading: true
}),
biceps: new THREE.MeshStandardMaterial({
color: 0x08a8bd,
roughness: 0.72,
metalness: 0,
flatShading: true
}),
triceps: new THREE.MeshStandardMaterial({
color: 0xd84f83,
roughness: 0.74,
metalness: 0,
flatShading: true
}),
tendon: new THREE.MeshStandardMaterial({
color: 0xf3ead8,
roughness: 0.88,
flatShading: true
}),
muscleBand: new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.18,
depthWrite: false
}),
toy: new THREE.MeshStandardMaterial({
color: 0xf0a14b,
roughness: 0.7,
flatShading: true
}),
toyAccent: new THREE.MeshStandardMaterial({
color: 0xf6ce65,
roughness: 0.72,
flatShading: true
}),
rope: new THREE.MeshStandardMaterial({
color: 0x4f6072,
roughness: 0.9,
flatShading: true
}),
clamp: new THREE.MeshStandardMaterial({
color: 0x607286,
roughness: 0.55,
metalness: 0.35,
flatShading: true
})
};
function shadow(mesh) {
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
// ------------------------------------------------------------
// Geometry helpers
// ------------------------------------------------------------
const Y_AXIS = new THREE.Vector3(0, 1, 0);
function cylinderBetween(a, b, radiusA, radiusB, material, segments = 8) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusB,
radiusA,
length,
segments,
1,
false
),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
Y_AXIS,
direction.normalize()
);
shadow(mesh);
return mesh;
}
function updateCylinderBetween(mesh, a, b) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.scale.set(1, length, 1);
mesh.quaternion.setFromUnitVectors(
Y_AXIS,
direction.normalize()
);
}
function createSpindle(a, b, radius, material) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const segments = 8;
const profile = [
[-0.50, 0.16],
[-0.34, 1.00],
[-0.04, 0.93],
[ 0.28, 0.76],
[ 0.50, 0.14]
];
const vertices = [];
function point(profileIndex, segmentIndex) {
const [t, r] = profile[profileIndex];
const angle = segmentIndex / segments * Math.PI * 2;
return [
Math.cos(angle) * radius * r,
t * length,
Math.sin(angle) * radius * r
];
}
function triangle(a, b, c) {
vertices.push(...a, ...b, ...c);
}
for (let row = 0; row < profile.length - 1; row++) {
for (let segment = 0; segment < segments; segment++) {
const next = (segment + 1) % segments;
const p00 = point(row, segment);
const p01 = point(row, next);
const p10 = point(row + 1, segment);
const p11 = point(row + 1, next);
triangle(p00, p10, p11);
triangle(p00, p11, p01);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(vertices, 3)
);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
Y_AXIS,
direction.normalize()
);
shadow(mesh);
for (const y of [-length * 0.22, 0, length * 0.24]) {
const band = new THREE.Mesh(
new THREE.TorusGeometry(radius * 0.91, 0.009, 4, 8),
materials.muscleBand
);
band.rotation.x = Math.PI / 2;
band.position.y = y;
mesh.add(band);
}
return mesh;
}
function makeLabel(text, color, width = 1.35) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.fillStyle = "rgba(21, 32, 45, 0.86)";
context.fillRect(0, 8, 512, 112);
context.strokeStyle = color;
context.lineWidth = 7;
context.strokeRect(4, 12, 504, 104);
context.fillStyle = color;
context.font = "700 31px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 65);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(width, width * 0.25, 1);
sprite.renderOrder = 10;
return sprite;
}
function createArc(color, radius, startAngle, endAngle) {
const group = new THREE.Group();
const points = [];
const steps = 42;
for (let i = 0; i <= steps; i++) {
const t = i / steps;
const angle = THREE.MathUtils.lerp(startAngle, endAngle, t);
points.push(
new THREE.Vector3(
Math.cos(angle) * radius,
Math.sin(angle) * radius,
0
)
);
}
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.9
})
);
group.add(line);
const directionSign = Math.sign(endAngle - startAngle) || 1;
const tangent = new THREE.Vector3(
-Math.sin(endAngle),
Math.cos(endAngle),
0
).multiplyScalar(directionSign);
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.055, 0.16, 5),
new THREE.MeshBasicMaterial({ color })
);
arrow.position.copy(points[points.length - 1]);
arrow.quaternion.setFromUnitVectors(Y_AXIS, tangent.normalize());
group.add(arrow);
return group;
}
// ------------------------------------------------------------
// Stylized anatomy
// ------------------------------------------------------------
const shoulder = new THREE.Vector3(-1.35, 1.60, 0);
const elbow = new THREE.Vector3(-0.55, 1.05, 0);
const wrist = new THREE.Vector3(0.85, 1.05, 0);
const shoulderJoint = shadow(new THREE.Mesh(
new THREE.IcosahedronGeometry(0.25, 1),
materials.joint
));
shoulderJoint.position.copy(shoulder);
anatomy.add(shoulderJoint);
anatomy.add(cylinderBetween(
shoulder.clone().add(new THREE.Vector3(0, -0.03, 0)),
elbow.clone().add(new THREE.Vector3(0, 0.02, 0)),
0.20,
0.17,
materials.bone,
7
));
anatomy.add(cylinderBetween(
elbow.clone().add(new THREE.Vector3(0.02, 0, 0)),
wrist.clone().add(new THREE.Vector3(-0.02, 0, 0)),
0.18,
0.115,
materials.bone,
7
));
const elbowJoint = shadow(new THREE.Mesh(
new THREE.IcosahedronGeometry(0.19, 1),
materials.joint
));
elbowJoint.position.copy(elbow);
anatomy.add(elbowJoint);
const wristJoint = shadow(new THREE.Mesh(
new THREE.IcosahedronGeometry(0.125, 1),
materials.joint
));
wristJoint.position.copy(wrist);
anatomy.add(wristJoint);
const hand = shadow(new THREE.Mesh(
new THREE.BoxGeometry(0.34, 0.14, 0.22),
materials.bone
));
hand.position.copy(wrist).add(new THREE.Vector3(0.19, -0.025, 0));
anatomy.add(hand);
for (let i = 0; i < 3; i++) {
const finger = shadow(new THREE.Mesh(
new THREE.BoxGeometry(0.22, 0.065, 0.065),
materials.boneDark
));
finger.position.copy(wrist).add(
new THREE.Vector3(0.43, -0.07 + i * 0.045, -0.065 + i * 0.065)
);
finger.rotation.z = -0.10;
anatomy.add(finger);
}
const thumb = shadow(new THREE.Mesh(
new THREE.BoxGeometry(0.18, 0.065, 0.065),
materials.boneDark
));
thumb.position.copy(wrist).add(new THREE.Vector3(0.20, -0.09, 0.10));
thumb.rotation.z = -0.50;
anatomy.add(thumb);
const bicepsStart = shoulder.clone().add(
new THREE.Vector3(-0.02, -0.12, 0.18)
);
const bicepsEnd = elbow.clone().add(
new THREE.Vector3(0.08, 0.10, 0.19)
);
const tricepsStart = shoulder.clone().add(
new THREE.Vector3(-0.02, -0.11, -0.22)
);
const tricepsEnd = elbow.clone().add(
new THREE.Vector3(-0.04, -0.06, -0.23)
);
const biceps = createSpindle(
bicepsStart,
bicepsEnd,
0.165,
materials.biceps
);
anatomy.add(biceps);
const triceps = createSpindle(
tricepsStart,
tricepsEnd,
0.145,
materials.triceps
);
anatomy.add(triceps);
anatomy.add(cylinderBetween(
bicepsEnd,
elbow.clone().add(new THREE.Vector3(0.34, 0.02, 0.18)),
0.038,
0.028,
materials.tendon,
6
));
anatomy.add(cylinderBetween(
tricepsEnd,
elbow.clone().add(new THREE.Vector3(-0.02, -0.03, -0.22)),
0.034,
0.026,
materials.tendon,
6
));
const bicepsLabel = makeLabel("BICEPS · FLEXOR", "#67d3df");
bicepsLabel.position.set(-1.06, 1.88, 0.34);
labels.add(bicepsLabel);
const tricepsLabel = makeLabel("TRICEPS · EXTENSOR", "#ef82ad");
tricepsLabel.position.set(-1.03, 0.67, -0.25);
labels.add(tricepsLabel);
const pivotLabel = makeLabel("ELBOW PIVOT", "#a8b5c3", 1.12);
pivotLabel.position.set(-0.50, 0.54, 0.32);
labels.add(pivotLabel);
// ------------------------------------------------------------
// Toy attachment, rope, and external load
// ------------------------------------------------------------
const attachmentClamp = shadow(new THREE.Mesh(
new THREE.TorusGeometry(0.19, 0.025, 5, 10),
materials.clamp
));
attachmentClamp.rotation.y = Math.PI / 2;
anatomy.add(attachmentClamp);
const rope = shadow(new THREE.Mesh(
new THREE.CylinderGeometry(0.012, 0.012, 1, 6),
materials.rope
));
anatomy.add(rope);
const toy = new THREE.Group();
anatomy.add(toy);
const toyBlock = shadow(new THREE.Mesh(
new THREE.BoxGeometry(1, 1, 1),
materials.toy
));
toy.add(toyBlock);
const toyStripe = shadow(new THREE.Mesh(
new THREE.BoxGeometry(1.03, 0.18, 1.03),
materials.toyAccent
));
toy.add(toyStripe);
const loadArrow = new THREE.ArrowHelper(
new THREE.Vector3(0, -1, 0),
new THREE.Vector3(),
0.7,
0xe98224,
0.15,
0.09
);
anatomy.add(loadArrow);
const toyLabel = makeLabel("TOY · EXTERNAL LOAD", "#f4ad62", 1.58);
labels.add(toyLabel);
// ------------------------------------------------------------
// Moment-direction guides
// ------------------------------------------------------------
const flexArc = createArc(0x08a8bd, 0.74, -0.15, 1.30);
const tricepsArc = createArc(0xd84f83, 0.55, 0.12, -1.30);
const loadArc = createArc(0xe98224, 0.39, 0.18, -1.65);
flexArc.position.copy(elbow).add(new THREE.Vector3(0, 0, 0.30));
tricepsArc.position.copy(elbow).add(new THREE.Vector3(0, 0, 0.32));
loadArc.position.copy(elbow).add(new THREE.Vector3(0, 0, 0.34));
guides.add(flexArc, tricepsArc, loadArc);
const distanceLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(),
new THREE.Vector3()
]),
new THREE.LineDashedMaterial({
color: 0xe98224,
dashSize: 0.075,
gapSize: 0.045,
transparent: true,
opacity: 0.95
})
);
guides.add(distanceLine);
const distanceArrowLeft = new THREE.Mesh(
new THREE.ConeGeometry(0.045, 0.13, 5),
new THREE.MeshBasicMaterial({ color: 0xe98224 })
);
distanceArrowLeft.quaternion.setFromUnitVectors(
Y_AXIS,
new THREE.Vector3(-1, 0, 0)
);
guides.add(distanceArrowLeft);
const distanceArrowRight = new THREE.Mesh(
new THREE.ConeGeometry(0.045, 0.13, 5),
new THREE.MeshBasicMaterial({ color: 0xe98224 })
);
distanceArrowRight.quaternion.setFromUnitVectors(
Y_AXIS,
new THREE.Vector3(1, 0, 0)
);
guides.add(distanceArrowRight);
const distanceLabel = makeLabel("d · ELBOW TO TOY", "#f4ad62", 1.42);
labels.add(distanceLabel);
// ------------------------------------------------------------
// Quantitative model
// ------------------------------------------------------------
const distanceRange = document.getElementById("distanceRange");
const loadRange = document.getElementById("loadRange");
const distanceOut = document.getElementById("distanceOut");
const loadOut = document.getElementById("loadOut");
const tauBValue = document.getElementById("tauBValue");
const tauTValue = document.getElementById("tauTValue");
const tauLoadValue = document.getElementById("tauLoadValue");
const netValue = document.getElementById("netValue");
const tauBBar = document.getElementById("tauBBar");
const tauTBar = document.getElementById("tauTBar");
const tauLoadBar = document.getElementById("tauLoadBar");
const loadTorqueMetric = document.getElementById("loadTorqueMetric");
const bicepsForceMetric = document.getElementById("bicepsForceMetric");
const tricepsForceMetric = document.getElementById("tricepsForceMetric");
// Model constants. These are educational assumptions, not measured data.
const BICEPS_MOMENT_ARM = 0.035; // m
const TRICEPS_MOMENT_ARM = 0.018; // m
const ANTAGONIST_RATIO = 0.25;
const MAX_DISPLAY_DISTANCE = 0.30; // m
const MAX_MODEL_FORCE = 20 * 0.30 /
(BICEPS_MOMENT_ARM - ANTAGONIST_RATIO * TRICEPS_MOMENT_ARM);
function formatNumber(value, decimals = 2) {
return Number(value).toFixed(decimals);
}
function updateModel() {
const distanceMeters = Number(distanceRange.value) / 100;
const externalLoad = Number(loadRange.value);
const loadTorque = externalLoad * distanceMeters;
const requiredBicepsForce = loadTorque /
(
BICEPS_MOMENT_ARM -
ANTAGONIST_RATIO * TRICEPS_MOMENT_ARM
);
const antagonistForce =
ANTAGONIST_RATIO * requiredBicepsForce;
const bicepsTorque =
requiredBicepsForce * BICEPS_MOMENT_ARM;
const tricepsTorque =
antagonistForce * TRICEPS_MOMENT_ARM;
const netMoment =
bicepsTorque - tricepsTorque - loadTorque;
// Model-quantity readouts.
distanceOut.textContent = `${distanceRange.value} cm`;
loadOut.textContent = `${formatNumber(externalLoad, 1)} N`;
tauBValue.textContent = `${formatNumber(bicepsTorque)} N·m`;
tauTValue.textContent = `${formatNumber(tricepsTorque)} N·m`;
tauLoadValue.textContent = `${formatNumber(loadTorque)} N·m`;
netValue.textContent = `${formatNumber(netMoment)} N·m`;
loadTorqueMetric.textContent = `${formatNumber(loadTorque)} N·m`;
bicepsForceMetric.textContent = `${formatNumber(requiredBicepsForce, 1)} N`;
tricepsForceMetric.textContent = `${formatNumber(antagonistForce, 1)} N`;
const scale = Math.max(
bicepsTorque,
tricepsTorque,
loadTorque,
0.5
);
tauBBar.style.width =
`${bicepsTorque > 0 ? Math.max(2, bicepsTorque / scale * 100) : 0}%`;
tauTBar.style.width =
`${tricepsTorque > 0 ? Math.max(2, tricepsTorque / scale * 100) : 0}%`;
tauLoadBar.style.width =
`${loadTorque > 0 ? Math.max(2, loadTorque / scale * 100) : 0}%`;
updateAnatomy(
distanceMeters,
externalLoad,
requiredBicepsForce,
antagonistForce
);
}
function updateAnatomy(
distanceMeters,
externalLoad,
bicepsForce,
tricepsForce
) {
const visualT = THREE.MathUtils.clamp(
distanceMeters / MAX_DISPLAY_DISTANCE,
0,
1
);
const attachment = elbow.clone().lerp(wrist, visualT);
attachmentClamp.position.copy(attachment);
const loadFraction = externalLoad / 20;
const toyWidth = 0.25 + loadFraction * 0.12;
const toyHeight = 0.20 + loadFraction * 0.10;
const toyDepth = 0.23 + loadFraction * 0.07;
toy.position.set(attachment.x, 0.17, 0.06);
toyBlock.scale.set(toyWidth, toyHeight, toyDepth);
toyStripe.scale.set(toyWidth, toyHeight, toyDepth);
toyStripe.position.y = toyHeight * 0.10;
const ropeStart = new THREE.Vector3(
attachment.x,
attachment.y - 0.17,
attachment.z
);
const ropeEnd = new THREE.Vector3(
toy.position.x,
toy.position.y + toyHeight * 0.5,
toy.position.z
);
updateCylinderBetween(rope, ropeStart, ropeEnd);
loadArrow.position.set(
attachment.x + toyWidth * 0.75 + 0.13,
toy.position.y + toyHeight * 0.65,
toy.position.z
);
loadArrow.setLength(
0.40 + loadFraction * 0.35,
0.14,
0.085
);
toyLabel.position.set(
attachment.x,
toy.position.y - 0.20,
toy.position.z + 0.20
);
// Muscle swelling is a qualitative cue only.
const bicepsActivation = THREE.MathUtils.clamp(
bicepsForce / MAX_MODEL_FORCE,
0,
1
);
const tricepsActivation = THREE.MathUtils.clamp(
tricepsForce / MAX_MODEL_FORCE,
0,
1
);
const bicepsScale = 1 + 0.24 * bicepsActivation;
const tricepsScale = 1 + 0.20 * tricepsActivation;
biceps.scale.set(bicepsScale, 1, bicepsScale);
triceps.scale.set(tricepsScale, 1, tricepsScale);
// Dimension guide is parallel to the forearm and represents d.
const guideY = elbow.y + 0.29;
const guideZ = 0.34;
const guideStart = new THREE.Vector3(
elbow.x,
guideY,
guideZ
);
const guideEnd = new THREE.Vector3(
attachment.x,
guideY,
guideZ
);
distanceLine.geometry.setFromPoints([guideStart, guideEnd]);
distanceLine.computeLineDistances();
distanceArrowLeft.position.copy(guideStart);
distanceArrowRight.position.copy(guideEnd);
distanceLabel.position.set(
(elbow.x + attachment.x) * 0.5,
guideY + 0.19,
guideZ
);
}
distanceRange.addEventListener("input", updateModel);
loadRange.addEventListener("input", updateModel);
updateModel();
// ------------------------------------------------------------
// Directly implemented camera controls
// ------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
if (event.button !== 0) return;
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraTheta -= deltaX * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi + deltaY * 0.006,
0.30,
Math.PI - 0.30
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.0035,
2.8,
7.5
);
updateCamera();
}, { passive: false });
function resetView() {
cameraTheta = 0.34;
cameraPhi = 1.27;
cameraRadius = 4.7;
updateCamera();
}
document.getElementById("resetViewButton").addEventListener(
"click",
resetView
);
renderer.domElement.addEventListener("dblclick", resetView);
const guidesButton = document.getElementById("guidesButton");
guidesButton.addEventListener("click", () => {
const visible = !guides.visible;
guides.visible = visible;
guidesButton.textContent = visible ? "Guides on" : "Guides off";
guidesButton.classList.toggle("active", visible);
});
// ------------------------------------------------------------
// Responsive renderer
// ------------------------------------------------------------
const resizeObserver = new ResizeObserver(() => {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
if (!width || !height) return;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
});
resizeObserver.observe(viewport);
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```