Prompt specification
Build or customize the Three.js 3D scene "Protist and prey size comparison" 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: Protist and prey size comparison
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/protist-and-prey-size-comparison-x0857
Scene Description Prompt:
Protist and prey size comparison. Create an enlarged generic protist beside smaller microbial prey spheres with a shared schematic scale; keep their roles labeled and avoid assigning real species from simplified shapes. Please build this with Three.js from cdnjs in one self-contained HTML file, using low-poly forms.
Working Three.js Starter (protist-and-prey-size-comparison-x0857):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Protist and Microbial Prey — Schematic Size Comparison</title>
<style>
:root {
--paper: #eaf0eb;
--panel: rgba(249, 251, 247, 0.92);
--ink: #15383d;
--muted: #647b7c;
--line: rgba(28, 73, 75, 0.16);
--teal: #36aa9e;
--teal-dark: #197d76;
--coral: #ef715f;
--gold: #efbd5b;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
#viewport canvas:active {
cursor: grabbing;
}
.intro {
position: fixed;
z-index: 10;
top: 22px;
left: 24px;
width: min(440px, calc(100vw - 190px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--teal-dark);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 23px;
height: 2px;
content: "";
background: var(--teal);
}
h1 {
margin: 0;
max-width: 430px;
font-size: clamp(27px, 3.1vw, 47px);
font-weight: 720;
letter-spacing: -0.045em;
line-height: 0.98;
}
.intro p {
max-width: 390px;
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.not-taxonomic {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 12px;
padding: 6px 9px;
border: 1px solid rgba(25, 125, 118, 0.24);
border-radius: 999px;
background: rgba(54, 170, 158, 0.08);
color: var(--teal-dark);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.not-taxonomic::before {
width: 6px;
height: 6px;
content: "";
border-radius: 50%;
background: var(--teal);
}
.controls {
position: fixed;
z-index: 20;
top: 22px;
right: 24px;
display: flex;
gap: 8px;
}
.control-button {
min-height: 38px;
padding: 0 13px;
border: 1px solid var(--line);
border-radius: 11px;
background: var(--panel);
color: var(--ink);
box-shadow: 0 8px 26px rgba(29, 62, 59, 0.08);
font-size: 12px;
font-weight: 700;
cursor: pointer;
backdrop-filter: blur(12px);
transition:
transform 160ms ease,
border-color 160ms ease,
background 160ms ease;
}
.control-button:hover {
transform: translateY(-1px);
border-color: rgba(25, 125, 118, 0.42);
}
.control-button[aria-pressed="true"] {
border-color: rgba(25, 125, 118, 0.35);
background: rgba(54, 170, 158, 0.13);
color: var(--teal-dark);
}
#labelLayer {
position: fixed;
z-index: 8;
inset: 0;
pointer-events: none;
transition: opacity 180ms ease;
}
#labelLayer.is-hidden {
opacity: 0;
}
.scene-label {
position: absolute;
min-width: 178px;
padding: 10px 12px 11px;
border: 1px solid var(--line);
border-left: 4px solid var(--teal);
border-radius: 11px;
background: rgba(251, 252, 248, 0.94);
box-shadow: 0 12px 35px rgba(22, 60, 58, 0.11);
transform: translate(-50%, -100%);
backdrop-filter: blur(10px);
}
.scene-label.prey {
border-left-color: var(--gold);
}
.label-kicker {
display: block;
margin-bottom: 4px;
color: var(--teal-dark);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.scene-label.prey .label-kicker {
color: #9b6b11;
}
.scene-label strong {
display: block;
font-size: 14px;
letter-spacing: -0.015em;
}
.scene-label small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.tick-label {
position: absolute;
color: rgba(21, 56, 61, 0.72);
font-size: 10px;
font-weight: 750;
transform: translate(-50%, 0);
}
.scale-panel {
position: fixed;
z-index: 15;
right: 24px;
bottom: 20px;
left: 24px;
display: grid;
grid-template-columns: minmax(220px, 1fr) auto;
gap: 18px;
align-items: center;
padding: 15px 18px;
border: 1px solid var(--line);
border-radius: 16px;
background: rgba(249, 251, 247, 0.92);
box-shadow: 0 15px 45px rgba(28, 67, 63, 0.1);
backdrop-filter: blur(16px);
}
.scale-heading {
display: flex;
align-items: center;
gap: 12px;
}
.scale-icon {
position: relative;
width: 46px;
height: 30px;
flex: 0 0 auto;
}
.scale-icon::before {
position: absolute;
top: 14px;
right: 0;
left: 0;
height: 2px;
content: "";
background: var(--ink);
}
.scale-icon::after {
position: absolute;
top: 7px;
left: 12px;
width: 2px;
height: 15px;
content: "";
background: var(--ink);
box-shadow: 10px 0 0 var(--ink), 20px 0 0 var(--ink);
}
.scale-heading h2 {
margin: 0;
font-size: 14px;
letter-spacing: -0.01em;
}
.scale-heading p {
margin: 4px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
.measurements {
display: flex;
align-items: center;
gap: 10px;
}
.measurement {
display: flex;
align-items: center;
gap: 9px;
min-width: 148px;
padding: 9px 11px;
border: 1px solid rgba(21, 56, 61, 0.09);
border-radius: 11px;
background: rgba(255, 255, 255, 0.48);
}
.measurement .swatch {
width: 18px;
height: 18px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--teal);
box-shadow: inset -3px -3px 0 rgba(18, 83, 79, 0.16);
}
.measurement.prey .swatch {
width: 10px;
height: 10px;
margin: 0 4px;
background: var(--gold);
box-shadow: inset -2px -2px 0 rgba(132, 84, 11, 0.16);
}
.measurement b {
display: block;
font-size: 11px;
}
.measurement small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
white-space: nowrap;
}
.ratio {
padding: 8px 10px;
border-radius: 9px;
background: rgba(54, 170, 158, 0.11);
color: var(--teal-dark);
font-size: 11px;
font-weight: 800;
text-align: center;
white-space: nowrap;
}
.disclaimer {
grid-column: 1 / -1;
margin-top: -5px;
padding-top: 10px;
border-top: 1px solid rgba(21, 56, 61, 0.08);
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.disclaimer strong {
color: var(--ink);
}
.camera-hint {
position: fixed;
z-index: 9;
right: 27px;
bottom: 169px;
padding: 7px 10px;
border: 1px solid rgba(21, 56, 61, 0.1);
border-radius: 999px;
background: rgba(249, 251, 247, 0.7);
color: var(--muted);
font-size: 10px;
pointer-events: none;
backdrop-filter: blur(8px);
}
#loading {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
background: var(--paper);
color: var(--teal-dark);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 350ms ease;
pointer-events: none;
}
body.ready #loading {
opacity: 0;
}
@media (max-width: 800px) {
.intro {
top: 17px;
left: 16px;
width: calc(100vw - 155px);
}
h1 {
font-size: clamp(25px, 7vw, 36px);
}
.intro p {
display: none;
}
.not-taxonomic {
margin-top: 9px;
font-size: 8px;
}
.controls {
top: 17px;
right: 15px;
flex-direction: column;
}
.control-button {
min-height: 34px;
padding: 0 10px;
font-size: 10px;
}
.scale-panel {
right: 10px;
bottom: 10px;
left: 10px;
grid-template-columns: 1fr;
gap: 10px;
padding: 12px;
}
.measurements {
justify-content: space-between;
}
.measurement {
min-width: 0;
flex: 1;
padding: 8px;
}
.ratio {
flex: 0 0 auto;
}
.disclaimer {
margin-top: 0;
font-size: 9px;
}
.camera-hint {
display: none;
}
.scene-label {
min-width: 145px;
padding: 8px 9px;
}
.scene-label strong {
font-size: 12px;
}
}
@media (max-width: 520px) {
.measurements {
gap: 6px;
}
.measurement {
gap: 6px;
}
.measurement b {
font-size: 9px;
}
.measurement small {
font-size: 8px;
}
.ratio {
padding: 7px;
font-size: 9px;
}
.scale-heading h2 {
font-size: 12px;
}
.scale-heading p {
font-size: 10px;
}
.scale-icon {
display: none;
}
}
</style>
</head>
<body>
<main id="viewport" aria-label="Interactive schematic comparison of a generic protist and microbial prey"></main>
<header class="intro">
<div class="eyebrow">Microbial ecology · size study</div>
<h1>Protist & microbial prey</h1>
<p>
A generic low-poly comparison using one shared schematic scale.
The simplified forms communicate body size and ecological role, not identity.
</p>
<div class="not-taxonomic">Not a species identification</div>
</header>
<nav class="controls" aria-label="View controls">
<button id="toggleLabels" class="control-button" type="button" aria-pressed="true">
Labels on
</button>
<button id="resetView" class="control-button" type="button">
Reset view
</button>
</nav>
<div id="labelLayer">
<div id="protistLabel" class="scene-label">
<span class="label-kicker">Generic protist</span>
<strong>Consumer role</strong>
<small>Enlarged, faceted body form</small>
</div>
<div id="preyLabel" class="scene-label prey">
<span class="label-kicker">Microbial prey</span>
<strong>Food-resource role</strong>
<small>Generic small spheres</small>
</div>
</div>
<div class="camera-hint">Drag to orbit · scroll or pinch to zoom · arrow keys to rotate</div>
<section class="scale-panel" aria-label="Shared scale and size measurements">
<div class="scale-heading">
<div class="scale-icon" aria-hidden="true"></div>
<div>
<h2>Shared schematic scale</h2>
<p>Arbitrary relative units (s.u.) · the same ruler applies to both groups</p>
</div>
</div>
<div class="measurements">
<div class="measurement">
<span class="swatch" aria-hidden="true"></span>
<div>
<b>Protist body</b>
<small>Ø ≈ 2.5 s.u.</small>
</div>
</div>
<div class="measurement prey">
<span class="swatch" aria-hidden="true"></span>
<div>
<b>Prey sphere</b>
<small>Ø ≈ 0.44 s.u.</small>
</div>
</div>
<div class="ratio">≈ 5.7×<br>visual diameter</div>
</div>
<div class="disclaimer">
<strong>Illustrative only.</strong>
Shapes are deliberately generic and do not describe a named species or establish
real-world dimensions. The enlarged protist and smaller prey spheres share one
arbitrary visual scale for comparison.
</div>
</section>
<div id="loading">Building schematic…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const labelLayer = document.getElementById("labelLayer");
const loading = document.getElementById("loading");
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
} catch (error) {
loading.textContent = "WebGL is unavailable in this browser";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Low-poly generic protist beside smaller generic microbial prey spheres"
);
renderer.domElement.tabIndex = 0;
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeaf0eb);
scene.fog = new THREE.Fog(0xeaf0eb, 12, 24);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
40
);
const target = new THREE.Vector3(0, -0.05, 0);
const orbit = {
theta: 0.08,
phi: 1.27,
radius: window.innerWidth < 700 ? 11.7 : 10.2
};
if (window.innerWidth < 700) {
target.y = -0.28;
}
function updateCamera() {
camera.position.setFromSphericalCoords(
orbit.radius,
orbit.phi,
orbit.theta
);
camera.position.add(target);
camera.lookAt(target);
}
updateCamera();
// Lighting
scene.add(new THREE.HemisphereLight(0xffffff, 0x72928a, 2.1));
const keyLight = new THREE.DirectionalLight(0xffffff, 2.7);
keyLight.position.set(4.5, 7, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const fillLight = new THREE.PointLight(0x79d8cf, 9, 13);
fillLight.position.set(-4, 1.5, 4);
scene.add(fillLight);
const warmLight = new THREE.PointLight(0xffb09d, 5, 11);
warmLight.position.set(4, 1, 3);
scene.add(warmLight);
// Ground and restrained schematic grid
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: 0xe4ebe5,
roughness: 0.98,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.72;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(18, 36, 0x7c9b94, 0xa8bbb4);
grid.position.y = -1.71;
grid.material.transparent = true;
grid.material.opacity = 0.14;
grid.material.depthWrite = false;
scene.add(grid);
function addSoftShadow(x, z, scaleX, scaleZ, opacity) {
const shadow = new THREE.Mesh(
new THREE.CircleGeometry(1, 48),
new THREE.MeshBasicMaterial({
color: 0x153e3b,
transparent: true,
opacity,
depthWrite: false
})
);
shadow.rotation.x = -Math.PI / 2;
shadow.position.set(x, -1.705, z);
shadow.scale.set(scaleX, scaleZ, 1);
scene.add(shadow);
}
addSoftShadow(-2.05, 0.05, 1.42, 0.74, 0.065);
addSoftShadow(2.35, 0.05, 0.95, 0.65, 0.045);
// Generic, irregular low-poly protist
const protist = new THREE.Group();
protist.position.set(-2.05, 0.08, 0);
scene.add(protist);
const bodyGeometry = new THREE.IcosahedronGeometry(1, 1);
const bodyPositions = bodyGeometry.attributes.position;
for (let i = 0; i < bodyPositions.count; i++) {
const x = bodyPositions.getX(i);
const y = bodyPositions.getY(i);
const z = bodyPositions.getZ(i);
const length = Math.hypot(x, y, z) || 1;
const nx = x / length;
const ny = y / length;
const nz = z / length;
const wobble =
1 +
0.065 * Math.sin(nx * 3.6 + ny * 1.7) +
0.035 * Math.cos(nz * 4.5 - nx * 2.1);
bodyPositions.setXYZ(
i,
nx * 1.22 * wobble * 1.04,
ny * 1.22 * wobble * 0.92,
nz * 1.22 * wobble * 0.92
);
}
bodyPositions.needsUpdate = true;
bodyGeometry.computeBoundingSphere();
const bodyMaterial = new THREE.MeshStandardMaterial({
color: 0x39afa5,
roughness: 0.56,
metalness: 0,
flatShading: true,
transparent: true,
opacity: 0.64,
depthWrite: false,
side: THREE.DoubleSide
});
const body = new THREE.Mesh(bodyGeometry, bodyMaterial);
body.castShadow = true;
body.renderOrder = 2;
protist.add(body);
const membraneEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(bodyGeometry, 16),
new THREE.LineBasicMaterial({
color: 0x176e69,
transparent: true,
opacity: 0.36
})
);
membraneEdges.renderOrder = 3;
protist.add(membraneEdges);
// Stylized internal structures: generic and non-diagnostic
const nucleus = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.35, 1),
new THREE.MeshStandardMaterial({
color: 0xee725f,
roughness: 0.66,
flatShading: true
})
);
nucleus.position.set(-0.13, 0.08, 0.34);
nucleus.rotation.set(0.2, 0.3, -0.15);
nucleus.renderOrder = 1;
protist.add(nucleus);
const vacuole = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.23, 1),
new THREE.MeshStandardMaterial({
color: 0x8bd9e5,
roughness: 0.45,
flatShading: true,
transparent: true,
opacity: 0.72,
depthWrite: false
})
);
vacuole.position.set(0.38, -0.18, 0.24);
vacuole.renderOrder = 1;
protist.add(vacuole);
const granuleGeometry = new THREE.IcosahedronGeometry(0.075, 0);
const granuleMaterial = new THREE.MeshStandardMaterial({
color: 0xf1bd57,
roughness: 0.7,
flatShading: true
});
const granulePositions = [
[-0.50, 0.42, 0.42],
[0.48, 0.47, 0.32],
[-0.55, -0.38, 0.38],
[0.20, -0.52, 0.43],
[0.57, -0.02, 0.08]
];
granulePositions.forEach((position, index) => {
const granule = new THREE.Mesh(granuleGeometry, granuleMaterial);
granule.position.set(...position);
granule.rotation.set(index * 0.7, index * 0.4, index * 0.2);
granule.renderOrder = 1;
protist.add(granule);
});
// Short, generic surface projections. Their shape is intentionally non-specific.
const projectionGeometry = new THREE.ConeGeometry(0.046, 0.29, 5);
const projectionMaterial = new THREE.MeshStandardMaterial({
color: 0x258f87,
roughness: 0.62,
flatShading: true
});
const projectionDirections = [
[1.0, 0.25, 0.15],
[-1.0, 0.20, 0.25],
[0.15, 1.0, 0.15],
[0.15, -0.85, 0.38],
[-0.35, -0.50, -0.85],
[0.78, 0.42, -0.42],
[-0.78, 0.70, -0.28],
[0.58, -0.42, -0.72],
[0.02, 0.22, 1.0],
[0.00, -0.20, -1.0]
];
const up = new THREE.Vector3(0, 1, 0);
projectionDirections.forEach((coordinates) => {
const direction = new THREE.Vector3(...coordinates).normalize();
const projection = new THREE.Mesh(
projectionGeometry,
projectionMaterial
);
projection.quaternion.setFromUnitVectors(up, direction);
projection.position.copy(direction).multiplyScalar(1.31);
projection.castShadow = true;
protist.add(projection);
});
// Generic smaller prey spheres on the same visual scale
const preyGroup = new THREE.Group();
preyGroup.position.set(2.35, 0.04, 0);
scene.add(preyGroup);
const preyGeometry = new THREE.IcosahedronGeometry(0.22, 1);
const preyMaterial = new THREE.MeshStandardMaterial({
color: 0xefbd5b,
roughness: 0.62,
metalness: 0,
flatShading: true
});
const preyPositions = [
[-0.05, 0.72, 0.10],
[0.58, 0.48, 0.28],
[-0.62, 0.30, 0.06],
[0.10, 0.02, 0.43],
[0.72, -0.18, 0.05],
[-0.18, -0.52, 0.22],
[0.25, -0.92, 0.02]
];
preyPositions.forEach((position, index) => {
const prey = new THREE.Mesh(preyGeometry, preyMaterial);
prey.position.set(...position);
prey.rotation.set(index * 0.45, index * 0.72, index * 0.18);
prey.castShadow = true;
preyGroup.add(prey);
});
// Shared 0–8 schematic-unit ruler
const ruler = new THREE.Group();
scene.add(ruler);
const rulerMaterial = new THREE.LineBasicMaterial({
color: 0x43686a,
transparent: true,
opacity: 0.64
});
const rulerStart = -4.2;
const rulerEnd = 4.2;
const rulerY = -1.43;
const rulerZ = 0.43;
const unitLength = 1.05;
const rulerLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(rulerStart, rulerY, rulerZ),
new THREE.Vector3(rulerEnd, rulerY, rulerZ)
]),
rulerMaterial
);
ruler.add(rulerLine);
for (let i = 0; i <= 8; i++) {
const x = rulerStart + i * unitLength;
const tickHeight = i % 2 === 0 ? 0.18 : 0.095;
const tick = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(x, rulerY, rulerZ),
new THREE.Vector3(x, rulerY + tickHeight, rulerZ)
]),
rulerMaterial
);
ruler.add(tick);
}
// Projected HTML labels
const labelAnchors = [
{
element: document.getElementById("protistLabel"),
position: new THREE.Vector3(-2.05, 1.73, 0)
},
{
element: document.getElementById("preyLabel"),
position: new THREE.Vector3(2.35, 1.30, 0)
}
];
const tickAnchors = [];
[0, 2, 4, 6, 8].forEach((value) => {
const element = document.createElement("span");
element.className = "tick-label";
element.textContent = String(value);
labelLayer.appendChild(element);
tickAnchors.push({
element,
position: new THREE.Vector3(
rulerStart + value * unitLength,
rulerY - 0.11,
rulerZ
)
});
});
// Dashed leaders connect the labels to their subjects.
const annotationLines = [];
function addLeader(start, end, color) {
const geometry = new THREE.BufferGeometry().setFromPoints([
start,
end
]);
const material = new THREE.LineDashedMaterial({
color,
dashSize: 0.07,
gapSize: 0.055,
transparent: true,
opacity: 0.58
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
scene.add(line);
annotationLines.push(line);
}
addLeader(
new THREE.Vector3(-2.05, 1.18, 0),
new THREE.Vector3(-2.05, 1.66, 0),
0x238b83
);
addLeader(
new THREE.Vector3(2.35, 0.98, 0),
new THREE.Vector3(2.35, 1.23, 0),
0xb17b1c
);
// Custom orbit controls, implemented without Three.js addons.
const pointers = new Map();
let previousSinglePointer = null;
let previousPinchDistance = 0;
let userHasMovedCamera = false;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
previousSinglePointer = {
x: event.clientX,
y: event.clientY
};
} else if (pointers.size === 2) {
previousPinchDistance = pointerDistance();
}
userHasMovedCamera = true;
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1 && previousSinglePointer) {
const deltaX = event.clientX - previousSinglePointer.x;
const deltaY = event.clientY - previousSinglePointer.y;
orbit.theta -= deltaX * 0.0055;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - deltaY * 0.0045,
0.38,
2.75
);
previousSinglePointer = {
x: event.clientX,
y: event.clientY
};
} else if (pointers.size === 2) {
const newDistance = pointerDistance();
if (newDistance > 0 && previousPinchDistance > 0) {
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * (previousPinchDistance / newDistance),
6.2,
15
);
}
previousPinchDistance = newDistance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 1) {
const remaining = [...pointers.values()][0];
previousSinglePointer = { ...remaining };
} else {
previousSinglePointer = null;
previousPinchDistance = 0;
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("lostpointercapture", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
6.2,
15
);
userHasMovedCamera = true;
},
{ passive: false }
);
function resetView() {
orbit.theta = 0.08;
orbit.phi = 1.27;
orbit.radius = window.innerWidth < 700 ? 11.7 : 10.2;
target.set(0, window.innerWidth < 700 ? -0.28 : -0.05, 0);
userHasMovedCamera = false;
}
document.getElementById("resetView").addEventListener("click", resetView);
let labelsVisible = true;
const toggleLabels = document.getElementById("toggleLabels");
toggleLabels.addEventListener("click", () => {
labelsVisible = !labelsVisible;
labelLayer.classList.toggle("is-hidden", !labelsVisible);
annotationLines.forEach((line) => {
line.visible = labelsVisible;
});
toggleLabels.setAttribute("aria-pressed", String(labelsVisible));
toggleLabels.textContent = labelsVisible ? "Labels on" : "Labels off";
});
document.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
let handled = true;
switch (event.key) {
case "ArrowLeft":
orbit.theta += 0.08;
break;
case "ArrowRight":
orbit.theta -= 0.08;
break;
case "ArrowUp":
orbit.phi = THREE.MathUtils.clamp(orbit.phi - 0.06, 0.38, 2.75);
break;
case "ArrowDown":
orbit.phi = THREE.MathUtils.clamp(orbit.phi + 0.06, 0.38, 2.75);
break;
case "+":
case "=":
orbit.radius = Math.max(6.2, orbit.radius - 0.35);
break;
case "-":
case "_":
orbit.radius = Math.min(15, orbit.radius + 0.35);
break;
case "r":
case "R":
resetView();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
userHasMovedCamera = true;
}
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height, false);
if (!userHasMovedCamera) {
orbit.radius = width < 700 ? 11.7 : 10.2;
target.y = width < 700 ? -0.28 : -0.05;
}
}
window.addEventListener("resize", resize);
const projected = new THREE.Vector3();
function positionLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
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.visibility =
projected.z > -1 && projected.z < 1 ? "visible" : "hidden";
}
function render() {
updateCamera();
labelAnchors.forEach(({ element, position }) => {
positionLabel(element, position);
});
tickAnchors.forEach(({ element, position }) => {
positionLabel(element, position);
});
renderer.render(scene, camera);
requestAnimationFrame(render);
}
render();
document.body.classList.add("ready");
setTimeout(() => loading.remove(), 450);
</script>
</body>
</html>
```