Prompt specification
Build or customize the Three.js 3D scene "Brasília pilotis column and open ground floor" 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: Brasília pilotis column and open ground floor
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/bras-lia-pilotis-column-and-open-ground-floor-x2649
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring residential pilotis in Brasília. Build a referenced residential pilotis fragment with columns supporting a raised floor slab. Show the walkable space beneath and distinguish structure from the open ground plane. Voxel style.
Working Three.js Starter (bras-lia-pilotis-column-and-open-ground-floor-x2649):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Pilotis — Brasília Residential Fragment</title>
<style>
:root {
--ink: #263432;
--muted: #65736d;
--paper: rgba(248, 246, 238, 0.86);
--line: rgba(38, 52, 50, 0.16);
--accent: #315c56;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce7df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#app,
canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
}
canvas {
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.title-card {
position: absolute;
top: 24px;
left: 24px;
max-width: min(440px, calc(100vw - 48px));
padding: 17px 19px 16px;
border: 1px solid var(--line);
border-radius: 3px;
background: var(--paper);
box-shadow: 0 12px 32px rgba(39, 54, 49, 0.08);
backdrop-filter: blur(14px);
}
.eyebrow {
margin: 0 0 7px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 39px);
font-weight: 650;
line-height: 0.98;
letter-spacing: -0.045em;
}
.subtitle {
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.legend {
position: absolute;
top: 24px;
right: 24px;
width: 208px;
padding: 15px 16px;
border: 1px solid var(--line);
border-radius: 3px;
background: var(--paper);
box-shadow: 0 12px 32px rgba(39, 54, 49, 0.08);
backdrop-filter: blur(14px);
}
.legend-title {
margin-bottom: 10px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 12px 1fr;
align-items: center;
gap: 9px;
margin: 8px 0;
font-size: 11px;
}
.swatch {
width: 12px;
height: 12px;
border: 1px solid rgba(35, 47, 43, 0.18);
}
.swatch.structure {
background: #e8e0cf;
}
.swatch.housing {
background: #f7f4e9;
}
.swatch.paving {
background: #cdbd9f;
}
.swatch.ground {
background: #9fac95;
}
.swatch.glass {
background: #365e5b;
}
.views {
position: absolute;
right: 24px;
bottom: 24px;
display: flex;
gap: 5px;
padding: 5px;
border: 1px solid var(--line);
border-radius: 4px;
background: var(--paper);
box-shadow: 0 10px 28px rgba(39, 54, 49, 0.08);
backdrop-filter: blur(14px);
pointer-events: auto;
}
.views button {
appearance: none;
border: 0;
border-radius: 2px;
padding: 9px 11px;
background: transparent;
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.07em;
text-transform: uppercase;
cursor: pointer;
transition:
background 160ms ease,
color 160ms ease;
}
.views button:hover,
.views button.active {
background: var(--ink);
color: #f9f7ef;
}
.instructions {
position: absolute;
left: 24px;
bottom: 24px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 3px;
background: rgba(248, 246, 238, 0.74);
color: var(--muted);
font-size: 10px;
letter-spacing: 0.035em;
backdrop-filter: blur(10px);
}
.annotation {
position: absolute;
z-index: 3;
padding: 6px 8px;
border: 1px solid rgba(38, 52, 50, 0.19);
border-radius: 2px;
background: rgba(249, 247, 239, 0.91);
color: #34433f;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.13em;
line-height: 1;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -100%);
box-shadow: 0 5px 16px rgba(37, 49, 45, 0.08);
transition: opacity 100ms linear;
}
.annotation::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 18px;
background: rgba(38, 52, 50, 0.38);
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #dce7df;
color: #3f514b;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
transition: opacity 500ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
.title-card {
top: 14px;
left: 14px;
padding: 13px 14px;
}
.subtitle {
display: none;
}
.legend {
top: 14px;
right: 14px;
width: 145px;
padding: 11px;
}
.legend-row {
margin: 6px 0;
font-size: 9px;
}
.views {
right: 14px;
bottom: 14px;
}
.views button {
padding: 8px;
font-size: 8px;
}
.instructions {
left: 14px;
bottom: 14px;
max-width: 170px;
line-height: 1.45;
}
.annotation {
display: none;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div class="hud">
<header class="title-card">
<p class="eyebrow">Brasília · Residential Architecture</p>
<h1>Pilotis<br />Fragment</h1>
<p class="subtitle">
A raised modernist floor carried above a continuous, walkable ground.
</p>
</header>
<aside class="legend" aria-label="Scene legend">
<div class="legend-title">Material Layers</div>
<div class="legend-row">
<span class="swatch structure"></span>
<span>Concrete frame</span>
</div>
<div class="legend-row">
<span class="swatch housing"></span>
<span>Occupied shell</span>
</div>
<div class="legend-row">
<span class="swatch paving"></span>
<span>Walkable undercroft</span>
</div>
<div class="legend-row">
<span class="swatch ground"></span>
<span>Open ground</span>
</div>
<div class="legend-row">
<span class="swatch glass"></span>
<span>Glazing</span>
</div>
</aside>
<div class="instructions">
Drag to orbit · Shift-drag to pan · Scroll to zoom
</div>
<nav class="views" aria-label="Camera views">
<button class="active" data-view="overview">Axonometric</button>
<button data-view="undercroft">Undercroft</button>
<button data-view="fragment">Fragment</button>
<button data-view="plan">Plan</button>
</nav>
</div>
<div class="annotation" id="label-slab">Raised floor slab</div>
<div class="annotation" id="label-column">Pilotis</div>
<div class="annotation" id="label-ground">Walkable ground</div>
<div id="loading">Constructing spatial fragment</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene, camera
// ------------------------------------------------------------
const app = document.querySelector("#app");
const loading = document.querySelector("#loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce7df);
scene.fog = new THREE.Fog(0xdce7df, 38, 92);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.04;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel-style Brasília residential pilotis scene"
);
app.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-18, 18, 10.5, -10.5, 0.1, 160);
const cameraState = {
azimuth: 0.72,
elevation: 0.58,
zoom: 1,
target: new THREE.Vector3(0, 2.15, 0)
};
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xf8fbef, 0x657267, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff3d8, 3.25);
sun.position.set(-12, 20, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -29;
sun.shadow.camera.right = 29;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -25;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbdd5d4, 0.72);
fill.position.set(15, 8, -12);
scene.add(fill);
// ------------------------------------------------------------
// Materials
// ------------------------------------------------------------
const standard = (color, roughness = 0.88, metalness = 0) =>
new THREE.MeshStandardMaterial({
color,
roughness,
metalness
});
const materials = {
ground: standard(0x9fac95),
grid: new THREE.LineBasicMaterial({
color: 0x6f7f70,
transparent: true,
opacity: 0.16
}),
paving: standard(0xcdbd9f),
path: standard(0xddd2bb),
seam: standard(0xa99f89),
slab: standard(0xf1ecde),
soffit: standard(0xc8bea9),
column: standard(0xe6decc),
columnBase: standard(0xbab19e),
wall: standard(0xf6f2e7),
wallShade: standard(0xe5ded0),
frame: standard(0x2e4543, 0.56, 0.08),
glass: standard(0x456e6b, 0.27, 0.12),
glassLight: standard(0x6c9690, 0.32, 0.08),
wood: standard(0x9d704d),
woodLight: standard(0xb18a62),
rug: standard(0xb46f58),
water: standard(0x719b96, 0.23, 0.1),
soil: standard(0x625848),
leafA: standard(0x658366),
leafB: standard(0x789470),
leafC: standard(0x4f715b),
trunk: standard(0x80654d),
dark: standard(0x35433f),
orange: standard(0xc77655),
blue: standard(0x577883),
skin: standard(0xc7a185)
};
// ------------------------------------------------------------
// Geometry helpers
// ------------------------------------------------------------
function box(w, h, d, x, y, z, material, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderBlock(radius, height, x, y, z, material, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, 8),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Open ground and paving
// ------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(120, 120),
materials.ground
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.035;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(100, 50, 0x718271, 0x879582);
grid.position.y = -0.018;
grid.material.transparent = true;
grid.material.opacity = 0.16;
grid.material.depthWrite = false;
scene.add(grid);
// The paved rectangle is intentionally distinct from the green ground.
box(23.2, 0.07, 11.7, 0, 0.005, 0, materials.paving);
// A central route continues beyond the structure.
box(4.7, 0.08, 20, 0, 0.055, 0.3, materials.path);
// Fine paving joints.
for (const x of [-1.55, 0, 1.55]) {
box(0.025, 0.015, 19.6, x, 0.103, 0.3, materials.seam);
}
for (let z = -9; z <= 10; z += 1.45) {
box(4.55, 0.015, 0.025, 0, 0.103, z, materials.seam);
}
// ------------------------------------------------------------
// Raised floor slab and concrete pilotis
// ------------------------------------------------------------
const slabBottom = 2.95;
const slabTop = 3.4;
box(22.8, 0.45, 11.2, 0, 3.175, 0, materials.slab);
// Darker soffit gives the elevated slab a readable underside.
box(22.35, 0.045, 10.75, 0, 2.936, 0, materials.soffit);
// Long downstand beams reinforce the structural reading.
box(21.9, 0.25, 0.42, 0, 2.82, -4.05, materials.soffit);
box(21.9, 0.25, 0.42, 0, 2.82, 4.05, materials.soffit);
// A continuous central gap keeps the undercroft route legible.
const columnXs = [-9.45, -6.3, -3.15, 3.15, 6.3, 9.45];
const columnZs = [-4.08, 4.08];
for (const x of columnXs) {
for (const z of columnZs) {
box(0.49, 2.76, 0.49, x, 1.42, z, materials.column);
box(0.61, 0.11, 0.61, x, 0.09, z, materials.columnBase);
}
}
// Thin slab-edge fascia.
box(22.9, 0.15, 0.13, 0, 3.03, 5.61, materials.soffit);
box(22.9, 0.15, 0.13, 0, 3.03, -5.61, materials.soffit);
// ------------------------------------------------------------
// Residential fragment: enclosed unit, cutaway room, terrace
// ------------------------------------------------------------
// Interior floor of the enclosed volume.
box(7.55, 0.12, 5.35, -6.62, 3.47, -1.55, materials.woodLight);
// Back and side walls.
box(7.55, 3.45, 0.18, -6.62, 5.15, -4.18, materials.wall);
box(0.18, 3.45, 5.35, -10.32, 5.15, -1.55, materials.wall);
// Front piers create large modernist window bays.
const pierXs = [-10.25, -8.32, -6.38, -4.43, -3.04];
for (const x of pierXs) {
box(0.24, 3.43, 0.24, x, 5.15, 1.0, materials.wall);
}
// Glazing with dark framing.
const windowXs = [-9.28, -7.35, -5.4];
windowXs.forEach((x, i) => {
box(1.72, 1.82, 0.07, x, 5.32, 1.105, materials.frame);
box(1.57, 1.66, 0.075, x, 5.32, 1.15, i === 1 ? materials.glassLight : materials.glass);
// Vertical and horizontal mullions.
box(0.055, 1.7, 0.08, x, 5.32, 1.205, materials.frame);
box(1.62, 0.055, 0.08, x, 5.32, 1.205, materials.frame);
});
// Door and small sidelight.
box(1.3, 2.45, 0.09, -3.78, 4.68, 1.12, materials.frame);
box(1.13, 2.27, 0.08, -3.78, 4.68, 1.18, materials.glass);
box(0.05, 0.42, 0.08, -3.48, 4.58, 1.24, materials.woodLight);
// Roof slab and small rooftop service volume.
box(7.85, 0.24, 5.72, -6.58, 6.96, -1.55, materials.wall);
box(2.15, 0.72, 1.55, -8.85, 7.43, -2.75, materials.wallShade);
box(2.35, 0.12, 1.75, -8.85, 7.83, -2.75, materials.wall);
// Balcony projecting from the facade.
box(7.85, 0.17, 1.45, -6.58, 3.47, 1.72, materials.slab);
for (const x of [-10.25, -8.45, -6.65, -4.85, -3.0]) {
box(0.065, 0.95, 0.065, x, 4.0, 2.39, materials.frame);
}
box(7.35, 0.075, 0.075, -6.62, 4.46, 2.39, materials.frame);
box(7.35, 0.05, 0.05, -6.62, 3.97, 2.39, materials.frame);
// Cutaway floor where the roof stops.
box(3.1, 0.12, 5.25, -1.48, 3.47, -1.58, materials.wood);
// Low partition exposes the domestic interior.
box(0.13, 1.15, 2.3, -2.93, 4.05, -2.4, materials.wall);
box(1.25, 0.12, 1.5, -1.5, 3.56, -1.9, materials.rug);
// Voxel sofa, table, and shelving.
box(1.52, 0.38, 0.62, -0.9, 3.75, -3.2, materials.blue);
box(1.52, 0.55, 0.16, -0.9, 4.02, -3.48, materials.blue);
box(0.3, 0.5, 0.68, -1.62, 3.8, -3.2, materials.blue);
box(0.3, 0.5, 0.68, -0.18, 3.8, -3.2, materials.blue);
box(0.78, 0.36, 0.7, -1.12, 3.73, -1.3, materials.woodLight);
box(0.08, 0.45, 0.08, -1.12, 3.48, -1.3, materials.frame);
box(1.55, 0.12, 0.42, -1.35, 4.55, -4.03, materials.wood);
// Terrace pool.
box(4.2, 0.16, 2.8, 5.45, 3.51, -2.05, materials.wallShade);
box(3.86, 0.06, 2.46, 5.45, 3.62, -2.05, materials.water);
// Two block lounge chairs.
for (const x of [2.3, 3.7]) {
box(0.92, 0.18, 1.35, x, 3.57, 0.45, materials.woodLight);
const back = box(0.92, 0.76, 0.18, x, 3.91, -0.1, materials.woodLight);
back.rotation.x = -0.12;
}
// Terrace planter and shrubs.
box(2.15, 0.48, 0.83, 9.2, 3.64, 3.55, materials.wallShade);
box(1.9, 0.06, 0.62, 9.2, 3.91, 3.55, materials.soil);
box(0.65, 0.55, 0.52, 8.65, 4.16, 3.55, materials.leafA);
box(0.62, 0.48, 0.5, 9.55, 4.12, 3.55, materials.leafB);
box(0.48, 0.38, 0.4, 9.95, 4.02, 3.55, materials.leafC);
// Terrace railing, leaving the stair opening clear.
for (const x of [1.6, 3.55, 5.5, 7.35]) {
box(0.065, 0.93, 0.065, x, 3.93, 5.08, materials.frame);
}
box(5.85, 0.075, 0.075, 4.47, 4.39, 5.08, materials.frame);
box(5.85, 0.05, 0.05, 4.47, 3.91, 5.08, materials.frame);
// ------------------------------------------------------------
// Exterior stair from open ground to the raised terrace
// ------------------------------------------------------------
const stairRise = slabTop / 10;
for (let i = 0; i < 10; i++) {
const height = stairRise * (i + 1);
const z = 9.8 - i * 0.55;
box(2.35, height, 0.56, 8.72, height / 2, z, materials.slab);
}
// Angular handrails.
for (const x of [7.48, 9.96]) {
for (const i of [0, 3, 6, 9]) {
const h = stairRise * (i + 1);
const z = 9.8 - i * 0.55;
box(0.07, 0.85, 0.07, x, h + 0.42, z, materials.frame);
}
const start = new THREE.Vector3(x, 1.23, 9.8);
const end = new THREE.Vector3(x, 4.22, 4.85);
const middle = start.clone().add(end).multiplyScalar(0.5);
const length = start.distanceTo(end);
const rail = box(0.075, 0.075, length, middle.x, middle.y, middle.z, materials.frame);
rail.rotation.x = Math.atan2(end.y - start.y, -(end.z - start.z));
}
// ------------------------------------------------------------
// Undercroft furniture and scale figures
// ------------------------------------------------------------
function bench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0.11, z);
group.rotation.y = rotation;
scene.add(group);
box(2.2, 0.16, 0.55, 0, 0.55, 0, materials.wood, group);
box(2.2, 0.52, 0.13, 0, 0.87, -0.23, materials.wood, group);
box(0.16, 0.5, 0.46, -0.8, 0.27, 0, materials.frame, group);
box(0.16, 0.5, 0.46, 0.8, 0.27, 0, materials.frame, group);
}
bench(-5.7, 1.6);
bench(5.55, 1.65, Math.PI);
function person(x, z, shirtMaterial, heading = 0) {
const group = new THREE.Group();
group.position.set(x, 0.11, z);
group.rotation.y = heading;
scene.add(group);
box(0.42, 0.52, 0.28, 0, 0.92, 0, shirtMaterial, group);
box(0.31, 0.31, 0.31, 0, 1.34, 0, materials.skin, group);
box(0.14, 0.52, 0.15, -0.12, 0.33, 0, materials.dark, group);
box(0.14, 0.52, 0.15, 0.12, 0.33, 0, materials.dark, group);
box(0.13, 0.4, 0.14, -0.28, 0.93, 0, shirtMaterial, group);
box(0.13, 0.4, 0.14, 0.28, 0.93, 0, shirtMaterial, group);
}
person(0.45, -0.55, materials.orange, -0.18);
person(4.15, 0.75, materials.blue, 0.55);
person(-8.1, 1.25, materials.woodLight, 0.1);
// ------------------------------------------------------------
// Voxel landscape
// ------------------------------------------------------------
function voxelTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
box(0.4, 2.65, 0.4, 0, 1.32, 0, materials.trunk, group);
box(1.35, 0.28, 0.35, 0.26, 1.95, 0, materials.trunk, group);
box(2.25, 1.42, 2.05, 0, 2.72, 0, materials.leafA, group);
box(1.65, 1.0, 1.55, -0.48, 3.45, 0.15, materials.leafB, group);
box(1.42, 0.92, 1.42, 0.62, 3.42, -0.22, materials.leafC, group);
box(1.15, 0.72, 1.22, 0.12, 4.03, 0.05, materials.leafB, group);
box(0.95, 0.8, 1.0, 1.08, 2.55, 0.52, materials.leafB, group);
box(0.9, 0.74, 0.92, -0.9, 2.52, -0.4, materials.leafC, group);
}
voxelTree(-14.2, -6.8, 1.05);
voxelTree(-14.8, 7.2, 0.9);
voxelTree(14.4, -8.7, 1.12);
voxelTree(15.2, 6.3, 0.94);
voxelTree(3.4, -14.7, 1.0);
voxelTree(-6.2, -14.4, 0.84);
voxelTree(-20, 1.2, 1.18);
// Low landscape blocks, preserving the open-ground reading.
const planterMaterial = materials.wallShade;
const planters = [
[-12.2, 3.5, 3.2, 0.8],
[12.6, 1.0, 3.8, 0.9],
[-2.4, -12.5, 3.0, 0.85]
];
for (const [x, z, w, d] of planters) {
box(w, 0.48, d, x, 0.24, z, planterMaterial);
box(w - 0.25, 0.06, d - 0.25, x, 0.51, z, materials.soil);
const count = Math.max(2, Math.floor(w / 0.7));
for (let i = 0; i < count; i++) {
const px = x - w * 0.36 + (i * (w * 0.72)) / Math.max(1, count - 1);
box(0.48, 0.48, 0.5, px, 0.76, z + (i % 2 ? 0.12 : -0.12), i % 2 ? materials.leafA : materials.leafB);
}
}
// ------------------------------------------------------------
// Custom orthographic camera controls
// ------------------------------------------------------------
const presets = {
overview: {
azimuth: 0.72,
elevation: 0.58,
zoom: 1,
target: new THREE.Vector3(0, 2.15, 0)
},
undercroft: {
azimuth: 0.12,
elevation: 0.17,
zoom: 1.72,
target: new THREE.Vector3(0.25, 1.42, 0.2)
},
fragment: {
azimuth: 1.12,
elevation: 0.48,
zoom: 1.35,
target: new THREE.Vector3(-2.8, 3.2, -0.25)
},
plan: {
azimuth: 0.015,
elevation: 1.47,
zoom: 0.94,
target: new THREE.Vector3(0, 1.1, 0)
}
};
function setPreset(name) {
const preset = presets[name];
if (!preset) return;
cameraState.azimuth = preset.azimuth;
cameraState.elevation = preset.elevation;
cameraState.zoom = preset.zoom;
cameraState.target.copy(preset.target);
document.querySelectorAll("[data-view]").forEach((button) => {
button.classList.toggle("active", button.dataset.view === name);
});
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => setPreset(button.dataset.view));
});
const pointer = {
active: false,
id: null,
x: 0,
y: 0
};
renderer.domElement.addEventListener("pointerdown", (event) => {
pointer.active = true;
pointer.id = event.pointerId;
pointer.x = event.clientX;
pointer.y = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointer.active || event.pointerId !== pointer.id) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (event.shiftKey || event.buttons === 2) {
const scale = 0.025 / cameraState.zoom;
const right = new THREE.Vector3(
Math.cos(cameraState.azimuth),
0,
-Math.sin(cameraState.azimuth)
);
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.z += dy * scale;
} else {
cameraState.azimuth -= dx * 0.006;
cameraState.elevation = THREE.MathUtils.clamp(
cameraState.elevation + dy * 0.0045,
0.13,
1.49
);
}
});
function stopPointer(event) {
if (event.pointerId === pointer.id) {
pointer.active = false;
pointer.id = null;
}
}
renderer.domElement.addEventListener("pointerup", stopPointer);
renderer.domElement.addEventListener("pointercancel", stopPointer);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.62,
2.35
);
},
{ passive: false }
);
function updateCamera() {
const radius = 36;
const cosElevation = Math.cos(cameraState.elevation);
camera.position.set(
cameraState.target.x +
radius * Math.sin(cameraState.azimuth) * cosElevation,
cameraState.target.y + radius * Math.sin(cameraState.elevation),
cameraState.target.z +
radius * Math.cos(cameraState.azimuth) * cosElevation
);
camera.lookAt(cameraState.target);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
// Preserve a useful scene width on narrow screens.
const verticalSpan = aspect < 1.1 ? 24 / aspect : 10.5;
camera.left = (-verticalSpan * aspect) / 2;
camera.right = (verticalSpan * aspect) / 2;
camera.top = verticalSpan / 2;
camera.bottom = -verticalSpan / 2;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
// ------------------------------------------------------------
// Screen-space annotations
// ------------------------------------------------------------
const annotations = [
{
element: document.querySelector("#label-slab"),
position: new THREE.Vector3(8.6, 3.2, 5.65)
},
{
element: document.querySelector("#label-column"),
position: new THREE.Vector3(3.15, 1.55, 4.08)
},
{
element: document.querySelector("#label-ground"),
position: new THREE.Vector3(0.4, 0.12, -0.7)
}
];
function updateAnnotations() {
for (const annotation of annotations) {
const projected = annotation.position.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.05 &&
Math.abs(projected.y) < 1.05;
annotation.element.style.opacity = visible ? "1" : "0";
annotation.element.style.left =
`${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
annotation.element.style.top =
`${(-projected.y * 0.5 + 0.5) * window.innerHeight - 18}px`;
}
}
// ------------------------------------------------------------
// Render loop
// ------------------------------------------------------------
let firstFrame = true;
function render() {
requestAnimationFrame(render);
updateCamera();
updateAnnotations();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
loading.classList.add("hidden");
window.setTimeout(() => loading.remove(), 600);
}
}
render();
</script>
</body>
</html>
```