Prompt specification
Build or customize the Three.js 3D scene "Hallgrímskirkja stepped facade rhythm fragment" 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: Hallgrímskirkja stepped facade rhythm fragment
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/hallgr-mskirkja-stepped-facade-rhythm-fragment-x2861
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: Hallgrímskirkja stepped facade rhythm fragment. Build a simplified referenced fragment of Reykjavík's church facade rhythm. Use progressively stepped vertical forms and make the small model's selective abstraction clear. Return one self-contained HTML file.
Working Three.js Starter (hallgr-mskirkja-stepped-facade-rhythm-fragment-x2861):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hallgrímskirkja — Facade Rhythm Fragment</title>
<style>
:root {
color-scheme: dark;
--ink: #e9e4d8;
--muted: #93a0a6;
--accent: #c7a66d;
--panel: rgba(10, 17, 23, 0.72);
--line: rgba(198, 213, 218, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #091117;
color: var(--ink);
font-family: Inter, "Helvetica Neue", Arial, sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.vignette,
.grain {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.vignette {
background:
radial-gradient(circle at 56% 43%, transparent 36%, rgba(3, 7, 11, 0.18) 72%, rgba(3, 7, 11, 0.64) 100%),
linear-gradient(180deg, rgba(5, 10, 15, 0.2), transparent 22%, transparent 72%, rgba(5, 10, 15, 0.34));
}
.grain {
opacity: 0.13;
background-image:
repeating-radial-gradient(circle at 20% 30%, rgba(255,255,255,0.16) 0 0.55px, transparent 0.7px 3px),
repeating-radial-gradient(circle at 70% 65%, rgba(0,0,0,0.22) 0 0.65px, transparent 0.8px 4px);
background-size: 9px 9px, 11px 11px;
mix-blend-mode: soft-light;
}
.overlay {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
}
.title-panel {
position: absolute;
top: 32px;
left: 36px;
width: min(420px, calc(100vw - 72px));
}
.eyebrow,
.spec-label,
.caption-label,
.interaction-hint,
button {
font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
text-transform: uppercase;
letter-spacing: 0.14em;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 13px;
color: var(--accent);
font-size: 10px;
font-weight: 700;
}
.eyebrow::before {
content: "";
width: 24px;
height: 1px;
background: currentColor;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(36px, 4.5vw, 66px);
font-weight: 400;
line-height: 0.95;
letter-spacing: -0.045em;
text-wrap: balance;
}
.subtitle {
margin-top: 13px;
color: #b8c0c2;
font-size: 12px;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.title-rule {
width: 100%;
height: 1px;
margin: 22px 0 16px;
background: linear-gradient(90deg, var(--line), transparent);
}
.intro {
max-width: 355px;
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.65;
}
.spec-panel {
position: absolute;
top: 34px;
right: 36px;
display: flex;
align-items: flex-start;
gap: 13px;
padding: 14px 16px;
border: 1px solid var(--line);
background: var(--panel);
backdrop-filter: blur(12px);
}
.status-dot {
width: 7px;
height: 7px;
margin-top: 5px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px rgba(199, 166, 109, 0.11);
}
.spec-label {
color: var(--accent);
font-size: 9px;
font-weight: 700;
}
.spec-value {
margin-top: 5px;
color: #c9d0d1;
font-size: 11px;
line-height: 1.5;
}
.caption {
position: absolute;
left: 36px;
bottom: 32px;
width: min(390px, calc(100vw - 72px));
padding-left: 15px;
border-left: 2px solid var(--accent);
}
.caption-label {
color: var(--accent);
font-size: 9px;
font-weight: 700;
}
.caption p {
margin: 7px 0 0;
color: #a9b4b8;
font-size: 12px;
line-height: 1.6;
}
.controls {
position: absolute;
right: 34px;
bottom: 30px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 7px;
pointer-events: auto;
}
button {
appearance: none;
min-height: 35px;
padding: 0 12px;
border: 1px solid var(--line);
border-radius: 2px;
background: rgba(10, 17, 23, 0.78);
color: #aeb9bd;
font-size: 9px;
font-weight: 700;
cursor: pointer;
backdrop-filter: blur(10px);
transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
}
button:hover,
button:focus-visible {
color: var(--ink);
border-color: rgba(199, 166, 109, 0.65);
outline: none;
}
button.active {
color: #151b1f;
border-color: var(--accent);
background: var(--accent);
}
.interaction-hint {
position: absolute;
right: 36px;
bottom: 82px;
color: rgba(166, 178, 183, 0.62);
font-size: 8px;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #091117;
color: var(--accent);
font: 10px "SFMono-Regular", Consolas, monospace;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 500ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.title-panel {
top: 22px;
left: 22px;
}
.spec-panel {
top: 22px;
right: 22px;
padding: 10px 12px;
}
.spec-value {
display: none;
}
.title-rule,
.intro {
display: none;
}
.subtitle {
max-width: 220px;
font-size: 9px;
line-height: 1.6;
}
.caption {
left: 22px;
bottom: 78px;
width: calc(100vw - 44px);
}
.caption p {
max-width: 280px;
}
.controls {
right: 20px;
bottom: 20px;
left: 20px;
justify-content: flex-start;
}
.interaction-hint {
display: none;
}
}
</style>
</head>
<body>
<div
id="scene"
role="img"
aria-label="Interactive voxel study of Hallgrímskirkja's stepped concrete facade rhythm."
></div>
<div class="vignette"></div>
<div class="grain"></div>
<main class="overlay">
<section class="title-panel">
<div class="eyebrow">Reykjavík · Iceland · 64.14° N</div>
<h1>Hallgrímskirkja</h1>
<div class="subtitle">Facade rhythm / Fragment 04</div>
<div class="title-rule"></div>
<p class="intro">
A small architectural model reduced to stepped concrete bays,
vertical compression, and the widening rhythm of the entrance facade.
</p>
</section>
<aside class="spec-panel" aria-label="Model specification">
<span class="status-dot"></span>
<div>
<div class="spec-label">Selected abstraction</div>
<div class="spec-value">
Central stepped bay + cropped side buttresses<br>
Voxel study · nominal scale 1:200
</div>
</div>
</aside>
<section class="caption">
<div class="caption-label">Interpretation, not reconstruction</div>
<p>
The nave, roof, and full elevation are omitted. Only the facade’s
repeated vertical courses and tapering silhouette are retained.
</p>
</section>
<div class="interaction-hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<nav class="controls" aria-label="Camera controls">
<button id="axonometric" class="active" type="button">Axonometric</button>
<button id="front" type="button">Front</button>
<button id="orbit" type="button" aria-pressed="true">Orbit on</button>
<button id="reset" type="button">Reset</button>
</nav>
</main>
<div id="loading">Assembling voxel study</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 container = document.getElementById("scene");
const loading = document.getElementById("loading");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 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 scene = new THREE.Scene();
scene.background = new THREE.Color(0x091117);
scene.fog = new THREE.FogExp2(0x091117, 0.028);
const camera = new THREE.PerspectiveCamera(
36,
window.innerWidth / window.innerHeight,
0.1,
100
);
const target = new THREE.Vector3(0, 2.15, 0);
const desiredView = {
theta: 0.58,
phi: 1.13,
radius: 11.8
};
const currentView = {
theta: desiredView.theta,
phi: desiredView.phi,
radius: desiredView.radius
};
let autoOrbit = true;
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xc7dbe4, 0x211b16, 1.55));
const keyLight = new THREE.DirectionalLight(0xffe2b9, 3.15);
keyLight.position.set(-5.5, 10, 7.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -3;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.00035;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x9ec9dc, 1.15);
fillLight.position.set(7, 5, -6);
scene.add(fillLight);
const edgeLight = new THREE.DirectionalLight(0xd8e6e8, 0.72);
edgeLight.position.set(-6, 4, -7);
scene.add(edgeLight);
// -------------------------------------------------------------------------
// Ground and presentation plinth
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(70, 70),
new THREE.MeshStandardMaterial({
color: 0x0d151c,
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.305;
ground.receiveShadow = true;
scene.add(ground);
const plinthMaterial = new THREE.MeshStandardMaterial({
color: 0x293239,
roughness: 0.86,
metalness: 0.04
});
const plinth = new THREE.Mesh(
new THREE.BoxGeometry(11.6, 0.28, 6.4),
plinthMaterial
);
plinth.position.y = -0.14;
plinth.castShadow = true;
plinth.receiveShadow = true;
scene.add(plinth);
const plinthCap = new THREE.Mesh(
new THREE.BoxGeometry(11.35, 0.04, 6.15),
new THREE.MeshStandardMaterial({
color: 0x313a40,
roughness: 0.9,
metalness: 0.02
})
);
plinthCap.position.y = 0.02;
plinthCap.receiveShadow = true;
scene.add(plinthCap);
const plinthEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(plinth.geometry),
new THREE.LineBasicMaterial({
color: 0x8a9ca3,
transparent: true,
opacity: 0.24
})
);
plinthEdges.position.copy(plinth.position);
scene.add(plinthEdges);
// Fine drafting grid on the model board.
const fineGridPositions = [];
for (let x = -5.2; x <= 5.21; x += 0.4) {
fineGridPositions.push(x, 0.043, -2.85, x, 0.043, 2.85);
}
for (let z = -2.8; z <= 2.81; z += 0.4) {
fineGridPositions.push(-5.25, 0.043, z, 5.25, 0.043, z);
}
const fineGrid = new THREE.LineSegments(
new THREE.BufferGeometry().setAttribute(
"position",
new THREE.Float32BufferAttribute(fineGridPositions, 3)
),
new THREE.LineBasicMaterial({
color: 0x789098,
transparent: true,
opacity: 0.095
})
);
scene.add(fineGrid);
const majorGridPositions = [];
for (let x = -4.8; x <= 4.81; x += 1.2) {
majorGridPositions.push(x, 0.047, -2.85, x, 0.047, 2.85);
}
for (let z = -2.4; z <= 2.41; z += 1.2) {
majorGridPositions.push(-5.25, 0.047, z, 5.25, 0.047, z);
}
const majorGrid = new THREE.LineSegments(
new THREE.BufferGeometry().setAttribute(
"position",
new THREE.Float32BufferAttribute(majorGridPositions, 3)
),
new THREE.LineBasicMaterial({
color: 0x8da0a6,
transparent: true,
opacity: 0.18
})
);
scene.add(majorGrid);
// -------------------------------------------------------------------------
// Voxel model data
// -------------------------------------------------------------------------
const PITCH = 0.4;
const VOXEL = 0.365;
const MODEL_BASE = 0.04;
const stoneBlocks = [];
const ribBlocks = [];
const darkBlocks = [];
const wingBlocks = [];
const goldBlocks = [];
let randomSeed = 4217;
function random() {
randomSeed |= 0;
randomSeed = (randomSeed + 0x6d2b79f5) | 0;
let t = Math.imul(randomSeed ^ (randomSeed >>> 15), 1 | randomSeed);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
}
function stoneColor(base = 0xc6bca9, amount = 0.07) {
const color = new THREE.Color(base);
color.offsetHSL(
(random() - 0.5) * 0.008,
(random() - 0.5) * 0.025,
(random() - 0.5) * amount
);
return color;
}
function addBlock(list, x, y, z, sx, sy, sz, color) {
list.push({
position: [x, y, z],
scale: [sx, sy, sz],
color: color instanceof THREE.Color ? color.clone() : new THREE.Color(color)
});
}
// Fifteen vertical bays. The stepped heights retain the facade's rhythm
// while compressing its full church elevation into a small fragment.
const bayHeights = [3, 4, 5, 6, 7, 8, 10, 12, 10, 8, 7, 6, 5, 4, 3];
for (let x = -7; x <= 7; x++) {
const height = bayHeights[x + 7];
for (let y = 0; y < height; y++) {
// Stepped central entrance: the opening narrows toward its head.
const inPortal = (Math.abs(x) <= 1 && y < 2) || (x === 0 && y === 2);
if (inPortal) continue;
const tier = Math.floor(y / 3);
const z = -0.065 * tier - Math.abs(x) * 0.008;
const yPos = MODEL_BASE + VOXEL / 2 + y * PITCH;
const xPos = x * PITCH;
const color = stoneColor(0xc6bca9, 0.085);
color.offsetHSL(0, 0, -Math.abs(x) * 0.0035);
addBlock(
stoneBlocks,
xPos,
yPos,
z,
VOXEL,
VOXEL,
0.46,
color
);
// Narrow pale ribs clarify the vertical facade courses.
if (x % 2 === 0) {
addBlock(
ribBlocks,
xPos,
yPos,
z + 0.273,
0.085,
0.305,
0.10,
stoneColor(0xe2d9c7, 0.035)
);
}
}
}
// Recessed, dark portal behind the omitted entrance blocks.
addBlock(
darkBlocks,
0,
MODEL_BASE + 0.72,
-0.32,
1.12,
1.44,
0.075,
0x111a20
);
// Portal threshold.
addBlock(
stoneBlocks,
0,
MODEL_BASE + 0.025,
0.015,
1.24,
0.05,
0.57,
stoneColor(0xb5aa96, 0.035)
);
// Two slim facade slots suggest narrow openings in the central tower.
for (const x of [-0.58, 0.58]) {
addBlock(
darkBlocks,
x,
MODEL_BASE + 3.12,
0.133,
0.052,
0.72,
0.035,
0x19242a
);
}
// Cropped side buttresses. Their detached courses make the reduction
// legible as an architectural fragment rather than a complete elevation.
function addWing(side) {
const profile = [2, 3, 2, 1];
for (let i = 0; i < profile.length; i++) {
const distance = 3.42 + i * 0.4;
const x = side * distance;
const height = profile[i];
for (let y = 0; y < height; y++) {
const z = -0.16 - Math.floor(y / 2) * 0.05;
const yPos = MODEL_BASE + 0.17 + y * PITCH;
addBlock(
wingBlocks,
x,
yPos,
z,
0.345,
0.345,
0.39,
stoneColor(i === 0 ? 0xb7ad9b : 0xa59d8f, 0.09)
);
if (i < 2) {
addBlock(
ribBlocks,
x,
yPos,
z + 0.225,
0.075,
0.285,
0.075,
stoneColor(0xd5cbb8, 0.04)
);
}
}
}
}
addWing(-1);
addWing(1);
// -------------------------------------------------------------------------
// Instanced geometry
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const dummy = new THREE.Object3D();
function makeInstances(data, material, castShadow = true) {
if (!data.length) return null;
const mesh = new THREE.InstancedMesh(unitBox, material, data.length);
data.forEach((block, index) => {
dummy.position.set(...block.position);
dummy.scale.set(...block.scale);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
mesh.setColorAt(index, block.color);
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
mesh.computeBoundingSphere();
scene.add(mesh);
return mesh;
}
makeInstances(
stoneBlocks,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.88,
metalness: 0.015
})
);
makeInstances(
wingBlocks,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.93,
metalness: 0.01
})
);
makeInstances(
ribBlocks,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.7,
metalness: 0.025
})
);
makeInstances(
darkBlocks,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.96,
metalness: 0
}),
false
);
// -------------------------------------------------------------------------
// Drafting annotations and scale marker
// -------------------------------------------------------------------------
const annotationMaterial = new THREE.LineBasicMaterial({
color: 0xc7a66d,
transparent: true,
opacity: 0.62
});
const dimensionPositions = [
// Width dimension.
-4.85, 0.055, 2.72,
4.85, 0.055, 2.72,
-4.85, 0.055, 2.56,
-4.85, 0.055, 2.88,
4.85, 0.055, 2.56,
4.85, 0.055, 2.88,
// Depth dimension.
5.22, 0.055, -1.65,
5.22, 0.055, 0.42,
5.06, 0.055, -1.65,
5.38, 0.055, -1.65,
5.06, 0.055, 0.42,
5.38, 0.055, 0.42
];
const dimensions = new THREE.LineSegments(
new THREE.BufferGeometry().setAttribute(
"position",
new THREE.Float32BufferAttribute(dimensionPositions, 3)
),
annotationMaterial
);
scene.add(dimensions);
// Alternating scale-bar blocks.
for (let i = 0; i < 10; i++) {
addBlock(
goldBlocks,
2.78 + i * 0.18,
0.062,
2.18,
0.18,
0.025,
0.09,
i % 2 === 0 ? 0xc7a66d : 0x455158
);
}
makeInstances(
goldBlocks,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.5,
metalness: 0.32
}),
false
);
// Small north marker.
const northShaft = new THREE.Mesh(
new THREE.BoxGeometry(0.035, 0.035, 0.65),
new THREE.MeshBasicMaterial({ color: 0xc7a66d })
);
northShaft.position.set(4.9, 0.068, -2.1);
scene.add(northShaft);
const northArrow = new THREE.Mesh(
new THREE.ConeGeometry(0.095, 0.25, 3),
new THREE.MeshBasicMaterial({ color: 0xc7a66d })
);
northArrow.rotation.x = -Math.PI / 2;
northArrow.position.set(4.9, 0.068, -2.48);
scene.add(northArrow);
// Model-board caption rendered entirely with a local CanvasTexture.
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 1024;
labelCanvas.height = 256;
const labelContext = labelCanvas.getContext("2d");
labelContext.clearRect(0, 0, 1024, 256);
labelContext.fillStyle = "rgba(216, 221, 216, 0.88)";
labelContext.font = '600 48px Arial, sans-serif';
labelContext.fillText("HALLGRÍMSKIRKJA", 18, 72);
labelContext.fillStyle = "rgba(199, 166, 109, 0.92)";
labelContext.fillRect(18, 101, 170, 3);
labelContext.fillStyle = "rgba(164, 177, 181, 0.78)";
labelContext.font = '25px monospace';
labelContext.fillText("FACADE RHYTHM / FRAGMENT 04 / 1:200", 18, 151);
const labelTexture = new THREE.CanvasTexture(labelCanvas);
labelTexture.colorSpace = THREE.SRGBColorSpace;
labelTexture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
const labelPlane = new THREE.Mesh(
new THREE.PlaneGeometry(4.75, 1.18),
new THREE.MeshBasicMaterial({
map: labelTexture,
transparent: true,
depthWrite: false,
toneMapped: false
})
);
labelPlane.rotation.x = -Math.PI / 2;
labelPlane.position.set(-2.72, 0.051, 2.05);
scene.add(labelPlane);
// -------------------------------------------------------------------------
// Direct camera controls: drag orbit, wheel zoom, double-click reset
// -------------------------------------------------------------------------
const pointerState = {
down: false,
x: 0,
y: 0,
moved: 0,
pointerId: null
};
function viewportRadiusScale() {
const aspect = window.innerWidth / window.innerHeight;
return Math.max(1, Math.min(1.85, 0.86 / aspect));
}
function setView(name) {
const scale = viewportRadiusScale();
if (name === "front") {
desiredView.theta = 0;
desiredView.phi = 1.42;
desiredView.radius = 10.8 * scale;
} else {
desiredView.theta = 0.58;
desiredView.phi = 1.13;
desiredView.radius = 11.8 * scale;
}
document
.getElementById("axonometric")
.classList.toggle("active", name === "axonometric");
document
.getElementById("front")
.classList.toggle("active", name === "front");
}
function setAutoOrbit(enabled) {
autoOrbit = enabled;
const button = document.getElementById("orbit");
button.textContent = enabled ? "Orbit on" : "Orbit off";
button.classList.toggle("active", enabled);
button.setAttribute("aria-pressed", String(enabled));
}
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerState.down = true;
pointerState.x = event.clientX;
pointerState.y = event.clientY;
pointerState.moved = 0;
pointerState.pointerId = event.pointerId;
renderer.domElement.setPointerCapture(event.pointerId);
setAutoOrbit(false);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerState.down || event.pointerId !== pointerState.pointerId) return;
const dx = event.clientX - pointerState.x;
const dy = event.clientY - pointerState.y;
pointerState.x = event.clientX;
pointerState.y = event.clientY;
pointerState.moved += Math.abs(dx) + Math.abs(dy);
desiredView.theta -= dx * 0.006;
desiredView.phi = THREE.MathUtils.clamp(
desiredView.phi - dy * 0.005,
0.58,
1.46
);
});
function endPointer(event) {
if (!pointerState.down) return;
if (
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
pointerState.down = false;
pointerState.pointerId = null;
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredView.radius = THREE.MathUtils.clamp(
desiredView.radius * Math.exp(event.deltaY * 0.001),
6.8,
22
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
setView("axonometric");
});
document.getElementById("axonometric").addEventListener("click", () => {
setView("axonometric");
});
document.getElementById("front").addEventListener("click", () => {
setView("front");
});
document.getElementById("reset").addEventListener("click", () => {
setView("axonometric");
});
document.getElementById("orbit").addEventListener("click", () => {
setAutoOrbit(!autoOrbit);
});
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "a") {
setAutoOrbit(!autoOrbit);
} else if (event.key.toLowerCase() === "f") {
setView("front");
} else if (event.key.toLowerCase() === "r") {
setView("axonometric");
}
});
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
const initialScale = viewportRadiusScale();
desiredView.radius *= initialScale;
currentView.radius *= initialScale;
const clock = new THREE.Clock();
const cameraSpherical = new THREE.Spherical();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (autoOrbit && !pointerState.down) {
desiredView.theta += delta * 0.085;
}
currentView.theta = THREE.MathUtils.damp(
currentView.theta,
desiredView.theta,
7,
delta
);
currentView.phi = THREE.MathUtils.damp(
currentView.phi,
desiredView.phi,
7,
delta
);
currentView.radius = THREE.MathUtils.damp(
currentView.radius,
desiredView.radius,
7,
delta
);
cameraSpherical.set(
currentView.radius,
currentView.phi,
currentView.theta
);
camera.position.setFromSpherical(cameraSpherical).add(target);
camera.lookAt(target);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
renderer.render(scene, camera);
loading.classList.add("hidden");
window.setTimeout(() => loading.remove(), 650);
animate();
</script>
</body>
</html>
```