Prompt specification
Build or customize the Three.js 3D scene "Engulfment versus surface-binding comparison" 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: Engulfment versus surface-binding comparison
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/engulfment-versus-surface-binding-comparison-x0868
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts phagocytosis. Let viewers toggle between receptor attachment and membrane enclosure around the same debris particle; reveal a sectional view demonstrating whether the object remains outside or enters a vesicle. Voxel style.
Working Three.js Starter (engulfment-versus-surface-binding-comparison-x0868):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Phagocytosis — Voxel Study</title>
<style>
:root {
--bg: #07131c;
--panel: rgba(8, 24, 33, 0.84);
--panel-border: rgba(98, 224, 203, 0.22);
--text: #e8fbf7;
--muted: #8eabb0;
--mint: #42e0bd;
--mint-dark: #158f7d;
--orange: #ff955f;
--purple: #aa8cff;
--lime: #b8e86d;
}
* {
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;
}
body {
background:
radial-gradient(circle at 68% 24%, rgba(25, 106, 101, 0.18), transparent 36%),
radial-gradient(circle at 30% 75%, rgba(22, 71, 92, 0.18), transparent 38%),
linear-gradient(145deg, #07131c, #091820 52%, #061016);
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
button,
input {
font: inherit;
}
.glass {
background: var(--panel);
border: 1px solid var(--panel-border);
box-shadow:
0 20px 70px rgba(0, 0, 0, 0.36),
inset 0 1px 0 rgba(255, 255, 255, 0.04);
backdrop-filter: blur(16px) saturate(130%);
-webkit-backdrop-filter: blur(16px) saturate(130%);
}
#control-panel {
position: fixed;
z-index: 10;
top: 18px;
left: 18px;
width: min(354px, calc(100vw - 36px));
padding: 19px;
border-radius: 18px;
pointer-events: auto;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
color: var(--mint);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 18px;
height: 2px;
background: var(--mint);
content: "";
box-shadow: 0 0 12px var(--mint);
}
h1 {
margin: 0;
font-size: clamp(27px, 4vw, 38px);
line-height: 1;
letter-spacing: -0.045em;
}
.intro {
margin: 11px 0 17px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.section-label {
margin: 17px 0 8px;
color: #6f9299;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.mode-switch {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.mode-button {
min-height: 64px;
padding: 11px 10px;
border: 1px solid rgba(142, 171, 176, 0.18);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
color: #91a9ae;
cursor: pointer;
text-align: left;
transition:
border-color 160ms ease,
background 160ms ease,
color 160ms ease,
transform 160ms ease;
}
.mode-button:hover {
border-color: rgba(66, 224, 189, 0.45);
color: #d7f8f1;
transform: translateY(-1px);
}
.mode-button.active {
border-color: rgba(66, 224, 189, 0.68);
background: rgba(66, 224, 189, 0.105);
color: #edfff9;
box-shadow: inset 0 0 20px rgba(66, 224, 189, 0.045);
}
.mode-button span {
display: block;
margin-bottom: 7px;
color: var(--mint);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.12em;
}
.mode-button strong {
display: block;
font-size: 12px;
line-height: 1.25;
}
.switch-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 12px;
padding: 10px 11px;
border: 1px solid rgba(142, 171, 176, 0.13);
border-radius: 10px;
background: rgba(0, 0, 0, 0.12);
}
.switch-copy strong,
.switch-copy small {
display: block;
}
.switch-copy strong {
font-size: 12px;
}
.switch-copy small {
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
.switch {
position: relative;
width: 39px;
height: 22px;
flex: 0 0 auto;
}
.switch input {
position: absolute;
width: 1px;
height: 1px;
opacity: 0;
}
.switch-track {
position: absolute;
inset: 0;
border: 1px solid rgba(142, 171, 176, 0.3);
border-radius: 999px;
background: #182a31;
cursor: pointer;
transition: 180ms ease;
}
.switch-track::after {
position: absolute;
top: 3px;
left: 3px;
width: 14px;
height: 14px;
border-radius: 50%;
background: #91a9ae;
content: "";
transition: 180ms ease;
}
.switch input:checked + .switch-track {
border-color: var(--mint);
background: var(--mint-dark);
box-shadow: 0 0 15px rgba(66, 224, 189, 0.22);
}
.switch input:checked + .switch-track::after {
left: 20px;
background: white;
transform: translateX(0);
}
.switch input:focus-visible + .switch-track {
outline: 2px solid white;
outline-offset: 3px;
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px 12px;
margin-top: 3px;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
color: #a6bbc0;
font-size: 10px;
}
.swatch {
width: 11px;
height: 11px;
border-radius: 2px;
box-shadow: inset -2px -2px 0 rgba(0, 0, 0, 0.18);
}
.swatch.membrane {
background: #31cbb0;
}
.swatch.receptor {
background: var(--lime);
}
.swatch.debris {
background: var(--orange);
}
.swatch.vesicle {
background: #8e83ec;
}
.replay {
width: 100%;
margin-top: 16px;
padding: 10px 12px;
border: 1px solid rgba(66, 224, 189, 0.22);
border-radius: 9px;
background: rgba(66, 224, 189, 0.06);
color: #bdeee3;
cursor: pointer;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.04em;
transition: 160ms ease;
}
.replay:hover {
background: rgba(66, 224, 189, 0.12);
border-color: rgba(66, 224, 189, 0.5);
}
#readout {
position: fixed;
z-index: 9;
bottom: 18px;
left: 50%;
width: min(780px, calc(100vw - 36px));
padding: 16px 18px;
border-radius: 15px;
transform: translateX(-50%);
pointer-events: none;
}
.readout-grid {
display: grid;
grid-template-columns: 1fr auto;
gap: 18px;
align-items: center;
}
#stage {
margin-bottom: 5px;
color: var(--mint);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.14em;
text-transform: uppercase;
}
#readout-title {
margin: 0 0 4px;
font-size: 17px;
letter-spacing: -0.02em;
}
#readout-detail {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
#status-badge {
min-width: 166px;
padding: 10px 12px;
border: 1px solid rgba(255, 149, 95, 0.35);
border-radius: 9px;
background: rgba(255, 149, 95, 0.08);
color: #ffc3a3;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.09em;
text-align: center;
text-transform: uppercase;
}
#status-badge[data-kind="inside"] {
border-color: rgba(142, 131, 236, 0.5);
background: rgba(142, 131, 236, 0.1);
color: #c6c0ff;
}
.stage-track {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 5px;
margin-top: 13px;
}
.stage-track span {
height: 3px;
border-radius: 999px;
background: rgba(255, 255, 255, 0.08);
transition: background 220ms ease, box-shadow 220ms ease;
}
.stage-track span.active {
background: var(--mint);
box-shadow: 0 0 9px rgba(66, 224, 189, 0.45);
}
.stage-track span.complete {
background: rgba(66, 224, 189, 0.42);
}
#camera-hint {
position: fixed;
z-index: 8;
top: 18px;
right: 18px;
display: flex;
align-items: center;
gap: 10px;
padding: 9px 11px;
border-radius: 10px;
color: #8ca7ac;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
letter-spacing: 0.03em;
pointer-events: none;
}
#reset-view {
padding: 6px 8px;
border: 1px solid rgba(142, 171, 176, 0.2);
border-radius: 6px;
background: transparent;
color: #b2c8cc;
cursor: pointer;
font-family: inherit;
font-size: 9px;
pointer-events: auto;
}
#reset-view:hover {
border-color: var(--mint);
color: white;
}
.scene-label {
position: fixed;
z-index: 6;
top: 0;
left: 0;
display: none;
align-items: center;
gap: 7px;
padding: 6px 8px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 6px;
background: rgba(5, 17, 24, 0.82);
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.25);
color: #c8dcde;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.08em;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -50%);
}
.scene-label::before {
width: 6px;
height: 6px;
flex: 0 0 auto;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 9px currentColor;
content: "";
}
.scene-label.debris {
color: var(--orange);
}
.scene-label.receptor {
color: var(--lime);
}
.scene-label.membrane {
color: var(--mint);
}
.scene-label.space {
color: #b6c7d4;
}
@media (max-width: 720px) {
#control-panel {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 14px;
}
.intro,
.legend,
#camera-hint {
display: none;
}
.mode-button {
min-height: 52px;
}
#readout {
bottom: 10px;
width: calc(100vw - 20px);
padding: 12px;
}
.readout-grid {
grid-template-columns: 1fr;
gap: 9px;
}
#status-badge {
min-width: 0;
padding: 7px;
}
#readout-title {
font-size: 14px;
}
#readout-detail {
font-size: 10px;
}
.scene-label {
font-size: 7px;
}
}
</style>
</head>
<body>
<aside id="control-panel" class="glass" aria-label="Scene controls">
<div class="eyebrow">Cellular process · Voxel study</div>
<h1>Phagocytosis</h1>
<p class="intro">
Follow one debris particle from receptor recognition to membrane enclosure.
Switch on the section view to reveal its final location.
</p>
<div class="section-label">Process state</div>
<div class="mode-switch" role="group" aria-label="Phagocytosis state">
<button class="mode-button active" data-mode="attachment" aria-pressed="true">
<span>01 / ATTACH</span>
<strong>Receptor attachment</strong>
</button>
<button class="mode-button" data-mode="enclosure" aria-pressed="false">
<span>02 / ENCLOSE</span>
<strong>Membrane enclosure</strong>
</button>
</div>
<div class="switch-row">
<div class="switch-copy">
<strong>Cross-section</strong>
<small>Cut through the membrane and cell</small>
</div>
<label class="switch">
<input id="section-toggle" type="checkbox" aria-label="Toggle cross-section" />
<span class="switch-track"></span>
</label>
</div>
<div class="section-label">Scene key</div>
<div class="legend">
<div class="legend-item">
<span class="swatch membrane"></span>
Cell membrane
</div>
<div class="legend-item">
<span class="swatch receptor"></span>
Receptor / ligand
</div>
<div class="legend-item">
<span class="swatch debris"></span>
Debris particle
</div>
<div class="legend-item">
<span class="swatch vesicle"></span>
Internal vesicle
</div>
</div>
<button id="replay" class="replay">↻ Replay enclosure animation</button>
</aside>
<div id="camera-hint" class="glass">
Drag to orbit · scroll to zoom
<button id="reset-view">Reset view</button>
</div>
<section id="readout" class="glass" aria-live="polite">
<div class="readout-grid">
<div>
<div id="stage">01 / RECEPTOR ATTACHMENT</div>
<h2 id="readout-title">Recognition at the cell surface.</h2>
<p id="readout-detail">
Receptors bind matching ligands and hold the debris outside the cell.
</p>
</div>
<div id="status-badge" data-kind="outside">Extracellular</div>
</div>
<div class="stage-track" aria-hidden="true">
<span class="active"></span>
<span></span>
<span></span>
<span></span>
</div>
</section>
<div id="label-particle" class="scene-label debris">
<span>Debris · same particle</span>
</div>
<div id="label-receptor" class="scene-label receptor">
<span>Ligand–receptor bonds</span>
</div>
<div id="label-membrane" class="scene-label membrane">
<span>Wrapping membrane</span>
</div>
<div id="label-space" class="scene-label space">
<span>Extracellular space</span>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene and renderer
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131c);
scene.fog = new THREE.FogExp2(0x07131c, 0.024);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.localClippingEnabled = true;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel depiction of phagocytosis"
);
document.body.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xb9fff1, 0x061018, 2.2);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(8, 13, 10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x35d8ff, 1.6);
rimLight.position.set(-9, 5, -8);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xff8a4c, 2.4, 7, 2);
warmLight.position.set(0, 3.1, 0.5);
scene.add(warmLight);
// -------------------------------------------------------------------------
// Shared helpers
// -------------------------------------------------------------------------
const clamp = (value, min, max) => Math.max(min, Math.min(max, value));
const lerp = THREE.MathUtils.lerp;
function smoothstep(edge0, edge1, value) {
const x = clamp((value - edge0) / (edge1 - edge0), 0, 1);
return x * x * (3 - 2 * x);
}
let randomSeed = 41872;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
const dummy = new THREE.Object3D();
const tempColor = new THREE.Color();
function setInstanceTransform(mesh, index, position, scale) {
dummy.position.copy(position);
dummy.scale.setScalar(Math.max(scale, 0.0001));
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
}
function createInstancedMesh(descriptors, geometry, material) {
const mesh = new THREE.InstancedMesh(
geometry,
material,
descriptors.length
);
descriptors.forEach((descriptor, index) => {
if (descriptor.position) dummy.position.copy(descriptor.position);
else dummy.position.set(0, 0, 0);
dummy.scale.setScalar(descriptor.scale ?? 1);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
if (descriptor.color) {
mesh.setColorAt(index, descriptor.color);
}
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
// The plane removes the front half of cellular structures in section mode.
const clipPlane = new THREE.Plane(
new THREE.Vector3(0, 0, -1),
0.05
);
const membraneMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.72,
metalness: 0.06
});
const granuleMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.85,
transparent: true,
opacity: 0.34,
depthWrite: false
});
const nucleusMaterial = new THREE.MeshStandardMaterial({
color: 0x7764bf,
roughness: 0.8,
transparent: true,
opacity: 0.63
});
const cupSideMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.62,
metalness: 0.04,
transparent: true,
opacity: 0.97
});
const cupCapMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.58,
metalness: 0.03,
transparent: true,
opacity: 0.77
});
const vesicleMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.6,
metalness: 0.05
});
const receptorStemMaterial = new THREE.MeshStandardMaterial({
color: 0xb8e86d,
roughness: 0.68
});
const receptorHeadMaterial = new THREE.MeshStandardMaterial({
color: 0xaa8cff,
roughness: 0.58
});
const ligandMaterial = new THREE.MeshStandardMaterial({
color: 0xffad67,
roughness: 0.55,
emissive: 0x4a1606,
emissiveIntensity: 0.45
});
const clippableMaterials = [
membraneMaterial,
granuleMaterial,
nucleusMaterial,
cupSideMaterial,
cupCapMaterial,
vesicleMaterial,
receptorStemMaterial,
receptorHeadMaterial
];
// -------------------------------------------------------------------------
// Voxel cell membrane
// -------------------------------------------------------------------------
const cellDescriptors = [];
const cellRadiusX = 6.25;
const cellRadiusY = 4.1;
const cellRadiusZ = 5.05;
const cellCenterY = -2.05;
for (let x = -6.3; x <= 6.3; x += 0.46) {
for (let y = -6.15; y <= 2.25; y += 0.46) {
for (let z = -5.1; z <= 5.1; z += 0.46) {
const nx = x / cellRadiusX;
const ny = (y - cellCenterY) / cellRadiusY;
const nz = z / cellRadiusZ;
const radiusSquared = nx * nx + ny * ny + nz * nz;
if (radiusSquared < 0.82 || radiusSquared > 1.025) continue;
const hue = 0.455 + random() * 0.035;
const lightness = 0.31 + random() * 0.11;
cellDescriptors.push({
position: new THREE.Vector3(x, y, z),
scale: 0.91 + random() * 0.1,
color: new THREE.Color().setHSL(hue, 0.58, lightness)
});
}
}
}
const cellMesh = createInstancedMesh(
cellDescriptors,
new THREE.BoxGeometry(0.46, 0.46, 0.46),
membraneMaterial
);
// -------------------------------------------------------------------------
// Cytoplasmic voxels and a dim nucleus visible in section mode
// -------------------------------------------------------------------------
const granuleDescriptors = [];
for (let i = 0; i < 135; i++) {
const x = (random() - 0.5) * 9.8;
const y = -5.2 + random() * 6.7;
const z = (random() - 0.5) * 8.2;
const q =
(x / 5.65) ** 2 +
((y - cellCenterY) / 3.62) ** 2 +
(z / 4.55) ** 2;
if (q > 0.68) continue;
const color = random() > 0.72
? new THREE.Color(0x8270d0)
: new THREE.Color(0x39bda9);
color.multiplyScalar(0.55 + random() * 0.45);
granuleDescriptors.push({
position: new THREE.Vector3(x, y, z),
scale: 0.55 + random() * 1.35,
color
});
}
createInstancedMesh(
granuleDescriptors,
new THREE.BoxGeometry(0.16, 0.16, 0.16),
granuleMaterial
);
const nucleusDescriptors = [];
const nucleusCenter = new THREE.Vector3(-2.05, -2.45, -0.55);
for (let x = -1.5; x <= 1.5; x += 0.34) {
for (let y = -1.3; y <= 1.3; y += 0.34) {
for (let z = -1.4; z <= 1.4; z += 0.34) {
const q =
(x / 1.4) ** 2 +
(y / 1.22) ** 2 +
(z / 1.32) ** 2;
if (q < 0.5 || q > 0.96) continue;
nucleusDescriptors.push({
position: new THREE.Vector3(
nucleusCenter.x + x,
nucleusCenter.y + y,
nucleusCenter.z + z
),
scale: 0.95,
color: new THREE.Color().setHSL(
0.71,
0.35,
0.34 + random() * 0.12
)
});
}
}
}
createInstancedMesh(
nucleusDescriptors,
new THREE.BoxGeometry(0.34, 0.34, 0.34),
nucleusMaterial
);
// -------------------------------------------------------------------------
// One persistent debris particle
// -------------------------------------------------------------------------
const debris = new THREE.Group();
scene.add(debris);
const debrisGeometry = new THREE.BoxGeometry(1, 1, 1);
const debrisMaterials = [
new THREE.MeshStandardMaterial({
color: 0xff9256,
roughness: 0.78,
emissive: 0x351006,
emissiveIntensity: 0.22
}),
new THREE.MeshStandardMaterial({
color: 0xd85c38,
roughness: 0.85
}),
new THREE.MeshStandardMaterial({
color: 0x623c32,
roughness: 0.95
})
];
const debrisBlocks = [
[0.00, 0.00, 0.00, 0.62, 0],
[0.34, 0.05, 0.03, 0.43, 1],
[-0.32, 0.08, 0.13, 0.41, 0],
[0.10, 0.35, -0.10, 0.43, 1],
[-0.13, 0.34, 0.23, 0.39, 0],
[0.18, -0.30, -0.14, 0.40, 0],
[-0.19, -0.29, 0.18, 0.36, 1],
[0.43, -0.18, 0.16, 0.32, 2],
[-0.43, -0.16, -0.13, 0.31, 1],
[0.17, 0.10, 0.42, 0.34, 0],
[-0.16, 0.11, -0.43, 0.32, 2],
[0.35, 0.33, 0.28, 0.27, 0],
[-0.35, 0.29, -0.29, 0.26, 2],
[0.02, -0.12, 0.43, 0.28, 1],
[-0.03, -0.10, -0.44, 0.27, 0],
[0.47, 0.13, -0.10, 0.22, 0],
[-0.47, 0.06, 0.08, 0.21, 2]
];
debrisBlocks.forEach(([x, y, z, size, materialIndex]) => {
const block = new THREE.Mesh(
debrisGeometry,
debrisMaterials[materialIndex]
);
block.position.set(x, y, z);
block.scale.setScalar(size);
block.castShadow = true;
block.receiveShadow = true;
debris.add(block);
});
const particleLight = new THREE.PointLight(0xff8349, 1.5, 4, 2);
debris.add(particleLight);
const externalParticlePosition = new THREE.Vector3(0, 3.18, 0.35);
const internalParticlePosition = new THREE.Vector3(0, 0.96, 0.24);
debris.position.copy(externalParticlePosition);
// -------------------------------------------------------------------------
// Receptors and ligand contacts
// -------------------------------------------------------------------------
const receptors = [];
const receptorData = [
{
base: new THREE.Vector3(-1.35, 1.93, 0.42),
target: new THREE.Vector3(-0.63, 2.59, 0.47)
},
{
base: new THREE.Vector3(-0.86, 2.00, 1.27),
target: new THREE.Vector3(-0.36, 2.64, 0.94)
},
{
base: new THREE.Vector3(0.86, 2.00, 1.27),
target: new THREE.Vector3(0.36, 2.64, 0.94)
},
{
base: new THREE.Vector3(1.35, 1.93, 0.42),
target: new THREE.Vector3(0.63, 2.59, 0.47)
},
{
base: new THREE.Vector3(-0.91, 2.01, -0.56),
target: new THREE.Vector3(-0.39, 2.61, -0.24)
},
{
base: new THREE.Vector3(0.91, 2.01, -0.56),
target: new THREE.Vector3(0.39, 2.61, -0.24)
},
{
base: new THREE.Vector3(0, 1.82, 1.72),
target: new THREE.Vector3(0, 2.61, 1.00)
}
];
const upAxis = new THREE.Vector3(0, 1, 0);
receptorData.forEach(({ base, target }) => {
const group = new THREE.Group();
group.position.copy(base);
const direction = target.clone().sub(base);
const length = direction.length();
direction.normalize();
group.quaternion.setFromUnitVectors(upAxis, direction);
const stem = new THREE.Mesh(
new THREE.BoxGeometry(0.17, length * 0.69, 0.17),
receptorStemMaterial
);
stem.position.y = length * 0.345;
stem.castShadow = true;
group.add(stem);
const shoulder = new THREE.Mesh(
new THREE.BoxGeometry(0.29, 0.22, 0.29),
receptorStemMaterial
);
shoulder.position.y = length * 0.69;
shoulder.castShadow = true;
group.add(shoulder);
const head = new THREE.Mesh(
new THREE.BoxGeometry(0.32, 0.28, 0.32),
receptorHeadMaterial
);
head.position.y = length - 0.08;
head.castShadow = true;
group.add(head);
const ligand = new THREE.Mesh(
new THREE.BoxGeometry(0.17, 0.17, 0.17),
ligandMaterial
);
ligand.position.y = length + 0.08;
ligand.castShadow = true;
group.add(ligand);
group.userData.ligand = ligand;
group.userData.length = length;
receptors.push(group);
scene.add(group);
});
// -------------------------------------------------------------------------
// Animated membrane cup
// -------------------------------------------------------------------------
const cupSideDescriptors = [];
const cupCapDescriptors = [];
const ringSteps = 20;
const cupLevels = 7;
for (let level = 0; level < cupLevels; level++) {
for (let ring = 0; ring < ringSteps; ring++) {
const angle = (ring / ringSteps) * Math.PI * 2;
cupSideDescriptors.push({
angle,
y: 1.84 + level * 0.36,
start: 0.055 + level * 0.035,
end: 0.31 + level * 0.045,
color: new THREE.Color().setHSL(
0.46 + random() * 0.025,
0.64,
0.39 + random() * 0.1
)
});
}
}
for (let gx = -4; gx <= 4; gx++) {
for (let gz = -3; gz <= 3; gz++) {
const q = (gx / 4.3) ** 2 + (gz / 3.35) ** 2;
if (q > 1.04) continue;
cupCapDescriptors.push({
x: gx * 0.31,
z: gz * 0.31,
y: 4.10,
color: new THREE.Color().setHSL(
0.47 + random() * 0.025,
0.62,
0.4 + random() * 0.1
)
});
}
}
const cupSideMesh = createInstancedMesh(
cupSideDescriptors,
new THREE.BoxGeometry(0.31, 0.31, 0.31),
cupSideMaterial
);
const cupCapMesh = createInstancedMesh(
cupCapDescriptors,
new THREE.BoxGeometry(0.31, 0.31, 0.31),
cupCapMaterial
);
cupSideMesh.frustumCulled = false;
cupCapMesh.frustumCulled = false;
// -------------------------------------------------------------------------
// Internal vesicle
// -------------------------------------------------------------------------
const vesicleDescriptors = [];
for (let x = -4; x <= 4; x++) {
for (let y = -3; y <= 3; y++) {
for (let z = -3; z <= 3; z++) {
const px = x * 0.3;
const py = y * 0.3;
const pz = z * 0.3;
const q =
(px / 1.28) ** 2 +
(py / 1.16) ** 2 +
(pz / 1.1) ** 2;
if (q < 0.63 || q > 0.99) continue;
vesicleDescriptors.push({
position: new THREE.Vector3(px, py, pz),
color: new THREE.Color().setHSL(
0.70 + random() * 0.035,
0.42,
0.42 + random() * 0.12
)
});
}
}
}
const vesicleMesh = createInstancedMesh(
vesicleDescriptors,
new THREE.BoxGeometry(0.3, 0.3, 0.3),
vesicleMaterial
);
vesicleMesh.frustumCulled = false;
// -------------------------------------------------------------------------
// Section plane indicator
// -------------------------------------------------------------------------
const sectionPlaneMaterial = new THREE.MeshBasicMaterial({
color: 0x6ad8ff,
transparent: true,
opacity: 0.035,
side: THREE.DoubleSide,
depthWrite: false,
toneMapped: false
});
const sectionPlaneMesh = new THREE.Mesh(
new THREE.PlaneGeometry(13.4, 10.7),
sectionPlaneMaterial
);
sectionPlaneMesh.position.set(0, -0.9, 0.05);
sectionPlaneMesh.renderOrder = -5;
sectionPlaneMesh.visible = false;
scene.add(sectionPlaneMesh);
const sectionOutlineGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-6.7, -6.25, 0.05),
new THREE.Vector3(6.7, -6.25, 0.05),
new THREE.Vector3(6.7, 4.45, 0.05),
new THREE.Vector3(-6.7, 4.45, 0.05),
new THREE.Vector3(-6.7, -6.25, 0.05)
]);
const sectionOutline = new THREE.Line(
sectionOutlineGeometry,
new THREE.LineBasicMaterial({
color: 0x7cdcff,
transparent: true,
opacity: 0.22,
toneMapped: false
})
);
sectionOutline.visible = false;
scene.add(sectionOutline);
// -------------------------------------------------------------------------
// Ground grid
// -------------------------------------------------------------------------
const grid = new THREE.GridHelper(
19,
38,
0x2b8b84,
0x153a45
);
grid.position.y = -6.18;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
const ground = new THREE.Mesh(
new THREE.CircleGeometry(10.8, 64),
new THREE.MeshStandardMaterial({
color: 0x081820,
roughness: 1,
transparent: true,
opacity: 0.88
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -6.21;
ground.receiveShadow = true;
scene.add(ground);
// -------------------------------------------------------------------------
// State and direct camera controls
// -------------------------------------------------------------------------
const state = {
mode: "attachment",
progress: 0,
progressTarget: 0,
section: false,
theta: 0.56,
targetTheta: 0.56,
phi: 1.04,
targetPhi: 1.04,
radius: 16.2,
targetRadius: 16.2,
cameraTarget: new THREE.Vector3(0, -0.45, 0)
};
function applyCamera() {
const sinPhi = Math.sin(state.phi);
camera.position.set(
state.cameraTarget.x +
state.radius * sinPhi * Math.sin(state.theta),
state.cameraTarget.y +
state.radius * Math.cos(state.phi),
state.cameraTarget.z +
state.radius * sinPhi * Math.cos(state.theta)
);
camera.lookAt(state.cameraTarget);
camera.updateMatrixWorld();
}
applyCamera();
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 deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
state.targetTheta -= deltaX * 0.006;
state.targetPhi = clamp(state.targetPhi - deltaY * 0.005, 0.46, 1.43);
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
state.targetRadius = clamp(
state.targetRadius + event.deltaY * 0.012,
10.5,
24
);
},
{ passive: false }
);
// -------------------------------------------------------------------------
// UI
// -------------------------------------------------------------------------
const modeButtons = [...document.querySelectorAll(".mode-button")];
const sectionToggle = document.getElementById("section-toggle");
const replayButton = document.getElementById("replay");
const resetViewButton = document.getElementById("reset-view");
const stageElement = document.getElementById("stage");
const titleElement = document.getElementById("readout-title");
const detailElement = document.getElementById("readout-detail");
const badgeElement = document.getElementById("status-badge");
const stageSegments = [...document.querySelectorAll(".stage-track span")];
const particleLabel = document.getElementById("label-particle");
const receptorLabel = document.getElementById("label-receptor");
const membraneLabel = document.getElementById("label-membrane");
const spaceLabel = document.getElementById("label-space");
function setMode(mode, replay = false) {
state.mode = mode;
if (mode === "enclosure") {
if (replay || state.progress < 0.02) {
state.progress = 0;
}
state.progressTarget = 1;
} else {
state.progressTarget = 0;
}
modeButtons.forEach((button) => {
const active = button.dataset.mode === mode;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
}
modeButtons.forEach((button) => {
button.addEventListener("click", () => {
setMode(button.dataset.mode);
});
});
function setSection(enabled) {
state.section = enabled;
sectionToggle.checked = enabled;
clippableMaterials.forEach((material) => {
material.clippingPlanes = enabled ? [clipPlane] : [];
material.clipShadows = enabled;
material.needsUpdate = true;
});
sectionPlaneMesh.visible = enabled;
sectionOutline.visible = enabled;
state.targetTheta = enabled ? 0.18 : 0.56;
state.targetPhi = enabled ? 1.1 : 1.04;
state.targetRadius = enabled ? 15.1 : 16.2;
}
sectionToggle.addEventListener("change", () => {
setSection(sectionToggle.checked);
});
replayButton.addEventListener("click", () => {
setMode("enclosure", true);
});
resetViewButton.addEventListener("click", () => {
state.targetTheta = state.section ? 0.18 : 0.56;
state.targetPhi = state.section ? 1.1 : 1.04;
state.targetRadius = state.section ? 15.1 : 16.2;
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function updateScene(progress) {
const moveProgress = smoothstep(0.58, 0.97, progress);
debris.position.lerpVectors(
externalParticlePosition,
internalParticlePosition,
moveProgress
);
debris.rotation.set(
0.03 + moveProgress * 0.09,
0.18 + moveProgress * 0.38,
-0.04
);
// Receptors retract as enclosure proceeds.
const receptorRetraction = smoothstep(0.18, 0.66, progress);
receptors.forEach((receptor) => {
receptor.scale.set(
1 - receptorRetraction * 0.12,
1 - receptorRetraction * 0.43,
1 - receptorRetraction * 0.12
);
receptor.visible = progress < 0.91;
});
// Membrane cup grows from the cell surface around the external particle.
cupSideDescriptors.forEach((descriptor, index) => {
const appearance = smoothstep(
descriptor.start,
descriptor.end,
progress
);
const radiusScale = 0.62 + appearance * 0.38;
const x =
externalParticlePosition.x +
Math.cos(descriptor.angle) * 1.46 * radiusScale;
const z =
externalParticlePosition.z +
Math.sin(descriptor.angle) * 1.27 * radiusScale;
const y = lerp(1.78, descriptor.y, appearance);
setInstanceTransform(
cupSideMesh,
index,
new THREE.Vector3(x, y, z),
appearance
);
});
cupSideMesh.instanceMatrix.needsUpdate = true;
// The upper membrane sheet closes over the particle.
cupCapDescriptors.forEach((descriptor, index) => {
const appearance = smoothstep(0.48, 0.79, progress);
setInstanceTransform(
cupCapMesh,
index,
new THREE.Vector3(
externalParticlePosition.x + descriptor.x,
lerp(3.62, descriptor.y, appearance),
externalParticlePosition.z + descriptor.z
),
appearance
);
});
cupCapMesh.instanceMatrix.needsUpdate = true;
const cupFade = smoothstep(0.73, 1, progress);
cupSideMaterial.opacity = 0.97 - cupFade * 0.68;
cupCapMaterial.opacity = 0.77 - cupFade * 0.46;
// A separate vesicle forms as the membrane pinches away from the cup.
const vesicleAppearance = smoothstep(0.68, 0.96, progress);
const vesicleTravel = smoothstep(0.72, 0.97, progress);
const vesicleCenter = externalParticlePosition.clone().lerp(
internalParticlePosition,
vesicleTravel
);
vesicleDescriptors.forEach((descriptor, index) => {
const local = descriptor.position;
const expansion = 0.45 + vesicleAppearance * 0.55;
setInstanceTransform(
vesicleMesh,
index,
new THREE.Vector3(
vesicleCenter.x + local.x * expansion,
vesicleCenter.y + local.y * expansion,
vesicleCenter.z + local.z * expansion
),
vesicleAppearance
);
});
vesicleMesh.instanceMatrix.needsUpdate = true;
warmLight.position.copy(debris.position);
warmLight.intensity = lerp(2.4, 1.5, moveProgress);
}
function updateStatus(progress) {
let stage;
let title;
let detail;
let badge;
let badgeKind;
let stageIndex;
if (state.mode === "attachment") {
stage = "01 / RECEPTOR ATTACHMENT";
title = "Recognition at the cell surface.";
detail =
"Receptors bind matching ligands and hold the debris outside the cell.";
badge = state.section ? "Section · remains outside" : "Extracellular";
badgeKind = "outside";
stageIndex = 0;
} else if (progress < 0.28) {
stage = "02 / MEMBRANE EXTENSION";
title = "A membrane cup extends toward the bound particle.";
detail =
"The cell surface rises around the same receptor-attached debris.";
badge = state.section
? "Section · outside"
: "Enclosure in progress";
badgeKind = "outside";
stageIndex = 1;
} else if (progress < 0.58) {
stage = "03 / MEMBRANE ENCLOSURE";
title = "The membrane wraps around the debris.";
detail =
"Opposing sides of the cup surround the particle while the receptors disengage.";
badge = state.section
? "Section · crossing membrane"
: "Particle enclosed";
badgeKind = "outside";
stageIndex = 2;
} else if (progress < 0.79) {
stage = "04 / PINCH-OFF";
title = "The membrane neck begins to constrict.";
detail =
"A membrane-bound compartment separates from the cell surface.";
badge = state.section
? "Section · forming vesicle"
: "Pinch-off";
badgeKind = "outside";
stageIndex = 3;
} else if (progress < 0.95) {
stage = "05 / VESICLE FORMATION";
title = "The debris moves into a vesicle.";
detail =
"The original particle is now surrounded by an internal membrane compartment.";
badge = state.section
? "Section · inside vesicle"
: "Internalization";
badgeKind = "inside";
stageIndex = 3;
} else {
stage = "05 / INTERNALIZATION COMPLETE";
title = "The same particle is now intracellular.";
detail =
"The section reveals the debris fully enclosed inside a membrane vesicle.";
badge = state.section
? "Section · inside vesicle"
: "Intracellular";
badgeKind = "inside";
stageIndex = 3;
}
if (stageElement.textContent !== stage) {
stageElement.textContent = stage;
}
if (titleElement.textContent !== title) {
titleElement.textContent = title;
}
if (detailElement.textContent !== detail) {
detailElement.textContent = detail;
}
if (badgeElement.textContent !== badge) {
badgeElement.textContent = badge;
}
badgeElement.dataset.kind = badgeKind;
stageSegments.forEach((segment, index) => {
segment.classList.toggle("active", index === stageIndex);
segment.classList.toggle("complete", index < stageIndex);
});
}
const projected = new THREE.Vector3();
function placeLabel(element, worldPosition, visible = true) {
if (!visible) {
element.style.display = "none";
return;
}
projected.copy(worldPosition).project(camera);
const visibleInFrame =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.05 &&
projected.x < 1.05 &&
projected.y > -1.05 &&
projected.y < 1.05;
if (!visibleInFrame) {
element.style.display = "none";
return;
}
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
element.style.display = "flex";
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function updateLabels(progress) {
const particleAnchor = debris.position.clone().add(
new THREE.Vector3(0, 1.08, 0)
);
const particleText = particleLabel.querySelector("span");
particleText.textContent =
state.mode === "attachment"
? "Debris · same particle"
: progress > 0.76
? "Debris · internalized"
: "Debris · enclosed";
placeLabel(particleLabel, particleAnchor);
placeLabel(
receptorLabel,
new THREE.Vector3(-1.95, 2.85, 1.0),
state.mode === "attachment" || progress < 0.43
);
const membraneText = membraneLabel.querySelector("span");
const vesicleReady = progress > 0.75;
membraneText.textContent = vesicleReady
? "Internal vesicle"
: "Wrapping membrane";
placeLabel(
membraneLabel,
vesicleReady
? new THREE.Vector3(1.15, 1.65, -0.35)
: new THREE.Vector3(1.72, 3.65, -0.35),
state.mode === "enclosure"
);
const spaceText = spaceLabel.querySelector("span");
spaceText.textContent =
state.mode === "attachment"
? "Extracellular space"
: "Intracellular cytoplasm";
placeLabel(
spaceLabel,
state.mode === "attachment"
? new THREE.Vector3(-3.0, 4.55, -0.4)
: new THREE.Vector3(-3.0, 2.0, -0.4),
state.section
);
}
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const response = 1 - Math.exp(-delta * 3.1);
state.progress +=
(state.progressTarget - state.progress) * response;
if (
state.mode === "attachment" &&
state.progressTarget === 0 &&
state.progress < 0.001
) {
state.progress = 0;
}
const cameraResponse = 1 - Math.exp(-delta * 8.0);
state.theta += (state.targetTheta - state.theta) * cameraResponse;
state.phi += (state.targetPhi - state.phi) * cameraResponse;
state.radius += (state.targetRadius - state.radius) * cameraResponse;
applyCamera();
updateScene(state.progress);
updateStatus(state.progress);
updateLabels(state.progress);
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
</script>
</body>
</html>
```