Prompt specification
Build or customize the Three.js 3D scene "Staggered Start Calculation Display" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Staggered Start Calculation Display
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/staggered-start-calculation-display-x3670
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: staggered start calculation display. Create a simplified oval track and place start marks for equal total distances. Compute offsets from the chosen geometry and state which lane path is measured. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (staggered-start-calculation-display-x3670):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Staggered Start Calculator</title>
<style>
:root {
color-scheme: dark;
--bg: #07131b;
--panel: rgba(9, 22, 31, 0.88);
--line: rgba(151, 196, 218, 0.18);
--text: #edf8ff;
--muted: #9bb5c4;
--accent: #62e6ff;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.card {
position: fixed;
z-index: 4;
background: var(--panel);
border: 1px solid var(--line);
border-radius: 16px;
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
backdrop-filter: blur(14px);
}
.intro {
top: 18px;
left: 18px;
width: min(390px, calc(100vw - 36px));
padding: 18px 20px;
pointer-events: none;
}
.eyebrow {
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 8px;
font-size: clamp(22px, 3vw, 31px);
line-height: 1.06;
letter-spacing: -0.035em;
}
.intro p {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.chips {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 14px;
}
.chip {
padding: 5px 8px;
border: 1px solid var(--line);
border-radius: 999px;
color: #cfe8f4;
background: rgba(98, 230, 255, 0.06);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.03em;
}
.calc {
top: 18px;
right: 18px;
width: min(445px, calc(100vw - 36px));
max-height: calc(100vh - 36px);
overflow: auto;
padding: 17px;
}
.calc-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
}
h2 {
margin: 0;
font-size: 17px;
letter-spacing: -0.02em;
}
.target {
flex: 0 0 auto;
padding: 6px 9px;
border: 1px solid rgba(98, 230, 255, 0.25);
border-radius: 9px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
}
.path-note {
margin: 0 0 12px;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.path-note strong { color: #e5f8ff; }
table {
width: 100%;
border-collapse: collapse;
font-variant-numeric: tabular-nums;
font-size: 10.5px;
}
th {
padding: 7px 5px;
border-bottom: 1px solid var(--line);
color: #7fa0b2;
text-align: right;
font-weight: 700;
white-space: nowrap;
}
th:first-child, td:first-child { text-align: left; }
td {
padding: 8px 5px;
border-bottom: 1px solid rgba(151, 196, 218, 0.09);
color: #d8eaf3;
text-align: right;
white-space: nowrap;
}
tr:last-child td { border-bottom: 0; }
.lane-name {
display: inline-flex;
align-items: center;
gap: 6px;
font-weight: 800;
}
.dot {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--lane);
box-shadow: 0 0 10px color-mix(in srgb, var(--lane), transparent 35%);
}
.remain { color: #8ff2d0; font-weight: 800; }
.explain {
margin-top: 12px;
padding: 11px 12px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.explain strong { color: #ecfaff; }
details {
margin-top: 11px;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
summary {
cursor: pointer;
color: #d7edf7;
font-weight: 700;
}
.formula {
display: block;
margin: 8px 0;
padding: 9px 10px;
border-left: 2px solid var(--accent);
background: rgba(98, 230, 255, 0.055);
color: #ccebf6;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
white-space: pre-wrap;
}
.tools {
position: fixed;
z-index: 5;
right: 18px;
bottom: 18px;
display: flex;
gap: 8px;
}
button {
padding: 9px 12px;
border: 1px solid rgba(151, 196, 218, 0.24);
border-radius: 10px;
background: rgba(9, 22, 31, 0.9);
color: #dff6ff;
font: inherit;
font-size: 11px;
font-weight: 800;
cursor: pointer;
backdrop-filter: blur(10px);
}
button:hover {
border-color: rgba(98, 230, 255, 0.55);
background: rgba(17, 42, 54, 0.96);
}
.hint {
position: fixed;
z-index: 3;
left: 18px;
bottom: 18px;
padding: 8px 10px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(9, 22, 31, 0.72);
color: #91afbe;
font-size: 10px;
pointer-events: none;
}
#labels {
position: fixed;
inset: 0;
z-index: 2;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
padding: 4px 7px;
border: 1px solid color-mix(in srgb, var(--lane), transparent 50%);
border-radius: 7px;
background: rgba(6, 16, 23, 0.82);
color: #eafaff;
font-size: 9px;
font-weight: 800;
white-space: nowrap;
transform: translate(-50%, -100%);
box-shadow: 0 5px 16px rgba(0, 0, 0, 0.25);
}
.scene-label.finish {
--lane: #ffffff;
border-color: rgba(255, 255, 255, 0.5);
}
@media (max-width: 780px) {
.intro {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 13px 15px;
}
.intro p { font-size: 11px; }
.chips { display: none; }
.calc {
top: auto;
right: 10px;
bottom: 60px;
width: calc(100vw - 20px);
max-height: 46vh;
padding: 13px;
}
.hint { left: 10px; bottom: 10px; }
.tools { right: 10px; bottom: 10px; }
}
</style>
</head>
<body>
<div id="scene"></div>
<section class="intro card">
<div class="eyebrow">Three.js / Voxel Geometry Study</div>
<h1>Equal-distance staggered start</h1>
<p>
A four-lane stadium track. Each start is placed from the exact lane-centerline
geometry so that every runner has exactly 200 m to the common finish.
</p>
<div class="chips">
<span class="chip">48 m straights</span>
<span class="chip">20 m inner radius</span>
<span class="chip">1.2 m lanes</span>
<span class="chip">1 unit = 1 m</span>
</div>
</section>
<aside class="calc card">
<div class="calc-head">
<h2>Lane calculation</h2>
<div class="target">TARGET = 200.00 m</div>
</div>
<p class="path-note">
<strong>Measured path:</strong> the clockwise centerline of each lane—not an
inner or outer edge. Each path has two 48 m straights joined by semicircles
of the listed radius. The common finish is 1.2 m after the top-left tangent.
</p>
<table>
<thead>
<tr>
<th>Lane</th>
<th>r (m)</th>
<th>Lap P (m)</th>
<th>Start x</th>
<th>Ahead Δ</th>
<th>Remain</th>
</tr>
</thead>
<tbody id="calcBody"></tbody>
</table>
<div class="explain" id="readout"></div>
<details open>
<summary>Geometry and offset method</summary>
<span class="formula">Pᵢ = 2L + 2πrᵢ
+sᵢ = (s_finish + Pᵢ − D) mod Pᵢ
+distance-to-finish = (s_finish − sᵢ + Pᵢ) mod Pᵢ = D</span>
The voxel blocks visually sample these exact paths. The table and marks use
the analytic stadium geometry, not the sampled block positions.
</details>
</aside>
<div id="labels"></div>
<div class="hint">Drag to orbit · Wheel to zoom · Shift not required</div>
<div class="tools">
<button id="topView">Top view</button>
<button id="reset">Reset camera</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 STRAIGHT_LENGTH = 48;
const HALF_STRAIGHT = STRAIGHT_LENGTH / 2;
const INNER_RADIUS = 20;
const LANE_WIDTH = 1.2;
const LANE_COUNT = 4;
const TARGET_DISTANCE = 200;
const FINISH_STATION = 1.2;
const laneColors = [
0x38a9ff,
0x28d3a4,
0xffb547,
0xef6cff
];
const cssLaneColors = [
"#38a9ff",
"#28d3a4",
"#ffb547",
"#ef6cff"
];
const mod = (n, m) => ((n % m) + m) % m;
const fmt = (n, digits = 2) => n.toFixed(digits);
const signed = n => `${n >= 0 ? "+" : "−"}${Math.abs(n).toFixed(2)}`;
function pathPoint(station, radius) {
const perimeter = 2 * STRAIGHT_LENGTH + 2 * Math.PI * radius;
let s = mod(station, perimeter);
// Top straight: left tangent to right tangent.
if (s <= STRAIGHT_LENGTH) {
return {
x: -HALF_STRAIGHT + s,
z: radius
};
}
// Right semicircle: top to bottom.
s -= STRAIGHT_LENGTH;
if (s <= Math.PI * radius) {
const theta = Math.PI / 2 - s / radius;
return {
x: HALF_STRAIGHT + radius * Math.cos(theta),
z: radius * Math.sin(theta)
};
}
// Bottom straight: right to left.
s -= Math.PI * radius;
if (s <= STRAIGHT_LENGTH) {
return {
x: HALF_STRAIGHT - s,
z: -radius
};
}
// Left semicircle: bottom to top.
s -= STRAIGHT_LENGTH;
const theta = -Math.PI / 2 - s / radius;
return {
x: -HALF_STRAIGHT + radius * Math.cos(theta),
z: radius * Math.sin(theta)
};
}
const lanes = [];
for (let i = 0; i < LANE_COUNT; i++) {
const radius = INNER_RADIUS + i * LANE_WIDTH;
const perimeter = 2 * STRAIGHT_LENGTH + 2 * Math.PI * radius;
const startStation = mod(
FINISH_STATION + perimeter - TARGET_DISTANCE,
perimeter
);
const point = pathPoint(startStation, radius);
const remaining = mod(FINISH_STATION - startStation, perimeter);
const ahead = mod(startStation - FINISH_STATION, perimeter);
lanes.push({
index: i,
radius,
perimeter,
startStation,
startPoint: point,
remaining,
ahead
});
}
const innerPerimeter = lanes[0].perimeter;
document.getElementById("calcBody").innerHTML = lanes.map(lane => `
<tr>
<td>
<span class="lane-name" style="--lane:${cssLaneColors[lane.index]}">
<span class="dot"></span>L${lane.index + 1}
</span>
</td>
<td>${fmt(lane.radius)}</td>
<td>${fmt(lane.perimeter)}</td>
<td>${fmt(lane.startPoint.x)}</td>
<td>${signed(lane.perimeter - innerPerimeter)}</td>
<td class="remain">${fmt(lane.remaining)}</td>
</tr>
`).join("");
const outerAdvance = lanes[LANE_COUNT - 1].perimeter - innerPerimeter;
document.getElementById("readout").innerHTML = `
<strong>Read the stagger:</strong> lane 4 starts
<strong>${fmt(outerAdvance)} m farther ahead</strong> than lane 1 because its
centerline lap is ${fmt(outerAdvance)} m longer. Each start nevertheless has
exactly <strong>${fmt(TARGET_DISTANCE)} m</strong> remaining to the checker.
`;
// ---------------------------------------------------------------------
// Three.js scene
// ---------------------------------------------------------------------
const container = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131b);
scene.fog = new THREE.Fog(0x07131b, 115, 220);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
300
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
container.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xbdeaff, 0x1b3026, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0d0, 3.3);
sun.position.set(-36, 65, 42);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -65;
sun.shadow.camera.right = 65;
sun.shadow.camera.top = 50;
sun.shadow.camera.bottom = -50;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 150;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x4ddfff, 1.1);
rim.position.set(40, 25, -45);
scene.add(rim);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(190, 145),
new THREE.MeshStandardMaterial({
color: 0x102b27,
roughness: 0.96,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.07;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(180, 90, 0x315c62, 0x193b3c);
grid.position.y = -0.035;
grid.material.transparent = true;
grid.material.opacity = 0.32;
scene.add(grid);
const trackGroup = new THREE.Group();
scene.add(trackGroup);
const tileGeometry = new THREE.BoxGeometry(1, 1, 1);
const dummy = new THREE.Object3D();
// Analytic lane paths, sampled only for the visible voxel blocks.
lanes.forEach(lane => {
const material = new THREE.MeshStandardMaterial({
color: laneColors[lane.index],
roughness: 0.73,
metalness: 0.06
});
const sampleCount = Math.ceil(lane.perimeter / 0.68);
const tiles = new THREE.InstancedMesh(
tileGeometry,
material,
sampleCount
);
tiles.castShadow = true;
tiles.receiveShadow = true;
tiles.instanceMatrix.setUsage(THREE.StaticDrawUsage);
for (let j = 0; j < sampleCount; j++) {
const station = j / sampleCount * lane.perimeter;
const p = pathPoint(station, lane.radius);
dummy.position.set(p.x, 0.15, p.z);
dummy.scale.set(0.93, 0.30, 0.93);
dummy.updateMatrix();
tiles.setMatrixAt(j, dummy.matrix);
}
trackGroup.add(tiles);
// Thin line shows the exact path used in the calculation.
const linePoints = [];
const lineSegments = 480;
for (let j = 0; j <= lineSegments; j++) {
const p = pathPoint(
j / lineSegments * lane.perimeter,
lane.radius
);
linePoints.push(new THREE.Vector3(p.x, 0.37, p.z));
}
const pathLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(linePoints),
new THREE.LineBasicMaterial({
color: 0xe9fbff,
transparent: true,
opacity: 0.52
})
);
trackGroup.add(pathLine);
});
// Common checker finish at x = -22.8 on the top straight.
const finishX = -HALF_STRAIGHT + FINISH_STATION;
const finishMinZ = INNER_RADIUS - LANE_WIDTH / 2;
const finishMaxZ = INNER_RADIUS + (LANE_COUNT - 1) * LANE_WIDTH + LANE_WIDTH / 2;
const finishBlocks = 12;
for (let i = 0; i < finishBlocks; i++) {
const t = (i + 0.5) / finishBlocks;
const z = THREE.MathUtils.lerp(finishMinZ, finishMaxZ, t);
const color = i % 2 === 0 ? 0xf4fbff : 0x111820;
const block = new THREE.Mesh(
new THREE.BoxGeometry(0.44, 0.52, 0.38),
new THREE.MeshStandardMaterial({
color,
roughness: 0.58,
emissive: i % 2 === 0 ? 0x23343a : 0x000000,
emissiveIntensity: 0.16
})
);
block.position.set(finishX, 0.39, z);
block.castShadow = true;
trackGroup.add(block);
}
// Start marks, positioned from the calculated station on each exact path.
const markerCaps = [];
lanes.forEach(lane => {
const markerMaterial = new THREE.MeshStandardMaterial({
color: laneColors[lane.index],
emissive: laneColors[lane.index],
emissiveIntensity: 0.65,
roughness: 0.36
});
for (let k = -1; k <= 1; k++) {
const block = new THREE.Mesh(
new THREE.BoxGeometry(0.42, 0.62, 0.34),
markerMaterial
);
block.position.set(
lane.startPoint.x,
0.47,
lane.radius + k * 0.36
);
block.castShadow = true;
trackGroup.add(block);
}
const post = new THREE.Mesh(
new THREE.BoxGeometry(0.16, 1.55, 0.16),
markerMaterial
);
post.position.set(
lane.startPoint.x,
0.91,
lane.radius - LANE_WIDTH * 0.48
);
post.castShadow = true;
trackGroup.add(post);
const cap = new THREE.Mesh(
new THREE.BoxGeometry(0.32, 0.25, 0.32),
markerMaterial
);
cap.position.set(
lane.startPoint.x,
1.82,
lane.radius - LANE_WIDTH * 0.48
);
cap.castShadow = true;
trackGroup.add(cap);
markerCaps.push(cap);
});
function createArrow(x, z, angle) {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color: 0xf4fbff,
emissive: 0x8bd7e8,
emissiveIntensity: 0.32,
roughness: 0.5
});
const shaft = new THREE.Mesh(
new THREE.BoxGeometry(2.4, 0.12, 0.30),
material
);
shaft.position.x = -0.45;
group.add(shaft);
const upper = new THREE.Mesh(
new THREE.BoxGeometry(1.35, 0.12, 0.30),
material
);
upper.position.set(0.45, 0, 0.30);
upper.rotation.y = -Math.PI / 4;
group.add(upper);
const lower = new THREE.Mesh(
new THREE.BoxGeometry(1.35, 0.12, 0.30),
material
);
lower.position.set(0.45, 0, -0.30);
lower.rotation.y = Math.PI / 4;
group.add(lower);
group.position.set(x, 0.43, z);
group.rotation.y = angle;
trackGroup.add(group);
}
// Clockwise direction indicators.
createArrow(-12.5, INNER_RADIUS, 0);
createArrow(0, -INNER_RADIUS, Math.PI);
// Voxel grandstands.
const standMaterials = [
new THREE.MeshStandardMaterial({ color: 0x294858, roughness: 0.82 }),
new THREE.MeshStandardMaterial({ color: 0x365c6b, roughness: 0.82 })
];
[-1, 1].forEach(side => {
for (let tier = 0; tier < 3; tier++) {
for (let x = -18; x <= 18; x += 3) {
const stand = new THREE.Mesh(
new THREE.BoxGeometry(2.65, 0.66, 1.35),
standMaterials[(Math.round(x) + tier) % 2]
);
stand.position.set(
x,
0.34 + tier * 0.54,
side * (28.4 + tier * 1.3)
);
stand.castShadow = true;
stand.receiveShadow = true;
scene.add(stand);
}
}
});
// A few block trees around the outside.
function addTree(x, z, scale = 1) {
const tree = new THREE.Group();
const trunk = new THREE.Mesh(
new THREE.BoxGeometry(0.5, 2.2, 0.5),
new THREE.MeshStandardMaterial({ color: 0x5a4030, roughness: 1 })
);
trunk.position.y = 1.1;
tree.add(trunk);
const leafMaterial = new THREE.MeshStandardMaterial({
color: 0x2f8f61,
roughness: 0.9
});
const leafA = new THREE.Mesh(
new THREE.BoxGeometry(1.9, 1.7, 1.9),
leafMaterial
);
leafA.position.y = 2.55;
tree.add(leafA);
const leafB = new THREE.Mesh(
new THREE.BoxGeometry(1.35, 1.25, 1.35),
leafMaterial
);
leafB.position.set(0.25, 3.55, -0.18);
tree.add(leafB);
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
tree.traverse(object => {
if (object.isMesh) object.castShadow = true;
});
scene.add(tree);
}
addTree(-53, -11, 1.05);
addTree(-51, 20, 0.85);
addTree(53, 9, 1.0);
addTree(50, -22, 0.9);
addTree(-28, -34, 0.8);
addTree(29, 35, 0.85);
// ---------------------------------------------------------------------
// Projected DOM labels
// ---------------------------------------------------------------------
const labelRoot = document.getElementById("labels");
const projectedLabels = [];
function createSceneLabel(text, position, laneColor, isFinish = false) {
const element = document.createElement("div");
element.className = `scene-label${isFinish ? " finish" : ""}`;
element.style.setProperty("--lane", laneColor);
element.textContent = text;
labelRoot.appendChild(element);
projectedLabels.push({
element,
position: position.clone()
});
}
lanes.forEach(lane => {
createSceneLabel(
`L${lane.index + 1} · x ${fmt(lane.startPoint.x)} m`,
new THREE.Vector3(
lane.startPoint.x,
1.55,
lane.radius
),
cssLaneColors[lane.index]
);
});
createSceneLabel(
"COMMON FINISH",
new THREE.Vector3(finishX, 1.25, (finishMinZ + finishMaxZ) / 2),
"#ffffff",
true
);
// ---------------------------------------------------------------------
// Direct camera controls: no examples/addons are imported.
// ---------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 0, 0),
radius: 112,
yaw: 0.73,
elevation: 0.82
};
function updateCamera() {
const horizontal = cameraState.radius *
Math.sin(cameraState.elevation);
camera.position.set(
cameraState.target.x + horizontal * Math.cos(cameraState.yaw),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.elevation),
cameraState.target.z + horizontal * Math.sin(cameraState.yaw)
);
camera.lookAt(cameraState.target);
camera.updateMatrixWorld();
}
let dragging = false;
let lastX = 0;
let lastY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
cameraState.yaw -= dx * 0.006;
cameraState.elevation = THREE.MathUtils.clamp(
cameraState.elevation + dy * 0.005,
0.16,
1.38
);
});
function stopDragging() {
dragging = false;
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
48,
175
);
}, { passive: false });
renderer.domElement.addEventListener("contextmenu", event => {
event.preventDefault();
});
document.getElementById("reset").addEventListener("click", () => {
cameraState.radius = 112;
cameraState.yaw = 0.73;
cameraState.elevation = 0.82;
cameraState.target.set(0, 0, 0);
});
document.getElementById("topView").addEventListener("click", () => {
cameraState.radius = 118;
cameraState.yaw = 0;
cameraState.elevation = 0.17;
});
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
addEventListener("resize", resize);
const projected = new THREE.Vector3();
function updateLabels() {
projectedLabels.forEach(label => {
projected.copy(label.position).project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
});
}
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
markerCaps.forEach((cap, i) => {
cap.position.y = 1.82 + Math.sin(elapsed * 3 + i * 0.9) * 0.08;
});
updateCamera();
updateLabels();
renderer.render(scene, camera);
}
updateCamera();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```