Prompt specification
Build or customize the Three.js 3D scene "Crossing-over segment exchange display" 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: Crossing-over segment exchange display
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/crossing-over-segment-exchange-display-x0930
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing meiotic recombination. Animate exchange between corresponding nonsister chromatids in a simplified paired-chromosome model; preserve segment order and explicitly identify the schematic crossover location. Stylized solid forms.
Working Three.js Starter (crossing-over-segment-exchange-display-x0930):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Meiotic Recombination — Schematic Crossover</title>
<style>
:root {
color-scheme: dark;
--bg: #07111e;
--panel: rgba(12, 25, 42, 0.88);
--line: rgba(164, 190, 220, 0.19);
--text: #edf5ff;
--muted: #9fb1c8;
--blue: #54adff;
--orange: #ff875f;
--yellow: #ffd166;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
user-select: none;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 45% 43%, transparent 25%, rgba(2, 8, 16, 0.14) 63%, rgba(2, 8, 16, 0.55) 100%);
}
header {
position: fixed;
top: 27px;
left: 31px;
max-width: 530px;
pointer-events: none;
z-index: 5;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: #b7c8dd;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 25px;
height: 2px;
border-radius: 99px;
background: linear-gradient(90deg, var(--blue), var(--orange));
}
h1 {
margin: 0;
font-size: clamp(28px, 3.3vw, 46px);
line-height: 1.03;
letter-spacing: -0.045em;
text-shadow: 0 3px 22px rgba(0, 0, 0, 0.28);
}
header p {
max-width: 480px;
margin: 12px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.panel {
position: fixed;
top: 26px;
right: 26px;
width: 340px;
max-height: calc(100vh - 145px);
overflow: auto;
padding: 20px;
border: 1px solid var(--line);
border-radius: 20px;
background: var(--panel);
box-shadow:
0 20px 60px rgba(0, 0, 0, 0.28),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
backdrop-filter: blur(18px);
z-index: 8;
scrollbar-width: thin;
scrollbar-color: #304660 transparent;
}
.phase-heading {
display: flex;
align-items: flex-start;
gap: 12px;
}
.phase-number {
display: grid;
flex: 0 0 38px;
width: 38px;
height: 38px;
place-items: center;
border: 1px solid rgba(255, 209, 102, 0.38);
border-radius: 12px;
background: rgba(255, 209, 102, 0.09);
color: var(--yellow);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.08em;
}
.phase-heading small {
display: block;
margin: 1px 0 4px;
color: var(--yellow);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.phase-heading h2 {
margin: 0;
font-size: 18px;
line-height: 1.2;
letter-spacing: -0.02em;
}
.phase-copy {
min-height: 76px;
margin: 14px 0 16px;
color: #b8c6d8;
font-size: 13px;
line-height: 1.55;
}
.status {
display: inline-flex;
align-items: center;
gap: 7px;
margin-bottom: 15px;
padding: 6px 10px;
border: 1px solid rgba(84, 173, 255, 0.23);
border-radius: 999px;
background: rgba(84, 173, 255, 0.07);
color: #b9dbff;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.status::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--blue);
box-shadow: 0 0 10px rgba(84, 173, 255, 0.7);
}
.marker-note {
display: flex;
align-items: center;
gap: 10px;
padding: 11px 12px;
border: 1px solid rgba(255, 209, 102, 0.24);
border-radius: 12px;
background: rgba(255, 209, 102, 0.065);
color: #f7dda1;
font-size: 11px;
line-height: 1.4;
}
.marker-x {
display: grid;
flex: 0 0 25px;
width: 25px;
height: 25px;
place-items: center;
border: 1px solid rgba(255, 209, 102, 0.48);
border-radius: 50%;
color: var(--yellow);
font-size: 16px;
font-weight: 900;
}
.section-label {
margin: 18px 0 8px;
color: #8fa3bc;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.order-row {
display: grid;
grid-template-columns: 20px 1fr;
align-items: center;
gap: 8px;
margin-top: 7px;
}
.order-row > span {
color: #aebed1;
font-size: 11px;
font-weight: 750;
}
.loci {
position: relative;
display: grid;
grid-template-columns: repeat(12, 1fr);
gap: 2px;
}
.loci::after {
content: "";
position: absolute;
z-index: 3;
top: -4px;
bottom: -4px;
left: 50%;
width: 2px;
transform: translateX(-1px);
border-radius: 2px;
background: var(--yellow);
box-shadow: 0 0 8px rgba(255, 209, 102, 0.65);
}
.locus {
display: grid;
min-width: 0;
height: 20px;
place-items: center;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 3px;
color: rgba(255, 255, 255, 0.9);
font-size: 7px;
font-weight: 800;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}
.order-caption {
margin: 9px 0 0 28px;
color: #7f93ad;
font-size: 10px;
line-height: 1.4;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 13px;
margin-top: 16px;
padding-top: 14px;
border-top: 1px solid var(--line);
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #aebed0;
font-size: 10px;
}
.swatch {
width: 12px;
height: 12px;
border-radius: 4px;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.swatch.blue {
background: var(--blue);
}
.swatch.orange {
background: var(--orange);
}
.swatch.yellow {
background: var(--yellow);
}
#labels {
position: fixed;
inset: 0;
overflow: hidden;
pointer-events: none;
z-index: 4;
}
.scene-label {
position: absolute;
top: 0;
left: 0;
white-space: nowrap;
padding: 6px 9px;
border: 1px solid rgba(163, 187, 214, 0.24);
border-radius: 8px;
background: rgba(8, 19, 33, 0.83);
box-shadow: 0 7px 22px rgba(0, 0, 0, 0.22);
color: #d6e4f5;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.03em;
opacity: 0;
transition: opacity 160ms ease;
}
.scene-label.homolog {
color: #b8c8da;
}
.scene-label.nonsister {
border-color: rgba(84, 173, 255, 0.4);
color: #b9ddff;
}
.scene-label.crossover {
border-color: rgba(255, 209, 102, 0.55);
background: rgba(38, 30, 12, 0.88);
color: #ffe09a;
box-shadow:
0 7px 24px rgba(0, 0, 0, 0.25),
0 0 18px rgba(255, 209, 102, 0.08);
}
.scene-label.recombinant {
border-color: rgba(155, 224, 255, 0.45);
color: #d7f2ff;
}
.scene-label.order {
border: 0;
background: transparent;
box-shadow: none;
color: #71869f;
font-size: 9px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.controls {
position: fixed;
left: 50%;
bottom: 25px;
display: flex;
align-items: center;
gap: 12px;
width: min(560px, calc(100vw - 40px));
padding: 10px 12px;
transform: translateX(-50%);
border: 1px solid var(--line);
border-radius: 16px;
background: rgba(9, 20, 34, 0.88);
box-shadow: 0 15px 45px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(16px);
z-index: 10;
}
.controls button {
flex: 0 0 auto;
min-width: 78px;
height: 36px;
padding: 0 15px;
border: 1px solid rgba(84, 173, 255, 0.34);
border-radius: 10px;
background: rgba(84, 173, 255, 0.1);
color: #cce8ff;
font: inherit;
font-size: 11px;
font-weight: 800;
cursor: pointer;
}
.controls button:hover {
background: rgba(84, 173, 255, 0.18);
}
.controls button:focus-visible,
input:focus-visible {
outline: 2px solid var(--yellow);
outline-offset: 2px;
}
#timeline {
flex: 1;
width: 100%;
height: 4px;
margin: 0;
border-radius: 99px;
accent-color: var(--yellow);
cursor: pointer;
}
#time {
flex: 0 0 78px;
color: #8ea2bb;
font-size: 10px;
font-variant-numeric: tabular-nums;
text-align: right;
}
.camera-hint {
position: fixed;
left: 31px;
bottom: 29px;
color: #758aa4;
font-size: 10px;
letter-spacing: 0.035em;
pointer-events: none;
z-index: 5;
}
@media (max-width: 900px) {
header {
max-width: 390px;
}
header p {
display: none;
}
.panel {
width: 310px;
}
.camera-hint {
display: none;
}
}
@media (max-width: 700px) {
header {
top: 17px;
left: 17px;
}
h1 {
max-width: 330px;
font-size: 29px;
}
.panel {
top: auto;
right: 12px;
bottom: 88px;
left: 12px;
width: auto;
max-height: 39vh;
padding: 14px;
border-radius: 16px;
}
.phase-copy {
min-height: 0;
margin: 10px 0 12px;
font-size: 12px;
}
.section-label,
.legend {
display: none;
}
.order-caption {
display: none;
}
.marker-note {
padding: 8px 10px;
}
.controls {
bottom: 14px;
width: calc(100vw - 24px);
}
#time {
display: none;
}
.scene-label.homolog,
.scene-label.order {
display: none !important;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Animated three-dimensional model of meiotic recombination"></canvas>
<div class="vignette"></div>
<header>
<div class="eyebrow">Meiosis · Reciprocal Crossover</div>
<h1>Meiotic recombination</h1>
<p>
A simplified four-chromatid model showing a reciprocal exchange between
corresponding nonsister chromatids while preserving left-to-right segment order.
</p>
</header>
<aside class="panel" aria-label="Animation explanation">
<div class="phase-heading">
<div class="phase-number" id="phaseNumber">01</div>
<div>
<small id="phaseTag">Synapsis</small>
<h2 id="phaseTitle">Homologous chromosomes align</h2>
</div>
</div>
<p class="phase-copy" id="phaseCopy" aria-live="polite">
The homologous chromosome pair is organized into four chromatids. Two inner
chromatids are selected for the crossover.
</p>
<div class="status" id="status">Parental arrangement</div>
<div class="marker-note">
<span class="marker-x">×</span>
<span>
<strong>Yellow X:</strong> schematic crossover location between loci 6 and 7.
</span>
</div>
<div class="section-label">Order check · participating chromatids</div>
<div class="order-row">
<span>A</span>
<div class="loci" id="rowA"></div>
</div>
<div class="order-row">
<span>B</span>
<div class="loci" id="rowB"></div>
</div>
<p class="order-caption">
Locus numbers never move or disappear. Only the parental source color of the
distal segments changes after the reciprocal exchange.
</p>
<div class="legend">
<div class="legend-item">
<span class="swatch blue"></span>
Homolog A material
</div>
<div class="legend-item">
<span class="swatch orange"></span>
Homolog B material
</div>
<div class="legend-item">
<span class="swatch yellow"></span>
Crossover marker
</div>
</div>
</aside>
<div id="labels" aria-hidden="true">
<div class="scene-label homolog" id="labelHomologA">Homolog A</div>
<div class="scene-label homolog" id="labelHomologB">Homolog B</div>
<div class="scene-label nonsister" id="labelNonsister">Selected nonsister pair</div>
<div class="scene-label crossover" id="labelCrossover">
Schematic crossover location
</div>
<div class="scene-label recombinant" id="labelRecombinant">
Recombinant chromatids
</div>
<div class="scene-label order" id="labelOrder">Ordered loci 1 → 12</div>
</div>
<div class="controls">
<button id="playButton" type="button">Pause</button>
<input
id="timeline"
type="range"
min="0"
max="1000"
value="0"
step="1"
aria-label="Animation timeline"
>
<span id="time">0.0 / 10.0 s</span>
</div>
<div class="camera-hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
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.background = new THREE.Color(0x07111e);
scene.fog = new THREE.Fog(0x07111e, 14, 27);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 60);
const cameraTarget = new THREE.Vector3(-0.8, 0, 0);
const cameraState = {
azimuth: 0.045,
polar: 1.31,
radius: 14.2
};
const hemi = new THREE.HemisphereLight(0xc6ddff, 0x172033, 2.0);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xffffff, 2.6);
keyLight.position.set(-2.5, 6.5, 8.5);
keyLight.target.position.set(-0.8, 0, 0);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 5;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 22;
keyLight.shadow.bias = -0.0007;
scene.add(keyLight, keyLight.target);
const fillLight = new THREE.DirectionalLight(0x8bbcff, 1.0);
fillLight.position.set(6, 1, 5);
scene.add(fillLight);
const warmFill = new THREE.DirectionalLight(0xffa27d, 0.75);
warmFill.position.set(-6, -2, 4);
scene.add(warmFill);
const modelRoot = new THREE.Group();
modelRoot.position.x = -0.8;
scene.add(modelRoot);
// Solid, softly beveled visual stage.
const backplate = new THREE.Mesh(
new THREE.BoxGeometry(11.8, 4.7, 0.18),
new THREE.MeshStandardMaterial({
color: 0x0c1a2b,
roughness: 0.9,
metalness: 0.02
})
);
backplate.position.set(-0.8, 0, -0.88);
backplate.receiveShadow = true;
scene.add(backplate);
const backplateEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(backplate.geometry),
new THREE.LineBasicMaterial({
color: 0x263c56,
transparent: true,
opacity: 0.65
})
);
backplateEdges.position.copy(backplate.position);
scene.add(backplateEdges);
const SOURCE = {
A: 0x54adff,
B: 0xff875f
};
const lanes = [
{ y: 1.18, z: -0.12, phase: 0.15, source: "A", selected: false },
{ y: 0.52, z: 0.10, phase: 0.55, source: "A", selected: true },
{ y: -0.52, z: 0.10, phase: 1.10, source: "B", selected: true },
{ y: -1.18, z: -0.12, phase: 1.50, source: "B", selected: false }
];
const locusCount = 12;
const spacing = 0.82;
const crossoverX = 0;
const sourceColor = {
A: new THREE.Color(SOURCE.A),
B: new THREE.Color(SOURCE.B)
};
function lanePoint(laneIndex, x, target = new THREE.Vector3()) {
const lane = lanes[laneIndex];
return target.set(
x,
lane.y + 0.052 * Math.sin(x * 0.72 + lane.phase),
lane.z + 0.026 * Math.cos(x * 0.55 + lane.phase)
);
}
// Shared capsule geometries are entirely part of the Three.js core.
const ordinaryGeometry = new THREE.CapsuleGeometry(0.155, 0.46, 6, 14);
const centromereGeometry = new THREE.CapsuleGeometry(0.118, 0.534, 6, 14);
const segmentRecords = [];
for (let laneIndex = 0; laneIndex < lanes.length; laneIndex++) {
const lane = lanes[laneIndex];
for (let locusIndex = 0; locusIndex < locusCount; locusIndex++) {
const x = (locusIndex - (locusCount - 1) / 2) * spacing;
const isCentromere = locusIndex === 2;
const baseColor = sourceColor[lane.source].clone();
baseColor.offsetHSL(0, 0, locusIndex % 2 === 0 ? -0.025 : 0.035);
const material = new THREE.MeshStandardMaterial({
color: baseColor,
roughness: 0.38,
metalness: 0.07,
emissive: 0xffc857,
emissiveIntensity: 0
});
const mesh = new THREE.Mesh(
isCentromere ? centromereGeometry : ordinaryGeometry,
material
);
mesh.rotation.z = Math.PI / 2;
mesh.castShadow = true;
mesh.receiveShadow = true;
const position = lanePoint(laneIndex, x);
mesh.position.copy(position);
const moving =
lane.selected && locusIndex >= locusCount / 2;
const destinationLane = moving
? (laneIndex === 1 ? 2 : 1)
: laneIndex;
modelRoot.add(mesh);
segmentRecords.push({
mesh,
laneIndex,
destinationLane,
locusIndex,
x,
moving,
selected: lane.selected
});
if (isCentromere) {
const centromereBand = new THREE.Mesh(
new THREE.TorusGeometry(0.132, 0.022, 8, 24),
new THREE.MeshStandardMaterial({
color: 0xe4edf8,
roughness: 0.45,
metalness: 0.08
})
);
centromereBand.rotation.y = Math.PI / 2;
centromereBand.position.copy(position);
centromereBand.castShadow = true;
modelRoot.add(centromereBand);
}
}
}
// Subtle rings identify the two participating nonsister chromatids.
const selectionMaterial = new THREE.MeshBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.72
});
for (const laneIndex of [1, 2]) {
const x = (2 - (locusCount - 1) / 2) * spacing;
const p = lanePoint(laneIndex, x);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.185, 0.025, 8, 28),
selectionMaterial
);
ring.rotation.y = Math.PI / 2;
ring.position.copy(p);
modelRoot.add(ring);
}
// A permanent arrow reinforces the left-to-right locus order.
const orderArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(-4.65, -1.72, 0),
9.3,
0x7890ad,
0.28,
0.16
);
modelRoot.add(orderArrow);
// Crossover marker: an X in the gap between loci 6 and 7.
const markerGroup = new THREE.Group();
markerGroup.position.set(crossoverX, 0, 0);
modelRoot.add(markerGroup);
const markerMaterial = new THREE.MeshBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0
});
const haloMaterial = new THREE.MeshBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0,
depthWrite: false
});
function cylinderBetween(a, b, radius, material) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radius,
radius,
length,
12
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
markerGroup.add(
cylinderBetween(
new THREE.Vector3(-0.17, -0.17, 0.44),
new THREE.Vector3( 0.17, 0.17, 0.44),
0.045,
markerMaterial
)
);
markerGroup.add(
cylinderBetween(
new THREE.Vector3(-0.17, 0.17, 0.44),
new THREE.Vector3( 0.17, -0.17, 0.44),
0.045,
markerMaterial
)
);
const markerRing = new THREE.Mesh(
new THREE.TorusGeometry(0.40, 0.032, 10, 40),
markerMaterial
);
markerRing.position.z = 0.43;
markerGroup.add(markerRing);
const markerHalo = new THREE.Mesh(
new THREE.CircleGeometry(0.72, 64),
haloMaterial
);
markerHalo.position.z = 0.35;
markerGroup.add(markerHalo);
const crossoverLight = new THREE.PointLight(0xffc85c, 0, 3.2, 2);
crossoverLight.position.set(crossoverX, 0, 1.0);
modelRoot.add(crossoverLight);
// DOM labels projected from 3D anchors.
const labelElements = {
homologA: document.getElementById("labelHomologA"),
homologB: document.getElementById("labelHomologB"),
nonsister: document.getElementById("labelNonsister"),
crossover: document.getElementById("labelCrossover"),
recombinant: document.getElementById("labelRecombinant"),
order: document.getElementById("labelOrder")
};
const projected = new THREE.Vector3();
function positionLabel(element, localPoint, offsetX, offsetY, opacity = 1) {
projected.copy(localPoint);
modelRoot.localToWorld(projected);
projected.project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.25 &&
Math.abs(projected.y) < 1.25;
if (!visible || opacity <= 0.01) {
element.style.opacity = "0";
return;
}
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.opacity = `${THREE.MathUtils.clamp(opacity, 0, 1)}`;
element.style.transform =
`translate(-50%, -50%) translate(${offsetX}px, ${offsetY}px)`;
}
// Miniature locus diagram.
const rowACells = [];
const rowBCells = [];
function createLocusRow(containerId, output) {
const container = document.getElementById(containerId);
for (let i = 0; i < locusCount; i++) {
const cell = document.createElement("div");
cell.className = "locus";
cell.textContent = String(i + 1);
container.appendChild(cell);
output.push(cell);
}
}
createLocusRow("rowA", rowACells);
createLocusRow("rowB", rowBCells);
// Animation and explanatory phases.
const TOTAL_TIME = 10;
const EXCHANGE_START = 3.15;
const EXCHANGE_END = 7.15;
let timelineTime = 0;
let playing = true;
let lastPhase = -1;
const phaseNumber = document.getElementById("phaseNumber");
const phaseTag = document.getElementById("phaseTag");
const phaseTitle = document.getElementById("phaseTitle");
const phaseCopy = document.getElementById("phaseCopy");
const status = document.getElementById("status");
const playButton = document.getElementById("playButton");
const timeline = document.getElementById("timeline");
const timeReadout = document.getElementById("time");
const phases = [
{
end: 1.8,
tag: "Synapsis",
title: "Homologous chromosomes align",
copy:
"The homologous pair is organized into four chromatids. The two inner chromatids are selected; they come from different homologs and are therefore nonsister chromatids.",
status: "Parental arrangement"
},
{
end: EXCHANGE_START,
tag: "Breakpoint",
title: "The crossover site is marked",
copy:
"The yellow X marks a schematic crossover location between corresponding loci 6 and 7. It identifies the intended break site, not a measured genomic coordinate.",
status: "Crossover site identified"
},
{
end: EXCHANGE_END,
tag: "Reciprocal exchange",
title: "Distal segments are exchanged",
copy:
"Only the segments distal to the breakpoint are exchanged. The colored blocks cross in depth while keeping their original left-to-right order and their reciprocal connection.",
status: "Reciprocal exchange in progress"
},
{
end: Infinity,
tag: "Recombinants",
title: "Recombinant chromatids are formed",
copy:
"Each participating chromatid now joins a proximal arm from one homolog to a distal arm from the other. Locus order is preserved, and the two nonparticipating chromatids remain parental.",
status: "Recombinant chromatids formed"
}
];
function smooth01(value) {
const t = THREE.MathUtils.clamp(value, 0, 1);
return t * t * (3 - 2 * t);
}
function updatePhase(time) {
let index = phases.findIndex(phase => time < phase.end);
if (index < 0) index = phases.length - 1;
if (index !== lastPhase) {
lastPhase = index;
const phase = phases[index];
phaseNumber.textContent = String(index + 1).padStart(2, "0");
phaseTag.textContent = phase.tag;
phaseTitle.textContent = phase.title;
phaseCopy.textContent = phase.copy;
status.textContent = phase.status;
}
}
function updateTimelineButton() {
if (timelineTime >= TOTAL_TIME - 0.001) {
playButton.textContent = "Replay";
} else if (playing) {
playButton.textContent = "Pause";
} else {
playButton.textContent = "Resume";
}
}
playButton.addEventListener("click", () => {
if (timelineTime >= TOTAL_TIME - 0.001) {
timelineTime = 0;
playing = true;
} else {
playing = !playing;
}
updateTimelineButton();
});
timeline.addEventListener("input", () => {
timelineTime = Number(timeline.value) / 1000 * TOTAL_TIME;
playing = false;
updateTimelineButton();
});
window.addEventListener("keydown", event => {
if (event.code === "Space" && event.target.tagName !== "INPUT" && event.target.tagName !== "BUTTON") {
event.preventDefault();
playButton.click();
}
});
const tempStart = new THREE.Vector3();
const tempEnd = new THREE.Vector3();
const mixedColor = new THREE.Color();
function updateModel(time) {
const alignment = smooth01(time / 1.65);
modelRoot.position.y = THREE.MathUtils.lerp(0.16, 0, alignment);
const markerReveal = smooth01((time - 1.35) / 0.85);
const exchange = smooth01(
(time - EXCHANGE_START) / (EXCHANGE_END - EXCHANGE_START)
);
const markerPulse = 1 + Math.sin(time * 5.2) * 0.035;
markerGroup.visible = markerReveal > 0.005;
markerGroup.scale.setScalar(
(0.82 + markerReveal * 0.18) * markerPulse
);
markerMaterial.opacity = markerReveal * 0.96;
haloMaterial.opacity = markerReveal * 0.09;
crossoverLight.intensity = markerReveal * 1.25;
selectionMaterial.opacity = 0.72 - exchange * 0.35;
for (const record of segmentRecords) {
if (!record.moving) {
if (record.selected) {
record.mesh.material.emissiveIntensity =
0.035 + smooth01((time - EXCHANGE_END) / 0.55) * 0.10;
}
continue;
}
lanePoint(record.laneIndex, record.x, tempStart);
lanePoint(record.destinationLane, record.x, tempEnd);
const wave = Math.sin(Math.PI * exchange);
record.mesh.position.x = record.x;
record.mesh.position.y = THREE.MathUtils.lerp(
tempStart.y,
tempEnd.y,
exchange
);
// Opposite depth offsets let the two distal blocks pass without visually
// occupying the same 3D position during the exchange.
const depthDirection = record.laneIndex === 1 ? 1 : -1;
const verticalDirection = record.laneIndex === 1 ? -1 : 1;
record.mesh.position.z =
THREE.MathUtils.lerp(tempStart.z, tempEnd.z, exchange) +
wave * depthDirection * 0.82;
record.mesh.position.y += wave * verticalDirection * 0.13;
record.mesh.rotation.z =
Math.PI / 2 + wave * depthDirection * 0.07;
record.mesh.material.emissiveIntensity =
0.035 + wave * 0.24 +
smooth01((time - EXCHANGE_END) / 0.55) * 0.08;
}
// The miniature order diagram changes parental source color, never order.
for (let i = 0; i < locusCount; i++) {
if (i < locusCount / 2) {
rowACells[i].style.background =
"#" + sourceColor.A.getHexString();
rowBCells[i].style.background =
"#" + sourceColor.B.getHexString();
} else {
mixedColor.lerpColors(
sourceColor.A,
sourceColor.B,
exchange
);
rowACells[i].style.background =
"#" + mixedColor.getHexString();
mixedColor.lerpColors(
sourceColor.B,
sourceColor.A,
exchange
);
rowBCells[i].style.background =
"#" + mixedColor.getHexString();
}
}
updatePhase(time);
timeline.value = String(time / TOTAL_TIME * 1000);
timeReadout.textContent =
`${time.toFixed(1)} / ${TOTAL_TIME.toFixed(1)} s`;
updateTimelineButton();
}
function updateCamera() {
const aspect = camera.aspect;
const fitScale = Math.max(1, 0.95 / aspect);
const radius = cameraState.radius * fitScale;
const sinPolar = Math.sin(cameraState.polar);
camera.position.set(
cameraTarget.x +
radius * sinPolar * Math.sin(cameraState.azimuth),
cameraTarget.y + radius * Math.cos(cameraState.polar),
cameraTarget.z +
radius * sinPolar * Math.cos(cameraState.azimuth)
);
camera.lookAt(cameraTarget);
}
function updateLabels(time) {
const markerReveal = smooth01((time - 1.35) / 0.85);
const finalReveal = smooth01((time - EXCHANGE_END) / 0.65);
positionLabel(
labelElements.homologA,
new THREE.Vector3(-5.15, 1.43, 0.15),
-28,
-18,
0.95
);
positionLabel(
labelElements.homologB,
new THREE.Vector3(-5.15, -1.43, 0.15),
-28,
18,
0.95
);
positionLabel(
labelElements.nonsister,
new THREE.Vector3(-4.15, 0, 0.25),
-75,
0,
smooth01((time - 0.3) / 0.5) * (1 - finalReveal * 0.35)
);
positionLabel(
labelElements.crossover,
new THREE.Vector3(0, 0, 0.58),
28,
-48,
markerReveal
);
positionLabel(
labelElements.recombinant,
new THREE.Vector3(4.65, 0, 0.25),
50,
0,
finalReveal
);
positionLabel(
labelElements.order,
new THREE.Vector3(0, -1.78, 0),
0,
20,
0.85
);
}
// Direct orbit controls, implemented without examples or addons.
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", event => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.azimuth -= dx * 0.005;
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar + dy * 0.005,
0.55,
2.15
);
});
function stopDragging(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
9.5,
20
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
cameraState.azimuth = 0.045;
cameraState.polar = 1.31;
cameraState.radius = 14.2;
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.fov = camera.aspect < 0.8 ? 44 : 38;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) {
timelineTime = Math.min(
TOTAL_TIME,
timelineTime + delta
);
if (timelineTime >= TOTAL_TIME) {
playing = false;
updateTimelineButton();
}
}
updateModel(timelineTime);
updateCamera();
modelRoot.updateWorldMatrix(true, true);
updateLabels(timelineTime);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```