Prompt specification
Build or customize the Three.js 3D scene "Cochlea educational cutaway station" 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: Cochlea educational cutaway station
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/cochlea-educational-cutaway-station-x0991
Scene Description Prompt:
Use Three.js from cdnjs to compose an ear outline beside an uncoiled schematic cochlea showing a frequency-dependent response region; label the uncoiling and response scale as illustrative. Deliver one self-contained HTML file with visible voxel blocks.
Working Three.js Starter (cochlea-educational-cutaway-station-x0991):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Cochlea, Unfolded — Interactive Voxel Schematic</title>
<style>
:root {
--ink: #183541;
--muted: #5f747b;
--paper: #eef4f3;
--glass: rgba(255, 255, 255, 0.82);
--line: rgba(24, 53, 65, 0.15);
--coral: #ef704c;
--teal: #1b9d94;
--blue: #2256a6;
--violet: #a65fa5;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.vignette {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
background:
radial-gradient(circle at 50% 42%, transparent 42%, rgba(31, 67, 78, 0.05) 100%),
linear-gradient(180deg, rgba(255,255,255,0.16), transparent 28%);
}
.hero {
position: fixed;
z-index: 7;
top: clamp(20px, 4vw, 42px);
left: clamp(20px, 4vw, 48px);
width: min(560px, calc(100vw - 40px));
pointer-events: none;
}
.kicker {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 11px;
color: var(--teal);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.kicker::before {
content: "";
width: 28px;
height: 2px;
background: currentColor;
}
h1 {
margin: 0;
max-width: 520px;
font-size: clamp(30px, 4.2vw, 58px);
font-weight: 650;
line-height: 0.98;
letter-spacing: -0.045em;
}
.hero p {
max-width: 490px;
margin: 16px 0 0;
color: var(--muted);
font-size: clamp(12px, 1.25vw, 15px);
line-height: 1.55;
}
.status {
position: fixed;
z-index: 8;
top: clamp(20px, 4vw, 42px);
right: clamp(20px, 4vw, 48px);
display: flex;
align-items: center;
gap: 10px;
}
.badge {
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(255, 255, 255, 0.68);
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
button {
appearance: none;
border: 1px solid rgba(24, 53, 65, 0.18);
border-radius: 999px;
padding: 10px 14px;
background: var(--ink);
color: white;
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
box-shadow: 0 8px 24px rgba(24, 53, 65, 0.13);
transition: transform 160ms ease, background 160ms ease;
}
button:hover {
background: #244a59;
transform: translateY(-1px);
}
button:focus-visible {
outline: 3px solid rgba(27, 157, 148, 0.35);
outline-offset: 3px;
}
.annotations {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.annotation {
position: absolute;
min-width: 120px;
padding: 7px 10px 8px;
border: 1px solid rgba(24, 53, 65, 0.13);
border-radius: 7px;
background: var(--glass);
box-shadow: 0 8px 24px rgba(30, 65, 75, 0.08);
backdrop-filter: blur(8px);
text-align: center;
transform: translate(-50%, -115%);
white-space: nowrap;
}
.annotation::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 20px;
background: rgba(24, 53, 65, 0.36);
}
.annotation strong {
display: block;
font-size: 9px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.annotation small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
line-height: 1.25;
}
.axis-label {
position: absolute;
padding: 5px 8px;
border-radius: 5px;
background: rgba(255,255,255,0.74);
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
transform: translate(-50%, 0);
white-space: nowrap;
}
.legend {
position: fixed;
z-index: 7;
left: clamp(16px, 3vw, 38px);
bottom: clamp(16px, 3vw, 34px);
width: min(610px, calc(100vw - 32px));
padding: 15px 17px 14px;
border: 1px solid rgba(24, 53, 65, 0.12);
border-radius: 13px;
background: rgba(255, 255, 255, 0.78);
box-shadow: 0 14px 45px rgba(24, 53, 65, 0.08);
backdrop-filter: blur(16px);
pointer-events: none;
}
.legend-kicker {
margin-bottom: 10px;
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
}
.scale-label {
margin-bottom: 7px;
color: var(--ink);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.ramp {
height: 8px;
border-radius: 99px;
}
.frequency-ramp {
background: linear-gradient(90deg, var(--blue), var(--teal) 47%, var(--violet));
}
.response-ramp {
background: linear-gradient(90deg, #476f83, var(--teal) 48%, var(--coral));
}
.ramp-ends {
display: flex;
justify-content: space-between;
margin-top: 5px;
color: var(--muted);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.legend p {
margin: 7px 0 0;
color: var(--muted);
font-size: 9px;
line-height: 1.35;
}
.hint {
position: fixed;
z-index: 7;
right: clamp(18px, 3vw, 38px);
bottom: clamp(18px, 3vw, 34px);
color: rgba(24, 53, 65, 0.58);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.04em;
pointer-events: none;
}
#fallback {
display: none;
position: fixed;
z-index: 20;
inset: 0;
place-items: center;
padding: 30px;
background: var(--paper);
text-align: center;
}
@media (max-width: 760px) {
.hero {
top: 18px;
left: 18px;
}
.hero p {
max-width: 360px;
margin-top: 10px;
font-size: 11px;
}
.status {
top: 18px;
right: 18px;
}
.badge {
display: none;
}
button {
padding: 9px 12px;
}
.legend {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
padding: 12px 13px;
}
.legend-grid {
grid-template-columns: 1fr;
gap: 11px;
}
.legend p {
display: none;
}
.hint {
display: none;
}
#ann-response,
#ann-ear {
display: none;
}
}
@media (max-height: 620px) {
.hero p {
display: none;
}
.legend {
padding: 10px 13px;
}
.legend-grid {
grid-template-columns: 1fr 1fr;
}
}
</style>
</head>
<body>
<main id="stage" aria-label="Interactive 3D schematic of an external ear and an uncoiled cochlea"></main>
<div class="vignette" aria-hidden="true"></div>
<header class="hero">
<div class="kicker">Auditory anatomy / voxel study</div>
<h1>Cochlea,<br>unfolded.</h1>
<p>
An external ear beside an illustrative cochlear duct. Voxel height and
the coral envelope encode a frequency-dependent response.
</p>
</header>
<div class="status">
<div class="badge">Schematic · not to scale</div>
<button id="reset" type="button" aria-label="Reset the 3D camera view">↺ Reset view</button>
</div>
<div class="annotations" aria-hidden="true">
<div id="ann-ear" class="annotation">
<strong>External ear</strong>
<small>outline and auditory pathway</small>
</div>
<div id="ann-uncoil" class="annotation">
<strong>Illustrative uncoiling</strong>
<small>coil and duct are simplified</small>
</div>
<div id="ann-cochlea" class="annotation">
<strong>Uncoiled cochlea</strong>
<small>sensory duct flattened for clarity</small>
</div>
<div id="ann-response" class="annotation">
<strong>Frequency-dependent response</strong>
<small>voxel height + coral envelope</small>
</div>
<div id="ann-base" class="axis-label">Base / high frequency</div>
<div id="ann-apex" class="axis-label">Apex / low frequency</div>
</div>
<section class="legend" aria-label="Illustrative chart scales">
<div class="legend-kicker">Illustrative scales · no calibrated units</div>
<div class="legend-grid">
<div>
<div class="scale-label">Illustrative frequency axis</div>
<div class="ramp frequency-ramp"></div>
<div class="ramp-ends">
<span>Base / high</span>
<span>Apex / low</span>
</div>
<p>Position and color indicate the schematic frequency map.</p>
</div>
<div>
<div class="scale-label">Illustrative response scale</div>
<div class="ramp response-ramp"></div>
<div class="ramp-ends">
<span>Low response</span>
<span>High response</span>
</div>
<p>Relative response only; units and thresholds are omitted.</p>
</div>
</div>
</section>
<div class="hint">Drag to orbit · Scroll or pinch to zoom · Double-click to reset</div>
<div id="fallback">
<div>
<h2>3D rendering is unavailable</h2>
<p>This illustration requires a browser with WebGL enabled.</p>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const fallback = document.getElementById("fallback");
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
} catch (error) {
fallback.style.display = "grid";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D cochlea schematic. Drag to rotate and scroll to zoom."
);
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeef4f3);
scene.fog = new THREE.Fog(0xeef4f3, 20, 34);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 80);
const target = new THREE.Vector3(0.15, 0.45, 0);
const controls = {
theta: 0.10,
phi: 1.08,
radius: 12.8
};
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
target.x + controls.radius * sinPhi * Math.sin(controls.theta),
target.y + controls.radius * Math.cos(controls.phi),
target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(target);
}
function resetView() {
controls.theta = 0.10;
controls.phi = 1.08;
controls.radius = window.innerWidth < 760 ? 22 : 12.8;
updateCamera();
}
// Lighting
scene.add(new THREE.HemisphereLight(0xffffff, 0x729398, 1.75));
const key = new THREE.DirectionalLight(0xfff9ed, 3.1);
key.position.set(-4, 9, 7);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -12;
key.shadow.camera.right = 12;
key.shadow.camera.top = 10;
key.shadow.camera.bottom = -10;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 30;
key.shadow.bias = -0.00015;
scene.add(key);
const fill = new THREE.DirectionalLight(0x9dd9e4, 1.35);
fill.position.set(7, 3, -5);
scene.add(fill);
const rim = new THREE.DirectionalLight(0xffb08d, 0.7);
rim.position.set(-7, 2, -4);
scene.add(rim);
// Ground and grid
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0xe8f0ef,
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.52;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(24, 48, 0xbfcfce, 0xd7e3e1);
grid.position.y = -1.505;
grid.material.transparent = true;
grid.material.opacity = 0.33;
scene.add(grid);
// Helpers
function tubeFromPoints(points, radius, material, closed = false, segments = 72) {
const curve = new THREE.CatmullRomCurve3(
points,
closed,
"catmullrom",
0.38
);
const geometry = new THREE.TubeGeometry(
curve,
segments,
radius,
9,
closed
);
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function frequencyColor(t) {
const blue = new THREE.Color(0x2256a6);
const teal = new THREE.Color(0x18a7a0);
const violet = new THREE.Color(0xa65fa5);
if (t < 0.47) {
return blue.clone().lerp(teal, t / 0.47);
}
return teal.clone().lerp(violet, (t - 0.47) / 0.53);
}
function responseColor(r) {
const low = new THREE.Color(0x476f83);
const mid = new THREE.Color(0x1b9d94);
const high = new THREE.Color(0xef704c);
if (r < 0.5) {
return low.clone().lerp(mid, r / 0.5);
}
return mid.clone().lerp(high, (r - 0.5) / 0.5);
}
// ---------------------------------------------------------
// External ear
// ---------------------------------------------------------
const ear = new THREE.Group();
ear.position.set(-4.55, 0, 0);
scene.add(ear);
const earDisc = new THREE.Mesh(
new THREE.CircleGeometry(1.82, 64),
new THREE.MeshStandardMaterial({
color: 0xdce9e7,
roughness: 0.95,
transparent: true,
opacity: 0.82,
side: THREE.DoubleSide
})
);
earDisc.position.set(0, 0.38, -0.62);
earDisc.receiveShadow = true;
ear.add(earDisc);
const earRing = new THREE.Mesh(
new THREE.TorusGeometry(1.84, 0.018, 8, 100),
new THREE.MeshBasicMaterial({
color: 0x9ab4b5,
transparent: true,
opacity: 0.55
})
);
earRing.position.set(0, 0.38, -0.60);
ear.add(earRing);
const earOutlineMaterial = new THREE.MeshStandardMaterial({
color: 0x284b59,
roughness: 0.45,
metalness: 0.04
});
const earInnerMaterial = new THREE.MeshStandardMaterial({
color: 0x78959b,
roughness: 0.62,
metalness: 0.02
});
const outerEarPoints = [
new THREE.Vector3(0.15, 1.92, 0.05),
new THREE.Vector3(-0.25, 2.03, 0.03),
new THREE.Vector3(-0.82, 1.67, 0),
new THREE.Vector3(-1.08, 0.96, -0.02),
new THREE.Vector3(-1.02, 0.26, -0.02),
new THREE.Vector3(-0.72, -0.48, 0),
new THREE.Vector3(-0.28, -1.08, 0.03),
new THREE.Vector3(0.15, -1.25, 0.07),
new THREE.Vector3(0.50, -1.02, 0.05),
new THREE.Vector3(0.56, -0.58, 0.02),
new THREE.Vector3(0.38, -0.15, 0),
new THREE.Vector3(0.26, 0.35, 0.03),
new THREE.Vector3(0.48, 0.67, 0.02),
new THREE.Vector3(0.76, 0.91, 0),
new THREE.Vector3(0.78, 1.38, 0.02),
new THREE.Vector3(0.55, 1.82, 0.04)
];
ear.add(
tubeFromPoints(
outerEarPoints,
0.115,
earOutlineMaterial,
true,
120
)
);
const antiHelix = [
new THREE.Vector3(-0.05, 1.48, 0.08),
new THREE.Vector3(-0.45, 1.25, 0.07),
new THREE.Vector3(-0.59, 0.72, 0.05),
new THREE.Vector3(-0.48, 0.25, 0.06),
new THREE.Vector3(-0.15, 0.02, 0.08),
new THREE.Vector3(0.10, 0.25, 0.10)
];
ear.add(tubeFromPoints(antiHelix, 0.085, earInnerMaterial));
const helixHighlight = [
new THREE.Vector3(0.10, 1.76, 0.10),
new THREE.Vector3(-0.34, 1.63, 0.08),
new THREE.Vector3(-0.64, 1.14, 0.06),
new THREE.Vector3(-0.70, 0.58, 0.04)
];
ear.add(
tubeFromPoints(
helixHighlight,
0.035,
new THREE.MeshStandardMaterial({
color: 0xa8c0c0,
roughness: 0.55
})
)
);
const concha = new THREE.Mesh(
new THREE.SphereGeometry(1, 32, 24),
new THREE.MeshStandardMaterial({
color: 0xb9d1d0,
roughness: 0.8
})
);
concha.position.set(0.08, 0.18, 0.04);
concha.scale.set(0.34, 0.52, 0.16);
concha.castShadow = true;
ear.add(concha);
const earOpening = new THREE.Mesh(
new THREE.SphereGeometry(1, 28, 20),
new THREE.MeshStandardMaterial({
color: 0x345762,
roughness: 0.62
})
);
earOpening.position.set(0.22, 0.23, 0.16);
earOpening.scale.set(0.16, 0.26, 0.10);
ear.add(earOpening);
const lobule = new THREE.Mesh(
new THREE.SphereGeometry(1, 28, 20),
new THREE.MeshStandardMaterial({
color: 0x365966,
roughness: 0.55
})
);
lobule.position.set(0.16, -1.10, 0.07);
lobule.scale.set(0.28, 0.35, 0.21);
lobule.castShadow = true;
ear.add(lobule);
const canal = [
new THREE.Vector3(0.35, 0.18, 0.16),
new THREE.Vector3(0.78, 0.15, 0.08),
new THREE.Vector3(1.25, 0.12, -0.12)
];
ear.add(
tubeFromPoints(
canal,
0.145,
new THREE.MeshStandardMaterial({
color: 0x247f82,
roughness: 0.55
})
)
);
// Auditory nerve leading toward the schematic coil
const nerve = [
new THREE.Vector3(-3.25, 0.12, -0.03),
new THREE.Vector3(-2.91, 0.18, 0.03),
new THREE.Vector3(-2.62, 0.45, 0.12),
new THREE.Vector3(-2.28, 0.62, 0.18),
new THREE.Vector3(-2.02, 0.73, 0.20)
];
scene.add(
tubeFromPoints(
nerve,
0.038,
new THREE.MeshStandardMaterial({
color: 0x238f88,
roughness: 0.52
})
)
);
// Small residual spiral indicates the original cochlear form
const spiralPoints = [];
for (let i = 0; i <= 88; i++) {
const u = i / 88;
const angle = -0.5 + u * 4.6 * Math.PI;
const radius = 0.14 + 0.58 * (1 - u);
spiralPoints.push(
new THREE.Vector3(
-2.05 + Math.cos(angle) * radius,
0.78 + Math.sin(angle) * radius * 0.82,
0.20
)
);
}
scene.add(
tubeFromPoints(
spiralPoints,
0.052,
new THREE.MeshStandardMaterial({
color: 0x648b92,
roughness: 0.46,
metalness: 0.04
}),
false,
120
)
);
const transition = [
new THREE.Vector3(-1.93, 0.79, 0.20),
new THREE.Vector3(-1.60, 0.82, 0.20),
new THREE.Vector3(-1.25, 0.84, 0.22)
];
scene.add(
tubeFromPoints(
transition,
0.045,
new THREE.MeshStandardMaterial({
color: 0x2a938c,
roughness: 0.45
})
)
);
const uncoilArrow = new THREE.Mesh(
new THREE.ConeGeometry(0.095, 0.25, 18),
new THREE.MeshStandardMaterial({
color: 0x2a938c,
roughness: 0.4
})
);
uncoilArrow.position.set(-1.20, 0.84, 0.24);
uncoilArrow.rotation.z = -Math.PI / 2;
uncoilArrow.castShadow = true;
scene.add(uncoilArrow);
// ---------------------------------------------------------
// Uncoiled cochlear duct
// ---------------------------------------------------------
const ductX0 = -1.15;
const ductX1 = 5.15;
function ductCenter(t) {
return 0.78 + 0.09 * Math.sin(t * Math.PI * 3.2);
}
function ductHalfWidth(t) {
return lerp(0.62, 0.29, t) * (1 + 0.035 * Math.sin(t * 18));
}
function ductX(t) {
return lerp(ductX0, ductX1, t);
}
function createRibbonGeometry({
widthStart,
widthEnd,
depth,
zOffset,
colorFunction,
segments = 96
}) {
const positions = [];
const colors = [];
const indices = [];
for (let i = 0; i <= segments; i++) {
const t = i / segments;
const x = ductX(t);
const y = ductCenter(t);
const width = lerp(widthStart, widthEnd, t);
const zFront = zOffset + depth / 2;
const zBack = zOffset - depth / 2;
const color = colorFunction(t);
positions.push(
x, y + width, zFront,
x, y - width, zFront,
x, y + width, zBack,
x, y - width, zBack
);
for (let k = 0; k < 4; k++) {
colors.push(color.r, color.g, color.b);
}
}
for (let i = 0; i < segments; i++) {
const a = i * 4;
const b = (i + 1) * 4;
// Front and back
indices.push(a, a + 1, b + 1, a, b + 1, b);
indices.push(a + 2, b + 2, b + 3, a + 2, b + 3, a + 3);
// Upper and lower edges
indices.push(a, b, b + 2, a, b + 2, a + 2);
indices.push(a + 1, a + 3, b + 3, a + 1, b + 3, b + 1);
}
// End caps
const last = segments * 4;
indices.push(0, 2, 3, 0, 3, 1);
indices.push(last, last + 1, last + 3, last, last + 3, last + 2);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
return geometry;
}
const duct = new THREE.Mesh(
createRibbonGeometry({
widthStart: 0.62,
widthEnd: 0.29,
depth: 0.28,
zOffset: -0.03,
colorFunction: frequencyColor
}),
new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
roughness: 0.42,
metalness: 0.04,
transparent: true,
opacity: 0.86,
side: THREE.DoubleSide
})
);
duct.castShadow = true;
duct.receiveShadow = true;
scene.add(duct);
const sensoryStrip = new THREE.Mesh(
createRibbonGeometry({
widthStart: 0.115,
widthEnd: 0.055,
depth: 0.07,
zOffset: 0.145,
colorFunction: (t) =>
new THREE.Color(0xffa06d).lerp(
new THREE.Color(0xffd08a),
0.35 + 0.35 * Math.sin(t * Math.PI)
)
}),
new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
roughness: 0.35,
emissive: 0x4a1607,
emissiveIntensity: 0.10
})
);
sensoryStrip.castShadow = true;
scene.add(sensoryStrip);
// ---------------------------------------------------------
// Frequency-dependent voxel response
// ---------------------------------------------------------
function responseAt(t) {
const early = 0.18 * Math.exp(-Math.pow((t - 0.20) / 0.12, 2));
const central = 0.72 * Math.exp(-Math.pow((t - 0.55) / 0.17, 2));
const late = 0.35 * Math.exp(-Math.pow((t - 0.82) / 0.10, 2));
return clamp(0.16 + early + central + late, 0, 1);
}
const voxelCountX = 44;
const voxelRows = 2;
const voxelCount = voxelCountX * voxelRows;
const voxelGeometry = new THREE.BoxGeometry(1, 1, 1);
const voxelMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.30,
metalness: 0.05
});
const voxels = new THREE.InstancedMesh(
voxelGeometry,
voxelMaterial,
voxelCount
);
voxels.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
voxels.castShadow = true;
voxels.receiveShadow = true;
voxels.frustumCulled = false;
const dummy = new THREE.Object3D();
let instanceIndex = 0;
for (let ix = 0; ix < voxelCountX; ix++) {
const t = ix / (voxelCountX - 1);
const x = lerp(-1.01, 5.00, t);
const response = responseAt(t);
const height = 0.12 + 0.84 * response;
const top = ductCenter(t) + ductHalfWidth(t);
for (let row = 0; row < voxelRows; row++) {
dummy.position.set(
x,
top + height / 2 + 0.035,
row === 0 ? -0.035 : 0.205
);
dummy.scale.set(0.112, height, 0.16);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
voxels.setMatrixAt(instanceIndex, dummy.matrix);
voxels.setColorAt(
instanceIndex,
responseColor(response)
);
instanceIndex++;
}
}
voxels.instanceMatrix.needsUpdate = true;
if (voxels.instanceColor) {
voxels.instanceColor.needsUpdate = true;
}
scene.add(voxels);
// Coral response envelope
const envelopePoints = [];
for (let i = 0; i <= 56; i++) {
const t = i / 56;
const x = ductX(t);
const response = responseAt(t);
const height = 0.12 + 0.84 * response;
const y =
ductCenter(t) +
ductHalfWidth(t) +
height +
0.16;
envelopePoints.push(new THREE.Vector3(x, y, 0.39));
}
const envelopeCurve = new THREE.CatmullRomCurve3(
envelopePoints,
false,
"catmullrom",
0.25
);
const envelope = new THREE.Mesh(
new THREE.TubeGeometry(envelopeCurve, 140, 0.019, 7, false),
new THREE.MeshStandardMaterial({
color: 0xef704c,
roughness: 0.38,
emissive: 0x4c160a,
emissiveIntensity: 0.09
})
);
scene.add(envelope);
for (const t of [0.20, 0.55, 0.82]) {
const response = responseAt(t);
const height = 0.12 + 0.84 * response;
const marker = new THREE.Mesh(
new THREE.SphereGeometry(0.047, 16, 12),
new THREE.MeshStandardMaterial({
color: 0xef704c,
roughness: 0.3,
emissive: 0x59180c,
emissiveIntensity: 0.12
})
);
marker.position.set(
ductX(t),
ductCenter(t) + ductHalfWidth(t) + height + 0.16,
0.39
);
scene.add(marker);
}
// Frequency baseline and ticks
const axisPoints = [];
for (let i = 0; i <= 80; i++) {
const t = i / 80;
axisPoints.push(
new THREE.Vector3(
ductX(t),
-0.19 + 0.035 * Math.sin(t * Math.PI * 2),
0.25
)
);
}
const axis = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(axisPoints),
new THREE.LineBasicMaterial({
color: 0x6e8a90,
transparent: true,
opacity: 0.65
})
);
scene.add(axis);
const tickPositions = [];
for (let i = 0; i <= 10; i++) {
const t = i / 10;
const x = ductX(t);
const y = -0.19 + 0.035 * Math.sin(t * Math.PI * 2);
tickPositions.push(
x, y, 0.25,
x, y - (i % 5 === 0 ? 0.14 : 0.075), 0.25
);
}
const ticks = new THREE.LineSegments(
new THREE.BufferGeometry().setAttribute(
"position",
new THREE.Float32BufferAttribute(tickPositions, 3)
),
new THREE.LineBasicMaterial({
color: 0x78959a,
transparent: true,
opacity: 0.55
})
);
scene.add(ticks);
// ---------------------------------------------------------
// Camera controls implemented directly
// ---------------------------------------------------------
const activePointers = new Map();
let previousPinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.focus({ preventScroll: true });
renderer.domElement.setPointerCapture(event.pointerId);
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 2) {
const points = [...activePointers.values()];
previousPinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!activePointers.has(event.pointerId)) return;
const previous = activePointers.get(event.pointerId);
const next = {
x: event.clientX,
y: event.clientY
};
activePointers.set(event.pointerId, next);
if (activePointers.size === 1) {
const dx = next.x - previous.x;
const dy = next.y - previous.y;
controls.theta -= dx * 0.006;
controls.phi = clamp(controls.phi + dy * 0.005, 0.62, 1.42);
} else if (activePointers.size === 2) {
const points = [...activePointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (previousPinchDistance > 0 && distance > 0) {
controls.radius = clamp(
controls.radius * (previousPinchDistance / distance),
7.5,
29
);
}
previousPinchDistance = distance;
}
updateCamera();
});
function endPointer(event) {
activePointers.delete(event.pointerId);
previousPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("lostpointercapture", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
7.5,
29
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
renderer.domElement.addEventListener("keydown", (event) => {
const key = event.key;
if (key === "ArrowLeft") {
controls.theta += 0.08;
} else if (key === "ArrowRight") {
controls.theta -= 0.08;
} else if (key === "ArrowUp") {
controls.phi = clamp(controls.phi - 0.06, 0.62, 1.42);
} else if (key === "ArrowDown") {
controls.phi = clamp(controls.phi + 0.06, 0.62, 1.42);
} else if (key === "+" || key === "=") {
controls.radius = clamp(controls.radius * 0.90, 7.5, 29);
} else if (key === "-" || key === "_") {
controls.radius = clamp(controls.radius * 1.10, 7.5, 29);
} else if (key === "Home") {
resetView();
event.preventDefault();
return;
} else {
return;
}
event.preventDefault();
updateCamera();
});
document.getElementById("reset").addEventListener("click", resetView);
// ---------------------------------------------------------
// Screen-space annotations
// ---------------------------------------------------------
const annotationAnchors = {
"ann-ear": new THREE.Vector3(-4.52, 2.22, 0.12),
"ann-uncoil": new THREE.Vector3(-1.83, 1.20, 0.24),
"ann-cochlea": new THREE.Vector3(3.10, 1.52, 0.18),
"ann-response": new THREE.Vector3(1.83, 2.03, 0.45),
"ann-base": new THREE.Vector3(-1.17, -0.31, 0.25),
"ann-apex": new THREE.Vector3(5.18, -0.31, 0.25)
};
const annotationElements = Object.entries(annotationAnchors).map(
([id, position]) => ({
element: document.getElementById(id),
position: position.clone()
})
);
const projected = new THREE.Vector3();
function updateAnnotations() {
const width = stage.clientWidth;
const height = stage.clientHeight;
for (const item of annotationElements) {
projected.copy(item.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.25 &&
projected.x < 1.25 &&
projected.y > -1.25 &&
projected.y < 1.25;
item.element.style.display = visible ? "" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
item.element.style.left = `${x}px`;
item.element.style.top = `${y}px`;
}
}
// ---------------------------------------------------------
// Resize and render
// ---------------------------------------------------------
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
resetView();
renderer.setAnimationLoop(() => {
updateAnnotations();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```