Prompt specification
Build or customize the Three.js 3D scene "Paraty historic waterfront street block" 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: Paraty historic waterfront street block
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/paraty-historic-waterfront-street-block-x2687
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing Paraty's historic waterfront. Build a bounded voxel model of the historic quay and adjoining streets with referenced rooflines, church silhouette, and boats. Avoid modeling the whole bay or claiming survey-level accuracy. Voxel style.
Working Three.js Starter (paraty-historic-waterfront-street-block-x2687):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Paraty — Historic Waterfront Voxel Study</title>
<style>
:root {
--ink: #17343b;
--paper: rgba(250, 244, 225, 0.94);
--line: rgba(23, 52, 59, 0.18);
--accent: #b84d35;
--accent-dark: #733528;
--shadow: 0 12px 35px rgba(20, 45, 50, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #a9c8ca;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 50;
display: grid;
place-items: center;
background: #a9c8ca;
transition: opacity 350ms ease, visibility 350ms ease;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
.loading-card {
padding: 20px 24px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--paper);
box-shadow: var(--shadow);
text-align: center;
}
.loading-card strong {
display: block;
margin-bottom: 5px;
font-size: 15px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.loading-card span {
font-size: 13px;
opacity: 0.7;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
}
#title-panel {
top: 18px;
left: 18px;
width: min(360px, calc(100vw - 36px));
padding: 18px 19px 16px;
}
.eyebrow {
margin: 0 0 7px;
color: var(--accent-dark);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(28px, 4vw, 39px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 0;
font-size: 12px;
line-height: 1.45;
opacity: 0.72;
}
.title-rule {
width: 42px;
height: 3px;
margin: 15px 0 12px;
background: var(--accent);
}
#controls {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
button {
appearance: none;
border: 1px solid rgba(23, 52, 59, 0.2);
border-radius: 8px;
padding: 7px 10px;
background: rgba(255, 255, 255, 0.65);
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 650;
cursor: pointer;
transition:
background 150ms ease,
transform 150ms ease,
border-color 150ms ease;
}
button:hover {
border-color: var(--accent);
background: #fffaf0;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
button:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
#info-panel {
top: 18px;
right: 18px;
width: min(290px, calc(100vw - 36px));
padding: 15px 16px;
}
#info-panel summary {
cursor: pointer;
list-style: none;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.04em;
text-transform: uppercase;
}
#info-panel summary::-webkit-details-marker {
display: none;
}
#info-panel summary::after {
content: "+";
float: right;
font-size: 18px;
font-weight: 400;
line-height: 12px;
}
#info-panel[open] summary::after {
content: "−";
}
.info-content {
padding-top: 12px;
font-size: 11.5px;
line-height: 1.55;
}
.info-content p {
margin: 0 0 10px;
}
.info-content ul {
margin: 0 0 11px;
padding-left: 17px;
}
.info-content li {
margin: 4px 0;
}
.disclaimer {
padding-top: 10px;
border-top: 1px solid var(--line);
color: var(--accent-dark);
font-weight: 650;
}
#hint {
position: fixed;
right: 18px;
bottom: 18px;
z-index: 8;
max-width: 285px;
padding: 10px 12px;
border: 1px solid rgba(255, 255, 255, 0.35);
border-radius: 10px;
background: rgba(23, 52, 59, 0.76);
color: #fffaf0;
font-size: 10.5px;
line-height: 1.5;
box-shadow: var(--shadow);
backdrop-filter: blur(8px);
}
kbd {
padding: 1px 4px;
border: 1px solid rgba(255, 255, 255, 0.3);
border-radius: 4px;
background: rgba(255, 255, 255, 0.1);
font-family: inherit;
font-size: 9.5px;
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
pointer-events: none;
overflow: hidden;
}
.world-label {
position: absolute;
left: 0;
top: 0;
padding: 4px 7px;
border: 1px solid rgba(255, 255, 255, 0.42);
border-radius: 5px;
background: rgba(23, 52, 59, 0.79);
color: #fffaf0;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.09em;
line-height: 1;
text-transform: uppercase;
white-space: nowrap;
box-shadow: 0 4px 12px rgba(15, 35, 40, 0.16);
transform: translate(-50%, -50%);
transition: opacity 120ms linear;
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 13px;
background: rgba(23, 52, 59, 0.62);
}
#credit {
position: fixed;
left: 18px;
bottom: 18px;
z-index: 8;
max-width: 310px;
padding: 9px 11px;
border-radius: 9px;
background: rgba(250, 244, 225, 0.87);
color: rgba(23, 52, 59, 0.74);
font-size: 10px;
line-height: 1.45;
box-shadow: var(--shadow);
}
@media (max-width: 720px) {
#title-panel {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 13px 14px;
}
h1 {
font-size: 28px;
}
.subtitle,
.title-rule {
display: none;
}
#info-panel {
top: auto;
right: 10px;
bottom: 50px;
width: 220px;
}
#info-panel:not([open]) {
padding: 10px 12px;
}
#hint {
display: none;
}
#credit {
left: 10px;
bottom: 10px;
max-width: calc(100vw - 250px);
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="loading">
<div class="loading-card">
<strong>Building Paraty</strong>
<span>Assembling the bounded voxel waterfront…</span>
</div>
</div>
<div id="labels" aria-hidden="true"></div>
<section id="title-panel" class="panel" aria-label="Model title and controls">
<p class="eyebrow">Brazil · Historic centre</p>
<h1>Paraty<br>Waterfront</h1>
<p class="subtitle">
A bounded voxel study of the quay, Rua do Comércio, adjoining lanes,
rooflines, a church silhouette, and small river craft.
</p>
<div class="title-rule"></div>
<nav id="controls" aria-label="Camera views">
<button type="button" data-view="reset">Reset</button>
<button type="button" data-view="street">Street</button>
<button type="button" data-view="quay">Quay</button>
<button type="button" data-view="top">Plan</button>
<button type="button" id="toggle-labels" aria-pressed="true">Labels</button>
</nav>
</section>
<details id="info-panel" class="panel">
<summary>Interpretive notes</summary>
<div class="info-content">
<p>
Reference anchors include the historic river edge around Praça do Porto,
the narrow commercial street, generalized colonial roof forms, and
Paraty’s distinctive church-tower silhouette.
</p>
<ul>
<li>Stepped parapets and continuous tile eaves</li>
<li>Compact, colorful street-front houses</li>
<li>Towered colonial church silhouette</li>
<li>Quay coping, bollards, trees, and launches</li>
</ul>
<p>
Roof profiles, building positions, proportions, and boats are typological
rather than measured.
</p>
<p class="disclaimer">
Interpretive diorama only. Not cadastral, architectural, archaeological,
or survey-level documentation.
</p>
</div>
</details>
<div id="hint">
<strong>Drag</strong> to orbit · <strong>Shift/right-drag</strong> to pan ·
<strong>Scroll</strong> to zoom<br>
<kbd>↑</kbd> <kbd>↓</kbd> <kbd>←</kbd> <kbd>→</kbd> orbit ·
<kbd>+</kbd> <kbd>−</kbd> zoom · <kbd>R</kbd> reset
</div>
<div id="credit">
A deliberately bounded voxel interpretation of Paraty’s historic waterfront.
Not a reconstruction of the whole bay.
</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 scene = new THREE.Scene();
scene.background = new THREE.Color(0xa9c8ca);
scene.fog = new THREE.Fog(0xa9c8ca, 88, 155);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
260
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel model of Paraty's historic waterfront"
);
renderer.domElement.tabIndex = 0;
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xdaf4ff, 0x8a6848, 2.05);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe8bf, 3.25);
sun.position.set(-28, 55, 30);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -62;
sun.shadow.camera.right = 62;
sun.shadow.camera.top = 62;
sun.shadow.camera.bottom = -62;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 145;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d8e2, 0.7);
fill.position.set(45, 24, -35);
scene.add(fill);
// Shared cube geometry gives the entire model a deliberately voxel form.
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.94,
metalness: options.metalness ?? 0,
flatShading: true,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
side: options.side ?? THREE.FrontSide
});
}
const M = {
base: standardMaterial(0x263b3d),
land: standardMaterial(0xb8aa87),
water: standardMaterial(0x4d929c, { roughness: 0.64 }),
waterLight: standardMaterial(0x8bc0c2, {
roughness: 0.72,
transparent: true,
opacity: 0.48
}),
stone: standardMaterial(0x8d8776),
stoneLight: standardMaterial(0xb8ae91),
stoneDark: standardMaterial(0x666b65),
road: standardMaterial(0x666d69),
plaster: [
standardMaterial(0xe7d7b6),
standardMaterial(0xd5a47d),
standardMaterial(0xc66c56),
standardMaterial(0xe2bc72),
standardMaterial(0x91aaa0),
standardMaterial(0xc8d1bd),
standardMaterial(0xb66e55),
standardMaterial(0xd8c4a2)
],
roof: [
standardMaterial(0xa94e38),
standardMaterial(0xb45b40),
standardMaterial(0x8f4536),
standardMaterial(0xc16b43)
],
trim: standardMaterial(0xf0e4c7),
frame: standardMaterial(0x51645e),
window: standardMaterial(0x233e45, { roughness: 0.48 }),
shutters: standardMaterial(0x55766f),
wood: standardMaterial(0x71462e),
woodLight: standardMaterial(0xa66c3c),
darkWood: standardMaterial(0x3f332b),
iron: standardMaterial(0x354d4b, { roughness: 0.66 }),
leaf: [
standardMaterial(0x3f7654),
standardMaterial(0x527f58),
standardMaterial(0x6d8c59)
],
trunk: standardMaterial(0x6a4932),
cream: standardMaterial(0xf1e3bf),
church: standardMaterial(0xe9d9b2),
churchShade: standardMaterial(0xcdbb94),
sail: standardMaterial(0xf4ead1),
sailOchre: standardMaterial(0xd9ad62),
flag: standardMaterial(0xb84d35),
lamp: standardMaterial(0xffd994, {
emissive: 0xffa640,
emissiveIntensity: 1.6
})
};
function addBox(
width,
height,
depth,
x,
y,
z,
material,
parent = scene,
castShadow = true
) {
const mesh = new THREE.Mesh(cubeGeometry, material);
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Deterministic pseudo-randomness keeps the composition reproducible.
let seed = 842170;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function randomBetween(min, max) {
return min + (max - min) * random();
}
function choose(list) {
return list[Math.floor(random() * list.length)];
}
// ---------------------------------------------------------------------
// Bounded base, land fragment, river fragment, and quay
// ---------------------------------------------------------------------
addBox(82, 2.4, 52, 0, -1.42, 11, M.base);
// Land occupies the northern/rear part of the diorama.
addBox(80, 0.3, 41, 0, -0.05, 16.5, M.land);
// Only a bounded strip of the river is represented.
addBox(80, 0.12, 11, 0, -0.04, -9.5, M.water, scene, false);
// Quay wall and coping.
addBox(80, 1.25, 0.7, 0, 0.05, -3.8, M.stoneDark);
addBox(80, 0.24, 0.95, 0, 0.72, -3.7, M.stoneLight);
for (let x = -39; x <= 39; x += 2.5) {
addBox(
2.34,
0.15,
0.92,
x + randomBetween(-0.06, 0.06),
0.87,
-3.68,
random() > 0.5 ? M.stone : M.stoneLight
);
}
// Promenade and street surfaces.
addBox(79.5, 0.14, 3.65, 0, 0.08, -1.45, M.stoneLight);
addBox(79.5, 0.10, 6.0, 0, 0.10, 4.05, M.road);
addBox(79.5, 0.12, 0.55, 0, 0.15, 7.35, M.stoneLight);
addBox(79.5, 0.12, 0.5, 0, 0.15, 0.82, M.stoneLight);
// Rear parallel street.
addBox(79.5, 0.10, 4.1, 0, 0.11, 21.3, M.road);
addBox(79.5, 0.12, 0.55, 0, 0.15, 23.7, M.stoneLight);
// A perpendicular lane connects the two parallel streets.
addBox(5.1, 0.11, 29.5, -8.6, 0.12, 21.4, M.road);
addBox(0.45, 0.13, 29.4, -11.35, 0.17, 21.4, M.stoneLight);
addBox(0.45, 0.13, 29.4, -5.85, 0.17, 21.4, M.stoneLight);
// Pixel-like cobbles on the promenade and primary street.
const paverTransforms = [];
const paverColors = [
new THREE.Color(0x8d8a7c),
new THREE.Color(0xa39d89),
new THREE.Color(0x737a74),
new THREE.Color(0xb4aa91)
];
for (let i = 0; i < 1500; i++) {
let x;
let z;
if (i < 550) {
x = randomBetween(-39.3, 39.3);
z = randomBetween(-3.15, 0.4);
} else if (i < 1250) {
x = randomBetween(-39.3, 39.3);
z = randomBetween(1.25, 6.85);
} else {
x = randomBetween(-10.7, -6.5);
z = randomBetween(7.2, 36.0);
}
paverTransforms.push({
x,
y: 0.175 + randomBetween(0, 0.012),
z,
w: randomBetween(0.35, 0.65),
d: randomBetween(0.35, 0.65),
color: choose(paverColors)
});
}
const paverMesh = new THREE.InstancedMesh(
cubeGeometry,
standardMaterial(0xffffff),
paverTransforms.length
);
const dummy = new THREE.Object3D();
paverTransforms.forEach((p, i) => {
dummy.position.set(p.x, p.y, p.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(p.w, 0.055, p.d);
dummy.updateMatrix();
paverMesh.setMatrixAt(i, dummy.matrix);
paverMesh.setColorAt(i, p.color);
});
paverMesh.instanceMatrix.needsUpdate = true;
paverMesh.receiveShadow = true;
scene.add(paverMesh);
// Flat, pixel-like water glints.
const waveTransforms = [];
for (let i = 0; i < 135; i++) {
waveTransforms.push({
x: randomBetween(-38.5, 38.5),
z: randomBetween(-14.3, -4.6),
w: randomBetween(0.8, 3.8),
d: randomBetween(0.055, 0.12),
y: 0.035 + randomBetween(0, 0.012)
});
}
const waveMesh = new THREE.InstancedMesh(
cubeGeometry,
M.waterLight,
waveTransforms.length
);
waveTransforms.forEach((w, i) => {
dummy.position.set(w.x, w.y, w.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(w.w, 0.018, w.d);
dummy.updateMatrix();
waveMesh.setMatrixAt(i, dummy.matrix);
});
waveMesh.instanceMatrix.needsUpdate = true;
scene.add(waveMesh);
// ---------------------------------------------------------------------
// Colonial-inspired houses
// ---------------------------------------------------------------------
function addFrontWindow(group, x, y, frontZ, width = 0.92, height = 1.18) {
addBox(width + 0.22, height + 0.22, 0.14, x, y, frontZ, M.trim, group);
addBox(width, height, 0.16, x, y, frontZ - 0.09, M.window, group);
addBox(0.065, height, 0.18, x - width * 0.5 - 0.13, y, frontZ - 0.03, M.shutters, group);
addBox(0.065, height, 0.18, x + width * 0.5 + 0.13, y, frontZ - 0.03, M.shutters, group);
addBox(width, 0.055, 0.19, x, y, frontZ - 0.13, M.trim, group);
}
function addSideWindow(group, x, y, z, width = 0.85) {
addBox(0.13, 1.32, width + 0.18, x, y, z, M.trim, group);
addBox(0.15, 1.08, width, x + Math.sign(x) * 0.02, y, z, M.window, group);
}
function createHouse({
x,
z,
width,
depth = 8,
bodyMaterial,
roofMaterial,
twoStory = true,
steppedGable = false
}) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
const front = -depth / 2;
const lowerHeight = twoStory ? 3.35 : 3.8;
const upperHeight = twoStory ? 2.65 : 0;
const bodyBase = 0.16;
addBox(
width,
lowerHeight,
depth,
0,
bodyBase + lowerHeight / 2,
0,
bodyMaterial,
group
);
// Slight upper-floor projection creates the familiar compressed row.
if (twoStory) {
addBox(
width + 0.42,
upperHeight,
depth + 0.32,
0,
bodyBase + lowerHeight + upperHeight / 2,
-0.06,
bodyMaterial,
group
);
}
const roofBase = bodyBase + lowerHeight + upperHeight;
const roofLayers = 6;
for (let i = 0; i < roofLayers; i++) {
const t = i / roofLayers;
const layerWidth = width + 0.62 - t * width * 0.22;
const layerDepth = depth + 0.55 - t * depth * 0.76;
addBox(
layerWidth,
0.31,
layerDepth,
0,
roofBase + 0.17 + i * 0.31,
0,
roofMaterial,
group
);
}
addBox(
width * 0.78 + 0.22,
0.18,
0.42,
0,
roofBase + roofLayers * 0.31 + 0.05,
0,
roofMaterial,
group
);
// Stepped side gables are generalized references rather than measured
// copies of a particular property.
if (steppedGable) {
for (const side of [-1, 1]) {
for (let i = 0; i < 5; i++) {
const gableDepth = (depth + 0.4) * (1 - i * 0.17);
addBox(
0.28,
0.29,
gableDepth,
side * (width / 2 + 0.15),
roofBase + 0.16 + i * 0.30,
0,
M.trim,
group
);
}
}
}
// Cornice and front door.
addBox(
width + 0.22,
0.16,
0.25,
0,
bodyBase + lowerHeight - 0.03,
front - 0.08,
M.trim,
group
);
const doorX = -width * 0.22;
addBox(1.15, 2.18, 0.16, doorX, 1.26, front - 0.1, M.trim, group);
addBox(0.88, 1.9, 0.18, doorX, 1.19, front - 0.18, M.darkWood, group);
addBox(0.065, 0.065, 0.07, doorX + 0.28, 1.2, front - 0.29, M.woodLight, group);
// Lower windows.
addFrontWindow(group, width * 0.25, 1.95, front - 0.04);
if (width > 4.1) {
addFrontWindow(group, -width * 0.05, 1.95, front - 0.04, 0.76, 1.08);
}
// Upper windows.
if (twoStory) {
const upperY = bodyBase + lowerHeight + upperHeight * 0.53;
if (width > 4.25) {
addFrontWindow(group, -width * 0.28, upperY, front - 0.24, 0.82, 1.12);
addFrontWindow(group, width * 0.28, upperY, front - 0.24, 0.82, 1.12);
} else {
addFrontWindow(group, 0, upperY, front - 0.24, 0.82, 1.12);
}
// Small projecting balcony on selected houses.
if (random() > 0.58) {
addBox(
width * 0.65,
0.14,
0.65,
0,
bodyBase + lowerHeight + 0.08,
front - 0.45,
M.wood,
group
);
addBox(
width * 0.65,
0.065,
0.065,
0,
bodyBase + lowerHeight + 0.75,
front - 0.73,
M.iron,
group
);
for (let i = 0; i <= 4; i++) {
addBox(
0.055,
0.7,
0.055,
-width * 0.325 + i * width * 0.1625,
bodyBase + lowerHeight + 0.42,
front - 0.73,
M.iron,
group
);
}
}
}
// Side windows remain visible from oblique views.
addSideWindow(group, width / 2 + 0.03, 2.0, -depth * 0.13);
addSideWindow(group, width / 2 + 0.03, 2.0, depth * 0.28, 0.72);
if (twoStory) {
addSideWindow(group, width / 2 + 0.26, 5.05, 0, 0.8);
}
// Small chimney.
const chimneyX = randomBetween(-width * 0.25, width * 0.25);
addBox(
0.52,
1.15,
0.55,
chimneyX,
roofBase + 0.8,
randomBetween(-depth * 0.15, depth * 0.15),
M.trim,
group
);
return group;
}
function createHouseRow(start, end, z, depth, options = {}) {
let x = start;
while (x < end - 2.8) {
const width = Math.min(randomBetween(3.8, 5.1), end - x);
const bodyMaterial = choose(M.plaster);
const roofMaterial = choose(M.roof);
createHouse({
x: x + width / 2,
z,
width,
depth,
bodyMaterial,
roofMaterial,
twoStory: options.twoStory ?? random() > 0.22,
steppedGable: options.steppedGable ?? random() > 0.55
});
x += width + randomBetween(0.16, 0.34);
}
}
// Front row along Rua do Comércio. The gaps preserve the perpendicular
// lane and make room for the church silhouette.
createHouseRow(-37, -12.2, 11.7, 8);
createHouseRow(-5.0, 16.8, 11.7, 8);
// Rear row and adjoining blocks.
createHouseRow(-37, -12.2, 28, 7.4, { twoStory: false });
createHouseRow(-5.0, 37, 28, 7.4, { twoStory: false });
// ---------------------------------------------------------------------
// Church silhouette
// ---------------------------------------------------------------------
function createChurch() {
const church = new THREE.Group();
church.position.set(25, 0, 12.2);
scene.add(church);
// Nave.
addBox(10, 7.1, 12, 0, 3.55, 0, M.church, church);
addBox(10.3, 0.28, 12.3, 0, 0.28, 0, M.churchShade, church);
// Side pilasters.
for (const x of [-4.45, -2.7, 2.7, 4.45]) {
addBox(0.36, 6.6, 0.34, x, 3.5, -6.15, M.cream, church);
addBox(0.36, 6.6, 0.34, x, 3.5, 6.15, M.cream, church);
}
// Central front doorway.
addBox(2.2, 3.35, 0.35, 0, 1.86, -6.18, M.trim, church);
addBox(1.65, 2.85, 0.38, 0, 1.68, -6.39, M.darkWood, church);
addBox(0.1, 2.8, 0.11, 0, 1.68, -6.62, M.woodLight, church);
// Voxel arch above the doorway.
addBox(1.95, 0.28, 0.38, 0, 3.25, -6.42, M.darkWood, church);
addBox(1.5, 0.28, 0.38, 0, 3.53, -6.42, M.darkWood, church);
addBox(0.95, 0.28, 0.38, 0, 3.81, -6.42, M.darkWood, church);
// Upper facade window.
addBox(1.5, 2.25, 0.25, 0, 5.45, -6.2, M.trim, church);
addBox(1.12, 1.87, 0.28, 0, 5.45, -6.39, M.window, church);
addBox(0.07, 1.88, 0.32, 0, 5.45, -6.55, M.trim, church);
// Stepped pediment.
for (let i = 0; i < 4; i++) {
addBox(
5.9 - i * 0.75,
0.3,
0.38,
0,
7.15 + i * 0.3,
-6.25,
M.cream,
church
);
}
// Twin tower masses.
for (const x of [-4.25, 4.25]) {
addBox(2.55, 9.3, 3.35, x, 4.65, -4.95, M.church, church);
addBox(2.75, 0.25, 3.55, x, 0.35, -4.95, M.churchShade, church);
addBox(2.72, 0.22, 3.52, x, 7.65, -4.95, M.trim, church);
// Bell openings.
addBox(1.02, 1.65, 0.22, x, 8.55, -6.67, M.trim, church);
addBox(0.72, 1.35, 0.24, x, 8.55, -6.82, M.window, church);
addBox(0.13, 1.32, 0.25, x, 8.5, -6.97, M.churchShade, church);
// Stepped tower roof.
for (let i = 0; i < 6; i++) {
const size = 3.12 - i * 0.43;
addBox(
size,
0.31,
size,
x,
9.92 + i * 0.31,
-4.95,
i % 2 === 0 ? M.roof[1] : M.roof[0],
church
);
}
// Cross.
addBox(0.13, 1.2, 0.13, x, 12.25, -4.95, M.iron, church);
addBox(0.65, 0.13, 0.13, x, 12.47, -4.95, M.iron, church);
}
// Terracotta stepped nave roof.
for (let i = 0; i < 7; i++) {
const t = i / 7;
addBox(
10.6 - t * 2.1,
0.3,
12.5 - t * 8.9,
0,
7.3 + i * 0.3,
0.35,
i % 2 === 0 ? M.roof[1] : M.roof[2],
church
);
}
// Entrance steps.
for (let i = 0; i < 4; i++) {
addBox(
3.4 + i * 0.35,
0.18,
0.75,
0,
0.22 + i * 0.16,
-6.75 - i * 0.58,
M.stoneLight,
church
);
}
// Small side chapel.
addBox(3.1, 4.7, 4.3, 6.9, 2.35, 0.3, M.churchShade, church);
addBox(3.35, 0.25, 4.55, 6.9, 4.62, 0.3, M.trim, church);
addBox(3.5, 1.0, 4.7, 6.9, 5.08, 0.3, M.roof[1], church);
addBox(1.2, 2.0, 0.2, 6.9, 1.3, -1.94, M.darkWood, church);
return church;
}
createChurch();
// ---------------------------------------------------------------------
// Quay furniture, trees, lamps, and small street details
// ---------------------------------------------------------------------
function createBollard(x, z) {
addBox(0.48, 0.72, 0.48, x, 0.55, z, M.iron);
addBox(0.68, 0.18, 0.68, x, 0.92, z, M.iron);
}
for (const x of [-36, -24, -12, 0, 12, 24, 36]) {
createBollard(x, -3.15);
}
// Three sets of steps descending toward the water.
for (const centerX of [-29, 7, 34]) {
for (let i = 0; i < 4; i++) {
addBox(
3.0,
0.18,
0.72,
centerX,
0.58 - i * 0.18,
-4.15 - i * 0.64,
M.stoneLight
);
}
}
function createLamp(x, z) {
addBox(0.16, 3.3, 0.16, x, 1.75, z, M.iron);
addBox(0.72, 0.16, 0.72, x, 3.4, z, M.iron);
addBox(0.48, 0.65, 0.48, x, 3.05, z, M.lamp, scene, false);
addBox(0.68, 0.13, 0.68, x, 3.79, z, M.iron);
}
for (const x of [-34, -20, -2, 14, 32]) {
createLamp(x, -2.65);
}
for (const x of [-18, 4, 19]) {
createLamp(x, 7.35);
}
function createTree(x, z, size = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(size);
scene.add(group);
addBox(0.58, 2.6, 0.58, 0, 1.3, 0, M.trunk, group);
const foliage = choose(M.leaf);
addBox(3.3, 1.3, 3.0, 0, 3.05, 0, foliage, group);
addBox(2.55, 1.1, 2.45, -0.18, 4.0, 0.12, choose(M.leaf), group);
addBox(1.75, 0.85, 1.8, 0.2, 4.72, -0.1, foliage, group);
addBox(0.9, 0.65, 1.0, -0.65, 3.35, 0.8, choose(M.leaf), group);
}
for (const [x, z, size] of [
[-34, -1.25, 0.85],
[-18, -1.25, 0.9],
[3, -1.25, 0.82],
[15, -1.25, 0.95],
[36, -1.2, 0.85],
[-12.9, 24.7, 0.78],
[-4.2, 25.1, 0.88],
[8, 24.7, 0.8],
[34, 25.0, 0.86]
]) {
createTree(x, z, size);
}
// Café tables and blocky parasols on the promenade.
for (const x of [-27, -14, 8, 27]) {
const z = -1.25;
addBox(1.0, 0.14, 1.0, x, 1.15, z, M.cream);
addBox(0.18, 1.0, 0.18, x, 0.64, z, M.iron);
addBox(0.55, 0.12, 0.55, x, 0.18, z, M.iron);
addBox(2.8, 0.16, 2.8, x, 3.02, z, x % 2 === 0 ? M.flag : M.trim);
addBox(2.0, 0.16, 2.0, x, 3.18, z, M.cream);
addBox(0.12, 2.2, 0.12, x, 1.9, z, M.wood);
}
// Crates and sacks near the quay.
for (let i = 0; i < 12; i++) {
const x = randomBetween(-35, 35);
const z = randomBetween(-2.7, -0.7);
if (Math.abs(x) < 3) continue;
addBox(
randomBetween(0.55, 0.9),
randomBetween(0.45, 0.75),
randomBetween(0.55, 0.85),
x,
0.48,
z,
choose([M.wood, M.woodLight])
);
}
// ---------------------------------------------------------------------
// Voxel boats
// ---------------------------------------------------------------------
const boats = [];
function createBoat({ x, z, rotation = 0, scale = 1, sail = true, ochre = false }) {
const boat = new THREE.Group();
boat.position.set(x, 0, z);
boat.rotation.y = rotation;
boat.scale.setScalar(scale);
scene.add(boat);
// Stacked hull blocks.
addBox(6.2, 0.34, 1.65, 0, 0.22, 0, M.darkWood, boat);
addBox(6.8, 0.43, 2.4, 0, 0.52, 0, M.wood, boat);
addBox(6.15, 0.16, 2.05, 0, 0.78, 0, M.woodLight, boat);
addBox(1.15, 0.35, 1.55, 3.25, 0.63, 0, M.wood, boat);
addBox(0.75, 0.32, 1.2, -3.25, 0.63, 0, M.wood, boat);
// Gunwales.
addBox(6.4, 0.18, 0.16, 0, 0.92, -1.05, M.woodLight, boat);
addBox(6.4, 0.18, 0.16, 0, 0.92, 1.05, M.woodLight, boat);
// Small cabin and cargo.
addBox(1.55, 1.15, 1.35, -1.4, 1.36, 0, M.cream, boat);
addBox(1.18, 0.48, 0.12, -1.4, 1.52, -0.72, M.window, boat);
addBox(0.7, 0.55, 0.7, 1.7, 1.13, 0.25, M.wood, boat);
if (sail) {
addBox(0.14, 5.25, 0.14, 0.55, 3.1, 0, M.wood, boat);
addBox(2.3, 0.12, 0.12, -0.65, 1.25, 0, M.wood, boat);
// Main sail made from progressively narrower rectangular steps.
for (let i = 0; i < 7; i++) {
const width = 3.0 - i * 0.36;
addBox(
width,
0.54,
0.075,
0.45 - width / 2,
1.55 + i * 0.54,
0.02,
ochre ? M.sailOchre : M.sail,
boat
);
}
// Smaller fore sail.
for (let i = 0; i < 4; i++) {
addBox(
1.25 - i * 0.2,
0.42,
0.07,
2.15,
1.5 + i * 0.42,
0.04,
M.sail,
boat
);
}
addBox(0.12, 0.85, 0.12, 0.55, 5.95, 0, M.iron, boat);
addBox(0.8, 0.42, 0.08, 0.95, 5.65, 0, M.flag, boat);
}
boats.push({
group: boat,
baseY: boat.position.y,
phase: randomBetween(0, Math.PI * 2),
tilt: randomBetween(0.004, 0.012)
});
return boat;
}
createBoat({
x: -24,
z: -8.2,
rotation: -0.08,
scale: 1.0,
sail: true,
ochre: true
});
createBoat({
x: 1.5,
z: -10.6,
rotation: 0.12,
scale: 0.88,
sail: true,
ochre: false
});
createBoat({
x: 31,
z: -7.7,
rotation: Math.PI + 0.06,
scale: 0.78,
sail: false
});
createBoat({
x: 13,
z: -6.7,
rotation: -Math.PI / 2,
scale: 0.57,
sail: false
});
// ---------------------------------------------------------------------
// World labels
// ---------------------------------------------------------------------
const labelDefinitions = [
{
text: "Praça do Porto · quay",
position: new THREE.Vector3(-18, 1.2, -3.6)
},
{
text: "Rua do Comércio",
position: new THREE.Vector3(4, 0.7, 4.1)
},
{
text: "Adjoining lane",
position: new THREE.Vector3(-8.6, 0.7, 26)
},
{
text: "Church silhouette",
position: new THREE.Vector3(25, 14.0, 7.3)
},
{
text: "River launches",
position: new THREE.Vector3(-23, 5.0, -8.2)
}
];
const worldLabels = labelDefinitions.map((definition) => {
const element = document.createElement("div");
element.className = "world-label";
element.textContent = definition.text;
document.getElementById("labels").appendChild(element);
return {
element,
position: definition.position.clone()
};
});
let labelsVisible = true;
document.getElementById("toggle-labels").addEventListener("click", (event) => {
labelsVisible = !labelsVisible;
event.currentTarget.setAttribute("aria-pressed", String(labelsVisible));
event.currentTarget.textContent = labelsVisible ? "Labels" : "No labels";
});
// ---------------------------------------------------------------------
// Direct camera controls: orbit, pan, wheel zoom, touch pinch
// ---------------------------------------------------------------------
const initialView = {
theta: 0.82,
phi: 1.08,
radius: 78,
target: new THREE.Vector3(0, 4.5, 10)
};
const current = {
theta: initialView.theta,
phi: initialView.phi,
radius: initialView.radius,
target: initialView.target.clone()
};
const goal = {
theta: initialView.theta,
phi: initialView.phi,
radius: initialView.radius,
target: initialView.target.clone()
};
function setView(name) {
if (name === "reset") {
goal.theta = initialView.theta;
goal.phi = initialView.phi;
goal.radius = initialView.radius;
goal.target.copy(initialView.target);
} else if (name === "street") {
goal.theta = 0.84;
goal.phi = 1.24;
goal.radius = 53;
goal.target.set(3, 3.6, 7.5);
} else if (name === "quay") {
goal.theta = Math.PI;
goal.phi = 1.18;
goal.radius = 60;
goal.target.set(0, 4.0, 5.5);
} else if (name === "top") {
goal.theta = 0;
goal.phi = 0.07;
goal.radius = 73;
goal.target.set(0, 0, 11.5);
}
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => setView(button.dataset.view));
});
const pointers = new Map();
let dragPointerId = null;
let panMode = false;
let lastPointer = { x: 0, y: 0 };
let previousPinchDistance = null;
let previousPinchCenter = null;
const canvas = renderer.domElement;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
function pointerCenter() {
const values = [...pointers.values()];
if (values.length < 2) return { x: 0, y: 0 };
return {
x: (values[0].x + values[1].x) / 2,
y: (values[0].y + values[1].y) / 2
};
}
function panCamera(deltaX, deltaY) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
const right = new THREE.Vector3()
.crossVectors(forward, camera.up)
.normalize();
const up = new THREE.Vector3()
.crossVectors(right, forward)
.normalize();
const scale = (goal.radius / innerHeight) * 1.15;
goal.target.addScaledVector(right, -deltaX * scale);
goal.target.addScaledVector(up, deltaY * scale);
goal.target.x = THREE.MathUtils.clamp(goal.target.x, -42, 42);
goal.target.y = THREE.MathUtils.clamp(goal.target.y, -1, 20);
goal.target.z = THREE.MathUtils.clamp(goal.target.z, -17, 38);
}
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.focus();
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
dragPointerId = event.pointerId;
panMode = event.button === 2 || event.shiftKey;
lastPointer = { x: event.clientX, y: event.clientY };
} else if (pointers.size === 2) {
dragPointerId = null;
previousPinchDistance = pointerDistance();
previousPinchCenter = pointerCenter();
}
});
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 distance = pointerDistance();
const center = pointerCenter();
if (previousPinchDistance && distance > 0) {
goal.radius = THREE.MathUtils.clamp(
goal.radius * (previousPinchDistance / distance),
23,
132
);
}
if (previousPinchCenter) {
panCamera(
center.x - previousPinchCenter.x,
center.y - previousPinchCenter.y
);
}
previousPinchDistance = distance;
previousPinchCenter = center;
return;
}
if (event.pointerId !== dragPointerId) return;
const deltaX = event.clientX - lastPointer.x;
const deltaY = event.clientY - lastPointer.y;
lastPointer = { x: event.clientX, y: event.clientY };
if (event.shiftKey || panMode) {
panCamera(deltaX, deltaY);
} else {
goal.theta -= deltaX * 0.006;
goal.phi = THREE.MathUtils.clamp(
goal.phi - deltaY * 0.006,
0.07,
1.46
);
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (dragPointerId === event.pointerId) {
dragPointerId = null;
}
if (pointers.size < 2) {
previousPinchDistance = null;
previousPinchCenter = null;
}
if (pointers.size === 1) {
const remaining = [...pointers.entries()][0];
dragPointerId = remaining[0];
lastPointer = { x: remaining[1].x, y: remaining[1].y };
panMode = false;
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const delta = THREE.MathUtils.clamp(event.deltaY, -150, 150);
goal.radius = THREE.MathUtils.clamp(
goal.radius * Math.exp(delta * 0.00115),
23,
132
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "r") {
setView("reset");
} else if (key === "+" || key === "=") {
goal.radius = THREE.MathUtils.clamp(goal.radius * 0.9, 23, 132);
} else if (key === "-" || key === "_") {
goal.radius = THREE.MathUtils.clamp(goal.radius * 1.1, 23, 132);
} else if (key === "arrowleft") {
goal.theta -= 0.1;
} else if (key === "arrowright") {
goal.theta += 0.1;
} else if (key === "arrowup") {
goal.phi = THREE.MathUtils.clamp(goal.phi - 0.08, 0.07, 1.46);
} else if (key === "arrowdown") {
goal.phi = THREE.MathUtils.clamp(goal.phi + 0.08, 0.07, 1.46);
} else {
return;
}
event.preventDefault();
});
// ---------------------------------------------------------------------
// Animation and projection
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
const projected = new THREE.Vector3();
function damp(currentValue, targetValue, smoothing, delta) {
return THREE.MathUtils.lerp(
currentValue,
targetValue,
1 - Math.exp(-smoothing * delta)
);
}
function shortestAngleDifference(from, to) {
let difference = (to - from) % (Math.PI * 2);
if (difference > Math.PI) difference -= Math.PI * 2;
if (difference < -Math.PI) difference += Math.PI * 2;
return difference;
}
function updateLabels() {
for (const label of worldLabels) {
if (!labelsVisible) {
label.element.style.opacity = "0";
continue;
}
projected.copy(label.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.08 &&
Math.abs(projected.y) < 1.08;
if (!visible) {
label.element.style.opacity = "0";
continue;
}
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
label.element.style.opacity = "0.88";
}
}
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
current.theta +=
shortestAngleDifference(current.theta, goal.theta) *
(1 - Math.exp(-9 * delta));
current.phi = damp(current.phi, goal.phi, 9, delta);
current.radius = damp(current.radius, goal.radius, 9, delta);
current.target.lerp(goal.target, 1 - Math.exp(-9 * delta));
const sinPhi = Math.sin(current.phi);
camera.position.set(
current.target.x +
current.radius * sinPhi * Math.sin(current.theta),
current.target.y + current.radius * Math.cos(current.phi),
current.target.z +
current.radius * sinPhi * Math.cos(current.theta)
);
camera.lookAt(current.target);
// A subtle bob keeps the river craft alive without departing from the
// static, block-built aesthetic.
boats.forEach((boat) => {
boat.group.position.y =
boat.baseY + Math.sin(elapsed * 0.85 + boat.phase) * 0.055;
boat.group.rotation.z =
Math.sin(elapsed * 0.68 + boat.phase) * boat.tilt;
});
updateLabels();
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
renderer.setAnimationLoop(animate);
document.getElementById("loading").classList.add("hidden");
</script>
</body>
</html>
```