Prompt specification
Build or customize the Three.js 3D scene "Digestive process mapping board" 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: Digestive process mapping board
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/digestive-process-mapping-board-x0976
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing the digestive tract. Let users select transport, breakdown, or absorption and highlight relevant schematic regions; avoid implying each process occurs at only one isolated anatomical point. Low-poly.
Working Three.js Starter (digestive-process-mapping-board-x0976):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Digestive Tract — Interactive Low-Poly Schematic</title>
<style>
:root {
--accent: #56d9e8;
--panel: rgba(8, 19, 29, 0.82);
--panel-border: rgba(180, 225, 240, 0.16);
--text: #edf7fb;
--muted: #9db2bd;
--soft: #c6d8df;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07121b;
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body::after {
content: "";
position: fixed;
inset: 0;
z-index: 1;
pointer-events: none;
background:
radial-gradient(circle at 48% 46%, transparent 28%, rgba(2, 8, 13, 0.48) 100%);
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
z-index: 0;
}
#scene:focus-visible {
outline: 2px solid var(--accent);
outline-offset: -4px;
}
.glass {
background: var(--panel);
border: 1px solid var(--panel-border);
border-radius: 18px;
box-shadow:
0 18px 50px rgba(0, 0, 0, 0.28),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
backdrop-filter: blur(15px) saturate(120%);
-webkit-backdrop-filter: blur(15px) saturate(120%);
}
.intro {
position: fixed;
z-index: 5;
top: 22px;
left: 22px;
width: min(440px, calc(100vw - 44px));
padding: 19px;
}
.eyebrow {
margin: 0 0 7px;
color: var(--accent);
font-size: 0.69rem;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(1.5rem, 2.2vw, 2.15rem);
line-height: 1.04;
letter-spacing: -0.035em;
}
.intro-copy {
margin: 9px 0 15px;
color: var(--muted);
font-size: 0.86rem;
line-height: 1.45;
}
.mode-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.mode-button {
min-height: 68px;
padding: 10px 8px;
color: var(--soft);
text-align: left;
background: rgba(255, 255, 255, 0.035);
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 12px;
cursor: pointer;
transition:
background 160ms ease,
border-color 160ms ease,
color 160ms ease,
transform 160ms ease;
}
.mode-button:hover {
background: rgba(255, 255, 255, 0.075);
transform: translateY(-1px);
}
.mode-button:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
.mode-button[aria-pressed="true"] {
color: #fff;
background: color-mix(in srgb, var(--accent) 15%, transparent);
border-color: color-mix(in srgb, var(--accent) 68%, transparent);
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.025);
}
.mode-icon {
display: block;
margin-bottom: 5px;
color: var(--accent);
font-size: 1rem;
line-height: 1;
}
.mode-button b,
.mode-button small {
display: block;
}
.mode-button b {
font-size: 0.77rem;
letter-spacing: 0.01em;
}
.mode-button small {
margin-top: 3px;
color: var(--muted);
font-size: 0.64rem;
line-height: 1.2;
}
.info {
position: fixed;
z-index: 5;
top: 22px;
right: 22px;
width: min(355px, calc(100vw - 44px));
max-height: calc(100vh - 120px);
padding: 20px;
overflow: auto;
scrollbar-width: thin;
scrollbar-color: rgba(255, 255, 255, 0.16) transparent;
}
.info h2 {
margin: 0 0 9px;
font-size: 1.27rem;
line-height: 1.16;
letter-spacing: -0.025em;
}
.info-copy {
margin: 0;
color: var(--soft);
font-size: 0.82rem;
line-height: 1.55;
}
.strip-label,
.site-label {
margin: 17px 0 8px;
color: var(--muted);
font-size: 0.64rem;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.process-strip {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 5px;
}
.process-strip span {
padding: 5px 8px;
color: #fff;
background: color-mix(in srgb, var(--accent) 15%, transparent);
border: 1px solid color-mix(in srgb, var(--accent) 42%, transparent);
border-radius: 999px;
font-size: 0.65rem;
font-weight: 700;
}
.process-strip b {
color: var(--accent);
font-size: 0.72rem;
}
.site-list {
display: grid;
gap: 9px;
margin: 0;
padding: 0;
list-style: none;
}
.site-list li {
display: grid;
grid-template-columns: 8px 1fr;
gap: 9px;
align-items: start;
}
.site-dot {
width: 6px;
height: 6px;
margin-top: 5px;
background: var(--accent);
border-radius: 50%;
box-shadow: 0 0 9px color-mix(in srgb, var(--accent) 65%, transparent);
}
.site-list strong,
.site-list small {
display: block;
}
.site-list strong {
margin-bottom: 2px;
font-size: 0.75rem;
color: #f3fafd;
}
.site-list small {
color: var(--muted);
font-size: 0.69rem;
line-height: 1.42;
}
.note {
margin: 17px 0 0;
padding-top: 13px;
color: #8299a5;
border-top: 1px solid rgba(255, 255, 255, 0.08);
font-size: 0.68rem;
line-height: 1.45;
}
.toolbar {
position: fixed;
z-index: 6;
right: 22px;
bottom: 22px;
display: flex;
gap: 7px;
}
.tool-button {
display: flex;
align-items: center;
gap: 7px;
min-height: 38px;
padding: 8px 11px;
color: var(--soft);
background: rgba(8, 19, 29, 0.8);
border: 1px solid rgba(180, 225, 240, 0.14);
border-radius: 11px;
cursor: pointer;
backdrop-filter: blur(10px);
font-size: 0.7rem;
font-weight: 700;
}
.tool-button:hover {
color: #fff;
border-color: color-mix(in srgb, var(--accent) 55%, transparent);
}
.tool-button:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
.tool-icon {
color: var(--accent);
font-size: 0.95rem;
}
.legend {
position: fixed;
z-index: 5;
left: 22px;
bottom: 22px;
display: flex;
align-items: center;
gap: 9px;
max-width: min(430px, calc(100vw - 44px));
padding: 9px 12px;
color: var(--muted);
background: rgba(8, 19, 29, 0.72);
border: 1px solid rgba(180, 225, 240, 0.12);
border-radius: 12px;
backdrop-filter: blur(10px);
font-size: 0.67rem;
line-height: 1.35;
}
.legend-dot {
flex: 0 0 auto;
width: 9px;
height: 9px;
background: var(--accent);
border-radius: 50%;
box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 70%, transparent);
}
.help {
position: fixed;
z-index: 4;
left: 50%;
bottom: 24px;
transform: translateX(-50%);
color: rgba(210, 228, 235, 0.54);
font-size: 0.66rem;
pointer-events: none;
white-space: nowrap;
}
#labels {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
transition: opacity 180ms ease;
}
#labels.hidden {
opacity: 0;
}
.anatomy-label {
position: absolute;
padding: 5px 8px;
color: #e9f5fa;
background: rgba(5, 14, 22, 0.72);
border: 1px solid rgba(170, 215, 230, 0.18);
border-radius: 8px;
box-shadow: 0 5px 18px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(6px);
transform: translate(-50%, -50%);
font-size: 0.64rem;
font-weight: 700;
letter-spacing: 0.01em;
white-space: nowrap;
transition:
opacity 180ms ease,
border-color 180ms ease,
color 180ms ease;
}
.anatomy-label::before {
content: "";
display: inline-block;
width: 5px;
height: 5px;
margin-right: 5px;
vertical-align: 1px;
background: var(--accent);
border-radius: 50%;
}
.anatomy-label.is-muted {
opacity: 0.2;
}
#fallback {
position: fixed;
z-index: 20;
inset: 50% auto auto 50%;
width: min(420px, calc(100vw - 40px));
transform: translate(-50%, -50%);
padding: 20px;
color: white;
background: #152631;
border: 1px solid #47606d;
border-radius: 14px;
text-align: center;
}
@media (max-width: 840px) {
.intro {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 14px;
}
.intro-copy {
margin: 7px 0 11px;
font-size: 0.76rem;
}
.mode-button {
min-height: 59px;
padding: 8px 6px;
}
.mode-button small {
display: none;
}
.info {
top: auto;
right: 10px;
bottom: 57px;
left: 10px;
width: auto;
max-height: 39vh;
padding: 14px;
}
.info h2 {
font-size: 1.08rem;
}
.info-copy {
font-size: 0.75rem;
}
.site-list small {
font-size: 0.65rem;
}
.toolbar {
right: 10px;
bottom: 10px;
}
.legend,
.help,
.anatomy-label {
display: none !important;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
scroll-behavior: auto !important;
transition-duration: 0.01ms !important;
animation-duration: 0.01ms !important;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive low-poly schematic of the digestive tract. Drag to rotate, scroll to zoom, and shift-drag to pan."
></canvas>
<div id="labels" aria-hidden="true"></div>
<header class="intro glass">
<p class="eyebrow">Interactive anatomy · low-poly schematic</p>
<h1>Digestive Tract</h1>
<p class="intro-copy">
Select a process to reveal the multiple connected regions where it unfolds.
Color spans whole participating regions—not one isolated hotspot.
</p>
<nav class="mode-grid" aria-label="Digestive process">
<button class="mode-button" data-mode="transport" aria-pressed="true">
<span class="mode-icon" aria-hidden="true">↝</span>
<b>Transport</b>
<small>Movement along the lumen</small>
</button>
<button class="mode-button" data-mode="breakdown" aria-pressed="false">
<span class="mode-icon" aria-hidden="true">✣</span>
<b>Breakdown</b>
<small>Mechanical and chemical digestion</small>
</button>
<button class="mode-button" data-mode="absorption" aria-pressed="false">
<span class="mode-icon" aria-hidden="true">⌁</span>
<b>Absorption</b>
<small>Transfer across broad surfaces</small>
</button>
</nav>
</header>
<section class="info glass" aria-live="polite" aria-atomic="true">
<p class="eyebrow" id="infoEyebrow">Selected process · 01</p>
<h2 id="infoTitle">Transport is continuous</h2>
<p class="info-copy" id="infoCopy"></p>
<p class="strip-label">Process continuum</p>
<div class="process-strip" id="processStrip"></div>
<p class="site-label">Highlighted schematic regions</p>
<ul class="site-list" id="siteList"></ul>
<p class="note" id="infoNote"></p>
</section>
<div class="toolbar">
<button class="tool-button" id="resetView" type="button">
<span class="tool-icon" aria-hidden="true">⟳</span>
<span>Reset view</span>
</button>
<button
class="tool-button"
id="toggleLabels"
type="button"
aria-pressed="true"
>
<span class="tool-icon" aria-hidden="true">A</span>
<span id="labelState">Labels on</span>
</button>
</div>
<div class="legend">
<span class="legend-dot" aria-hidden="true"></span>
<span>
Whole-region shading plus distributed markers show where the selected
process participates. Schematic, not to scale.
</span>
</div>
<div class="help">Drag to rotate · Scroll to zoom · Shift-drag to pan</div>
<div id="fallback" hidden>
This interactive schematic requires WebGL. Please try a browser with
hardware-accelerated WebGL enabled.
</div>
<noscript>This interactive schematic requires JavaScript.</noscript>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const labelsLayer = document.getElementById("labels");
const modeButtons = [...document.querySelectorAll(".mode-button")];
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
let renderer;
try {
renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
} catch (error) {
document.getElementById("fallback").hidden = false;
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07121b);
scene.fog = new THREE.Fog(0x07121b, 11, 25);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
60
);
const anatomy = new THREE.Group();
scene.add(anatomy);
const hemisphere = new THREE.HemisphereLight(0xc9efff, 0x17212a, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(-4.5, 8, 6.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -5;
keyLight.shadow.camera.right = 5;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 20;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x56d9e8, 1.35);
rimLight.position.set(5, 1, -5);
scene.add(rimLight);
const warmFill = new THREE.PointLight(0xffa66c, 11, 13, 2);
warmFill.position.set(-2, 2.5, 4);
scene.add(warmFill);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(22, 22),
new THREE.MeshStandardMaterial({
color: 0x09141d,
roughness: 0.95,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -2.78;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(9, 18, 0x28404d, 0x182a35);
grid.position.y = -2.765;
grid.material.transparent = true;
grid.material.opacity = 0.24;
scene.add(grid);
const materialRecords = [];
const dimColor = new THREE.Color(0x14212b);
function makeMaterial(region, color, options = {}) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.78,
metalness: options.metalness ?? 0.02,
flatShading: options.flatShading ?? true,
transparent: true,
opacity: 1
});
materialRecords.push({
material,
region,
baseColor: material.color.clone(),
targetColor: material.color.clone(),
targetEmissive: new THREE.Color(0x000000),
targetIntensity: 0,
targetOpacity: 1
});
return material;
}
function addMesh(
geometry,
material,
position = [0, 0, 0],
scale = [1, 1, 1],
rotation = [0, 0, 0]
) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.scale.set(...scale);
mesh.rotation.set(...rotation);
mesh.castShadow = true;
mesh.receiveShadow = true;
anatomy.add(mesh);
return mesh;
}
function makeTube(points, radius, material, segments = 36) {
const curve = new THREE.CatmullRomCurve3(
points.map((point) => new THREE.Vector3(...point)),
false,
"centripetal",
0.5
);
const geometry = new THREE.TubeGeometry(
curve,
segments,
radius,
6,
false
);
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
anatomy.add(mesh);
return { curve, mesh };
}
const mouthMaterial = makeMaterial("mouth", 0xd97891);
const toothMaterial = makeMaterial("mouth", 0xf2eadc, {
roughness: 0.62
});
const salivaryMaterial = makeMaterial("salivary", 0xe1b45d);
const esophagusMaterial = makeMaterial("esophagus", 0xc77f89);
const stomachMaterial = makeMaterial("stomach", 0xc86d73);
const liverMaterial = makeMaterial("liver", 0x934d51);
const gallbladderMaterial = makeMaterial("gallbladder", 0x7d9e64);
const pancreasMaterial = makeMaterial("pancreas", 0xd29a50);
const smallMaterial = makeMaterial("small", 0xd78578);
const colonMaterial = makeMaterial("colon", 0xae7758);
const rectumMaterial = makeMaterial("rectum", 0x986650);
// Oral cavity, tongue, teeth, and salivary glands.
addMesh(
new THREE.IcosahedronGeometry(0.29, 1),
mouthMaterial,
[0, 4.18, 0.19],
[1, 0.82, 0.72]
);
addMesh(
new THREE.IcosahedronGeometry(0.18, 1),
mouthMaterial,
[0, 4.02, 0.38],
[1.4, 0.42, 0.68],
[0.08, 0, 0]
);
for (let i = -2; i <= 2; i++) {
addMesh(
new THREE.BoxGeometry(0.065, 0.065, 0.075),
toothMaterial,
[i * 0.09, 4.23, 0.40],
[1, 1, 1],
[0, 0, i * 0.035]
);
}
addMesh(
new THREE.IcosahedronGeometry(0.11, 1),
salivaryMaterial,
[-0.31, 4.20, -0.02],
[0.75, 1.25, 0.8]
);
addMesh(
new THREE.IcosahedronGeometry(0.11, 1),
salivaryMaterial,
[0.31, 4.20, -0.02],
[0.75, 1.25, 0.8]
);
// Pharynx and esophagus.
addMesh(
new THREE.IcosahedronGeometry(0.16, 1),
esophagusMaterial,
[0, 3.80, 0.12],
[0.9, 1.1, 0.9]
);
const esophagusTube = makeTube(
[
[0, 3.88, 0.14],
[0, 3.38, 0.12],
[0, 2.82, 0.08],
[0.08, 2.30, 0.08],
[0.20, 2.03, 0.12]
],
0.105,
esophagusMaterial,
30
);
// Liver, gallbladder, and pancreas.
addMesh(
new THREE.IcosahedronGeometry(1, 2),
liverMaterial,
[-0.92, 2.46, -0.16],
[0.91, 0.61, 0.53],
[0.05, -0.18, -0.13]
);
addMesh(
new THREE.IcosahedronGeometry(1, 1),
liverMaterial,
[-0.20, 2.28, -0.19],
[0.63, 0.43, 0.43],
[0.02, 0.1, 0.1]
);
addMesh(
new THREE.IcosahedronGeometry(1, 1),
gallbladderMaterial,
[-0.46, 1.98, 0.30],
[0.15, 0.23, 0.15],
[0.12, 0, -0.18]
);
addMesh(
new THREE.IcosahedronGeometry(1, 2),
pancreasMaterial,
[0.30, 1.13, -0.43],
[0.91, 0.18, 0.24],
[0.02, -0.11, -0.10]
);
for (let i = 0; i < 5; i++) {
addMesh(
new THREE.IcosahedronGeometry(0.18, 1),
pancreasMaterial,
[-0.35 + i * 0.27, 1.14 - i * 0.025, -0.39],
[1.1, 0.8, 0.8]
);
}
// Stomach.
addMesh(
new THREE.IcosahedronGeometry(1, 2),
stomachMaterial,
[0.57, 1.62, 0.16],
[0.77, 0.95, 0.57],
[0.02, -0.12, -0.30]
);
// Coiled small intestine.
const smallTube = makeTube(
[
[1.30, 0.91, 0.42],
[1.00, 0.52, 0.54],
[0.10, 0.66, 0.58],
[-0.55, 0.42, 0.58],
[0.45, 0.12, 0.62],
[-0.52, -0.18, 0.60],
[0.50, -0.48, 0.55],
[-0.50, -0.78, 0.50],
[0.45, -1.05, 0.40],
[-0.25, -1.35, 0.26],
[1.48, -1.45, -0.02]
],
0.15,
smallMaterial,
110
);
// Framed large intestine.
const colonTube = makeTube(
[
[1.48, -1.45, -0.02],
[1.55, -0.90, -0.06],
[1.50, -0.20, -0.08],
[1.45, 0.55, -0.06],
[1.25, 1.18, -0.05],
[0.55, 1.35, -0.05],
[-0.45, 1.32, -0.06],
[-1.25, 1.12, -0.05],
[-1.50, 0.35, -0.05],
[-1.50, -0.65, -0.05],
[-1.25, -1.55, -0.03],
[-0.65, -2.00, 0.00],
[0.00, -2.20, 0.00]
],
0.21,
colonMaterial,
86
);
// Faceted haustral bulges.
for (let i = 0; i < 12; i++) {
const t = 0.035 + (i / 12) * 0.94;
const point = colonTube.curve.getPointAt(t);
addMesh(
new THREE.IcosahedronGeometry(0.235, 1),
colonMaterial,
point.toArray(),
[1, 0.94, 0.94]
);
}
const rectumTube = makeTube(
[
[0, -2.13, 0],
[0, -2.36, 0.01],
[0, -2.62, 0.02]
],
0.16,
rectumMaterial,
18
);
addMesh(
new THREE.TorusGeometry(0.16, 0.042, 5, 10),
rectumMaterial,
[0, -2.62, 0.02],
[1, 1, 1],
[Math.PI / 2, 0, 0]
);
// Additional schematic paths used by the transport cues.
const oralCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(0, 4.28, 0.25),
new THREE.Vector3(0, 4.04, 0.19),
new THREE.Vector3(0, 3.84, 0.14)
],
false,
"centripetal"
);
const stomachTransitCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(0.18, 2.05, 0.14),
new THREE.Vector3(0.43, 1.91, 0.29),
new THREE.Vector3(0.77, 1.65, 0.37),
new THREE.Vector3(0.73, 1.35, 0.35),
new THREE.Vector3(1.15, 1.17, 0.33),
new THREE.Vector3(1.30, 0.91, 0.42)
],
false,
"centripetal"
);
// Deterministic random generator for reproducible marker positions.
function mulberry32(seed) {
return function random() {
let value = (seed += 0x6d2b79f5);
value = Math.imul(value ^ (value >>> 15), value | 1);
value ^= value + Math.imul(value ^ (value >>> 7), value | 61);
return ((value ^ (value >>> 14)) >>> 0) / 4294967296;
};
}
function sampleCurveSurface(curve, count, radius, random) {
const points = [];
const reference = new THREE.Vector3(0, 1, 0);
const alternateReference = new THREE.Vector3(0, 0, 1);
for (let i = 0; i < count; i++) {
const t = (i + 0.35 + random() * 0.3) / count;
const point = curve.getPointAt(Math.min(t, 0.995));
const tangent = curve.getTangentAt(Math.min(t, 0.995)).normalize();
const ref =
Math.abs(tangent.dot(reference)) > 0.9
? alternateReference
: reference;
const side = new THREE.Vector3()
.crossVectors(tangent, ref)
.normalize();
const binormal = new THREE.Vector3()
.crossVectors(tangent, side)
.normalize();
const angle = random() * Math.PI * 2;
const offset = side
.multiplyScalar(Math.cos(angle))
.addScaledVector(binormal, Math.sin(angle))
.multiplyScalar(radius + 0.025);
points.push(point.clone().add(offset));
}
return points;
}
function sampleEllipsoid(center, scale, count, random) {
const points = [];
for (let i = 0; i < count; i++) {
const z = random() * 2 - 1;
const angle = random() * Math.PI * 2;
const radial = Math.sqrt(Math.max(0, 1 - z * z));
const direction = new THREE.Vector3(
radial * Math.cos(angle),
z,
radial * Math.sin(angle)
);
points.push(
new THREE.Vector3(
center[0] + direction.x * scale[0],
center[1] + direction.y * scale[1],
center[2] + direction.z * scale[2]
)
);
}
return points;
}
function createDotMesh(positions, color, size) {
const geometry = new THREE.IcosahedronGeometry(size, 0);
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.9,
toneMapped: false
});
const mesh = new THREE.InstancedMesh(
geometry,
material,
positions.length
);
const dummy = new THREE.Object3D();
const random = mulberry32(913);
positions.forEach((position, index) => {
dummy.position.copy(position);
dummy.rotation.set(
random() * Math.PI,
random() * Math.PI,
random() * Math.PI
);
dummy.scale.setScalar(0.8 + random() * 0.5);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.frustumCulled = false;
mesh.renderOrder = 3;
return mesh;
}
const markerRoot = new THREE.Group();
scene.add(markerRoot);
const breakdownRandom = mulberry32(401);
const breakdownPositions = [
...sampleCurveSurface(
smallTube.curve,
22,
0.16,
breakdownRandom
),
...sampleCurveSurface(
colonTube.curve,
15,
0.22,
breakdownRandom
),
...sampleEllipsoid(
[0.57, 1.62, 0.16],
[0.78, 0.95, 0.58],
16,
breakdownRandom
),
...sampleEllipsoid(
[0, 4.18, 0.19],
[0.28, 0.23, 0.20],
7,
breakdownRandom
),
...sampleEllipsoid(
[-0.92, 2.46, -0.16],
[0.92, 0.61, 0.54],
11,
breakdownRandom
),
...sampleEllipsoid(
[-0.46, 1.98, 0.30],
[0.16, 0.24, 0.16],
5,
breakdownRandom
),
...sampleEllipsoid(
[0.30, 1.13, -0.43],
[0.92, 0.18, 0.24],
9,
breakdownRandom
)
];
const absorptionRandom = mulberry32(802);
const absorptionPositions = [
...sampleCurveSurface(
smallTube.curve,
48,
0.16,
absorptionRandom
),
...sampleCurveSurface(
colonTube.curve,
27,
0.22,
absorptionRandom
),
...sampleEllipsoid(
[0.57, 1.62, 0.16],
[0.78, 0.95, 0.58],
8,
absorptionRandom
)
];
const breakdownDots = createDotMesh(
breakdownPositions,
0xffa56b,
0.037
);
const absorptionDots = createDotMesh(
absorptionPositions,
0xb8ef67,
0.034
);
markerRoot.add(breakdownDots, absorptionDots);
// Transport arrows remain on the camera-facing surface of each route.
const transportRoot = new THREE.Group();
scene.add(transportRoot);
const arrowGeometry = new THREE.ConeGeometry(0.075, 0.22, 5);
const arrowMaterial = new THREE.MeshBasicMaterial({
color: 0x73f4ff,
toneMapped: false
});
const transportPaths = [
{
curve: oralCurve,
radius: 0.16,
speed: 0.13,
count: 1,
offset: 0.12
},
{
curve: esophagusTube.curve,
radius: 0.115,
speed: 0.09,
count: 2,
offset: 0.08
},
{
curve: stomachTransitCurve,
radius: 0.48,
speed: 0.075,
count: 2,
offset: 0.14
},
{
curve: smallTube.curve,
radius: 0.16,
speed: 0.055,
count: 3,
offset: 0.04
},
{
curve: colonTube.curve,
radius: 0.22,
speed: 0.043,
count: 3,
offset: 0.18
}
];
const transportArrows = [];
transportPaths.forEach((path) => {
for (let i = 0; i < path.count; i++) {
const arrow = new THREE.Mesh(arrowGeometry, arrowMaterial);
arrow.renderOrder = 5;
transportRoot.add(arrow);
transportArrows.push({
arrow,
path,
offset:
path.offset +
(i / Math.max(1, path.count)) / Math.max(0.1, path.speed)
});
}
});
const modeData = {
transport: {
accent: "#56d9e8",
number: "01",
title: "Transport is continuous",
copy:
"The highlighted route follows the connected lumen. Swallowing, " +
"peristalsis, segmentation, gastric emptying and colonic transit " +
"distribute movement along several regions rather than one location.",
strip: [
"Mouth",
"Esophagus",
"Stomach",
"Small intestine",
"Colon"
],
sites: [
[
"Mouth and pharynx",
"Swallowing begins movement of the bolus."
],
[
"Esophagus",
"Coordinated peristalsis carries it downward."
],
[
"Stomach",
"Churning mixes contents; gastric emptying moves chyme onward."
],
[
"Small intestine",
"Segmentation and peristalsis continually redistribute contents."
],
[
"Colon",
"Haustral and propulsive motility move residual material."
]
],
note:
"Arrows indicate direction only; actual speed, pressure and " +
"contractions vary along the tract."
},
breakdown: {
accent: "#ff9864",
number: "02",
title: "Breakdown is distributed",
copy:
"Digestive work unfolds at multiple sites. Chewing and saliva begin " +
"in the mouth, the stomach starts chemical digestion, bile and " +
"pancreatic enzymes act mainly in the small intestine, and microbes " +
"ferment some remaining fiber in the colon.",
strip: [
"Mouth",
"Stomach",
"Small intestine",
"Colon"
],
sites: [
[
"Mouth and salivary glands",
"Chewing and salivary amylase begin mechanical and starch digestion."
],
[
"Stomach",
"Acid and enzymes denature proteins and begin their digestion."
],
[
"Liver, gallbladder and pancreas",
"These accessory organs supply bile and digestive enzymes downstream."
],
[
"Small intestine",
"Most chemical digestion occurs here with pancreatic enzymes and bile."
],
[
"Colon",
"Microbial fermentation can break down some remaining fiber."
]
],
note:
"Liver, gallbladder and pancreas contribute secretions to digestion; " +
"they are not shown as isolated digestion sites."
},
absorption: {
accent: "#b4ed69",
number: "03",
title: "Absorption spans broad surfaces",
copy:
"Absorption depends on extensive epithelial surface area. Most " +
"nutrient uptake and much water/electrolyte absorption occur across " +
"the small intestine's villi and microvilli; the colon recovers " +
"remaining water and electrolytes, while stomach absorption is limited.",
strip: [
"Stomach: limited",
"Small intestine: primary",
"Colon: remaining water"
],
sites: [
[
"Stomach — limited",
"Small amounts of water, alcohol and some drugs may be absorbed."
],
[
"Small intestine — primary",
"Most nutrients plus much water and electrolytes cross a folded lining."
],
[
"Colon — additional",
"Recovers remaining water and electrolytes; some microbial products may also be absorbed."
]
],
note:
"Green markers sample multiple points along the intestinal surfaces; " +
"they are not meant to represent individual absorption pores."
}
};
const modeRegions = {
transport: new Set([
"mouth",
"esophagus",
"stomach",
"small",
"colon"
]),
breakdown: new Set([
"mouth",
"salivary",
"stomach",
"liver",
"gallbladder",
"pancreas",
"small",
"colon"
]),
absorption: new Set(["stomach", "small", "colon"])
};
let currentMode = "transport";
function updateHighlightTargets(mode) {
const accent = new THREE.Color(modeData[mode].accent);
const selectedRegions = modeRegions[mode];
materialRecords.forEach((record) => {
const selected = selectedRegions.has(record.region);
const target = record.baseColor.clone();
if (selected) {
target.lerp(accent, 0.25);
} else {
target.lerp(dimColor, 0.64);
}
record.targetColor.copy(target);
record.targetEmissive.copy(selected ? accent : new THREE.Color(0));
record.targetIntensity = selected ? 0.23 : 0;
record.targetOpacity = selected ? 0.97 : 0.3;
record.material.depthWrite = selected;
});
breakdownDots.visible = mode === "breakdown";
absorptionDots.visible = mode === "absorption";
transportRoot.visible = mode === "transport";
}
const labelSpecs = [
{
text: "Mouth + salivary glands",
position: [-0.02, 4.37, 0.22],
offset: [-95, -18],
regions: ["mouth", "salivary"]
},
{
text: "Esophagus",
position: [0, 3.17, 0.1],
offset: [-68, 0],
regions: ["esophagus"]
},
{
text: "Liver + gallbladder",
position: [-1.02, 2.63, -0.06],
offset: [-78, -22],
regions: ["liver", "gallbladder"]
},
{
text: "Stomach",
position: [0.75, 1.79, 0.37],
offset: [67, -16],
regions: ["stomach"]
},
{
text: "Pancreas",
position: [0.32, 1.04, -0.31],
offset: [67, 19],
regions: ["pancreas"]
},
{
text: "Small intestine",
position: [-0.12, -0.50, 0.55],
offset: [-76, 14],
regions: ["small"]
},
{
text: "Large intestine",
position: [-1.49, -0.08, -0.02],
offset: [-78, 0],
regions: ["colon", "rectum"]
}
];
const labels = labelSpecs.map((spec) => {
const element = document.createElement("div");
element.className = "anatomy-label";
element.textContent = spec.text;
labelsLayer.appendChild(element);
return {
...spec,
element,
worldPosition: new THREE.Vector3(...spec.position)
};
});
function updateLabelEmphasis(mode) {
const selectedRegions = modeRegions[mode];
labels.forEach((label) => {
const relevant = label.regions.some((region) =>
selectedRegions.has(region)
);
label.element.classList.toggle("is-muted", !relevant);
});
}
function setMode(mode) {
currentMode = mode;
const data = modeData[mode];
document.documentElement.style.setProperty("--accent", data.accent);
document.getElementById("infoEyebrow").textContent =
`Selected process · ${data.number}`;
document.getElementById("infoTitle").textContent = data.title;
document.getElementById("infoCopy").textContent = data.copy;
document.getElementById("infoNote").textContent = data.note;
document.getElementById("processStrip").innerHTML = data.strip
.map((label) => `<span>${label}</span>`)
.join("<b aria-hidden=\"true\">→</b>");
document.getElementById("siteList").innerHTML = data.sites
.map(
([title, detail]) => `
<li>
<span class="site-dot" aria-hidden="true"></span>
<div>
<strong>${title}</strong>
<small>${detail}</small>
</div>
</li>
`
)
.join("");
modeButtons.forEach((button) => {
button.setAttribute(
"aria-pressed",
String(button.dataset.mode === mode)
);
});
updateHighlightTargets(mode);
updateLabelEmphasis(mode);
}
modeButtons.forEach((button) => {
button.addEventListener("click", () => {
setMode(button.dataset.mode);
});
});
// Custom camera controls implemented directly with pointer events.
const cameraState = {
theta: 0.36,
phi: 1.17,
radius: 10.8,
target: new THREE.Vector3(0.18, 0.62, 0)
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function resetView() {
cameraState.theta = 0.36;
cameraState.phi = 1.17;
cameraState.radius = 10.8;
cameraState.target.set(0.18, 0.62, 0);
updateCamera();
}
document.getElementById("resetView").addEventListener("click", resetView);
canvas.addEventListener("dblclick", resetView);
const pointers = new Map();
let dragging = false;
let panMode = false;
let lastX = 0;
let lastY = 0;
let pinchDistance = 0;
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
canvas.addEventListener("pointerdown", (event) => {
event.preventDefault();
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
dragging = true;
panMode = event.shiftKey || event.button === 2;
lastX = event.clientX;
lastY = event.clientY;
} else if (pointers.size === 2) {
dragging = false;
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (pinchDistance / distance),
6.7,
16
);
updateCamera();
}
pinchDistance = distance;
return;
}
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (panMode) {
const scale = cameraState.radius * 0.0015;
const right = new THREE.Vector3(
Math.cos(cameraState.theta),
0,
-Math.sin(cameraState.theta)
);
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.y += dy * scale;
cameraState.target.x = THREE.MathUtils.clamp(
cameraState.target.x,
-1.6,
1.6
);
cameraState.target.y = THREE.MathUtils.clamp(
cameraState.target.y,
-1.0,
2.2
);
} else {
cameraState.theta -= dx * 0.0075;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.0075,
0.42,
2.58
);
}
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) {
pinchDistance = 0;
}
dragging = pointers.size === 1;
if (dragging) {
const remaining = [...pointers.values()][0];
lastX = remaining.x;
lastY = remaining.y;
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
6.7,
16
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraState.theta -= 0.09;
break;
case "ArrowRight":
cameraState.theta += 0.09;
break;
case "ArrowUp":
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - 0.07,
0.42,
2.58
);
break;
case "ArrowDown":
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + 0.07,
0.42,
2.58
);
break;
case "+":
case "=":
cameraState.radius = Math.max(6.7, cameraState.radius - 0.4);
break;
case "-":
case "_":
cameraState.radius = Math.min(16, cameraState.radius + 0.4);
break;
case "0":
case "r":
case "R":
resetView();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
let labelsVisible = true;
document.getElementById("toggleLabels").addEventListener("click", () => {
labelsVisible = !labelsVisible;
labelsLayer.classList.toggle("hidden", !labelsVisible);
const button = document.getElementById("toggleLabels");
button.setAttribute("aria-pressed", String(labelsVisible));
document.getElementById("labelState").textContent = labelsVisible
? "Labels on"
: "Labels off";
});
const projected = new THREE.Vector3();
function updateLabels() {
const width = canvas.clientWidth;
const height = canvas.clientHeight;
labels.forEach((label) => {
projected.copy(label.worldPosition).project(camera);
const onScreen =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
if (!onScreen || !labelsVisible) {
label.element.style.display = "none";
return;
}
const x = (projected.x * 0.5 + 0.5) * width + label.offset[0];
const y = (-projected.y * 0.5 + 0.5) * height + label.offset[1];
label.element.style.display = "block";
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
});
}
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
}
window.addEventListener("resize", onResize);
const clock = new THREE.Clock();
const up = new THREE.Vector3(0, 1, 0);
function updateTransportArrows(elapsed) {
transportArrows.forEach(({ arrow, path, offset }) => {
const t =
(offset + (reducedMotion ? 0 : elapsed * path.speed)) % 1;
const point = path.curve.getPointAt(t);
const tangent = path.curve.getTangentAt(t).normalize();
// Project the camera direction into the plane perpendicular to
// the path so arrows stay on the visible surface.
const towardCamera = camera.position.clone().sub(point);
towardCamera.addScaledVector(
tangent,
-towardCamera.dot(tangent)
);
if (towardCamera.lengthSq() < 0.00001) {
towardCamera.set(0, 0, 1);
} else {
towardCamera.normalize();
}
arrow.position
.copy(point)
.addScaledVector(towardCamera, path.radius + 0.055);
arrow.quaternion.setFromUnitVectors(up, tangent);
});
}
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const transition = reducedMotion ? 1 : 0.11;
materialRecords.forEach((record) => {
record.material.color.lerp(record.targetColor, transition);
record.material.emissive.lerp(record.targetEmissive, transition);
record.material.emissiveIntensity = THREE.MathUtils.lerp(
record.material.emissiveIntensity,
record.targetIntensity,
transition
);
record.material.opacity = THREE.MathUtils.lerp(
record.material.opacity,
record.targetOpacity,
transition
);
});
if (currentMode === "breakdown") {
breakdownDots.material.opacity = reducedMotion
? 0.88
: 0.72 + Math.sin(elapsed * 2.4) * 0.15;
}
if (currentMode === "absorption") {
absorptionDots.material.opacity = reducedMotion
? 0.9
: 0.7 + Math.sin(elapsed * 2.1 + 1.2) * 0.16;
}
updateTransportArrows(elapsed);
renderer.render(scene, camera);
updateLabels();
}
updateCamera();
setMode("transport");
onResize();
animate();
</script>
</body>
</html>
```