Prompt specification
Build or customize the Three.js 3D scene "Heart lungs and body circuit 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: Heart lungs and body circuit exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/heart-lungs-and-body-circuit-exhibit-x0995
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows a voxel exhibit of pulmonary and systemic circulation. Arrange a simplified central heart between paired lungs and a schematic branching body network. Separate the heart into readable right-side and left-side pumping paths, with connected vessels forming one loop through lungs, heart, body, and back to the heart; send one tracer around that continuous route at a slow illustrative speed, highlighting the region it currently traverses. Use contrasting circuit colors and a small legend. Keep vessel widths and tracer speed explicitly schematic, and make the connections inspectable rather than hiding them behind a dense anatomical shell. Place a pause point near each major junction so the next connected section can be followed before the tracer continues around the loop.
Working Three.js Starter (heart-lungs-and-body-circuit-exhibit-x0995):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Circulation Exhibit</title>
<style>
:root {
color-scheme: dark;
--bg: #07111b;
--panel: rgba(10, 23, 36, 0.88);
--panel-border: rgba(153, 196, 224, 0.2);
--text: #eaf4fb;
--muted: #9bb0c1;
--blue: #39a9ff;
--red: #ff6078;
--gold: #ffd166;
--violet: #a982ff;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
canvas {
position: fixed;
inset: 0;
display: block;
touch-action: none;
}
button, input { font: inherit; }
#hud {
position: fixed;
inset: 0;
z-index: 10;
pointer-events: none;
}
.panel {
position: absolute;
pointer-events: auto;
background: var(--panel);
border: 1px solid var(--panel-border);
border-radius: 14px;
box-shadow: 0 16px 45px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(12px);
}
#titlePanel {
top: 18px;
left: 18px;
width: min(410px, calc(100vw - 36px));
padding: 17px 18px 15px;
}
.eyebrow {
color: #78d7ff;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 6px 0 4px;
font-size: clamp(20px, 2.4vw, 30px);
line-height: 1.05;
letter-spacing: -0.025em;
}
#titlePanel p {
margin: 8px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
#legendPanel {
top: 18px;
right: 18px;
width: 272px;
padding: 15px;
}
.panel-title {
margin-bottom: 10px;
color: #cfe2ef;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin: 7px 0;
color: #d9e6ef;
font-size: 11px;
}
.swatch {
width: 25px;
height: 6px;
flex: 0 0 auto;
border-radius: 99px;
background: var(--blue);
box-shadow: 0 0 12px currentColor;
}
.swatch.red { background: var(--red); color: var(--red); }
.swatch.blue { background: var(--blue); color: var(--blue); }
.swatch.gradient {
background: linear-gradient(90deg, var(--blue), var(--red));
color: var(--violet);
}
.swatch.gold { background: var(--gold); color: var(--gold); }
.legend-note {
margin-top: 11px;
padding-top: 10px;
border-top: 1px solid rgba(255, 255, 255, 0.1);
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.checkpoint-key {
display: flex;
flex-wrap: wrap;
gap: 5px;
margin-top: 9px;
}
.checkpoint-key span {
padding: 3px 6px;
border: 1px solid rgba(255, 209, 102, 0.3);
border-radius: 6px;
color: #f6d894;
background: rgba(255, 209, 102, 0.07);
font-size: 9px;
}
#statusPanel {
left: 18px;
bottom: 18px;
width: min(420px, calc(100vw - 36px));
padding: 16px 17px;
}
.status-head {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
}
#statusDot {
width: 10px;
height: 10px;
border-radius: 50%;
background: var(--gold);
box-shadow: 0 0 14px var(--gold);
}
#statusTitle {
font-size: 14px;
font-weight: 800;
line-height: 1.25;
}
#statusDetail,
#statusNext {
margin: 4px 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
#statusNext strong { color: #d8e7f0; }
.progress-track {
height: 4px;
margin: 11px 0 2px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.09);
}
#progressBar {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--blue), var(--gold), var(--red));
transition: width 0.08s linear;
}
#controls {
right: 18px;
bottom: 18px;
width: 326px;
padding: 13px;
}
.control-row {
display: flex;
gap: 8px;
align-items: center;
}
button {
min-height: 38px;
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 9px;
padding: 8px 11px;
color: var(--text);
background: rgba(255, 255, 255, 0.075);
cursor: pointer;
transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}
button:hover:not(:disabled) {
background: rgba(255, 255, 255, 0.13);
border-color: rgba(255, 255, 255, 0.3);
}
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled {
cursor: default;
opacity: 0.38;
}
#playBtn {
flex: 1 0 102px;
font-weight: 750;
}
#continueBtn {
flex: 1 1 170px;
border-color: rgba(255, 209, 102, 0.45);
color: #ffe5a7;
background: rgba(255, 209, 102, 0.11);
}
.speed-row {
display: grid;
grid-template-columns: auto 1fr auto;
gap: 9px;
align-items: center;
margin-top: 11px;
color: var(--muted);
font-size: 10px;
}
#speed {
width: 100%;
accent-color: var(--gold);
}
#speedValue {
min-width: 36px;
color: #f4dfaa;
font-variant-numeric: tabular-nums;
text-align: right;
}
.camera-help {
margin-top: 9px;
color: #8199aa;
font-size: 9px;
text-align: center;
}
#worldLabels,
#checkpointLabels {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.world-label {
position: absolute;
transform: translate(-50%, -50%);
padding: 5px 8px;
border: 1px solid rgba(170, 211, 236, 0.19);
border-radius: 7px;
color: #d9eaf4;
background: rgba(7, 17, 27, 0.74);
box-shadow: 0 5px 18px rgba(0, 0, 0, 0.22);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.04em;
white-space: nowrap;
}
.world-label small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 8px;
font-weight: 500;
letter-spacing: 0;
}
.world-label.blue { border-color: rgba(57, 169, 255, 0.4); }
.world-label.red { border-color: rgba(255, 96, 120, 0.4); }
.checkpoint-tag {
position: absolute;
transform: translate(-50%, -50%);
width: 25px;
height: 25px;
display: grid;
place-items: center;
border: 1px solid rgba(255, 209, 102, 0.62);
border-radius: 50%;
color: #ffe3a0;
background: rgba(38, 29, 12, 0.9);
box-shadow: 0 0 13px rgba(255, 209, 102, 0.16);
cursor: pointer;
pointer-events: auto;
font-size: 9px;
font-weight: 850;
user-select: none;
}
.checkpoint-tag:hover,
.checkpoint-tag.selected {
color: #07111b;
background: var(--gold);
box-shadow: 0 0 22px rgba(255, 209, 102, 0.65);
}
.checkpoint-tag.waiting {
animation: checkpointPulse 1.25s ease-in-out infinite;
}
@keyframes checkpointPulse {
0%, 100% { box-shadow: 0 0 8px rgba(255, 209, 102, 0.2); }
50% { box-shadow: 0 0 24px rgba(255, 209, 102, 0.8); }
}
#tracerTag {
position: fixed;
z-index: 7;
transform: translate(-50%, -100%);
padding: 4px 7px;
border: 1px solid rgba(255, 209, 102, 0.45);
border-radius: 6px;
color: #ffe4a2;
background: rgba(28, 23, 12, 0.88);
font-size: 9px;
font-weight: 800;
white-space: nowrap;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
color: #a8c1d2;
background: var(--bg);
font-size: 12px;
letter-spacing: 0.08em;
}
@media (max-width: 820px) {
#legendPanel {
top: auto;
right: 12px;
bottom: 150px;
width: 235px;
padding: 11px;
}
#titlePanel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
}
#statusPanel {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
}
#controls {
right: 12px;
bottom: 164px;
width: calc(100vw - 24px);
}
.legend-note, .checkpoint-key { display: none; }
}
</style>
</head>
<body>
<div id="loading">BUILDING VOXEL CIRCULATION…</div>
<div id="hud">
<section id="titlePanel" class="panel">
<div class="eyebrow">Exploded voxel exhibit</div>
<h1>Pulmonary ↔ Systemic Circulation</h1>
<p>
A single tracer follows one continuous connected route: right heart → lungs →
left heart → body → right heart. Transparent voxels keep every junction inspectable.
</p>
</section>
<section id="legendPanel" class="panel">
<div class="panel-title">Circuit legend</div>
<div class="legend-row">
<span class="swatch blue"></span>
<span>Deoxygenated · right heart / pulmonary circuit</span>
</div>
<div class="legend-row">
<span class="swatch red"></span>
<span>Oxygenated · left heart / systemic circuit</span>
</div>
<div class="legend-row">
<span class="swatch gradient"></span>
<span>Capillary color transition</span>
</div>
<div class="legend-row">
<span class="swatch gold"></span>
<span>Tracer and numbered pause point</span>
</div>
<div class="checkpoint-key">
<span>P1 split</span><span>P2 lung inlet</span><span>P3 vein outlet</span>
<span>P4 aorta</span><span>P5 tissue inlet</span><span>P6 tissue outlet</span>
<span>P7 cava</span>
</div>
<div class="legend-note">
<strong>Schematic scale:</strong> vessel widths are enlarged and tracer speed is
illustrative, not physiological. The tracer follows one representative lung branch;
the second lung and extra tissue branches remain connected.
</div>
</section>
<section id="statusPanel" class="panel">
<div class="status-head">
<span id="statusDot"></span>
<div id="statusTitle">Tracer in right heart → pulmonary trunk</div>
</div>
<div id="statusDetail"></div>
<div id="statusNext"></div>
<div class="progress-track"><div id="progressBar"></div></div>
</section>
<section id="controls" class="panel">
<div class="control-row">
<button id="playBtn" type="button">Pause tracer</button>
<button id="continueBtn" type="button" disabled>Continue at junction</button>
</div>
<div class="speed-row">
<label for="speed">Slow speed</label>
<input id="speed" type="range" min="0.5" max="2" step="0.1" value="1">
<output id="speedValue">1.0×</output>
</div>
<div class="control-row" style="margin-top:9px">
<button id="resetBtn" type="button" style="flex:1">Restart loop</button>
<button id="cameraBtn" type="button" style="flex:1">Reset camera</button>
</div>
<div class="camera-help">Drag to orbit · wheel/pinch to zoom · click P1–P7 to inspect</div>
</section>
</div>
<div id="worldLabels"></div>
<div id="checkpointLabels"></div>
<div id="tracerTag">TRACER</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111b);
scene.fog = new THREE.Fog(0x07111b, 18, 34);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.18;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
target: new THREE.Vector3(0, 1.25, 0),
yaw: 0.12,
pitch: 0.34,
radius: 15.7
};
function updateCamera() {
const { target, yaw, pitch, radius } = cameraState;
camera.position.set(
target.x + radius * Math.sin(yaw) * Math.cos(pitch),
target.y + radius * Math.sin(pitch),
target.z + radius * Math.cos(yaw) * Math.cos(pitch)
);
camera.lookAt(target);
}
updateCamera();
scene.add(new THREE.HemisphereLight(0xb9e6ff, 0x172331, 2.0));
const keyLight = new THREE.DirectionalLight(0xffffff, 2.8);
keyLight.position.set(-5, 10, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -5;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x358dff, 28, 18, 2);
rimLight.position.set(-5, 4, -3);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xff536f, 22, 16, 2);
warmLight.position.set(6, 3, 4);
scene.add(warmLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 30),
new THREE.MeshStandardMaterial({
color: 0x09141e,
roughness: 0.94,
metalness: 0.02
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.26;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(30, 30, 0x294257, 0x142a3a);
grid.position.y = -0.245;
grid.material.transparent = true;
grid.material.opacity = 0.6;
scene.add(grid);
const routeGroup = new THREE.Group();
const branchGroup = new THREE.Group();
scene.add(routeGroup, branchGroup);
const DEOXY = new THREE.Color(0x39a9ff);
const OXY = new THREE.Color(0xff6078);
const GOLD = new THREE.Color(0xffd166);
// -------------------------------------------------------------------------
// Small construction helpers
// -------------------------------------------------------------------------
function vec(x, y, z) {
return new THREE.Vector3(x, y, z);
}
function addBox(parent, x, y, z, sx, sy, sz, material, edgeOpacity = 0.25) {
const geometry = new THREE.BoxGeometry(sx, sy, sz);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
if (edgeOpacity > 0) {
const edge = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry),
new THREE.LineBasicMaterial({
color: 0xbdd8ea,
transparent: true,
opacity: edgeOpacity
})
);
edge.position.copy(mesh.position);
parent.add(edge);
}
return mesh;
}
function addPlatform(x, z, width, depth, color) {
const mat = new THREE.MeshStandardMaterial({
color,
roughness: 0.8,
metalness: 0.08,
transparent: true,
opacity: 0.46
});
addBox(scene, x, -0.08, z, width, 0.22, depth, mat, 0.16);
}
function curveFrom(points) {
return new THREE.CatmullRomCurve3(
points.map(p => p.clone()),
false,
"centripetal"
);
}
function makeTube(parent, points, options = {}) {
const curve = curveFrom(points);
const segments = options.segments ?? Math.max(24, Math.ceil(curve.getLength() * 11));
const radialSegments = options.radialSegments ?? 6;
const radius = options.radius ?? 0.085;
const start = new THREE.Color(options.start ?? 0x39a9ff);
const end = new THREE.Color(options.end ?? options.start ?? 0x39a9ff);
const geometry = new THREE.TubeGeometry(
curve,
segments,
radius,
radialSegments,
false
);
// Color every ring, producing a true blue-to-red capillary transition.
const colors = [];
const color = new THREE.Color();
for (let i = 0; i <= segments; i++) {
color.copy(start).lerp(end, i / segments);
for (let j = 0; j <= radialSegments; j++) {
colors.push(color.r, color.g, color.b);
}
}
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
roughness: 0.47,
metalness: 0.03,
emissive: 0x000000,
emissiveIntensity: 0
});
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.renderOrder = 4;
parent.add(mesh);
let highlight = null;
if (options.highlight !== false) {
const highlightGeometry = new THREE.TubeGeometry(
curve,
segments,
radius * 1.62,
radialSegments,
false
);
highlight = new THREE.Mesh(
highlightGeometry,
new THREE.MeshBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.12,
depthWrite: false
})
);
highlight.visible = false;
highlight.renderOrder = 3;
parent.add(highlight);
}
let arrow = null;
if (options.arrow !== false) {
const arrowColor = start.clone().lerp(end, 0.55);
arrow = new THREE.Mesh(
new THREE.ConeGeometry(radius * 1.55, radius * 3.4, 6),
new THREE.MeshBasicMaterial({ color: arrowColor })
);
arrow.position.copy(curve.getPointAt(0.58));
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
curve.getTangentAt(0.58).normalize()
);
arrow.renderOrder = 5;
parent.add(arrow);
}
return {
curve,
mesh,
material,
highlight,
arrow,
length: curve.getLength()
};
}
function makeVoxelLung(cx, cz, tint) {
const material = new THREE.MeshStandardMaterial({
color: tint,
roughness: 0.93,
metalness: 0,
transparent: true,
opacity: 0.21,
depthWrite: false
});
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x9ed8ff,
transparent: true,
opacity: 0.2
});
for (let iy = 0; iy < 8; iy++) {
for (let ix = -2; ix <= 2; ix++) {
for (let iz = -1; iz <= 1; iz++) {
const taper = 1 - Math.abs(ix + 0.5) / 4.8;
const y = 0.36 + iy * 0.31;
const shape = (ix * ix) / 5.2 + ((y - 1.45) ** 2) / 4.3;
const depth = iz === 0 ? 0 : 0.26;
if (shape > 1.12 + taper * 0.1) continue;
// Sparse front layer preserves a clear view through the lung.
if (iz === 1 && Math.abs(ix) < 1 && iy > 1 && iy < 6) continue;
const x = cx + ix * 0.34;
const z = cz + iz * 0.25;
const geometry = new THREE.BoxGeometry(0.31, 0.28, 0.25);
const cube = new THREE.Mesh(geometry, material);
cube.position.set(x, y, z);
cube.renderOrder = 1;
scene.add(cube);
const edge = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry),
edgeMaterial
);
edge.position.copy(cube.position);
edge.renderOrder = 2;
scene.add(edge);
}
}
}
}
function makeTissueCluster(cx, cy, cz, color = 0x78879b) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0.05
});
const cells = [
[-0.24, 0.12, 0], [0.02, 0.12, 0], [0.27, 0.12, 0],
[-0.12, -0.12, 0], [0.15, -0.12, 0], [0.02, 0.36, 0],
[-0.12, -0.36, 0], [0.16, -0.36, 0]
];
for (const [x, y, z] of cells) {
addBox(
scene,
cx + x,
cy + y,
cz + z,
0.21,
0.21,
0.28,
material,
0.3
);
}
}
// -------------------------------------------------------------------------
// Exhibit architecture
// -------------------------------------------------------------------------
addPlatform(-3.3, -0.25, 3.55, 1.65, 0x153b55);
addPlatform(0, 0.45, 2.55, 1.75, 0x263c50);
addPlatform(4.55, 0.45, 2.75, 2.0, 0x4b2834);
makeVoxelLung(-4.22, -0.48, 0x448baa);
makeVoxelLung(-2.38, -0.48, 0x448baa);
// Open, block-built heart: the visible chamber colors define its two sides.
const heartCellMaterial = new THREE.MeshStandardMaterial({
color: 0x35485c,
roughness: 0.85,
metalness: 0.03,
transparent: true,
opacity: 0.58,
depthWrite: false
});
const heartRows = [
[2.12, [-0.72, 0, 0.72]],
[1.72, [-0.9, -0.45, 0, 0.45, 0.9]],
[1.32, [-0.9, -0.45, 0, 0.45, 0.9]],
[0.92, [-0.72, -0.3, 0.3, 0.72]],
[0.52, [-0.4, 0.4]]
];
for (const [y, xs] of heartRows) {
for (const x of xs) {
addBox(scene, x, y, 0.42, 0.43, 0.42, 0.58, heartCellMaterial, 0.18);
}
}
const rightChamberMaterial = new THREE.MeshStandardMaterial({
color: 0x197fbd,
emissive: 0x082b45,
emissiveIntensity: 0.5,
roughness: 0.45,
transparent: true,
opacity: 0.88
});
const leftChamberMaterial = new THREE.MeshStandardMaterial({
color: 0xc83f58,
emissive: 0x4a0c1a,
emissiveIntensity: 0.5,
roughness: 0.45,
transparent: true,
opacity: 0.88
});
addBox(scene, -0.55, 1.52, 0.9, 0.57, 0.64, 0.3, rightChamberMaterial, 0.28);
addBox(scene, -0.55, 0.83, 0.9, 0.57, 0.64, 0.3, rightChamberMaterial, 0.28);
addBox(scene, 0.55, 1.52, 0.9, 0.57, 0.64, 0.3, leftChamberMaterial, 0.28);
addBox(scene, 0.55, 0.83, 0.9, 0.57, 0.64, 0.3, leftChamberMaterial, 0.28);
// -------------------------------------------------------------------------
// Main continuous tracer route
// -------------------------------------------------------------------------
const RA = vec(-0.55, 1.52, 1.22);
const RV = vec(-0.55, 0.83, 1.22);
const TRUNK = vec(-0.15, 2.55, 1.08);
const SPLIT = vec(-3.12, 2.62, 0.26);
const LUNG_IN = vec(-2.38, 2.04, 0.36);
const LUNG_OUT = vec(-2.38, 1.05, 0.36);
const PV = vec(-1.12, 1.64, 0.91);
const LA = vec(0.55, 1.52, 1.22);
const LV = vec(0.55, 0.83, 1.22);
const AORTA = vec(0.55, 2.91, 0.98);
const SYS_ART = vec(4.12, 2.28, 0.86);
const TISSUE_IN = vec(4.56, 1.64, 0.68);
const TISSUE_OUT = vec(3.65, 0.55, 0.72);
const VENOUS = vec(1.32, 0.55, 0.96);
const sectionDefinitions = [
{
name: "Right heart → pulmonary trunk",
short: "Right heart → trunk",
points: [RA, RV, TRUNK, SPLIT],
start: DEOXY,
end: DEOXY,
radius: 0.09
},
{
name: "Pulmonary artery → lung inlet",
short: "Pulmonary artery",
points: [SPLIT, vec(-3.18, 2.54, 0.25), LUNG_IN],
start: DEOXY,
end: DEOXY,
radius: 0.082
},
{
name: "Lung capillary exchange",
short: "Lung capillary",
points: [
LUNG_IN,
vec(-2.18, 1.79, 0.44),
vec(-2.62, 1.35, 0.43),
LUNG_OUT
],
start: DEOXY,
end: OXY,
radius: 0.074
},
{
name: "Pulmonary vein → left heart → aorta",
short: "Pulmonary vein → left heart",
points: [LUNG_OUT, PV, LA, LV, AORTA],
start: OXY,
end: OXY,
radius: 0.088
},
{
name: "Systemic artery → body tissue",
short: "Systemic artery",
points: [
AORTA,
vec(1.75, 3.02, 0.88),
vec(3.18, 2.72, 0.88),
SYS_ART,
TISSUE_IN
],
start: OXY,
end: OXY,
radius: 0.086
},
{
name: "Body tissue capillary exchange",
short: "Tissue capillary",
points: [
TISSUE_IN,
vec(4.78, 1.22, 0.58),
vec(4.12, 0.73, 0.52),
TISSUE_OUT
],
start: OXY,
end: DEOXY,
radius: 0.075
},
{
name: "Systemic vein → right atrium",
short: "Systemic vein → RA",
points: [
TISSUE_OUT,
vec(2.65, 0.45, 0.84),
VENOUS,
RA
],
start: DEOXY,
end: DEOXY,
radius: 0.088
}
];
const sections = sectionDefinitions.map(def => ({
...def,
...makeTube(routeGroup, def.points, {
start: def.start,
end: def.end,
radius: def.radius,
segments: 70
})
}));
// -------------------------------------------------------------------------
// Additional connected branches: the unused lung and several body tissues
// -------------------------------------------------------------------------
const lungAIn = vec(-4.22, 2.03, 0.30);
const lungAOut = vec(-4.22, 1.03, 0.30);
makeTube(branchGroup, [
SPLIT,
vec(-3.72, 2.62, 0.18),
vec(-4.12, 2.34, 0.22),
lungAIn
], {
start: DEOXY,
end: DEOXY,
radius: 0.057,
segments: 42
});
makeTube(branchGroup, [
lungAIn,
vec(-4.45, 1.75, 0.40),
vec(-4.05, 1.28, 0.40),
lungAOut
], {
start: DEOXY,
end: OXY,
radius: 0.052,
segments: 42
});
makeTube(branchGroup, [
lungAOut,
vec(-3.42, 1.42, 0.43),
vec(-1.74, 1.48, 0.66),
PV
], {
start: OXY,
end: OXY,
radius: 0.057,
segments: 42
});
const tissueClusters = [
vec(5.25, 2.32, 0.02),
vec(5.22, 1.18, -0.04),
vec(3.67, 1.52, 0.02),
vec(4.55, 1.64, 0.20)
];
tissueClusters.forEach((cluster, index) => {
makeTissueCluster(cluster.x, cluster.y, cluster.z, index === 3 ? 0x8b6173 : 0x6f7f91);
if (index < 3) {
makeTube(branchGroup, [
SYS_ART,
vec(4.62, 2.36, 0.48),
cluster
], {
start: OXY,
end: OXY,
radius: 0.048,
segments: 34
});
makeTube(branchGroup, [
cluster,
vec(3.82 + index * 0.18, 0.88 + index * 0.18, 0.45),
VENOUS
], {
start: DEOXY,
end: DEOXY,
radius: 0.048,
segments: 34
});
}
});
// -------------------------------------------------------------------------
// Checkpoint markers
// -------------------------------------------------------------------------
const checkpointNames = [
"Pulmonary trunk / lung split",
"Lung capillary inlet",
"Pulmonary vein outlet",
"Aortic outflow",
"Tissue capillary inlet",
"Tissue capillary outlet",
"Vena cava / right atrium"
];
const checkpointDescriptions = [
"The pulmonary trunk divides toward both connected lung beds.",
"The representative lung branch enters its capillary bed.",
"Oxygenated blood leaves the lung through the pulmonary vein.",
"The left ventricle pumps into the systemic arterial route.",
"Systemic arterial blood reaches a representative tissue bed.",
"Deoxygenated blood leaves the tissue bed into systemic veins.",
"Systemic venous blood returns to the right atrium, closing the loop."
];
const checkpointLabels = document.getElementById("checkpointLabels");
const checkpoints = [];
const checkpointHitMeshes = [];
function makeCheckpoint(point, index) {
const group = new THREE.Group();
const anchor = point.clone().add(vec(0, 0.28, 0.28));
group.position.copy(anchor);
scene.add(group);
const stemGeometry = new THREE.BufferGeometry().setFromPoints([
point,
anchor
]);
scene.add(new THREE.Line(
stemGeometry,
new THREE.LineBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.65
})
));
const gem = new THREE.Mesh(
new THREE.OctahedronGeometry(0.115, 0),
new THREE.MeshStandardMaterial({
color: 0xffd166,
emissive: 0xff9f2d,
emissiveIntensity: 0.65,
roughness: 0.35,
metalness: 0.25
})
);
gem.userData.checkpointIndex = index;
group.add(gem);
checkpointHitMeshes.push(gem);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.19, 0.022, 6, 20),
new THREE.MeshBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.72
})
);
group.add(ring);
const tag = document.createElement("button");
tag.className = "checkpoint-tag";
tag.type = "button";
tag.textContent = `P${index + 1}`;
tag.title = `${checkpointNames[index]} — click to inspect`;
tag.setAttribute("aria-label", tag.title);
tag.addEventListener("click", event => {
event.stopPropagation();
inspectCheckpoint(index);
});
checkpointLabels.appendChild(tag);
checkpoints.push({
point: point.clone(),
anchor,
group,
gem,
ring,
tag
});
}
sections.forEach((section, index) => {
makeCheckpoint(section.curve.getPointAt(1), index);
});
// -------------------------------------------------------------------------
// World labels
// -------------------------------------------------------------------------
const worldLabels = [];
function makeWorldLabel(text, subtitle, position, className = "") {
const element = document.createElement("div");
element.className = `world-label ${className}`;
element.innerHTML = `${text}${subtitle ? `<small>${subtitle}</small>` : ""}`;
document.getElementById("worldLabels").appendChild(element);
worldLabels.push({ element, position: position.clone() });
}
makeWorldLabel("PAIRED LUNGS", "voxel capillary beds", vec(-3.35, 3.18, -0.1), "blue");
makeWorldLabel("RIGHT HEART", "deoxygenated", vec(-1.08, 0.76, 1.35), "blue");
makeWorldLabel("LEFT HEART", "oxygenated", vec(1.08, 0.76, 1.35), "red");
makeWorldLabel("BODY NETWORK", "arteries · tissues · veins", vec(4.67, 2.96, 0.3), "red");
// -------------------------------------------------------------------------
// Tracer and trail
// -------------------------------------------------------------------------
const tracer = new THREE.Group();
scene.add(tracer);
const tracerCore = new THREE.Mesh(
new THREE.SphereGeometry(0.13, 16, 12),
new THREE.MeshStandardMaterial({
color: 0xffd166,
emissive: 0xff9f2d,
emissiveIntensity: 2.4,
roughness: 0.25,
metalness: 0.15
})
);
tracer.add(tracerCore);
const tracerHalo = new THREE.Mesh(
new THREE.TorusGeometry(0.21, 0.023, 6, 24),
new THREE.MeshBasicMaterial({
color: 0xffe4a0,
transparent: true,
opacity: 0.85
})
);
tracer.add(tracerHalo);
const tracerLight = new THREE.PointLight(0xffc65c, 7, 2.4, 2);
tracer.add(tracerLight);
const trailPositions = new Float32Array(120 * 3);
const trailGeometry = new THREE.BufferGeometry();
trailGeometry.setAttribute(
"position",
new THREE.BufferAttribute(trailPositions, 3)
);
trailGeometry.setDrawRange(0, 0);
const trail = new THREE.Line(
trailGeometry,
new THREE.LineBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.72
})
);
trail.frustumCulled = false;
scene.add(trail);
const trailHistory = [];
const lastTrailPoint = new THREE.Vector3(999, 999, 999);
// -------------------------------------------------------------------------
// Animation state
// -------------------------------------------------------------------------
let activeSection = 0;
let sectionDistance = 0;
let speedMultiplier = 1;
let userPaused = false;
let waitingAtJunction = false;
let inspectionIndex = -1;
const baseTracerSpeed = 0.38; // schematic world units per second
const playBtn = document.getElementById("playBtn");
const continueBtn = document.getElementById("continueBtn");
const resetBtn = document.getElementById("resetBtn");
const cameraBtn = document.getElementById("cameraBtn");
const speedInput = document.getElementById("speed");
const speedValue = document.getElementById("speedValue");
const statusTitle = document.getElementById("statusTitle");
const statusDetail = document.getElementById("statusDetail");
const statusNext = document.getElementById("statusNext");
const statusDot = document.getElementById("statusDot");
const progressBar = document.getElementById("progressBar");
const tracerTag = document.getElementById("tracerTag");
function nextSectionIndex() {
return (activeSection + 1) % sections.length;
}
function updateMarkerClasses() {
checkpoints.forEach((checkpoint, index) => {
checkpoint.tag.classList.toggle(
"waiting",
waitingAtJunction && index === activeSection
);
checkpoint.tag.classList.toggle(
"selected",
inspectionIndex === index || (waitingAtJunction && index === activeSection)
);
});
}
function renderStatus() {
const section = sections[activeSection];
const next = sections[nextSectionIndex()];
if (waitingAtJunction) {
statusTitle.textContent =
`Paused at P${activeSection + 1} · ${checkpointNames[activeSection]}`;
statusDetail.textContent =
`Completed: ${section.name}. Inspect this junction and its connected vessels.`;
statusNext.innerHTML =
`<strong>Next:</strong> ${next.name}`;
statusDot.style.background = "#ffd166";
statusDot.style.boxShadow = "0 0 14px #ffd166";
} else if (inspectionIndex >= 0) {
statusTitle.textContent =
`Inspecting P${inspectionIndex + 1} · ${checkpointNames[inspectionIndex]}`;
statusDetail.textContent = checkpointDescriptions[inspectionIndex];
statusNext.innerHTML =
`<strong>Connected next:</strong> ${sections[(inspectionIndex + 1) % sections.length].name}`;
statusDot.style.background = "#a982ff";
statusDot.style.boxShadow = "0 0 14px #a982ff";
} else if (userPaused) {
statusTitle.textContent = `Paused in ${section.name}`;
statusDetail.textContent = "The highlighted vessel region remains active.";
statusNext.innerHTML = `<strong>Next:</strong> ${next.name}`;
statusDot.style.background = "#a982ff";
statusDot.style.boxShadow = "0 0 14px #a982ff";
} else {
statusTitle.textContent = `Tracer in ${section.name}`;
statusDetail.textContent =
"Follow the gold tracer and the highlighted connected vessel segment.";
statusNext.innerHTML =
`<strong>Next junction:</strong> P${activeSection + 1} · ${checkpointNames[activeSection]}`;
statusDot.style.background = "#ffd166";
statusDot.style.boxShadow = "0 0 14px #ffd166";
}
playBtn.textContent = waitingAtJunction
? "Junction pause"
: userPaused
? "Resume tracer"
: "Pause tracer";
playBtn.disabled = waitingAtJunction;
continueBtn.disabled = !waitingAtJunction;
continueBtn.textContent = waitingAtJunction
? `Continue → ${next.short}`
: "Continue at junction";
tracerTag.textContent = section.short.toUpperCase();
updateMarkerClasses();
}
function inspectCheckpoint(index) {
inspectionIndex = index;
userPaused = true;
renderStatus();
}
function continueFromJunction() {
if (!waitingAtJunction) return;
activeSection = nextSectionIndex();
sectionDistance = 0;
waitingAtJunction = false;
userPaused = false;
inspectionIndex = -1;
renderStatus();
}
function resetTracer() {
activeSection = 0;
sectionDistance = 0;
waitingAtJunction = false;
userPaused = false;
inspectionIndex = -1;
trailHistory.length = 0;
trailGeometry.setDrawRange(0, 0);
lastTrailPoint.set(999, 999, 999);
renderStatus();
}
playBtn.addEventListener("click", () => {
if (waitingAtJunction) return;
userPaused = !userPaused;
inspectionIndex = -1;
renderStatus();
});
continueBtn.addEventListener("click", continueFromJunction);
resetBtn.addEventListener("click", resetTracer);
speedInput.addEventListener("input", () => {
speedMultiplier = Number(speedInput.value);
speedValue.textContent = `${speedMultiplier.toFixed(1)}×`;
});
cameraBtn.addEventListener("click", () => {
cameraState.yaw = 0.12;
cameraState.pitch = 0.34;
cameraState.radius = 15.7;
updateCamera();
});
renderStatus();
// -------------------------------------------------------------------------
// Direct camera controls — no Three.js addons
// -------------------------------------------------------------------------
let pointerDown = false;
let pointerMoved = false;
let previousX = 0;
let previousY = 0;
let downX = 0;
let downY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
pointerDown = true;
pointerMoved = false;
previousX = event.clientX;
previousY = event.clientY;
downX = event.clientX;
downY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointerDown) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
if (Math.hypot(event.clientX - downX, event.clientY - downY) > 4) {
pointerMoved = true;
}
cameraState.yaw -= dx * 0.005;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.004,
0.08,
1.05
);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
renderer.domElement.addEventListener("pointerup", event => {
pointerDown = false;
if (!pointerMoved) {
const bounds = renderer.domElement.getBoundingClientRect();
const mouse = new THREE.Vector2(
((event.clientX - bounds.left) / bounds.width) * 2 - 1,
-((event.clientY - bounds.top) / bounds.height) * 2 + 1
);
const raycaster = new THREE.Raycaster();
raycaster.setFromCamera(mouse, camera);
const hit = raycaster.intersectObjects(checkpointHitMeshes, false)[0];
if (hit) {
inspectCheckpoint(hit.object.userData.checkpointIndex);
}
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
10,
24
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => {
cameraState.yaw = 0.12;
cameraState.pitch = 0.34;
cameraState.radius = 15.7;
updateCamera();
});
// -------------------------------------------------------------------------
// Projection helpers for HTML labels
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function projectToScreen(position) {
projected.copy(position).project(camera);
return {
x: (projected.x * 0.5 + 0.5) * window.innerWidth,
y: (-projected.y * 0.5 + 0.5) * window.innerHeight,
visible: projected.z > -1 && projected.z < 1
};
}
function updateProjectedLabels() {
for (const label of worldLabels) {
const p = projectToScreen(label.position);
label.element.style.display = p.visible ? "block" : "none";
label.element.style.left = `${p.x}px`;
label.element.style.top = `${p.y}px`;
}
checkpoints.forEach(checkpoint => {
const p = projectToScreen(checkpoint.anchor);
checkpoint.tag.style.display = p.visible ? "grid" : "none";
checkpoint.tag.style.left = `${p.x}px`;
checkpoint.tag.style.top = `${p.y}px`;
});
const tracerPosition = projectToScreen(tracer.position);
tracerTag.style.display = tracerPosition.visible ? "block" : "none";
tracerTag.style.left = `${tracerPosition.x}px`;
tracerTag.style.top = `${tracerPosition.y - 27}px`;
}
// -------------------------------------------------------------------------
// Main loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function updateTracer(dt) {
const section = sections[activeSection];
if (!userPaused && !waitingAtJunction) {
sectionDistance += baseTracerSpeed * speedMultiplier * dt;
if (sectionDistance >= section.length) {
sectionDistance = section.length;
waitingAtJunction = true;
inspectionIndex = -1;
renderStatus();
}
}
const t = THREE.MathUtils.clamp(
sectionDistance / section.length,
0,
1
);
const point = section.curve.getPointAt(t);
tracer.position.copy(point);
if (
!userPaused &&
!waitingAtJunction &&
point.distanceToSquared(lastTrailPoint) > 0.0013
) {
trailHistory.push(point.clone());
if (trailHistory.length > 120) trailHistory.shift();
lastTrailPoint.copy(point);
}
trailHistory.forEach((trailPoint, index) => {
trailPositions[index * 3] = trailPoint.x;
trailPositions[index * 3 + 1] = trailPoint.y;
trailPositions[index * 3 + 2] = trailPoint.z;
});
trailGeometry.attributes.position.needsUpdate = true;
trailGeometry.setDrawRange(0, trailHistory.length);
sections.forEach((routeSection, index) => {
const active = index === activeSection;
routeSection.highlight.visible = active;
routeSection.material.emissive.setHex(0xffb84d);
routeSection.material.emissiveIntensity = active ? 0.36 : 0;
if (routeSection.arrow) {
routeSection.arrow.scale.setScalar(active ? 1.16 : 0.93);
}
});
progressBar.style.width = `${t * 100}%`;
}
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
updateTracer(dt);
const time = clock.elapsedTime;
tracerHalo.rotation.z = time * 1.8;
tracerHalo.rotation.y = Math.sin(time * 2) * 0.25;
tracerCore.scale.setScalar(1 + Math.sin(time * 5) * 0.08);
checkpoints.forEach((checkpoint, index) => {
checkpoint.ring.rotation.z = time * 0.7 + index;
const active = waitingAtJunction && index === activeSection;
const selected = inspectionIndex === index;
const pulse = active
? 1.15 + Math.sin(time * 5) * 0.16
: selected
? 1.08
: 1;
checkpoint.group.scale.setScalar(pulse);
checkpoint.gem.material.emissiveIntensity =
active || selected ? 1.15 : 0.58;
});
updateProjectedLabels();
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
document.getElementById("loading").style.display = "none";
animate();
</script>
</body>
</html>
```