Prompt specification
Build or customize the Three.js 3D scene "Intestinal absorption wall exhibit" 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: Intestinal absorption wall exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/intestinal-absorption-wall-exhibit-x0823
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring epithelial cell polarity. Compose a simplified lumen, epithelial sheet, support layer, and vessel below; trace a schematic nutrient route while distinguishing tissue scale from enlarged cellular insets. Voxel style.
Working Three.js Starter (intestinal-absorption-wall-exhibit-x0823):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Epithelial Polarity — Voxel Anatomy</title>
<style>
:root {
color-scheme: dark;
--ink: #edf5ff;
--muted: #9eb0c7;
--panel: rgba(10, 22, 39, 0.76);
--line: rgba(170, 200, 230, 0.2);
--cyan: #54d9e7;
--green: #bfff69;
--peach: #ffad78;
--sand: #d7b780;
--red: #ff6676;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07111f;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene,
#scene canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#scene canvas {
display: block;
touch-action: none;
outline: none;
}
#vignette {
position: fixed;
inset: 0;
z-index: 1;
pointer-events: none;
background:
radial-gradient(
circle at 48% 46%,
transparent 30%,
rgba(2, 7, 16, 0.18) 67%,
rgba(2, 7, 16, 0.58) 100%
);
}
#ui {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
color: var(--ink);
}
.masthead {
position: absolute;
top: 30px;
left: 34px;
width: min(430px, 42vw);
text-shadow: 0 2px 20px rgba(0, 0, 0, 0.4);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
color: #9cdce6;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 2px;
content: "";
background: var(--cyan);
box-shadow: 0 0 12px rgba(84, 217, 231, 0.8);
}
h1 {
max-width: 410px;
margin: 0;
font-size: clamp(30px, 4.2vw, 58px);
font-weight: 760;
line-height: 0.98;
letter-spacing: -0.055em;
}
.intro {
max-width: 370px;
margin: 16px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.scale-note {
position: absolute;
top: 28px;
right: 30px;
width: 254px;
padding: 15px 16px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(8, 18, 33, 0.64);
backdrop-filter: blur(14px);
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
}
.scale-note .note-title {
margin-bottom: 9px;
color: #dcecff;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.scale-note p {
margin: 0 0 8px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.scale-note p:last-child {
margin-bottom: 0;
}
.scale-note strong {
color: var(--green);
font-weight: 700;
}
#labels {
position: absolute;
inset: 0;
pointer-events: none;
}
.world-label {
position: absolute;
left: 0;
top: 0;
min-width: max-content;
padding: 8px 11px;
border: 1px solid rgba(170, 200, 230, 0.22);
border-radius: 9px;
background: rgba(8, 18, 33, 0.82);
box-shadow: 0 7px 24px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(10px);
transform: translate(-50%, -50%);
transition: opacity 180ms ease;
white-space: nowrap;
}
.world-label b {
display: block;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
line-height: 1.2;
text-transform: uppercase;
}
.world-label span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.02em;
}
.world-label.scale {
border-color: rgba(84, 217, 231, 0.4);
background: rgba(8, 27, 43, 0.9);
}
.world-label.scale b {
color: #9beaf2;
}
.world-label.inset {
border-color: rgba(191, 255, 105, 0.38);
}
.world-label.inset b {
color: var(--green);
}
.world-label.layer {
display: flex;
align-items: center;
gap: 8px;
padding: 6px 9px;
border-radius: 7px;
}
.world-label.layer b {
display: inline;
font-size: 9px;
letter-spacing: 0.1em;
}
.world-label.layer span {
display: none;
}
.world-label .dot {
width: 7px;
height: 7px;
flex: 0 0 auto;
border-radius: 2px;
background: var(--dot, var(--cyan));
box-shadow: 0 0 10px var(--dot, var(--cyan));
}
.world-label.route {
padding: 6px 9px;
border-color: rgba(191, 255, 105, 0.4);
background: rgba(21, 39, 26, 0.85);
}
.world-label.route b {
color: var(--green);
}
.world-label.callout {
padding: 5px 8px;
border-style: dashed;
border-color: rgba(213, 229, 245, 0.35);
background: rgba(8, 18, 33, 0.68);
}
.world-label.callout b {
color: #c9d8e9;
font-size: 8px;
letter-spacing: 0.1em;
}
.legend {
position: absolute;
bottom: 28px;
left: 34px;
display: flex;
flex-wrap: wrap;
gap: 9px 16px;
max-width: min(580px, 58vw);
padding: 12px 14px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(8, 18, 33, 0.7);
backdrop-filter: blur(12px);
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #b9c8d9;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.02em;
}
.legend-item i {
width: 9px;
height: 9px;
border-radius: 3px;
background: var(--swatch);
box-shadow: 0 0 10px color-mix(in srgb, var(--swatch), transparent 30%);
}
.controls {
position: absolute;
right: 30px;
bottom: 28px;
display: flex;
gap: 7px;
pointer-events: auto;
}
.controls button {
padding: 9px 12px;
border: 1px solid rgba(166, 198, 225, 0.24);
border-radius: 9px;
color: #d9e7f5;
background: rgba(9, 21, 37, 0.82);
cursor: pointer;
backdrop-filter: blur(12px);
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.controls button:hover {
border-color: rgba(84, 217, 231, 0.65);
background: rgba(16, 36, 57, 0.92);
transform: translateY(-1px);
}
.controls button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
.hint {
position: absolute;
left: 50%;
bottom: 30px;
color: rgba(194, 210, 225, 0.55);
font-size: 10px;
letter-spacing: 0.04em;
transform: translateX(-50%);
}
@media (max-width: 900px) {
.masthead {
top: 20px;
left: 20px;
width: 60vw;
}
.intro,
.scale-note,
.hint {
display: none;
}
.legend {
left: 20px;
bottom: 20px;
max-width: 52vw;
}
.controls {
right: 20px;
bottom: 20px;
}
}
@media (max-width: 620px) {
.masthead {
width: calc(100vw - 40px);
}
h1 {
max-width: 290px;
font-size: 30px;
}
.legend {
display: none;
}
.controls {
left: 20px;
right: 20px;
justify-content: center;
}
.controls button {
flex: 1;
padding: 9px 7px;
font-size: 11px;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive voxel diagram of epithelial nutrient transport"></div>
<div id="vignette"></div>
<div id="ui">
<header class="masthead">
<div class="eyebrow">Voxel anatomy · epithelial polarity</div>
<h1>From lumen<br />to blood.</h1>
<p class="intro">
A layered tissue schematic paired with enlarged cellular cutaways.
Nutrients cross the apical membrane, traverse the epithelial cell,
and enter the vascular compartment below.
</p>
</header>
<aside class="scale-note">
<div class="note-title">Reading the model</div>
<p>
The large tissue panel shows <strong>relative spatial relationships</strong>
between lumen, epithelium, support tissue, and vessel.
</p>
<p>
The cellular panels are <strong>diagrammatic enlargements</strong>,
not literal scale or magnification measurements.
</p>
</aside>
<div id="labels">
<div id="label-tissue" class="world-label scale">
<b>Tissue scale</b>
<span>relative architecture</span>
</div>
<div id="label-lumen" class="world-label layer" style="--dot: #54d9e7">
<i class="dot"></i><b>Lumen</b>
</div>
<div id="label-epithelial" class="world-label layer" style="--dot: #ffad78">
<i class="dot"></i><b>Epithelial sheet</b>
</div>
<div id="label-support" class="world-label layer" style="--dot: #d7b780">
<i class="dot"></i><b>Support layer</b>
</div>
<div id="label-vessel" class="world-label layer" style="--dot: #ff6676">
<i class="dot"></i><b>Vessel</b>
</div>
<div id="label-route" class="world-label route">
<b>Nutrient route</b>
</div>
<div id="label-callout" class="world-label callout">
<b>enlarged from highlighted cell</b>
</div>
<div id="label-inset-a" class="world-label inset">
<b>Cellular inset 01</b>
<span>apical uptake · enlarged</span>
</div>
<div id="label-inset-b" class="world-label inset">
<b>Cellular inset 02</b>
<span>basal exit · enlarged</span>
</div>
</div>
<div class="legend" aria-label="Scene legend">
<div class="legend-item" style="--swatch: #54d9e7">
<i></i>Lumen / transporter
</div>
<div class="legend-item" style="--swatch: #ffad78">
<i></i>Epithelium
</div>
<div class="legend-item" style="--swatch: #d7b780">
<i></i>Support matrix
</div>
<div class="legend-item" style="--swatch: #ff6676">
<i></i>Vessel
</div>
<div class="legend-item" style="--swatch: #bfff69">
<i></i>Nutrient path
</div>
</div>
<div class="controls">
<button id="reset" type="button">Reset view</button>
<button id="flow" type="button">Pause flow</button>
<button id="labels-toggle" type="button">Labels on</button>
</div>
<div class="hint">Drag to orbit · wheel / pinch to zoom · right-drag to pan</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const sceneHost = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.appendChild(renderer.domElement);
renderer.domElement.setAttribute(
"aria-label",
"Voxel-style epithelial tissue and nutrient transport schematic"
);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 23, 42);
const camera = new THREE.OrthographicCamera(-10, 10, 6, -6, 0.1, 80);
const hemi = new THREE.HemisphereLight(0xbadfff, 0x172033, 1.75);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xfff1dc, 3.3);
keyLight.position.set(-5, 11, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -14;
keyLight.shadow.camera.right = 14;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x66dfff, 1.6);
rimLight.position.set(9, 4, -8);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(70, 70),
new THREE.MeshStandardMaterial({
color: 0x091526,
roughness: 0.92,
metalness: 0.05
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -2.25;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(44, 44, 0x23435e, 0x142a40);
grid.position.y = -2.235;
grid.material.transparent = true;
grid.material.opacity = 0.32;
scene.add(grid);
// -------------------------------------------------------------------------
// Materials and reusable voxel helpers
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materials = {
plinth: new THREE.MeshStandardMaterial({
color: 0x122238,
roughness: 0.72,
metalness: 0.18
}),
plinthEdge: new THREE.MeshStandardMaterial({
color: 0x29425d,
roughness: 0.58,
metalness: 0.22
}),
support: [
new THREE.MeshStandardMaterial({ color: 0xc5a46f, roughness: 0.92 }),
new THREE.MeshStandardMaterial({ color: 0xd8bd87, roughness: 0.9 }),
new THREE.MeshStandardMaterial({ color: 0xb99461, roughness: 0.94 })
],
membrane: new THREE.MeshStandardMaterial({
color: 0xe8cf9f,
roughness: 0.78
}),
epithelial: [
new THREE.MeshStandardMaterial({ color: 0xf39a69, roughness: 0.77 }),
new THREE.MeshStandardMaterial({ color: 0xffb47d, roughness: 0.75 }),
new THREE.MeshStandardMaterial({ color: 0xe88a61, roughness: 0.8 })
],
highlightedCell: new THREE.MeshStandardMaterial({
color: 0xffd079,
emissive: 0x6b3100,
emissiveIntensity: 0.28,
roughness: 0.64
}),
lumen: new THREE.MeshStandardMaterial({
color: 0x49c9df,
emissive: 0x0d5265,
emissiveIntensity: 0.3,
transparent: true,
opacity: 0.13,
depthWrite: false,
roughness: 0.25
}),
cellBody: new THREE.MeshStandardMaterial({
color: 0xffa270,
emissive: 0x42180d,
emissiveIntensity: 0.14,
transparent: true,
opacity: 0.46,
depthWrite: false,
roughness: 0.8
}),
nucleus: new THREE.MeshStandardMaterial({
color: 0x9a557c,
roughness: 0.72
}),
protein: new THREE.MeshStandardMaterial({
color: 0x52d5e5,
emissive: 0x0a6673,
emissiveIntensity: 0.7,
roughness: 0.38
}),
vessel: [
new THREE.MeshStandardMaterial({ color: 0xd9475a, roughness: 0.68 }),
new THREE.MeshStandardMaterial({ color: 0xf15a69, roughness: 0.66 }),
new THREE.MeshStandardMaterial({ color: 0xb9364d, roughness: 0.74 })
],
vesselDark: new THREE.MeshStandardMaterial({
color: 0x721f38,
roughness: 0.82
}),
nutrient: new THREE.MeshStandardMaterial({
color: 0xc9ff72,
emissive: 0x5b9b20,
emissiveIntensity: 0.9,
roughness: 0.45
}),
insetBack: new THREE.MeshStandardMaterial({
color: 0x101d31,
roughness: 0.82,
metalness: 0.1
}),
route: new THREE.MeshBasicMaterial({
color: 0xbfff69,
toneMapped: false,
depthTest: false,
depthWrite: false
}),
routeParticle: new THREE.MeshBasicMaterial({
color: 0xe0ff9d,
toneMapped: false,
depthTest: false,
depthWrite: false
})
};
function makeBox(
parent,
sx,
sy,
sz,
x,
y,
z,
material,
castShadow = true
) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(sx, sy, sz);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addEdges(
parent,
sx,
sy,
sz,
x,
y,
z,
color = 0x8fc9e7,
opacity = 0.45,
overlay = false
) {
const geometry = new THREE.EdgesGeometry(
new THREE.BoxGeometry(sx, sy, sz)
);
const material = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity,
depthTest: !overlay,
depthWrite: false
});
const line = new THREE.LineSegments(geometry, material);
line.position.set(x, y, z);
line.renderOrder = overlay ? 7 : 2;
parent.add(line);
return line;
}
let randomSeed = 29;
function random() {
randomSeed =
(randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
// -------------------------------------------------------------------------
// Nutrient path: square-section tube, arrowheads, and moving voxel cargo
// -------------------------------------------------------------------------
const animatedRoutes = [];
const up = new THREE.Vector3(0, 1, 0);
function createCurve(points) {
return new THREE.CatmullRomCurve3(
points.map((point) => new THREE.Vector3(...point)),
false,
"catmullrom",
0.12
);
}
function addRoute(parent, points, options = {}) {
const curve = createCurve(points);
const radius = options.radius ?? 0.055;
const particleCount = options.particleCount ?? 6;
const speed = options.speed ?? 0.18;
const tube = new THREE.Mesh(
new THREE.TubeGeometry(
curve,
Math.max(30, points.length * 9),
radius,
4,
false
),
materials.route
);
tube.renderOrder = 8;
parent.add(tube);
const arrowGeometry = new THREE.ConeGeometry(
options.arrowSize ?? 0.16,
(options.arrowSize ?? 0.16) * 2.3,
4
);
const arrowTimes = options.arrowTimes ?? [0.17, 0.38, 0.58, 0.76];
arrowTimes.forEach((time) => {
const arrow = new THREE.Mesh(arrowGeometry, materials.route);
arrow.position.copy(curve.getPointAt(time));
arrow.quaternion.setFromUnitVectors(
up,
curve.getTangentAt(time).normalize()
);
arrow.renderOrder = 9;
parent.add(arrow);
});
const particleGeometry = new THREE.BoxGeometry(
options.particleSize ?? 0.12,
options.particleSize ?? 0.12,
options.particleSize ?? 0.12
);
const particles = [];
for (let i = 0; i < particleCount; i++) {
const particle = new THREE.Mesh(
particleGeometry,
materials.routeParticle
);
particle.userData.offset = i / particleCount;
particle.renderOrder = 10;
parent.add(particle);
particles.push(particle);
}
const route = {
curve,
particles,
speed,
spin: 1.1 + random() * 1.4
};
animatedRoutes.push(route);
return route;
}
// -------------------------------------------------------------------------
// Tissue-scale panel
// -------------------------------------------------------------------------
const tissue = new THREE.Group();
tissue.position.set(-3.6, 0, 0);
scene.add(tissue);
makeBox(
tissue,
9.7,
0.22,
5.4,
0,
-2.02,
0,
materials.plinth
);
makeBox(
tissue,
9.72,
0.12,
0.18,
0,
-1.84,
2.59,
materials.plinthEdge
);
addEdges(tissue, 9.7, 0.22, 5.4, 0, -2.02, 0, 0x4d6b88, 0.38);
const routeX = 0.7;
const routeZ = 1.08;
// Support matrix.
for (let ix = 0; ix < 13; ix++) {
const x = -4.2 + ix * 0.7;
for (let iz = 0; iz < 5; iz++) {
const z = -1.7 + iz * 0.72;
if (
Math.abs(x - routeX) < 0.42 &&
Math.abs(z - routeZ) < 0.42
) {
continue;
}
if (random() < 0.09) continue;
const height = 0.34 + random() * 0.22;
makeBox(
tissue,
0.57,
height,
0.57,
x,
0.15 + (height - 0.4) * 0.12,
z,
materials.support[Math.floor(random() * materials.support.length)]
);
}
}
// Thin basement membrane under the epithelial sheet.
for (let ix = 0; ix < 13; ix++) {
const x = -4.2 + ix * 0.7;
for (let iz = 0; iz < 5; iz++) {
const z = -1.7 + iz * 0.72;
if (
Math.abs(x - routeX) < 0.42 &&
Math.abs(z - routeZ) < 0.42
) {
continue;
}
makeBox(
tissue,
0.62,
0.11,
0.59,
x,
0.67,
z,
materials.membrane
);
}
}
// Epithelial sheet.
for (let ix = 0; ix < 13; ix++) {
const x = -4.2 + ix * 0.7;
for (let iz = 0; iz < 6; iz++) {
const z = -1.8 + iz * 0.72;
const highlighted =
Math.abs(x - routeX) < 0.32 &&
Math.abs(z - routeZ) < 0.32;
const material = highlighted
? materials.highlightedCell
: materials.epithelial[(ix + iz * 2) % materials.epithelial.length];
makeBox(
tissue,
0.62,
0.68,
0.59,
x,
1.2 + (random() - 0.5) * 0.025,
z,
material
);
}
}
const highlightOutline = addEdges(
tissue,
0.67,
0.73,
0.64,
routeX,
1.2,
routeZ,
0xcfff85,
0.9,
true
);
// Translucent lumen volume.
const lumenVolume = makeBox(
tissue,
9.42,
1.42,
4.35,
0,
2.18,
0,
materials.lumen,
false
);
lumenVolume.renderOrder = 1;
addEdges(
tissue,
9.42,
1.42,
4.35,
0,
2.18,
0,
0x54d9e7,
0.35
);
// Ambient nutrient voxels floating in the lumen.
const ambientNutrients = [];
for (let i = 0; i < 12; i++) {
const size = 0.09 + random() * 0.07;
const nutrient = new THREE.Mesh(
new THREE.BoxGeometry(size, size, size),
materials.nutrient
);
const baseY = 2.25 + random() * 0.7;
nutrient.position.set(
-4 + random() * 7.8,
baseY,
-1.7 + random() * 3.4
);
nutrient.userData.baseY = baseY;
nutrient.userData.phase = random() * Math.PI * 2;
tissue.add(nutrient);
ambientNutrients.push(nutrient);
}
// Voxel vessel below the support layer.
for (let ix = 0; ix < 13; ix++) {
const x = -4.2 + ix * 0.65;
makeBox(
tissue,
0.59,
0.22,
1.22,
x,
-0.72,
routeZ,
materials.vessel[(ix + 1) % materials.vessel.length]
);
makeBox(
tissue,
0.59,
0.22,
1.22,
x,
-1.68,
routeZ,
materials.vessel[(ix + 2) % materials.vessel.length]
);
makeBox(
tissue,
0.59,
0.72,
0.23,
x,
-1.2,
routeZ - 0.49,
materials.vessel[ix % materials.vessel.length]
);
makeBox(
tissue,
0.59,
0.72,
0.23,
x,
-1.2,
routeZ + 0.49,
materials.vessel[(ix + 1) % materials.vessel.length]
);
}
makeBox(
tissue,
8.4,
0.48,
0.48,
0,
-1.2,
routeZ,
materials.vesselDark,
false
);
addRoute(
tissue,
[
[routeX, 2.84, routeZ],
[routeX, 2.35, routeZ],
[routeX, 1.48, routeZ],
[routeX, 0.65, routeZ],
[routeX, -0.25, routeZ],
[routeX, -1.2, routeZ],
[2.25, -1.2, routeZ],
[3.85, -1.2, routeZ]
],
{
radius: 0.058,
particleCount: 7,
particleSize: 0.13,
speed: 0.16,
arrowSize: 0.17
}
);
// -------------------------------------------------------------------------
// Enlarged cellular inset 01: apical uptake
// -------------------------------------------------------------------------
const insetA = new THREE.Group();
insetA.position.set(3.25, 2.15, -0.15);
scene.add(insetA);
makeBox(
insetA,
4.1,
3.25,
0.15,
0,
0,
-1.02,
materials.insetBack
);
addEdges(
insetA,
4.1,
3.25,
0.15,
0,
0,
-1.02,
0x54d9e7,
0.4
);
// Enlarged translucent cell body.
const cellBody = makeBox(
insetA,
2.46,
1.56,
1.17,
0,
-0.05,
0.1,
materials.cellBody,
false
);
cellBody.renderOrder = 2;
addEdges(
insetA,
2.46,
1.56,
1.17,
0,
-0.05,
0.1,
0xffc094,
0.8
);
// Enlarged lumen and basement membrane.
makeBox(
insetA,
2.8,
0.56,
1.36,
0,
1.25,
0.1,
materials.lumen,
false
);
addEdges(
insetA,
2.8,
0.56,
1.36,
0,
1.25,
0.1,
0x54d9e7,
0.45
);
makeBox(
insetA,
2.64,
0.13,
1.35,
0,
-0.88,
0.1,
materials.membrane
);
// Large voxel nucleus.
makeBox(
insetA,
0.67,
0.65,
0.61,
0.7,
-0.13,
0.12,
materials.nucleus
);
// Apical transporter, represented as a voxel bracket.
makeBox(
insetA,
0.76,
0.13,
0.15,
0,
0.84,
0.43,
materials.protein
);
makeBox(
insetA,
0.14,
0.47,
0.15,
-0.31,
0.61,
0.43,
materials.protein
);
makeBox(
insetA,
0.14,
0.47,
0.15,
0.31,
0.61,
0.43,
materials.protein
);
// A nutrient voxel above the transporter.
makeBox(
insetA,
0.18,
0.18,
0.18,
0,
1.27,
0.43,
materials.nutrient
);
addRoute(
insetA,
[
[0, 1.25, 0.43],
[0, 0.72, 0.43],
[0, 0.12, 0.43],
[0, -0.48, 0.43],
[0, -1.04, 0.43]
],
{
radius: 0.065,
particleCount: 5,
particleSize: 0.14,
speed: 0.19,
arrowSize: 0.18
}
);
// -------------------------------------------------------------------------
// Enlarged cellular inset 02: basal exit
// -------------------------------------------------------------------------
const insetB = new THREE.Group();
insetB.position.set(3.25, -1.35, -0.1);
scene.add(insetB);
makeBox(
insetB,
4.1,
2.65,
0.15,
0,
0,
-0.95,
materials.insetBack
);
addEdges(
insetB,
4.1,
2.65,
0.15,
0,
0,
-0.95,
0x54d9e7,
0.4
);
// Basement boundary.
makeBox(
insetB,
3.3,
0.13,
1.38,
0,
0.72,
0.12,
materials.membrane
);
// Enlarged support matrix.
for (let ix = 0; ix < 6; ix++) {
const x = -1.55 + ix * 0.62;
for (let iz = 0; iz < 3; iz++) {
if (
Math.abs(x) < 0.35 &&
Math.abs(0.16 + iz * 0.42 - 0.25) < 0.2
) {
continue;
}
makeBox(
insetB,
0.53,
0.3 + random() * 0.15,
0.38,
x,
0.37,
-0.25 + iz * 0.42,
materials.support[(ix + iz) % materials.support.length]
);
}
}
// Enlarged capillary.
for (let ix = 0; ix < 7; ix++) {
const x = -1.8 + ix * 0.6;
makeBox(
insetB,
0.54,
0.23,
0.8,
x,
-0.45,
0.22,
materials.vessel[ix % materials.vessel.length]
);
makeBox(
insetB,
0.54,
0.23,
0.8,
x,
-1.08,
0.22,
materials.vessel[(ix + 1) % materials.vessel.length]
);
makeBox(
insetB,
0.54,
0.4,
0.2,
x,
-0.765,
-0.08,
materials.vessel[(ix + 2) % materials.vessel.length]
);
}
makeBox(
insetB,
3.9,
0.33,
0.35,
0,
-0.765,
0.22,
materials.vesselDark,
false
);
addRoute(
insetB,
[
[0, 0.92, 0.25],
[0, 0.35, 0.25],
[0, -0.25, 0.25],
[0, -0.76, 0.25],
[1.42, -0.76, 0.25]
],
{
radius: 0.062,
particleCount: 5,
particleSize: 0.13,
speed: 0.18,
arrowSize: 0.17
}
);
// Dashed connector between the two enlarged panels.
const insetConnector = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(3.25, 0.57, -0.12),
new THREE.Vector3(3.25, 0.08, -0.12)
]),
new THREE.LineDashedMaterial({
color: 0xbfff69,
transparent: true,
opacity: 0.42,
dashSize: 0.11,
gapSize: 0.09
})
);
insetConnector.computeLineDistances();
scene.add(insetConnector);
// -------------------------------------------------------------------------
// Magnification callout from the tissue-scale highlighted cell
// -------------------------------------------------------------------------
const calloutPoints = [
new THREE.Vector3(-2.9, 1.22, routeZ),
new THREE.Vector3(-0.7, 1.45, 0.62),
new THREE.Vector3(1.18, 1.5, -0.08)
];
const calloutLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(calloutPoints),
new THREE.LineDashedMaterial({
color: 0xcbd8e7,
transparent: true,
opacity: 0.48,
dashSize: 0.16,
gapSize: 0.12
})
);
calloutLine.computeLineDistances();
scene.add(calloutLine);
const calloutMarker = new THREE.Mesh(
new THREE.BoxGeometry(0.11, 0.11, 0.11),
new THREE.MeshBasicMaterial({
color: 0xcfff85,
toneMapped: false,
depthTest: false
})
);
calloutMarker.position.copy(calloutPoints[0]);
calloutMarker.renderOrder = 9;
scene.add(calloutMarker);
// -------------------------------------------------------------------------
// DOM annotation projection
// -------------------------------------------------------------------------
const labelDefinitions = [
{
id: "label-tissue",
position: new THREE.Vector3(-3.6, 3.95, 0),
offset: [0, 0]
},
{
id: "label-lumen",
position: new THREE.Vector3(-7.62, 2.45, 2.12),
offset: [-4, -4]
},
{
id: "label-epithelial",
position: new THREE.Vector3(-7.62, 1.26, 2.12),
offset: [-4, 0]
},
{
id: "label-support",
position: new THREE.Vector3(-7.62, 0.52, 2.12),
offset: [-4, 0]
},
{
id: "label-vessel",
position: new THREE.Vector3(-7.62, -1.18, 2.12),
offset: [-4, 0]
},
{
id: "label-route",
position: new THREE.Vector3(-2.15, 3.05, routeZ),
offset: [43, -8]
},
{
id: "label-callout",
position: new THREE.Vector3(-0.7, 1.65, 0.62),
offset: [0, -21]
},
{
id: "label-inset-a",
position: new THREE.Vector3(3.25, 3.93, 0),
offset: [0, 0]
},
{
id: "label-inset-b",
position: new THREE.Vector3(3.25, 0.08, 0),
offset: [0, 0]
}
];
const projectedPoint = new THREE.Vector3();
function updateLabels() {
const width = renderer.domElement.clientWidth;
const height = renderer.domElement.clientHeight;
labelDefinitions.forEach((definition) => {
projectedPoint.copy(definition.position).project(camera);
const x = (projectedPoint.x * 0.5 + 0.5) * width;
const y = (-projectedPoint.y * 0.5 + 0.5) * height;
const element = document.getElementById(definition.id);
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.transform =
`translate(-50%, -50%) translate(${definition.offset[0]}px, ${definition.offset[1]}px)`;
});
}
// -------------------------------------------------------------------------
// Direct camera controls: orbit, zoom, pan, touch pinch
// -------------------------------------------------------------------------
const controlState = {
target: new THREE.Vector3(-1.25, 0.45, 0),
theta: 0.3,
phi: 1.03,
zoom: 1
};
const defaultState = {
target: controlState.target.clone(),
theta: controlState.theta,
phi: controlState.phi,
zoom: controlState.zoom
};
const pointers = new Map();
let dragMode = "orbit";
let lastPinchDistance = 0;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
function updateCamera() {
const radius = 16.5;
const sinPhi = Math.sin(controlState.phi);
camera.position.set(
controlState.target.x + radius * sinPhi * Math.sin(controlState.theta),
controlState.target.y + radius * Math.cos(controlState.phi),
controlState.target.z + radius * sinPhi * Math.cos(controlState.theta)
);
camera.lookAt(controlState.target);
camera.zoom = controlState.zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function panScene(dx, dy) {
const panUnit =
(camera.top - camera.bottom) /
renderer.domElement.clientHeight /
camera.zoom;
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrixWorld,
0
);
const upVector = new THREE.Vector3().setFromMatrixColumn(
camera.matrixWorld,
1
);
controlState.target.addScaledVector(right, -dx * panUnit);
controlState.target.addScaledVector(upVector, dy * panUnit);
}
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
event.preventDefault();
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
dragMode = event.button === 2 ? "pan" : "orbit";
} else if (pointers.size === 2) {
dragMode = "pinch";
lastPinchDistance = pointerDistance();
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1 && dragMode === "orbit") {
controlState.theta -= dx * 0.0055;
controlState.phi = THREE.MathUtils.clamp(
controlState.phi - dy * 0.0045,
0.48,
1.43
);
} else if (pointers.size === 1 && dragMode === "pan") {
panScene(dx, dy);
} else if (pointers.size === 2 && dragMode === "pinch") {
const currentDistance = pointerDistance();
if (lastPinchDistance > 0 && currentDistance > 0) {
controlState.zoom = THREE.MathUtils.clamp(
controlState.zoom * (currentDistance / lastPinchDistance),
0.68,
1.65
);
}
lastPinchDistance = currentDistance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 1) {
dragMode = "orbit";
} else if (pointers.size === 0) {
lastPinchDistance = 0;
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controlState.zoom = THREE.MathUtils.clamp(
controlState.zoom * Math.exp(-event.deltaY * 0.001),
0.68,
1.65
);
},
{ passive: false }
);
function resetView() {
controlState.target.copy(defaultState.target);
controlState.theta = defaultState.theta;
controlState.phi = defaultState.phi;
controlState.zoom = defaultState.zoom;
}
document.getElementById("reset").addEventListener("click", resetView);
let flowPaused = false;
const flowButton = document.getElementById("flow");
function toggleFlow() {
flowPaused = !flowPaused;
flowButton.textContent = flowPaused ? "Resume flow" : "Pause flow";
}
flowButton.addEventListener("click", toggleFlow);
let labelsVisible = true;
const labelsToggle = document.getElementById("labels-toggle");
function toggleLabels() {
labelsVisible = !labelsVisible;
document.getElementById("labels").style.opacity = labelsVisible
? "1"
: "0";
labelsToggle.textContent = labelsVisible ? "Labels on" : "Labels off";
}
labelsToggle.addEventListener("click", toggleLabels);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLButtonElement) return;
if (event.key.toLowerCase() === "r") {
resetView();
}
if (event.code === "Space") {
event.preventDefault();
toggleFlow();
}
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const halfHeight = Math.max(5.8, 8.2 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
updateCamera();
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (!flowPaused) elapsed += delta;
updateCamera();
animatedRoutes.forEach((route) => {
route.particles.forEach((particle) => {
const time =
(elapsed * route.speed + particle.userData.offset) % 1;
particle.position.copy(route.curve.getPointAt(time));
particle.rotation.x += delta * route.spin;
particle.rotation.y += delta * route.spin * 0.8;
});
});
ambientNutrients.forEach((nutrient) => {
nutrient.position.y =
nutrient.userData.baseY +
Math.sin(elapsed * 1.25 + nutrient.userData.phase) * 0.08;
nutrient.rotation.y += delta * 0.55;
});
const pulse = 1 + Math.sin(elapsed * 2.1) * 0.025;
highlightOutline.scale.set(pulse, pulse, pulse);
calloutMarker.rotation.x += delta * 1.6;
calloutMarker.rotation.y += delta * 1.6;
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```