Prompt specification
Build or customize the Three.js 3D scene "Sidi Bou Said doorway and stair threshold" 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: Sidi Bou Said doorway and stair threshold
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/sidi-bou-said-doorway-and-stair-threshold-x2953
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts the hillside lanes of Sidi Bou Said. Build a referenced blue doorway with white wall and short stone steps. Show how the threshold responds to a sloping street without copying a specific private home's decoration exactly. Voxel style.
Working Three.js Starter (sidi-bou-said-doorway-and-stair-threshold-x2953):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Sidi Bou Said — Hillside Threshold</title>
<style>
:root {
color-scheme: light;
--ink: #153d52;
--blue: #1767a5;
--paper: rgba(248, 243, 226, 0.92);
--line: rgba(21, 61, 82, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #91cbd6;
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
display: block;
touch-action: none;
}
.panel {
position: fixed;
z-index: 10;
color: var(--ink);
background: var(--paper);
border: 1px solid var(--line);
box-shadow: 0 12px 35px rgba(19, 54, 70, 0.16);
backdrop-filter: blur(10px);
}
#intro {
top: 18px;
left: 18px;
width: min(360px, calc(100vw - 36px));
padding: 18px 19px 16px;
border-radius: 3px;
}
.eyebrow {
margin-bottom: 7px;
color: var(--blue);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 4vw, 37px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.025em;
}
.subtitle {
margin: 10px 0 0;
color: #315f73;
font-size: 12px;
font-weight: 750;
letter-spacing: 0.09em;
text-transform: uppercase;
}
#intro p {
margin: 13px 0 15px;
color: #355667;
font-size: 13px;
line-height: 1.55;
}
.actions {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
button {
appearance: none;
border: 1px solid rgba(23, 103, 165, 0.35);
border-radius: 2px;
padding: 9px 12px;
color: #124f78;
background: rgba(255, 255, 255, 0.62);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
}
button:hover {
color: white;
background: var(--blue);
}
button:focus-visible {
outline: 3px solid rgba(241, 184, 75, 0.65);
outline-offset: 2px;
}
#controls {
right: 18px;
bottom: 18px;
max-width: min(320px, calc(100vw - 36px));
padding: 11px 14px;
border-radius: 3px;
color: #355667;
font-size: 11px;
line-height: 1.55;
}
#controls strong {
color: var(--ink);
}
#labels {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
transition: opacity 180ms ease;
}
#labels.hidden {
display: none;
}
.label {
position: absolute;
padding: 5px 8px;
color: #183f51;
background: rgba(255, 249, 230, 0.94);
border-left: 3px solid #e6a433;
box-shadow: 0 4px 14px rgba(20, 50, 65, 0.14);
font-size: 11px;
font-weight: 750;
line-height: 1.25;
white-space: nowrap;
transform: translate(-50%, -50%);
}
#label-upper {
transform: translate(8px, -125%);
}
#label-landing {
transform: translate(-115%, -70%);
}
#label-risers {
transform: translate(12px, -20%);
}
#label-lower {
transform: translate(10px, 25%);
}
#label-hill {
transform: translate(-50%, -125%);
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
color: var(--ink);
background: #91cbd6;
font-size: 13px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.done {
opacity: 0;
pointer-events: none;
}
@media (max-width: 650px) {
#intro {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 14px;
}
#intro p {
margin: 10px 0 12px;
font-size: 12px;
}
#controls {
right: 10px;
bottom: 10px;
max-width: calc(100vw - 20px);
}
.label {
font-size: 9px;
}
}
</style>
</head>
<body>
<section id="intro" class="panel" aria-label="Scene description">
<div class="eyebrow">Architectural vignette</div>
<h1>Sidi Bou Said</h1>
<div class="subtitle">Hillside threshold study</div>
<p>
A generic cobalt doorway meets a steep lane with a level landing and
three shallow stone risers. Whitewashed massing, blue accents, and
stepped forms evoke the town without reproducing a specific home.
</p>
<div class="actions">
<button id="gradeButton" type="button">Hide grade guides</button>
<button id="resetButton" type="button">Reset view</button>
</div>
</section>
<aside id="controls" class="panel">
<strong>Controls</strong> — drag to orbit · wheel or pinch to zoom ·
arrow keys to rotate · R to reset
</aside>
<div id="labels" aria-hidden="true">
<div id="label-upper" class="label">Upper lane · +2.20 m</div>
<div id="label-landing" class="label">Level door landing</div>
<div id="label-risers" class="label">Three shallow risers</div>
<div id="label-lower" class="label">Lower lane · +1.10 m</div>
<div id="label-hill" class="label">Lane rises uphill</div>
</div>
<div id="loading">Building the hillside…</div>
<script type="module">
// Only the Three.js core ES module is used.
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x91cbd6);
scene.fog = new THREE.Fog(0x91cbd6, 35, 88);
const camera = new THREE.PerspectiveCamera(
41,
innerWidth / innerHeight,
0.1,
140
);
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
} catch (error) {
document.querySelector("#loading").textContent =
"This scene requires a browser with WebGL enabled.";
throw error;
}
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, 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", "Interactive voxel hillside scene");
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xe9fbff, 0x8a735e, 2.05);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1d2, 3.1);
sun.position.set(-10, 19, 13);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -28;
sun.shadow.camera.right = 28;
sun.shadow.camera.top = 28;
sun.shadow.camera.bottom = -28;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9ed9ee, 0.65);
fill.position.set(12, 8, -14);
scene.add(fill);
const material = (color, roughness = 0.9, extra = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness,
metalness: 0,
...extra
});
const mats = {
white: material(0xf7f0df),
whiteWarm: material(0xeee4cf),
whiteCool: material(0xe9ece7),
blue: material(0x1767a5),
blueLight: material(0x2581bb),
blueDark: material(0x0f4f82),
blueRecess: material(0x123d60),
stone: material(0xb9aa91),
stoneLight: material(0xd1c1a2),
stoneDark: material(0x8d826f),
paving: material(0xffffff, 0.98),
earth: material(0x9c8e76),
green: material(0x536f54),
greenLight: material(0x718566),
bronze: material(0x8f6c3e, 0.48, { metalness: 0.42 }),
sea: material(0x3e9fbd, 0.42)
};
function box(
width,
height,
depth,
x,
y,
z,
mat,
parent = scene,
castShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Deterministic variation for paving and small details.
function mulberry32(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 = mulberry32(481516);
/*
The lane is a sequence of broad voxel terraces.
It rises in the negative Z direction, toward the upper village.
*/
const laneSegments = [
{ z0: -14, z1: -6, level: 3.3 },
{ z0: -6, z1: 2, level: 2.2 },
{ z0: 2, z1: 10, level: 1.1 },
{ z0: 10, z1: 18, level: 0 }
];
const laneWidth = 9;
// Stone road cores and raised side terraces.
laneSegments.forEach((segment, index) => {
const depth = segment.z1 - segment.z0;
const centerZ = (segment.z0 + segment.z1) / 2;
const supportHeight = segment.level + 2.5;
const supportY = segment.level - supportHeight / 2;
box(
laneWidth,
supportHeight,
depth,
0,
supportY,
centerZ,
index % 2 ? mats.earth : mats.stoneDark,
scene,
false
);
// Right and left retaining shoulders.
box(
4.4,
supportHeight,
depth,
6.75,
supportY,
centerZ,
mats.earth,
scene,
false
);
box(
4.4,
supportHeight,
depth,
-6.75,
supportY,
centerZ,
mats.earth,
scene,
false
);
// A narrow central drainage channel.
box(
0.28,
0.08,
depth - 0.2,
0,
segment.level + 0.02,
centerZ,
mats.stoneDark,
scene,
false
);
});
// Individual pavers are instanced for performance.
const paverGeometry = new THREE.BoxGeometry(0.66, 0.14, 0.66);
const paverMatrices = [];
const paverColors = [];
const dummy = new THREE.Object3D();
const color = new THREE.Color();
laneSegments.forEach((segment) => {
const columns = 12;
const rows = Math.floor((segment.z1 - segment.z0) / 0.72);
for (let column = 0; column < columns; column++) {
for (let row = 0; row < rows; row++) {
const x = -3.95 + column * 0.72;
const z = segment.z0 + 0.36 + row * 0.72;
if (Math.abs(x) < 0.31) continue;
dummy.position.set(
x + (random() - 0.5) * 0.025,
segment.level + 0.08,
z + (random() - 0.5) * 0.025
);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(
0.93 + random() * 0.08,
0.92 + random() * 0.08,
0.93 + random() * 0.08
);
dummy.updateMatrix();
paverMatrices.push(dummy.matrix.clone());
color.setHSL(
0.105 + (random() - 0.5) * 0.025,
0.12 + random() * 0.04,
0.61 + (random() - 0.5) * 0.12
);
paverColors.push(color.clone());
}
}
});
const pavers = new THREE.InstancedMesh(
paverGeometry,
mats.paving,
paverMatrices.length
);
paverMatrices.forEach((matrix, index) => {
pavers.setMatrixAt(index, matrix);
pavers.setColorAt(index, paverColors[index]);
});
pavers.instanceMatrix.needsUpdate = true;
if (pavers.instanceColor) pavers.instanceColor.needsUpdate = true;
pavers.receiveShadow = true;
pavers.castShadow = false;
scene.add(pavers);
// Blocky curb stones.
const curbGeometry = new THREE.BoxGeometry(0.34, 0.27, 0.66);
const curbMatrices = [];
laneSegments.forEach((segment) => {
const rows = Math.floor((segment.z1 - segment.z0) / 0.72);
for (const side of [-1, 1]) {
for (let row = 0; row < rows; row++) {
dummy.position.set(
side * 4.3,
segment.level + 0.135,
segment.z0 + 0.36 + row * 0.72
);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 0.96 + random() * 0.04);
dummy.updateMatrix();
curbMatrices.push(dummy.matrix.clone());
}
}
});
const curbs = new THREE.InstancedMesh(
curbGeometry,
mats.stoneLight,
curbMatrices.length
);
curbMatrices.forEach((matrix, index) => {
curbs.setMatrixAt(index, matrix);
});
curbs.instanceMatrix.needsUpdate = true;
curbs.receiveShadow = true;
scene.add(curbs);
/*
Target composition:
a generic white wall and cobalt door on the upper edge of a
street transition. The landing stays level; three stone treads
descend to the lower lane.
*/
const doorX = 3.9;
const upperLevel = 2.2;
const lowerLevel = 1.1;
// Main building mass behind the facade.
box(
4.8,
4.6,
6.3,
4.1,
upperLevel + 2.3,
-1.35,
mats.whiteWarm
);
// White front wall.
box(
4.8,
4.6,
0.42,
4.1,
upperLevel + 2.3,
1.66,
mats.white
);
// Flat roof and simple parapet.
box(5.05, 0.24, 6.55, 4.1, upperLevel + 4.72, -1.35, mats.whiteCool);
box(5.05, 0.4, 0.28, 4.1, upperLevel + 5.0, 1.48, mats.white);
box(0.28, 0.4, 6.35, 1.83, upperLevel + 5.0, -1.4, mats.white);
box(0.28, 0.4, 6.35, 6.37, upperLevel + 5.0, -1.4, mats.white);
// A stepped white frame around the blue opening.
box(
0.32, 2.28, 0.27,
doorX - 0.92, upperLevel + 1.14, 1.94,
mats.whiteCool
);
box(
0.32, 2.28, 0.27,
doorX + 0.92, upperLevel + 1.14, 1.94,
mats.whiteCool
);
box(
0.43, 0.29, 0.27,
doorX - 0.78, upperLevel + 2.30, 1.94,
mats.whiteCool
);
box(
0.43, 0.29, 0.27,
doorX + 0.78, upperLevel + 2.30, 1.94,
mats.whiteCool
);
box(
0.45, 0.29, 0.27,
doorX - 0.53, upperLevel + 2.59, 1.94,
mats.whiteCool
);
box(
0.45, 0.29, 0.27,
doorX + 0.53, upperLevel + 2.59, 1.94,
mats.whiteCool
);
box(
0.45, 0.29, 0.27,
doorX, upperLevel + 2.88, 1.94,
mats.whiteCool
);
// Cobalt door, constructed from stacked voxel blocks.
box(
1.48, 2.15, 0.14,
doorX, upperLevel + 1.075, 1.97,
mats.blue
);
box(
1.10, 0.22, 0.14,
doorX, upperLevel + 2.26, 1.97,
mats.blue
);
box(
0.72, 0.22, 0.14,
doorX, upperLevel + 2.48, 1.97,
mats.blue
);
// Simple inset panels: intentionally generic, not a copied decoration.
box(
0.54, 1.55, 0.035,
doorX - 0.35, upperLevel + 1.08, 2.055,
mats.blueDark
);
box(
0.54, 1.55, 0.035,
doorX + 0.35, upperLevel + 1.08, 2.055,
mats.blueDark
);
box(
1.25, 0.09, 0.045,
doorX, upperLevel + 1.02, 2.075,
mats.blueLight
);
box(
0.08, 0.28, 0.11,
doorX + 0.45, upperLevel + 1.03, 2.12,
mats.bronze
);
// Small upper blue opening.
box(
0.9, 0.82, 0.13,
4.45, upperLevel + 3.48, 1.92,
mats.blueDark
);
box(
0.64, 0.22, 0.13,
4.45, upperLevel + 4.0, 1.92,
mats.blueDark
);
// Stone threshold at the exact door floor level.
box(
2.18, 0.18, 0.56,
doorX, upperLevel - 0.09, 2.15,
mats.stoneLight
);
// Level landing.
box(
2.42, 0.30, 0.60,
doorX, upperLevel - 0.15, 2.16,
mats.stoneLight
);
// Three progressively descending stone treads.
const stepDepth = 0.58;
const stepCenters = [2.75, 3.33, 3.91];
const stepTops = [
upperLevel - (upperLevel - lowerLevel) / 3,
upperLevel - 2 * (upperLevel - lowerLevel) / 3,
lowerLevel
];
stepCenters.forEach((z, index) => {
const top = stepTops[index];
const bottom = lowerLevel - 0.45;
box(
2.42,
top - bottom,
stepDepth,
doorX,
(top + bottom) / 2,
z,
index === 2 ? mats.stone : mats.stoneLight
);
// Slightly lighter nosing emphasizes the three shallow risers.
box(
2.43,
0.055,
0.08,
doorX,
top - 0.025,
z + stepDepth / 2,
mats.whiteWarm,
scene,
false
);
});
// Generic side houses with blue doors and windows.
function addSideHouse({
x,
z,
base,
width = 5.6,
depth = 7.8,
height = 4.4,
direction = 1,
offset = 0
}) {
box(width, height, depth, x, base + height / 2, z, mats.white);
// Slightly projecting upper white band.
box(
width + 0.12,
0.32,
depth + 0.12,
x,
base + height - 0.45,
z,
mats.whiteWarm
);
const faceX = x + direction * (width / 2 + 0.02);
const doorZ = z + offset;
// One simple threshold.
box(
0.65,
0.18,
1.8,
faceX + direction * 0.25,
base + 0.09,
doorZ,
mats.stoneLight
);
// Blue door on the lane-facing wall.
box(
0.13,
2.18,
1.22,
faceX + direction * 0.09,
base + 1.27,
doorZ,
mats.blue
);
box(
0.18,
2.42,
0.18,
faceX + direction * 0.11,
base + 1.39,
doorZ - 0.77,
mats.whiteCool
);
box(
0.18,
2.42,
0.18,
faceX + direction * 0.11,
base + 1.39,
doorZ + 0.77,
mats.whiteCool
);
box(
0.18,
0.20,
1.75,
faceX + direction * 0.11,
base + 2.58,
doorZ,
mats.whiteCool
);
// Small blue window above.
box(
0.12,
0.85,
0.92,
faceX + direction * 0.09,
base + 3.25,
doorZ - 1.35,
mats.blueDark
);
}
addSideHouse({
x: -7.25,
z: 8.0,
base: 1.1,
direction: 1,
offset: 0.55
});
addSideHouse({
x: -7.45,
z: -1.0,
base: 2.2,
width: 5.9,
depth: 8.7,
height: 4.8,
direction: 1,
offset: -0.4
});
addSideHouse({
x: -7.55,
z: -10.2,
base: 3.3,
width: 5.8,
depth: 7.0,
height: 4.3,
direction: 1,
offset: 0.2
});
addSideHouse({
x: 8.05,
z: -8.4,
base: 3.3,
width: 5.3,
depth: 7.4,
height: 4.7,
direction: -1,
offset: 0.4
});
addSideHouse({
x: 8.4,
z: -15.0,
base: 4.0,
width: 5.6,
depth: 6.5,
height: 4.2,
direction: -1,
offset: -0.3
});
// Distant blocky village and a blue stepped dome.
function addDistantHouse(x, z, base, width, height, depth) {
box(width, height, depth, x, base + height / 2, z, mats.white);
box(
width + 0.18,
0.22,
depth + 0.18,
x,
base + height + 0.10,
z,
mats.whiteCool
);
const openings = 2 + Math.floor(random() * 3);
for (let i = 0; i < openings; i++) {
const ox = x - width * 0.3 + (i / Math.max(1, openings - 1)) * width * 0.6;
const oy = base + height * (0.35 + random() * 0.35);
box(
0.38,
0.62,
0.09,
ox,
oy,
z + depth / 2 + 0.055,
i % 3 === 0 ? mats.blue : mats.blueDark
);
}
}
addDistantHouse(-6.7, -20.0, 4.0, 4.8, 3.5, 4.5);
addDistantHouse(-1.9, -22.5, 4.1, 4.1, 3.0, 3.8);
addDistantHouse(3.0, -21.0, 4.0, 4.7, 4.0, 4.4);
addDistantHouse(7.0, -23.0, 4.2, 4.4, 3.2, 4.0);
// A distant, stepped blue dome.
box(3.8, 2.5, 3.8, 4.5, 8.35, -17.2, mats.white);
box(3.0, 0.55, 3.0, 4.5, 9.85, -17.2, mats.blue);
box(2.2, 0.55, 2.2, 4.5, 10.4, -17.2, mats.blue);
box(1.4, 0.55, 1.4, 4.5, 10.95, -17.2, mats.blueLight);
box(0.45, 0.48, 0.45, 4.5, 11.45, -17.2, mats.blue);
// Sparse cubic greenery.
const shrubs = [
[-4.95, 2.9, 4.6],
[-5.05, 4.1, -4.7],
[5.45, 5.05, -5.8],
[6.1, 2.0, 8.5]
];
shrubs.forEach(([x, y, z], index) => {
box(
0.72,
0.72,
0.72,
x,
y,
z,
index % 2 ? mats.green : mats.greenLight
);
box(
0.42,
0.42,
0.42,
x + 0.36,
y + 0.22,
z - 0.22,
mats.green
);
});
// A distant blue-gray Mediterranean strip.
box(
120,
0.12,
45,
0,
-1.15,
-52,
mats.sea,
scene,
false
);
/*
Grade guide:
an intentionally diagrammatic vertical dimension beside the steps.
*/
const gradeGroup = new THREE.Group();
scene.add(gradeGroup);
const guideMaterial = new THREE.MeshBasicMaterial({
color: 0xf1ad3d,
transparent: true,
opacity: 0.94,
depthTest: false
});
function guideBox(w, h, d, x, y, z) {
const mesh = box(w, h, d, x, y, z, guideMaterial, gradeGroup, false);
mesh.renderOrder = 20;
return mesh;
}
guideBox(0.055, 1.1, 0.055, 5.32, 1.65, 3.17);
guideBox(1.15, 0.045, 0.055, 4.78, 2.2, 3.17);
guideBox(1.15, 0.045, 0.055, 4.78, 1.1, 3.17);
guideBox(0.18, 0.18, 0.055, 5.32, 2.12, 3.17);
guideBox(0.18, 0.18, 0.055, 5.32, 1.18, 3.17);
// Screen-space labels projected from world-space anchors.
const labelAnchors = {
"label-upper": new THREE.Vector3(5.12, 2.36, 2.2),
"label-landing": new THREE.Vector3(4.15, 2.35, 1.9),
"label-risers": new THREE.Vector3(4.9, 1.52, 3.55),
"label-lower": new THREE.Vector3(4.95, 1.22, 4.32),
"label-hill": new THREE.Vector3(-0.2, 3.75, -5.2)
};
const labelElements = Object.fromEntries(
Object.entries(labelAnchors).map(([id, anchor]) => [
id,
{ element: document.getElementById(id), anchor }
])
);
function updateLabels() {
Object.values(labelElements).forEach(({ element, anchor }) => {
const projected = anchor.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.opacity = visible ? "1" : "0";
element.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
});
}
/*
Camera controls implemented directly here so no Three.js addons are
required. The controls support orbit, wheel zoom, touch pinch,
arrow-key orbit, and reset.
*/
const controls = {
target: new THREE.Vector3(1.0, 2.45, -0.6),
radius: 26,
azimuth: 0.39,
elevation: 0.38,
minRadius: 11,
maxRadius: 43,
minElevation: 0.10,
maxElevation: 1.12
};
function updateCamera() {
const horizontal = controls.radius * Math.cos(controls.elevation);
camera.position.set(
controls.target.x + horizontal * Math.sin(controls.azimuth),
controls.target.y + controls.radius * Math.sin(controls.elevation),
controls.target.z + horizontal * Math.cos(controls.azimuth)
);
camera.lookAt(controls.target);
}
function resetCamera() {
controls.target.set(1.0, 2.45, -0.6);
controls.radius = 26;
controls.azimuth = 0.39;
controls.elevation = 0.38;
}
const pointers = new Map();
let lastPointerX = 0;
let lastPointerY = 0;
let pinchStartDistance = 0;
let pinchStartRadius = 26;
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);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
lastPointerX = event.clientX;
lastPointerY = event.clientY;
} else if (pointers.size === 2) {
pinchStartDistance = pointerDistance();
pinchStartRadius = controls.radius;
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
const distance = pointerDistance();
if (pinchStartDistance > 0) {
controls.radius = THREE.MathUtils.clamp(
pinchStartRadius * (pinchStartDistance / distance),
controls.minRadius,
controls.maxRadius
);
}
return;
}
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
controls.azimuth -= deltaX * 0.005;
controls.elevation = THREE.MathUtils.clamp(
controls.elevation + deltaY * 0.004,
controls.minElevation,
controls.maxElevation
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
});
function removePointer(event) {
pointers.delete(event.pointerId);
pinchStartDistance = 0;
if (pointers.size === 1) {
const remaining = [...pointers.values()][0];
lastPointerX = remaining.x;
lastPointerY = remaining.y;
}
}
renderer.domElement.addEventListener("pointerup", removePointer);
renderer.domElement.addEventListener("pointercancel", removePointer);
renderer.domElement.addEventListener("lostpointercapture", removePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
controls.minRadius,
controls.maxRadius
);
},
{ passive: false }
);
addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "arrowleft") controls.azimuth += 0.09;
else if (key === "arrowright") controls.azimuth -= 0.09;
else if (key === "arrowup") {
controls.elevation = THREE.MathUtils.clamp(
controls.elevation + 0.06,
controls.minElevation,
controls.maxElevation
);
} else if (key === "arrowdown") {
controls.elevation = THREE.MathUtils.clamp(
controls.elevation - 0.06,
controls.minElevation,
controls.maxElevation
);
} else if (key === "+" || key === "=") {
controls.radius = Math.max(controls.minRadius, controls.radius - 1.5);
} else if (key === "-") {
controls.radius = Math.min(controls.maxRadius, controls.radius + 1.5);
} else if (key === "r") {
resetCamera();
} else {
return;
}
event.preventDefault();
});
const gradeButton = document.getElementById("gradeButton");
const resetButton = document.getElementById("resetButton");
const labels = document.getElementById("labels");
let gradeVisible = true;
gradeButton.addEventListener("click", () => {
gradeVisible = !gradeVisible;
gradeGroup.visible = gradeVisible;
labels.classList.toggle("hidden", !gradeVisible);
gradeButton.textContent = gradeVisible
? "Hide grade guides"
: "Show grade guides";
});
resetButton.addEventListener("click", resetCamera);
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
updateCamera();
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
updateCamera();
updateLabels();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
document.getElementById("loading").classList.add("done");
}
}
animate();
</script>
</body>
</html>
```