Prompt specification
Build or customize the Three.js 3D scene "Tissue differentiation teaching gallery" 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: Tissue differentiation teaching gallery
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/tissue-differentiation-teaching-gallery-x0907
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring gene expression. Compose muscle-like, nerve-like, and secretory cell exhibits connected to a shared genetic-template panel; explain functional specialization through selective expression rather than missing genes. Voxel style.
Working Three.js Starter (tissue-differentiation-teaching-gallery-x0907):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="color-scheme" content="dark">
<title>Same Genome · Different Jobs</title>
<style>
:root {
--accent: #49e6c1;
--ink: #eafcff;
--muted: #91aab1;
--panel: rgba(6, 19, 24, 0.82);
--line: rgba(145, 210, 218, 0.2);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 38%, #12313a 0%, #07161b 46%, #03090c 100%);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body::before {
content: "";
position: fixed;
inset: 0;
pointer-events: none;
opacity: 0.25;
background-image:
linear-gradient(rgba(125, 220, 230, 0.025) 1px, transparent 1px),
linear-gradient(90deg, rgba(125, 220, 230, 0.025) 1px, transparent 1px);
background-size: 42px 42px;
mask-image: linear-gradient(to bottom, black, transparent 88%);
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
}
.brand {
position: fixed;
z-index: 5;
top: 24px;
left: 28px;
max-width: 560px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
color: var(--accent);
font: 700 11px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 9px;
height: 9px;
background: var(--accent);
box-shadow: 0 0 18px var(--accent);
}
h1 {
margin: 10px 0 7px;
font-size: clamp(26px, 3.3vw, 49px);
line-height: 0.98;
letter-spacing: -0.055em;
font-weight: 800;
}
.brand p {
margin: 0;
max-width: 510px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.info {
position: fixed;
z-index: 5;
top: 28px;
right: 28px;
width: min(340px, calc(100vw - 56px));
padding: 18px;
border: 1px solid var(--line);
border-top: 2px solid var(--accent);
border-radius: 14px;
background: linear-gradient(145deg, rgba(10, 31, 37, 0.92), var(--panel));
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(16px);
pointer-events: none;
}
.info-kicker {
color: var(--accent);
font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.info h2 {
margin: 8px 0 8px;
font-size: 22px;
line-height: 1.08;
letter-spacing: -0.035em;
}
.info p {
margin: 0;
color: #b5c9ce;
font-size: 12.5px;
line-height: 1.55;
}
.info p strong {
color: #f2feff;
font-weight: 700;
}
.stats {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin: 14px 0;
}
.stat {
min-width: 0;
padding: 9px 8px;
border: 1px solid rgba(150, 220, 225, 0.12);
border-radius: 8px;
background: rgba(0, 0, 0, 0.13);
}
.stat b {
display: block;
color: var(--accent);
font-size: 17px;
line-height: 1;
}
.stat span {
display: block;
margin-top: 5px;
color: #79949b;
font: 600 8px/1.25 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 13px;
padding-top: 12px;
border-top: 1px solid rgba(150, 220, 225, 0.11);
color: #91aab1;
font: 600 9px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.055em;
text-transform: uppercase;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--accent);
box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 55%, transparent);
}
.swatch.dim {
background: #173038;
border: 1px solid #35505a;
box-shadow: none;
}
.footnote {
margin-top: 10px !important;
color: #66828a !important;
font-size: 10px !important;
}
.controls {
position: fixed;
z-index: 8;
left: 50%;
bottom: 22px;
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 7px;
width: min(760px, calc(100vw - 32px));
padding: 8px;
transform: translateX(-50%);
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(5, 17, 22, 0.84);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.36);
backdrop-filter: blur(15px);
}
button {
appearance: none;
min-height: 34px;
padding: 0 12px;
border: 1px solid rgba(140, 205, 215, 0.14);
border-radius: 8px;
background: rgba(255, 255, 255, 0.035);
color: #9db5bb;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.07em;
text-transform: uppercase;
cursor: pointer;
transition: border-color 160ms, color 160ms, background 160ms, transform 160ms;
}
button:hover {
border-color: color-mix(in srgb, var(--accent) 50%, transparent);
color: #f4ffff;
background: rgba(255, 255, 255, 0.07);
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
button.active {
border-color: var(--accent);
color: #061216;
background: var(--accent);
box-shadow: 0 0 20px color-mix(in srgb, var(--accent) 22%, transparent);
}
.separator {
width: 1px;
margin: 3px 3px;
background: var(--line);
}
.tooltip {
position: fixed;
z-index: 20;
display: none;
max-width: 245px;
padding: 11px 12px;
border: 1px solid rgba(140, 220, 230, 0.25);
border-radius: 9px;
background: rgba(4, 15, 19, 0.96);
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.4);
color: #b9cdd2;
font-size: 11px;
line-height: 1.45;
pointer-events: none;
}
.tooltip b {
display: block;
margin-bottom: 4px;
color: #fff;
font: 800 14px/1.1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.loading {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
background: #061116;
color: #8eb0b7;
font: 700 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 350ms;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
.loading::before {
content: "";
width: 28px;
height: 28px;
margin-right: 14px;
border: 2px solid #23434a;
border-top-color: #49e6c1;
border-radius: 50%;
animation: spin 900ms linear infinite;
}
.loading span {
display: flex;
align-items: center;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 820px) {
.brand {
top: 17px;
left: 18px;
right: 18px;
}
.brand p { max-width: 380px; }
.info {
top: auto;
right: 14px;
bottom: 86px;
width: min(330px, calc(100vw - 28px));
max-height: 34vh;
overflow: auto;
padding: 14px;
}
.info h2 { font-size: 18px; }
.stats { margin: 10px 0; }
.controls { bottom: 12px; padding: 6px; }
button { min-height: 32px; padding: 0 9px; font-size: 9px; }
.separator { display: none; }
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive voxel-style gene expression exhibit. Drag to orbit, scroll to zoom, shift-drag to pan, and select a cell to inspect it."
></canvas>
<header class="brand">
<div class="eyebrow">Cell identity / expression atlas</div>
<h1>Same genome.<br>Different jobs.</h1>
<p>
Muscle, nerve, and secretory cells retain the same genetic template.
Their specialized functions emerge from which genes are highly expressed.
</p>
</header>
<aside class="info" id="info" aria-live="polite"></aside>
<nav class="controls" aria-label="Exhibit controls">
<button data-focus="all" class="active" aria-pressed="true">All exhibits</button>
<button data-focus="muscle" aria-pressed="false">Muscle-like</button>
<button data-focus="nerve" aria-pressed="false">Nerve-like</button>
<button data-focus="secretory" aria-pressed="false">Secretory</button>
<div class="separator"></div>
<button id="pause">Pause expression</button>
<button id="reset">Reset view</button>
</nav>
<div class="tooltip" id="tooltip"></div>
<div class="loading" id="loading">
<span>Assembling genetic template</span>
</div>
<noscript>This exhibit requires JavaScript and WebGL.</noscript>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Basic renderer, scene, and camera
// -------------------------------------------------------------------------
const canvas = document.getElementById("scene");
const loading = document.getElementById("loading");
const tooltip = document.getElementById("tooltip");
const info = document.getElementById("info");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x061014, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x061014, 0.018);
const camera = new THREE.OrthographicCamera(-10, 10, 7, -7, 0.1, 100);
camera.position.set(7, 9, 20);
const orbit = {
yaw: 0.27,
pitch: 0.48,
zoom: 1
};
const desiredOrbit = {
yaw: 0.27,
pitch: 0.48,
zoom: 1
};
const cameraTarget = new THREE.Vector3(0, 0.35, -0.9);
const desiredTarget = cameraTarget.clone();
const hemi = new THREE.HemisphereLight(0xbdefff, 0x10252b, 2.1);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xdffaff, 3.2);
keyLight.position.set(5, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -14;
keyLight.shadow.camera.right = 14;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x43d8e7, 35, 24, 2);
rimLight.position.set(-7, 6, -4);
scene.add(rimLight);
const floorGrid = new THREE.GridHelper(40, 40, 0x24545c, 0x102e35);
floorGrid.position.y = -2.68;
floorGrid.material.transparent = true;
floorGrid.material.opacity = 0.34;
scene.add(floorGrid);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
new THREE.MeshStandardMaterial({
color: 0x071317,
roughness: 0.95,
metalness: 0.05,
transparent: true,
opacity: 0.78
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -2.7;
floor.receiveShadow = true;
scene.add(floor);
// -------------------------------------------------------------------------
// Palette and illustrative gene panel
// -------------------------------------------------------------------------
const COLORS = {
core: 0x49e6c1,
muscle: 0xff647b,
nerve: 0x9181ff,
secretory: 0xffc857
};
const CSS_COLORS = {
core: "#49e6c1",
muscle: "#ff647b",
nerve: "#9181ff",
secretory: "#ffc857"
};
const categoryNames = {
core: "CORE",
muscle: "MUSCLE",
nerve: "NERVE",
secretory: "SECRET"
};
const categoryFullNames = {
core: "Housekeeping",
muscle: "Muscle-like",
nerve: "Nerve-like",
secretory: "Secretory"
};
const genes = [
["ACTB", "core"], ["GAPDH", "core"], ["TUBA1B", "core"],
["RPLP0", "core"], ["B2M", "core"], ["PPIA", "core"],
["HPRT1", "core"],
["ACTA1", "muscle"], ["MYH2", "muscle"], ["TNNT2", "muscle"],
["TPM1", "muscle"], ["DES", "muscle"], ["DMD", "muscle"],
["MYBPC3", "muscle"],
["SNAP25", "nerve"], ["SYT1", "nerve"], ["RBFOX3", "nerve"],
["STMN2", "nerve"], ["TUBB3", "nerve"], ["MAP2", "nerve"],
["NEFL", "nerve"],
["INS", "secretory"], ["CHGA", "secretory"], ["CHGB", "secretory"],
["SYP", "secretory"], ["SCG2", "secretory"], ["IAPP", "secretory"],
["CALCA", "secretory"]
].map(([name, category]) => ({ name, category }));
function standard(color, emissive = 0x000000, intensity = 0, options = {}) {
return new THREE.MeshStandardMaterial({
color,
emissive,
emissiveIntensity: intensity,
roughness: options.roughness ?? 0.62,
metalness: options.metalness ?? 0.12,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
side: options.side ?? THREE.FrontSide
});
}
function addBox(parent, size, position, material, shadow = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(...size), material);
mesh.position.set(...position);
mesh.castShadow = shadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function textSprite(text, options = {}) {
const width = options.canvasWidth ?? 768;
const height = options.canvasHeight ?? 256;
const c = document.createElement("canvas");
c.width = width;
c.height = height;
const ctx = c.getContext("2d");
ctx.clearRect(0, 0, width, height);
const fontSize = options.fontSize ?? 92;
const weight = options.weight ?? 800;
const family = options.fontFamily ??
"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";
ctx.font = `${weight} ${fontSize}px ${family}`;
const measured = ctx.measureText(text).width;
const fitted = Math.min(fontSize, fontSize * (width * 0.88) / measured);
ctx.font = `${weight} ${fitted}px ${family}`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
if (options.background) {
ctx.fillStyle = options.background;
roundedRect(ctx, 8, 8, width - 16, height - 16, 34);
ctx.fill();
}
if (options.border) {
ctx.strokeStyle = options.border;
ctx.lineWidth = options.borderWidth ?? 5;
roundedRect(ctx, 8, 8, width - 16, height - 16, 34);
ctx.stroke();
}
ctx.shadowColor = options.glow ?? "transparent";
ctx.shadowBlur = options.glow ? 18 : 0;
ctx.fillStyle = options.color ?? "#eafcff";
ctx.fillText(text, width / 2, height / 2 + (options.offsetY ?? 0));
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.needsUpdate = true;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: options.depthTest ?? false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(options.width ?? 4, options.height ?? 0.7, 1);
sprite.renderOrder = options.renderOrder ?? 30;
return sprite;
}
function voxelPath(parent, points, size, material, spacing = 0.22) {
const made = new Set();
const result = [];
for (let s = 0; s < points.length - 1; s++) {
const a = points[s];
const b = points[s + 1];
const distance = a.distanceTo(b);
const steps = Math.max(1, Math.ceil(distance / spacing));
for (let i = 0; i <= steps; i++) {
const p = a.clone().lerp(b, i / steps);
const key = `${p.x.toFixed(2)}:${p.y.toFixed(2)}:${p.z.toFixed(2)}`;
if (made.has(key)) continue;
made.add(key);
const cube = addBox(
parent,
[size, size, size],
[p.x, p.y, p.z],
material
);
result.push(cube);
}
}
return result;
}
function polylinePoint(points, t) {
const lengths = [];
let total = 0;
for (let i = 0; i < points.length - 1; i++) {
const length = points[i].distanceTo(points[i + 1]);
lengths.push(length);
total += length;
}
let distance = ((t % 1) + 1) % 1 * total;
for (let i = 0; i < lengths.length; i++) {
if (distance <= lengths[i]) {
return points[i].clone().lerp(
points[i + 1],
lengths[i] === 0 ? 0 : distance / lengths[i]
);
}
distance -= lengths[i];
}
return points.at(-1).clone();
}
// -------------------------------------------------------------------------
// Shared genetic-template panel
// -------------------------------------------------------------------------
const panel = new THREE.Group();
panel.position.set(0, 2.12, -4.55);
scene.add(panel);
const panelBack = standard(0x0a1c23, 0x0b3038, 0.16, {
roughness: 0.78,
metalness: 0.28
});
addBox(panel, [8.9, 4.12, 0.34], [0, 0, 0], panelBack);
const panelFrame = standard(0x1b4951, 0x1c6570, 0.28, {
roughness: 0.5,
metalness: 0.35
});
addBox(panel, [8.72, 0.055, 0.12], [0, 1.96, 0.22], panelFrame);
addBox(panel, [8.72, 0.055, 0.12], [0, -1.96, 0.22], panelFrame);
addBox(panel, [0.055, 3.9, 0.12], [-4.34, 0, 0.22], panelFrame);
addBox(panel, [0.055, 3.9, 0.12], [4.34, 0, 0.22], panelFrame);
const panelTitle = textSprite("SHARED GENETIC TEMPLATE", {
width: 6.6,
height: 0.56,
fontSize: 88,
color: "#eaffff",
glow: "#49e6c1"
});
panelTitle.position.set(0, 1.56, 0.3);
panel.add(panelTitle);
const panelCaption = textSprite("28 / 28 GENES • IDENTICAL IN EVERY EXHIBIT", {
width: 6.7,
height: 0.34,
fontSize: 53,
color: "#7fa5ad",
background: "rgba(3, 13, 17, 0.78)"
});
panelCaption.position.set(0, -1.75, 0.3);
panel.add(panelCaption);
const panelTileMeshes = [];
const panelTiles = [];
const rowCategories = ["core", "muscle", "nerve", "secretory"];
rowCategories.forEach((category, row) => {
const rowY = 0.79 - row * 0.67;
const marker = addBox(
panel,
[0.18, 0.18, 0.09],
[-3.7, rowY, 0.23],
standard(COLORS[category], COLORS[category], 1.2)
);
marker.userData.noPick = true;
const rowLabel = textSprite(categoryNames[category], {
width: 1.25,
height: 0.25,
canvasWidth: 512,
canvasHeight: 128,
fontSize: 57,
color: CSS_COLORS[category]
});
rowLabel.position.set(-3.1, rowY, 0.27);
panel.add(rowLabel);
const rowGenes = genes.filter(gene => gene.category === category);
rowGenes.forEach((gene, column) => {
const categoryColor = new THREE.Color(COLORS[gene.category]);
const material = standard(
categoryColor.clone().multiplyScalar(0.22),
categoryColor,
0.35,
{ roughness: 0.52, metalness: 0.25 }
);
const tile = addBox(
panel,
[0.88, 0.47, 0.15],
[-2.55 + column * 1.02, rowY, 0.22],
material
);
tile.userData.gene = gene;
const label = textSprite(gene.name, {
width: 0.82,
height: 0.3,
canvasWidth: 512,
canvasHeight: 160,
fontSize: 67,
color: "#eefcff"
});
label.position.set(0, 0, 0.1);
tile.add(label);
panelTileMeshes.push(tile);
panelTiles.push({
mesh: tile,
material,
gene,
baseIntensity: 0.35
});
});
});
// -------------------------------------------------------------------------
// Exhibit groups and miniature complete-genome copies
// -------------------------------------------------------------------------
const cellGroups = {};
const miniCopies = {};
const exhibitRings = {};
const exhibitLights = {};
function createMiniGenome(key, parent) {
const entries = [];
const backing = addBox(
parent,
[2.47, 1.48, 0.08],
[0, -1.16, 1.43],
standard(0x0b1b21, 0x102a31, 0.12, {
roughness: 0.78,
metalness: 0.18
}),
false
);
backing.userData.noPick = true;
genes.forEach((gene, index) => {
const column = index % 7;
const row = Math.floor(index / 7);
const active = gene.category === "core" || gene.category === key;
const categoryColor = new THREE.Color(COLORS[gene.category]);
const material = standard(
active ? categoryColor.clone().multiplyScalar(0.58) : 0x173038,
active ? categoryColor : 0x071216,
active ? 0.9 : 0.035,
{ roughness: 0.55, metalness: 0.18 }
);
const tile = addBox(
parent,
[0.235, 0.22, 0.07],
[
(column - 3) * 0.315,
-1.16 + 0.465 - row * 0.31,
1.5
],
material,
false
);
tile.userData.exhibit = key;
entries.push({ mesh: tile, material, active });
});
const caption = textSprite("CELL GENOME COPY • 28 GENES • 14 HIGHLIGHTED", {
width: 3.0,
height: 0.28,
canvasWidth: 768,
canvasHeight: 150,
fontSize: 47,
color: "#8aa8ae",
background: "rgba(4, 14, 18, 0.88)"
});
caption.position.set(0, -1.96, 1.5);
parent.add(caption);
miniCopies[key] = entries;
}
function createPedestal(key, x) {
const z = 0.32;
addBox(
scene,
[4.75, 0.18, 3.0],
[x, -2.48, z],
standard(0x0b1b21, 0x0c252c, 0.12, {
roughness: 0.86,
metalness: 0.2
})
);
const ringMaterial = new THREE.MeshBasicMaterial({
color: COLORS[key],
transparent: true,
opacity: 0.8
});
const ring = new THREE.Group();
scene.add(ring);
addBox(ring, [4.55, 0.045, 0.07], [x, -2.365, z - 1.34], ringMaterial, false);
addBox(ring, [4.55, 0.045, 0.07], [x, -2.365, z + 1.34], ringMaterial, false);
addBox(ring, [0.07, 0.045, 2.68], [x - 2.275, -2.365, z], ringMaterial, false);
addBox(ring, [0.07, 0.045, 2.68], [x + 2.275, -2.365, z], ringMaterial, false);
const light = new THREE.PointLight(COLORS[key], 12, 6.5, 2);
light.position.set(x, 0.7, 1.4);
scene.add(light);
exhibitRings[key] = ringMaterial;
exhibitLights[key] = light;
}
// Muscle-like exhibit -----------------------------------------------------
const muscle = new THREE.Group();
muscle.position.set(-4.65, 0, 0);
scene.add(muscle);
cellGroups.muscle = muscle;
const muscleFiber = new THREE.Group();
muscle.add(muscleFiber);
const muscleMain = standard(0xca3d58, 0x68162b, 0.28, {
roughness: 0.66,
metalness: 0.16
});
const muscleAlt = standard(0xe65068, 0x7b1d32, 0.3, {
roughness: 0.62,
metalness: 0.16
});
const muscleStripe = standard(0x521b31, 0x230812, 0.08, {
roughness: 0.84
});
for (let i = 0; i < 13; i++) {
const x = -2.16 + i * 0.36;
const taper = 0.92 + (1 - Math.abs(i - 6) / 6) * 0.28;
addBox(
muscleFiber,
[0.43, taper, 1.08],
[x, 0.32, 0],
i % 2 ? muscleMain : muscleAlt
);
addBox(
muscleFiber,
[0.075, taper * 0.76, 0.055],
[x + 0.16, 0.32, 0.567],
muscleStripe,
false
);
}
addBox(
muscleFiber,
[0.62, 0.5, 0.16],
[0.73, 0.34, 0.62],
standard(0x76243d, 0x431022, 0.18)
);
const muscleLabel = textSprite("MUSCLE-LIKE / CONTRACTILE", {
width: 4.1,
height: 0.43,
fontSize: 72,
color: "#ffdbe1",
glow: "#ff647b"
});
muscleLabel.position.set(0, 1.55, 0);
muscle.add(muscleLabel);
createMiniGenome("muscle", muscle);
createPedestal("muscle", -4.65);
// Nerve-like exhibit ------------------------------------------------------
const nerve = new THREE.Group();
nerve.position.set(0.05, 0.08, 0);
scene.add(nerve);
cellGroups.nerve = nerve;
const nerveMain = standard(0x6754cc, 0x2c206c, 0.34, {
roughness: 0.61,
metalness: 0.18
});
const nerveLight = standard(0x8978ed, 0x392c89, 0.36, {
roughness: 0.58,
metalness: 0.18
});
const nerveCore = standard(0x221c4c, 0x100d28, 0.08);
const somaBlocks = [
[-0.52, 0.03, 0], [0.52, 0.03, 0],
[-0.52, 0.86, 0], [0.52, 0.86, 0],
[0, 0.44, 0.18], [-0.2, 0.4, -0.55], [0.34, 0.38, -0.48]
];
somaBlocks.forEach((position, index) => {
addBox(
nerve,
[0.93, 0.83, 0.86],
position,
index % 2 ? nerveMain : nerveLight
);
});
addBox(
nerve,
[0.54, 0.54, 0.15],
[0.02, 0.42, 0.54],
standard(0xaaa0ff, 0x5748bd, 0.55)
);
const dendritePaths = [
[new THREE.Vector3(-0.45, 0.42, 0), new THREE.Vector3(-1.18, 1.1, 0.05), new THREE.Vector3(-1.75, 1.66, 0.05)],
[new THREE.Vector3(-0.45, 0.15, 0), new THREE.Vector3(-1.22, -0.45, 0.16), new THREE.Vector3(-1.8, -0.78, 0.25)],
[new THREE.Vector3(0.12, 1.05, 0), new THREE.Vector3(0.28, 1.62, -0.12), new THREE.Vector3(0.06, 2.08, -0.18)],
[new THREE.Vector3(0.5, 0.2, 0), new THREE.Vector3(1.3, 0.65, 0.22), new THREE.Vector3(1.86, 1.18, 0.3)]
];
dendritePaths.forEach(path => voxelPath(nerve, path, 0.25, nerveLight, 0.19));
const axonPath = [
new THREE.Vector3(0.9, 0.25, 0),
new THREE.Vector3(1.65, 0.25, 0.02),
new THREE.Vector3(2.45, 0.12, 0.18),
new THREE.Vector3(3.05, -0.05, 0.34)
];
voxelPath(nerve, axonPath, 0.23, nerveMain, 0.18);
voxelPath(
nerve,
[
new THREE.Vector3(2.25, 0.18, 0.12),
new THREE.Vector3(2.48, -0.55, 0.4),
new THREE.Vector3(2.78, -1.02, 0.54)
],
0.18,
nerveLight,
0.16
);
const nerveSignalMaterial = standard(0xc6c0ff, 0x7667ff, 2.2);
const nerveSignal = addBox(
nerve,
[0.27, 0.27, 0.27],
[0, 0, 0],
nerveSignalMaterial,
false
);
const nerveLabel = textSprite("NERVE-LIKE / SYNAPTIC", {
width: 4.0,
height: 0.43,
fontSize: 72,
color: "#e5e0ff",
glow: "#9181ff"
});
nerveLabel.position.set(0, 2.35, 0);
nerve.add(nerveLabel);
createMiniGenome("nerve", nerve);
createPedestal("nerve", 0.05);
// Secretory exhibit -------------------------------------------------------
const secretory = new THREE.Group();
secretory.position.set(4.65, 0, 0);
scene.add(secretory);
cellGroups.secretory = secretory;
const secretMain = standard(0xd79a2e, 0x6e4610, 0.27, {
roughness: 0.6,
metalness: 0.17
});
const secretLight = standard(0xf2bd4e, 0x805818, 0.31, {
roughness: 0.58,
metalness: 0.18
});
const secretCore = standard(0x533b18, 0x1d1207, 0.08);
const secretBlocks = [
[-0.7, 0.0, 0], [0, 0, 0], [0.7, 0, 0],
[-0.7, 0.68, 0], [0, 0.68, 0], [0.7, 0.68, 0],
[0, 0.08, -0.66], [-0.7, 0.08, -0.66], [0.7, 0.08, -0.66]
];
secretBlocks.forEach((position, index) => {
addBox(
secretory,
[0.72, 0.72, 0.72],
position,
index % 3 === 0 ? secretLight : secretMain
);
});
addBox(
secretory,
[0.5, 0.5, 0.16],
[0.05, 0.26, 0.43],
standard(0xffe29a, 0xb4771c, 0.5)
);
const granuleMaterial = standard(0xffdc72, 0xffad22, 1.25);
const granules = [];
[
[-0.42, 0.2, 0.42], [0.38, 0.52, 0.42], [0.42, -0.05, 0.42],
[-0.48, 0.75, 0.1]
].forEach(position => {
granules.push(addBox(
secretory,
[0.19, 0.19, 0.19],
position,
granuleMaterial,
false
));
});
const secretionMaterial = standard(0xffd76c, 0xffa91f, 1.8, {
transparent: true,
opacity: 0.9
});
const secretionPuff = addBox(
secretory,
[0.25, 0.25, 0.25],
[0, 1, 0],
secretionMaterial,
false
);
const secretLabel = textSprite("SECRETORY / ENDOCRINE", {
width: 4.0,
height: 0.43,
fontSize: 70,
color: "#fff0c4",
glow: "#ffc857"
});
secretLabel.position.set(0, 1.65, 0);
secretory.add(secretLabel);
createMiniGenome("secretory", secretory);
createPedestal("secretory", 4.65);
// -------------------------------------------------------------------------
// Expression routes: panel to cell genome copies
// -------------------------------------------------------------------------
const routes = [];
function makeRoute(points, category, phaseOffset = 0) {
const group = new THREE.Group();
scene.add(group);
const color = COLORS[category];
const coreMaterial = standard(color, color, 1.15, {
transparent: true,
opacity: 0.55,
roughness: 0.4
});
const underMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.08,
depthWrite: false
});
const path = points.map(point =>
point instanceof THREE.Vector3 ? point : new THREE.Vector3(...point)
);
for (let i = 0; i < path.length - 1; i++) {
const a = path[i];
const b = path[i + 1];
const direction = b.clone().sub(a);
const length = direction.length();
if (length < 0.001) continue;
const midpoint = a.clone().add(b).multiplyScalar(0.5);
const quaternion = new THREE.Quaternion().setFromUnitVectors(
new THREE.Vector3(1, 0, 0),
direction.clone().normalize()
);
const under = new THREE.Mesh(
new THREE.BoxGeometry(length + 0.04, 0.16, 0.16),
underMaterial
);
under.position.copy(midpoint);
under.quaternion.copy(quaternion);
group.add(under);
const core = new THREE.Mesh(
new THREE.BoxGeometry(length, 0.065, 0.065),
coreMaterial
);
core.position.copy(midpoint);
core.quaternion.copy(quaternion);
group.add(core);
}
path.slice(1, -1).forEach(point => {
const joint = addBox(
group,
[0.18, 0.18, 0.18],
[point.x, point.y, point.z],
coreMaterial,
false
);
joint.userData.noPick = true;
});
const packet = addBox(
group,
[0.19, 0.19, 0.19],
[path[0].x, path[0].y, path[0].z],
standard(color, color, 2.2),
false
);
packet.userData.noPick = true;
const route = {
category,
path,
group,
coreMaterial,
underMaterial,
packet,
phaseOffset
};
routes.push(route);
return route;
}
makeRoute([
[-2.2, 0.08, -4.28],
[-2.2, -0.88, -3.4],
[-4.65, -0.88, -3.4],
[-4.65, -1.16, 1.5]
], "muscle", 0.0);
makeRoute([
[0, 0.08, -4.28],
[0, -0.62, -3.45],
[0.05, -1.16, 1.5]
], "nerve", 0.33);
makeRoute([
[2.2, 0.08, -4.28],
[2.2, -0.88, -3.4],
[4.65, -0.88, -3.4],
[4.65, -1.16, 1.5]
], "secretory", 0.66);
// Shared housekeeping bus and branches.
makeRoute([
[-3.55, 0.08, -4.28],
[-3.55, -2.08, -3.4],
[4.65, -2.08, -3.4]
], "core", 0.15);
makeRoute([
[-4.65, -2.08, -3.4],
[-4.65, -1.16, 1.5]
], "core", 0.4);
makeRoute([
[0.05, -2.08, -3.4],
[0.05, -1.16, 1.5]
], "core", 0.65);
makeRoute([
[4.65, -2.08, -3.4],
[4.65, -1.16, 1.5]
], "core", 0.9);
// -------------------------------------------------------------------------
// Interactive state and explanatory copy
// -------------------------------------------------------------------------
let selected = "all";
let paused = false;
const focusData = {
all: {
accent: CSS_COLORS.core,
kicker: "Core idea",
title: "Same genome. Different expression.",
body:
"Every exhibit contains the same <strong>28-gene set</strong>. " +
"Bright tiles indicate genes highly expressed in that cell; dim tiles " +
"are still present, but not highly expressed. Cell specialization is " +
"a regulatory state—not a missing genome.",
stats: [["28", "genes / cell"], ["3", "cell identities"], ["4", "programs"]]
},
muscle: {
accent: CSS_COLORS.muscle,
kicker: "Muscle-like program",
title: "Force through a contractile network.",
body:
"<strong>ACTA1, MYH2, TNNT2, DES, DMD</strong> and related genes are " +
"highly expressed to build and maintain contractile machinery. " +
"Neural and secretory genes remain in the genome but are largely silent.",
stats: [["14", "highlighted"], ["7", "muscle genes"], ["7", "shared genes"]]
},
nerve: {
accent: CSS_COLORS.nerve,
kicker: "Nerve-like program",
title: "Electrical and synaptic specialization.",
body:
"<strong>SNAP25, SYT1, STMN2, RBFOX3, MAP2</strong> and related genes " +
"support neural identity and signaling. Contractile and endocrine genes " +
"are not absent—they simply have a different regulatory state.",
stats: [["14", "highlighted"], ["7", "nerve genes"], ["7", "shared genes"]]
},
secretory: {
accent: CSS_COLORS.secretory,
kicker: "Secretory program",
title: "Packaged, regulated hormone release.",
body:
"<strong>INS, CHGA, CHGB, SYP, SCG2</strong> and related genes support " +
"regulated secretion. Muscle and neural genes remain present in every " +
"cell, while the secretory program dominates this exhibit.",
stats: [["14", "highlighted"], ["7", "secretory genes"], ["7", "shared genes"]]
}
};
function updateInfo() {
const data = focusData[selected];
document.documentElement.style.setProperty("--accent", data.accent);
info.innerHTML = `
<div class="info-kicker">${data.kicker}</div>
<h2>${data.title}</h2>
<p>${data.body}</p>
<div class="stats">
${data.stats.map(stat => `
<div class="stat">
<b>${stat[0]}</b>
<span>${stat[1]}</span>
</div>
`).join("")}
</div>
<div class="legend">
<span><i class="swatch"></i> high expression</span>
<span><i class="swatch dim"></i> present, low expression</span>
</div>
<p class="footnote">
Illustrative gene panel. Bright tiles show a selected program, not the
complete real-world transcriptome.
</p>
`;
}
function setFocus(key) {
selected = key;
document.querySelectorAll("[data-focus]").forEach(button => {
const active = button.dataset.focus === key;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
const targets = {
all: [new THREE.Vector3(0, 0.35, -0.9), 1],
muscle: [new THREE.Vector3(-4.65, 0.1, 0.3), 1.55],
nerve: [new THREE.Vector3(0.05, 0.45, 0.25), 1.62],
secretory: [new THREE.Vector3(4.65, 0.3, 0.3), 1.55]
};
desiredTarget.copy(targets[key][0]);
desiredOrbit.zoom = targets[key][1];
panelTiles.forEach(tile => {
const category = tile.gene.category;
let intensity;
if (key === "all") {
intensity = category === "core" ? 0.6 : 0.38;
} else {
intensity = category === "core" || category === key ? 1.05 : 0.045;
}
tile.baseIntensity = intensity;
tile.material.emissiveIntensity = intensity;
});
Object.keys(exhibitRings).forEach(exhibitKey => {
const active = key === "all" || key === exhibitKey;
exhibitRings[exhibitKey].opacity = active ? 0.92 : 0.17;
exhibitLights[exhibitKey].intensity = active ? 16 : 4;
});
routes.forEach(route => {
let opacity;
if (route.category === "core") {
opacity = key === "all" ? 0.42 : 0.72;
} else if (key === "all") {
opacity = 0.48;
} else {
opacity = route.category === key ? 0.96 : 0.055;
}
route.coreMaterial.opacity = opacity;
route.underMaterial.opacity = opacity * 0.18;
route.packet.visible = opacity > 0.1;
});
updateInfo();
}
document.querySelectorAll("[data-focus]").forEach(button => {
button.addEventListener("click", () => setFocus(button.dataset.focus));
});
const pauseButton = document.getElementById("pause");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume expression" : "Pause expression";
pauseButton.classList.toggle("active", paused);
});
document.getElementById("reset").addEventListener("click", () => {
desiredOrbit.yaw = 0.27;
desiredOrbit.pitch = 0.48;
setFocus("all");
});
// -------------------------------------------------------------------------
// Custom camera controls: orbit, wheel zoom, shift/right-drag pan
// -------------------------------------------------------------------------
let pointerDown = null;
let dragging = false;
function updateHover(event) {
const rect = canvas.getBoundingClientRect();
mouse.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
mouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(mouse, camera);
const hits = raycaster.intersectObjects(interactiveMeshes, false);
if (!hits.length) {
tooltip.style.display = "none";
canvas.style.cursor = dragging ? "grabbing" : "default";
return;
}
const hit = hits[0].object;
if (hit.userData.gene) {
const gene = hit.userData.gene;
const expression = gene.category === "core"
? "Highly expressed in all three cell types."
: `Highly expressed in the ${categoryFullNames[gene.category].toLowerCase()} exhibit.`;
tooltip.innerHTML = `
<b>${gene.name}</b>
Present in every cell in this template.<br>
${expression}
`;
tooltip.style.display = "block";
const maxX = window.innerWidth - 265;
const maxY = window.innerHeight - 105;
tooltip.style.left = `${Math.max(8, Math.min(event.clientX + 15, maxX))}px`;
tooltip.style.top = `${Math.max(8, Math.min(event.clientY + 15, maxY))}px`;
canvas.style.cursor = "pointer";
} else {
tooltip.style.display = "none";
canvas.style.cursor = "pointer";
}
}
canvas.addEventListener("pointerdown", event => {
if (event.button !== 0 && event.button !== 2) return;
pointerDown = {
x: event.clientX,
y: event.clientY,
lastX: event.clientX,
lastY: event.clientY,
button: event.button,
pan: event.shiftKey || event.button === 2
};
dragging = false;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", event => {
if (!pointerDown) {
updateHover(event);
return;
}
const dx = event.clientX - pointerDown.lastX;
const dy = event.clientY - pointerDown.lastY;
const totalDistance = Math.hypot(
event.clientX - pointerDown.x,
event.clientY - pointerDown.y
);
if (totalDistance > 4) dragging = true;
if (pointerDown.pan) {
const right = new THREE.Vector3(
Math.cos(desiredOrbit.yaw),
0,
-Math.sin(desiredOrbit.yaw)
);
const up = new THREE.Vector3(0, 1, 0);
const panScale = 0.012 / desiredOrbit.zoom;
desiredTarget.addScaledVector(right, -dx * panScale);
desiredTarget.addScaledVector(up, dy * panScale);
} else {
desiredOrbit.yaw -= dx * 0.006;
desiredOrbit.pitch = THREE.MathUtils.clamp(
desiredOrbit.pitch + dy * 0.005,
0.12,
1.15
);
}
pointerDown.lastX = event.clientX;
pointerDown.lastY = event.clientY;
});
canvas.addEventListener("pointerup", event => {
const wasDragging = dragging;
pointerDown = null;
dragging = false;
canvas.style.cursor = "default";
if (!wasDragging) {
updateHover(event);
const rect = canvas.getBoundingClientRect();
mouse.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
mouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(mouse, camera);
const hits = raycaster.intersectObjects(interactiveMeshes, false);
if (!hits.length) return;
const object = hits[0].object;
if (object.userData.gene) {
const category = object.userData.gene.category;
setFocus(category === "core" ? "all" : category);
} else if (object.userData.exhibit) {
setFocus(object.userData.exhibit);
}
}
});
canvas.addEventListener("pointercancel", () => {
pointerDown = null;
dragging = false;
canvas.style.cursor = "default";
});
canvas.addEventListener("pointerleave", () => {
if (!pointerDown) tooltip.style.display = "none";
});
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("wheel", event => {
event.preventDefault();
desiredOrbit.zoom = THREE.MathUtils.clamp(
desiredOrbit.zoom * Math.exp(-event.deltaY * 0.001),
0.72,
2.8
);
}, { passive: false });
window.addEventListener("keydown", event => {
if (["BUTTON", "INPUT", "TEXTAREA"].includes(event.target.tagName)) return;
if (event.key === "ArrowLeft") desiredOrbit.yaw += 0.08;
if (event.key === "ArrowRight") desiredOrbit.yaw -= 0.08;
if (event.key === "ArrowUp") desiredOrbit.pitch += 0.06;
if (event.key === "ArrowDown") desiredOrbit.pitch -= 0.06;
if (event.key === "1") setFocus("all");
if (event.key === "2") setFocus("muscle");
if (event.key === "3") setFocus("nerve");
if (event.key === "4") setFocus("secretory");
if (event.code === "Space") {
event.preventDefault();
pauseButton.click();
}
});
// -------------------------------------------------------------------------
// Picking setup
// -------------------------------------------------------------------------
const cellPickMeshes = [];
Object.entries(cellGroups).forEach(([key, group]) => {
group.traverse(object => {
if (object.isMesh && !object.userData.noPick) {
object.userData.exhibit = key;
cellPickMeshes.push(object);
}
});
});
const interactiveMeshes = [...panelTileMeshes, ...cellPickMeshes];
const raycaster = new THREE.Raycaster();
const mouse = new THREE.Vector2();
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let simulationTime = 0;
let firstFrame = true;
const nerveSignalPath = [
new THREE.Vector3(-1.7, 1.62, 0.08),
new THREE.Vector3(-1.12, 1.05, 0.05),
new THREE.Vector3(-0.42, 0.43, 0.05),
new THREE.Vector3(0.7, 0.25, 0.02),
new THREE.Vector3(1.65, 0.25, 0.03),
new THREE.Vector3(2.45, 0.12, 0.19),
new THREE.Vector3(3.05, -0.05, 0.35)
];
const secretionPath = [
new THREE.Vector3(0.15, 0.75, 0.43),
new THREE.Vector3(0.55, 1.32, 0.52),
new THREE.Vector3(1.03, 1.93, 0.58),
new THREE.Vector3(1.48, 2.42, 0.61)
];
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
if (!paused) simulationTime += dt;
// Smooth camera movement.
const smoothing = 1 - Math.exp(-dt * 8);
orbit.yaw = THREE.MathUtils.lerp(orbit.yaw, desiredOrbit.yaw, smoothing);
orbit.pitch = THREE.MathUtils.lerp(orbit.pitch, desiredOrbit.pitch, smoothing);
orbit.zoom = THREE.MathUtils.lerp(orbit.zoom, desiredOrbit.zoom, smoothing);
cameraTarget.lerp(desiredTarget, smoothing);
const distance = 25;
const horizontal = Math.cos(orbit.pitch) * distance;
const desiredPosition = new THREE.Vector3(
cameraTarget.x + Math.sin(orbit.yaw) * horizontal,
cameraTarget.y + Math.sin(orbit.pitch) * distance,
cameraTarget.z + Math.cos(orbit.yaw) * horizontal
);
camera.position.lerp(desiredPosition, smoothing);
camera.zoom = orbit.zoom;
camera.updateProjectionMatrix();
camera.lookAt(cameraTarget);
// Muscle contraction.
const contraction = 1 + Math.sin(simulationTime * 4.1) * 0.038;
muscleFiber.scale.x = contraction;
muscleStripe.emissiveIntensity = 0.06 + Math.sin(simulationTime * 4.1) * 0.025;
// Nerve signal.
const nervePhase = (simulationTime * 0.24) % 1;
nerveSignal.position.copy(polylinePoint(nerveSignalPath, nervePhase));
nerveSignal.rotation.set(
simulationTime * 1.7,
simulationTime * 2.1,
simulationTime * 1.3
);
nerveSignalMaterial.emissiveIntensity = 1.8 + Math.sin(simulationTime * 12) * 0.55;
// Secretory granule release.
const secretionPhase = (simulationTime * 0.2) % 1;
secretionPuff.position.copy(polylinePoint(secretionPath, secretionPhase));
secretionPuff.scale.setScalar(0.65 + secretionPhase * 1.2);
secretionMaterial.opacity = Math.max(0, 0.9 * (1 - secretionPhase));
secretionPuff.rotation.set(
simulationTime * 1.2,
simulationTime * 1.5,
simulationTime * 0.8
);
granules.forEach((granule, index) => {
const pulse = 1 + Math.sin(simulationTime * 2.5 + index) * 0.08;
granule.scale.setScalar(pulse);
});
// Moving expression packets.
routes.forEach(route => {
if (!route.packet.visible) return;
const phase = (simulationTime * 0.17 + route.phaseOffset) % 1;
route.packet.position.copy(polylinePoint(route.path, phase));
route.packet.rotation.set(
simulationTime * 1.5,
simulationTime * 2,
simulationTime
);
});
// Gentle panel pulse.
panelTiles.forEach((tile, index) => {
const pulse = 0.94 + Math.sin(simulationTime * 2.2 + index * 0.32) * 0.06;
tile.material.emissiveIntensity = tile.baseIntensity * pulse;
});
// Miniature genome-copy expression pulses.
Object.values(miniCopies).forEach(entries => {
entries.forEach((entry, index) => {
entry.material.emissiveIntensity = entry.active
? 0.88 + Math.sin(simulationTime * 2.5 + index * 0.25) * 0.2
: 0.025;
});
});
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 450);
}
}
// -------------------------------------------------------------------------
// Resize
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(10.8, 16.5 / aspect);
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
setFocus("all");
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```