Prompt specification
Build or customize the Three.js 3D scene "Planet Size Tokens on One Scale" 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: Planet Size Tokens on One Scale
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/planet-size-tokens-on-one-scale-x3761
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring planetary radius comparisons. Display several source-checked planetary radius tokens using one stated scale. Keep a separate legend and avoid silently enlarging the smallest bodies within the same view. Low-poly.
Working Three.js Starter (planet-size-tokens-on-one-scale-x3761):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Planetary Radius — One True Scale</title>
<style>
:root {
color-scheme: dark;
--bg: #070b12;
--panel: #0d1420;
--panel-2: #111b2a;
--line: #243249;
--text: #edf4ff;
--muted: #9caec3;
--accent: #7dd3fc;
--accent-2: #a7f3d0;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
min-height: 100%;
margin: 0;
}
body {
overflow: hidden;
color: var(--text);
background: var(--bg);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
header {
height: 88px;
padding: 16px 22px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
border-bottom: 1px solid var(--line);
background: rgba(8, 13, 22, 0.96);
}
.eyebrow {
display: block;
margin-bottom: 4px;
color: var(--accent);
font-size: 0.68rem;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(1.25rem, 2.3vw, 1.85rem);
line-height: 1.05;
letter-spacing: -0.035em;
}
.scale-pill {
flex: 0 0 auto;
padding: 10px 13px;
border: 1px solid #31506a;
border-radius: 999px;
color: #d7f3ff;
background: #102232;
font-size: 0.76rem;
font-weight: 700;
letter-spacing: 0.035em;
text-align: right;
}
main {
display: grid;
grid-template-columns: minmax(0, 1fr) minmax(330px, 370px);
height: calc(100vh - 88px);
min-height: 620px;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background:
radial-gradient(circle at 48% 32%, #16233a 0, #0a111d 38%, #070b12 75%),
#070b12;
}
#canvas-host {
position: absolute;
inset: 0;
}
#canvas-host canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
#canvas-host canvas:active {
cursor: grabbing;
}
.scene-badge {
position: absolute;
top: 16px;
left: 16px;
z-index: 4;
max-width: min(520px, calc(100% - 32px));
padding: 10px 12px;
border: 1px solid rgba(125, 211, 252, 0.25);
border-radius: 10px;
color: #cceeff;
background: rgba(7, 13, 23, 0.76);
backdrop-filter: blur(10px);
font-size: 0.72rem;
line-height: 1.45;
pointer-events: none;
}
.scene-badge strong {
color: var(--accent-2);
}
.instructions {
position: absolute;
left: 16px;
bottom: 16px;
z-index: 5;
display: flex;
align-items: center;
gap: 8px;
flex-wrap: wrap;
max-width: calc(100% - 32px);
padding: 9px 10px;
border: 1px solid rgba(148, 163, 184, 0.2);
border-radius: 11px;
background: rgba(7, 13, 23, 0.82);
backdrop-filter: blur(10px);
color: var(--muted);
font-size: 0.7rem;
}
.controls {
position: absolute;
right: 16px;
bottom: 16px;
z-index: 6;
display: flex;
gap: 6px;
}
button {
min-width: 40px;
height: 38px;
padding: 0 12px;
border: 1px solid #33445d;
border-radius: 9px;
color: var(--text);
background: #111b2a;
font: inherit;
font-size: 0.76rem;
font-weight: 700;
cursor: pointer;
}
button:hover {
border-color: #5b789c;
background: #17253a;
}
button:focus-visible,
a:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
.body-label,
.scale-label {
position: absolute;
z-index: 3;
pointer-events: none;
user-select: none;
white-space: nowrap;
}
.body-label {
display: flex;
align-items: center;
gap: 6px;
padding: 4px 7px;
border: 1px solid rgba(148, 163, 184, 0.19);
border-radius: 7px;
color: #eaf2ff;
background: rgba(8, 14, 24, 0.76);
backdrop-filter: blur(7px);
font-size: 0.68rem;
font-weight: 700;
transform: translate(-50%, -100%);
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}
.body-label .dot {
width: 7px;
height: 7px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--body-color);
box-shadow: 0 0 7px color-mix(in srgb, var(--body-color), transparent 25%);
}
.body-label .minor {
color: var(--muted);
font-size: 0.6rem;
font-weight: 600;
}
.scale-label {
padding: 3px 6px;
border-radius: 5px;
color: #d6f8ed;
background: rgba(8, 14, 24, 0.8);
font-size: 0.65rem;
font-weight: 800;
transform: translate(-50%, 0);
}
#legend {
min-width: 0;
overflow: auto;
padding: 21px 19px 30px;
border-left: 1px solid var(--line);
background: linear-gradient(180deg, #0e1623, #090f18);
}
#legend h2 {
margin: 0 0 12px;
font-size: 1.02rem;
letter-spacing: -0.02em;
}
.legend-note {
margin: 0 0 14px;
padding: 11px 12px;
border: 1px solid #29445a;
border-radius: 10px;
color: #d7e8f5;
background: #0d1c29;
font-size: 0.75rem;
line-height: 1.55;
}
.legend-note code {
color: var(--accent-2);
font-size: 0.72rem;
}
.truth-note {
margin: 0 0 18px;
color: #a9e8d4;
font-size: 0.73rem;
line-height: 1.5;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 0.74rem;
}
caption {
margin-bottom: 9px;
color: var(--muted);
font-size: 0.72rem;
line-height: 1.45;
text-align: left;
}
th,
td {
padding: 8px 5px;
border-bottom: 1px solid rgba(148, 163, 184, 0.13);
text-align: right;
}
th:first-child,
td:first-child {
text-align: left;
}
th {
color: #8ea4bc;
font-size: 0.64rem;
letter-spacing: 0.07em;
text-transform: uppercase;
}
td:first-child {
color: #edf5ff;
font-weight: 700;
}
td:nth-child(2) {
font-variant-numeric: tabular-nums;
}
td:nth-child(3) {
color: var(--muted);
font-variant-numeric: tabular-nums;
}
a {
color: #91d7f7;
text-decoration-color: rgba(145, 215, 247, 0.35);
text-underline-offset: 2px;
}
a:hover {
color: #c4efff;
}
.minor {
color: var(--muted);
font-size: 0.67rem;
font-weight: 500;
}
.source {
margin: 18px 0 0;
padding-top: 15px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 0.69rem;
line-height: 1.6;
}
.source strong {
color: #c9d9e9;
}
.source-list {
margin: 7px 0 0;
padding-left: 18px;
}
noscript {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
padding: 30px;
color: white;
background: #070b12;
}
@media (max-width: 900px) {
body {
overflow: auto;
}
header {
height: auto;
min-height: 88px;
align-items: flex-start;
flex-direction: column;
gap: 10px;
}
.scale-pill {
text-align: left;
}
main {
display: block;
height: auto;
min-height: 0;
}
#stage {
height: 68vh;
min-height: 520px;
}
#legend {
overflow: visible;
border-top: 1px solid var(--line);
border-left: 0;
}
.controls {
top: 16px;
right: 16px;
bottom: auto;
}
.scene-badge {
top: 64px;
}
}
@media (max-width: 520px) {
header {
padding: 14px;
}
#stage {
min-height: 480px;
}
.instructions {
right: 12px;
bottom: 12px;
left: 12px;
}
.controls {
right: 12px;
}
.body-label {
font-size: 0.61rem;
}
}
</style>
</head>
<body>
<header>
<div>
<span class="eyebrow">Planetary scale study</span>
<h1>Radius tokens, one true scale</h1>
</div>
<div class="scale-pill">
r<sub>scene</sub> = r<sub>km</sub> ÷ 1,000<br />
No body-specific enlargement
</div>
</header>
<main>
<section id="stage" aria-label="Interactive three-dimensional planetary radius comparison">
<div id="canvas-host"></div>
<div class="scene-badge">
<strong>Orthographic projection · true relative radii.</strong><br />
Pluto and Mercury remain tiny by design; there is no minimum-size boost.
</div>
<div class="instructions">
Drag to rotate · Wheel or pinch to zoom · Arrow keys rotate · R resets
</div>
<div class="controls" aria-label="Scene controls">
<button id="zoom-out" type="button" aria-label="Zoom out">−</button>
<button id="zoom-in" type="button" aria-label="Zoom in">+</button>
<button id="reset" type="button">Reset</button>
</div>
</section>
<aside id="legend" aria-label="Legend and source data">
<h2>Legend & source data</h2>
<p class="legend-note">
Every geometric radius is calculated with the same factor:
<code>rendered radius = source radius ÷ 1,000</code>.
The camera is orthographic, so perspective does not change apparent
object size. Zoom affects all bodies equally.
</p>
<p class="truth-note">
<strong>Small-body policy:</strong> no clamp, minimum diameter, halo,
or individual scale multiplier is applied. Pluto is included as a
dwarf-planet comparison.
</p>
<table>
<caption>
NASA NSSDC volumetric mean radii. Each linked value opens its
corresponding NASA fact sheet.
</caption>
<thead>
<tr>
<th scope="col">Body</th>
<th scope="col">Mean radius</th>
<th scope="col">× Earth</th>
</tr>
</thead>
<tbody id="radius-rows"></tbody>
</table>
<p class="source">
<strong>Source checked:</strong> NASA NSSDC Planetary Fact Sheet,
physical-parameter tables. Values are volumetric mean radii in
kilometers and are reproduced at the precision published by NASA.
<br /><br />
The two display lanes are a layout choice only; vertical position does
not encode a value. Saturn’s rings are omitted so they do not obscure
its radius token.
<span class="source-list">
<a
href="https://nssdc.gsfc.nasa.gov/planetary/factsheet/"
target="_blank"
rel="noopener noreferrer"
>NASA Planetary Fact Sheet index</a>
</span>
</p>
</aside>
</main>
<noscript>This scene requires JavaScript and WebGL.</noscript>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const KM_PER_SCENE_UNIT = 1000;
const EARTH_RADIUS_KM = 6371.0;
/*
Source: NASA NSSDC Planetary Fact Sheet, volumetric mean radii.
Placement coordinates and colors are presentational only.
No placement code changes any radius.
*/
const bodies = [
{
name: "Mercury",
radiusKm: 2439.4,
color: 0xa7a19a,
x: 95,
lane: 0,
source:
"https://nssdc.gsfc.nasa.gov/planetary/factsheet/mercury_table.html"
},
{
name: "Venus",
radiusKm: 6051.8,
color: 0xd5a35e,
x: -45,
lane: 0,
source:
"https://nssdc.gsfc.nasa.gov/planetary/factsheet/venus_table.html"
},
{
name: "Earth",
radiusKm: 6371.0,
color: 0x3f83df,
x: -125,
lane: 0,
source:
"https://nssdc.gsfc.nasa.gov/planetary/factsheet/earth_table.html"
},
{
name: "Mars",
radiusKm: 3389.5,
color: 0xc45c3b,
x: 35,
lane: 0,
source:
"https://nssdc.gsfc.nasa.gov/planetary/factsheet/mars_table.html"
},
{
name: "Jupiter",
radiusKm: 69911,
color: 0xc7a071,
x: -280,
lane: 90,
source:
"https://nssdc.gsfc.nasa.gov/planetary/factsheet/jupiter_table.html"
},
{
name: "Saturn",
radiusKm: 58232,
color: 0xd7c38f,
x: 10,
lane: 90,
source:
"https://nssdc.gsfc.nasa.gov/planetary/factsheet/saturn_table.html"
},
{
name: "Uranus",
radiusKm: 25362,
color: 0x76d4d9,
x: -360,
lane: 0,
source:
"https://nssdc.gsfc.nasa.gov/planetary/factsheet/uranus_table.html"
},
{
name: "Neptune",
radiusKm: 24622,
color: 0x4667d8,
x: -235,
lane: 0,
source:
"https://nssdc.gsfc.nasa.gov/planetary/factsheet/neptune_table.html"
},
{
name: "Pluto",
minor: "dwarf planet",
radiusKm: 1188.3,
color: 0xd0b49b,
x: 160,
lane: 0,
source:
"https://nssdc.gsfc.nasa.gov/planetary/factsheet/pluto_table.html"
}
];
const stage = document.getElementById("stage");
const host = document.getElementById("canvas-host");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
host.appendChild(renderer.domElement);
const canvas = renderer.domElement;
canvas.tabIndex = 0;
canvas.setAttribute(
"aria-label",
"True-scale planetary radius scene. Drag to rotate and use the controls to zoom."
);
const scene = new THREE.Scene();
const camera = new THREE.OrthographicCamera(-300, 300, 200, -200, 0.1, 2000);
const cameraTarget = new THREE.Vector3(-110, 105, 0);
const cameraDistance = 700;
let yaw = 0;
let pitch = 0.075;
let zoom = 1;
let targetYaw = yaw;
let targetPitch = pitch;
let targetZoom = zoom;
let width = 1;
let height = 1;
let cameraSpan = 400;
const hemisphere = new THREE.HemisphereLight(0xaacfff, 0x17101c, 1.65);
scene.add(hemisphere);
const key = new THREE.DirectionalLight(0xffffff, 3.1);
key.position.set(-180, 260, 420);
scene.add(key);
const rim = new THREE.DirectionalLight(0x6ea8ff, 1.15);
rim.position.set(260, 80, -260);
scene.add(rim);
const ambient = new THREE.AmbientLight(0xffffff, 0.18);
scene.add(ambient);
const grid = new THREE.GridHelper(820, 28, 0x31445f, 0x1b2a40);
grid.position.y = -1.4;
grid.material.transparent = true;
grid.material.opacity = 0.18;
grid.material.depthWrite = false;
scene.add(grid);
// Display shelves. Their heights are layout-only and carry no data.
const shelfMaterial = new THREE.LineBasicMaterial({
color: 0x5e7899,
transparent: true,
opacity: 0.2,
depthWrite: false
});
const shelfVertices = [
-410, 0, 0, 205, 0, 0,
-390, 90, 0, 135, 90, 0,
-410, 0, 0, -410, 90, 0,
205, 0, 0, 205, 90, 0
];
const shelfGeometry = new THREE.BufferGeometry();
shelfGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(shelfVertices, 3)
);
scene.add(new THREE.LineSegments(shelfGeometry, shelfMaterial));
const bodyLabels = [];
for (const body of bodies) {
const radiusScene = body.radiusKm / KM_PER_SCENE_UNIT;
/*
Intentionally no Math.max(), minimum-size adjustment, halo,
or body-specific multiplier. Every radius uses this same factor.
*/
const geometry = new THREE.IcosahedronGeometry(radiusScene, 2);
const color = new THREE.Color(body.color);
const material = new THREE.MeshStandardMaterial({
color,
emissive: color.clone().multiplyScalar(0.06),
emissiveIntensity: 0.75,
roughness: 0.86,
metalness: 0.02,
flatShading: true
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(body.x, body.lane + radiusScene, 0);
mesh.userData.radiusScene = radiusScene;
scene.add(mesh);
const label = document.createElement("div");
label.className = "body-label";
label.style.setProperty("--body-color", `#${body.color.toString(16).padStart(6, "0")}`);
const minor = body.minor
? `<span class="minor">${body.minor}</span>`
: "";
label.innerHTML = `
<span class="dot"></span>
<span>${body.name}</span>
${minor}
`;
stage.appendChild(label);
bodyLabels.push({ body, mesh, label });
}
// A true 100,000 km scale bar: 100 scene units at the stated scale.
const scaleBarMaterial = new THREE.LineBasicMaterial({
color: 0x8ee8c5,
transparent: true,
opacity: 0.82,
depthTest: false,
depthWrite: false
});
const scaleBarY = -12;
const scaleBarZ = 110;
const scaleBarVertices = [
-335, scaleBarY, scaleBarZ, -235, scaleBarY, scaleBarZ,
-335, scaleBarY - 5, scaleBarZ, -335, scaleBarY + 5, scaleBarZ,
-235, scaleBarY - 5, scaleBarZ, -235, scaleBarY + 5, scaleBarZ
];
const scaleBarGeometry = new THREE.BufferGeometry();
scaleBarGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(scaleBarVertices, 3)
);
const scaleBar = new THREE.LineSegments(scaleBarGeometry, scaleBarMaterial);
scaleBar.renderOrder = 10;
scene.add(scaleBar);
const scaleLabel = document.createElement("div");
scaleLabel.className = "scale-label";
scaleLabel.textContent = "100,000 km";
stage.appendChild(scaleLabel);
const scaleLabelPosition = new THREE.Vector3(
-285,
scaleBarY - 8,
scaleBarZ
);
// Populate the separate HTML legend from the same data used by the scene.
const radiusRows = document.getElementById("radius-rows");
for (const body of bodies) {
const relative = body.radiusKm / EARTH_RADIUS_KM;
const row = document.createElement("tr");
const minor = body.minor
? ` <span class="minor">${body.minor}</span>`
: "";
row.innerHTML = `
<td>${body.name}${minor}</td>
<td>
<a
href="${body.source}"
target="_blank"
rel="noopener noreferrer"
title="Open the NASA source for ${body.name}"
>${body.radiusKm.toLocaleString("en-US", {
minimumFractionDigits: body.radiusKm % 1 ? 1 : 0,
maximumFractionDigits: 1
})}</a>
</td>
<td>${relative.toFixed(3)}×</td>
`;
radiusRows.appendChild(row);
}
function clamp(value, min, max) {
return Math.min(max, Math.max(min, value));
}
function updateCamera() {
const aspect = width / height;
// Keep a consistent horizontal fit while allowing tall viewports.
const baseWidth = 620;
const baseHeight = Math.max(300, baseWidth / aspect);
cameraSpan = baseHeight / zoom;
camera.left = (-cameraSpan * aspect) / 2;
camera.right = (cameraSpan * aspect) / 2;
camera.top = cameraSpan / 2;
camera.bottom = -cameraSpan / 2;
const cosPitch = Math.cos(pitch);
camera.position.set(
cameraTarget.x + cameraDistance * Math.sin(yaw) * cosPitch,
cameraTarget.y + cameraDistance * Math.sin(pitch),
cameraTarget.z + cameraDistance * Math.cos(yaw) * cosPitch
);
camera.lookAt(cameraTarget);
camera.updateProjectionMatrix();
}
function resize() {
width = Math.max(1, stage.clientWidth);
height = Math.max(1, stage.clientHeight);
renderer.setSize(width, height, false);
updateCamera();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
resize();
const projected = new THREE.Vector3();
function project(worldPosition) {
projected.copy(worldPosition).project(camera);
return {
x: (projected.x * 0.5 + 0.5) * width,
y: (-projected.y * 0.5 + 0.5) * height,
visible: projected.z >= -1 && projected.z <= 1
};
}
function updateLabels() {
const pixelsPerUnit = height / cameraSpan;
for (const item of bodyLabels) {
const point = project(item.mesh.position);
const radiusPixels = item.mesh.userData.radiusScene * pixelsPerUnit;
item.label.style.left = `${point.x}px`;
item.label.style.top = `${point.y - radiusPixels - 8}px`;
item.label.style.opacity = point.visible ? "1" : "0";
}
const scalePoint = project(scaleLabelPosition);
scaleLabel.style.left = `${scalePoint.x}px`;
scaleLabel.style.top = `${scalePoint.y}px`;
scaleLabel.style.opacity = scalePoint.visible ? "1" : "0";
}
// Direct camera controls implemented here without examples or addons.
const pointers = new Map();
let lastPointer = null;
let pinchDistance = 0;
let pinchZoom = 1;
function currentPinchDistance() {
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
);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.focus({ preventScroll: true });
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
lastPointer = {
x: event.clientX,
y: event.clientY
};
} else if (pointers.size === 2) {
pinchDistance = currentPinchDistance();
pinchZoom = targetZoom;
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1 && lastPointer) {
const dx = event.clientX - lastPointer.x;
const dy = event.clientY - lastPointer.y;
targetYaw -= dx * 0.006;
targetPitch = clamp(targetPitch + dy * 0.005, -0.38, 0.58);
lastPointer = {
x: event.clientX,
y: event.clientY
};
} else if (pointers.size === 2) {
const nextDistance = currentPinchDistance();
if (pinchDistance > 0 && nextDistance > 0) {
targetZoom = clamp(
pinchZoom * (nextDistance / pinchDistance),
0.65,
5
);
}
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 1) {
const remaining = [...pointers.values()][0];
lastPointer = {
x: remaining.x,
y: remaining.y
};
} else {
lastPointer = null;
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
targetZoom = clamp(
targetZoom * Math.exp(-event.deltaY * 0.001),
0.65,
5
);
},
{ passive: false }
);
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
function resetView() {
targetYaw = 0;
targetPitch = 0.075;
targetZoom = 1;
}
document.getElementById("reset").addEventListener("click", resetView);
document.getElementById("zoom-in").addEventListener("click", () => {
targetZoom = clamp(targetZoom * 1.25, 0.65, 5);
});
document.getElementById("zoom-out").addEventListener("click", () => {
targetZoom = clamp(targetZoom / 1.25, 0.65, 5);
});
canvas.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key.toLowerCase()) {
case "arrowleft":
targetYaw += 0.08;
break;
case "arrowright":
targetYaw -= 0.08;
break;
case "arrowup":
targetPitch = clamp(targetPitch + 0.06, -0.38, 0.58);
break;
case "arrowdown":
targetPitch = clamp(targetPitch - 0.06, -0.38, 0.58);
break;
case "+":
case "=":
targetZoom = clamp(targetZoom * 1.2, 0.65, 5);
break;
case "-":
targetZoom = clamp(targetZoom / 1.2, 0.65, 5);
break;
case "r":
resetView();
break;
default:
handled = false;
}
if (handled) event.preventDefault();
});
function animate() {
const smoothing = 0.14;
yaw += (targetYaw - yaw) * smoothing;
pitch += (targetPitch - pitch) * smoothing;
zoom += (targetZoom - zoom) * smoothing;
updateCamera();
renderer.render(scene, camera);
updateLabels();
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```