Prompt specification
Build or customize the Three.js 3D scene "Thoracic component coordination rig" 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: Thoracic component coordination rig
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/thoracic-component-coordination-rig-x0972
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a low-poly thoracic motion teaching rig. Use a transparent torso outline, simplified ribs connected to a central spine, and a separate diaphragm surface beneath the cavity. Two sliders independently adjust rib orientation and diaphragm shape, while a third control plays an authored coordinated breathing cycle. Display the changing cavity outline from the front and side, keeping bone lengths and attachment positions consistent. The independent settings are educational abstractions, not naturally occurring breathing patterns. Avoid diagnostic readouts; the purpose is to inspect how the two structural changes contribute differently to the space enclosed by this schematic model. A detachable front rib section exposes the diaphragm attachment edge, while a translucent outline preserves the neutral cavity shape for comparison with each selected setting.
Working Three.js Starter (thoracic-component-coordination-rig-x0972):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Thoracic Motion Teaching Rig</title>
<style>
:root {
color-scheme: dark;
--bg: #071018;
--panel: rgba(14, 28, 39, 0.88);
--panel-soft: rgba(20, 39, 52, 0.72);
--line: rgba(160, 205, 225, 0.16);
--text: #e9f2f5;
--muted: #91a8b5;
--cyan: #8dd9e8;
--bone: #dfcaaa;
--orange: #ffb473;
--coral: #ff806f;
--green: #9ad9bc;
}
* {
box-sizing: border-box;
}
html, body {
margin: 0;
min-height: 100%;
background:
radial-gradient(circle at 12% 0%, rgba(45, 111, 135, 0.18), transparent 32rem),
radial-gradient(circle at 88% 12%, rgba(130, 73, 61, 0.12), transparent 30rem),
var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
padding: 22px;
}
button, input {
font: inherit;
}
.shell {
width: min(1500px, 100%);
margin: 0 auto;
}
header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 28px;
margin-bottom: 18px;
}
.eyebrow {
margin: 0 0 7px;
color: var(--cyan);
font-size: 0.72rem;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(1.65rem, 3vw, 2.8rem);
font-weight: 680;
letter-spacing: -0.035em;
line-height: 1.03;
}
.subtitle {
max-width: 760px;
margin: 11px 0 0;
color: var(--muted);
font-size: 0.94rem;
line-height: 1.55;
}
.badge {
flex: 0 0 auto;
padding: 10px 13px;
border: 1px solid rgba(154, 217, 188, 0.22);
border-radius: 999px;
background: rgba(154, 217, 188, 0.06);
color: var(--green);
font-size: 0.75rem;
letter-spacing: 0.04em;
white-space: nowrap;
}
.layout {
display: grid;
grid-template-columns: minmax(0, 1.35fr) minmax(370px, 0.65fr);
gap: 18px;
align-items: stretch;
}
.card {
overflow: hidden;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
}
.scene-card {
min-height: 720px;
position: relative;
}
#viewport {
position: absolute;
inset: 0;
overflow: hidden;
background: #07141e;
}
#viewport canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
cursor: grab;
touch-action: none;
}
#viewport canvas:active {
cursor: grabbing;
}
.scene-top {
position: absolute;
z-index: 2;
top: 18px;
left: 18px;
right: 18px;
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 16px;
pointer-events: none;
}
.scene-title,
.scene-help {
border: 1px solid rgba(168, 215, 231, 0.13);
border-radius: 12px;
background: rgba(6, 18, 27, 0.62);
backdrop-filter: blur(8px);
}
.scene-title {
padding: 10px 12px;
}
.scene-title strong {
display: block;
font-size: 0.78rem;
letter-spacing: 0.04em;
}
.scene-title span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 0.72rem;
}
.scene-help {
padding: 9px 11px;
color: #a8bdc7;
font-size: 0.7rem;
text-align: right;
line-height: 1.45;
}
.scene-bottom {
position: absolute;
z-index: 2;
left: 18px;
right: 18px;
bottom: 18px;
display: flex;
justify-content: space-between;
align-items: flex-end;
gap: 16px;
pointer-events: none;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 13px;
max-width: 460px;
padding: 10px 12px;
border: 1px solid rgba(168, 215, 231, 0.13);
border-radius: 12px;
background: rgba(6, 18, 27, 0.68);
color: #b2c4cc;
font-size: 0.7rem;
backdrop-filter: blur(8px);
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 8px;
height: 8px;
border-radius: 50%;
box-shadow: 0 0 9px currentColor;
}
.swatch.bone { background: var(--bone); color: var(--bone); }
.swatch.diaphragm { background: var(--coral); color: var(--coral); }
.swatch.torso { background: var(--cyan); color: var(--cyan); }
.swatch.anchor { background: #f4d67a; color: #f4d67a; }
.inspection-note {
max-width: 300px;
padding: 10px 12px;
border: 1px solid rgba(255, 180, 115, 0.18);
border-radius: 12px;
background: rgba(48, 27, 23, 0.68);
color: #e6bfa8;
font-size: 0.7rem;
line-height: 1.45;
backdrop-filter: blur(8px);
}
.analysis {
padding: 18px;
}
.section-heading {
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
margin-bottom: 15px;
}
.section-heading h2 {
margin: 0;
font-size: 1rem;
font-weight: 650;
}
.section-heading p {
margin: 0;
color: var(--muted);
font-size: 0.72rem;
}
.control-stack {
display: grid;
gap: 11px;
}
.control {
padding: 13px 14px 12px;
border: 1px solid var(--line);
border-radius: 13px;
background: var(--panel-soft);
}
.control-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
}
.control label {
font-size: 0.83rem;
font-weight: 650;
}
.control output {
color: var(--cyan);
font-size: 0.72rem;
font-weight: 650;
text-align: right;
}
input[type="range"] {
width: 100%;
height: 22px;
margin: 0;
accent-color: var(--cyan);
cursor: pointer;
}
.control[data-kind="diaphragm"] input[type="range"] {
accent-color: var(--coral);
}
.range-labels {
display: flex;
justify-content: space-between;
margin-top: 3px;
color: #718994;
font-size: 0.65rem;
}
.cycle-row {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
gap: 10px;
margin-top: 12px;
}
button {
border: 1px solid rgba(141, 217, 232, 0.22);
border-radius: 11px;
background: rgba(141, 217, 232, 0.09);
color: var(--text);
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
button:hover {
border-color: rgba(141, 217, 232, 0.45);
background: rgba(141, 217, 232, 0.15);
}
button:active {
transform: translateY(1px);
}
button:focus-visible,
input:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 3px;
}
#cycleButton {
min-height: 42px;
padding: 0 15px;
color: #dff8fb;
font-size: 0.78rem;
font-weight: 650;
text-align: left;
}
#cycleButton span:first-child {
display: inline-block;
width: 24px;
color: var(--cyan);
}
#detachButton {
min-width: 150px;
padding: 0 13px;
color: #f2c3b4;
border-color: rgba(255, 128, 111, 0.22);
background: rgba(255, 128, 111, 0.07);
font-size: 0.75rem;
}
#detachButton[aria-pressed="true"] {
border-color: rgba(255, 128, 111, 0.48);
background: rgba(255, 128, 111, 0.15);
}
.progress-track {
height: 3px;
margin-top: 9px;
overflow: hidden;
border-radius: 99px;
background: rgba(141, 217, 232, 0.09);
}
#cycleProgress {
width: 0%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--cyan), var(--coral));
}
.phase-row {
display: flex;
justify-content: space-between;
align-items: center;
gap: 10px;
margin-top: 8px;
color: #839aa6;
font-size: 0.67rem;
}
#phaseLabel {
color: #b6cad3;
}
.envelope-heading {
margin: 19px 0 10px;
}
.envelope-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.envelope {
overflow: hidden;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(5, 16, 24, 0.58);
}
.envelope header {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 8px;
padding: 10px 11px 0;
}
.envelope header strong {
font-size: 0.77rem;
}
.envelope header small {
color: #728b97;
font-size: 0.61rem;
}
.envelope svg {
display: block;
width: 100%;
aspect-ratio: 1.12;
padding: 4px;
}
.grid-line {
stroke: rgba(140, 190, 209, 0.09);
stroke-width: 1;
vector-effect: non-scaling-stroke;
}
.axis-line {
stroke: rgba(140, 190, 209, 0.15);
stroke-width: 1;
vector-effect: non-scaling-stroke;
}
.front-current,
.side-current {
stroke-width: 2;
vector-effect: non-scaling-stroke;
}
.front-current {
fill: rgba(255, 180, 115, 0.1);
stroke: var(--orange);
}
.side-current {
fill: rgba(255, 128, 111, 0.12);
stroke: var(--coral);
}
.front-neutral,
.side-neutral {
fill: rgba(116, 215, 255, 0.025);
stroke: rgba(141, 217, 232, 0.48);
stroke-width: 1.25;
stroke-dasharray: 5 5;
vector-effect: non-scaling-stroke;
pointer-events: none;
}
.envelope-legend {
display: flex;
flex-wrap: wrap;
gap: 9px 15px;
margin-top: 10px;
color: #8097a2;
font-size: 0.66rem;
}
.envelope-legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.line-key {
width: 19px;
height: 0;
border-top: 2px solid var(--orange);
}
.line-key.diaphragm-key {
border-color: var(--coral);
}
.line-key.neutral-key {
border-color: rgba(141, 217, 232, 0.62);
border-top-style: dashed;
}
.invariants {
margin-top: 16px;
padding: 12px 13px;
border-left: 2px solid rgba(154, 217, 188, 0.55);
background: rgba(154, 217, 188, 0.045);
color: #9fb3bb;
font-size: 0.7rem;
line-height: 1.52;
}
.invariants strong {
color: #c8ded4;
}
.disclaimer {
margin: 13px 0 0;
color: #78909b;
font-size: 0.68rem;
line-height: 1.5;
}
@media (max-width: 1050px) {
.layout {
grid-template-columns: 1fr;
}
.scene-card {
min-height: 610px;
}
}
@media (max-width: 650px) {
body {
padding: 12px;
}
header {
display: block;
}
.badge {
display: inline-block;
margin-top: 12px;
}
.scene-card {
min-height: 500px;
}
.scene-help,
.inspection-note {
display: none;
}
.scene-bottom {
right: 12px;
left: 12px;
bottom: 12px;
}
.envelope-grid {
grid-template-columns: 1fr;
}
.envelope svg {
aspect-ratio: 1.5;
}
.cycle-row {
grid-template-columns: 1fr;
}
#detachButton {
min-height: 40px;
}
}
</style>
</head>
<body>
<div class="shell">
<header>
<div>
<p class="eyebrow">Structural Motion Study</p>
<h1>Thoracic Motion Teaching Rig</h1>
<p class="subtitle">
Inspect how a schematic rib orientation and a schematic diaphragm shape
alter the space enclosed by the cage. The neutral outline remains visible
for comparison.
</p>
</div>
<div class="badge">Educational abstraction · not a clinical model</div>
</header>
<main class="layout">
<section class="card scene-card" aria-label="Interactive three-dimensional thoracic rig">
<div id="viewport"></div>
<div class="scene-top">
<div class="scene-title">
<strong>Low-poly thoracic assembly</strong>
<span>Rigid rib links · fixed anchors · separate membrane</span>
</div>
<div class="scene-help">
Drag to orbit<br>
Wheel to zoom · double-click to reset
</div>
</div>
<div class="scene-bottom">
<div class="legend" aria-label="Scene legend">
<span><i class="swatch bone"></i>Ribs & spine</span>
<span><i class="swatch diaphragm"></i>Diaphragm</span>
<span><i class="swatch torso"></i>Torso outline</span>
<span><i class="swatch anchor"></i>Fixed attachments</span>
</div>
<div class="inspection-note">
Detach the lower anterior rib section to reveal the diaphragm's
highlighted attachment edge.
</div>
</div>
</section>
<aside class="card analysis">
<div class="section-heading">
<h2>Independent structure controls</h2>
<p>Schematic only</p>
</div>
<div class="control-stack">
<div class="control" data-kind="rib">
<div class="control-head">
<label for="ribSlider">Rib orientation</label>
<output id="ribValue" for="ribSlider">balanced arc</output>
</div>
<input
id="ribSlider"
type="range"
min="-18"
max="42"
step="1"
value="12"
aria-describedby="ribRangeLabels"
>
<div class="range-labels" id="ribRangeLabels">
<span>anterior-low</span>
<span>anterior-high</span>
</div>
</div>
<div class="control" data-kind="diaphragm">
<div class="control-head">
<label for="diaphragmSlider">Diaphragm shape</label>
<output id="diaphragmValue" for="diaphragmSlider">neutral dome</output>
</div>
<input
id="diaphragmSlider"
type="range"
min="-1"
max="1"
step="0.01"
value="0"
aria-describedby="diaphragmRangeLabels"
>
<div class="range-labels" id="diaphragmRangeLabels">
<span>shallow</span>
<span>domed</span>
</div>
</div>
</div>
<div class="cycle-row">
<div>
<button id="cycleButton" type="button" aria-label="Play authored coordinated breathing cycle">
<span id="cycleIcon" aria-hidden="true">▶</span>
<span id="cycleText">Play authored cycle</span>
</button>
<div class="progress-track" aria-hidden="true">
<div id="cycleProgress"></div>
</div>
</div>
<button id="detachButton" type="button" aria-pressed="false">
Detach front section
</button>
</div>
<div class="phase-row">
<span id="phaseLabel" aria-live="polite">Independent controls paused</span>
<span>10-second authored sequence</span>
</div>
<div class="section-heading envelope-heading">
<h2>Cavity envelopes</h2>
<p>Front & side projections</p>
</div>
<div class="envelope-grid">
<article class="envelope">
<header>
<strong>Front</strong>
<small>left ↔ right</small>
</header>
<svg viewBox="-1.65 -1.48 3.3 2.96" preserveAspectRatio="xMidYMid meet" aria-label="Front cavity outline">
<g class="grid">
<line class="grid-line" x1="-1.65" y1="0" x2="1.65" y2="0"></line>
<line class="grid-line" x1="0" y1="-1.48" x2="0" y2="1.48"></line>
<line class="grid-line" x1="-1.1" y1="-1.48" x2="-1.1" y2="1.48"></line>
<line class="grid-line" x1="1.1" y1="-1.48" x2="1.1" y2="1.48"></line>
<line class="grid-line" x1="-1.65" y1="-0.75" x2="1.65" y2="-0.75"></line>
<line class="grid-line" x1="-1.65" y1="0.75" x2="1.65" y2="0.75"></line>
</g>
<path id="frontCurrent" class="front-current"></path>
<path id="frontNeutral" class="front-neutral"></path>
</svg>
</article>
<article class="envelope">
<header>
<strong>Side</strong>
<small>posterior ← anterior</small>
</header>
<svg viewBox="-1.65 -1.48 3.3 2.96" preserveAspectRatio="xMidYMid meet" aria-label="Side cavity outline">
<g class="grid">
<line class="grid-line" x1="-1.65" y1="0" x2="1.65" y2="0"></line>
<line class="grid-line" x1="0" y1="-1.48" x2="0" y2="1.48"></line>
<line class="grid-line" x1="-1.1" y1="-1.48" x2="-1.1" y2="1.48"></line>
<line class="grid-line" x1="1.1" y1="-1.48" x2="1.1" y2="1.48"></line>
<line class="grid-line" x1="-1.65" y1="-0.75" x2="1.65" y2="-0.75"></line>
<line class="grid-line" x1="-1.65" y1="0.75" x2="1.65" y2="0.75"></line>
</g>
<path id="sideCurrent" class="side-current"></path>
<path id="sideNeutral" class="side-neutral"></path>
</svg>
</article>
</div>
<div class="envelope-legend">
<span><i class="line-key"></i>Current front</span>
<span><i class="line-key diaphragm-key"></i>Current side</span>
<span><i class="line-key neutral-key"></i>Neutral reference</span>
</div>
<div class="invariants">
<strong>Held constant:</strong>
every rib-link length, the posterior spine roots, the anterior sternum
attachments, and the diaphragm perimeter. The rib control rotates the
rib arc around its fixed root-to-sternum chord.
</div>
<p class="disclaimer">
The two sliders are independent educational geometric abstractions.
The played sequence is authored for inspection and is not presented as
a naturally occurring breathing pattern.
</p>
</aside>
</main>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
const smoothstep = (t) => {
t = clamp(t, 0, 1);
return t * t * t * (t * (t * 6 - 15) + 10);
};
const defaults = {
rib: 12,
diaphragm: 0
};
let settings = { ...defaults };
let displayed = { ...defaults };
let modelDirty = true;
let cyclePlaying = false;
let cycleStart = 0;
let cycleSaved = { ...settings };
const cycleDuration = 10000;
let detachRequested = 0;
let detachAmount = 0;
// ------------------------------------------------------------
// Three.js scene
// ------------------------------------------------------------
const viewport = $("viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07141e);
scene.fog = new THREE.Fog(0x07141e, 8.5, 15);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
viewport.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, -0.05, 0);
const cameraState = {
theta: 0.58,
phi: 1.13,
radius: 5.35
};
function updateCamera() {
const { theta, phi, radius } = cameraState;
camera.position.set(
cameraTarget.x + radius * Math.sin(phi) * Math.sin(theta),
cameraTarget.y + radius * Math.cos(phi),
cameraTarget.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
scene.add(new THREE.HemisphereLight(0xa9e4f2, 0x17202b, 2.15));
const keyLight = new THREE.DirectionalLight(0xffead5, 3.2);
keyLight.position.set(3.5, 5.5, 4.5);
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x70bfd2, 1.5);
fillLight.position.set(-4, 1.5, -3);
scene.add(fillLight);
const warmLight = new THREE.DirectionalLight(0xff8b72, 1.1);
warmLight.position.set(1.5, -2.5, 2.5);
scene.add(warmLight);
const grid = new THREE.GridHelper(9, 18, 0x31505d, 0x19323e);
grid.position.y = -1.32;
grid.material.transparent = true;
grid.material.opacity = 0.23;
scene.add(grid);
const torsoGroup = new THREE.Group();
const spineGroup = new THREE.Group();
const ribGroup = new THREE.Group();
const diaphragmGroup = new THREE.Group();
scene.add(torsoGroup, spineGroup, ribGroup, diaphragmGroup);
const boneMaterial = new THREE.MeshStandardMaterial({
color: 0xdfcaaa,
roughness: 0.77,
metalness: 0.02,
flatShading: true
});
const spineMaterial = new THREE.MeshStandardMaterial({
color: 0xf0dfc2,
roughness: 0.68,
metalness: 0.02,
flatShading: true
});
const anchorMaterial = new THREE.MeshStandardMaterial({
color: 0xf4d67a,
emissive: 0x6d5315,
emissiveIntensity: 0.5,
roughness: 0.6,
flatShading: true
});
const unitCylinder = new THREE.CylinderGeometry(1, 1, 1, 6, 1, false);
const Y_AXIS = new THREE.Vector3(0, 1, 0);
const X_AXIS = new THREE.Vector3(1, 0, 0);
function addStaticRod(a, b, radius, material, parent) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(unitCylinder, material);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(Y_AXIS, direction.normalize());
mesh.scale.set(radius, length, radius);
parent.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Transparent torso shell and line outline
// ------------------------------------------------------------
const torsoRings = [
{ y: -1.30, rx: 1.20, rz: 0.64 },
{ y: -1.02, rx: 1.38, rz: 0.77 },
{ y: -0.58, rx: 1.34, rz: 0.77 },
{ y: 0.02, rx: 1.38, rz: 0.74 },
{ y: 0.58, rx: 1.46, rz: 0.69 },
{ y: 1.07, rx: 1.31, rz: 0.56 },
{ y: 1.38, rx: 0.91, rz: 0.39 }
];
const torsoSegments = 16;
const torsoVertices = [];
const torsoIndices = [];
const torsoLinePositions = [];
torsoRings.forEach((ring) => {
for (let s = 0; s < torsoSegments; s++) {
const a = (s / torsoSegments) * Math.PI * 2;
const x = Math.cos(a) * ring.rx;
const z = Math.sin(a) * ring.rz;
torsoVertices.push(x, ring.y, z);
}
});
for (let r = 0; r < torsoRings.length - 1; r++) {
for (let s = 0; s < torsoSegments; s++) {
const s2 = (s + 1) % torsoSegments;
const a = r * torsoSegments + s;
const b = r * torsoSegments + s2;
const c = (r + 1) * torsoSegments + s2;
const d = (r + 1) * torsoSegments + s;
torsoIndices.push(a, b, d, b, c, d);
}
}
const torsoGeometry = new THREE.BufferGeometry();
torsoGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(torsoVertices, 3)
);
torsoGeometry.setIndex(torsoIndices);
torsoGeometry.computeVertexNormals();
const torsoShell = new THREE.Mesh(
torsoGeometry,
new THREE.MeshBasicMaterial({
color: 0x79d4e8,
transparent: true,
opacity: 0.035,
side: THREE.DoubleSide,
depthWrite: false
})
);
torsoGroup.add(torsoShell);
torsoRings.forEach((ring) => {
for (let s = 0; s < torsoSegments; s++) {
const a0 = (s / torsoSegments) * Math.PI * 2;
const a1 = ((s + 1) / torsoSegments) * Math.PI * 2;
torsoLinePositions.push(
Math.cos(a0) * ring.rx, ring.y, Math.sin(a0) * ring.rz,
Math.cos(a1) * ring.rx, ring.y, Math.sin(a1) * ring.rz
);
}
});
for (let r = 0; r < torsoRings.length - 1; r++) {
for (let s = 0; s < torsoSegments; s += 2) {
const a = (s / torsoSegments) * Math.PI * 2;
const lower = torsoRings[r];
const upper = torsoRings[r + 1];
torsoLinePositions.push(
Math.cos(a) * lower.rx, lower.y, Math.sin(a) * lower.rz,
Math.cos(a) * upper.rx, upper.y, Math.sin(a) * upper.rz
);
}
}
const torsoLineGeometry = new THREE.BufferGeometry();
torsoLineGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(torsoLinePositions, 3)
);
const torsoLines = new THREE.LineSegments(
torsoLineGeometry,
new THREE.LineBasicMaterial({
color: 0x8dd9e8,
transparent: true,
opacity: 0.18,
depthWrite: false
})
);
torsoGroup.add(torsoLines);
// ------------------------------------------------------------
// Spine, sternum, and fixed attachment hardware
// ------------------------------------------------------------
const vertebralGeometry = new THREE.CylinderGeometry(
0.095, 0.112, 0.145, 7, 1, false
);
for (let i = 0; i < 12; i++) {
const vertebra = new THREE.Mesh(vertebralGeometry, spineMaterial);
vertebra.position.set(0, -1.12 + i * 0.205, -0.56);
vertebra.rotation.y = i * 0.19;
spineGroup.add(vertebra);
}
const sternum = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 2.03, 0.12, 1, 4, 1),
spineMaterial
);
sternum.position.set(0, 0.02, 0.685);
spineGroup.add(sternum);
// ------------------------------------------------------------
// Rib construction
//
// Each rib is a chain of equal-length links between two fixed
// anchors. Changing orientation rotates the planar arc around
// the fixed anchor-to-anchor chord; no segment is scaled.
// ------------------------------------------------------------
const ribLevels = 10;
const ribSegmentCount = 8;
const ribLinkLength = 0.285;
const ribRootZ = -0.56;
const ribEndZ = 0.635;
const ribGeometry = new THREE.CylinderGeometry(
0.032, 0.026, 1, 5, 1, false
);
const anchorGeometry = new THREE.OctahedronGeometry(0.034, 0);
const ribChains = [];
const thetaCoefficients = Array.from(
{ length: ribSegmentCount },
(_, i) => 1 - (2 * i) / (ribSegmentCount - 1)
);
function solveRibAlpha(chordLength) {
const target = chordLength / ribLinkLength;
let low = 0;
let high = 1.9;
const sum = (alpha) =>
thetaCoefficients.reduce(
(total, c) => total + Math.cos(alpha * c),
0
);
for (let i = 0; i < 60; i++) {
const mid = (low + high) * 0.5;
if (sum(mid) > target) {
low = mid;
} else {
high = mid;
}
}
return (low + high) * 0.5;
}
for (let level = 0; level < ribLevels; level++) {
const y = -0.92 + level * 0.205;
for (const side of [-1, 1]) {
const root = new THREE.Vector3(side * 0.09, y, ribRootZ);
const end = new THREE.Vector3(side * 0.105, y, ribEndZ);
addStaticRod(
new THREE.Vector3(0, y, ribRootZ),
root,
0.027,
spineMaterial,
spineGroup
);
const rootMarker = new THREE.Mesh(anchorGeometry, anchorMaterial);
rootMarker.position.copy(root);
spineGroup.add(rootMarker);
const endMarker = new THREE.Mesh(anchorGeometry, anchorMaterial);
endMarker.position.copy(end);
spineGroup.add(endMarker);
const chain = {
level,
side,
root,
end,
alpha: solveRibAlpha(root.distanceTo(end)),
positions: Array.from(
{ length: ribSegmentCount + 1 },
() => new THREE.Vector3()
),
meshes: [],
detachableSegments: []
};
for (let segment = 0; segment < ribSegmentCount; segment++) {
const mesh = new THREE.Mesh(ribGeometry, boneMaterial);
ribGroup.add(mesh);
chain.meshes.push(mesh);
chain.detachableSegments.push(level <= 2 && segment >= 4);
}
ribChains.push(chain);
}
}
function updateRibGeometry(angleDegrees) {
const phi = THREE.MathUtils.degToRad(angleDegrees);
for (const chain of ribChains) {
const chord = new THREE.Vector3().subVectors(chain.end, chain.root);
const chordLength = chord.length();
const D = chord.clone().normalize();
const rawU = new THREE.Vector3(
Math.cos(phi),
Math.sin(phi),
0
);
const U = rawU.clone().addScaledVector(D, -rawU.dot(D)).normalize();
chain.positions[0].copy(chain.root);
for (let i = 0; i < ribSegmentCount; i++) {
const theta = chain.alpha * thetaCoefficients[i];
const direction = new THREE.Vector3()
.addScaledVector(D, Math.cos(theta))
.addScaledVector(U, Math.sin(theta))
.normalize();
chain.positions[i + 1]
.copy(chain.positions[i])
.addScaledVector(direction, ribLinkLength);
}
// The symmetric vector construction reaches the fixed endpoint
// mathematically; this assignment removes floating-point residue.
chain.positions[ribSegmentCount].copy(chain.end);
}
applyRibMeshes();
}
function applyRibMeshes() {
const detachQuaternion = new THREE.Quaternion().setFromAxisAngle(
X_AXIS,
0.42 * detachAmount
);
for (const chain of ribChains) {
for (let segment = 0; segment < ribSegmentCount; segment++) {
const mesh = chain.meshes[segment];
const pA = chain.positions[segment];
const pB = chain.positions[segment + 1];
let a = pA.clone();
let b = pB.clone();
let center = a.clone().add(b).multiplyScalar(0.5);
if (chain.detachableSegments[segment] && detachAmount > 0.001) {
const rotatedA = center.clone()
.add(a.clone().sub(center).applyQuaternion(detachQuaternion));
const rotatedB = center.clone()
.add(b.clone().sub(center).applyQuaternion(detachQuaternion));
const offset = new THREE.Vector3(
chain.side * 0.10 * detachAmount,
-0.24 * detachAmount,
0.26 * detachAmount
);
center.add(offset);
a = rotatedA.add(offset);
b = rotatedB.add(offset);
}
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
mesh.position.copy(center);
mesh.quaternion.setFromUnitVectors(Y_AXIS, direction.normalize());
mesh.scale.set(1, length, 1);
}
}
}
// ------------------------------------------------------------
// Separate diaphragm surface with a fixed perimeter
// ------------------------------------------------------------
const diaphragmState = {
edgeY: -0.76,
edgeX: 0.78,
edgeZ: 0.55,
height: 0.39
};
const diaphragmSegments = 28;
const diaphragmRings = 7;
const diaphragmVertexCount = 1 + diaphragmSegments * diaphragmRings;
const diaphragmPositions = new Float32Array(diaphragmVertexCount * 3);
const diaphragmIndices = [];
for (let s = 0; s < diaphragmSegments; s++) {
const next = (s + 1) % diaphragmSegments;
diaphragmIndices.push(0, 1 + s, 1 + next);
}
for (let ring = 1; ring < diaphragmRings; ring++) {
const previousStart = 1 + (ring - 1) * diaphragmSegments;
const currentStart = 1 + ring * diaphragmSegments;
for (let s = 0; s < diaphragmSegments; s++) {
const next = (s + 1) % diaphragmSegments;
const a = previousStart + s;
const b = previousStart + next;
const c = currentStart + next;
const d = currentStart + s;
diaphragmIndices.push(a, d, b, b, d, c);
}
}
const diaphragmGeometry = new THREE.BufferGeometry();
diaphragmGeometry.setAttribute(
"position",
new THREE.BufferAttribute(diaphragmPositions, 3).setUsage(
THREE.DynamicDrawUsage
)
);
diaphragmGeometry.setIndex(diaphragmIndices);
const diaphragmMaterial = new THREE.MeshStandardMaterial({
color: 0xe86f61,
emissive: 0x5d1814,
emissiveIntensity: 0.38,
roughness: 0.47,
metalness: 0,
transparent: true,
opacity: 0.73,
side: THREE.DoubleSide,
depthWrite: false,
flatShading: true
});
const diaphragmMesh = new THREE.Mesh(
diaphragmGeometry,
diaphragmMaterial
);
diaphragmGroup.add(diaphragmMesh);
const diaphragmWire = new THREE.Mesh(
diaphragmGeometry,
new THREE.MeshBasicMaterial({
color: 0xffc2b7,
wireframe: true,
transparent: true,
opacity: 0.22,
depthWrite: false
})
);
diaphragmGroup.add(diaphragmWire);
const edgePoints = [];
for (let s = 0; s < 40; s++) {
const a = (s / 40) * Math.PI * 2;
edgePoints.push(
new THREE.Vector3(
Math.cos(a) * diaphragmState.edgeX,
diaphragmState.edgeY,
Math.sin(a) * diaphragmState.edgeZ
)
);
}
const edgeCurve = new THREE.CatmullRomCurve3(
edgePoints,
true,
"catmullrom",
0.12
);
const edgeMaterial = new THREE.MeshStandardMaterial({
color: 0xff9a87,
emissive: 0xa82d20,
emissiveIntensity: 0.35,
roughness: 0.45,
flatShading: true
});
const diaphragmEdge = new THREE.Mesh(
new THREE.TubeGeometry(edgeCurve, 128, 0.015, 5, true),
edgeMaterial
);
diaphragmGroup.add(diaphragmEdge);
function updateDiaphragmGeometry(shape) {
diaphragmState.height =
0.13 + ((clamp(shape, -1, 1) + 1) * 0.5) * 0.52;
diaphragmPositions[0] = 0;
diaphragmPositions[1] = diaphragmState.edgeY + diaphragmState.height;
diaphragmPositions[2] = 0;
let offset = 3;
for (let ring = 1; ring <= diaphragmRings; ring++) {
const radius = ring / diaphragmRings;
const dome = Math.pow(Math.max(0, 1 - radius * radius), 1.18);
for (let s = 0; s < diaphragmSegments; s++) {
const a = (s / diaphragmSegments) * Math.PI * 2;
diaphragmPositions[offset++] =
Math.cos(a) * diaphragmState.edgeX * radius;
diaphragmPositions[offset++] =
diaphragmState.edgeY + diaphragmState.height * dome;
diaphragmPositions[offset++] =
Math.sin(a) * diaphragmState.edgeZ * radius;
}
}
diaphragmGeometry.attributes.position.needsUpdate = true;
diaphragmGeometry.computeVertexNormals();
diaphragmGeometry.computeBoundingSphere();
edgeMaterial.emissiveIntensity = 0.35 + detachAmount * 2.6;
diaphragmMaterial.emissiveIntensity = 0.38 + detachAmount * 0.38;
}
// ------------------------------------------------------------
// Projection outlines
// ------------------------------------------------------------
function convexHull(points) {
const sorted = points
.slice()
.sort((a, b) => a.x - b.x || a.y - b.y);
const unique = sorted.filter((point, index) => {
if (index === 0) return true;
const previous = sorted[index - 1];
return Math.abs(point.x - previous.x) > 1e-8 ||
Math.abs(point.y - previous.y) > 1e-8;
});
if (unique.length < 3) return unique;
const cross = (o, a, b) =>
(a.x - o.x) * (b.y - o.y) -
(a.y - o.y) * (b.x - o.x);
const lower = [];
for (const point of unique) {
while (
lower.length >= 2 &&
cross(lower[lower.length - 2], lower[lower.length - 1], point) <= 0
) {
lower.pop();
}
lower.push(point);
}
const upper = [];
for (let i = unique.length - 1; i >= 0; i--) {
const point = unique[i];
while (
upper.length >= 2 &&
cross(upper[upper.length - 2], upper[upper.length - 1], point) <= 0
) {
upper.pop();
}
upper.push(point);
}
lower.pop();
upper.pop();
return lower.concat(upper);
}
function pathFromPoints(points) {
if (!points.length) return "";
const commands = points.map((point, index) => {
const command = index === 0 ? "M" : "L";
return `${command}${point.x.toFixed(4)},${(-point.y).toFixed(4)}`;
});
return `${commands.join(" ")} Z`;
}
function computeFrontPoints() {
const points = [];
for (const chain of ribChains) {
for (let segment = 0; segment < ribSegmentCount; segment++) {
if (
chain.detachableSegments[segment] &&
detachAmount > 0.12
) {
continue;
}
for (const position of [
chain.positions[segment],
chain.positions[segment + 1]
]) {
points.push({ x: position.x, y: position.y });
}
}
}
points.push(
{ x: 0, y: 1.16 },
{ x: 0, y: -1.19 },
{ x: -0.10, y: -1.00 },
{ x: 0.10, y: -1.00 }
);
for (let s = 0; s < 40; s++) {
const a = (s / 40) * Math.PI * 2;
points.push({
x: Math.cos(a) * diaphragmState.edgeX,
y: diaphragmState.edgeY
});
}
return convexHull(points);
}
function computeSidePoints() {
const topChain = ribChains.find(
(chain) => chain.level === ribLevels - 1 && chain.side === 1
);
const points = [
{ x: ribRootZ, y: 1.16 }
];
for (const position of topChain.positions) {
points.push({ x: position.z, y: position.y });
}
points.push(
{ x: 0.685, y: 1.16 },
{ x: diaphragmState.edgeZ, y: diaphragmState.edgeY }
);
for (let step = 1; step <= 42; step++) {
const t = step / 42;
const z = lerp(
diaphragmState.edgeZ,
-diaphragmState.edgeZ,
t
);
const radius = Math.abs(z / diaphragmState.edgeZ);
const y = diaphragmState.edgeY +
diaphragmState.height *
Math.pow(Math.max(0, 1 - radius * radius), 1.18);
points.push({ x: z, y });
}
points.push({
x: -diaphragmState.edgeZ,
y: diaphragmState.edgeY
});
return points;
}
function updateEnvelopePaths() {
$("frontCurrent").setAttribute(
"d",
pathFromPoints(computeFrontPoints())
);
$("sideCurrent").setAttribute(
"d",
pathFromPoints(computeSidePoints())
);
}
updateRibGeometry(defaults.rib);
updateDiaphragmGeometry(defaults.diaphragm);
// Save the neutral reference once; it never changes with the sliders.
const neutralFrontPath = pathFromPoints(computeFrontPoints());
const neutralSidePath = pathFromPoints(computeSidePoints());
$("frontNeutral").setAttribute("d", neutralFrontPath);
$("sideNeutral").setAttribute("d", neutralSidePath);
updateEnvelopePaths();
// ------------------------------------------------------------
// UI labels and authored cycle
// ------------------------------------------------------------
function ribDescription(value) {
if (value < -6) return "anterior-low";
if (value < 6) return "low rake";
if (value < 18) return "balanced arc";
if (value < 30) return "high rake";
return "anterior-high";
}
function diaphragmDescription(value) {
if (value < -0.58) return "very shallow";
if (value < -0.12) return "flatter";
if (value <= 0.12) return "neutral dome";
if (value <= 0.58) return "more domed";
return "high dome";
}
function updateOutputs(values = settings) {
$("ribValue").textContent = ribDescription(values.rib);
$("diaphragmValue").textContent =
diaphragmDescription(values.diaphragm);
$("ribSlider").value = values.rib;
$("diaphragmSlider").value = values.diaphragm;
}
function setPhase(text) {
$("phaseLabel").textContent = text;
}
function setCycleButton(playing) {
$("cycleIcon").textContent = playing ? "Ⅱ" : "▶";
$("cycleText").textContent = playing
? "Pause authored cycle"
: "Play authored cycle";
}
function resetCycleUI() {
cyclePlaying = false;
$("cycleProgress").style.width = "0%";
$("ribSlider").disabled = false;
$("diaphragmSlider").disabled = false;
setCycleButton(false);
}
$("ribSlider").addEventListener("input", (event) => {
if (cyclePlaying) return;
settings.rib = Number(event.target.value);
displayed = { ...settings };
updateOutputs();
modelDirty = true;
});
$("diaphragmSlider").addEventListener("input", (event) => {
if (cyclePlaying) return;
settings.diaphragm = Number(event.target.value);
displayed = { ...settings };
updateOutputs();
modelDirty = true;
});
$("cycleButton").addEventListener("click", () => {
if (cyclePlaying) {
resetCycleUI();
displayed = { ...settings };
updateOutputs();
setPhase("Independent controls resumed");
modelDirty = true;
return;
}
cyclePlaying = true;
cycleSaved = { ...settings };
cycleStart = performance.now();
$("ribSlider").disabled = true;
$("diaphragmSlider").disabled = true;
setCycleButton(true);
setPhase("Settling to the neutral reference");
});
$("detachButton").addEventListener("click", () => {
detachRequested = detachRequested ? 0 : 1;
$("detachButton").setAttribute(
"aria-pressed",
String(Boolean(detachRequested))
);
$("detachButton").textContent = detachRequested
? "Attach front section"
: "Detach front section";
});
function updateCycle(now) {
const progress = clamp(
(now - cycleStart) / cycleDuration,
0,
1
);
const neutral = { ...defaults };
const expanded = {
rib: 30,
diaphragm: 0.88
};
if (progress < 0.08) {
const t = smoothstep(progress / 0.08);
displayed = {
rib: lerp(cycleSaved.rib, neutral.rib, t),
diaphragm: lerp(cycleSaved.diaphragm, neutral.diaphragm, t)
};
setPhase("Settling to the neutral reference");
} else if (progress < 0.38) {
const t = smoothstep((progress - 0.08) / 0.30);
displayed = {
rib: lerp(neutral.rib, expanded.rib, t),
diaphragm: lerp(neutral.diaphragm, expanded.diaphragm, t)
};
setPhase("Authored coordinated expansion");
} else if (progress < 0.50) {
displayed = { ...expanded };
setPhase("Authored hold");
} else if (progress < 0.80) {
const t = smoothstep((progress - 0.50) / 0.30);
displayed = {
rib: lerp(expanded.rib, neutral.rib, t),
diaphragm: lerp(expanded.diaphragm, neutral.diaphragm, t)
};
setPhase("Authored coordinated return");
} else {
const t = smoothstep((progress - 0.80) / 0.20);
displayed = {
rib: lerp(neutral.rib, cycleSaved.rib, t),
diaphragm: lerp(neutral.diaphragm, cycleSaved.diaphragm, t)
};
setPhase("Restoring the independent setting");
}
$("cycleProgress").style.width = `${progress * 100}%`;
updateOutputs(displayed);
modelDirty = true;
if (progress >= 1) {
displayed = { ...cycleSaved };
updateOutputs();
resetCycleUI();
setPhase("Authored cycle complete");
modelDirty = true;
}
}
// ------------------------------------------------------------
// Direct camera controls: orbit, zoom, reset
// ------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = clamp(cameraState.phi + dy * 0.005, 0.55, 2.35);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = clamp(
cameraState.radius + event.deltaY * 0.0035,
3.5,
8.5
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraState.theta = 0.58;
cameraState.phi = 1.13;
cameraState.radius = 5.35;
updateCamera();
});
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
function resizeRenderer() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resizeRenderer);
resizeObserver.observe(viewport);
resizeRenderer();
function animate(now) {
requestAnimationFrame(animate);
if (cyclePlaying) {
updateCycle(now);
}
if (modelDirty) {
updateRibGeometry(displayed.rib);
updateDiaphragmGeometry(displayed.diaphragm);
updateEnvelopePaths();
modelDirty = false;
}
if (Math.abs(detachRequested - detachAmount) > 0.001) {
detachAmount +=
(detachRequested - detachAmount) * 0.085;
if (Math.abs(detachRequested - detachAmount) < 0.002) {
detachAmount = detachRequested;
}
applyRibMeshes();
updateDiaphragmGeometry(displayed.diaphragm);
updateEnvelopePaths();
}
renderer.render(scene, camera);
}
updateOutputs();
setPhase("Independent controls paused");
requestAnimationFrame(animate);
</script>
</body>
</html>
```