Prompt specification
Build or customize the Three.js 3D scene "Motor protein cargo on a filament" 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: Motor protein cargo on a filament
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/motor-protein-cargo-on-a-filament-x0833
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows cytoskeletal cargo transport. Build one filament track, a simplified two-part motor, and attached vesicle; animate directed stepping schematically while labeling all molecular dimensions exaggerated. Low-poly.
Working Three.js Starter (motor-protein-cargo-on-a-filament-x0833):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Cytoskeletal Cargo Transport</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: rgba(10, 24, 42, 0.82);
--border: rgba(145, 196, 226, 0.2);
--text: #eaf5ff;
--muted: #91abc1;
--cyan: #48dfd0;
--blue: #6688ff;
--orange: #ff9f43;
--purple: #b176ff;
--yellow: #ffe082;
}
* { 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; }
#app {
position: relative;
width: 100%;
height: 100%;
isolation: isolate;
}
#scene {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active { cursor: grabbing; }
.vignette {
position: absolute;
inset: 0;
z-index: 1;
pointer-events: none;
background:
radial-gradient(circle at 52% 42%, transparent 30%, rgba(1, 7, 16, 0.2) 72%),
linear-gradient(180deg, rgba(3, 10, 20, 0.08), rgba(3, 10, 20, 0.28));
}
#labels {
position: absolute;
inset: 0;
z-index: 2;
pointer-events: none;
overflow: hidden;
}
.label {
--accent: var(--cyan);
position: absolute;
min-width: 132px;
max-width: 190px;
padding: 8px 10px 9px;
border: 1px solid rgba(177, 219, 240, 0.2);
border-left: 3px solid var(--accent);
border-radius: 7px;
background: rgba(6, 18, 33, 0.88);
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(8px);
transform: translate(-50%, -50%);
transition: opacity 120ms ease;
white-space: nowrap;
font-size: 11px;
line-height: 1.35;
color: #d9e9f4;
}
.label::after {
content: "";
position: absolute;
left: 7px;
bottom: -15px;
width: 1px;
height: 14px;
background: linear-gradient(var(--accent), transparent);
opacity: 0.75;
}
.label .kicker {
display: block;
margin-bottom: 2px;
color: var(--accent);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.label b {
display: block;
margin-top: 3px;
color: #fff;
font-size: 10px;
font-weight: 650;
}
.labels-off .label { opacity: 0 !important; }
.hud {
position: absolute;
z-index: 4;
top: 22px;
left: 24px;
right: 24px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 18px;
pointer-events: none;
}
.brand {
display: flex;
align-items: flex-start;
gap: 12px;
}
.brand-mark {
width: 11px;
height: 38px;
margin-top: 2px;
border-radius: 8px;
background: linear-gradient(var(--cyan), var(--blue));
box-shadow: 0 0 22px rgba(72, 223, 208, 0.28);
}
h1 {
margin: 0;
font-size: clamp(18px, 2vw, 27px);
font-weight: 700;
letter-spacing: -0.035em;
}
.subtitle {
margin: 5px 0 0;
color: var(--muted);
font-size: 12px;
letter-spacing: 0.01em;
}
.badge {
flex: 0 0 auto;
padding: 8px 11px;
border: 1px solid rgba(255, 224, 130, 0.35);
border-radius: 999px;
background: rgba(65, 49, 18, 0.44);
color: var(--yellow);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.info {
position: absolute;
z-index: 4;
top: 94px;
right: 24px;
width: 245px;
padding: 15px;
border: 1px solid var(--border);
border-radius: 12px;
background: var(--panel);
box-shadow: 0 16px 55px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(12px);
}
.section-title {
margin: 0 0 10px;
color: #dcecf7;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.legend {
display: grid;
gap: 8px;
margin-bottom: 14px;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
color: #c8dbe8;
font-size: 11px;
}
.swatch {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 2px;
box-shadow: 0 0 10px currentColor;
}
.swatch.blue { color: var(--blue); background: var(--blue); }
.swatch.orange { color: var(--orange); background: var(--orange); }
.swatch.purple { color: var(--purple); background: var(--purple); }
.swatch.cyan { color: var(--cyan); background: var(--cyan); }
.dimension-list {
margin: 0;
padding: 11px 0 0;
border-top: 1px solid var(--border);
}
.dimension-row {
display: flex;
justify-content: space-between;
gap: 12px;
margin: 7px 0;
color: var(--muted);
font-size: 10px;
}
.dimension-row strong {
color: #e8f5ff;
font-weight: 650;
}
.note {
margin: 11px 0 0;
color: #7893a8;
font-size: 9px;
line-height: 1.5;
}
.controls {
position: absolute;
z-index: 5;
left: 24px;
bottom: 23px;
display: flex;
align-items: center;
gap: 9px;
padding: 9px;
border: 1px solid var(--border);
border-radius: 12px;
background: rgba(7, 19, 34, 0.88);
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(10px);
}
.control-button {
min-width: 75px;
padding: 8px 11px;
border: 1px solid rgba(130, 186, 218, 0.2);
border-radius: 7px;
background: rgba(36, 70, 96, 0.45);
color: #e8f5ff;
cursor: pointer;
font-size: 11px;
font-weight: 650;
transition: background 150ms ease, border-color 150ms ease;
}
.control-button:hover {
border-color: rgba(72, 223, 208, 0.55);
background: rgba(37, 94, 105, 0.56);
}
.control-button.primary {
border-color: rgba(72, 223, 208, 0.45);
background: rgba(41, 137, 132, 0.48);
}
.speed-box {
display: grid;
grid-template-columns: auto 88px auto;
align-items: center;
gap: 8px;
padding: 0 5px;
color: var(--muted);
font-size: 10px;
}
input[type="range"] {
width: 88px;
accent-color: var(--cyan);
cursor: pointer;
}
#speedValue {
width: 31px;
color: #dcecf7;
font-variant-numeric: tabular-nums;
}
.status {
position: absolute;
z-index: 4;
left: 50%;
bottom: 25px;
width: min(340px, 40vw);
transform: translateX(-50%);
pointer-events: none;
text-align: center;
}
.status-pill {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 8px 13px;
border: 1px solid var(--border);
border-radius: 999px;
background: rgba(7, 19, 34, 0.74);
color: #dcecf7;
font-size: 10px;
backdrop-filter: blur(8px);
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 12px var(--cyan);
}
.progress-track {
height: 2px;
margin-top: 8px;
overflow: hidden;
border-radius: 2px;
background: rgba(117, 157, 183, 0.18);
}
#progressFill {
width: 0;
height: 100%;
background: linear-gradient(90deg, var(--cyan), var(--blue), var(--purple));
box-shadow: 0 0 10px rgba(72, 223, 208, 0.5);
}
.hint {
position: absolute;
z-index: 4;
right: 24px;
bottom: 27px;
color: #68849a;
font-size: 9px;
text-align: right;
line-height: 1.5;
pointer-events: none;
}
@media (max-width: 760px) {
.hud { top: 15px; left: 15px; right: 15px; }
.badge { max-width: 125px; text-align: center; line-height: 1.35; }
.subtitle { font-size: 10px; max-width: 250px; }
.info { display: none; }
.controls { left: 12px; bottom: 12px; gap: 6px; padding: 7px; }
.control-button { min-width: 61px; padding: 7px 8px; }
.speed-box { grid-template-columns: 42px 58px 28px; gap: 5px; }
input[type="range"] { width: 58px; }
.status { display: none; }
.hint { right: 12px; bottom: 76px; }
.label { min-width: 108px; max-width: 145px; padding: 6px 8px; font-size: 9px; }
}
</style>
</head>
<body>
<div id="app">
<canvas id="scene"></canvas>
<div class="vignette"></div>
<div id="labels">
<div class="label" id="headLabel" style="--accent: var(--blue)">
<span class="kicker">Motor part 1</span>
Microtubule-binding head
<b>~15–20 nm</b>
</div>
<div class="label" id="neckLabel" style="--accent: var(--orange)">
<span class="kicker">Motor part 2</span>
Cargo-binding neck
<b>~10 nm</b>
</div>
<div class="label" id="vesicleLabel" style="--accent: var(--purple)">
<span class="kicker">Attached cargo</span>
Transport vesicle
<b>~50–80 nm</b>
</div>
<div class="label" id="trackLabel" style="--accent: var(--cyan)">
<span class="kicker">Filament track</span>
Microtubule diameter
<b>~25 nm</b>
</div>
<div class="label" id="stepLabel" style="--accent: var(--yellow)">
<span class="kicker">Directed step</span>
One motor step
<b>~8 nm</b>
</div>
<div class="label" id="minusLabel" style="--accent: #91abc1; min-width: auto">
<span class="kicker">− end</span>
</div>
<div class="label" id="plusLabel" style="--accent: var(--cyan); min-width: auto">
<span class="kicker">+ end</span>
</div>
<div class="label" id="directionLabel" style="--accent: var(--cyan); min-width: auto">
<span class="kicker">Transport direction →</span>
</div>
</div>
<header class="hud">
<div class="brand">
<div class="brand-mark"></div>
<div>
<h1>Cytoskeletal Cargo Transport</h1>
<p class="subtitle">A low-poly, schematic motor making ATP-powered steps along a single filament.</p>
</div>
</div>
<div class="badge">All molecular dimensions exaggerated</div>
</header>
<aside class="info">
<p class="section-title">Molecular legend</p>
<div class="legend">
<div class="legend-row"><i class="swatch cyan"></i>Single filament track</div>
<div class="legend-row"><i class="swatch blue"></i>Motor: binding head</div>
<div class="legend-row"><i class="swatch orange"></i>Motor: cargo neck</div>
<div class="legend-row"><i class="swatch purple"></i>Attached vesicle</div>
</div>
<p class="section-title">Indicative dimensions</p>
<div class="dimension-list">
<div class="dimension-row"><span>Filament diameter</span><strong>~25 nm</strong></div>
<div class="dimension-row"><span>Two-part motor</span><strong>~25–30 nm</strong></div>
<div class="dimension-row"><span>Transport vesicle</span><strong>~50–80 nm</strong></div>
<div class="dimension-row"><span>Directed step</span><strong>~8 nm</strong></div>
</div>
<p class="note">
Molecular sizes are deliberately enlarged and are not drawn to a common scale.
The animation represents repeated binding, power-stroke, and recovery phases.
</p>
</aside>
<div class="controls">
<button class="control-button primary" id="playButton" type="button">Pause</button>
<button class="control-button" id="resetButton" type="button">Reset</button>
<button class="control-button" id="viewButton" type="button">View</button>
<button class="control-button" id="labelsButton" type="button">Labels</button>
<div class="speed-box">
<span>Speed</span>
<input id="speed" type="range" min="0.4" max="2" value="1" step="0.1" />
<span id="speedValue">1.0×</span>
</div>
</div>
<div class="status">
<div class="status-pill">
<i class="status-dot"></i>
<span id="statusText">Dwell · ATP loaded</span>
</div>
<div class="progress-track"><div id="progressFill"></div></div>
</div>
<div class="hint">
Drag: orbit · Shift/right-drag: pan · Scroll: zoom<br />
Double-click: reset camera
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const labelsLayer = document.querySelector("#labels");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
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.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.FogExp2(0x07111f, 0.025);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const controls = {
target: new THREE.Vector3(0, 0.72, 0),
theta: 0.43,
phi: 1.15,
radius: window.innerWidth < 760 ? 19 : 14.6
};
function applyCamera() {
const spherical = new THREE.Spherical(controls.radius, controls.phi, controls.theta);
camera.position.setFromSpherical(spherical).add(controls.target);
camera.lookAt(controls.target);
camera.updateMatrixWorld();
}
applyCamera();
scene.add(new THREE.HemisphereLight(0x8bc8ff, 0x172034, 1.65));
const keyLight = new THREE.DirectionalLight(0xffffff, 2.25);
keyLight.position.set(4, 9, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.bias = -0.0006;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x35dfd0, 18, 24, 2);
rimLight.position.set(-5, 2.5, -3);
scene.add(rimLight);
const cargoLight = new THREE.PointLight(0xa56cff, 12, 14, 2);
cargoLight.position.set(3.5, 4, 3);
scene.add(cargoLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(42, 42),
new THREE.MeshStandardMaterial({
color: 0x081522,
roughness: 0.95,
metalness: 0.03
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.12;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(30, 30, 0x28475c, 0x173044);
grid.position.y = -1.09;
grid.material.transparent = true;
grid.material.opacity = 0.32;
grid.material.depthWrite = false;
scene.add(grid);
// ---------------------------------------------------------------------
// Single low-poly filament track
// ---------------------------------------------------------------------
const trackMaterial = new THREE.MeshStandardMaterial({
color: 0x28b9ad,
emissive: 0x073c38,
emissiveIntensity: 0.55,
roughness: 0.52,
metalness: 0.12,
flatShading: true
});
const track = new THREE.Mesh(
new THREE.CylinderGeometry(0.19, 0.19, 19, 8, 1, false),
trackMaterial
);
track.rotation.z = Math.PI / 2;
track.castShadow = true;
track.receiveShadow = true;
scene.add(track);
const ringGeometry = new THREE.TorusGeometry(0.205, 0.032, 4, 8);
const ringMaterial = new THREE.MeshStandardMaterial({
color: 0x5ce5d8,
emissive: 0x0a4b45,
emissiveIntensity: 0.42,
roughness: 0.48,
metalness: 0.08,
flatShading: true
});
for (let x = -9.2; x <= 9.21; x += 0.8) {
const ring = new THREE.Mesh(ringGeometry, ringMaterial);
ring.rotation.y = Math.PI / 2;
ring.position.set(x, 0, 0);
ring.castShadow = true;
scene.add(ring);
}
const endCapMaterial = new THREE.MeshStandardMaterial({
color: 0x94fff1,
emissive: 0x17675e,
emissiveIntensity: 0.8,
roughness: 0.35,
flatShading: true
});
const plusCap = new THREE.Mesh(
new THREE.CylinderGeometry(0.205, 0.205, 0.13, 8),
endCapMaterial
);
plusCap.rotation.z = Math.PI / 2;
plusCap.position.x = 9.52;
scene.add(plusCap);
// Schematic transport-direction arrow.
const directionArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(-7.4, 0.56, -0.52),
2.35,
0x62efe1,
0.32,
0.18
);
directionArrow.line.material.transparent = true;
directionArrow.line.material.opacity = 0.82;
directionArrow.cone.material.transparent = true;
directionArrow.cone.material.opacity = 0.9;
scene.add(directionArrow);
// ---------------------------------------------------------------------
// Simplified two-part motor and attached vesicle
// ---------------------------------------------------------------------
const headMaterial = new THREE.MeshStandardMaterial({
color: 0x6688ff,
emissive: 0x152c78,
emissiveIntensity: 0.72,
roughness: 0.34,
metalness: 0.18,
flatShading: true,
transparent: true
});
const neckMaterial = new THREE.MeshStandardMaterial({
color: 0xff9f43,
emissive: 0x713300,
emissiveIntensity: 0.52,
roughness: 0.42,
metalness: 0.12,
flatShading: true,
transparent: true
});
const collarMaterial = new THREE.MeshStandardMaterial({
color: 0xffc173,
emissive: 0x5c2f00,
emissiveIntensity: 0.4,
roughness: 0.46,
metalness: 0.1,
flatShading: true,
transparent: true
});
const tetherMaterial = new THREE.MeshStandardMaterial({
color: 0xe4efff,
emissive: 0x344867,
emissiveIntensity: 0.35,
roughness: 0.48,
flatShading: true,
transparent: true
});
const vesicleMaterial = new THREE.MeshStandardMaterial({
color: 0xb176ff,
emissive: 0x42156b,
emissiveIntensity: 0.65,
roughness: 0.35,
metalness: 0.08,
flatShading: true,
transparent: true
});
const motorHead = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.5, 0),
headMaterial
);
motorHead.scale.set(1.18, 0.73, 0.94);
motorHead.position.set(-5.2, 0.52, 0);
motorHead.rotation.y = 0.28;
motorHead.castShadow = true;
scene.add(motorHead);
const motorNeck = new THREE.Mesh(
new THREE.CylinderGeometry(0.22, 0.3, 0.65, 6),
neckMaterial
);
motorNeck.position.set(-5.2, 1.08, 0);
motorNeck.castShadow = true;
scene.add(motorNeck);
const collar = new THREE.Mesh(
new THREE.CylinderGeometry(0.34, 0.34, 0.13, 8),
collarMaterial
);
collar.position.set(-5.2, 0.84, 0);
collar.castShadow = true;
scene.add(collar);
const motorConnector = new THREE.Mesh(
new THREE.CylinderGeometry(0.075, 0.075, 1, 6),
tetherMaterial
);
motorConnector.castShadow = true;
scene.add(motorConnector);
const cargoTether = new THREE.Mesh(
new THREE.CylinderGeometry(0.052, 0.052, 1, 6),
tetherMaterial
);
cargoTether.castShadow = true;
scene.add(cargoTether);
const vesicle = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.68, 0),
vesicleMaterial
);
vesicle.scale.set(1, 0.9, 0.95);
vesicle.position.set(-5.2, 2.14, 0);
vesicle.rotation.set(0.25, 0.4, -0.12);
vesicle.castShadow = true;
scene.add(vesicle);
const contactRingMaterial = new THREE.MeshStandardMaterial({
color: 0xffdf78,
emissive: 0xff9e20,
emissiveIntensity: 1.25,
roughness: 0.35,
flatShading: true,
transparent: true
});
const contactRing = new THREE.Mesh(
new THREE.TorusGeometry(0.315, 0.047, 4, 12),
contactRingMaterial
);
contactRing.rotation.y = Math.PI / 2;
contactRing.position.set(-5.2, 0, 0);
scene.add(contactRing);
// ---------------------------------------------------------------------
// Dimension brackets
// ---------------------------------------------------------------------
function makeBracket(color) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(18), 3).setUsage(THREE.DynamicDrawUsage)
);
const line = new THREE.LineSegments(
geometry,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.9
})
);
line.frustumCulled = false;
scene.add(line);
return line;
}
function setBracket(line, points) {
const array = line.geometry.attributes.position.array;
for (let i = 0; i < points.length; i++) {
array[i * 3] = points[i].x;
array[i * 3 + 1] = points[i].y;
array[i * 3 + 2] = points[i].z;
}
line.geometry.attributes.position.needsUpdate = true;
}
const trackBracket = makeBracket(0x48dfd0);
const motorBracket = makeBracket(0x6688ff);
const vesicleBracket = makeBracket(0xb176ff);
const stepBracket = makeBracket(0xffe082);
// ---------------------------------------------------------------------
// Animation state
// ---------------------------------------------------------------------
const START_X = -5.2;
const STEP_DISTANCE = 0.8;
const TOTAL_STEPS = 13;
const CYCLE_DURATION = 1.15;
const TRAVEL_DURATION = TOTAL_STEPS * CYCLE_DURATION;
const HOLD_DURATION = 1.5;
const FADE_DURATION = 0.8;
let simulationTime = 0;
let playing = true;
let speed = 1;
let labelsVisible = true;
const state = {
headX: START_X,
neckX: START_X,
cargoX: START_X,
stepA: START_X,
stepB: START_X + STEP_DISTANCE,
phase: "Dwell · ATP loaded",
opacity: 1,
progress: 0
};
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
const lerp = (a, b, t) => a + (b - a) * t;
const ease = t => {
t = clamp(t, 0, 1);
return t * t * (3 - 2 * t);
};
const easeOut = t => 1 - Math.pow(1 - clamp(t, 0, 1), 3);
function updateSimulation(time) {
const totalDuration = TRAVEL_DURATION + HOLD_DURATION + FADE_DURATION;
const localTime = time % totalDuration;
let headX = START_X;
let neckX = START_X;
let cargoX = START_X;
let stepA = START_X;
let stepB = START_X + STEP_DISTANCE;
let phase = "Dwell · ATP loaded";
let opacity = 1;
if (localTime < TRAVEL_DURATION) {
const stepPosition = localTime / CYCLE_DURATION;
const index = Math.min(Math.floor(stepPosition), TOTAL_STEPS - 1);
const p = stepPosition - index;
const a = START_X + index * STEP_DISTANCE;
const b = a + STEP_DISTANCE;
stepA = a;
stepB = b;
if (p < 0.14) {
headX = neckX = cargoX = a;
phase = "Dwell · ATP loaded";
} else if (p < 0.58) {
const u = ease((p - 0.14) / 0.44);
headX = lerp(a, b, u);
neckX = lerp(a, b, 0.72 * u);
cargoX = lerp(a, b, 0.5 * u);
phase = "Power stroke → + end";
} else if (p < 0.86) {
const u = ease((p - 0.58) / 0.28);
headX = b;
neckX = lerp(a, b, 0.72 + 0.28 * u);
cargoX = lerp(a, b, 0.5 + 0.5 * u);
phase = "Recovery · cargo catches up";
} else {
headX = neckX = cargoX = b;
phase = "Dwell · next ATP cycle";
}
} else if (localTime < TRAVEL_DURATION + HOLD_DURATION) {
const endX = START_X + TOTAL_STEPS * STEP_DISTANCE;
headX = neckX = cargoX = endX;
stepA = endX - STEP_DISTANCE;
stepB = endX;
phase = "Cargo reached the + end";
} else {
const endX = START_X + TOTAL_STEPS * STEP_DISTANCE;
headX = neckX = cargoX = endX;
stepA = endX - STEP_DISTANCE;
stepB = endX;
opacity = 1 - (localTime - TRAVEL_DURATION - HOLD_DURATION) / FADE_DURATION;
phase = "Resetting transport cycle";
}
state.headX = headX;
state.neckX = neckX;
state.cargoX = cargoX;
state.stepA = stepA;
state.stepB = stepB;
state.phase = phase;
state.opacity = clamp(opacity, 0, 1);
state.progress = clamp(localTime / TRAVEL_DURATION, 0, 1);
}
const upVector = new THREE.Vector3(0, 1, 0);
const tempA = new THREE.Vector3();
const tempB = new THREE.Vector3();
const tempDirection = new THREE.Vector3();
function setCylinderBetween(mesh, a, b) {
tempDirection.subVectors(b, a);
const length = tempDirection.length();
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.scale.set(1, length, 1);
mesh.quaternion.setFromUnitVectors(upVector, tempDirection.normalize());
}
function updateObjects() {
const { headX, neckX, cargoX, stepA, stepB, opacity } = state;
motorHead.position.set(headX, 0.52, 0);
motorHead.rotation.y += 0.008;
motorNeck.position.set(neckX, 1.08, 0);
motorNeck.rotation.z = clamp((headX - neckX) * -0.32, -0.23, 0.23);
collar.position.set(neckX, 0.84, 0);
collar.rotation.y += 0.012;
tempA.set(headX, 0.78, 0);
tempB.set(neckX, 0.83, 0);
setCylinderBetween(motorConnector, tempA, tempB);
vesicle.position.set(
cargoX,
2.14 + Math.sin(simulationTime * 2.1) * 0.035,
0.04
);
vesicle.rotation.x += 0.003;
vesicle.rotation.y += 0.007;
tempA.set(neckX, 1.38, 0);
tempB.set(cargoX, 1.53, 0.04);
setCylinderBetween(cargoTether, tempA, tempB);
contactRing.position.x = headX;
const pulse = 1 + Math.sin(simulationTime * 5.5) * 0.045;
contactRing.scale.set(pulse, pulse, pulse);
headMaterial.opacity = opacity;
neckMaterial.opacity = opacity;
collarMaterial.opacity = opacity;
tetherMaterial.opacity = opacity;
vesicleMaterial.opacity = opacity;
contactRingMaterial.opacity = opacity;
motorBracket.material.opacity = 0.9 * opacity;
vesicleBracket.material.opacity = 0.9 * opacity;
// Static filament diameter bracket.
setBracket(trackBracket, [
new THREE.Vector3(-7.35, -0.27, 0.52),
new THREE.Vector3(-7.35, 0.27, 0.52),
new THREE.Vector3(-7.48, -0.27, 0.52),
new THREE.Vector3(-7.22, -0.27, 0.52),
new THREE.Vector3(-7.48, 0.27, 0.52),
new THREE.Vector3(-7.22, 0.27, 0.52)
]);
// Motor head width.
setBracket(motorBracket, [
new THREE.Vector3(headX - 0.59, 0.18, 0.58),
new THREE.Vector3(headX + 0.59, 0.18, 0.58),
new THREE.Vector3(headX - 0.59, 0.08, 0.58),
new THREE.Vector3(headX - 0.59, 0.28, 0.58),
new THREE.Vector3(headX + 0.59, 0.08, 0.58),
new THREE.Vector3(headX + 0.59, 0.28, 0.58)
]);
// Vesicle diameter.
const vesicleY = vesicle.position.y;
setBracket(vesicleBracket, [
new THREE.Vector3(cargoX + 0.86, vesicleY - 0.65, 0.08),
new THREE.Vector3(cargoX + 0.86, vesicleY + 0.65, 0.08),
new THREE.Vector3(cargoX + 0.76, vesicleY - 0.65, 0.08),
new THREE.Vector3(cargoX + 0.96, vesicleY - 0.65, 0.08),
new THREE.Vector3(cargoX + 0.76, vesicleY + 0.65, 0.08),
new THREE.Vector3(cargoX + 0.96, vesicleY + 0.65, 0.08)
]);
// Schematic 8 nm step bracket.
setBracket(stepBracket, [
new THREE.Vector3(stepA, -0.34, 0.52),
new THREE.Vector3(stepB, -0.34, 0.52),
new THREE.Vector3(stepA, -0.44, 0.52),
new THREE.Vector3(stepA, -0.24, 0.52),
new THREE.Vector3(stepB, -0.44, 0.52),
new THREE.Vector3(stepB, -0.24, 0.52)
]);
}
// ---------------------------------------------------------------------
// HTML labels projected from 3D anchors
// ---------------------------------------------------------------------
function positionLabel(element, worldPosition, offsetX = 0, offsetY = 0, opacity = 1) {
const projected = worldPosition.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
if (!visible) {
element.style.opacity = "0";
return;
}
const x = (projected.x * 0.5 + 0.5) * window.innerWidth + offsetX;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight + offsetY;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.opacity = String(opacity);
}
function updateLabels() {
const opacity = state.opacity;
positionLabel(
document.querySelector("#headLabel"),
new THREE.Vector3(state.headX - 0.1, 0.58, 0.3),
-58, -39, opacity
);
positionLabel(
document.querySelector("#neckLabel"),
new THREE.Vector3(state.neckX, 1.08, 0.25),
69, -4, opacity
);
positionLabel(
document.querySelector("#vesicleLabel"),
new THREE.Vector3(state.cargoX, 2.22, 0.12),
72, -17, opacity
);
positionLabel(
document.querySelector("#trackLabel"),
new THREE.Vector3(-7.35, 0, 0.52),
-56, 0
);
positionLabel(
document.querySelector("#stepLabel"),
new THREE.Vector3((state.stepA + state.stepB) * 0.5, -0.39, 0.52),
0, 32
);
positionLabel(
document.querySelector("#minusLabel"),
new THREE.Vector3(-9.45, 0.36, 0),
0, 0
);
positionLabel(
document.querySelector("#plusLabel"),
new THREE.Vector3(9.48, 0.36, 0),
0, 0
);
positionLabel(
document.querySelector("#directionLabel"),
new THREE.Vector3(-6.2, 0.56, -0.52),
0, 38
);
}
// ---------------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom
// ---------------------------------------------------------------------
let dragging = false;
let dragMode = "orbit";
let lastX = 0;
let lastY = 0;
canvas.addEventListener("pointerdown", event => {
dragging = true;
dragMode = event.button === 2 || event.shiftKey ? "pan" : "orbit";
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (dragMode === "orbit") {
controls.theta -= dx * 0.006;
controls.phi = clamp(controls.phi - dy * 0.006, 0.28, 1.47);
} else {
camera.updateMatrixWorld();
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const panScale = controls.radius * 0.00145;
controls.target.addScaledVector(right, -dx * panScale);
controls.target.addScaledVector(up, dy * panScale);
controls.target.x = clamp(controls.target.x, -5, 5);
controls.target.y = clamp(controls.target.y, 0.1, 3.2);
}
applyCamera();
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
controls.radius = clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
6.5,
29
);
applyCamera();
},
{ passive: false }
);
function resetView() {
controls.target.set(0, 0.72, 0);
controls.theta = 0.43;
controls.phi = 1.15;
controls.radius = window.innerWidth < 760 ? 19 : 14.6;
applyCamera();
}
canvas.addEventListener("dblclick", resetView);
// ---------------------------------------------------------------------
// Interface
// ---------------------------------------------------------------------
const playButton = document.querySelector("#playButton");
const resetButton = document.querySelector("#resetButton");
const viewButton = document.querySelector("#viewButton");
const labelsButton = document.querySelector("#labelsButton");
const speedInput = document.querySelector("#speed");
const speedValue = document.querySelector("#speedValue");
const statusText = document.querySelector("#statusText");
const progressFill = document.querySelector("#progressFill");
playButton.addEventListener("click", () => {
playing = !playing;
playButton.textContent = playing ? "Pause" : "Play";
});
resetButton.addEventListener("click", () => {
simulationTime = 0;
});
viewButton.addEventListener("click", resetView);
labelsButton.addEventListener("click", () => {
labelsVisible = !labelsVisible;
labelsLayer.classList.toggle("labels-off", !labelsVisible);
labelsButton.textContent = labelsVisible ? "Labels" : "Hidden";
});
speedInput.addEventListener("input", () => {
speed = Number(speedInput.value);
speedValue.textContent = `${speed.toFixed(1)}×`;
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// ---------------------------------------------------------------------
// Render loop
// ---------------------------------------------------------------------
let previousTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (playing) {
simulationTime += delta * speed;
}
updateSimulation(simulationTime);
updateObjects();
updateLabels();
statusText.textContent = state.phase;
progressFill.style.width = `${state.progress * 100}%`;
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```