Prompt specification
Build or customize the Three.js 3D scene "Meal-to-absorption educational scene" 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: Meal-to-absorption educational scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/meal-to-absorption-educational-scene-x0975
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: meal-to-absorption educational scene. Compose a small meal beside a digestive cutaway and enlarged intestinal surface; separate physical movement, chemical breakdown, and nutrient transfer as distinct labeled processes. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (meal-to-absorption-educational-scene-x0975):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
<meta name="theme-color" content="#f4efe6">
<title>From Bite to Blood — Voxel Digestion Study</title>
<style>
:root {
--ink: #27313b;
--muted: #66717b;
--paper: #f4efe6;
--panel: rgba(255, 253, 248, 0.88);
--line: rgba(39, 49, 59, 0.15);
--movement: #f3a62f;
--breakdown: #e85c91;
--transfer: #18a99a;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button { font: inherit; }
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
canvas:active { cursor: grabbing; }
.ui {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.masthead {
position: absolute;
top: 22px;
left: 24px;
display: flex;
align-items: flex-start;
gap: 15px;
max-width: 520px;
}
.mark {
width: 44px;
height: 44px;
flex: 0 0 auto;
display: grid;
place-items: center;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255,255,255,.62);
box-shadow: 0 10px 30px rgba(46,52,55,.07);
backdrop-filter: blur(12px);
}
.mark svg { width: 25px; height: 25px; }
.eyebrow {
margin: 1px 0 5px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: .18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(21px, 2.4vw, 34px);
line-height: .98;
letter-spacing: -.045em;
font-weight: 850;
}
h1 span {
display: block;
margin-top: 5px;
color: #7b837f;
font-size: .43em;
letter-spacing: .12em;
text-transform: uppercase;
font-weight: 800;
}
.top-controls {
position: absolute;
top: 22px;
right: 24px;
display: flex;
gap: 8px;
pointer-events: auto;
}
.control {
min-height: 40px;
padding: 0 14px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255,255,255,.72);
color: var(--ink);
box-shadow: 0 9px 24px rgba(46,52,55,.06);
backdrop-filter: blur(12px);
cursor: pointer;
font-size: 12px;
font-weight: 750;
transition: transform .18s ease, background .18s ease, border-color .18s ease;
}
.control:hover {
transform: translateY(-2px);
background: #fff;
border-color: rgba(39,49,59,.28);
}
.control.primary {
background: var(--ink);
color: #fff;
border-color: var(--ink);
}
.info-card {
position: absolute;
left: 24px;
bottom: 116px;
width: min(315px, calc(100vw - 48px));
padding: 17px 18px 16px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 16px 45px rgba(49,54,55,.09);
backdrop-filter: blur(16px);
}
.info-kicker {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
font-size: 10px;
font-weight: 850;
letter-spacing: .13em;
text-transform: uppercase;
}
.info-dot {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--movement);
}
.info-card h2 {
margin: 0 0 6px;
font-size: 17px;
letter-spacing: -.025em;
}
.info-card p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.process-rail {
position: absolute;
left: 50%;
bottom: 18px;
width: min(900px, calc(100vw - 32px));
transform: translateX(-50%);
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
pointer-events: auto;
}
.process {
position: relative;
min-height: 82px;
padding: 13px 14px 12px 48px;
text-align: left;
border: 1px solid var(--line);
border-radius: 15px;
background: rgba(255,253,248,.9);
color: var(--ink);
box-shadow: 0 13px 35px rgba(49,54,55,.08);
backdrop-filter: blur(15px);
cursor: pointer;
overflow: hidden;
transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}
.process:hover {
transform: translateY(-3px);
box-shadow: 0 18px 42px rgba(49,54,55,.12);
}
.process.active {
border-color: var(--process);
box-shadow: inset 0 0 0 1px var(--process), 0 15px 38px rgba(49,54,55,.1);
}
.process::after {
content: "";
position: absolute;
inset: auto 0 0;
height: 3px;
background: var(--process);
transform: scaleX(0);
transform-origin: left;
transition: transform .25s ease;
}
.process.active::after { transform: scaleX(1); }
.process-number {
position: absolute;
left: 14px;
top: 14px;
width: 25px;
height: 25px;
display: grid;
place-items: center;
border-radius: 7px;
background: color-mix(in srgb, var(--process) 17%, white);
color: color-mix(in srgb, var(--process) 80%, #26313a);
font-size: 10px;
font-weight: 900;
}
.process-title {
display: block;
margin-bottom: 4px;
font-size: 12px;
font-weight: 850;
letter-spacing: .02em;
}
.process-desc {
display: block;
color: var(--muted);
font-size: 10.5px;
line-height: 1.35;
}
.hint {
position: absolute;
right: 24px;
bottom: 118px;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255,255,255,.56);
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: .08em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
pointer-events: none;
overflow: hidden;
}
.scene-label {
position: absolute;
min-width: 124px;
max-width: 210px;
padding: 9px 11px 9px 12px;
border: 1px solid rgba(39,49,59,.14);
border-left: 4px solid var(--label-color, #75818a);
border-radius: 10px;
background: rgba(255,253,248,.9);
box-shadow: 0 10px 28px rgba(40,47,50,.11);
backdrop-filter: blur(10px);
transform: translate(-50%, -100%);
transition: opacity .2s ease, box-shadow .2s ease, border-color .2s ease;
will-change: left, top;
}
.scene-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 18px;
background: linear-gradient(var(--label-color, #75818a), transparent);
opacity: .65;
}
.scene-label strong {
display: block;
color: var(--label-color, #35424a);
font-size: 9px;
letter-spacing: .12em;
text-transform: uppercase;
}
.scene-label span {
display: block;
margin-top: 3px;
color: var(--ink);
font-size: 10px;
font-weight: 700;
line-height: 1.3;
}
.scene-label.active {
border-color: var(--label-color);
box-shadow: 0 12px 34px rgba(40,47,50,.16), inset 0 0 0 1px var(--label-color);
}
.scene-label.hidden { opacity: 0; }
.loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: var(--paper);
color: var(--muted);
font-size: 12px;
font-weight: 750;
letter-spacing: .1em;
text-transform: uppercase;
transition: opacity .4s ease;
}
.loading.done { opacity: 0; pointer-events: none; }
@media (max-width: 760px) {
.masthead { top: 15px; left: 15px; }
.mark { width: 38px; height: 38px; border-radius: 11px; }
.top-controls { top: 15px; right: 15px; }
.control { min-height: 38px; padding: 0 10px; font-size: 0; }
.control::first-letter { font-size: 15px; }
.control .desktop { display: none; }
.info-card, .hint { display: none; }
.process-rail { bottom: 12px; width: calc(100vw - 20px); gap: 5px; }
.process {
min-height: 67px;
padding: 10px 8px 8px 37px;
border-radius: 12px;
}
.process-number { left: 8px; top: 10px; width: 22px; height: 22px; }
.process-title { font-size: 9.5px; line-height: 1.15; }
.process-desc { display: none; }
.scene-label { min-width: 104px; padding: 7px 8px; }
.scene-label strong { font-size: 7.5px; }
.scene-label span { font-size: 8.5px; }
.scene-label.optional { display: none; }
}
@media (max-width: 480px) {
h1 { font-size: 20px; }
h1 span { font-size: 8px; }
.eyebrow { font-size: 8px; }
.mark { display: none; }
.scene-label { max-width: 145px; }
}
</style>
</head>
<body>
<div id="stage" aria-label="Interactive voxel illustration of digestion and nutrient absorption"></div>
<div id="labels" aria-hidden="true">
<div class="scene-label optional" id="label-meal" style="--label-color:#7b8790">
<strong>Starting point</strong>
<span>Carbs · protein · fats</span>
</div>
<div class="scene-label" id="label-movement" style="--label-color:#f3a62f">
<strong>01 · Physical movement</strong>
<span>Swallow, churn, advance</span>
</div>
<div class="scene-label" id="label-breakdown" style="--label-color:#e85c91">
<strong>02 · Chemical breakdown</strong>
<span>Acid and enzymes make smaller units</span>
</div>
<div class="scene-label" id="label-transfer" style="--label-color:#18a99a">
<strong>03 · Nutrient transfer</strong>
<span>Across villi into blood</span>
</div>
</div>
<main class="ui">
<header class="masthead">
<div class="mark" aria-hidden="true">
<svg viewBox="0 0 32 32" fill="none">
<path d="M5 9h13v13H5z" fill="#f3a62f"/>
<path d="M14 14h6v8h8v6h-6v-5h-8z" fill="#18a99a"/>
<path d="M8 5h5v4H8z" fill="#e85c91"/>
</svg>
</div>
<div>
<p class="eyebrow">Interactive voxel study</p>
<h1>From bite to blood<span>Digestion & absorption</span></h1>
</div>
</header>
<div class="top-controls">
<button class="control" id="pause" title="Pause or resume animation">
<span aria-hidden="true">Ⅱ</span> <span class="desktop" id="pause-text">Pause motion</span>
</button>
<button class="control primary" id="reset" title="Reset the camera view">
<span aria-hidden="true">↺</span> <span class="desktop">Reset view</span>
</button>
</div>
<aside class="info-card" aria-live="polite">
<div class="info-kicker"><span class="info-dot" id="info-dot"></span><span id="info-kicker">The full journey</span></div>
<h2 id="info-title">One meal. Three coordinated processes.</h2>
<p id="info-body">Follow food as it is physically moved, chemically reduced to absorbable molecules, and transferred across the intestinal wall into circulation.</p>
</aside>
<nav class="process-rail" aria-label="Digestive process focus controls">
<button class="process" data-process="0" style="--process:#f3a62f">
<span class="process-number">01</span>
<span class="process-title">PHYSICAL MOVEMENT</span>
<span class="process-desc">Swallowing, stomach churning, peristalsis</span>
</button>
<button class="process" data-process="1" style="--process:#e85c91">
<span class="process-number">02</span>
<span class="process-title">CHEMICAL BREAKDOWN</span>
<span class="process-desc">Acid and enzymes reduce food molecules</span>
</button>
<button class="process" data-process="2" style="--process:#18a99a">
<span class="process-number">03</span>
<span class="process-title">NUTRIENT TRANSFER</span>
<span class="process-desc">Villi move nutrients into blood</span>
</button>
</nav>
<div class="hint">Drag to orbit · Scroll to zoom · Arrow keys to pan</div>
</main>
<div class="loading" id="loading">Building the voxel digestive system…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf4efe6);
scene.fog = new THREE.Fog(0xf4efe6, 26, 48);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute("aria-label", "Voxel scene. Drag to orbit and use the mouse wheel to zoom.");
stage.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(38, window.innerWidth / window.innerHeight, 0.1, 100);
const hemi = new THREE.HemisphereLight(0xfff9ed, 0x9aa8a5, 2.15);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xfff2d9, 3.6);
keyLight.position.set(-8, 15, 11);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -16;
keyLight.shadow.camera.right = 16;
keyLight.shadow.camera.top = 14;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 45;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9e5ef, 1.15);
fillLight.position.set(10, 7, -9);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xffd4b7, 1.1);
rimLight.position.set(0, 8, -12);
scene.add(rimLight);
const world = new THREE.Group();
scene.add(world);
const edgeMaterial = new THREE.LineBasicMaterial({ color: 0x465158, transparent: true, opacity: 0.24 });
const materialCache = new Map();
function material(color, options = {}) {
const key = String(color) + JSON.stringify(options);
if (materialCache.has(key)) return materialCache.get(key);
const mat = new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.78,
metalness: options.metalness ?? 0.02,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0,
side: options.side ?? THREE.FrontSide
});
materialCache.set(key, mat);
return mat;
}
function box(parent, size, position, color, options = {}) {
const geometry = new THREE.BoxGeometry(size[0], size[1], size[2]);
const mesh = new THREE.Mesh(geometry, options.material || material(color, options));
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
if (options.rotation) mesh.rotation.set(...options.rotation);
if (options.edge) {
const lines = new THREE.LineSegments(new THREE.EdgesGeometry(geometry), edgeMaterial);
lines.renderOrder = 2;
mesh.add(lines);
}
parent.add(mesh);
return mesh;
}
function chain(parent, points, cubeSize, color, options = {}) {
const group = new THREE.Group();
parent.add(group);
for (let i = 0; i < points.length - 1; i++) {
const a = new THREE.Vector3(...points[i]);
const b = new THREE.Vector3(...points[i + 1]);
const count = Math.max(1, Math.ceil(a.distanceTo(b) / (cubeSize * 0.82)));
for (let j = 0; j < count; j++) {
const p = a.clone().lerp(b, j / count);
box(group, [cubeSize, cubeSize, cubeSize], p.toArray(), color, options);
}
}
const last = points[points.length - 1];
box(group, [cubeSize, cubeSize, cubeSize], last, color, options);
return group;
}
function arrow(parent, from, to, color, options = {}) {
const a = new THREE.Vector3(...from);
const b = new THREE.Vector3(...to);
const direction = b.clone().sub(a);
const length = direction.length();
const headLength = options.headLength ?? Math.min(0.42, length * 0.28);
const shaftLength = Math.max(0.05, length - headLength * 0.72);
const group = new THREE.Group();
parent.add(group);
const shaft = box(group, [options.width ?? 0.09, shaftLength, options.width ?? 0.09], [0,0,0], color, {
emissive: color,
emissiveIntensity: options.glow ?? 0.15
});
shaft.quaternion.setFromUnitVectors(new THREE.Vector3(0,1,0), direction.clone().normalize());
const head = new THREE.Mesh(
new THREE.ConeGeometry(options.headRadius ?? 0.2, headLength, 4),
material(color, { emissive: color, emissiveIntensity: options.glow ?? 0.15 })
);
head.position.copy(b.clone().addScaledVector(direction.clone().normalize(), -headLength * 0.42));
head.quaternion.setFromUnitVectors(new THREE.Vector3(0,1,0), direction.clone().normalize());
head.castShadow = true;
group.add(head);
return group;
}
function voxelCurve(parent, points, cubeSize, color, options = {}) {
const curve = new THREE.CatmullRomCurve3(points.map(p => new THREE.Vector3(...p)));
const group = new THREE.Group();
parent.add(group);
const count = options.count ?? 24;
for (let i = 0; i < count; i++) {
const p = curve.getPoint(i / (count - 1));
box(group, [cubeSize, cubeSize, cubeSize], p.toArray(), color, options);
}
return { group, curve };
}
function octagonalRing(parent, center, radius, color, count = 16) {
const group = new THREE.Group();
parent.add(group);
for (let i = 0; i < count; i++) {
const angle = i / count * Math.PI * 2;
const x = center[0] + Math.cos(angle) * radius;
const y = center[1] + Math.sin(angle) * radius;
const cube = box(group, [0.13, 0.13, 0.13], [x, y, center[2]], color, {
emissive: color,
emissiveIntensity: 0.18
});
cube.rotation.z = angle;
}
return group;
}
// Ground and visual scale grid.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(44, 34),
material(0xf4efe6, { roughness: 1, metalness: 0 })
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.11;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(36, 36, 0xb8c1bc, 0xd5d9d3);
grid.position.y = -0.095;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
// Shared visual groups.
const physicalGroup = new THREE.Group();
const chemicalGroup = new THREE.Group();
const transferGroup = new THREE.Group();
world.add(physicalGroup, chemicalGroup, transferGroup);
// ------------------------------------------------------------------
// THE MEAL — balanced plate made from voxel food pieces.
// ------------------------------------------------------------------
const meal = new THREE.Group();
meal.position.set(-7.25, 0, 0.15);
world.add(meal);
box(meal, [5.25, 0.22, 4.1], [0, 0.02, 0], 0xded9ce, { edge: true });
box(meal, [4.65, 0.16, 3.55], [0, 0.19, 0], 0xfffaf0, { edge: true });
box(meal, [4.12, 0.11, 3.05], [0, 0.31, 0], 0xf2eadf, { edge: true });
// Bread slices.
for (let i = 0; i < 3; i++) {
box(meal, [0.82, 0.15, 0.72], [-1.05 + i * 0.08, 0.47 + i * 0.13, -0.72 + i * 0.16], 0xb66d35, { edge: true });
box(meal, [0.68, 0.11, 0.59], [-1.05 + i * 0.08, 0.58 + i * 0.13, -0.72 + i * 0.16], 0xf0c883);
}
// Apple pieces.
box(meal, [0.56, 0.52, 0.55], [-1.18, 0.64, 0.48], 0xdb4f4a, { edge: true });
box(meal, [0.42, 0.28, 0.45], [-1.17, 0.98, 0.48], 0xed6760);
box(meal, [0.13, 0.22, 0.13], [-1.14, 1.18, 0.48], 0x5e8850);
box(meal, [0.48, 0.47, 0.5], [-0.31, 0.59, 0.62], 0xe05c52, { edge: true });
// Greens.
const green = 0x67985a;
box(meal, [0.42, 0.17, 0.5], [0.52, 0.49, -0.56], green, { rotation: [0, .25, 0] });
box(meal, [0.36, 0.2, 0.45], [0.88, 0.52, -0.25], 0x79a95f, { rotation: [0, -.35, .12] });
box(meal, [0.42, 0.16, 0.46], [0.85, 0.57, 0.35], 0x527f4c, { rotation: [0, .18, -.1] });
// Carrot cubes.
box(meal, [0.36, 0.35, 0.35], [0.42, 0.6, 0.75], 0xee8c36, { edge: true });
box(meal, [0.31, 0.3, 0.32], [0.8, 0.57, 0.78], 0xf3a342, { edge: true });
// Egg / protein.
box(meal, [0.62, 0.28, 0.62], [1.38, 0.51, -0.55], 0xfff6df, { edge: true });
box(meal, [0.27, 0.16, 0.27], [1.38, 0.71, -0.55], 0xf2bd3d);
// Fork built from little blocks.
box(meal, [0.09, 0.08, 1.45], [1.9, 0.46, 0.1], 0xaeb9b9, { rotation: [0, -.15, 0] });
box(meal, [0.42, 0.08, 0.1], [1.98, 0.46, -0.57], 0xaeb9b9);
for (let i = 0; i < 4; i++) {
box(meal, [0.065, 0.07, 0.32], [1.8 + i * 0.12, 0.46, -0.83], 0xaeb9b9);
}
// Nutrient tokens above the meal.
const mealTokens = [];
[
[-1.12, 1.65, -0.72, 0xf3a62f],
[0.4, 1.62, 0.72, 0xe85c91],
[1.38, 1.58, -0.54, 0x18a99a]
].forEach(([x,y,z,c], i) => {
const token = box(meal, [0.22,0.22,0.22], [x,y,z], c, {
emissive: c,
emissiveIntensity: .28
});
token.rotation.set(.2, i * .7, .12);
mealTokens.push({ mesh: token, y, phase: i * 1.9 });
});
// ------------------------------------------------------------------
// DIGESTIVE CUTAWAY — front-facing voxel anatomy.
// ------------------------------------------------------------------
const anatomy = new THREE.Group();
anatomy.position.set(-0.65, 0, 0);
world.add(anatomy);
box(anatomy, [4.55, 0.22, 2.7], [0, 0.02, 0], 0xdfd9ce, { edge: true });
box(anatomy, [3.85, 4.35, 0.24], [0, 3.32, -0.52], 0xf0b49a, {
transparent: true,
opacity: 0.19,
roughness: 1
});
// Torso outline.
box(anatomy, [1.18, 1.14, 0.9], [0, 6.03, -0.22], 0xf2c1a8, { edge: true });
box(anatomy, [0.45, 0.45, 0.45], [0, 5.34, -0.12], 0xe7a88e);
box(anatomy, [1.35, 0.4, 0.72], [-1.18, 5.08, -0.22], 0xf2c1a8, { edge: true });
box(anatomy, [1.35, 0.4, 0.72], [1.18, 5.08, -0.22], 0xf2c1a8, { edge: true });
box(anatomy, [0.38, 3.3, 0.62], [-1.88, 3.32, -0.28], 0xeab498, { edge: true });
box(anatomy, [0.38, 3.3, 0.62], [1.88, 3.32, -0.28], 0xeab498, { edge: true });
box(anatomy, [3.95, 0.38, 0.62], [0, 1.55, -0.28], 0xeab498, { edge: true });
// Rib hints, kept behind the organs.
[4.62, 4.15, 3.68].forEach((y, index) => {
const width = 1.38 - index * 0.08;
box(anatomy, [width, 0.12, 0.42], [-1.12, y, -0.28], 0xf8d7c3, { edge: true });
box(anatomy, [width, 0.12, 0.42], [1.12, y, -0.28], 0xf8d7c3, { edge: true });
});
// Mouth and esophagus.
box(anatomy, [0.62, 0.18, 0.15], [0, 5.57, 0.26], 0x713f43, { edge: true });
chain(anatomy, [[0,5.45,0.16],[0,4.95,0.17],[-.08,4.55,0.22],[-.18,4.18,0.28]], 0.22, 0xe7aa84);
// Liver.
box(anatomy, [1.48, 0.45, 0.72], [0.62, 4.2, 0.0], 0xa9534e, { edge: true });
box(anatomy, [0.95, 0.4, 0.7], [0.45, 3.88, 0.02], 0xb65b52, { edge: true });
// Stomach, assembled from voxel blocks.
const stomachBlocks = [
[-0.43,3.75,0.20], [0.04,3.78,0.20],
[-0.78,3.42,0.22], [-0.32,3.42,0.22], [0.12,3.42,0.22],
[-0.58,3.08,0.22], [-0.12,3.08,0.22],
[-0.38,2.75,0.22]
];
stomachBlocks.forEach(p => box(anatomy, [0.44,0.42,0.48], p, 0xe7867e, { edge: true }));
// Large intestine frame.
const gutBrown = 0xc98555;
chain(anatomy, [[-1.37,2.88,.48],[1.0,2.88,.48],[1.0,1.22,.48],[-.96,1.22,.48]], .25, gutBrown);
chain(anatomy, [[-1.37,2.88,.48],[-1.37,1.55,.48]], .25, gutBrown);
box(anatomy, [.28,.3,.36], [-1.37,1.3,.48], 0xdf9b68, { edge: true });
// Small intestine loops.
const coilColors = [0xe8a16f, 0xf0b27f, 0xd98760];
const coils = [];
for (let layer = 0; layer < 3; layer++) {
const y = 2.52 - layer * 0.42;
const z = 0.58 + (layer % 2) * 0.14;
const points = [
[-1.15,y,z], [-0.65,y+.13,z+.18], [0.08,y+.08,z],
[0.72,y-.04,z+.2], [0.46,y-.2,z-.1], [-0.2,y-.12,z],
[-0.84,y-.18,z-.18]
];
coils.push(voxelCurve(anatomy, points, .18, coilColors[layer], { count: 27 }));
}
// Pancreas.
box(anatomy, [0.92,0.2,0.28], [0.42,2.93,0.38], 0xe4c269, { edge: true });
// Physical process: amber arrows and traveling blocks.
arrow(physicalGroup, [-0.65,5.17,0.62], [-0.83,4.63,0.62], 0xf3a62f, { width: .11, headRadius: .22 });
arrow(physicalGroup, [-1.7,3.6,0.72], [-1.18,3.15,0.72], 0xf3a62f, { width: .09, headRadius: .18 });
arrow(physicalGroup, [0.18,2.55,1.0], [0.72,1.92,1.0], 0xf3a62f, { width: .09, headRadius: .18 });
const physicalParticles = [];
const movementPath = new THREE.CatmullRomCurve3([
new THREE.Vector3(-0.65,5.28,.68),
new THREE.Vector3(-0.69,4.92,.69),
new THREE.Vector3(-0.73,4.56,.69),
new THREE.Vector3(-0.73,4.13,.69),
new THREE.Vector3(-0.72,3.73,.69)
]);
for (let i = 0; i < 6; i++) {
const m = box(physicalGroup, [.13,.13,.13], [0,0,0], 0xf7b544, {
emissive: 0xf3a62f,
emissiveIntensity: .45
});
physicalParticles.push({ mesh: m, offset: i / 6 });
}
const churnRing = octagonalRing(chemicalGroup, [-0.7,3.7,0.7], .66, 0xe85c91, 16);
// Chemical process: enzyme symbols and smaller fragments.
const chemicalParticles = [];
for (let i = 0; i < 15; i++) {
const m = box(chemicalGroup, [.095,.095,.095], [-.7,3.6,.62], 0xef72a4, {
emissive: 0xe85c91,
emissiveIntensity: .55
});
chemicalParticles.push({ mesh: m, angle: i * 2.399, radius: .18 + (i % 5) * .075, speed: .45 + (i % 3) * .18, phase: i * .31 });
}
box(chemicalGroup, [.34,.08,.08], [-.78,3.95,.76], 0xf59abc, { emissive: 0xe85c91, emissiveIntensity: .3 });
box(chemicalGroup, [.08,.34,.08], [-.78,3.95,.76], 0xf59abc, { emissive: 0xe85c91, emissiveIntensity: .3 });
// Nutrients leaving the small intestine toward a vessel.
arrow(transferGroup, [1.02,1.98,1.02], [1.55,1.52,1.02], 0x18a99a, { width: .08, headRadius: .16 });
chain(transferGroup, [[1.5,1.5,1.02],[1.5,.72,1.02],[.2,.72,1.02]], .11, 0xcd5c62);
// ------------------------------------------------------------------
// ENLARGED INTESTINAL SURFACE — epithelial wall, villi, and vessel.
// ------------------------------------------------------------------
const surface = new THREE.Group();
surface.position.set(6.15, 0, 0.05);
world.add(surface);
box(surface, [6.05,0.24,4.35], [0,0.02,0], 0xded9ce, { edge: true });
box(surface, [5.65,0.62,3.85], [0,0.45,0], 0xe9a58e, { edge: true });
box(surface, [5.55,0.12,3.75], [0,0.82,0], 0xf3b9a4, { edge: true });
// Capillary running along the front face of the wall.
for (let i = 0; i < 17; i++) {
box(surface, [.29,.18,.18], [-2.35 + i*.295,.56,1.94], 0xc75a62, { edge: i % 4 === 0 });
}
// Voxel villi rising from the wall.
const villi = new THREE.Group();
surface.add(villi);
const xs = [-2.05,-1.25,-.45,.35,1.15,1.95];
const zs = [-1.22,-.58,.06,.70];
zs.forEach((z, row) => {
xs.forEach((x, col) => {
const height = 3 + ((row + col) % 3);
for (let k = 0; k < height; k++) {
const color = k === height - 1 ? 0xf08e91 : (k % 2 ? 0xee9a94 : 0xf3aaa0);
box(villi, [.24,.24,.24], [x,.96 + k*.235,z], color, {
edge: k === height - 1
});
}
});
});
// Lumen food fragments above the villi.
const lumenFragments = [];
[
[-1.65,2.55,-.35,0xf3a62f], [-.7,2.95,.45,0xe85c91],
[.3,2.62,-.65,0xf0bd4d], [1.25,3.08,.1,0x18a99a],
[1.8,2.55,.62,0xe85c91], [-2.05,2.95,.85,0xf3a62f]
].forEach(([x,y,z,c], i) => {
const m = box(surface, [.2,.2,.2], [x,y,z], c, { emissive: c, emissiveIntensity: .12 });
m.rotation.set(.2, i * .6, .3);
lumenFragments.push({ mesh: m, y, phase: i * 1.4 });
});
// Transfer arrows: lumen → villus → blood.
arrow(transferGroup, [4.35,2.86,.62], [4.35,1.55,.62], 0x18a99a, { width: .085, headRadius: .17 });
arrow(transferGroup, [6.55,2.98,-.72], [6.55,1.67,-.72], 0x18a99a, { width: .085, headRadius: .17 });
arrow(transferGroup, [8.62,2.73,.25], [8.62,1.43,.25], 0x18a99a, { width: .085, headRadius: .17 });
const transferParticles = [];
const transferCurves = [
new THREE.CatmullRomCurve3([
new THREE.Vector3(4.35,2.75,.62),
new THREE.Vector3(4.35,1.55,.62),
new THREE.Vector3(4.35,.64,1.92),
new THREE.Vector3(3.65,.64,1.92)
]),
new THREE.CatmullRomCurve3([
new THREE.Vector3(6.55,2.84,-.72),
new THREE.Vector3(6.55,1.58,-.72),
new THREE.Vector3(6.55,.64,1.92),
new THREE.Vector3(5.8,.64,1.92)
]),
new THREE.CatmullRomCurve3([
new THREE.Vector3(8.62,2.62,.25),
new THREE.Vector3(8.62,1.42,.25),
new THREE.Vector3(8.62,.64,1.92),
new THREE.Vector3(7.8,.64,1.92)
])
];
transferCurves.forEach((curve, ci) => {
for (let i = 0; i < 4; i++) {
const m = box(transferGroup, [.105,.105,.105], [0,0,0], 0x2cc4b2, {
emissive: 0x18a99a,
emissiveIntensity: .65
});
transferParticles.push({ mesh: m, curve, offset: i / 4 + ci * .08 });
}
});
// Magnification brackets around the enlarged surface.
[
[-2.95,-1.9,.32], [2.95,-1.9,.32],
[-2.95,1.9,.32], [2.95,1.9,.32]
].forEach(([x,z,h]) => {
box(surface, [.1,h,.1], [x,1.08+h/2,z], 0x7a8588, { castShadow: false });
});
// ------------------------------------------------------------------
// CAMERA CONTROL — implemented directly without Three.js addons.
// ------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 2.45, 0),
desiredTarget: new THREE.Vector3(0, 2.45, 0),
radius: 21.5,
desiredRadius: 21.5,
theta: 0.34,
desiredTheta: 0.34,
phi: 1.05,
desiredPhi: 1.05
};
let dragging = false;
let pointerX = 0;
let pointerY = 0;
function setCameraFromState() {
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);
}
setCameraFromState();
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
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;
cameraState.desiredTheta -= dx * 0.006;
cameraState.desiredPhi = THREE.MathUtils.clamp(cameraState.desiredPhi - dy * 0.005, 0.42, 1.43);
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.desiredRadius = THREE.MathUtils.clamp(
cameraState.desiredRadius * Math.exp(event.deltaY * 0.001),
7.2,
29
);
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetView);
window.addEventListener("keydown", event => {
const key = event.key;
if (key === "ArrowLeft") cameraState.desiredTheta += 0.12;
if (key === "ArrowRight") cameraState.desiredTheta -= 0.12;
if (key === "ArrowUp") cameraState.desiredPhi = THREE.MathUtils.clamp(cameraState.desiredPhi - 0.08, .42, 1.43);
if (key === "ArrowDown") cameraState.desiredPhi = THREE.MathUtils.clamp(cameraState.desiredPhi + 0.08, .42, 1.43);
if (key === "+" || key === "=") cameraState.desiredRadius = Math.max(7.2, cameraState.desiredRadius - 1);
if (key === "-" || key === "_") cameraState.desiredRadius = Math.min(29, cameraState.desiredRadius + 1);
if (key.toLowerCase() === "r") resetView();
if (["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","+","=","-","_"].includes(key)) event.preventDefault();
});
// ------------------------------------------------------------------
// EDUCATIONAL FOCUS CONTROLS.
// ------------------------------------------------------------------
const processButtons = [...document.querySelectorAll(".process")];
const labelMeal = document.getElementById("label-meal");
const labelMovement = document.getElementById("label-movement");
const labelBreakdown = document.getElementById("label-breakdown");
const labelTransfer = document.getElementById("label-transfer");
const infoTitle = document.getElementById("info-title");
const infoBody = document.getElementById("info-body");
const infoKicker = document.getElementById("info-kicker");
const infoDot = document.getElementById("info-dot");
const info = [
{
kicker: "Process 01 · Mechanical",
title: "Food keeps moving.",
body: "Swallowing pushes food down the esophagus. Muscular contractions churn the stomach and advance the mixture through the intestines.",
color: "#f3a62f",
target: [-0.65,3.55,0.25],
radius: 9.2,
theta: 0.12,
phi: 1.13
},
{
kicker: "Process 02 · Chemical",
title: "Large pieces become smaller molecules.",
body: "Stomach acid and digestive enzymes break food into absorbable units such as amino acids, simple sugars, fatty acids, and vitamins.",
color: "#e85c91",
target: [-0.72,3.35,0.38],
radius: 7.6,
theta: 0.08,
phi: 1.16
},
{
kicker: "Process 03 · Absorptive",
title: "The intestine is an exchange surface.",
body: "Finger-like villi provide a large surface. Nutrients cross the epithelial wall, enter tiny blood vessels, and travel to tissues throughout the body.",
color: "#18a99a",
target: [6.15,1.85,0.15],
radius: 8.3,
theta: 0.52,
phi: 1.06
}
];
function clearActive() {
processButtons.forEach(button => button.classList.remove("active"));
[labelMeal,labelMovement,labelBreakdown,labelTransfer].forEach(label => label.classList.remove("active"));
}
function focusProcess(index) {
const item = info[index];
clearActive();
processButtons[index].classList.add("active");
[labelMovement,labelBreakdown,labelTransfer][index].classList.add("active");
infoKicker.textContent = item.kicker;
infoTitle.textContent = item.title;
infoBody.textContent = item.body;
infoDot.style.background = item.color;
cameraState.desiredTarget.set(...item.target);
cameraState.desiredRadius = item.radius;
cameraState.desiredTheta = item.theta;
cameraState.desiredPhi = item.phi;
}
processButtons.forEach((button, index) => button.addEventListener("click", () => focusProcess(index)));
function resetView() {
clearActive();
cameraState.desiredTarget.set(0,2.45,0);
cameraState.desiredRadius = 21.5;
cameraState.desiredTheta = 0.34;
cameraState.desiredPhi = 1.05;
infoKicker.textContent = "The full journey";
infoTitle.textContent = "One meal. Three coordinated processes.";
infoBody.textContent = "Follow food as it is physically moved, chemically reduced to absorbable molecules, and transferred across the intestinal wall into circulation.";
infoDot.style.background = "#f3a62f";
}
document.getElementById("reset").addEventListener("click", resetView);
// ------------------------------------------------------------------
// ANIMATION.
// ------------------------------------------------------------------
let paused = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const pauseButton = document.getElementById("pause");
const pauseText = document.getElementById("pause-text");
function updatePauseButton() {
pauseButton.querySelector("[aria-hidden]").textContent = paused ? "▶" : "Ⅱ";
pauseText.textContent = paused ? "Resume motion" : "Pause motion";
pauseButton.setAttribute("aria-label", paused ? "Resume animation" : "Pause animation");
}
pauseButton.addEventListener("click", () => {
paused = !paused;
updatePauseButton();
});
updatePauseButton();
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), .05);
if (!paused) elapsed += dt;
// Smooth camera interpolation.
const smoothing = 1 - Math.exp(-dt * 7.5);
cameraState.target.lerp(cameraState.desiredTarget, smoothing);
cameraState.radius = THREE.MathUtils.lerp(cameraState.radius, cameraState.desiredRadius, smoothing);
cameraState.theta = THREE.MathUtils.lerp(cameraState.theta, cameraState.desiredTheta, smoothing);
cameraState.phi = THREE.MathUtils.lerp(cameraState.phi, cameraState.desiredPhi, smoothing);
setCameraFromState();
// Floating tokens over the meal.
mealTokens.forEach(token => {
token.mesh.position.y = token.y + Math.sin(elapsed * 1.7 + token.phase) * .09;
token.mesh.rotation.y += dt * .45;
});
// Traveling physical movement.
physicalParticles.forEach(particle => {
const t = (elapsed * .24 + particle.offset) % 1;
particle.mesh.position.copy(movementPath.getPoint(t));
particle.mesh.rotation.y += dt * 1.6;
});
// Chemical churn and particle orbiting.
churnRing.rotation.z = elapsed * .35;
const churnScale = 1 + Math.sin(elapsed * 2.2) * .035;
churnRing.scale.setScalar(churnScale);
chemicalParticles.forEach(particle => {
const angle = particle.angle + elapsed * particle.speed;
particle.mesh.position.set(
-.72 + Math.cos(angle) * particle.radius,
3.55 + Math.sin(angle) * particle.radius * .72,
.68 + Math.sin(angle * 1.4) * .18
);
particle.mesh.rotation.x += dt * 2;
particle.mesh.rotation.y += dt * 1.5;
});
// Lumen fragments gently drift.
lumenFragments.forEach(fragment => {
fragment.mesh.position.y = fragment.y + Math.sin(elapsed * 1.4 + fragment.phase) * .08;
fragment.mesh.rotation.y += dt * .65;
fragment.mesh.rotation.z += dt * .35;
});
// Nutrients cross the epithelial surface and enter the vessel.
transferParticles.forEach(particle => {
const t = (elapsed * .16 + particle.offset) % 1;
particle.mesh.position.copy(particle.curve.getPoint(t));
particle.mesh.rotation.x += dt * 2;
particle.mesh.rotation.y += dt * 1.7;
});
renderer.render(scene, camera);
positionLabels();
}
// HTML callouts projected from fixed 3D anchor points.
const labelEntries = [
{ element: labelMeal, point: new THREE.Vector3(-7.25,1.85,.15) },
{ element: labelMovement, point: new THREE.Vector3(-1.2,5.02,.65) },
{ element: labelBreakdown, point: new THREE.Vector3(-1.13,3.45,.86) },
{ element: labelTransfer, point: new THREE.Vector3(8.85,2.55,.55) }
];
function positionLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
labelEntries.forEach(entry => {
const projected = entry.point.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1 && Math.abs(projected.x) < 1.35 && Math.abs(projected.y) < 1.35;
entry.element.classList.toggle("hidden", !visible);
if (!visible) return;
const x = (projected.x * .5 + .5) * width;
const y = (-projected.y * .5 + .5) * height;
const offset = width < 760 ? 12 : 18;
entry.element.style.left = `${THREE.MathUtils.clamp(x, 80, width - 80)}px`;
entry.element.style.top = `${Math.max(58, y - offset)}px`;
});
}
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", onResize);
animate();
requestAnimationFrame(() => loading.classList.add("done"));
</script>
</body>
</html>
```