Prompt specification
Build or customize the Three.js 3D scene "Muscle tissue supply diorama" 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: Muscle tissue supply diorama
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/muscle-tissue-supply-diorama-x0967
Scene Description Prompt:
Voxel muscle fibers sit within capillary loops, with enlarged exchange insets showing tissue proximity. Create one HTML file using Three.js from cdnjs.
Working Three.js Starter (muscle-tissue-supply-diorama-x0967):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Muscle Capillary Exchange</title>
<style>
:root {
--bg: #061019;
--panel: #0b1824;
--panel-soft: #0e1d2a;
--line: rgba(155, 205, 225, 0.14);
--text: #edf8fb;
--muted: #8ca7b4;
--cyan: #62e6ef;
--blue: #468dff;
--red: #ff6574;
--coral: #f58d86;
--amber: #ffc568;
--green: #7ce7b7;
}
* {
box-sizing: border-box;
}
html {
color-scheme: dark;
}
body {
margin: 0;
min-width: 320px;
background:
radial-gradient(circle at 18% -10%, rgba(62, 167, 187, 0.15), transparent 35%),
radial-gradient(circle at 95% 20%, rgba(71, 91, 180, 0.12), transparent 32%),
var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
-webkit-font-smoothing: antialiased;
}
button,
canvas {
-webkit-tap-highlight-color: transparent;
}
button {
font: inherit;
}
.app {
width: min(1580px, 100%);
margin: 0 auto;
padding: 28px;
}
.masthead {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
gap: 30px;
align-items: end;
padding: 8px 4px 26px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 13px;
color: var(--cyan);
font-size: 0.7rem;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 26px;
height: 1px;
background: var(--cyan);
content: "";
box-shadow: 0 0 10px rgba(98, 230, 239, 0.8);
}
h1 {
max-width: 780px;
margin: 0;
font-size: clamp(2.35rem, 4.5vw, 4.7rem);
font-weight: 580;
letter-spacing: -0.055em;
line-height: 0.97;
}
h1 span {
color: #91aeba;
font-weight: 380;
}
.subtitle {
max-width: 670px;
margin: 18px 0 0;
color: var(--muted);
font-size: clamp(0.92rem, 1.3vw, 1.05rem);
line-height: 1.65;
}
.model-stats {
display: grid;
grid-template-columns: repeat(3, auto);
gap: 1px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--line);
}
.stat {
min-width: 112px;
padding: 16px 18px;
background: rgba(10, 24, 34, 0.82);
backdrop-filter: blur(14px);
}
.stat strong,
.stat small {
display: block;
}
.stat strong {
font-size: 0.92rem;
font-weight: 650;
}
.stat small {
margin-top: 5px;
color: var(--muted);
font-size: 0.66rem;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.layout {
display: grid;
grid-template-columns: minmax(0, 1fr) 390px;
gap: 18px;
align-items: stretch;
}
.stage {
position: relative;
min-height: 690px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 28px;
background:
radial-gradient(circle at 50% 42%, rgba(38, 100, 119, 0.19), transparent 43%),
linear-gradient(145deg, rgba(13, 31, 43, 0.98), rgba(6, 15, 24, 0.98));
box-shadow:
0 30px 80px rgba(0, 0, 0, 0.32),
inset 0 1px rgba(255, 255, 255, 0.025);
isolation: isolate;
}
.stage::before {
position: absolute;
inset: 0;
z-index: -1;
background-image:
radial-gradient(circle, rgba(145, 201, 217, 0.26) 0 1px, transparent 1.5px),
radial-gradient(circle, rgba(145, 201, 217, 0.13) 0 1px, transparent 1.5px);
background-position: 0 0, 27px 31px;
background-size: 68px 68px, 91px 91px;
opacity: 0.24;
content: "";
mask-image: linear-gradient(to bottom, transparent, black 25%, black 75%, transparent);
}
#scene {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene.dragging {
cursor: grabbing;
}
.stage-top {
position: absolute;
top: 20px;
left: 20px;
right: 20px;
z-index: 4;
display: flex;
align-items: center;
justify-content: space-between;
gap: 15px;
pointer-events: none;
}
.live-pill,
.orbit-pill {
display: inline-flex;
align-items: center;
gap: 9px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(6, 17, 26, 0.7);
color: #b7cbd3;
font-size: 0.67rem;
font-weight: 680;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(12px);
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 12px rgba(124, 231, 183, 0.85);
animation: pulse 2.2s ease-in-out infinite;
}
@keyframes pulse {
50% {
opacity: 0.42;
transform: scale(0.75);
}
}
.orbit-pill {
color: var(--muted);
}
.leaders {
position: absolute;
inset: 0;
z-index: 2;
width: 100%;
height: 100%;
overflow: visible;
pointer-events: none;
transition: opacity 220ms ease;
}
.leaders line {
stroke: rgba(160, 217, 231, 0.48);
stroke-width: 1;
stroke-dasharray: 3 4;
}
.leaders circle {
fill: var(--cyan);
stroke: rgba(255, 255, 255, 0.85);
stroke-width: 1;
filter: drop-shadow(0 0 4px rgba(98, 230, 239, 0.9));
}
.annotation {
position: absolute;
z-index: 3;
min-width: 130px;
padding: 9px 11px;
transform: translate(-50%, -50%);
border: 1px solid rgba(148, 205, 220, 0.17);
border-radius: 10px;
background: rgba(6, 17, 26, 0.76);
color: #d8e8ed;
font-size: 0.68rem;
font-weight: 680;
letter-spacing: 0.045em;
line-height: 1.25;
text-align: center;
pointer-events: none;
backdrop-filter: blur(10px);
transition: opacity 200ms ease;
}
.annotation small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 0.57rem;
font-weight: 520;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.stage.labels-off .leaders,
.stage.labels-off .annotation {
opacity: 0;
}
.stage-bottom {
position: absolute;
left: 20px;
right: 20px;
bottom: 18px;
z-index: 4;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 18px;
pointer-events: none;
}
.controls,
.legend {
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(6, 17, 26, 0.74);
backdrop-filter: blur(14px);
}
.controls {
display: flex;
gap: 5px;
padding: 5px;
pointer-events: auto;
}
.control-button {
display: inline-flex;
align-items: center;
gap: 7px;
min-height: 34px;
padding: 0 10px;
border: 0;
border-radius: 9px;
background: transparent;
color: #9eb5bf;
cursor: pointer;
font-size: 0.68rem;
font-weight: 650;
transition: background 160ms ease, color 160ms ease;
}
.control-button:hover,
.control-button[aria-pressed="true"] {
background: rgba(98, 230, 239, 0.09);
color: var(--text);
}
.control-button svg {
width: 14px;
height: 14px;
fill: none;
stroke: currentColor;
stroke-linecap: round;
stroke-linejoin: round;
stroke-width: 1.8;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 13px;
padding: 10px 13px;
color: #a8bdc6;
font-size: 0.63rem;
font-weight: 630;
letter-spacing: 0.035em;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 3px;
}
.swatch.muscle {
background: var(--coral);
box-shadow: 0 0 8px rgba(245, 141, 134, 0.4);
}
.swatch.blood {
background: linear-gradient(90deg, var(--red), var(--blue));
}
.swatch.oxygen {
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 8px rgba(98, 230, 239, 0.65);
}
.swatch.co2 {
border-radius: 50%;
background: var(--amber);
box-shadow: 0 0 8px rgba(255, 197, 104, 0.55);
}
.rail {
display: flex;
flex-direction: column;
gap: 14px;
}
.rail-heading {
display: flex;
align-items: end;
justify-content: space-between;
gap: 15px;
padding: 5px 3px 1px;
}
.rail-heading span {
color: var(--cyan);
font-size: 0.65rem;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.rail-heading p {
margin: 0;
color: var(--muted);
font-size: 0.66rem;
}
.inset-card {
overflow: hidden;
border: 1px solid var(--line);
border-radius: 21px;
background: linear-gradient(150deg, rgba(15, 33, 45, 0.96), rgba(8, 21, 31, 0.96));
box-shadow: 0 20px 45px rgba(0, 0, 0, 0.18);
}
.inset-header {
display: grid;
grid-template-columns: auto 1fr auto;
gap: 11px;
align-items: center;
padding: 16px 16px 12px;
}
.inset-number {
display: grid;
width: 30px;
height: 30px;
place-items: center;
border: 1px solid rgba(98, 230, 239, 0.22);
border-radius: 9px;
background: rgba(98, 230, 239, 0.07);
color: var(--cyan);
font-size: 0.66rem;
font-weight: 760;
}
.inset-header h2 {
margin: 0;
font-size: 0.95rem;
font-weight: 670;
letter-spacing: -0.015em;
}
.inset-header p {
margin: 4px 0 0;
color: var(--muted);
font-size: 0.65rem;
}
.inset-direction {
padding: 5px 7px;
border-radius: 6px;
background: rgba(98, 230, 239, 0.07);
color: var(--cyan);
font-size: 0.56rem;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.inset-card.venous .inset-direction {
background: rgba(255, 197, 104, 0.08);
color: var(--amber);
}
.inset-view {
position: relative;
height: 205px;
margin: 0 10px;
overflow: hidden;
border: 1px solid rgba(155, 205, 225, 0.1);
border-radius: 14px;
background:
radial-gradient(circle at 50% 50%, rgba(38, 98, 116, 0.18), transparent 65%),
rgba(4, 13, 21, 0.4);
}
.inset-view canvas {
display: block;
width: 100%;
height: 100%;
}
.magnify-badge {
position: absolute;
top: 9px;
left: 9px;
padding: 5px 7px;
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 6px;
background: rgba(5, 15, 23, 0.68);
color: #95aeb9;
font-size: 0.54rem;
font-weight: 730;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.distance-label {
position: absolute;
right: 10px;
bottom: 10px;
color: #a8bdc6;
font-size: 0.58rem;
font-weight: 650;
letter-spacing: 0.04em;
}
.distance-label strong {
color: #e6f2f5;
}
.inset-footer {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
padding: 12px;
}
.exchange-stat {
padding: 10px;
border: 1px solid rgba(155, 205, 225, 0.09);
border-radius: 10px;
background: rgba(255, 255, 255, 0.018);
}
.exchange-stat small {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 0.54rem;
font-weight: 700;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.exchange-stat strong {
font-size: 0.67rem;
font-weight: 670;
}
.oxygen-stat strong {
color: var(--cyan);
}
.carbon-stat strong {
color: var(--amber);
}
.note-card {
padding: 18px;
border: 1px solid var(--line);
border-radius: 18px;
background: rgba(12, 28, 39, 0.72);
}
.note-card h3 {
margin: 0 0 10px;
font-size: 0.82rem;
font-weight: 700;
}
.note-card p {
margin: 0;
color: var(--muted);
font-size: 0.7rem;
line-height: 1.65;
}
.process {
display: flex;
align-items: center;
gap: 7px;
margin-top: 14px;
color: #9eb6c0;
font-size: 0.58rem;
font-weight: 680;
}
.process i {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--coral);
}
.process b {
flex: 1;
height: 1px;
background: linear-gradient(90deg, var(--cyan), var(--amber));
}
.footer {
display: flex;
justify-content: space-between;
gap: 20px;
padding: 17px 4px 0;
color: #5f7b87;
font-size: 0.61rem;
letter-spacing: 0.05em;
}
@media (max-width: 1120px) {
.layout {
grid-template-columns: 1fr;
}
.rail {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.rail-heading,
.note-card {
grid-column: 1 / -1;
}
}
@media (max-width: 760px) {
.app {
padding: 17px;
}
.masthead {
grid-template-columns: 1fr;
}
.model-stats {
grid-template-columns: repeat(3, 1fr);
}
.stat {
min-width: 0;
padding: 13px;
}
.stage {
min-height: 560px;
border-radius: 22px;
}
.rail {
grid-template-columns: 1fr;
}
.rail-heading,
.note-card {
grid-column: auto;
}
.legend {
display: none;
}
.orbit-pill {
display: none;
}
.annotation.optional {
display: none;
}
.footer {
flex-direction: column;
gap: 6px;
}
}
@media (max-width: 480px) {
h1 {
font-size: 2.55rem;
}
.model-stats {
display: none;
}
.stage {
min-height: 510px;
}
.stage-top,
.stage-bottom {
left: 12px;
right: 12px;
}
.control-button span {
display: none;
}
}
</style>
</head>
<body>
<main class="app">
<header class="masthead">
<div>
<div class="eyebrow">Microvascular exchange / interactive study</div>
<h1>Where blood meets <span>muscle.</span></h1>
<p class="subtitle">
A voxel-scale view of oxygen-rich blood flowing through capillary loops,
exchanging gases with nearby muscle fibers at a micrometre-scale interface.
</p>
</div>
<div class="model-stats" aria-label="Model information">
<div class="stat">
<strong>Voxel</strong>
<small>Muscle geometry</small>
</div>
<div class="stat">
<strong>Loop</strong>
<small>Capillary network</small>
</div>
<div class="stat">
<strong>2 views</strong>
<small>Exchange close-ups</small>
</div>
</div>
</header>
<section class="layout">
<div class="stage" id="stage">
<canvas id="scene" aria-label="Interactive 3D voxel muscle fibers and capillary loop"></canvas>
<svg class="leaders" id="leaders" aria-hidden="true"></svg>
<div class="annotation" id="label-tissue">
Voxel myofiber
<small>Contractile tissue</small>
</div>
<div class="annotation" id="label-loop">
Capillary loop
<small>Perfusion pathway</small>
</div>
<div class="annotation optional" id="label-flow">
Red blood cells
<small>Directional flow</small>
</div>
<div class="annotation optional" id="label-exchange">
Gas exchange
<small>Diffusion interface</small>
</div>
<div class="stage-top">
<div class="live-pill">
<span class="live-dot"></span>
Live voxel model
</div>
<div class="orbit-pill">Drag to orbit · scroll to zoom</div>
</div>
<div class="stage-bottom">
<div class="controls" aria-label="Scene controls">
<button class="control-button" id="pause-button" type="button" aria-pressed="false">
<svg viewBox="0 0 20 20" aria-hidden="true">
<path d="M7 5v10M13 5v10"></path>
</svg>
<span>Pause flow</span>
</button>
<button class="control-button" id="labels-button" type="button" aria-pressed="true">
<svg viewBox="0 0 20 20" aria-hidden="true">
<path d="M3 4h9l5 5-7 7-7-7z"></path>
<circle cx="7" cy="8" r="1.5"></circle>
</svg>
<span>Labels</span>
</button>
<button class="control-button" id="reset-button" type="button">
<svg viewBox="0 0 20 20" aria-hidden="true">
<path d="M4 7a7 7 0 1 1-.2 5"></path>
<path d="M4 3v4h4"></path>
</svg>
<span>Reset view</span>
</button>
</div>
<div class="legend" aria-label="Scene legend">
<span class="legend-item">
<i class="swatch muscle"></i>
Muscle
</span>
<span class="legend-item">
<i class="swatch blood"></i>
Blood flow
</span>
<span class="legend-item">
<i class="swatch oxygen"></i>
O₂
</span>
<span class="legend-item">
<i class="swatch co2"></i>
CO₂
</span>
</div>
</div>
</div>
<aside class="rail">
<div class="rail-heading">
<span>Exchange insets</span>
<p>Magnified tissue proximity</p>
</div>
<article class="inset-card arterial">
<header class="inset-header">
<div class="inset-number">01</div>
<div>
<h2>Oxygen loading</h2>
<p>Arterial side of the exchange</p>
</div>
<span class="inset-direction">Blood → muscle</span>
</header>
<div class="inset-view">
<canvas id="oxygen-inset" aria-label="Magnified oxygen exchange inset"></canvas>
<span class="magnify-badge">Magnified interface</span>
<span class="distance-label"><strong>Micrometre-scale</strong> proximity</span>
</div>
<div class="inset-footer">
<div class="exchange-stat oxygen-stat">
<small>Direction</small>
<strong>O₂ diffusion outward</strong>
</div>
<div class="exchange-stat">
<small>Blood state</small>
<strong>Oxygen-rich</strong>
</div>
</div>
</article>
<article class="inset-card venous">
<header class="inset-header">
<div class="inset-number">02</div>
<div>
<h2>Carbon dioxide unloading</h2>
<p>Venous side of the exchange</p>
</div>
<span class="inset-direction">Muscle → blood</span>
</header>
<div class="inset-view">
<canvas id="carbon-inset" aria-label="Magnified carbon dioxide exchange inset"></canvas>
<span class="magnify-badge">Magnified interface</span>
<span class="distance-label"><strong>Tight coupling</strong> to tissue</span>
</div>
<div class="inset-footer">
<div class="exchange-stat carbon-stat">
<small>Direction</small>
<strong>CO₂ diffusion inward</strong>
</div>
<div class="exchange-stat">
<small>Blood state</small>
<strong>Deoxygenated</strong>
</div>
</div>
</article>
<article class="note-card">
<h3>Reading the model</h3>
<p>
The block-like tissue represents a voxelized muscle fascicle. The looping
vessel illustrates how capillaries bring blood close enough for rapid
gas exchange without crossing the muscle-fiber membrane.
</p>
<div class="process">
<i></i>
O₂
<b></b>
CO₂
<i style="background: var(--amber)"></i>
</div>
</article>
</aside>
</section>
<footer class="footer">
<span>Conceptual biomedical visualization · geometry and scale are simplified</span>
<span>Three.js core / custom camera controls</span>
</footer>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const TAU = Math.PI * 2;
const Z_AXIS = new THREE.Vector3(0, 0, 1);
const stage = document.getElementById("stage");
const sceneCanvas = document.getElementById("scene");
const leadersSvg = document.getElementById("leaders");
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x07131d, 0.035);
const camera = new THREE.PerspectiveCamera(40, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({
canvas: sceneCanvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setClearColor(0x000000, 0);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.18;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
scene.add(new THREE.HemisphereLight(0xc4f2ff, 0x24121c, 2.2));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.7);
keyLight.position.set(4, 7, 5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.bias = -0.001;
scene.add(keyLight);
const warmLight = new THREE.PointLight(0xff766f, 12, 10, 2);
warmLight.position.set(-4, 0.5, 3);
scene.add(warmLight);
const coolLight = new THREE.PointLight(0x4f91ff, 13, 10, 2);
coolLight.position.set(4, 1, 3);
scene.add(coolLight);
const world = new THREE.Group();
scene.add(world);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.ShadowMaterial({ color: 0x000000, opacity: 0.24 })
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.48;
floor.receiveShadow = true;
world.add(floor);
const grid = new THREE.GridHelper(18, 36, 0x356071, 0x183442);
grid.position.y = -1.46;
grid.material.transparent = true;
grid.material.opacity = 0.18;
grid.material.depthWrite = false;
world.add(grid);
// Voxel muscle fibers: discrete cuboids retain the block-like geometry.
const muscleGroup = new THREE.Group();
muscleGroup.rotation.y = -0.08;
world.add(muscleGroup);
const voxelGeometry = new THREE.BoxGeometry(0.39, 0.52, 0.68);
const voxelEdgeGeometry = new THREE.EdgesGeometry(voxelGeometry);
const voxelEdgeMaterial = new THREE.LineBasicMaterial({
color: 0x6c2838,
transparent: true,
opacity: 0.34
});
const voxelMaterials = [
new THREE.MeshStandardMaterial({
color: 0xee7774,
roughness: 0.78,
metalness: 0.02
}),
new THREE.MeshStandardMaterial({
color: 0xf18a83,
roughness: 0.75,
metalness: 0.02
}),
new THREE.MeshStandardMaterial({
color: 0xdc6870,
roughness: 0.82,
metalness: 0.02
}),
new THREE.MeshStandardMaterial({
color: 0xf59b8f,
roughness: 0.72,
metalness: 0.015
})
];
let voxelIndex = 0;
for (const z of [-0.68, 0.68]) {
for (let i = 0; i < 14; i++) {
const material = voxelMaterials[(voxelIndex * 3 + i) % voxelMaterials.length];
const voxel = new THREE.Mesh(voxelGeometry, material);
voxel.position.set(-2.52 + i * 0.4, 0.66, z);
voxel.castShadow = true;
voxel.receiveShadow = true;
muscleGroup.add(voxel);
const edges = new THREE.LineSegments(voxelEdgeGeometry, voxelEdgeMaterial);
voxel.add(edges);
voxelIndex++;
}
}
// Subtle transverse markings make the long fibers easier to read.
const markingGeometry = new THREE.BoxGeometry(0.055, 0.018, 0.61);
const markingMaterial = new THREE.MeshStandardMaterial({
color: 0x9f3f51,
roughness: 0.9
});
for (const z of [-0.68, 0.68]) {
for (let i = 1; i < 14; i += 2) {
const marking = new THREE.Mesh(markingGeometry, markingMaterial);
marking.position.set(-2.52 + i * 0.4, 0.928, z);
marking.rotation.y = 0.03;
muscleGroup.add(marking);
}
}
// The main capillary loops beneath and around the muscle fibers.
const capillaryCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-3.65, 0.74, 0),
new THREE.Vector3(-3.05, 0.74, 0),
new THREE.Vector3(-2.48, 0.57, 0),
new THREE.Vector3(-2.08, 0.08, 0),
new THREE.Vector3(-1.84, -0.55, 0),
new THREE.Vector3(0, -1.06, 0),
new THREE.Vector3(1.84, -0.55, 0),
new THREE.Vector3(2.08, 0.08, 0),
new THREE.Vector3(2.48, 0.57, 0),
new THREE.Vector3(3.05, 0.74, 0),
new THREE.Vector3(3.65, 0.74, 0)
]);
function makeGradientTube(curve, radius, tubularSegments, radialSegments) {
const geometry = new THREE.TubeGeometry(
curve,
tubularSegments,
radius,
radialSegments,
false
);
const positions = geometry.attributes.position;
const uv = geometry.attributes.uv;
const colors = new Float32Array(positions.count * 3);
const red = new THREE.Color(0xff5365);
const middle = new THREE.Color(0xb07ae8);
const blue = new THREE.Color(0x3f83ff);
const color = new THREE.Color();
for (let i = 0; i < positions.count; i++) {
const t = uv.getX(i);
if (t < 0.5) {
color.copy(red).lerp(middle, t * 2);
} else {
color.copy(middle).lerp(blue, (t - 0.5) * 2);
}
colors[i * 3] = color.r;
colors[i * 3 + 1] = color.g;
colors[i * 3 + 2] = color.b;
}
geometry.setAttribute("color", new THREE.BufferAttribute(colors, 3));
return geometry;
}
const capillary = new THREE.Mesh(
makeGradientTube(capillaryCurve, 0.115, 180, 12),
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.32,
metalness: 0.03,
emissive: 0x28111c,
emissiveIntensity: 0.28
})
);
capillary.castShadow = true;
world.add(capillary);
const capillaryGlow = new THREE.Mesh(
new THREE.TubeGeometry(capillaryCurve, 180, 0.19, 10, false),
new THREE.MeshBasicMaterial({
color: 0x71cfff,
transparent: true,
opacity: 0.055,
depthWrite: false
})
);
world.add(capillaryGlow);
// Distinct arterial and venous entry/exit segments.
const arteryCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-4.3, 0.74, 0),
new THREE.Vector3(-3.95, 0.74, 0),
new THREE.Vector3(-3.58, 0.74, 0)
]);
const veinCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(3.58, 0.74, 0),
new THREE.Vector3(3.95, 0.74, 0),
new THREE.Vector3(4.3, 0.74, 0)
]);
const artery = new THREE.Mesh(
new THREE.TubeGeometry(arteryCurve, 30, 0.118, 12, false),
new THREE.MeshStandardMaterial({
color: 0xff5365,
roughness: 0.34,
emissive: 0x5b1019,
emissiveIntensity: 0.34
})
);
artery.castShadow = true;
world.add(artery);
const vein = new THREE.Mesh(
new THREE.TubeGeometry(veinCurve, 30, 0.118, 12, false),
new THREE.MeshStandardMaterial({
color: 0x3f83ff,
roughness: 0.34,
emissive: 0x102c73,
emissiveIntensity: 0.38
})
);
vein.castShadow = true;
world.add(vein);
// Moving red blood cells.
const bloodCells = [];
const bloodGeometry = new THREE.SphereGeometry(0.09, 14, 10);
for (let i = 0; i < 15; i++) {
const cellMaterial = new THREE.MeshStandardMaterial({
color: i % 3 === 0 ? 0xff9b91 : 0xf14f5f,
roughness: 0.42,
emissive: 0x6d1020,
emissiveIntensity: 0.32
});
const cell = new THREE.Mesh(bloodGeometry, cellMaterial);
cell.scale.set(1, 1, 0.42);
cell.castShadow = true;
world.add(cell);
bloodCells.push(cell);
}
// Small molecules moving across the exchange interface.
const exchangeParticles = [];
const oxygenMaterial = new THREE.MeshBasicMaterial({
color: 0x62e6ef,
transparent: true,
opacity: 0.95
});
const carbonMaterial = new THREE.MeshBasicMaterial({
color: 0xffc568,
transparent: true,
opacity: 0.95
});
for (let i = 0; i < 10; i++) {
const oxygenSide = i < 5;
const particle = new THREE.Mesh(
new THREE.SphereGeometry(0.038, 8, 6),
oxygenSide ? oxygenMaterial : carbonMaterial
);
particle.userData.oxygenSide = oxygenSide;
particle.userData.offset = (i % 5) * 0.17;
particle.userData.x = oxygenSide
? -1.25 + (i % 3) * 0.22
: 0.25 + (i % 3) * 0.25;
world.add(particle);
exchangeParticles.push(particle);
}
// A small pool of red cells below the venous side.
const venousPool = new THREE.Mesh(
new THREE.SphereGeometry(0.12, 16, 12),
new THREE.MeshStandardMaterial({
color: 0xff6670,
roughness: 0.4,
emissive: 0x5a1020,
emissiveIntensity: 0.25
})
);
venousPool.scale.set(1.9, 0.28, 0.75);
venousPool.position.set(3.95, 0.2, 0);
world.add(venousPool);
// Custom camera controls: no addon dependency.
const cameraState = {
theta: 0.43,
phi: 1.17,
radius: 8.75,
target: new THREE.Vector3(0, 0.02, 0)
};
const defaultCamera = { ...cameraState, target: cameraState.target.clone() };
function updateCamera() {
const aspectCompensation = camera.aspect < 1.05 ? 1.2 : 1;
const radius = cameraState.radius * aspectCompensation;
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + radius * Math.cos(cameraState.phi),
cameraState.target.z + radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
sceneCanvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
sceneCanvas.setPointerCapture(event.pointerId);
sceneCanvas.classList.add("dragging");
});
sceneCanvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.48,
2.55
);
});
function endDrag(event) {
dragging = false;
sceneCanvas.classList.remove("dragging");
if (event.pointerId !== undefined && sceneCanvas.hasPointerCapture(event.pointerId)) {
sceneCanvas.releasePointerCapture(event.pointerId);
}
}
sceneCanvas.addEventListener("pointerup", endDrag);
sceneCanvas.addEventListener("pointercancel", endDrag);
sceneCanvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
6.0,
12.5
);
},
{ passive: false }
);
// HTML annotations projected directly from the Three.js scene.
const annotationDefinitions = [
{
element: document.getElementById("label-tissue"),
point: new THREE.Vector3(-1.15, 0.92, 0.68),
offset: new THREE.Vector2(-105, -54)
},
{
element: document.getElementById("label-loop"),
point: new THREE.Vector3(0.75, -1.06, 0),
offset: new THREE.Vector2(70, 60)
},
{
element: document.getElementById("label-flow"),
point: new THREE.Vector3(-2.78, 0.74, 0),
offset: new THREE.Vector2(-90, -55)
},
{
element: document.getElementById("label-exchange"),
point: new THREE.Vector3(-0.2, 0.34, 0),
offset: new THREE.Vector2(115, -30)
}
];
for (const annotation of annotationDefinitions) {
const line = document.createElementNS("http://www.w3.org/2000/svg", "line");
const dot = document.createElementNS("http://www.w3.org/2000/svg", "circle");
dot.setAttribute("r", "3");
leadersSvg.append(line, dot);
annotation.line = line;
annotation.dot = dot;
}
function updateAnnotations() {
const width = stage.clientWidth;
const height = stage.clientHeight;
for (const annotation of annotationDefinitions) {
const projected = annotation.point.clone().project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
const labelX = x + annotation.offset.x;
const labelY = y + annotation.offset.y;
annotation.element.style.left = `${labelX}px`;
annotation.element.style.top = `${labelY}px`;
annotation.line.setAttribute("x1", x);
annotation.line.setAttribute("y1", y);
animationFrame => 0;
annotation.line.setAttribute("x2", labelX);
annotation.line.setAttribute("y2", labelY);
annotation.dot.setAttribute("cx", x);
annotation.dot.setAttribute("cy", y);
const visible =
projected.z > -1 &&
projected.z < 1 &&
x > -40 &&
x < width + 40 &&
y > -40 &&
y < height + 40;
annotation.element.style.visibility = visible ? "visible" : "hidden";
}
}
// A compact 3D inset factory.
function createInset(canvas, mode) {
const insetScene = new THREE.Scene();
const insetCamera = new THREE.PerspectiveCamera(32, 1, 0.1, 50);
insetCamera.position.set(3.0, 1.75, 5.3);
insetCamera.lookAt(0, 0.04, 0);
const insetRenderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
insetRenderer.setClearColor(0x000000, 0);
insetRenderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
insetRenderer.outputColorSpace = THREE.SRGBColorSpace;
insetRenderer.toneMapping = THREE.ACESFilmicToneMapping;
insetRenderer.toneMappingExposure = 1.25;
insetScene.add(
new THREE.HemisphereLight(0xd8f7ff, 0x2c1520, 2.7)
);
const light = new THREE.DirectionalLight(0xffffff, 3.5);
light.position.set(-2, 4, 5);
insetScene.add(light);
const rim = new THREE.PointLight(
mode === "oxygen" ? 0xff6977 : 0x4f8dff,
9,
8,
2
);
rim.position.set(2.5, 0.4, 2);
insetScene.add(rim);
const insetGroup = new THREE.Group();
insetGroup.rotation.y = -0.07;
insetScene.add(insetGroup);
const insetBlockGeometry = new THREE.BoxGeometry(0.38, 0.43, 1.35);
const insetBlockMaterials = [
new THREE.MeshStandardMaterial({
color: 0xef7c79,
roughness: 0.76
}),
new THREE.MeshStandardMaterial({
color: 0xf39489,
roughness: 0.72
}),
new THREE.MeshStandardMaterial({
color: 0xdc6d73,
roughness: 0.8
})
];
for (const y of [0.69, -0.69]) {
for (let i = 0; i < 9; i++) {
const block = new THREE.Mesh(
insetBlockGeometry,
insetBlockMaterials[(i + (y > 0 ? 0 : 1)) % 3]
);
block.position.set(-1.78 + i * 0.445, y, 0);
block.castShadow = true;
insetGroup.add(block);
}
}
const insetCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-2.2, 0, 0),
new THREE.Vector3(-0.8, 0, 0),
new THREE.Vector3(0.8, 0, 0),
new THREE.Vector3(2.2, 0, 0)
]);
const bloodMaterial = new THREE.MeshStandardMaterial({
color: mode === "oxygen" ? 0xff5969 : 0x477ff1,
roughness: 0.3,
emissive: mode === "oxygen" ? 0x65101c : 0x122a75,
emissiveIntensity: 0.38
});
const tube = new THREE.Mesh(
new THREE.TubeGeometry(insetCurve, 90, 0.16, 12, false),
bloodMaterial
);
tube.castShadow = true;
insetGroup.add(tube);
const insetCells = [];
const cellGeometry = new THREE.SphereGeometry(0.105, 14, 10);
for (let i = 0; i < 7; i++) {
const cell = new THREE.Mesh(
cellGeometry,
new THREE.MeshStandardMaterial({
color: mode === "oxygen" ? 0xff9284 : 0xe75a77,
roughness: 0.45,
emissive: 0x5a1020,
emissiveIntensity: 0.25
})
);
cell.scale.set(1, 1, 0.42);
cell.userData.offset = i / 7;
insetGroup.add(cell);
insetCells.push(cell);
}
const arrowColor = mode === "oxygen" ? 0x62e6ef : 0xffc568;
const arrowParticles = [];
const particleGeometry = new THREE.SphereGeometry(0.035, 8, 6);
const particleMaterial = new THREE.MeshBasicMaterial({ color: arrowColor });
for (let i = 0; i < 5; i++) {
const x = -1.45 + i * 0.72;
const direction = mode === "oxygen" ? 1 : -1;
const originY = mode === "oxygen" ? 0.2 : 0.48;
const arrow = new THREE.ArrowHelper(
new THREE.Vector3(0, direction, 0),
new THREE.Vector3(x, originY, 0),
0.3,
arrowColor,
0.1,
0.075
);
insetGroup.add(arrow);
const particle = new THREE.Mesh(particleGeometry, particleMaterial);
particle.userData.x = x;
particle.userData.offset = i * 0.17;
particle.userData.direction = direction;
insetGroup.add(particle);
arrowParticles.push(particle);
}
// Bracket marking the close tissue-capillary distance.
const bracketGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(2.05, 0.19, 0.05),
new THREE.Vector3(2.05, 0.46, 0.05),
new THREE.Vector3(1.96, 0.19, 0.05),
new THREE.Vector3(2.14, 0.19, 0.05),
new THREE.Vector3(1.96, 0.46, 0.05),
new THREE.Vector3(2.14, 0.46, 0.05)
]);
const bracket = new THREE.LineSegments(
bracketGeometry,
new THREE.LineBasicMaterial({
color: 0xaed1da,
transparent: true,
opacity: 0.72
})
);
insetGroup.add(bracket);
function resize() {
const width = canvas.clientWidth;
const height = canvas.clientHeight;
if (!width || !height) return;
insetRenderer.setSize(width, height, false);
insetCamera.aspect = width / height;
insetCamera.updateProjectionMatrix();
}
const observer = new ResizeObserver(resize);
observer.observe(canvas);
resize();
function update(time) {
insetGroup.rotation.y = -0.07 + Math.sin(time * 0.23 + (mode === "oxygen" ? 0 : 1)) * 0.045;
for (let i = 0; i < insetCells.length; i++) {
const t = (time * 0.075 + insetCells[i].userData.offset) % 1;
const point = insetCurve.getPointAt(t);
const tangent = insetCurve.getTangentAt(t).normalize();
insetCells[i].position.copy(point);
insetCells[i].quaternion.setFromUnitVectors(Z_AXIS, tangent);
}
for (const particle of arrowParticles) {
const phase = (time * 0.7 + particle.userData.offset) % 1;
particle.position.x = particle.userData.x;
particle.position.y =
particle.userData.direction > 0
? 0.2 + phase * 0.28
: 0.48 - phase * 0.28;
}
}
return { renderer: insetRenderer, scene: insetScene, camera: insetCamera, update };
}
const oxygenInset = createInset(
document.getElementById("oxygen-inset"),
"oxygen"
);
const carbonInset = createInset(
document.getElementById("carbon-inset"),
"carbon"
);
// UI controls.
let paused = false;
const pauseButton = document.getElementById("pause-button");
const labelsButton = document.getElementById("labels-button");
const resetButton = document.getElementById("reset-button");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.setAttribute("aria-pressed", String(paused));
pauseButton.querySelector("span").textContent = paused ? "Resume flow" : "Pause flow";
pauseButton.querySelector("path").setAttribute(
"d",
paused ? "M6 4l9 6-9 6z" : "M7 5v10M13 5v10"
);
});
labelsButton.addEventListener("click", () => {
const enabled = !stage.classList.contains("labels-off");
stage.classList.toggle("labels-off", enabled);
labelsButton.setAttribute("aria-pressed", String(!enabled));
});
resetButton.addEventListener("click", () => {
cameraState.theta = defaultCamera.theta;
cameraState.phi = defaultCamera.phi;
cameraState.radius = defaultCamera.radius;
cameraState.target.copy(defaultCamera.target);
});
function resizeMain() {
const width = stage.clientWidth;
const height = stage.clientHeight;
if (!width || !height) return;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
leadersSvg.setAttribute("viewBox", `0 0 ${width} ${height}`);
}
const mainObserver = new ResizeObserver(resizeMain);
mainObserver.observe(stage);
resizeMain();
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) elapsed += delta;
const point = new THREE.Vector3();
const tangent = new THREE.Vector3();
for (let i = 0; i < bloodCells.length; i++) {
const t = (elapsed * 0.026 + i / bloodCells.length) % 1;
capillaryCurve.getPointAt(t, point);
capillaryCurve.getTangentAt(t, tangent).normalize();
bloodCells[i].position.copy(point);
bloodCells[i].quaternion.setFromUnitVectors(Z_AXIS, tangent);
}
for (const particle of exchangeParticles) {
const phase = (elapsed * 0.48 + particle.userData.offset) % 1;
particle.position.x = particle.userData.x;
particle.position.y = particle.userData.oxygenSide
? 0.17 + phase * 0.38
: 0.55 - phase * 0.38;
}
oxygenInset.update(elapsed);
carbonInset.update(elapsed);
updateCamera();
updateAnnotations();
renderer.render(scene, camera);
oxygenInset.renderer.render(oxygenInset.scene, oxygenInset.camera);
carbonInset.renderer.render(carbonInset.scene, carbonInset.camera);
}
animate();
</script>
</body>
</html>
```