Prompt specification
Build or customize the Three.js 3D scene "Ciudad Vieja stone gateway and paving tile" 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: Ciudad Vieja stone gateway and paving tile
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/ciudad-vieja-stone-gateway-and-paving-tile-x2757
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows Ciudad Vieja in Montevideo. Build a simplified referenced Puerta de la Ciudadela fragment with adjacent paving. Show the gateway opening and its relationship to present-day pedestrian space. Voxel style.
Working Three.js Starter (ciudad-vieja-stone-gateway-and-paving-tile-x2757):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#ded7ca" />
<title>Puerta de la Ciudadela — Ciudad Vieja, Montevideo</title>
<style>
:root {
--ink: #252923;
--muted: #64695f;
--paper: rgba(247, 244, 237, 0.91);
--line: rgba(55, 60, 51, 0.22);
--accent: #a64f34;
--sand: #cbb89a;
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: #ded7ca;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
outline: none;
cursor: grab;
touch-action: none;
}
#scene.dragging { cursor: grabbing; }
.panel {
position: fixed;
z-index: 5;
pointer-events: auto;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.7);
box-shadow:
0 16px 45px rgba(49, 44, 36, 0.12),
0 2px 8px rgba(49, 44, 36, 0.08);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
#title-panel {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 20px 22px 18px;
border-radius: 4px 18px 18px 18px;
}
.eyebrow {
margin: 0 0 9px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(29px, 4vw, 43px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
margin: 11px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.divider {
height: 1px;
margin: 17px 0 13px;
background: var(--line);
}
.view-controls {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
button {
appearance: none;
border: 1px solid rgba(55, 60, 51, 0.19);
border-radius: 999px;
padding: 8px 12px;
background: rgba(255, 255, 255, 0.62);
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.03em;
cursor: pointer;
transition:
background 160ms ease,
color 160ms ease,
transform 160ms ease,
border-color 160ms ease;
}
button:hover {
transform: translateY(-1px);
border-color: rgba(166, 79, 52, 0.5);
}
button.active {
border-color: var(--ink);
background: var(--ink);
color: #f7f4ed;
}
#utility-controls {
top: 22px;
right: 22px;
display: flex;
gap: 7px;
padding: 8px;
border-radius: 999px;
}
#utility-controls button {
min-width: 36px;
padding: 8px 10px;
}
#interpretation {
left: 22px;
bottom: 22px;
width: min(355px, calc(100vw - 44px));
padding: 15px 17px;
border-radius: 14px;
color: #51564e;
font-size: 12px;
line-height: 1.55;
}
#interpretation strong {
display: block;
margin-bottom: 4px;
color: var(--ink);
font-size: 11px;
letter-spacing: 0.11em;
text-transform: uppercase;
}
#controls-hint {
position: fixed;
right: 22px;
bottom: 22px;
z-index: 4;
padding: 9px 12px;
border-radius: 999px;
background: rgba(247, 244, 237, 0.72);
color: #5d6259;
font-size: 10px;
letter-spacing: 0.05em;
pointer-events: none;
backdrop-filter: blur(8px);
}
#annotations {
position: fixed;
inset: 0;
z-index: 3;
overflow: hidden;
pointer-events: none;
transition: opacity 180ms ease;
}
#annotations.hidden { opacity: 0; }
#annotations svg {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
overflow: visible;
}
#annotations line {
stroke: rgba(59, 64, 55, 0.64);
stroke-width: 1.2;
stroke-dasharray: 3 4;
}
#annotations circle {
fill: #f8f4e9;
stroke: var(--accent);
stroke-width: 2;
}
.annotation {
position: absolute;
min-width: 150px;
max-width: 220px;
padding: 10px 12px;
border-left: 3px solid var(--accent);
border-radius: 4px 10px 10px 4px;
background: rgba(248, 245, 237, 0.94);
box-shadow: 0 7px 24px rgba(45, 42, 35, 0.13);
transform: translate(-50%, -50%);
backdrop-filter: blur(10px);
}
.annotation .number {
display: block;
margin-bottom: 3px;
color: var(--accent);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.16em;
}
.annotation .name {
display: block;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
font-size: 15px;
line-height: 1.15;
}
.annotation .detail {
display: block;
margin-top: 4px;
color: #686d63;
font-size: 10px;
line-height: 1.35;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #ded7ca;
color: #52574e;
transition: opacity 500ms ease, visibility 500ms ease;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
.loading-mark {
text-align: center;
}
.loading-mark span {
display: block;
margin-top: 9px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.loading-cube {
width: 27px;
height: 27px;
margin: auto;
border: 2px solid var(--accent);
box-shadow: 7px -7px 0 -4px rgba(166, 79, 52, 0.25);
animation: breathe 1.3s ease-in-out infinite;
}
@keyframes breathe {
50% { transform: translateY(-7px) rotate(8deg); }
}
@media (max-width: 760px) {
#title-panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 16px 17px 14px;
}
h1 { font-size: 29px; }
.subtitle { font-size: 12px; }
#utility-controls {
top: auto;
right: 12px;
bottom: 64px;
}
#interpretation {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
padding: 11px 13px;
}
#controls-hint { display: none; }
.annotation { min-width: 130px; max-width: 170px; }
.annotation .detail { display: none; }
}
</style>
</head>
<body>
<canvas id="scene" tabindex="0" aria-label="Interactive voxel model of the Puerta de la Ciudadela in Montevideo"></canvas>
<section id="title-panel" class="panel">
<p class="eyebrow">Ciudad Vieja · Montevideo</p>
<h1>Puerta de la Ciudadela</h1>
<p class="subtitle">
A simplified voxel fragment set within the pedestrian fabric of the historic center.
</p>
<div class="divider"></div>
<nav class="view-controls" aria-label="Camera views">
<button class="active" data-view="isometric">Isometric</button>
<button data-view="frontal">Frontal</button>
<button data-view="overhead">Plan</button>
<button data-view="passage">Passage</button>
</nav>
</section>
<div id="utility-controls" class="panel" aria-label="Scene controls">
<button id="zoom-out" aria-label="Zoom out">−</button>
<button id="zoom-in" aria-label="Zoom in">+</button>
<button id="toggle-labels" class="active" aria-label="Toggle annotations">Labels</button>
</div>
<aside id="interpretation" class="panel">
<strong>Interpretive urban model</strong>
The masonry is deliberately simplified rather than metrically reconstructed.
The open passage remains connected to the contemporary paving, showing how the
former threshold now operates as part of a shared pedestrian route.
</aside>
<div id="controls-hint">DRAG TO ORBIT · SCROLL TO ZOOM · ARROW KEYS TO PAN</div>
<div id="annotations">
<svg aria-hidden="true">
<line id="line-0"></line>
<line id="line-1"></line>
<line id="line-2"></line>
<circle id="dot-0" r="4"></circle>
<circle id="dot-1" r="4"></circle>
<circle id="dot-2" r="4"></circle>
</svg>
<div class="annotation" id="annotation-0">
<span class="number">01</span>
<span class="name">Historic fragment</span>
<span class="detail">Sandstone blocks, truncated wall ends, and a central arched opening.</span>
</div>
<div class="annotation" id="annotation-1">
<span class="number">02</span>
<span class="name">The open threshold</span>
<span class="detail">The passage remains permeable across the former city boundary.</span>
</div>
<div class="annotation" id="annotation-2">
<span class="number">03</span>
<span class="name">Contemporary pedestrian space</span>
<span class="detail">Paving, benches, trees, and everyday movement continue through the site.</span>
</div>
</div>
<div id="loading">
<div class="loading-mark">
<div class="loading-cube"></div>
<span>Constructing Ciudad Vieja</span>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xded7ca);
scene.fog = new THREE.Fog(0xded7ca, 34, 68);
const camera = new THREE.OrthographicCamera(-18, 18, 10, -10, 0.1, 120);
const hemisphere = new THREE.HemisphereLight(0xfff7e8, 0x788078, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe5bd, 4.2);
sun.position.set(-13, 23, 17);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -28;
sun.shadow.camera.right = 28;
sun.shadow.camera.top = 28;
sun.shadow.camera.bottom = -28;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc7d7e6, 0.75);
fill.position.set(16, 10, -12);
scene.add(fill);
// A shared cube keeps the scene light and gives everything a voxel character.
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
flatShading: true,
...options
});
}
const materials = {
base: material(0xb9ad99),
ground: material(0xc8c0af),
darkPaving: material(0x858b83),
curb: material(0xd1c9b8),
road: material(0x626964),
mortar: material(0x655e53),
bronze: material(0x9d7545, { metalness: 0.35, roughness: 0.55 }),
iron: material(0x343b37, { metalness: 0.55, roughness: 0.48 }),
wood: material(0x946b46),
woodLight: material(0xb18457),
soil: material(0x51483b),
trunk: material(0x67513d),
leaf: material(0x657c4c),
leafLight: material(0x82925a),
leafDark: material(0x4f6945),
white: material(0xeee8db),
glass: material(0x405b63, { roughness: 0.38, metalness: 0.12 }),
creamFacade: material(0xcbbda6),
grayFacade: material(0xa5aaa4),
roseFacade: material(0xb98f80),
awning: material(0x854d3c),
awningLight: material(0xd2b99a),
skin: material(0xc99268),
skinDark: material(0x8d6049),
hair: material(0x3d332c)
};
const stoneMaterials = [
material(0xc7ae8c),
material(0xb99f7f),
material(0xd2b995),
material(0xad9477),
material(0xc0a383),
material(0xd7c1a0)
];
function box(w, h, d, x, y, z, mat, parent = scene, rz = 0, ry = 0) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.rotation.z = rz;
mesh.rotation.y = ry;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Deterministic randomness keeps the composition consistent between reloads.
let seed = 82741;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
// -------------------------------------------------------------------------
// Ground and contemporary paving
// -------------------------------------------------------------------------
box(48, 0.8, 39, 0, -0.56, 2, materials.base);
box(47, 0.14, 37, 0, -0.12, 2, materials.ground);
const paverCountX = 28;
const paverCountZ = 25;
const paverSize = 0.8;
const pavingMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.95,
metalness: 0,
vertexColors: true
});
const paving = new THREE.InstancedMesh(
unitBox,
pavingMaterial,
paverCountX * paverCountZ
);
paving.receiveShadow = true;
paving.castShadow = false;
const dummy = new THREE.Object3D();
const paverColor = new THREE.Color();
let paverIndex = 0;
for (let iz = 0; iz < paverCountZ; iz++) {
for (let ix = 0; ix < paverCountX; ix++) {
const x = -10.8 + ix * paverSize;
const z = -4.4 + iz * paverSize;
dummy.position.set(x, -0.015, z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(0.755, 0.095, 0.755);
dummy.updateMatrix();
paving.setMatrixAt(paverIndex, dummy.matrix);
if (Math.abs(x) < 1.46) {
paverColor.set(0x8e9188).offsetHSL(0, 0, (random() - 0.5) * 0.07);
} else if (Math.abs(Math.abs(x) - 1.95) < 0.2) {
paverColor.set(0xafa58f).offsetHSL(0, 0, (random() - 0.5) * 0.05);
} else {
paverColor.set(0xc8bda7).offsetHSL(
(random() - 0.5) * 0.012,
(random() - 0.5) * 0.035,
(random() - 0.5) * 0.11
);
}
paving.setColorAt(paverIndex, paverColor);
paverIndex++;
}
}
paving.instanceMatrix.needsUpdate = true;
if (paving.instanceColor) paving.instanceColor.needsUpdate = true;
scene.add(paving);
box(0.38, 0.24, 20.8, -11.25, 0.02, 5.6, materials.curb);
box(0.38, 0.24, 20.8, 11.25, 0.02, 5.6, materials.curb);
box(22.8, 0.24, 0.38, 0, 0.02, 15.85, materials.curb);
// A subtle linear axis makes the continuity through the opening legible.
box(0.035, 0.018, 20.2, -1.55, 0.052, 5.55, materials.bronze);
box(0.035, 0.018, 20.2, 1.55, 0.052, 5.55, materials.bronze);
// Quiet foreground roadway establishes a contemporary edge to the plaza.
box(48, 0.12, 5.5, 0, -0.015, 19.3, materials.road);
for (let x = -20; x <= 20; x += 4) {
box(1.8, 0.025, 0.1, x, 0.065, 19.3, materials.white);
}
// -------------------------------------------------------------------------
// Simplified Puerta de la Ciudadela masonry fragment
// -------------------------------------------------------------------------
const gate = new THREE.Group();
gate.position.z = -1.45;
scene.add(gate);
const openingHalfWidth = 1.55;
const archSpring = 2.45;
const innerRadius = 1.55;
const outerRadius = 2.30;
const courseHeight = 0.36;
const wallDepth = 1.86;
// Dark mortar backing remains behind the open central void.
box(2.60, 5.02, 1.48, -2.86, 2.51, 0.02, materials.mortar, gate);
box(2.60, 5.02, 1.48, 2.86, 2.51, 0.02, materials.mortar, gate);
function masonrySpan(x1, x2, y) {
let x = x1;
while (x < x2 - 0.05) {
let width = Math.min(0.76 + random() * 0.38, x2 - x);
if (width < 0.12) break;
const mat = stoneMaterials[Math.floor(random() * stoneMaterials.length)];
const depth = wallDepth + (random() - 0.5) * 0.10;
const z = (random() - 0.5) * 0.035;
box(
width - 0.035,
courseHeight - 0.025,
depth,
x + width / 2,
y,
z,
mat,
gate
);
x += width;
}
}
// The two formal piers framing the opening.
for (let row = 0; row < 14; row++) {
const y = courseHeight * 0.5 + row * courseHeight;
masonrySpan(-4.18, -openingHalfWidth, y);
masonrySpan(openingHalfWidth, 4.18, y);
}
// Lower, irregular remnants suggest that only a fragment of the wall survives.
function rubbleWall(x1, x2, minimumHeight, variation) {
const backingHeight = minimumHeight + 0.5;
box(
x2 - x1,
backingHeight,
1.42,
(x1 + x2) / 2,
backingHeight / 2,
0.01,
materials.mortar,
gate
);
let x = x1;
while (x < x2 - 0.05) {
const width = Math.min(0.68 + random() * 0.38, x2 - x);
if (width < 0.12) break;
const localHeight = minimumHeight + random() * variation;
const rows = Math.floor(localHeight / courseHeight);
for (let row = 0; row < rows; row++) {
const mat = stoneMaterials[Math.floor(random() * stoneMaterials.length)];
box(
width - 0.035,
courseHeight - 0.03,
wallDepth + (random() - 0.5) * 0.08,
x + width / 2,
courseHeight * 0.5 + row * courseHeight,
(random() - 0.5) * 0.035,
mat,
gate
);
}
x += width;
}
}
rubbleWall(-6.62, -4.18, 3.45, 2.0);
rubbleWall(4.18, 6.48, 3.05, 1.75);
// The arch is assembled from rectangular, tangential blocks.
const archBlocks = 15;
for (let i = 0; i < archBlocks; i++) {
const angle = (i / (archBlocks - 1)) * Math.PI;
const radius = (innerRadius + outerRadius) / 2;
const x = Math.cos(angle) * radius;
const y = archSpring + Math.sin(angle) * radius;
const tangentWidth = (Math.PI * radius) / archBlocks + 0.075;
const mat = stoneMaterials[(i + 2) % stoneMaterials.length];
box(
outerRadius - innerRadius + 0.06,
tangentWidth,
wallDepth,
x,
y,
0,
mat,
gate,
angle
);
}
// Upper wall and capstones complete the preserved fragment.
masonrySpan(-1.55, 1.55, 5.06);
box(2.65, 0.22, 2.00, -2.86, 5.16, 0, stoneMaterials[1], gate);
box(2.65, 0.22, 2.00, 2.86, 5.16, 0, stoneMaterials[0], gate);
box(3.35, 0.24, 2.00, 0, 5.22, 0, stoneMaterials[2], gate);
// Projecting keystone and worn patches.
box(0.66, 0.76, 0.26, 0, 4.48, 1.02, stoneMaterials[0], gate);
box(0.36, 0.42, 0.06, 0, 4.48, 1.17, materials.mortar, gate);
for (let i = 0; i < 28; i++) {
const side = random() > 0.5 ? 1 : -1;
const x = side * (1.75 + random() * 2.15);
const y = 0.4 + random() * 4.25;
box(
0.11 + random() * 0.25,
0.07 + random() * 0.13,
0.035,
x,
y,
wallDepth / 2 + 0.012,
random() > 0.5 ? materials.mortar : stoneMaterials[4],
gate
);
}
// The old threshold and present-day paving meet without a physical barrier.
box(3.08, 0.10, 2.08, 0, 0.015, 0, stoneMaterials[3], gate);
// -------------------------------------------------------------------------
// Contextual low-rise façades
// -------------------------------------------------------------------------
function createFacade(cx, cz, width, depth, height, facadeMaterial, shopName) {
const group = new THREE.Group();
scene.add(group);
box(width, height, depth, cx, height / 2, cz, facadeMaterial, group);
box(width + 0.28, 0.28, depth + 0.28, cx, height + 0.05, cz, materials.white, group);
box(width + 0.18, 0.45, depth + 0.18, cx, 0.2, cz, materials.curb, group);
const front = cz + depth / 2 + 0.055;
const floors = Math.floor((height - 2) / 2.25);
const columns = Math.max(3, Math.floor(width / 2.05));
for (let floor = 0; floor < floors; floor++) {
const y = 2.9 + floor * 2.25;
for (let column = 0; column < columns; column++) {
const x = cx - width / 2 + ((column + 0.5) * width) / columns;
box(1.02, 1.34, 0.10, x, y, front, materials.glass, group);
box(1.18, 0.12, 0.20, x, y - 0.72, front + 0.03, materials.white, group);
box(0.10, 1.37, 0.13, x, y, front + 0.03, materials.white, group);
if ((floor + column) % 3 === 0) {
box(1.45, 0.13, 0.68, x, y - 0.83, front + 0.30, materials.iron, group);
for (let rail = 0; rail < 5; rail++) {
box(0.055, 0.55, 0.055, x - 0.55 + rail * 0.275, y - 0.52, front + 0.55, materials.iron, group);
}
}
}
}
// Street-level glazing.
const shopColumns = Math.max(2, Math.floor(width / 2.7));
for (let i = 0; i < shopColumns; i++) {
const x = cx - width / 2 + ((i + 0.5) * width) / shopColumns;
box(width / shopColumns - 0.34, 1.85, 0.10, x, 1.25, front, materials.glass, group);
}
// Simple striped shop awning.
const awningWidth = width - 1.1;
const awningSegments = Math.max(4, Math.floor(awningWidth / 0.62));
for (let i = 0; i < awningSegments; i++) {
const segmentWidth = awningWidth / awningSegments;
const x = cx - awningWidth / 2 + segmentWidth * (i + 0.5);
const mat = i % 2 ? materials.awningLight : materials.awning;
box(segmentWidth, 0.13, 1.15, x, 2.25, front + 0.48, mat, group, -0.10);
}
// Canvas-generated sign, with no external texture assets.
const signCanvas = document.createElement("canvas");
signCanvas.width = 512;
signCanvas.height = 128;
const ctx = signCanvas.getContext("2d");
ctx.fillStyle = "#343a35";
ctx.fillRect(0, 0, 512, 128);
ctx.fillStyle = "#eee4cf";
ctx.font = "700 44px sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(shopName, 256, 65);
const texture = new THREE.CanvasTexture(signCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const signMaterial = new THREE.MeshBasicMaterial({ map: texture });
const sign = new THREE.Mesh(new THREE.PlaneGeometry(Math.min(3.4, width - 1), 0.75), signMaterial);
sign.position.set(cx, 2.78, front + 0.08);
group.add(sign);
return group;
}
createFacade(-10.6, -9.2, 9.2, 5.2, 9.4, materials.creamFacade, "CAFÉ · SARANDÍ");
createFacade(10.8, -9.7, 8.8, 5.4, 8.6, materials.grayFacade, "CIUDAD VIEJA");
// -------------------------------------------------------------------------
// Street furniture and urban landscape
// -------------------------------------------------------------------------
function planterTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
box(1.55, 0.52, 1.55, 0, 0.26, 0, materials.curb, group);
box(1.31, 0.08, 1.31, 0, 0.55, 0, materials.soil, group);
box(0.22, 2.45, 0.22, 0, 1.55, 0, materials.trunk, group);
box(1.52, 1.25, 1.38, -0.25, 3.02, 0.04, materials.leaf, group);
box(1.45, 1.10, 1.35, 0.42, 3.05, -0.08, materials.leafLight, group);
box(1.23, 1.18, 1.10, 0.06, 3.78, 0.08, materials.leafDark, group);
box(0.74, 0.84, 0.85, -0.54, 3.65, 0.36, materials.leafLight, group);
}
planterTree(-8.2, 6.4, 0.95);
planterTree(8.2, 4.9, 1.02);
planterTree(-8.2, -0.4, 0.83);
planterTree(7.8, -1.3, 0.87);
function bench(x, z, yaw = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = yaw;
scene.add(group);
for (let i = 0; i < 4; i++) {
box(2.35, 0.09, 0.13, 0, 0.55, -0.24 + i * 0.16, materials.woodLight, group);
}
for (let i = 0; i < 3; i++) {
box(2.35, 0.12, 0.09, 0, 0.84 + i * 0.18, -0.35, materials.wood, group);
}
box(0.10, 0.60, 0.10, -0.88, 0.28, 0, materials.iron, group);
box(0.10, 0.60, 0.10, 0.88, 0.28, 0, materials.iron, group);
box(0.09, 0.85, 0.09, -0.88, 0.77, -0.35, materials.iron, group);
box(0.09, 0.85, 0.09, 0.88, 0.77, -0.35, materials.iron, group);
}
bench(-5.7, 3.3, Math.PI / 2);
bench(5.6, 7.1, -Math.PI / 2);
bench(-7.4, 10.4, 0);
function lamp(x, z) {
box(0.11, 4.25, 0.11, x, 2.12, z, materials.iron);
box(0.44, 0.12, 0.44, x, 0.06, z, materials.iron);
box(0.12, 0.55, 0.12, x + 0.24, 4.15, z, materials.iron);
box(0.48, 0.16, 0.48, x + 0.47, 3.88, z, materials.iron);
box(0.34, 0.22, 0.34, x + 0.47, 3.74, z, material(0xfff1bf, {
emissive: 0xffd78c,
emissiveIntensity: 0.7
}));
}
lamp(-6.7, -1.6);
lamp(6.6, 0.4);
lamp(-8.0, 12.0);
lamp(8.0, 12.0);
function bollard(x, z) {
box(0.18, 0.85, 0.18, x, 0.43, z, materials.iron);
box(0.25, 0.10, 0.25, x, 0.88, z, materials.bronze);
}
for (const z of [2.0, 5.0, 8.0, 11.0]) {
bollard(-3.6, z);
bollard(3.6, z);
}
function cafeSet(x, z) {
box(0.88, 0.09, 0.88, x, 0.78, z, materials.woodLight);
box(0.11, 0.73, 0.11, x, 0.39, z, materials.iron);
box(0.54, 0.08, 0.54, x, 0.05, z, materials.iron);
for (const side of [-1, 1]) {
const chairX = x + side * 0.95;
box(0.52, 0.08, 0.52, chairX, 0.46, z, materials.wood);
box(0.52, 0.53, 0.08, chairX, 0.72, z - 0.22, materials.wood);
box(0.07, 0.43, 0.07, chairX - 0.18, 0.23, z, materials.iron);
box(0.07, 0.43, 0.07, chairX + 0.18, 0.23, z, materials.iron);
}
}
cafeSet(9.1, 8.7);
cafeSet(-9.2, 8.4);
// A compact utility box and an interpretive plaque add fine-grained scale.
box(0.72, 1.05, 0.52, 9.8, 0.53, 1.4, materials.iron);
box(0.12, 1.55, 0.12, 5.1, 0.78, 2.6, materials.iron);
box(1.15, 0.63, 0.13, 5.1, 1.50, 2.6, materials.bronze, scene, -0.22);
box(0.84, 0.33, 0.025, 5.1, 1.50, 2.70, materials.darkPaving, scene, -0.22);
// -------------------------------------------------------------------------
// Voxel pedestrians
// -------------------------------------------------------------------------
function person(x, z, coatColor, options = {}) {
const group = new THREE.Group();
group.position.set(x, 0.05, z);
group.rotation.y = options.yaw || 0;
group.scale.setScalar(options.scale || 1);
scene.add(group);
const coat = material(coatColor);
const skin = options.darkSkin ? materials.skinDark : materials.skin;
box(0.19, 0.72, 0.23, -0.15, 0.38, 0, materials.iron, group);
box(0.19, 0.72, 0.23, 0.15, 0.38, 0, materials.iron, group);
box(0.55, 0.73, 0.34, 0, 1.10, 0, coat, group);
box(0.16, 0.62, 0.18, -0.37, 1.09, 0, coat, group);
box(0.16, 0.62, 0.18, 0.37, 1.09, 0, coat, group);
box(0.42, 0.42, 0.40, 0, 1.69, 0, skin, group);
box(0.45, 0.16, 0.43, 0, 1.93, -0.015, materials.hair, group);
if (options.bag) {
box(0.32, 0.39, 0.19, 0.45, 0.83, 0.08, materials.wood, group);
}
if (options.hat) {
box(0.51, 0.11, 0.50, 0, 2.02, 0, coat, group);
}
return group;
}
person(-2.4, 3.1, 0x496d7b, { yaw: -0.35, bag: true });
person(0.35, -1.30, 0xb56542, { yaw: Math.PI, scale: 0.98 });
person(2.7, 5.5, 0xd1a64c, { yaw: 0.55, hat: true });
person(-5.2, 8.5, 0x777c67, { yaw: 1.2, darkSkin: true });
person(5.0, -3.0, 0x8d5a70, { yaw: -1.4, scale: 0.93 });
person(-0.6, 10.4, 0xddd2b9, { yaw: 0.2, bag: true });
person(7.3, 11.1, 0x435d68, { yaw: -0.7, hat: true });
// -------------------------------------------------------------------------
// Camera controls — implemented directly without external add-ons
// -------------------------------------------------------------------------
const cameraState = {
yaw: 0.64,
pitch: 0.62,
zoom: 1,
distance: 30,
target: new THREE.Vector3(0, 2.0, 1.8)
};
const presets = {
isometric: {
yaw: 0.64, pitch: 0.62, zoom: 1, distance: 30,
target: new THREE.Vector3(0, 2.0, 1.8)
},
frontal: {
yaw: 0, pitch: 0.24, zoom: 1.20, distance: 28,
target: new THREE.Vector3(0, 2.25, -0.8)
},
overhead: {
yaw: 0.18, pitch: 1.18, zoom: 0.90, distance: 34,
target: new THREE.Vector3(0, 0.4, 3.0)
},
passage: {
yaw: 0.05, pitch: 0.20, zoom: 1.62, distance: 24,
target: new THREE.Vector3(0, 2.05, -1.6)
}
};
let cameraTween = null;
const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
function updateCamera() {
const horizontal = Math.cos(cameraState.pitch) * cameraState.distance;
camera.position.set(
cameraState.target.x + Math.sin(cameraState.yaw) * horizontal,
cameraState.target.y + Math.sin(cameraState.pitch) * cameraState.distance,
cameraState.target.z + Math.cos(cameraState.yaw) * horizontal
);
camera.lookAt(cameraState.target);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function setPreset(name) {
const preset = presets[name];
if (!preset) return;
cameraTween = {
start: performance.now(),
duration: reduceMotion ? 1 : 850,
from: {
yaw: cameraState.yaw,
pitch: cameraState.pitch,
zoom: cameraState.zoom,
distance: cameraState.distance,
target: cameraState.target.clone()
},
to: {
yaw: preset.yaw,
pitch: preset.pitch,
zoom: preset.zoom,
distance: preset.distance,
target: preset.target.clone()
}
};
document.querySelectorAll("[data-view]").forEach(button => {
button.classList.toggle("active", button.dataset.view === name);
});
}
function updateTween(now) {
if (!cameraTween) return;
const t = Math.min((now - cameraTween.start) / cameraTween.duration, 1);
const eased = 1 - Math.pow(1 - t, 3);
const from = cameraTween.from;
const to = cameraTween.to;
cameraState.yaw = THREE.MathUtils.lerp(from.yaw, to.yaw, eased);
cameraState.pitch = THREE.MathUtils.lerp(from.pitch, to.pitch, eased);
cameraState.zoom = THREE.MathUtils.lerp(from.zoom, to.zoom, eased);
cameraState.distance = THREE.MathUtils.lerp(from.distance, to.distance, eased);
cameraState.target.lerpVectors(from.target, to.target, eased);
if (t >= 1) cameraTween = null;
}
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", event => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.classList.add("dragging");
canvas.setPointerCapture(event.pointerId);
canvas.focus();
cameraTween = null;
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.yaw -= deltaX * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + deltaY * 0.005,
0.16,
1.30
);
document.querySelectorAll("[data-view]").forEach(button => {
button.classList.remove("active");
});
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("dblclick", () => setPreset("isometric"));
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.62,
2.25
);
cameraTween = null;
}, { passive: false });
window.addEventListener("keydown", event => {
const step = 0.12;
if (event.key === "ArrowLeft") {
cameraState.target.x -= step;
} else if (event.key === "ArrowRight") {
cameraState.target.x += step;
} else if (event.key === "ArrowUp") {
cameraState.target.z -= step;
} else if (event.key === "ArrowDown") {
cameraState.target.z += step;
} else if (event.key === "+" || event.key === "=") {
cameraState.zoom = Math.min(cameraState.zoom * 1.08, 2.25);
} else if (event.key === "-" || event.key === "_") {
cameraState.zoom = Math.max(cameraState.zoom / 1.08, 0.62);
} else {
return;
}
event.preventDefault();
cameraTween = null;
});
document.querySelectorAll("[data-view]").forEach(button => {
button.addEventListener("click", () => setPreset(button.dataset.view));
});
document.querySelector("#zoom-in").addEventListener("click", () => {
cameraState.zoom = Math.min(cameraState.zoom * 1.12, 2.25);
cameraTween = null;
});
document.querySelector("#zoom-out").addEventListener("click", () => {
cameraState.zoom = Math.max(cameraState.zoom / 1.12, 0.62);
cameraTween = null;
});
const annotationsVisible = true;
document.querySelector("#toggle-labels").addEventListener("click", event => {
annotationsVisible = !annotationsVisible;
document.querySelector("#annotations").classList.toggle("hidden", !annotationsVisible);
event.currentTarget.classList.toggle("active", annotationsVisible);
});
// -------------------------------------------------------------------------
// Screen-space annotations
// -------------------------------------------------------------------------
const annotationData = [
{
element: document.querySelector("#annotation-0"),
line: document.querySelector("#line-0"),
dot: document.querySelector("#dot-0"),
anchor: new THREE.Vector3(-3.7, 4.75, -0.25),
offset: new THREE.Vector2(-65, -70)
},
{
element: document.querySelector("#annotation-1"),
line: document.querySelector("#line-1"),
dot: document.querySelector("#dot-1"),
anchor: new THREE.Vector3(0, 2.72, -0.30),
offset: new THREE.Vector2(120, -55)
},
{
element: document.querySelector("#annotation-2"),
line: document.querySelector("#line-2"),
dot: document.querySelector("#dot-2"),
anchor: new THREE.Vector3(4.35, 0.18, 6.1),
offset: new THREE.Vector2(75, 55)
}
];
const projected = new THREE.Vector3();
function updateAnnotations() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const annotation of annotationData) {
projected.copy(annotation.anchor).project(camera);
const anchorX = (projected.x * 0.5 + 0.5) * width;
const anchorY = (-projected.y * 0.5 + 0.5) * height;
const cardX = THREE.MathUtils.clamp(
anchorX + annotation.offset.x,
90,
width - 90
);
const cardY = THREE.MathUtils.clamp(
anchorY + annotation.offset.y,
90,
height - 95
);
annotation.element.style.left = `${cardX}px`;
annotation.element.style.top = `${cardY}px`;
annotation.line.setAttribute("x1", anchorX);
annotation.line.setAttribute("y1", anchorY);
annotation.line.setAttribute("x2", cardX);
annotation.line.setAttribute("y2", cardY);
annotation.dot.setAttribute("cx", anchorX);
annotation.dot.setAttribute("cy", anchorY);
const visible = projected.z > -1 && projected.z < 1;
annotation.element.style.display = visible ? "block" : "none";
annotation.line.style.display = visible ? "block" : "none";
annotation.dot.style.display = visible ? "block" : "none";
}
}
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
// Preserve the full monument in portrait screens.
const viewHeight = Math.max(20.5, 31.5 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
updateCamera();
renderer.setAnimationLoop(now => {
updateTween(now);
updateCamera();
renderer.render(scene, camera);
updateAnnotations();
});
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```