Prompt specification
Build or customize the Three.js 3D scene "Federation Square faceted facade panel study" 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: Federation Square faceted facade panel study
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/federation-square-faceted-facade-panel-study-x3005
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing Federation Square in Melbourne. Build a simplified referenced faceted facade fragment with distinct triangular planes. Keep the panel geometry coherent and separate its visual pattern from the supporting building mass. Voxel style.
Verify the behavior against the actual geometry and data in each relevant state. Use schematic labels for deliberately synthetic elements.
Technical checks: Assign defined sandstone materials to the intended facade panels. Render the referenced faceted facade and distinguish its panel groups.
Return one complete HTML document. The file must run in a sandbox allowing inline scripts and the cdnjs Three.js r160 module. Construct procedural assets, use local event handlers and avoid remote assets, runtime network requests besides Three.js, pointer lock and native form submission. Keep the main requested geometry visible in the initial view.
Working Three.js Starter (federation-square-faceted-facade-panel-study-x3005):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Federation Square, Melbourne — Voxel Schematic</title>
<style>
:root {
--ink: #152b35;
--paper: rgba(249, 246, 237, 0.92);
--paper-solid: #f6f1e5;
--line: rgba(21, 43, 53, 0.2);
--accent: #bd754b;
--ok: #24745a;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b8cfd8;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#viewport,
#viewport canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
}
#viewport canvas {
display: block;
outline: none;
touch-action: none;
cursor: grab;
}
#viewport canvas.dragging {
cursor: grabbing;
}
.card {
position: absolute;
z-index: 5;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.68);
box-shadow: 0 10px 30px rgba(31, 48, 52, 0.16);
backdrop-filter: blur(10px);
}
#title-card {
top: 18px;
left: 18px;
width: min(360px, calc(100vw - 36px));
padding: 15px 17px 14px;
border-radius: 5px;
pointer-events: none;
}
.eyebrow {
margin: 0 0 5px;
color: #7b4931;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(20px, 2.4vw, 29px);
line-height: 1.05;
letter-spacing: -0.025em;
}
.subtitle {
margin: 7px 0 0;
color: rgba(21, 43, 53, 0.72);
font-size: 12px;
line-height: 1.45;
}
#controls {
top: 18px;
right: 18px;
display: flex;
gap: 8px;
padding: 8px;
border-radius: 5px;
}
button {
min-height: 36px;
padding: 8px 12px;
border: 1px solid rgba(21, 43, 53, 0.2);
border-radius: 4px;
background: #fffdf8;
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition: transform 120ms ease, background 120ms ease;
}
button:hover {
background: #eee5d5;
transform: translateY(-1px);
}
button:focus-visible {
outline: 3px solid rgba(45, 111, 135, 0.35);
outline-offset: 2px;
}
button[aria-pressed="true"] {
border-color: rgba(36, 116, 90, 0.45);
background: #e3eee7;
}
#geometry-card {
left: 18px;
bottom: 18px;
width: 285px;
padding: 13px 15px 14px;
border-radius: 5px;
pointer-events: none;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 9px;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.live-dot {
display: inline-block;
width: 7px;
height: 7px;
margin-right: 6px;
border-radius: 50%;
background: var(--ok);
box-shadow: 0 0 0 3px rgba(36, 116, 90, 0.12);
}
#geometry-list {
display: grid;
gap: 6px;
margin: 0;
padding: 0;
list-style: none;
font-size: 12px;
}
#geometry-list li {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
}
#geometry-list span {
color: rgba(21, 43, 53, 0.7);
}
code {
color: var(--ink);
font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
font-size: 11px;
font-weight: 700;
}
#instructions {
right: 18px;
bottom: 18px;
max-width: 310px;
padding: 10px 13px;
border-radius: 5px;
color: rgba(21, 43, 53, 0.76);
font-size: 11px;
line-height: 1.45;
pointer-events: none;
}
#labels {
position: absolute;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
top: 0;
left: 0;
max-width: 220px;
padding: 6px 8px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 3px;
background: rgba(250, 247, 238, 0.9);
box-shadow: 0 4px 13px rgba(22, 42, 49, 0.13);
color: #203640;
font-size: 10px;
font-weight: 750;
line-height: 1.25;
white-space: nowrap;
}
.scene-label::before {
content: "";
position: absolute;
top: 50%;
width: 7px;
height: 7px;
border: 2px solid #f7f3e9;
border-radius: 50%;
background: #b86e47;
transform: translate(-50%, -50%);
box-shadow: 0 0 0 1px rgba(21, 43, 53, 0.35);
}
.scene-label.align-left {
transform: translate(12px, -50%);
}
.scene-label.align-left::before {
left: -7px;
}
.scene-label.align-right {
transform: translate(calc(-100% - 12px), -50%);
}
.scene-label.align-right::before {
left: calc(100% + 7px);
}
[hidden] {
display: none !important;
}
@media (max-width: 760px) {
#title-card {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 11px 13px;
}
#controls {
top: auto;
right: 10px;
bottom: 10px;
}
#geometry-card {
left: 10px;
bottom: 10px;
width: min(260px, calc(100vw - 150px));
padding: 10px 12px;
}
#geometry-list {
gap: 4px;
font-size: 10px;
}
#instructions,
.scene-label.align-right,
#label-plaza {
display: none !important;
}
button {
padding: 7px 9px;
font-size: 10px;
}
}
</style>
</head>
<body>
<main id="viewport" aria-label="Interactive voxel model of Federation Square in Melbourne"></main>
<section id="title-card" class="card">
<p class="eyebrow">Melbourne · Victoria</p>
<h1>Federation Square</h1>
<p class="subtitle">
Simplified voxel study of the sandstone building mass and a contiguous,
triangular facade-panel fragment.
</p>
</section>
<nav id="controls" class="card" aria-label="Model controls">
<button id="pattern-toggle" type="button" aria-pressed="true">Hide panel pattern</button>
<button id="reset-view" type="button">Reset view</button>
</nav>
<section id="geometry-card" class="card" aria-label="Live geometry status">
<div class="panel-heading">
<span><span class="live-dot"></span>Live geometry</span>
<span>Schema</span>
</div>
<ul id="geometry-list">
<li><span>Left wing material</span><code id="left-material">sandstoneSide</code></li>
<li><span>Facade triangles</span><code id="triangle-count">0</code></li>
<li><span>Pattern group</span><code id="pattern-separation">separate</code></li>
<li><span>Pattern state</span><code id="pattern-state" aria-live="polite">visible</code></li>
</ul>
</section>
<aside id="instructions" class="card">
Drag to orbit · Wheel or pinch to zoom · Arrow keys to orbit ·
Double-click to reset
</aside>
<div id="labels" aria-hidden="true">
<div id="label-facade" class="scene-label align-left">
Schematic triangular facade panel field
</div>
<div id="label-left" class="scene-label align-right">
Sandstone side wing · sandstoneSide
</div>
<div id="label-visitor" class="scene-label align-left">
Schematic voxel visitors
</div>
<div id="label-plaza" class="scene-label align-left">
Schematic plaza paving
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.querySelector("#viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb8cfd8);
scene.fog = new THREE.Fog(0xb8cfd8, 27, 58);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
120
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 1.8));
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;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Federation Square voxel model. Drag to orbit and use the mouse wheel to zoom."
);
viewport.appendChild(renderer.domElement);
const hemiLight = new THREE.HemisphereLight(0xe5f3f4, 0x75513e, 2.1);
scene.add(hemiLight);
const sun = new THREE.DirectionalLight(0xffe8c8, 3.2);
sun.position.set(-9, 16, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -19;
sun.shadow.camera.right = 19;
sun.shadow.camera.top = 17;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 48;
sun.shadow.normalBias = 0.035;
sun.target.position.set(0, 2.2, 1);
scene.add(sun, sun.target);
const coolFill = new THREE.DirectionalLight(0x98c8dc, 1.15);
coolFill.position.set(12, 8, -10);
scene.add(coolFill);
// Explicit material identities are retained for every major mass.
const sandstoneMain = new THREE.MeshStandardMaterial({
name: "sandstoneMain",
color: 0xb77951,
roughness: 0.88,
metalness: 0.02
});
// This material is deliberately defined and explicitly assigned to the left wing.
const sandstoneSide = new THREE.MeshStandardMaterial({
name: "sandstoneSide",
color: 0x91583d,
roughness: 0.92,
metalness: 0.01
});
const darkGlass = new THREE.MeshStandardMaterial({
name: "recessedGlass",
color: 0x20333a,
roughness: 0.3,
metalness: 0.2
});
const pavingMaterials = [
new THREE.MeshStandardMaterial({ color: 0xd5cec0, roughness: 0.93 }),
new THREE.MeshStandardMaterial({ color: 0xc9c1b2, roughness: 0.95 }),
new THREE.MeshStandardMaterial({ color: 0xded8ca, roughness: 0.91 })
];
const panelPalette = [
new THREE.MeshStandardMaterial({
name: "panelDeepBlue", color: 0x244a61, roughness: 0.42, metalness: 0.36, flatShading: true
}),
new THREE.MeshStandardMaterial({
name: "panelBlueGrey", color: 0x54737d, roughness: 0.4, metalness: 0.34, flatShading: true
}),
new THREE.MeshStandardMaterial({
name: "panelSilver", color: 0xaebbb9, roughness: 0.38, metalness: 0.42, flatShading: true
}),
new THREE.MeshStandardMaterial({
name: "panelTeal", color: 0x3e6869, roughness: 0.46, metalness: 0.28, flatShading: true
}),
new THREE.MeshStandardMaterial({
name: "panelGraphite", color: 0x314149, roughness: 0.44, metalness: 0.32, flatShading: true
}),
new THREE.MeshStandardMaterial({
name: "panelWarmSilver", color: 0x8d9996, roughness: 0.44, metalness: 0.32, flatShading: true
}),
new THREE.MeshStandardMaterial({
name: "panelOchre", color: 0xb28a50, roughness: 0.5, metalness: 0.2, flatShading: true
})
];
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Supporting sandstone building mass.
const buildingMass = new THREE.Group();
buildingMass.name = "buildingMass";
buildingMass.userData.role = "supporting-building-mass";
scene.add(buildingMass);
const mainBlock = addBox(
buildingMass,
[10.6, 5.8, 4.3],
[0, 2.9, -0.35],
sandstoneMain
);
mainBlock.userData.role = "central-sandstone-volume";
const leftWing = addBox(
buildingMass,
[4.5, 4.65, 5.0],
[-7.45, 2.325, -0.1],
sandstoneSide
);
leftWing.name = "leftSandstoneWing";
leftWing.userData.role = "left-wing";
leftWing.userData.materialRole = "sandstoneSide";
const rightWing = addBox(
buildingMass,
[4.4, 4.45, 5.0],
[7.45, 2.225, -0.2],
sandstoneMain
);
rightWing.name = "rightSandstoneWing";
rightWing.userData.role = "right-wing";
addBox(buildingMass, [2.25, 0.55, 3.15], [-7.25, 4.85, -0.35], sandstoneSide);
addBox(buildingMass, [3.15, 0.55, 3.35], [1.55, 6.08, -0.65], sandstoneMain);
addBox(buildingMass, [2.5, 0.55, 3.1], [7.25, 4.7, -0.45], sandstoneMain);
addBox(buildingMass, [1.35, 0.7, 2.45], [-2.9, 6.05, -0.95], sandstoneMain);
// Recessed, voxel-like window openings on the two wings.
const leftFront = -0.1 + 2.5;
const rightFront = -0.2 + 2.5;
[-8.45, -7.35, -6.25].forEach((x) => {
addBox(buildingMass, [0.72, 0.74, 0.08], [x, 1.22, leftFront + 0.045], darkGlass, false);
addBox(buildingMass, [0.72, 0.74, 0.08], [x, 2.55, leftFront + 0.045], darkGlass, false);
addBox(buildingMass, [0.72, 0.74, 0.08], [x, 3.88, leftFront + 0.045], darkGlass, false);
});
[6.35, 7.5, 8.6].forEach((x) => {
addBox(buildingMass, [0.72, 0.72, 0.08], [x, 1.2, rightFront + 0.045], darkGlass, false);
addBox(buildingMass, [0.72, 0.72, 0.08], [x, 2.5, rightFront + 0.045], darkGlass, false);
addBox(buildingMass, [0.72, 0.72, 0.08], [x, 3.78, rightFront + 0.045], darkGlass, false);
});
// Facade support is separate from both the sandstone mass and its visual panel group.
const facadeAssembly = new THREE.Group();
facadeAssembly.name = "facadeAssembly";
facadeAssembly.userData.role = "facade-support";
scene.add(facadeAssembly);
addBox(
facadeAssembly,
[9.15, 4.95, 0.14],
[0, 3.05, 1.79],
darkGlass,
false
);
addBox(facadeAssembly, [0.22, 5.05, 0.30], [-4.57, 3.05, 1.92], sandstoneMain);
addBox(facadeAssembly, [0.22, 5.05, 0.30], [4.57, 3.05, 1.92], sandstoneMain);
addBox(facadeAssembly, [9.35, 0.22, 0.30], [0, 0.63, 1.92], sandstoneMain);
addBox(facadeAssembly, [9.35, 0.22, 0.30], [0, 5.48, 1.92], sandstoneMain);
// The pattern group contains only the triangular visual panels and their seams.
const facadePattern = new THREE.Group();
facadePattern.name = "facadePattern";
facadePattern.userData.role = "visual-triangular-pattern";
facadeAssembly.add(facadePattern);
const cols = 8;
const rows = 5;
const panelWidth = 8.8;
const panelHeight = 4.6;
const panelX0 = -panelWidth / 2;
const panelY0 = 0.75;
const dx = panelWidth / cols;
const dy = panelHeight / rows;
function hash01(i, j, salt = 0) {
let n = (
Math.imul(i + 11, 374761393) +
Math.imul(j + 17, 668265263) +
Math.imul(salt + 31, 2246822519)
) >>> 0;
n = Math.imul(n ^ (n >>> 13), 1274126177);
return ((n ^ (n >>> 16)) >>> 0) / 4294967295;
}
// A shared vertex cache guarantees that adjoining triangles meet at exactly
// the same coordinates, including their faceted depth offsets.
const sharedVertices = new Map();
function panelVertex(i, j) {
const key = `${i}:${j}`;
if (sharedVertices.has(key)) return sharedVertices.get(key);
const z = 1.97 + (hash01(i, j, 7) - 0.5) * 0.14;
const vertex = new THREE.Vector3(
panelX0 + i * dx,
panelY0 + j * dy,
z
);
sharedVertices.set(key, vertex);
return vertex;
}
const triangleMeshes = [];
const edgeMap = new Map();
function registerEdge(a, b) {
const aKey = `${a.x.toFixed(4)},${a.y.toFixed(4)},${a.z.toFixed(4)}`;
const bKey = `${b.x.toFixed(4)},${b.y.toFixed(4)},${b.z.toFixed(4)}`;
const key = aKey < bKey ? `${aKey}|${bKey}` : `${bKey}|${aKey}`;
if (!edgeMap.has(key)) edgeMap.set(key, [a, b]);
}
function addTriangle(a, b, c, materialIndex, cellIndex, triangleIndex) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
a.x, a.y, a.z,
b.x, b.y, b.z,
c.x, c.y, c.z
], 3)
);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, panelPalette[materialIndex]);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.userData.role = "triangular-facade-panel";
mesh.userData.cellIndex = cellIndex;
mesh.userData.triangleIndex = triangleIndex;
facadePattern.add(mesh);
triangleMeshes.push(mesh);
registerEdge(a, b);
registerEdge(b, c);
registerEdge(c, a);
}
let cellIndex = 0;
let triangleIndex = 0;
for (let j = 0; j < rows; j++) {
for (let i = 0; i < cols; i++) {
// Stepped corners produce one coherent facade fragment rather than
// disconnected floating triangles.
const omittedCorner =
(j === 0 || j === rows - 1) &&
(i === 0 || i === cols - 1);
if (omittedCorner) continue;
const p00 = panelVertex(i, j);
const p10 = panelVertex(i + 1, j);
const p01 = panelVertex(i, j + 1);
const p11 = panelVertex(i + 1, j + 1);
const colorA = Math.floor(hash01(i, j, 2) * panelPalette.length);
const colorB = Math.floor(hash01(i, j, 5) * panelPalette.length);
const accent = (i * 5 + j * 3) % 13 === 0;
const materialA = accent ? panelPalette.length - 1 : colorA;
const materialB = accent ? panelPalette.length - 2 : colorB;
if ((i + j) % 2 === 0) {
addTriangle(p00, p10, p11, materialA, cellIndex, triangleIndex++);
addTriangle(p00, p11, p01, materialB, cellIndex, triangleIndex++);
} else {
addTriangle(p00, p10, p01, materialA, cellIndex, triangleIndex++);
addTriangle(p10, p11, p01, materialB, cellIndex, triangleIndex++);
}
cellIndex++;
}
}
const seamPositions = [];
edgeMap.forEach(([a, b]) => {
seamPositions.push(a.x, a.y, a.z, b.x, b.y, b.z);
});
const seamGeometry = new THREE.BufferGeometry();
seamGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(seamPositions, 3)
);
const seamMaterial = new THREE.LineBasicMaterial({
color: 0x172f38,
transparent: true,
opacity: 0.62
});
const panelSeams = new THREE.LineSegments(seamGeometry, seamMaterial);
panelSeams.name = "triangularPanelSeams";
panelSeams.userData.role = "panel-seam-overlay";
facadePattern.add(panelSeams);
// Stepped sandstone approach blocks.
addBox(buildingMass, [9.3, 0.18, 0.85], [0, 0.09, 2.55], sandstoneMain);
addBox(buildingMass, [8.7, 0.18, 0.85], [0, 0.27, 3.05], sandstoneMain);
addBox(buildingMass, [8.1, 0.18, 0.85], [0, 0.45, 3.55], sandstoneMain);
// Abstract plaza base and paving.
addBox(scene, [46, 0.32, 42], [0, -0.22, 2.5], new THREE.MeshStandardMaterial({
color: 0xb9b0a1,
roughness: 1
}), false);
const tileGeometry = new THREE.BoxGeometry(2.5, 0.08, 2.28);
for (let row = 0; row < 6; row++) {
for (let column = -5; column <= 5; column++) {
const tile = new THREE.Mesh(
tileGeometry,
pavingMaterials[(row + column + 30) % pavingMaterials.length]
);
tile.position.set(column * 2.65, -0.01, 4.15 + row * 2.42);
tile.receiveShadow = true;
scene.add(tile);
}
}
// Deliberately synthetic voxel visitors, identified by an on-screen label.
function createVisitor(x, z, bodyColor, scale = 1) {
const visitor = new THREE.Group();
visitor.position.set(x, 0.05, z);
visitor.scale.setScalar(scale);
const bodyMaterial = new THREE.MeshStandardMaterial({
color: bodyColor,
roughness: 0.8
});
const trouserMaterial = new THREE.MeshStandardMaterial({
color: 0x293c44,
roughness: 0.86
});
const skinMaterial = new THREE.MeshStandardMaterial({
color: 0xd6a47e,
roughness: 0.86
});
addBox(visitor, [0.17, 0.47, 0.18], [-0.11, 0.24, 0], trouserMaterial);
addBox(visitor, [0.17, 0.47, 0.18], [0.11, 0.24, 0], trouserMaterial);
addBox(visitor, [0.43, 0.55, 0.25], [0, 0.73, 0], bodyMaterial);
addBox(visitor, [0.13, 0.46, 0.14], [-0.29, 0.73, 0], bodyMaterial);
addBox(visitor, [0.13, 0.46, 0.14], [0.29, 0.73, 0], bodyMaterial);
addBox(visitor, [0.28, 0.28, 0.27], [0, 1.15, 0], skinMaterial);
scene.add(visitor);
return visitor;
}
createVisitor(-1.55, 5.7, 0x315f79, 1);
createVisitor(3.25, 6.85, 0xa85f45, 0.9);
// Direct camera controls: no pointer lock and no external control addon.
const controls = {
target: new THREE.Vector3(0, 2.75, 0.4),
yaw: 0.34,
pitch: 0.34,
distance: 19,
dragging: false,
pointerId: null,
lastX: 0,
lastY: 0
};
function preferredHomeDistance() {
const aspect = window.innerWidth / window.innerHeight;
return aspect < 1 ? 31 : 19;
}
function updateCamera() {
const horizontalDistance = Math.cos(controls.pitch) * controls.distance;
camera.position.set(
controls.target.x + Math.sin(controls.yaw) * horizontalDistance,
controls.target.y + Math.sin(controls.pitch) * controls.distance,
controls.target.z + Math.cos(controls.yaw) * horizontalDistance
);
camera.lookAt(controls.target);
}
function resetView() {
controls.yaw = 0.34;
controls.pitch = 0.34;
controls.distance = preferredHomeDistance();
updateCamera();
}
resetView();
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
controls.dragging = true;
controls.pointerId = event.pointerId;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
canvas.focus({ preventScroll: true });
});
canvas.addEventListener("pointermove", (event) => {
if (!controls.dragging || event.pointerId !== controls.pointerId) return;
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
controls.yaw -= dx * 0.006;
controls.pitch = THREE.MathUtils.clamp(controls.pitch + dy * 0.005, 0.12, 1.25);
updateCamera();
});
function endPointerDrag(event) {
if (event.pointerId !== controls.pointerId) return;
controls.dragging = false;
controls.pointerId = null;
canvas.classList.remove("dragging");
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endPointerDrag);
canvas.addEventListener("pointercancel", endPointerDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.distance = THREE.MathUtils.clamp(
controls.distance * Math.exp(event.deltaY * 0.001),
10,
42
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
canvas.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
controls.yaw += 0.08;
break;
case "ArrowRight":
controls.yaw -= 0.08;
break;
case "ArrowUp":
controls.pitch = THREE.MathUtils.clamp(controls.pitch + 0.06, 0.12, 1.25);
break;
case "ArrowDown":
controls.pitch = THREE.MathUtils.clamp(controls.pitch - 0.06, 0.12, 1.25);
break;
case "+":
case "=":
controls.distance = Math.max(10, controls.distance - 1);
break;
case "-":
controls.distance = Math.min(42, controls.distance + 1);
break;
case "Home":
resetView();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
// Live values are read from the actual scene graph rather than duplicated constants.
const leftMaterialValue = document.querySelector("#left-material");
const triangleCountValue = document.querySelector("#triangle-count");
const patternSeparationValue = document.querySelector("#pattern-separation");
const patternStateValue = document.querySelector("#pattern-state");
const patternToggle = document.querySelector("#pattern-toggle");
const resetButton = document.querySelector("#reset-view");
const facadeLabel = document.querySelector("#label-facade");
function refreshGeometryStatus() {
const leftMaterialIsCorrect = leftWing.material === sandstoneSide;
const patternIsSeparate =
facadePattern.parent === facadeAssembly &&
!buildingMass.getObjectById(facadePattern.id);
leftMaterialValue.textContent = leftWing.material.name;
leftMaterialValue.style.color = leftMaterialIsCorrect ? "#24745a" : "#a13b32";
triangleCountValue.textContent = String(triangleMeshes.length);
patternSeparationValue.textContent = patternIsSeparate ? "separate" : "incorrect";
patternSeparationValue.style.color = patternIsSeparate ? "#24745a" : "#a13b32";
patternStateValue.textContent = facadePattern.visible ? "visible" : "hidden";
patternToggle.setAttribute("aria-pressed", String(facadePattern.visible));
patternToggle.textContent = facadePattern.visible
? "Hide panel pattern"
: "Show panel pattern";
facadeLabel.innerHTML =
`Schematic triangular facade panel field<br>${triangleMeshes.length} contiguous triangles`;
}
patternToggle.addEventListener("click", () => {
facadePattern.visible = !facadePattern.visible;
refreshGeometryStatus();
});
resetButton.addEventListener("click", resetView);
refreshGeometryStatus();
const labelDefinitions = [
{
element: facadeLabel,
anchor: new THREE.Vector3(2.5, 4.72, 2.05),
alignment: "align-left",
requiresPattern: true
},
{
element: document.querySelector("#label-left"),
anchor: new THREE.Vector3(-7.45, 4.7, 2.35),
alignment: "align-right"
},
{
element: document.querySelector("#label-visitor"),
anchor: new THREE.Vector3(-1.55, 1.52, 5.7),
alignment: "align-left"
},
{
element: document.querySelector("#label-plaza"),
anchor: new THREE.Vector3(8.0, 0.2, 8.4),
alignment: "align-left"
}
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
labelDefinitions.forEach((definition) => {
projected.copy(definition.anchor).project(camera);
const onScreen =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.08 &&
projected.x < 1.08 &&
projected.y > -1.08 &&
projected.y < 1.08;
const permitted =
!definition.requiresPattern || facadePattern.visible;
definition.element.hidden = !(onScreen && permitted);
if (definition.element.hidden) return;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
definition.element.style.left = `${x}px`;
definition.element.style.top = `${y}px`;
definition.element.className = `scene-label ${definition.alignment}`;
});
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 1.8));
renderer.setSize(window.innerWidth, window.innerHeight);
});
renderer.setAnimationLoop(() => {
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```