Prompt specification
Build or customize the Three.js 3D scene "Cell logistics interruption explorer" 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: Cell logistics interruption explorer
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/cell-logistics-interruption-explorer-x0876
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring vesicle sorting and delivery. Allow blocking a single transport route in a schematic cell; show cargo accumulation upstream and reduced delivery downstream without implying a clinically realistic disease model. Low-poly.
Working Three.js Starter (cell-logistics-interruption-explorer-x0876):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vesicle Sorting & Delivery</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: rgba(10, 23, 39, 0.78);
--panel-border: rgba(143, 210, 255, 0.16);
--text: #eef8ff;
--muted: #91a9bc;
--cyan: #65ddff;
--mint: #75f0c0;
--amber: #ffc568;
--red: #ff657d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
touch-action: none;
}
.panel {
border: 1px solid var(--panel-border);
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.brand {
position: fixed;
z-index: 10;
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 18px 20px;
border-radius: 18px;
pointer-events: none;
}
.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, 30px);
line-height: 1.08;
letter-spacing: -0.035em;
}
.brand-copy {
margin: 8px 0 14px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.route-badge {
display: inline-flex;
align-items: center;
gap: 8px;
min-height: 28px;
padding: 6px 10px;
border: 1px solid rgba(117, 240, 192, 0.25);
border-radius: 999px;
color: var(--mint);
background: rgba(117, 240, 192, 0.07);
font-size: 11px;
font-weight: 750;
}
.route-badge i {
width: 7px;
height: 7px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 12px currentColor;
}
.route-badge.closed {
color: var(--red);
border-color: rgba(255, 101, 125, 0.3);
background: rgba(255, 101, 125, 0.08);
}
.interaction-hint {
margin-top: 12px;
color: #70889a;
font-size: 10px;
letter-spacing: 0.04em;
}
.stats {
position: fixed;
z-index: 10;
top: 22px;
right: 22px;
width: 286px;
padding: 15px;
border-radius: 18px;
pointer-events: none;
}
.metric-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.metric {
min-width: 0;
padding: 10px 9px;
border: 1px solid rgba(255, 255, 255, 0.06);
border-radius: 12px;
background: rgba(255, 255, 255, 0.025);
}
.metric-label {
display: block;
overflow: hidden;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-overflow: ellipsis;
text-transform: uppercase;
white-space: nowrap;
}
.metric-value {
display: block;
margin-top: 4px;
font-size: 22px;
font-variant-numeric: tabular-nums;
font-weight: 750;
letter-spacing: -0.04em;
}
.metric:first-child .metric-value {
color: var(--amber);
}
.metric:nth-child(2) .metric-value {
color: var(--cyan);
}
.metric:nth-child(3) .metric-value {
color: var(--mint);
}
.activity {
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid rgba(255, 255, 255, 0.07);
}
.activity-heading {
display: flex;
justify-content: space-between;
align-items: center;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#deliveryRate {
color: var(--text);
font-size: 12px;
font-variant-numeric: tabular-nums;
letter-spacing: 0;
}
#activityChart {
display: block;
width: 100%;
height: 54px;
margin-top: 7px;
}
.legend {
position: fixed;
z-index: 10;
top: 190px;
left: 22px;
display: grid;
gap: 9px;
padding: 13px 15px;
border-radius: 14px;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 9px;
color: var(--muted);
font-size: 11px;
}
.legend-dot {
width: 9px;
height: 9px;
border-radius: 3px;
background: var(--cyan);
box-shadow: 0 0 10px rgba(101, 221, 255, 0.45);
}
.legend-dot.gold {
background: var(--amber);
box-shadow: 0 0 10px rgba(255, 197, 104, 0.4);
}
.legend-dot.mint {
background: var(--mint);
box-shadow: 0 0 10px rgba(117, 240, 192, 0.4);
}
.legend-dot.red {
background: var(--red);
box-shadow: 0 0 10px rgba(255, 101, 125, 0.4);
}
.disclaimer {
position: fixed;
z-index: 9;
bottom: 118px;
left: 50%;
width: min(650px, calc(100vw - 32px));
transform: translateX(-50%);
color: #a4bac8;
font-size: 11px;
line-height: 1.45;
text-align: center;
pointer-events: none;
}
.disclaimer strong {
color: #d6e7f0;
font-weight: 700;
}
.controls {
position: fixed;
z-index: 12;
bottom: 24px;
left: 50%;
display: flex;
align-items: center;
gap: 9px;
width: max-content;
max-width: calc(100vw - 32px);
padding: 10px;
transform: translateX(-50%);
border-radius: 18px;
}
.control-button {
min-height: 42px;
padding: 0 15px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 11px;
color: var(--text);
background: rgba(255, 255, 255, 0.055);
cursor: pointer;
font-size: 12px;
font-weight: 750;
transition:
transform 0.16s ease,
border-color 0.16s ease,
background 0.16s ease;
}
.control-button:hover {
transform: translateY(-1px);
border-color: rgba(101, 221, 255, 0.35);
background: rgba(101, 221, 255, 0.1);
}
.control-button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
.control-button.primary {
border-color: rgba(255, 101, 125, 0.42);
color: #fff3f5;
background: rgba(255, 101, 125, 0.16);
}
.control-button.primary.reopen {
border-color: rgba(117, 240, 192, 0.38);
color: #effff8;
background: rgba(117, 240, 192, 0.13);
}
.speed-control {
display: flex;
align-items: center;
gap: 10px;
min-height: 42px;
padding: 0 13px;
border: 1px solid rgba(255, 255, 255, 0.07);
border-radius: 11px;
color: var(--muted);
background: rgba(0, 0, 0, 0.12);
font-size: 11px;
font-weight: 700;
}
#flow {
width: 92px;
accent-color: var(--cyan);
cursor: pointer;
}
#flowValue {
width: 35px;
color: var(--text);
font-variant-numeric: tabular-nums;
text-align: right;
}
#labels {
position: fixed;
z-index: 4;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
min-width: 92px;
padding: 7px 10px;
transform: translate(-50%, -50%);
border: 1px solid rgba(148, 216, 255, 0.2);
border-radius: 9px;
color: #eaf7ff;
background: rgba(7, 17, 31, 0.82);
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.035em;
text-align: center;
white-space: nowrap;
transition:
left 0.04s linear,
top 0.04s linear,
border-color 0.2s ease;
}
.world-label small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 8px;
font-weight: 650;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#gateLabel.closed {
border-color: rgba(255, 101, 125, 0.62);
color: #ffd9df;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 760px) {
.brand {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.brand-copy {
margin-bottom: 10px;
}
.interaction-hint,
.legend {
display: none;
}
.stats {
top: 154px;
right: 12px;
left: 12px;
width: auto;
padding: 10px;
}
.metric {
padding: 8px;
}
.metric-value {
font-size: 19px;
}
.activity {
display: none;
}
.controls {
bottom: 12px;
flex-wrap: wrap;
justify-content: center;
width: calc(100vw - 24px);
}
.control-button {
flex: 1 1 auto;
padding: 0 10px;
}
.speed-control {
flex: 1 1 100%;
justify-content: center;
}
.disclaimer {
bottom: 130px;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive 3D vesicle transport schematic"></main>
<div id="labels" aria-hidden="true">
<div id="erLabel" class="world-label">
ENDOPLASMIC RETICULUM
<small id="erCount">0 cargo upstream</small>
</div>
<div id="gateLabel" class="world-label">
ROUTE R1
<small id="gateState">open</small>
</div>
<div id="golgiLabel" class="world-label">
SORTING STATION
<small>color conversion</small>
</div>
<div id="membraneLabel" class="world-label">
PLASMA MEMBRANE
<small>delivery pore</small>
</div>
</div>
<header class="brand panel">
<div class="eyebrow">Cellular logistics · interactive schematic</div>
<h1>Vesicle sorting & delivery</h1>
<p class="brand-copy">
Close one upstream transport route and watch cargo gather before the
gate while downstream delivery falls away.
</p>
<div id="routeBadge" class="route-badge">
<i></i>
Route R1 open
</div>
<div class="interaction-hint">DRAG TO ORBIT · SCROLL TO ZOOM · CLICK THE GATE</div>
</header>
<aside class="stats panel" aria-label="Simulation statistics">
<div class="metric-grid">
<div class="metric">
<span class="metric-label">Upstream</span>
<span id="upstreamValue" class="metric-value">0</span>
</div>
<div class="metric">
<span class="metric-label">Downstream</span>
<span id="downstreamValue" class="metric-value">0</span>
</div>
<div class="metric">
<span class="metric-label">Delivered</span>
<span id="deliveredValue" class="metric-value">0</span>
</div>
</div>
<div class="activity">
<div class="activity-heading">
<span>Delivery activity</span>
<span id="deliveryRate">0.0/s</span>
</div>
<canvas id="activityChart" aria-label="Recent delivery activity"></canvas>
</div>
</aside>
<aside class="legend panel" aria-label="Color legend">
<div class="legend-item">
<span class="legend-dot gold"></span>
Unsorted cargo
</div>
<div class="legend-item">
<span class="legend-dot mint"></span>
Sorted cargo
</div>
<div class="legend-item">
<span class="legend-dot"></span>
Active route
</div>
<div class="legend-item">
<span class="legend-dot red"></span>
Blocked route
</div>
</aside>
<div class="disclaimer">
<strong>Abstract transport visualization only.</strong>
This scene is not a clinically realistic cell or disease model.
</div>
<nav class="controls panel" aria-label="Simulation controls">
<button id="blockButton" class="control-button primary" aria-pressed="false">
<span id="blockButtonText">Block route R1</span>
</button>
<button id="pauseButton" class="control-button">Pause</button>
<label class="speed-control" for="flow">
Speed
<input id="flow" type="range" min="0.5" max="2" step="0.1" value="1" />
<span id="flowValue">1.0×</span>
</label>
<button id="resetButton" class="control-button">Reset</button>
</nav>
<div id="liveStatus" class="sr-only" aria-live="polite"></div>
<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: 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.15;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 20, 38);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraTarget = new THREE.Vector3(0, 0, 0);
let cameraRadius = 17.2;
let cameraTheta = 0.12;
let cameraPhi = 1.27;
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraRadius * sinPhi * Math.sin(cameraTheta),
cameraRadius * Math.cos(cameraPhi),
cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
scene.add(new THREE.HemisphereLight(0xa8e9ff, 0x101827, 2.1));
const keyLight = new THREE.DirectionalLight(0xc7efff, 2.8);
keyLight.position.set(4, 7, 11);
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x42d9ff, 15, 18, 2);
cyanLight.position.set(-5, 2, 6);
scene.add(cyanLight);
const warmLight = new THREE.PointLight(0xffb35c, 11, 16, 2);
warmLight.position.set(4, 1, 5);
scene.add(warmLight);
const root = new THREE.Group();
scene.add(root);
// Soft, low-poly particles behind the schematic.
const backgroundPositions = [];
for (let i = 0; i < 160; i++) {
backgroundPositions.push(
(Math.random() - 0.5) * 28,
(Math.random() - 0.5) * 18,
-2 - Math.random() * 7
);
}
const backgroundGeometry = new THREE.BufferGeometry();
backgroundGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(backgroundPositions, 3)
);
const backgroundPoints = new THREE.Points(
backgroundGeometry,
new THREE.PointsMaterial({
color: 0x6ac8ef,
size: 0.035,
transparent: true,
opacity: 0.35,
sizeAttenuation: true
})
);
scene.add(backgroundPoints);
// Stylized cell boundary.
const cellFill = new THREE.Mesh(
new THREE.CircleGeometry(5.43, 48),
new THREE.MeshBasicMaterial({
color: 0x174b68,
transparent: true,
opacity: 0.11,
depthWrite: false
})
);
cellFill.scale.y = 0.7;
cellFill.position.z = -0.32;
root.add(cellFill);
const membrane = new THREE.Mesh(
new THREE.TorusGeometry(5.5, 0.15, 6, 56),
new THREE.MeshStandardMaterial({
color: 0x247da3,
emissive: 0x0b3c5a,
emissiveIntensity: 0.75,
roughness: 0.38,
metalness: 0.2,
flatShading: true
})
);
membrane.scale.y = 0.7;
membrane.position.z = -0.04;
root.add(membrane);
const membraneInner = new THREE.Mesh(
new THREE.TorusGeometry(5.28, 0.035, 5, 48),
new THREE.MeshBasicMaterial({
color: 0x75dfff,
transparent: true,
opacity: 0.45
})
);
membraneInner.scale.y = 0.7;
membraneInner.position.z = 0.08;
root.add(membraneInner);
// Low-poly membrane proteins.
const proteinGeometry = new THREE.BoxGeometry(0.15, 0.3, 0.15);
const proteinMaterial = new THREE.MeshStandardMaterial({
color: 0x22516c,
roughness: 0.6,
flatShading: true
});
for (let i = 0; i < 18; i++) {
const angle = (i / 18) * Math.PI * 2;
const protein = new THREE.Mesh(proteinGeometry, proteinMaterial);
protein.position.set(
5.5 * Math.cos(angle),
3.85 * Math.sin(angle),
0.02
);
const tangentAngle = Math.atan2(
3.85 * Math.cos(angle),
-5.5 * Math.sin(angle)
);
protein.rotation.z = tangentAngle - Math.PI / 2;
root.add(protein);
}
// Schematic endoplasmic reticulum.
const erGroup = new THREE.Group();
erGroup.position.set(-0.1, -0.05, 0);
root.add(erGroup);
const erHalo = new THREE.Mesh(
new THREE.CircleGeometry(1.6, 24),
new THREE.MeshBasicMaterial({
color: 0xffb65f,
transparent: true,
opacity: 0.055,
depthWrite: false
})
);
erHalo.scale.set(1.35, 0.85, 1);
erHalo.position.set(-3.25, -0.45, -0.18);
erGroup.add(erHalo);
const erMaterial = new THREE.MeshStandardMaterial({
color: 0x4f9da8,
emissive: 0x163f48,
emissiveIntensity: 0.65,
roughness: 0.48,
metalness: 0.08,
flatShading: true
});
const ribosomeMaterial = new THREE.MeshStandardMaterial({
color: 0xff8c83,
emissive: 0x5c171f,
emissiveIntensity: 0.35,
roughness: 0.65,
flatShading: true
});
const ribosomeGeometry = new THREE.IcosahedronGeometry(0.075, 0);
const erCurves = [];
for (let row = 0; row < 5; row++) {
const y = -1.18 + row * 0.33;
const curve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-4.45, y, 0),
new THREE.Vector3(-3.8, y - 0.16, 0.02),
new THREE.Vector3(-3.2, y + 0.02, 0.05),
new THREE.Vector3(-2.65, y + 0.22, 0.08),
new THREE.Vector3(-2.35, y + 0.42, 0.1)
]);
erCurves.push(curve);
const cisterna = new THREE.Mesh(
new THREE.TubeGeometry(curve, 24, 0.105, 6, false),
erMaterial
);
erGroup.add(cisterna);
for (let j = 0; j < 7; j++) {
const t = 0.08 + (j / 6) * 0.84;
const point = curve.getPointAt(t);
const ribosome = new THREE.Mesh(
ribosomeGeometry,
ribosomeMaterial
);
ribosome.position.copy(point);
ribosome.position.z += 0.12;
ribosome.rotation.set(Math.random(), Math.random(), Math.random());
erGroup.add(ribosome);
}
}
// Stylized Golgi-like sorting station.
const golgiGroup = new THREE.Group();
golgiGroup.position.set(0.2, 0.12, 0.12);
root.add(golgiGroup);
const golgiHalo = new THREE.Mesh(
new THREE.CircleGeometry(1.18, 24),
new THREE.MeshBasicMaterial({
color: 0xffba65,
transparent: true,
opacity: 0.055,
depthWrite: false
})
);
golgiHalo.scale.set(1.15, 0.82, 1);
golgiHalo.position.z = -0.15;
golgiGroup.add(golgiHalo);
const golgiMaterial = new THREE.MeshStandardMaterial({
color: 0xe49b52,
emissive: 0x673316,
emissiveIntensity: 0.65,
roughness: 0.48,
metalness: 0.12,
flatShading: true
});
for (let row = 0; row < 5; row++) {
const y = -0.56 + row * 0.28;
const curve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-0.85, y, row * 0.045),
new THREE.Vector3(-0.35, y + 0.1, row * 0.045),
new THREE.Vector3(0.25, y + 0.08, row * 0.045),
new THREE.Vector3(0.75, y - 0.03, row * 0.045),
new THREE.Vector3(1.0, y - 0.22, row * 0.045)
]);
const cisterna = new THREE.Mesh(
new THREE.TubeGeometry(curve, 24, 0.11, 6, false),
golgiMaterial
);
golgiGroup.add(cisterna);
}
// The two visible transport segments. Only R1 can be blocked.
const routeACurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-2.68, -0.58, 0.42),
new THREE.Vector3(-2.0, -0.34, 0.44),
new THREE.Vector3(-1.25, -0.08, 0.47),
new THREE.Vector3(-0.4, 0.13, 0.48)
]);
const routeBCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(0.92, 0.28, 0.48),
new THREE.Vector3(1.8, 0.46, 0.48),
new THREE.Vector3(2.75, 0.69, 0.48),
new THREE.Vector3(3.75, 0.91, 0.48),
new THREE.Vector3(4.78, 1.04, 0.48)
]);
const routeAMaterial = new THREE.MeshStandardMaterial({
color: 0x65ddff,
emissive: 0x12647c,
emissiveIntensity: 0.8,
transparent: true,
opacity: 0.82,
roughness: 0.4,
depthWrite: false
});
const routeBMaterial = new THREE.MeshStandardMaterial({
color: 0x75f0c0,
emissive: 0x146849,
emissiveIntensity: 0.65,
transparent: true,
opacity: 0.78,
roughness: 0.4,
depthWrite: false
});
const routeAMesh = new THREE.Mesh(
new THREE.TubeGeometry(routeACurve, 36, 0.07, 6, false),
routeAMaterial
);
const routeBMesh = new THREE.Mesh(
new THREE.TubeGeometry(routeBCurve, 40, 0.07, 6, false),
routeBMaterial
);
root.add(routeAMesh, routeBMesh);
const arrowA = new THREE.MeshStandardMaterial({
color: 0x65ddff,
emissive: 0x12647c,
emissiveIntensity: 0.8,
transparent: true,
opacity: 0.82,
flatShading: true
});
const arrowB = new THREE.MeshStandardMaterial({
color: 0x75f0c0,
emissive: 0x146849,
emissiveIntensity: 0.65,
transparent: true,
opacity: 0.78,
flatShading: true
});
const upAxis = new THREE.Vector3(0, 1, 0);
function addRouteArrow(curve, t, material) {
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.1, 0.24, 5),
material
);
arrow.position.copy(curve.getPointAt(t));
arrow.quaternion.setFromUnitVectors(
upAxis,
curve.getTangentAt(t).normalize()
);
root.add(arrow);
}
[0.2, 0.48, 0.77].forEach((t) =>
addRouteArrow(routeACurve, t, arrowA)
);
[0.18, 0.43, 0.68, 0.88].forEach((t) =>
addRouteArrow(routeBCurve, t, arrowB)
);
// Route gate.
const gateProgress = 0.58;
const gatePosition = routeACurve.getPointAt(gateProgress);
const gateGroup = new THREE.Group();
gateGroup.position.copy(gatePosition);
gateGroup.position.z += 0.18;
root.add(gateGroup);
const gateMaterial = new THREE.MeshStandardMaterial({
color: 0x75f0c0,
emissive: 0x1b7654,
emissiveIntensity: 0.65,
roughness: 0.35,
metalness: 0.25,
flatShading: true
});
const gateDisk = new THREE.Mesh(
new THREE.CylinderGeometry(0.27, 0.27, 0.13, 6),
gateMaterial
);
gateDisk.rotation.x = Math.PI / 2;
gateGroup.add(gateDisk);
const gateBarMaterial = new THREE.MeshStandardMaterial({
color: 0xeafff6,
emissive: 0x75f0c0,
emissiveIntensity: 0.35,
flatShading: true
});
const gateBar = new THREE.Mesh(
new THREE.BoxGeometry(0.075, 0.32, 0.14),
gateBarMaterial
);
gateBar.position.z = 0.02;
gateGroup.add(gateBar);
const gatePulseMaterial = new THREE.MeshBasicMaterial({
color: 0x75f0c0,
transparent: true,
opacity: 0.28,
depthWrite: false
});
const gatePulse = new THREE.Mesh(
new THREE.TorusGeometry(0.36, 0.026, 5, 18),
gatePulseMaterial
);
gatePulse.position.z = 0.03;
gateGroup.add(gatePulse);
// Delivery pore and outside marker.
const pore = new THREE.Mesh(
new THREE.TorusGeometry(0.22, 0.055, 5, 12),
new THREE.MeshStandardMaterial({
color: 0x75f0c0,
emissive: 0x1a8058,
emissiveIntensity: 0.9,
roughness: 0.35,
flatShading: true
})
);
pore.position.set(5.23, 0.96, 0.22);
root.add(pore);
const deliveryStart = new THREE.Vector3(4.78, 1.04, 0.48);
const deliveryEnd = new THREE.Vector3(5.72, 1.03, 0.2);
// Cargo system.
const cargoLayer = new THREE.Group();
root.add(cargoLayer);
const cargoGeometry = new THREE.OctahedronGeometry(0.14, 0);
const cargoRingGeometry = new THREE.TorusGeometry(0.145, 0.018, 4, 10);
const cargoRingMaterial = new THREE.MeshStandardMaterial({
color: 0xe7f9ff,
emissive: 0x274b57,
emissiveIntensity: 0.25,
roughness: 0.35,
flatShading: true
});
const pulseGeometry = new THREE.OctahedronGeometry(0.16, 0);
const cargoList = [];
const deliveryPulses = [];
let blocked = false;
let paused = false;
let flow = 1;
let simTime = 0;
let spawnClock = 0;
let bucketClock = 0;
let delivered = 0;
const deliveryEvents = [];
const activityBuckets = Array(18).fill(0);
const activityBlocked = Array(18).fill(false);
function spawnCargo(initialProgress = null) {
const material = new THREE.MeshStandardMaterial({
color: 0xffc568,
emissive: 0x6a3510,
emissiveIntensity: 0.7,
roughness: 0.38,
metalness: 0.08,
flatShading: true
});
const group = new THREE.Group();
const body = new THREE.Mesh(cargoGeometry, material);
const ring = new THREE.Mesh(cargoRingGeometry, cargoRingMaterial);
group.add(body, ring);
cargoLayer.add(group);
const progress =
initialProgress !== null
? initialProgress
: blocked
? 0.025 + Math.random() * 0.08
: 0;
cargoList.push({
group,
material,
phase: "A",
progress,
target: blocked
? 0.2 + Math.random() * 0.36
: 1,
lane: (Math.random() - 0.5) * 0.38,
laneZ: (Math.random() - 0.5) * 0.25,
speed: 0.2 + Math.random() * 0.07,
spin: (Math.random() - 0.5) * 1.7
});
}
function transitionToDownstream(cargo) {
cargo.phase = "B";
cargo.progress = 0;
cargo.lane = (Math.random() - 0.5) * 0.28;
cargo.laneZ = (Math.random() - 0.5) * 0.18;
cargo.speed = 0.24 + Math.random() * 0.08;
cargo.material.color.setHex(0x75f0c0);
cargo.material.emissive.setHex(0x176044);
cargo.material.emissiveIntensity = 0.85;
}
function createDeliveryPulse() {
const material = new THREE.MeshStandardMaterial({
color: 0x9affd9,
emissive: 0x42e6a4,
emissiveIntensity: 1.3,
transparent: true,
opacity: 1,
roughness: 0.25,
flatShading: true
});
const mesh = new THREE.Mesh(pulseGeometry, material);
mesh.position.copy(deliveryStart);
root.add(mesh);
deliveryPulses.push({
mesh,
material,
age: 0
});
}
function deliverCargo(cargo, index) {
delivered += 1;
deliveryEvents.push(simTime);
activityBuckets[activityBuckets.length - 1] += 1;
createDeliveryPulse();
cargoLayer.remove(cargo.group);
cargo.material.dispose();
cargoList.splice(index, 1);
}
function setBlocked(value) {
blocked = value;
if (blocked) {
cargoList.forEach((cargo) => {
if (cargo.phase === "A" && cargo.progress <= gateProgress) {
cargo.target = Math.max(
cargo.progress,
0.2 + Math.random() * 0.36
);
}
});
} else {
cargoList.forEach((cargo) => {
if (cargo.phase === "A") {
cargo.target = 1;
}
});
}
routeAMaterial.color.setHex(blocked ? 0xff657d : 0x65ddff);
routeAMaterial.emissive.setHex(blocked ? 0x74162c : 0x12647c);
routeAMaterial.emissiveIntensity = blocked ? 0.55 : 0.8;
routeAMaterial.opacity = blocked ? 0.38 : 0.82;
routeBMaterial.opacity = blocked ? 0.2 : 0.78;
routeBMaterial.emissiveIntensity = blocked ? 0.25 : 0.65;
arrowA.color.setHex(blocked ? 0xff657d : 0x65ddff);
arrowA.emissive.setHex(blocked ? 0x74162c : 0x12647c);
arrowA.opacity = blocked ? 0.35 : 0.82;
arrowB.opacity = blocked ? 0.18 : 0.78;
arrowB.emissiveIntensity = blocked ? 0.2 : 0.65;
gateMaterial.color.setHex(blocked ? 0xff657d : 0x75f0c0);
gateMaterial.emissive.setHex(blocked ? 0x7f132b : 0x1b7654);
gateMaterial.emissiveIntensity = blocked ? 0.95 : 0.65;
gateBarMaterial.color.setHex(blocked ? 0xffe4e9 : 0xeafff6);
gateBarMaterial.emissive.setHex(blocked ? 0xff657d : 0x75f0c0);
gatePulseMaterial.color.setHex(blocked ? 0xff657d : 0x75f0c0);
gatePulseMaterial.opacity = blocked ? 0.48 : 0.25;
const badge = document.getElementById("routeBadge");
badge.className = `route-badge${blocked ? " closed" : ""}`;
badge.innerHTML = `<i></i>${blocked ? "Route R1 blocked" : "Route R1 open"}`;
const button = document.getElementById("blockButton");
button.classList.toggle("reopen", blocked);
button.setAttribute("aria-pressed", String(blocked));
document.getElementById("blockButtonText").textContent = blocked
? "Reopen route R1"
: "Block route R1";
document.getElementById("gateLabel").classList.toggle("closed", blocked);
document.getElementById("gateState").textContent = blocked
? "blocked"
: "open";
activityBlocked[activityBlocked.length - 1] = blocked;
document.getElementById("liveStatus").textContent = blocked
? "Route R1 blocked. Cargo is accumulating upstream."
: "Route R1 reopened. Cargo can continue downstream.";
}
function updateSimulation(dt) {
simTime += dt;
spawnClock += dt;
bucketClock += dt;
if (bucketClock >= 2) {
bucketClock -= 2;
activityBuckets.shift();
activityBlocked.shift();
activityBuckets.push(0);
activityBlocked.push(blocked);
}
if (spawnClock >= 0.85) {
spawnClock -= 0.85;
const upstreamCount = cargoList.filter(
(cargo) => cargo.phase === "A"
).length;
if (upstreamCount < (blocked ? 24 : 10)) {
spawnCargo();
}
}
for (let i = cargoList.length - 1; i >= 0; i--) {
const cargo = cargoList[i];
if (cargo.phase === "A") {
const heldAtGate =
blocked &&
cargo.progress <= gateProgress &&
cargo.progress < cargo.target;
if (heldAtGate) {
cargo.progress = Math.min(
cargo.target,
cargo.progress + cargo.speed * dt
);
} else if (blocked && cargo.progress <= gateProgress) {
cargo.progress = cargo.target;
} else {
cargo.progress += cargo.speed * dt;
if (cargo.progress >= 1) {
transitionToDownstream(cargo);
}
}
} else {
cargo.progress += cargo.speed * dt;
if (cargo.progress >= 1) {
deliverCargo(cargo, i);
}
}
}
}
function updateVisuals(dt) {
const normal = new THREE.Vector3();
cargoList.forEach((cargo) => {
const curve = cargo.phase === "A" ? routeACurve : routeBCurve;
const p = THREE.MathUtils.clamp(cargo.progress, 0, 0.9999);
const point = curve.getPointAt(p);
const tangent = curve.getTangentAt(p).normalize();
normal.set(-tangent.y, tangent.x, 0).normalize();
point.addScaledVector(normal, cargo.lane);
point.z += cargo.laneZ;
cargo.group.position.copy(point);
cargo.group.rotation.z += cargo.spin * dt;
cargo.group.rotation.y += dt * 0.35;
});
const pulseScale = blocked
? 1.05 + Math.sin(simTime * 5.5) * 0.15
: 1 + Math.sin(simTime * 2.5) * 0.07;
gatePulse.scale.setScalar(pulseScale);
gatePulse.rotation.z += dt * (blocked ? 1.1 : 0.35);
for (let i = deliveryPulses.length - 1; i >= 0; i--) {
const pulse = deliveryPulses[i];
pulse.age += dt;
const t = THREE.MathUtils.clamp(pulse.age / 0.8, 0, 1);
pulse.mesh.position.lerpVectors(deliveryStart, deliveryEnd, t);
pulse.mesh.scale.setScalar(1 - t * 0.48);
pulse.mesh.rotation.z += dt * 4;
pulse.material.opacity = 1 - t;
if (t >= 1) {
root.remove(pulse.mesh);
pulse.material.dispose();
deliveryPulses.splice(i, 1);
}
}
backgroundPoints.rotation.z += dt * 0.008;
}
// HUD and chart.
const upstreamValue = document.getElementById("upstreamValue");
const downstreamValue = document.getElementById("downstreamValue");
const deliveredValue = document.getElementById("deliveredValue");
const deliveryRate = document.getElementById("deliveryRate");
const erCount = document.getElementById("erCount");
function drawActivityChart() {
const canvas = document.getElementById("activityChart");
const width = canvas.clientWidth || 250;
const height = canvas.clientHeight || 54;
const dpr = Math.min(window.devicePixelRatio, 2);
if (
canvas.width !== Math.round(width * dpr) ||
canvas.height !== Math.round(height * dpr)
) {
canvas.width = Math.round(width * dpr);
canvas.height = Math.round(height * dpr);
}
const ctx = canvas.getContext("2d");
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
ctx.clearRect(0, 0, width, height);
ctx.strokeStyle = "rgba(145, 169, 188, 0.12)";
ctx.lineWidth = 1;
for (let i = 1; i < 3; i++) {
const y = (height / 3) * i;
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(width, y);
ctx.stroke();
}
const gap = 2;
const barWidth = Math.max(
2,
(width - gap * (activityBuckets.length - 1)) /
activityBuckets.length
);
const maxValue = Math.max(2, ...activityBuckets);
activityBuckets.forEach((value, index) => {
const barHeight = (value / maxValue) * (height - 8);
const x = index * (barWidth + gap);
const y = height - barHeight;
ctx.fillStyle = activityBlocked[index]
? "rgba(255, 101, 125, 0.82)"
: "rgba(117, 240, 192, 0.82)";
ctx.fillRect(x, y, barWidth, barHeight);
});
}
function updateHUD() {
const upstream = cargoList.filter(
(cargo) => cargo.phase === "A"
).length;
const downstream = cargoList.filter(
(cargo) => cargo.phase === "B"
).length;
upstreamValue.textContent = upstream;
downstreamValue.textContent = downstream;
deliveredValue.textContent = delivered;
erCount.textContent = `${upstream} cargo upstream`;
const recentEvents = deliveryEvents.filter(
(time) => time >= simTime - 10
).length;
const denominator = Math.max(1, Math.min(10, simTime));
deliveryRate.textContent = `${(recentEvents / denominator).toFixed(1)}/s`;
drawActivityChart();
}
// Project DOM labels onto 3D anchors.
const labels = [
{
element: document.getElementById("erLabel"),
position: new THREE.Vector3(-3.35, -1.85, 0.15)
},
{
element: document.getElementById("gateLabel"),
position: gatePosition.clone().add(new THREE.Vector3(0, 0.67, 0.25))
},
{
element: document.getElementById("golgiLabel"),
position: new THREE.Vector3(0.2, 1.24, 0.25)
},
{
element: document.getElementById("membraneLabel"),
position: new THREE.Vector3(4.3, 2.28, 0.2)
}
];
function updateLabels() {
labels.forEach(({ element, position }) => {
const projected = position.clone().project(camera);
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.opacity =
projected.z > 1 || projected.z < -1 ? "0" : "1";
});
}
// Direct camera controls: no addons or examples modules.
let pointerDown = false;
let pointerMoved = false;
let pointerStartX = 0;
let pointerStartY = 0;
let previousX = 0;
let previousY = 0;
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerDown = true;
pointerMoved = false;
pointerStartX = event.clientX;
pointerStartY = event.clientY;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerDown) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
if (
Math.hypot(
event.clientX - pointerStartX,
event.clientY - pointerStartY
) > 5
) {
pointerMoved = true;
}
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi - dy * 0.005,
0.55,
1.45
);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
pointerDown = false;
if (!pointerMoved) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(
gateGroup.children,
true
);
if (intersections.length > 0) {
setBlocked(!blocked);
}
}
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.012,
12,
24
);
updateCamera();
},
{ passive: false }
);
// UI events.
document
.getElementById("blockButton")
.addEventListener("click", () => setBlocked(!blocked));
document.getElementById("pauseButton").addEventListener("click", () => {
paused = !paused;
const button = document.getElementById("pauseButton");
button.textContent = paused ? "Resume" : "Pause";
document.getElementById("liveStatus").textContent = paused
? "Simulation paused."
: "Simulation resumed.";
});
document.getElementById("flow").addEventListener("input", (event) => {
flow = Number(event.target.value);
document.getElementById("flowValue").textContent = `${flow.toFixed(1)}×`;
});
function resetSimulation() {
cargoList.forEach((cargo) => {
cargoLayer.remove(cargo.group);
cargo.material.dispose();
});
cargoList.length = 0;
deliveryPulses.forEach((pulse) => {
root.remove(pulse.mesh);
pulse.material.dispose();
});
deliveryPulses.length = 0;
delivered = 0;
simTime = 0;
spawnClock = 0;
bucketClock = 0;
paused = false;
deliveryEvents.length = 0;
activityBuckets.fill(0);
activityBlocked.fill(false);
document.getElementById("pauseButton").textContent = "Pause";
setBlocked(false);
cameraRadius = 17.2;
cameraTheta = 0.12;
cameraPhi = 1.27;
updateCamera();
for (let i = 0; i < 6; i++) {
spawnCargo(0.08 + i * 0.1);
}
updateHUD();
}
document
.getElementById("resetButton")
.addEventListener("click", resetSimulation);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// Animation loop.
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const realDelta = Math.min(clock.getDelta(), 0.05);
const simulationDelta = realDelta * flow;
if (!paused) {
updateSimulation(simulationDelta);
}
updateVisuals(realDelta);
updateHUD();
updateLabels();
renderer.render(scene, camera);
}
resetSimulation();
animate();
</script>
</body>
</html>
```