Prompt specification
Build or customize the Three.js 3D scene "Vesicle delivery address demonstration" 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: Vesicle delivery address demonstration
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/vesicle-delivery-address-demonstration-x0874
Scene Description Prompt:
Please use Three.js from cdnjs for a stylized scene based on this idea: vesicle delivery address demonstration. Place donor and target compartments on a small cell slice; vesicles with matching symbolic tags dock only at the designated target under a stated simplified recognition rule. Return one self-contained HTML file.
Working Three.js Starter (vesicle-delivery-address-demonstration-x0874):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vesicle Delivery Address Demonstration</title>
<style>
:root {
color-scheme: dark;
--bg: #06101c;
--panel: rgba(10, 24, 39, 0.82);
--panel-border: rgba(148, 205, 224, 0.16);
--text: #eaf7fb;
--muted: #91aebb;
--mint: #72f2d0;
--orange: #ffb46b;
--violet: #ae96ff;
--red: #ff6482;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 48% 40%, #102c40 0%, #091827 40%, #050c15 100%);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#app,
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas:active {
cursor: grabbing;
}
.overlay {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.hero {
position: absolute;
top: 28px;
left: 30px;
width: min(430px, calc(100vw - 60px));
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
color: var(--mint);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 1px;
content: "";
background: var(--mint);
box-shadow: 0 0 12px rgba(114, 242, 208, 0.8);
}
h1 {
max-width: 410px;
margin: 0;
font-size: clamp(29px, 3.4vw, 49px);
font-weight: 680;
line-height: 1.02;
letter-spacing: -0.045em;
text-wrap: balance;
}
.hero p {
max-width: 410px;
margin: 13px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.rule-card {
position: absolute;
top: 28px;
right: 30px;
width: 326px;
padding: 17px 18px 16px;
border: 1px solid var(--panel-border);
border-radius: 17px;
background: linear-gradient(145deg, rgba(17, 39, 55, 0.9), var(--panel));
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(14px);
}
.rule-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
}
.rule-heading strong {
font-size: 12px;
letter-spacing: 0.04em;
}
.simplified {
padding: 4px 7px;
border: 1px solid rgba(114, 242, 208, 0.22);
border-radius: 999px;
color: var(--mint);
background: rgba(114, 242, 208, 0.07);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.rule-card p {
margin: 0;
color: #b9cbd4;
font-size: 12px;
line-height: 1.5;
}
.equation {
display: flex;
align-items: center;
gap: 9px;
margin-top: 12px;
padding: 9px 11px;
border: 1px solid rgba(114, 242, 208, 0.17);
border-radius: 11px;
background: rgba(4, 17, 27, 0.5);
font-size: 20px;
font-weight: 800;
}
.equation .tag {
display: inline-grid;
width: 28px;
height: 28px;
place-items: center;
border-radius: 8px;
font-size: 18px;
}
.tag.triangle {
color: var(--mint);
background: rgba(114, 242, 208, 0.11);
}
.tag.circle {
color: var(--orange);
background: rgba(255, 180, 107, 0.1);
}
.tag.square {
color: var(--violet);
background: rgba(174, 150, 255, 0.1);
}
.equation .equals {
color: #708794;
font-size: 13px;
}
.equation .verdict {
margin-left: auto;
color: var(--mint);
font-size: 10px;
letter-spacing: 0.12em;
}
.rule-note {
display: block;
margin-top: 9px;
color: #849ba8;
font-size: 10px;
line-height: 1.45;
}
.annotation {
position: absolute;
z-index: 3;
min-width: 126px;
padding: 8px 11px 8px 13px;
transform: translate(-50%, -100%);
border: 1px solid rgba(148, 205, 224, 0.16);
border-radius: 9px;
background: rgba(6, 18, 29, 0.78);
box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(9px);
pointer-events: none;
}
.annotation::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 20px;
content: "";
background: linear-gradient(var(--mint), transparent);
opacity: 0.65;
}
.annotation .name {
display: flex;
align-items: center;
gap: 7px;
color: #e8f5f8;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.annotation .name::before {
width: 6px;
height: 6px;
content: "";
border-radius: 50%;
background: var(--mint);
box-shadow: 0 0 10px rgba(114, 242, 208, 0.75);
}
.annotation small {
display: block;
margin-top: 3px;
color: #8098a6;
font-size: 9px;
}
#targetAnnotation .name::before {
background: #6bd9ff;
box-shadow: 0 0 10px rgba(107, 217, 255, 0.75);
}
#plainAnnotation {
min-width: 112px;
opacity: 0.78;
}
#plainAnnotation .name::before {
background: #657d8c;
box-shadow: none;
}
#plainAnnotation::after {
background: linear-gradient(#657d8c, transparent);
}
.legend {
position: absolute;
bottom: 30px;
left: 30px;
display: flex;
flex-direction: column;
gap: 9px;
padding: 13px 15px;
border: 1px solid var(--panel-border);
border-radius: 13px;
background: rgba(7, 20, 31, 0.72);
backdrop-filter: blur(10px);
}
.legend-title {
color: #748e9d;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
color: #b9cbd4;
font-size: 10px;
}
.legend-row b {
display: inline-grid;
width: 21px;
height: 21px;
place-items: center;
border-radius: 6px;
font-size: 13px;
}
.legend-row .accepted {
color: var(--mint);
background: rgba(114, 242, 208, 0.1);
}
.legend-row .rejected {
color: var(--orange);
background: rgba(255, 180, 107, 0.1);
}
.stats {
position: absolute;
right: 30px;
bottom: 30px;
width: 260px;
padding: 14px 16px;
border: 1px solid var(--panel-border);
border-radius: 13px;
background: rgba(7, 20, 31, 0.75);
backdrop-filter: blur(10px);
}
.stats-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
}
.stat strong {
display: block;
font-size: 24px;
font-weight: 650;
letter-spacing: -0.04em;
}
.stat span {
color: #7f98a6;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.stat.accept strong {
color: var(--mint);
}
.stat.reject strong {
color: var(--red);
}
.event {
margin-top: 10px;
padding-top: 10px;
border-top: 1px solid rgba(148, 205, 224, 0.1);
color: #a8bdc8;
font-size: 10px;
line-height: 1.4;
}
.toolbar {
position: absolute;
bottom: 28px;
left: 50%;
display: flex;
align-items: center;
gap: 7px;
padding: 8px;
transform: translateX(-50%);
border: 1px solid var(--panel-border);
border-radius: 14px;
background: rgba(8, 23, 35, 0.88);
box-shadow: 0 16px 45px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(15px);
pointer-events: auto;
}
.toolbar button {
height: 34px;
padding: 0 12px;
border: 1px solid rgba(151, 205, 222, 0.13);
border-radius: 9px;
color: #c9dbe3;
background: rgba(125, 174, 194, 0.07);
cursor: pointer;
font-size: 10px;
font-weight: 700;
transition: 140ms ease;
}
.toolbar button:hover {
border-color: rgba(114, 242, 208, 0.35);
color: white;
background: rgba(114, 242, 208, 0.09);
}
.toolbar button.primary {
min-width: 76px;
border-color: rgba(114, 242, 208, 0.26);
color: var(--mint);
background: rgba(114, 242, 208, 0.08);
}
.divider {
width: 1px;
height: 23px;
margin: 0 2px;
background: rgba(151, 205, 222, 0.13);
}
.speed-control {
display: flex;
align-items: center;
gap: 8px;
padding: 0 6px;
color: #8199a7;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.speed-control output {
min-width: 28px;
color: #c9dbe3;
font-size: 10px;
text-align: right;
}
input[type="range"] {
width: 74px;
accent-color: var(--mint);
cursor: pointer;
}
.camera-hint {
position: absolute;
bottom: 91px;
left: 50%;
transform: translateX(-50%);
color: rgba(154, 181, 194, 0.66);
font-size: 9px;
letter-spacing: 0.06em;
white-space: nowrap;
}
@media (max-width: 900px) {
.legend {
display: none;
}
.stats {
width: 220px;
}
}
@media (max-width: 700px) {
.hero {
top: 15px;
left: 15px;
width: calc(100vw - 30px);
}
h1 {
max-width: 330px;
font-size: 27px;
}
.hero p {
display: none;
}
.rule-card {
top: 102px;
right: 15px;
width: 245px;
padding: 12px;
}
.rule-card p {
font-size: 10px;
}
.rule-note {
display: none;
}
.equation {
margin-top: 8px;
padding: 6px 8px;
}
.stats {
right: 15px;
bottom: 86px;
width: 190px;
padding: 10px 12px;
}
.stat strong {
font-size: 19px;
}
.event {
display: none;
}
.toolbar {
bottom: 13px;
width: calc(100vw - 24px);
justify-content: center;
}
.toolbar button {
padding: 0 9px;
}
.speed-control {
display: none;
}
.camera-hint {
bottom: 75px;
}
}
</style>
</head>
<body>
<main id="app">
<div id="scene" aria-label="Interactive three-dimensional vesicle delivery demonstration"></div>
<div class="overlay">
<header class="hero">
<div class="eyebrow">Vesicle delivery / address demo</div>
<h1>Only the right tag gets home.</h1>
<p>
A stylized cell slice shows vesicles leaving a donor compartment and testing
a designated target receptor. Shape equality is the only address rule in this
simplified model.
</p>
</header>
<section class="rule-card" aria-label="Simplified recognition rule">
<div class="rule-heading">
<strong>Recognition rule</strong>
<span class="simplified">Simplified</span>
</div>
<p>
A vesicle docks only when its <b>tag shape</b> matches the shape displayed by
the receptor on the designated target.
</p>
<div class="equation" aria-label="Triangle matches triangle and docks">
<span class="tag triangle">▲</span>
<span class="equals">=</span>
<span class="tag triangle">▲</span>
<span class="verdict">DOCK</span>
</div>
<small class="rule-note">
Circle ● and square ■ tags fail shape matching at this target and are released.
Plain membrane has no receptor.
</small>
</section>
<div id="donorAnnotation" class="annotation">
<div class="name">Donor compartment</div>
<small>Vesicle release zone</small>
</div>
<div id="targetAnnotation" class="annotation">
<div class="name">Designated target</div>
<small>▲ receptor site</small>
</div>
<div id="plainAnnotation" class="annotation">
<div class="name">Plain membrane</div>
<small>No receptor</small>
</div>
<section class="legend" aria-label="Symbol legend">
<div class="legend-title">Symbol tags</div>
<div class="legend-row"><b class="accepted">▲</b> Matches target receptor</div>
<div class="legend-row"><b class="rejected">●</b> Mismatched / rejected</div>
<div class="legend-row"><b class="rejected">■</b> Mismatched / rejected</div>
</section>
<section class="stats" aria-live="polite">
<div class="stats-grid">
<div class="stat accept"><strong id="dockedCount">0</strong><span>Docked</span></div>
<div class="stat reject"><strong id="rejectedCount">0</strong><span>Rejected</span></div>
</div>
<div id="eventText" class="event">Waiting for the first vesicle…</div>
</section>
<div class="camera-hint">Drag to orbit · Scroll or pinch to zoom · Double-click to reset view</div>
<nav class="toolbar" aria-label="Simulation controls">
<button id="playButton" class="primary" type="button">Pause</button>
<button id="resetButton" type="button">Reset demo</button>
<button id="viewButton" type="button">Reset view</button>
<span class="divider"></span>
<button id="pathButton" type="button" aria-pressed="true">Paths on</button>
<label class="speed-control" for="speedSlider">
Speed
<input id="speedSlider" type="range" min="0.5" max="2" step="0.1" value="1" />
<output id="speedOutput">1.0×</output>
</label>
</nav>
</div>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setClearColor(0x06101c, 0);
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",
"Three-dimensional cell slice with donor, target, and tagged vesicles"
);
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x071421, 0.017);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0.2, 0);
const currentView = { theta: -0.11, phi: 1.04, radius: 13.5 };
const desiredView = { ...currentView };
const clock = new THREE.Clock();
const TYPE_COLORS = {
triangle: 0x72f2d0,
circle: 0xffb46b,
square: 0xae96ff
};
const TYPE_SYMBOLS = {
triangle: "▲",
circle: "●",
square: "■"
};
const donorPosition = new THREE.Vector3(-3.45, 0.2, 0);
const targetPosition = new THREE.Vector3(3.4, 0.2, 0);
const targetDockPosition = new THREE.Vector3(3.4, 0.41, 0);
let playing = true;
let simulationTime = 0;
let playbackSpeed = 1;
let targetPulse = 0;
let deliveredCount = 0;
let rejectedCount = 0;
let lastEvent = "Waiting for the first vesicle…";
const vesicles = [];
const sparks = [];
const disposableMaterials = [];
// Lighting
scene.add(new THREE.HemisphereLight(0xb9ecff, 0x08111d, 1.65));
const keyLight = new THREE.DirectionalLight(0xd9f7ff, 3.2);
keyLight.position.set(-4, 9, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -6;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x4de5cf, 22, 18, 2);
rimLight.position.set(4.5, 3.5, -2.5);
scene.add(rimLight);
const donorLight = new THREE.PointLight(0x778dff, 12, 8, 2);
donorLight.position.set(-3.7, 2.4, 1.5);
scene.add(donorLight);
// Shared geometry
const vesicleGeometry = new THREE.SphereGeometry(0.205, 28, 20);
const payloadGeometry = new THREE.SphereGeometry(0.06, 14, 10);
const vesicleRingGeometry = new THREE.TorusGeometry(0.206, 0.012, 8, 48);
const sparkGeometry = new THREE.OctahedronGeometry(0.042, 0);
// Procedural symbol textures: no external assets or addons.
function createSymbolTexture(type) {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 128;
const context = canvas.getContext("2d");
context.translate(64, 64);
context.fillStyle = "#ffffff";
context.strokeStyle = "#ffffff";
context.lineWidth = 12;
context.lineJoin = "round";
if (type === "triangle") {
context.beginPath();
context.moveTo(0, -39);
context.lineTo(37, 31);
context.lineTo(-37, 31);
context.closePath();
context.fill();
} else if (type === "circle") {
context.beginPath();
context.arc(0, 0, 33, 0, Math.PI * 2);
context.fill();
} else {
const radius = 30;
context.beginPath();
context.roundRect(-radius, -radius, radius * 2, radius * 2, 6);
context.fill();
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.needsUpdate = true;
return texture;
}
const symbolTextures = {
triangle: createSymbolTexture("triangle"),
circle: createSymbolTexture("circle"),
square: createSymbolTexture("square")
};
function roundedRectangleShape(width, height, radius) {
const shape = new THREE.Shape();
const x = -width / 2;
const y = -height / 2;
shape.moveTo(x + radius, y);
shape.lineTo(x + width - radius, y);
shape.quadraticCurveTo(x + width, y, x + width, y + radius);
shape.lineTo(x + width, y + height - radius);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
shape.lineTo(x + radius, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - radius);
shape.lineTo(x, y + radius);
shape.quadraticCurveTo(x, y, x + radius, y);
return shape;
}
// The small cell slice.
const cellShape = roundedRectangleShape(12, 5.6, 0.68);
const cellGeometry = new THREE.ExtrudeGeometry(cellShape, {
depth: 0.28,
bevelEnabled: true,
bevelThickness: 0.08,
bevelSize: 0.08,
bevelSegments: 3,
curveSegments: 24
});
cellGeometry.rotateX(-Math.PI / 2);
cellGeometry.translate(0, -0.28, 0);
const cellMaterial = new THREE.MeshPhysicalMaterial({
color: 0x17465b,
emissive: 0x071a26,
emissiveIntensity: 0.55,
roughness: 0.48,
metalness: 0.05,
transparent: true,
opacity: 0.84
});
const cell = new THREE.Mesh(cellGeometry, cellMaterial);
cell.receiveShadow = true;
cell.castShadow = true;
scene.add(cell);
const insetGeometry = new THREE.ShapeGeometry(
roundedRectangleShape(11.65, 5.25, 0.55),
32
);
insetGeometry.rotateX(-Math.PI / 2);
const insetMaterial = new THREE.MeshBasicMaterial({
color: 0x1d6c81,
transparent: true,
opacity: 0.18,
side: THREE.DoubleSide,
depthWrite: false
});
const inset = new THREE.Mesh(insetGeometry, insetMaterial);
inset.position.y = 0.086;
scene.add(inset);
const perimeterPoints = cellShape.getPoints(100).map(
(point) => new THREE.Vector3(point.x, 0.105, -point.y)
);
const perimeterGeometry = new THREE.BufferGeometry().setFromPoints(perimeterPoints);
const perimeter = new THREE.LineLoop(
perimeterGeometry,
new THREE.LineBasicMaterial({
color: 0x78dcec,
transparent: true,
opacity: 0.55
})
);
scene.add(perimeter);
// Cytoskeleton-like filaments for a stylized slice.
const filamentMaterial = new THREE.MeshBasicMaterial({
color: 0x62c6d8,
transparent: true,
opacity: 0.17,
depthWrite: false
});
for (let index = 0; index < 5; index += 1) {
const z = -1.75 + index * 0.83;
const curve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-5.45, 0.12, z + Math.sin(index) * 0.18),
new THREE.Vector3(-2.8, 0.13, z - 0.35),
new THREE.Vector3(0, 0.12, z + 0.3),
new THREE.Vector3(2.7, 0.13, z - 0.28),
new THREE.Vector3(5.35, 0.12, z + 0.16)
]);
const filament = new THREE.Mesh(
new THREE.TubeGeometry(curve, 80, 0.018, 5, false),
filamentMaterial
);
scene.add(filament);
}
// Subtle background particles.
const backgroundPositions = new Float32Array(150 * 3);
for (let index = 0; index < 150; index += 1) {
backgroundPositions[index * 3] = (Math.random() - 0.5) * 23;
backgroundPositions[index * 3 + 1] = Math.random() * 8 - 1;
backgroundPositions[index * 3 + 2] = -4 - Math.random() * 9;
}
const backgroundGeometry = new THREE.BufferGeometry();
backgroundGeometry.setAttribute(
"position",
new THREE.BufferAttribute(backgroundPositions, 3)
);
scene.add(
new THREE.Points(
backgroundGeometry,
new THREE.PointsMaterial({
color: 0x8ac8d7,
size: 0.035,
transparent: true,
opacity: 0.36,
depthWrite: false
})
)
);
// Donor compartment.
const donorMaterial = new THREE.MeshPhysicalMaterial({
color: 0x23355d,
emissive: 0x111c42,
emissiveIntensity: 0.65,
roughness: 0.42,
metalness: 0.12,
transparent: true,
opacity: 0.9
});
const donorPatch = new THREE.Mesh(
new THREE.CylinderGeometry(1.08, 1.08, 0.1, 56),
donorMaterial
);
donorPatch.position.copy(donorPosition);
donorPatch.position.y = 0.13;
donorPatch.receiveShadow = true;
scene.add(donorPatch);
const donorRingMaterial = new THREE.MeshBasicMaterial({
color: 0x8da5ff,
transparent: true,
opacity: 0.58
});
const donorRing = new THREE.Mesh(
new THREE.TorusGeometry(0.78, 0.035, 10, 72),
donorRingMaterial
);
donorRing.position.set(donorPosition.x, 0.22, donorPosition.z);
donorRing.rotation.x = Math.PI / 2;
scene.add(donorRing);
const donorInnerRing = new THREE.Mesh(
new THREE.TorusGeometry(0.53, 0.014, 8, 64),
new THREE.MeshBasicMaterial({
color: 0x7898ff,
transparent: true,
opacity: 0.35
})
);
donorInnerRing.position.set(donorPosition.x, 0.225, donorPosition.z);
donorInnerRing.rotation.x = Math.PI / 2;
scene.add(donorInnerRing);
// Plain membrane patch: deliberately has no receptor.
const plainPatch = new THREE.Mesh(
new THREE.CylinderGeometry(0.46, 0.46, 0.055, 40),
new THREE.MeshPhysicalMaterial({
color: 0x2c6172,
emissive: 0x0d2933,
emissiveIntensity: 0.25,
roughness: 0.62,
transparent: true,
opacity: 0.45
})
);
plainPatch.position.set(0.25, 0.115, -1.28);
scene.add(plainPatch);
// Designated target compartment.
const targetMaterial = new THREE.MeshPhysicalMaterial({
color: 0x227b78,
emissive: 0x0b514e,
emissiveIntensity: 0.65,
roughness: 0.32,
metalness: 0.08,
transparent: true,
opacity: 0.9
});
const targetPatch = new THREE.Mesh(
new THREE.CylinderGeometry(1.1, 1.1, 0.1, 64),
targetMaterial
);
targetPatch.position.set(targetPosition.x, 0.14, targetPosition.z);
targetPatch.receiveShadow = true;
scene.add(targetPatch);
const targetGlowMaterial = new THREE.MeshBasicMaterial({
color: 0x6cf3d2,
transparent: true,
opacity: 0.12,
side: THREE.DoubleSide,
depthWrite: false
});
const targetGlow = new THREE.Mesh(
new THREE.CircleGeometry(0.92, 64),
targetGlowMaterial
);
targetGlow.position.set(targetPosition.x, 0.198, targetPosition.z);
targetGlow.rotation.x = -Math.PI / 2;
scene.add(targetGlow);
const targetRingMaterial = new THREE.MeshStandardMaterial({
color: 0x72f2d0,
emissive: 0x39cba9,
emissiveIntensity: 0.8,
roughness: 0.3
});
const targetRing = new THREE.Mesh(
new THREE.TorusGeometry(0.69, 0.042, 10, 80),
targetRingMaterial
);
targetRing.position.set(targetPosition.x, 0.23, targetPosition.z);
targetRing.rotation.x = Math.PI / 2;
scene.add(targetRing);
const targetSocket = new THREE.Mesh(
new THREE.TorusGeometry(0.46, 0.052, 12, 72, Math.PI * 1.72),
new THREE.MeshStandardMaterial({
color: 0xa8fff0,
emissive: 0x53d9c0,
emissiveIntensity: 0.7,
roughness: 0.28
})
);
targetSocket.position.set(targetPosition.x, 0.255, targetPosition.z);
targetSocket.rotation.x = Math.PI / 2;
targetSocket.rotation.z = -0.55;
scene.add(targetSocket);
for (let index = 0; index < 3; index += 1) {
const angle = index * (Math.PI * 2 / 3) + 0.45;
const bracket = new THREE.Mesh(
new THREE.BoxGeometry(0.13, 0.08, 0.25),
new THREE.MeshStandardMaterial({
color: 0x8dfff0,
emissive: 0x2cbaa3,
emissiveIntensity: 0.45
})
);
bracket.position.set(
targetPosition.x + Math.cos(angle) * 0.47,
0.26,
targetPosition.z + Math.sin(angle) * 0.47
);
bracket.rotation.y = -angle;
scene.add(bracket);
}
const targetBadge = new THREE.Sprite(
new THREE.SpriteMaterial({
map: symbolTextures.triangle,
color: TYPE_COLORS.triangle,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
})
);
targetBadge.position.set(4.08, 0.72, 0.42);
targetBadge.scale.set(0.58, 0.58, 1);
targetBadge.renderOrder = 20;
scene.add(targetBadge);
// Three possible vesicle routes. Only the designated target has a socket.
const routeCurves = [-0.34, 0, 0.34].map(
(lane) =>
new THREE.CatmullRomCurve3(
[
new THREE.Vector3(-3.45, 0.59, lane),
new THREE.Vector3(-2.75, 0.98, lane * 1.25),
new THREE.Vector3(-0.7, 1.08, lane),
new THREE.Vector3(1.4, 0.84, lane * 0.65),
new THREE.Vector3(2.8, 0.57, lane * 0.18),
new THREE.Vector3(3.4, 0.41, 0)
],
false,
"catmullrom",
0.38
)
);
const routeGroup = new THREE.Group();
routeCurves.forEach((curve, index) => {
const geometry = new THREE.BufferGeometry().setFromPoints(
curve.getPoints(130)
);
const material = new THREE.LineDashedMaterial({
color: index === 1 ? 0x72f2d0 : 0x5eb4c8,
dashSize: 0.16,
gapSize: 0.13,
transparent: true,
opacity: index === 1 ? 0.36 : 0.18,
depthWrite: false
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
routeGroup.add(line);
});
scene.add(routeGroup);
function createVesicle(type, startTime, routeIndex) {
const group = new THREE.Group();
const bodyMaterial = new THREE.MeshPhysicalMaterial({
color: 0xb9edf6,
emissive: 0x153e50,
emissiveIntensity: 0.55,
roughness: 0.2,
metalness: 0.02,
transparent: true,
opacity: 0.72,
depthWrite: false
});
const ringMaterial = new THREE.MeshStandardMaterial({
color: TYPE_COLORS[type],
emissive: TYPE_COLORS[type],
emissiveIntensity: 0.72,
roughness: 0.25
});
const payloadMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
emissive: TYPE_COLORS[type],
emissiveIntensity: 1.4,
roughness: 0.25
});
const body = new THREE.Mesh(vesicleGeometry, bodyMaterial);
body.castShadow = true;
group.add(body);
const ring = new THREE.Mesh(vesicleRingGeometry, ringMaterial);
group.add(ring);
const payload = new THREE.Mesh(payloadGeometry, payloadMaterial);
payload.position.set(0.025, -0.015, 0.025);
group.add(payload);
const badge = new THREE.Sprite(
new THREE.SpriteMaterial({
map: symbolTextures[type],
color: TYPE_COLORS[type],
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
})
);
badge.position.set(0, 0.29, 0);
badge.scale.set(0.34, 0.34, 1);
badge.renderOrder = 30;
group.add(badge);
group.position.copy(routeCurves[routeIndex].getPointAt(0));
scene.add(group);
disposableMaterials.push(bodyMaterial, ringMaterial, payloadMaterial, badge.material);
return {
group,
body,
ring,
badge,
type,
startTime,
route: routeCurves[routeIndex],
phase: "travel",
phaseStart: 0
};
}
function spawnSparks(position, color, amount = 9) {
for (let index = 0; index < amount; index += 1) {
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.95,
depthWrite: false
});
const mesh = new THREE.Mesh(sparkGeometry, material);
mesh.position.copy(position);
const angle = (index / amount) * Math.PI * 2 + Math.random() * 0.4;
const speed = 0.45 + Math.random() * 0.55;
const velocity = new THREE.Vector3(
Math.cos(angle) * speed,
0.25 + Math.random() * 0.55,
Math.sin(angle) * speed
);
scene.add(mesh);
sparks.push({ mesh, material, velocity, age: 0, life: 0.65 + Math.random() * 0.25 });
}
}
function setEvent(message) {
lastEvent = message;
document.getElementById("eventText").textContent = message;
document.getElementById("dockedCount").textContent = deliveredCount;
document.getElementById("rejectedCount").textContent = rejectedCount;
}
function removeVesicle(index) {
const vesicle = vesicles[index];
scene.remove(vesicle.group);
vesicles.splice(index, 1);
}
function resetSimulation() {
while (vesicles.length) {
removeVesicle(vesicles.length - 1);
}
for (const spark of sparks) {
scene.remove(spark.mesh);
spark.material.dispose();
}
sparks.length = 0;
simulationTime = 0;
targetPulse = 0;
deliveredCount = 0;
rejectedCount = 0;
setEvent("Waiting for the first vesicle…");
const schedule = [
["triangle", 0.0, 1],
["circle", 0.9, 0],
["square", 2.05, 2],
["triangle", 3.25, 1],
["circle", 4.45, 2],
["triangle", 5.65, 0],
["triangle", 6.95, 1],
["circle", 8.2, 2]
];
schedule.forEach(([type, startTime, routeIndex]) => {
vesicles.push(createVesicle(type, startTime, routeIndex));
});
}
function updateVesicles(deltaTime) {
const travelDuration = 4.2;
const contactPoint = 0.91;
for (let index = vesicles.length - 1; index >= 0; index -= 1) {
const vesicle = vesicles[index];
const age = simulationTime - vesicle.startTime;
if (age < 0) {
vesicle.group.visible = false;
continue;
}
vesicle.group.visible = true;
if (vesicle.phase === "travel") {
const progress = Math.min(age / travelDuration, 1);
const point = vesicle.route.getPointAt(progress * contactPoint);
vesicle.group.position.copy(point);
vesicle.group.position.y += Math.sin(age * 3.1) * 0.025;
const spawnScale = Math.min(1, progress * 7);
vesicle.group.scale.setScalar(spawnScale);
vesicle.ring.scale.setScalar(1 + Math.sin(age * 4.5) * 0.035);
if (progress >= 1) {
if (vesicle.type === "triangle") {
vesicle.phase = "dock";
vesicle.phaseStart = simulationTime;
} else {
vesicle.phase = "reject";
vesicle.phaseStart = simulationTime;
vesicle.badge.material.color.setHex(0xff6482);
spawnSparks(vesicle.group.position, 0xff6482, 10);
rejectedCount += 1;
setEvent(
`${TYPE_SYMBOLS[vesicle.type]} rejected: shape does not match the ▲ receptor.`
);
}
}
continue;
}
if (vesicle.phase === "dock") {
const dockTime = simulationTime - vesicle.phaseStart;
const progress = Math.min(dockTime / 1.15, 1);
const eased = progress * progress * (3 - 2 * progress);
const contact = vesicle.route.getPointAt(contactPoint);
vesicle.group.position.lerpVectors(contact, targetDockPosition, eased);
vesicle.group.scale.setScalar(1);
vesicle.ring.scale.setScalar(1 + Math.sin(progress * Math.PI) * 0.18);
vesicle.badge.position.y = 0.29 + Math.sin(progress * Math.PI) * 0.08;
if (progress >= 1) {
vesicle.phase = "merge";
vesicle.phaseStart = simulationTime;
deliveredCount += 1;
targetPulse = 1;
spawnSparks(targetDockPosition, 0x72f2d0, 13);
setEvent("▲ accepted: matching tag docked at the designated target.");
}
continue;
}
if (vesicle.phase === "merge") {
const mergeTime = simulationTime - vesicle.phaseStart;
const progress = Math.min(mergeTime / 0.85, 1);
vesicle.group.scale.setScalar(1 - progress * 0.88);
vesicle.group.position.copy(targetDockPosition);
vesicle.badge.material.opacity = 1 - progress;
if (progress >= 1) {
removeVesicle(index);
}
continue;
}
if (vesicle.phase === "reject") {
const rejectTime = simulationTime - vesicle.phaseStart;
if (rejectTime < 0.34) {
vesicle.group.position.copy(vesicle.route.getPointAt(contactPoint));
vesicle.group.position.x += Math.sin(rejectTime * 80) * 0.02;
vesicle.ring.scale.setScalar(1.13);
} else {
const returnProgress = Math.min((rejectTime - 0.34) / 2.25, 1);
const eased = returnProgress * returnProgress * (3 - 2 * returnProgress);
const pathProgress = contactPoint * (1 - eased);
vesicle.group.position.copy(vesicle.route.getPointAt(pathProgress));
vesicle.group.scale.setScalar(1 - Math.max(0, returnProgress - 0.7) / 0.3);
if (returnProgress >= 1) {
removeVesicle(index);
}
}
}
}
}
function updateSparks(deltaTime) {
for (let index = sparks.length - 1; index >= 0; index -= 1) {
const spark = sparks[index];
spark.age += deltaTime;
spark.mesh.position.addScaledVector(spark.velocity, deltaTime);
spark.velocity.y -= deltaTime * 0.65;
spark.mesh.rotation.x += deltaTime * 4;
spark.mesh.rotation.z += deltaTime * 3;
const remaining = 1 - spark.age / spark.life;
spark.material.opacity = Math.max(0, remaining);
spark.mesh.scale.setScalar(Math.max(0.1, remaining));
if (spark.age >= spark.life) {
scene.remove(spark.mesh);
spark.material.dispose();
sparks.splice(index, 1);
}
}
}
// DOM annotations follow their 3D anchors.
const annotationElements = {
donor: document.getElementById("donorAnnotation"),
target: document.getElementById("targetAnnotation"),
plain: document.getElementById("plainAnnotation")
};
const annotationAnchors = {
donor: new THREE.Vector3(-3.45, 1.15, 0),
target: new THREE.Vector3(3.4, 1.25, 0),
plain: new THREE.Vector3(0.25, 0.55, -1.28)
};
const projected = new THREE.Vector3();
function updateAnnotations() {
const width = window.innerWidth;
const height = window.innerHeight;
Object.entries(annotationAnchors).forEach(([key, anchor]) => {
projected.copy(anchor).project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
const element = annotationElements[key];
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.opacity = projected.z > 1 ? "0" : "1";
});
}
// Direct camera controls implemented without addons.
function updateCamera(deltaTime) {
const damping = 1 - Math.exp(-deltaTime * 9);
currentView.theta += (desiredView.theta - currentView.theta) * damping;
currentView.phi += (desiredView.phi - currentView.phi) * damping;
currentView.radius += (desiredView.radius - currentView.radius) * damping;
const sinPhi = Math.sin(currentView.phi);
camera.position.set(
cameraTarget.x + sinPhi * Math.sin(currentView.theta) * currentView.radius,
cameraTarget.y + Math.cos(currentView.phi) * currentView.radius,
cameraTarget.z + sinPhi * Math.cos(currentView.theta) * currentView.radius
);
camera.lookAt(cameraTarget);
}
function resetView() {
desiredView.theta = -0.11;
desiredView.phi = 1.04;
desiredView.radius = window.innerWidth < 700 ? 19 : 13.5;
}
let dragging = false;
let previousX = 0;
let previousY = 0;
let activePointer = null;
const pointers = new Map();
let pinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
activePointer = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
dragging = true;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size >= 2) {
const values = Array.from(pointers.values());
const distance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (pinchDistance > 0) {
desiredView.radius = THREE.MathUtils.clamp(
desiredView.radius + (pinchDistance - distance) * 0.025,
8,
25
);
}
pinchDistance = distance;
dragging = false;
return;
}
if (!dragging || event.pointerId !== activePointer) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
desiredView.theta -= deltaX * 0.006;
desiredView.phi = THREE.MathUtils.clamp(
desiredView.phi - deltaY * 0.005,
0.48,
1.38
);
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
if (event.pointerId === activePointer) {
activePointer = null;
dragging = pointers.size > 0;
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredView.radius = THREE.MathUtils.clamp(
desiredView.radius + event.deltaY * 0.008,
8,
25
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
if (width < 700) {
desiredView.radius = Math.max(desiredView.radius, 18);
}
}
window.addEventListener("resize", resize);
// Interface controls.
const playButton = document.getElementById("playButton");
const resetButton = document.getElementById("resetButton");
const viewButton = document.getElementById("viewButton");
const pathButton = document.getElementById("pathButton");
const speedSlider = document.getElementById("speedSlider");
const speedOutput = document.getElementById("speedOutput");
playButton.addEventListener("click", () => {
playing = !playing;
playButton.textContent = playing ? "Pause" : "Play";
});
resetButton.addEventListener("click", () => {
resetSimulation();
playing = true;
playButton.textContent = "Pause";
});
viewButton.addEventListener("click", resetView);
pathButton.addEventListener("click", () => {
routeGroup.visible = !routeGroup.visible;
pathButton.textContent = routeGroup.visible ? "Paths on" : "Paths off";
pathButton.setAttribute("aria-pressed", String(routeGroup.visible));
});
speedSlider.addEventListener("input", () => {
playbackSpeed = Number(speedSlider.value);
speedOutput.textContent = `${playbackSpeed.toFixed(1)}×`;
});
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
if (event.code === "Space") {
event.preventDefault();
playButton.click();
} else if (event.key.toLowerCase() === "r") {
resetSimulation();
} else if (event.key.toLowerCase() === "v") {
resetView();
}
});
resize();
resetView();
resetSimulation();
function animate() {
requestAnimationFrame(animate);
const deltaTime = Math.min(clock.getDelta(), 0.05);
if (playing) {
simulationTime += deltaTime * playbackSpeed;
updateVesicles(deltaTime * playbackSpeed);
updateSparks(deltaTime * playbackSpeed);
}
targetPulse = Math.max(0, targetPulse - deltaTime * 1.35);
targetGlowMaterial.opacity = 0.12 + targetPulse * 0.38;
targetRing.scale.setScalar(1 + targetPulse * 0.075);
targetRingMaterial.emissiveIntensity = 0.8 + targetPulse * 1.4;
targetMaterial.emissiveIntensity = 0.65 + targetPulse * 0.8;
const donorPulse = 1 + Math.sin(simulationTime * 2.4) * 0.025;
donorRing.scale.setScalar(donorPulse);
donorRingMaterial.opacity = 0.48 + Math.sin(simulationTime * 2.4) * 0.1;
targetBadge.scale.setScalar(0.58 + targetPulse * 0.08);
updateCamera(deltaTime);
updateAnnotations();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```