Prompt specification
Build or customize the Three.js 3D scene "Ribeira quay and hillside street slice" 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: Ribeira quay and hillside street slice
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/ribeira-quay-and-hillside-street-slice-x2855
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring Porto's Ribeira waterfront. Build a bounded voxel scene with referenced waterfront facades, river edge, and a partial bridge approach. Keep the contrast between horizontal quay and steep rear streets visible. Voxel style.
Working Three.js Starter (ribeira-quay-and-hillside-street-slice-x2855):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Ribeira, Porto — Voxel Waterfront</title>
<style>
:root {
--ink: #183039;
--paper: rgba(250, 247, 237, 0.9);
--line: rgba(24, 48, 57, 0.16);
--accent: #cf5947;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce6e2;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(
circle at 50% 45%,
transparent 48%,
rgba(30, 53, 57, 0.12) 115%
);
}
.title-card {
position: fixed;
top: 24px;
left: 24px;
width: min(360px, calc(100vw - 48px));
padding: 20px 22px 18px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 18px 45px rgba(29, 54, 60, 0.12);
backdrop-filter: blur(12px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 4vw, 48px);
font-weight: 500;
line-height: 0.95;
letter-spacing: -0.045em;
}
.subtitle {
margin: 12px 0 0;
max-width: 290px;
color: rgba(24, 48, 57, 0.72);
font-size: 12px;
line-height: 1.5;
}
.tags {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 15px;
}
.tag {
padding: 5px 8px;
border: 1px solid rgba(24, 48, 57, 0.13);
border-radius: 999px;
background: rgba(255, 255, 255, 0.46);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.toolbar {
position: fixed;
top: 24px;
right: 24px;
display: flex;
gap: 8px;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 11px;
padding: 10px 13px;
background: var(--paper);
color: var(--ink);
box-shadow: 0 8px 24px rgba(29, 54, 60, 0.1);
backdrop-filter: blur(10px);
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 750;
transition:
transform 120ms ease,
background 120ms ease;
}
button:hover {
transform: translateY(-1px);
background: rgba(255, 255, 255, 0.97);
}
button:active {
transform: translateY(0);
}
.help {
position: fixed;
bottom: 24px;
left: 24px;
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(250, 247, 237, 0.78);
color: rgba(24, 48, 57, 0.7);
backdrop-filter: blur(10px);
font-size: 10px;
line-height: 1.45;
pointer-events: none;
}
.help strong {
color: var(--ink);
}
.edition {
position: fixed;
right: 24px;
bottom: 24px;
color: rgba(24, 48, 57, 0.54);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.16em;
text-transform: uppercase;
pointer-events: none;
}
#labels {
position: fixed;
inset: 0;
overflow: hidden;
pointer-events: none;
transition: opacity 180ms ease;
}
#labels.off {
opacity: 0;
}
.annotation {
position: absolute;
min-width: max-content;
padding: 7px 10px;
border: 1px solid rgba(24, 48, 57, 0.15);
border-radius: 9px;
background: rgba(252, 249, 240, 0.91);
box-shadow: 0 7px 20px rgba(29, 54, 60, 0.11);
color: var(--ink);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
transform: translate(-50%, -100%);
}
.annotation::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 18px;
background: rgba(24, 48, 57, 0.45);
content: "";
}
@media (max-width: 680px) {
.title-card {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 15px 17px;
}
.subtitle,
.tags {
display: none;
}
.toolbar {
top: auto;
right: 14px;
bottom: 52px;
}
.help {
bottom: 14px;
left: 14px;
right: 14px;
}
.edition {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="vignette"></div>
<header class="title-card">
<div class="eyebrow">Douro River · Portugal</div>
<h1>Ribeira,<br />Porto</h1>
<p class="subtitle">
A bounded voxel study of the Douro waterfront: narrow tiled houses,
the horizontal stone quay, steep rear lanes, and a fragment of the
Dom Luís I Bridge.
</p>
<div class="tags">
<span class="tag">Cais da Ribeira</span>
<span class="tag">Escadas do Barredo</span>
<span class="tag">D. Luís I Bridge</span>
</div>
</header>
<div class="toolbar">
<button id="toggleLabels" type="button">Hide labels</button>
<button id="resetView" type="button">Reset view</button>
</div>
<div id="labels">
<div class="annotation" id="labelQuay">Cais da Ribeira</div>
<div class="annotation" id="labelStairs">Steep rear streets</div>
<div class="annotation" id="labelBridge">Bridge approach</div>
</div>
<div class="help">
<strong>Drag</strong> orbit ·
<strong>Wheel</strong> zoom ·
<strong>Right-drag</strong> pan
</div>
<div class="edition">Voxel waterfront study · 01</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneRoot = document.querySelector("#scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce6e2);
scene.fog = new THREE.Fog(0xdce6e2, 52, 100);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneRoot.appendChild(renderer.domElement);
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel model of Porto's Ribeira waterfront"
);
const camera = new THREE.OrthographicCamera(-20, 20, 12, -12, 0.1, 150);
const target = new THREE.Vector3(0, 2.2, -0.6);
const control = {
theta: 0.72,
phi: 0.69,
radius: 43,
zoom: 1
};
const initialView = { ...control, target: target.clone() };
const hemi = new THREE.HemisphereLight(0xf6f1df, 0x496e72, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1cf, 3.4);
sun.position.set(15, 25, 18);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8ebbc2, 0.65);
fill.position.set(-18, 10, -14);
scene.add(fill);
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function getMaterial(color, options = {}) {
const key = [
color,
options.opacity ?? 1,
options.transparent ?? false,
options.roughness ?? 0.82,
options.metalness ?? 0,
options.emissive ?? "none",
options.emissiveIntensity ?? 1
].join("|");
if (materialCache.has(key)) return materialCache.get(key);
const material = new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.82,
metalness: options.metalness ?? 0,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1
});
if (options.emissive) {
material.emissive = new THREE.Color(options.emissive);
material.emissiveIntensity = options.emissiveIntensity ?? 1;
}
materialCache.set(key, material);
return material;
}
function box(
parent,
width,
height,
depth,
color,
x,
y,
z,
options = {}
) {
const mesh = new THREE.Mesh(
cubeGeometry,
options.material || getMaterial(color, options)
);
mesh.position.set(x, y, z);
mesh.scale.set(width, height, depth);
if (options.rotation) {
mesh.rotation.set(
options.rotation[0] || 0,
options.rotation[1] || 0,
options.rotation[2] || 0
);
}
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function beam(parent, a, b, thickness, color, options = {}) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = new THREE.Mesh(
cubeGeometry,
options.material || getMaterial(color, options)
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.scale.set(thickness, length, thickness);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const C = {
base: 0x334e52,
baseSide: 0x263f44,
stone: 0xb8aa8e,
stoneLight: 0xd2c5a8,
stoneDark: 0x8e826d,
road: 0x777c78,
roof: 0x9d493d,
roofDark: 0x743b35,
iron: 0x34474a,
dark: 0x20343b,
window: 0x244651,
cream: 0xf1e3bd,
water: 0x3e8794
};
/* -------------------------------------------------------------
Bounded diorama base, land, quay, and river
------------------------------------------------------------- */
box(scene, 30, 1, 22, C.base, 0, -1, 0);
box(scene, 30.15, 0.18, 22.15, C.baseSide, 0, -1.46, 0);
// Raised north bank.
box(scene, 28.8, 1.1, 8.8, 0x968d78, 0, 0.05, -5.8);
// River bed and surface.
box(scene, 28.8, 0.55, 10.2, 0x245f6e, 0, -0.225, 5.55);
box(
scene,
28.72,
0.08,
10.1,
C.water,
0,
0.08,
5.55,
{ roughness: 0.34, metalness: 0.08 }
);
// Horizontal quay promenade.
box(scene, 28.75, 0.16, 1.75, 0xc8b99c, 0, 0.66, -0.45);
box(scene, 28.8, 0.7, 0.35, 0x9f9078, 0, 0.28, 0.2);
// Stone courses along the river edge.
for (let x = -14; x < 14.25; x += 0.95) {
box(scene, 0.88, 0.39, 0.39, C.stoneDark, x, 0.08, 0.39);
box(scene, 0.88, 0.25, 0.39, C.stone, x, 0.42, 0.39);
}
// Paving joints emphasize the long horizontal quay.
for (let x = -13.5; x <= 13.5; x += 0.9) {
box(
scene,
0.025,
0.012,
1.55,
0xaa9b81,
x,
0.748,
-0.48,
{ castShadow: false }
);
}
// Dark border around the water.
box(scene, 28.8, 0.08, 0.08, 0x24515c, 0, 0.145, 10.55);
box(scene, 0.08, 0.08, 10.2, 0x24515c, 14.4, 0.145, 5.55);
box(scene, 0.08, 0.08, 10.2, 0x24515c, -14.4, 0.145, 5.55);
/* -------------------------------------------------------------
Rear terraces and steep street
------------------------------------------------------------- */
// High terraces behind the row of houses.
box(scene, 18.7, 2.8, 2.55, 0x9c907a, -5.2, 1.05, -8.85);
box(scene, 6.4, 3.2, 2.3, 0xa79a82, 9.15, 1.35, -9.25);
// Upper street surface.
box(scene, 18.8, 0.13, 1.1, 0xb3a68d, -5.2, 2.52, -8.0);
box(scene, 6.2, 0.13, 0.95, 0xb3a68d, 9.15, 3.02, -8.55);
// Retaining-wall courses.
for (let y = 0.05; y < 2.6; y += 0.46) {
box(
scene,
18.65,
0.035,
0.045,
0x887c68,
-5.2,
y,
-7.56,
{ castShadow: false }
);
}
// Small rear houses above the waterfront row.
const rearHouses = [
{ x: -9.0, color: 0xc78464 },
{ x: -6.3, color: 0xd8c27b },
{ x: -3.6, color: 0x78999c },
{ x: -0.9, color: 0xc3a88d }
];
for (const house of rearHouses) {
const y = 2.59;
const h = 2.25;
const z = -9.25;
box(scene, 1.75, h, 1.55, house.color, house.x, y + h / 2, z);
box(scene, 1.92, 0.18, 1.7, C.roofDark, house.x, y + h + 0.08, z);
box(scene, 1.45, 0.16, 1.25, C.roof, house.x, y + h + 0.23, z);
for (let col = 0; col < 2; col++) {
const wx = house.x + (col - 0.5) * 0.62;
box(scene, 0.32, 0.52, 0.05, C.window, wx, y + 1.35, z + 0.8);
box(scene, 0.38, 0.58, 0.035, C.cream, wx, y + 1.35, z + 0.77);
}
}
// The stair opening in the row makes the steep rear route visible.
const stairCount = 20;
const stairStartZ = -2.02;
const stairStartX = 5.58;
const stairEndX = 8.12;
const stairEndZ = -8.48;
const stairBottom = 0.56;
for (let i = 0; i < stairCount; i++) {
const t = i / (stairCount - 1);
const x = THREE.MathUtils.lerp(stairStartX, stairEndX, t);
const z = THREE.MathUtils.lerp(stairStartZ, stairEndZ, t);
const top = THREE.MathUtils.lerp(0.77, 3.34, t);
const height = top - stairBottom;
box(
scene,
1.38,
height,
0.37,
i % 4 === 0 ? C.stoneLight : C.stone,
x,
stairBottom + height / 2,
z
);
}
// Sloping handrails.
for (const side of [-0.72, 0.72]) {
beam(
scene,
[stairStartX + side, 1.65, stairStartZ],
[stairEndX + side, 4.24, stairEndZ],
0.055,
C.iron
);
for (let i = 0; i <= 4; i++) {
const t = i / 4;
const x = THREE.MathUtils.lerp(stairStartX, stairEndX, t) + side;
const z = THREE.MathUtils.lerp(stairStartZ, stairEndZ, t);
const y = THREE.MathUtils.lerp(0.77, 3.34, t);
box(scene, 0.055, 0.83, 0.055, C.iron, x, y + 0.42, z);
}
}
/* -------------------------------------------------------------
Ribeira waterfront facades
------------------------------------------------------------- */
const frontZ = -2.02;
const buildingDepth = 2.62;
const buildingCenterZ = frontZ - buildingDepth / 2;
const groundY = 0.74;
const houseSpecs = [
{ x: -11.75, w: 2.55, h: 6.45, color: 0xd4a33f, church: true },
{ x: -9.82, w: 1.68, h: 5.65, color: 0xd7d0ae },
{ x: -7.91, w: 1.78, h: 7.05, color: 0xbc6c55 },
{ x: -5.91, w: 1.72, h: 5.85, color: 0x9ab2b0 },
{ x: -3.91, w: 1.80, h: 6.35, color: 0xe0bf72 },
{ x: -1.98, w: 1.73, h: 7.35, color: 0xb95f4b },
{ x: -0.08, w: 1.77, h: 5.65, color: 0xd7d0b5 },
{ x: 1.83, w: 1.75, h: 6.65, color: 0x73959a },
{ x: 3.83, w: 1.72, h: 5.85, color: 0xd19a5b },
{ x: 6.72, w: 1.78, h: 6.80, color: 0xc87058 },
{ x: 8.72, w: 1.72, h: 5.75, color: 0xd9cda4 }
];
function createFacade(spec, index) {
const group = new THREE.Group();
group.name = `Ribeira facade ${index + 1}`;
scene.add(group);
const { x, w, h, color } = spec;
box(group, w, h, buildingDepth, color, x, groundY + h / 2, buildingCenterZ);
box(group, w + 0.08, 0.16, buildingDepth + 0.08, C.cream, x, groundY + 0.14, buildingCenterZ);
box(group, w + 0.12, 0.17, buildingDepth + 0.1, C.cream, x, groundY + h - 0.12, buildingCenterZ);
// Stepped tiled roof.
box(group, w + 0.14, 0.18, buildingDepth + 0.14, C.roofDark, x, groundY + h + 0.08, buildingCenterZ);
box(group, w - 0.18, 0.22, buildingDepth - 0.16, C.roof, x, groundY + h + 0.25, buildingCenterZ);
// Chimney and roof vent.
box(group, 0.27, 0.5, 0.28, 0x8e493f, x + w * 0.25, groundY + h + 0.43, buildingCenterZ - 0.42);
const rows = Math.max(2, Math.floor((h - 1.25) / 1.23));
const columns = w > 2 ? 2 : 1;
const windowWidth = Math.min(0.52, w * 0.35);
for (let row = 0; row < rows; row++) {
const wy = groundY + 1.35 + row * 1.23;
if (wy + 0.45 > groundY + h - 0.2) continue;
for (let column = 0; column < columns; column++) {
const offset = columns === 1 ? 0 : (column - 0.5) * 0.65;
const wx = x + offset;
box(group, windowWidth + 0.09, 0.78, 0.07, C.cream, wx, wy, frontZ + 0.045);
box(group, windowWidth - 0.05, 0.64, 0.085, C.window, wx, wy, frontZ + 0.085);
box(group, 0.035, 0.63, 0.095, 0xb99b70, wx, wy, frontZ + 0.11);
// Occasional shutters.
if ((row + column + index) % 3 === 0) {
const shutterColor = index % 2 ? 0x526f6c : 0x6d725a;
box(group, 0.105, 0.69, 0.08, shutterColor, wx - windowWidth * 0.67, wy, frontZ + 0.075);
box(group, 0.105, 0.69, 0.08, shutterColor, wx + windowWidth * 0.67, wy, frontZ + 0.075);
}
// Small iron balcony on upper floors.
if (row > 0 && (row + index) % 2 === 0) {
const balconyWidth = Math.min(0.78, w * 0.57);
box(group, balconyWidth, 0.07, 0.34, C.iron, wx, wy - 0.47, frontZ + 0.19);
box(group, balconyWidth, 0.045, 0.045, C.iron, wx, wy - 0.17, frontZ + 0.35);
for (let post = 0; post < 4; post++) {
const px = wx - balconyWidth / 2 + (post / 3) * balconyWidth;
box(group, 0.032, 0.3, 0.032, C.iron, px, wy - 0.31, frontZ + 0.35);
}
}
}
}
// Ground-floor doorway and stone surround.
const doorX = x + (index % 3 - 1) * 0.16;
box(group, 0.78, 1.35, 0.08, 0xddd0aa, doorX, groundY + 0.67, frontZ + 0.035);
box(group, 0.56, 1.15, 0.1, index % 2 ? 0x3c5c60 : 0x70453e, doorX, groundY + 0.58, frontZ + 0.09);
box(group, 0.06, 0.06, 0.06, C.cream, doorX + 0.17, groundY + 0.61, frontZ + 0.16);
// Shop or restaurant canopy.
if (index % 3 === 1) {
box(group, w * 0.78, 0.12, 0.48, index % 2 ? 0x8b4d45 : 0x517b78, x, groundY + 1.32, frontZ + 0.25);
}
// Tile-like facade accents.
if (index % 2 === 0) {
for (let tile = 0; tile < 4; tile++) {
box(
group,
0.18,
0.18,
0.035,
0xe8d9b5,
x - 0.32 + tile * 0.21,
groundY + 1.95,
frontZ + 0.055
);
}
}
}
houseSpecs.forEach(createFacade);
/* -------------------------------------------------------------
Stylized São Francisco-inspired golden facade
------------------------------------------------------------- */
const church = new THREE.Group();
scene.add(church);
const churchX = -11.75;
box(church, 1.55, 5.8, 2.8, 0xd6a442, churchX, groundY + 2.9, -3.25);
box(church, 1.8, 0.23, 3.02, 0xe0b456, churchX, groundY + 5.85, -3.25);
box(church, 1.35, 0.28, 2.6, 0xe0b456, churchX, groundY + 6.08, -3.25);
box(church, 0.9, 0.25, 2.25, 0xe0b456, churchX, groundY + 6.28, -3.25);
// Stepped pediment.
box(church, 1.1, 0.55, 0.3, 0xe3b957, churchX, groundY + 5.88, -1.76);
box(church, 0.72, 0.35, 0.3, 0xe8c668, churchX, groundY + 6.27, -1.76);
box(church, 0.32, 0.3, 0.3, 0xe8c668, churchX, groundY + 6.56, -1.76);
// Twin upper openings and clock-like blue square.
box(church, 0.35, 0.8, 0.09, C.window, churchX - 0.48, groundY + 4.65, -1.79);
box(church, 0.35, 0.8, 0.09, C.window, churchX + 0.48, groundY + 4.65, -1.79);
box(church, 0.42, 0.42, 0.09, 0x607c82, churchX, groundY + 3.7, -1.79);
box(church, 0.05, 0.27, 0.1, C.cream, churchX, groundY + 3.72, -1.72);
box(church, 0.22, 0.05, 0.1, C.cream, churchX, groundY + 3.72, -1.72);
// Cross.
box(church, 0.08, 0.48, 0.08, C.cream, churchX, groundY + 6.9, -1.77);
box(church, 0.32, 0.08, 0.08, C.cream, churchX, groundY + 7.02, -1.77);
/* -------------------------------------------------------------
Casa do Infante-inspired medieval tower
------------------------------------------------------------- */
const tower = new THREE.Group();
scene.add(tower);
const towerX = 11.25;
const towerW = 2.35;
const towerD = 3.05;
const towerH = 5.6;
box(tower, towerW, towerH, towerD, 0xb4a88d, towerX, groundY + towerH / 2, -3.3);
box(tower, towerW + 0.12, 0.2, towerD + 0.12, 0xc4b99f, towerX, groundY + towerH, -3.3);
// Crenellations.
for (let i = 0; i < 5; i++) {
box(tower, 0.29, 0.45, 0.35, 0xc5b89d, towerX - 0.9 + i * 0.45, groundY + towerH + 0.25, -1.68);
}
for (const side of [-1, 1]) {
for (let i = 0; i < 4; i++) {
box(
tower,
0.33,
0.43,
0.34,
0xc5b89d,
towerX + side * (towerW / 2 - 0.17),
groundY + towerH + 0.24,
-2.45 - i * 0.56
);
}
}
// Arrow slits and small stone frames.
for (let row = 0; row < 3; row++) {
for (let col = 0; col < 2; col++) {
const wx = towerX + (col - 0.5) * 0.62;
const wy = groundY + 1.55 + row * 1.25;
box(tower, 0.27, 0.64, 0.08, 0x7e7769, wx, wy, -1.75);
box(tower, 0.36, 0.73, 0.05, 0xcabb9d, wx, wy, -1.72);
}
}
/* -------------------------------------------------------------
Quay furniture: bollards, lamps, benches
------------------------------------------------------------- */
for (let x = -13.2; x <= 13.2; x += 2.15) {
box(scene, 0.16, 0.42, 0.16, C.iron, x, 0.94, -0.02);
box(scene, 0.28, 0.08, 0.24, C.iron, x, 1.17, -0.02);
}
for (const x of [-10.5, -4.2, 2.1, 8.4]) {
box(scene, 0.08, 1.55, 0.08, C.iron, x, 1.5, -0.76);
box(scene, 0.32, 0.08, 0.32, C.iron, x, 2.28, -0.76);
box(
scene,
0.22,
0.29,
0.22,
0xffe7a8,
x,
2.13,
-0.76,
{
emissive: 0xffc55d,
emissiveIntensity: 0.65,
roughness: 0.4
}
);
box(scene, 0.3, 0.07, 0.3, C.iron, x, 2.32, -0.76);
}
for (const x of [-7.7, 0.2]) {
box(scene, 1.25, 0.09, 0.38, 0x795844, x, 1.14, -0.74);
box(scene, 1.25, 0.34, 0.08, 0x795844, x, 1.35, -0.91);
box(scene, 0.1, 0.38, 0.32, C.iron, x - 0.43, 0.93, -0.74);
box(scene, 0.1, 0.38, 0.32, C.iron, x + 0.43, 0.93, -0.74);
}
/* -------------------------------------------------------------
Water highlights and façade reflections
------------------------------------------------------------- */
const waveColors = [0x6aa5ab, 0x75adb1, 0x59969f];
for (let i = 0; i < 32; i++) {
const x = -13.3 + (i * 3.17) % 26.5;
const z = 0.9 + ((i * 1.91) % 9.3);
const length = 0.7 + (i % 4) * 0.43;
box(
scene,
length,
0.018,
0.055,
waveColors[i % waveColors.length],
x,
0.135,
z,
{
transparent: true,
opacity: 0.25,
roughness: 0.45,
castShadow: false
}
);
}
for (const spec of houseSpecs) {
box(
scene,
spec.w * 0.64,
0.018,
0.65,
spec.color,
spec.x,
0.145,
0.82,
{
transparent: true,
opacity: 0.075,
castShadow: false,
roughness: 0.5
}
);
}
/* -------------------------------------------------------------
Rabelo-style voxel boat
------------------------------------------------------------- */
const boat = new THREE.Group();
boat.position.set(-6.2, 0.29, 4.4);
boat.rotation.y = -0.26;
scene.add(boat);
box(boat, 3.05, 0.34, 0.96, 0x684332, 0, 0, 0);
box(boat, 2.58, 0.17, 0.66, 0xc29a62, 0, 0.18, 0);
box(boat, 1.25, 0.3, 0.94, 0x684332, -1.28, 0.06, 0);
box(boat, 1.25, 0.3, 0.94, 0x684332, 1.28, 0.06, 0);
// Gunwales.
box(boat, 2.8, 0.13, 0.11, 0x4b352b, 0, 0.34, -0.47);
box(boat, 2.8, 0.13, 0.11, 0x4b352b, 0, 0.34, 0.47);
// Cross benches.
for (const x of [-0.85, 0.05, 0.85]) {
box(boat, 0.22, 0.12, 0.9, 0x7b5638, x, 0.31, 0);
}
// Mast and square sail.
box(boat, 0.08, 1.85, 0.08, 0x594637, 0.15, 1.16, 0);
box(boat, 1.15, 1.25, 0.055, 0xe7dfc8, 0.15, 1.36, 0.02);
box(boat, 1.28, 0.07, 0.07, 0x594637, 0.15, 0.78, 0.02);
// Wine casks.
for (const x of [-0.82, -0.42]) {
box(boat, 0.3, 0.3, 0.3, 0x8a6039, x, 0.39, 0);
box(boat, 0.32, 0.035, 0.32, C.iron, x, 0.39, 0);
}
/* -------------------------------------------------------------
Partial Dom Luís I Bridge approach
------------------------------------------------------------- */
const bridge = new THREE.Group();
scene.add(bridge);
const bridgeA = new THREE.Vector2(13.7, 10.9);
const bridgeB = new THREE.Vector2(8.7, 1.7);
const bridgeDelta = bridgeB.clone().sub(bridgeA);
const bridgeLength = bridgeDelta.length();
const bridgeCenter = bridgeA.clone().add(bridgeB).multiplyScalar(0.5);
bridge.position.set(bridgeCenter.x, 0, bridgeCenter.y);
bridge.rotation.y = -Math.atan2(bridgeDelta.y, bridgeDelta.x);
// Lower and upper decks.
box(bridge, bridgeLength, 0.28, 2.65, 0x6d706a, 0, 2.72, 0);
box(bridge, bridgeLength, 0.23, 2.18, 0x3c4d4e, 0, 6.08, 0);
// Stone piers.
for (const localX of [-bridgeLength * 0.3, bridgeLength * 0.02, bridgeLength * 0.34]) {
box(bridge, 1.05, 5.55, 2.85, C.stone, localX, 2.95, 0);
box(bridge, 1.25, 0.22, 3.05, C.stoneLight, localX, 5.78, 0);
box(bridge, 1.28, 0.34, 3.08, C.stoneDark, localX, 0.24, 0);
}
// Upper deck rails.
for (const side of [-1.08, 1.08]) {
box(bridge, bridgeLength, 0.07, 0.07, C.iron, 0, 6.77, side);
box(bridge, bridgeLength, 0.05, 0.05, C.iron, 0, 6.43, side);
for (let x = -bridgeLength / 2; x <= bridgeLength / 2; x += 0.72) {
box(bridge, 0.045, 0.72, 0.045, C.iron, x, 6.45, side);
}
}
// Large iron arch, approximated with voxel-like straight segments.
const archSegments = 24;
const archPoints = [];
for (let i = 0; i <= archSegments; i++) {
const t = i / archSegments;
const x = -bridgeLength / 2 + t * bridgeLength;
const normalized = (x / (bridgeLength / 2));
const y = 3.05 + 3.75 * (1 - normalized * normalized);
archPoints.push(new THREE.Vector3(x, y, 0));
}
for (const side of [-1.08, 1.08]) {
for (let i = 0; i < archSegments; i++) {
const a = archPoints[i].clone();
const b = archPoints[i + 1].clone();
a.z = side;
b.z = side;
beam(bridge, a.toArray(), b.toArray(), 0.13, C.iron);
}
// Vertical hangers.
for (let i = 0; i <= archSegments; i += 2) {
const p = archPoints[i];
beam(
bridge,
[p.x, p.y, side],
[p.x, 6.08, side],
0.06,
C.iron
);
}
}
// Lower-deck edge rails.
for (const side of [-1.31, 1.31]) {
box(bridge, bridgeLength, 0.06, 0.06, C.iron, 0, 3.45, side);
for (let x = -bridgeLength / 2; x <= bridgeLength / 2; x += 0.78) {
box(bridge, 0.045, 0.7, 0.045, C.iron, x, 3.1, side);
}
}
// Bridge lamps.
for (const x of [-bridgeLength * 0.35, 0, bridgeLength * 0.35]) {
box(bridge, 0.08, 1.2, 0.08, C.iron, x, 6.55, 1.03);
box(
bridge,
0.2,
0.24,
0.2,
0xffe7a8,
x,
7.13,
1.03,
{
emissive: 0xffc55d,
emissiveIntensity: 0.55,
roughness: 0.4
}
);
}
/* -------------------------------------------------------------
Small waterfront details
------------------------------------------------------------- */
// Mooring posts in the river.
for (const [x, z] of [[-9.6, 1.1], [-2.7, 0.85], [5.4, 1.05]]) {
box(scene, 0.22, 0.72, 0.22, 0x675844, x, 0.34, z);
box(scene, 0.31, 0.1, 0.31, 0x514735, x, 0.72, z);
}
// A few voxel crates on the quay.
box(scene, 0.58, 0.42, 0.58, 0x936f46, 11.8, 0.95, -0.62);
box(scene, 0.48, 0.38, 0.48, 0x9c784c, 12.25, 0.93, -0.45);
box(scene, 0.5, 0.08, 0.5, 0x6d5338, 11.8, 1.18, -0.62);
/* -------------------------------------------------------------
Camera controls implemented without addons
------------------------------------------------------------- */
let orbitPointer = null;
let panPointer = null;
let lastX = 0;
let lastY = 0;
const canvas = renderer.domElement;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.focus();
canvas.setPointerCapture(event.pointerId);
lastX = event.clientX;
lastY = event.clientY;
if (event.button === 2) {
panPointer = event.pointerId;
} else {
orbitPointer = event.pointerId;
}
});
canvas.addEventListener("pointermove", (event) => {
if (event.pointerId !== orbitPointer && event.pointerId !== panPointer) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (event.pointerId === orbitPointer) {
control.theta -= dx * 0.006;
control.phi = THREE.MathUtils.clamp(
control.phi + dy * 0.005,
0.28,
1.28
);
} else {
const panScale = (22 / camera.zoom) * 0.017;
const right = new THREE.Vector3(
Math.cos(control.theta),
0,
-Math.sin(control.theta)
);
const forward = new THREE.Vector3(
Math.sin(control.theta),
0,
Math.cos(control.theta)
);
target.addScaledVector(right, -dx * panScale);
target.addScaledVector(forward, dy * panScale);
target.x = THREE.MathUtils.clamp(target.x, -10, 10);
target.z = THREE.MathUtils.clamp(target.z, -9, 9);
}
updateCamera();
});
function endPointer(event) {
if (event.pointerId === orbitPointer) orbitPointer = null;
if (event.pointerId === panPointer) panPointer = null;
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const factor = Math.exp(-event.deltaY * 0.001);
control.zoom = THREE.MathUtils.clamp(
control.zoom * factor,
0.68,
2.35
);
updateCamera();
},
{ passive: false }
);
function updateCamera() {
const sinPhi = Math.sin(control.phi);
const cosPhi = Math.cos(control.phi);
camera.position.set(
target.x + control.radius * sinPhi * Math.sin(control.theta),
target.y + control.radius * sinPhi * cosPhi,
target.z + control.radius * sinPhi * Math.cos(control.theta)
);
camera.zoom = control.zoom;
camera.updateProjectionMatrix();
camera.lookAt(target);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = 23.5;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
updateCamera();
}
window.addEventListener("resize", resize);
document.querySelector("#resetView").addEventListener("click", () => {
control.theta = initialView.theta;
control.phi = initialView.phi;
control.radius = initialView.radius;
control.zoom = initialView.zoom;
target.copy(initialView.target);
updateCamera();
});
const labelLayer = document.querySelector("#labels");
const labelButton = document.querySelector("#toggleLabels");
let labelsVisible = true;
labelButton.addEventListener("click", () => {
labelsVisible = !labelsVisible;
labelLayer.classList.toggle("off", !labelsVisible);
labelButton.textContent = labelsVisible ? "Hide labels" : "Show labels";
});
const annotations = [
{
element: document.querySelector("#labelQuay"),
position: new THREE.Vector3(-4.2, 1.15, -0.05)
},
{
element: document.querySelector("#labelStairs"),
position: new THREE.Vector3(7.7, 4.9, -7.1)
},
{
element: document.querySelector("#labelBridge"),
position: new THREE.Vector3(10.7, 8.15, 5.8)
}
];
const projected = new THREE.Vector3();
function updateAnnotations() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const annotation of annotations) {
projected.copy(annotation.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.2 &&
projected.x < 1.2 &&
projected.y > -1.2 &&
projected.y < 1.2;
annotation.element.style.visibility = visible ? "visible" : "hidden";
annotation.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
annotation.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
resize();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
// Restrained motion keeps the scene architectural rather than game-like.
boat.position.y = 0.29 + Math.sin(time * 1.15) * 0.025;
boat.rotation.z = Math.sin(time * 0.75) * 0.008;
updateAnnotations();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```