Prompt specification
Build or customize the Three.js 3D scene "Nephron route selection explorer" 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: Nephron route selection explorer
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/nephron-route-selection-explorer-x1004
Scene Description Prompt:
Please make a low-poly Three.js scene in one standalone HTML file using cdnjs. Let viewers choose a symbolic substance and highlight its modeled path through filtration and return routes; state that the simplified choices do not predict clinical renal handling.
Working Three.js Starter (nephron-route-selection-explorer-x1004):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Low-Poly Renal Pathway Explorer</title>
<style>
:root {
color-scheme: dark;
--bg: #071521;
--panel: rgba(9, 25, 39, 0.92);
--panel-border: rgba(160, 213, 232, 0.18);
--text: #e8f4f7;
--muted: #9bb5bf;
--cyan: #62ddff;
--mint: #62f0ca;
--amber: #ffc85b;
--blood-in: #d84d68;
--blood-out: #318eaf;
--gold: #b9aa80;
}
* {
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;
}
button {
font: inherit;
}
#scene,
#labels {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
#panel {
position: fixed;
z-index: 10;
top: 18px;
left: 18px;
width: min(370px, calc(100vw - 36px));
max-height: calc(100vh - 36px);
overflow: auto;
padding: 19px;
border: 1px solid var(--panel-border);
border-radius: 18px;
color: var(--text);
background:
linear-gradient(145deg, rgba(20, 48, 65, 0.92), rgba(7, 23, 36, 0.94));
box-shadow:
0 18px 55px rgba(0, 0, 0, 0.38),
inset 0 1px 0 rgba(255, 255, 255, 0.05);
backdrop-filter: blur(14px);
}
.eyebrow {
margin: 0 0 7px;
color: var(--cyan);
font-size: 0.7rem;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(1.45rem, 3vw, 2rem);
line-height: 1.03;
letter-spacing: -0.035em;
}
.intro {
margin: 10px 0 15px;
color: var(--muted);
font-size: 0.83rem;
line-height: 1.5;
}
.section-label {
margin: 16px 0 8px;
color: #c9dce2;
font-size: 0.69rem;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#choices {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 8px;
}
.choice {
min-height: 57px;
padding: 10px 11px;
border: 1px solid rgba(157, 204, 220, 0.16);
border-radius: 11px;
color: #dbe9ed;
text-align: left;
background: rgba(255, 255, 255, 0.035);
cursor: pointer;
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.choice:hover {
transform: translateY(-1px);
border-color: rgba(157, 204, 220, 0.38);
background: rgba(255, 255, 255, 0.065);
}
.choice:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
.choice[aria-pressed="true"] {
border-color: var(--choice-color);
background: color-mix(in srgb, var(--choice-color) 14%, transparent);
box-shadow: inset 3px 0 0 var(--choice-color);
}
.choice-name {
display: block;
font-size: 0.84rem;
font-weight: 800;
}
.choice-role {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 0.68rem;
line-height: 1.25;
}
#readout {
margin-top: 14px;
padding: 13px;
border: 1px solid rgba(157, 204, 220, 0.13);
border-radius: 12px;
background: rgba(2, 13, 22, 0.35);
}
#readout h2 {
margin: 0 0 6px;
font-size: 0.96rem;
}
#description {
margin: 0;
color: #b8cdd4;
font-size: 0.76rem;
line-height: 1.5;
}
.route-table {
display: grid;
grid-template-columns: 84px 1fr;
gap: 6px 10px;
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid rgba(157, 204, 220, 0.12);
font-size: 0.7rem;
line-height: 1.35;
}
.route-table dt {
color: #8eabb5;
font-weight: 700;
}
.route-table dd {
margin: 0;
color: #d8e7eb;
}
.warning {
margin-top: 13px;
padding: 10px 11px;
border: 1px solid rgba(255, 200, 91, 0.26);
border-radius: 10px;
color: #ffe6a7;
background: rgba(255, 200, 91, 0.075);
font-size: 0.7rem;
line-height: 1.45;
}
.warning strong {
color: #ffd77b;
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px 12px;
margin-top: 12px;
color: #a9c0c8;
font-size: 0.67rem;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 13px;
height: 4px;
flex: 0 0 auto;
border-radius: 4px;
background: var(--swatch);
box-shadow: 0 0 9px var(--swatch);
}
.actions {
display: flex;
gap: 8px;
margin-top: 15px;
}
.action {
flex: 1;
padding: 9px 10px;
border: 1px solid rgba(157, 204, 220, 0.18);
border-radius: 9px;
color: #dcebef;
background: rgba(255, 255, 255, 0.045);
cursor: pointer;
font-size: 0.72rem;
font-weight: 700;
}
.action:hover {
background: rgba(255, 255, 255, 0.08);
}
.action:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
.scene-label {
position: fixed;
z-index: 4;
left: 0;
top: 0;
padding: 4px 7px;
border: 1px solid rgba(150, 208, 226, 0.18);
border-radius: 6px;
color: #c8dce4;
background: rgba(5, 18, 29, 0.74);
box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
font-size: 0.64rem;
font-weight: 700;
letter-spacing: 0.025em;
pointer-events: none;
white-space: nowrap;
transform: translate(-50%, -50%);
}
.scene-label.blood-in {
border-color: rgba(216, 77, 104, 0.4);
color: #f2a5b2;
}
.scene-label.blood-out {
border-color: rgba(49, 142, 175, 0.45);
color: #9bd8ed;
}
#help {
position: fixed;
z-index: 5;
right: 18px;
bottom: 16px;
padding: 9px 12px;
border: 1px solid rgba(160, 213, 232, 0.15);
border-radius: 10px;
color: #9eb8c1;
background: rgba(5, 18, 29, 0.75);
font-size: 0.67rem;
line-height: 1.45;
pointer-events: none;
}
@media (max-width: 700px) {
#panel {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
max-height: 49vh;
padding: 14px;
border-radius: 14px;
}
#choices {
grid-template-columns: repeat(4, minmax(0, 1fr));
}
.choice {
min-height: 52px;
padding: 8px 6px;
text-align: center;
}
.choice-role {
display: none;
}
.legend {
grid-template-columns: 1fr;
}
.scene-label {
font-size: 0.58rem;
}
#help {
right: 10px;
bottom: 10px;
}
}
@media (max-width: 480px) {
.intro,
.warning {
font-size: 0.65rem;
}
#readout {
padding: 10px;
}
#description {
font-size: 0.7rem;
}
.scene-label:not(.important) {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="labels" aria-hidden="true">
<div class="scene-label important" id="label-glomerulus">Glomerulus / filtration</div>
<div class="scene-label" id="label-proximal">Proximal tubule</div>
<div class="scene-label" id="label-loop">Loop of Henle</div>
<div class="scene-label" id="label-distal">Distal tubule</div>
<div class="scene-label" id="label-collecting">Collecting duct</div>
<div class="scene-label" id="label-bladder">Bladder</div>
<div class="scene-label blood-in" id="label-in">Arterial blood</div>
<div class="scene-label blood-out" id="label-out">Venous return</div>
</div>
<section id="panel" aria-label="Renal pathway controls">
<p class="eyebrow">Low-poly teaching model</p>
<h1>Renal Pathway Explorer</h1>
<p class="intro">
Choose a symbolic substance to illuminate its modeled filtration,
tubular movement, secretion, and return-to-blood route.
</p>
<div class="section-label">Choose a symbolic substance</div>
<div id="choices" role="group" aria-label="Substances"></div>
<div id="readout" aria-live="polite">
<h2 id="substance-title">Inulin</h2>
<p id="description"></p>
<dl class="route-table">
<dt>Filtration</dt>
<dd id="status-filtration"></dd>
<dt>Return</dt>
<dd id="status-return"></dd>
<dt>Secretion</dt>
<dd id="status-secretion"></dd>
<dt>Urine route</dt>
<dd id="status-urine"></dd>
</dl>
</div>
<div class="warning">
<strong>Schematic only.</strong>
The simplified choices do not predict clinical renal handling.
No quantitative filtration, transport, or clinical decision model is implied.
</div>
<div class="legend" aria-label="Scene legend">
<div class="legend-item">
<span class="swatch" id="legend-substance" style="--swatch:#62ddff"></span>
Selected substance movement
</div>
<div class="legend-item">
<span class="swatch" style="--swatch:#62f0ca"></span>
Return toward blood
</div>
<div class="legend-item">
<span class="swatch" style="--swatch:#ffc85b"></span>
Secretion toward tubule
</div>
<div class="legend-item">
<span class="swatch" style="--swatch:#b9aa80"></span>
Nephron anatomy
</div>
<div class="legend-item">
<span class="swatch" style="--swatch:#d84d68"></span>
Arterial blood
</div>
<div class="legend-item">
<span class="swatch" style="--swatch:#318eaf"></span>
Venous blood
</div>
</div>
<div class="actions">
<button class="action" id="play-pause" type="button">Pause animation</button>
<button class="action" id="reset-view" type="button">Reset view</button>
</div>
</section>
<div id="help">
Drag: orbit · Wheel: zoom · Shift-drag: pan<br>
R: reset view · Space: pause/resume
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.querySelector("#scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071521);
scene.fog = new THREE.Fog(0x071521, 16, 27);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
60
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.18;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly renal filtration and return-pathway scene"
);
sceneHost.appendChild(renderer.domElement);
// Lighting
scene.add(new THREE.HemisphereLight(0xa9d9ed, 0x281729, 1.45));
const keyLight = new THREE.DirectionalLight(0xffffff, 2.2);
keyLight.position.set(4, 8, 9);
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x5ddcff, 22, 18, 2);
rimLight.position.set(-5, 3, 4);
scene.add(rimLight);
const magentaLight = new THREE.PointLight(0xd45cff, 14, 15, 2);
magentaLight.position.set(2, -3, 3);
scene.add(magentaLight);
// Shared materials
const materials = {
tubule: new THREE.MeshStandardMaterial({
color: 0xb9aa80,
roughness: 0.78,
metalness: 0.02
}),
tubuleDark: new THREE.MeshStandardMaterial({
color: 0x6e654e,
roughness: 0.86
}),
artery: new THREE.MeshStandardMaterial({
color: 0xd84d68,
emissive: 0x4a0d1e,
emissiveIntensity: 0.45,
roughness: 0.55
}),
vein: new THREE.MeshStandardMaterial({
color: 0x318eaf,
emissive: 0x073448,
emissiveIntensity: 0.55,
roughness: 0.5
}),
exchange: new THREE.MeshStandardMaterial({
color: 0x466c70,
emissive: 0x10292d,
emissiveIntensity: 0.4,
transparent: true,
opacity: 0.52,
roughness: 0.65
}),
bladder: new THREE.MeshStandardMaterial({
color: 0x6d95a4,
emissive: 0x102b38,
emissiveIntensity: 0.35,
roughness: 0.58
}),
glom: new THREE.MeshStandardMaterial({
color: 0xe35771,
emissive: 0x521020,
emissiveIntensity: 0.65,
roughness: 0.48
})
};
function curve(points) {
return new THREE.CatmullRomCurve3(
points.map((p) => new THREE.Vector3(...p)),
false,
"centripetal"
);
}
function tube(parent, path, radius, material, tubularSegments = 44) {
const geometry = new THREE.TubeGeometry(
path,
tubularSegments,
radius,
6,
false
);
const mesh = new THREE.Mesh(geometry, material);
parent.add(mesh);
return mesh;
}
// Key anatomical locations
const G = [-2.05, 2.15, 0.55];
const B = [-1.28, 1.88, 0.82];
const PCT_REABS = [-0.45, 1.62, 0.86];
const PCT_SECRET = [0.15, 1.75, 0.88];
const PT = [0.15, 0.55, 0.76];
const LOOP_REABS = [-0.42, -0.62, 0.72];
const DCT = [1.45, 0.42, 0.78];
const CD = [1.92, 1.55, 0.70];
const URETER = [3.10, -1.35, 0.38];
const BLADDER = [4.35, -2.45, 0.20];
const J = [-1.35, 1.35, 0.12];
const arterialCurve = curve([
[-5.80, 2.70, 0.00],
[-4.50, 2.65, 0.08],
[-3.30, 2.40, 0.25],
G
]);
const efferentCurve = curve([
G,
[-2.80, 2.05, 0.20],
[-2.05, 1.55, 0.12],
J
]);
const venousCurve = curve([
J,
[-1.15, 0.70, 0.08],
[-0.95, -0.55, 0.08],
[-1.70, -1.75, 0.08],
[-3.00, -2.15, 0.12],
[-5.55, -2.00, 0.12]
]);
const proximalReturnConnector = curve([
PCT_REABS,
[-0.65, 1.55, 0.45],
J
]);
const loopReturnConnector = curve([
LOOP_REABS,
[-0.70, -0.62, 0.36],
[-0.95, -0.55, 0.08]
]);
const secretionConnector = curve([
J,
[-1.05, 1.55, 0.36],
PCT_SECRET
]);
const proximalCurve = curve([
B,
[-0.70, 1.50, 0.86],
PCT_REABS,
[0.45, 1.95, 0.85],
PCT_SECRET,
[0.85, 1.15, 0.80],
PT
]);
const loopCurve = curve([
PT,
[-0.25, -0.45, 0.76],
[-0.55, -1.45, 0.68],
[0.20, -1.65, 0.68],
[0.70, -0.95, 0.72],
[0.85, -0.25, 0.78],
DCT
]);
const distalCurve = curve([
DCT,
[1.70, 0.75, 0.80],
[1.35, 1.05, 0.78],
CD
]);
const collectingCurve = curve([
CD,
[2.25, 0.80, 0.60],
[2.55, -0.30, 0.45],
URETER
]);
const ureterCurve = curve([
URETER,
[3.55, -2.00, 0.32],
BLADDER
]);
const urinaryCurve = curve([
B,
[-0.70, 1.50, 0.86],
PCT_REABS,
[0.45, 1.95, 0.85],
PCT_SECRET,
[0.85, 1.15, 0.80],
PT,
[-0.25, -0.45, 0.76],
[-0.55, -1.45, 0.68],
[0.20, -1.65, 0.68],
[0.70, -0.95, 0.72],
[0.85, -0.25, 0.78],
DCT,
[1.70, 0.75, 0.80],
[1.35, 1.05, 0.78],
CD,
[2.25, 0.80, 0.60],
[2.55, -0.30, 0.45],
URETER,
[3.55, -2.00, 0.32],
BLADDER
]);
const filterCurve = curve([
[-5.80, 2.70, 0.00],
[-4.50, 2.65, 0.08],
[-3.30, 2.40, 0.25],
G,
B,
[-0.70, 1.50, 0.86],
PCT_REABS
]);
const proximalReturnCurve = curve([
PCT_REABS,
[-0.65, 1.55, 0.45],
J,
[-1.15, 0.70, 0.08],
[-0.95, -0.55, 0.08],
[-1.70, -1.75, 0.08],
[-3.00, -2.15, 0.12],
[-5.55, -2.00, 0.12]
]);
const loopReturnCurve = curve([
LOOP_REABS,
[-0.70, -0.62, 0.36],
[-0.95, -0.55, 0.08],
[-1.70, -1.75, 0.08],
[-3.00, -2.15, 0.12],
[-5.55, -2.00, 0.12]
]);
// Stylized low-poly kidney backdrop
const kidneyShape = new THREE.Shape();
const kidneyOutline = [
[-3.25, 1.45],
[-2.70, 2.55],
[-1.75, 3.00],
[-0.65, 2.55],
[0.25, 1.40],
[-0.25, 0.55],
[0.50, -0.35],
[-0.10, -1.55],
[-1.10, -2.65],
[-2.30, -2.45],
[-3.05, -1.10]
];
kidneyOutline.forEach(([x, y], index) => {
if (index === 0) kidneyShape.moveTo(x, y);
else kidneyShape.lineTo(x, y);
});
kidneyShape.closePath();
const kidneyGeometry = new THREE.ExtrudeGeometry(kidneyShape, {
depth: 0.28,
bevelEnabled: false,
steps: 1,
curveSegments: 1
});
kidneyGeometry.translate(0, 0, -1.05);
const kidneyMaterial = new THREE.MeshStandardMaterial({
color: 0x8b4d77,
emissive: 0x2a1027,
emissiveIntensity: 0.28,
transparent: true,
opacity: 0.16,
side: THREE.DoubleSide,
depthWrite: false,
roughness: 0.9
});
const kidney = new THREE.Mesh(kidneyGeometry, kidneyMaterial);
scene.add(kidney);
const kidneyEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(kidneyGeometry),
new THREE.LineBasicMaterial({
color: 0xb86d9e,
transparent: true,
opacity: 0.22
})
);
scene.add(kidneyEdges);
// Ground grid
const grid = new THREE.GridHelper(24, 24, 0x214052, 0x122b39);
grid.position.y = -3.12;
grid.material.transparent = true;
grid.material.opacity = 0.36;
scene.add(grid);
// Blood vessels
tube(scene, arterialCurve, 0.105, materials.artery, 38);
tube(scene, efferentCurve, 0.075, materials.artery, 30);
tube(scene, venousCurve, 0.095, materials.vein, 50);
// Low-poly glomerular tuft
const glomerulus = new THREE.Group();
const tuftOffsets = [
[0, 0, 0],
[0.20, 0.10, 0.02],
[-0.19, 0.12, 0.05],
[0.12, -0.19, 0.08],
[-0.14, -0.17, 0.03],
[0.27, -0.06, -0.02],
[-0.27, -0.04, 0.11],
[0.03, 0.25, 0.00],
[0.02, -0.27, 0.10]
];
for (const [x, y, z] of tuftOffsets) {
const mesh = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.18, 1),
materials.glom
);
mesh.position.set(G[0] + x, G[1] + y, G[2] + z);
mesh.scale.set(1.15, 0.9, 0.85);
glomerulus.add(mesh);
}
scene.add(glomerulus);
// Bowman's capsule
const bowmanMaterial = new THREE.MeshStandardMaterial({
color: 0xb9aa80,
emissive: 0x2c281b,
emissiveIntensity: 0.3,
roughness: 0.7
});
const bowman = new THREE.Mesh(
new THREE.TorusGeometry(0.54, 0.075, 5, 24),
bowmanMaterial
);
bowman.position.set(G[0], G[1], G[2] + 0.18);
scene.add(bowman);
const filtrationHalo = new THREE.Mesh(
new THREE.TorusGeometry(0.69, 0.025, 5, 30),
new THREE.MeshBasicMaterial({
color: 0x62ddff,
transparent: true,
opacity: 0.55,
depthWrite: false
})
);
filtrationHalo.position.set(G[0], G[1], G[2] + 0.20);
scene.add(filtrationHalo);
// Tubular anatomy and independent highlight meshes
const tubularSegments = {};
function addTubularSegment(key, path, radius = 0.115) {
const base = tube(scene, path, radius, materials.tubule, 52);
const highlightMaterial = new THREE.MeshStandardMaterial({
color: 0x62ddff,
emissive: 0x62ddff,
emissiveIntensity: 0.85,
transparent: true,
opacity: 0.40,
depthWrite: false,
roughness: 0.35
});
const highlight = tube(
scene,
path,
radius * 1.16,
highlightMaterial,
52
);
highlight.visible = false;
tubularSegments[key] = { base, highlight, highlightMaterial };
}
addTubularSegment("proximal", proximalCurve);
addTubularSegment("loop", loopCurve);
addTubularSegment("distal", distalCurve, 0.105);
addTubularSegment("collecting", collectingCurve, 0.115);
addTubularSegment("ureter", ureterCurve, 0.085);
// Exchange connectors are always faintly visible as anatomical context.
tube(scene, proximalReturnConnector, 0.035, materials.exchange, 28);
tube(scene, loopReturnConnector, 0.030, materials.exchange, 26);
tube(scene, secretionConnector, 0.030, materials.exchange, 26);
// Bladder
const bladder = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.56, 1),
materials.bladder
);
bladder.position.set(...BLADDER);
bladder.scale.set(1.18, 0.88, 1.0);
scene.add(bladder);
// Dynamic highlights, arrows and particles
const dynamicGroup = new THREE.Group();
scene.add(dynamicGroup);
let particleRoutes = [];
let selectedColor = 0x62ddff;
let paused = false;
let animationTime = 0;
function clearDynamicGroup() {
const geometries = new Set();
const materialsToDispose = new Set();
dynamicGroup.traverse((object) => {
if (object.geometry) geometries.add(object.geometry);
if (object.material) {
if (Array.isArray(object.material)) {
object.material.forEach((m) => materialsToDispose.add(m));
} else {
materialsToDispose.add(object.material);
}
}
});
geometries.forEach((g) => g.dispose());
materialsToDispose.forEach((m) => m.dispose());
dynamicGroup.clear();
particleRoutes = [];
}
function addRouteOverlay(path, color, radius = 0.045, opacity = 0.70) {
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false,
blending: THREE.AdditiveBlending
});
return tube(dynamicGroup, path, radius, material, 64);
}
function addArrows(path, color, count = 5) {
const geometry = new THREE.ConeGeometry(0.10, 0.26, 5);
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.92,
depthWrite: false
});
const up = new THREE.Vector3(0, 1, 0);
for (let i = 0; i < count; i++) {
const t = 0.13 + (i * 0.74) / Math.max(1, count - 1);
const arrow = new THREE.Mesh(geometry, material);
arrow.position.copy(path.getPointAt(t));
arrow.position.z += 0.05;
const tangent = path.getTangentAt(t).normalize();
arrow.quaternion.setFromUnitVectors(up, tangent);
dynamicGroup.add(arrow);
}
}
function addParticleRoute(path, color, count, speed) {
const geometry = new THREE.IcosahedronGeometry(0.065, 0);
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.95
});
const particles = [];
for (let i = 0; i < count; i++) {
const particle = new THREE.Mesh(geometry, material);
dynamicGroup.add(particle);
particles.push(particle);
}
particleRoutes.push({
path,
particles,
speed,
offset: Math.random()
});
}
function clearTubularHighlights() {
for (const segment of Object.values(tubularSegments)) {
segment.highlight.visible = false;
}
}
function highlightTubularSegments(keys, color) {
clearTubularHighlights();
for (const key of keys) {
const segment = tubularSegments[key];
if (!segment) continue;
segment.highlight.visible = true;
segment.highlightMaterial.color.setHex(color);
segment.highlightMaterial.emissive.setHex(color);
}
}
const substances = {
inulin: {
name: "Inulin",
role: "Filtered tracer",
color: 0x62ddff,
description:
"A symbolic freely filtered marker. In this model it crosses into Bowman’s space and continues to the urine without tubular recovery or secretion.",
filtration: "Crosses the glomerular filter into Bowman’s space.",
returnStatus: "None shown.",
secretion: "None shown.",
urine: "Full tubular route to the bladder.",
urinary: true,
returns: [],
secretionShown: false
},
creatinine: {
name: "Creatinine",
role: "Filtered waste marker",
color: 0xffa45b,
description:
"A symbolic filtered waste marker. This model shows filtration, a small secretion toward the proximal tubule, and movement to the urine.",
filtration: "Crosses the glomerular filter into Bowman’s space.",
returnStatus: "None shown.",
secretion: "A small proximal secretion route is shown.",
urine: "Full tubular route to the bladder.",
urinary: true,
returns: [],
secretionShown: true
},
urea: {
name: "Urea",
role: "Partly recovered solute",
color: 0xc493ff,
description:
"A symbolic filtered solute. This model splits the route: some returns to blood from proximal and loop segments, while the remainder continues toward urine.",
filtration: "Crosses the glomerular filter into Bowman’s space.",
returnStatus: "Proximal and loop return-to-blood branches are shown.",
secretion: "None shown.",
urine: "The remaining modeled route continues to the bladder.",
urinary: true,
returns: ["proximal", "loop"],
secretionShown: false
},
glucose: {
name: "Glucose",
role: "Recovered solute",
color: 0x61e6a8,
description:
"A symbolic filtered solute. This model moves it through the proximal tubule and back to peritubular blood, with no onward urinary route.",
filtration: "Crosses the glomerular filter into Bowman’s space.",
returnStatus: "Returns from the proximal tubule to venous blood.",
secretion: "None shown.",
urine: "No onward urinary route is shown after proximal recovery.",
urinary: false,
returns: ["proximal"],
secretionShown: false
}
};
const choiceContainer = document.querySelector("#choices");
const choiceButtons = new Map();
for (const [key, substance] of Object.entries(substances)) {
const button = document.createElement("button");
button.type = "button";
button.className = "choice";
button.style.setProperty(
"--choice-color",
`#${substance.color.toString(16).padStart(6, "0")}`
);
button.setAttribute("aria-pressed", "false");
button.innerHTML = `
<span class="choice-name">${substance.name}</span>
<span class="choice-role">${substance.role}</span>
`;
button.addEventListener("click", () => selectSubstance(key));
choiceContainer.appendChild(button);
choiceButtons.set(key, button);
}
const ui = {
title: document.querySelector("#substance-title"),
description: document.querySelector("#description"),
filtration: document.querySelector("#status-filtration"),
returnStatus: document.querySelector("#status-return"),
secretion: document.querySelector("#status-secretion"),
urine: document.querySelector("#status-urine"),
legend: document.querySelector("#legend-substance"),
playPause: document.querySelector("#play-pause")
};
function selectSubstance(key) {
const substance = substances[key];
selectedColor = substance.color;
for (const [buttonKey, button] of choiceButtons) {
button.setAttribute("aria-pressed", String(buttonKey === key));
}
ui.title.textContent = substance.name;
ui.description.textContent = substance.description;
ui.filtration.textContent = substance.filtration;
ui.returnStatus.textContent = substance.returnStatus;
ui.secretion.textContent = substance.secretion;
ui.urine.textContent = substance.urine;
const cssColor = `#${substance.color.toString(16).padStart(6, "0")}`;
ui.legend.style.setProperty("--swatch", cssColor);
clearDynamicGroup();
// Filtration route: arterial blood → glomerulus → tubular entry.
addRouteOverlay(filterCurve, selectedColor, 0.043, 0.56);
addArrows(filterCurve, selectedColor, 4);
addParticleRoute(filterCurve, selectedColor, 13, 0.105);
// Bowman's capsule and glomerular halo take the selected color.
bowmanMaterial.color.setHex(selectedColor);
bowmanMaterial.emissive.setHex(selectedColor);
bowmanMaterial.emissiveIntensity = 0.22;
filtrationHalo.material.color.setHex(selectedColor);
if (substance.urinary) {
highlightTubularSegments(
["proximal", "loop", "distal", "collecting", "ureter"],
selectedColor
);
addArrows(urinaryCurve, selectedColor, 9);
addParticleRoute(urinaryCurve, selectedColor, 24, 0.043);
} else {
// Glucose is highlighted only through the proximal segment.
highlightTubularSegments(["proximal"], selectedColor);
}
const mint = 0x62f0ca;
const amber = 0xffc85b;
if (substance.returns.includes("proximal")) {
addRouteOverlay(proximalReturnCurve, mint, 0.048, 0.82);
addArrows(proximalReturnCurve, mint, 6);
addParticleRoute(proximalReturnCurve, mint, 15, 0.075);
}
if (substance.returns.includes("loop")) {
addRouteOverlay(loopReturnCurve, mint, 0.045, 0.78);
addArrows(loopReturnCurve, mint, 4);
addParticleRoute(loopReturnCurve, mint, 11, 0.085);
}
if (substance.secretionShown) {
addRouteOverlay(secretionConnector, amber, 0.043, 0.85);
addArrows(secretionConnector, amber, 2);
addParticleRoute(secretionConnector, amber, 7, 0.095);
}
}
// Camera controls implemented locally, without addons.
const target = new THREE.Vector3(-0.15, 0.05, 0);
let yaw = 0.16;
let pitch = 0.09;
let distance = 12.6;
let dragging = false;
let panning = false;
let pointerX = 0;
let pointerY = 0;
function updateCamera() {
const cosPitch = Math.cos(pitch);
camera.position.set(
target.x + distance * cosPitch * Math.sin(yaw),
target.y + distance * Math.sin(pitch),
target.z + distance * cosPitch * Math.cos(yaw)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
function resetView() {
yaw = 0.16;
pitch = 0.09;
distance = 12.6;
target.set(-0.15, 0.05, 0);
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
panning = event.shiftKey || event.button === 2;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
if (panning) {
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
0
);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const panScale = distance * 0.0015;
target.addScaledVector(right, -dx * panScale);
target.addScaledVector(up, dy * panScale);
target.x = THREE.MathUtils.clamp(target.x, -3.5, 3.5);
target.y = THREE.MathUtils.clamp(target.y, -2.5, 2.8);
} else {
yaw -= dx * 0.006;
pitch = THREE.MathUtils.clamp(
pitch + dy * 0.005,
-0.85,
1.05
);
}
updateCamera();
});
function endPointer(event) {
dragging = false;
panning = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
distance = THREE.MathUtils.clamp(
distance * Math.exp(event.deltaY * 0.001),
7.2,
18.5
);
updateCamera();
},
{ passive: false }
);
function togglePause() {
paused = !paused;
ui.playPause.textContent = paused
? "Resume animation"
: "Pause animation";
}
ui.playPause.addEventListener("click", togglePause);
document.querySelector("#reset-view").addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetView();
if (
event.code === "Space" &&
document.activeElement?.tagName !== "BUTTON"
) {
event.preventDefault();
togglePause();
}
});
// Projected HTML labels
const labels = [
{
element: document.querySelector("#label-glomerulus"),
position: new THREE.Vector3(G[0], G[1] + 0.73, G[2])
},
{
element: document.querySelector("#label-proximal"),
position: new THREE.Vector3(0.1, 1.78, 1.0)
},
{
element: document.querySelector("#label-loop"),
position: new THREE.Vector3(0.05, -1.62, 0.9)
},
{
element: document.querySelector("#label-distal"),
position: new THREE.Vector3(1.55, 0.74, 1.0)
},
{
element: document.querySelector("#label-collecting"),
position: new THREE.Vector3(2.65, -0.35, 0.7)
},
{
element: document.querySelector("#label-bladder"),
position: new THREE.Vector3(BLADDER[0], BLADDER[1] - 0.72, BLADDER[2])
},
{
element: document.querySelector("#label-in"),
position: new THREE.Vector3(-4.75, 2.92, 0.2)
},
{
element: document.querySelector("#label-out"),
position: new THREE.Vector3(-3.6, -2.45, 0.3)
}
];
function updateLabels() {
for (const label of labels) {
const projected = label.position.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.12 &&
Math.abs(projected.y) < 1.12;
label.element.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
label.element.style.transform =
`translate(-50%, -50%) translate(${x}px, ${y}px)`;
}
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
window.addEventListener("resize", resize);
// Start with a clear schematic tracer.
selectSubstance("inulin");
updateCamera();
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) {
animationTime += delta;
for (const route of particleRoutes) {
route.particles.forEach((particle, index) => {
const t =
(animationTime * route.speed +
index / route.particles.length +
route.offset) %
1;
particle.position.copy(route.path.getPointAt(t));
particle.rotation.x += 0.04;
particle.rotation.y += 0.06;
});
}
const pulse = 1 + Math.sin(animationTime * 3.1) * 0.075;
filtrationHalo.scale.setScalar(pulse);
filtrationHalo.material.opacity = 0.42 + Math.sin(animationTime * 3.1) * 0.16;
}
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```