Prompt specification
Build or customize the Three.js 3D scene "Diffusion near a tissue vessel" 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: Diffusion near a tissue vessel
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/diffusion-near-a-tissue-vessel-x0966
Scene Description Prompt:
Animate labeled oxygen-like tracers moving between a simplified capillary and nearby cells under a stated concentration-gradient rule; distinguish this from a complete circulation model. Build this with Three.js from cdnjs as a cutaway scene in one self-contained HTML file.
Working Three.js Starter (diffusion-near-a-tissue-vessel-x0966):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Oxygen-like tracer exchange — Three.js cutaway</title>
<style>
:root {
color-scheme: dark;
--ink: #e8fbff;
--muted: #99bdc6;
--panel: rgba(5, 18, 25, 0.78);
--line: rgba(125, 226, 234, 0.24);
--cyan: #6be7f2;
--gold: #ffd166;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #06131a;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
display: block;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.panel {
border: 1px solid var(--line);
border-radius: 16px;
background:
linear-gradient(145deg, rgba(14, 42, 51, 0.86), var(--panel));
box-shadow:
0 18px 60px rgba(0, 0, 0, 0.28),
inset 0 1px rgba(255, 255, 255, 0.04);
backdrop-filter: blur(14px);
}
.title-panel {
position: absolute;
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 19px 20px 18px;
}
.eyebrow {
margin-bottom: 7px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(21px, 2.5vw, 31px);
font-weight: 720;
letter-spacing: -0.035em;
line-height: 1.04;
}
.subtitle {
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.rule-panel {
position: absolute;
bottom: 22px;
left: 22px;
width: min(410px, calc(100vw - 44px));
padding: 17px 19px;
}
.panel-title {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 13px var(--cyan);
}
.gradient-bar {
position: relative;
height: 6px;
margin: 12px 0 11px;
overflow: hidden;
border-radius: 999px;
background: linear-gradient(90deg, #ffbd61, #78e8d0, #66dcff);
}
.gradient-bar::after {
position: absolute;
inset: 0;
background: linear-gradient(
90deg,
transparent,
rgba(255, 255, 255, 0.4),
transparent
);
content: "";
animation: scan 3.6s linear infinite;
}
@keyframes scan {
from { transform: translateX(-100%); }
to { transform: translateX(100%); }
}
.rule-panel p,
.scope-panel p {
margin: 0;
color: #b7d1d8;
font-size: 12px;
line-height: 1.55;
}
.rule-panel strong,
.scope-panel strong {
color: #efffff;
}
.equation {
display: inline-block;
margin: 0 4px;
padding: 2px 7px;
border: 1px solid rgba(107, 231, 242, 0.25);
border-radius: 7px;
background: rgba(107, 231, 242, 0.08);
color: var(--cyan);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11px;
}
.scope-panel {
position: absolute;
right: 22px;
bottom: 22px;
width: min(360px, calc(100vw - 44px));
padding: 17px 19px;
border-color: rgba(255, 209, 102, 0.25);
}
.scope-panel .panel-title {
color: var(--gold);
}
.scope-badge {
display: inline-block;
margin-top: 10px;
padding: 5px 8px;
border: 1px solid rgba(255, 209, 102, 0.28);
border-radius: 999px;
background: rgba(255, 209, 102, 0.08);
color: #ffe2a4;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.legend {
position: absolute;
top: 22px;
right: 22px;
padding: 12px 14px;
color: #b8d2d8;
font-size: 11px;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin: 5px 0;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 50%;
box-shadow: 0 0 9px currentColor;
}
.swatch.tracer {
background: var(--gold);
color: var(--gold);
}
.swatch.cell {
background: #68dbc8;
color: #68dbc8;
}
.swatch.vessel {
background: #ff7e8b;
color: #ff7e8b;
}
.controls {
position: absolute;
bottom: 24px;
left: 50%;
padding: 8px 13px;
transform: translateX(-50%);
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(4, 16, 23, 0.68);
color: #9cbcc5;
font-size: 10px;
letter-spacing: 0.02em;
white-space: nowrap;
backdrop-filter: blur(10px);
}
.loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #06131a;
color: var(--cyan);
font-size: 12px;
letter-spacing: 0.14em;
text-transform: uppercase;
}
@media (max-width: 820px) {
.title-panel {
top: 12px;
left: 12px;
width: min(330px, calc(100vw - 24px));
padding: 14px 15px;
}
.subtitle {
display: none;
}
.legend {
top: auto;
right: 12px;
bottom: 170px;
}
.rule-panel {
bottom: 52px;
left: 12px;
width: min(330px, calc(100vw - 24px));
}
.scope-panel {
right: 12px;
bottom: 52px;
width: min(300px, calc(100vw - 24px));
}
.controls {
bottom: 10px;
}
}
@media (max-width: 620px) {
.scope-panel {
display: none;
}
.rule-panel {
width: calc(100vw - 24px);
}
.legend {
display: none;
}
}
</style>
</head>
<body>
<div id="loading" class="loading">Building cutaway scene…</div>
<main class="hud">
<section class="panel title-panel">
<div class="eyebrow">Cutaway / local exchange study</div>
<h1>Oxygen-like tracer exchange</h1>
<p class="subtitle">
A stylized O₂* tracer moves from a cutaway capillary through the
interstitial space and into nearby cells.
</p>
</section>
<section class="panel rule-panel">
<div class="panel-title">
<span class="live-dot"></span>
Concentration-gradient rule
</div>
<p>
<strong>Direction:</strong>
<span class="equation">C<sub>capillary</sub> > C<sub>space</sub> > C<sub>cell</sub></span><br />
For each local path, concentration decreases toward the cell, so the
tracer follows <span class="equation">J = −D∇C</span>.
It moves capillary → interstitial space → cell and is removed at uptake.
</p>
<div class="gradient-bar"></div>
<p>
Color changes from gold at high concentration to cyan near the
lower-concentration cell surface.
</p>
</section>
<section class="panel scope-panel">
<div class="panel-title">Important scope distinction</div>
<p>
This is <strong>not a complete circulation model</strong>. It contains
no heart or pump, pressure/flow solver, vascular network, tissue
perfusion calculation, or full oxygen-transport equations.
</p>
<span class="scope-badge">
Local exchange schematic only
</span>
</section>
<aside class="panel legend">
<div class="legend-row">
<span class="swatch tracer"></span>
Labeled O₂* tracer
</div>
<div class="legend-row">
<span class="swatch cell"></span>
Nearby cell / uptake site
</div>
<div class="legend-row">
<span class="swatch vessel"></span>
Simplified cutaway capillary
</div>
</aside>
<div class="controls">
Drag: orbit · Shift-drag: pan · Wheel: zoom · Double-click: reset
</div>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, camera
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive cutaway showing oxygen-like tracers moving from a capillary into nearby cells"
);
renderer.domElement.style.touchAction = "none";
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x06131a);
scene.fog = new THREE.FogExp2(0x06131a, 0.027);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const controls = {
target: new THREE.Vector3(0, 0.35, 0),
spherical: new THREE.Spherical(12.1, 1.17, 0.64),
home: {
target: new THREE.Vector3(0, 0.35, 0),
spherical: new THREE.Spherical(12.1, 1.17, 0.64)
}
};
function updateCamera() {
camera.position
.setFromSpherical(controls.spherical)
.add(controls.target);
camera.lookAt(controls.target);
}
updateCamera();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xbdefff, 0x09232b, 1.7));
const keyLight = new THREE.DirectionalLight(0xd9f6ff, 2.8);
keyLight.position.set(-3, 8, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1536, 1536);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x5bc7ff, 1.35);
rimLight.position.set(6, 2, -5);
scene.add(rimLight);
const vesselLight = new THREE.PointLight(0xff9a89, 18, 8, 2);
vesselLight.position.set(0, 1.25, 0.25);
scene.add(vesselLight);
// -------------------------------------------------------------------------
// Small helpers for generated textures and labels
// -------------------------------------------------------------------------
function roundedRect(ctx, x, y, w, h, r) {
const radius = Math.min(r, w * 0.5, h * 0.5);
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.arcTo(x + w, y, x + w, y + h, radius);
ctx.arcTo(x + w, y + h, x, y + h, radius);
ctx.arcTo(x, y + h, x, y, radius);
ctx.arcTo(x, y, x + w, y, radius);
ctx.closePath();
}
function canvasTexture(canvas) {
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
4,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function makeTextSprite(
text,
{
width = 2.2,
accent = "#6be7f2",
foreground = "#efffff",
background = "rgba(4, 17, 24, 0.84)",
fontSize = 48
} = {}
) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 5, 5, 502, 118, 22);
ctx.fillStyle = background;
ctx.fill();
ctx.strokeStyle = accent;
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = foreground;
ctx.font = `700 ${fontSize}px system-ui, sans-serif`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 66);
const material = new THREE.SpriteMaterial({
map: canvasTexture(canvas),
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * 0.25, 1);
sprite.renderOrder = 20;
return sprite;
}
function makeTracerLabelTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 96;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 5, 5, 246, 86, 18);
ctx.fillStyle = "rgba(3, 15, 21, 0.86)";
ctx.fill();
ctx.strokeStyle = "rgba(255, 231, 156, 0.9)";
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = "#fff3bd";
ctx.font = "800 48px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText("O₂*", 128, 49);
return canvasTexture(canvas);
}
function makeHaloTexture() {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 128;
const ctx = canvas.getContext("2d");
const gradient = ctx.createRadialGradient(
64, 64, 0,
64, 64, 64
);
gradient.addColorStop(0, "rgba(255,255,255,0.9)");
gradient.addColorStop(0.2, "rgba(255,255,255,0.36)");
gradient.addColorStop(1, "rgba(255,255,255,0)");
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 128, 128);
return canvasTexture(canvas);
}
// -------------------------------------------------------------------------
// Cutaway tissue block: back wall and floor only, leaving the front open
// -------------------------------------------------------------------------
const tissueGroup = new THREE.Group();
scene.add(tissueGroup);
const wallMaterial = new THREE.MeshStandardMaterial({
color: 0x17434a,
transparent: true,
opacity: 0.42,
roughness: 0.88,
side: THREE.DoubleSide,
depthWrite: false
});
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x15383d,
transparent: true,
opacity: 0.6,
roughness: 0.92,
side: THREE.DoubleSide
});
const backWall = new THREE.Mesh(
new THREE.BoxGeometry(11.6, 4.5, 0.18),
wallMaterial
);
backWall.position.set(0, 0.6, -1.78);
backWall.receiveShadow = true;
tissueGroup.add(backWall);
const floor = new THREE.Mesh(
new THREE.BoxGeometry(11.6, 0.36, 4.05),
floorMaterial
);
floor.position.set(0, -1.31, 0.19);
floor.receiveShadow = true;
tissueGroup.add(floor);
function addEdges(mesh, color = 0x73cbd0, opacity = 0.28) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
edges.position.copy(mesh.position);
edges.rotation.copy(mesh.rotation);
tissueGroup.add(edges);
}
addEdges(backWall, 0x70d5db, 0.32);
addEdges(floor, 0x70d5db, 0.36);
// Fine fibers embedded in the visible back cut surface.
const fiberMaterial = new THREE.LineBasicMaterial({
color: 0x75d7d7,
transparent: true,
opacity: 0.09
});
for (let i = 0; i < 22; i++) {
const x = -5.3 + Math.random() * 10.6;
const y = -1.0 + Math.random() * 3.65;
const curve = new THREE.QuadraticBezierCurve3(
new THREE.Vector3(x, y, -1.675),
new THREE.Vector3(
x + (Math.random() - 0.5) * 1.5,
y + (Math.random() - 0.5) * 0.9,
-1.67
),
new THREE.Vector3(
x + (Math.random() - 0.5) * 2.4,
y + (Math.random() - 0.5) * 1.4,
-1.665
)
);
tissueGroup.add(
new THREE.Line(
new THREE.BufferGeometry().setFromPoints(curve.getPoints(18)),
fiberMaterial
)
);
}
// A sparse interstitial point field.
const interstitialPositions = new Float32Array(120 * 3);
for (let i = 0; i < 120; i++) {
interstitialPositions[i * 3] = -5.4 + Math.random() * 10.8;
interstitialPositions[i * 3 + 1] = -1.05 + Math.random() * 3.45;
interstitialPositions[i * 3 + 2] = -1.5 + Math.random() * 3.2;
}
const interstitialGeometry = new THREE.BufferGeometry();
interstitialGeometry.setAttribute(
"position",
new THREE.BufferAttribute(interstitialPositions, 3)
);
tissueGroup.add(
new THREE.Points(
interstitialGeometry,
new THREE.PointsMaterial({
color: 0x8be4e1,
size: 0.035,
transparent: true,
opacity: 0.32,
depthWrite: false
})
)
);
// -------------------------------------------------------------------------
// Simplified capillary, opened toward the viewer
// -------------------------------------------------------------------------
const vesselGroup = new THREE.Group();
scene.add(vesselGroup);
const vesselLength = 9.25;
const vesselRadius = 0.65;
const vesselCenter = new THREE.Vector3(0, 1.28, -0.18);
const vesselWallGeometry = new THREE.CylinderGeometry(
vesselRadius,
vesselRadius,
vesselLength,
48,
1,
true,
Math.PI / 2,
Math.PI
);
vesselWallGeometry.rotateZ(Math.PI / 2);
const vesselWall = new THREE.Mesh(
vesselWallGeometry,
new THREE.MeshPhysicalMaterial({
color: 0xff7f89,
transparent: true,
opacity: 0.62,
roughness: 0.34,
metalness: 0.02,
side: THREE.DoubleSide,
depthWrite: false
})
);
vesselWall.position.copy(vesselCenter);
vesselWall.renderOrder = 3;
vesselGroup.add(vesselWall);
const lumenGeometry = new THREE.CylinderGeometry(
0.525,
0.525,
vesselLength - 0.08,
40,
1,
true
);
lumenGeometry.rotateZ(Math.PI / 2);
const lumen = new THREE.Mesh(
lumenGeometry,
new THREE.MeshStandardMaterial({
color: 0xd94b64,
transparent: true,
opacity: 0.17,
roughness: 0.42,
side: THREE.DoubleSide,
depthWrite: false
})
);
lumen.position.copy(vesselCenter);
lumen.renderOrder = 2;
vesselGroup.add(lumen);
// Long lips of the cut-open vessel.
const lipPoints = [
new THREE.Vector3(
-vesselLength / 2,
vesselCenter.y + vesselRadius,
vesselCenter.z
),
new THREE.Vector3(
vesselLength / 2,
vesselCenter.y + vesselRadius,
vesselCenter.z
),
new THREE.Vector3(
-vesselLength / 2,
vesselCenter.y - vesselRadius,
vesselCenter.z
),
new THREE.Vector3(
vesselLength / 2,
vesselCenter.y - vesselRadius,
vesselCenter.z
)
];
vesselGroup.add(
new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints(lipPoints),
new THREE.LineBasicMaterial({
color: 0xffa0a4,
transparent: true,
opacity: 0.8
})
)
);
// Curved cross-section marks emphasize that the vessel is cut open.
for (const x of [-4.55, -1.55, 1.55, 4.55]) {
const points = [];
for (let i = 0; i <= 40; i++) {
const angle = (i / 40) * Math.PI;
points.push(
new THREE.Vector3(
x,
vesselCenter.y + vesselRadius * Math.cos(angle),
vesselCenter.z - vesselRadius * Math.sin(angle)
)
);
}
vesselGroup.add(
new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({
color: 0xffa2aa,
transparent: true,
opacity: 0.28
})
)
);
}
const capillaryLabel = makeTextSprite("SIMPLIFIED CAPILLARY · CUTAWAY", {
width: 3.45,
accent: "#ff8e96",
foreground: "#ffe6e7",
fontSize: 39
});
capillaryLabel.position.set(0, 2.36, -0.1);
scene.add(capillaryLabel);
const highLabel = makeTextSprite("HIGH C", {
width: 1.2,
accent: "#ffd166",
foreground: "#fff0bd",
fontSize: 48
});
highLabel.position.set(-4.65, 1.42, 0.55);
scene.add(highLabel);
const lowLabel = makeTextSprite("LOWER C", {
width: 1.55,
accent: "#67e1f2",
foreground: "#d9fbff",
fontSize: 43
});
lowLabel.position.set(4.55, -0.24, 1.0);
scene.add(lowLabel);
// -------------------------------------------------------------------------
// Nearby cells
// -------------------------------------------------------------------------
const cellDefinitions = [
{
name: "CELL A",
center: new THREE.Vector3(-3.62, -0.15, 0.48),
radii: new THREE.Vector3(1.02, 0.70, 0.86),
color: 0x55d5c4
},
{
name: "CELL B",
center: new THREE.Vector3(-1.73, -0.28, 1.04),
radii: new THREE.Vector3(0.92, 0.67, 0.80),
color: 0x789eff
},
{
name: "CELL C",
center: new THREE.Vector3(0.12, -0.12, 0.40),
radii: new THREE.Vector3(1.08, 0.73, 0.91),
color: 0xb48cff
},
{
name: "CELL D",
center: new THREE.Vector3(2.00, -0.30, 1.00),
radii: new THREE.Vector3(0.94, 0.66, 0.82),
color: 0x53c9e5
},
{
name: "CELL E",
center: new THREE.Vector3(3.72, -0.08, 0.36),
radii: new THREE.Vector3(0.98, 0.69, 0.83),
color: 0x83d991
}
];
const cells = [];
const haloTexture = makeHaloTexture();
function createCell(definition, index) {
const group = new THREE.Group();
group.position.copy(definition.center);
scene.add(group);
const membrane = new THREE.Mesh(
new THREE.SphereGeometry(1, 36, 24),
new THREE.MeshStandardMaterial({
color: definition.color,
transparent: true,
opacity: 0.57,
roughness: 0.4,
metalness: 0.03,
side: THREE.DoubleSide,
depthWrite: false
})
);
membrane.scale.copy(definition.radii);
membrane.castShadow = true;
group.add(membrane);
const nucleus = new THREE.Mesh(
new THREE.SphereGeometry(1, 28, 20),
new THREE.MeshStandardMaterial({
color: 0x173d59,
roughness: 0.62,
transparent: true,
opacity: 0.86
})
);
nucleus.scale.copy(definition.radii).multiplyScalar(0.34);
nucleus.position.set(-0.12, 0.04, 0.07);
group.add(nucleus);
const membraneRing = new THREE.Mesh(
new THREE.TorusGeometry(1, 0.018, 8, 72),
new THREE.MeshBasicMaterial({
color: definition.color,
transparent: true,
opacity: 0.68,
depthWrite: false
})
);
membraneRing.rotation.x = Math.PI / 2;
membraneRing.scale.copy(definition.radii).multiplyScalar(1.01);
group.add(membraneRing);
const label = makeTextSprite(definition.name, {
width: 1.12,
accent: `#${new THREE.Color(definition.color).getHexString()}`,
foreground: "#efffff",
fontSize: 45
});
label.position.copy(
definition.center.clone().add(
new THREE.Vector3(0, definition.radii.y + 0.43, 0)
)
);
scene.add(label);
const cell = {
...definition,
group,
membrane,
label,
pulse: 0,
marker: null,
halo: null,
endpoint: null
};
cells.push(cell);
return cell;
}
cellDefinitions.forEach(createCell);
// -------------------------------------------------------------------------
// Gradient paths and uptake markers
// -------------------------------------------------------------------------
const highColor = new THREE.Color(0xffd166);
const lowColor = new THREE.Color(0x67e4ff);
const yAxis = new THREE.Vector3(0, 1, 0);
function ellipsoidSurfacePoint(center, radii, direction) {
const divisor = Math.sqrt(
Math.pow(direction.x / radii.x, 2) +
Math.pow(direction.y / radii.y, 2) +
Math.pow(direction.z / radii.z, 2)
);
return center.clone().addScaledVector(direction, 1 / divisor);
}
function addDirectionalArrow(path, t, opacity = 0.64) {
const color = highColor.clone().lerp(
lowColor,
THREE.MathUtils.smoothstep(t, 0, 1)
);
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.075, 0.23, 12),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false
})
);
arrow.position.copy(path.getPointAt(t));
arrow.quaternion.setFromUnitVectors(
yAxis,
path.getTangentAt(t).normalize()
);
scene.add(arrow);
}
for (const cell of cells) {
const jitterX = (Math.random() - 0.5) * 0.48;
const jitterY = (Math.random() - 0.5) * 0.28;
const start = new THREE.Vector3(
cell.center.x + jitterX,
vesselCenter.y + jitterY,
vesselCenter.z + 0.04 + (Math.random() - 0.5) * 0.14
);
const direction = start.clone().sub(cell.center).normalize();
const endpoint = ellipsoidSurfacePoint(
cell.center,
cell.radii,
direction
);
const first = start.clone().lerp(endpoint, 0.32);
first.z += 0.23;
const second = start.clone().lerp(endpoint, 0.68);
second.z += 0.18;
const path = new THREE.CatmullRomCurve3(
[start, first, second, endpoint],
false,
"catmullrom",
0.45
);
cell.path = path;
cell.endpoint = endpoint;
const pathPoints = path.getPoints(90);
const pathColors = [];
pathPoints.forEach((point, index) => {
const t = index / (pathPoints.length - 1);
const color = highColor.clone().lerp(
lowColor,
THREE.MathUtils.smoothstep(t, 0, 1)
);
pathColors.push(color.r, color.g, color.b);
});
const pathGeometry = new THREE.BufferGeometry().setFromPoints(pathPoints);
pathGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(pathColors, 3)
);
scene.add(
new THREE.Line(
pathGeometry,
new THREE.LineBasicMaterial({
vertexColors: true,
transparent: true,
opacity: 0.28,
depthWrite: false
})
)
);
addDirectionalArrow(path, 0.35, 0.56);
addDirectionalArrow(path, 0.67, 0.62);
const marker = new THREE.Mesh(
new THREE.SphereGeometry(0.082, 18, 12),
new THREE.MeshStandardMaterial({
color: 0xe4ffff,
emissive: cell.color,
emissiveIntensity: 1.4,
roughness: 0.28
})
);
marker.position.copy(endpoint);
scene.add(marker);
cell.marker = marker;
const halo = new THREE.Sprite(
new THREE.SpriteMaterial({
map: haloTexture,
color: cell.color,
transparent: true,
opacity: 0,
blending: THREE.AdditiveBlending,
depthTest: false,
depthWrite: false
})
);
halo.position.copy(endpoint);
halo.scale.setScalar(0.6);
halo.renderOrder = 12;
scene.add(halo);
cell.halo = halo;
}
// -------------------------------------------------------------------------
// Labeled oxygen-like tracers
// -------------------------------------------------------------------------
const tracerLabelTexture = makeTracerLabelTexture();
const tracers = [];
for (let i = 0; i < 12; i++) {
const cell = cells[i % cells.length];
const group = new THREE.Group();
scene.add(group);
const material = new THREE.MeshStandardMaterial({
color: highColor,
emissive: highColor,
emissiveIntensity: 1.8,
roughness: 0.2,
transparent: true,
opacity: 1
});
const core = new THREE.Mesh(
new THREE.SphereGeometry(0.083, 18, 12),
material
);
group.add(core);
const halo = new THREE.Sprite(
new THREE.SpriteMaterial({
map: haloTexture,
color: highColor,
transparent: true,
opacity: 0.52,
blending: THREE.AdditiveBlending,
depthTest: false,
depthWrite: false
})
);
halo.scale.setScalar(0.48);
halo.renderOrder = 14;
group.add(halo);
const label = new THREE.Sprite(
new THREE.SpriteMaterial({
map: tracerLabelTexture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
label.position.set(0.19, 0.19, 0);
label.scale.set(0.69, 0.26, 1);
label.renderOrder = 25;
group.add(label);
tracers.push({
group,
core,
halo,
label,
cell,
offset: (i / 12 + Math.random() * 0.04) % 1,
speed: 0.055 + Math.random() * 0.018,
previous: 0
});
}
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
for (const tracer of tracers) {
const t = (elapsed * tracer.speed + tracer.offset) % 1;
// A tracer reaching the membrane triggers a local uptake pulse.
if (tracer.previous < 0.9 && t >= 0.9) {
tracer.cell.pulse = 1;
}
tracer.previous = t;
const position = tracer.cell.path.getPointAt(t);
tracer.group.position.copy(position);
const concentrationMix = THREE.MathUtils.smoothstep(t, 0, 1);
const currentColor = highColor.clone().lerp(
lowColor,
concentrationMix
);
tracer.core.material.color.copy(currentColor);
tracer.core.material.emissive.copy(currentColor);
tracer.halo.material.color.copy(currentColor);
const fadeIn = Math.min(1, t / 0.07);
const fadeOut = Math.min(1, (1 - t) / 0.06);
const opacity = Math.max(0, fadeIn * fadeOut);
tracer.core.material.opacity = opacity;
tracer.halo.material.opacity = opacity * 0.5;
tracer.label.material.opacity = opacity;
const bob = Math.sin(elapsed * 4 + tracer.offset * 17) * 0.025;
tracer.group.position.y += bob * Math.sin(Math.PI * t);
}
for (const cell of cells) {
cell.pulse = Math.max(0, cell.pulse - delta * 1.55);
cell.marker.scale.setScalar(1 + cell.pulse * 0.7);
cell.marker.material.emissiveIntensity =
1.4 + cell.pulse * 2.2;
cell.halo.material.opacity = cell.pulse * 0.72;
cell.halo.scale.setScalar(0.55 + cell.pulse * 0.75);
cell.membrane.material.opacity = 0.57 + cell.pulse * 0.12;
}
renderer.render(scene, camera);
}
animate();
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, reset
// -------------------------------------------------------------------------
const canvas = renderer.domElement;
let drag = null;
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
canvas.addEventListener("pointerdown", (event) => {
drag = {
x: event.clientX,
y: event.clientY,
pan: event.shiftKey || event.button === 2
};
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!drag) return;
const dx = event.clientX - drag.x;
const dy = event.clientY - drag.y;
if (drag.pan) {
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
0
);
const up = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
1
);
const panScale = controls.spherical.radius * 0.00115;
controls.target
.addScaledVector(right, -dx * panScale)
.addScaledVector(up, dy * panScale);
} else {
controls.spherical.theta -= dx * 0.006;
controls.spherical.phi = THREE.MathUtils.clamp(
controls.spherical.phi - dy * 0.005,
0.48,
1.48
);
}
drag.x = event.clientX;
drag.y = event.clientY;
updateCamera();
});
function endDrag(event) {
if (drag && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
drag = null;
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.spherical.radius = THREE.MathUtils.clamp(
controls.spherical.radius * Math.exp(event.deltaY * 0.001),
6.4,
20
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
controls.target.copy(controls.home.target);
controls.spherical.copy(controls.home.spherical);
updateCamera();
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
document.getElementById("loading")?.remove();
</script>
</body>
</html>
```