Prompt specification
Build or customize the Three.js 3D scene "The Rocks lane and harbor-edge slice" 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: The Rocks lane and harbor-edge slice
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/the-rocks-lane-and-harbor-edge-slice-x3031
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: The Rocks lane and harbor-edge slice. Build a bounded voxel scene with selected referenced sandstone buildings, stairs, market edge, and partial harbor view. Avoid inserting a complete opera house or bridge merely as decoration. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (the-rocks-lane-and-harbor-edge-slice-x3031):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>The Rocks — Lane & Harbor Edge</title>
<style>
:root {
color-scheme: dark;
--ink: #f5ead7;
--muted: #c8bba8;
--glass: rgba(25, 31, 32, 0.76);
--line: rgba(242, 216, 175, 0.25);
--accent: #e6b56f;
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: #aebfc2;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.panel {
position: fixed;
z-index: 10;
color: var(--ink);
background: var(--glass);
border: 1px solid var(--line);
box-shadow: 0 12px 35px rgba(16, 22, 23, 0.18);
backdrop-filter: blur(12px);
}
#title {
top: 22px;
left: 22px;
width: min(370px, calc(100vw - 44px));
padding: 18px 20px 16px;
border-radius: 4px;
}
.eyebrow {
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 7px;
font-size: clamp(24px, 4vw, 39px);
font-weight: 750;
line-height: 0.98;
letter-spacing: -0.035em;
}
#title p {
margin: 0;
max-width: 310px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
#key {
right: 22px;
bottom: 22px;
padding: 13px 15px;
border-radius: 4px;
color: var(--muted);
font-size: 11px;
line-height: 1.75;
text-align: right;
}
#key strong {
color: var(--ink);
font-weight: 650;
}
#reset {
position: fixed;
z-index: 11;
right: 22px;
top: 22px;
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 4px;
color: var(--ink);
background: var(--glass);
cursor: pointer;
font: inherit;
font-size: 11px;
letter-spacing: 0.04em;
backdrop-filter: blur(12px);
}
#reset:hover {
border-color: var(--accent);
color: #fff2dc;
}
#legend {
position: fixed;
z-index: 10;
left: 22px;
bottom: 22px;
display: grid;
gap: 7px;
padding: 12px 14px;
border-radius: 4px;
color: var(--muted);
background: rgba(25, 31, 32, 0.65);
border: 1px solid var(--line);
backdrop-filter: blur(10px);
font-size: 10px;
letter-spacing: 0.04em;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
}
.swatch {
width: 9px;
height: 9px;
background: var(--c);
box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
color: #eee2cf;
background: #263033;
font-size: 11px;
letter-spacing: .18em;
text-transform: uppercase;
transition: opacity .35s ease;
}
#loading.done {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
#title {
top: 14px;
left: 14px;
width: calc(100vw - 82px);
padding: 14px 15px;
}
#title p { display: none; }
#reset {
top: 14px;
right: 14px;
}
#legend { display: none; }
#key {
right: 14px;
bottom: 14px;
padding: 9px 11px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel scene of The Rocks lane and harbor edge"></canvas>
<section id="title" class="panel">
<div class="eyebrow">Sydney · sandstone precinct</div>
<h1>The Rocks<br />Lane & Harbor Edge</h1>
<p>
A bounded voxel study of narrow lanes, selected sandstone terraces,
market stalls, harbor stairs, and a partial working-waterfront view.
</p>
</section>
<section id="legend" class="panel">
<div class="legend-row"><span class="swatch" style="--c:#ca985d"></span> Sandstone terraces</div>
<div class="legend-row"><span class="swatch" style="--c:#a85f43"></span> Market edge</div>
<div class="legend-row"><span class="swatch" style="--c:#547f87"></span> Working harbor</div>
</section>
<div id="key" class="panel">
<strong>DRAG</strong> orbit · <strong>WHEEL</strong> zoom<br />
<strong>SHIFT / RIGHT-DRAG</strong> pan · <strong>DOUBLE-CLICK</strong> reset
</div>
<button id="reset" type="button">Reset view</button>
<div id="loading">Building the lane…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const loading = document.getElementById("loading");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb6c6c7);
scene.fog = new THREE.Fog(0xb6c6c7, 67, 112);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
180
);
const target = new THREE.Vector3(0, 4.1, 0);
const spherical = new THREE.Spherical(59, 1.02, 0.66);
function updateCamera() {
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xdce9e8, 0x76604a, 1.65);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffd29b, 3.25);
sun.position.set(-27, 38, 24);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -35;
sun.shadow.camera.right = 35;
sun.shadow.camera.top = 31;
sun.shadow.camera.bottom = -31;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 95;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8eb8c4, 0.75);
fill.position.set(26, 18, -24);
scene.add(fill);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.88,
metalness: options.metalness ?? 0,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0
});
const M = {
plinth: material(0x343d3d),
plinthTop: material(0x515653),
sandstone: material(0xca985d),
sandstoneLight: material(0xd8ad72),
sandstonePale: material(0xe0b982),
sandstoneDark: material(0xa96f42),
mortar: material(0xb17b4c),
roof: material(0x3d4547),
roofLight: material(0x596160),
window: material(0x243238, { roughness: 0.35 }),
windowFrame: material(0x765842),
wood: material(0x72503a),
woodLight: material(0x9b724b),
darkMetal: material(0x323b3d, { roughness: 0.55, metalness: 0.35 }),
cream: material(0xe8d8b8),
rust: material(0xa9583d),
green: material(0x56734f),
red: material(0xac4939),
yellow: material(0xd6a544),
water: material(0x507f88, { roughness: 0.32, metalness: 0.16 }),
waterDark: material(0x3e6d78, { roughness: 0.36, metalness: 0.12 }),
waterLight: material(0x6e9da0, { roughness: 0.4 }),
lamp: material(0xffd792, {
roughness: 0.4,
emissive: 0xffb34d,
emissiveIntensity: 2.1
})
};
function addBox(parent, mat, w, h, d, x, y, z, cast = true, receive = true) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
let seed = 82471;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
const LAND = 3.6;
// Bounded, stepped diorama base.
addBox(scene, M.plinth, 50, 0.75, 38, 0, -0.75, 0, false, true);
addBox(scene, M.plinthTop, 49.2, 0.55, 37.2, 0, -0.10, 0, false, true);
// Land masses leave a cut for the descending stair.
addBox(scene, M.sandstoneDark, 29, LAND, 36, -10, LAND / 2, 0, false, true);
addBox(scene, M.sandstoneDark, 7, LAND, 19, 8, LAND / 2, -8.5, false, true);
addBox(scene, M.sandstoneDark, 4.5, LAND, 36, 13.75, LAND / 2, 0, false, true);
addBox(scene, M.sandstoneDark, 7, 0.55, 7, 8, 0.275, 14.5, false, true);
// Harbor water is built from broad voxel-like strips.
addBox(scene, M.water, 2, 0.34, 36, 17, 0.17, 0, false, true);
addBox(scene, M.waterDark, 2, 0.35, 36, 19, 0.175, 0, false, true);
addBox(scene, M.water, 2, 0.36, 36, 21, 0.18, 0, false, true);
addBox(scene, M.waterDark, 2, 0.37, 36, 23, 0.185, 0, false, true);
// Lane paving.
const paving = [
material(0xa88661),
material(0xb39168),
material(0x9f7d59),
material(0xc09b70)
];
for (let row = 0; row < 35; row++) {
for (let col = 0; col < 6; col++) {
const x = -2.65 + col * 1.02;
const z = -17 + row * 1.01;
const height = 0.08 + random() * 0.055;
addBox(
scene,
paving[Math.floor(random() * paving.length)],
0.91,
height,
0.91,
x,
LAND + height / 2 + 0.01,
z,
false,
true
);
}
}
// A darker drainage line runs through the lane.
for (let z = -17; z <= 17; z += 1) {
addBox(scene, M.darkMetal, 0.13, 0.045, 0.9, 0, LAND + 0.075, z, false, true);
}
function addBuilding({
x, z, w, d, h, floors = 3,
body = M.sandstone,
trim = M.sandstoneLight,
attic = false
}) {
const g = new THREE.Group();
g.position.set(x, 0, z);
scene.add(g);
addBox(g, body, w, h, d, 0, LAND + h / 2, 0);
addBox(g, M.sandstoneDark, w + 0.25, 0.42, d + 0.25, 0, LAND + 0.18, 0);
addBox(g, trim, w + 0.16, 0.28, d + 0.16, 0, LAND + h - 0.1, 0);
// Horizontal stone courses give each façade a voxel masonry rhythm.
for (let floor = 1; floor < floors; floor++) {
const y = LAND + floor * (h / floors);
addBox(g, M.mortar, w + 0.08, 0.13, 0.11, 0, y, d / 2 + 0.045);
addBox(g, M.mortar, w + 0.08, 0.13, 0.11, 0, y, -d / 2 - 0.045);
addBox(g, M.mortar, 0.11, 0.13, d + 0.08, w / 2 + 0.045, y, 0);
addBox(g, M.mortar, 0.11, 0.13, d + 0.08, -w / 2 - 0.045, y, 0);
}
const floorHeight = h / floors;
function southWindow(px, py) {
addBox(g, M.window, 1.02, 1.28, 0.12, px, py, d / 2 + 0.09);
addBox(g, trim, 1.25, 0.13, 0.24, px, py - 0.69, d / 2 + 0.12);
addBox(g, M.windowFrame, 0.07, 1.22, 0.08, px, py, d / 2 + 0.17);
addBox(g, M.windowFrame, 0.95, 0.06, 0.08, px, py + 0.05, d / 2 + 0.17);
}
function eastWindow(pz, py) {
addBox(g, M.window, 0.12, 1.28, 1.02, w / 2 + 0.09, py, pz);
addBox(g, trim, 0.24, 0.13, 1.25, w / 2 + 0.12, py - 0.69, pz);
addBox(g, M.windowFrame, 0.08, 1.22, 0.07, w / 2 + 0.17, py, pz);
addBox(g, M.windowFrame, 0.08, 0.06, 0.95, w / 2 + 0.17, py + 0.05, pz);
}
for (let floor = 0; floor < floors; floor++) {
const y = LAND + floorHeight * floor + floorHeight * 0.57;
const southCount = Math.max(2, Math.floor(w / 2.15));
for (let i = 0; i < southCount; i++) {
const px = -w / 2 + 1.25 + i * ((w - 2.5) / Math.max(1, southCount - 1));
southWindow(px, y);
}
const eastCount = Math.max(2, Math.floor(d / 2.2));
for (let i = 0; i < eastCount; i++) {
const pz = -d / 2 + 1.15 + i * ((d - 2.3) / Math.max(1, eastCount - 1));
eastWindow(pz, y);
}
}
// Street-level doorway.
addBox(g, M.window, 1.35, 2.35, 0.14, -w * 0.25, LAND + 1.2, d / 2 + 0.10);
addBox(g, trim, 1.65, 0.16, 0.28, -w * 0.25, LAND + 2.48, d / 2 + 0.14);
addBox(g, M.woodLight, 0.11, 0.11, 0.12, -w * 0.25 + 0.38, LAND + 1.15, d / 2 + 0.20);
// Alternating corner stones.
for (let i = 0; i < Math.floor(h / 0.72); i++) {
const y = LAND + 0.42 + i * 0.72;
const offset = i % 2 === 0 ? -0.12 : 0.12;
for (const sx of [-1, 1]) {
addBox(
g,
trim,
0.5,
0.48,
0.30,
sx * (w / 2 - 0.28) + offset,
y,
d / 2 + 0.16
);
}
for (const sz of [-1, 1]) {
addBox(
g,
trim,
0.30,
0.48,
0.5,
w / 2 + 0.16,
y,
sz * (d / 2 - 0.28) - offset
);
}
}
// Layered roof and a few chimney stacks.
addBox(g, M.roof, w + 0.55, 0.34, d + 0.55, 0, LAND + h + 0.12, 0);
addBox(g, M.roofLight, w * 0.68, 0.18, d * 0.68, -0.2, LAND + h + 0.35, 0);
if (attic) {
addBox(g, body, w * 0.34, 1.7, d * 0.32, -w * 0.18, LAND + h + 1.05, 0);
addBox(g, M.roof, w * 0.38, 0.22, d * 0.36, -w * 0.18, LAND + h + 2.0, 0);
}
const chimneys = Math.max(1, Math.floor(w / 5));
for (let i = 0; i < chimneys; i++) {
const cx = -w * 0.3 + i * ((w * 0.6) / Math.max(1, chimneys - 1));
addBox(g, M.sandstoneDark, 0.78, 1.45, 0.78, cx, LAND + h + 0.95, -d * 0.2);
addBox(g, M.roof, 0.94, 0.18, 0.94, cx, LAND + h + 1.72, -d * 0.2);
}
return g;
}
// Selected sandstone buildings rather than a continuous architectural replica.
addBuilding({
x: -16, z: -10, w: 10, d: 9, h: 12.5, floors: 4,
body: M.sandstone, trim: M.sandstonePale, attic: true
});
addBuilding({
x: -8, z: -11, w: 6.5, d: 8, h: 10.5, floors: 3,
body: M.sandstoneLight, trim: M.sandstonePale
});
addBuilding({
x: -16, z: 7, w: 11, d: 10, h: 9, floors: 3,
body: M.sandstoneDark, trim: M.sandstone
});
addBuilding({
x: -8, z: 6, w: 6, d: 11, h: 9.5, floors: 3,
body: M.sandstone, trim: M.sandstoneLight
});
addBuilding({
x: 9, z: -12, w: 8, d: 9, h: 11, floors: 3,
body: M.sandstoneDark, trim: M.sandstonePale
});
addBuilding({
x: 9, z: -4, w: 7, d: 6, h: 7.5, floors: 2,
body: M.sandstone, trim: M.sandstoneLight
});
// Harbor stair descending from the upper lane toward the working quay.
const stairCount = 11;
for (let i = 0; i < stairCount; i++) {
const top = 3.55 - i * 0.30;
const z = 1.25 + i * 0.90;
addBox(scene, M.sandstone, 7.45, top, 0.89, 8, top / 2, z, false, true);
addBox(scene, M.sandstoneLight, 7.48, 0.11, 0.11, 8, top + 0.03, z + 0.40, false, true);
// Stepped handrails on both sides.
for (const x of [4.18, 11.82]) {
addBox(scene, M.darkMetal, 0.12, 0.12, 0.88, x, top + 1.02, z, true, true);
if (i % 2 === 0) {
addBox(scene, M.darkMetal, 0.13, 0.95, 0.13, x, top + 0.50, z - 0.18, true, true);
}
}
}
// Market edge: three compact stalls with striped voxel awnings.
function marketStall(z, accent) {
const g = new THREE.Group();
g.position.set(-4.2, 0, z);
scene.add(g);
for (const x of [-0.78, 0.78]) {
for (const zz of [-1.25, 1.25]) {
addBox(g, M.wood, 0.12, 3.25, 0.12, x, LAND + 1.62, zz);
}
}
addBox(g, M.woodLight, 1.65, 0.18, 2.7, 0, LAND + 0.92, 0);
addBox(g, M.wood, 0.18, 0.75, 0.18, -0.62, LAND + 0.38, -0.95);
addBox(g, M.wood, 0.18, 0.75, 0.18, 0.62, LAND + 0.38, 0.95);
for (let i = 0; i < 6; i++) {
const zz = -1.27 + i * 0.51;
const rise = (1.5 - Math.abs(i - 2.5) * 0.37) * 0.08;
addBox(
g,
i % 2 === 0 ? M.cream : accent,
1.95,
0.15,
0.50,
0,
LAND + 3.25 + rise,
zz
);
}
addBox(g, M.wood, 1.85, 0.15, 0.16, 0, LAND + 3.02, -1.3);
addBox(g, M.wood, 1.85, 0.15, 0.16, 0, LAND + 3.02, 1.3);
const produce = [M.red, M.yellow, M.green, accent];
for (let ix = 0; ix < 2; ix++) {
for (let iz = 0; iz < 4; iz++) {
const px = -0.38 + ix * 0.76;
const pz = -0.88 + iz * 0.58;
addBox(g, M.woodLight, 0.62, 0.32, 0.48, px, LAND + 1.16, pz);
for (let k = 0; k < 3; k++) {
addBox(
g,
produce[(ix + iz + k) % produce.length],
0.16,
0.16,
0.16,
px - 0.17 + k * 0.17,
LAND + 1.40,
pz + (k % 2 ? 0.08 : -0.06)
);
}
}
}
}
marketStall(2.8, M.rust);
marketStall(7.0, M.green);
marketStall(11.4, M.rust);
// Market storage and hand carts.
for (let i = 0; i < 7; i++) {
const x = -4.2 + (i % 2) * 0.62;
const z = 0.3 + i * 0.53;
addBox(scene, i % 3 === 0 ? M.woodLight : M.wood, 0.52, 0.48, 0.52, x, LAND + 0.25, z);
}
// Lamp posts with warm cube lights.
for (const z of [-15, -6, 3.6, 15]) {
addBox(scene, M.darkMetal, 0.14, 3.55, 0.14, 3.65, LAND + 1.78, z);
addBox(scene, M.darkMetal, 0.75, 0.12, 0.12, 3.32, LAND + 3.48, z);
addBox(scene, M.lamp, 0.34, 0.38, 0.34, 3.02, LAND + 3.29, z, false, false);
addBox(scene, M.darkMetal, 0.48, 0.12, 0.48, 3.02, LAND + 3.54, z);
}
// Segmented harbor retaining wall.
for (let i = 0; i < 15; i++) {
const z = -17.3 + i * 2.46;
addBox(
scene,
i % 2 ? M.sandstoneDark : M.sandstone,
0.38,
3.38,
2.28,
15.91,
1.72,
z,
false,
true
);
addBox(scene, M.sandstoneLight, 0.62, 0.25, 2.42, 15.88, 3.69, z);
}
// Bollards and short quay ropes.
for (let i = 0; i < 5; i++) {
const z = -14 + i * 7;
addBox(scene, M.darkMetal, 0.38, 0.78, 0.38, 15.18, LAND + 0.4, z);
addBox(scene, M.darkMetal, 0.55, 0.16, 0.55, 15.18, LAND + 0.82, z);
if (i < 4) {
addBox(scene, M.woodLight, 0.07, 0.07, 6.85, 15.26, LAND + 0.58, z + 3.5);
}
}
// Cargo on the quay.
const crateStack = [
[13.8, -11.5, 1, 1],
[14.5, -11.3, 1, 2],
[13.9, 4.0, 1, 2],
[14.7, 4.2, 1, 1],
[13.8, 13.0, 1, 1],
[14.6, 13.2, 1, 2]
];
for (const [x, z, w, levels] of crateStack) {
for (let level = 0; level < levels; level++) {
addBox(
scene,
level % 2 ? M.wood : M.woodLight,
w,
0.72,
0.86,
x,
LAND + 0.37 + level * 0.72,
z
);
}
}
// A small working launch: the harbor remains a partial, functional edge.
const boat = new THREE.Group();
boat.position.set(20.1, 0.37, 7.2);
boat.rotation.y = -0.12;
scene.add(boat);
addBox(boat, M.darkMetal, 2.15, 0.65, 4.5, 0, 0.30, 0);
addBox(boat, M.roof, 1.65, 0.32, 3.2, 0, 0.75, -0.05);
addBox(boat, M.cream, 1.45, 1.2, 1.55, 0, 1.35, -0.45);
addBox(boat, M.window, 1.52, 0.58, 0.10, 0, 1.52, 0.34);
addBox(boat, M.darkMetal, 0.12, 3.5, 0.12, 0.25, 2.35, -0.8);
addBox(boat, M.rust, 1.45, 0.16, 0.18, 0.25, 3.75, -0.8);
// Voxel reflections and short water glints.
for (let i = 0; i < 74; i++) {
const x = 16.45 + random() * 7.05;
const z = -17.2 + random() * 34.4;
const w = 0.35 + random() * 1.75;
const d = 0.06 + random() * 0.10;
addBox(
scene,
random() > 0.56 ? M.waterLight : M.waterDark,
w,
0.035,
d,
x,
0.39,
z,
false,
false
);
}
// Small planters at the southern edge.
function planter(x, z) {
addBox(scene, M.sandstoneDark, 1.15, 0.52, 1.15, x, LAND + 0.26, z);
addBox(scene, M.wood, 0.12, 1.45, 0.12, x, LAND + 1.05, z);
addBox(scene, M.green, 0.92, 0.85, 0.92, x, LAND + 1.58, z);
addBox(scene, M.green, 0.62, 0.55, 0.62, x + 0.18, LAND + 2.08, z - 0.1);
}
planter(-21.8, 15.6);
planter(13.3, 16.4);
// Direct camera controls: orbit, zoom, and pan.
let dragging = false;
let panning = false;
let previousX = 0;
let previousY = 0;
let pointerId = null;
function resetView() {
target.set(0, 4.1, 0);
spherical.set(59, 1.02, 0.66);
updateCamera();
}
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
panning = event.button === 2 || event.shiftKey;
previousX = event.clientX;
previousY = event.clientY;
pointerId = event.pointerId;
canvas.setPointerCapture(pointerId);
});
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;
if (panning) {
camera.updateMatrixWorld();
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const scale = spherical.radius * 0.00155;
target.addScaledVector(right, -dx * scale);
target.addScaledVector(up, dy * scale);
target.x = THREE.MathUtils.clamp(target.x, -13, 13);
target.y = THREE.MathUtils.clamp(target.y, 1.0, 9.0);
target.z = THREE.MathUtils.clamp(target.z, -13, 13);
} else {
spherical.theta -= dx * 0.006;
spherical.phi = THREE.MathUtils.clamp(spherical.phi - dy * 0.005, 0.34, 1.39);
}
});
function endDrag(event) {
if (event.pointerId !== pointerId) return;
dragging = false;
panning = false;
if (canvas.hasPointerCapture(pointerId)) canvas.releasePointerCapture(pointerId);
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
spherical.radius = THREE.MathUtils.clamp(
spherical.radius * Math.exp(event.deltaY * 0.001),
31,
84
);
}, { passive: false });
canvas.addEventListener("dblclick", resetView);
document.getElementById("reset").addEventListener("click", resetView);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
});
renderer.setAnimationLoop(() => {
updateCamera();
renderer.render(scene, camera);
if (!loading.classList.contains("done")) {
loading.classList.add("done");
setTimeout(() => loading.remove(), 400);
}
});
</script>
</body>
</html>
```