Prompt specification
Build or customize the Three.js 3D scene "Equal-mean different-spread token rows" 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: Equal-mean different-spread token rows
Category: Algorithms & Systems · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/equal-mean-different-spread-token-rows-x1837
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring variance and spread around a mean. Arrange two numerical token sets around marked equal means; display distances from the mean and keep the same horizontal scale for both sets. Low-poly.
Working Three.js Starter (equal-mean-different-spread-token-rows-x1837):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#0b1020" />
<title>Equal Means, Different Spread</title>
<style>
:root {
color-scheme: dark;
--bg: #0b1020;
--panel: rgba(12, 17, 32, 0.78);
--line: rgba(255, 255, 255, 0.12);
--text: #f4f7ff;
--muted: #a7b0c7;
--gold: #ffd166;
--set-a: #a99bff;
--set-b: #ffad66;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene,
#scene canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
}
#scene canvas {
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
#hud {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.intro {
position: absolute;
top: 28px;
left: 30px;
width: min(430px, calc(100vw - 60px));
text-shadow: 0 2px 24px rgba(0, 0, 0, 0.55);
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 9px;
margin-bottom: 12px;
color: var(--gold);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--gold);
box-shadow: 0 0 18px rgba(255, 209, 102, 0.8);
content: "";
}
h1 {
margin: 0;
color: var(--text);
font-size: clamp(35px, 4.2vw, 64px);
font-weight: 760;
letter-spacing: -0.055em;
line-height: 0.98;
}
.intro p {
max-width: 390px;
margin: 16px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.equality {
display: inline-flex;
align-items: center;
gap: 12px;
margin-top: 18px;
padding: 10px 14px;
border: 1px solid rgba(255, 209, 102, 0.3);
border-radius: 999px;
background: rgba(18, 22, 38, 0.76);
color: var(--gold);
font-size: 13px;
font-weight: 750;
backdrop-filter: blur(12px);
}
.equality span {
color: var(--muted);
font-weight: 500;
}
.stats {
position: absolute;
top: 28px;
right: 30px;
display: flex;
gap: 12px;
}
.card {
position: relative;
width: 190px;
padding: 17px 18px 16px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(14px);
}
.card::after {
position: absolute;
right: -20px;
bottom: -35px;
width: 90px;
height: 90px;
border-radius: 50%;
background: var(--accent);
filter: blur(48px);
opacity: 0.18;
content: "";
}
.card-a {
--accent: var(--set-a);
}
.card-b {
--accent: var(--set-b);
}
.card-title {
display: flex;
align-items: center;
justify-content: space-between;
color: var(--accent);
font-size: 11px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.card-title small {
color: var(--muted);
font-size: 9px;
letter-spacing: 0.08em;
}
.variance {
display: flex;
align-items: baseline;
gap: 8px;
margin: 10px 0 7px;
}
.variance strong {
color: var(--text);
font-size: 38px;
font-weight: 760;
letter-spacing: -0.05em;
line-height: 1;
}
.variance span {
color: var(--accent);
font-size: 16px;
font-weight: 800;
}
.card-meta {
display: grid;
gap: 5px;
color: var(--muted);
font-size: 11px;
}
.card-meta b {
color: #e9edf8;
font-weight: 650;
}
.legend {
position: absolute;
bottom: 24px;
left: 50%;
display: flex;
align-items: center;
gap: 18px;
padding: 11px 16px;
transform: translateX(-50%);
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(12, 17, 32, 0.72);
color: var(--muted);
font-size: 11px;
white-space: nowrap;
backdrop-filter: blur(12px);
}
.legend strong {
color: var(--text);
font-weight: 650;
}
.legend .divider {
width: 1px;
height: 16px;
background: var(--line);
}
.controls {
position: absolute;
right: 30px;
bottom: 28px;
color: rgba(196, 205, 225, 0.65);
font-size: 10px;
letter-spacing: 0.06em;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: var(--bg);
color: var(--text);
font-size: 14px;
letter-spacing: 0.08em;
text-align: center;
}
#loading .loader {
width: 38px;
height: 38px;
margin: 0 auto 16px;
border: 2px solid rgba(255, 255, 255, 0.12);
border-top-color: var(--gold);
border-radius: 50%;
animation: spin 0.9s linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
@media (max-width: 860px) {
.intro {
top: 18px;
left: 18px;
}
.intro p {
display: none;
}
.equality {
margin-top: 12px;
}
.stats {
top: auto;
right: 18px;
bottom: 70px;
}
.card {
width: 158px;
padding: 13px;
}
.variance strong {
font-size: 31px;
}
.controls {
display: none;
}
.legend {
bottom: 16px;
gap: 10px;
font-size: 10px;
}
}
@media (max-width: 560px) {
h1 {
font-size: 34px;
}
.stats {
right: 12px;
bottom: 60px;
left: 12px;
gap: 8px;
}
.card {
width: 50%;
}
.card-meta {
font-size: 10px;
}
.legend {
max-width: calc(100vw - 24px);
overflow: hidden;
}
.legend .optional {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="hud">
<section class="intro">
<div class="eyebrow">Statistics in space</div>
<h1>Equal means.<br />Different spread.</h1>
<p>
Two numerical token sets share the same mean and horizontal scale.
Each line and label shows that token’s distance from the gold mean marker.
</p>
<div class="equality">
μ<sub>A</sub> = μ<sub>B</sub> = 3.50
<span>one shared axis</span>
</div>
</section>
<section class="stats" aria-label="Set statistics">
<article class="card card-a">
<div class="card-title">
Set A
<small>8 tokens</small>
</div>
<div class="variance">
<strong id="var-a">0.75</strong>
<span>σ²</span>
</div>
<div class="card-meta">
<div>SD <b id="sd-a">0.87</b></div>
<div>Range <b id="range-a">2–5</b></div>
<div>ΣΔ² <b id="sum-a">6.00</b></div>
</div>
</article>
<article class="card card-b">
<div class="card-title">
Set B
<small>8 tokens</small>
</div>
<div class="variance">
<strong id="var-b">2.25</strong>
<span>σ²</span>
</div>
<div class="card-meta">
<div>SD <b id="sd-b">1.50</b></div>
<div>Range <b id="range-b">1–6</b></div>
<div>ΣΔ² <b id="sum-b">18.00</b></div>
</div>
</article>
</section>
<div class="legend">
<span><strong>Δ = |x − μ|</strong></span>
<span class="divider"></span>
<span>Shared scale: <strong>1–6</strong></span>
<span class="divider optional"></span>
<span class="optional">Variance measures squared spread</span>
</div>
<div class="controls">DRAG TO ORBIT · WHEEL / PINCH TO ZOOM · R TO RESET</div>
</div>
<div id="loading">
<div>
<div class="loader"></div>
BUILDING THE SCENE
</div>
</div>
<script type="module">
const loading = document.getElementById("loading");
let THREE;
try {
THREE = await import(
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js"
);
} catch (error) {
loading.innerHTML =
"<div>Unable to load Three.js.<br />Please check your network connection.</div>";
throw error;
}
const SETS = [
{
id: "A",
values: [2, 3, 3, 3, 4, 4, 4, 5],
color: 0xa99bff,
css: "#a99bff",
z: -1.02
},
{
id: "B",
values: [1, 2, 3, 3, 4, 4, 5, 6],
color: 0xffad66,
css: "#ffad66",
z: 1.02
}
];
const MIN_VALUE = 1;
const MAX_VALUE = 6;
const SCALE = 1.65;
const MEAN = 3.5;
const GOLD = 0xffd166;
const valueToX = value => (value - MEAN) * SCALE;
function statistics(values) {
const mean = values.reduce((sum, value) => sum + value, 0) / values.length;
const sumSquared = values.reduce(
(sum, value) => sum + (value - mean) ** 2,
0
);
const variance = sumSquared / values.length;
return {
mean,
variance,
standardDeviation: Math.sqrt(variance),
sumSquared,
min: Math.min(...values),
max: Math.max(...values)
};
}
SETS.forEach(set => {
const stats = statistics(set.values);
document.getElementById(`var-${set.id.toLowerCase()}`).textContent =
stats.variance.toFixed(2);
document.getElementById(`sd-${set.id.toLowerCase()}`).textContent =
stats.standardDeviation.toFixed(2);
document.getElementById(`range-${set.id.toLowerCase()}`).textContent =
`${stats.min}–${stats.max}`;
document.getElementById(`sum-${set.id.toLowerCase()}`).textContent =
stats.sumSquared.toFixed(2);
});
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b1020);
scene.fog = new THREE.Fog(0x0b1020, 13, 28);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
100
);
let renderer;
try {
renderer = new THREE.WebGLRenderer({ antialias: true });
} catch (error) {
loading.innerHTML =
"<div>This scene requires a browser with WebGL enabled.</div>";
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.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Two low-poly numerical token sets with equal means and different variance"
);
document.getElementById("scene").appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xc9dcff, 0x101629, 1.7);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(-4, 9, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x8ba9ff, 1.25);
rimLight.position.set(5, 4, -7);
scene.add(rimLight);
const goldLight = new THREE.PointLight(GOLD, 18, 9, 2);
goldLight.position.set(0, 3, 0);
scene.add(goldLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0x090d19,
roughness: 0.96,
metalness: 0.02
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.22;
floor.receiveShadow = true;
scene.add(floor);
const board = new THREE.Mesh(
new THREE.BoxGeometry(11.8, 0.18, 6.6),
new THREE.MeshStandardMaterial({
color: 0x121a2d,
roughness: 0.78,
metalness: 0.08
})
);
board.position.set(0, -0.09, 0.35);
board.receiveShadow = true;
scene.add(board);
const boardEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(board.geometry),
new THREE.LineBasicMaterial({
color: 0x35415c,
transparent: true,
opacity: 0.62
})
);
boardEdges.position.copy(board.position);
scene.add(boardEdges);
const geometry = new THREE.BufferGeometry();
const particlePositions = new Float32Array(150 * 3);
for (let i = 0; i < 150; i++) {
particlePositions[i * 3] = (Math.random() - 0.5) * 28;
particlePositions[i * 3 + 1] = Math.random() * 10 - 1;
particlePositions[i * 3 + 2] = (Math.random() - 0.5) * 24 - 3;
}
geometry.setAttribute(
"position",
new THREE.BufferAttribute(particlePositions, 3)
);
const particles = new THREE.Points(
geometry,
new THREE.PointsMaterial({
color: 0x8798bd,
size: 0.025,
transparent: true,
opacity: 0.42,
depthWrite: false
})
);
scene.add(particles);
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function canvasSprite(canvas, worldWidth, worldHeight) {
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(worldWidth, worldHeight, 1);
sprite.renderOrder = 20;
return sprite;
}
function makeBadge(title, subtitle, borderColor, worldWidth = 1.22) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 176;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 8, 8, 496, 160, 28);
ctx.fillStyle = "rgba(10, 15, 29, 0.94)";
ctx.fill();
ctx.lineWidth = 7;
ctx.strokeStyle = borderColor;
ctx.stroke();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#f7f9ff";
ctx.font = "750 56px system-ui, sans-serif";
ctx.fillText(title, 256, subtitle ? 67 : 88);
if (subtitle) {
ctx.fillStyle = borderColor;
ctx.font = "650 34px system-ui, sans-serif";
ctx.fillText(subtitle, 256, 126);
}
return canvasSprite(canvas, worldWidth, worldWidth * 0.344);
}
function makeText(text, color, worldWidth = 1) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.shadowColor = "rgba(0, 0, 0, 0.9)";
ctx.shadowBlur = 12;
ctx.fillStyle = color;
ctx.font = "750 54px system-ui, sans-serif";
ctx.fillText(text, 256, 64);
return canvasSprite(canvas, worldWidth, worldWidth * 0.25);
}
function addLine(points, color, opacity = 1) {
const lineGeometry = new THREE.BufferGeometry().setFromPoints(
points.map(point => new THREE.Vector3(...point))
);
const line = new THREE.Line(
lineGeometry,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
scene.add(line);
return line;
}
// Shared integer grid and horizontal axis.
const axisLength = (MAX_VALUE - MIN_VALUE) * SCALE;
for (let value = MIN_VALUE; value <= MAX_VALUE; value++) {
const x = valueToX(value);
addLine(
[
[x, 0.018, -1.72],
[x, 0.018, 2.28]
],
0x7180a3,
0.18
);
const tick = new THREE.Mesh(
new THREE.BoxGeometry(0.025, 0.035, 0.25),
new THREE.MeshBasicMaterial({ color: 0x8d9ab8 })
);
tick.position.set(x, 0.045, 2.38);
scene.add(tick);
const tickLabel = makeText(String(value), "#aeb9d2", 0.45);
tickLabel.position.set(x, 0.13, 2.66);
scene.add(tickLabel);
}
const sharedAxis = new THREE.Mesh(
new THREE.BoxGeometry(axisLength, 0.035, 0.035),
new THREE.MeshBasicMaterial({ color: 0x7785a5 })
);
sharedAxis.position.set(0, 0.04, 2.38);
scene.add(sharedAxis);
const axisTitle = makeText("SHARED VALUE SCALE · 1–6", "#8f9bb8", 3.1);
axisTitle.position.set(0, 0.12, 2.91);
scene.add(axisTitle);
const markerTops = [];
function addMeanMarker(z, id) {
const marker = new THREE.Group();
marker.position.set(0, 0, z);
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.085, 0.13, 0.76, 6),
new THREE.MeshStandardMaterial({
color: GOLD,
emissive: 0x5c3a00,
emissiveIntensity: 0.42,
roughness: 0.4,
metalness: 0.28,
flatShading: true
})
);
post.position.y = 0.38;
post.castShadow = true;
marker.add(post);
const top = new THREE.Mesh(
new THREE.OctahedronGeometry(0.19),
new THREE.MeshStandardMaterial({
color: 0xffe5a1,
emissive: 0x8a5500,
emissiveIntensity: 0.8,
roughness: 0.28,
metalness: 0.35,
flatShading: true
})
);
top.position.y = 0.87;
top.castShadow = true;
marker.add(top);
markerTops.push(top);
const ring = new THREE.Mesh(
new THREE.RingGeometry(0.25, 0.31, 6),
new THREE.MeshBasicMaterial({
color: GOLD,
side: THREE.DoubleSide,
transparent: true,
opacity: 0.28,
depthWrite: false
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.y = 0.026;
marker.add(ring);
const mu = makeText("μ", "#ffd166", 0.42);
mu.position.set(0, 1.12, 0);
marker.add(mu);
scene.add(marker);
}
addMeanMarker(SETS[0].z, "A");
addMeanMarker(SETS[1].z, "B");
// A central spine visually connects the equal means.
const centralSpine = new THREE.Mesh(
new THREE.CylinderGeometry(0.018, 0.018, 1.35, 6),
new THREE.MeshBasicMaterial({
color: GOLD,
transparent: true,
opacity: 0.62
})
);
centralSpine.position.set(0, 1.58, 0);
scene.add(centralSpine);
const equalityBadge = makeBadge(
"μA = μB",
"MEAN 3.50 · SHARED SCALE",
"#ffd166",
2.65
);
equalityBadge.position.set(0, 2.42, 0);
scene.add(equalityBadge);
function addToken(set, value, stackIndex, distance) {
const x = valueToX(value);
const y = 0.18 + stackIndex * 0.45;
const token = new THREE.Group();
token.position.set(x, y, set.z);
token.rotation.y = (stackIndex % 2) * (Math.PI / 6);
const baseColor = new THREE.Color(set.color);
baseColor.offsetHSL(0, 0, stackIndex * 0.045);
const bodyMaterial = new THREE.MeshStandardMaterial({
color: baseColor,
roughness: 0.58,
metalness: 0.1,
flatShading: true
});
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.235, 0.285, 0.25, 6, 1, false),
bodyMaterial
);
body.castShadow = true;
body.receiveShadow = true;
token.add(body);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(body.geometry),
new THREE.LineBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.2
})
);
body.add(edges);
const topColor = baseColor.clone().offsetHSL(0, -0.04, 0.12);
const cap = new THREE.Mesh(
new THREE.CylinderGeometry(0.19, 0.235, 0.055, 6),
new THREE.MeshStandardMaterial({
color: topColor,
roughness: 0.42,
metalness: 0.15,
flatShading: true
})
);
cap.position.y = 0.145;
cap.castShadow = true;
token.add(cap);
const belt = new THREE.Mesh(
new THREE.TorusGeometry(0.237, 0.022, 4, 6),
new THREE.MeshStandardMaterial({
color: 0x202a43,
roughness: 0.7,
flatShading: true
})
);
belt.rotation.x = Math.PI / 2;
belt.position.y = -0.015;
token.add(belt);
const badge = makeBadge(
`x = ${value}`,
`Δ ${distance.toFixed(2)}`,
set.css,
1.22
);
badge.position.set(0, 0.46, 0);
token.add(badge);
scene.add(token);
// Every deviation is represented by the same horizontal scale.
addLine(
[
[0, 0.055, set.z],
[x, 0.055, set.z],
[x, y - 0.12, set.z]
],
set.color,
0.43
);
}
SETS.forEach(set => {
const stats = statistics(set.values);
const band = new THREE.Mesh(
new THREE.BoxGeometry(axisLength, 0.018, 0.76),
new THREE.MeshStandardMaterial({
color: set.color,
emissive: set.color,
emissiveIntensity: 0.06,
transparent: true,
opacity: 0.08,
roughness: 0.8
})
);
band.position.set(0, 0.008, set.z);
scene.add(band);
const rail = new THREE.Mesh(
new THREE.BoxGeometry(axisLength, 0.025, 0.035),
new THREE.MeshStandardMaterial({
color: set.color,
emissive: set.color,
emissiveIntensity: 0.14,
roughness: 0.55,
metalness: 0.15
})
);
rail.position.set(0, 0.035, set.z);
scene.add(rail);
const label = makeText(`SET ${set.id}`, set.css, 1.15);
label.position.set(-5.05, 0.26, set.z);
scene.add(label);
const stackCounts = new Map();
set.values.forEach(value => {
const stackIndex = stackCounts.get(value) || 0;
stackCounts.set(value, stackIndex + 1);
addToken(
set,
value,
stackIndex,
Math.abs(value - stats.mean)
);
});
});
// Custom camera controls: no addon modules are used.
const target = new THREE.Vector3(0, 0.48, 0.25);
const spherical = new THREE.Spherical();
let interacted = false;
function defaultRadius() {
const aspect = window.innerWidth / window.innerHeight;
if (aspect < 0.65) return 28;
if (aspect < 1) return 20;
if (aspect < 1.3) return 16;
return 13.6;
}
function resetCamera() {
spherical.set(defaultRadius(), 1.03, 0);
interacted = false;
applyCamera();
}
function applyCamera() {
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
}
resetCamera();
const pointers = new Map();
let previousPinchDistance = 0;
function pinchDistance() {
const points = [...pointers.values()];
if (points.length < 2) return 0;
return Math.hypot(
points[0].clientX - points[1].clientX,
points[0].clientY - points[1].clientY
);
}
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
previousPinchDistance = pinchDistance();
}
interacted = true;
});
renderer.domElement.addEventListener("pointermove", event => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size >= 2) {
const distance = pinchDistance();
if (previousPinchDistance > 0 && distance > 0) {
spherical.radius = THREE.MathUtils.clamp(
spherical.radius * (previousPinchDistance / distance),
8.5,
32
);
applyCamera();
}
previousPinchDistance = distance;
return;
}
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
spherical.theta -= dx * 0.005;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi + dy * 0.004,
0.62,
1.34
);
applyCamera();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = pointers.size >= 2 ? pinchDistance() : 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
interacted = true;
spherical.radius = THREE.MathUtils.clamp(
spherical.radius * Math.exp(event.deltaY * 0.001),
8.5,
32
);
applyCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", event => {
const key = event.key.toLowerCase();
let handled = true;
if (key === "arrowleft") spherical.theta -= 0.08;
else if (key === "arrowright") spherical.theta += 0.08;
else if (key === "arrowup") spherical.phi -= 0.05;
else if (key === "arrowdown") spherical.phi += 0.05;
else if (key === "+" || key === "=") spherical.radius -= 0.6;
else if (key === "-") spherical.radius += 0.6;
else if (key === "r") resetCamera();
else handled = false;
if (handled) {
event.preventDefault();
interacted = true;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi,
0.62,
1.34
);
spherical.radius = THREE.MathUtils.clamp(
spherical.radius,
8.5,
32
);
applyCamera();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
if (!interacted) {
resetCamera();
}
});
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const time = clock.getElapsedTime();
markerTops.forEach((top, index) => {
top.rotation.y += 0.008 + index * 0.001;
top.position.y = 0.87 + Math.sin(time * 1.7 + index) * 0.025;
});
particles.rotation.y = time * 0.008;
renderer.render(scene, camera);
});
loading.remove();
</script>
</body>
</html>
```