Prompt specification
Build or customize the Three.js 3D scene "Hearing pathway selector exhibit" 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: Hearing pathway selector exhibit
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/hearing-pathway-selector-exhibit-x0992
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring ear vibration transmission. Let users choose external, middle, or inner ear stages and highlight transmitted signal type; keep mechanical motion and neural signaling visually distinct without simulating hearing loss. Low-poly.
Working Three.js Starter (hearing-pathway-selector-exhibit-x0992):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Ear Signal Lab — Three.js</title>
<style>
:root {
--bg: #07131b;
--panel: rgba(10, 25, 35, 0.82);
--panel-border: rgba(154, 216, 230, 0.16);
--text: #e9f5f6;
--muted: #91aab1;
--cyan: #58e7ef;
--amber: #ffb65c;
--violet: #a58bff;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#viewport canvas:active {
cursor: grabbing;
}
.topbar {
position: fixed;
z-index: 10;
top: 24px;
left: 26px;
right: 26px;
display: flex;
align-items: flex-start;
justify-content: space-between;
pointer-events: none;
}
.brand {
max-width: 420px;
pointer-events: auto;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 2px;
content: "";
background: var(--cyan);
box-shadow: 0 0 12px rgba(88, 231, 239, 0.6);
}
h1 {
margin: 0;
font-size: clamp(26px, 3vw, 42px);
line-height: 1;
letter-spacing: -0.045em;
}
.subtitle {
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.stage-nav {
position: fixed;
z-index: 11;
left: 26px;
top: 150px;
display: flex;
flex-direction: column;
gap: 8px;
width: 190px;
padding: 8px;
border: 1px solid var(--panel-border);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 16px 45px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(16px);
}
.stage-nav button {
position: relative;
display: grid;
grid-template-columns: 28px 1fr;
align-items: center;
gap: 8px;
width: 100%;
padding: 11px 10px;
border: 0;
border-radius: 11px;
color: var(--muted);
background: transparent;
text-align: left;
cursor: pointer;
transition:
color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.stage-nav button:hover {
color: var(--text);
background: rgba(255, 255, 255, 0.045);
transform: translateX(2px);
}
.stage-nav button.active {
color: var(--text);
background: rgba(88, 231, 239, 0.1);
}
.stage-nav button.active::after {
position: absolute;
right: 9px;
width: 6px;
height: 6px;
content: "";
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 12px var(--cyan);
}
.stage-number {
display: grid;
width: 25px;
height: 25px;
place-items: center;
border: 1px solid rgba(255, 255, 255, 0.11);
border-radius: 8px;
color: #b8cdd1;
font-size: 10px;
font-weight: 800;
}
.active .stage-number {
border-color: rgba(88, 231, 239, 0.4);
color: var(--cyan);
background: rgba(88, 231, 239, 0.08);
}
.stage-nav strong {
display: block;
font-size: 13px;
font-weight: 700;
}
.stage-nav small {
display: block;
margin-top: 2px;
color: #708b92;
font-size: 10px;
}
.info-panel {
position: fixed;
z-index: 10;
top: 100px;
right: 26px;
width: min(340px, calc(100vw - 52px));
padding: 20px;
border: 1px solid var(--panel-border);
border-radius: 20px;
background: var(--panel);
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(18px);
}
.signal-type {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 13px;
padding: 6px 9px;
border: 1px solid rgba(255, 182, 92, 0.25);
border-radius: 999px;
color: var(--amber);
background: rgba(255, 182, 92, 0.08);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.signal-type.neural {
border-color: rgba(88, 231, 239, 0.3);
color: var(--cyan);
background: rgba(88, 231, 239, 0.08);
}
.signal-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 12px currentColor;
}
.info-panel h2 {
margin: 0;
font-size: 24px;
line-height: 1.1;
letter-spacing: -0.035em;
}
.description {
min-height: 62px;
margin: 12px 0 16px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.route {
display: grid;
gap: 7px;
padding: 13px;
border: 1px solid rgba(255, 255, 255, 0.07);
border-radius: 13px;
background: rgba(0, 0, 0, 0.12);
}
.route-step {
display: flex;
align-items: center;
gap: 9px;
color: #bed0d4;
font-size: 11px;
}
.route-step::before {
width: 6px;
height: 6px;
flex: 0 0 auto;
content: "";
border: 1px solid var(--amber);
border-radius: 50%;
box-shadow: 0 0 8px rgba(255, 182, 92, 0.35);
}
.route-step:not(:last-child)::after {
width: 1px;
height: 7px;
margin-left: 2px;
content: "";
background: rgba(255, 255, 255, 0.1);
}
.controls {
display: flex;
gap: 8px;
margin-top: 16px;
}
.control-button {
flex: 1;
padding: 10px 11px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 10px;
color: #c8dadd;
background: rgba(255, 255, 255, 0.04);
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition:
border-color 150ms ease,
color 150ms ease,
background 150ms ease;
}
.control-button:hover {
border-color: rgba(88, 231, 239, 0.35);
color: white;
background: rgba(88, 231, 239, 0.08);
}
.legend {
position: fixed;
z-index: 10;
right: 26px;
bottom: 25px;
display: flex;
gap: 8px;
padding: 9px;
border: 1px solid var(--panel-border);
border-radius: 13px;
background: var(--panel);
backdrop-filter: blur(14px);
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
padding: 5px 8px;
color: #a9bec3;
font-size: 10px;
white-space: nowrap;
}
.legend-swatch {
width: 18px;
height: 3px;
border-radius: 3px;
background: var(--amber);
box-shadow: 0 0 8px rgba(255, 182, 92, 0.55);
}
.legend-swatch.neural {
background: var(--cyan);
box-shadow: 0 0 8px rgba(88, 231, 239, 0.6);
}
.note {
position: fixed;
z-index: 10;
left: 26px;
bottom: 25px;
max-width: 480px;
padding: 9px 12px;
border: 1px solid var(--panel-border);
border-radius: 10px;
color: #829ca2;
background: rgba(7, 19, 27, 0.72);
font-size: 10px;
line-height: 1.45;
backdrop-filter: blur(10px);
}
.camera-hint {
position: fixed;
z-index: 8;
left: 50%;
bottom: 28px;
transform: translateX(-50%);
color: rgba(185, 207, 211, 0.55);
font-size: 10px;
pointer-events: none;
}
#labels {
position: fixed;
z-index: 5;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.anatomy-label {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
padding: 5px 8px;
border: 1px solid rgba(167, 214, 222, 0.18);
border-radius: 7px;
color: #d3e3e5;
background: rgba(5, 16, 23, 0.74);
box-shadow: 0 5px 18px rgba(0, 0, 0, 0.18);
font-size: 9px;
letter-spacing: 0.02em;
white-space: nowrap;
transform: translate(-50%, -50%);
backdrop-filter: blur(8px);
}
.anatomy-label::before {
width: 5px;
height: 5px;
content: "";
border-radius: 50%;
background: #b9dce2;
box-shadow: 0 0 8px rgba(185, 220, 226, 0.6);
}
@media (max-width: 820px) {
.topbar {
top: 16px;
left: 16px;
right: 16px;
}
.subtitle {
display: none;
}
.stage-nav {
top: auto;
left: 50%;
bottom: 70px;
width: min(420px, calc(100vw - 24px));
transform: translateX(-50%);
flex-direction: row;
}
.stage-nav button {
grid-template-columns: 1fr;
justify-items: center;
text-align: center;
}
.stage-nav small,
.stage-nav button.active::after {
display: none;
}
.stage-nav strong {
font-size: 11px;
}
.info-panel {
top: 78px;
right: 16px;
width: 255px;
padding: 15px;
}
.info-panel h2 {
font-size: 20px;
}
.description {
min-height: 0;
margin: 9px 0 12px;
font-size: 11px;
}
.route {
display: none;
}
.controls {
margin-top: 12px;
}
.legend {
right: 16px;
bottom: 15px;
}
.note,
.camera-hint {
display: none;
}
}
@media (max-width: 520px) {
.info-panel {
top: 76px;
left: 16px;
right: 16px;
width: auto;
}
.description,
.controls {
display: none;
}
.signal-type {
margin-bottom: 7px;
}
.legend {
left: 16px;
right: 16px;
justify-content: center;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div id="labels" aria-hidden="true"></div>
<header class="topbar">
<div class="brand">
<div class="eyebrow">Interactive anatomy · 01</div>
<h1>Ear Signal Lab</h1>
<p class="subtitle">
Follow vibration from airborne pressure to cochlear fluid and neural activity.
</p>
</div>
</header>
<nav class="stage-nav" aria-label="Ear stage">
<button type="button" data-stage="external" class="active" aria-pressed="true">
<span class="stage-number">01</span>
<span>
<strong>External ear</strong>
<small>Air & pressure waves</small>
</span>
</button>
<button type="button" data-stage="middle" aria-pressed="false">
<span class="stage-number">02</span>
<span>
<strong>Middle ear</strong>
<small>Ossicular movement</small>
</span>
</button>
<button type="button" data-stage="inner" aria-pressed="false">
<span class="stage-number">03</span>
<span>
<strong>Inner ear</strong>
<small>Fluid & nerve signals</small>
</span>
</button>
</nav>
<aside class="info-panel" aria-live="polite">
<div id="signalType" class="signal-type">
<span class="signal-dot"></span>
<span id="signalText">Acoustic pressure</span>
</div>
<h2 id="stageTitle">Air becomes a pressure wave</h2>
<p id="stageDescription" class="description">
The pinna collects sound and the ear canal directs alternating air pressure
toward the eardrum.
</p>
<div id="route" class="route">
<div class="route-step">Sound enters the air</div>
<div class="route-step">Pinna collects and filters it</div>
<div class="route-step">Pressure reaches the eardrum</div>
</div>
<div class="controls">
<button id="replayButton" class="control-button" type="button">
↻ Replay signal
</button>
<button id="pauseButton" class="control-button" type="button">
Pause
</button>
</div>
</aside>
<div class="legend" aria-label="Signal color legend">
<div class="legend-item">
<span class="legend-swatch"></span>
Mechanical / acoustic
</div>
<div class="legend-item">
<span class="legend-swatch neural"></span>
Neural activity
</div>
</div>
<div class="note">
Normal transmission pathway only. This visualization does not simulate hearing loss
or pathology.
</div>
<div class="camera-hint">Drag to orbit · scroll or pinch to zoom · keys 1–3</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const labelLayer = document.getElementById("labels");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131b);
scene.fog = new THREE.FogExp2(0x07131b, 0.055);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.appendChild(renderer.domElement);
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly model of the external, middle, and inner ear"
);
// Lighting
scene.add(new THREE.HemisphereLight(0xa5dbe4, 0x16202a, 1.45));
const keyLight = new THREE.DirectionalLight(0xd9f6ff, 3.1);
keyLight.position.set(-3, 6, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -6;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x66dce8, 1.4);
rimLight.position.set(6, 1, -5);
scene.add(rimLight);
const amberLight = new THREE.PointLight(0xffa84e, 7, 8, 2);
amberLight.position.set(-4, 0.8, 2.4);
scene.add(amberLight);
const cyanLight = new THREE.PointLight(0x55e9f1, 7, 8, 2);
cyanLight.position.set(4, 0.4, 2.2);
scene.add(cyanLight);
const activeLight = new THREE.PointLight(0x58e7ef, 5, 7, 2);
activeLight.position.set(-3, 0, 1);
scene.add(activeLight);
// Ground and grid
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(18, 10),
new THREE.MeshStandardMaterial({
color: 0x081a23,
roughness: 0.94,
metalness: 0.05
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.85;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(18, 36, 0x1b4550, 0x102d37);
grid.position.y = -1.82;
grid.material.transparent = true;
grid.material.opacity = 0.42;
scene.add(grid);
// Sparse background motes
const motePositions = [];
for (let i = 0; i < 130; i++) {
motePositions.push(
(Math.random() - 0.5) * 15,
Math.random() * 6 - 1.5,
(Math.random() - 0.5) * 8 - 1
);
}
const moteGeometry = new THREE.BufferGeometry();
moteGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(motePositions, 3)
);
const motes = new THREE.Points(
moteGeometry,
new THREE.PointsMaterial({
color: 0x7ebbc5,
size: 0.025,
transparent: true,
opacity: 0.36,
depthWrite: false
})
);
scene.add(motes);
// Shared materials
const materials = {
skin: new THREE.MeshStandardMaterial({
color: 0xd58d73,
roughness: 0.82,
flatShading: true
}),
skinDark: new THREE.MeshStandardMaterial({
color: 0x8c4f48,
roughness: 0.88,
flatShading: true
}),
canal: new THREE.MeshStandardMaterial({
color: 0x805045,
roughness: 0.95,
flatShading: true
}),
bone: new THREE.MeshStandardMaterial({
color: 0xe8d6ad,
roughness: 0.7,
flatShading: true
}),
membrane: new THREE.MeshStandardMaterial({
color: 0x83aeb8,
roughness: 0.48,
metalness: 0.05,
transparent: true,
opacity: 0.86,
flatShading: true
}),
cochlea: new THREE.MeshStandardMaterial({
color: 0xe47e72,
roughness: 0.64,
flatShading: true
}),
nerve: new THREE.MeshStandardMaterial({
color: 0x55dce5,
emissive: 0x0a5961,
emissiveIntensity: 0.7,
roughness: 0.52,
flatShading: true
}),
violet: new THREE.MeshStandardMaterial({
color: 0x8b82bc,
roughness: 0.7,
flatShading: true
}),
dark: new THREE.MeshStandardMaterial({
color: 0x12252e,
roughness: 0.9,
flatShading: true
})
};
const externalGroup = new THREE.Group();
const middleGroup = new THREE.Group();
const innerGroup = new THREE.Group();
externalGroup.position.x = -2.7;
middleGroup.position.x = 0;
innerGroup.position.x = 2.8;
scene.add(externalGroup, middleGroup, innerGroup);
const labels = [];
function addLabel(stage, text, localPosition) {
const element = document.createElement("div");
element.className = "anatomy-label";
element.textContent = text;
labelLayer.appendChild(element);
labels.push({
stage,
element,
group:
stage === "external"
? externalGroup
: stage === "middle"
? middleGroup
: innerGroup,
position: new THREE.Vector3(...localPosition)
});
}
function cylinderBetween(a, b, radius, material, radialSegments = 6) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments,
1,
false
),
material
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function lowPolySphere(radius, material, detail = 1) {
const mesh = new THREE.Mesh(
new THREE.IcosahedronGeometry(radius, detail),
material
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
// ------------------------------------------------------------
// EXTERNAL EAR
// ------------------------------------------------------------
const auricleShape = new THREE.Shape();
auricleShape.moveTo(-0.85, -1.25);
auricleShape.lineTo(0.25, -1.15);
auricleShape.lineTo(0.75, -0.55);
auricleShape.lineTo(0.62, 0.25);
auricleShape.lineTo(0.15, 0.95);
auricleShape.lineTo(-0.25, 1.3);
auricleShape.lineTo(-0.85, 1.1);
auricleShape.lineTo(-1.15, 0.35);
auricleShape.lineTo(-1.05, -0.35);
auricleShape.closePath();
const auricleHole = new THREE.Path();
auricleHole.moveTo(-0.48, -0.75);
auricleHole.lineTo(-0.5, 0.2);
auricleHole.lineTo(-0.28, 0.65);
auricleHole.lineTo(0.05, 0.55);
auricleHole.lineTo(0.3, -0.2);
auricleHole.lineTo(0.08, -0.7);
auricleHole.closePath();
auricleShape.holes.push(auricleHole);
const auricleGeometry = new THREE.ExtrudeGeometry(auricleShape, {
depth: 0.18,
bevelEnabled: false,
curveSegments: 1,
steps: 1
});
auricleGeometry.translate(0, 0, -0.09);
const auricle = new THREE.Mesh(auricleGeometry, materials.skin);
auricle.position.set(-0.72, 0, 0);
auricle.castShadow = true;
auricle.receiveShadow = true;
externalGroup.add(auricle);
// Raised auricular ridge
const ridgeCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-1.42, 0.72, 0.13),
new THREE.Vector3(-0.93, 0.94, 0.15),
new THREE.Vector3(-0.49, 0.48, 0.14),
new THREE.Vector3(-0.56, -0.18, 0.14),
new THREE.Vector3(-0.25, -0.83, 0.13),
new THREE.Vector3(0.2, -0.73, 0.12)
]);
const ridge = new THREE.Mesh(
new THREE.TubeGeometry(ridgeCurve, 24, 0.055, 5, false),
materials.skinDark
);
ridge.castShadow = true;
externalGroup.add(ridge);
// Ear canal
const canal = new THREE.Mesh(
new THREE.CylinderGeometry(0.37, 0.32, 1.25, 7, 1, true),
materials.canal
);
canal.rotation.z = Math.PI / 2;
canal.position.set(0.26, -0.03, 0);
canal.castShadow = true;
externalGroup.add(canal);
const canalMouth = new THREE.Mesh(
new THREE.TorusGeometry(0.34, 0.065, 5, 12),
materials.skinDark
);
canalMouth.rotation.y = Math.PI / 2;
canalMouth.position.set(-0.38, -0.03, 0);
externalGroup.add(canalMouth);
const tragus = lowPolySphere(0.18, materials.skinDark);
tragus.scale.set(0.7, 1.5, 0.65);
tragus.position.set(-0.3, -0.24, 0.17);
externalGroup.add(tragus);
// Pressure wavefronts
const externalWaves = [];
for (let i = 0; i < 4; i++) {
const material = new THREE.MeshBasicMaterial({
color: 0xffb65c,
transparent: true,
opacity: 0.4,
depthWrite: false
});
const wave = new THREE.Mesh(
new THREE.TorusGeometry(0.72, 0.022, 4, 24),
material
);
wave.rotation.y = Math.PI / 2;
wave.position.y = -0.03;
wave.userData.offset = i / 4;
externalGroup.add(wave);
externalWaves.push(wave);
}
addLabel("external", "Pinna", [-1.55, 0.9, 0.2]);
addLabel("external", "Ear canal", [0.35, -0.48, 0.2]);
// ------------------------------------------------------------
// MIDDLE EAR
// ------------------------------------------------------------
const cavity = new THREE.Mesh(
new THREE.CylinderGeometry(0.88, 0.74, 1.55, 8, 1, true),
new THREE.MeshStandardMaterial({
color: 0x263940,
roughness: 0.92,
flatShading: true,
side: THREE.DoubleSide
})
);
cavity.rotation.z = Math.PI / 2;
cavity.position.set(-0.15, 0, -0.02);
middleGroup.add(cavity);
const membranePivot = new THREE.Group();
membranePivot.position.set(-0.93, 0, 0);
middleGroup.add(membranePivot);
const eardrum = new THREE.Mesh(
new THREE.CylinderGeometry(0.68, 0.68, 0.07, 10),
materials.membrane
);
eardrum.rotation.z = Math.PI / 2;
eardrum.castShadow = true;
membranePivot.add(eardrum);
const eardrumRim = new THREE.Mesh(
new THREE.TorusGeometry(0.69, 0.045, 5, 14),
materials.bone
);
eardrumRim.rotation.y = Math.PI / 2;
membranePivot.add(eardrumRim);
// Ossicles
const ossicles = new THREE.Group();
middleGroup.add(ossicles);
const malleusHandle = cylinderBetween(
[-0.56, -0.56, 0.04],
[-0.22, -0.13, 0.04],
0.075,
materials.bone
);
ossicles.add(malleusHandle);
const malleusHead = lowPolySphere(0.17, materials.bone);
malleusHead.position.set(-0.22, -0.09, 0.04);
ossicles.add(malleusHead);
const incusBody = lowPolySphere(0.2, materials.bone);
incusBody.position.set(0.2, 0.05, 0.03);
ossicles.add(incusBody);
const incusArm = cylinderBetween(
[0.25, 0.12, 0.03],
[0.63, 0.42, 0.03],
0.075,
materials.bone
);
ossicles.add(incusArm);
const incusJoint = lowPolySphere(0.1, materials.skinDark);
incusJoint.position.set(0.63, 0.42, 0.03);
ossicles.add(incusJoint);
const stapesArch = new THREE.Mesh(
new THREE.TorusGeometry(0.18, 0.055, 5, 9, Math.PI),
materials.bone
);
stapesArch.rotation.set(0, Math.PI / 2, Math.PI / 2);
stapesArch.position.set(1.0, 0.38, 0.02);
ossicles.add(stapesArch);
const stapesPlateA = cylinderBetween(
[1.0, 0.2, -0.12],
[1.13, 0.38, -0.12],
0.04,
materials.bone
);
const stapesPlateB = cylinderBetween(
[1.0, 0.2, 0.12],
[1.13, 0.38, 0.12],
0.04,
materials.bone
);
ossicles.add(stapesPlateA, stapesPlateB);
const ovalWindow = new THREE.Mesh(
new THREE.CylinderGeometry(0.23, 0.23, 0.08, 8),
materials.violet
);
ovalWindow.rotation.z = Math.PI / 2;
ovalWindow.position.set(1.25, 0.38, 0);
middleGroup.add(ovalWindow);
// Mechanical transmission route
const middleSignalCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-0.9, -0.03, 0.16),
new THREE.Vector3(-0.48, -0.14, 0.17),
new THREE.Vector3(0.02, 0.02, 0.18),
new THREE.Vector3(0.45, 0.24, 0.17),
new THREE.Vector3(0.9, 0.36, 0.15),
new THREE.Vector3(1.24, 0.38, 0.13)
]);
const middleSignalLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(
middleSignalCurve.getPoints(60)
),
new THREE.LineBasicMaterial({
color: 0xffb65c,
transparent: true,
opacity: 0.28
})
);
middleGroup.add(middleSignalLine);
const mechanicalParticles = [];
for (let i = 0; i < 6; i++) {
const particle = new THREE.Mesh(
new THREE.OctahedronGeometry(0.07, 0),
new THREE.MeshBasicMaterial({ color: 0xffb65c })
);
particle.userData.offset = i / 6;
middleGroup.add(particle);
mechanicalParticles.push(particle);
}
addLabel("middle", "Tympanic membrane", [-1.05, -0.84, 0.2]);
addLabel("middle", "Ossicles", [0.25, 0.58, 0.2]);
// ------------------------------------------------------------
// INNER EAR
// ------------------------------------------------------------
const cochleaPoints = [];
for (let i = 0; i <= 100; i++) {
const t = i / 100;
const theta = t * Math.PI * 4.2;
const radius = 1.22 - t * 1.08;
cochleaPoints.push(
new THREE.Vector3(
radius * Math.cos(theta),
radius * Math.sin(theta),
0.08 * Math.sin(theta * 1.5)
)
);
}
const cochleaCurve = new THREE.CatmullRomCurve3(cochleaPoints);
const cochlea = new THREE.Mesh(
new THREE.TubeGeometry(cochleaCurve, 100, 0.17, 6, false),
materials.cochlea
);
cochlea.position.set(-0.3, -0.08, 0);
cochlea.castShadow = true;
cochlea.receiveShadow = true;
innerGroup.add(cochlea);
// Dark core makes the spiral easier to read
const cochleaCore = new THREE.Mesh(
new THREE.TubeGeometry(cochleaCurve, 100, 0.065, 5, false),
materials.dark
);
cochleaCore.position.set(-0.3, -0.08, 0.14);
innerGroup.add(cochleaCore);
// Semicircular canals
const canalMaterial = materials.violet;
const loop1 = new THREE.Mesh(
new THREE.TorusGeometry(0.62, 0.075, 5, 22, Math.PI * 1.58),
canalMaterial
);
loop1.position.set(0.95, 0.88, 0.02);
loop1.rotation.set(0.12, -0.2, 0.4);
innerGroup.add(loop1);
const loop2 = new THREE.Mesh(
new THREE.TorusGeometry(0.55, 0.072, 5, 22, Math.PI * 1.48),
canalMaterial
);
loop2.position.set(1.12, 0.92, 0.02);
loop2.rotation.set(Math.PI / 2, 0.35, -0.1);
innerGroup.add(loop2);
const loop3 = new THREE.Mesh(
new THREE.TorusGeometry(0.48, 0.07, 5, 20, Math.PI * 1.42),
canalMaterial
);
loop3.position.set(0.85, 1.08, 0.02);
loop3.rotation.set(0.5, Math.PI / 2, 0.65);
innerGroup.add(loop3);
const vestibularJunction = lowPolySphere(0.18, canalMaterial);
vestibularJunction.position.set(0.58, 0.45, 0);
innerGroup.add(vestibularJunction);
// Auditory nerve paths
const nerveCurves = [
new THREE.CatmullRomCurve3([
new THREE.Vector3(-0.15, -0.04, 0.02),
new THREE.Vector3(0.45, -0.25, 0.02),
new THREE.Vector3(1.08, -0.38, 0.02),
new THREE.Vector3(1.78, -0.55, 0.02)
]),
new THREE.CatmullRomCurve3([
new THREE.Vector3(-0.16, -0.14, -0.08),
new THREE.Vector3(0.42, -0.43, -0.08),
new THREE.Vector3(1.1, -0.58, -0.08),
new THREE.Vector3(1.82, -0.7, -0.08)
]),
new THREE.CatmullRomCurve3([
new THREE.Vector3(-0.12, -0.08, 0.1),
new THREE.Vector3(0.4, -0.34, 0.1),
new THREE.Vector3(1.07, -0.5, 0.1),
new THREE.Vector3(1.75, -0.62, 0.1)
])
];
nerveCurves.forEach((curve) => {
const nerve = new THREE.Mesh(
new THREE.TubeGeometry(curve, 36, 0.035, 5, false),
materials.nerve
);
innerGroup.add(nerve);
});
// Neural endpoint
const nerveEndpoint = lowPolySphere(0.24, materials.nerve);
nerveEndpoint.scale.set(1.4, 0.9, 0.8);
nerveEndpoint.position.set(1.92, -0.65, 0);
innerGroup.add(nerveEndpoint);
const endpointRing = new THREE.Mesh(
new THREE.TorusGeometry(0.32, 0.035, 5, 16),
new THREE.MeshBasicMaterial({
color: 0x58e7ef,
transparent: true,
opacity: 0.55
})
);
endpointRing.position.copy(nerveEndpoint.position);
endpointRing.rotation.y = Math.PI / 2;
innerGroup.add(endpointRing);
// Cochlear fluid particles: amber and mechanical
const fluidParticles = [];
for (let i = 0; i < 7; i++) {
const particle = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.06, 0),
new THREE.MeshBasicMaterial({ color: 0xffb65c })
);
particle.userData.offset = i / 7;
innerGroup.add(particle);
fluidParticles.push(particle);
}
// Neural packets: cyan core with a soft halo
const neuralParticles = [];
const neuralCoreMaterial = new THREE.MeshBasicMaterial({ color: 0x8af8ff });
const neuralGlowMaterial = new THREE.MeshBasicMaterial({
color: 0x58e7ef,
transparent: true,
opacity: 0.2,
depthWrite: false
});
for (let i = 0; i < 9; i++) {
const packet = new THREE.Group();
const core = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.055, 0),
neuralCoreMaterial
);
const glow = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.125, 1),
neuralGlowMaterial
);
packet.add(core, glow);
packet.userData.offset = i / 9;
packet.userData.curveIndex = i % nerveCurves.length;
innerGroup.add(packet);
neuralParticles.push(packet);
}
addLabel("inner", "Cochlea", [-0.3, -1.22, 0.2]);
addLabel("inner", "Semicircular canals", [1.1, 1.62, 0.15]);
addLabel("inner", "Auditory nerve", [1.45, -1.0, 0.12]);
// ------------------------------------------------------------
// CAMERA CONTROLS — implemented without external addons
// ------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(-3.1, 0, 0),
desiredTarget: new THREE.Vector3(-3.1, 0, 0),
yaw: -0.08,
desiredYaw: -0.08,
elevation: 0.1,
desiredElevation: 0.1,
radius: 5.1,
desiredRadius: 5.1
};
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
let activePointerId = null;
let pinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.pointerType === "touch" && activePointerId !== null) {
return;
}
dragging = true;
activePointerId = event.pointerId;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== activePointerId) return;
const dx = event.clientX - previousPointerX;
const dy = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
cameraState.desiredYaw -= dx * 0.006;
cameraState.desiredElevation = THREE.MathUtils.clamp(
cameraState.desiredElevation + dy * 0.005,
-0.85,
0.9
);
});
function stopDragging(event) {
if (activePointerId !== null && event.pointerId === activePointerId) {
dragging = false;
activePointerId = null;
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.desiredRadius = THREE.MathUtils.clamp(
cameraState.desiredRadius + event.deltaY * 0.003,
2.5,
8
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraState.desiredRadius = stageSettings[currentStage].radius;
cameraState.desiredYaw = stageSettings[currentStage].yaw;
cameraState.desiredElevation = stageSettings[currentStage].elevation;
});
// Basic two-finger pinch support.
const touchPoints = new Map();
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.pointerType === "touch") {
touchPoints.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (event.pointerType !== "touch" || !touchPoints.has(event.pointerId)) {
return;
}
touchPoints.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (touchPoints.size === 2) {
const points = [...touchPoints.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (pinchDistance > 0) {
cameraState.desiredRadius = THREE.MathUtils.clamp(
cameraState.desiredRadius + (pinchDistance - distance) * 0.012,
2.5,
8
);
}
pinchDistance = distance;
}
});
function removeTouch(event) {
touchPoints.delete(event.pointerId);
if (touchPoints.size < 2) pinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", removeTouch);
renderer.domElement.addEventListener("pointercancel", removeTouch);
// ------------------------------------------------------------
// STAGE UI AND CONTENT
// ------------------------------------------------------------
const stageSettings = {
external: {
title: "Air becomes a pressure wave",
description:
"The pinna collects sound and the ear canal directs alternating air pressure toward the eardrum.",
type: "Acoustic pressure",
neural: false,
target: new THREE.Vector3(-3.25, 0, 0),
radius: 5.1,
yaw: -0.08,
elevation: 0.09,
light: 0xffb65c,
route: [
"Sound enters the air",
"Pinna collects and filters it",
"Pressure reaches the eardrum"
]
},
middle: {
title: "Vibration crosses the ossicles",
description:
"The tympanic membrane moves the malleus, incus, and stapes, converting sound into a concentrated mechanical vibration.",
type: "Mechanical vibration",
neural: false,
target: new THREE.Vector3(0.05, 0, 0),
radius: 4.4,
yaw: -0.03,
elevation: 0.08,
light: 0xffb65c,
route: [
"Eardrum moves",
"Ossicles amplify and transfer force",
"Stapes drives the inner-ear fluid"
]
},
inner: {
title: "Fluid motion becomes nerve activity",
description:
"Cochlear fluid displacement bends sensory cells. Their transduction is represented here as cyan action potentials traveling toward the auditory nerve.",
type: "Neural action potential",
neural: true,
target: new THREE.Vector3(3.3, 0, 0),
radius: 4.9,
yaw: 0.13,
elevation: 0.08,
light: 0x58e7ef,
route: [
"Cochlear fluid shifts",
"Sensory cells transduce the motion",
"Auditory nerve carries action potentials"
]
}
};
const buttons = [...document.querySelectorAll("[data-stage]")];
const signalType = document.getElementById("signalType");
const signalText = document.getElementById("signalText");
const stageTitle = document.getElementById("stageTitle");
const stageDescription = document.getElementById("stageDescription");
const route = document.getElementById("route");
const pauseButton = document.getElementById("pauseButton");
const replayButton = document.getElementById("replayButton");
let currentStage = "external";
let isPlaying = true;
let simulationTime = 0;
function setStage(stage) {
currentStage = stage;
const settings = stageSettings[stage];
externalGroup.visible = stage === "external";
middleGroup.visible = stage === "middle";
innerGroup.visible = stage === "inner";
buttons.forEach((button) => {
const selected = button.dataset.stage === stage;
button.classList.toggle("active", selected);
button.setAttribute("aria-pressed", String(selected));
});
signalText.textContent = settings.type;
signalType.classList.toggle("neural", settings.neural);
stageTitle.textContent = settings.title;
stageDescription.textContent = settings.description;
route.replaceChildren(
...settings.route.map((step) => {
const element = document.createElement("div");
element.className = "route-step";
element.textContent = step;
return element;
})
);
cameraState.desiredTarget.copy(settings.target);
cameraState.desiredRadius = settings.radius;
cameraState.desiredYaw = settings.yaw;
cameraState.desiredElevation = settings.elevation;
activeLight.color.setHex(settings.light);
activeLight.intensity = stage === "inner" ? 6 : 4;
}
buttons.forEach((button) => {
button.addEventListener("click", () => setStage(button.dataset.stage));
});
pauseButton.addEventListener("click", () => {
isPlaying = !isPlaying;
pauseButton.textContent = isPlaying ? "Pause" : "Play";
});
replayButton.addEventListener("click", () => {
simulationTime = 0;
});
window.addEventListener("keydown", (event) => {
if (event.key === "1") setStage("external");
if (event.key === "2") setStage("middle");
if (event.key === "3") setStage("inner");
if (event.code === "Space") {
event.preventDefault();
pauseButton.click();
}
});
setStage("external");
// ------------------------------------------------------------
// RESIZE
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
// ------------------------------------------------------------
// ANIMATION
// ------------------------------------------------------------
const clock = new THREE.Clock();
const projected = new THREE.Vector3();
function updateCamera(delta) {
const smoothing = 1 - Math.exp(-delta * 5);
cameraState.target.lerp(cameraState.desiredTarget, smoothing);
cameraState.yaw = THREE.MathUtils.lerp(
cameraState.yaw,
cameraState.desiredYaw,
smoothing
);
cameraState.elevation = THREE.MathUtils.lerp(
cameraState.elevation,
cameraState.desiredElevation,
smoothing
);
cameraState.radius = THREE.MathUtils.lerp(
cameraState.radius,
cameraState.desiredRadius,
smoothing
);
const horizontalRadius =
cameraState.radius * Math.cos(cameraState.elevation);
camera.position.set(
cameraState.target.x +
horizontalRadius * Math.sin(cameraState.yaw),
cameraState.target.y +
cameraState.radius * Math.sin(cameraState.elevation),
cameraState.target.z +
horizontalRadius * Math.cos(cameraState.yaw)
);
camera.lookAt(cameraState.target);
}
function updateLabels() {
for (const label of labels) {
if (label.stage !== currentStage) {
label.element.style.display = "none";
continue;
}
projected.copy(label.position);
label.group.localToWorld(projected);
projected.project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
label.element.style.display = visible ? "flex" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
}
function updateSignals(time) {
// External pressure wavefronts
for (const wave of externalWaves) {
const phase = (time * 0.48 + wave.userData.offset) % 1;
wave.position.x = -3.35 + phase * 2.5;
const fade = Math.sin(Math.PI * phase);
wave.material.opacity = 0.08 + fade * 0.46;
wave.scale.setScalar(0.82 + phase * 0.36);
}
// Middle-ear membrane and ossicular motion
membranePivot.rotation.x = Math.sin(time * 8.5) * 0.032;
ossicles.rotation.z = Math.sin(time * 8.5 + 0.45) * 0.018;
for (const particle of mechanicalParticles) {
const phase = (time * 0.72 + particle.userData.offset) % 1;
particle.position.copy(middleSignalCurve.getPointAt(phase));
particle.rotation.x = time * 2;
particle.rotation.y = time * 3;
particle.scale.setScalar(0.75 + Math.sin(phase * Math.PI) * 0.5);
}
// Cochlear fluid: still mechanical, therefore amber
for (const particle of fluidParticles) {
const phase = (time * 0.32 + particle.userData.offset) % 1;
particle.position.copy(cochleaCurve.getPointAt(phase));
particle.position.x -= 0.3;
particle.position.y -= 0.08;
particle.scale.setScalar(0.7 + Math.sin(phase * Math.PI) * 0.55);
}
// Neural action potentials: cyan, traveling along nerve paths
for (const packet of neuralParticles) {
const curve = nerveCurves[packet.userData.curveIndex];
const phase = (time * 0.58 + packet.userData.offset) % 1;
packet.position.copy(curve.getPointAt(phase));
packet.scale.setScalar(0.72 + Math.sin(phase * Math.PI) * 0.75);
packet.rotation.x = time * 2.5;
packet.rotation.y = time * 3.5;
}
endpointRing.scale.setScalar(1 + Math.sin(time * 3.2) * 0.08);
}
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (isPlaying) simulationTime += delta;
updateCamera(delta);
updateSignals(simulationTime);
updateLabels();
motes.rotation.y += delta * 0.012;
activeLight.position.x = THREE.MathUtils.lerp(
activeLight.position.x,
cameraState.target.x,
1 - Math.exp(-delta * 4)
);
activeLight.position.y = 0.35;
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```