Prompt specification
Build or customize the Three.js 3D scene "Semicircular canal orientation model" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Semicircular canal orientation model
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/semicircular-canal-orientation-model-x1029
Scene Description Prompt:
Make a cutaway Three.js scene in a self-contained HTML file using cdnjs: semicircular canal orientation model. Build three loop-shaped canal models in approximate spatial orientations beside an otolith-organ inset; label the geometry schematic and distinguish rotational from linear acceleration sensing.
Working Three.js Starter (semicircular-canal-orientation-model-x1029):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Inner Ear — Vestibular Sensing Schematic</title>
<style>
:root {
color-scheme: dark;
--bg: #07121c;
--panel: rgba(10, 25, 37, 0.82);
--line: rgba(177, 218, 238, 0.18);
--text: #e8f5fb;
--muted: #91aebe;
--superior: #ffb45c;
--posterior: #ed73f7;
--horizontal: #36d8c4;
--linear: #61d9ff;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
body::after {
content: "";
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
background:
radial-gradient(circle at 50% 45%, transparent 42%, rgba(0, 7, 13, 0.42) 100%),
linear-gradient(180deg, rgba(3, 11, 18, 0.2), transparent 35%, rgba(3, 11, 18, 0.36));
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
z-index: 6;
border: 1px solid var(--line);
background: var(--panel);
box-shadow: 0 16px 45px rgba(0, 0, 0, 0.2);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.main-hud {
top: 24px;
left: 24px;
width: min(410px, calc(100vw - 48px));
padding: 20px 22px 18px;
border-radius: 16px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 11px;
color: #81d9ef;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 22px;
height: 1px;
background: #61d9ff;
box-shadow: 0 0 10px #61d9ff;
}
h1 {
margin: 0;
font-size: clamp(25px, 3.1vw, 39px);
font-weight: 650;
line-height: 1.03;
letter-spacing: -0.035em;
}
.subtitle {
margin: 12px 0 0;
max-width: 340px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.badges {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 16px;
}
.badge {
padding: 6px 8px;
border: 1px solid rgba(125, 211, 252, 0.19);
border-radius: 999px;
color: #b9d9e7;
background: rgba(97, 217, 255, 0.045);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.axis-key {
display: flex;
flex-wrap: wrap;
gap: 7px 14px;
margin-top: 16px;
padding-top: 14px;
border-top: 1px solid rgba(177, 218, 238, 0.1);
color: #7895a7;
font-size: 9px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.axis-key span {
display: inline-flex;
align-items: center;
gap: 5px;
}
.axis-key i {
display: inline-block;
width: 13px;
height: 2px;
border-radius: 2px;
}
.axis-key .x { background: #ff7777; }
.axis-key .y { background: #65e798; }
.axis-key .z { background: #69a8ff; }
.inset-hud {
top: 24px;
right: 24px;
width: 260px;
padding: 16px 18px;
border-radius: 14px;
pointer-events: none;
}
.inset-hud .index {
color: var(--linear);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.inset-hud h2 {
margin: 7px 0 5px;
font-size: 21px;
font-weight: 620;
letter-spacing: -0.02em;
}
.inset-hud p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.mode-panel {
left: 24px;
bottom: 24px;
width: min(410px, calc(100vw - 48px));
padding: 15px 17px;
border-radius: 14px;
}
.mode-row {
display: grid;
grid-template-columns: 18px 1fr;
gap: 10px;
align-items: start;
}
.mode-row + .mode-row {
margin-top: 12px;
padding-top: 12px;
border-top: 1px solid rgba(177, 218, 238, 0.1);
}
.mode-icon {
width: 16px;
height: 16px;
margin-top: 2px;
border: 2px solid var(--linear);
border-radius: 50%;
box-shadow: 0 0 12px rgba(97, 217, 255, 0.24);
}
.mode-icon.rotation {
border-color: var(--horizontal);
box-shadow: 0 0 12px rgba(54, 216, 196, 0.24);
}
.mode-row b {
display: block;
margin-bottom: 3px;
font-size: 11px;
letter-spacing: 0.035em;
}
.mode-row small {
display: block;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.controls {
position: fixed;
right: 24px;
bottom: 24px;
z-index: 7;
display: flex;
align-items: center;
gap: 8px;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 999px;
padding: 10px 14px;
color: #d9edf5;
background: rgba(10, 25, 37, 0.88);
font: 650 10px/1 ui-sans-serif, system-ui, sans-serif;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(12px);
transition:
border-color 160ms ease,
background 160ms ease,
color 160ms ease;
}
button:hover,
button.active {
border-color: rgba(97, 217, 255, 0.55);
color: white;
background: rgba(23, 54, 72, 0.94);
}
.hint {
color: #718e9f;
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#annotation-layer {
position: fixed;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
#leaders {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
overflow: visible;
}
.annotation {
position: absolute;
width: max-content;
max-width: 220px;
display: flex;
align-items: flex-start;
gap: 9px;
padding: 8px 10px 8px 9px;
border-left: 2px solid var(--accent);
border-radius: 0 8px 8px 0;
background: rgba(6, 18, 27, 0.84);
box-shadow: 0 7px 22px rgba(0, 0, 0, 0.18);
backdrop-filter: blur(9px);
-webkit-backdrop-filter: blur(9px);
transition: opacity 120ms linear;
}
.annotation::before {
content: "";
flex: 0 0 auto;
width: 6px;
height: 6px;
margin-top: 4px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 9px var(--accent);
}
.annotation b {
display: block;
color: #edf8fc;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.095em;
line-height: 1.25;
text-transform: uppercase;
}
.annotation small {
display: block;
margin-top: 4px;
color: #8ca9b9;
font-size: 9px;
line-height: 1.35;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: #a9d5e5;
background: var(--bg);
font-size: 11px;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.main-hud {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.main-hud h1 {
font-size: 25px;
}
.subtitle,
.axis-key {
display: none;
}
.badges {
margin-top: 11px;
}
.inset-hud {
top: auto;
right: 12px;
bottom: 118px;
width: 205px;
padding: 11px 13px;
}
.inset-hud h2 {
font-size: 17px;
}
.mode-panel {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
padding: 12px 14px;
}
.controls {
right: 12px;
bottom: 74px;
}
.hint {
display: none;
}
.annotation {
max-width: 165px;
padding: 6px 8px;
}
.annotation small {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div id="annotation-layer">
<svg id="leaders" aria-hidden="true"></svg>
</div>
<header class="hud main-hud">
<div class="eyebrow">Inner ear · vestibular system</div>
<h1>Semicircular canal<br>orientation schematic</h1>
<p class="subtitle">
An enlarged temporal-bone cutaway showing the three loop-shaped canals.
Canal planes are approximate and color-coded by rotational sensitivity.
</p>
<div class="badges">
<span class="badge">Cutaway view</span>
<span class="badge">Geometry schematic</span>
<span class="badge">Not to scale</span>
</div>
<div class="axis-key" aria-label="Reference axes">
<span><i class="x"></i>X · left / right</span>
<span><i class="y"></i>Y · up / down</span>
<span><i class="z"></i>Z · front / back</span>
</div>
</header>
<aside class="hud inset-hud">
<div class="index">Inset 02</div>
<h2>Otolith organ</h2>
<p>Maculae and otoconia detect linear acceleration, gravity and static head tilt.</p>
</aside>
<aside class="hud mode-panel">
<div class="mode-row">
<span class="mode-icon rotation"></span>
<div>
<b>Semicircular canals · rotational sensing</b>
<small>Angular acceleration deflects endolymph and bends the cupula in each ampulla.</small>
</div>
</div>
<div class="mode-row">
<span class="mode-icon"></span>
<div>
<b>Otolith organs · linear sensing</b>
<small>Otoconia load the utricular and saccular maculae relative to gravity.</small>
</div>
</div>
</aside>
<div class="controls">
<span class="hint">Drag to orbit · wheel to zoom · double-click to reset</span>
<button id="auto-orbit" type="button">Auto orbit</button>
<button id="reset-view" type="button">Reset view</button>
</div>
<div id="loading">Building vestibular schematic…</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.querySelector("#stage");
const annotationLayer = document.querySelector("#annotation-layer");
const leaders = document.querySelector("#leaders");
const loading = document.querySelector("#loading");
const COLORS = {
superior: 0xffb45c,
posterior: 0xed73f7,
horizontal: 0x36d8c4,
linear: 0x61d9ff,
bone: 0xc7b393,
ivory: 0xe9e0ca,
nerve: 0x7edb9a
};
const CSS_COLORS = {
superior: "#ffb45c",
posterior: "#ed73f7",
horizontal: "#36d8c4",
linear: "#61d9ff",
bone: "#c7b393",
nerve: "#7edb9a"
};
// ---------------------------------------------------------------------
// Renderer, scene and camera
// ---------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.22;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional cutaway of the semicircular canals and otolith organs"
);
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07121c);
scene.fog = new THREE.FogExp2(0x07121c, 0.035);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
80
);
const ambient = new THREE.HemisphereLight(0xbdeaff, 0x14202b, 1.45);
scene.add(ambient);
const keyLight = new THREE.DirectionalLight(0xffffff, 2.5);
keyLight.position.set(4, 7, 6);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x5dd9ff, 2.1);
rimLight.position.set(-5, 2, -4);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffb46d, 18, 11, 2);
warmLight.position.set(-2, 1.5, 3);
scene.add(warmLight);
const blueLight = new THREE.PointLight(0x4abfff, 17, 9, 2);
blueLight.position.set(3.2, 0.5, 2.5);
scene.add(blueLight);
// ---------------------------------------------------------------------
// Direct camera controls — no examples or addons
// ---------------------------------------------------------------------
const orbit = {
target: new THREE.Vector3(0.35, 0.08, 0),
theta: 0.32,
phi: 1.17,
radius: 8.6,
baseRadius: 8.6,
dragging: false,
auto: false,
lastX: 0,
lastY: 0
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
function resetView() {
orbit.theta = 0.32;
orbit.phi = 1.17;
orbit.radius = orbit.baseRadius;
orbit.auto = false;
autoButton.classList.remove("active");
autoButton.textContent = "Auto orbit";
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
orbit.dragging = true;
orbit.lastX = event.clientX;
orbit.lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!orbit.dragging) return;
const dx = event.clientX - orbit.lastX;
const dy = event.clientY - orbit.lastY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi - dy * 0.006, 0.48, 2.32);
orbit.lastX = event.clientX;
orbit.lastY = event.clientY;
});
function endDrag(event) {
orbit.dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
5.5,
17
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
const resetButton = document.querySelector("#reset-view");
const autoButton = document.querySelector("#auto-orbit");
resetButton.addEventListener("click", resetView);
autoButton.addEventListener("click", () => {
orbit.auto = !orbit.auto;
autoButton.classList.toggle("active", orbit.auto);
autoButton.textContent = orbit.auto ? "Pause orbit" : "Auto orbit";
});
// ---------------------------------------------------------------------
// Geometry helpers
// ---------------------------------------------------------------------
function canalMaterial(color) {
return new THREE.MeshPhysicalMaterial({
color,
roughness: 0.23,
metalness: 0.03,
clearcoat: 0.95,
clearcoatRoughness: 0.16,
emissive: color,
emissiveIntensity: 0.19
});
}
function addTube(parent, points, radius, material, closed = false, segments = 120) {
const curve = new THREE.CatmullRomCurve3(
points.map((point) => point.clone()),
closed,
"centripetal",
0.45
);
const geometry = new THREE.TubeGeometry(
curve,
segments,
radius,
12,
closed
);
const mesh = new THREE.Mesh(geometry, material);
parent.add(mesh);
return { mesh, curve };
}
function addCanalGlow(parent, points, color, closed = false) {
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.085,
depthWrite: false,
blending: THREE.AdditiveBlending
});
return addTube(
parent,
points,
0.095,
material,
closed,
120
).mesh;
}
function addAmpulla(parent, position, tangent, color) {
const group = new THREE.Group();
group.position.copy(position);
const ampulla = new THREE.Mesh(
new THREE.SphereGeometry(0.115, 32, 22),
canalMaterial(color)
);
ampulla.scale.set(1.42, 0.92, 0.92);
ampulla.quaternion.setFromUnitVectors(
new THREE.Vector3(1, 0, 0),
tangent.clone().normalize()
);
group.add(ampulla);
const collar = new THREE.Mesh(
new THREE.TorusGeometry(0.108, 0.013, 8, 32),
new THREE.MeshStandardMaterial({
color: 0xf4fbff,
roughness: 0.28,
emissive: color,
emissiveIntensity: 0.15
})
);
collar.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
tangent.clone().normalize()
);
collar.position.copy(tangent.clone().normalize().multiplyScalar(0.07));
group.add(collar);
const cupula = new THREE.Mesh(
new THREE.SphereGeometry(0.061, 24, 18),
new THREE.MeshPhysicalMaterial({
color: 0xc9f7ff,
roughness: 0.12,
transmission: 0.35,
transparent: true,
opacity: 0.46,
clearcoat: 1
})
);
cupula.scale.set(0.7, 1.3, 0.7);
cupula.position.copy(tangent.clone().normalize().multiplyScalar(0.025));
group.add(cupula);
parent.add(group);
return group;
}
function addAxisArrow(parent, center, axis, halfLength, color) {
const direction = axis.clone().normalize();
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
center.clone().addScaledVector(direction, -halfLength),
center.clone().addScaledVector(direction, halfLength)
]),
new THREE.LineDashedMaterial({
color,
dashSize: 0.065,
gapSize: 0.045,
transparent: true,
opacity: 0.62
})
);
line.computeLineDistances();
parent.add(line);
const coneGeometry = new THREE.ConeGeometry(0.047, 0.135, 14);
const forward = new THREE.Mesh(
coneGeometry,
new THREE.MeshBasicMaterial({ color })
);
forward.position.copy(center).addScaledVector(direction, halfLength);
forward.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction
);
parent.add(forward);
const backward = new THREE.Mesh(
coneGeometry,
new THREE.MeshBasicMaterial({ color })
);
backward.position.copy(center).addScaledVector(direction, -halfLength);
backward.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().negate()
);
parent.add(backward);
}
function addRotationArc(parent, center, axis, radius, color) {
const normalizedAxis = axis.clone().normalize();
let reference = Math.abs(normalizedAxis.y) > 0.88
? new THREE.Vector3(1, 0, 0)
: new THREE.Vector3(0, 1, 0);
const u = new THREE.Vector3()
.crossVectors(normalizedAxis, reference)
.normalize();
const v = new THREE.Vector3()
.crossVectors(normalizedAxis, u)
.normalize();
const points = [];
const count = 42;
const sweep = Math.PI * 1.55;
for (let i = 0; i <= count; i++) {
const angle = (i / count) * sweep;
points.push(
center.clone().add(
u.clone().multiplyScalar(Math.cos(angle) * radius)
.add(v.clone().multiplyScalar(Math.sin(angle) * radius))
)
);
}
const curve = new THREE.CatmullRomCurve3(points, false, "centripetal");
const arc = new THREE.Mesh(
new THREE.TubeGeometry(curve, 64, 0.013, 7, false),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.86
})
);
parent.add(arc);
const endAngle = sweep;
const tangent = u.clone().multiplyScalar(-Math.sin(endAngle))
.add(v.clone().multiplyScalar(Math.cos(endAngle)))
.normalize();
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.047, 0.13, 14),
new THREE.MeshBasicMaterial({ color })
);
arrow.position.copy(points[points.length - 1]);
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
tangent
);
parent.add(arrow);
}
// ---------------------------------------------------------------------
// Main cutaway model
// ---------------------------------------------------------------------
const mainModel = new THREE.Group();
mainModel.position.set(-1.28, 0.02, 0);
mainModel.rotation.y = -0.08;
scene.add(mainModel);
const shellMaterial = new THREE.MeshPhysicalMaterial({
color: COLORS.bone,
roughness: 0.78,
metalness: 0,
transparent: true,
opacity: 0.12,
transmission: 0.12,
side: THREE.DoubleSide,
depthWrite: false
});
const shellGeometry = new THREE.SphereGeometry(
1.44,
64,
40,
-0.3,
Math.PI * 1.53,
0.24,
Math.PI * 0.82
);
const shell = new THREE.Mesh(shellGeometry, shellMaterial);
shell.position.set(-0.03, -0.05, 0);
shell.renderOrder = -2;
mainModel.add(shell);
const shellEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(shellGeometry, 28),
new THREE.LineBasicMaterial({
color: COLORS.bone,
transparent: true,
opacity: 0.12
})
);
shellEdges.position.copy(shell.position);
mainModel.add(shellEdges);
const cutFace = new THREE.Mesh(
new THREE.CircleGeometry(1, 96),
new THREE.MeshBasicMaterial({
color: 0xb8a78d,
transparent: true,
opacity: 0.045,
side: THREE.DoubleSide,
depthWrite: false
})
);
cutFace.scale.set(1.33, 1.2, 1);
cutFace.position.set(-0.03, -0.05, -0.42);
cutFace.renderOrder = -3;
mainModel.add(cutFace);
const cutEdgePoints = [];
for (let i = 0; i < 100; i++) {
const angle = (i / 100) * Math.PI * 2;
cutEdgePoints.push(
new THREE.Vector3(
Math.cos(angle) * 1.33 - 0.03,
Math.sin(angle) * 1.2 - 0.05,
-0.42
)
);
}
const cutEdge = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(cutEdgePoints),
new THREE.LineBasicMaterial({
color: 0xc7b393,
transparent: true,
opacity: 0.32
})
);
mainModel.add(cutEdge);
const vestibule = new THREE.Mesh(
new THREE.SphereGeometry(0.225, 40, 28),
new THREE.MeshPhysicalMaterial({
color: COLORS.ivory,
roughness: 0.35,
clearcoat: 0.7,
emissive: 0x5b4b38,
emissiveIntensity: 0.08
})
);
mainModel.add(vestibule);
// Superior/anterior canal: approximately sagittal plane.
const superiorPoints = [
new THREE.Vector3(0.00, 0.06, 0.00),
new THREE.Vector3(0.00, 0.46, 0.33),
new THREE.Vector3(0.00, 0.97, 0.52),
new THREE.Vector3(0.00, 1.30, 0.13),
new THREE.Vector3(0.00, 1.02, -0.40),
new THREE.Vector3(0.00, 0.49, -0.53),
new THREE.Vector3(0.00, 0.12, -0.29)
];
addCanalGlow(mainModel, superiorPoints, COLORS.superior, true);
addTube(
mainModel,
superiorPoints,
0.054,
canalMaterial(COLORS.superior),
true,
150
);
addAmpulla(
mainModel,
new THREE.Vector3(0, 0.12, -0.29),
new THREE.Vector3(0, 0.5, -0.5),
COLORS.superior
);
// Posterior canal: approximately coronal plane.
const posteriorPoints = [
new THREE.Vector3(0.00, 0.02, 0.08),
new THREE.Vector3(0.29, -0.24, 0.10),
new THREE.Vector3(0.51, -0.70, 0.10),
new THREE.Vector3(0.47, -1.16, 0.10),
new THREE.Vector3(0.04, -1.35, 0.10),
new THREE.Vector3(-0.38, -1.10, 0.10),
new THREE.Vector3(-0.49, -0.57, 0.10),
new THREE.Vector3(-0.27, -0.12, 0.10)
];
addCanalGlow(mainModel, posteriorPoints, COLORS.posterior, true);
addTube(
mainModel,
posteriorPoints,
0.054,
canalMaterial(COLORS.posterior),
true,
150
);
addAmpulla(
mainModel,
new THREE.Vector3(-0.27, -0.12, 0.10),
new THREE.Vector3(-0.6, -0.6, 0),
COLORS.posterior
);
// Horizontal/lateral canal: approximately transverse plane.
const horizontalPoints = [
new THREE.Vector3(0.00, 0.00, 0.00),
new THREE.Vector3(0.48, 0.00, 0.18),
new THREE.Vector3(0.94, 0.00, 0.36),
new THREE.Vector3(1.17, 0.00, 0.08),
new THREE.Vector3(0.97, 0.00, -0.31),
new THREE.Vector3(0.46, 0.00, -0.38)
];
addCanalGlow(mainModel, horizontalPoints, COLORS.horizontal, true);
addTube(
mainModel,
horizontalPoints,
0.054,
canalMaterial(COLORS.horizontal),
true,
140
);
addAmpulla(
mainModel,
new THREE.Vector3(0.46, 0, -0.38),
new THREE.Vector3(0.7, 0, -0.7),
COLORS.horizontal
);
// Rotational axes and curved motion indicators.
addAxisArrow(
mainModel,
new THREE.Vector3(0, 0.67, 0),
new THREE.Vector3(1, 0, 0),
0.88,
COLORS.superior
);
addRotationArc(
mainModel,
new THREE.Vector3(0, 0.67, 0),
new THREE.Vector3(1, 0, 0),
0.24,
COLORS.superior
);
addAxisArrow(
mainModel,
new THREE.Vector3(0, -0.58, 0.10),
new THREE.Vector3(0, 0, 1),
0.91,
COLORS.posterior
);
addRotationArc(
mainModel,
new THREE.Vector3(0, -0.58, 0.10),
new THREE.Vector3(0, 0, 1),
0.24,
COLORS.posterior
);
addAxisArrow(
mainModel,
new THREE.Vector3(0.55, 0, 0),
new THREE.Vector3(0, 1, 0),
0.88,
COLORS.horizontal
);
addRotationArc(
mainModel,
new THREE.Vector3(0.55, 0, 0),
new THREE.Vector3(0, 1, 0),
0.23,
COLORS.horizontal
);
// Simplified cochlea for anatomical context.
const cochleaPoints = [];
for (let i = 0; i <= 100; i++) {
const t = i / 100;
const angle = t * Math.PI * 3.65;
const radius = 0.43 * (1 - t * 0.73);
cochleaPoints.push(
new THREE.Vector3(
0.46 + t * 0.05,
-0.61 + radius * Math.cos(angle),
-0.18 + radius * Math.sin(angle)
)
);
}
addTube(
mainModel,
cochleaPoints,
0.038,
new THREE.MeshPhysicalMaterial({
color: 0xdc7189,
roughness: 0.3,
clearcoat: 0.8,
emissive: 0x7d233c,
emissiveIntensity: 0.16
}),
false,
150
);
// Vestibular nerve fibers.
const nerveMaterial = new THREE.MeshStandardMaterial({
color: COLORS.nerve,
roughness: 0.52,
emissive: COLORS.nerve,
emissiveIntensity: 0.12
});
const nervePaths = [
[
new THREE.Vector3(-0.04, -0.10, 0),
new THREE.Vector3(-0.13, -0.75, -0.06),
new THREE.Vector3(0.06, -1.47, -0.26)
],
[
new THREE.Vector3(0.06, -0.12, 0.02),
new THREE.Vector3(0.21, -0.79, -0.10),
new THREE.Vector3(0.39, -1.50, -0.28)
],
[
new THREE.Vector3(0.11, -0.12, 0.02),
new THREE.Vector3(0.34, -0.84, -0.06),
new THREE.Vector3(0.56, -1.49, -0.25)
]
];
nervePaths.forEach((path) => {
addTube(mainModel, path, 0.014, nerveMaterial, false, 60);
});
// ---------------------------------------------------------------------
// Otolith-organ inset
// ---------------------------------------------------------------------
const inset = new THREE.Group();
inset.position.set(2.42, 0.02, 0.12);
inset.rotation.y = -0.14;
scene.add(inset);
const insetBackdrop = new THREE.Mesh(
new THREE.CircleGeometry(1.08, 96),
new THREE.MeshBasicMaterial({
color: 0x0a2232,
transparent: true,
opacity: 0.66,
side: THREE.DoubleSide,
depthWrite: false
})
);
insetBackdrop.position.z = -0.14;
insetBackdrop.renderOrder = -1;
inset.add(insetBackdrop);
const insetRing = new THREE.Mesh(
new THREE.TorusGeometry(1.09, 0.018, 10, 120),
new THREE.MeshStandardMaterial({
color: COLORS.linear,
roughness: 0.3,
metalness: 0.12,
emissive: COLORS.linear,
emissiveIntensity: 0.22
})
);
inset.add(insetRing);
const innerRing = new THREE.Mesh(
new THREE.TorusGeometry(0.96, 0.006, 8, 120),
new THREE.MeshBasicMaterial({
color: COLORS.linear,
transparent: true,
opacity: 0.28
})
);
innerRing.position.z = -0.03;
inset.add(innerRing);
const blueOrganMaterial = new THREE.MeshPhysicalMaterial({
color: 0x2d8fd5,
roughness: 0.18,
metalness: 0.02,
transmission: 0.18,
transparent: true,
opacity: 0.67,
clearcoat: 1,
clearcoatRoughness: 0.12,
emissive: 0x0e4d7a,
emissiveIntensity: 0.22,
depthWrite: false
});
// Utricle: horizontal macula.
const utricle = new THREE.Mesh(
new THREE.SphereGeometry(0.5, 48, 32),
blueOrganMaterial
);
utricle.position.set(-0.15, 0.13, 0);
utricle.scale.set(1.08, 0.34, 0.74);
inset.add(utricle);
const utricularMacula = new THREE.Mesh(
new THREE.SphereGeometry(0.5, 44, 20),
new THREE.MeshPhysicalMaterial({
color: 0x8de9ff,
roughness: 0.3,
emissive: 0x2aabc9,
emissiveIntensity: 0.38
})
);
utricularMacula.position.set(-0.15, 0.29, 0);
utricularMacula.scale.set(0.84, 0.055, 0.39);
inset.add(utricularMacula);
// Saccule: vertical macula.
const saccule = new THREE.Mesh(
new THREE.SphereGeometry(0.42, 48, 32),
blueOrganMaterial
);
saccule.position.set(0.28, -0.26, 0.02);
saccule.scale.set(0.72, 1.12, 0.68);
inset.add(saccule);
const saccularMacula = new THREE.Mesh(
new THREE.SphereGeometry(0.5, 40, 20),
new THREE.MeshPhysicalMaterial({
color: 0x8de9ff,
roughness: 0.3,
emissive: 0x2aabc9,
emissiveIntensity: 0.38
})
);
saccularMacula.position.set(0.28, -0.23, 0.275);
saccularMacula.scale.set(0.22, 0.59, 0.055);
inset.add(saccularMacula);
// Small sensory hairs above the utricular macula.
const hairMaterial = new THREE.LineBasicMaterial({
color: 0xd5f8ff,
transparent: true,
opacity: 0.7
});
for (let i = 0; i < 13; i++) {
const x = -0.51 + (i / 12) * 0.72;
const z = Math.sin(i * 1.7) * 0.12;
const hair = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(x, 0.32, z),
new THREE.Vector3(x + 0.015, 0.40 + (i % 3) * 0.012, z)
]),
hairMaterial
);
inset.add(hair);
}
// Otoconia: calcium carbonate crystals embedded in the maculae.
let randomSeed = 8721;
function seededRandom() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
const otoconiaCount = 48;
const otoconia = new THREE.InstancedMesh(
new THREE.OctahedronGeometry(0.025, 0),
new THREE.MeshStandardMaterial({
color: 0xe9fbff,
roughness: 0.18,
metalness: 0.12,
emissive: 0x7ddcf4,
emissiveIntensity: 0.16
}),
otoconiaCount
);
const dummy = new THREE.Object3D();
for (let i = 0; i < otoconiaCount; i++) {
if (i < 28) {
dummy.position.set(
-0.52 + seededRandom() * 0.72,
0.335 + Math.abs(seededRandom() - 0.5) * 0.022,
(seededRandom() - 0.5) * 0.28
);
} else {
dummy.position.set(
0.28 + (seededRandom() - 0.5) * 0.09,
-0.52 + seededRandom() * 0.52,
0.315
);
}
dummy.rotation.set(
seededRandom() * Math.PI,
seededRandom() * Math.PI,
seededRandom() * Math.PI
);
const scale = 0.65 + seededRandom() * 0.8;
dummy.scale.set(scale, scale * 0.7, scale);
dummy.updateMatrix();
otoconia.setMatrixAt(i, dummy.matrix);
}
otoconia.instanceMatrix.needsUpdate = true;
inset.add(otoconia);
// Otolithic nerve.
addTube(
inset,
[
new THREE.Vector3(-0.15, -0.02, 0),
new THREE.Vector3(-0.04, -0.69, 0.04),
new THREE.Vector3(0.06, -0.94, 0.08)
],
0.023,
nerveMaterial,
false,
70
);
addTube(
inset,
[
new THREE.Vector3(0.27, -0.64, 0.02),
new THREE.Vector3(0.19, -0.79, 0.05),
new THREE.Vector3(0.06, -0.94, 0.08)
],
0.018,
nerveMaterial,
false,
60
);
// Linear acceleration and gravity vectors.
const linearDirection = new THREE.Vector3(0.88, 0.30, 0.12).normalize();
const linearArrow = new THREE.ArrowHelper(
linearDirection,
new THREE.Vector3(-0.88, -0.69, 0.24),
1.18,
COLORS.linear,
0.18,
0.09
);
inset.add(linearArrow);
const gravityArrow = new THREE.ArrowHelper(
new THREE.Vector3(0, -1, 0),
new THREE.Vector3(0.73, 0.72, 0.17),
1.15,
0xf0f8fb,
0.16,
0.08
);
inset.add(gravityArrow);
// ---------------------------------------------------------------------
// Projected annotations and leader lines
// ---------------------------------------------------------------------
const annotations = [];
function addAnnotation({
title,
subtitle,
parent,
point,
offsetX,
offsetY,
color,
side = "right"
}) {
const element = document.createElement("div");
element.className = "annotation";
element.style.setProperty("--accent", color);
element.innerHTML = `
<div>
<b>${title}</b>
<small>${subtitle}</small>
</div>
`;
annotationLayer.appendChild(element);
const line = document.createElementNS(
"http://www.w3.org/2000/svg",
"line"
);
line.setAttribute("stroke", color);
line.setAttribute("stroke-width", "1");
line.setAttribute("stroke-opacity", "0.62");
line.setAttribute("stroke-linecap", "round");
leaders.appendChild(line);
annotations.push({
element,
line,
parent,
point: point.clone(),
offsetX,
offsetY,
side
});
}
addAnnotation({
title: "Superior / anterior canal",
subtitle: "Pitch rotation · sagittal-plane approximation",
parent: mainModel,
point: new THREE.Vector3(0, 1.23, 0.42),
offsetX: -205,
offsetY: -48,
color: CSS_COLORS.superior,
side: "left"
});
addAnnotation({
title: "Posterior canal",
subtitle: "Roll rotation · coronal-plane approximation",
parent: mainModel,
point: new THREE.Vector3(0.42, -1.13, 0.10),
offsetX: -208,
offsetY: 34,
color: CSS_COLORS.posterior,
side: "left"
});
addAnnotation({
title: "Horizontal / lateral canal",
subtitle: "Yaw rotation · transverse-plane approximation",
parent: mainModel,
point: new THREE.Vector3(1.04, 0, -0.24),
offsetX: 20,
offsetY: 66,
color: CSS_COLORS.horizontal
});
addAnnotation({
title: "Vestibule + ampullae",
subtitle: "Endolymph moves; cupula bends",
parent: mainModel,
point: new THREE.Vector3(0, -0.06, 0.02),
offsetX: -174,
offsetY: 85,
color: CSS_COLORS.bone,
side: "left"
});
addAnnotation({
title: "Utricle",
subtitle: "Horizontal linear acceleration",
parent: inset,
point: new THREE.Vector3(-0.16, 0.31, 0.02),
offsetX: -170,
offsetY: -58,
color: CSS_COLORS.linear,
side: "left"
});
addAnnotation({
title: "Saccule",
subtitle: "Vertical linear acceleration",
parent: inset,
point: new THREE.Vector3(0.29, -0.29, 0.30),
offsetX: 24,
offsetY: 57,
color: CSS_COLORS.linear
});
addAnnotation({
title: "Otoconia",
subtitle: "CaCO₃ crystals load the macula",
parent: inset,
point: new THREE.Vector3(-0.15, 0.35, 0.03),
offsetX: 48,
offsetY: -76,
color: "#d8f8ff"
});
addAnnotation({
title: "Linear acceleration",
subtitle: "Inertial force on otoconia",
parent: inset,
point: new THREE.Vector3(0.16, -0.35, 0.31),
offsetX: 43,
offsetY: 110,
color: CSS_COLORS.linear
});
function updateAnnotations() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const annotation of annotations) {
const world = annotation.parent.localToWorld(
annotation.point.clone()
);
const projected = world.clone().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;
annotation.element.style.opacity = visible ? "1" : "0";
annotation.line.style.opacity = visible ? "1" : "0";
if (!visible) continue;
const anchorX = (projected.x * 0.5 + 0.5) * width;
const anchorY = (-projected.y * 0.5 + 0.5) * height;
const elementWidth = annotation.element.offsetWidth;
const elementHeight = annotation.element.offsetHeight;
const minimumY = width < 760 ? 120 : 24;
const maximumY = height - 100;
const labelX = THREE.MathUtils.clamp(
anchorX + annotation.offsetX,
10,
Math.max(10, width - elementWidth - 10)
);
const labelY = THREE.MathUtils.clamp(
anchorY + annotation.offsetY,
minimumY,
Math.max(minimumY, maximumY)
);
annotation.element.style.left = `${labelX}px`;
annotation.element.style.top = `${labelY}px`;
const endpointX = annotation.side === "left"
? labelX + elementWidth
: labelX;
const endpointY = labelY + elementHeight * 0.5;
annotation.line.setAttribute("x1", anchorX);
annotation.line.setAttribute("y1", anchorY);
annotation.line.setAttribute("x2", endpointX);
animationLineY(endpointY);
}
}
// Keep SVG line endpoint assignment concise and explicit.
function animationLineY(value) {
// This function is replaced below by the active line reference.
}
// Correct the endpoint helper by assigning it during annotation updates.
const originalUpdateAnnotations = updateAnnotations;
updateAnnotations = function () {
const width = window.innerWidth;
const height = window.innerHeight;
for (const annotation of annotations) {
const world = annotation.parent.localToWorld(
annotation.point.clone()
);
const projected = world.clone().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;
annotation.element.style.opacity = visible ? "1" : "0";
annotation.line.style.opacity = visible ? "1" : "0";
if (!visible) continue;
const anchorX = (projected.x * 0.5 + 0.5) * width;
const anchorY = (-projected.y * 0.5 + 0.5) * height;
const elementWidth = annotation.element.offsetWidth;
const elementHeight = annotation.element.offsetHeight;
const minimumY = width < 760 ? 120 : 24;
const maximumY = height - 100;
const labelX = THREE.MathUtils.clamp(
anchorX + annotation.offsetX,
10,
Math.max(10, width - elementWidth - 10)
);
const labelY = THREE.MathUtils.clamp(
anchorY + annotation.offsetY,
minimumY,
Math.max(minimumY, maximumY)
);
annotation.element.style.left = `${labelX}px`;
annotation.element.style.top = `${labelY}px`;
const endpointX = annotation.side === "left"
? labelX + elementWidth
: labelX;
const endpointY = labelY + elementHeight * 0.5;
annotation.line.setAttribute("x1", anchorX);
annotation.line.setAttribute("y1", anchorY);
annotation.line.setAttribute("x2", endpointX);
annotation.line.setAttribute("y2", endpointY);
}
};
// ---------------------------------------------------------------------
// Resize and animation
// ---------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const newBaseRadius = 8.6 * Math.max(1, 1.28 / aspect);
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * (newBaseRadius / orbit.baseRadius),
5.5,
20
);
orbit.baseRadius = newBaseRadius;
camera.aspect = aspect;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
leaders.setAttribute("viewBox", `0 0 ${width} ${height}`);
updateCamera();
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (orbit.auto && !orbit.dragging) {
orbit.theta += delta * 0.085;
}
updateCamera();
renderer.render(scene, camera);
updateAnnotations();
}
resize();
orbit.radius = orbit.baseRadius;
updateCamera();
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 450);
});
</script>
</body>
</html>
```