Prompt specification
Build or customize the Three.js 3D scene "Middle-ear linkage 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: Middle-ear linkage model
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/middle-ear-linkage-model-x0989
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a middle-ear ossicle linkage. Build a simplified eardrum, three connected ossicle shapes, and inner-ear boundary; show the contact sequence clearly and label anatomical dimensions exaggerated. A 3D cutaway view.
Working Three.js Starter (middle-ear-linkage-model-x0989):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Middle-Ear Ossicle Linkage</title>
<style>
:root {
--bg: #07131d;
--panel: rgba(9, 25, 37, 0.78);
--line: rgba(174, 220, 239, 0.18);
--text: #eaf7fb;
--muted: #8eabb8;
--cyan: #62d8f5;
--gold: #f5bc72;
--mint: #65d4c4;
--violet: #a9a8ff;
--yellow: #ffe38a;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 48% 42%, #163648 0%, #0b1d2a 38%, #061018 76%),
var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.overlay {
position: fixed;
inset: 0;
pointer-events: none;
}
.masthead {
position: absolute;
top: 24px;
left: 28px;
max-width: 540px;
}
.eyebrow {
margin-bottom: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 42px);
font-weight: 650;
letter-spacing: -0.04em;
line-height: 1;
}
.subtitle {
margin-top: 10px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.direction {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 13px;
padding: 7px 10px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(7, 20, 30, 0.56);
color: #b8d6e1;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.direction span {
color: var(--yellow);
font-size: 15px;
letter-spacing: 0;
}
.dimensions {
position: absolute;
top: 24px;
right: 24px;
width: 252px;
padding: 16px;
border: 1px solid var(--line);
border-radius: 15px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(16px);
pointer-events: auto;
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
color: #c5dce6;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.scale-badge {
padding: 4px 6px;
border-radius: 5px;
background: rgba(255, 227, 138, 0.12);
color: var(--yellow);
font-size: 8px;
letter-spacing: 0.08em;
}
.dimension-row {
display: grid;
grid-template-columns: 8px 1fr auto;
gap: 9px;
align-items: center;
padding: 8px 0;
border-top: 1px solid rgba(255, 255, 255, 0.06);
font-size: 11px;
}
.dimension-row:first-of-type {
border-top: 0;
}
.dimension-row .swatch {
width: 7px;
height: 7px;
border-radius: 50%;
box-shadow: 0 0 10px currentColor;
}
.dimension-row .name {
color: #c7d9e0;
}
.dimension-row .value {
color: #f3fbfd;
font-variant-numeric: tabular-nums;
font-weight: 650;
}
.dimension-note {
margin: 10px 0 0;
color: #7896a4;
font-size: 10px;
line-height: 1.45;
}
.controls {
position: absolute;
left: 26px;
bottom: 146px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
border: 1px solid rgba(167, 217, 235, 0.22);
border-radius: 9px;
padding: 9px 12px;
background: rgba(9, 26, 38, 0.8);
color: #d9edf4;
font: inherit;
font-size: 11px;
font-weight: 650;
cursor: pointer;
backdrop-filter: blur(12px);
transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}
button:hover {
border-color: rgba(98, 216, 245, 0.55);
background: rgba(18, 47, 62, 0.92);
transform: translateY(-1px);
}
button.primary {
min-width: 84px;
border-color: rgba(98, 216, 245, 0.45);
background: rgba(45, 151, 180, 0.22);
}
.hint {
position: absolute;
right: 26px;
bottom: 151px;
color: #718e9b;
font-size: 10px;
letter-spacing: 0.04em;
}
.timeline-wrap {
position: absolute;
right: 22px;
bottom: 18px;
left: 22px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 15px;
background: rgba(7, 21, 31, 0.84);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(18px);
pointer-events: auto;
}
.timeline-top {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px 14px 9px;
border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.timeline-title {
color: #a8c5d1;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.timeline-legend {
color: #6f8c99;
font-size: 9px;
}
.progress-track {
height: 2px;
background: rgba(255, 255, 255, 0.05);
}
#progressFill {
width: 0%;
height: 100%;
background: linear-gradient(90deg, var(--cyan), var(--yellow));
box-shadow: 0 0 12px rgba(255, 227, 138, 0.55);
}
.stages {
display: grid;
grid-template-columns: repeat(5, 1fr);
}
.stage {
position: relative;
min-height: 88px;
padding: 12px 13px 11px;
border: 0;
border-right: 1px solid rgba(255, 255, 255, 0.06);
border-radius: 0;
background: transparent;
text-align: left;
backdrop-filter: none;
}
.stage:last-child {
border-right: 0;
}
.stage:hover {
background: rgba(255, 255, 255, 0.035);
transform: none;
}
.stage.active {
background: linear-gradient(180deg, rgba(98, 216, 245, 0.11), transparent);
}
.stage.active::before {
position: absolute;
top: 0;
right: 12px;
left: 12px;
height: 2px;
border-radius: 0 0 3px 3px;
background: var(--stage-color);
box-shadow: 0 0 10px var(--stage-color);
content: "";
}
.stage-index {
display: inline-block;
margin-bottom: 5px;
color: var(--stage-color);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
}
.stage strong {
display: block;
color: #dcecf1;
font-size: 11px;
font-weight: 700;
}
.stage small {
display: block;
margin-top: 4px;
color: #6f8d9a;
font-size: 9px;
line-height: 1.35;
}
#leaders {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
overflow: visible;
pointer-events: none;
}
#leaders line {
stroke: rgba(163, 211, 227, 0.38);
stroke-width: 1;
stroke-dasharray: 3 4;
}
.annotation {
position: absolute;
min-width: 116px;
max-width: 160px;
padding: 8px 10px;
border: 1px solid rgba(167, 215, 232, 0.18);
border-radius: 8px;
background: rgba(6, 20, 30, 0.8);
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
backdrop-filter: blur(10px);
transform: translate(-50%, -50%);
pointer-events: none;
}
.annotation .anno-kicker {
display: block;
margin-bottom: 2px;
color: var(--anno-color);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.annotation strong {
display: block;
color: #e9f6fa;
font-size: 10px;
line-height: 1.2;
}
.annotation small {
display: block;
margin-top: 3px;
color: #7898a6;
font-size: 8px;
}
.contact-marker {
position: absolute;
display: grid;
width: 24px;
height: 24px;
place-items: center;
border: 1px solid rgba(255, 255, 255, 0.36);
border-radius: 50%;
background: rgba(8, 24, 35, 0.88);
color: #c8dce4;
box-shadow: 0 0 0 4px rgba(98, 216, 245, 0.07);
font-size: 9px;
font-weight: 800;
transform: translate(-50%, -50%);
transition: border-color 160ms ease, color 160ms ease, box-shadow 160ms ease;
}
.contact-marker.active {
border-color: var(--yellow);
color: var(--yellow);
box-shadow: 0 0 0 5px rgba(255, 227, 138, 0.12), 0 0 18px rgba(255, 227, 138, 0.32);
}
@media (max-width: 900px) {
.dimensions {
display: none;
}
.annotation,
#leaders {
display: none;
}
.hint {
display: none;
}
}
@media (max-width: 640px) {
.masthead {
top: 18px;
left: 18px;
}
.subtitle {
max-width: 310px;
}
.controls {
left: 16px;
bottom: 133px;
}
.timeline-wrap {
right: 10px;
bottom: 10px;
left: 10px;
}
.stage {
min-height: 75px;
padding: 10px 7px;
}
.stage small {
display: none;
}
.stage strong {
font-size: 9px;
}
.timeline-legend {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive three-dimensional cutaway of the middle-ear ossicles"></canvas>
<div class="overlay">
<header class="masthead">
<div class="eyebrow">Anatomy / Sound Transmission</div>
<h1>Middle-ear ossicle linkage</h1>
<div class="subtitle">
A cutaway view of the tympanic membrane, malleus, incus, stapes,
and oval window. Dimensions are intentionally exaggerated for clarity.
</div>
<div class="direction"><span>→</span> Sound travels lateral to medial</div>
</header>
<aside class="dimensions">
<div class="panel-title">
Reference dimensions
<span class="scale-badge">3D enlarged</span>
</div>
<div class="dimension-row">
<span class="swatch" style="color:#d9eef3;background:#d9eef3"></span>
<span class="name">Tympanic membrane</span>
<span class="value">Ø 9 mm</span>
</div>
<div class="dimension-row">
<span class="swatch" style="color:#f5bc72;background:#f5bc72"></span>
<span class="name">Malleus</span>
<span class="value">8 mm</span>
</div>
<div class="dimension-row">
<span class="swatch" style="color:#65d4c4;background:#65d4c4"></span>
<span class="name">Incus</span>
<span class="value">7 mm</span>
</div>
<div class="dimension-row">
<span class="swatch" style="color:#a9a8ff;background:#a9a8ff"></span>
<span class="name">Stapes</span>
<span class="value">3 mm</span>
</div>
<div class="dimension-row">
<span class="swatch" style="color:#62d8f5;background:#62d8f5"></span>
<span class="name">Oval window</span>
<span class="value">3.2 × 1.4 mm</span>
</div>
<p class="dimension-note">
Typical adult reference values are shown. The 3D anatomy is simplified
and not drawn to scale.
</p>
</aside>
<svg id="leaders" aria-hidden="true"></svg>
<div class="controls">
<button id="playButton" class="primary" type="button">Pause</button>
<button id="restartButton" type="button">Restart</button>
<button id="resetViewButton" type="button">Reset view</button>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<div class="timeline-wrap">
<div class="timeline-top">
<span class="timeline-title">Contact sequence</span>
<span class="timeline-legend">Animated signal follows the mechanical chain</span>
</div>
<div class="progress-track"><div id="progressFill"></div></div>
<div class="stages">
<button class="stage active" type="button" data-stage="0" style="--stage-color:#d9eef3">
<span class="stage-index">01</span>
<strong>Tympanic membrane</strong>
<small>Acoustic pressure begins lateral vibration.</small>
</button>
<button class="stage" type="button" data-stage="1" style="--stage-color:#f5bc72">
<span class="stage-index">02</span>
<strong>Malleus</strong>
<small>The manubrium transfers force into the head.</small>
</button>
<button class="stage" type="button" data-stage="2" style="--stage-color:#65d4c4">
<span class="stage-index">03</span>
<strong>Incus</strong>
<small>The long process relays the impulse medially.</small>
</button>
<button class="stage" type="button" data-stage="3" style="--stage-color:#a9a8ff">
<span class="stage-index">04</span>
<strong>Stapes</strong>
<small>The smallest bone converts motion into piston action.</small>
</button>
<button class="stage" type="button" data-stage="4" style="--stage-color:#62d8f5">
<span class="stage-index">05</span>
<strong>Oval window</strong>
<small>Footplate pressure launches cochlear fluid waves.</small>
</button>
</div>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, camera, and direct camera controls (no external addons)
// -------------------------------------------------------------------------
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.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.setClearColor(0x07131d, 0);
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x07131d, 0.022);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const target = new THREE.Vector3(0.15, 0.05, 0);
const defaultCameraPosition = new THREE.Vector3(5.25, 3.45, 7.25);
camera.position.copy(defaultCameraPosition);
camera.lookAt(target);
const spherical = new THREE.Spherical().setFromVector3(
camera.position.clone().sub(target)
);
let dragging = false;
let previousX = 0;
let previousY = 0;
function updateCamera() {
spherical.phi = THREE.MathUtils.clamp(spherical.phi, 0.22, Math.PI - 0.22);
spherical.radius = THREE.MathUtils.clamp(spherical.radius, 4.6, 12);
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
}
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
spherical.theta -= dx * 0.006;
spherical.phi -= dy * 0.006;
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
spherical.radius *= Math.exp(event.deltaY * 0.001);
updateCamera();
}, { passive: false });
function resetCamera() {
spherical.setFromVector3(defaultCameraPosition.clone().sub(target));
updateCamera();
}
canvas.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xc9f2ff, 0x09131d, 2.25));
const keyLight = new THREE.DirectionalLight(0xffe1b8, 3.4);
keyLight.position.set(-2.5, 5.5, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -5;
keyLight.shadow.camera.right = 5;
keyLight.shadow.camera.top = 4;
keyLight.shadow.camera.bottom = -4;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x54d7ff, 2.4);
rimLight.position.set(4, 2, -4);
scene.add(rimLight);
const warmPoint = new THREE.PointLight(0xffba70, 8, 8, 2);
warmPoint.position.set(-1.7, 1.1, 1.4);
scene.add(warmPoint);
const coolPoint = new THREE.PointLight(0x54dfff, 10, 9, 2);
coolPoint.position.set(1.6, 0.8, -1.2);
scene.add(coolPoint);
// -------------------------------------------------------------------------
// Materials and helpers
// -------------------------------------------------------------------------
const malleusMaterial = new THREE.MeshPhysicalMaterial({
color: 0xf3b66c,
roughness: 0.38,
metalness: 0.03,
clearcoat: 0.18,
flatShading: true
});
const incusMaterial = new THREE.MeshPhysicalMaterial({
color: 0x59c9bd,
roughness: 0.36,
metalness: 0.02,
clearcoat: 0.18,
flatShading: true
});
const stapesMaterial = new THREE.MeshPhysicalMaterial({
color: 0x9c9cf1,
roughness: 0.34,
metalness: 0.03,
clearcoat: 0.2,
flatShading: true
});
const membraneMaterial = new THREE.MeshPhysicalMaterial({
color: 0xcfe8ed,
roughness: 0.47,
metalness: 0,
transmission: 0.12,
transparent: true,
opacity: 0.82,
side: THREE.DoubleSide,
depthWrite: false
});
const boneMaterial = new THREE.MeshPhysicalMaterial({
color: 0xbcae98,
roughness: 0.86,
transparent: true,
opacity: 0.12,
side: THREE.DoubleSide,
depthWrite: false
});
const innerEarMaterial = new THREE.MeshPhysicalMaterial({
color: 0x50c8e8,
roughness: 0.25,
metalness: 0.02,
transmission: 0.25,
transparent: true,
opacity: 0.15,
side: THREE.DoubleSide,
depthWrite: false
});
function addRod(group, start, end, startRadius, endRadius, material) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
endRadius,
startRadius,
length,
14,
1,
false
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
return mesh;
}
function addOrganicSphere(group, position, scale, material, detail = 24) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(1, detail, Math.max(12, Math.floor(detail * 0.7))),
material
);
mesh.position.copy(position);
mesh.scale.copy(scale);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Cutaway temporal-bone cavity and outer ear canal
// -------------------------------------------------------------------------
const cutawayShell = new THREE.Mesh(
new THREE.CylinderGeometry(
1.27, 1.27, 3.85, 48, 1, true,
Math.PI * 0.5, Math.PI
),
boneMaterial
);
cutawayShell.geometry.rotateZ(Math.PI / 2);
cutawayShell.position.set(-0.93, 0.02, 0);
cutawayShell.renderOrder = -3;
scene.add(cutawayShell);
const shellEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(cutawayShell.geometry, 25),
new THREE.LineBasicMaterial({
color: 0xc7b9a6,
transparent: true,
opacity: 0.2
})
);
shellEdges.position.copy(cutawayShell.position);
scene.add(shellEdges);
const earCanal = new THREE.Mesh(
new THREE.CylinderGeometry(
0.98, 0.8, 1.25, 40, 1, true,
Math.PI * 0.5, Math.PI
),
new THREE.MeshPhysicalMaterial({
color: 0xc0ae95,
roughness: 0.82,
transparent: true,
opacity: 0.19,
side: THREE.DoubleSide,
depthWrite: false
})
);
earCanal.geometry.rotateZ(Math.PI / 2);
earCanal.position.set(-2.66, 0, 0);
scene.add(earCanal);
const canalEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(earCanal.geometry, 25),
new THREE.LineBasicMaterial({
color: 0xd3c0a9,
transparent: true,
opacity: 0.24
})
);
canalEdges.position.copy(earCanal.position);
scene.add(canalEdges);
const annulus = new THREE.Mesh(
new THREE.TorusGeometry(0.94, 0.065, 12, 72),
new THREE.MeshStandardMaterial({
color: 0xbba98f,
roughness: 0.76
})
);
annulus.rotation.y = Math.PI / 2;
annulus.position.set(-2.08, 0, 0);
annulus.castShadow = true;
scene.add(annulus);
// -------------------------------------------------------------------------
// Tympanic membrane
// -------------------------------------------------------------------------
const membraneGroup = new THREE.Group();
membraneGroup.position.set(-2.08, 0, 0);
scene.add(membraneGroup);
const membraneRadius = 0.92;
const membraneGeometry = new THREE.CircleGeometry(membraneRadius, 72);
const membranePositions = membraneGeometry.attributes.position;
const membraneBaseX = new Float32Array(membranePositions.count);
for (let i = 0; i < membranePositions.count; i++) {
const y = membranePositions.getY(i);
const z = membranePositions.getZ(i);
const radiusSquared = (y * y + z * z) / (membraneRadius * membraneRadius);
const x = 0.12 * (1 - radiusSquared);
membranePositions.setXYZ(i, x, y, z);
membraneBaseX[i] = x;
}
membraneGeometry.computeVertexNormals();
const membrane = new THREE.Mesh(membraneGeometry, membraneMaterial);
membrane.renderOrder = 1;
membraneGroup.add(membrane);
// Fine radial fibers make the membrane readable as a membrane rather than a disc.
const fiberPositions = [];
for (let i = 0; i < 24; i++) {
const angle = (i / 24) * Math.PI * 2;
const innerRadius = 0.1 + (i % 3) * 0.03;
const outerRadius = membraneRadius * (0.83 + (i % 4) * 0.035);
const innerX = 0.12 * (1 - (innerRadius / membraneRadius) ** 2);
const outerX = 0.12 * (1 - (outerRadius / membraneRadius) ** 2);
fiberPositions.push(
innerX, Math.cos(angle) * innerRadius, Math.sin(angle) * innerRadius,
outerX, Math.cos(angle) * outerRadius, Math.sin(angle) * outerRadius
);
}
const membraneFibers = new THREE.LineSegments(
new THREE.BufferGeometry().setAttribute(
"position",
new THREE.Float32BufferAttribute(fiberPositions, 3)
),
new THREE.LineBasicMaterial({
color: 0x86aeba,
transparent: true,
opacity: 0.22
})
);
membraneGroup.add(membraneFibers);
// -------------------------------------------------------------------------
// Malleus
// -------------------------------------------------------------------------
const malleusGroup = new THREE.Group();
malleusGroup.position.set(-1.38, 0.28, 0);
scene.add(malleusGroup);
addOrganicSphere(
malleusGroup,
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(0.32, 0.31, 0.29),
malleusMaterial
);
addRod(
malleusGroup,
new THREE.Vector3(-0.04, -0.07, 0),
new THREE.Vector3(-0.57, -0.38, 0),
0.13,
0.07,
malleusMaterial
);
addRod(
malleusGroup,
new THREE.Vector3(-0.08, -0.12, 0),
new THREE.Vector3(-0.31, -0.62, 0),
0.075,
0.035,
malleusMaterial
);
// -------------------------------------------------------------------------
// Incus
// -------------------------------------------------------------------------
const incusGroup = new THREE.Group();
incusGroup.position.set(-1.02, 0.27, 0);
scene.add(incusGroup);
addOrganicSphere(
incusGroup,
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(0.27, 0.29, 0.24),
incusMaterial
);
addRod(
incusGroup,
new THREE.Vector3(0.08, -0.03, 0),
new THREE.Vector3(0.89, -0.07, 0),
0.13,
0.065,
incusMaterial
);
addRod(
incusGroup,
new THREE.Vector3(0.05, 0.08, 0),
new THREE.Vector3(0.18, 0.30, 0.17),
0.09,
0.045,
incusMaterial
);
addOrganicSphere(
incusGroup,
new THREE.Vector3(0.9, -0.07, 0),
new THREE.Vector3(0.12, 0.11, 0.11),
incusMaterial,
18
);
// -------------------------------------------------------------------------
// Stapes
// -------------------------------------------------------------------------
const stapesGroup = new THREE.Group();
stapesGroup.position.set(-0.03, 0.2, 0);
scene.add(stapesGroup);
addOrganicSphere(
stapesGroup,
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(0.16, 0.14, 0.14),
stapesMaterial,
20
);
const stapesTopNeck = new THREE.Vector3(0.16, 0.12, 0.12);
const stapesBottomNeck = new THREE.Vector3(0.16, -0.11, -0.12);
const stapesTopFoot = new THREE.Vector3(0.66, 0.13, 0.24);
const stapesBottomFoot = new THREE.Vector3(0.66, -0.16, -0.24);
addRod(stapesGroup, new THREE.Vector3(0.06, 0.02, 0), stapesTopNeck, 0.09, 0.065, stapesMaterial);
addRod(stapesGroup, new THREE.Vector3(0.06, -0.02, 0), stapesBottomNeck, 0.09, 0.065, stapesMaterial);
addRod(stapesGroup, stapesTopNeck, stapesTopFoot, 0.065, 0.055, stapesMaterial);
addRod(stapesGroup, stapesBottomNeck, stapesBottomFoot, 0.065, 0.055, stapesMaterial);
addOrganicSphere(
stapesGroup,
new THREE.Vector3(0.66, 0, 0),
new THREE.Vector3(0.055, 0.245, 0.285),
stapesMaterial,
20
);
// -------------------------------------------------------------------------
// Oval window and inner-ear boundary
// -------------------------------------------------------------------------
const ovalWindow = new THREE.Mesh(
new THREE.TorusGeometry(0.205, 0.044, 12, 64),
new THREE.MeshStandardMaterial({
color: 0x6fdef5,
emissive: 0x15546c,
emissiveIntensity: 0.7,
roughness: 0.35
})
);
ovalWindow.rotation.y = Math.PI / 2;
ovalWindow.scale.set(1, 1.28, 1);
ovalWindow.position.set(0.73, 0.2, 0);
scene.add(ovalWindow);
const vestibule = new THREE.Mesh(
new THREE.SphereGeometry(1, 40, 28),
innerEarMaterial
);
vestibule.position.set(1.26, 0.2, 0);
vestibule.scale.set(0.57, 0.61, 0.64);
vestibule.renderOrder = -1;
scene.add(vestibule);
const cochleaPoints = [];
const cochleaTurns = Math.PI * 4.6;
for (let i = 0; i <= 190; i++) {
const t = (i / 190) * cochleaTurns;
const radius = 0.68 * (1 - t / cochleaTurns) + 0.065;
cochleaPoints.push(new THREE.Vector3(
1.27 + t * 0.09,
0.2 + Math.cos(t) * radius,
Math.sin(t) * radius
));
}
const cochleaCurve = new THREE.CatmullRomCurve3(cochleaPoints, false, "centripetal");
const cochlea = new THREE.Mesh(
new THREE.TubeGeometry(cochleaCurve, 220, 0.105, 10, false),
new THREE.MeshPhysicalMaterial({
color: 0x62d8f0,
emissive: 0x0b526a,
emissiveIntensity: 0.55,
roughness: 0.26,
transmission: 0.16,
transparent: true,
opacity: 0.72
})
);
scene.add(cochlea);
const cochleaCore = new THREE.Mesh(
new THREE.TubeGeometry(cochleaCurve, 220, 0.036, 8, false),
new THREE.MeshBasicMaterial({
color: 0xb4f4ff,
transparent: true,
opacity: 0.5
})
);
scene.add(cochleaCore);
const canalPoints = [];
for (let i = 0; i <= 72; i++) {
const t = (i / 72) * Math.PI * 2;
canalPoints.push(new THREE.Vector3(
1.28 + Math.cos(t) * 0.3,
0.25 + Math.sin(t) * 0.66,
-0.03
));
}
const semicircularCanal = new THREE.Mesh(
new THREE.TubeGeometry(
new THREE.CatmullRomCurve3(canalPoints, true),
90,
0.07,
9,
true
),
new THREE.MeshPhysicalMaterial({
color: 0x79dff5,
emissive: 0x104e64,
emissiveIntensity: 0.45,
roughness: 0.3,
transparent: true,
opacity: 0.56
})
);
scene.add(semicircularCanal);
// -------------------------------------------------------------------------
// Contact-point halos and the animated sound path
// -------------------------------------------------------------------------
const contacts = [
{
position: new THREE.Vector3(-1.98, -0.09, 0),
phase: 0.1,
color: 0xd9eef3,
number: "01"
},
{
position: new THREE.Vector3(-1.18, 0.27, 0),
phase: 0.3,
color: 0xf5bc72,
number: "02"
},
{
position: new THREE.Vector3(-0.17, 0.2, 0),
phase: 0.5,
color: 0x65d4c4,
number: "03"
},
{
position: new THREE.Vector3(0.67, 0.2, 0),
phase: 0.7,
color: 0xa9a8ff,
number: "04"
},
{
position: new THREE.Vector3(0.78, 0.2, 0),
phase: 0.9,
color: 0x62d8f5,
number: "05"
}
];
contacts.forEach((contact) => {
const halo = new THREE.Mesh(
new THREE.TorusGeometry(0.14, 0.021, 8, 40),
new THREE.MeshBasicMaterial({
color: contact.color,
transparent: true,
opacity: 0.25,
depthWrite: false,
depthTest: false
})
);
halo.rotation.y = Math.PI / 2;
halo.position.copy(contact.position);
halo.renderOrder = 8;
contact.halo = halo;
scene.add(halo);
});
const signalPoints = [
new THREE.Vector3(-2.01, -0.08, 0),
new THREE.Vector3(-1.37, 0.28, 0),
new THREE.Vector3(-1.02, 0.27, 0),
new THREE.Vector3(-0.03, 0.2, 0),
new THREE.Vector3(0.76, 0.2, 0)
];
const signalCurve = new THREE.CatmullRomCurve3(
signalPoints,
false,
"centripetal",
0.12
);
const signalLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(signalCurve.getPoints(120)),
new THREE.LineDashedMaterial({
color: 0xffe38a,
transparent: true,
opacity: 0.18,
dashSize: 0.05,
gapSize: 0.07,
depthWrite: false
})
);
signalLine.computeLineDistances();
scene.add(signalLine);
const pulseMeshes = [];
for (let i = 0; i < 3; i++) {
const pulse = new THREE.Mesh(
new THREE.SphereGeometry(0.075, 16, 12),
new THREE.MeshBasicMaterial({
color: 0xfff0a5,
transparent: true,
opacity: 0.95,
depthWrite: false,
depthTest: false
})
);
pulse.renderOrder = 12;
scene.add(pulse);
pulseMeshes.push(pulse);
}
// -------------------------------------------------------------------------
// Exaggerated dimension brackets
// -------------------------------------------------------------------------
function createDimensionBracket(start, end, color, tickDirection) {
const vertices = [];
const tick = tickDirection.clone().multiplyScalar(0.09);
vertices.push(...start.toArray(), ...end.toArray());
vertices.push(
start.clone().sub(tick).x,
start.clone().sub(tick).y,
start.clone().sub(tick).z,
start.clone().add(tick).x,
start.clone().add(tick).y,
start.clone().add(tick).z
);
vertices.push(
end.clone().sub(tick).x,
end.clone().sub(tick).y,
end.clone().sub(tick).z,
end.clone().add(tick).x,
end.clone().add(tick).y,
end.clone().add(tick).z
);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(vertices, 3));
const line = new THREE.LineSegments(
geometry,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.52,
depthTest: false
})
);
line.renderOrder = 7;
scene.add(line);
}
createDimensionBracket(
new THREE.Vector3(-1.95, -0.62, 0),
new THREE.Vector3(-1.18, -0.62, 0),
0xf5bc72,
new THREE.Vector3(0, 1, 0)
);
createDimensionBracket(
new THREE.Vector3(-1.02, -0.74, 0.13),
new THREE.Vector3(-0.12, -0.74, 0.13),
0x65d4c4,
new THREE.Vector3(0, 1, 0)
);
createDimensionBracket(
new THREE.Vector3(-0.03, -0.62, -0.16),
new THREE.Vector3(0.67, -0.62, -0.16),
0xa9a8ff,
new THREE.Vector3(0, 1, 0)
);
createDimensionBracket(
new THREE.Vector3(-2.18, -0.92, -0.92),
new THREE.Vector3(-2.18, -0.92, 0.92),
0xd9eef3,
new THREE.Vector3(1, 0, 0)
);
// -------------------------------------------------------------------------
// HTML annotations projected from 3D anchor points
// -------------------------------------------------------------------------
const leaderSvg = document.querySelector("#leaders");
const annotations = [];
function createAnnotation(kicker, title, detail, color, anchor, offset) {
const element = document.createElement("div");
element.className = "annotation";
element.style.setProperty("--anno-color", color);
element.innerHTML = `
<span class="anno-kicker">${kicker}</span>
<strong>${title}</strong>
<small>${detail}</small>
`;
document.querySelector(".overlay").appendChild(element);
const line = document.createElementNS("http://www.w3.org/2000/svg", "line");
leaderSvg.appendChild(line);
annotations.push({
element,
line,
anchor: anchor.clone(),
offset
});
}
createAnnotation(
"Tympanic membrane",
"Eardrum",
"Ø ~9 mm · enlarged",
"#d9eef3",
new THREE.Vector3(-2.08, -0.76, 0.18),
[-95, 72]
);
createAnnotation(
"Ossicle 01",
"Malleus",
"~8 mm · enlarged",
"#f5bc72",
new THREE.Vector3(-1.55, 0.64, 0.08),
[-90, -74]
);
createAnnotation(
"Ossicle 02",
"Incus",
"~7 mm · enlarged",
"#65d4c4",
new THREE.Vector3(-0.76, 0.62, 0.05),
[-30, -112]
);
createAnnotation(
"Ossicle 03",
"Stapes",
"~3 mm · enlarged",
"#a9a8ff",
new THREE.Vector3(0.26, 0.5, 0.1),
[54, -102]
);
createAnnotation(
"Inner ear",
"Oval window",
"3.2 × 1.4 mm",
"#62d8f5",
new THREE.Vector3(0.79, 0.61, 0),
[56, -82]
);
const markerElements = contacts.map((contact) => {
const element = document.createElement("div");
element.className = "contact-marker";
element.textContent = contact.number;
document.querySelector(".overlay").appendChild(element);
return element;
});
const projected = new THREE.Vector3();
function projectPoint(point) {
projected.copy(point).project(camera);
return {
x: (projected.x * 0.5 + 0.5) * window.innerWidth,
y: (-projected.y * 0.5 + 0.5) * window.innerHeight,
visible: projected.z > -1 && projected.z < 1
};
}
function updateAnnotations() {
annotations.forEach((annotation) => {
const point = projectPoint(annotation.anchor);
const rect = annotation.element.getBoundingClientRect();
const x = THREE.MathUtils.clamp(
point.x + annotation.offset[0],
rect.width * 0.5 + 10,
window.innerWidth - rect.width * 0.5 - 10
);
const y = THREE.MathUtils.clamp(
point.y + annotation.offset[1],
92,
window.innerHeight - 145
);
annotation.element.style.left = `${x}px`;
annotation.element.style.top = `${y}px`;
annotation.element.style.opacity = point.visible ? "1" : "0";
const lineEndX = point.x < x ? x - rect.width / 2 : x + rect.width / 2;
annotation.line.setAttribute("x1", point.x);
annotation.line.setAttribute("y1", point.y);
annotation.line.setAttribute("x2", lineEndX);
annotation.line.setAttribute("y2", y);
annotation.line.style.opacity = point.visible ? "1" : "0";
});
contacts.forEach((contact, index) => {
const point = projectPoint(contact.position);
const marker = markerElements[index];
marker.style.left = `${point.x}px`;
marker.style.top = `${point.y}px`;
marker.style.opacity = point.visible ? "1" : "0";
});
}
// -------------------------------------------------------------------------
// Timeline and playback
// -------------------------------------------------------------------------
const duration = 12;
let elapsed = 0;
let playing = true;
let lastStage = -1;
const stageButtons = [...document.querySelectorAll(".stage")];
const progressFill = document.querySelector("#progressFill");
const playButton = document.querySelector("#playButton");
function setPlaying(value) {
playing = value;
playButton.textContent = playing ? "Pause" : "Play";
}
playButton.addEventListener("click", () => setPlaying(!playing));
document.querySelector("#restartButton").addEventListener("click", () => {
elapsed = 0;
setPlaying(true);
});
document.querySelector("#resetViewButton").addEventListener("click", resetCamera);
stageButtons.forEach((button, index) => {
button.addEventListener("click", () => {
elapsed = (index / 5) * duration + 0.01;
setPlaying(true);
});
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) elapsed += delta;
const cycle = (elapsed % duration) / duration;
const stage = Math.min(4, Math.floor(cycle * 5));
if (stage !== lastStage) {
stageButtons.forEach((button, index) => {
button.classList.toggle("active", index === stage);
});
lastStage = stage;
}
progressFill.style.width = `${cycle * 100}%`;
// Amplified membrane motion.
const membraneAmplitude = 0.035;
const membranePosition = membraneGeometry.attributes.position;
for (let i = 0; i < membranePosition.count; i++) {
const y = membranePosition.getY(i);
const z = membranePosition.getZ(i);
const radialWeight = Math.max(0, 1 - (y * y + z * z) / (membraneRadius * membraneRadius));
membranePosition.setX(
i,
membraneBaseX[i] +
Math.sin(elapsed * 22) * membraneAmplitude * radialWeight
);
}
membranePosition.needsUpdate = true;
// Tiny phase-shifted movements emphasize the mechanical chain.
malleusGroup.rotation.z = Math.sin(elapsed * 12 + 0.4) * 0.012;
incusGroup.rotation.z = Math.sin(elapsed * 12 + 1.1) * 0.009;
stapesGroup.rotation.z = Math.sin(elapsed * 12 + 1.8) * 0.006;
stapesGroup.position.x = -0.03 + Math.sin(elapsed * 12 + 2.0) * 0.008;
// Contact halos illuminate in sequence.
contacts.forEach((contact, index) => {
const difference = Math.abs(cycle - contact.phase);
const wrappedDifference = Math.min(difference, 1 - difference);
const strength = Math.exp(-Math.pow(wrappedDifference / 0.055, 2));
contact.halo.material.opacity = 0.15 + strength * 0.72;
contact.halo.scale.setScalar(1 + strength * 0.4);
markerElements[index].classList.toggle("active", index === stage);
});
// Traveling energy pulses make the force-transfer direction explicit.
pulseMeshes.forEach((pulse, index) => {
const pulsePosition = (cycle + index / pulseMeshes.length) % 1;
const point = signalCurve.getPointAt(pulsePosition);
pulse.position.copy(point);
const pulseScale = 0.82 + Math.sin(elapsed * 15 + index) * 0.16;
pulse.scale.setScalar(pulseScale);
pulse.material.opacity = 0.65 + Math.sin(elapsed * 15 + index) * 0.22;
});
ovalWindow.material.emissiveIntensity =
0.55 + Math.exp(-Math.pow(Math.min(Math.abs(cycle - 0.9), 1 - Math.abs(cycle - 0.9)) / 0.07, 2)) * 1.4;
updateAnnotations();
renderer.render(scene, camera);
}
animate();
// -------------------------------------------------------------------------
// Responsive resize
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
camera.aspect = width / height;
camera.updateProjectionMatrix();
leaderSvg.setAttribute("viewBox", `0 0 ${width} ${height}`);
leaderSvg.setAttribute("width", width);
leaderSvg.setAttribute("height", height);
}
window.addEventListener("resize", resize);
resize();
</script>
</body>
</html>
```