Prompt specification
Build or customize the Three.js 3D scene "Paired inheritance-token organizer" 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: Paired inheritance-token organizer
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/paired-inheritance-token-organizer-x0921
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this low-poly scene: Build two parent trays containing paired symbolic hereditary tokens and one empty offspring tray; distinguish paired copies from unrelated traits using explicit labels.
Working Three.js Starter (paired-inheritance-token-organizer-x0921):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hereditary Token Bench</title>
<style>
:root {
--ink: #172536;
--muted: #667382;
--paper: #f4ecdc;
--cyan: #55cbe3;
--violet: #a98bea;
--orange: #f4a261;
--gold: #f5c85b;
--teal: #3aa99a;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e7dfd0;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
#labels {
position: fixed;
inset: 0;
z-index: 2;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
min-width: 152px;
padding: 9px 11px;
transform: translate(-50%, -100%);
border: 1px solid rgba(255, 255, 255, 0.18);
border-radius: 10px;
background: rgba(22, 34, 49, 0.94);
color: #f8f5ee;
box-shadow:
0 10px 24px rgba(20, 28, 38, 0.18),
0 2px 5px rgba(20, 28, 38, 0.12);
white-space: nowrap;
pointer-events: none;
will-change: left, top;
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 13px;
background: linear-gradient(rgba(255, 255, 255, 0.72), transparent);
}
.world-label.pair {
border-color: rgba(85, 203, 227, 0.75);
}
.world-label.pair.violet {
border-color: rgba(169, 139, 234, 0.8);
}
.world-label.unrelated {
border-color: rgba(244, 162, 97, 0.82);
}
.world-label.unrelated.gold {
border-color: rgba(245, 200, 91, 0.85);
}
.world-label.title-label {
padding: 8px 10px;
background: rgba(247, 241, 228, 0.96);
color: var(--ink);
border-color: rgba(23, 37, 54, 0.15);
}
.world-label.offspring-label {
border-color: rgba(58, 169, 154, 0.85);
}
.world-label.empty-label {
min-width: 190px;
text-align: center;
border-style: dashed;
border-color: rgba(58, 169, 154, 0.9);
background: rgba(28, 55, 60, 0.94);
}
.label-heading {
display: flex;
align-items: center;
gap: 8px;
}
.label-heading strong {
display: block;
font-size: 12px;
line-height: 1.1;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.label-heading small {
display: block;
margin-bottom: 2px;
color: #aeb9c5;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.title-label .label-heading small {
color: #7c8793;
}
.parent-chip {
display: grid;
place-items: center;
width: 27px;
height: 27px;
flex: 0 0 27px;
border-radius: 7px;
background: var(--ink);
color: white;
font-size: 12px;
font-weight: 900;
}
.parent-chip.a {
background: #d8684e;
}
.parent-chip.b {
background: #477ea5;
}
.parent-chip.o {
background: var(--teal);
}
.label-main {
margin-top: 5px;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.055em;
text-transform: uppercase;
}
.label-main b {
margin-left: 4px;
color: var(--cyan);
font-size: 11px;
}
.pair.violet .label-main b {
color: var(--violet);
}
.unrelated .label-main b {
color: var(--orange);
}
.unrelated.gold .label-main b {
color: var(--gold);
}
.label-detail {
margin-top: 3px;
color: #b9c1ca;
font-size: 8px;
font-weight: 700;
letter-spacing: 0.055em;
text-transform: uppercase;
}
.title-label .label-detail {
color: #687582;
}
.symbol {
display: inline-block;
margin-right: 4px;
color: var(--cyan);
font-size: 11px;
letter-spacing: -0.18em;
}
.symbol.violet {
color: var(--violet);
}
.symbol.orange {
color: var(--orange);
}
.symbol.gold {
color: var(--gold);
}
#hud {
position: fixed;
z-index: 4;
top: 24px;
left: 26px;
max-width: 390px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: #596775;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
max-width: 330px;
font-size: clamp(25px, 3vw, 42px);
line-height: 0.98;
letter-spacing: -0.055em;
}
#hud p {
max-width: 340px;
margin: 12px 0 0;
color: #65717c;
font-size: 12px;
line-height: 1.55;
}
.legend {
position: fixed;
z-index: 4;
top: 24px;
right: 24px;
width: 270px;
padding: 15px;
border: 1px solid rgba(23, 37, 54, 0.12);
border-radius: 14px;
background: rgba(248, 243, 232, 0.88);
box-shadow: 0 14px 35px rgba(40, 45, 50, 0.09);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-title {
margin-bottom: 11px;
color: #687480;
font-size: 8px;
font-weight: 900;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 46px 1fr;
align-items: center;
gap: 9px;
margin: 8px 0;
}
.legend-icon {
display: grid;
place-items: center;
height: 31px;
border-radius: 8px;
color: white;
font-size: 14px;
font-weight: 900;
letter-spacing: -0.15em;
}
.legend-icon.pair {
background: #3aabc4;
}
.legend-icon.single {
background: #e89b52;
letter-spacing: 0;
}
.legend-row strong {
display: block;
font-size: 10px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.legend-row small {
display: block;
margin-top: 2px;
color: #74808a;
font-size: 9px;
line-height: 1.35;
}
.legend-note {
margin-top: 11px;
padding-top: 10px;
border-top: 1px solid rgba(23, 37, 54, 0.11);
color: #6e7983;
font-size: 9px;
line-height: 1.4;
}
.help {
position: fixed;
z-index: 4;
left: 26px;
bottom: 23px;
color: rgba(31, 45, 59, 0.65);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
.controls {
position: fixed;
z-index: 5;
right: 24px;
bottom: 22px;
display: flex;
gap: 8px;
}
button {
appearance: none;
border: 1px solid rgba(23, 37, 54, 0.16);
border-radius: 9px;
padding: 9px 12px;
background: rgba(248, 243, 232, 0.92);
color: var(--ink);
box-shadow: 0 7px 18px rgba(40, 45, 50, 0.1);
font: inherit;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
}
button:hover {
background: white;
transform: translateY(-1px);
}
button[aria-pressed="false"] {
opacity: 0.6;
}
@media (max-width: 760px) {
#hud {
top: 14px;
left: 15px;
max-width: calc(100% - 30px);
}
#hud h1 {
max-width: 240px;
font-size: 25px;
}
#hud p {
display: none;
}
.legend {
top: auto;
right: 14px;
bottom: 66px;
width: 225px;
padding: 11px;
}
.legend-note,
.help {
display: none;
}
.controls {
right: 14px;
bottom: 14px;
}
.world-label {
min-width: 126px;
padding: 6px 8px;
border-radius: 8px;
}
.world-label .label-detail {
display: none;
}
.label-heading strong {
font-size: 9px;
}
.label-heading small {
font-size: 7px;
}
.label-main {
font-size: 8px;
}
.world-label.empty-label {
min-width: 155px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly hereditary token scene"></canvas>
<div id="labels" aria-hidden="true"></div>
<header id="hud">
<div class="eyebrow">Genetic inheritance bench · Model 01</div>
<h1>Paired tokens,<br>clearly marked.</h1>
<p>
Two parent trays hold symbolic hereditary tokens. Matching twin markers
are paired copies; standalone markers represent unrelated traits.
The offspring tray begins empty.
</p>
</header>
<aside class="legend" aria-label="Marker legend">
<div class="legend-title">Marker key</div>
<div class="legend-row">
<div class="legend-icon pair">◆◆</div>
<div>
<strong>Paired copies · ×2</strong>
<small>Identical symbol and color, joined by a bridge.</small>
</div>
</div>
<div class="legend-row">
<div class="legend-icon single">●</div>
<div>
<strong>Unrelated trait · ×1</strong>
<small>A separate marker with no twin and no pair bridge.</small>
</div>
</div>
<div class="legend-note">
The dashed teal outline identifies the intentionally empty offspring tray.
</div>
</aside>
<div class="help">Drag to orbit · Wheel to zoom · Shift-drag to pan · R to reset</div>
<div class="controls">
<button id="toggleLabels" type="button" aria-pressed="true">Labels on</button>
<button id="resetView" type="button">Reset view</button>
</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 labelLayer = document.querySelector("#labels");
const toggleLabelsButton = document.querySelector("#toggleLabels");
const resetViewButton = document.querySelector("#resetView");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe7dfd0);
scene.fog = new THREE.Fog(0xe7dfd0, 28, 55);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Custom orbit/pan/zoom camera controls.
const controls = {
target: new THREE.Vector3(0, 0.45, 0.55),
radius: window.innerWidth < 760 ? 27 : 22.5,
theta: window.innerWidth < 760 ? 0.16 : 0.30,
phi: 0.83
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x +
controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y +
controls.radius * Math.cos(controls.phi),
controls.target.z +
controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
camera.updateMatrixWorld();
}
function resetView() {
controls.target.set(0, 0.45, 0.55);
controls.radius = window.innerWidth < 760 ? 27 : 22.5;
controls.theta = window.innerWidth < 760 ? 0.16 : 0.30;
controls.phi = 0.83;
updateCamera();
}
updateCamera();
// Lighting.
scene.add(new THREE.HemisphereLight(0xfff7e8, 0x667587, 2.15));
const keyLight = new THREE.DirectionalLight(0xffefd8, 3.3);
keyLight.position.set(8, 15, 10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -17;
keyLight.shadow.camera.right = 17;
keyLight.shadow.camera.top = 17;
keyLight.shadow.camera.bottom = -17;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 42;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xbddcff, 1.25);
rimLight.position.set(-10, 8, -10);
scene.add(rimLight);
// Materials.
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0.03,
flatShading: true,
...options
});
}
function addMesh(parent, geometry, material, position = [0, 0, 0]) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Low-poly table and floor.
const floor = addMesh(
scene,
new THREE.PlaneGeometry(100, 100),
standard(0xc9bea9),
[0, -0.52, 0]
);
floor.rotation.x = -Math.PI / 2;
floor.castShadow = false;
addMesh(
scene,
new THREE.CylinderGeometry(12.7, 13.25, 0.5, 16),
standard(0xb5a68e),
[0, -0.25, 0]
);
addMesh(
scene,
new THREE.CylinderGeometry(12.65, 12.65, 0.08, 16),
standard(0xd3c3a7),
[0, 0.02, 0]
);
const labels = [];
const tokenAnimations = [];
function addLabel(parent, position, html, className = "") {
const anchor = new THREE.Object3D();
anchor.position.set(...position);
parent.add(anchor);
const element = document.createElement("div");
element.className = `world-label ${className}`;
element.innerHTML = html;
labelLayer.appendChild(element);
labels.push({ anchor, element });
return element;
}
function createTray({
x,
z,
width = 6.2,
depth = 4.05,
accent,
rotation = 0
}) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
const baseMaterial = standard(0x26374a);
const innerMaterial = standard(0xf1e6cf);
const rimMaterial = standard(accent, {
roughness: 0.58,
metalness: 0.08
});
addMesh(
group,
new THREE.BoxGeometry(width, 0.28, depth),
baseMaterial,
[0, 0.20, 0]
);
addMesh(
group,
new THREE.BoxGeometry(width - 0.34, 0.08, depth - 0.34),
innerMaterial,
[0, 0.38, 0]
);
const wallHeight = 0.43;
const wallY = 0.61;
const thickness = 0.17;
addMesh(
group,
new THREE.BoxGeometry(thickness, wallHeight, depth),
rimMaterial,
[-width / 2 + thickness / 2, wallY, 0]
);
addMesh(
group,
new THREE.BoxGeometry(thickness, wallHeight, depth),
rimMaterial,
[width / 2 - thickness / 2, wallY, 0]
);
addMesh(
group,
new THREE.BoxGeometry(width, wallHeight, thickness),
rimMaterial,
[0, wallY, -depth / 2 + thickness / 2]
);
// The front wall is lower so the contents remain visible.
addMesh(
group,
new THREE.BoxGeometry(width, 0.28, thickness),
rimMaterial,
[0, 0.54, depth / 2 - thickness / 2]
);
// Small angular corner caps emphasize the tray construction.
const capGeometry = new THREE.CylinderGeometry(0.15, 0.15, 0.48, 6);
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
addMesh(
group,
capGeometry,
rimMaterial,
[
sx * (width / 2 - 0.12),
0.62,
sz * (depth / 2 - 0.12)
]
);
}
}
return group;
}
function createToken(shape, color) {
let geometry;
let tokenY = 1.0;
if (shape === "diamond") {
geometry = new THREE.OctahedronGeometry(0.52, 0);
geometry.scale(1, 1.08, 1);
tokenY = 1.03;
} else if (shape === "pyramid") {
geometry = new THREE.ConeGeometry(0.56, 1.08, 5);
tokenY = 1.02;
} else if (shape === "crystal") {
geometry = new THREE.IcosahedronGeometry(0.49, 0);
tokenY = 0.98;
} else {
geometry = new THREE.BoxGeometry(0.84, 0.84, 0.84);
tokenY = 0.92;
}
const material = standard(color, {
roughness: 0.48,
metalness: 0.14
});
const token = new THREE.Mesh(geometry, material);
token.castShadow = true;
token.receiveShadow = true;
token.position.y = tokenY;
if (shape === "diamond") token.rotation.y = 0.22;
if (shape === "pyramid") token.rotation.y = Math.PI / 4;
if (shape === "cube") token.rotation.y = 0.24;
return token;
}
// The pair function uses one bridge and two identical copies.
function createPair(parent, x, z, shape, color, phase) {
const group = new THREE.Group();
group.position.set(x, 0, z);
parent.add(group);
addMesh(
group,
new THREE.BoxGeometry(2.18, 0.07, 0.36),
standard(0x42586d),
[0, 0.43, 0]
);
const padGeometry = new THREE.CylinderGeometry(0.47, 0.5, 0.08, 8);
const padMaterial = standard(0xd9cbb3);
for (const offset of [-0.64, 0.64]) {
addMesh(
group,
padGeometry,
padMaterial,
[offset, 0.45, 0]
);
}
const first = createToken(shape, color);
first.position.x = -0.64;
group.add(first);
const second = first.clone();
second.position.x = 0.64;
group.add(second);
tokenAnimations.push({
meshes: [first, second],
baseRotation: first.rotation.y,
phase,
speed: 0.8
});
return group;
}
// The unrelated marker is intentionally solitary and has no pair bridge.
function createUnrelated(parent, x, z, shape, color, phase) {
const group = new THREE.Group();
group.position.set(x, 0, z);
parent.add(group);
addMesh(
group,
new THREE.CylinderGeometry(0.62, 0.65, 0.08, 8),
standard(0xd9cbb3),
[0, 0.45, 0]
);
const ring = addMesh(
group,
new THREE.TorusGeometry(0.72, 0.025, 4, 20),
standard(color, {
roughness: 0.5,
metalness: 0.12,
emissive: color,
emissiveIntensity: 0.06
}),
[0, 0.46, 0]
);
ring.rotation.x = Math.PI / 2;
const token = createToken(shape, color);
group.add(token);
tokenAnimations.push({
meshes: [token],
baseRotation: token.rotation.y,
phase,
speed: 0.65
});
return group;
}
// Parent A.
const parentA = createTray({
x: -4.85,
z: -1.55,
accent: 0xd8684e,
rotation: -0.025
});
createPair(parentA, -1.38, 0.05, "diamond", 0x55cbe3, 0);
createUnrelated(parentA, 1.92, 0.05, "crystal", 0xf4a261, 1.3);
addLabel(
parentA,
[0, 1.62, -1.56],
`
<div class="label-heading">
<span class="parent-chip a">A</span>
<div>
<small>Parent tray</small>
<strong>Parent A</strong>
</div>
</div>
`,
"title-label"
);
addLabel(
parentA,
[-1.38, 1.66, 0.05],
`
<div class="label-heading">
<div>
<small>Hereditary token A</small>
<strong>Paired copies</strong>
</div>
</div>
<div class="label-main"><span class="symbol">◆◆</span>Same trait · ×2</div>
<div class="label-detail">Identical symbol and color</div>
`,
"pair"
);
addLabel(
parentA,
[1.92, 1.43, 0.05],
`
<div class="label-heading">
<div>
<small>Different hereditary trait</small>
<strong>Unrelated trait</strong>
</div>
</div>
<div class="label-main"><span class="symbol orange">●</span>Solo marker · ×1</div>
<div class="label-detail">No matching copy in this tray</div>
`,
"unrelated"
);
// Parent B.
const parentB = createTray({
x: 4.85,
z: -1.55,
accent: 0x477ea5,
rotation: 0.025
});
createPair(parentB, -1.38, 0.05, "pyramid", 0xa98bea, 1.8);
createUnrelated(parentB, 1.92, 0.05, "cube", 0xf5c85b, 0.7);
addLabel(
parentB,
[0, 1.62, -1.56],
`
<div class="label-heading">
<span class="parent-chip b">B</span>
<div>
<small>Parent tray</small>
<strong>Parent B</strong>
</div>
</div>
`,
"title-label"
);
addLabel(
parentB,
[-1.38, 1.66, 0.05],
`
<div class="label-heading">
<div>
<small>Hereditary token B</small>
<strong>Paired copies</strong>
</div>
</div>
<div class="label-main"><span class="symbol violet">▲▲</span>Same trait · ×2</div>
<div class="label-detail">Identical symbol and color</div>
`,
"pair violet"
);
addLabel(
parentB,
[1.92, 1.43, 0.05],
`
<div class="label-heading">
<div>
<small>Different hereditary trait</small>
<strong>Unrelated trait</strong>
</div>
</div>
<div class="label-main"><span class="symbol gold">■</span>Solo marker · ×1</div>
<div class="label-detail">No matching copy in this tray</div>
`,
"unrelated gold"
);
// Empty offspring tray.
const offspring = createTray({
x: 0,
z: 4.15,
width: 6.65,
depth: 4.05,
accent: 0x3aa99a
});
const emptyOutlinePoints = [
new THREE.Vector3(-2.82, 0.435, -1.50),
new THREE.Vector3(2.82, 0.435, -1.50),
new THREE.Vector3(2.82, 0.435, 1.50),
new THREE.Vector3(-2.82, 0.435, 1.50),
new THREE.Vector3(-2.82, 0.435, -1.50)
];
const emptyOutline = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(emptyOutlinePoints),
new THREE.LineDashedMaterial({
color: 0x3aa99a,
dashSize: 0.19,
gapSize: 0.13,
transparent: true,
opacity: 0.8
})
);
emptyOutline.computeLineDistances();
offspring.add(emptyOutline);
addLabel(
offspring,
[0, 1.62, -1.56],
`
<div class="label-heading">
<span class="parent-chip o">O</span>
<div>
<small>Destination tray</small>
<strong>Offspring</strong>
</div>
</div>
`,
"title-label"
);
addLabel(
offspring,
[0, 0.72, 0.42],
`
<div class="label-main">Empty offspring tray</div>
<div class="label-detail">Ready for an inheritance combination</div>
`,
"empty-label offspring-label"
);
// Project the DOM labels from 3D anchors.
const projected = new THREE.Vector3();
function updateLabels() {
for (const item of labels) {
item.anchor.getWorldPosition(projected);
projected.project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.25 &&
projected.x < 1.25 &&
projected.y > -1.25 &&
projected.y < 1.25;
item.element.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
item.element.style.left = `${x}px`;
item.element.style.top = `${y}px`;
}
}
// Pointer controls.
let drag = null;
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0 && event.button !== 2) return;
drag = {
pointerId: event.pointerId,
x: event.clientX,
y: event.clientY,
moved: false,
mode: event.button === 2 || event.shiftKey ? "pan" : "orbit"
};
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!drag || event.pointerId !== drag.pointerId) return;
const dx = event.clientX - drag.x;
const dy = event.clientY - drag.y;
if (Math.abs(dx) + Math.abs(dy) > 2) drag.moved = true;
if (drag.mode === "orbit") {
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi + dy * 0.006,
0.34,
1.35
);
} else {
const forward = camera.getWorldDirection(new THREE.Vector3());
const right = new THREE.Vector3()
.crossVectors(forward, camera.up)
.normalize();
const up = new THREE.Vector3()
.crossVectors(right, forward)
.normalize();
const scale = controls.radius * 0.00145;
controls.target
.addScaledVector(right, -dx * scale)
.addScaledVector(up, dy * scale);
controls.target.x = THREE.MathUtils.clamp(
controls.target.x,
-8,
8
);
controls.target.z = THREE.MathUtils.clamp(
controls.target.z,
-6,
8
);
}
drag.x = event.clientX;
drag.y = event.clientY;
updateCamera();
});
function endDrag(event) {
if (!drag || event.pointerId !== drag.pointerId) return;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
drag = null;
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
13,
34
);
updateCamera();
},
{ passive: false }
);
resetViewButton.addEventListener("click", resetView);
toggleLabelsButton.addEventListener("click", () => {
const visible = labelLayer.style.display !== "none";
labelLayer.style.display = visible ? "none" : "block";
toggleLabelsButton.textContent = visible ? "Labels off" : "Labels on";
toggleLabelsButton.setAttribute("aria-pressed", String(!visible));
});
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetView();
});
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.fov = window.innerWidth < 760 ? 50 : 42;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
for (const animation of tokenAnimations) {
const angle =
animation.baseRotation +
Math.sin(elapsed * animation.speed + animation.phase) * 0.11;
for (const mesh of animation.meshes) {
mesh.rotation.y = angle;
}
}
updateCamera();
scene.updateMatrixWorld(true);
updateLabels();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```