Prompt specification
Build or customize the Three.js 3D scene "Malá Strana stepped doorway and paving corner" 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: Malá Strana stepped doorway and paving corner
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/mal-strana-stepped-doorway-and-paving-corner-x2857
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: Malá Strana stepped doorway and paving corner. Build a referenced Prague doorway with stone step, arched opening, and rising paving. Keep the facade vertical while the street changes elevation across the tile. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (mal-strana-stepped-doorway-and-paving-corner-x2857):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>Malá Strana — Voxel Doorway</title>
<style>
:root {
color-scheme: light;
--ink: #3d342c;
--paper: rgba(245, 238, 225, 0.88);
--accent: #a6533f;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #ded7c9;
font-family: Georgia, "Times New Roman", serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.caption {
position: fixed;
left: 24px;
bottom: 22px;
z-index: 2;
max-width: min(360px, calc(100vw - 48px));
padding: 15px 18px 14px;
color: var(--ink);
background: var(--paper);
border: 1px solid rgba(77, 60, 43, 0.16);
border-left: 4px solid var(--accent);
box-shadow: 0 12px 30px rgba(65, 48, 31, 0.12);
backdrop-filter: blur(8px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 5px;
color: var(--accent);
font: 700 10px/1.2 Arial, sans-serif;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 4vw, 36px);
font-weight: 500;
line-height: 1;
}
.caption p {
margin: 8px 0 0;
color: #77695c;
font: 12px/1.45 Arial, sans-serif;
letter-spacing: 0.035em;
}
.controls {
position: fixed;
top: 20px;
right: 20px;
z-index: 3;
display: flex;
align-items: center;
gap: 10px;
color: #55493e;
font: 11px/1 Arial, sans-serif;
letter-spacing: 0.06em;
}
.controls span {
padding: 9px 11px;
background: rgba(245, 238, 225, 0.75);
border: 1px solid rgba(77, 60, 43, 0.13);
backdrop-filter: blur(8px);
pointer-events: none;
}
button {
padding: 9px 12px;
color: #55493e;
background: rgba(245, 238, 225, 0.9);
border: 1px solid rgba(77, 60, 43, 0.18);
border-radius: 0;
font: 11px/1 Arial, sans-serif;
letter-spacing: 0.06em;
cursor: pointer;
}
button:hover { background: #fff9ed; }
@media (max-width: 650px) {
.caption { left: 14px; bottom: 14px; }
.controls { top: 12px; right: 12px; }
.controls span { display: none; }
}
</style>
</head>
<body>
<div class="caption">
<div class="eyebrow">Voxel architectural study</div>
<h1>Malá Strana</h1>
<p>Prague · vertical stucco facade, arched stone portal, stepped threshold and rising cobbled paving.</p>
</div>
<div class="controls">
<span>DRAG TO ORBIT · SCROLL TO ZOOM</span>
<button id="reset" type="button">RESET VIEW</button>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xded7c9);
scene.fog = new THREE.Fog(0xded7c9, 29, 58);
const camera = new THREE.PerspectiveCamera(
35,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xfff5df, 0x796c62, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0d3, 4.2);
sun.position.set(-9, 16, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 42;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb7c8d3, 0.85);
fill.position.set(11, 7, -7);
scene.add(fill);
// -------------------------------------------------------------------------
// Shared geometry and materials
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const material = (color, roughness = 0.86, extra = {}) =>
new THREE.MeshStandardMaterial({ color, roughness, ...extra });
const M = {
instance: material(0xffffff),
plaster: material(0xc99873, 0.94),
plasterLight: material(0xd8ad88, 0.94),
cornice: material(0xd8c3a5, 0.9),
stone: material(0xb9ad99, 0.96),
stoneLight: material(0xcdc2ae, 0.95),
stoneDark: material(0x938978, 0.98),
base: material(0x756d62, 0.96),
baseEdge: material(0x5e5a54, 0.98),
substrate: material(0x807a6f, 1.0),
wood: material(0x6d3e28, 0.83),
woodLight: material(0x805039, 0.82),
dark: material(0x211c18, 0.98),
recess: material(0x171311, 1.0),
iron: material(0x282724, 0.58, { metalness: 0.35 }),
glass: material(0x34484a, 0.32, { metalness: 0.12 }),
shutter: material(0x486963, 0.82),
brass: material(0xc09345, 0.38, { metalness: 0.68 }),
glow: material(0xffc56c, 0.48, {
emissive: 0xff8b2e,
emissiveIntensity: 1.7
}),
terracotta: material(0xa85c3e, 0.95),
leaf: material(0x506b43, 0.96),
leafLight: material(0x728754, 0.96)
};
function addBox(w, h, d, x, y, z, mat, rz = 0, ry = 0, cast = true) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.rotation.set(0, ry, rz);
mesh.castShadow = cast;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function makeInstances(entries, mat, castShadow = true) {
if (!entries.length) return null;
const mesh = new THREE.InstancedMesh(unitBox, mat, entries.length);
const dummy = new THREE.Object3D();
entries.forEach((entry, index) => {
dummy.position.set(entry.x, entry.y, entry.z);
dummy.scale.set(entry.w, entry.h, entry.d);
dummy.rotation.set(0, entry.ry || 0, entry.rz || 0);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
if (entry.color) {
mesh.setColorAt(index, entry.color);
}
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function seededRandom(seed) {
return function () {
seed |= 0;
seed = seed + 0x6D2B79F5 | 0;
let t = Math.imul(seed ^ seed >>> 15, 1 | seed);
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
return ((t ^ t >>> 14) >>> 0) / 4294967296;
};
}
const random = seededRandom(1701);
// -------------------------------------------------------------------------
// Diorama base
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(120, 120),
material(0xded7c9, 1.0)
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.39;
ground.receiveShadow = true;
scene.add(ground);
addBox(15.75, 0.56, 10.9, 0, -1.08, 1.45, M.base, 0, 0, false);
addBox(15.45, 0.18, 10.62, 0, -1.39, 1.45, M.baseEdge, 0, 0, false);
// -------------------------------------------------------------------------
// Rising paving: the facade remains fixed while the street rises to the right
// -------------------------------------------------------------------------
function pavingHeight(x, z) {
const across = (x + 7.5) / 15;
const frontRise = Math.max(0, z - 1.6) * 0.012;
const irregularity = Math.sin(x * 1.37 + z * 0.47) * 0.018;
const height = -0.08 + across * 1.25 + frontRise + irregularity;
return Math.round(height / 0.055) * 0.055;
}
const pavingEntries = [];
const substrateEntries = [];
const pavingPalette = [
0x777772, 0x88877f, 0x98958a, 0x696d6a,
0xa09a8e, 0x817c72, 0x8d918b
];
const pavingCell = 0.58;
const pavingColumns = 26;
const pavingRows = 18;
for (let ix = 0; ix < pavingColumns; ix++) {
for (let iz = 0; iz < pavingRows; iz++) {
const x = -7.54 + (ix + 0.5) * pavingCell;
const z = -3.44 + (iz + 0.5) * pavingCell;
const top = pavingHeight(x, z);
const color = new THREE.Color(
pavingPalette[Math.floor(random() * pavingPalette.length)]
);
color.offsetHSL(
(random() - 0.5) * 0.018,
(random() - 0.5) * 0.05,
(random() - 0.5) * 0.07
);
pavingEntries.push({
x, y: top - 0.105, z,
w: pavingCell - 0.045,
h: 0.21,
d: pavingCell - 0.045,
color
});
const fillBottom = -0.79;
const fillTop = top - 0.195;
substrateEntries.push({
x,
y: (fillBottom + fillTop) * 0.5,
z,
w: pavingCell - 0.008,
h: fillTop - fillBottom,
d: pavingCell - 0.008
});
}
}
makeInstances(substrateEntries, M.substrate, false);
makeInstances(pavingEntries, M.instance, true);
// Pale curb stones wrap around the raised front-right corner.
const curbEntries = [];
for (let ix = 0; ix < pavingColumns; ix++) {
const x = -7.54 + (ix + 0.5) * pavingCell;
const z = 6.55;
curbEntries.push({
x,
y: pavingHeight(x, z) + 0.10,
z,
w: pavingCell - 0.025,
h: 0.30,
d: 0.34
});
}
for (let iz = 0; iz < pavingRows; iz++) {
const z = -3.44 + (iz + 0.5) * pavingCell;
const x = 7.62;
curbEntries.push({
x,
y: pavingHeight(x, z) + 0.10,
z,
w: 0.34,
h: 0.30,
d: pavingCell - 0.025
});
}
makeInstances(curbEntries, M.stoneLight, true);
// A lighter diagonal seam makes the corner read as an old paved junction.
const seamEntries = [];
for (let i = 0; i < 14; i++) {
const t = i / 13;
const x = THREE.MathUtils.lerp(3.55, 7.35, t);
const z = THREE.MathUtils.lerp(3.55, 6.32, t);
seamEntries.push({
x,
y: pavingHeight(x, z) + 0.018,
z,
w: 0.29,
h: 0.035,
d: 0.29,
rz: Math.PI / 4
});
}
makeInstances(seamEntries, M.stoneLight, false);
// -------------------------------------------------------------------------
// Vertical stucco facade
// -------------------------------------------------------------------------
const DOOR_X = -1.9;
const DOOR_THRESHOLD = 1.0;
const ARCH_SPRING = 3.28;
const INNER_RADIUS = 1.42;
const wallEntries = [];
const wallBaseColor = new THREE.Color(0xc99772);
const cell = 0.62;
const wallColumns = 25;
const wallRows = 16;
function archTopAt(x) {
const dx = Math.abs(x - DOOR_X);
if (dx >= INNER_RADIUS) return ARCH_SPRING;
return ARCH_SPRING + Math.sqrt(
INNER_RADIUS * INNER_RADIUS - dx * dx
);
}
for (let ix = 0; ix < wallColumns; ix++) {
for (let iy = 0; iy < wallRows; iy++) {
const x = -7.75 + (ix + 0.5) * cell;
const y = -0.42 + (iy + 0.5) * cell;
// Approximate the arched opening through the voxel wall.
const inDoorWidth = Math.abs(x - DOOR_X) < INNER_RADIUS - 0.06;
const belowArch = y < archTopAt(x) - 0.05;
const aboveThreshold = y > DOOR_THRESHOLD - 0.12;
if (inDoorWidth && belowArch && aboveThreshold) continue;
const color = wallBaseColor.clone();
color.offsetHSL(
(random() - 0.5) * 0.014,
(random() - 0.5) * 0.055,
(random() - 0.5) * 0.075
);
wallEntries.push({
x,
y,
z: -3.65,
w: cell - 0.012,
h: cell - 0.012,
d: 0.52,
color
});
}
}
makeInstances(wallEntries, M.instance, true);
// Stone plinth along the bottom of the vertical facade.
const plinthEntries = [];
for (let ix = 0; ix < wallColumns; ix++) {
const x = -7.75 + (ix + 0.5) * cell;
if (Math.abs(x - DOOR_X) < INNER_RADIUS + 0.18) continue;
plinthEntries.push({
x,
y: -0.27,
z: -3.35,
w: cell - 0.018,
h: 0.75,
d: 0.64
});
}
makeInstances(plinthEntries, M.stone, true);
// Heavy cornice and thin roof lip.
addBox(15.9, 0.25, 0.90, 0, 9.54, -3.48, M.cornice);
addBox(15.45, 0.15, 1.03, 0, 9.77, -3.53, M.stoneLight);
addBox(14.9, 0.12, 0.68, 0, 9.91, -3.63, M.baseEdge);
// Pale corner quoins.
for (const x of [-7.44, 7.44]) {
for (let i = 0; i < 12; i++) {
addBox(
0.58, 0.56, 0.28,
x,
0.02 + i * 0.76,
-3.34,
i % 2 ? M.stone : M.stoneLight
);
}
}
// -------------------------------------------------------------------------
// Recessed arched doorway and wooden double door
// -------------------------------------------------------------------------
const doorPlanks = 12;
const doorWidth = INNER_RADIUS * 2;
for (let i = 0; i < doorPlanks; i++) {
const x = DOOR_X - doorWidth / 2 + (i + 0.5) * (doorWidth / doorPlanks);
const top = archTopAt(x);
const h = top - DOOR_THRESHOLD;
// Dark masonry visible in the recess behind the leaves.
addBox(
doorWidth / doorPlanks + 0.015,
h,
0.16,
x,
DOOR_THRESHOLD + h / 2,
-3.82,
M.recess,
0, 0, false
);
// Voxelized wooden leaves.
addBox(
doorWidth / doorPlanks - 0.018,
h,
0.13,
x,
DOOR_THRESHOLD + h / 2,
-3.51,
i % 3 === 0 ? M.woodLight : M.wood
);
}
// Door rails.
addBox(2.72, 0.12, 0.12, DOOR_X, 1.78, -3.40, M.woodLight);
addBox(2.72, 0.12, 0.12, DOOR_X, 2.88, -3.40, M.woodLight);
// Center seam and simple brass handles.
addBox(0.035, 2.35, 0.07, DOOR_X, 2.15, -3.39, M.dark, 0, 0, false);
addBox(0.07, 0.29, 0.11, DOOR_X - 0.17, 2.28, -3.34, M.brass);
addBox(0.07, 0.29, 0.11, DOOR_X + 0.17, 2.28, -3.34, M.brass);
// Stone jambs.
for (const side of [-1, 1]) {
for (let i = 0; i < 5; i++) {
addBox(
0.54,
0.59,
0.44,
DOOR_X + side * 1.69,
DOOR_THRESHOLD + 0.29 + i * 0.58,
-3.18,
i % 2 ? M.stone : M.stoneLight
);
}
}
// Radial voxel voussoirs around the arch.
const archBlocks = 15;
for (let i = 0; i < archBlocks; i++) {
const angle = (i / (archBlocks - 1)) * Math.PI;
const radius = 1.70;
const x = DOOR_X + Math.cos(angle) * radius;
const y = ARCH_SPRING + Math.sin(angle) * radius;
addBox(
0.45,
0.60,
0.45,
x,
y,
-3.17,
i % 2 ? M.stone : M.stoneLight,
angle - Math.PI / 2
);
}
// Keystone.
addBox(0.56, 0.76, 0.49, DOOR_X, ARCH_SPRING + 1.78, -3.15, M.stoneLight);
// Threshold and three broad stone steps.
addBox(3.20, 0.22, 0.31, DOOR_X, 0.94, -3.31, M.stoneLight);
addBox(3.66, 1.79, 0.62, DOOR_X, 0.105, -3.07, M.stone);
addBox(3.58, 1.53, 0.62, DOOR_X, -0.035, -2.45, M.stoneLight);
addBox(3.50, 1.27, 0.62, DOOR_X, -0.175, -1.83, M.stone);
// -------------------------------------------------------------------------
// Baroque-style facade windows
// -------------------------------------------------------------------------
function addWindow(x, y, w = 1.25, h = 2.0) {
const frameZ = -3.18;
addBox(w * 0.78, h * 0.79, 0.08, x, y, -3.31, M.glass, 0, 0, false);
addBox(0.22, h + 0.25, 0.34, x - w / 2, y, frameZ, M.stoneLight);
addBox(0.22, h + 0.25, 0.34, x + w / 2, y, frameZ, M.stoneLight);
addBox(w + 0.30, 0.23, 0.36, x, y + h / 2, frameZ, M.stoneLight);
addBox(w + 0.42, 0.18, 0.52, x, y - h / 2 - 0.10, -3.08, M.stone);
addBox(0.075, h * 0.80, 0.10, x, y, -3.14, M.wood);
addBox(w * 0.80, 0.075, 0.10, x, y + 0.08, -3.14, M.wood);
// Projecting muted-green shutters.
addBox(
0.40, h * 0.88, 0.11,
x - w * 0.63, y, -3.03,
M.shutter, 0, -0.28
);
addBox(
0.40, h * 0.88, 0.11,
x + w * 0.63, y, -3.03,
M.shutter, 0, 0.28
);
}
addWindow(1.42, 3.72, 1.25, 2.02);
addWindow(4.92, 3.72, 1.25, 2.02);
addWindow(1.42, 7.02, 1.02, 1.68);
addWindow(4.92, 7.02, 1.02, 1.68);
// Small blue house-number plaque with voxel numerals.
addBox(0.48, 0.62, 0.10, 0.05, 2.62, -3.12, material(0x294f68, 0.75));
addBox(0.045, 0.26, 0.035, -0.05, 2.63, -3.045, M.stoneLight, 0, 0, false);
addBox(0.18, 0.045, 0.035, 0.13, 2.76, -3.045, M.stoneLight, 0, 0, false);
addBox(0.045, 0.27, 0.035, 0.21, 2.64, -3.045, M.stoneLight, 0, 0, false);
// -------------------------------------------------------------------------
// Wall lantern
// -------------------------------------------------------------------------
addBox(0.11, 0.65, 0.11, -4.03, 3.75, -3.20, M.iron);
addBox(0.12, 0.12, 0.52, -4.03, 4.05, -2.99, M.iron);
addBox(0.40, 0.52, 0.40, -4.03, 3.66, -2.77, M.iron);
addBox(0.28, 0.36, 0.28, -4.03, 3.66, -2.74, M.glow, 0, 0, false);
addBox(0.53, 0.12, 0.53, -4.03, 3.98, -2.77, M.iron);
addBox(0.46, 0.10, 0.46, -4.03, 3.34, -2.77, M.iron);
const lanternLight = new THREE.PointLight(0xffa64c, 14, 4.2, 2);
lanternLight.position.set(-4.03, 3.60, -2.45);
scene.add(lanternLight);
// -------------------------------------------------------------------------
// Small street-life details
// -------------------------------------------------------------------------
const planterX = -5.43;
const planterZ = -1.42;
const planterGround = pavingHeight(planterX, planterZ);
addBox(
0.82, 0.66, 0.82,
planterX, planterGround + 0.33, planterZ,
M.terracotta
);
addBox(
0.93, 0.14, 0.93,
planterX, planterGround + 0.68, planterZ,
M.stoneDark
);
const foliage = [
[-0.13, 1.12, 0.00, 0.46, 0.58, 0.47, M.leaf],
[ 0.22, 1.18, 0.06, 0.42, 0.50, 0.44, M.leafLight],
[ 0.00, 1.51,-0.08, 0.45, 0.43, 0.43, M.leaf],
[-0.22, 1.39, 0.14, 0.38, 0.37, 0.38, M.leafLight],
[ 0.20, 1.57, 0.17, 0.34, 0.35, 0.35, M.leaf]
];
for (const [dx, dy, dz, w, h, d, mat] of foliage) {
addBox(
w, h, d,
planterX + dx,
planterGround + dy,
planterZ + dz,
mat
);
}
// Bollard on the rising side of the pavement.
const bollardX = 5.65;
const bollardZ = 4.60;
const bollardGround = pavingHeight(bollardX, bollardZ);
addBox(
0.34, 0.72, 0.34,
bollardX, bollardGround + 0.36, bollardZ,
M.stoneDark
);
addBox(
0.43, 0.12, 0.43,
bollardX, bollardGround + 0.76, bollardZ,
M.stone
);
// A few darker replacement cobbles for texture.
const accentPavers = [];
for (let i = 0; i < 22; i++) {
const x = -6.8 + random() * 13.1;
const z = -0.8 + random() * 6.6;
const top = pavingHeight(x, z);
accentPavers.push({
x,
y: top - 0.103,
z,
w: 0.50,
h: 0.205,
d: 0.50,
rz: (random() - 0.5) * 0.04
});
}
makeInstances(accentPavers, M.stoneDark, true);
// -------------------------------------------------------------------------
// Camera controls implemented locally, without Three.js addons
// -------------------------------------------------------------------------
const view = {
target: new THREE.Vector3(-0.15, 2.45, 0.95),
radius: 22.0,
theta: 0.58,
phi: 1.08
};
const initialView = {
radius: 22.0,
theta: 0.58,
phi: 1.08
};
function updateCamera() {
const sinPhi = Math.sin(view.phi);
camera.position.set(
view.target.x + view.radius * sinPhi * Math.sin(view.theta),
view.target.y + view.radius * Math.cos(view.phi),
view.target.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(view.target);
}
function resetView() {
view.radius = initialView.radius;
view.theta = initialView.theta;
view.phi = initialView.phi;
updateCamera();
}
updateCamera();
const canvas = renderer.domElement;
const pointers = new Map();
let lastPinchDistance = 0;
function pinchDistance() {
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.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
lastPinchDistance = pinchDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
view.theta -= dx * 0.005;
view.phi = THREE.MathUtils.clamp(
view.phi - dy * 0.0045,
0.48,
1.38
);
} else if (pointers.size === 2) {
const distance = pinchDistance();
if (lastPinchDistance > 0 && distance > 0) {
view.radius = THREE.MathUtils.clamp(
view.radius * (lastPinchDistance / distance),
10.5,
34
);
}
lastPinchDistance = distance;
}
updateCamera();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
lastPinchDistance = pointers.size === 2 ? pinchDistance() : 0;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("lostpointercapture", releasePointer);
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius * Math.exp(event.deltaY * 0.001),
10.5,
34
);
updateCamera();
}, { passive: false });
canvas.addEventListener("dblclick", resetView);
window.addEventListener("keydown", (event) => {
const step = 0.08;
if (event.key === "ArrowLeft") view.theta += step;
if (event.key === "ArrowRight") view.theta -= step;
if (event.key === "ArrowUp") view.phi = Math.max(0.48, view.phi - step * 0.6);
if (event.key === "ArrowDown") view.phi = Math.min(1.38, view.phi + step * 0.6);
if (event.key === "+" || event.key === "=") view.radius = Math.max(10.5, view.radius - 1);
if (event.key === "-" || event.key === "_") view.radius = Math.min(34, view.radius + 1);
updateCamera();
});
document.getElementById("reset").addEventListener("click", resetView);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```