Prompt specification
Build or customize the Three.js 3D scene "Zoom transitions through a tissue sample" 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: Zoom transitions through a tissue sample
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/zoom-transitions-through-a-tissue-sample-x0810
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing biological size scales. Animate discrete zoom stages from a small tissue patch to one cell and an organelle inset; update scale labels at every transition and avoid seamless false proportions. Stylized solid forms.
Working Three.js Starter (zoom-transitions-through-a-tissue-sample-x0810):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Biological Scale Study — Tissue to Organelle</title>
<style>
:root {
--paper: #f3f0e8;
--ink: #17342e;
--muted: #6d7974;
--line: rgba(23, 52, 46, 0.18);
--lime: #d9ef79;
--coral: #e97958;
--bar-width: 150px;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
}
body {
overflow: hidden;
color: var(--ink);
background: var(--paper);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button {
font: inherit;
}
.app {
display: grid;
grid-template-rows: auto minmax(0, 1fr);
width: 100%;
height: 100dvh;
}
.topbar {
position: relative;
z-index: 20;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 20px 30px 17px;
background: var(--paper);
border-bottom: 1px solid var(--line);
}
.brand {
display: flex;
align-items: center;
gap: 14px;
min-width: 0;
}
.brand-mark {
position: relative;
flex: 0 0 auto;
width: 35px;
height: 35px;
border: 1px solid var(--ink);
border-radius: 50%;
}
.brand-mark::before,
.brand-mark::after {
position: absolute;
content: "";
border-radius: 50%;
}
.brand-mark::before {
width: 15px;
height: 15px;
top: 5px;
left: 9px;
background: var(--coral);
}
.brand-mark::after {
width: 7px;
height: 7px;
right: 5px;
bottom: 5px;
background: var(--ink);
}
.eyebrow {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
overflow: hidden;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(22px, 2.2vw, 34px);
font-weight: 500;
letter-spacing: -0.035em;
line-height: 1;
text-overflow: ellipsis;
white-space: nowrap;
}
.readout {
flex: 0 0 auto;
min-width: 218px;
padding: 12px 16px 13px;
color: var(--paper);
background: var(--ink);
border-radius: 16px;
box-shadow: 0 10px 30px rgba(23, 52, 46, 0.13);
}
.readout-kicker {
margin-bottom: 1px;
color: rgba(243, 240, 232, 0.62);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.readout-main {
display: flex;
align-items: baseline;
gap: 7px;
line-height: 1;
}
#scaleValue {
font-family: Georgia, "Times New Roman", serif;
font-size: 39px;
letter-spacing: -0.055em;
}
#scaleUnit {
color: var(--lime);
font-size: 18px;
font-weight: 750;
}
#scaleName {
margin-top: 5px;
color: rgba(243, 240, 232, 0.82);
font-size: 11px;
}
.readout.pulse {
animation: readout-pulse 480ms ease-out;
}
@keyframes readout-pulse {
0% {
transform: translateY(0) scale(1);
}
30% {
transform: translateY(-3px) scale(1.025);
}
100% {
transform: translateY(0) scale(1);
}
}
#stage {
position: relative;
min-height: 0;
overflow: hidden;
isolation: isolate;
}
#canvas-wrap,
#canvas-wrap canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
}
#canvas-wrap canvas {
display: block;
}
.scene-heading {
position: absolute;
z-index: 8;
top: 28px;
left: 30px;
display: flex;
align-items: flex-start;
gap: 13px;
max-width: 430px;
pointer-events: none;
}
.scene-heading::before {
flex: 0 0 auto;
width: 26px;
height: 2px;
margin-top: 8px;
background: var(--coral);
content: "";
}
.scene-kicker {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.scene-heading h2 {
margin: 0 0 7px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(29px, 3.2vw, 46px);
font-weight: 500;
letter-spacing: -0.045em;
line-height: 0.98;
}
.scene-heading p {
max-width: 340px;
margin: 0;
color: #52625d;
font-size: 12px;
line-height: 1.5;
}
#annotations {
position: absolute;
z-index: 9;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.annotation {
position: absolute;
width: 1px;
height: 1px;
opacity: 0;
transition: opacity 250ms ease;
}
.annotation.visible {
opacity: 1;
}
.annotation-dot {
position: absolute;
width: 7px;
height: 7px;
left: -3px;
top: -3px;
background: var(--paper);
border: 2px solid var(--ink);
border-radius: 50%;
box-shadow: 0 0 0 3px rgba(243, 240, 232, 0.45);
}
.annotation-leader {
position: absolute;
height: 1px;
transform-origin: 0 50%;
background: rgba(23, 52, 46, 0.65);
}
.annotation-label {
position: absolute;
padding: 6px 9px;
color: var(--ink);
background: rgba(243, 240, 232, 0.88);
border: 1px solid rgba(23, 52, 46, 0.18);
border-radius: 8px;
box-shadow: 0 5px 16px rgba(23, 52, 46, 0.08);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.02em;
white-space: nowrap;
backdrop-filter: blur(8px);
}
.scale-key {
position: absolute;
z-index: 8;
bottom: 116px;
left: 30px;
display: grid;
grid-template-columns: var(--bar-width) auto;
grid-template-rows: auto auto;
column-gap: 9px;
align-items: center;
pointer-events: none;
}
.scale-bar {
grid-column: 1;
height: 7px;
border-right: 1px solid var(--ink);
border-bottom: 1px solid var(--ink);
border-left: 1px solid var(--ink);
}
#barLabel {
grid-column: 2;
grid-row: 1 / span 2;
font-size: 11px;
font-weight: 800;
}
.scale-key small {
grid-column: 1;
margin-top: 5px;
color: var(--muted);
font-size: 8px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.continuity-note {
position: absolute;
z-index: 8;
right: 30px;
bottom: 115px;
display: flex;
align-items: center;
gap: 8px;
max-width: 300px;
color: #62706b;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.05em;
line-height: 1.4;
text-align: right;
text-transform: uppercase;
pointer-events: none;
}
.continuity-note::before {
flex: 0 0 auto;
width: 8px;
height: 8px;
background: var(--coral);
border-radius: 50%;
content: "";
}
.stage-nav {
position: absolute;
z-index: 15;
left: 50%;
bottom: 22px;
display: flex;
gap: 4px;
padding: 5px;
background: rgba(243, 240, 232, 0.88);
border: 1px solid rgba(23, 52, 46, 0.16);
border-radius: 17px;
box-shadow: 0 16px 38px rgba(23, 52, 46, 0.13);
transform: translateX(-50%);
backdrop-filter: blur(12px);
}
.stage-button {
display: flex;
align-items: center;
gap: 10px;
min-width: 145px;
padding: 10px 13px;
color: var(--ink);
background: transparent;
border: 0;
border-radius: 12px;
cursor: pointer;
text-align: left;
transition:
color 180ms ease,
background 180ms ease,
transform 180ms ease;
}
.stage-button:hover {
background: rgba(23, 52, 46, 0.07);
}
.stage-button:focus-visible {
outline: 2px solid var(--coral);
outline-offset: 2px;
}
.stage-button.active {
color: var(--paper);
background: var(--ink);
}
.stage-button.active:hover {
background: var(--ink);
}
.stage-button:active {
transform: scale(0.98);
}
.button-number {
font-family: Georgia, "Times New Roman", serif;
font-size: 17px;
opacity: 0.65;
}
.button-copy {
display: flex;
flex-direction: column;
gap: 1px;
}
.button-copy b {
font-size: 11px;
font-weight: 800;
}
.button-copy small {
font-size: 9px;
opacity: 0.62;
}
#cut {
position: absolute;
z-index: 40;
inset: 0;
display: grid;
place-items: center;
overflow: hidden;
background: rgba(23, 52, 46, 0.96);
opacity: 0;
pointer-events: none;
transition: opacity 230ms ease;
}
#cut::before,
#cut::after {
position: absolute;
left: 0;
width: 100%;
height: 1px;
background: rgba(217, 239, 121, 0.42);
content: "";
}
#cut::before {
top: 50%;
transform: translateY(-105px);
}
#cut::after {
top: 50%;
transform: translateY(105px);
}
#cut.active {
opacity: 1;
}
.cut-card {
color: var(--paper);
text-align: center;
transform: translateY(7px);
transition: transform 230ms ease;
}
#cut.active .cut-card {
transform: translateY(0);
}
.cut-card span {
display: block;
margin-bottom: 9px;
color: var(--lime);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.cut-card strong {
display: block;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(29px, 4vw, 52px);
font-weight: 500;
letter-spacing: -0.04em;
}
.cut-card small {
display: block;
margin-top: 10px;
color: rgba(243, 240, 232, 0.6);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 760px) {
.topbar {
gap: 10px;
padding: 13px 15px 12px;
}
.brand {
gap: 9px;
}
.brand-mark {
width: 29px;
height: 29px;
}
.brand-mark::before {
width: 12px;
height: 12px;
top: 4px;
left: 7px;
}
.eyebrow {
font-size: 8px;
}
h1 {
font-size: 21px;
}
.readout {
min-width: 116px;
padding: 9px 11px;
border-radius: 12px;
}
#scaleValue {
font-size: 29px;
}
#scaleUnit {
font-size: 14px;
}
#scaleName {
display: none;
}
.readout-kicker {
font-size: 7px;
}
.scene-heading {
top: 17px;
left: 17px;
max-width: 76%;
}
.scene-heading::before {
width: 18px;
}
.scene-heading h2 {
font-size: 30px;
}
.scene-heading p {
font-size: 10px;
}
#annotations {
display: none;
}
.scale-key {
bottom: 103px;
left: 17px;
}
.continuity-note {
display: none;
}
.stage-nav {
right: 8px;
bottom: 8px;
left: 8px;
width: auto;
transform: none;
}
.stage-button {
flex: 1;
min-width: 0;
justify-content: center;
padding: 10px 7px;
}
.button-copy small {
display: none;
}
.button-copy b {
font-size: 10px;
}
}
@media (max-height: 620px) {
.scene-heading p,
.continuity-note,
.scale-key small {
display: none;
}
.scale-key {
bottom: 98px;
}
.stage-nav {
bottom: 8px;
}
.stage-button {
padding-top: 7px;
padding-bottom: 7px;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
scroll-behavior: auto !important;
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<span class="eyebrow">Micro atlas / scale study</span>
<h1>From tissue to organelle</h1>
</div>
</div>
<div class="readout" id="readout" aria-live="polite">
<div class="readout-kicker">
<span id="viewIndex">01</span> / 03 · Current scale
</div>
<div class="readout-main">
<span id="scaleValue">2</span>
<span id="scaleUnit">mm</span>
</div>
<div id="scaleName">tissue field width</div>
</div>
</header>
<main id="stage">
<div
id="canvas-wrap"
role="img"
aria-label="Stylized three-dimensional views of biological size scales"
></div>
<section class="scene-heading" aria-live="polite">
<div>
<span class="scene-kicker" id="sceneKicker">01 / Millimetres</span>
<h2 id="sceneTitle">Tissue patch</h2>
<p id="sceneDescription">
A 2 mm epithelial field with a small capillary running through it.
</p>
</div>
</section>
<div id="annotations" aria-hidden="true"></div>
<div class="scale-key">
<div class="scale-bar"></div>
<span id="barLabel">1 mm</span>
<small>Scale applies to this view only</small>
</div>
<div class="continuity-note">
Discrete views. Objects are not proportionally linked.
</div>
<nav class="stage-nav" aria-label="Biological scale stages">
<button class="stage-button active" data-stage="0" aria-current="step">
<span class="button-number">01</span>
<span class="button-copy">
<b>Tissue</b>
<small>~2 mm</small>
</span>
</button>
<button class="stage-button" data-stage="1">
<span class="button-number">02</span>
<span class="button-copy">
<b>One cell</b>
<small>~30 µm</small>
</span>
</button>
<button class="stage-button" data-stage="2">
<span class="button-number">03</span>
<span class="button-copy">
<b>Organelle</b>
<small>~2 µm inset</small>
</span>
</button>
</nav>
<div id="cut" aria-hidden="true">
<div class="cut-card">
<span>Resetting scale</span>
<strong id="cutTitle">Entering cell view</strong>
<small>Separate view · not a continuous magnification</small>
</div>
</div>
<div id="status" class="sr-only" aria-live="polite"></div>
</main>
</div>
<noscript>This interactive scale study requires JavaScript.</noscript>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Renderer, camera and lighting
// ---------------------------------------------------------------------
const host = document.querySelector("#canvas-wrap");
const scene = new THREE.Scene();
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
host.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(34, 1, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0.05, 0);
const hemisphere = new THREE.HemisphereLight(
0xfff9e9,
0x5f766e,
2.35
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(4.5, 7.5, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -6;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xffb08e, 1.25);
rimLight.position.set(-5, 3, -4);
scene.add(rimLight);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0xdde5dd,
roughness: 1,
metalness: 0
});
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.08;
floor.receiveShadow = true;
scene.add(floor);
const stageData = [
{
title: "Tissue patch",
kicker: "01 / Millimetres",
description:
"A 2 mm epithelial field with a small capillary running through it.",
scaleValue: "2",
scaleUnit: "mm",
scaleName: "tissue field width",
barLabel: "1 mm",
barWidth: 150,
background: 0xe8eee8,
floor: 0xd9e4dc,
camera: new THREE.Vector3(0, 3.35, 7.7),
target: new THREE.Vector3(0, -0.02, 0),
cutTitle: "Entering tissue view"
},
{
title: "One cell",
kicker: "02 / Micrometres",
description:
"A 30 µm cell, with selected internal structures shown as solid forms.",
scaleValue: "30",
scaleUnit: "µm",
scaleName: "cell diameter",
barLabel: "10 µm",
barWidth: 122,
background: 0xf1eadc,
floor: 0xe3d7c6,
camera: new THREE.Vector3(0, 2.85, 6.65),
target: new THREE.Vector3(0, 0.12, 0),
cutTitle: "Entering one-cell view"
},
{
title: "Mitochondrion",
kicker: "03 / Magnified organelle inset",
description:
"A 2 µm mitochondrion, enlarged as a separate inset—not drawn to the cell's scale.",
scaleValue: "2",
scaleUnit: "µm",
scaleName: "organelle length · inset",
barLabel: "0.5 µm",
barWidth: 98,
background: 0xe9e6ed,
floor: 0xdad5e0,
camera: new THREE.Vector3(0, 2.45, 6.65),
target: new THREE.Vector3(0, 0.08, 0),
cutTitle: "Entering organelle inset"
}
];
const roots = stageData.map(() => {
const group = new THREE.Group();
scene.add(group);
return group;
});
// ---------------------------------------------------------------------
// Modeling helpers
// ---------------------------------------------------------------------
function standardMaterial(color, roughness = 0.72, metalness = 0) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness
});
}
function addMesh(group, geometry, material, position, scale, rotation) {
const mesh = new THREE.Mesh(geometry, material);
if (position) mesh.position.set(...position);
if (scale) mesh.scale.set(...scale);
if (rotation) mesh.rotation.set(...rotation);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
return mesh;
}
function makeTube(points, radius, material, segments = 36) {
const curve = new THREE.CatmullRomCurve3(
points.map((point) => new THREE.Vector3(...point))
);
const geometry = new THREE.TubeGeometry(
curve,
segments,
radius,
8,
false
);
return new THREE.Mesh(geometry, material);
}
function roundedRectangleShape(width, height, radius) {
const shape = new THREE.Shape();
const x = -width / 2;
const y = -height / 2;
shape.moveTo(x + radius, y);
shape.lineTo(x + width - radius, y);
shape.quadraticCurveTo(x + width, y, x + width, y + radius);
shape.lineTo(x + width, y + height - radius);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
shape.lineTo(x + radius, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - radius);
shape.lineTo(x, y + radius);
shape.quadraticCurveTo(x, y, x + radius, y);
return shape;
}
// ---------------------------------------------------------------------
// Stage 1: tissue patch
// ---------------------------------------------------------------------
const tissueRoot = roots[0];
const tissueShape = roundedRectangleShape(5.15, 3.35, 0.34);
const tissueGeometry = new THREE.ExtrudeGeometry(tissueShape, {
depth: 0.42,
bevelEnabled: true,
bevelSegments: 3,
steps: 1,
bevelSize: 0.12,
bevelThickness: 0.1,
curveSegments: 14
});
tissueGeometry.rotateX(-Math.PI / 2);
addMesh(
tissueRoot,
tissueGeometry,
standardMaterial(0xe9b89c, 0.88),
[0, -0.42, 0]
);
const cellColors = [
0xe98565,
0xf29b78,
0xd96f58,
0xf3ae88,
0xdf7c61
];
const cellPositions = [
[-1.78, -0.92],
[-0.58, -0.93],
[0.63, -0.95],
[1.82, -0.88],
[-1.72, -0.02],
[-0.48, 0.02],
[0.71, 0.01],
[1.76, 0.08],
[-1.73, 0.9],
[-0.47, 0.93],
[0.76, 0.91],
[1.76, 0.92]
];
cellPositions.forEach(([x, z], index) => {
const cell = addMesh(
tissueRoot,
new THREE.SphereGeometry(0.72, 24, 16),
standardMaterial(cellColors[index % cellColors.length], 0.78),
[
x + (index % 3 === 0 ? 0.07 : -0.04),
0.16 + (index % 2) * 0.025,
z + (index % 4 === 0 ? 0.05 : -0.03)
],
[1, 0.25, 0.84],
[0, (index % 3 - 1) * 0.05, 0]
);
addMesh(
tissueRoot,
new THREE.SphereGeometry(0.28, 18, 12),
standardMaterial(index % 2 ? 0x9e4f4a : 0xb75d51, 0.72),
[cell.position.x, 0.325, cell.position.z],
[1, 0.26, 0.82]
);
});
const capillaryMaterial = standardMaterial(0xb9484d, 0.65);
const capillary = addMesh(
tissueRoot,
new THREE.CylinderGeometry(0.17, 0.17, 4.3, 24),
capillaryMaterial,
[0, 0.22, -1.18],
[1, 1, 1],
[0, 0, Math.PI / 2]
);
capillary.castShadow = false;
[-1.55, -0.78, 0.05, 0.88, 1.65].forEach((x, index) => {
addMesh(
tissueRoot,
new THREE.SphereGeometry(0.26, 18, 12),
standardMaterial(index % 2 ? 0xd95c5b : 0xc74d50, 0.6),
[x, 0.39, -1.18],
[1.15, 0.33, 0.67],
[0, 0.18, 0.06]
);
});
// ---------------------------------------------------------------------
// Stage 2: one cell
// ---------------------------------------------------------------------
const cellRoot = roots[1];
const cellOuterMaterial = standardMaterial(0x2c685b, 0.76);
const cellInnerMaterial = standardMaterial(0x79b89d, 0.78);
addMesh(
cellRoot,
new THREE.SphereGeometry(1, 64, 40),
cellOuterMaterial,
[0, 0.15, 0],
[2.27, 1.47, 1.52]
);
addMesh(
cellRoot,
new THREE.SphereGeometry(1, 64, 40),
cellInnerMaterial,
[0, 0.16, 0],
[2.18, 1.38, 1.43]
);
const nucleusMaterial = standardMaterial(0x654b76, 0.64);
addMesh(
cellRoot,
new THREE.SphereGeometry(1, 48, 30),
nucleusMaterial,
[-0.3, 1.02, 0.16],
[0.9, 0.56, 0.78]
);
addMesh(
cellRoot,
new THREE.SphereGeometry(0.25, 20, 14),
standardMaterial(0x493556, 0.58),
[-0.62, 1.43, 0.27],
[1, 0.55, 0.9]
);
addMesh(
cellRoot,
new THREE.SphereGeometry(0.18, 18, 12),
standardMaterial(0x82658c, 0.6),
[0.08, 1.44, 0.36],
[1.1, 0.6, 0.9]
);
const erMaterial = standardMaterial(0xa993b7, 0.7);
const erPaths = [
[
[-1.35, 0.87, 0.02],
[-1.04, 1.02, 0.35],
[-0.6, 1.08, 0.61],
[-0.12, 0.96, 0.7]
],
[
[-1.3, 0.98, -0.1],
[-0.95, 1.15, 0.16],
[-0.52, 1.18, 0.43],
[-0.05, 1.02, 0.55]
],
[
[-0.92, 0.91, 0.72],
[-0.47, 1.0, 0.84],
[0.05, 0.95, 0.74]
]
];
erPaths.forEach((path) => {
const tube = makeTube(path, 0.055, erMaterial, 28);
tube.castShadow = true;
cellRoot.add(tube);
});
const golgiMaterial = standardMaterial(0xe6b54f, 0.68);
for (let i = 0; i < 4; i++) {
const y = 0.54 + i * 0.12;
const tube = makeTube(
[
[-1.45, y, 0.45],
[-1.08, y + 0.08, 0.68],
[-0.67, y + 0.09, 0.75],
[-0.27, y, 0.55]
],
0.065,
golgiMaterial,
28
);
tube.castShadow = true;
cellRoot.add(tube);
}
const smallMito = addMesh(
cellRoot,
new THREE.SphereGeometry(1, 36, 22),
standardMaterial(0xe87955, 0.64),
[1.0, 1.02, 0.43],
[0.59, 0.24, 0.32],
[0, -0.25, -0.12]
);
const mitoCapMaterial = standardMaterial(0xc95343, 0.62);
addMesh(
cellRoot,
new THREE.SphereGeometry(1, 20, 14),
mitoCapMaterial,
[1.43, 1.01, 0.48],
[0.21, 0.23, 0.29]
);
addMesh(
cellRoot,
new THREE.SphereGeometry(1, 20, 14),
mitoCapMaterial,
[0.58, 1.04, 0.38],
[0.2, 0.22, 0.28]
);
[
[-1.58, 0.6, 0.7, 0.18],
[1.52, 0.66, -0.42, 0.15],
[0.26, 0.85, 0.92, 0.13]
].forEach(([x, y, z, size]) => {
addMesh(
cellRoot,
new THREE.SphereGeometry(size, 20, 14),
standardMaterial(0xb8d990, 0.6),
[x, y, z]
);
});
// ---------------------------------------------------------------------
// Stage 3: enlarged mitochondrion inset
// ---------------------------------------------------------------------
const organelleRoot = roots[2];
const organelleMaterial = standardMaterial(0xe97a56, 0.63);
addMesh(
organelleRoot,
new THREE.SphereGeometry(1, 64, 40),
organelleMaterial,
[0, 0.08, 0],
[2.16, 0.77, 0.87]
);
const endMaterial = standardMaterial(0xc95a48, 0.62);
addMesh(
organelleRoot,
new THREE.SphereGeometry(1, 28, 18),
endMaterial,
[-1.79, 0.06, 0],
[0.42, 0.7, 0.78]
);
addMesh(
organelleRoot,
new THREE.SphereGeometry(1, 28, 18),
endMaterial,
[1.79, 0.06, 0],
[0.42, 0.7, 0.78]
);
const cristaMaterial = standardMaterial(0x8d3f43, 0.66);
const cristaX = [-1.32, -0.8, -0.27, 0.27, 0.8, 1.32];
cristaX.forEach((baseX, cristaIndex) => {
const points = [];
for (let i = 0; i < 9; i++) {
const z = -0.63 + (i / 8) * 1.26;
const x =
baseX +
Math.sin((i / 8) * Math.PI * 2 + cristaIndex * 0.42) * 0.08;
const ellipse =
1 -
(x / 2.16) ** 2 -
(z / 0.87) ** 2;
const y =
0.08 +
0.77 * Math.sqrt(Math.max(0.06, ellipse)) +
0.055;
points.push([x, y, z]);
}
const crista = makeTube(points, 0.065, cristaMaterial, 44);
crista.castShadow = true;
organelleRoot.add(crista);
});
// ---------------------------------------------------------------------
// DOM annotations
// ---------------------------------------------------------------------
const annotationDefinitions = [
[
{
text: "Epithelial cells",
point: new THREE.Vector3(0.66, 0.37, 0.02),
offset: [84, -42]
},
{
text: "Capillary",
point: new THREE.Vector3(-0.75, 0.43, -1.18),
offset: [82, -56]
}
],
[
{
text: "Nucleus",
point: new THREE.Vector3(-0.32, 1.55, 0.18),
offset: [-105, -52]
},
{
text: "Mitochondrion",
point: new THREE.Vector3(1.0, 1.27, 0.44),
offset: [88, -30]
}
],
[
{
text: "Cristae",
point: new THREE.Vector3(0.18, 0.84, 0.18),
offset: [86, -38]
},
{
text: "Outer membrane",
point: new THREE.Vector3(-1.78, 0.56, 0.24),
offset: [-112, 36]
}
]
];
const annotationHost = document.querySelector("#annotations");
let annotationElements = [];
function buildAnnotations(stageIndex) {
annotationHost.innerHTML = "";
annotationElements = annotationDefinitions[stageIndex].map((item) => {
const element = document.createElement("div");
element.className = "annotation";
const dot = document.createElement("i");
dot.className = "annotation-dot";
const leader = document.createElement("i");
leader.className = "annotation-leader";
const label = document.createElement("span");
label.className = "annotation-label";
label.textContent = item.text;
element.append(leader, dot, label);
annotationHost.appendChild(element);
return {
element,
leader,
label,
definition: item
};
});
requestAnimationFrame(() => {
annotationElements.forEach((item) => item.element.classList.add("visible"));
});
}
function updateAnnotations() {
if (!annotationElements.length) return;
const width = host.clientWidth;
const height = host.clientHeight;
const root = roots[currentStage];
annotationElements.forEach(({ element, leader, label, definition }) => {
const projected = root.localToWorld(definition.point.clone());
projected.project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
const [dx, dy] = definition.offset;
const length = Math.hypot(dx, dy);
const angle = Math.atan2(dy, dx) * (180 / Math.PI);
element.style.left = `${x}px`;
element.style.top = `${y}px`;
leader.style.width = `${length}px`;
leader.style.transform = `rotate(${angle}deg)`;
label.style.left = `${dx}px`;
label.style.top = `${dy}px`;
label.style.transform =
dx < 0
? "translate(-100%, -50%)"
: "translate(0, -50%)";
const visible =
projected.z > -1 &&
projected.z < 1 &&
x > -20 &&
x < width + 20 &&
y > -20 &&
y < height + 20;
element.style.visibility = visible ? "visible" : "hidden";
});
}
// ---------------------------------------------------------------------
// Interface and discrete stage transitions
// ---------------------------------------------------------------------
const readout = document.querySelector("#readout");
const viewIndex = document.querySelector("#viewIndex");
const scaleValue = document.querySelector("#scaleValue");
const scaleUnit = document.querySelector("#scaleUnit");
const scaleName = document.querySelector("#scaleName");
const sceneKicker = document.querySelector("#sceneKicker");
const sceneTitle = document.querySelector("#sceneTitle");
const sceneDescription = document.querySelector("#sceneDescription");
const barLabel = document.querySelector("#barLabel");
const cut = document.querySelector("#cut");
const cutTitle = document.querySelector("#cutTitle");
const status = document.querySelector("#status");
const buttons = [...document.querySelectorAll(".stage-button")];
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
let currentStage = 0;
let transitionBusy = false;
const tweens = [];
function wait(duration) {
return new Promise((resolve) => {
window.setTimeout(resolve, duration);
});
}
function tween(duration, update) {
return new Promise((resolve) => {
tweens.push({
start: performance.now(),
duration,
update,
resolve
});
});
}
function updateInterface(index) {
const data = stageData[index];
viewIndex.textContent = String(index + 1).padStart(2, "0");
scaleValue.textContent = data.scaleValue;
scaleUnit.textContent = data.scaleUnit;
scaleName.textContent = data.scaleName;
sceneKicker.textContent = data.kicker;
sceneTitle.textContent = data.title;
sceneDescription.textContent = data.description;
barLabel.textContent = data.barLabel;
document.documentElement.style.setProperty(
"--bar-width",
`${data.barWidth}px`
);
buttons.forEach((button, buttonIndex) => {
const active = buttonIndex === index;
button.classList.toggle("active", active);
if (active) {
button.setAttribute("aria-current", "step");
} else {
button.removeAttribute("aria-current");
}
});
readout.classList.remove("pulse");
void readout.offsetWidth;
readout.classList.add("pulse");
buildAnnotations(index);
status.textContent =
`View ${index + 1} of 3. ${data.title}. ` +
`Scale ${data.scaleValue} ${data.scaleUnit}. ${data.description}`;
}
function cameraPositionFor(index) {
const position = stageData[index].camera.clone();
// Keep the wide tissue composition visible on narrow screens.
if (camera.aspect < 0.85) {
position.z *= 1.3;
position.y *= 1.04;
}
return position;
}
async function transitionTo(nextStage) {
if (
transitionBusy ||
nextStage === currentStage ||
nextStage < 0 ||
nextStage >= stageData.length
) {
return;
}
transitionBusy = true;
const previousStage = currentStage;
const previousBackground = scene.background.clone();
const previousFloor = floorMaterial.color.clone();
const nextBackground = new THREE.Color(stageData[nextStage].background);
const nextFloor = new THREE.Color(stageData[nextStage].floor);
cutTitle.textContent = stageData[nextStage].cutTitle;
cut.classList.add("active");
await wait(reducedMotion ? 0 : 230);
roots[previousStage].visible = false;
roots[nextStage].visible = true;
currentStage = nextStage;
cameraTarget.copy(stageData[nextStage].target);
camera.lookAt(cameraTarget);
updateInterface(nextStage);
const cameraStart = cameraPositionFor(nextStage).add(
new THREE.Vector3(0, 0.48, 1.75)
);
const cameraEnd = cameraPositionFor(nextStage);
const root = roots[nextStage];
camera.position.copy(cameraStart);
root.scale.setScalar(0.84);
// Reveal the next independent view while its short zoom settles.
cut.classList.remove("active");
const duration = reducedMotion ? 1 : 760;
await tween(duration, (progress) => {
camera.position.lerpVectors(cameraStart, cameraEnd, progress);
camera.lookAt(cameraTarget);
root.scale.setScalar(0.84 + 0.16 * progress);
scene.background.lerpColors(
previousBackground,
nextBackground,
progress
);
floorMaterial.color.lerpColors(
previousFloor,
nextFloor,
progress
);
});
root.scale.setScalar(1);
camera.position.copy(cameraEnd);
camera.lookAt(cameraTarget);
scene.background.copy(nextBackground);
floorMaterial.color.copy(nextFloor);
transitionBusy = false;
}
buttons.forEach((button) => {
button.addEventListener("click", () => {
transitionTo(Number(button.dataset.stage));
});
});
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowRight" || event.key === "ArrowDown") {
event.preventDefault();
transitionTo(currentStage + 1);
}
if (event.key === "ArrowLeft" || event.key === "ArrowUp") {
event.preventDefault();
transitionTo(currentStage - 1);
}
if (event.key === "Home") {
event.preventDefault();
transitionTo(0);
}
if (event.key === "End") {
event.preventDefault();
transitionTo(stageData.length - 1);
}
});
let wheelLocked = false;
window.addEventListener(
"wheel",
(event) => {
if (Math.abs(event.deltaY) < 8) return;
event.preventDefault();
if (wheelLocked || transitionBusy) return;
wheelLocked = true;
window.setTimeout(() => {
wheelLocked = false;
}, 850);
transitionTo(
currentStage + (event.deltaY > 0 ? 1 : -1)
);
},
{ passive: false }
);
// ---------------------------------------------------------------------
// Resize and render loop
// ---------------------------------------------------------------------
function resize() {
const width = host.clientWidth;
const height = host.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / Math.max(height, 1);
camera.updateProjectionMatrix();
if (!transitionBusy) {
camera.position.copy(cameraPositionFor(currentStage));
camera.lookAt(cameraTarget);
}
}
window.addEventListener("resize", resize);
function render(now) {
requestAnimationFrame(render);
for (let i = tweens.length - 1; i >= 0; i--) {
const item = tweens[i];
const rawProgress = Math.min(
1,
(now - item.start) / Math.max(item.duration, 1)
);
const easedProgress =
1 - Math.pow(1 - rawProgress, 3);
item.update(easedProgress);
if (rawProgress >= 1) {
tweens.splice(i, 1);
item.resolve();
}
}
updateAnnotations();
renderer.render(scene, camera);
}
roots[0].visible = true;
roots[1].visible = false;
roots[2].visible = false;
scene.background = new THREE.Color(stageData[0].background);
floorMaterial.color.set(stageData[0].floor);
cameraTarget.copy(stageData[0].target);
resize();
updateInterface(0);
requestAnimationFrame(render);
</script>
</body>
</html>
```