Prompt specification
Build or customize the Three.js 3D scene "Diaphragm shortening and tendon displacement pair" 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: Diaphragm shortening and tendon displacement pair
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/diaphragm-shortening-and-tendon-displacement-pair-x0969
Scene Description Prompt:
Model two isolated schematic diaphragm domes with fixed rims and radial muscle bands. Compare relaxed and shortened-band shapes, marking central-tendon descent and the corresponding reduction in band length. Use Three.js from cdnjs in a single HTML file, with a 3D cutaway.
Working Three.js Starter (diaphragm-shortening-and-tendon-displacement-pair-x0969):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Diaphragm Mechanics — Relaxed vs. Shortened Bands</title>
<style>
:root {
color-scheme: dark;
--bg: #07111e;
--panel: rgba(10, 24, 40, 0.82);
--border: rgba(165, 205, 230, 0.18);
--text: #eef7ff;
--muted: #91a9bd;
--cyan: #83d8ee;
--coral: #e56760;
--gold: #ffd166;
--silver: #aebdc9;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 30%, #132b42 0%, #091624 44%, #050c15 100%);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
canvas {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
#leaders {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
pointer-events: none;
overflow: visible;
z-index: 4;
}
#leaders line {
stroke: rgba(202, 224, 239, 0.55);
stroke-width: 1;
stroke-dasharray: 3 4;
}
#leaders circle {
fill: var(--gold);
stroke: rgba(255, 255, 255, 0.75);
stroke-width: 1;
}
.panel {
position: fixed;
z-index: 5;
border: 1px solid var(--border);
background: var(--panel);
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
header {
top: 22px;
left: 24px;
width: min(490px, calc(100vw - 48px));
padding: 18px 20px 17px;
border-radius: 16px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 2px;
content: "";
background: var(--cyan);
box-shadow: 0 0 12px rgba(131, 216, 238, 0.75);
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 32px);
font-weight: 650;
line-height: 1.08;
letter-spacing: -0.035em;
}
header p {
max-width: 420px;
margin: 10px 0 0;
color: var(--muted);
font-size: 12.5px;
line-height: 1.55;
}
.legend {
bottom: 22px;
left: 24px;
width: 225px;
padding: 15px 16px;
border-radius: 14px;
}
.legend-title,
.control-title {
margin-bottom: 11px;
color: #c9d9e5;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 15px 1fr;
align-items: center;
gap: 9px;
margin: 8px 0;
color: #b9cbd8;
font-size: 11px;
}
.swatch {
width: 14px;
height: 5px;
border-radius: 10px;
background: var(--coral);
}
.swatch.rim {
background: var(--silver);
}
.swatch.tendon {
background: var(--cyan);
}
.swatch.measure {
background: var(--gold);
}
.legend-note {
margin-top: 11px;
padding-top: 10px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
color: #72899c;
font-size: 9.5px;
line-height: 1.45;
}
#controls {
right: 24px;
bottom: 22px;
width: 245px;
padding: 15px 16px;
border-radius: 14px;
}
.control-label {
display: flex;
justify-content: space-between;
margin-bottom: 7px;
color: #b8c9d6;
font-size: 10px;
}
#cut-value {
color: var(--cyan);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0 0 14px;
appearance: none;
border-radius: 4px;
outline: none;
background: linear-gradient(90deg, var(--cyan), rgba(131, 216, 238, 0.18));
}
input[type="range"]::-webkit-slider-thumb {
width: 14px;
height: 14px;
appearance: none;
border: 2px solid #dff7ff;
border-radius: 50%;
background: #102b3e;
box-shadow: 0 0 12px rgba(131, 216, 238, 0.55);
cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 2px solid #dff7ff;
border-radius: 50%;
background: #102b3e;
cursor: pointer;
}
.buttons {
display: flex;
gap: 7px;
}
button {
flex: 1;
padding: 8px 9px;
border: 1px solid rgba(255, 255, 255, 0.11);
border-radius: 8px;
background: rgba(255, 255, 255, 0.045);
color: #c9d9e5;
font: inherit;
font-size: 10px;
cursor: pointer;
transition: 150ms ease;
}
button:hover {
border-color: rgba(131, 216, 238, 0.45);
background: rgba(131, 216, 238, 0.1);
color: white;
}
.hint {
margin-top: 10px;
color: #71899c;
font-size: 9.5px;
line-height: 1.45;
text-align: center;
}
.annotation {
position: fixed;
top: 0;
left: 0;
z-index: 6;
width: 176px;
padding: 10px 12px;
border: 1px solid rgba(164, 205, 230, 0.22);
border-radius: 11px;
background: rgba(7, 19, 32, 0.9);
box-shadow: 0 9px 30px rgba(0, 0, 0, 0.28);
pointer-events: none;
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
}
.annotation::before {
display: block;
width: 22px;
height: 2px;
margin-bottom: 7px;
content: "";
background: var(--accent, var(--cyan));
box-shadow: 0 0 10px color-mix(in srgb, var(--accent, var(--cyan)) 65%, transparent);
}
.annotation .kicker {
color: var(--accent, var(--cyan));
font-size: 8px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.annotation strong {
display: block;
margin-top: 3px;
color: #f2f8fc;
font-size: 16px;
font-weight: 650;
letter-spacing: -0.02em;
}
.annotation small {
display: block;
margin-top: 3px;
color: #8da5b8;
font-size: 9.5px;
line-height: 1.35;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #07111e;
color: var(--cyan);
font-size: 11px;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
header {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
header p {
display: none;
}
.legend {
display: none;
}
#controls {
right: 12px;
bottom: 12px;
width: 215px;
}
.annotation {
width: 145px;
padding: 8px 10px;
}
.annotation strong {
font-size: 14px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive 3D comparison of relaxed and shortened diaphragm domes"></canvas>
<svg id="leaders" aria-hidden="true"></svg>
<header class="panel">
<div class="eyebrow">Diaphragm mechanics · 3D schematic</div>
<h1>Fixed rim. Shorter radial bands.</h1>
<p>
Two isolated diaphragm domes compare a relaxed, elevated central tendon with a
shortened-band state in which the tendon descends toward the fixed rim.
</p>
</header>
<aside class="panel legend">
<div class="legend-title">Model key</div>
<div class="legend-row"><span class="swatch rim"></span>Fixed rim</div>
<div class="legend-row"><span class="swatch"></span>Radial muscle bands</div>
<div class="legend-row"><span class="swatch tendon"></span>Central tendon</div>
<div class="legend-row"><span class="swatch measure"></span>Measured band</div>
<div class="legend-note">
Illustrative geometry, not anatomical scale. Percentages are calculated from
the displayed radial-band centerlines.
</div>
</aside>
<aside class="panel" id="controls">
<div class="control-title">Cutaway & view</div>
<div class="control-label">
<span>Removed sector</span>
<span id="cut-value">72°</span>
</div>
<input id="cutaway" type="range" min="45" max="105" value="72" step="1">
<div class="buttons">
<button id="reset-view" type="button">3D view</button>
<button id="front-view" type="button">Front</button>
<button id="top-view" type="button">Top</button>
</div>
<div class="hint">Drag to orbit · wheel to zoom · right-drag to pan</div>
</aside>
<div id="loading">Loading 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";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
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.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x07111e, 0.028);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
100
);
const target = new THREE.Vector3(0, 0.15, 0);
const spherical = new THREE.Spherical(14.4, 1.18, 0.70);
function applyCamera() {
spherical.phi = THREE.MathUtils.clamp(spherical.phi, 0.08, Math.PI - 0.12);
spherical.radius = THREE.MathUtils.clamp(spherical.radius, 7, 28);
const position = new THREE.Vector3().setFromSpherical(spherical).add(target);
camera.position.copy(position);
camera.lookAt(target);
}
applyCamera();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xbfe8ff, 0x162333, 1.55));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(5, 9, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x70c9ee, 1.55);
fillLight.position.set(-8, 3, -6);
scene.add(fillLight);
const rimLight = new THREE.PointLight(0xff8278, 22, 18, 2);
rimLight.position.set(0, 4, -5);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Ground and reference grid
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.ShadowMaterial({ color: 0x000000, opacity: 0.32 })
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.08;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(30, 30, 0x31536a, 0x193247);
grid.position.y = -1.075;
grid.material.transparent = true;
grid.material.opacity = 0.22;
scene.add(grid);
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
const CUT_CENTER = 0.48;
const INNER_RADIUS = 0.62;
const OUTER_RADIUS = 2.15;
const SHELL_THICKNESS = 0.065;
const RELAXED_TENDON_Y = 0.95;
const CONTRACTED_TENDON_Y = 0.18;
let cutHalfAngle = THREE.MathUtils.degToRad(72) / 2;
function profileFactory(tendonY, exponent) {
return (s) => tendonY * Math.pow(Math.max(0, 1 - s), exponent);
}
function makeSurfaceGeometry(angleStart, angleEnd, profile, lower = false) {
const radialSegments = 24;
const angularSegments = 110;
const positions = [];
const indices = [];
const thicknessOffset = lower ? -SHELL_THICKNESS : 0;
for (let j = 0; j <= radialSegments; j++) {
const s = j / radialSegments;
const radius = INNER_RADIUS + (OUTER_RADIUS - INNER_RADIUS) * s;
for (let i = 0; i <= angularSegments; i++) {
const angle = angleStart +
(angleEnd - angleStart) * (i / angularSegments);
const y = profile(s) + thicknessOffset;
positions.push(
Math.cos(angle) * radius,
y,
Math.sin(angle) * radius
);
}
}
const stride = angularSegments + 1;
for (let j = 0; j < radialSegments; j++) {
for (let i = 0; i < angularSegments; i++) {
const a = j * stride + i;
const b = a + 1;
const c = a + stride;
const d = c + 1;
indices.push(a, c, b, b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function makeWallGeometry(angleStart, angleEnd, profile, outerWall) {
const segments = 110;
const positions = [];
const indices = [];
const radius = outerWall ? OUTER_RADIUS : INNER_RADIUS;
const s = outerWall ? 1 : 0;
const top = profile(s);
const bottom = top - SHELL_THICKNESS;
for (let i = 0; i <= segments; i++) {
const angle = angleStart +
(angleEnd - angleStart) * (i / segments);
positions.push(
Math.cos(angle) * radius,
top,
Math.sin(angle) * radius
);
positions.push(
Math.cos(angle) * radius,
bottom,
Math.sin(angle) * radius
);
}
for (let i = 0; i < segments; i++) {
const a = i * 2;
indices.push(a, a + 1, a + 2, a + 1, a + 3, a + 2);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function makeCutFaceGeometry(angle, profile) {
const segments = 24;
const positions = [];
const indices = [];
for (let j = 0; j <= segments; j++) {
const s = j / segments;
const radius = INNER_RADIUS + (OUTER_RADIUS - INNER_RADIUS) * s;
const top = profile(s);
const bottom = top - SHELL_THICKNESS;
positions.push(
Math.cos(angle) * radius,
top,
Math.sin(angle) * radius
);
positions.push(
Math.cos(angle) * radius,
bottom,
Math.sin(angle) * radius
);
}
for (let j = 0; j < segments; j++) {
const a = j * 2;
indices.push(a, a + 1, a + 2, a + 1, a + 3, a + 2);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function makeRibbonGeometry(angle, profile, width = 0.085) {
const segments = 64;
const positions = [];
const indices = [];
for (let j = 0; j <= segments; j++) {
const s = j / segments;
const radius = INNER_RADIUS + (OUTER_RADIUS - INNER_RADIUS) * s;
const halfAngle = width / (2 * radius);
const y = profile(s) + 0.052;
for (const side of [-1, 1]) {
const a = angle + side * halfAngle;
positions.push(
Math.cos(a) * radius,
y,
Math.sin(a) * radius
);
}
}
for (let j = 0; j < segments; j++) {
const a = j * 2;
indices.push(a, a + 1, a + 2, a + 1, a + 3, a + 2);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
class ProfileCurve extends THREE.Curve {
constructor(angle, profile, lift = 0.052) {
super();
this.angle = angle;
this.profile = profile;
this.lift = lift;
}
getPoint(t, target = new THREE.Vector3()) {
const radius = INNER_RADIUS + (OUTER_RADIUS - INNER_RADIUS) * t;
const y = this.profile(t) + this.lift;
return target.set(
Math.cos(this.angle) * radius,
y,
Math.sin(this.angle) * radius
);
}
}
function makeLine(points, material) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
return line;
}
function makeTicks(curve, angle) {
const group = new THREE.Group();
const material = new THREE.LineBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.95
});
const tangent = new THREE.Vector3(-Math.sin(angle), 0, Math.cos(angle));
for (const t of [0, 1]) {
const center = curve.getPoint(t).clone();
center.y += 0.025;
const half = tangent.clone().multiplyScalar(0.075);
group.add(makeLine(
[center.clone().sub(half), center.clone().add(half)],
material
));
const dot = new THREE.Mesh(
new THREE.SphereGeometry(0.028, 10, 8),
new THREE.MeshBasicMaterial({ color: 0xffd166 })
);
dot.position.copy(center);
group.add(dot);
}
return group;
}
// -------------------------------------------------------------------------
// Dome construction
// -------------------------------------------------------------------------
let relaxedDome;
let contractedDome;
function buildDome({
x,
tendonY,
exponent,
muscleColor,
showGhost = false
}) {
const group = new THREE.Group();
group.position.x = x;
scene.add(group);
const profile = profileFactory(tendonY, exponent);
const visibleStart = CUT_CENTER + cutHalfAngle;
const visibleEnd = CUT_CENTER + Math.PI * 2 - cutHalfAngle;
const shellTopMaterial = new THREE.MeshPhysicalMaterial({
color: muscleColor,
roughness: 0.42,
metalness: 0.02,
clearcoat: 0.35,
clearcoatRoughness: 0.4,
transparent: true,
opacity: 0.29,
side: THREE.DoubleSide,
depthWrite: false
});
const shellBottomMaterial = new THREE.MeshPhysicalMaterial({
color: 0x7f302f,
roughness: 0.66,
transparent: true,
opacity: 0.3,
side: THREE.DoubleSide,
depthWrite: false
});
const cutMaterial = new THREE.MeshStandardMaterial({
color: 0xa84743,
roughness: 0.62,
side: THREE.DoubleSide
});
const top = new THREE.Mesh(
makeSurfaceGeometry(visibleStart, visibleEnd, profile, false),
shellTopMaterial
);
top.castShadow = true;
top.receiveShadow = true;
top.renderOrder = 1;
group.add(top);
const bottom = new THREE.Mesh(
makeSurfaceGeometry(visibleStart, visibleEnd, profile, true),
shellBottomMaterial
);
bottom.receiveShadow = true;
bottom.renderOrder = 0;
group.add(bottom);
group.add(new THREE.Mesh(
makeWallGeometry(visibleStart, visibleEnd, profile, true),
cutMaterial
));
group.add(new THREE.Mesh(
makeWallGeometry(visibleStart, visibleEnd, profile, false),
cutMaterial
));
group.add(new THREE.Mesh(
makeCutFaceGeometry(visibleStart, profile),
cutMaterial
));
group.add(new THREE.Mesh(
makeCutFaceGeometry(visibleEnd, profile),
cutMaterial
));
// Central tendon: solid blue hub exposed by the cutaway.
const tendonMaterial = new THREE.MeshPhysicalMaterial({
color: 0x79cee7,
emissive: 0x123b4a,
emissiveIntensity: 0.35,
roughness: 0.28,
metalness: 0.12,
clearcoat: 0.6
});
const tendon = new THREE.Mesh(
new THREE.CylinderGeometry(
INNER_RADIUS * 1.02,
INNER_RADIUS * 1.06,
0.14,
64
),
tendonMaterial
);
tendon.position.y = tendonY;
tendon.castShadow = true;
tendon.receiveShadow = true;
group.add(tendon);
const tendonTop = new THREE.Mesh(
new THREE.CircleGeometry(INNER_RADIUS * 0.98, 64),
new THREE.MeshStandardMaterial({
color: 0xa5e4f2,
roughness: 0.38,
metalness: 0.08
})
);
tendonTop.rotation.x = -Math.PI / 2;
tendonTop.position.y = tendonY + 0.072;
tendonTop.receiveShadow = true;
group.add(tendonTop);
// Radial muscle bands.
const bandMaterial = new THREE.MeshStandardMaterial({
color: muscleColor,
roughness: 0.46,
metalness: 0.02,
side: THREE.DoubleSide
});
const selectedMaterial = new THREE.MeshStandardMaterial({
color: 0xffd166,
emissive: 0x4a3100,
emissiveIntensity: 0.35,
roughness: 0.35,
side: THREE.DoubleSide
});
const bandCount = 17;
const selectedAngle = visibleStart + 0.026;
for (let i = 0; i <= bandCount; i++) {
const angle = visibleStart +
(visibleEnd - visibleStart) * (i / bandCount);
const isSelected = i === 0;
const ribbon = new THREE.Mesh(
makeRibbonGeometry(angle, profile, isSelected ? 0.135 : 0.085),
isSelected ? selectedMaterial : bandMaterial
);
ribbon.castShadow = true;
ribbon.receiveShadow = true;
group.add(ribbon);
}
// Fixed rim and mechanical-looking clamps.
const rimMaterial = new THREE.MeshStandardMaterial({
color: 0xb4c1cb,
roughness: 0.24,
metalness: 0.78
});
const rim = new THREE.Mesh(
new THREE.TorusGeometry(OUTER_RADIUS, 0.055, 12, 120),
rimMaterial
);
rim.rotation.x = Math.PI / 2;
rim.castShadow = true;
group.add(rim);
const lowerRim = new THREE.Mesh(
new THREE.TorusGeometry(OUTER_RADIUS, 0.027, 8, 120),
new THREE.MeshStandardMaterial({
color: 0x506675,
roughness: 0.36,
metalness: 0.72
})
);
lowerRim.rotation.x = Math.PI / 2;
lowerRim.position.y = -0.045;
group.add(lowerRim);
const clampMaterial = new THREE.MeshStandardMaterial({
color: 0x6e818e,
roughness: 0.3,
metalness: 0.76
});
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * Math.PI * 2;
const clamp = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 0.12, 0.30),
clampMaterial
);
clamp.position.set(
Math.cos(angle) * (OUTER_RADIUS + 0.035),
0,
Math.sin(angle) * (OUTER_RADIUS + 0.035)
);
clamp.rotation.y = Math.PI / 2 - angle;
clamp.castShadow = true;
group.add(clamp);
}
// The highlighted band centerline and its dimension line.
const measuredCurve = new ProfileCurve(selectedAngle, profile, 0.052);
const measuredLength = measuredCurve.getLength();
const dimensionMaterial = new THREE.LineBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.95
});
const dimensionPoints = [];
const tangent = new THREE.Vector3(
-Math.sin(selectedAngle),
0,
Math.cos(selectedAngle)
);
for (let i = 0; i <= 64; i++) {
const point = measuredCurve.getPoint(i / 64).clone();
point.addScaledVector(tangent, 0.18);
point.y += 0.028;
dimensionPoints.push(point);
}
group.add(makeLine(dimensionPoints, dimensionMaterial));
group.add(makeTicks(measuredCurve, selectedAngle));
// Ghost tendon outline and downward descent arrow in the shortened state.
if (showGhost) {
const ghostMaterial = new THREE.MeshBasicMaterial({
color: 0x83d8ee,
transparent: true,
opacity: 0.48,
depthWrite: false
});
const ghostRing = new THREE.Mesh(
new THREE.TorusGeometry(INNER_RADIUS * 1.04, 0.018, 8, 72),
ghostMaterial
);
ghostRing.rotation.x = Math.PI / 2;
ghostRing.position.y = RELAXED_TENDON_Y;
group.add(ghostRing);
const arrowX = 0.94;
const arrowZ = -0.36;
const arrowTop = RELAXED_TENDON_Y + 0.02;
const arrowBottom = CONTRACTED_TENDON_Y + 0.08;
const arrowMaterial = new THREE.LineDashedMaterial({
color: 0x83d8ee,
dashSize: 0.075,
gapSize: 0.045,
transparent: true,
opacity: 0.95
});
const arrow = makeLine([
new THREE.Vector3(arrowX, arrowTop, arrowZ),
new THREE.Vector3(arrowX, arrowBottom, arrowZ)
], arrowMaterial);
group.add(arrow);
const arrowHead = new THREE.Mesh(
new THREE.ConeGeometry(0.07, 0.18, 12),
new THREE.MeshBasicMaterial({ color: 0x83d8ee })
);
arrowHead.rotation.x = Math.PI;
arrowHead.position.set(arrowX, arrowBottom - 0.04, arrowZ);
group.add(arrowHead);
}
const selectedMid = measuredCurve.getPoint(0.52);
return {
group,
measuredLength,
selectedMid: () => selectedMid.clone(),
tendonAnchor: () => new THREE.Vector3(0, tendonY + 0.06, 0),
descentAnchor: () =>
new THREE.Vector3(
0.94,
(RELAXED_TENDON_Y + CONTRACTED_TENDON_Y) / 2,
-0.36
),
rimAnchor: () => {
const angle = 4.42;
return new THREE.Vector3(
Math.cos(angle) * OUTER_RADIUS,
0,
Math.sin(angle) * OUTER_RADIUS
);
}
};
}
function disposeDome(dome) {
if (!dome) return;
scene.remove(dome.group);
dome.group.traverse((object) => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
const materials = Array.isArray(object.material)
? object.material
: [object.material];
materials.forEach((material) => material.dispose());
}
});
}
function rebuildDomes() {
disposeDome(relaxedDome);
disposeDome(contractedDome);
relaxedDome = buildDome({
x: -3.05,
tendonY: RELAXED_TENDON_Y,
exponent: 1.8,
muscleColor: 0xd85d57
});
contractedDome = buildDome({
x: 3.05,
tendonY: CONTRACTED_TENDON_Y,
exponent: 1.25,
muscleColor: 0xe66d66,
showGhost: true
});
const ratio = contractedDome.measuredLength / relaxedDome.measuredLength;
const percent = Math.round(ratio * 100);
const reduction = 100 - percent;
const descent = RELAXED_TENDON_Y - CONTRACTED_TENDON_Y;
annotationById.relaxedBand.element.innerHTML = `
<div class="kicker">Radial band</div>
<strong>100% reference</strong>
<small>${relaxedDome.measuredLength.toFixed(2)} model units</small>
`;
annotationById.contractedBand.element.innerHTML = `
<div class="kicker">Shortened radial band</div>
<strong>${percent}% of relaxed</strong>
<small>${reduction}% shorter · ${contractedDome.measuredLength.toFixed(2)} model units</small>
`;
annotationById.descent.element.innerHTML = `
<div class="kicker">Central-tendon descent</div>
<strong>Δy = ${descent.toFixed(2)} u</strong>
<small>Fixed rim remains unchanged</small>
`;
}
// -------------------------------------------------------------------------
// Screen-space annotations without an external renderer
// -------------------------------------------------------------------------
const annotationLayer = document.createElement("div");
document.body.appendChild(annotationLayer);
const svg = document.querySelector("#leaders");
const annotationById = {};
function createAnnotation({
id,
anchor,
dx,
dy,
accent = "#83d8ee"
}) {
const element = document.createElement("div");
element.className = "annotation";
element.id = `annotation-${id}`;
element.style.setProperty("--accent", accent);
annotationLayer.appendChild(element);
const line = document.createElementNS(
"http://www.w3.org/2000/svg",
"line"
);
const circle = document.createElementNS(
"http://www.w3.org/2000/svg",
"circle"
);
circle.setAttribute("r", "3");
svg.appendChild(line);
svg.appendChild(circle);
const annotation = {
element,
line,
circle,
anchor,
dx,
dy
};
annotationById[id] = annotation;
return annotation;
}
createAnnotation({
id: "relaxedTendon",
anchor: () => relaxedDome.tendonAnchor(),
dx: -125,
dy: -75,
accent: "#83d8ee"
});
createAnnotation({
id: "contractedTendon",
anchor: () => contractedDome.tendonAnchor(),
dx: 50,
dy: -75,
accent: "#83d8ee"
});
createAnnotation({
id: "relaxedBand",
anchor: () => relaxedDome.selectedMid(),
dx: -155,
dy: 35,
accent: "#ffd166"
});
createAnnotation({
id: "contractedBand",
anchor: () => contractedDome.selectedMid(),
dx: 75,
dy: 40,
accent: "#ffd166"
});
createAnnotation({
id: "descent",
anchor: () => contractedDome.descentAnchor(),
dx: 75,
dy: -15,
accent: "#83d8ee"
});
createAnnotation({
id: "fixedRim",
anchor: () => contractedDome.rimAnchor(),
dx: -100,
dy: 65,
accent: "#aebdc9"
});
annotationById.relaxedTendon.element.innerHTML = `
<div class="kicker">Relaxed state</div>
<strong>Elevated central tendon</strong>
<small>Long, curved radial muscle bands</small>
`;
annotationById.contractedTendon.element.innerHTML = `
<div class="kicker">Shortened-band state</div>
<strong>Descended central tendon</strong>
<small>Radial bands shorten toward the fixed rim</small>
`;
annotationById.fixedRim.element.innerHTML = `
<div class="kicker">Rigid boundary</div>
<strong>Fixed rim</strong>
<small>Same radius and height in both states</small>
`;
rebuildDomes();
// -------------------------------------------------------------------------
// Custom camera controls — no Three.js examples/addons
// -------------------------------------------------------------------------
let dragging = false;
let panning = false;
let previousX = 0;
let previousY = 0;
let pointerId = null;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
panning = event.button === 2 || event.button === 1;
previousX = event.clientX;
previousY = event.clientY;
pointerId = event.pointerId;
canvas.setPointerCapture(pointerId);
canvas.style.cursor = panning ? "grabbing" : "move";
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (panning) {
const right = new THREE.Vector3();
const up = new THREE.Vector3();
camera.matrixWorld.extractBasis(right, up, new THREE.Vector3());
const scale = spherical.radius * 0.0015;
target.addScaledVector(right, -dx * scale);
target.addScaledVector(up, dy * scale);
} else {
spherical.theta -= dx * 0.006;
spherical.phi -= dy * 0.006;
}
applyCamera();
});
function endPointer(event) {
if (event.pointerId !== pointerId) return;
dragging = false;
panning = false;
canvas.style.cursor = "default";
if (canvas.hasPointerCapture(pointerId)) {
canvas.releasePointerCapture(pointerId);
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
spherical.radius *= Math.exp(event.deltaY * 0.001);
applyCamera();
}, { passive: false });
// Camera presets.
document.querySelector("#reset-view").addEventListener("click", () => {
target.set(0, 0.15, 0);
spherical.set(14.4, 1.18, 0.70);
applyCamera();
});
document.querySelector("#front-view").addEventListener("click", () => {
target.set(0, 0.15, 0);
spherical.set(13.6, Math.PI / 2, 0);
applyCamera();
});
document.querySelector("#top-view").addEventListener("click", () => {
target.set(0, 0.15, 0);
spherical.set(13.8, 0.12, 0);
applyCamera();
});
// Adjustable cutaway.
const cutawayInput = document.querySelector("#cutaway");
const cutValue = document.querySelector("#cut-value");
cutawayInput.addEventListener("input", () => {
cutHalfAngle = THREE.MathUtils.degToRad(Number(cutawayInput.value)) / 2;
cutValue.textContent = `${cutawayInput.value}°`;
rebuildDomes();
});
// -------------------------------------------------------------------------
// Annotation projection and resize
// -------------------------------------------------------------------------
function updateAnnotations() {
scene.updateMatrixWorld(true);
const width = window.innerWidth;
const height = window.innerHeight;
for (const annotation of Object.values(annotationById)) {
const world = annotation.anchor();
const local = relaxedDome.group.parent === scene
? world
: world;
// Convert the dome-local point into world coordinates.
if (annotation.anchor === relaxedDome.tendonAnchor ||
annotation.anchor === relaxedDome.selectedMid) {
relaxedDome.group.localToWorld(local);
} else if (annotation.anchor === contractedDome.tendonAnchor ||
annotation.anchor === contractedDome.selectedMid ||
annotation.anchor === contractedDome.descentAnchor ||
annotation.anchor === contractedDome.rimAnchor) {
contractedDome.group.localToWorld(local);
}
const projected = local.clone().project(camera);
const px = (projected.x * 0.5 + 0.5) * width;
const py = (-projected.y * 0.5 + 0.5) * height;
const cardWidth = annotation.element.offsetWidth || 176;
const cardHeight = annotation.element.offsetHeight || 70;
const lx = THREE.MathUtils.clamp(
px + annotation.dx,
10,
width - cardWidth - 10
);
const ly = THREE.MathUtils.clamp(
py + annotation.dy,
10,
height - cardHeight - 10
);
annotation.element.style.transform =
`translate3d(${lx}px, ${ly}px, 0)`;
const visible = projected.z > -1 && projected.z < 1;
annotation.element.style.opacity = visible ? "1" : "0";
annotation.line.style.opacity = visible ? "1" : "0";
annotation.circle.style.opacity = visible ? "1" : "0";
annotation.line.setAttribute("x1", px);
annotation.line.setAttribute("y1", py);
annotation.line.setAttribute("x2", lx + cardWidth * 0.45);
annotation.line.setAttribute("y2", ly + cardHeight * 0.5);
annotation.circle.setAttribute("cx", px);
annotation.circle.setAttribute("cy", py);
}
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
svg.setAttribute("viewBox", `0 0 ${window.innerWidth} ${window.innerHeight}`);
}
window.addEventListener("resize", resize);
resize();
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
updateAnnotations();
if (firstFrame) {
firstFrame = false;
document.querySelector("#loading").classList.add("hidden");
}
}
animate();
</script>
</body>
</html>
```