Prompt specification
Build or customize the Three.js 3D scene "Sequence bead strip with one change" 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: Sequence bead strip with one change
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/sequence-bead-strip-with-one-change-x0933
Scene Description Prompt:
Align two low-poly symbolic DNA strips with one substituted symbol highlighted. Three.js from cdnjs in a single HTML file.
Working Three.js Starter (sequence-bead-strip-with-one-change-x0933):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>DNA Alignment — Substitution Detected</title>
<style>
:root {
--bg: #071018;
--panel: rgba(12, 25, 35, 0.72);
--border: rgba(164, 213, 225, 0.16);
--text: #eef9fb;
--muted: #91aab2;
--cyan: #53d8d0;
--blue: #6599ff;
--coral: #ff665f;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 52% 45%, #153241 0%, #091720 42%, #050b11 100%);
color: var(--text);
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;
background:
linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px);
background-size: 48px 48px;
mask-image: radial-gradient(circle at center, black, transparent 76%);
z-index: 0;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
cursor: grab;
z-index: 1;
}
#scene.dragging {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
box-shadow: inset 0 0 180px rgba(0, 0, 0, 0.56);
}
.ui {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
}
.intro {
position: absolute;
top: 30px;
left: 34px;
width: min(390px, calc(100vw - 68px));
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 13px;
color: var(--cyan);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 25px;
height: 1px;
background: var(--cyan);
box-shadow: 0 0 10px rgba(83, 216, 208, 0.8);
}
h1 {
margin: 0;
max-width: 370px;
font-size: clamp(31px, 3.3vw, 48px);
font-weight: 620;
line-height: 1.02;
letter-spacing: -0.045em;
}
.description {
max-width: 340px;
margin: 15px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.65;
}
.stats {
position: absolute;
top: 30px;
right: 34px;
display: grid;
grid-template-columns: repeat(3, minmax(88px, 1fr));
gap: 8px;
padding: 10px;
border: 1px solid var(--border);
border-radius: 16px;
background: rgba(7, 16, 24, 0.5);
backdrop-filter: blur(14px);
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.18);
}
.stat {
min-width: 94px;
padding: 8px 12px;
border-right: 1px solid rgba(255, 255, 255, 0.07);
}
.stat:last-child {
border-right: 0;
}
.stat strong {
display: block;
font-size: 20px;
font-weight: 650;
letter-spacing: -0.04em;
}
.stat span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.stat.alert strong {
color: var(--coral);
}
.strand-label {
position: absolute;
transform: translate(-100%, -50%);
color: rgba(225, 243, 247, 0.74);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.16em;
line-height: 1.7;
text-align: right;
text-transform: uppercase;
white-space: nowrap;
text-shadow: 0 2px 10px #02070b;
}
.strand-label small {
display: block;
color: rgba(145, 170, 178, 0.72);
font-size: 8px;
letter-spacing: 0.1em;
}
.callout {
position: absolute;
min-width: 154px;
padding: 12px 14px;
transform: translate(-50%, 18px);
border: 1px solid rgba(255, 102, 95, 0.38);
border-radius: 13px;
background:
linear-gradient(135deg, rgba(66, 24, 28, 0.91), rgba(19, 22, 30, 0.9));
box-shadow:
0 18px 45px rgba(0, 0, 0, 0.38),
0 0 35px rgba(255, 85, 75, 0.09);
backdrop-filter: blur(14px);
}
.callout::before {
content: "";
position: absolute;
top: -26px;
left: 50%;
width: 1px;
height: 25px;
background: linear-gradient(to top, var(--coral), transparent);
}
.callout-top {
display: flex;
align-items: center;
gap: 7px;
color: #ffaaa5;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.callout-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--coral);
box-shadow: 0 0 10px var(--coral);
}
.change {
display: flex;
align-items: center;
gap: 10px;
margin-top: 8px;
}
.base-token {
display: grid;
width: 29px;
height: 29px;
place-items: center;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 8px;
color: #fff;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 16px;
font-weight: 800;
}
.base-token.sub {
border-color: rgba(255, 102, 95, 0.68);
background: rgba(255, 102, 95, 0.2);
color: #ffd1cd;
}
.change-arrow {
color: var(--coral);
font-size: 17px;
}
.callout small {
display: block;
margin-top: 8px;
color: rgba(220, 226, 230, 0.6);
font-size: 9px;
letter-spacing: 0.08em;
}
.sequence-card {
position: absolute;
right: 34px;
bottom: 30px;
width: 265px;
padding: 15px 17px;
border: 1px solid var(--border);
border-radius: 15px;
background: var(--panel);
backdrop-filter: blur(16px);
}
.sequence-row {
display: grid;
grid-template-columns: 66px 1fr;
align-items: center;
gap: 12px;
margin-top: 9px;
}
.sequence-row:first-of-type {
margin-top: 12px;
}
.sequence-label {
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.sequence {
color: #dbecef;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 13px;
font-weight: 700;
letter-spacing: 0.16em;
}
.sequence .substitution {
color: #ff8d87;
text-shadow: 0 0 13px rgba(255, 102, 95, 0.8);
}
.legend {
position: absolute;
left: 34px;
bottom: 30px;
display: flex;
gap: 18px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.07em;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.legend-swatch {
width: 8px;
height: 8px;
border-radius: 2px;
background: #5ea8b7;
box-shadow: 0 0 9px rgba(94, 168, 183, 0.5);
}
.legend-swatch.sub {
border-radius: 50%;
background: var(--coral);
box-shadow: 0 0 10px rgba(255, 102, 95, 0.7);
}
.controls {
position: absolute;
left: 50%;
bottom: 30px;
display: flex;
gap: 6px;
padding: 6px;
transform: translateX(-50%);
border: 1px solid var(--border);
border-radius: 13px;
background: rgba(8, 18, 26, 0.72);
backdrop-filter: blur(14px);
pointer-events: auto;
}
.controls button {
display: grid;
width: 32px;
height: 32px;
padding: 0;
place-items: center;
border: 0;
border-radius: 8px;
background: transparent;
color: #dcebed;
font: inherit;
font-size: 17px;
cursor: pointer;
transition: background 160ms ease, color 160ms ease;
}
.controls button:hover {
background: rgba(83, 216, 208, 0.12);
color: var(--cyan);
}
.controls button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
.hint {
position: absolute;
right: 34px;
bottom: 128px;
color: rgba(145, 170, 178, 0.72);
font-size: 9px;
font-weight: 650;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #071018;
color: var(--cyan);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.2em;
text-transform: uppercase;
transition: opacity 500ms ease, visibility 500ms ease;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
@media (max-width: 820px) {
.intro {
top: 20px;
left: 20px;
}
.description {
display: none;
}
.stats {
top: 18px;
right: 18px;
grid-template-columns: 1fr;
gap: 0;
padding: 5px 12px;
}
.stat {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
min-width: 128px;
padding: 4px 0;
border-right: 0;
}
.stat strong {
font-size: 15px;
}
.stat span {
margin-top: 0;
font-size: 8px;
}
.strand-label,
.legend,
.sequence-card {
display: none;
}
.controls {
right: 18px;
bottom: 18px;
left: auto;
transform: none;
}
.hint {
right: auto;
bottom: 31px;
left: 20px;
}
.callout {
min-width: 135px;
padding: 10px 11px;
}
}
@media (max-width: 520px) {
.eyebrow {
font-size: 9px;
}
h1 {
max-width: 230px;
font-size: 28px;
}
.stats {
top: auto;
right: 16px;
bottom: 70px;
}
.hint {
max-width: 170px;
line-height: 1.6;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive 3D DNA sequence alignment"></canvas>
<div class="vignette"></div>
<main class="ui">
<section class="intro">
<div class="eyebrow">Alignment analysis · 08 loci</div>
<h1>One base out of place.</h1>
<p class="description">
Two symbolic DNA strands are aligned position by position.
Seven loci are conserved; a single substituted nucleotide is flagged.
</p>
</section>
<section class="stats" aria-label="Alignment statistics">
<div class="stat">
<strong>7 / 8</strong>
<span>Conserved</span>
</div>
<div class="stat alert">
<strong>01</strong>
<span>Substitution</span>
</div>
<div class="stat">
<strong>87.5%</strong>
<span>Identity</span>
</div>
</section>
<div id="referenceLabel" class="strand-label">
Reference
<small>5′ → 3′</small>
</div>
<div id="sampleLabel" class="strand-label">
Sample
<small>5′ → 3′</small>
</div>
<aside id="substitutionCallout" class="callout">
<div class="callout-top">
<span class="callout-dot"></span>
Substitution
</div>
<div class="change">
<span class="base-token">C</span>
<span class="change-arrow">→</span>
<span class="base-token sub">A</span>
</div>
<small>Position 04 · C replaced by A</small>
</aside>
<section class="sequence-card" aria-label="Aligned sequences">
<div class="sequence-row">
<span class="sequence-label">Reference</span>
<span class="sequence">ATGCATGC</span>
</div>
<div class="sequence-row">
<span class="sequence-label">Sample</span>
<span class="sequence">ATG<span class="substitution">A</span>TCGC</span>
</div>
</section>
<section class="legend" aria-label="Legend">
<div class="legend-item">
<span class="legend-swatch"></span>
Conserved locus
</div>
<div class="legend-item">
<span class="legend-swatch sub"></span>
Substitution
</div>
</section>
<div class="controls" aria-label="Camera controls">
<button id="zoomOut" type="button" aria-label="Zoom out">−</button>
<button id="zoomIn" type="button" aria-label="Zoom in">+</button>
<button id="reset" type="button" aria-label="Reset camera">↺</button>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
</main>
<div id="loading">Initializing alignment</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setClearColor(0x071018, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x071018, 0.018);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, -0.05, 0);
const hemi = new THREE.HemisphereLight(0xb8f3ff, 0x071018, 1.65);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(4, 7, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -6;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x45d6e0, 1.25);
rimLight.position.set(-6, -2, 5);
scene.add(rimLight);
const mismatchLight = new THREE.PointLight(0xff5f57, 1.7, 3.2, 2);
scene.add(mismatchLight);
const shadowPlane = new THREE.Mesh(
new THREE.PlaneGeometry(22, 13),
new THREE.ShadowMaterial({ opacity: 0.18 })
);
shadowPlane.position.z = -0.72;
shadowPlane.receiveShadow = true;
scene.add(shadowPlane);
// Sparse background particles.
const particlePositions = new Float32Array(150 * 3);
for (let i = 0; i < 150; i++) {
particlePositions[i * 3] = (Math.random() - 0.5) * 17;
particlePositions[i * 3 + 1] = (Math.random() - 0.5) * 10;
particlePositions[i * 3 + 2] = (Math.random() - 0.5) * 5 - 0.8;
}
const particleGeometry = new THREE.BufferGeometry();
particleGeometry.setAttribute(
"position",
new THREE.BufferAttribute(particlePositions, 3)
);
const particles = new THREE.Points(
particleGeometry,
new THREE.PointsMaterial({
color: 0x6ca8b6,
size: 0.026,
transparent: true,
opacity: 0.25,
depthWrite: false
})
);
scene.add(particles);
const topSequence = ["A", "T", "G", "C", "A", "T", "G", "C"];
const bottomSequence = ["A", "T", "G", "A", "T", "C", "G", "C"];
const mismatchIndex = 3;
const spacing = 1.15;
const topY = 1.27;
const bottomY = -1.27;
const baseColors = {
A: 0x30d6bf,
T: 0x5f8fff,
G: 0xff7097,
C: 0xa875ff
};
const glyphMaterial = new THREE.MeshStandardMaterial({
color: 0xf4fbfc,
roughness: 0.34,
metalness: 0.16,
emissive: 0xbde9ef,
emissiveIntensity: 0.035,
flatShading: true
});
const mismatchGlyphMaterial = new THREE.MeshStandardMaterial({
color: 0xfff4ee,
roughness: 0.3,
metalness: 0.12,
emissive: 0xff6c60,
emissiveIntensity: 0.15,
flatShading: true
});
const innerMaterial = new THREE.MeshStandardMaterial({
color: 0x091923,
roughness: 0.58,
metalness: 0.32,
flatShading: true
});
const railMaterialTop = new THREE.MeshStandardMaterial({
color: 0x347e8c,
roughness: 0.38,
metalness: 0.55,
emissive: 0x123b46,
emissiveIntensity: 0.3
});
const railMaterialBottom = new THREE.MeshStandardMaterial({
color: 0x405b70,
roughness: 0.4,
metalness: 0.55,
emissive: 0x19283d,
emissiveIntensity: 0.25
});
const rungMaterial = new THREE.MeshStandardMaterial({
color: 0x5aa7b5,
roughness: 0.42,
metalness: 0.4,
emissive: 0x174f5a,
emissiveIntensity: 0.35,
transparent: true,
opacity: 0.52
});
const mismatchRungMaterial = new THREE.MeshStandardMaterial({
color: 0xff665f,
emissive: 0xff3029,
emissiveIntensity: 1.1,
roughness: 0.35,
metalness: 0.2
});
const baseRecords = [];
const mismatchSegments = [];
function createSegment(x1, y1, x2, y2, thickness, material) {
const length = Math.hypot(x2 - x1, y2 - y1);
const angle = Math.atan2(y2 - y1, x2 - x1);
const segment = new THREE.Mesh(
new THREE.BoxGeometry(length, thickness, 0.085),
material
);
segment.position.set((x1 + x2) / 2, (y1 + y2) / 2, 0);
segment.rotation.z = angle;
segment.castShadow = true;
return segment;
}
function createGlyph(letter, material) {
const group = new THREE.Group();
if (letter === "A") {
group.add(
createSegment(-0.28, -0.35, 0, 0.39, 0.075, material),
createSegment(0, 0.39, 0.28, -0.35, 0.075, material),
createSegment(-0.15, -0.08, 0.15, -0.08, 0.065, material)
);
} else if (letter === "T") {
group.add(
createSegment(-0.31, 0.35, 0.31, 0.35, 0.075, material),
createSegment(0, 0.35, 0, -0.37, 0.075, material)
);
} else if (letter === "C") {
group.add(
createSegment(-0.28, 0.18, -0.09, 0.36, 0.075, material),
createSegment(-0.09, 0.36, 0.18, 0.28, 0.075, material),
createSegment(-0.29, -0.18, -0.1, -0.36, 0.075, material),
createSegment(-0.1, -0.36, 0.16, -0.31, 0.075, material),
createSegment(0.18, -0.31, 0.28, -0.18, 0.075, material)
);
} else if (letter === "G") {
group.add(
createSegment(-0.28, 0.18, -0.09, 0.36, 0.075, material),
createSegment(-0.09, 0.36, 0.19, 0.28, 0.075, material),
createSegment(-0.29, -0.18, -0.1, -0.36, 0.075, material),
createSegment(-0.1, -0.36, 0.16, -0.31, 0.075, material),
createSegment(0.16, -0.31, 0.28, -0.18, 0.075, material),
createSegment(0.28, -0.18, 0.28, -0.06, 0.075, material),
createSegment(0.04, -0.06, 0.28, -0.06, 0.075, material)
);
}
return group;
}
function createBase(letter, x, y, isMismatch, index) {
const group = new THREE.Group();
group.position.set(x, y, 0);
const color = isMismatch ? 0xff625b : baseColors[letter];
const outerMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: isMismatch ? 0.28 : 0.1,
roughness: 0.36,
metalness: 0.32,
flatShading: true
});
const outer = new THREE.Mesh(
new THREE.CylinderGeometry(0.43, 0.43, 0.16, 6),
outerMaterial
);
outer.rotation.x = Math.PI / 2;
outer.castShadow = true;
group.add(outer);
const inner = new THREE.Mesh(
new THREE.CylinderGeometry(0.355, 0.355, 0.17, 6),
innerMaterial
);
inner.rotation.x = Math.PI / 2;
inner.position.z = 0.025;
inner.castShadow = true;
group.add(inner);
const edgeMaterial = new THREE.LineBasicMaterial({
color: isMismatch ? 0xffb5b0 : 0xb7ecf2,
transparent: true,
opacity: isMismatch ? 0.34 : 0.13
});
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(outer.geometry, 20),
edgeMaterial
);
edges.rotation.x = Math.PI / 2;
edges.position.z = 0.005;
group.add(edges);
const glyph = createGlyph(
letter,
isMismatch ? mismatchGlyphMaterial : glyphMaterial
);
glyph.position.z = 0.145;
group.add(glyph);
let halo = null;
if (isMismatch) {
halo = new THREE.Mesh(
new THREE.TorusGeometry(0.505, 0.019, 4, 48),
new THREE.MeshBasicMaterial({
color: 0xff6a62,
transparent: true,
opacity: 0.9
})
);
halo.position.z = 0.18;
group.add(halo);
mismatchLight.position.set(x, y, 1.25);
}
scene.add(group);
baseRecords.push({
group,
glyph,
halo,
index,
phase: index * 0.72
});
}
// Horizontal backbone rails.
const railWidth = (topSequence.length - 1) * spacing + 0.8;
const topRail = new THREE.Mesh(
new THREE.BoxGeometry(railWidth, 0.085, 0.10),
railMaterialTop
);
topRail.position.set(0, topY, -0.27);
topRail.castShadow = true;
scene.add(topRail);
const bottomRail = new THREE.Mesh(
new THREE.BoxGeometry(railWidth, 0.085, 0.10),
railMaterialBottom
);
bottomRail.position.set(0, bottomY, -0.27);
bottomRail.castShadow = true;
scene.add(bottomRail);
for (let i = 0; i < topSequence.length; i++) {
const x = (i - (topSequence.length - 1) / 2) * spacing;
const mismatch = i === mismatchIndex;
createBase(topSequence[i], x, topY, false, i);
createBase(bottomSequence[i], x, bottomY, mismatch, i + 0.5);
if (!mismatch) {
const rung = new THREE.Mesh(
new THREE.CylinderGeometry(0.023, 0.023, 1.66, 5),
rungMaterial
);
rung.position.set(x, 0, -0.22);
scene.add(rung);
} else {
for (let segmentIndex = 0; segmentIndex < 7; segmentIndex++) {
const segment = new THREE.Mesh(
new THREE.CylinderGeometry(0.032, 0.032, 0.15, 5),
mismatchRungMaterial
);
segment.position.set(
x,
-0.72 + segmentIndex * 0.24,
-0.22
);
segment.userData.phase = segmentIndex * 0.55;
mismatchSegments.push(segment);
scene.add(segment);
}
const guide = new THREE.Mesh(
new THREE.CylinderGeometry(0.008, 0.008, 2.6, 4),
new THREE.MeshBasicMaterial({
color: 0xff665f,
transparent: true,
opacity: 0.17
})
);
guide.position.set(x, 0, -0.34);
scene.add(guide);
}
}
// Projected HTML labels.
const projectedElements = [
{
element: document.querySelector("#referenceLabel"),
anchor: new THREE.Vector3(-4.85, topY, 0),
visible: true
},
{
element: document.querySelector("#sampleLabel"),
anchor: new THREE.Vector3(-4.85, bottomY, 0),
visible: true
},
{
element: document.querySelector("#substitutionCallout"),
anchor: new THREE.Vector3(
(mismatchIndex - 3.5) * spacing,
bottomY - 0.53,
0.25
),
visible: true
}
];
function updateProjectedElements() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const item of projectedElements) {
const projected = item.anchor.clone().project(camera);
const onScreen =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.2 &&
projected.x < 1.2 &&
projected.y > -1.2 &&
projected.y < 1.2;
item.element.style.display = onScreen ? "" : "none";
item.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
item.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
// Direct camera controls, implemented without Three.js addons.
const currentOrbit = {
theta: 0,
phi: Math.PI / 2 - 0.035,
radius: 9
};
const desiredOrbit = {
theta: 0,
phi: Math.PI / 2 - 0.035,
radius: 9
};
let baseRadius = 9;
let hasInteracted = false;
let dragging = false;
let previousX = 0;
let previousY = 0;
function clampOrbit() {
desiredOrbit.theta = THREE.MathUtils.clamp(
desiredOrbit.theta,
-0.95,
0.95
);
desiredOrbit.phi = THREE.MathUtils.clamp(
desiredOrbit.phi,
0.68,
2.42
);
desiredOrbit.radius = THREE.MathUtils.clamp(
desiredOrbit.radius,
baseRadius * 0.58,
baseRadius * 1.85
);
}
function resetCamera() {
desiredOrbit.theta = 0;
desiredOrbit.phi = Math.PI / 2 - 0.035;
desiredOrbit.radius = baseRadius;
hasInteracted = false;
}
function zoomBy(factor) {
desiredOrbit.radius *= factor;
hasInteracted = true;
clampOrbit();
}
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
hasInteracted = true;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
desiredOrbit.theta -= deltaX * 0.0055;
desiredOrbit.phi += deltaY * 0.0045;
clampOrbit();
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredOrbit.radius *= Math.exp(event.deltaY * 0.001);
hasInteracted = true;
clampOrbit();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
document.querySelector("#zoomIn").addEventListener("click", () => zoomBy(0.88));
document.querySelector("#zoomOut").addEventListener("click", () => zoomBy(1.14));
document.querySelector("#reset").addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "r") {
resetCamera();
} else if (event.key === "+" || event.key === "=") {
zoomBy(0.9);
} else if (event.key === "-") {
zoomBy(1.1);
} else if (event.key === "ArrowLeft") {
desiredOrbit.theta -= 0.07;
hasInteracted = true;
clampOrbit();
} else if (event.key === "ArrowRight") {
desiredOrbit.theta += 0.07;
hasInteracted = true;
clampOrbit();
} else if (event.key === "ArrowUp") {
desiredOrbit.phi -= 0.05;
hasInteracted = true;
clampOrbit();
} else if (event.key === "ArrowDown") {
desiredOrbit.phi += 0.05;
hasInteracted = true;
clampOrbit();
}
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
const halfFovRadians = THREE.MathUtils.degToRad(camera.fov / 2);
const tangent = Math.tan(halfFovRadians);
const verticalExtent = 5.25;
const horizontalExtent = 10.2;
const requiredDistance = Math.max(
verticalExtent / (2 * tangent),
horizontalExtent / (2 * tangent * camera.aspect)
);
baseRadius = requiredDistance * 1.08;
if (!hasInteracted) {
currentOrbit.radius = baseRadius;
desiredOrbit.radius = baseRadius;
}
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
const cameraSpherical = new THREE.Spherical();
function animate() {
const elapsed = clock.getElapsedTime();
currentOrbit.theta +=
(desiredOrbit.theta - currentOrbit.theta) * 0.085;
currentOrbit.phi +=
(desiredOrbit.phi - currentOrbit.phi) * 0.085;
currentOrbit.radius +=
(desiredOrbit.radius - currentOrbit.radius) * 0.085;
cameraSpherical.set(
currentOrbit.radius,
currentOrbit.phi,
currentOrbit.theta
);
camera.position.setFromSpherical(cameraSpherical).add(cameraTarget);
camera.lookAt(cameraTarget);
for (const record of baseRecords) {
record.group.position.z =
Math.sin(elapsed * 0.85 + record.phase) * 0.035;
record.glyph.rotation.z =
Math.sin(elapsed * 0.7 + record.phase) * 0.012;
if (record.halo) {
const pulse = 1 + Math.sin(elapsed * 3.2) * 0.085;
record.halo.scale.setScalar(pulse);
record.halo.rotation.z = elapsed * 0.28;
}
}
for (const segment of mismatchSegments) {
const pulse =
0.82 +
Math.sin(elapsed * 4.2 + segment.userData.phase) * 0.16;
segment.scale.x = pulse;
segment.scale.z = pulse;
}
mismatchLight.intensity = 1.55 + Math.sin(elapsed * 3.2) * 0.55;
particles.rotation.z = elapsed * 0.006;
updateProjectedElements();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```