Prompt specification
Build or customize the Three.js 3D scene "Stair landing above a shopfront" 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: Stair landing above a shopfront
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/stair-landing-above-a-shopfront-x2313
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a Roman insula shopfront and exterior stair. Model a compact masonry shopfront with an exterior stair reaching an upper landing. Keep the shop entrance and residential access separate in the visible geometry. Stylized solid forms.
Working Three.js Starter (stair-landing-above-a-shopfront-x2313):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Roman Insula Shopfront</title>
<style>
:root {
color-scheme: light;
--ink: #30261f;
--paper: rgba(248, 241, 225, 0.91);
--accent: #9d4f32;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #bed5dc;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas.dragging {
cursor: grabbing;
}
.title-card {
position: fixed;
top: 24px;
left: 24px;
max-width: min(390px, calc(100vw - 48px));
padding: 17px 20px 16px;
background: var(--paper);
border: 1px solid rgba(75, 55, 38, 0.28);
border-left: 5px solid var(--accent);
box-shadow: 0 12px 30px rgba(55, 40, 26, 0.16);
pointer-events: none;
backdrop-filter: blur(5px);
}
.title-card h1 {
margin: 0 0 5px;
font-size: clamp(21px, 3vw, 31px);
font-weight: 600;
letter-spacing: 0.02em;
}
.title-card p {
margin: 0;
font: 13px/1.45 Arial, sans-serif;
color: #67594c;
}
.legend {
position: fixed;
right: 22px;
bottom: 22px;
display: grid;
gap: 8px;
padding: 12px 14px;
background: var(--paper);
border: 1px solid rgba(75, 55, 38, 0.24);
box-shadow: 0 8px 24px rgba(55, 40, 26, 0.13);
font: 12px/1.2 Arial, sans-serif;
pointer-events: none;
}
.legend div {
display: flex;
align-items: center;
gap: 9px;
}
.swatch {
width: 13px;
height: 13px;
border-radius: 2px;
border: 1px solid rgba(0, 0, 0, 0.22);
}
.shop {
background: #c79b57;
}
.home {
background: #8e4832;
}
.help {
position: fixed;
left: 22px;
bottom: 22px;
display: flex;
align-items: center;
gap: 12px;
padding: 10px 12px;
background: rgba(248, 241, 225, 0.86);
border: 1px solid rgba(75, 55, 38, 0.22);
font: 12px Arial, sans-serif;
color: #5c5045;
}
button {
border: 1px solid #806b55;
background: #f2e8d7;
color: #44362b;
padding: 7px 10px;
cursor: pointer;
font: 11px Arial, sans-serif;
}
button:hover {
background: #fff9ed;
}
@media (max-width: 650px) {
.title-card {
top: 12px;
left: 12px;
padding: 12px 14px;
}
.title-card p {
display: none;
}
.legend {
right: 12px;
bottom: 12px;
}
.help {
left: 12px;
bottom: 12px;
}
.help span {
display: none;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive three-dimensional Roman insula shopfront"></div>
<section class="title-card">
<h1>Insula Shopfront</h1>
<p>
A compact masonry taberna with a broad street-level entrance. The
domestic access, stone stair, and upper landing occupy a separate
bay on the right.
</p>
</section>
<section class="legend" aria-label="Building legend">
<div><span class="swatch shop"></span> TABERNA · commercial entrance</div>
<div><span class="swatch home"></span> DOMUS · residential access</div>
</section>
<div class="help">
<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 mount = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({ antialias: true });
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;
renderer.domElement.setAttribute("aria-label", "Roman masonry building");
mount.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xbed5dc);
scene.fog = new THREE.Fog(0xbed5dc, 29, 58);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const clock = new THREE.Clock();
const hemisphere = new THREE.HemisphereLight(0xd9eef4, 0x806344, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe2b3, 3.5);
sun.position.set(-8, 15, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
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(0x9dc9dc, 0.85);
fill.position.set(11, 8, -10);
scene.add(fill);
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const material = {
limestone: new THREE.MeshStandardMaterial({
color: 0xd7bb89,
roughness: 0.93
}),
limestoneLight: new THREE.MeshStandardMaterial({
color: 0xe7d0a5,
roughness: 0.88
}),
limestoneDark: new THREE.MeshStandardMaterial({
color: 0xb99464,
roughness: 0.96
}),
mortar: new THREE.MeshStandardMaterial({
color: 0xa98760,
roughness: 1
}),
stair: new THREE.MeshStandardMaterial({
color: 0xc4a677,
roughness: 0.94
}),
terracotta: new THREE.MeshStandardMaterial({
color: 0xad5c3b,
roughness: 0.86
}),
wood: new THREE.MeshStandardMaterial({
color: 0x593b2b,
roughness: 0.82
}),
woodLight: new THREE.MeshStandardMaterial({
color: 0x80583a,
roughness: 0.85
}),
interior: new THREE.MeshStandardMaterial({
color: 0x27211d,
roughness: 1
}),
iron: new THREE.MeshStandardMaterial({
color: 0x302c28,
roughness: 0.58,
metalness: 0.38
}),
ground: new THREE.MeshStandardMaterial({
color: 0xb7aa91,
roughness: 1
}),
street: new THREE.MeshStandardMaterial({
color: 0x817b70,
roughness: 1
}),
green: new THREE.MeshStandardMaterial({
color: 0x596b43,
roughness: 0.95
})
};
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
function addMesh(geometry, mat, x = 0, y = 0, z = 0, cast = true) {
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function box(w, h, d, mat, x = 0, y = 0, z = 0, cast = true) {
return addMesh(
new THREE.BoxGeometry(w, h, d),
mat,
x,
y,
z,
cast
);
}
function cylinder(rTop, rBottom, h, mat, x, y, z, segments = 12) {
return addMesh(
new THREE.CylinderGeometry(rTop, rBottom, h, segments),
mat,
x,
y,
z
);
}
function archGeometry(width, height) {
const radius = width / 2;
const springHeight = Math.max(0.001, height - radius);
const shape = new THREE.Shape();
shape.moveTo(-radius, 0);
shape.lineTo(radius, 0);
shape.lineTo(radius, springHeight);
shape.absarc(0, springHeight, radius, 0, Math.PI, false);
shape.lineTo(-radius, 0);
return new THREE.ShapeGeometry(shape, 32);
}
function archMesh(width, height, mat, cx, baseY, z = 0.055) {
const mesh = addMesh(
archGeometry(width, height),
mat,
cx,
baseY,
z
);
return mesh;
}
function addArchFrame(cx, baseY, width, height) {
const radius = width / 2;
const springY = baseY + height - radius;
const jambHeight = height - radius;
box(
0.25,
jambHeight,
0.3,
material.limestoneLight,
cx - radius - 0.125,
baseY + jambHeight / 2,
0.14
);
box(
0.25,
jambHeight,
0.3,
material.limestoneLight,
cx + radius + 0.125,
baseY + jambHeight / 2,
0.14
);
const blockCount = 11;
const frameRadius = radius + 0.135;
for (let i = 0; i < blockCount; i++) {
const angle = (i / (blockCount - 1)) * Math.PI;
const block = box(
0.28,
0.34,
0.3,
material.limestoneLight,
cx + Math.cos(angle) * frameRadius,
springY + Math.sin(angle) * frameRadius,
0.14
);
block.rotation.z = angle;
}
}
function addMasonryJoints(x0, x1, y0, y1) {
const courseHeight = 0.44;
for (let row = 0, y = y0; y < y1 - 0.03; y += courseHeight, row++) {
if (y > y0 + 0.03) {
box(
x1 - x0,
0.023,
0.022,
material.mortar,
(x0 + x1) / 2,
y,
0.018,
false
);
}
const offset = row % 2 === 0 ? 0.32 : 0.91;
for (let x = x0 + offset; x < x1 - 0.12; x += 1.2) {
box(
0.024,
courseHeight * 0.9,
0.022,
material.mortar,
x,
y + courseHeight / 2,
0.019,
false
);
}
}
}
function makeTextTexture(text, background = "#513425", foreground = "#efd7a4") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 160;
const context = canvas.getContext("2d");
context.fillStyle = background;
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = foreground;
context.lineWidth = 7;
context.strokeRect(13, 13, canvas.width - 26, canvas.height - 26);
context.fillStyle = foreground;
context.font = "700 58px Georgia, serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(4, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function addLabel(text, width, height, x, y, z) {
const texture = makeTextTexture(text);
const mat = new THREE.MeshBasicMaterial({ map: texture });
return addMesh(
new THREE.PlaneGeometry(width, height),
mat,
x,
y,
z,
false
);
}
function addAmphora(x, y, z, scale = 1) {
const profile = [
new THREE.Vector2(0.12, 0),
new THREE.Vector2(0.21, 0.08),
new THREE.Vector2(0.25, 0.38),
new THREE.Vector2(0.19, 0.58),
new THREE.Vector2(0.09, 0.73),
new THREE.Vector2(0.11, 0.9),
new THREE.Vector2(0.07, 1.0)
];
const amphora = addMesh(
new THREE.LatheGeometry(profile, 12),
material.terracotta,
x,
y,
z
);
amphora.scale.setScalar(scale);
const handleGeometry = new THREE.TorusGeometry(
0.13 * scale,
0.026 * scale,
6,
12,
Math.PI
);
const leftHandle = addMesh(
handleGeometry,
material.terracotta,
x - 0.13 * scale,
y + 0.72 * scale,
z
);
leftHandle.rotation.z = -0.15;
const rightHandle = addMesh(
handleGeometry,
material.terracotta,
x + 0.13 * scale,
y + 0.72 * scale,
z
);
rightHandle.rotation.z = Math.PI + 0.15;
}
// -------------------------------------------------------------------------
// Ground and Roman street
// -------------------------------------------------------------------------
const ground = addMesh(
new THREE.PlaneGeometry(90, 90),
material.ground,
0,
-0.09,
0,
false
);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
box(34, 0.08, 21, material.street, 0, -0.055, 6, false);
// Deterministic random placement for the cobbles.
let randomState = 32917;
function random() {
randomState |= 0;
randomState = (randomState + 0x6d2b79f5) | 0;
let value = Math.imul(randomState ^ (randomState >>> 15), 1 | randomState);
value = (value + Math.imul(value ^ (value >>> 7), 61 | value)) ^ value;
return ((value ^ (value >>> 14)) >>> 0) / 4294967296;
}
const cobbleGeometry = new THREE.BoxGeometry(0.5, 0.07, 0.38);
const cobbleMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1
});
const cobbles = new THREE.InstancedMesh(
cobbleGeometry,
cobbleMaterial,
250
);
const cobbleTransform = new THREE.Object3D();
const cobbleColor = new THREE.Color();
for (let i = 0; i < 250; i++) {
const row = Math.floor(i / 14);
const column = i % 14;
cobbleTransform.position.set(
-12.2 + column * 1.05 + (random() - 0.5) * 0.15,
-0.005 + random() * 0.012,
2.0 + row * 0.73 + (random() - 0.5) * 0.13
);
cobbleTransform.rotation.set(
0,
(random() - 0.5) * 0.09,
0
);
cobbleTransform.scale.set(
0.9 + random() * 0.2,
0.85 + random() * 0.25,
0.9 + random() * 0.2
);
cobbleTransform.updateMatrix();
cobbles.setMatrixAt(i, cobbleTransform.matrix);
cobbleColor.setHSL(
0.09,
0.06 + random() * 0.05,
0.39 + random() * 0.12
);
cobbles.setColorAt(i, cobbleColor);
}
cobbles.instanceMatrix.needsUpdate = true;
cobbles.instanceColor.needsUpdate = true;
cobbles.castShadow = true;
cobbles.receiveShadow = true;
scene.add(cobbles);
// -------------------------------------------------------------------------
// Main masonry shell
// -------------------------------------------------------------------------
const buildingWidth = 12.8;
const facadeZ = 0;
const buildingDepth = 4.2;
// Upper storey.
box(
buildingWidth,
4.2,
buildingDepth,
material.limestone,
0,
5.1,
-buildingDepth / 2
);
// Ground-floor wall segments leave a genuine opening for the taberna.
box(2.2, 3.0, buildingDepth, material.limestone, -5.3, 1.5, -2.1);
box(5.7, 3.0, buildingDepth, material.limestone, 3.55, 1.5, -2.1);
// Masonry courses and staggered joints.
addMasonryJoints(-6.35, 6.35, 3.03, 7.15);
addMasonryJoints(-6.35, -4.2, 0.04, 2.98);
addMasonryJoints(0.72, 6.35, 0.04, 2.98);
// Foundation and plinth.
box(2.3, 0.22, 4.4, material.limestoneDark, -5.3, 0.11, -2.08);
box(5.8, 0.22, 4.4, material.limestoneDark, 3.55, 0.11, -2.08);
// Corner pilasters emphasize the compact block.
box(0.42, 7.15, 0.38, material.limestoneLight, -6.18, 3.575, 0.18);
box(0.42, 7.15, 0.38, material.limestoneLight, 6.18, 3.575, 0.18);
// Cornice, tiled coping, and low roof parapet.
box(13.35, 0.25, 4.75, material.limestoneLight, 0, 7.25, -2.02);
box(13.05, 0.18, 4.48, material.terracotta, 0, 7.44, -2.06);
box(12.85, 0.5, 0.3, material.limestone, 0, 7.68, -0.04);
box(0.3, 0.5, 4.25, material.limestone, -6.25, 7.68, -2.08);
box(0.3, 0.5, 4.25, material.limestone, 6.25, 7.68, -2.08);
// Small dentils below the cornice.
for (let x = -6.0; x <= 6.0; x += 0.55) {
box(0.21, 0.16, 0.25, material.limestoneLight, x, 7.03, 0.19);
}
// -------------------------------------------------------------------------
// Shop interior and taberna entrance
// -------------------------------------------------------------------------
// Recessed room visible through the broad shop opening.
box(4.85, 0.1, 1.75, material.interior, -1.75, 0.04, -0.87, false);
box(4.85, 2.9, 0.12, material.interior, -1.75, 1.45, -1.75, false);
box(0.12, 2.9, 1.7, material.interior, -4.08, 1.45, -0.86, false);
box(0.12, 2.9, 1.7, material.interior, 0.58, 1.45, -0.86, false);
// Interior shelving.
for (let y = 0.55; y <= 2.25; y += 0.55) {
box(3.6, 0.09, 0.28, material.wood, -1.95, y, -1.48);
}
box(1.55, 0.82, 0.7, material.wood, -0.28, 0.42, 0.18);
box(1.7, 0.12, 0.78, material.limestoneLight, -0.28, 0.89, 0.18);
addAmphora(-0.7, 0.95, 0.15, 0.63);
addAmphora(-0.28, 0.95, -0.02, 0.52);
addAmphora(0.12, 0.95, 0.16, 0.58);
const shopLight = new THREE.PointLight(0xffb45d, 11, 5.2, 2);
shopLight.position.set(-1.8, 1.8, 0.05);
scene.add(shopLight);
function addTuscanColumn(x) {
box(0.48, 0.18, 0.5, material.limestoneLight, x, 0.17, 0.2);
cylinder(0.15, 0.19, 2.08, material.limestoneLight, x, 1.3, 0.2, 14);
box(0.48, 0.18, 0.5, material.limestoneLight, x, 2.43, 0.2);
box(0.55, 0.14, 0.56, material.limestoneLight, x, 2.56, 0.2);
}
addTuscanColumn(-4.02);
addTuscanColumn(0.52);
box(5.0, 0.25, 0.55, material.limestoneLight, -1.75, 2.78, 0.19);
box(5.15, 0.13, 0.62, material.limestone, -1.75, 2.96, 0.17);
// Threshold separates the public street from the shop floor.
box(4.82, 0.09, 0.75, material.limestoneDark, -1.75, 0.055, 0.3, false);
// Hanging TABERNA sign.
const signGroup = new THREE.Group();
signGroup.position.set(-1.75, 3.34, 0.5);
scene.add(signGroup);
const signBoard = new THREE.Mesh(
new THREE.BoxGeometry(1.95, 0.49, 0.12),
material.wood
);
signBoard.castShadow = true;
signGroup.add(signBoard);
const signFace = new THREE.Mesh(
new THREE.PlaneGeometry(1.82, 0.4),
new THREE.MeshBasicMaterial({ map: makeTextTexture("TABERNA") })
);
signFace.position.z = 0.066;
signGroup.add(signFace);
box(0.035, 0.38, 0.035, material.iron, -2.43, 3.73, 0.5);
box(0.035, 0.38, 0.035, material.iron, -1.07, 3.73, 0.5);
// -------------------------------------------------------------------------
// Upper windows
// -------------------------------------------------------------------------
function addUpperWindow(cx, baseY) {
const width = 1.03;
const height = 1.68;
archMesh(width, height, material.interior, cx, baseY, 0.057);
addArchFrame(cx, baseY, width, height);
// Timber shutters folded against the opening.
box(0.27, 1.08, 0.12, material.woodLight, cx - 0.68, baseY + 0.58, 0.19);
box(0.27, 1.08, 0.12, material.woodLight, cx + 0.68, baseY + 0.58, 0.19);
for (let y = baseY + 0.2; y < baseY + 1.1; y += 0.25) {
box(0.025, 0.2, 0.015, material.wood, cx - 0.68, y, 0.258, false);
box(0.025, 0.2, 0.015, material.wood, cx + 0.68, y, 0.258, false);
}
box(1.46, 0.12, 0.36, material.limestoneLight, cx, baseY - 0.02, 0.16);
}
addUpperWindow(-3.75, 4.33);
addUpperWindow(-0.25, 4.33);
addUpperWindow(2.72, 4.33);
// -------------------------------------------------------------------------
// Residential doors, stair, and upper landing
// -------------------------------------------------------------------------
function addResidentialDoor(cx, baseY, width, height) {
archMesh(width, height, material.interior, cx, baseY, 0.058);
archMesh(
width * 0.88,
height * 0.94,
material.wood,
cx,
baseY + 0.035,
0.075
);
addArchFrame(cx, baseY, width, height);
// Door seam and iron handle.
box(0.018, height * 0.67, 0.014, material.woodLight, cx, baseY + 0.72, 0.089, false);
const handle = addMesh(
new THREE.SphereGeometry(0.055, 10, 8),
material.iron,
cx + width * 0.28,
baseY + 0.92,
0.13
);
handle.scale.z = 0.55;
}
// Ground-level domestic entry, clearly separated from the shop.
addResidentialDoor(5.72, 0.12, 0.98, 2.18);
// Upper domestic door reached by the exterior stair.
addResidentialDoor(5.7, 3.18, 1.08, 2.2);
// Stone stair: solid, block-like steps rising from left to right.
const stepCount = 11;
const stepRise = 0.28;
const stepRun = 0.38;
const stairStart = 1.25;
const stairCenterZ = 0.82;
for (let i = 0; i < stepCount; i++) {
const top = (i + 1) * stepRise;
const x = stairStart + (i + 0.5) * stepRun;
box(
stepRun,
top,
1.5,
material.stair,
x,
top / 2,
stairCenterZ
);
box(
stepRun + 0.012,
0.065,
1.57,
material.limestoneLight,
x,
top + 0.025,
stairCenterZ
);
// Low outer cheek wall, built as a sequence of solid blocks.
box(
stepRun + 0.008,
0.24,
0.2,
material.limestoneDark,
x,
top + 0.1,
1.61
);
}
const landingTop = stepCount * stepRise + 0.06;
box(
1.28,
0.22,
1.72,
material.limestoneLight,
5.84,
landingTop - 0.11,
0.82
);
// A small corbel emphasizes that this is an exterior landing.
box(
0.44,
0.5,
0.46,
material.limestoneDark,
6.15,
landingTop - 0.38,
1.38
);
// Labels identify the two functions without replacing the architecture.
addLabel("DOMUS", 0.63, 0.2, 6.17, 2.48, 0.14);
addLabel("DOMUS", 0.61, 0.2, 4.67, 4.23, 0.14);
// -------------------------------------------------------------------------
// Small street props
// -------------------------------------------------------------------------
// Low planters near the shop threshold.
function addPlanter(x, z) {
cylinder(0.34, 0.27, 0.42, material.terracotta, x, 0.21, z, 10);
const foliage = addMesh(
new THREE.IcosahedronGeometry(0.35, 1),
material.green,
x,
0.68,
z
);
foliage.scale.set(0.85, 1.15, 0.85);
}
addPlanter(-4.65, 0.62);
addPlanter(-0.02, 0.63);
// A narrow street drain.
box(11.7, 0.025, 0.11, material.iron, -0.2, 0.01, 1.88, false);
// -------------------------------------------------------------------------
// Direct camera controls — no external controls module
// -------------------------------------------------------------------------
const target = new THREE.Vector3(-0.15, 2.85, 0.15);
const initialView = {
azimuth: 0.47,
polar: 1.245,
radius: 19.2
};
let azimuth = initialView.azimuth;
let polar = initialView.polar;
let radius = initialView.radius;
let dragging = false;
let previousX = 0;
let previousY = 0;
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);
}
function resetView() {
azimuth = initialView.azimuth;
polar = initialView.polar;
radius = initialView.radius;
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
azimuth -= deltaX * 0.006;
polar = THREE.MathUtils.clamp(polar + deltaY * 0.005, 0.7, 1.46);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
function stopDragging(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (event.pointerId !== undefined) {
try {
renderer.domElement.releasePointerCapture(event.pointerId);
} catch (_) {
// Pointer capture may already have been released.
}
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(
radius * Math.exp(event.deltaY * 0.001),
12,
30
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
document.querySelector("#reset").addEventListener("click", resetView);
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 = Math.max(0.7, polar - 0.06);
break;
case "ArrowDown":
polar = Math.min(1.46, polar + 0.06);
break;
case "+":
case "=":
radius = Math.max(12, radius - 0.8);
break;
case "-":
radius = Math.min(30, radius + 0.8);
break;
case "r":
case "R":
resetView();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
updateCamera();
function animate() {
const elapsed = clock.getElapsedTime();
// A restrained sign sway gives the scene a subtle sense of life.
signGroup.rotation.z = Math.sin(elapsed * 0.85) * 0.012;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```