Prompt specification
Build or customize the Three.js 3D scene "Surveyors marking a rebuilt Lisbon street" 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: Surveyors marking a rebuilt Lisbon street
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/surveyors-marking-a-rebuilt-lisbon-street-x2438
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows Lisbon's reconstruction after the 1755 earthquake. Create a non-graphic reconstruction vignette with survey stakes, measuring rope, and a cleared street edge. Use references for period tools and avoid inventing named participants. A 3D cutaway view.
Working Three.js Starter (surveyors-marking-a-rebuilt-lisbon-street-x2438):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#17262c">
<title>Lisbon After 1755 — Reconstruction Vignette</title>
<style>
:root {
--ink: #17262c;
--paper: #eee7d9;
--paper-bright: #fffaf0;
--muted: #b8b7aa;
--line: rgba(255, 255, 255, 0.16);
--amber: #d69b52;
--amber-light: #f0c889;
--green: #557568;
--shadow: 0 16px 50px rgba(13, 24, 28, 0.28);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e4dfd4;
color: var(--paper-bright);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#viewport {
position: fixed;
inset: 0;
overflow: hidden;
background:
radial-gradient(circle at 65% 35%, rgba(255, 255, 255, 0.75), transparent 42%),
#e4dfd4;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.panel {
border: 1px solid var(--line);
background: rgba(23, 38, 44, 0.91);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#title-panel {
position: absolute;
top: 22px;
left: 22px;
width: min(430px, calc(100vw - 44px));
padding: 20px 22px 18px;
border-radius: 4px;
pointer-events: auto;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--amber-light);
font-size: 0.68rem;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 28px;
height: 1px;
content: "";
background: var(--amber);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(2rem, 4vw, 3.15rem);
font-weight: 400;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
margin: 13px 0 0;
max-width: 370px;
color: #d5d4c9;
font-family: Georgia, "Times New Roman", serif;
font-size: 1.02rem;
line-height: 1.42;
}
.chips {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 15px;
}
.chip {
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 2px;
color: #c8cbc3;
background: rgba(255, 255, 255, 0.045);
font-size: 0.66rem;
letter-spacing: 0.04em;
}
#action-bar {
position: absolute;
top: 22px;
right: 22px;
display: flex;
gap: 8px;
pointer-events: auto;
}
.action {
min-height: 38px;
padding: 9px 12px;
border: 1px solid rgba(23, 38, 44, 0.2);
border-radius: 3px;
background: rgba(250, 247, 239, 0.92);
color: var(--ink);
box-shadow: 0 8px 25px rgba(24, 34, 36, 0.13);
cursor: pointer;
font-size: 0.72rem;
font-weight: 700;
letter-spacing: 0.04em;
transition: transform 150ms ease, background 150ms ease;
}
.action:hover {
transform: translateY(-1px);
background: #fffdf7;
}
.action[aria-pressed="true"] {
border-color: #b07838;
background: #f2d6ae;
}
#layer-panel {
position: absolute;
right: 22px;
bottom: 22px;
width: 255px;
padding: 16px 17px 14px;
border-radius: 4px;
pointer-events: auto;
}
.panel-heading {
margin: 0 0 12px;
color: #e9e5d9;
font-size: 0.69rem;
font-weight: 750;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.toggle {
display: grid;
grid-template-columns: 22px 1fr;
gap: 9px;
align-items: start;
padding: 8px 0;
border-top: 1px solid rgba(255, 255, 255, 0.08);
cursor: pointer;
}
.toggle:first-of-type {
border-top: 0;
}
.toggle input {
width: 17px;
height: 17px;
margin: 1px 0 0;
accent-color: var(--amber);
cursor: pointer;
}
.toggle-title {
display: block;
color: #efeee5;
font-size: 0.76rem;
font-weight: 650;
}
.toggle-note {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 0.66rem;
line-height: 1.35;
}
#legend {
position: absolute;
left: 22px;
bottom: 22px;
display: flex;
flex-wrap: wrap;
gap: 10px 16px;
max-width: min(560px, calc(100vw - 310px));
padding: 12px 15px;
border-radius: 4px;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #d5d5cb;
font-size: 0.66rem;
letter-spacing: 0.02em;
}
.swatch {
width: 13px;
height: 8px;
border-radius: 1px;
border: 1px solid rgba(255, 255, 255, 0.24);
}
#help {
position: absolute;
left: 50%;
bottom: 24px;
transform: translateX(-50%);
padding: 8px 12px;
border-radius: 3px;
background: rgba(23, 38, 44, 0.78);
color: #d9d8ce;
font-size: 0.65rem;
letter-spacing: 0.025em;
pointer-events: none;
white-space: nowrap;
}
#labels {
position: absolute;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.pin {
position: absolute;
min-width: 125px;
max-width: 195px;
padding: 7px 9px 7px 11px;
border-left: 2px solid var(--amber);
border-radius: 2px;
background: rgba(23, 38, 44, 0.88);
box-shadow: 0 7px 20px rgba(22, 29, 31, 0.18);
color: #f5f0e5;
transform: translate(-50%, calc(-100% - 13px));
transition: opacity 120ms linear;
backdrop-filter: blur(7px);
-webkit-backdrop-filter: blur(7px);
}
.pin::after {
position: absolute;
left: -5px;
bottom: -15px;
width: 8px;
height: 8px;
border: 2px solid var(--amber-light);
border-radius: 50%;
background: var(--ink);
content: "";
box-shadow: 0 0 0 3px rgba(23, 38, 44, 0.3);
}
.pin-title {
display: block;
font-size: 0.69rem;
font-weight: 750;
letter-spacing: 0.035em;
}
.pin-note {
display: block;
margin-top: 2px;
color: #c3c6be;
font-size: 0.61rem;
line-height: 1.3;
}
#source-panel {
position: absolute;
top: 0;
right: 0;
width: min(470px, 100vw);
height: 100%;
padding: 26px 27px 32px;
overflow-y: auto;
background: rgba(23, 38, 44, 0.97);
box-shadow: -20px 0 60px rgba(17, 25, 28, 0.28);
transform: translateX(102%);
transition: transform 250ms cubic-bezier(0.22, 0.8, 0.25, 1);
pointer-events: auto;
z-index: 20;
}
#source-panel.open {
transform: translateX(0);
}
#close-sources {
position: absolute;
top: 18px;
right: 18px;
width: 34px;
height: 34px;
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 50%;
background: transparent;
color: #eee9dd;
cursor: pointer;
font-size: 1.2rem;
}
#source-panel h2 {
margin: 6px 40px 10px 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 2rem;
font-weight: 400;
}
#source-panel h3 {
margin: 22px 0 7px;
color: var(--amber-light);
font-size: 0.7rem;
letter-spacing: 0.13em;
text-transform: uppercase;
}
#source-panel p,
#source-panel li {
color: #d2d2c8;
font-size: 0.78rem;
line-height: 1.58;
}
#source-panel ul {
padding-left: 18px;
}
#source-panel a {
color: #f0c889;
text-underline-offset: 3px;
}
.method-note {
padding: 12px 14px;
border: 1px solid rgba(214, 155, 82, 0.32);
background: rgba(214, 155, 82, 0.08);
}
#loading {
position: absolute;
inset: 0;
display: grid;
place-items: center;
background: #e4dfd4;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
font-size: 1.1rem;
z-index: 50;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
#title-panel {
width: min(360px, calc(100vw - 44px));
padding: 16px 18px;
}
.subtitle {
font-size: 0.9rem;
}
#legend {
display: none;
}
#help {
left: 16px;
transform: none;
white-space: normal;
}
#layer-panel {
width: 220px;
}
}
@media (max-width: 620px) {
#title-panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
}
h1 {
font-size: 2.1rem;
}
.subtitle,
.chips {
display: none;
}
#action-bar {
top: 124px;
right: 12px;
flex-direction: column;
}
.action {
min-height: 34px;
padding: 7px 9px;
font-size: 0.64rem;
}
#layer-panel {
right: 12px;
bottom: 12px;
width: 205px;
padding: 12px 13px;
}
.toggle {
padding: 6px 0;
}
.toggle-note {
display: none;
}
#help {
bottom: 12px;
left: 12px;
max-width: calc(100vw - 235px);
font-size: 0.59rem;
}
.pin {
min-width: 105px;
max-width: 150px;
padding: 5px 7px;
}
.pin-note {
display: none;
}
}
</style>
</head>
<body>
<main id="viewport" aria-label="Interactive 3D reconstruction of Lisbon after the 1755 earthquake">
<section id="title-panel" class="panel">
<div class="eyebrow">Lisbon · Reconstruction archive</div>
<h1>After the Fire</h1>
<p class="subtitle">
A non-graphic reconstruction vignette of the post-1755 rebuilding:
a cleared street edge, an orthogonal survey setting, and the timber-and-masonry
structure of the new Baixa.
</p>
<div class="chips">
<span class="chip">Interpretive 3D cutaway</span>
<span class="chip">1755–1759 context</span>
<span class="chip">No human figures</span>
</div>
</section>
<nav id="action-bar" aria-label="Scene actions">
<button id="reset-view" class="action" type="button">Reset view</button>
<button id="rotate-view" class="action" type="button" aria-pressed="false">Auto orbit</button>
<button id="open-sources" class="action" type="button">Sources & method</button>
</nav>
<aside id="layer-panel" class="panel" aria-label="Visible reconstruction layers">
<h2 class="panel-heading">Visible layers</h2>
<label class="toggle">
<input id="toggle-survey" type="checkbox" checked>
<span>
<span class="toggle-title">Survey setting</span>
<span class="toggle-note">Stakes, measuring rope, 20 m chain and generic period tools.</span>
</span>
</label>
<label class="toggle">
<input id="toggle-frame" type="checkbox" checked>
<span>
<span class="toggle-title">Timber cage</span>
<span class="toggle-note">An interpretive Pombaline <i>gaiola</i> frame.</span>
</span>
</label>
<label class="toggle">
<input id="toggle-cutaway" type="checkbox" checked>
<span>
<span class="toggle-title">Section & foundation</span>
<span class="toggle-note">Highlighted masonry remains within the model cut.</span>
</span>
</label>
<label class="toggle">
<input id="toggle-labels" type="checkbox" checked>
<span>
<span class="toggle-title">Annotations</span>
<span class="toggle-note">Labels for tools, alignments and construction.</span>
</span>
</label>
</aside>
<div id="legend" class="panel" aria-label="Color legend">
<div class="legend-item"><span class="swatch" style="background:#6e4530"></span>Timber cage</div>
<div class="legend-item"><span class="swatch" style="background:#a85e45"></span>Brick infill</div>
<div class="legend-item"><span class="swatch" style="background:#c7c2b3"></span>New calçada paving</div>
<div class="legend-item"><span class="swatch" style="background:#d69b52"></span>Survey alignment</div>
<div class="legend-item"><span class="swatch" style="background:#d4b27d"></span>Measuring rope</div>
</div>
<div id="help">Drag to orbit · Right-drag to pan · Wheel or pinch to zoom · Arrow keys also orbit</div>
<div id="labels" aria-hidden="true"></div>
<aside id="source-panel" aria-label="Sources and method">
<button id="close-sources" type="button" aria-label="Close sources panel">×</button>
<div class="eyebrow">Reference note</div>
<h2>Sources & method</h2>
<p class="method-note">
This is a composite historical vignette, not an archaeological reconstruction
of one documented Lisbon address. No casualties are depicted, and no named
participants or individual work crews have been invented.
</p>
<h3>Urban reconstruction</h3>
<p>
The scene uses the broad construction logic associated with the rebuilt Baixa:
a more regular street layout, standardized masonry houses, and timber frames
known as <i>gaiolas</i>. The cutaway house is schematic rather than a measured
reconstruction of a surviving building.
</p>
<ul>
<li>
<a href="https://arquivo.museu.pt/" target="_blank" rel="noopener noreferrer">
Arquivo Municipal de Lisboa
</a>
— cartographic and architectural collections documenting Lisbon and the
post-earthquake rebuilding.
</li>
<li>
<a href="https://www.museudelisboa.pt/en/" target="_blank" rel="noopener noreferrer">
Museu de Lisboa
</a>
— contextual material on the earthquake, fire and reconstruction of Lisbon.
</li>
</ul>
<h3>Period-tool basis</h3>
<p>
The stake setting, iron surveyor's chain, folding carpenter's square,
plumb line and drawing board are generic eighteenth-century instruments.
They are included as visual evidence of measuring and setting-out practice,
not as evidence that a particular Lisbon crew used them in exactly this way.
</p>
<ul>
<li>
<a href="https://collection.sciencemuseumgroup.org.uk/objects" target="_blank" rel="noopener noreferrer">
Science Museum Group Collection
</a>
— surviving chains, measuring instruments and historical survey equipment.
</li>
<li>
<a href="https://www.mhs.ox.ac.uk/collections" target="_blank" rel="noopener noreferrer">
Museum of the History of Science, Oxford
</a>
— historical scientific and surveying instrument collections.
</li>
</ul>
<h3>How to read the vignette</h3>
<ul>
<li>The diagonal amber trace suggests an irregular former street alignment.</li>
<li>The rope and stakes establish a cleared frontage and building datum.</li>
<li>The 20 m chain is represented schematically; the scene uses approximately one world unit per metre.</li>
<li>The open facade exposes a simplified timber cage embedded with brick masonry.</li>
<li>The sectioned corner exposes soil, clay, bedrock and surviving masonry foundations.</li>
</ul>
<p>
Rendering uses only the Three.js core module. Camera orbit, pan, zoom and
keyboard controls are implemented directly in this file.
</p>
</aside>
<div id="loading">Preparing the reconstruction model…</div>
</main>
<script type="module">
const loading = document.getElementById("loading");
let THREE;
try {
THREE = await import(
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js"
);
} catch (error) {
loading.textContent = "Unable to load Three.js. Check the network connection and reload.";
console.error(error);
throw error;
}
const viewport = document.getElementById("viewport");
const labelLayer = document.getElementById("labels");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe4dfd4);
scene.fog = new THREE.Fog(0xe4dfd4, 38, 78);
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
} catch (error) {
loading.textContent = "This scene requires WebGL. Try a current browser with hardware acceleration enabled.";
console.error(error);
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Three-dimensional cutaway model. Drag to orbit, right-drag to pan, and scroll to zoom."
);
viewport.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
41,
window.innerWidth / window.innerHeight,
0.1,
150
);
const hemi = new THREE.HemisphereLight(0xfff8e7, 0x65737a, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1d6, 3.25);
sun.position.set(-15, 24, 13);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -25;
sun.shadow.camera.right = 25;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -22;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.0004;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8d1d4, 0.75);
fill.position.set(18, 9, -16);
scene.add(fill);
const model = new THREE.Group();
scene.add(model);
const surveyGroup = new THREE.Group();
const timberGroup = new THREE.Group();
const infillGroup = new THREE.Group();
const cutawayGroup = new THREE.Group();
const annotationGroup = new THREE.Group();
model.add(surveyGroup, timberGroup, infillGroup, cutawayGroup, annotationGroup);
const materials = {
topsoil: new THREE.MeshStandardMaterial({
color: 0x9b7652,
roughness: 1
}),
clay: new THREE.MeshStandardMaterial({
color: 0xa96949,
roughness: 1
}),
bedrock: new THREE.MeshStandardMaterial({
color: 0x77766f,
roughness: 0.98
}),
parcel: new THREE.MeshStandardMaterial({
color: 0xb59a72,
roughness: 1
}),
cleared: new THREE.MeshStandardMaterial({
color: 0xc5ad82,
roughness: 1
}),
streetBase: new THREE.MeshStandardMaterial({
color: 0x89877f,
roughness: 0.96
}),
curb: new THREE.MeshStandardMaterial({
color: 0xbbb9ae,
roughness: 0.9
}),
stone: new THREE.MeshStandardMaterial({
color: 0x9e9b8e,
roughness: 0.94
}),
paleStone: new THREE.MeshStandardMaterial({
color: 0xd0c9b8,
roughness: 0.85
}),
plaster: new THREE.MeshStandardMaterial({
color: 0xd8c29d,
roughness: 0.96
}),
plasterLight: new THREE.MeshStandardMaterial({
color: 0xe0cfac,
roughness: 0.94
}),
timber: new THREE.MeshStandardMaterial({
color: 0x65412d,
roughness: 0.88
}),
timberDark: new THREE.MeshStandardMaterial({
color: 0x493126,
roughness: 0.94
}),
brick: new THREE.MeshStandardMaterial({
color: 0xa65b43,
roughness: 0.96
}),
roof: new THREE.MeshStandardMaterial({
color: 0x9f4e38,
roughness: 0.86
}),
roofDark: new THREE.MeshStandardMaterial({
color: 0x783c31,
roughness: 0.9
}),
window: new THREE.MeshStandardMaterial({
color: 0x283a3c,
roughness: 0.34,
metalness: 0.12
}),
shutter: new THREE.MeshStandardMaterial({
color: 0x4d7164,
roughness: 0.85
}),
rope: new THREE.MeshStandardMaterial({
color: 0xd1ae72,
roughness: 1
}),
stake: new THREE.MeshStandardMaterial({
color: 0x755238,
roughness: 1
}),
redPaint: new THREE.MeshStandardMaterial({
color: 0xb54b38,
roughness: 0.82
}),
iron: new THREE.MeshStandardMaterial({
color: 0x4b4b47,
roughness: 0.54,
metalness: 0.72
}),
brass: new THREE.MeshStandardMaterial({
color: 0xa88245,
roughness: 0.42,
metalness: 0.66
}),
parchment: new THREE.MeshStandardMaterial({
color: 0xd9c79f,
roughness: 1
})
};
function addBox(parent, width, height, depth, material, x, y, z, cast = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
segments,
material,
x,
y,
z,
cast = true
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function beamBetween(parent, a, b, thickness, depth, material) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(thickness, length, depth),
material
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderBetween(parent, a, b, radius, material, segments = 8) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, direction.length(), segments),
material
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Deterministic pseudo-random sequence so the paving pattern is stable.
let randomSeed = 1755;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
/*
* Cutaway model base.
* A rectangular notch is left in the front-right corner so the soil,
* clay and bedrock sections can be viewed as an architectural model.
*/
const notchX = 7;
const notchZ = 5;
const modelWidth = 28;
const modelDepth = 18;
function addLayeredBase(height, y, material) {
const leftWidth = notchX + modelWidth / 2;
const leftX = -modelWidth / 2 + leftWidth / 2;
addBox(model, leftWidth, height, modelDepth, material, leftX, y, 0);
const rightWidth = modelWidth / 2 - notchX;
const rightX = notchX + rightWidth / 2;
const rightDepth = notchZ + modelDepth / 2;
const rightZ = -modelDepth / 2 + rightDepth / 2;
addBox(model, rightWidth, height, rightDepth, material, rightX, y, rightZ);
}
addLayeredBase(0.7, -0.35, materials.topsoil);
addLayeredBase(0.8, -1.1, materials.clay);
addLayeredBase(0.65, -1.825, materials.bedrock);
const backdrop = new THREE.Mesh(
new THREE.PlaneGeometry(160, 160),
new THREE.MeshStandardMaterial({ color: 0xdcd7cc, roughness: 1 })
);
backdrop.rotation.x = -Math.PI / 2;
backdrop.position.y = -2.16;
backdrop.receiveShadow = true;
scene.add(backdrop);
// Parcel surfaces and street base.
addBox(model, 11.4, 0.055, 8.2, materials.parcel, -5.0, 0.025, -3.9, false);
addBox(model, 7.8, 0.055, 7.5, materials.parcel, 7.2, 0.025, -4.45, false);
addBox(model, 20, 0.07, 5.4, materials.streetBase, -3, 0.025, 4.35, false);
addBox(model, 6, 0.07, 3.3, materials.streetBase, 10, 0.025, 3.35, false);
// Raised stone gutters and kerbs.
addBox(model, 26, 0.13, 0.2, materials.curb, 0, 0.07, 1.65, false);
addBox(model, 20, 0.13, 0.2, materials.curb, -3, 0.07, 7.02, false);
addBox(model, 6, 0.13, 0.2, materials.curb, 10, 0.07, 5.03, false);
// Portuguese-style small limestone setts, represented with six-sided stones.
const cobblePositions = [];
for (let z = 1.92; z <= 6.75; z += 0.41) {
for (let x = -12.9; x <= 12.9; x += 0.53) {
const jitterX = (random() - 0.5) * 0.08;
const jitterZ = (random() - 0.5) * 0.06;
if (x > notchX && z > notchZ) continue;
cobblePositions.push({
x: x + jitterX,
z: z + jitterZ,
angle: random() * Math.PI,
scale: 0.87 + random() * 0.22,
dark: random() > 0.72
});
}
}
const cobbleGeometry = new THREE.CylinderGeometry(0.205, 0.225, 0.085, 6);
const cobbleMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.96,
vertexColors: true
});
const cobbles = new THREE.InstancedMesh(
cobbleGeometry,
cobbleMaterial,
cobblePositions.length
);
cobbles.receiveShadow = true;
const dummy = new THREE.Object3D();
const paleStoneColor = new THREE.Color(0xcfc7b6);
const darkStoneColor = new THREE.Color(0x545957);
cobblePositions.forEach((stone, index) => {
dummy.position.set(stone.x, 0.105, stone.z);
dummy.rotation.set(0, stone.angle, 0);
dummy.scale.setScalar(stone.scale);
dummy.updateMatrix();
cobbles.setMatrixAt(index, dummy.matrix);
cobbles.setColorAt(
index,
stone.dark ? darkStoneColor : paleStoneColor
);
});
cobbles.instanceMatrix.needsUpdate = true;
if (cobbles.instanceColor) cobbles.instanceColor.needsUpdate = true;
model.add(cobbles);
// Subtle orthogonal setting-out grid for the new street pattern.
const gridVertices = [];
for (let x = -14; x <= 14; x += 2) {
gridVertices.push(x, 0.066, -8.7, x, 0.066, 1.35);
}
for (let z = -8; z <= 1; z += 2) {
gridVertices.push(-13.7, 0.066, z, 13.7, 0.066, z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridVertices, 3)
);
const gridLines = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x665d4c,
transparent: true,
opacity: 0.17
})
);
annotationGroup.add(gridLines);
// Interpretive trace of a former, irregular street alignment.
const formerStreetPoints = [
new THREE.Vector3(-13, 0.095, -1.3),
new THREE.Vector3(-8.2, 0.095, -0.4),
new THREE.Vector3(-3.8, 0.095, 0.4),
new THREE.Vector3(0.5, 0.095, 1.1),
new THREE.Vector3(4.6, 0.095, 1.55)
];
const formerStreet = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(formerStreetPoints),
new THREE.LineDashedMaterial({
color: 0xc8873f,
dashSize: 0.42,
gapSize: 0.24,
transparent: true,
opacity: 0.92
})
);
formerStreet.computeLineDistances();
annotationGroup.add(formerStreet);
/*
* Cleared street edge and survey setting.
*/
addBox(surveyGroup, 19.2, 0.045, 1.65, materials.cleared, -2.55, 0.08, 1.45, false);
const stakePositions = [];
for (let x = -11.2; x <= 6.5; x += 1.77) {
stakePositions.push(x);
}
stakePositions.forEach((x) => {
const stake = addCylinder(
surveyGroup,
0.042,
0.065,
1.08,
8,
materials.stake,
x,
0.57,
1.12
);
stake.rotation.z = (random() - 0.5) * 0.035;
addCylinder(
surveyGroup,
0.047,
0.047,
0.17,
8,
materials.redPaint,
x,
1.0,
1.12
);
const tie = new THREE.Mesh(
new THREE.TorusGeometry(0.079, 0.014, 6, 14),
materials.rope
);
tie.rotation.x = Math.PI / 2;
tie.position.set(x, 0.93, 1.12);
tie.castShadow = true;
surveyGroup.add(tie);
});
// Slightly sagging rope between the stakes.
for (let i = 0; i < stakePositions.length - 1; i++) {
const x1 = stakePositions[i];
const x2 = stakePositions[i + 1];
const curve = new THREE.QuadraticBezierCurve3(
new THREE.Vector3(x1, 0.91, 1.12),
new THREE.Vector3((x1 + x2) / 2, 0.61, 1.12),
new THREE.Vector3(x2, 0.91, 1.12)
);
const rope = new THREE.Mesh(
new THREE.TubeGeometry(curve, 18, 0.022, 6, false),
materials.rope
);
rope.castShadow = true;
surveyGroup.add(rope);
}
// A period-style iron surveyor's chain, represented as 20 m in model scale.
const chainGeometry = new THREE.TorusGeometry(0.145, 0.022, 6, 14);
const chain = new THREE.InstancedMesh(chainGeometry, materials.iron, 41);
const chainDummy = new THREE.Object3D();
for (let i = 0; i <= 40; i++) {
chainDummy.position.set(-10 + i * 0.5, 0.155, 2.57);
chainDummy.rotation.set(i % 2 === 0 ? 0 : Math.PI / 2, 0, 0);
chainDummy.scale.set(1.38, 0.78, 1);
chainDummy.updateMatrix();
chain.setMatrixAt(i, chainDummy.matrix);
}
chain.instanceMatrix.needsUpdate = true;
chain.castShadow = true;
surveyGroup.add(chain);
[-10, 10].forEach((x) => {
const handleRing = new THREE.Mesh(
new THREE.TorusGeometry(0.2, 0.034, 7, 18),
materials.brass
);
handleRing.position.set(x, 0.18, 2.57);
handleRing.rotation.y = Math.PI / 2;
handleRing.castShadow = true;
surveyGroup.add(handleRing);
});
for (let x = -8; x <= 8; x += 2) {
const tally = new THREE.Mesh(
new THREE.SphereGeometry(0.055, 8, 6),
materials.brass
);
tally.position.set(x, 0.18, 2.57);
surveyGroup.add(tally);
}
// Generic drawing board and parchment plan.
const board = new THREE.Group();
board.position.set(-11.15, 0.16, 3.8);
board.rotation.y = 0.18;
surveyGroup.add(board);
addBox(board, 1.1, 0.09, 0.78, materials.timberDark, 0, 0.46, 0);
addBox(board, 0.13, 0.45, 0.13, materials.timber, -0.38, 0.23, -0.2);
addBox(board, 0.13, 0.45, 0.13, materials.timber, 0.38, 0.23, -0.2);
addBox(board, 0.13, 0.45, 0.13, materials.timber, -0.38, 0.23, 0.2);
addBox(board, 0.13, 0.45, 0.13, materials.timber, 0.38, 0.23, 0.2);
function makePlanTexture() {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 320;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#d8c69c";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = "rgba(89, 73, 49, 0.20)";
ctx.lineWidth = 1;
for (let x = 0; x <= 512; x += 32) {
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, 320);
ctx.stroke();
}
for (let y = 0; y <= 320; y += 32) {
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(512, y);
ctx.stroke();
}
ctx.strokeStyle = "#665039";
ctx.lineWidth = 3;
ctx.strokeRect(58, 46, 156, 96);
ctx.strokeRect(251, 72, 172, 128);
ctx.beginPath();
ctx.moveTo(42, 236);
ctx.lineTo(238, 170);
ctx.lineTo(455, 217);
ctx.stroke();
ctx.strokeStyle = "#9b4e3d";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(250, 24);
ctx.lineTo(250, 282);
ctx.stroke();
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const planMaterial = new THREE.MeshStandardMaterial({
map: makePlanTexture(),
roughness: 1
});
const plan = new THREE.Mesh(new THREE.PlaneGeometry(0.97, 0.65), planMaterial);
plan.rotation.x = -Math.PI / 2;
plan.position.y = 0.511;
board.add(plan);
// Brass dividers resting on the plan.
beamBetween(board, [-0.06, 0.535, 0.04], [-0.25, 0.535, 0.25], 0.018, 0.012, materials.brass);
beamBetween(board, [-0.06, 0.535, 0.04], [0.18, 0.535, 0.19], 0.018, 0.012, materials.brass);
// Folding carpenter's square.
const square = new THREE.Group();
square.position.set(-10.15, 0.15, 2.55);
square.rotation.y = -0.34;
surveyGroup.add(square);
addBox(square, 1.42, 0.075, 0.13, materials.timber, 0.55, 0.02, 0);
addBox(square, 0.13, 0.075, 0.95, materials.timber, -0.1, 0.02, 0.42);
const hinge = new THREE.Mesh(
new THREE.CylinderGeometry(0.065, 0.065, 0.09, 12),
materials.brass
);
hinge.position.set(-0.1, 0.025, 0);
hinge.castShadow = true;
square.add(hinge);
// Plumb bob on a short cord.
const plumbCord = cylinderBetween(
surveyGroup,
[-11.18, 1.04, 1.14],
[-11.18, 0.36, 1.14],
0.009,
materials.rope,
6
);
plumbCord.castShadow = false;
const bobProfile = [
new THREE.Vector2(0, 0),
new THREE.Vector2(0.09, 0.02),
new THREE.Vector2(0.105, 0.12),
new THREE.Vector2(0.065, 0.24),
new THREE.Vector2(0, 0.29)
];
const plumbBob = new THREE.Mesh(
new THREE.LatheGeometry(bobProfile, 12),
materials.iron
);
plumbBob.position.set(-11.18, 0.12, 1.14);
plumbBob.castShadow = true;
surveyGroup.add(plumbBob);
// Shovel and mallet, placed outside the active measuring line.
cylinderBetween(
surveyGroup,
[-12.15, 0.16, 4.28],
[-11.72, 1.88, 4.48],
0.035,
materials.timber,
8
);
const shovelBlade = addBox(
surveyGroup,
0.43,
0.52,
0.08,
materials.iron,
-12.2,
0.22,
4.23
);
shovelBlade.rotation.set(0.15, 0.22, -0.12);
cylinderBetween(
surveyGroup,
[-9.85, 0.13, 4.3],
[-9.45, 0.13, 4.38],
0.04,
materials.timber,
8
);
const malletHead = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.12, 0.45, 12),
materials.timberDark
);
malletHead.rotation.z = Math.PI / 2;
malletHead.position.set(-9.45, 0.2, 4.38);
malletHead.castShadow = true;
surveyGroup.add(malletHead);
/*
* Open-front masonry house with an interpretive timber cage.
*/
addBox(infillGroup, 9.55, 0.42, 7.55, materials.stone, -5.2, 0.21, -3.45);
// Lower masonry infill at the back and side.
addBox(infillGroup, 9.0, 2.72, 0.28, materials.brick, -5.2, 1.77, -6.92);
addBox(infillGroup, 0.28, 2.72, 7.05, materials.brick, -9.62, 1.77, -3.45);
addBox(infillGroup, 0.28, 2.72, 3.35, materials.brick, -0.78, 1.77, -5.3);
// Upper infill leaves the central framing visible.
addBox(infillGroup, 3.5, 2.72, 0.28, materials.brick, -3.15, 4.61, -6.92);
addBox(infillGroup, 0.28, 2.72, 3.25, materials.brick, -9.62, 4.61, -5.35);
// Pale plaster finish on part of the lower side wall.
addBox(infillGroup, 0.035, 2.4, 2.65, materials.plasterLight, -9.765, 1.75, -2.7, false);
const postXs = [-9.35, -5.2, -1.05];
const postZs = [-6.88, -0.02];
postXs.forEach((x) => {
postZs.forEach((z) => {
addBox(timberGroup, 0.3, 5.8, 0.3, materials.timber, x, 3.33, z);
});
});
[0.43, 3.18, 6.22].forEach((y) => {
postZs.forEach((z) => {
addBox(timberGroup, 8.62, 0.28, 0.3, materials.timber, -5.2, y, z);
});
[-9.35, -1.05].forEach((x) => {
addBox(timberGroup, 0.3, 0.28, 7.15, materials.timber, x, y, -3.45);
});
});
// Visible X-bracing at upper levels and on the side wall.
beamBetween(timberGroup, [-9.3, 3.35, -6.89], [-5.25, 6.1, -6.89], 0.18, 0.16, materials.timberDark);
beamBetween(timberGroup, [-5.25, 3.35, -6.89], [-9.3, 6.1, -6.89], 0.18, 0.16, materials.timberDark);
beamBetween(timberGroup, [-5.15, 3.35, -6.89], [-1.1, 6.1, -6.89], 0.18, 0.16, materials.timberDark);
beamBetween(timberGroup, [-1.1, 3.35, -6.89], [-5.15, 6.1, -6.89], 0.18, 0.16, materials.timberDark);
beamBetween(timberGroup, [-9.36, 3.35, -0.05], [-9.36, 6.1, -6.85], 0.18, 0.16, materials.timberDark);
beamBetween(timberGroup, [-9.36, 3.35, -6.85], [-9.36, 6.1, -0.05], 0.18, 0.16, materials.timberDark);
beamBetween(timberGroup, [-1.06, 3.35, -0.05], [-1.06, 6.1, -6.85], 0.18, 0.16, materials.timberDark);
beamBetween(timberGroup, [-1.06, 3.35, -6.85], [-1.06, 6.1, -0.05], 0.18, 0.16, materials.timberDark);
// Open roof rafters and ridge.
beamBetween(timberGroup, [-9.35, 6.25, -0.02], [-5.2, 7.55, -3.45], 0.2, 0.18, materials.timber);
beamBetween(timberGroup, [-5.2, 7.55, -3.45], [-1.05, 6.25, -0.02], 0.2, 0.18, materials.timber);
beamBetween(timberGroup, [-9.35, 6.25, -6.88], [-5.2, 7.55, -3.45], 0.2, 0.18, materials.timber);
beamBetween(timberGroup, [-5.2, 7.55, -3.45], [-1.05, 6.25, -6.88], 0.2, 0.18, materials.timber);
addBox(timberGroup, 0.22, 0.22, 7.1, materials.timber, -5.2, 7.55, -3.45);
// Timber floor joists visible in the open section.
for (let x = -8.95; x <= -1.4; x += 0.75) {
addBox(timberGroup, 0.12, 0.17, 6.55, materials.timberDark, x, 3.1, -3.45);
}
// Small dark pegs on the main posts.
postXs.forEach((x) => {
postZs.forEach((z) => {
[0.9, 3.18, 5.7].forEach((y) => {
const peg = addCylinder(
timberGroup,
0.045,
0.045,
0.08,
8,
materials.timberDark,
x,
y,
z + 0.17
);
peg.rotation.x = Math.PI / 2;
});
});
});
/*
* A completed masonry house provides context for the rebuilt district.
*/
addBox(infillGroup, 6.65, 0.42, 6.65, materials.stone, 7.0, 0.21, -4.5);
addBox(infillGroup, 6.25, 8.05, 0.28, materials.plasterLight, 7.0, 4.46, -1.3);
addBox(infillGroup, 0.28, 8.05, 6.25, materials.plaster, 10.08, 4.46, -4.5);
addBox(infillGroup, 0.28, 8.05, 6.25, materials.plaster, 3.92, 4.46, -4.5);
// Pilasters and a stone cornice.
[4.1, 7.0, 9.9].forEach((x) => {
addBox(infillGroup, 0.22, 7.9, 0.16, materials.paleStone, x, 4.42, -1.12);
});
addBox(infillGroup, 6.45, 0.2, 0.26, materials.paleStone, 7.0, 8.37, -1.08);
addBox(infillGroup, 6.45, 0.18, 0.26, materials.paleStone, 7.0, 5.93, -1.08);
function addWindow(x, y, width = 0.92, height = 1.35) {
addBox(infillGroup, width + 0.22, height + 0.2, 0.1, materials.paleStone, x, y, -1.12);
addBox(infillGroup, width, height, 0.11, materials.window, x, y, -1.055);
addBox(infillGroup, 0.045, height, 0.13, materials.paleStone, x, y, -1.0);
addBox(infillGroup, width, 0.045, 0.13, materials.paleStone, x, y, -1.0);
addBox(infillGroup, width * 0.47, height + 0.04, 0.09, materials.shutter, x - width * 0.76, y, -1.02);
addBox(infillGroup, width * 0.47, height + 0.04, 0.09, materials.shutter, x + width * 0.76, y, -1.02);
}
addWindow(4.92, 2.15);
addWindow(7.0, 2.15);
addWindow(9.08, 2.15);
addWindow(4.92, 4.55);
addWindow(7.0, 4.55);
addWindow(9.08, 4.55);
addWindow(5.2, 6.85, 0.78, 1.15);
addWindow(8.8, 6.85, 0.78, 1.15);
addBox(infillGroup, 1.08, 2.15, 0.16, materials.stone, 7.0, 1.48, -1.08);
addBox(infillGroup, 0.79, 1.9, 0.12, materials.timberDark, 7.0, 1.43, -0.985);
addBox(infillGroup, 0.045, 1.9, 0.14, materials.timber, 7.0, 1.43, -0.91);
// Triangular terracotta roof prism, built without external geometry helpers.
const roofShape = new THREE.Shape();
roofShape.moveTo(-3.35, 0);
roofShape.lineTo(0, 1.55);
roofShape.lineTo(3.35, 0);
roofShape.closePath();
const roofGeometry = new THREE.ExtrudeGeometry(roofShape, {
depth: 6.72,
bevelEnabled: false,
steps: 1
});
const roofMesh = new THREE.Mesh(roofGeometry, materials.roof);
roofMesh.position.set(7.0, 8.48, -7.76);
roofMesh.castShadow = true;
roofMesh.receiveShadow = true;
infillGroup.add(roofMesh);
const ridge = addCylinder(
infillGroup,
0.13,
0.13,
6.85,
10,
materials.roofDark,
7.0,
10.03,
-4.4
);
ridge.rotation.x = Math.PI / 2;
// Tile courses on the front roof slope.
for (let i = 1; i <= 5; i++) {
const t = i / 6;
const y = 8.48 + 1.55 * t;
const halfWidth = 3.35 * (1 - t);
const stripe = addBox(
infillGroup,
halfWidth * 2,
0.035,
0.035,
materials.roofDark,
7.0,
y,
-1.015
);
stripe.rotation.z = Math.atan2(1.55, 3.35);
}
/*
* Foundation stones exposed in the sectioned corner.
*/
for (let row = 0; row < 4; row++) {
for (let col = 0; col < 7; col++) {
addBox(
cutawayGroup,
0.6,
0.25,
0.13,
row === 0 ? materials.paleStone : materials.stone,
7.42 + col * 0.7,
-0.2 - row * 0.27,
5.015
);
}
}
for (let row = 0; row < 4; row++) {
for (let col = 0; col < 5; col++) {
addBox(
cutawayGroup,
0.13,
0.25,
0.65,
row === 0 ? materials.paleStone : materials.stone,
7.015,
-0.2 - row * 0.27,
5.35 + col * 0.72
);
}
}
const sectionOutline = new THREE.LineSegments(
new THREE.EdgesGeometry(
new THREE.BoxGeometry(7, 0.035, 4)
),
new THREE.LineBasicMaterial({
color: 0xd89b4c,
transparent: true,
opacity: 0.85
})
);
sectionOutline.position.set(10.5, 0.09, 7.0);
annotationGroup.add(sectionOutline);
// Neatly stacked salvaged stone beyond the measured frontage.
for (let i = 0; i < 3; i++) {
for (let j = 0; j < 2; j++) {
addBox(
surveyGroup,
0.58,
0.23,
0.38,
materials.stone,
-11.5 + j * 0.65,
0.14 + i * 0.24,
-0.35
);
}
}
/*
* HTML annotations projected from 3D positions.
*/
const pins = [];
function addPin(title, note, position, offsetX = 0, offsetY = 0) {
const element = document.createElement("div");
element.className = "pin";
element.innerHTML = `
<span class="pin-title">${title}</span>
<span class="pin-note">${note}</span>
`;
labelLayer.appendChild(element);
pins.push({
element,
position: new THREE.Vector3(...position),
offsetX,
offsetY
});
}
addPin(
"Cleared street edge",
"Stakes and rope establish a new frontage.",
[-8.7, 1.12, 1.12],
-18,
-5
);
addPin(
"20 m surveyor's chain",
"Generic eighteenth-century measuring instrument.",
[0.6, 0.34, 2.57],
8,
2
);
addPin(
"Former street trace",
"Interpretive diagonal alignment, not a surveyed location.",
[-5.0, 0.18, 0.25],
-6,
-3
);
addPin(
"Pombaline gaiola",
"Simplified timber cage tied into masonry construction.",
[-6.9, 4.95, -1.0],
-12,
-12
);
addPin(
"Masonry infill",
"Brickwork locks the timber frame into the wall.",
[-9.75, 2.15, -3.0],
-35,
0
);
addPin(
"Rebuilt masonry façade",
"Regularized frontage of the new Baixa.",
[8.95, 5.25, -1.05],
25,
-12
);
addPin(
"Sectioned foundation",
"Masonry remains shown within soil and clay.",
[10.7, -0.35, 5.05],
20,
7
);
const projection = new THREE.Vector3();
function updatePins() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
pins.forEach((pin) => {
projection.copy(pin.position).project(camera);
const visible =
projection.z > -1 &&
projection.z < 1 &&
projection.x > -1.08 &&
projection.x < 1.08 &&
projection.y > -1.05 &&
projection.y < 1.05;
pin.element.style.opacity = visible ? "1" : "0";
if (!visible) return;
const x = (projection.x * 0.5 + 0.5) * width + pin.offsetX;
const y = (-projection.y * 0.5 + 0.5) * height + pin.offsetY;
pin.element.style.left = `${x}px`;
pin.element.style.top = `${y}px`;
});
}
/*
* Direct camera controls: orbit, pan, wheel zoom, pinch zoom and keyboard.
*/
const initial = {
theta: 0.67,
phi: 1.02,
radius: 28,
target: new THREE.Vector3(-0.2, 1.4, -0.5)
};
const desired = {
theta: initial.theta,
phi: initial.phi,
radius: initial.radius,
target: initial.target.clone()
};
const actual = {
theta: initial.theta,
phi: initial.phi,
radius: initial.radius,
target: initial.target.clone()
};
let autoRotate = false;
let dragging = false;
let panning = false;
let lastX = 0;
let lastY = 0;
let activePointer = null;
let pinchDistance = 0;
const pointers = new Map();
const canvas = renderer.domElement;
function resetView() {
desired.theta = initial.theta;
desired.phi = initial.phi;
desired.radius = initial.radius;
desired.target.copy(initial.target);
}
function setPointerMode(event) {
panning =
event.button === 2 ||
event.button === 1 ||
event.shiftKey;
}
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
activePointer = event.pointerId;
dragging = true;
setPointerMode(event);
lastX = event.clientX;
lastY = event.clientY;
} else if (pointers.size === 2) {
dragging = false;
const points = [...pointers.values()];
pinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size >= 2) {
const points = [...pointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (pinchDistance > 0 && distance > 0) {
desired.radius = THREE.MathUtils.clamp(
desired.radius * (pinchDistance / distance),
11,
48
);
}
pinchDistance = distance;
return;
}
if (!dragging || event.pointerId !== activePointer) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (panning) {
const right = new THREE.Vector3(1, 0, 0).applyQuaternion(camera.quaternion);
right.y = 0;
right.normalize();
const forward = camera.getWorldDirection(new THREE.Vector3());
forward.y = 0;
forward.normalize();
const scale = desired.radius * 0.00135;
desired.target
.addScaledVector(right, -dx * scale)
.addScaledVector(forward, dy * scale);
desired.target.x = THREE.MathUtils.clamp(desired.target.x, -10, 10);
desired.target.z = THREE.MathUtils.clamp(desired.target.z, -8, 7);
} else {
desired.theta -= dx * 0.005;
desired.phi = THREE.MathUtils.clamp(
desired.phi - dy * 0.005,
0.35,
1.43
);
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (event.pointerId === activePointer) {
activePointer = null;
dragging = false;
}
if (pointers.size === 1) {
const remaining = [...pointers.entries()][0];
activePointer = remaining[0];
lastX = remaining[1].x;
lastY = remaining[1].y;
pinchDistance = 0;
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("lostpointercapture", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
11,
48
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
canvas.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "arrowleft") desired.theta += 0.08;
else if (key === "arrowright") desired.theta -= 0.08;
else if (key === "arrowup") desired.phi = Math.max(0.35, desired.phi - 0.06);
else if (key === "arrowdown") desired.phi = Math.min(1.43, desired.phi + 0.06);
else if (key === "+" || key === "=") desired.radius = Math.max(11, desired.radius - 1);
else if (key === "-" || key === "_") desired.radius = Math.min(48, desired.radius + 1);
else if (key === "r") resetView();
else return;
event.preventDefault();
});
document.getElementById("reset-view").addEventListener("click", resetView);
document.getElementById("rotate-view").addEventListener("click", (event) => {
autoRotate = !autoRotate;
event.currentTarget.setAttribute("aria-pressed", String(autoRotate));
});
document.getElementById("toggle-survey").addEventListener("change", (event) => {
surveyGroup.visible = event.target.checked;
});
document.getElementById("toggle-frame").addEventListener("change", (event) => {
timberGroup.visible = event.target.checked;
});
document.getElementById("toggle-cutaway").addEventListener("change", (event) => {
cutawayGroup.visible = event.target.checked;
});
document.getElementById("toggle-labels").addEventListener("change", (event) => {
labelLayer.style.display = event.target.checked ? "block" : "none";
});
const sourcePanel = document.getElementById("source-panel");
document.getElementById("open-sources").addEventListener("click", () => {
sourcePanel.classList.add("open");
});
document.getElementById("close-sources").addEventListener("click", () => {
sourcePanel.classList.remove("open");
});
document.addEventListener("keydown", (event) => {
if (event.key === "Escape") sourcePanel.classList.remove("open");
});
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 spherical = new THREE.Spherical();
const offset = new THREE.Vector3();
function animate() {
requestAnimationFrame(animate);
if (autoRotate && !dragging) {
desired.theta += 0.0027;
}
actual.theta += (desired.theta - actual.theta) * 0.11;
actual.phi += (desired.phi - actual.phi) * 0.11;
actual.radius += (desired.radius - actual.radius) * 0.11;
actual.target.lerp(desired.target, 0.11);
spherical.set(actual.radius, actual.phi, actual.theta);
offset.setFromSpherical(spherical);
camera.position.copy(actual.target).add(offset);
camera.lookAt(actual.target);
updatePins();
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => loading.classList.add("hidden"));
</script>
</body>
</html>
```