Prompt specification
Build or customize the Three.js 3D scene "Secretory cell transport diorama" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Secretory cell transport diorama
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/secretory-cell-transport-diorama-x0875
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows a voxel secretory-cell transport diorama in an open cutaway. Place the nucleus near one side, rough endoplasmic reticulum around it, a separate layered Golgi stack, and the plasma membrane around the outer edge.
Use a small labeled cargo marker that begins in the rough ER, travels in a vesicle to the Golgi, and then leaves in another vesicle for the cell membrane. Keep structural labels separate from the moving process indicator. The cargo should follow one continuous schematic route, with vesicle budding and arrival shown as distinct events rather than a marker passing through every organelle. At the final arrival, show the vesicle meeting the plasma membrane and releasing its cargo outward while its membrane joins the boundary.
Working Three.js Starter (secretory-cell-transport-diorama-x0875):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>Voxel Secretory-Cell Transport Diorama</title>
<style>
:root {
color-scheme: dark;
--ink: #eaf5ff;
--muted: #93a9bc;
--panel: rgba(8, 20, 34, 0.78);
--line: rgba(137, 205, 239, 0.17);
--cyan: #45caff;
--mint: #50e3c2;
--gold: #ffb35c;
--violet: #a486ff;
--pink: #ff5fa2;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 52% 42%, #142d43 0%, #091726 45%, #050b13 100%);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.hud {
position: fixed;
z-index: 10;
pointer-events: none;
}
.title {
top: 22px;
left: 24px;
max-width: 470px;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.6);
}
.eyebrow {
margin-bottom: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 42px);
line-height: 1;
letter-spacing: -0.045em;
font-weight: 760;
}
.subtitle {
margin-top: 10px;
color: var(--muted);
font-size: 13px;
letter-spacing: 0.03em;
}
.panel {
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(15px) saturate(125%);
}
.structures {
left: 24px;
bottom: 24px;
width: 244px;
padding: 15px 16px 14px;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 11px;
color: #bcd0df;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.static-tag {
padding: 3px 6px;
border: 1px solid rgba(122, 185, 217, 0.2);
border-radius: 999px;
color: #829bad;
font-size: 8px;
letter-spacing: 0.1em;
}
.structure-row {
display: grid;
grid-template-columns: 13px 1fr;
align-items: center;
gap: 9px;
min-height: 27px;
color: #dceaf3;
font-size: 12px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
box-shadow: 0 0 13px currentColor;
}
.structure-note {
margin: 10px 1px 0;
padding-top: 10px;
border-top: 1px solid var(--line);
color: #7992a5;
font-size: 10px;
line-height: 1.45;
}
.process {
top: 22px;
right: 24px;
width: 326px;
padding: 16px;
}
.live {
display: flex;
align-items: center;
gap: 7px;
color: var(--pink);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--pink);
box-shadow: 0 0 12px var(--pink);
animation: pulse 1.35s ease-in-out infinite;
}
@keyframes pulse {
50% { opacity: 0.35; transform: scale(0.75); }
}
#stage-title {
margin-top: 10px;
font-size: 18px;
line-height: 1.15;
letter-spacing: -0.025em;
font-weight: 720;
}
#stage-detail {
min-height: 36px;
margin-top: 7px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.process-track {
position: relative;
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: 5px;
margin-top: 14px;
}
.process-track::before {
content: "";
position: absolute;
top: 8px;
left: 9%;
right: 9%;
height: 1px;
background: rgba(125, 180, 210, 0.22);
}
.step {
position: relative;
z-index: 1;
text-align: center;
color: #61788b;
font-size: 8px;
font-weight: 750;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.step::before {
content: "";
display: block;
width: 8px;
height: 8px;
margin: 4px auto 7px;
border: 2px solid #284154;
border-radius: 50%;
background: #0a1724;
transition: 180ms ease;
}
.step.active { color: #e9f7ff; }
.step.active::before {
border-color: var(--pink);
background: var(--pink);
box-shadow: 0 0 12px rgba(255, 95, 162, 0.75);
}
.step.done { color: #9eb8c9; }
.step.done::before {
border-color: var(--mint);
background: var(--mint);
}
.progress {
height: 3px;
margin-top: 16px;
overflow: hidden;
border-radius: 99px;
background: rgba(116, 164, 191, 0.15);
}
#progress-fill {
width: 0;
height: 100%;
background: linear-gradient(90deg, var(--gold), var(--pink), var(--mint));
box-shadow: 0 0 12px rgba(255, 95, 162, 0.4);
}
.controls {
right: 24px;
bottom: 24px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
min-width: 78px;
padding: 9px 13px;
border: 1px solid rgba(133, 197, 229, 0.22);
border-radius: 10px;
background: rgba(9, 23, 38, 0.88);
color: #dcecf7;
font: inherit;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.07em;
text-transform: uppercase;
cursor: pointer;
transition: 150ms ease;
}
button:hover {
border-color: rgba(69, 202, 255, 0.65);
color: white;
transform: translateY(-1px);
}
.hint {
left: 50%;
bottom: 25px;
transform: translateX(-50%);
color: rgba(185, 211, 229, 0.58);
font-size: 10px;
letter-spacing: 0.07em;
text-align: center;
}
.label-anchor {
position: fixed;
z-index: 5;
width: 0;
height: 0;
pointer-events: none;
}
.label-anchor span {
position: absolute;
display: flex;
align-items: center;
gap: 6px;
white-space: nowrap;
transform: translate(calc(-50% + var(--ox)), calc(-50% + var(--oy)));
}
.structure-label {
padding: 5px 8px;
border: 1px solid rgba(133, 190, 220, 0.2);
border-radius: 6px;
background: rgba(5, 16, 27, 0.72);
color: #c4d8e6;
font-size: 9px;
font-weight: 780;
letter-spacing: 0.09em;
text-transform: uppercase;
box-shadow: 0 5px 16px rgba(0, 0, 0, 0.18);
}
.structure-label::before {
content: "";
width: 5px;
height: 5px;
border-radius: 1px;
background: var(--dot);
box-shadow: 0 0 8px var(--dot);
}
.cargo-label {
padding: 4px 7px;
border: 1px solid rgba(255, 95, 162, 0.75);
border-radius: 999px;
background: rgba(31, 8, 22, 0.82);
color: #ffd3e5;
font-size: 8px;
font-weight: 900;
letter-spacing: 0.13em;
box-shadow: 0 0 18px rgba(255, 95, 162, 0.22);
}
.cargo-label::before {
content: "";
width: 5px;
height: 5px;
border-radius: 1px;
background: var(--pink);
box-shadow: 0 0 8px var(--pink);
}
.cutaway-tag {
left: 50%;
top: 17px;
transform: translateX(-50%);
padding: 6px 10px;
border: 1px solid rgba(112, 188, 224, 0.16);
border-radius: 999px;
background: rgba(5, 15, 25, 0.5);
color: #6f8da2;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
@media (max-width: 760px) {
.title { top: 15px; left: 15px; }
.subtitle { display: none; }
.structures {
left: 12px;
bottom: 12px;
width: 190px;
padding: 11px 12px;
}
.structure-note { display: none; }
.process {
top: 92px;
right: 12px;
width: 255px;
padding: 12px;
}
#stage-title { font-size: 15px; }
.controls { right: 12px; bottom: 12px; }
.hint { display: none; }
.cutaway-tag { display: none; }
}
</style>
</head>
<body>
<div id="app"></div>
<header class="hud title">
<div class="eyebrow">Cellular logistics / live schematic</div>
<h1>Secretory Cell</h1>
<div class="subtitle">Voxel cutaway showing ER-to-Golgi-to-membrane cargo transport</div>
</header>
<section class="hud panel structures" aria-label="Structural labels">
<div class="panel-heading">
<span>Structures</span>
<span class="static-tag">Static</span>
</div>
<div class="structure-row"><i class="swatch" style="color:#a486ff;background:#a486ff"></i>Nucleus</div>
<div class="structure-row"><i class="swatch" style="color:#ffb35c;background:#ffb35c"></i>Rough endoplasmic reticulum</div>
<div class="structure-row"><i class="swatch" style="color:#50e3c2;background:#50e3c2"></i>Layered Golgi stack</div>
<div class="structure-row"><i class="swatch" style="color:#45caff;background:#45caff"></i>Plasma membrane</div>
<p class="structure-note">The front-left membrane is lowered to expose the interior. All organelle labels remain separate from the moving cargo indicator.</p>
</section>
<section class="hud panel process" aria-label="Moving cargo process">
<div class="live"><span class="live-dot"></span><span>Moving cargo indicator</span></div>
<div id="stage-title">Cargo held in rough ER</div>
<div id="stage-detail">The labeled cargo begins in a ribosome-studded ER cisterna.</div>
<div class="process-track">
<div class="step active" id="step-er">ER</div>
<div class="step" id="step-bud1">Bud 1</div>
<div class="step" id="step-golgi">Golgi</div>
<div class="step" id="step-bud2">Bud 2</div>
<div class="step" id="step-release">Release</div>
</div>
<div class="progress"><div id="progress-fill"></div></div>
</section>
<div class="hud controls">
<button id="play-button" type="button">Pause</button>
<button id="restart-button" type="button">Restart</button>
</div>
<div class="hud hint">Drag to orbit · Wheel to zoom · Double-click to reset</div>
<div class="hud cutaway-tag">Open cutaway</div>
<div class="label-anchor" id="label-nucleus" style="--ox:-4px;--oy:-30px">
<span class="structure-label" style="--dot:#a486ff">Nucleus</span>
</div>
<div class="label-anchor" id="label-er" style="--ox:5px;--oy:-24px">
<span class="structure-label" style="--dot:#ffb35c">Rough ER</span>
</div>
<div class="label-anchor" id="label-golgi" style="--ox:0px;--oy:-27px">
<span class="structure-label" style="--dot:#50e3c2">Golgi stack</span>
</div>
<div class="label-anchor" id="label-membrane" style="--ox:15px;--oy:25px">
<span class="structure-label" style="--dot:#45caff">Plasma membrane</span>
</div>
<div class="label-anchor" id="label-cargo" style="--ox:0px;--oy:-25px">
<span class="cargo-label">CARGO</span>
</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
const app = document.getElementById('app');
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111d);
scene.fog = new THREE.FogExp2(0x07111d, 0.027);
const camera = new THREE.PerspectiveCamera(42, innerWidth / innerHeight, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.22;
app.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xbceaff, 0x182237, 1.65);
scene.add(hemisphere);
const key = new THREE.DirectionalLight(0xf3fbff, 3.1);
key.position.set(5, 10, 7);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -12;
key.shadow.camera.right = 12;
key.shadow.camera.top = 10;
key.shadow.camera.bottom = -10;
key.shadow.camera.near = 1;
key.shadow.camera.far = 30;
key.shadow.bias = -0.0005;
scene.add(key);
const fill = new THREE.DirectionalLight(0x4e8dff, 1.65);
fill.position.set(-8, 5, -5);
scene.add(fill);
const rim = new THREE.PointLight(0x45e2d0, 18, 18, 2);
rim.position.set(3, 3, -6);
scene.add(rim);
const stage = new THREE.Mesh(
new THREE.PlaneGeometry(42, 42),
new THREE.MeshStandardMaterial({ color: 0x07111a, roughness: 0.93, metalness: 0.05 })
);
stage.rotation.x = -Math.PI / 2;
stage.position.y = -0.64;
stage.receiveShadow = true;
scene.add(stage);
const grid = new THREE.GridHelper(34, 34, 0x21465b, 0x102a3b);
grid.position.y = -0.625;
grid.material.transparent = true;
grid.material.opacity = 0.34;
scene.add(grid);
const cellGroup = new THREE.Group();
scene.add(cellGroup);
const clamp01 = v => Math.max(0, Math.min(1, v));
const smooth = v => {
v = clamp01(v);
return v * v * (3 - 2 * v);
};
const mix = (a, b, t) => a + (b - a) * t;
function signedPow(v, power = 0.5) {
return Math.sign(v) * Math.pow(Math.abs(v), power);
}
// ---------------------------------------------------------------------------
// Plasma membrane: a low, rounded voxel boundary with an open front-left cut.
// ---------------------------------------------------------------------------
const membraneChunks = [];
const membraneMaterial = new THREE.MeshStandardMaterial({
color: 0x2489ad,
emissive: 0x0b4360,
emissiveIntensity: 0.8,
roughness: 0.38,
metalness: 0.2
});
const membraneGeometry = new THREE.BoxGeometry(0.53, 0.38, 0.32);
const membraneCount = 96;
const a = 6.12;
const b = 4.28;
function squirclePoint(i) {
const angle = i / membraneCount * Math.PI * 2;
return new THREE.Vector3(
a * signedPow(Math.cos(angle)),
0,
b * signedPow(Math.sin(angle))
);
}
for (let i = 0; i < membraneCount; i++) {
const point = squirclePoint(i);
const next = squirclePoint((i + 1) % membraneCount);
const prev = squirclePoint((i - 1 + membraneCount) % membraneCount);
const tangent = next.clone().sub(prev);
const rotation = -Math.atan2(tangent.z, tangent.x);
const cutaway = point.z > 2.35 && point.x < 2.25;
const material = membraneMaterial.clone();
const chunk = new THREE.Mesh(membraneGeometry, material);
chunk.position.set(point.x, cutaway ? -0.19 : -0.02, point.z);
chunk.rotation.y = rotation;
chunk.scale.y = cutaway ? 0.5 : 1;
chunk.castShadow = true;
chunk.receiveShadow = true;
chunk.userData.baseScale = chunk.scale.clone();
chunk.userData.cutaway = cutaway;
cellGroup.add(chunk);
membraneChunks.push(chunk);
}
// ---------------------------------------------------------------------------
// Voxel nucleus placed near the left side of the cell.
// ---------------------------------------------------------------------------
const nucleusCenter = new THREE.Vector3(-3.05, 1.03, -0.48);
const nucleusPositions = [];
const nucleusColors = [];
const nucleusPalette = [0x7657c6, 0x8669db, 0x6849b4, 0x9478ea];
const nucleusRadius = new THREE.Vector3(1.3, 0.86, 1.13);
const voxel = 0.27;
for (let ix = -5; ix <= 5; ix++) {
for (let iy = -4; iy <= 4; iy++) {
for (let iz = -5; iz <= 5; iz++) {
const dx = ix * voxel / nucleusRadius.x;
const dy = iy * voxel / nucleusRadius.y;
const dz = iz * voxel / nucleusRadius.z;
if (dx * dx + dy * dy + dz * dz <= 1.02) {
nucleusPositions.push(new THREE.Vector3(
nucleusCenter.x + ix * voxel,
nucleusCenter.y + iy * voxel,
nucleusCenter.z + iz * voxel
));
nucleusColors.push(new THREE.Color(
nucleusPalette[Math.floor(Math.random() * nucleusPalette.length)]
));
}
}
}
}
const nucleusMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(voxel * 0.91, voxel * 0.91, voxel * 0.91),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.7,
metalness: 0.06
}),
nucleusPositions.length
);
const dummy = new THREE.Object3D();
nucleusPositions.forEach((position, i) => {
dummy.position.copy(position);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
nucleusMesh.setMatrixAt(i, dummy.matrix);
nucleusMesh.setColorAt(i, nucleusColors[i]);
});
nucleusMesh.instanceMatrix.needsUpdate = true;
nucleusMesh.instanceColor.needsUpdate = true;
nucleusMesh.castShadow = true;
nucleusMesh.receiveShadow = true;
cellGroup.add(nucleusMesh);
// Darker nucleolus blocks for visual differentiation.
const nucleolusMaterial = new THREE.MeshStandardMaterial({
color: 0x4e328d,
roughness: 0.8
});
for (let x = 0; x < 2; x++) {
for (let z = 0; z < 2; z++) {
const block = new THREE.Mesh(
new THREE.BoxGeometry(0.28, 0.28, 0.28),
nucleolusMaterial
);
block.position.set(-3.2 + x * 0.26, 1.8, -0.62 + z * 0.26);
block.castShadow = true;
cellGroup.add(block);
}
}
// ---------------------------------------------------------------------------
// Rough ER: concentric voxel cisternae wrapping around the nucleus.
// ---------------------------------------------------------------------------
const erMatrices = [];
const erColors = [];
const ribosomeMatrices = [];
const erCenter = new THREE.Vector3(-3.05, 0, -0.48);
const erSamples = 29;
for (let layer = 0; layer < 5; layer++) {
const y = 0.49 + layer * 0.265;
const radius = 1.56 + (layer % 2) * 0.075;
for (let i = 0; i < erSamples; i++) {
const angle = THREE.MathUtils.degToRad(-116 + (232 * i / (erSamples - 1)));
const x = erCenter.x + Math.cos(angle) * radius;
const z = erCenter.z + Math.sin(angle) * radius;
const nextAngle = angle + 0.03;
const nextX = erCenter.x + Math.cos(nextAngle) * radius;
const nextZ = erCenter.z + Math.sin(nextAngle) * radius;
const tangent = new THREE.Vector3(nextX - x, 0, nextZ - z);
dummy.position.set(x, y, z);
dummy.rotation.set(0, -Math.atan2(tangent.z, tangent.x), 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
erMatrices.push(dummy.matrix.clone());
erColors.push(new THREE.Color(layer % 2 ? 0xe98b3d : 0xffad58));
if (i % 2 === 0) {
dummy.position.set(x, y + 0.145, z);
dummy.scale.set(0.42, 0.48, 0.42);
dummy.updateMatrix();
ribosomeMatrices.push(dummy.matrix.clone());
}
}
}
const erMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.28, 0.145, 0.25),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.62,
metalness: 0.04,
emissive: 0x351404,
emissiveIntensity: 0.25
}),
erMatrices.length
);
erMatrices.forEach((matrix, i) => {
erMesh.setMatrixAt(i, matrix);
erMesh.setColorAt(i, erColors[i]);
});
erMesh.instanceMatrix.needsUpdate = true;
erMesh.instanceColor.needsUpdate = true;
erMesh.castShadow = true;
erMesh.receiveShadow = true;
cellGroup.add(erMesh);
const ribosomes = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.095, 0.095, 0.095),
new THREE.MeshStandardMaterial({ color: 0x753113, roughness: 0.85 }),
ribosomeMatrices.length
);
ribosomeMatrices.forEach((matrix, i) => ribosomes.setMatrixAt(i, matrix));
ribosomes.instanceMatrix.needsUpdate = true;
ribosomes.castShadow = true;
cellGroup.add(ribosomes);
// ---------------------------------------------------------------------------
// Separate layered Golgi stack.
// ---------------------------------------------------------------------------
const golgiMatrices = [];
const golgiColors = [];
const golgiPalette = [0x49d8c3, 0x56bfae, 0x68e4d0, 0x5fcbb7, 0x48a99f];
const golgiCenterX = 2.35;
const golgiCenterZ = -0.05;
for (let layer = 0; layer < 5; layer++) {
const y = 0.56 + layer * 0.265;
const width = 2.32 - layer * 0.105;
const tiles = 9;
for (let i = 0; i < tiles; i++) {
const u = i / (tiles - 1);
const x = golgiCenterX - width / 2 + width * u;
const z = golgiCenterZ + Math.sin(u * Math.PI) * 0.16;
const scale = 0.88 + Math.sin(u * Math.PI) * 0.16;
dummy.position.set(x, y, z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, scale);
dummy.updateMatrix();
golgiMatrices.push(dummy.matrix.clone());
golgiColors.push(new THREE.Color(golgiPalette[layer]));
}
}
const golgiMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.285, 0.15, 0.72),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.48,
metalness: 0.1,
emissive: 0x073b36,
emissiveIntensity: 0.32
}),
golgiMatrices.length
);
golgiMatrices.forEach((matrix, i) => {
golgiMesh.setMatrixAt(i, matrix);
golgiMesh.setColorAt(i, golgiColors[i]);
});
golgiMesh.instanceMatrix.needsUpdate = true;
golgiMesh.instanceColor.needsUpdate = true;
golgiMesh.castShadow = true;
golgiMesh.receiveShadow = true;
cellGroup.add(golgiMesh);
// ---------------------------------------------------------------------------
// One continuous schematic route, assembled from four smooth segments.
// ---------------------------------------------------------------------------
const P_ER = new THREE.Vector3(-1.45, 1.72, 0.68);
const P_CIS = new THREE.Vector3(1.15, 1.90, -0.05);
const P_TRANS = new THREE.Vector3(3.62, 1.90, -0.05);
const P_DOCK = new THREE.Vector3(3.62, 0.47, 4.16);
const P_OUT = new THREE.Vector3(3.62, 0.47, 5.22);
const routeER = new THREE.CatmullRomCurve3([
P_ER,
new THREE.Vector3(-0.35, 1.91, 0.56),
P_CIS
]);
const routeGolgi = new THREE.CatmullRomCurve3([
P_CIS,
new THREE.Vector3(2.30, 1.91, -0.02),
P_TRANS
]);
const routeMembrane = new THREE.CatmullRomCurve3([
P_TRANS,
new THREE.Vector3(4.25, 1.40, 1.15),
new THREE.Vector3(4.02, 0.75, 2.95),
P_DOCK
]);
const routeOutside = new THREE.CatmullRomCurve3([
P_DOCK,
new THREE.Vector3(3.62, 0.49, 4.70),
P_OUT
]);
const routeSamples = [];
for (const curve of [routeER, routeGolgi, routeMembrane, routeOutside]) {
const points = curve.getPoints(45);
routeSamples.push(...points);
}
const routeDashes = [];
for (let i = 0; i < routeSamples.length; i += 3) {
routeDashes.push(routeSamples[i]);
}
const routeMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.075, 0.075, 0.075),
new THREE.MeshStandardMaterial({
color: 0x4b9fbd,
emissive: 0x14516a,
emissiveIntensity: 0.7,
transparent: true,
opacity: 0.34,
depthWrite: false
}),
routeDashes.length
);
routeDashes.forEach((position, i) => {
dummy.position.copy(position);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
routeMesh.setMatrixAt(i, dummy.matrix);
});
routeMesh.instanceMatrix.needsUpdate = true;
cellGroup.add(routeMesh);
// ---------------------------------------------------------------------------
// Cargo marker: a tiny emissive voxel cross.
// ---------------------------------------------------------------------------
const cargo = new THREE.Group();
const cargoMaterial = new THREE.MeshStandardMaterial({
color: 0xff4f9b,
emissive: 0xff176f,
emissiveIntensity: 1.9,
roughness: 0.32,
metalness: 0.05
});
const cargoCore = new THREE.Mesh(
new THREE.BoxGeometry(0.19, 0.19, 0.19),
cargoMaterial
);
cargoCore.castShadow = true;
cargo.add(cargoCore);
for (const offset of [
[0.14, 0, 0], [-0.14, 0, 0],
[0, 0.14, 0], [0, -0.14, 0],
[0, 0, 0.14], [0, 0, -0.14]
]) {
const bit = new THREE.Mesh(
new THREE.BoxGeometry(0.075, 0.075, 0.075),
cargoMaterial
);
bit.position.set(...offset);
cargo.add(bit);
}
cellGroup.add(cargo);
// A small ER pocket makes the starting relationship explicit.
const erPocket = new THREE.Group();
for (let i = 0; i < 4; i++) {
const angle = i * Math.PI / 2 + Math.PI / 4;
const tile = new THREE.Mesh(
new THREE.BoxGeometry(0.16, 0.12, 0.16),
new THREE.MeshStandardMaterial({ color: 0xffb35c, emissive: 0x5a2204, emissiveIntensity: 0.7 })
);
tile.position.set(P_ER.x + Math.cos(angle) * 0.24, P_ER.y - 0.02, P_ER.z + Math.sin(angle) * 0.24);
erPocket.add(tile);
}
cellGroup.add(erPocket);
// ---------------------------------------------------------------------------
// Voxel vesicle membranes, assembled from small cubic tiles.
// ---------------------------------------------------------------------------
function createVesicle(color) {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color,
emissive: new THREE.Color(color).multiplyScalar(0.25),
emissiveIntensity: 1.25,
roughness: 0.35,
metalness: 0.08,
transparent: true,
opacity: 0.82,
depthWrite: false
});
const directions = [];
for (const x of [-1, 0, 1]) {
for (const y of [-1, 0, 1]) {
for (const z of [-1, 0, 1]) {
if (x === 0 && y === 0 && z === 0) continue;
const length = Math.sqrt(x*x + y*y + z*z);
if (length >= 1.35 && length <= 1.75) {
directions.push(new THREE.Vector3(x, y, z).normalize().multiplyScalar(0.285));
}
}
}
}
for (const direction of directions) {
const tile = new THREE.Mesh(
new THREE.BoxGeometry(0.145, 0.145, 0.145),
material
);
tile.position.copy(direction);
tile.castShadow = true;
group.add(tile);
}
group.userData.material = material;
group.visible = false;
cellGroup.add(group);
return group;
}
const erVesicle = createVesicle(0x52aef8);
const secretoryVesicle = createVesicle(0x56e2bd);
// A voxel patch that becomes continuous with the plasma membrane.
const fusionPatch = new THREE.Group();
const fusionMaterial = new THREE.MeshStandardMaterial({
color: 0x43c8ff,
emissive: 0x126b9b,
emissiveIntensity: 1.25,
roughness: 0.35,
metalness: 0.15,
transparent: true,
opacity: 0
});
for (let x = -1; x <= 1; x++) {
for (let z = -1; z <= 1; z++) {
const tile = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 0.11, 0.18),
fusionMaterial
);
tile.position.set(P_DOCK.x + x * 0.18, 0.17, P_DOCK.z + z * 0.18);
fusionPatch.add(tile);
}
}
fusionPatch.visible = false;
cellGroup.add(fusionPatch);
// ---------------------------------------------------------------------------
// Animation stages.
// ---------------------------------------------------------------------------
const durations = {
er: 2.2,
bud1: 4.0,
toGolgi: 7.0,
dock1: 8.2,
golgi: 9.7,
bud2: 11.5,
toMembrane: 15.2,
dock2: 16.6,
release: 18.7
};
let elapsed = 0;
let playing = true;
let completed = false;
const stageTitle = document.getElementById('stage-title');
const stageDetail = document.getElementById('stage-detail');
const progressFill = document.getElementById('progress-fill');
const playButton = document.getElementById('play-button');
const restartButton = document.getElementById('restart-button');
const steps = {
er: document.getElementById('step-er'),
bud1: document.getElementById('step-bud1'),
golgi: document.getElementById('step-golgi'),
bud2: document.getElementById('step-bud2'),
release: document.getElementById('step-release')
};
function setStep(name, state) {
steps[name].classList.toggle('active', state === 'active');
steps[name].classList.toggle('done', state === 'done');
}
function updateStageUI(t) {
let title;
let detail;
let active;
if (t < durations.er) {
title = 'Cargo held in rough ER';
detail = 'The labeled cargo begins in a ribosome-studded ER cisterna.';
active = 'er';
} else if (t < durations.bud1) {
title = 'ER vesicle budding';
detail = 'A transport vesicle forms around the cargo at the ER membrane.';
active = 'bud1';
} else if (t < durations.toGolgi) {
title = 'Vesicle traveling to Golgi';
detail = 'The cargo is enclosed and carried along the schematic route.';
active = 'golgi';
} else if (t < durations.dock1) {
title = 'Arrival at cis-Golgi';
detail = 'The first vesicle reaches the Golgi and fuses with its receiving face.';
active = 'golgi';
} else if (t < durations.golgi) {
title = 'Golgi processing';
detail = 'The cargo moves across the layered Golgi stack before repackaging.';
active = 'golgi';
} else if (t < durations.bud2) {
title = 'Secretory vesicle budding';
detail = 'A second, distinct vesicle buds from the trans-Golgi face.';
active = 'bud2';
} else if (t < durations.toMembrane) {
title = 'Secretory vesicle traveling';
detail = 'The cargo remains inside the vesicle as it approaches the cell edge.';
active = 'bud2';
} else if (t < durations.dock2) {
title = 'Vesicle reaches plasma membrane';
detail = 'The vesicle meets the boundary and prepares for membrane fusion.';
active = 'release';
} else if (t < durations.release) {
title = 'Cargo released outward';
detail = 'Cargo crosses the boundary while the vesicle membrane joins the plasma membrane.';
active = 'release';
} else {
title = 'Secretion complete';
detail = 'Cargo is outside the cell and the vesicle membrane has become part of the boundary.';
active = 'release';
}
if (stageTitle.textContent !== title) stageTitle.textContent = title;
if (stageDetail.textContent !== detail) stageDetail.textContent = detail;
const state = name => {
if (name === active) return 'active';
const order = ['er', 'bud1', 'golgi', 'bud2', 'release'];
return order.indexOf(name) < order.indexOf(active) ? 'done' : '';
};
for (const name of Object.keys(steps)) setStep(name, state(name));
progressFill.style.width = `${clamp01(t / durations.release) * 100}%`;
}
function updateCargo(t) {
cargo.position.copy(P_ER);
cargo.rotation.y = t * 0.45;
cargo.scale.setScalar(1);
erVesicle.visible = false;
secretoryVesicle.visible = false;
fusionPatch.visible = false;
fusionMaterial.opacity = 0;
// ER residence and first budding event.
if (t < durations.bud1) {
const u = clamp01((t - durations.er) / (durations.bud1 - durations.er));
erVesicle.visible = true;
erVesicle.position.copy(P_ER);
const s = smooth(u);
erVesicle.scale.setScalar(0.04 + s * 0.96);
cargo.position.copy(P_ER);
}
// Transport from ER to the cis face.
if (t >= durations.bud1 && t < durations.toGolgi) {
const u = clamp01((t - durations.bud1) / (durations.toGolgi - durations.bud1));
const position = routeER.getPoint(u);
erVesicle.visible = true;
erVesicle.position.copy(position);
erVesicle.scale.setScalar(1);
cargo.position.copy(position);
}
// Distinct arrival/docking event at the Golgi.
if (t >= durations.toGolgi && t < durations.dock1) {
const u = clamp01((t - durations.toGolgi) / (durations.dock1 - durations.toGolgi));
erVesicle.visible = true;
erVesicle.position.copy(P_CIS);
erVesicle.scale.set(1 + u * 0.18, 1 - u * 0.28, 1 - u * 0.36);
cargo.position.copy(P_CIS);
}
// The cargo crosses the Golgi stack.
if (t >= durations.dock1 && t < durations.golgi) {
const u = clamp01((t - durations.dock1) / (durations.golgi - durations.dock1));
cargo.position.copy(routeGolgi.getPoint(u));
cargo.rotation.y += 0.045;
}
// A separate vesicle buds from the trans face.
if (t >= durations.golgi && t < durations.bud2) {
const u = clamp01((t - durations.golgi) / (durations.bud2 - durations.golgi));
cargo.position.copy(P_TRANS);
secretoryVesicle.visible = true;
secretoryVesicle.position.copy(P_TRANS);
secretoryVesicle.scale.setScalar(0.04 + smooth(u) * 0.96);
}
// Secretory transport to the membrane.
if (t >= durations.bud2 && t < durations.toMembrane) {
const u = clamp01((t - durations.bud2) / (durations.toMembrane - durations.bud2));
const position = routeMembrane.getPoint(u);
secretoryVesicle.visible = true;
secretoryVesicle.position.copy(position);
secretoryVesicle.scale.setScalar(1);
cargo.position.copy(position);
cargo.rotation.y += 0.04;
}
// Distinct vesicle arrival at the plasma membrane.
if (t >= durations.toMembrane && t < durations.dock2) {
const u = clamp01((t - durations.toMembrane) / (durations.dock2 - durations.toMembrane));
secretoryVesicle.visible = true;
secretoryVesicle.position.copy(P_DOCK);
secretoryVesicle.scale.set(1 + u * 0.13, 1 - u * 0.25, 1 + u * 0.1);
cargo.position.copy(P_DOCK);
}
// Final exocytosis-like event: cargo exits; vesicle membrane becomes boundary.
if (t >= durations.dock2 && t < durations.release) {
const u = clamp01((t - durations.dock2) / (durations.release - durations.dock2));
const eased = smooth(u);
cargo.position.copy(routeOutside.getPoint(eased));
cargo.rotation.y += 0.08;
secretoryVesicle.visible = true;
secretoryVesicle.position.copy(P_DOCK);
secretoryVesicle.scale.set(
1.08 + eased * 0.38,
1 - eased * 0.73,
1.08 + eased * 0.42
);
secretoryVesicle.userData.material.opacity = 0.82 * (1 - eased * 0.72);
fusionPatch.visible = true;
fusionPatch.position.set(P_DOCK.x, 0, P_DOCK.z);
fusionPatch.scale.setScalar(0.25 + eased * 0.78);
fusionMaterial.opacity = eased * 0.92;
for (const chunk of membraneChunks) {
const distance = Math.hypot(chunk.position.x - P_DOCK.x, chunk.position.z - P_DOCK.z);
if (distance < 0.85) {
const local = 1 - distance / 0.85;
chunk.scale.x = chunk.userData.baseScale.x * (1 + eased * local * 0.18);
chunk.scale.y = chunk.userData.baseScale.y * (1 + eased * local * 0.48);
}
}
}
if (t >= durations.release) {
cargo.position.copy(P_OUT);
cargo.rotation.y += 0.02;
fusionPatch.visible = true;
fusionMaterial.opacity = 0.92;
secretoryVesicle.visible = false;
for (const chunk of membraneChunks) {
const distance = Math.hypot(chunk.position.x - P_DOCK.x, chunk.position.z - P_DOCK.z);
if (distance < 0.85) {
const local = 1 - distance / 0.85;
chunk.scale.x = chunk.userData.baseScale.x * (1 + local * 0.18);
chunk.scale.y = chunk.userData.baseScale.y * (1 + local * 0.48);
}
}
}
// Gentle cargo pulse keeps the small marker legible.
const pulse = 1 + Math.sin(t * 5.2) * 0.045;
cargo.scale.setScalar(pulse);
}
playButton.addEventListener('click', () => {
if (completed) {
elapsed = 0;
completed = false;
playing = true;
playButton.textContent = 'Pause';
return;
}
playing = !playing;
playButton.textContent = playing ? 'Pause' : 'Play';
});
restartButton.addEventListener('click', () => {
elapsed = 0;
completed = false;
playing = true;
playButton.textContent = 'Pause';
});
// ---------------------------------------------------------------------------
// Camera controls implemented directly, without examples or addon modules.
// ---------------------------------------------------------------------------
const cameraState = {
yaw: 0.72,
pitch: 0.92,
radius: 15.6,
target: new THREE.Vector3(0, 0.62, 0)
};
const defaultCamera = { ...cameraState };
function updateCamera() {
const horizontal = Math.sin(cameraState.pitch) * cameraState.radius;
camera.position.set(
cameraState.target.x + Math.sin(cameraState.yaw) * horizontal,
cameraState.target.y + Math.cos(cameraState.pitch) * cameraState.radius,
cameraState.target.z + Math.cos(cameraState.yaw) * horizontal
);
camera.lookAt(cameraState.target);
}
updateCamera();
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener('pointerdown', event => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener('pointermove', event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(cameraState.pitch + dy * 0.005, 0.48, 1.24);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener('pointerup', stopDragging);
renderer.domElement.addEventListener('pointercancel', stopDragging);
renderer.domElement.addEventListener('wheel', event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
10.5,
23
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener('dblclick', () => {
cameraState.yaw = defaultCamera.yaw;
cameraState.pitch = defaultCamera.pitch;
cameraState.radius = defaultCamera.radius;
cameraState.target.copy(defaultCamera.target);
updateCamera();
});
// ---------------------------------------------------------------------------
// HTML labels projected from fixed structural anchors and the moving cargo.
// ---------------------------------------------------------------------------
const labelItems = [
{ element: document.getElementById('label-nucleus'), position: new THREE.Vector3(-3.05, 2.03, -0.48) },
{ element: document.getElementById('label-er'), position: new THREE.Vector3(-1.62, 1.88, 0.74) },
{ element: document.getElementById('label-golgi'), position: new THREE.Vector3(2.35, 1.94, -0.05) },
{ element: document.getElementById('label-membrane'), position: new THREE.Vector3(4.85, 0.34, 3.65) },
{ element: document.getElementById('label-cargo'), position: cargo.position }
];
const projected = new THREE.Vector3();
function updateLabels() {
for (const item of labelItems) {
projected.copy(item.position).project(camera);
const visible = projected.z > -1 && projected.z < 1;
item.element.style.display = visible ? 'block' : 'none';
if (!visible) continue;
item.element.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
item.element.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
}
}
window.addEventListener('resize', () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
// ---------------------------------------------------------------------------
// Main loop.
// ---------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (playing && !completed) {
elapsed += dt;
if (elapsed >= durations.release) {
elapsed = durations.release;
completed = true;
playing = false;
playButton.textContent = 'Replay';
}
}
updateCargo(elapsed);
updateStageUI(elapsed);
// Cargo labels use the current animated position.
labelItems[4].position.copy(cargo.position);
camera.updateMatrixWorld();
updateLabels();
renderer.render(scene, camera);
}
updateCargo(0);
updateStageUI(0);
animate();
</script>
</body>
</html>
```