Prompt specification
Build or customize the Three.js 3D scene "Sound-to-motion transfer demonstration" 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: Sound-to-motion transfer demonstration
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/sound-to-motion-transfer-demonstration-x0990
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring ear vibration transmission. Animate an incoming pressure-wave indicator driving eardrum motion and a linked ossicle movement; distinguish air-particle oscillation from the movement of sound through space. A 3D cutaway view.
Working Three.js Starter (sound-to-motion-transfer-demonstration-x0990):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Ear Pressure Transmission — 3D Cutaway</title>
<style>
:root {
color-scheme: dark;
--bg: #061019;
--panel: rgba(9, 22, 33, 0.78);
--line: rgba(171, 213, 230, 0.16);
--text: #edf7fa;
--muted: #91aab5;
--cyan: #63e7ff;
--amber: #ffd166;
--coral: #ee9a8d;
--mint: #4ce3c3;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 48% 44%, #102b3a 0%, #071722 42%, #040a10 100%);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
button,
input {
font: inherit;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
.title-block {
position: fixed;
top: 28px;
left: 30px;
z-index: 5;
width: min(440px, calc(100vw - 60px));
pointer-events: none;
}
.eyebrow {
margin-bottom: 9px;
color: var(--cyan);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
max-width: 430px;
font-size: clamp(28px, 3.6vw, 50px);
font-weight: 650;
line-height: 0.98;
letter-spacing: -0.045em;
text-wrap: balance;
}
.subtitle {
max-width: 410px;
margin: 14px 0 0;
color: #aac0ca;
font-size: 13px;
line-height: 1.55;
}
.badge {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 15px;
padding: 7px 10px;
border: 1px solid rgba(99, 231, 255, 0.25);
border-radius: 999px;
background: rgba(99, 231, 255, 0.06);
color: #bdefff;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.badge::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 12px var(--cyan);
content: "";
}
.control-panel {
position: fixed;
z-index: 10;
top: 28px;
right: 28px;
width: 288px;
padding: 17px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(18px);
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 15px;
}
.panel-heading strong {
font-size: 11px;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.live-dot {
display: flex;
align-items: center;
gap: 6px;
color: #a6c0ca;
font-size: 9px;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.live-dot::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--mint);
box-shadow: 0 0 10px var(--mint);
content: "";
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
button {
min-height: 36px;
padding: 8px 10px;
border: 1px solid rgba(151, 203, 220, 0.18);
border-radius: 10px;
background: rgba(131, 188, 208, 0.08);
color: var(--text);
cursor: pointer;
font-size: 11px;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
button:hover {
border-color: rgba(99, 231, 255, 0.45);
background: rgba(99, 231, 255, 0.12);
}
button:active {
transform: translateY(1px);
}
.control {
margin-top: 15px;
}
.control-label {
display: flex;
justify-content: space-between;
margin-bottom: 8px;
color: #b8cbd3;
font-size: 10px;
letter-spacing: 0.05em;
}
.control-label output {
color: var(--cyan);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 3px 0;
accent-color: var(--cyan);
cursor: pointer;
}
.pressure-card {
margin-top: 17px;
padding-top: 15px;
border-top: 1px solid var(--line);
}
.pressure-row {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 12px;
}
#pressureValue {
font-size: 27px;
font-weight: 620;
font-variant-numeric: tabular-nums;
letter-spacing: -0.04em;
}
#phaseValue {
margin-bottom: 4px;
color: var(--cyan);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.meter {
position: relative;
height: 5px;
margin-top: 12px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.08);
}
.meter::after {
position: absolute;
top: 0;
bottom: 0;
left: 50%;
width: 1px;
background: rgba(255, 255, 255, 0.36);
content: "";
}
#meterFill {
position: absolute;
top: 0;
bottom: 0;
left: 50%;
width: 50%;
border-radius: 99px;
background: var(--cyan);
transform-origin: left center;
transition: background 120ms ease;
}
.meter-note {
margin-top: 8px;
color: var(--muted);
font-size: 9px;
}
.explanation {
position: fixed;
z-index: 5;
left: 30px;
bottom: 92px;
width: min(390px, calc(100vw - 60px));
pointer-events: none;
}
.explanation h2 {
margin: 0 0 11px;
font-size: 11px;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.explanation p {
margin: 0;
color: #a9bec7;
font-size: 11px;
line-height: 1.65;
}
.legend {
position: fixed;
z-index: 10;
right: 28px;
bottom: 27px;
left: 28px;
display: flex;
align-items: center;
justify-content: center;
gap: 22px;
min-height: 46px;
padding: 9px 15px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(8, 20, 29, 0.74);
backdrop-filter: blur(15px);
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
color: #b7c9d0;
font-size: 10px;
white-space: nowrap;
}
.legend-symbol {
position: relative;
width: 20px;
height: 12px;
}
.legend-symbol.wave::before {
position: absolute;
top: 1px;
left: 1px;
width: 17px;
height: 9px;
border: 1px solid var(--cyan);
border-radius: 50%;
box-shadow: 0 0 8px rgba(99, 231, 255, 0.45);
content: "";
}
.legend-symbol.particle::before {
position: absolute;
top: 2px;
left: 6px;
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--amber);
box-shadow: 0 0 8px rgba(255, 209, 102, 0.5);
content: "";
}
.legend-symbol.particle::after {
position: absolute;
top: 5px;
left: 1px;
width: 16px;
height: 1px;
background: var(--amber);
content: "";
}
.legend-symbol.bone::before {
position: absolute;
top: 1px;
left: 2px;
width: 16px;
height: 8px;
border-radius: 60% 40% 55% 45%;
background: var(--coral);
transform: rotate(-12deg);
content: "";
}
.legend-divider {
width: 1px;
height: 20px;
background: var(--line);
}
.hint {
color: #708b97;
font-size: 9px;
letter-spacing: 0.04em;
white-space: nowrap;
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
#labels.hidden {
display: none;
}
.scene-label {
position: absolute;
display: grid;
grid-template-columns: 20px auto;
grid-template-rows: auto auto;
min-width: 135px;
padding: 8px 10px;
border: 1px solid rgba(154, 206, 222, 0.2);
border-radius: 10px;
background: rgba(5, 17, 25, 0.8);
box-shadow: 0 10px 28px rgba(0, 0, 0, 0.2);
opacity: 0;
transform: translate(-50%, calc(-100% - 12px));
transition: opacity 180ms ease;
backdrop-filter: blur(10px);
}
.scene-label::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 14px;
background: rgba(154, 206, 222, 0.45);
content: "";
}
.scene-label .number {
grid-row: 1 / 3;
align-self: center;
color: var(--cyan);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
}
.scene-label b {
font-size: 10px;
font-weight: 700;
letter-spacing: 0.03em;
}
.scene-label em {
margin-top: 2px;
color: #8fa9b4;
font-size: 8px;
font-style: normal;
line-height: 1.3;
}
.scene-label.wave {
border-color: rgba(99, 231, 255, 0.27);
}
.scene-label.particle .number {
color: var(--amber);
}
.scene-label.bone .number {
color: var(--coral);
}
.scene-label.fluid .number {
color: var(--mint);
}
#loading {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
background: #061019;
color: #a9c4ce;
font-size: 11px;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
.control-panel {
top: auto;
right: 15px;
bottom: 84px;
width: 255px;
}
.title-block {
top: 20px;
left: 20px;
}
.subtitle,
.explanation {
display: none;
}
.legend {
right: 12px;
bottom: 12px;
left: 12px;
gap: 10px;
justify-content: flex-start;
overflow-x: auto;
}
.hint {
display: none;
}
}
@media (max-width: 580px) {
.title-block {
width: calc(100vw - 40px);
}
h1 {
max-width: 280px;
font-size: 30px;
}
.badge {
margin-top: 10px;
}
.control-panel {
right: 12px;
bottom: 74px;
width: 224px;
padding: 13px;
}
.pressure-card {
display: none;
}
.legend-item {
font-size: 9px;
}
.legend-divider {
display: none;
}
.scene-label {
transform: translate(-50%, calc(-100% - 7px)) scale(0.84);
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div id="labels"></div>
<header class="title-block">
<div class="eyebrow">Acoustics Lab / Interactive Cutaway</div>
<h1>Pressure becomes mechanical motion.</h1>
<p class="subtitle">
Follow an incoming sound wave as it displaces the tympanic membrane,
moves the ossicles, and transfers pressure into the cochlea.
</p>
<div class="badge">3D cutaway · motion amplified</div>
</header>
<aside class="control-panel">
<div class="panel-heading">
<strong>Simulation</strong>
<span class="live-dot">Running</span>
</div>
<div class="button-row">
<button id="playButton" type="button">Ⅱ Pause</button>
<button id="resetButton" type="button">Reset view</button>
</div>
<div class="control">
<label class="control-label" for="speedControl">
<span>Playback speed</span>
<output id="speedOutput">1.00×</output>
</label>
<input
id="speedControl"
type="range"
min="0.25"
max="2"
step="0.05"
value="1"
>
</div>
<div class="control">
<label class="control-label" for="tissueControl">
<span>Tissue opacity</span>
<output id="tissueOutput">55%</output>
</label>
<input
id="tissueControl"
type="range"
min="0"
max="1"
step="0.01"
value="0.55"
>
</div>
<div class="control">
<div class="button-row">
<button id="labelButton" type="button">Labels on</button>
<button id="motionButton" type="button">Motion ×120</button>
</div>
</div>
<div class="pressure-card">
<div class="pressure-row">
<div id="pressureValue">+0.00</div>
<div id="phaseValue">Equilibrium</div>
</div>
<div class="meter">
<div id="meterFill"></div>
</div>
<div class="meter-note">Relative pressure at the eardrum</div>
</div>
</aside>
<section class="explanation">
<h2>Two different kinds of motion</h2>
<p>
Cyan wavefronts show sound energy traveling through the canal.
Amber air particles do not stream inward with the wave: each particle
oscillates back and forth around a fixed position, parallel to the
direction of propagation.
</p>
</section>
<div class="legend">
<div class="legend-item">
<span class="legend-symbol wave"></span>
<span>Pressure wavefronts travel right</span>
</div>
<div class="legend-divider"></div>
<div class="legend-item">
<span class="legend-symbol particle"></span>
<span>Air particles oscillate in place</span>
</div>
<div class="legend-divider"></div>
<div class="legend-item">
<span class="legend-symbol bone"></span>
<span>Ossicle movement amplified</span>
</div>
<div class="legend-divider"></div>
<div class="hint">Drag to orbit · Scroll to zoom · Space to pause</div>
</div>
<div id="loading">Loading acoustic cutaway…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const stage = document.querySelector("#stage");
const loading = document.querySelector("#loading");
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x061019, 0.018);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
120
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional cutaway of sound transmission through the ear"
);
stage.appendChild(renderer.domElement);
const ambient = new THREE.HemisphereLight(0xc9f5ff, 0x2a1720, 1.65);
scene.add(ambient);
const keyLight = new THREE.DirectionalLight(0xdaf7ff, 3.1);
keyLight.position.set(-3, 7, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0xff8e78, 18, 12, 2);
rimLight.position.set(-2, 1, -3);
scene.add(rimLight);
const innerLight = new THREE.PointLight(0x4debd2, 12, 7, 2);
innerLight.position.set(3.2, 0.8, 1.8);
scene.add(innerLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0x07141d,
roughness: 0.92,
metalness: 0.05
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.52;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(30, 30, 0x173746, 0x0d202b);
grid.position.y = -1.505;
grid.material.transparent = true;
grid.material.opacity = 0.36;
scene.add(grid);
// ------------------------------------------------------------
// Small geometry helpers
// ------------------------------------------------------------
const UP = new THREE.Vector3(0, 1, 0);
function geometryFromArrays(positions, indices) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function setSegment(mesh, a, b) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(UP, direction.normalize());
mesh.scale.set(1, length, 1);
}
function addSegment(group, a, b, radiusA, radiusB, material) {
const geometry = new THREE.CylinderGeometry(
radiusB,
radiusA,
1,
14,
1,
false
);
const mesh = new THREE.Mesh(geometry, material);
setSegment(mesh, a, b);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
return mesh;
}
function makeAnchor(parent, x, y, z = 0) {
const anchor = new THREE.Object3D();
anchor.position.set(x, y, z);
parent.add(anchor);
return anchor;
}
// ------------------------------------------------------------
// Materials
// ------------------------------------------------------------
const tissueMaterial = new THREE.MeshPhysicalMaterial({
color: 0xc97569,
roughness: 0.5,
metalness: 0,
transparent: true,
opacity: 0.55,
side: THREE.DoubleSide,
depthWrite: false
});
const innerTissueMaterial = new THREE.MeshPhysicalMaterial({
color: 0xf1b09a,
roughness: 0.48,
transparent: true,
opacity: 0.28,
side: THREE.DoubleSide,
depthWrite: false
});
const cutMaterial = new THREE.MeshStandardMaterial({
color: 0xffc9ad,
roughness: 0.6,
transparent: true,
opacity: 0.72,
side: THREE.DoubleSide
});
const boneMaterial = new THREE.MeshStandardMaterial({
color: 0xe7d4b4,
roughness: 0.38,
metalness: 0.04
});
const jointMaterial = new THREE.MeshStandardMaterial({
color: 0xb58c6c,
roughness: 0.48,
metalness: 0.05
});
const membraneMaterial = new THREE.MeshPhysicalMaterial({
color: 0xf5d4ae,
roughness: 0.36,
metalness: 0,
transparent: true,
opacity: 0.78,
side: THREE.DoubleSide,
emissive: 0x4b261a,
emissiveIntensity: 0.08
});
const fluidMaterial = new THREE.MeshStandardMaterial({
color: 0x27d9c7,
emissive: 0x0d8179,
emissiveIntensity: 0.85,
roughness: 0.28,
transparent: true,
opacity: 0.56,
depthWrite: false
});
// ------------------------------------------------------------
// Partial cylindrical canal: the upper/front sector is removed
// to expose the tympanic membrane and middle-ear structures.
// ------------------------------------------------------------
function makeCanalShell() {
const x0 = -4.15;
const x1 = 0.64;
const cy = 0;
const cz = 0;
const radialSegments = 40;
const lengthSegments = 26;
// Angular convention: y = cos(theta), z = sin(theta).
// This leaves an opening facing upward and toward the camera.
const thetaStart = Math.PI * 0.28;
const thetaLength = Math.PI * 1.28;
const outerRadiusAt = x => {
const t = THREE.MathUtils.clamp((x - x0) / (x1 - x0), 0, 1);
return 0.88 + 0.12 * (1 - t);
};
const innerRadiusAt = x => outerRadiusAt(x) - 0.17;
function buildSurface(inner) {
const positions = [];
const indices = [];
for (let ix = 0; ix <= lengthSegments; ix++) {
const x = THREE.MathUtils.lerp(x0, x1, ix / lengthSegments);
const radius = inner
? innerRadiusAt(x)
: outerRadiusAt(x);
for (let it = 0; it <= radialSegments; it++) {
const theta =
thetaStart + (it / radialSegments) * thetaLength;
positions.push(
x,
cy + radius * Math.cos(theta),
cz + radius * Math.sin(theta)
);
}
}
const row = radialSegments + 1;
for (let ix = 0; ix < lengthSegments; ix++) {
for (let it = 0; it < radialSegments; it++) {
const a = ix * row + it;
const b = a + row;
const c = b + 1;
const d = a + 1;
if (inner) {
indices.push(a, c, b, a, d, c);
} else {
indices.push(a, b, c, a, c, d);
}
}
}
return geometryFromArrays(positions, indices);
}
const outerMesh = new THREE.Mesh(
buildSurface(false),
tissueMaterial
);
const innerMesh = new THREE.Mesh(
buildSurface(true),
innerTissueMaterial
);
outerMesh.castShadow = true;
outerMesh.receiveShadow = true;
scene.add(outerMesh, innerMesh);
// End caps.
for (const x of [x0, x1]) {
const positions = [];
const indices = [];
for (let it = 0; it <= radialSegments; it++) {
const theta =
thetaStart + (it / radialSegments) * thetaLength;
positions.push(
x,
cy + outerRadiusAt(x) * Math.cos(theta),
cz + outerRadiusAt(x) * Math.sin(theta)
);
positions.push(
x,
cy + innerRadiusAt(x) * Math.cos(theta),
cz + innerRadiusAt(x) * Math.sin(theta)
);
}
for (let it = 0; it < radialSegments; it++) {
const a = it * 2;
const b = a + 1;
const c = a + 2;
const d = a + 3;
indices.push(a, b, c, b, d, c);
}
const cap = new THREE.Mesh(
geometryFromArrays(positions, indices),
cutMaterial
);
scene.add(cap);
}
// Longitudinal cut faces.
for (const theta of [thetaStart, thetaStart + thetaLength]) {
const positions = [];
const indices = [];
for (let ix = 0; ix <= lengthSegments; ix++) {
const x = THREE.MathUtils.lerp(
x0,
x1,
ix / lengthSegments
);
positions.push(
x,
cy + outerRadiusAt(x) * Math.cos(theta),
cz + outerRadiusAt(x) * Math.sin(theta)
);
positions.push(
x,
cy + innerRadiusAt(x) * Math.cos(theta),
cz + innerRadiusAt(x) * Math.sin(theta)
);
}
for (let ix = 0; ix < lengthSegments; ix++) {
const a = ix * 2;
const b = a + 1;
const c = a + 2;
const d = a + 3;
indices.push(a, b, c, b, d, c);
}
const cut = new THREE.Mesh(
geometryFromArrays(positions, indices),
cutMaterial
);
scene.add(cut);
}
// Bright cut-edge outlines.
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0xffd1b7,
transparent: true,
opacity: 0.58
});
for (const theta of [thetaStart, thetaStart + thetaLength]) {
const points = [];
for (let ix = 0; ix <= lengthSegments; ix++) {
const x = THREE.MathUtils.lerp(
x0,
x1,
ix / lengthSegments
);
const r = outerRadiusAt(x);
points.push(
new THREE.Vector3(
x,
cy + r * Math.cos(theta),
cz + r * Math.sin(theta)
)
);
}
scene.add(
new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
edgeMaterial
)
);
}
}
makeCanalShell();
// ------------------------------------------------------------
// Stylized external ear / pinna
// ------------------------------------------------------------
const pinnaPoints = [
new THREE.Vector3(-4.80, 0.95, 0.00),
new THREE.Vector3(-5.38, 0.76, 0.05),
new THREE.Vector3(-5.66, 0.18, 0.06),
new THREE.Vector3(-5.53, -0.47, 0.04),
new THREE.Vector3(-5.06, -1.02, 0.00),
new THREE.Vector3(-4.57, -1.12, -0.03),
new THREE.Vector3(-4.24, -0.78, -0.04),
new THREE.Vector3(-4.40, -0.35, 0.00),
new THREE.Vector3(-4.21, 0.08, 0.03),
new THREE.Vector3(-4.34, 0.58, 0.02),
new THREE.Vector3(-4.80, 0.95, 0.00)
];
const pinnaCurve = new THREE.CatmullRomCurve3(
pinnaPoints,
true,
"catmullrom",
0.35
);
const pinna = new THREE.Mesh(
new THREE.TubeGeometry(pinnaCurve, 90, 0.17, 12, true),
new THREE.MeshPhysicalMaterial({
color: 0xd88979,
roughness: 0.54,
transparent: true,
opacity: 0.88,
side: THREE.DoubleSide
})
);
pinna.castShadow = true;
scene.add(pinna);
const antihelixCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-4.64, 0.67, 0.09),
new THREE.Vector3(-5.06, 0.40, 0.10),
new THREE.Vector3(-5.12, -0.13, 0.10),
new THREE.Vector3(-4.81, -0.60, 0.09)
]);
const antihelix = new THREE.Mesh(
new THREE.TubeGeometry(antihelixCurve, 40, 0.09, 10, false),
new THREE.MeshStandardMaterial({
color: 0xe59a85,
roughness: 0.6
})
);
scene.add(antihelix);
// ------------------------------------------------------------
// Translucent temporal-bone and middle-ear context
// ------------------------------------------------------------
const cavityMaterial = new THREE.MeshPhysicalMaterial({
color: 0xe7a392,
roughness: 0.6,
transparent: true,
opacity: 0.09,
side: THREE.DoubleSide,
depthWrite: false
});
const middleCavity = new THREE.Mesh(
new THREE.SphereGeometry(1, 32, 20),
cavityMaterial
);
middleCavity.position.set(1.55, 0.23, -0.22);
middleCavity.scale.set(1.25, 0.86, 0.62);
scene.add(middleCavity);
const temporalBone = new THREE.Mesh(
new THREE.SphereGeometry(1, 36, 24),
new THREE.MeshPhysicalMaterial({
color: 0xd99383,
roughness: 0.7,
transparent: true,
opacity: 0.13,
side: THREE.DoubleSide,
depthWrite: false
})
);
temporalBone.position.set(3.58, 0.02, -0.42);
temporalBone.scale.set(1.72, 1.38, 0.82);
scene.add(temporalBone);
// ------------------------------------------------------------
// Tympanic membrane: radial mesh with a fixed rim and moving center
// ------------------------------------------------------------
const membraneCenterX = 0.64;
const membraneRadius = 0.72;
const membraneRings = 9;
const membraneSegments = 64;
const membranePositions = [membraneCenterX, 0, 0];
const membraneBaseX = [membraneCenterX];
const membraneWeights = [1];
for (let ring = 1; ring <= membraneRings; ring++) {
const r = ring / membraneRings;
const radius = r * membraneRadius;
for (let segment = 0; segment < membraneSegments; segment++) {
const angle = (segment / membraneSegments) * Math.PI * 2;
const baseX = membraneCenterX + 0.075 * r * r;
membranePositions.push(
baseX,
radius * Math.cos(angle),
radius * Math.sin(angle)
);
membraneBaseX.push(baseX);
membraneWeights.push(1 - r * r);
}
}
const membraneIndices = [];
for (let segment = 0; segment < membraneSegments; segment++) {
membraneIndices.push(
0,
1 + segment,
1 + ((segment + 1) % membraneSegments)
);
}
for (let ring = 1; ring < membraneRings; ring++) {
const innerStart = 1 + (ring - 1) * membraneSegments;
const outerStart = 1 + ring * membraneSegments;
for (let segment = 0; segment < membraneSegments; segment++) {
const next = (segment + 1) % membraneSegments;
const a = innerStart + segment;
const b = outerStart + segment;
const c = outerStart + next;
const d = innerStart + next;
membraneIndices.push(a, b, c, a, c, d);
}
}
const membraneGeometry = geometryFromArrays(
membranePositions,
membraneIndices
);
membraneGeometry.setAttribute(
"baseX",
new THREE.Float32BufferAttribute(membraneBaseX, 1)
);
membraneGeometry.setAttribute(
"weight",
new THREE.Float32BufferAttribute(membraneWeights, 1)
);
const membrane = new THREE.Mesh(
membraneGeometry,
membraneMaterial
);
membrane.castShadow = true;
scene.add(membrane);
const membraneRim = new THREE.Mesh(
new THREE.TorusGeometry(membraneRadius, 0.035, 8, 72),
new THREE.MeshStandardMaterial({
color: 0xe7b18f,
roughness: 0.55
})
);
membraneRim.rotation.y = Math.PI / 2;
membraneRim.position.x = membraneCenterX + 0.075;
scene.add(membraneRim);
// ------------------------------------------------------------
// Ossicles: malleus, incus, stapes
// ------------------------------------------------------------
const malleus = new THREE.Group();
const incus = new THREE.Group();
const stapes = new THREE.Group();
scene.add(malleus, incus, stapes);
const malleusPivot = new THREE.Vector3(1.02, 0.42, 0);
const incusPivot = new THREE.Vector3(1.31, 0.52, 0);
const stapesPivot = new THREE.Vector3(2.15, 0.34, 0);
malleus.position.copy(malleusPivot);
incus.position.copy(incusPivot);
stapes.position.copy(stapesPivot);
function addJoint(group, position, scale, material = jointMaterial) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(1, 18, 12),
material
);
mesh.position.copy(position);
mesh.scale.copy(scale);
mesh.castShadow = true;
group.add(mesh);
return mesh;
}
// Malleus head and handle.
addJoint(
malleus,
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(0.23, 0.20, 0.17),
boneMaterial
);
addSegment(
malleus,
new THREE.Vector3(0, -0.05, 0),
new THREE.Vector3(-0.33, -0.50, 0),
0.10,
0.055,
boneMaterial
);
addSegment(
malleus,
new THREE.Vector3(0.02, 0.01, 0),
new THREE.Vector3(0.24, 0.04, 0),
0.11,
0.075,
boneMaterial
);
// Incus body and long process.
addJoint(
incus,
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(0.21, 0.18, 0.16),
boneMaterial
);
addSegment(
incus,
new THREE.Vector3(0.08, -0.02, 0),
new THREE.Vector3(0.68, -0.20, 0),
0.095,
0.05,
boneMaterial
);
addJoint(
incus,
new THREE.Vector3(0.68, -0.20, 0),
new THREE.Vector3(0.075, 0.065, 0.065),
jointMaterial
);
// Stapes superstructure and oval footplate.
addJoint(
stapes,
new THREE.Vector3(-0.06, 0, 0),
new THREE.Vector3(0.10, 0.10, 0.09),
boneMaterial
);
addSegment(
stapes,
new THREE.Vector3(-0.04, 0.07, 0),
new THREE.Vector3(0.29, 0.18, 0),
0.043,
0.03,
boneMaterial
);
addSegment(
stapes,
new THREE.Vector3(-0.04, -0.07, 0),
new THREE.Vector3(0.29, -0.18, 0),
0.043,
0.03,
boneMaterial
);
addSegment(
stapes,
new THREE.Vector3(0.29, 0.18, 0),
new THREE.Vector3(0.32, 0, 0),
0.028,
0.028,
boneMaterial
);
addSegment(
stapes,
new THREE.Vector3(0.29, -0.18, 0),
new THREE.Vector3(0.32, 0, 0),
0.028,
0.028,
boneMaterial
);
const footplate = addJoint(
stapes,
new THREE.Vector3(0.32, 0, 0),
new THREE.Vector3(0.042, 0.25, 0.145),
boneMaterial
);
footplate.material = boneMaterial.clone();
footplate.material.emissive = new THREE.Color(0x633f28);
footplate.material.emissiveIntensity = 0.15;
const malleusProcess = makeAnchor(
malleus,
0.24,
0.04
);
const malleusContact = makeAnchor(
malleus,
-0.33,
-0.50
);
const incusBody = makeAnchor(incus, 0, 0);
const incusEnd = makeAnchor(incus, 0.68, -0.20);
const stapesBody = makeAnchor(stapes, -0.06, 0);
const malleusIncusLink = new THREE.Mesh(
new THREE.CylinderGeometry(1, 1, 1, 12),
jointMaterial
);
const incusStapesLink = new THREE.Mesh(
new THREE.CylinderGeometry(1, 1, 1, 12),
jointMaterial
);
const drumLink = new THREE.Mesh(
new THREE.CylinderGeometry(1, 1, 1, 10),
jointMaterial
);
scene.add(malleusIncusLink, incusStapesLink, drumLink);
function updateDynamicLink(mesh, a, b, radius) {
setSegment(mesh, a, b);
mesh.scale.x = radius;
mesh.scale.z = radius;
}
// Oval window / cochlear entrance.
const ovalWindow = new THREE.Mesh(
new THREE.TorusGeometry(0.23, 0.05, 10, 48),
new THREE.MeshStandardMaterial({
color: 0xe4bd9a,
roughness: 0.5,
emissive: 0x3f2316,
emissiveIntensity: 0.15
})
);
ovalWindow.rotation.y = Math.PI / 2;
ovalWindow.position.set(2.48, 0.34, 0);
ovalWindow.scale.set(0.66, 1.28, 1);
scene.add(ovalWindow);
// ------------------------------------------------------------
// Cochlea: transparent outer spiral and animated inner fluid path
// ------------------------------------------------------------
const cochleaPoints = [];
for (let i = 0; i <= 110; i++) {
const t = i / 110;
const radius = 1.05 * (1 - 0.78 * t);
const angle = Math.PI + 0.35 + t * Math.PI * 2.4;
cochleaPoints.push(
new THREE.Vector3(
3.62 + radius * Math.cos(angle),
radius * Math.sin(angle),
0.08 + 0.07 * Math.sin(t * Math.PI)
)
);
}
const cochleaCurve = new THREE.CatmullRomCurve3(cochleaPoints);
const cochleaShell = new THREE.Mesh(
new THREE.TubeGeometry(cochleaCurve, 180, 0.245, 14, false),
new THREE.MeshPhysicalMaterial({
color: 0xe7aa93,
roughness: 0.48,
transparent: true,
opacity: 0.29,
side: THREE.DoubleSide,
depthWrite: false
})
);
scene.add(cochleaShell);
const cochlearFluid = new THREE.Mesh(
new THREE.TubeGeometry(cochleaCurve, 180, 0.095, 10, false),
fluidMaterial
);
scene.add(cochlearFluid);
const spiralLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(
cochleaCurve.getPoints(220)
),
new THREE.LineBasicMaterial({
color: 0x58f2d9,
transparent: true,
opacity: 0.7
})
);
scene.add(spiralLine);
const fluidPackets = [];
const packetGeometry = new THREE.SphereGeometry(0.057, 12, 8);
for (let i = 0; i < 11; i++) {
const packet = new THREE.Mesh(
packetGeometry,
new THREE.MeshBasicMaterial({
color: 0x9cfff0,
transparent: true,
opacity: 0.92,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
scene.add(packet);
fluidPackets.push(packet);
}
// ------------------------------------------------------------
// Traveling pressure wavefronts
// ------------------------------------------------------------
const wavefronts = [];
const waveRingGeometry = new THREE.TorusGeometry(
0.64,
0.012,
6,
72
);
waveRingGeometry.rotateY(Math.PI / 2);
for (let i = 0; i < 7; i++) {
const ring = new THREE.Mesh(
waveRingGeometry,
new THREE.MeshBasicMaterial({
color: 0x63e7ff,
transparent: true,
opacity: 0.3,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
scene.add(ring);
wavefronts.push(ring);
}
const directionArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(-7.6, 1.47, 0.08),
2.35,
0x63e7ff,
0.26,
0.13
);
directionArrow.line.material.transparent = true;
directionArrow.line.material.opacity = 0.72;
directionArrow.cone.material.transparent = true;
directionArrow.cone.material.opacity = 0.88;
scene.add(directionArrow);
const guideLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-7.8, 1.47, 0.08),
new THREE.Vector3(0.25, 1.47, 0.08)
]),
new THREE.LineDashedMaterial({
color: 0x63e7ff,
transparent: true,
opacity: 0.24,
dashSize: 0.16,
gapSize: 0.12
})
);
guideLine.computeLineDistances();
scene.add(guideLine);
// ------------------------------------------------------------
// Air particles: fixed equilibrium positions with longitudinal
// oscillation. They do not travel across the canal with the wave.
// ------------------------------------------------------------
let randomSeed = 31829;
function seededRandom() {
randomSeed =
(randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
const particleCount = 54;
const particleBase = [];
const particlePositions = new Float32Array(particleCount * 3);
const trailPositions = new Float32Array(particleCount * 6);
for (let i = 0; i < particleCount; i++) {
const x = -7.05 + seededRandom() * 7.48;
const angle = seededRandom() * Math.PI * 2;
const radius = Math.sqrt(seededRandom()) * 0.49;
const y = Math.cos(angle) * radius;
const z = Math.sin(angle) * radius;
particleBase.push({ x, y, z });
particlePositions[i * 3] = x;
particlePositions[i * 3 + 1] = y;
particlePositions[i * 3 + 2] = z;
}
const particleGeometry = new THREE.BufferGeometry();
particleGeometry.setAttribute(
"position",
new THREE.BufferAttribute(particlePositions, 3)
);
const particles = new THREE.Points(
particleGeometry,
new THREE.PointsMaterial({
color: 0xffd166,
size: 0.055,
sizeAttenuation: true,
transparent: true,
opacity: 0.95,
depthWrite: false
})
);
scene.add(particles);
const particleTrails = new THREE.LineSegments(
new THREE.BufferGeometry().setAttribute(
"position",
new THREE.BufferAttribute(trailPositions, 3)
),
new THREE.LineBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.18,
depthWrite: false
})
);
scene.add(particleTrails);
// ------------------------------------------------------------
// Projected HTML labels, implemented without renderer add-ons
// ------------------------------------------------------------
const labelsRoot = document.querySelector("#labels");
const labelDefinitions = [
{
number: "01",
title: "Air column",
text: "Particles oscillate locally",
anchor: new THREE.Vector3(-3.45, 0.93, 0.05),
className: "particle"
},
{
number: "02",
title: "Tympanic membrane",
text: "Pressure difference → vibration",
anchor: new THREE.Vector3(0.66, -0.98, 0.05),
className: "wave"
},
{
number: "03",
title: "Ossicles",
text: "Malleus · incus · stapes",
anchor: new THREE.Vector3(1.55, 1.02, 0.02),
className: "bone"
},
{
number: "04",
title: "Cochlear fluid",
text: "Pressure travels through fluid",
anchor: new THREE.Vector3(3.62, 1.27, 0.10),
className: "fluid"
},
{
number: "→",
title: "Energy direction",
text: "Wave propagates toward the ear",
anchor: new THREE.Vector3(-5.85, 1.48, 0.08),
className: "wave"
}
];
const projectedLabels = labelDefinitions.map(definition => {
const element = document.createElement("div");
element.className = `scene-label ${definition.className}`;
element.innerHTML = `
<span class="number">${definition.number}</span>
<b>${definition.title}</b>
<em>${definition.text}</em>
`;
labelsRoot.appendChild(element);
return { ...definition, element };
});
function updateLabels() {
const width = innerWidth;
const height = innerHeight;
for (const label of projectedLabels) {
const projected = label.anchor.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
if (!visible) {
label.element.style.opacity = "0";
continue;
}
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
label.element.style.opacity = "0.92";
}
}
// ------------------------------------------------------------
// Custom orbit controls
// ------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(-1.1, 0.02, 0),
azimuth: 1.62,
polar: 1.22,
radius: 12.8
};
function resetCamera() {
cameraState.azimuth = 1.62;
cameraState.polar = 1.22;
cameraState.radius = 12.8;
cameraState.target.set(-1.1, 0.02, 0);
}
function updateCamera() {
const responsiveScale = Math.max(
1,
1.45 / camera.aspect
);
const radius = cameraState.radius * responsiveScale;
const sinPolar = Math.sin(cameraState.polar);
camera.position.set(
cameraState.target.x +
radius * sinPolar * Math.cos(cameraState.azimuth),
cameraState.target.y +
radius * Math.cos(cameraState.polar),
cameraState.target.z +
radius * sinPolar * Math.sin(cameraState.azimuth)
);
camera.lookAt(cameraState.target);
}
let dragging = false;
let dragX = 0;
let dragY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
dragX = event.clientX;
dragY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - dragX;
const dy = event.clientY - dragY;
dragX = event.clientX;
dragY = event.clientY;
cameraState.azimuth -= dx * 0.006;
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar + dy * 0.005,
0.38,
1.48
);
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined) {
try {
renderer.domElement.releasePointerCapture(event.pointerId);
} catch (_) {}
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", event => {
event.preventDefault();
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
6.5,
22
);
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
// ------------------------------------------------------------
// UI controls
// ------------------------------------------------------------
const playButton = document.querySelector("#playButton");
const resetButton = document.querySelector("#resetButton");
const labelButton = document.querySelector("#labelButton");
const motionButton = document.querySelector("#motionButton");
const speedControl = document.querySelector("#speedControl");
const speedOutput = document.querySelector("#speedOutput");
const tissueControl = document.querySelector("#tissueControl");
const tissueOutput = document.querySelector("#tissueOutput");
const pressureValue = document.querySelector("#pressureValue");
const phaseValue = document.querySelector("#phaseValue");
const meterFill = document.querySelector("#meterFill");
let playing = true;
let playbackSpeed = 1;
let motionAmplification = 1;
let labelsVisible = true;
playButton.addEventListener("click", () => {
playing = !playing;
playButton.textContent = playing ? "Ⅱ Pause" : "▶ Play";
document.querySelector(".live-dot").style.opacity = playing
? "1"
: "0.45";
});
resetButton.addEventListener("click", resetCamera);
speedControl.addEventListener("input", () => {
playbackSpeed = Number(speedControl.value);
speedOutput.textContent = `${playbackSpeed.toFixed(2)}×`;
});
tissueControl.addEventListener("input", () => {
const opacity = Number(tissueControl.value);
tissueMaterial.opacity = 0.12 + opacity * 0.55;
innerTissueMaterial.opacity = 0.06 + opacity * 0.34;
cutMaterial.opacity = 0.24 + opacity * 0.60;
cavityMaterial.opacity = 0.025 + opacity * 0.10;
temporalBone.material.opacity = 0.035 + opacity * 0.16;
tissueOutput.textContent = `${Math.round(opacity * 100)}%`;
});
labelButton.addEventListener("click", () => {
labelsVisible = !labelsVisible;
labelsRoot.classList.toggle("hidden", !labelsVisible);
labelButton.textContent = labelsVisible ? "Labels on" : "Labels off";
});
motionButton.addEventListener("click", () => {
motionAmplification = motionAmplification === 1 ? 0.25 : 1;
motionButton.textContent =
motionAmplification === 1 ? "Motion ×120" : "Motion ×30";
});
window.addEventListener("keydown", event => {
if (event.code === "Space") {
event.preventDefault();
playButton.click();
}
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
// ------------------------------------------------------------
// Simulation
// ------------------------------------------------------------
const waveNumber = (Math.PI * 2) / 1.65;
const angularFrequency = 3.1;
const waveStart = -7.55;
const waveSpan = 8.05;
const waveSpeed = angularFrequency / waveNumber;
function pressureAt(x, time) {
return Math.sin(waveNumber * x - angularFrequency * time);
}
const temporaryA = new THREE.Vector3();
const temporaryB = new THREE.Vector3();
function updateSimulation(time) {
const membranePressure = pressureAt(membraneCenterX, time);
// Membrane deformation: the rim stays fixed, the center moves.
const positions = membraneGeometry.attributes.position.array;
const baseX = membraneGeometry.attributes.baseX.array;
const weights = membraneGeometry.attributes.weight.array;
for (let i = 0; i < weights.length; i++) {
positions[i * 3] =
baseX[i] +
membranePressure *
0.105 *
weights[i] *
motionAmplification;
}
membraneGeometry.attributes.position.needsUpdate = true;
membraneGeometry.computeVertexNormals();
membraneMaterial.emissiveIntensity =
0.05 + Math.abs(membranePressure) * 0.12;
// The linked ossicle chain amplifies the small membrane motion.
malleus.rotation.z =
membranePressure * 0.082 * motionAmplification;
incus.rotation.z =
membranePressure * 0.074 * motionAmplification;
stapes.position.x =
stapesPivot.x +
membranePressure * 0.046 * motionAmplification;
stapes.rotation.z =
membranePressure * 0.060 * motionAmplification;
scene.updateMatrixWorld(true);
// Dynamic articulations preserve visible mechanical linkage.
malleusProcess.getWorldPosition(temporaryA);
incusBody.getWorldPosition(temporaryB);
updateDynamicLink(
malleusIncusLink,
temporaryA,
temporaryB,
0.085
);
incusEnd.getWorldPosition(temporaryA);
stapesBody.getWorldPosition(temporaryB);
updateDynamicLink(
incusStapesLink,
temporaryA,
temporaryB,
0.06
);
// Connect the malleus handle to the moving membrane surface.
malleusContact.getWorldPosition(temporaryA);
const drumY = temporaryA.y;
const radialFraction = THREE.MathUtils.clamp(
Math.abs(drumY) / membraneRadius,
0,
1
);
const drumWeight = 1 - radialFraction * radialFraction;
const drumX =
membraneCenterX +
0.075 * radialFraction * radialFraction +
membranePressure * 0.105 * drumWeight * motionAmplification;
temporaryB.set(drumX, drumY, temporaryA.z);
updateDynamicLink(
drumLink,
temporaryA,
temporaryB,
0.025
);
// Advancing compression wavefronts.
const travel = ((angularFrequency * time) / waveNumber) % waveSpan;
wavefronts.forEach((ring, index) => {
const x =
waveStart +
((travel + index * waveSpan / wavefronts.length) % waveSpan);
ring.position.x = x;
ring.scale.setScalar(
1 + 0.035 * Math.sin(index * 1.7 + time * 1.2)
);
const proximity = THREE.MathUtils.clamp(
(x - waveStart) / waveSpan,
0,
1
);
const fade = Math.sin(proximity * Math.PI);
ring.material.opacity =
0.12 + fade * 0.28 + Math.abs(membranePressure) * 0.035;
});
// Air particles oscillate parallel to propagation around fixed
// equilibrium positions. Their base X never advances with time.
for (let i = 0; i < particleCount; i++) {
const base = particleBase[i];
const localPressure = pressureAt(base.x, time);
const displacedX =
base.x +
localPressure *
0.09 *
motionAmplification;
particlePositions[i * 3] = displacedX;
particlePositions[i * 3 + 1] = base.y;
particlePositions[i * 3 + 2] = base.z;
const trail = i * 6;
trailPositions[trail] = base.x;
trailPositions[trail + 1] = base.y;
trailPositions[trail + 2] = base.z;
trailPositions[trail + 3] = displacedX;
trailPositions[trail + 4] = base.y;
trailPositions[trail + 5] = base.z;
}
particleGeometry.attributes.position.needsUpdate = true;
particleTrails.geometry.attributes.position.needsUpdate = true;
// Cochlear fluid packets move away from the stapes and curl
// toward the apex of the spiral.
fluidPackets.forEach((packet, index) => {
const u = (index / fluidPackets.length + time * 0.075) % 1;
const point = cochleaCurve.getPointAt(u);
packet.position.copy(point);
const pulse =
0.5 +
0.5 *
Math.sin(
u * Math.PI * 12 -
angularFrequency * time * 1.4 +
index
);
packet.scale.setScalar(0.62 + pulse * 0.72);
packet.material.opacity = 0.48 + pulse * 0.48;
});
ovalWindow.material.emissiveIntensity =
0.12 + Math.abs(membranePressure) * 0.32;
// Numeric readout.
const signedPressure = membranePressure;
pressureValue.textContent =
`${signedPressure >= 0 ? "+" : ""}${signedPressure.toFixed(2)}`;
if (signedPressure > 0.22) {
phaseValue.textContent = "Compression";
} else if (signedPressure < -0.22) {
phaseValue.textContent = "Rarefaction";
} else {
phaseValue.textContent = "Equilibrium";
}
const magnitude = Math.abs(signedPressure);
meterFill.style.width = `${magnitude * 50}%`;
meterFill.style.left =
signedPressure >= 0 ? "50%" : `${50 - magnitude * 50}%`;
meterFill.style.background =
signedPressure >= 0 ? "#63e7ff" : "#ffd166";
}
function onResize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
window.addEventListener("resize", onResize);
// ------------------------------------------------------------
// Animation loop
// ------------------------------------------------------------
let simulationTime = 0;
let previousTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const delta = THREE.MathUtils.clamp((now - previousTime) / 1000, 0, 0.05);
previousTime = now;
if (playing) {
simulationTime += delta * playbackSpeed;
}
updateCamera();
updateSimulation(simulationTime);
updateLabels();
renderer.render(scene, camera);
}
updateCamera();
updateSimulation(0);
requestAnimationFrame(animate);
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 450);
});
</script>
</body>
</html>
```