Prompt specification
Build or customize the Three.js 3D scene "Savanna grass patch and shallow hoof trail" 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: Savanna grass patch and shallow hoof trail
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/savanna-grass-patch-and-shallow-hoof-trail-x3117
Scene Description Prompt:
Savanna grass patch and shallow hoof trail. Build a referenced Serengeti grassland tile with a shallow trail and small water depression. Keep terrain detail subtle and avoid filling the scene with unrelated animal species. Please build this with Three.js from cdnjs in one self-contained HTML file, using visible voxel blocks.
Working Three.js Starter (savanna-grass-patch-and-shallow-hoof-trail-x3117):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Serengeti Voxel Grassland</title>
<style>
:root {
--ink: #343126;
--paper: #eee7d2;
--muted: #706854;
--grass: #85834b;
--trail: #a17c54;
--water: #5d9189;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8d0b7;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
color: var(--ink);
}
#app {
position: fixed;
inset: 0;
}
canvas {
display: block;
cursor: grab;
touch-action: none;
outline: none;
}
canvas.dragging {
cursor: grabbing;
}
.title-card {
position: fixed;
top: 28px;
left: 30px;
z-index: 2;
pointer-events: none;
user-select: none;
}
.eyebrow {
margin-bottom: 7px;
color: #756d59;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(24px, 3vw, 38px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
max-width: 320px;
margin-top: 10px;
color: #625c4d;
font-size: 12px;
line-height: 1.55;
}
.legend {
position: fixed;
left: 30px;
bottom: 27px;
z-index: 2;
display: flex;
flex-wrap: wrap;
gap: 15px;
padding: 10px 13px;
border: 1px solid rgba(75, 66, 49, 0.14);
border-radius: 8px;
background: rgba(239, 233, 214, 0.72);
box-shadow: 0 8px 25px rgba(64, 52, 34, 0.08);
backdrop-filter: blur(8px);
pointer-events: none;
user-select: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #655e4e;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
box-shadow: inset 0 0 0 1px rgba(35, 30, 22, 0.12);
}
.swatch.grass {
background: var(--grass);
}
.swatch.trail {
background: var(--trail);
}
.swatch.water {
background: var(--water);
}
.controls {
position: fixed;
right: 28px;
bottom: 29px;
z-index: 2;
color: rgba(62, 56, 43, 0.7);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.08em;
text-align: right;
text-transform: uppercase;
pointer-events: none;
user-select: none;
}
.loading {
position: fixed;
inset: 0;
z-index: 5;
display: grid;
place-items: center;
background: #d8d0b7;
color: #6f6755;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 680px) {
.title-card {
top: 20px;
left: 20px;
}
.subtitle {
max-width: 240px;
}
.legend {
left: 18px;
bottom: 18px;
gap: 10px;
}
.controls {
right: 18px;
bottom: 76px;
max-width: 135px;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div class="title-card">
<div class="eyebrow">Field Study 07 · Tanzania</div>
<h1>Serengeti<br>Grassland Tile</h1>
<div class="subtitle">
Dry seasonal grass, a shallow hoof trail, and a small water pocket.
Built as restrained, visible voxel terrain.
</div>
</div>
<div class="legend">
<div class="legend-item">
<span class="swatch grass"></span>
Savanna grass
</div>
<div class="legend-item">
<span class="swatch trail"></span>
Hoof trail
</div>
<div class="legend-item">
<span class="swatch water"></span>
Water pocket
</div>
</div>
<div class="controls">
Drag to orbit<br>
Shift-drag to pan · Wheel to zoom
</div>
<div class="loading" id="loading">Building grassland</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const container = document.getElementById("app");
const loading = document.getElementById("loading");
// -------------------------------------------------------------------------
// Renderer, camera, and atmosphere
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8d0b7);
scene.fog = new THREE.Fog(0xd8d0b7, 56, 108);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
container.appendChild(renderer.domElement);
const canvas = renderer.domElement;
canvas.tabIndex = 0;
const camera = new THREE.OrthographicCamera(-25, 25, 18, -18, 0.1, 200);
const target = new THREE.Vector3(0, 0.65, 0);
let azimuth = 0.72;
let polar = 0.94;
let radius = 52;
function updateCamera() {
const sinPolar = Math.sin(polar);
camera.position.set(
target.x + radius * sinPolar * Math.sin(azimuth),
target.y + radius * Math.cos(polar),
target.z + radius * sinPolar * Math.cos(azimuth)
);
camera.lookAt(target);
camera.zoom = 50 / radius;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
// Preserve the full rectangular tile at narrow and wide viewport sizes.
const halfHeight = Math.max(17.5, 24.5 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
}
window.addEventListener("resize", resize);
resize();
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xffefd0, 0x655039, 1.55);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffdfa0, 3.1);
sun.position.set(-18, 31, 20);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -35;
sun.shadow.camera.right = 35;
sun.shadow.camera.top = 35;
sun.shadow.camera.bottom = -35;
sun.shadow.camera.near = 2;
sun.shadow.camera.far = 85;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.045;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8d0cf, 0.48);
fill.position.set(22, 12, -20);
scene.add(fill);
// -------------------------------------------------------------------------
// Deterministic helpers
// -------------------------------------------------------------------------
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function smoothstep(edge0, edge1, value) {
const t = clamp((value - edge0) / (edge1 - edge0), 0, 1);
return t * t * (3 - 2 * t);
}
function hash(x, z = 0) {
const n = Math.sin(x * 127.1 + z * 311.7) * 43758.5453123;
return n - Math.floor(n);
}
function randomGenerator(seed) {
return function () {
let t = seed += 0x6D2B79F5;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = randomGenerator(74021);
// -------------------------------------------------------------------------
// Terrain layout
// -------------------------------------------------------------------------
const GRID_WIDTH = 38;
const GRID_DEPTH = 30;
const CELL_SIZE = 1;
const MIN_X = -18.5;
const MIN_Z = -14.5;
const WATER_LEVEL = 0.47;
const WATER_CENTER_X = 8.5;
const WATER_CENTER_Z = 7.0;
const WATER_RADIUS_X = 4.5;
const WATER_RADIUS_Z = 2.8;
function trailZ(x) {
const t = (x - MIN_X) / ((GRID_WIDTH - 1) * CELL_SIZE);
return 9.0 - 14.0 * t + 3.0 * Math.sin(t * Math.PI * 2.2);
}
function trailWeight(x, z) {
const distance = Math.abs(z - trailZ(x));
return 1 - smoothstep(0.34, 1.28, distance);
}
function waterField(x, z) {
const dx = (x - WATER_CENTER_X) / WATER_RADIUS_X;
const dz = (z - WATER_CENTER_Z) / WATER_RADIUS_Z;
return 1 - Math.sqrt(dx * dx + dz * dz);
}
function terrainHeight(x, z) {
let height =
0.84 +
Math.sin(x * 0.43) * 0.095 +
Math.cos(z * 0.37) * 0.085 +
Math.sin((x - z) * 0.29) * 0.055;
// A shallow compressed route rather than a deep trench.
height -= 0.115 * trailWeight(x, z);
// A soft-edged seasonal depression.
const field = waterField(x, z);
if (field > 0) {
const blend = smoothstep(0, 1, field);
const basinHeight = 0.28 + field * 0.12;
height = THREE.MathUtils.lerp(height, basinHeight, blend);
}
return Math.max(0.18, height);
}
// Neutral ground beyond the tile.
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xb9aa86,
roughness: 1
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(180, 180),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.45;
ground.receiveShadow = true;
scene.add(ground);
// Darker earth base makes the individual voxel columns easy to read.
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0x594a36,
roughness: 1
});
const base = new THREE.Mesh(
new THREE.BoxGeometry(
GRID_WIDTH * CELL_SIZE + 0.2,
0.42,
GRID_DEPTH * CELL_SIZE + 0.2
),
baseMaterial
);
base.position.y = -0.22;
base.castShadow = true;
base.receiveShadow = true;
scene.add(base);
// -------------------------------------------------------------------------
// Voxel terrain blocks
// -------------------------------------------------------------------------
const terrainGeometry = new THREE.BoxGeometry(1, 1, 1);
const terrainVertexColors = new Float32Array(terrainGeometry.attributes.position.count * 3).fill(1);
terrainGeometry.setAttribute("color", new THREE.BufferAttribute(terrainVertexColors, 3));
const terrainMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.98,
metalness: 0,
vertexColors: true
});
const terrainCells = [];
const waterCells = [];
for (let iz = 0; iz < GRID_DEPTH; iz++) {
for (let ix = 0; ix < GRID_WIDTH; ix++) {
const x = MIN_X + ix * CELL_SIZE;
const z = MIN_Z + iz * CELL_SIZE;
const height = terrainHeight(x, z);
const field = waterField(x, z);
const path = trailWeight(x, z);
terrainCells.push({ x, z, height, field, path });
if (field > 0.04 && height < WATER_LEVEL - 0.012) {
waterCells.push({ x, z, height });
}
}
}
const terrain = new THREE.InstancedMesh(
terrainGeometry,
terrainMaterial,
terrainCells.length
);
terrain.castShadow = true;
terrain.receiveShadow = true;
terrain.instanceMatrix.setUsage(THREE.StaticDrawUsage);
const dummy = new THREE.Object3D();
const grassColor = new THREE.Color();
const trailColor = new THREE.Color();
const dampSoilColor = new THREE.Color();
const blendedColor = new THREE.Color();
terrainCells.forEach((cell, index) => {
const { x, z, height, field, path } = cell;
const n = hash(x, z);
const n2 = hash(z + 91.3, x - 17.8);
// Olive and straw colors remain subdued to preserve the dry-season feel.
grassColor.setHSL(
0.145 + n * 0.025,
0.25 + n2 * 0.1,
0.345 + n2 * 0.085
);
trailColor.setHSL(
0.092 + n * 0.008,
0.32 + n2 * 0.07,
0.40 + n * 0.055
);
dampSoilColor.setHSL(
0.105,
0.27,
0.29 + n * 0.035
);
blendedColor.copy(grassColor);
if (path > 0.025) {
const pathBlend = smoothstep(0.025, 0.78, path);
blendedColor.lerp(trailColor, pathBlend);
}
// A narrow damp rim visually anchors the water pocket.
if (field > -0.19) {
const dampBlend = 1 - smoothstep(-0.19, 0.24, field);
blendedColor.lerp(dampSoilColor, dampBlend * 0.8);
}
dummy.position.set(x, height * 0.5, z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(0.965, height, 0.965);
dummy.updateMatrix();
terrain.setMatrixAt(index, dummy.matrix);
terrain.setColorAt(index, blendedColor);
});
terrain.instanceMatrix.needsUpdate = true;
terrain.instanceColor.needsUpdate = true;
scene.add(terrain);
// -------------------------------------------------------------------------
// Water, made from a small field of translucent voxel tiles
// -------------------------------------------------------------------------
const waterMaterial = new THREE.MeshPhysicalMaterial({
color: 0x5a938c,
roughness: 0.23,
metalness: 0.03,
transparent: true,
opacity: 0.82,
clearcoat: 0.55,
clearcoatRoughness: 0.28,
depthWrite: false
});
const water = new THREE.InstancedMesh(
terrainGeometry,
waterMaterial,
waterCells.length
);
water.renderOrder = 2;
waterCells.forEach((cell, index) => {
dummy.position.set(cell.x, WATER_LEVEL - 0.045, cell.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(0.94, 0.09, 0.94);
dummy.updateMatrix();
water.setMatrixAt(index, dummy.matrix);
});
water.instanceMatrix.needsUpdate = true;
scene.add(water);
// -------------------------------------------------------------------------
// Sparse, block-like grass
// -------------------------------------------------------------------------
const grassTufts = [];
for (let attempt = 0; attempt < 500 && grassTufts.length < 190; attempt++) {
const x = MIN_X + 0.6 + random() * (GRID_WIDTH - 1.2);
const z = MIN_Z + 0.6 + random() * (GRID_DEPTH - 1.2);
if (trailWeight(x, z) > 0.07) continue;
if (waterField(x, z) > 0.18) continue;
grassTufts.push({ x, z });
}
const grassMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
vertexColors: true
});
const grass = new THREE.InstancedMesh(
terrainGeometry,
grassMaterial,
grassTufts.length * 2
);
grass.castShadow = true;
grass.receiveShadow = true;
let grassIndex = 0;
grassTufts.forEach((tuft) => {
for (let blade = 0; blade < 2; blade++) {
const angle = random() * Math.PI * 2;
const offset = random() * 0.13;
const x = tuft.x + Math.cos(angle) * offset;
const z = tuft.z + Math.sin(angle) * offset;
const y = terrainHeight(x, z);
const bladeHeight = 0.24 + random() * 0.34;
const bladeWidth = 0.055 + random() * 0.045;
const dry = random() > 0.48;
dummy.position.set(
x,
y + bladeHeight * 0.47,
z
);
dummy.rotation.set(
(random() - 0.5) * 0.22,
angle,
(random() - 0.5) * 0.22
);
dummy.scale.set(bladeWidth, bladeHeight, bladeWidth);
dummy.updateMatrix();
grass.setMatrixAt(grassIndex, dummy.matrix);
const color = new THREE.Color();
color.setHSL(
dry ? 0.14 + random() * 0.025 : 0.19 + random() * 0.02,
dry ? 0.31 : 0.28,
dry ? 0.46 + random() * 0.07 : 0.34 + random() * 0.05
);
grass.setColorAt(grassIndex, color);
grassIndex++;
}
});
grass.instanceMatrix.needsUpdate = true;
grass.instanceColor.needsUpdate = true;
scene.add(grass);
// -------------------------------------------------------------------------
// Paired hoof impressions along the compressed route
// -------------------------------------------------------------------------
const hoofPrints = [];
for (let x = -17.2; x <= 17.2; x += 1.32) {
const z = trailZ(x);
const derivative =
(trailZ(x + 0.06) - trailZ(x - 0.06)) / 0.12;
const tangentLength = Math.sqrt(1 + derivative * derivative);
const normalX = -derivative / tangentLength;
const normalZ = 1 / tangentLength;
for (const side of [-1, 1]) {
const px = x + normalX * 0.25 * side;
const pz = z + normalZ * 0.25 * side;
if (waterField(px, pz) > 0) continue;
hoofPrints.push({
x: px,
z: pz,
y: terrainHeight(px, pz),
angle: Math.atan2(1, derivative),
variant: hash(px, pz)
});
}
}
const hoofMaterial = new THREE.MeshStandardMaterial({
color: 0x5a4331,
roughness: 1,
vertexColors: true
});
const hoofMesh = new THREE.InstancedMesh(
terrainGeometry,
hoofMaterial,
hoofPrints.length
);
hoofPrints.forEach((print, index) => {
dummy.position.set(print.x, print.y + 0.012, print.z);
dummy.rotation.set(0, print.angle, 0);
dummy.scale.set(0.15, 0.026, 0.34);
dummy.updateMatrix();
hoofMesh.setMatrixAt(index, dummy.matrix);
const color = new THREE.Color().setHSL(
0.085,
0.30,
0.245 + print.variant * 0.045
);
hoofMesh.setColorAt(index, color);
});
hoofMesh.instanceMatrix.needsUpdate = true;
hoofMesh.instanceColor.needsUpdate = true;
hoofMesh.castShadow = true;
hoofMesh.receiveShadow = true;
scene.add(hoofMesh);
// -------------------------------------------------------------------------
// One restrained flat-top acacia for geographic context
// -------------------------------------------------------------------------
const tree = new THREE.Group();
tree.position.set(
-12.1,
terrainHeight(-12.1, -10.0),
-10.0
);
const trunkMaterial = new THREE.MeshStandardMaterial({
color: 0x675039,
roughness: 1
});
const canopyMaterials = [
new THREE.MeshStandardMaterial({ color: 0x686c3c, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0x747745, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0x7b7b48, roughness: 1 })
];
function treeBlock(parent, material, sx, sy, sz, x, y, z) {
const mesh = new THREE.Mesh(terrainGeometry, material);
mesh.position.set(x, y, z);
mesh.scale.set(sx, sy, sz);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function branchBetween(start, end, thickness) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const midpoint = new THREE.Vector3()
.addVectors(start, end)
.multiplyScalar(0.5);
const mesh = new THREE.Mesh(terrainGeometry, trunkMaterial);
mesh.position.copy(midpoint);
mesh.scale.set(thickness, length, thickness);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
tree.add(mesh);
}
for (let i = 0; i < 5; i++) {
treeBlock(
tree,
trunkMaterial,
0.52 - i * 0.055,
0.92,
0.5 - i * 0.045,
i * 0.12,
0.46 + i * 0.78,
-i * 0.025
);
}
branchBetween(
new THREE.Vector3(0.32, 2.0, 0),
new THREE.Vector3(-1.65, 3.05, -0.5),
0.22
);
branchBetween(
new THREE.Vector3(0.42, 2.15, 0),
new THREE.Vector3(1.65, 3.08, 0.15),
0.2
);
branchBetween(
new THREE.Vector3(0.4, 2.1, 0),
new THREE.Vector3(0.2, 3.12, 1.15),
0.18
);
for (let gx = -3; gx <= 3; gx++) {
for (let gz = -2; gz <= 2; gz++) {
const ellipse =
Math.pow(gx / 3.35, 2) +
Math.pow(gz / 2.45, 2);
if (ellipse > 1) continue;
const n = hash(gx + 80, gz + 41);
if (n < 0.09) continue;
const edgeDrop = ellipse > 0.66 ? -0.17 : 0;
const material =
canopyMaterials[Math.floor(n * canopyMaterials.length) % canopyMaterials.length];
treeBlock(
tree,
material,
1.04,
0.42,
1.02,
gx * 1.03 + 0.12,
3.27 + edgeDrop + (n - 0.5) * 0.12,
gz * 0.97
);
}
}
scene.add(tree);
// -------------------------------------------------------------------------
// Custom camera controls: orbit, pan, zoom, keyboard, and touch pinch
// -------------------------------------------------------------------------
const pointers = new Map();
let interactionMode = "orbit";
let pinchDistance = 0;
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
);
}
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
button: event.button
});
if (pointers.size === 1) {
interactionMode =
event.shiftKey || event.button === 2 ? "pan" : "orbit";
} else if (pointers.size === 2) {
pinchDistance = pointerDistance();
}
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
button: previous.button
});
if (pointers.size === 1) {
if (interactionMode === "pan") {
const screenHeight =
(camera.top - camera.bottom) / camera.zoom;
const panScale =
(screenHeight / Math.max(canvas.clientHeight, 1)) * 1.15;
const right = new THREE.Vector3(
Math.cos(azimuth),
0,
-Math.sin(azimuth)
);
const forward = new THREE.Vector3(
-Math.sin(azimuth),
0,
-Math.cos(azimuth)
);
target.addScaledVector(right, -dx * panScale);
target.addScaledVector(forward, dy * panScale);
} else {
azimuth -= dx * 0.006;
polar = clamp(polar - dy * 0.005, 0.38, 1.35);
}
} else if (pointers.size === 2) {
const nextDistance = pointerDistance();
if (pinchDistance > 0 && nextDistance > 0) {
radius = clamp(
radius * (pinchDistance / nextDistance),
31,
78
);
}
pinchDistance = nextDistance;
}
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) {
pinchDistance = 0;
}
if (pointers.size === 0) {
canvas.classList.remove("dragging");
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("wheel", event => {
event.preventDefault();
radius = clamp(
radius * Math.exp(event.deltaY * 0.001),
31,
78
);
updateCamera();
}, { passive: false });
function resetCamera() {
target.set(0, 0.65, 0);
azimuth = 0.72;
polar = 0.94;
radius = 52;
updateCamera();
}
window.addEventListener("keydown", event => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
azimuth += 0.08;
break;
case "ArrowRight":
azimuth -= 0.08;
break;
case "ArrowUp":
polar = clamp(polar - 0.06, 0.38, 1.35);
break;
case "ArrowDown":
polar = clamp(polar + 0.06, 0.38, 1.35);
break;
case "+":
case "=":
radius = clamp(radius - 2, 31, 78);
break;
case "-":
case "_":
radius = clamp(radius + 2, 31, 78);
break;
case "r":
case "R":
resetCamera();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 400);
});
</script>
</body>
</html>
```