Prompt specification
Build or customize the Three.js 3D scene "Package size and price 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: Package size and price display
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/package-size-and-price-display-x0553
Scene Description Prompt:
Two voxel packages of different sizes beside price cards and a shared unit scale distinguishing total and unit prices. One HTML file, Three.js from cdnjs.
Working Three.js Starter (package-size-and-price-display-x0553):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Value — Price Comparison</title>
<style>
:root {
--ink: #192522;
--muted: #66736e;
--paper: #fffdf7;
--total: #ed633d;
--unit: #087f78;
--line: rgba(25, 37, 34, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eee9de;
color: var(--ink);
font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
#scene canvas.dragging {
cursor: grabbing;
}
.header {
position: fixed;
top: 0;
left: 0;
z-index: 5;
width: min(620px, calc(100vw - 40px));
padding: 30px 34px 48px;
pointer-events: none;
background: linear-gradient(
180deg,
rgba(244, 240, 232, 0.96) 0%,
rgba(244, 240, 232, 0.78) 62%,
rgba(244, 240, 232, 0) 100%
);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
width: 22px;
height: 3px;
border-radius: 4px;
background: var(--total);
content: "";
}
h1 {
max-width: 520px;
margin: 0;
font-size: clamp(32px, 4.1vw, 60px);
font-weight: 850;
letter-spacing: -0.055em;
line-height: 0.98;
}
.intro {
max-width: 480px;
margin: 15px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.controls {
position: fixed;
top: 28px;
right: 28px;
z-index: 10;
display: flex;
gap: 8px;
}
button {
appearance: none;
border: 1px solid rgba(25, 37, 34, 0.16);
border-radius: 999px;
padding: 10px 14px;
background: rgba(255, 253, 247, 0.88);
color: var(--ink);
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
box-shadow: 0 8px 24px rgba(43, 48, 40, 0.08);
backdrop-filter: blur(12px);
transition:
transform 160ms ease,
background 160ms ease;
}
button:hover {
transform: translateY(-2px);
background: #fffdf7;
}
button:active {
transform: translateY(0);
}
.legend {
position: fixed;
bottom: 28px;
left: 30px;
z-index: 5;
display: flex;
flex-wrap: wrap;
gap: 9px;
max-width: calc(100vw - 60px);
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 9px;
border: 1px solid rgba(25, 37, 34, 0.12);
border-radius: 999px;
padding: 10px 13px;
background: rgba(255, 253, 247, 0.88);
color: #48534f;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.03em;
box-shadow: 0 10px 30px rgba(44, 48, 42, 0.08);
backdrop-filter: blur(12px);
}
.swatch {
width: 10px;
height: 10px;
border-radius: 3px;
}
.swatch.total {
background: var(--total);
}
.swatch.unit {
background: var(--unit);
}
.hint {
position: fixed;
right: 30px;
bottom: 30px;
z-index: 5;
color: rgba(25, 37, 34, 0.58);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
pointer-events: none;
}
.loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #eee9de;
color: var(--muted);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
.header {
padding: 22px 20px 40px;
width: calc(100vw - 24px);
}
h1 {
max-width: 340px;
font-size: 36px;
}
.intro {
display: none;
}
.controls {
top: auto;
right: 16px;
bottom: 74px;
}
button {
padding: 9px 11px;
font-size: 9px;
}
.legend {
left: 16px;
bottom: 16px;
gap: 6px;
}
.legend-item {
padding: 9px 11px;
font-size: 9px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive 3D comparison of two voxel package prices"></main>
<header class="header">
<div class="eyebrow">Pricing study / voxel series 01</div>
<h1>Voxel value,<br />clearly scaled.</h1>
<p class="intro">
Two package sizes share the same per-unit rate. The cards separate the
total package price from the price of one voxel, while the shared scale
makes the relationship visible.
</p>
</header>
<div class="controls">
<button id="top-view" type="button">Top view</button>
<button id="reset-view" type="button">Reset</button>
</div>
<div class="legend" aria-label="Price color legend">
<div class="legend-item">
<span class="swatch total"></span>
Total package price
</div>
<div class="legend-item">
<span class="swatch unit"></span>
Price per voxel
</div>
</div>
<div class="hint">Drag to orbit · Scroll to zoom</div>
<div class="loading" id="loading">Building the voxel display…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const COLORS = {
background: 0xeee9de,
platform: 0xf8f4e9,
grid: 0x53635e,
total: "#ed633d",
unit: "#087f78",
ink: "#192522",
muted: "#66736e",
paper: "#fffdf7"
};
const scene = new THREE.Scene();
scene.background = new THREE.Color(COLORS.background);
scene.fog = new THREE.Fog(COLORS.background, 19, 36);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute("aria-label", "3D voxel pricing scene");
sceneHost.appendChild(renderer.domElement);
const maxAnisotropy = renderer.capabilities.getMaxAnisotropy();
// Lighting
scene.add(new THREE.HemisphereLight(0xfffaf0, 0x758078, 2.2));
const keyLight = new THREE.DirectionalLight(0xfff4dd, 3.4);
keyLight.position.set(5, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.normalBias = 0.035;
keyLight.shadow.bias = -0.00015;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb8d7d2, 1.2);
fillLight.position.set(-7, 5, -5);
scene.add(fillLight);
// Platform and floor
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0xe8e2d6,
roughness: 1
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.34;
floor.receiveShadow = true;
scene.add(floor);
const platform = new THREE.Mesh(
new THREE.BoxGeometry(13.2, 0.3, 8.8),
new THREE.MeshStandardMaterial({
color: COLORS.platform,
roughness: 0.92
})
);
platform.position.set(0, -0.15, 0.55);
platform.receiveShadow = true;
platform.castShadow = true;
scene.add(platform);
// Custom grid, clipped to the platform
const gridVertices = [];
const gridLeft = -6.5;
const gridRight = 6.5;
const gridBack = -3.8;
const gridFront = 4.9;
for (let x = gridLeft; x <= gridRight + 0.01; x += 0.5) {
gridVertices.push(x, 0.009, gridBack, x, 0.009, gridFront);
}
for (let z = gridBack; z <= gridFront + 0.01; z += 0.5) {
gridVertices.push(gridLeft, 0.009, z, gridRight, 0.009, z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridVertices, 3)
);
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: COLORS.grid,
transparent: true,
opacity: 0.12,
depthWrite: false
})
);
scene.add(grid);
function roundedRect(ctx, x, y, w, h, r) {
const radius = Math.min(r, w / 2, h / 2);
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.arcTo(x + w, y, x + w, y + h, radius);
ctx.arcTo(x + w, y + h, x, y + h, radius);
ctx.arcTo(x, y + h, x, y, radius);
ctx.arcTo(x, y, x + w, y, radius);
ctx.closePath();
}
function createTexture(width, height, draw) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
draw(ctx, width, height);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = maxAnisotropy;
texture.needsUpdate = true;
return texture;
}
function drawPriceCard(spec) {
return createTexture(1024, 1280, (ctx, w, h) => {
ctx.clearRect(0, 0, w, h);
ctx.fillStyle = COLORS.paper;
roundedRect(ctx, 12, 12, w - 24, h - 24, 46);
ctx.fill();
ctx.strokeStyle = "rgba(25,37,34,0.13)";
ctx.lineWidth = 3;
roundedRect(ctx, 13, 13, w - 26, h - 26, 45);
ctx.stroke();
// Header
ctx.fillStyle = COLORS.total;
roundedRect(ctx, 62, 62, 18, 94, 8);
ctx.fill();
ctx.fillStyle = COLORS.muted;
ctx.font = "800 25px Arial, sans-serif";
ctx.letterSpacing = "2px";
ctx.fillText(`PRICE CARD / ${spec.index}`, 108, 91);
ctx.fillStyle = COLORS.ink;
ctx.font = "900 72px Arial, sans-serif";
ctx.fillText(spec.title, 62, 210);
ctx.fillStyle = COLORS.muted;
ctx.font = "700 29px Arial, sans-serif";
ctx.fillText(spec.subtitle, 62, 263);
ctx.strokeStyle = "rgba(25,37,34,0.13)";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(62, 315);
ctx.lineTo(962, 315);
ctx.stroke();
// Total block
ctx.fillStyle = "rgba(237,99,61,0.11)";
roundedRect(ctx, 62, 365, 900, 337, 30);
ctx.fill();
ctx.fillStyle = COLORS.total;
ctx.font = "900 31px Arial, sans-serif";
ctx.fillText("TOTAL PACKAGE PRICE", 96, 427);
ctx.fillStyle = COLORS.ink;
ctx.font = "900 112px Arial, sans-serif";
ctx.fillText(spec.total, 92, 548);
ctx.fillStyle = "#7b4939";
ctx.font = "700 30px Arial, sans-serif";
ctx.fillText(`${spec.units} voxels × $3.00`, 96, 630);
// Unit block
ctx.fillStyle = "rgba(8,127,120,0.11)";
roundedRect(ctx, 62, 742, 900, 337, 30);
ctx.fill();
ctx.fillStyle = COLORS.unit;
ctx.font = "900 31px Arial, sans-serif";
ctx.fillText("PRICE PER UNIT", 96, 804);
ctx.fillStyle = COLORS.ink;
ctx.font = "900 112px Arial, sans-serif";
ctx.fillText(spec.unitPrice, 92, 925);
ctx.fillStyle = "#376c68";
ctx.font = "700 30px Arial, sans-serif";
ctx.fillText("one voxel · same rate", 96, 1007);
// Footer
ctx.strokeStyle = "rgba(25,37,34,0.13)";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(62, 1131);
ctx.lineTo(962, 1131);
ctx.stroke();
ctx.fillStyle = COLORS.muted;
ctx.font = "800 25px Arial, sans-serif";
ctx.fillText("SHARED UNIT SCALE →", 62, 1187);
ctx.fillStyle = COLORS.unit;
ctx.beginPath();
ctx.arc(940, 1179, 13, 0, Math.PI * 2);
ctx.fill();
});
}
function drawPackageLabel(title, units) {
return createTexture(640, 300, (ctx, w, h) => {
ctx.fillStyle = "#fff8df";
roundedRect(ctx, 10, 10, w - 20, h - 20, 24);
ctx.fill();
ctx.strokeStyle = "rgba(25,37,34,0.2)";
ctx.lineWidth = 5;
roundedRect(ctx, 13, 13, w - 26, h - 26, 22);
ctx.stroke();
ctx.fillStyle = COLORS.ink;
ctx.font = "900 76px Arial, sans-serif";
ctx.fillText(title, 46, 113);
ctx.fillStyle = COLORS.muted;
ctx.font = "800 32px Arial, sans-serif";
ctx.fillText(`${units} VOXELS`, 48, 183);
ctx.fillStyle = COLORS.total;
for (let i = 0; i < 5; i++) {
ctx.fillRect(48 + i * 28, 226, 18, 18);
}
});
}
function drawSharedScale() {
return createTexture(2048, 360, (ctx, w, h) => {
ctx.fillStyle = COLORS.paper;
roundedRect(ctx, 8, 8, w - 16, h - 16, 30);
ctx.fill();
ctx.strokeStyle = "rgba(25,37,34,0.14)";
ctx.lineWidth = 3;
roundedRect(ctx, 10, 10, w - 20, h - 20, 28);
ctx.stroke();
ctx.fillStyle = COLORS.ink;
ctx.font = "900 39px Arial, sans-serif";
ctx.fillText("SHARED 24-UNIT SCALE", 66, 58);
ctx.fillStyle = COLORS.muted;
ctx.font = "700 22px Arial, sans-serif";
ctx.fillText("ONE REFERENCE FOR BOTH PACKAGES", 490, 56);
// Total row
ctx.fillStyle = COLORS.total;
ctx.font = "900 31px Arial, sans-serif";
ctx.fillText("TOTAL", 66, 148);
ctx.fillStyle = COLORS.ink;
ctx.font = "900 40px Arial, sans-serif";
ctx.fillText("$72", 205, 148);
const startX = 420;
const segmentW = 34;
const gap = 4;
for (let i = 0; i < 24; i++) {
const x = startX + i * (segmentW + gap);
ctx.fillStyle = i % 2 === 0 ? COLORS.total : "#f58b68";
roundedRect(ctx, x, 110, segmentW, 48, 5);
ctx.fill();
}
ctx.fillStyle = COLORS.total;
ctx.font = "800 27px Arial, sans-serif";
ctx.fillText("24 voxels × $3", 1390, 145);
// Unit row
ctx.fillStyle = COLORS.unit;
ctx.font = "900 31px Arial, sans-serif";
ctx.fillText("UNIT", 66, 258);
ctx.fillStyle = COLORS.ink;
ctx.font = "900 40px Arial, sans-serif";
ctx.fillText("$3", 205, 258);
ctx.fillStyle = COLORS.unit;
roundedRect(ctx, startX, 219, segmentW, 48, 5);
ctx.fill();
ctx.fillStyle = COLORS.unit;
ctx.font = "800 27px Arial, sans-serif";
ctx.fillText("$3 per voxel · identical unit rate", 500, 253);
ctx.fillStyle = COLORS.muted;
ctx.font = "700 21px Arial, sans-serif";
ctx.fillText("24 units", 1390, 253);
});
}
function createVoxelPackage({
cols,
rows,
depth,
x,
z,
baseColors,
label,
units
}) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = -0.08;
const cubeSize = 0.72;
const gap = 0.05;
const step = cubeSize + gap;
const count = cols * rows * depth;
const geometry = new THREE.BoxGeometry(cubeSize, cubeSize, cubeSize);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.72,
metalness: 0.02,
vertexColors: true
});
const voxels = new THREE.InstancedMesh(geometry, material, count);
voxels.castShadow = true;
voxels.receiveShadow = true;
const matrix = new THREE.Matrix4();
const color = new THREE.Color();
let index = 0;
for (let ix = 0; ix < cols; ix++) {
for (let iy = 0; iy < rows; iy++) {
for (let iz = 0; iz < depth; iz++) {
const px = (ix - (cols - 1) / 2) * step;
const py = cubeSize / 2 + iy * step;
const pz = (iz - (depth - 1) / 2) * step;
matrix.makeTranslation(px, py, pz);
voxels.setMatrixAt(index, matrix);
const base = new THREE.Color(baseColors[(ix + iy + iz) % baseColors.length]);
color.copy(base);
color.offsetHSL(0, 0, ((index % 3) - 1) * 0.018);
voxels.setColorAt(index, color);
index++;
}
}
}
voxels.instanceMatrix.needsUpdate = true;
if (voxels.instanceColor) voxels.instanceColor.needsUpdate = true;
group.add(voxels);
// Small packing band across the top
const totalWidth = cols * step - gap;
const totalDepth = depth * step - gap;
const band = new THREE.Mesh(
new THREE.BoxGeometry(totalWidth + 0.04, 0.025, 0.13),
new THREE.MeshStandardMaterial({
color: 0xffdf9a,
roughness: 0.8
})
);
band.position.set(0, rows * step - gap + 0.014, 0);
band.castShadow = true;
group.add(band);
const labelTexture = drawPackageLabel(label, units);
const labelWidth = units > 10 ? 1.43 : 1.18;
const labelHeight = units > 10 ? 0.67 : 0.56;
const labelMesh = new THREE.Mesh(
new THREE.PlaneGeometry(labelWidth, labelHeight),
new THREE.MeshBasicMaterial({
map: labelTexture,
toneMapped: false,
side: THREE.DoubleSide
})
);
labelMesh.position.set(
-0.12,
rows * step * 0.48,
totalDepth / 2 + 0.025
);
group.add(labelMesh);
return group;
}
function createPriceCard(spec) {
const group = new THREE.Group();
group.position.set(spec.x, 0, spec.z);
group.rotation.y = 0.12;
const width = 2.35;
const height = 2.94;
const backing = new THREE.Mesh(
new THREE.BoxGeometry(width, height, 0.11),
new THREE.MeshStandardMaterial({
color: COLORS.paper,
roughness: 0.9
})
);
backing.position.y = height / 2 + 0.05;
backing.castShadow = true;
backing.receiveShadow = true;
group.add(backing);
const face = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: drawPriceCard(spec),
toneMapped: false
})
);
face.position.set(0, height / 2 + 0.05, 0.061);
group.add(face);
const foot = new THREE.Mesh(
new THREE.BoxGeometry(width * 0.62, 0.08, 0.38),
new THREE.MeshStandardMaterial({
color: 0xd7d0c2,
roughness: 0.9
})
);
foot.position.y = 0.04;
foot.castShadow = true;
group.add(foot);
return group;
}
// Large package: 4 × 3 × 2 = 24 units
scene.add(
createVoxelPackage({
cols: 4,
rows: 3,
depth: 2,
x: -3.3,
z: -0.7,
baseColors: ["#ef7048", "#e9623b", "#f17a51", "#df5632"],
label: "BULK",
units: 24
})
);
// Small package: 2 × 2 × 2 = 8 units
scene.add(
createVoxelPackage({
cols: 2,
rows: 2,
depth: 2,
x: 1.65,
z: -0.95,
baseColors: ["#f08a5e", "#e96e42", "#f39a6e", "#df5c35"],
label: "MINI",
units: 8
})
);
scene.add(
createPriceCard({
index: "01",
title: "BULK BOX",
subtitle: "24 VOXELS · 4 × 3 × 2",
units: 24,
total: "$72",
unitPrice: "$3",
x: -0.2,
z: 0.35
})
);
scene.add(
createPriceCard({
index: "02",
title: "STARTER BOX",
subtitle: "8 VOXELS · 2 × 2 × 2",
units: 8,
total: "$24",
unitPrice: "$3",
x: 3.8,
z: 0.28
})
);
// Shared unit scale lying in front of both products
const scale = new THREE.Mesh(
new THREE.PlaneGeometry(11.8, 2.075),
new THREE.MeshBasicMaterial({
map: drawSharedScale(),
toneMapped: false,
transparent: true
})
);
scale.rotation.x = -Math.PI / 2;
scale.position.set(0, 0.022, 2.62);
scale.receiveShadow = true;
scene.add(scale);
// Direct camera controls: orbit, zoom, and damping
const target = new THREE.Vector3(0, 0.75, 0.25);
let desiredYaw = 0.43;
let desiredPitch = 0.57;
let desiredDistance = innerWidth < 700 ? 28 : 15.6;
let yaw = desiredYaw;
let pitch = desiredPitch;
let distance = desiredDistance;
const minPitch = 0.2;
const maxPitch = 1.35;
const minDistance = 9;
const maxDistance = 33;
let dragging = false;
let previousX = 0;
let previousY = 0;
let pointerId = null;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerId = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
desiredYaw -= dx * 0.006;
desiredPitch = THREE.MathUtils.clamp(
desiredPitch + dy * 0.005,
minPitch,
maxPitch
);
});
function endDrag(event) {
if (!dragging) return;
if (event.pointerId === pointerId && canvas.hasPointerCapture(pointerId)) {
canvas.releasePointerCapture(pointerId);
}
dragging = false;
pointerId = null;
canvas.classList.remove("dragging");
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredDistance = THREE.MathUtils.clamp(
desiredDistance + event.deltaY * 0.012,
minDistance,
maxDistance
);
},
{ passive: false }
);
function resetCamera() {
desiredYaw = 0.43;
desiredPitch = 0.57;
desiredDistance = innerWidth < 700 ? 28 : 15.6;
}
function topView() {
desiredYaw = 0;
desiredPitch = 1.32;
desiredDistance = innerWidth < 700 ? 28 : 15.6;
}
document.querySelector("#reset-view").addEventListener("click", resetCamera);
document.querySelector("#top-view").addEventListener("click", topView);
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
function animate() {
requestAnimationFrame(animate);
yaw += (desiredYaw - yaw) * 0.09;
pitch += (desiredPitch - pitch) * 0.09;
distance += (desiredDistance - distance) * 0.09;
const horizontal = distance * Math.sin(pitch);
camera.position.set(
target.x + horizontal * Math.sin(yaw),
target.y + distance * Math.cos(pitch),
target.z + horizontal * Math.cos(yaw)
);
camera.lookAt(target);
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => loading.classList.add("hidden"));
</script>
</body>
</html>
```