Prompt specification
Build or customize the Three.js 3D scene "Genetic linkage teaching laboratory" 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: Genetic linkage teaching laboratory
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/genetic-linkage-teaching-laboratory-x0927
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: genetic linkage teaching laboratory. Compose chromosome models, synthetic offspring category bins, and a linkage diagram; connect recombination events to observed categories without presenting fabricated data as an experiment. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (genetic-linkage-teaching-laboratory-x0927):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Link/Lab — Genetic Linkage Teaching Model</title>
<style>
:root {
--bg: #09111d;
--panel: #111d2c;
--panel-2: #172638;
--line: rgba(174, 205, 231, 0.14);
--text: #eef7ff;
--muted: #9db0c3;
--cyan: #67e8f9;
--teal: #4ecdc4;
--amber: #ffb703;
--orange: #ff7a45;
--pink: #ff6b9f;
--blue: #4cc9f0;
--a: #ffd166;
--aa: #9c7a2a;
--shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}
* { box-sizing: border-box; }
html, body {
margin: 0;
min-height: 100%;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
height: 100vh;
overflow: hidden;
}
header {
height: 74px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 0 22px;
border-bottom: 1px solid var(--line);
background: rgba(9, 17, 29, 0.96);
position: relative;
z-index: 20;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
width: 34px;
height: 34px;
position: relative;
flex: 0 0 auto;
}
.brand-mark i {
position: absolute;
width: 14px;
height: 14px;
border-radius: 3px;
box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
}
.brand-mark i:nth-child(1) { left: 0; top: 10px; background: var(--cyan); }
.brand-mark i:nth-child(2) { left: 10px; top: 0; background: var(--amber); }
.brand-mark i:nth-child(3) { left: 20px; top: 10px; background: var(--pink); }
.brand-mark i:nth-child(4) { left: 10px; top: 20px; background: var(--teal); }
.brand-copy { min-width: 0; }
.brand-title {
font-size: 17px;
font-weight: 800;
letter-spacing: .09em;
line-height: 1.1;
}
.brand-subtitle {
margin-top: 4px;
color: var(--muted);
font: 600 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .13em;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.synthetic-badge {
display: inline-flex;
align-items: center;
gap: 8px;
flex: 0 0 auto;
border: 1px solid rgba(255, 183, 3, .38);
background: rgba(255, 183, 3, .08);
color: #ffd56a;
padding: 9px 12px;
border-radius: 8px;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .1em;
}
.synthetic-badge::before {
content: "";
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--amber);
box-shadow: 0 0 12px rgba(255,183,3,.7);
}
main {
height: calc(100vh - 74px);
display: grid;
grid-template-columns: minmax(0, 1fr) 340px;
}
#stage {
position: relative;
min-width: 0;
overflow: hidden;
background:
radial-gradient(circle at 45% 30%, rgba(41, 74, 99, .22), transparent 44%),
#0b1623;
}
#stage canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.stage-hud {
position: absolute;
z-index: 6;
top: 18px;
left: 18px;
display: flex;
gap: 8px;
align-items: center;
pointer-events: none;
}
.hud-chip {
border: 1px solid rgba(174, 205, 231, .16);
background: rgba(9, 17, 29, .72);
backdrop-filter: blur(12px);
border-radius: 7px;
padding: 8px 10px;
color: #c8d8e7;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .1em;
}
.hud-chip strong { color: var(--cyan); }
.stage-help {
position: absolute;
z-index: 6;
left: 18px;
bottom: 18px;
display: flex;
align-items: center;
gap: 12px;
color: #b9cad8;
background: rgba(9, 17, 29, .78);
border: 1px solid rgba(174, 205, 231, .13);
backdrop-filter: blur(12px);
border-radius: 8px;
padding: 10px 12px;
font: 600 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .04em;
pointer-events: none;
}
.stage-help span { color: var(--cyan); }
.zoom-tools {
position: absolute;
right: 18px;
bottom: 18px;
z-index: 8;
display: flex;
gap: 6px;
}
.zoom-tools button {
width: 34px;
height: 34px;
border: 1px solid rgba(174, 205, 231, .18);
background: rgba(9, 17, 29, .84);
color: var(--text);
border-radius: 7px;
font: 700 18px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
cursor: pointer;
}
.zoom-tools button:hover { border-color: var(--cyan); color: var(--cyan); }
#loading {
position: absolute;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #0b1623;
color: var(--muted);
font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .13em;
}
#loading::before {
content: "";
width: 18px;
height: 18px;
margin-right: 12px;
border: 2px solid rgba(103,232,249,.18);
border-top-color: var(--cyan);
animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#labels {
position: absolute;
inset: 0;
z-index: 5;
pointer-events: none;
overflow: hidden;
}
.world-label {
position: absolute;
left: 0;
top: 0;
min-width: 94px;
padding: 7px 9px;
border-radius: 6px;
border: 1px solid rgba(174, 205, 231, .17);
background: rgba(8, 16, 27, .82);
backdrop-filter: blur(8px);
box-shadow: 0 7px 24px rgba(0,0,0,.2);
color: #dceaf5;
font: 700 9px/1.25 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .08em;
white-space: nowrap;
pointer-events: none;
will-change: transform;
}
.world-label .sub {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 8px;
letter-spacing: .05em;
}
.world-label.zone {
color: var(--cyan);
border-color: rgba(103,232,249,.24);
background: rgba(8, 23, 34, .88);
}
.world-label.event {
color: #ffc178;
border-color: rgba(255,122,69,.34);
}
.world-label.bin-label {
pointer-events: auto;
cursor: pointer;
}
.world-label.bin-label b {
display: inline-block;
margin-right: 5px;
color: var(--text);
font-size: 12px;
}
.world-label.bin-label.recombinant {
border-color: rgba(255,183,3,.35);
}
.world-label.bin-label.selected {
box-shadow: 0 0 0 2px rgba(103,232,249,.32), 0 10px 28px rgba(0,0,0,.28);
border-color: var(--cyan);
}
aside {
position: relative;
z-index: 10;
border-left: 1px solid var(--line);
background: linear-gradient(180deg, #111d2c, #0d1826);
overflow-y: auto;
padding: 19px 18px 24px;
scrollbar-width: thin;
scrollbar-color: #294157 transparent;
}
.eyebrow {
color: var(--cyan);
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .16em;
text-transform: uppercase;
}
h1 {
margin: 9px 0 8px;
font-size: 24px;
line-height: 1.08;
letter-spacing: -.035em;
}
.lede {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.section {
margin-top: 20px;
padding-top: 18px;
border-top: 1px solid var(--line);
}
.section-title {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 11px;
color: #cfe0ed;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .12em;
text-transform: uppercase;
}
.section-title span {
color: #647c92;
font-size: 8px;
}
.sequence {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.sequence button {
min-height: 62px;
text-align: left;
padding: 10px;
color: #d7e6f1;
border: 1px solid rgba(174,205,231,.13);
border-radius: 8px;
background: rgba(255,255,255,.025);
cursor: pointer;
transition: .18s ease;
}
.sequence button:hover,
.sequence button.active {
border-color: rgba(103,232,249,.45);
background: rgba(103,232,249,.075);
}
.sequence button strong {
display: block;
color: var(--cyan);
font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .08em;
}
.sequence button span {
display: block;
margin-top: 7px;
color: var(--muted);
font-size: 10px;
line-height: 1.25;
}
.control-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 9px 0;
}
.control-row + .control-row { border-top: 1px solid rgba(174,205,231,.08); }
.control-copy strong {
display: block;
font-size: 11px;
margin-bottom: 3px;
}
.control-copy small {
color: var(--muted);
font-size: 9px;
line-height: 1.35;
}
.switch {
position: relative;
width: 38px;
height: 21px;
flex: 0 0 auto;
}
.switch input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.switch i {
position: absolute;
inset: 0;
border-radius: 20px;
background: #26394d;
border: 1px solid rgba(174,205,231,.13);
cursor: pointer;
transition: .2s ease;
}
.switch i::after {
content: "";
position: absolute;
width: 15px;
height: 15px;
left: 2px;
top: 2px;
border-radius: 50%;
background: #9db0c3;
transition: .2s ease;
}
.switch input:checked + i { background: rgba(78,205,196,.28); border-color: rgba(78,205,196,.55); }
.switch input:checked + i::after { transform: translateX(17px); background: var(--teal); }
.table-wrap {
overflow: hidden;
border: 1px solid rgba(174,205,231,.11);
border-radius: 8px;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 10px;
}
th {
padding: 9px 8px;
color: #7890a5;
background: rgba(255,255,255,.025);
text-align: left;
font: 700 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .08em;
text-transform: uppercase;
}
td {
padding: 10px 8px;
border-top: 1px solid rgba(174,205,231,.08);
color: #c8d8e5;
}
tbody tr { cursor: pointer; }
tbody tr:hover,
tbody tr.active { background: rgba(103,232,249,.055); }
td.genotype {
color: var(--text);
font: 800 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
td.relation.recombinant { color: var(--amber); }
td.relation.parental { color: var(--teal); }
td.observed { color: #6e8599; text-align: center; }
.detail-card {
margin-top: 10px;
padding: 11px;
border-left: 2px solid var(--cyan);
background: rgba(103,232,249,.055);
border-radius: 0 7px 7px 0;
}
.detail-card strong {
display: block;
font-size: 11px;
margin-bottom: 5px;
}
.detail-card p {
margin: 0;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.disclaimer {
padding: 12px;
border: 1px solid rgba(255,183,3,.23);
border-radius: 8px;
background: rgba(255,183,3,.055);
}
.disclaimer strong {
display: block;
margin-bottom: 6px;
color: #ffd56a;
font: 800 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .1em;
}
.disclaimer p {
margin: 0;
color: #c5b98f;
font-size: 10px;
line-height: 1.5;
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px 12px;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #afc2d2;
font-size: 9px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
flex: 0 0 auto;
}
.keyline {
margin-top: 15px;
color: #657d92;
font: 600 8px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .04em;
}
@media (max-width: 900px) {
body { height: auto; overflow: auto; }
header { padding: 0 14px; }
.synthetic-badge { font-size: 8px; padding: 8px; }
main { height: auto; display: block; }
#stage { height: 64vh; min-height: 480px; }
aside { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
}
@media (max-width: 560px) {
.brand-subtitle { display: none; }
.synthetic-badge { max-width: 132px; white-space: normal; line-height: 1.35; }
#stage { height: 58vh; min-height: 420px; }
.stage-help { max-width: calc(100% - 120px); }
.world-label { transform: scale(.88); }
}
</style>
</head>
<body>
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true"><i></i><i></i><i></i><i></i></div>
<div class="brand-copy">
<div class="brand-title">LINK/LAB 02</div>
<div class="brand-subtitle">GENETIC LINKAGE • VOXEL TEACHING MODEL</div>
</div>
</div>
<div class="synthetic-badge">SYNTHETIC DISPLAY · NO EXPERIMENTAL DATA</div>
</header>
<main>
<section id="stage" aria-label="Interactive three-dimensional genetic linkage laboratory">
<div id="loading">ASSEMBLING VOXEL LAB</div>
<div id="labels"></div>
<div class="stage-hud">
<div class="hud-chip"><strong>MODEL</strong> A — B LINKAGE</div>
<div class="hud-chip">CLICK A CATEGORY TO INSPECT</div>
</div>
<div class="stage-help">
<span>DRAG</span> orbit
<span>SCROLL</span> zoom
<span>1–4</span> focus
</div>
<div class="zoom-tools" aria-label="Camera controls">
<button id="zoomIn" title="Zoom in" aria-label="Zoom in">+</button>
<button id="zoomOut" title="Zoom out" aria-label="Zoom out">−</button>
</div>
</section>
<aside>
<div class="eyebrow">Teaching laboratory</div>
<h1>Reading a linkage event</h1>
<p class="lede">
Explore how one illustrated crossover between linked loci can map to
parental and recombinant gamete classes.
</p>
<div class="section">
<div class="section-title">Lesson sequence <span>CLICK TO FOCUS</span></div>
<nav class="sequence" aria-label="Lesson sequence">
<button data-view="parent" class="active">
<strong>01 · MODELS</strong>
<span>Homologous chromosomes and meiotic products</span>
</button>
<button data-view="event">
<strong>02 · EVENT</strong>
<span>Locate the crossover on the linkage map</span>
</button>
<button data-view="bins">
<strong>03 · CATEGORIES</strong>
<span>Connect parental and recombinant classes</span>
</button>
<button data-view="overview">
<strong>04 · BOUNDARY</strong>
<span>Separate the model from observations</span>
</button>
</nav>
</div>
<div class="section">
<div class="section-title">Display layers <span>LIVE</span></div>
<div class="control-row">
<div class="control-copy">
<strong>Synthetic category icons</strong>
<small>Decorative voxels, not sampled offspring.</small>
</div>
<label class="switch">
<input id="iconsToggle" type="checkbox" checked>
<i aria-hidden="true"></i>
</label>
</div>
<div class="control-row">
<div class="control-copy">
<strong>Event traces</strong>
<small>Shows category connections.</small>
</div>
<label class="switch">
<input id="traceToggle" type="checkbox" checked>
<i aria-hidden="true"></i>
</label>
</div>
</div>
<div class="section">
<div class="section-title">Observed categories <span>NO VALUES ENTERED</span></div>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Class</th>
<th>Relation</th>
<th title="No observation has been entered">Observed</th>
</tr>
</thead>
<tbody id="categoryRows">
<tr data-bin="AB">
<td class="genotype">AB</td>
<td class="relation parental">parental</td>
<td class="observed">—</td>
</tr>
<tr data-bin="Ab">
<td class="genotype">Ab</td>
<td class="relation recombinant">recombinant</td>
<td class="observed">—</td>
</tr>
<tr data-bin="aB">
<td class="genotype">aB</td>
<td class="relation recombinant">recombinant</td>
<td class="observed">—</td>
</tr>
<tr data-bin="ab">
<td class="genotype">ab</td>
<td class="relation parental">parental</td>
<td class="observed">—</td>
</tr>
</tbody>
</table>
</div>
<div class="detail-card" id="detailCard">
<strong id="detailTitle">AB · parental class</strong>
<p id="detailText">
An illustrative parental haplotype. The bin contains synthetic icons only;
no observation or count has been supplied.
</p>
</div>
</div>
<div class="section">
<div class="disclaimer">
<strong>MODEL — NOT EXPERIMENT</strong>
<p>
The scene depicts one pedagogical crossover configuration. It is not a
sampled population, does not estimate recombination frequency, and does
not present fabricated counts as observations.
</p>
</div>
</div>
<div class="section">
<div class="section-title">Color key <span>ALLELES / CLASSES</span></div>
<div class="legend">
<div class="legend-item"><span class="swatch" style="background:#ffd166"></span>A allele</div>
<div class="legend-item"><span class="swatch" style="background:#9c7a2a"></span>a allele</div>
<div class="legend-item"><span class="swatch" style="background:#ff6b9f"></span>B allele</div>
<div class="legend-item"><span class="swatch" style="background:#4cc9f0"></span>b allele</div>
<div class="legend-item"><span class="swatch" style="background:#4ecdc4"></span>parental class</div>
<div class="legend-item"><span class="swatch" style="background:#ffb703"></span>recombinant class</div>
</div>
<div class="keyline">
R · RESET VIEW T · TOGGLE TRACES<br>
1 MODELS 2 EVENT 3 CATEGORIES 4 OVERVIEW
</div>
</div>
</aside>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const labelLayer = document.getElementById("labels");
const reducedMotion = matchMedia("(prefers-reduced-motion: reduce)").matches;
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Voxel genetic linkage laboratory. Drag to orbit, scroll to zoom, and click category bins."
);
stage.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b1623);
scene.fog = new THREE.Fog(0x0b1623, 31, 60);
const camera = new THREE.OrthographicCamera(-15, 15, 10, -10, 0.1, 100);
const cameraState = {
target: new THREE.Vector3(0, 1.4, 0),
desiredTarget: new THREE.Vector3(0, 1.4, 0),
yaw: 0.66,
desiredYaw: 0.66,
pitch: 0.62,
desiredPitch: 0.62,
zoom: 0.92,
desiredZoom: 0.92
};
const hemi = new THREE.HemisphereLight(0xbfe8ff, 0x18202e, 2.15);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(-9, 17, 10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -20;
keyLight.shadow.camera.right = 20;
keyLight.shadow.camera.top = 15;
keyLight.shadow.camera.bottom = -15;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 50;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x54dff5, 28, 24, 2);
cyanLight.position.set(8, 7, 3);
scene.add(cyanLight);
const amberLight = new THREE.PointLight(0xffa33d, 18, 18, 2);
amberLight.position.set(-1, 6, -4);
scene.add(amberLight);
const COLORS = {
wall: 0x15283a,
wallInset: 0x0e1d2c,
floor: 0x172638,
floorLight: 0x1b3044,
floorDark: 0x132235,
bench: 0x9eb3bd,
benchTop: 0xd6e0dd,
benchDark: 0x516a77,
cyan: 0x67e8f9,
teal: 0x4ecdc4,
amber: 0xffb703,
orange: 0xff7a45,
pink: 0xff6b9f,
blue: 0x4cc9f0,
A: 0xffd166,
a: 0x9c7a2a,
B: 0xff6b9f,
b: 0x4cc9f0,
chromosome: 0xdbe8f2,
chromosomeAlt: 0xa8bdcc,
dark: 0x07111d,
ink: 0x172332,
white: 0xf4fbff
};
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0.04,
...options
});
}
const MAT = {
wall: standard(COLORS.wall),
wallInset: standard(COLORS.wallInset),
bench: standard(COLORS.bench),
benchTop: standard(COLORS.benchTop),
benchDark: standard(COLORS.benchDark),
chromosome: standard(COLORS.chromosome),
chromosomeAlt: standard(COLORS.chromosomeAlt),
dark: standard(COLORS.dark),
white: standard(COLORS.white),
teal: standard(COLORS.teal, { emissive: COLORS.teal, emissiveIntensity: 0.05 }),
amber: standard(COLORS.amber, { emissive: COLORS.amber, emissiveIntensity: 0.11 }),
orange: standard(COLORS.orange, { emissive: COLORS.orange, emissiveIntensity: 0.28 }),
A: standard(COLORS.A),
a: standard(COLORS.a),
B: standard(COLORS.B),
b: standard(COLORS.b),
cyan: standard(COLORS.cyan, { emissive: COLORS.cyan, emissiveIntensity: 0.1 })
};
function makeBox(parent, size, position, material, outline = false) {
const resolved = typeof material === "number" ? standard(material) : material;
const mesh = new THREE.Mesh(new THREE.BoxGeometry(...size), resolved);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
if (outline) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({
color: 0x06101a,
transparent: true,
opacity: 0.42
})
);
mesh.add(edges);
}
return mesh;
}
function makeTextSprite(text, {
color = "#eef7ff",
background = "rgba(7,17,29,0.90)",
border = "rgba(103,232,249,0.34)",
width = 512,
height = 128,
scale = [2.2, 0.55, 1],
fontSize = 44,
align = "center"
} = {}) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, width, height);
ctx.strokeStyle = border;
ctx.lineWidth = 5;
ctx.strokeRect(3, 3, width - 6, height - 6);
ctx.fillStyle = color;
ctx.font = `700 ${fontSize}px ui-monospace, SFMono-Regular, Menlo, monospace`;
ctx.textBaseline = "middle";
ctx.textAlign = align;
ctx.fillText(
text,
align === "left" ? 26 : width / 2,
height / 2 + 1,
width - 50
);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
}));
sprite.scale.set(...scale);
return sprite;
}
// Floor and room shell.
makeBox(scene, [31, 0.6, 19], [0, -0.5, 0], standard(COLORS.floorDark), true);
const tileGeometry = new THREE.BoxGeometry(1.02, 0.09, 1.02);
const tileMaterial = standard(0xffffff, { roughness: 0.93 });
const tileCountX = 26;
const tileCountZ = 16;
const tiles = new THREE.InstancedMesh(tileGeometry, tileMaterial, tileCountX * tileCountZ);
tiles.receiveShadow = true;
const dummy = new THREE.Object3D();
const tileColor = new THREE.Color();
for (let row = 0; row < tileCountZ; row++) {
for (let col = 0; col < tileCountX; col++) {
const index = row * tileCountX + col;
dummy.position.set(-14.95 + col * 1.2, -0.14, -8.35 + row * 1.12);
dummy.updateMatrix();
tiles.setMatrixAt(index, dummy.matrix);
const base = (row + col) % 3 === 0 ? COLORS.floorLight : COLORS.floor;
tileColor.setHex(base).offsetHSL(0, 0, ((col * 7 + row * 3) % 5 - 2) * 0.006);
tiles.setColorAt(index, tileColor);
}
}
scene.add(tiles);
makeBox(scene, [31, 7.2, 0.5], [0, 3.25, -9.15], MAT.wall, true);
makeBox(scene, [0.5, 7.2, 18.5], [-15.25, 3.25, -0.15], MAT.wall, true);
for (let x = -12; x <= 12; x += 6) {
makeBox(scene, [5.2, 3.4, 0.08], [x, 3.25, -8.86], MAT.wallInset, true);
makeBox(scene, [0.07, 1.1, 0.12], [x, 5.45, -8.78], MAT.cyan);
}
const wallTitle = makeTextSprite("LINKAGE / MODEL 02", {
color: "#bff6ff",
background: "rgba(8,19,31,0.92)",
border: "rgba(103,232,249,0.30)",
width: 768,
height: 128,
scale: [7.2, 1.2, 1],
fontSize: 43
});
wallTitle.position.set(0, 6.05, -8.72);
scene.add(wallTitle);
function makeBench(cx, cz, width, depth) {
makeBox(scene, [width, 0.34, depth], [cx, 1.1, cz], MAT.benchTop, true);
makeBox(scene, [width - 0.6, 0.48, depth - 0.55], [cx, 0.73, cz], MAT.bench);
const legXs = [cx - width / 2 + 0.7, cx + width / 2 - 0.7];
const legZs = [cz - depth / 2 + 0.7, cz + depth / 2 - 0.7];
for (const x of legXs) {
for (const z of legZs) {
makeBox(scene, [0.24, 1.6, 0.24], [x, 0.2, z], MAT.benchDark);
}
}
for (let i = 0; i < 3; i++) {
makeBox(
scene,
[0.92, 0.33, 0.06],
[cx - width * 0.29 + i * width * 0.29, 0.77, cz + depth / 2 - 0.26],
MAT.benchDark
);
}
}
makeBench(-8.1, -2.25, 9.8, 5.8);
makeBench(0, -3.75, 7.5, 4.9);
// Right-hand tier supports the synthetic category bins.
makeBox(scene, [8.7, 0.72, 7.4], [9.1, 0.37, -0.15], standard(0x23394c), true);
makeBox(scene, [8.9, 0.18, 7.6], [9.1, 0.81, -0.15], standard(0x496275), true);
// A small voxel microscope and vial rack provide laboratory context.
const microscope = new THREE.Group();
microscope.position.set(-13.05, 1.29, -4.15);
scene.add(microscope);
makeBox(microscope, [1.2, 0.18, 0.9], [0, 0, 0], MAT.benchDark, true);
makeBox(microscope, [0.28, 1.6, 0.32], [-0.2, 0.8, 0], MAT.bench, true);
makeBox(microscope, [1.05, 0.28, 0.34], [0.25, 1.5, 0], MAT.bench, true);
makeBox(microscope, [0.32, 0.65, 0.32], [0.55, 1.14, 0], MAT.white, true);
makeBox(microscope, [0.7, 0.16, 0.55], [0.55, 0.72, 0], MAT.benchTop, true);
makeBox(microscope, [0.18, 0.12, 0.18], [0.55, 0.56, 0], MAT.cyan);
const rack = new THREE.Group();
rack.position.set(4.55, 1.29, -4.7);
scene.add(rack);
makeBox(rack, [1.7, 0.16, 0.75], [0, 0, 0], MAT.benchDark, true);
const vialColors = [COLORS.A, COLORS.B, COLORS.teal, COLORS.blue, COLORS.amber];
for (let i = 0; i < 5; i++) {
makeBox(rack, [0.18, 0.48, 0.18], [-0.6 + i * 0.3, 0.31, 0], standard(vialColors[i]));
makeBox(rack, [0.22, 0.11, 0.22], [-0.6 + i * 0.3, 0.60, 0], MAT.white);
}
// Chromosome model helpers.
function makeChromosome(parent, position, {
top = "A",
bottom = "B",
crossover = false,
scale = 1
} = {}) {
const group = new THREE.Group();
group.position.set(...position);
group.scale.setScalar(scale);
parent.add(group);
const blocks = 9;
for (let i = 0; i < blocks; i++) {
const y = -0.92 + i * 0.23;
const bodyMat = i % 2 ? MAT.chromosomeAlt : MAT.chromosome;
makeBox(group, [0.25, 0.21, 0.25], [0, y, 0], bodyMat, true);
}
makeBox(group, [0.31, 0.25, 0.31], [0, 0, 0], MAT.benchDark, true);
makeBox(group, [0.36, 0.34, 0.36], [0, 0.49, 0], MAT[top], true);
makeBox(group, [0.36, 0.34, 0.36], [0, -0.49, 0], MAT[bottom], true);
if (crossover) {
makeBox(group, [0.34, 0.19, 0.34], [0, 0.10, 0], MAT.orange);
}
return group;
}
function makeCellShell(parent) {
const shellMaterial = new THREE.MeshPhongMaterial({
color: COLORS.cyan,
transparent: true,
opacity: 0.075,
depthWrite: false,
side: THREE.DoubleSide
});
const shell = new THREE.Mesh(new THREE.BoxGeometry(3.25, 3.55, 2.5), shellMaterial);
parent.add(shell);
const frame = new THREE.LineSegments(
new THREE.EdgesGeometry(shell.geometry),
new THREE.LineBasicMaterial({
color: COLORS.cyan,
transparent: true,
opacity: 0.48
})
);
parent.add(frame);
// Voxel corner brackets reinforce the cubic, classroom-model aesthetic.
for (const x of [-1.52, 1.52]) {
for (const y of [-1.67, 1.67]) {
for (const z of [-1.15, 1.15]) {
makeBox(parent, [0.18, 0.18, 0.18], [x, y, z], MAT.cyan);
}
}
}
}
const parentCell = new THREE.Group();
parentCell.position.set(-10.25, 3.05, -2.25);
scene.add(parentCell);
makeCellShell(parentCell);
makeBox(parentCell, [2.65, 2.9, 1.95], [0, 0, 0], standard(0x173349, {
transparent: true,
opacity: 0.12,
depthWrite: false
}));
makeChromosome(parentCell, [-0.58, 0.05, 0], { top: "A", bottom: "B" });
makeChromosome(parentCell, [0.58, 0.05, 0], { top: "a", bottom: "b" });
const abSprite = makeTextSprite("AB", {
color: "#fff0ad", border: "rgba(255,209,102,.55)", scale: [0.72, 0.23, 1], fontSize: 52
});
abSprite.position.set(-0.58, 1.15, 0.1);
parentCell.add(abSprite);
const abLowerSprite = makeTextSprite("ab", {
color: "#a9e9ff", border: "rgba(76,201,240,.55)", scale: [0.72, 0.23, 1], fontSize: 52
});
abLowerSprite.position.set(0.58, 1.15, 0.1);
parentCell.add(abLowerSprite);
const productCell = new THREE.Group();
productCell.position.set(-5.85, 3.05, -2.25);
scene.add(productCell);
makeCellShell(productCell);
const products = [
{ genotype: "AB", top: "A", bottom: "B", x: -0.58, z: -0.46, crossover: false },
{ genotype: "ab", top: "a", bottom: "b", x: 0.58, z: -0.46, crossover: false },
{ genotype: "Ab", top: "A", bottom: "b", x: -0.58, z: 0.48, crossover: true },
{ genotype: "aB", top: "a", bottom: "B", x: 0.58, z: 0.48, crossover: true }
];
for (const product of products) {
makeChromosome(productCell, [product.x, 0.04, product.z], {
top: product.top,
bottom: product.bottom,
crossover: product.crossover,
scale: 0.72
});
const label = makeTextSprite(product.genotype, {
color: product.crossover ? "#ffd166" : "#dff8ff",
border: product.crossover ? "rgba(255,183,3,.5)" : "rgba(103,232,249,.35)",
scale: [0.62, 0.20, 1],
fontSize: 49
});
label.position.set(product.x, 1.02, product.z);
productCell.add(label);
}
// Central linkage-map panel.
const linkagePanel = new THREE.Group();
linkagePanel.position.set(0, 3.0, -5.58);
scene.add(linkagePanel);
makeBox(linkagePanel, [7.25, 3.85, 0.36], [0, 0, 0], standard(0x0a1826), true);
makeBox(linkagePanel, [7.48, 0.13, 0.52], [0, 2.0, 0.03], MAT.benchDark, true);
makeBox(linkagePanel, [7.48, 0.13, 0.52], [0, -2.0, 0.03], MAT.benchDark, true);
const panelTitle = makeTextSprite("LINKAGE MAP · A — B", {
color: "#c7f8ff",
background: "rgba(9,25,39,.98)",
border: "rgba(103,232,249,.32)",
width: 640,
height: 96,
scale: [4.4, 0.66, 1],
fontSize: 38
});
panelTitle.position.set(0, 1.52, 0.26);
linkagePanel.add(panelTitle);
// Two homologous rails.
for (let i = 0; i < 15; i++) {
const x = -2.65 + i * 0.38;
makeBox(linkagePanel, [0.33, 0.24, 0.25], [x, 0.58, 0.28], i % 2 ? MAT.chromosomeAlt : MAT.chromosome);
makeBox(linkagePanel, [0.33, 0.24, 0.25], [x, -0.58, 0.28], i % 2 ? MAT.chromosome : MAT.chromosomeAlt);
}
makeBox(linkagePanel, [0.48, 0.48, 0.42], [-1.72, 0.58, 0.35], MAT.A, true);
makeBox(linkagePanel, [0.48, 0.48, 0.42], [1.72, 0.58, 0.35], MAT.B, true);
makeBox(linkagePanel, [0.48, 0.48, 0.42], [-1.72, -0.58, 0.35], MAT.a, true);
makeBox(linkagePanel, [0.48, 0.48, 0.42], [1.72, -0.58, 0.35], MAT.b, true);
const eventPoints = [
[-0.38, 0.30], [-0.22, 0.18], [-0.08, 0.06], [0.08, -0.06],
[0.22, -0.18], [0.38, -0.30],
[0.38, 0.30], [0.22, 0.18], [0.08, 0.06], [-0.08, -0.06],
[-0.22, -0.18], [-0.38, -0.30]
];
for (const [x, y] of eventPoints) {
makeBox(linkagePanel, [0.18, 0.18, 0.22], [x, y, 0.40], MAT.orange, true);
}
const eventCore = makeBox(linkagePanel, [0.27, 0.27, 0.30], [0, 0, 0.47], MAT.orange, true);
const mapNote = makeTextSprite("A — crossover — B", {
color: "#ffbe80",
background: "rgba(44,22,18,.94)",
border: "rgba(255,122,69,.42)",
width: 700,
height: 96,
scale: [4.1, 0.56, 1],
fontSize: 36
});
mapNote.position.set(0, -1.36, 0.28);
linkagePanel.add(mapNote);
// Synthetic category bins.
const bins = {};
const clickables = [];
const organismGroups = [];
function alleleColor(genotype, index) {
const allele = genotype[index];
return MAT[allele];
}
function makeOrganism(parent, x, z, genotype, classColor) {
const group = new THREE.Group();
group.position.set(x, 0.25, z);
parent.add(group);
makeBox(group, [0.46, 0.40, 0.38], [0, 0.32, 0], standard(classColor), true);
makeBox(group, [0.34, 0.31, 0.34], [0, 0.68, 0.015], standard(COLORS.white), true);
makeBox(group, [0.09, 0.09, 0.045], [-0.09, 0.72, 0.19], MAT.dark);
makeBox(group, [0.09, 0.09, 0.045], [0.09, 0.72, 0.19], MAT.dark);
makeBox(group, [0.11, 0.18, 0.13], [-0.13, 0.04, 0], MAT.benchDark);
makeBox(group, [0.11, 0.18, 0.13], [0.13, 0.04, 0], MAT.benchDark);
// Allele chips make the synthetic icon legible without implying a count.
makeBox(group, [0.13, 0.13, 0.07], [-0.11, 0.38, 0.215], alleleColor(genotype, 0));
makeBox(group, [0.13, 0.13, 0.07], [0.11, 0.38, 0.215], alleleColor(genotype, 1));
organismGroups.push(group);
return group;
}
function makeBin(id, genotype, relation, x, z) {
const group = new THREE.Group();
group.position.set(x, 1.02, z);
scene.add(group);
const classColor = relation === "parental" ? COLORS.teal : COLORS.amber;
const classMaterial = standard(classColor, {
emissive: classColor,
emissiveIntensity: relation === "recombinant" ? 0.08 : 0.04
});
const wallMaterial = standard(relation === "parental" ? 0x245b5a : 0x705018);
makeBox(group, [3.25, 0.18, 2.35], [0, 0, 0], standard(0x9ab0b9), true);
makeBox(group, [3.25, 0.56, 0.14], [0, 0.26, -1.10], wallMaterial, true);
makeBox(group, [0.14, 0.56, 2.2], [-1.55, 0.26, 0], wallMaterial, true);
makeBox(group, [0.14, 0.56, 2.2], [1.55, 0.26, 0], wallMaterial, true);
makeBox(group, [3.25, 0.28, 0.14], [0, 0.12, 1.10], classMaterial, true);
const highlightMaterial = new THREE.MeshBasicMaterial({
color: classColor,
transparent: true,
opacity: 0.045,
depthWrite: false
});
const highlight = makeBox(group, [3.55, 0.035, 2.65], [0, -0.11, 0], highlightMaterial);
highlight.castShadow = false;
highlight.receiveShadow = false;
const iconGroup = new THREE.Group();
group.add(iconGroup);
makeOrganism(iconGroup, -0.55, -0.03, genotype, classColor);
makeOrganism(iconGroup, 0.55, -0.03, genotype, classColor);
const plaque = makeTextSprite(`${genotype} · ${relation.toUpperCase()}`, {
color: relation === "recombinant" ? "#ffd166" : "#9ff5e8",
background: "rgba(7,17,29,.96)",
border: relation === "recombinant"
? "rgba(255,183,3,.48)"
: "rgba(78,205,196,.46)",
width: 620,
height: 96,
scale: [2.55, 0.39, 1],
fontSize: 35
});
plaque.position.set(0, 0.17, 1.22);
group.add(plaque);
const syntheticTag = makeTextSprite("SYNTHETIC · COUNT NOT MEASURED", {
color: "#a8bac9",
background: "rgba(7,17,29,.92)",
border: "rgba(174,205,231,.20)",
width: 760,
height: 72,
scale: [2.55, 0.24, 1],
fontSize: 26
});
syntheticTag.position.set(0, -0.06, 1.22);
group.add(syntheticTag);
const hitboxMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
});
const hitbox = makeBox(group, [3.4, 1.4, 2.5], [0, 0.4, 0], hitboxMaterial);
hitbox.castShadow = false;
hitbox.receiveShadow = false;
hitbox.userData.bin = id;
clickables.push(hitbox);
bins[id] = {
id,
genotype,
relation,
group,
iconGroup,
highlight,
highlightMaterial,
endpoint: new THREE.Vector3(x, 2.45, z)
};
}
makeBin("AB", "AB", "parental", 6.95, -1.78);
makeBin("Ab", "Ab", "recombinant", 11.05, -1.78);
makeBin("ab", "ab", "parental", 6.95, 1.32);
makeBin("aB", "aB", "recombinant", 11.05, 1.32);
// Voxel dotted traces connect the central crossover to recombinant bins.
const traces = new THREE.Group();
scene.add(traces);
const animatedTraces = [];
function makeTrace(source, endpoint, color, type) {
const mid1 = source.clone().lerp(endpoint, 0.34);
const mid2 = source.clone().lerp(endpoint, 0.70);
mid1.y += 0.75;
mid2.y += 0.25;
const curve = new THREE.CatmullRomCurve3([source.clone(), mid1, mid2, endpoint.clone()]);
const material = standard(color, {
emissive: color,
emissiveIntensity: type === "recombinant" ? 0.55 : 0.18,
transparent: true,
opacity: type === "recombinant" ? 0.95 : 0.5
});
const points = curve.getPoints(54);
for (let i = 0; i < points.length; i += 3) {
makeBox(traces, [0.11, 0.11, 0.11], points[i].toArray(), material);
}
const pulseMaterial = new THREE.MeshBasicMaterial({ color });
const pulse = makeBox(traces, [0.21, 0.21, 0.21], [0, 0, 0], pulseMaterial);
pulse.castShadow = false;
// Small pixel arrowhead at the receiving category.
const beforeEnd = curve.getPointAt(0.91);
const tangent = curve.getTangentAt(0.91).normalize();
const side = new THREE.Vector3(-tangent.z, 0, tangent.x).normalize();
makeBox(traces, [0.15, 0.15, 0.15], beforeEnd.toArray(), material);
makeBox(
traces,
[0.13, 0.13, 0.13],
beforeEnd.clone().addScaledVector(tangent, 0.22).addScaledVector(side, 0.13).toArray(),
material
);
makeBox(
traces,
[0.13, 0.13, 0.13],
beforeEnd.clone().addScaledVector(tangent, 0.22).addScaledVector(side, -0.13).toArray(),
material
);
animatedTraces.push({ curve, pulse, speed: type === "recombinant" ? 0.22 : 0.15, offset: Math.random() });
}
const eventPoint = new THREE.Vector3(0, 3.0, -5.05);
makeTrace(eventPoint, bins.Ab.endpoint.clone(), COLORS.amber, "recombinant");
makeTrace(eventPoint, bins.aB.endpoint.clone(), COLORS.amber, "recombinant");
const parentSource = new THREE.Vector3(-5.85, 3.25, -1.45);
makeTrace(parentSource, bins.AB.endpoint.clone(), COLORS.teal, "parental");
makeTrace(parentSource, bins.ab.endpoint.clone(), COLORS.teal, "parental");
// DOM labels anchored to 3D positions.
const labels = [];
function addLabel(html, position, options = {}) {
const element = document.createElement("div");
element.className = `world-label ${options.className || ""}`;
element.innerHTML = html;
labelLayer.appendChild(element);
const item = {
element,
position: new THREE.Vector3(...position),
offset: options.offset || [0, 0]
};
labels.push(item);
return item;
}
addLabel("<span>01</span> CHROMOSOME MODELS", [-8.05, 5.25, -2.25], { className: "zone" });
addLabel("HOMOLOGOUS PAIR<span>linked loci A and B</span>", [-10.25, 5.05, -2.25]);
addLabel("MEIOTIC PRODUCTS<span>four illustrative chromatids</span>", [-5.85, 5.05, -2.25]);
addLabel("<span>02</span> LINKAGE EVENT", [0, 5.28, -5.4], { className: "zone" });
addLabel("RECOMBINANT TRACE<span>crossover → Ab / aB</span>", [5.15, 3.85, -2.75], {
className: "event"
});
addLabel("<span>03</span> SYNTHETIC CATEGORY BINS", [9.0, 3.75, -0.2], { className: "zone" });
for (const id of ["AB", "Ab", "ab", "aB"]) {
const bin = bins[id];
const label = addLabel(
`<b>${id}</b>${bin.relation}<span>observed —</span>`,
[bin.group.position.x, 2.72, bin.group.position.z],
{ className: `bin-label ${bin.relation}` }
);
label.element.dataset.bin = id;
label.element.addEventListener("click", () => selectBin(id));
}
// Category selection and lesson copy.
const details = {
AB: {
title: "AB · parental class",
text: "An illustrative parental haplotype. The bin contains synthetic icons only; no observation or count has been supplied."
},
Ab: {
title: "Ab · recombinant class",
text: "A recombinant haplotype formed when linked segments are exchanged between the illustrated loci. Its observed count remains unentered."
},
aB: {
title: "aB · recombinant class",
text: "The reciprocal recombinant class of the illustrated crossover. The trace shows the event connection, not a measured frequency."
},
ab: {
title: "ab · parental class",
text: "The second illustrative parental haplotype. The empty readout deliberately distinguishes a category model from experimental data."
}
};
let selectedBin = null;
function selectBin(id) {
selectedBin = id;
const detail = details[id];
document.getElementById("detailTitle").textContent = detail.title;
document.getElementById("detailText").textContent = detail.text;
document.querySelectorAll("#categoryRows tr").forEach(row => {
row.classList.toggle("active", row.dataset.bin === id);
});
labels.forEach(label => {
if (label.element.classList.contains("bin-label")) {
label.element.classList.toggle("selected", label.element.dataset.bin === id);
}
});
Object.values(bins).forEach(bin => {
bin.highlightMaterial.opacity = bin.id === id ? 0.32 : 0.045;
});
}
document.querySelectorAll("#categoryRows tr").forEach(row => {
row.addEventListener("click", () => selectBin(row.dataset.bin));
});
// Camera presets. Controls are implemented directly, without external helpers.
const views = {
overview: {
target: [0, 1.4, -0.4],
yaw: 0.66,
pitch: 0.62,
zoom: 0.92
},
parent: {
target: [-8.0, 2.2, -2.2],
yaw: 0.52,
pitch: 0.56,
zoom: 1.42
},
event: {
target: [0.15, 3.0, -4.6],
yaw: 0.30,
pitch: 0.46,
zoom: 1.48
},
bins: {
target: [9.0, 1.65, -0.2],
yaw: 0.72,
pitch: 0.60,
zoom: 1.34
}
};
function focusView(name) {
const view = views[name] || views.overview;
cameraState.desiredTarget.set(...view.target);
cameraState.desiredYaw = view.yaw;
cameraState.desiredPitch = view.pitch;
cameraState.desiredZoom = view.zoom;
document.querySelectorAll("[data-view]").forEach(button => {
button.classList.toggle("active", button.dataset.view === name);
});
}
document.querySelectorAll("[data-view]").forEach(button => {
button.addEventListener("click", () => focusView(button.dataset.view));
});
document.getElementById("zoomIn").addEventListener("click", () => {
cameraState.desiredZoom = Math.min(2.2, cameraState.desiredZoom * 1.14);
});
document.getElementById("zoomOut").addEventListener("click", () => {
cameraState.desiredZoom = Math.max(0.62, cameraState.desiredZoom / 1.14);
});
let dragging = false;
let dragDistance = 0;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
dragDistance = 0;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
dragDistance += Math.abs(dx) + Math.abs(dy);
cameraState.desiredYaw -= dx * 0.006;
cameraState.desiredPitch = THREE.MathUtils.clamp(
cameraState.desiredPitch + dy * 0.005,
0.30,
1.16
);
document.querySelectorAll("[data-view]").forEach(button => button.classList.remove("active"));
});
renderer.domElement.addEventListener("pointerup", event => {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (dragDistance < 5) {
const rect = renderer.domElement.getBoundingClientRect();
const pointer = new THREE.Vector2(
((event.clientX - rect.left) / rect.width) * 2 - 1,
-((event.clientY - rect.top) / rect.height) * 2 + 1
);
const raycaster = new THREE.Raycaster();
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(clickables, false);
if (hits.length) selectBin(hits[0].object.userData.bin);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
const factor = event.deltaY > 0 ? 0.92 : 1.08;
cameraState.desiredZoom = THREE.MathUtils.clamp(
cameraState.desiredZoom * factor,
0.62,
2.2
);
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => focusView("overview"));
document.addEventListener("keydown", event => {
const key = event.key.toLowerCase();
if (key === "1") focusView("parent");
if (key === "2") focusView("event");
if (key === "3") focusView("bins");
if (key === "4") focusView("overview");
if (key === "r") focusView("overview");
if (key === "t") {
const toggle = document.getElementById("traceToggle");
toggle.checked = !toggle.checked;
toggle.dispatchEvent(new Event("change"));
}
});
document.getElementById("traceToggle").addEventListener("change", event => {
traces.visible = event.target.checked;
});
document.getElementById("iconsToggle").addEventListener("change", event => {
Object.values(bins).forEach(bin => {
bin.iconGroup.visible = event.target.checked;
});
});
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
const aspect = width / Math.max(height, 1);
const viewHeight = Math.max(19.2, 32.8 / 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, false);
}
new ResizeObserver(resize).observe(stage);
resize();
const projected = new THREE.Vector3();
function updateLabels() {
const width = stage.clientWidth;
const height = stage.clientHeight;
for (const label of labels) {
projected.copy(label.position).project(camera);
const visible = projected.z > -1 && projected.z < 1;
const x = (projected.x * 0.5 + 0.5) * width + label.offset[0];
const y = (-projected.y * 0.5 + 0.5) * height + label.offset[1];
label.element.style.opacity = visible ? "1" : "0";
label.element.style.transform =
`translate(-50%, -50%) translate(${x.toFixed(1)}px, ${y.toFixed(1)}px)`;
}
}
function updateCamera(dt) {
const smoothing = reducedMotion ? 1 : 1 - Math.exp(-dt * 6.5);
cameraState.target.lerp(cameraState.desiredTarget, smoothing);
cameraState.yaw = THREE.MathUtils.lerp(cameraState.yaw, cameraState.desiredYaw, smoothing);
cameraState.pitch = THREE.MathUtils.lerp(cameraState.pitch, cameraState.desiredPitch, smoothing);
cameraState.zoom = THREE.MathUtils.lerp(cameraState.zoom, cameraState.desiredZoom, smoothing);
const distance = 36;
const cosPitch = Math.cos(cameraState.pitch);
camera.position.set(
cameraState.target.x + distance * Math.sin(cameraState.yaw) * cosPitch,
cameraState.target.y + distance * Math.sin(cameraState.pitch),
cameraState.target.z + distance * Math.cos(cameraState.yaw) * cosPitch
);
camera.lookAt(cameraState.target);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
}
selectBin("AB");
focusView("overview");
document.getElementById("loading").remove();
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateCamera(dt);
updateLabels();
if (!reducedMotion) {
const pulse = 1 + Math.sin(elapsed * 3.4) * 0.08;
eventCore.scale.setScalar(pulse);
for (const trace of animatedTraces) {
const t = (elapsed * trace.speed + trace.offset) % 1;
trace.pulse.position.copy(trace.curve.getPointAt(t));
trace.pulse.scale.setScalar(0.8 + Math.sin(t * Math.PI) * 0.45);
}
organismGroups.forEach((group, index) => {
group.position.y = 0.25 + Math.sin(elapsed * 1.7 + index * 0.9) * 0.025;
});
}
renderer.render(scene, camera);
});
</script>
</body>
</html>
```