Prompt specification
Build or customize the Three.js 3D scene "Checkpoint barrier and opened gate segment" 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: Checkpoint barrier and opened gate segment
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/checkpoint-barrier-and-opened-gate-segment-x2417
Scene Description Prompt:
Model a referenced Berlin checkpoint barrier segment in its opened position. Label the November 1989 context and avoid presenting a generic wall fragment as a precise site replica. Build this with Three.js from cdnjs as a stylized scene in one self-contained HTML file.
Working Three.js Starter (checkpoint-barrier-and-opened-gate-segment-x2417):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Berlin Checkpoint Barrier — November 1989 Interpretive Model</title>
<style>
:root {
color-scheme: dark;
--ink: #172022;
--paper: #e9e5d8;
--muted: #b8b8ad;
--accent: #cf493b;
--green: #75c98b;
--panel: rgba(18, 25, 27, 0.88);
--line: rgba(233, 229, 216, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #aeb8ba;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#stage canvas.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
color: var(--paper);
background: var(--panel);
border: 1px solid var(--line);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.brief {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 21px 22px 19px;
border-radius: 4px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 11px;
color: #d8d6ca;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 3px;
background: var(--accent);
content: "";
}
h1 {
margin: 0;
max-width: 330px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(29px, 3.1vw, 43px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.lede {
margin: 15px 0 0;
color: #d1d0c6;
font-size: 13px;
line-height: 1.55;
}
.context {
margin-top: 17px;
padding: 14px 15px;
background: rgba(255, 255, 255, 0.055);
border-left: 3px solid var(--accent);
}
.context strong {
display: block;
margin-bottom: 6px;
color: #f0e7d7;
font-size: 11px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.context p {
margin: 0;
color: #c9c9bf;
font-size: 12px;
line-height: 1.55;
}
.disclaimer {
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: #aaaFA9;
font-size: 10px;
line-height: 1.5;
}
.disclaimer b {
color: #d9d7cb;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.classification {
top: 22px;
right: 22px;
max-width: 255px;
padding: 12px 15px;
border-radius: 3px;
text-align: right;
}
.classification .status {
display: flex;
justify-content: flex-end;
align-items: center;
gap: 8px;
color: #f2ecdd;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 12px rgba(117, 201, 139, 0.8);
}
.classification p {
margin: 7px 0 0;
color: #aaaFA9;
font-size: 10px;
line-height: 1.45;
}
.controls {
bottom: 22px;
left: 50%;
display: flex;
align-items: center;
gap: 7px;
padding: 8px;
border-radius: 4px;
transform: translateX(-50%);
}
button {
appearance: none;
border: 1px solid rgba(233, 229, 216, 0.18);
border-radius: 2px;
padding: 8px 11px;
color: #e8e4d7;
background: rgba(255, 255, 255, 0.06);
font: inherit;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
}
button:hover,
button:focus-visible {
border-color: rgba(233, 229, 216, 0.5);
background: rgba(255, 255, 255, 0.12);
outline: none;
}
.hint {
padding: 0 9px;
color: #b4b5ae;
white-space: nowrap;
font-size: 10px;
letter-spacing: 0.035em;
}
#labels {
position: fixed;
z-index: 6;
inset: 0;
overflow: hidden;
pointer-events: none;
transition: opacity 180ms ease;
}
#labels.hidden {
opacity: 0;
}
.anchor {
position: absolute;
width: max-content;
max-width: 205px;
padding: 8px 10px;
color: #f0ece0;
background: rgba(20, 27, 29, 0.84);
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 2px;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.17);
transform: translate(-50%, calc(-100% - 22px));
font-size: 9px;
font-weight: 750;
line-height: 1.35;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.anchor::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 22px;
background: rgba(255, 255, 255, 0.58);
content: "";
}
.anchor::before {
position: absolute;
top: calc(100% + 19px);
left: calc(50% - 3px);
width: 7px;
height: 7px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 50%;
background: #c74a3d;
content: "";
}
.anchor small {
display: block;
margin-top: 3px;
color: #bdbeb6;
font-size: 8px;
font-weight: 500;
letter-spacing: 0.04em;
text-transform: none;
}
@media (max-width: 760px) {
.brief {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 16px;
}
h1 {
max-width: 270px;
font-size: 29px;
}
.lede {
display: none;
}
.context {
margin-top: 13px;
padding: 10px 12px;
}
.context p {
font-size: 11px;
}
.disclaimer {
font-size: 9px;
}
.classification {
display: none;
}
.controls {
bottom: 12px;
width: calc(100vw - 24px);
justify-content: center;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<main id="stage" aria-label="Interactive stylized Three.js scene of an opened Berlin border checkpoint barrier"></main>
<section class="panel brief" aria-labelledby="title">
<div class="eyebrow">Open position · 9 November 1989</div>
<h1 id="title">Berlin border checkpoint</h1>
<p class="lede">
A stylized interpretation of a raised red-and-white boom arm,
guard kiosk, and concrete lane furniture representing an opened passage.
</p>
<div class="context">
<strong>November 1989</strong>
<p>
After the announcement of new travel rules on 9 November, crowds
gathered at Berlin border crossings. Personnel opened passage and,
in many places, stood aside. Crossing and dismantling unfolded over
the following days.
</p>
</div>
<div class="disclaimer">
<b>Interpretive type study — not a precise site replica.</b><br>
The geometry is invented and stylized. It does not reproduce
Checkpoint Charlie or any other named checkpoint.
</div>
</section>
<aside class="panel classification" aria-label="Model classification">
<div class="status">
<span class="status-dot"></span>
Passage open
</div>
<p>
Reference vocabulary: striped boom arm, checkpoint kiosk, lane blocks.<br>
No surveyed geometry or archival image matching.
</p>
</aside>
<div id="labels" aria-hidden="true">
<div class="anchor" id="label-boom">
Raised boom arm
<small>Open position leaves the passage clear</small>
</div>
<div class="anchor" id="label-hinge">
Hinge and open signal
<small>Stylized checkpoint hardware</small>
</div>
<div class="anchor" id="label-date">
9 November 1989
<small>Border passage opens to crowds</small>
</div>
<div class="anchor" id="label-type">
Interpretive checkpoint type
<small>Not tied to a surveyed location</small>
</div>
</div>
<nav class="panel controls" aria-label="Scene controls">
<button id="reset" type="button" title="Reset camera">Reset view</button>
<button id="toggle-labels" type="button" aria-pressed="true">Labels on</button>
<span class="hint">Drag to orbit · Scroll or pinch to zoom · R resets</span>
</nav>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const labelLayer = document.querySelector("#labels");
const labels = {
boom: document.querySelector("#label-boom"),
hinge: document.querySelector("#label-hinge"),
date: document.querySelector("#label-date"),
type: document.querySelector("#label-type")
};
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xaeb9bb);
scene.fog = new THREE.Fog(0xaeb9bb, 19, 43);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
80
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
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.03;
stage.appendChild(renderer.domElement);
const canvas = renderer.domElement;
// ---------- Procedural, asset-free textures ----------
let randomSeed = 19891109;
function random() {
randomSeed =
(randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function makeNoiseTexture(base, fleck, count, repeatX, repeatY) {
const textureCanvas = document.createElement("canvas");
textureCanvas.width = 256;
textureCanvas.height = 256;
const context = textureCanvas.getContext("2d");
context.fillStyle = base;
context.fillRect(0, 0, 256, 256);
for (let i = 0; i < count; i++) {
const shade = Math.floor(80 + random() * 120);
const alpha = 0.025 + random() * 0.075;
context.fillStyle = `rgba(${shade},${shade},${shade},${alpha})`;
context.fillRect(
Math.floor(random() * 256),
Math.floor(random() * 256),
random() > 0.92 ? 2 : 1,
random() > 0.92 ? 2 : 1
);
}
const texture = new THREE.CanvasTexture(textureCanvas);
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(repeatX, repeatY);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
const concreteTexture = makeNoiseTexture(
"#aaa89d",
"#77766f",
2800,
2.5,
2.5
);
const roadTexture = makeNoiseTexture(
"#414748",
"#888",
4300,
5,
11
);
const groundTexture = makeNoiseTexture(
"#777e79",
"#aaa",
3000,
10,
10
);
// ---------- Materials ----------
const concreteMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
map: concreteTexture,
roughness: 0.92,
metalness: 0
});
const roadMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
map: roadTexture,
roughness: 0.98,
metalness: 0
});
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
map: groundTexture,
roughness: 1
});
const darkMetal = new THREE.MeshStandardMaterial({
color: 0x252b2c,
roughness: 0.62,
metalness: 0.5
});
const redMaterial = new THREE.MeshStandardMaterial({
color: 0xc43f34,
roughness: 0.58,
metalness: 0.08
});
const whiteMaterial = new THREE.MeshStandardMaterial({
color: 0xe4e0d4,
roughness: 0.68
});
const boothMaterial = new THREE.MeshStandardMaterial({
color: 0x8d8d7f,
roughness: 0.86
});
const roofMaterial = new THREE.MeshStandardMaterial({
color: 0x414747,
roughness: 0.75,
metalness: 0.12
});
const glassMaterial = new THREE.MeshPhysicalMaterial({
color: 0x426064,
roughness: 0.24,
metalness: 0,
transparent: true,
opacity: 0.72,
transmission: 0.08,
thickness: 0.15
});
const yellowMaterial = new THREE.MeshStandardMaterial({
color: 0xd0ae55,
roughness: 0.78
});
const greenLightMaterial = new THREE.MeshStandardMaterial({
color: 0x68d88d,
emissive: 0x36b866,
emissiveIntensity: 1.7,
roughness: 0.28
});
// ---------- Lighting ----------
scene.add(new THREE.HemisphereLight(0xd9e4e6, 0x52534e, 2.1));
const sun = new THREE.DirectionalLight(0xfff0d4, 3.1);
sun.position.set(-8, 15, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.00015;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xa9c8d4, 0.85);
fill.position.set(10, 7, -8);
scene.add(fill);
// ---------- Helpers ----------
function box(
width,
height,
depth,
material,
x,
y,
z,
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(
radiusTop,
radiusBottom,
height,
material,
x,
y,
z,
parent = scene,
segments = 20
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// ---------- Ground and roadway ----------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(34, 28),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.07;
ground.receiveShadow = true;
scene.add(ground);
box(7.6, 0.09, 20, roadMaterial, 0, 0.015, -0.5);
box(5.1, 0.16, 20, concreteMaterial, -6.35, 0.02, -0.5);
box(5.1, 0.16, 20, concreteMaterial, 6.35, 0.02, -0.5);
// Road edge markings and dashed center line.
for (const x of [-3.38, 3.38]) {
box(0.07, 0.022, 18.5, whiteMaterial, x, 0.073, -0.5);
}
for (let z = -8.6; z <= 8; z += 2.45) {
box(0.075, 0.024, 1.08, yellowMaterial, 0, 0.074, z);
}
// ---------- Concrete lane furniture ----------
// These are discrete blocks, not a continuous wall fragment.
function jerseyBarrier(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0.12, z);
group.rotation.y = rotation;
scene.add(group);
box(1.08, 0.28, 2.2, concreteMaterial, 0, 0.14, 0, group);
box(0.72, 0.76, 2.08, concreteMaterial, 0, 0.62, 0, group);
box(0.48, 0.18, 1.98, concreteMaterial, 0, 1.02, 0, group);
return group;
}
jerseyBarrier(-4.72, -1.55, 0.08);
jerseyBarrier(-4.72, 0.76, 0.08);
jerseyBarrier(4.8, -4.45, -0.05);
// ---------- Guard kiosk ----------
const kiosk = new THREE.Group();
kiosk.position.set(4.45, 0.13, -1.25);
scene.add(kiosk);
box(2.05, 2.45, 2.08, boothMaterial, 0, 1.225, 0, kiosk);
box(2.35, 0.2, 2.38, roofMaterial, 0, 2.53, 0, kiosk);
box(2.12, 0.16, 2.14, darkMetal, 0, 0.08, 0, kiosk);
// Front glazing and frame.
box(1.48, 0.98, 0.055, darkMetal, 0, 1.62, 1.065, kiosk);
box(1.33, 0.83, 0.062, glassMaterial, 0, 1.62, 1.1, kiosk);
box(0.055, 0.86, 0.075, darkMetal, 0, 1.62, 1.145, kiosk);
// Side window.
box(0.06, 0.88, 1.25, darkMetal, 1.055, 1.62, 0.08, kiosk);
box(0.065, 0.74, 1.11, glassMaterial, 1.09, 1.62, 0.08, kiosk);
// Door and handle.
box(0.62, 1.8, 0.06, darkMetal, -0.58, 0.95, 1.09, kiosk);
box(0.53, 1.68, 0.07, boothMaterial, -0.58, 0.95, 1.13, kiosk);
box(0.04, 0.22, 0.08, whiteMaterial, -0.34, 0.99, 1.19, kiosk);
// Roof lip.
box(2.43, 0.08, 2.46, roofMaterial, 0, 2.46, 0, kiosk);
// ---------- Raised striped boom ----------
const supportX = 2.65;
const supportZ = 0.82;
const pivotY = 1.43;
box(0.95, 0.2, 0.95, concreteMaterial, supportX, 0.23, supportZ);
box(0.42, 1.72, 0.42, darkMetal, supportX, 1.05, supportZ);
// Red-white sleeves on the support.
for (let i = 0; i < 5; i++) {
box(
0.45,
0.23,
0.45,
i % 2 === 0 ? redMaterial : whiteMaterial,
supportX,
0.48 + i * 0.23,
supportZ
);
}
const hinge = cylinder(
0.22,
0.22,
0.62,
darkMetal,
supportX,
pivotY,
supportZ,
scene,
28
);
hinge.rotation.x = Math.PI / 2;
const hingeCap = cylinder(
0.13,
0.13,
0.67,
redMaterial,
supportX,
pivotY,
supportZ,
scene,
24
);
hingeCap.rotation.x = Math.PI / 2;
const armPivot = new THREE.Group();
armPivot.position.set(supportX, pivotY, supportZ);
armPivot.rotation.z = -THREE.MathUtils.degToRad(60);
scene.add(armPivot);
const armLength = 5.55;
const stripeCount = 10;
const stripeLength = armLength / stripeCount;
for (let i = 0; i < stripeCount; i++) {
const x = -(i + 0.5) * stripeLength;
box(
stripeLength - 0.012,
0.18,
0.18,
i % 2 === 0 ? redMaterial : whiteMaterial,
x,
0,
0,
armPivot
);
}
box(0.14, 0.22, 0.23, darkMetal, -armLength - 0.01, 0, 0, armPivot);
box(0.36, 0.32, 0.32, redMaterial, 0.28, 0, 0, armPivot);
const tipMarker = new THREE.Object3D();
tipMarker.position.set(-armLength, 0, 0);
armPivot.add(tipMarker);
// Open signal mounted above the hinge.
box(0.44, 0.68, 0.34, darkMetal, supportX, 2.18, supportZ);
const signalLens = new THREE.Mesh(
new THREE.SphereGeometry(0.12, 20, 14),
greenLightMaterial
);
signalLens.scale.set(1, 1, 0.55);
signalLens.position.set(supportX, 2.27, supportZ + 0.21);
scene.add(signalLens);
// ---------- Interpretive date sign ----------
function createDateSignTexture() {
const signCanvas = document.createElement("canvas");
signCanvas.width = 1024;
signCanvas.height = 512;
const context = signCanvas.getContext("2d");
context.fillStyle = "#20292a";
context.fillRect(0, 0, 1024, 512);
context.fillStyle = "#c74739";
context.fillRect(0, 0, 1024, 17);
context.fillRect(0, 477, 1024, 35);
context.fillStyle = "#f0ebde";
context.font = "700 66px Arial, sans-serif";
context.fillText("NOVEMBER 1989", 58, 111);
context.fillStyle = "#d9d5c8";
context.font = "500 42px Arial, sans-serif";
context.fillText("BERLIN BORDER CHECKPOINT", 58, 194);
context.fillStyle = "#b9bcb4";
context.font = "700 30px Arial, sans-serif";
context.fillText("RAISED BOOM / OPEN PASSAGE", 58, 281);
context.fillStyle = "#d9d5c8";
context.font = "500 25px Arial, sans-serif";
context.fillText("INTERPRETIVE TYPE STUDY", 58, 357);
context.fillStyle = "#b9bcb4";
context.font = "500 23px Arial, sans-serif";
context.fillText("NOT A PRECISE SITE REPLICA", 58, 404);
context.fillStyle = "#f0ebde";
context.font = "700 22px Arial, sans-serif";
context.fillText("9 NOV 1989", 58, 455);
const texture = new THREE.CanvasTexture(signCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
const signGroup = new THREE.Group();
signGroup.position.set(-2.85, 0, 3.15);
signGroup.rotation.y = 0.16;
scene.add(signGroup);
box(3.15, 1.63, 0.14, darkMetal, 0, 1.9, 0, signGroup);
box(0.13, 1.88, 0.13, darkMetal, -1.15, 0.96, 0, signGroup);
box(0.13, 1.88, 0.13, darkMetal, 1.15, 0.96, 0, signGroup);
const dateSign = new THREE.Mesh(
new THREE.PlaneGeometry(3.02, 1.51),
new THREE.MeshBasicMaterial({
map: createDateSignTexture(),
side: THREE.DoubleSide,
toneMapped: false
})
);
dateSign.position.set(0, 1.9, 0.076);
signGroup.add(dateSign);
// ---------- Checkpoint lamps ----------
function addLamp(x, z, flip = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
cylinder(0.065, 0.09, 5.25, darkMetal, 0, 2.63, 0, group);
box(0.68, 0.11, 0.11, darkMetal, 0.29 * flip, 5.2, 0, group);
box(0.42, 0.18, 0.28, roofMaterial, 0.58 * flip, 5.12, 0, group);
box(0.3, 0.035, 0.18, whiteMaterial, 0.58 * flip, 5.01, 0, group);
}
addLamp(-5.45, -4.4, 1);
addLamp(5.55, -5.5, -1);
// ---------- Quiet, abstract background ----------
const backgroundMaterial = new THREE.MeshStandardMaterial({
color: 0x777e7e,
roughness: 1
});
const buildingData = [
[-8.3, 2.8, 2.2, -11.5, 2.7],
[-4.9, 1.6, 2.0, -12.5, 2.1],
[2.7, 2.2, 2.5, -12.8, 2.6],
[7.5, 3.1, 2.8, -11.6, 3.4]
];
for (const [x, width, height, z, depth] of buildingData) {
box(width, height, depth, backgroundMaterial, x, height / 2 - 0.03, z);
}
// ---------- Custom orbit camera controls ----------
const cameraTarget = new THREE.Vector3(0.2, 2.05, -0.35);
const initialView = {
theta: 0.67,
phi: 1.18,
radius: 15.2
};
const view = { ...initialView };
function updateCamera() {
const sinPhi = Math.sin(view.phi);
camera.position.set(
cameraTarget.x + view.radius * sinPhi * Math.sin(view.theta),
cameraTarget.y + view.radius * Math.cos(view.phi),
cameraTarget.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(cameraTarget);
}
function resetView() {
view.theta = initialView.theta;
view.phi = initialView.phi;
view.radius = initialView.radius;
updateCamera();
}
const pointers = new Map();
let pinchDistance = 0;
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
canvas.classList.add("dragging");
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
view.theta -= dx * 0.006;
view.phi = THREE.MathUtils.clamp(
view.phi + dy * 0.005,
0.52,
1.43
);
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0 && distance > 0) {
view.radius = THREE.MathUtils.clamp(
view.radius * (pinchDistance / distance),
7.5,
25
);
}
pinchDistance = distance;
}
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) {
pinchDistance = 0;
}
if (pointers.size === 0) {
canvas.classList.remove("dragging");
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("lostpointercapture", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius + event.deltaY * 0.008,
7.5,
25
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
document.querySelector("#reset").addEventListener("click", resetView);
const labelsButton = document.querySelector("#toggle-labels");
labelsButton.addEventListener("click", () => {
const hidden = labelLayer.classList.toggle("hidden");
labelsButton.textContent = hidden ? "Labels off" : "Labels on";
labelsButton.setAttribute("aria-pressed", String(!hidden));
});
window.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "r") {
resetView();
} else if (key === "arrowleft") {
view.theta -= 0.12;
} else if (key === "arrowright") {
view.theta += 0.12;
} else if (key === "arrowup") {
view.phi = Math.max(0.52, view.phi - 0.08);
} else if (key === "arrowdown") {
view.phi = Math.min(1.43, view.phi + 0.08);
} else if (key === "+" || key === "=") {
view.radius = Math.max(7.5, view.radius - 0.7);
} else if (key === "-") {
view.radius = Math.min(25, view.radius + 0.7);
} else {
return;
}
updateCamera();
});
// ---------- Projected HTML annotations ----------
const projected = new THREE.Vector3();
function positionLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const width = stage.clientWidth;
const height = stage.clientHeight;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
const visible =
projected.z > -1 &&
projected.z < 1 &&
x > -120 &&
x < width + 120 &&
y > -80 &&
y < height + 80;
element.style.visibility = visible ? "visible" : "hidden";
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
const tipWorld = new THREE.Vector3();
const hingeWorld = new THREE.Vector3();
const signWorld = new THREE.Vector3();
const kioskWorld = new THREE.Vector3();
function updateLabels() {
tipMarker.getWorldPosition(tipWorld);
hinge.getWorldPosition(hingeWorld);
dateSign.getWorldPosition(signWorld);
kiosk.getWorldPosition(kioskWorld);
positionLabel(labels.boom, tipWorld);
positionLabel(labels.hinge, hingeWorld);
positionLabel(labels.date, signWorld);
positionLabel(labels.type, kioskWorld);
}
// ---------- Resize and render loop ----------
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
window.addEventListener("resize", resize);
resize();
updateCamera();
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
updateLabels();
});
</script>
</body>
</html>
```