Prompt specification
Build or customize the Three.js 3D scene "Kidney organization teaching gallery" 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: Kidney organization teaching gallery
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/kidney-organization-teaching-gallery-x1003
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: kidney organization teaching gallery. Compose an organ-shaped cutaway with cortical and medullary zones beside one enlarged nephron; explicitly separate organ scale from the oversized process inset. Return one self-contained HTML file.
Working Three.js Starter (kidney-organization-teaching-gallery-x1003):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#08111f" />
<title>Kidney, Unpacked — Voxel Anatomy Gallery</title>
<style>
:root {
color-scheme: dark;
--ink: #f4f7fb;
--muted: #a8b5c7;
--panel: rgba(11, 23, 40, 0.78);
--line: rgba(255, 255, 255, 0.14);
--cortex: #f58a78;
--medulla: #c74678;
--pelvis: #f6c85f;
--pink: #ff7aa2;
--blue: #49bfff;
--teal: #44d7c4;
--violet: #b58cff;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 22% 36%, rgba(42, 69, 103, 0.42), transparent 34%),
radial-gradient(circle at 78% 42%, rgba(45, 103, 108, 0.26), transparent 32%),
linear-gradient(150deg, #0a1525 0%, #08101d 58%, #07101b 100%);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#app {
position: relative;
width: 100%;
height: 100%;
isolation: isolate;
}
#scene {
position: absolute;
inset: 0;
display: block;
width: 100%;
height: 100%;
outline: none;
cursor: grab;
touch-action: none;
}
#scene:active {
cursor: grabbing;
}
.header {
position: absolute;
top: clamp(24px, 4vw, 48px);
left: clamp(22px, 4vw, 60px);
z-index: 5;
width: min(470px, calc(100vw - 44px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 15px;
color: #bdc9da;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.eyebrow::before {
width: 31px;
height: 2px;
content: "";
background: #65d9d0;
box-shadow: 0 0 14px rgba(101, 217, 208, 0.55);
}
.live-dot {
display: inline-block;
width: 6px;
height: 6px;
margin-right: 7px;
border-radius: 50%;
background: #69e1d4;
box-shadow: 0 0 12px rgba(105, 225, 212, 0.8);
}
h1 {
margin: 0;
font-size: clamp(38px, 5.1vw, 72px);
font-weight: 650;
letter-spacing: -0.055em;
line-height: 0.94;
}
h1 span {
color: #70ddd3;
}
.intro {
max-width: 420px;
margin: 18px 0 0;
color: var(--muted);
font-size: clamp(12px, 1.15vw, 15px);
line-height: 1.65;
}
.scale-card {
position: absolute;
top: clamp(145px, 18vh, 190px);
z-index: 4;
width: 190px;
padding-left: 13px;
border-left: 2px solid rgba(255, 255, 255, 0.26);
pointer-events: none;
}
.scale-card.organ {
left: 23%;
border-left-color: var(--cortex);
}
.scale-card.nephron {
left: 59%;
border-left-color: var(--blue);
}
.scale-number {
display: block;
margin-bottom: 6px;
color: #75869c;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.scale-card h2 {
margin: 0 0 5px;
font-size: 13px;
font-weight: 760;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.scale-card p {
margin: 0;
color: #91a1b5;
font-size: 10px;
line-height: 1.5;
}
.scale-card .warning {
display: inline-block;
margin-top: 8px;
color: #efbd62;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.divider {
position: absolute;
top: 17%;
bottom: 17%;
left: 50%;
z-index: 2;
width: 1px;
background: linear-gradient(
to bottom,
transparent,
rgba(255, 255, 255, 0.18) 18%,
rgba(255, 255, 255, 0.18) 82%,
transparent
);
pointer-events: none;
}
.divider::before,
.divider::after {
position: absolute;
left: 50%;
width: 5px;
height: 5px;
border: 1px solid rgba(255, 255, 255, 0.45);
border-radius: 50%;
content: "";
transform: translateX(-50%);
background: #0b1728;
}
.divider::before {
top: 0;
}
.divider::after {
bottom: 0;
}
#labels {
position: absolute;
inset: 0;
z-index: 3;
pointer-events: none;
transition: opacity 180ms ease;
}
.labels-off #labels {
opacity: 0;
}
.scene-label {
position: absolute;
top: 0;
left: 0;
display: flex;
align-items: center;
gap: 7px;
width: max-content;
max-width: 160px;
padding: 6px 9px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 4px;
background: rgba(7, 17, 31, 0.82);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
color: #eaf0f8;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.075em;
line-height: 1.2;
text-transform: uppercase;
transform: translate(
calc(-50% + var(--ox, 0px)),
calc(-50% + var(--oy, 0px))
);
backdrop-filter: blur(9px);
}
.scene-label::before {
position: absolute;
top: 50%;
left: -17px;
width: 12px;
height: 1px;
content: "";
background: rgba(255, 255, 255, 0.35);
}
.scene-label::after {
position: absolute;
top: calc(50% - 2px);
left: -20px;
width: 4px;
height: 4px;
border-radius: 50%;
content: "";
background: currentColor;
box-shadow: 0 0 8px currentColor;
}
.scene-label.cortex { color: var(--cortex); }
.scene-label.medulla { color: #dc5c8c; }
.scene-label.pelvis { color: var(--pelvis); }
.scene-label.glomerulus { color: #ff7897; }
.scene-label.pct { color: var(--pink); }
.scene-label.loop { color: var(--blue); }
.scene-label.dct { color: var(--violet); }
.scene-label.collecting { color: var(--pelvis); }
.legend {
position: absolute;
bottom: clamp(24px, 4vw, 48px);
left: clamp(22px, 4vw, 60px);
z-index: 5;
width: min(380px, calc(100vw - 44px));
padding: 15px 17px;
border: 1px solid var(--line);
border-radius: 9px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.2);
backdrop-filter: blur(15px);
}
.legend-title {
margin-bottom: 11px;
color: #8292a8;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.legend-items {
display: flex;
flex-wrap: wrap;
gap: 9px 17px;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #cbd5e2;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.055em;
text-transform: uppercase;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
background: var(--swatch);
box-shadow: 0 0 10px color-mix(in srgb, var(--swatch) 55%, transparent);
}
.controls {
position: absolute;
right: clamp(22px, 4vw, 60px);
bottom: clamp(24px, 4vw, 48px);
z-index: 6;
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 9px;
}
.button-row {
display: flex;
gap: 8px;
}
button {
min-height: 38px;
padding: 0 14px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 6px;
background: rgba(13, 28, 47, 0.86);
color: #d8e2ee;
cursor: pointer;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(12px);
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
button:hover {
border-color: rgba(255, 255, 255, 0.34);
background: rgba(24, 44, 68, 0.94);
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid #68ddd2;
outline-offset: 3px;
}
button.primary {
display: flex;
align-items: center;
gap: 9px;
border-color: rgba(104, 221, 210, 0.55);
background: rgba(39, 135, 133, 0.24);
color: #dffffb;
}
button.primary:hover {
background: rgba(39, 153, 148, 0.36);
}
.play-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #6de0d4;
box-shadow: 0 0 12px rgba(109, 224, 212, 0.8);
}
#caption {
position: absolute;
right: clamp(22px, 4vw, 60px);
bottom: 138px;
z-index: 5;
width: min(360px, 42vw);
color: #aebdd0;
font-size: 11px;
line-height: 1.55;
text-align: right;
pointer-events: none;
}
#caption strong {
color: #edf7f5;
font-weight: 750;
}
.hint {
position: absolute;
top: 50%;
left: 50%;
z-index: 4;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 4px;
background: rgba(8, 18, 32, 0.56);
color: rgba(203, 218, 235, 0.62);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
transform: translate(-50%, 680px) rotate(-90deg);
pointer-events: none;
}
.loading {
position: absolute;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #08111f;
color: #8ea0b6;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
.header {
width: 360px;
}
.intro {
max-width: 320px;
}
.scale-card {
top: 155px;
width: 150px;
}
.scale-card.organ { left: 18%; }
.scale-card.nephron { left: 61%; }
#caption {
width: 300px;
}
.hint {
display: none;
}
}
@media (max-width: 650px) {
.header {
top: 20px;
left: 20px;
}
.eyebrow {
margin-bottom: 10px;
font-size: 8px;
}
.eyebrow .live-dot + span {
display: none;
}
h1 {
font-size: 38px;
}
.intro {
display: none;
}
.scale-card {
top: 104px;
width: 130px;
padding-left: 8px;
}
.scale-card.organ { left: 18%; }
.scale-card.nephron { left: 60%; }
.scale-card h2 {
font-size: 10px;
}
.scale-card p {
font-size: 8px;
}
.scale-card .warning {
font-size: 7px;
}
.legend {
bottom: 92px;
left: 16px;
width: calc(100vw - 32px);
padding: 11px 13px;
}
.legend-title {
display: none;
}
.legend-items {
gap: 8px 12px;
}
.legend-item {
font-size: 7px;
}
.controls {
right: 16px;
bottom: 18px;
left: 16px;
align-items: stretch;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
}
.button-row button:first-child {
grid-column: 1 / -1;
}
button {
min-height: 35px;
padding: 0 10px;
font-size: 8px;
}
#caption {
display: none;
}
.scene-label {
padding: 5px 7px;
font-size: 7px;
}
.divider {
top: 20%;
bottom: 24%;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
scroll-behavior: auto !important;
transition-duration: 0.001ms !important;
}
}
</style>
</head>
<body>
<main id="app">
<canvas id="scene" aria-label="Interactive voxel cutaway of a kidney beside an enlarged nephron"></canvas>
<header class="header">
<div class="eyebrow">
<span>Visual anatomy / 03</span>
<span><i class="live-dot"></i>Interactive voxel study</span>
</div>
<h1>Kidney,<br /><span>unpacked.</span></h1>
<p class="intro">
From a cutaway organ to one working nephron: separate the scales, then
follow filtrate through the filtration pathway.
</p>
</header>
<section class="scale-card organ" aria-label="Organ scale annotation">
<span class="scale-number">01 / Organ scale</span>
<h2>Cutaway kidney</h2>
<p>Approx. 11 cm tall.<br />Cortex, medulla and collecting space.</p>
</section>
<section class="scale-card nephron" aria-label="Nephron process inset annotation">
<span class="scale-number">02 / Process inset</span>
<h2>One nephron</h2>
<p>Conceptually enlarged to reveal the tubule pathway.</p>
<span class="warning">Separate scale · not to scale</span>
</section>
<div class="divider" aria-hidden="true"></div>
<div id="labels" aria-hidden="true"></div>
<aside class="legend" aria-label="Color legend">
<div class="legend-title">Structural key</div>
<div class="legend-items">
<span class="legend-item"><i class="swatch" style="--swatch:#f58a78"></i>Cortex</span>
<span class="legend-item"><i class="swatch" style="--swatch:#c74678"></i>Medulla</span>
<span class="legend-item"><i class="swatch" style="--swatch:#f6c85f"></i>Pelvis / urine</span>
<span class="legend-item"><i class="swatch" style="--swatch:#49bfff"></i>Loop of Henle</span>
<span class="legend-item"><i class="swatch" style="--swatch:#b58cff"></i>Distal tubule</span>
</div>
</aside>
<div class="controls">
<div id="caption" aria-live="polite">
<strong>Explore the pathway.</strong> Press “Follow filtrate” to animate one
particle through the enlarged nephron.
</div>
<div class="button-row">
<button id="flowButton" class="primary" type="button" aria-pressed="false">
<span class="play-dot"></span>
<span id="flowButtonText">Follow filtrate</span>
</button>
<button id="labelButton" type="button" aria-pressed="true">Labels on</button>
<button id="resetButton" type="button">Reset view</button>
</div>
</div>
<div class="hint">Drag to orbit · Scroll to zoom</div>
<div class="loading" id="loading">Constructing voxel gallery</div>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.getElementById("app");
const canvas = document.getElementById("scene");
const loading = document.getElementById("loading");
const labelLayer = document.getElementById("labels");
const flowButton = document.getElementById("flowButton");
const flowButtonText = document.getElementById("flowButtonText");
const labelButton = document.getElementById("labelButton");
const resetButton = document.getElementById("resetButton");
const caption = document.getElementById("caption");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x08111f, 0.022);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const orbit = {
theta: 0.075,
phi: 1.25,
radius: 13.7,
target: new THREE.Vector3(0, 0.08, 0)
};
const desiredOrbit = {
theta: orbit.theta,
phi: orbit.phi,
radius: orbit.radius
};
const sceneLights = new THREE.Group();
scene.add(sceneLights);
sceneLights.add(new THREE.HemisphereLight(0xd9efff, 0x142033, 2.25));
const keyLight = new THREE.DirectionalLight(0xfff2df, 3.4);
keyLight.position.set(-4.5, 8, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0005;
sceneLights.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x65d9ff, 1.7);
rimLight.position.set(7, 3, -6);
sceneLights.add(rimLight);
const warmFill = new THREE.PointLight(0xff7f78, 18, 13, 2);
warmFill.position.set(-4, 1, 5);
sceneLights.add(warmFill);
const coolFill = new THREE.PointLight(0x4fdacb, 16, 12, 2);
coolFill.position.set(4.5, 0.5, 4);
sceneLights.add(coolFill);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(50, 30),
new THREE.MeshStandardMaterial({
color: 0x091522,
roughness: 0.94,
metalness: 0.03,
transparent: true,
opacity: 0.86
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.92;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(36, 36, 0x365069, 0x20344a);
grid.position.y = -1.905;
grid.material.transparent = true;
grid.material.opacity = 0.19;
scene.add(grid);
const labelRecords = [];
function addLabel(text, parent, position, className, offsetX = 0, offsetY = 0) {
const anchor = new THREE.Object3D();
anchor.position.copy(position);
parent.add(anchor);
const element = document.createElement("div");
element.className = `scene-label ${className}`;
element.textContent = text;
element.style.setProperty("--ox", `${offsetX}px`);
element.style.setProperty("--oy", `${offsetY}px`);
labelLayer.appendChild(element);
labelRecords.push({ anchor, element });
}
function makePlatform(radius, accent, x) {
const platform = new THREE.Group();
platform.position.x = x;
const base = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius * 1.06, 0.2, 8),
new THREE.MeshStandardMaterial({
color: 0x16263a,
roughness: 0.78,
metalness: 0.12,
flatShading: true
})
);
base.position.y = -1.79;
base.castShadow = true;
base.receiveShadow = true;
platform.add(base);
const top = new THREE.Mesh(
new THREE.CylinderGeometry(radius * 0.94, radius * 0.97, 0.1, 8),
new THREE.MeshStandardMaterial({
color: 0x20344a,
roughness: 0.66,
metalness: 0.08,
flatShading: true
})
);
top.position.y = -1.64;
top.castShadow = true;
top.receiveShadow = true;
platform.add(top);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(radius * 0.89, 0.018, 4, 64),
new THREE.MeshBasicMaterial({
color: accent,
transparent: true,
opacity: 0.55
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = -1.582;
platform.add(ring);
scene.add(platform);
return platform;
}
const organ = new THREE.Group();
organ.position.set(-2.55, 0.32, 0);
scene.add(organ);
const nephron = new THREE.Group();
nephron.position.set(2.65, 0.28, 0);
scene.add(nephron);
makePlatform(2.15, 0xf58a78, -2.55);
makePlatform(2.1, 0x49bfff, 2.65);
function hash(value) {
const x = Math.sin(value * 12.9898 + 78.233) * 43758.5453;
return x - Math.floor(x);
}
function kidneyBounds(y) {
const normalized = THREE.MathUtils.clamp(y / 1.9, -1, 1);
const width =
1.58 *
Math.pow(Math.max(0, 1 - normalized * normalized), 0.55) *
(0.94 + 0.06 * Math.cos(y * 1.25));
const center = 0.16 + 0.08 * Math.sin(y * 0.9);
const medialInset = 0.3 * Math.exp(-Math.pow(y / 0.58, 2));
const left = center - width * (0.84 - medialInset);
const right = center + width;
return { left, right };
}
function insideTriangle(px, py, a, b, c) {
const d1 = (px - b[0]) * (a[1] - b[1]) - (a[0] - b[0]) * (py - b[1]);
const d2 = (px - c[0]) * (b[1] - c[1]) - (b[0] - c[0]) * (py - c[1]);
const d3 = (px - a[0]) * (c[1] - a[1]) - (c[0] - a[0]) * (py - a[1]);
const hasNegative = d1 < 0 || d2 < 0 || d3 < 0;
const hasPositive = d1 > 0 || d2 > 0 || d3 > 0;
return !(hasNegative && hasPositive);
}
const pyramids = [
[[-0.27, 0.72], [-0.18, 1.62], [1.13, 1.46]],
[[-0.30, 0.16], [-0.12, 0.92], [1.28, 0.72]],
[[-0.31, -0.48], [-0.13, -0.18], [1.25, -0.92]],
[[-0.26, -1.08], [-0.05, -0.72], [0.98, -1.58]]
];
function isMedulla(x, y) {
return pyramids.some((triangle) =>
insideTriangle(x, y, triangle[0], triangle[1], triangle[2])
);
}
const kidneyVoxels = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.132, 0.132, 0.132),
new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
roughness: 0.72,
metalness: 0.025
}),
6200
);
kidneyVoxels.castShadow = true;
kidneyVoxels.receiveShadow = true;
const dummy = new THREE.Object3D();
const cortexColor = new THREE.Color("#f28a78");
const deepCortexColor = new THREE.Color("#a84859");
const medullaColor = new THREE.Color("#bd416f");
const pelvisColor = new THREE.Color("#f3c55e");
const tempColor = new THREE.Color();
let voxelIndex = 0;
let yi = 0;
for (let y = -1.84; y <= 1.84; y += 0.145) {
const bounds = kidneyBounds(y);
let xi = 0;
for (let x = -1.04; x <= 1.8; x += 0.145) {
if (x >= bounds.left && x <= bounds.right) {
const edgeDistance = Math.min(
x - bounds.left,
bounds.right - x,
(1.9 - Math.abs(y)) * 1.15
);
const isShell = edgeDistance < 0.34;
const frontLimit = isShell ? 0.58 : 0.145;
for (let z = -0.58; z <= frontLimit + 0.001; z += 0.145) {
if (voxelIndex >= 6200) break;
dummy.position.set(x, y, z);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
kidneyVoxels.setMatrixAt(voxelIndex, dummy.matrix);
const variation = (hash(voxelIndex * 1.37) - 0.5) * 0.07;
if (!isShell && z < 0.02) {
tempColor.copy(deepCortexColor);
} else if (isShell) {
tempColor.copy(cortexColor);
} else if (isMedulla(x, y)) {
tempColor.copy(medullaColor);
} else if (x < -0.18 && Math.abs(y) < 1.28) {
tempColor.copy(pelvisColor);
} else {
tempColor.copy(cortexColor);
}
tempColor.offsetHSL(0, 0, variation);
kidneyVoxels.setColorAt(voxelIndex, tempColor);
voxelIndex++;
}
}
xi++;
}
yi++;
}
kidneyVoxels.count = voxelIndex;
kidneyVoxels.instanceMatrix.needsUpdate = true;
if (kidneyVoxels.instanceColor) kidneyVoxels.instanceColor.needsUpdate = true;
kidneyVoxels.computeBoundingSphere();
organ.add(kidneyVoxels);
function addVoxelLine(parent, points, color, size = 0.09, opacity = 1) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.45,
metalness: 0.05,
emissive: color,
emissiveIntensity: 0.11,
transparent: opacity < 1,
opacity
});
const positions = [];
for (let segment = 0; segment < points.length - 1; segment++) {
const a = points[segment];
const b = points[segment + 1];
const distance = a.distanceTo(b);
const count = Math.max(1, Math.ceil(distance / (size * 0.72)));
for (let i = 0; i < count; i++) {
const t = i / count;
positions.push(
new THREE.Vector3().lerpVectors(a, b, t)
);
}
}
positions.push(points[points.length - 1].clone());
const mesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(size, size, size),
material,
positions.length
);
positions.forEach((position, index) => {
dummy.position.copy(position);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
// Gold collecting space and ureter laid over the cut face.
addVoxelLine(
organ,
[
new THREE.Vector3(-0.48, 0.12, 0.34),
new THREE.Vector3(-0.34, 0.52, 0.36),
new THREE.Vector3(-0.27, 0.72, 0.37)
],
0xffcf62,
0.105
);
addVoxelLine(
organ,
[
new THREE.Vector3(-0.48, 0.12, 0.35),
new THREE.Vector3(-0.35, -0.08, 0.36),
new THREE.Vector3(-0.31, -0.48, 0.37)
],
0xffcf62,
0.105
);
addVoxelLine(
organ,
[
new THREE.Vector3(-0.48, 0.1, 0.34),
new THREE.Vector3(-0.27, -1.08, 0.36)
],
0xffcf62,
0.105
);
addVoxelLine(
organ,
[
new THREE.Vector3(-0.48, 0.08, 0.35),
new THREE.Vector3(-0.92, -0.02, 0.37),
new THREE.Vector3(-1.3, -0.26, 0.39),
new THREE.Vector3(-1.57, -0.72, 0.39)
],
0xf6c85f,
0.115
);
// Renal artery and vein at the hilum.
addVoxelLine(
organ,
[
new THREE.Vector3(-0.65, 0.48, 0.48),
new THREE.Vector3(-1.04, 0.59, 0.5),
new THREE.Vector3(-1.48, 0.72, 0.48)
],
0xee5d68,
0.105
);
addVoxelLine(
organ,
[
new THREE.Vector3(-0.66, 0.28, 0.51),
new THREE.Vector3(-1.08, 0.31, 0.52),
new THREE.Vector3(-1.5, 0.39, 0.5)
],
0x489ee8,
0.105
);
addLabel(
"Cortex",
organ,
new THREE.Vector3(0.84, 1.05, 0.67),
"cortex",
74,
-14
);
addLabel(
"Medullary pyramids",
organ,
new THREE.Vector3(0.42, -0.28, 0.31),
"medulla",
84,
12
);
addLabel(
"Renal pelvis",
organ,
new THREE.Vector3(-0.52, 0.08, 0.43),
"pelvis",
-77,
-8
);
// Enlarged nephron: one continuous, color-coded filtration pathway.
const pathwayDefinitions = [
{
name: "Glomerular filtration",
description: "Blood pressure pushes water and small solutes into Bowman’s capsule.",
color: 0xffffff,
points: [
[-0.95, 1.25, 0.08],
[-0.72, 1.25, 0.08]
]
},
{
name: "Proximal tubule",
description: "The proximal tubule reclaims most filtered water, salts and nutrients.",
color: 0xff7aa2,
points: [
[-0.72, 1.25, 0.08],
[-0.38, 1.58, 0.16],
[0.22, 1.6, 0.12],
[0.63, 1.29, 0.02],
[0.28, 1.08, -0.08],
[-0.15, 1.08, -0.02]
]
},
{
name: "Descending limb",
description: "The thin descending limb passes into the medulla; water exits into the interstitium.",
color: 0x49bfff,
points: [
[-0.15, 1.08, -0.02],
[-0.15, 0.42, -0.06],
[-0.15, -0.78, -0.08],
[-0.12, -1.3, -0.03],
[0.18, -1.53, 0.08],
[0.58, -1.34, 0.12]
]
},
{
name: "Ascending limb",
description: "The ascending limb returns toward the cortex while transporting salt out.",
color: 0x44d7c4,
points: [
[0.58, -1.34, 0.12],
[0.6, -0.82, 0.06],
[0.6, 0.28, 0.02],
[0.57, 0.83, 0.04],
[0.9, 1.0, 0.08]
]
},
{
name: "Distal tubule",
description: "The distal tubule fine-tunes pH and electrolyte balance before final collection.",
color: 0xb58cff,
points: [
[0.9, 1.0, 0.08],
[1.28, 0.68, 0.13],
[0.98, 0.43, 0.08],
[0.58, 0.51, 0.01],
[0.72, 0.1, -0.02]
]
},
{
name: "Collecting duct",
description: "The collecting duct concentrates urine and carries it toward the renal papilla.",
color: 0xf6c85f,
points: [
[0.72, 0.1, -0.02],
[0.45, -0.12, -0.06],
[0.31, -0.48, -0.08],
[0.31, -1.03, -0.07],
[0.31, -1.64, -0.03]
]
}
];
const flowPath = new THREE.CurvePath();
const flowRecords = [];
pathwayDefinitions.forEach((definition, index) => {
const points = definition.points.map(
(point) => new THREE.Vector3(point[0], point[1], point[2])
);
const curve = new THREE.CatmullRomCurve3(points, false, "centripetal", 0.45);
flowPath.add(curve);
const record = {
...definition,
curve,
index,
material: null
};
if (index > 0) {
const length = curve.getLength();
const count = Math.max(18, Math.ceil(length / 0.055));
const material = new THREE.MeshStandardMaterial({
color: definition.color,
roughness: 0.42,
metalness: 0.03,
emissive: definition.color,
emissiveIntensity: 0.12
});
const tube = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.112, 0.112, 0.112),
material,
count
);
for (let i = 0; i < count; i++) {
const t = i / (count - 1);
dummy.position.copy(curve.getPointAt(t));
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
tube.setMatrixAt(i, dummy.matrix);
}
tube.instanceMatrix.needsUpdate = true;
tube.castShadow = true;
tube.receiveShadow = true;
nephron.add(tube);
record.material = material;
}
flowRecords.push(record);
});
// Glomerular capillary tuft.
const glomerulusGeometry = new THREE.BoxGeometry(0.135, 0.135, 0.135);
const glomerulusMaterial = new THREE.MeshStandardMaterial({
color: 0xef5376,
roughness: 0.48,
emissive: 0x8f183a,
emissiveIntensity: 0.18
});
const glomerulus = new THREE.InstancedMesh(
glomerulusGeometry,
glomerulusMaterial,
38
);
for (let i = 0; i < 38; i++) {
const theta = hash(i * 2.13) * Math.PI * 2;
const radius = Math.sqrt(hash(i * 4.71)) * 0.25;
dummy.position.set(
-0.95 + Math.cos(theta) * radius * 1.06,
1.25 + Math.sin(theta) * radius,
0.08 + (hash(i * 8.2) - 0.5) * 0.19
);
const scale = 0.75 + hash(i * 3.4) * 0.6;
dummy.scale.setScalar(scale);
dummy.updateMatrix();
glomerulus.setMatrixAt(i, dummy.matrix);
}
glomerulus.instanceMatrix.needsUpdate = true;
glomerulus.castShadow = true;
nephron.add(glomerulus);
// Bowman's capsule rendered as a voxel ring.
const capsuleMaterial = new THREE.MeshStandardMaterial({
color: 0xf6d89a,
roughness: 0.56,
metalness: 0.02,
emissive: 0x8b6b32,
emissiveIntensity: 0.08
});
const capsule = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.1, 0.1, 0.1),
capsuleMaterial,
30
);
for (let i = 0; i < 30; i++) {
const angle = (i / 30) * Math.PI * 2;
dummy.position.set(
-0.95 + Math.cos(angle) * 0.36,
1.25 + Math.sin(angle) * 0.4,
0.08
);
dummy.rotation.set(0, 0, angle);
dummy.scale.setScalar(1);
dummy.updateMatrix();
capsule.setMatrixAt(i, dummy.matrix);
}
capsule.instanceMatrix.needsUpdate = true;
capsule.castShadow = true;
nephron.add(capsule);
const glomerulusHalo = new THREE.Mesh(
new THREE.TorusGeometry(0.43, 0.018, 4, 48),
new THREE.MeshBasicMaterial({
color: 0xff7796,
transparent: true,
opacity: 0.28
})
);
glomerulusHalo.position.set(-0.95, 1.25, 0.02);
nephron.add(glomerulusHalo);
// Directional arrows along the enlarged pathway.
const arrowRecords = [];
flowRecords.forEach((record) => {
if (record.index === 0) return;
const tangent = record.curve.getTangentAt(0.56).normalize();
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.105, 0.24, 4),
new THREE.MeshStandardMaterial({
color: 0xf4fbff,
roughness: 0.35,
emissive: 0xaed6df,
emissiveIntensity: 0.2
})
);
arrow.position.copy(record.curve.getPointAt(0.56));
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
tangent
);
arrow.castShadow = true;
nephron.add(arrow);
arrowRecords.push(arrow);
});
addLabel(
"Glomerulus",
nephron,
new THREE.Vector3(-0.95, 1.42, 0.08),
"glomerulus",
-64,
-28
);
addLabel(
"Proximal tubule",
nephron,
new THREE.Vector3(0.15, 1.72, 0.1),
"pct",
65,
-30
);
addLabel(
"Loop of Henle",
nephron,
new THREE.Vector3(0.2, -1.52, 0.06),
"loop",
-63,
20
);
addLabel(
"Distal tubule",
nephron,
new THREE.Vector3(1.13, 0.62, 0.1),
"dct",
73,
-13
);
addLabel(
"Collecting duct",
nephron,
new THREE.Vector3(0.31, -1.05, 0),
"collecting",
76,
20
);
const tracer = new THREE.Mesh(
new THREE.BoxGeometry(0.16, 0.16, 0.16),
new THREE.MeshStandardMaterial({
color: 0xffffff,
emissive: 0x9dfff3,
emissiveIntensity: 2.8,
roughness: 0.2
})
);
tracer.visible = false;
tracer.castShadow = true;
nephron.add(tracer);
const tracerLight = new THREE.PointLight(0xa8fff2, 4, 1.5, 2);
tracer.add(tracerLight);
let flowActive = false;
let flowComplete = false;
let flowT = 0;
function updateFlowButton() {
if (flowActive) {
flowButtonText.textContent = "Pause filtrate";
flowButton.setAttribute("aria-pressed", "true");
} else if (flowComplete) {
flowButtonText.textContent = "Replay filtrate";
flowButton.setAttribute("aria-pressed", "false");
} else {
flowButtonText.textContent = "Follow filtrate";
flowButton.setAttribute("aria-pressed", "false");
}
}
flowButton.addEventListener("click", () => {
if (flowComplete && !flowActive) {
flowT = 0;
flowComplete = false;
flowActive = true;
tracer.visible = true;
} else {
flowActive = !flowActive;
tracer.visible = true;
}
updateFlowButton();
});
labelButton.addEventListener("click", () => {
const hidden = app.classList.toggle("labels-off");
labelButton.textContent = hidden ? "Labels off" : "Labels on";
labelButton.setAttribute("aria-pressed", String(!hidden));
});
resetButton.addEventListener("click", () => {
desiredOrbit.theta = 0.075;
desiredOrbit.phi = 1.25;
desiredOrbit.radius = 13.7;
});
// Direct camera controls, implemented without external helper modules.
let dragging = false;
let previousX = 0;
let previousY = 0;
let pointerId = null;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerId = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
desiredOrbit.theta = THREE.MathUtils.clamp(
desiredOrbit.theta - dx * 0.005,
-0.58,
0.58
);
desiredOrbit.phi = THREE.MathUtils.clamp(
desiredOrbit.phi - dy * 0.004,
0.78,
1.46
);
});
function endDrag(event) {
if (event.pointerId !== pointerId) return;
dragging = false;
pointerId = null;
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("lostpointercapture", () => {
dragging = false;
pointerId = null;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredOrbit.radius = THREE.MathUtils.clamp(
desiredOrbit.radius + event.deltaY * 0.008,
9.5,
18
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
desiredOrbit.theta = 0.075;
desiredOrbit.phi = 1.25;
desiredOrbit.radius = 13.7;
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height, false);
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
const projected = new THREE.Vector3();
const upAxis = new THREE.Vector3(0, 1, 0);
let animationTime = 0;
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
labelRecords.forEach(({ anchor, element }) => {
anchor.getWorldPosition(projected);
projected.project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "flex" : "none";
element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
});
}
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
animationTime += delta;
const damping = 0.085;
orbit.theta += (desiredOrbit.theta - orbit.theta) * damping;
orbit.phi += (desiredOrbit.phi - orbit.phi) * damping;
orbit.radius += (desiredOrbit.radius - orbit.radius) * damping;
const responsiveFactor =
camera.aspect < 0.75 ? 1.42 :
camera.aspect < 1.1 ? 1.18 : 1;
const radius = orbit.radius * responsiveFactor;
const horizontal = Math.sin(orbit.phi) * radius;
camera.position.set(
orbit.target.x + horizontal * Math.sin(orbit.theta),
orbit.target.y + Math.cos(orbit.phi) * radius,
orbit.target.z + horizontal * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
if (flowActive) {
flowT += delta / 10.5;
if (flowT >= 1) {
flowT = 1;
flowActive = false;
flowComplete = true;
updateFlowButton();
}
const point = flowPath.getPointAt(flowT);
const tangent = flowPath.getTangentAt(flowT).normalize();
tracer.position.copy(point);
tracer.quaternion.setFromUnitVectors(upAxis, tangent);
const pulse = 1 + Math.sin(animationTime * 7) * 0.12;
tracer.scale.setScalar(pulse);
const lengths = flowPath.getCurveLengths();
const distance = flowT * flowPath.getLength();
let activeIndex = 0;
for (let i = 0; i < lengths.length; i++) {
if (distance <= lengths[i]) {
activeIndex = i;
break;
}
activeIndex = i;
}
flowRecords.forEach((record, index) => {
if (record.material) {
record.material.emissiveIntensity =
index === activeIndex ? 0.52 : 0.12;
}
});
const active = flowRecords[activeIndex];
caption.innerHTML =
`<strong>${active.name}.</strong> ${active.description}`;
}
arrowRecords.forEach((arrow, index) => {
const pulse = 1 + Math.sin(animationTime * 2.7 + index * 1.6) * 0.08;
arrow.scale.setScalar(pulse);
});
const haloPulse = 1 + Math.sin(animationTime * 2.1) * 0.045;
glomerulusHalo.scale.setScalar(haloPulse);
glomerulusHalo.material.opacity = 0.22 + Math.sin(animationTime * 2.1) * 0.08;
scene.updateMatrixWorld(true);
updateLabels();
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => loading.classList.add("hidden"));
</script>
</body>
</html>
```