Prompt specification
Build or customize the Three.js 3D scene "River passenger boarding below Porto's hillside" 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: River passenger boarding below Porto's hillside
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/river-passenger-boarding-below-porto-s-hillside-x2854
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Create a compact Ribeira vignette with boat landing, quay path, and steep facade backdrop. Animate boarding through a clear access point without blocking the waterfront walkway.
Working Three.js Starter (river-passenger-boarding-below-porto-s-hillside-x2854):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Ribeira — Boarding Vignette</title>
<style>
:root {
color-scheme: dark;
--ink: #102d34;
--paper: #f7f0df;
--gold: #e8b75d;
--teal: #347b78;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9d8df;
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;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.overlay {
position: fixed;
inset: 0;
pointer-events: none;
color: var(--paper);
text-shadow: 0 2px 12px rgb(8 34 40 / 35%);
}
.title-card {
position: absolute;
top: 28px;
left: 30px;
max-width: 360px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 9px;
color: #fff2cf;
font-size: 11px;
font-weight: 750;
letter-spacing: .22em;
text-transform: uppercase;
}
.eyebrow::before {
width: 29px;
height: 2px;
content: "";
background: var(--gold);
box-shadow: 0 1px 8px rgb(0 0 0 / 20%);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(38px, 6vw, 72px);
font-weight: 500;
line-height: .9;
letter-spacing: -.045em;
}
.subtitle {
margin: 13px 0 0;
color: #e9f3ef;
font-size: 13px;
line-height: 1.5;
letter-spacing: .03em;
}
.status-card {
position: absolute;
bottom: 28px;
left: 30px;
width: min(340px, calc(100vw - 60px));
padding: 16px 18px;
border: 1px solid rgb(255 255 255 / 18%);
border-radius: 14px;
background: rgb(10 42 48 / 76%);
box-shadow: 0 12px 35px rgb(4 25 29 / 18%);
backdrop-filter: blur(12px);
text-shadow: none;
}
.status-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
}
.status-label {
display: flex;
align-items: center;
gap: 9px;
font-size: 12px;
font-weight: 700;
letter-spacing: .08em;
text-transform: uppercase;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--gold);
box-shadow: 0 0 0 5px rgb(232 183 93 / 13%);
}
#statusText {
color: #b9d5d2;
font-size: 11px;
white-space: nowrap;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 14px;
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid rgb(255 255 255 / 12%);
color: #d9e7e3;
font-size: 11px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 17px;
height: 5px;
border-radius: 4px;
}
.swatch.promenade {
background: #d8b982;
}
.swatch.access {
background: #e8b75d;
}
.controls {
position: absolute;
right: 28px;
bottom: 28px;
display: flex;
align-items: center;
gap: 12px;
color: #f4f7f2;
font-size: 11px;
letter-spacing: .05em;
text-shadow: 0 2px 10px rgb(0 0 0 / 35%);
}
button {
pointer-events: auto;
padding: 9px 13px;
border: 1px solid rgb(255 255 255 / 24%);
border-radius: 9px;
background: rgb(10 42 48 / 72%);
color: white;
font: inherit;
font-size: 11px;
cursor: pointer;
backdrop-filter: blur(10px);
}
button:hover {
border-color: rgb(255 255 255 / 48%);
background: rgb(18 61 67 / 88%);
}
@media (max-width: 700px) {
.title-card {
top: 20px;
left: 20px;
}
.subtitle {
max-width: 260px;
}
.status-card {
bottom: 20px;
left: 20px;
width: calc(100vw - 40px);
}
.controls {
top: 22px;
right: 18px;
bottom: auto;
}
.controls .hint {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly Ribeira waterfront scene"></canvas>
<div class="overlay">
<header class="title-card">
<div class="eyebrow">Porto · Portugal</div>
<h1>Ribeira</h1>
<p class="subtitle">
A compact Douro waterfront study with a dedicated boat-landing route
kept separate from the public promenade.
</p>
</header>
<section class="status-card" aria-live="polite">
<div class="status-row">
<div class="status-label">
<span class="status-dot"></span>
<span id="statusText">Boarding access active</span>
</div>
<span>Promenade clear</span>
</div>
<div class="legend">
<span><i class="swatch promenade"></i>Public quay path</span>
<span><i class="swatch access"></i>Boarding access</span>
</div>
</section>
<div class="controls">
<span class="hint">Drag to orbit · Scroll to zoom</span>
<button id="resetView" type="button">Reset view</button>
</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,
alpha: false
});
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.12;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb9d8df);
scene.fog = new THREE.Fog(0xb9d8df, 29, 62);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xd8eff1, 0x80694f, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe2ad, 3.15);
sun.position.set(-12, 21, 15);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -22;
sun.shadow.camera.right = 22;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x8ec6d6, 0.65);
rim.position.set(15, 8, -16);
scene.add(rim);
// -------------------------------------------------------------------------
// Materials and helpers
// -------------------------------------------------------------------------
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
flatShading: true,
...options
});
}
const mats = {
quay: material(0x8d8778),
stone: material(0x777a72),
stoneLight: material(0xa6a092),
darkStone: material(0x656a64),
promenade: material(0xd0b47f),
access: material(0xdfa957),
road: material(0xb99e72),
cream: material(0xf0dfb9),
trim: material(0xf4e8cd),
glass: material(0x28535a, { roughness: 0.3, metalness: 0.12 }),
metal: material(0x263c40, { roughness: 0.48, metalness: 0.28 }),
rope: material(0x8a6b43),
wood: material(0x896044),
woodLight: material(0xb88751),
boat: material(0x286b73),
boatTrim: material(0xe5c88e),
red: material(0xa84d3c),
green: material(0x527b55),
orange: material(0xc97740),
blue: material(0x4f7893),
yellow: material(0xe5b653),
skin: material(0xb97e58),
shirt: material(0xe0a94c),
trousers: material(0x354b55)
};
function box(w, h, d, mat, parent, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(rTop, rBottom, h, mat, parent, x = 0, y = 0, z = 0, sides = 8) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rTop, rBottom, h, sides),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function rodBetween(a, b, radius, mat, parent = scene, sides = 6) {
const direction = new THREE.Vector3().subVectors(b, a);
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, direction.length(), sides),
mat
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
function triangleMarker(x, y, z, mat) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
x - 0.18, y, z + 0.2,
x + 0.18, y, z + 0.2,
x, y, z - 0.2
], 3)
);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(
geometry,
new THREE.MeshBasicMaterial({ color: mat.color, side: THREE.DoubleSide })
);
scene.add(mesh);
return mesh;
}
function canvasTexture(width, height, draw) {
const c = document.createElement("canvas");
c.width = width;
c.height = height;
draw(c.getContext("2d"), width, height);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
// -------------------------------------------------------------------------
// River
// -------------------------------------------------------------------------
const waterGeometry = new THREE.PlaneGeometry(80, 60, 24, 18);
const waterPosition = waterGeometry.attributes.position;
const waterColors = [];
const waterPalette = [
new THREE.Color(0x4c9ba3),
new THREE.Color(0x5ca8ad),
new THREE.Color(0x438f9b),
new THREE.Color(0x69afb0)
];
for (let i = 0; i < waterPosition.count; i++) {
waterPosition.setZ(
i,
(Math.random() - 0.5) * 0.11
);
const color = waterPalette[Math.floor(Math.random() * waterPalette.length)];
waterColors.push(color.r, color.g, color.b);
}
waterGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(waterColors, 3)
);
waterGeometry.computeVertexNormals();
const water = new THREE.Mesh(
waterGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.27,
metalness: 0.08,
flatShading: true
})
);
water.rotation.x = -Math.PI / 2;
water.position.y = -0.08;
water.receiveShadow = true;
scene.add(water);
// -------------------------------------------------------------------------
// Quay, promenade, and separated boarding access
// -------------------------------------------------------------------------
box(25, 1, 5.8, mats.quay, scene, 0, 0.5, -0.45);
box(25.1, 1.08, 0.46, mats.darkStone, scene, 0, 0.53, 2.37);
box(25.15, 0.12, 0.58, mats.stoneLight, scene, 0, 1.08, 2.34);
// Main promenade ends before the boarding lane.
box(19.1, 0.09, 1.72, mats.promenade, scene, -2.1, 1.045, 1.02);
for (let x = -11.2; x < 7.4; x += 1.25) {
box(0.025, 0.012, 1.66, mats.road, scene, x, 1.096, 1.02);
}
// Dedicated access branch runs parallel to, rather than across, the path.
box(2.12, 0.095, 4.55, mats.access, scene, 8.8, 1.048, -0.1);
for (const z of [-0.8, 0.2, 1.2]) {
triangleMarker(8.8, 1.105, z, mats.yellow);
}
// Thin edge lines make the boarding route explicit.
for (const x of [7.76, 9.84]) {
for (let z = -1.8; z < 2.15; z += 0.65) {
box(0.08, 0.025, 0.36, mats.yellow, scene, x, 1.11, z);
}
}
// Riverside railing, stopping short of the dedicated access.
for (let x = -11.55; x <= 7.15; x += 1.15) {
cylinder(0.045, 0.055, 0.78, mats.metal, scene, x, 1.45, 2.23, 6);
}
box(18.75, 0.06, 0.06, mats.metal, scene, -2.15, 1.77, 2.23);
box(18.75, 0.045, 0.045, mats.metal, scene, -2.15, 1.35, 2.23);
// Bollards separate the public path from the landing area.
for (const x of [7.15, 10.35]) {
cylinder(0.12, 0.16, 0.62, mats.metal, scene, x, 1.34, 1.82, 8);
cylinder(0.13, 0.13, 0.08, mats.yellow, scene, x, 1.68, 1.82, 8);
}
// Benches, lamps, planters, and café furniture remain on the building side.
function bench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 1.05, z);
group.rotation.y = rotation;
scene.add(group);
box(1.65, 0.12, 0.46, mats.wood, group, 0, 0.48, 0);
box(1.65, 0.48, 0.09, mats.wood, group, 0, 0.78, -0.2);
box(0.12, 0.45, 0.38, mats.metal, group, -0.61, 0.24, 0);
box(0.12, 0.45, 0.38, mats.metal, group, 0.61, 0.24, 0);
}
bench(-6.3, -0.48);
bench(-1.7, -0.48);
bench(3.7, -0.48);
function lamp(x) {
cylinder(0.075, 0.11, 2.8, mats.metal, scene, x, 2.42, -0.42, 8);
box(0.42, 0.12, 0.42, mats.metal, scene, x, 3.82, -0.42);
box(0.27, 0.24, 0.27, mats.yellow, scene, x, 3.64, -0.42);
cylinder(0.19, 0.1, 0.16, mats.metal, scene, x, 3.92, -0.42, 8);
}
lamp(-9.3);
lamp(-3.8);
lamp(1.4);
lamp(6.0);
function planter(x, z, scale = 1) {
cylinder(0.29 * scale, 0.22 * scale, 0.48 * scale,
material(0xb56e45), scene, x, 1.29 * scale, z, 7);
const foliage = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.46 * scale, 0),
mats.green
);
foliage.position.set(x, 1.76 * scale, z);
foliage.castShadow = true;
scene.add(foliage);
}
planter(-8.0, -0.55, 1.05);
planter(-2.6, -0.55, 0.9);
planter(2.8, -0.55, 1.0);
planter(6.8, -0.6, 0.85);
for (const [x, z] of [[-5.1, -0.55], [-0.1, -0.55], [5.1, -0.55]]) {
cylinder(0.34, 0.34, 0.08, mats.cream, scene, x, 1.42, z, 10);
cylinder(0.06, 0.08, 0.67, mats.metal, scene, x, 1.1, z, 6);
for (const dx of [-0.43, 0.43]) {
cylinder(0.2, 0.2, 0.07, mats.wood, scene, x + dx, 1.4, z, 8);
cylinder(0.04, 0.05, 0.58, mats.metal, scene, x + dx, 1.1, z, 6);
}
}
// -------------------------------------------------------------------------
// Steep, stacked Ribeira facades
// -------------------------------------------------------------------------
box(23, 3.2, 0.65, mats.stone, scene, 0, 2.55, -3.83);
box(22, 4.1, 0.75, mats.stoneLight, scene, 0, 4.65, -6.02);
box(20.5, 3.4, 0.85, mats.stone, scene, 0, 7.05, -8.13);
box(23.2, 0.16, 0.8, mats.cream, scene, 0, 4.18, -3.76);
box(22.2, 0.16, 0.9, mats.cream, scene, 0, 6.72, -5.94);
const facadeMaterials = [
material(0xd17e55),
material(0xe0bd70),
material(0xe4d4ac),
material(0x4b9290),
material(0xc97847),
material(0x7798a4),
material(0xd89a71)
];
const roofMaterials = [
material(0x8b4938),
material(0x596f73),
material(0x7d5c47)
];
function addWindow(group, x, y, z, shutterMat) {
box(0.72, 0.82, 0.08, mats.trim, group, x, y, z);
box(0.53, 0.63, 0.09, mats.glass, group, x, y, z + 0.035);
box(0.035, 0.63, 0.025, mats.trim, group, x, y, z + 0.09);
box(0.53, 0.035, 0.025, mats.trim, group, x, y, z + 0.09);
box(0.19, 0.78, 0.07, shutterMat, group, x - 0.47, y, z + 0.015);
box(0.19, 0.78, 0.07, shutterMat, group, x + 0.47, y, z + 0.015);
}
function addBalcony(group, x, y, frontZ, shutterMat) {
box(1.55, 0.1, 0.52, mats.cream, group, x, y, frontZ + 0.24);
box(1.55, 0.045, 0.045, mats.metal, group, x, y + 0.52, frontZ + 0.5);
for (const dx of [-0.68, -0.34, 0, 0.34, 0.68]) {
box(0.035, 0.5, 0.035, mats.metal, group, x + dx, y + 0.27, frontZ + 0.5);
}
cylinder(0.13, 0.1, 0.22, material(0xb56e45), group,
x + 0.48, y + 0.17, frontZ + 0.23, 7);
const leaves = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.18, 0),
mats.green
);
leaves.position.set(x + 0.48, y + 0.36, frontZ + 0.23);
group.add(leaves);
}
function addHouse({
x,
z,
base = 1.05,
w = 2.8,
d = 2.35,
h = 4.8,
color,
roofColor,
shutters,
variant = 0
}) {
const group = new THREE.Group();
group.position.set(x, base, z);
scene.add(group);
const wallMat = color || facadeMaterials[variant % facadeMaterials.length];
const shutterMat = shutters || wallMat;
box(w, h, d, wallMat, group, 0, h / 2, 0);
box(w + 0.06, 0.14, d + 0.06, mats.trim, group, 0, h - 0.06, 0);
box(w * 0.96, 0.08, 0.08, mats.trim, group, 0, 0.18, d / 2 + 0.045);
const front = d / 2 + 0.07;
const floors = Math.max(2, Math.floor(h / 1.45));
// Ground-floor door and shop-like opening.
box(0.72, 1.55, 0.1, mats.trim, group, -w * 0.18, 0.79, front);
box(0.54, 1.37, 0.12, wallMat, group, -w * 0.18, 0.77, front + 0.045);
box(0.44, 0.73, 0.13, mats.glass, group, w * 0.25, 0.85, front + 0.02);
for (let floor = 0; floor < floors; floor++) {
const y = 1.95 + floor * 1.42;
if (y + 0.42 > h - 0.25) continue;
addWindow(group, -w * 0.23, y, front, shutterMat);
addWindow(group, w * 0.23, y, front, shutterMat);
if ((floor + variant) % 2 === 0) {
addBalcony(group, 0, y - 0.48, front, shutterMat);
}
}
const half = w / 2 + 0.2;
const rise = 0.8;
const roofLength = Math.hypot(half, rise);
const roofMat = roofColor || roofMaterials[variant % roofMaterials.length];
const leftRoof = box(
roofLength, 0.12, d + 0.35, roofMat, group,
-half / 2, h + rise / 2, 0
);
leftRoof.rotation.z = Math.atan2(rise, half);
const rightRoof = box(
roofLength, 0.12, d + 0.35, roofMat, group,
half / 2, h + rise / 2, 0
);
rightRoof.rotation.z = -Math.atan2(rise, half);
// A few chimneys reinforce the low-poly silhouette.
if (variant % 2 === 0) {
box(0.25, 0.75, 0.25, roofMat, group, w * 0.22, h + 0.85, -0.25);
}
return group;
}
const lowerHouses = [
{ x: -10.1, w: 2.7, h: 4.65, color: facadeMaterials[0] },
{ x: -7.0, w: 2.8, h: 5.35, color: facadeMaterials[1] },
{ x: -3.9, w: 2.8, h: 4.85, color: facadeMaterials[2] },
{ x: -0.55, w: 3.0, h: 5.65, color: facadeMaterials[3] },
{ x: 3.35, w: 2.7, h: 4.75, color: facadeMaterials[4] },
{ x: 6.25, w: 2.55, h: 4.15, color: facadeMaterials[5] }
];
lowerHouses.forEach((house, i) => {
addHouse({
...house,
z: -2.12,
d: 2.35,
base: 1.05,
shutters: facadeMaterials[(i + 2) % facadeMaterials.length],
variant: i
});
});
const upperHouses = [
{ x: -9.6, w: 2.8, h: 3.55, color: facadeMaterials[5] },
{ x: -6.45, w: 2.8, h: 3.9, color: facadeMaterials[0] },
{ x: -3.2, w: 2.65, h: 3.45, color: facadeMaterials[4] },
{ x: 0.1, w: 2.8, h: 3.8, color: facadeMaterials[2] },
{ x: 3.35, w: 2.7, h: 3.5, color: facadeMaterials[3] },
{ x: 6.55, w: 2.55, h: 3.2, color: facadeMaterials[1] }
];
upperHouses.forEach((house, i) => {
addHouse({
...house,
z: -4.86,
d: 2.1,
base: 4.25,
shutters: facadeMaterials[(i + 4) % facadeMaterials.length],
variant: i + 2
});
});
const backHouses = [
{ x: -7.5, w: 2.6, h: 2.8, color: facadeMaterials[2] },
{ x: -4.4, w: 2.7, h: 3.0, color: facadeMaterials[0] },
{ x: -1.2, w: 2.6, h: 2.75, color: facadeMaterials[5] },
{ x: 2.0, w: 2.8, h: 3.1, color: facadeMaterials[4] },
{ x: 5.25, w: 2.6, h: 2.85, color: facadeMaterials[3] }
];
backHouses.forEach((house, i) => {
addHouse({
...house,
z: -7.28,
d: 1.9,
base: 6.8,
shutters: facadeMaterials[(i + 1) % facadeMaterials.length],
variant: i + 4
});
});
// A steep stair thread between the terraces.
for (let i = 0; i < 11; i++) {
box(
0.82, 0.24, 0.55, i % 2 ? mats.stoneLight : mats.stone,
scene, 1.38, 1.2 + i * 0.39, -0.87 - i * 0.32
);
}
// Small clock tower.
const tower = new THREE.Group();
tower.position.set(-11.05, 4.4, -4.75);
scene.add(tower);
box(1.55, 4.7, 1.55, material(0xe6d4ac), tower, 0, 2.35, 0);
box(1.72, 0.16, 1.72, mats.trim, tower, 0, 4.72, 0);
const towerRoof = new THREE.Mesh(
new THREE.CylinderGeometry(0, 1.18, 1.25, 4),
material(0x80503e)
);
towerRoof.position.y = 5.42;
towerRoof.rotation.y = Math.PI / 4;
towerRoof.castShadow = true;
tower.add(towerRoof);
const clockFace = new THREE.Mesh(
new THREE.CylinderGeometry(0.34, 0.34, 0.07, 16),
mats.trim
);
clockFace.rotation.x = Math.PI / 2;
clockFace.position.set(0, 2.65, 0.81);
tower.add(clockFace);
box(0.05, 0.24, 0.04, mats.metal, tower, 0, 2.72, 0.87);
box(0.18, 0.045, 0.04, mats.metal, tower, 0.06, 2.65, 0.87);
// A laundry line adds a small Ribeira-specific detail.
rodBetween(
new THREE.Vector3(-6.0, 6.55, -0.75),
new THREE.Vector3(-3.4, 6.2, -0.75),
0.015,
mats.rope
);
box(0.28, 0.44, 0.035, mats.blue, scene, -5.5, 6.32, -0.75);
box(0.23, 0.38, 0.035, mats.cream, scene, -5.05, 6.23, -0.75);
box(0.32, 0.4, 0.035, mats.red, scene, -4.55, 6.13, -0.75);
// -------------------------------------------------------------------------
// Boat landing, ramp, gate, and signage
// -------------------------------------------------------------------------
const landing = new THREE.Group();
scene.add(landing);
box(2.18, 0.18, 1.28, mats.wood, landing, 8.8, 0.45, 3.86);
for (let i = 0; i < 6; i++) {
box(2.12, 0.025, 0.035, mats.woodLight, landing,
8.8, 0.555, 3.32 + i * 0.21);
}
for (const x of [7.86, 9.74]) {
for (const z of [3.38, 4.34]) {
cylinder(0.095, 0.12, 1.45, mats.wood, landing, x, -0.04, z, 7);
}
}
// Sloped ramp from quay level to the floating landing.
const rampA = new THREE.Vector3(8.8, 1.03, 2.18);
const rampB = new THREE.Vector3(8.8, 0.54, 3.25);
const rampDirection = new THREE.Vector3().subVectors(rampB, rampA);
const rampLength = rampDirection.length();
const ramp = box(
1.68, 0.12, rampLength, mats.woodLight,
scene, 8.8, (rampA.y + rampB.y) / 2, (rampA.z + rampB.z) / 2
);
ramp.rotation.x = Math.atan2(-rampDirection.y, rampDirection.z);
for (const x of [7.98, 9.62]) {
rodBetween(
new THREE.Vector3(x, 1.45, 2.18),
new THREE.Vector3(x, 0.96, 3.25),
0.028,
mats.metal
);
rodBetween(
new THREE.Vector3(x, 0.92, 2.18),
new THREE.Vector3(x, 0.43, 3.25),
0.028,
mats.metal
);
}
// Gate posts and an animated leaf; it opens away from the walking line.
for (const x of [7.74, 9.88]) {
cylinder(0.075, 0.09, 1.18, mats.yellow, scene, x, 1.63, 2.14, 8);
cylinder(0.11, 0.11, 0.08, mats.yellow, scene, x, 2.25, 2.14, 8);
}
const gate = new THREE.Group();
gate.position.set(7.78, 1.08, 2.14);
scene.add(gate);
box(2.0, 0.07, 0.07, mats.yellow, gate, 1.0, 0.55, 0);
box(2.0, 0.07, 0.07, mats.yellow, gate, 1.0, 0.08, 0);
for (let i = 0; i <= 7; i++) {
box(0.045, 0.55, 0.045, mats.yellow, gate, i * 0.285, 0.31, 0);
}
// Clear-access marker painted on the quay.
const accessRing = new THREE.Mesh(
new THREE.TorusGeometry(0.64, 0.045, 6, 24),
mats.yellow
);
accessRing.rotation.x = Math.PI / 2;
accessRing.position.set(8.8, 1.11, 1.55);
scene.add(accessRing);
const signTexture = canvasTexture(512, 220, (ctx, w, h) => {
ctx.fillStyle = "#153f43";
ctx.fillRect(0, 0, w, h);
ctx.strokeStyle = "#e8b75d";
ctx.lineWidth = 12;
ctx.strokeRect(8, 8, w - 16, h - 16);
ctx.fillStyle = "#f8edcf";
ctx.textAlign = "center";
ctx.font = "bold 54px sans-serif";
ctx.fillText("BOARDING", w / 2, 91);
ctx.font = "34px sans-serif";
ctx.fillStyle = "#e8b75d";
ctx.fillText("ACCESS ↓", w / 2, 151);
ctx.font = "22px sans-serif";
ctx.fillStyle = "#d8e4de";
ctx.fillText("QUAY WALK CLEAR", w / 2, 194);
});
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(1.72, 0.74),
new THREE.MeshStandardMaterial({
map: signTexture,
roughness: 0.8,
side: THREE.DoubleSide
})
);
sign.position.set(10.2, 2.14, 2.13);
sign.rotation.y = -0.08;
scene.add(sign);
cylinder(0.055, 0.07, 1.12, mats.metal, scene, 10.2, 1.58, 2.12, 8);
// -------------------------------------------------------------------------
// Low-poly river boat
// -------------------------------------------------------------------------
const boat = new THREE.Group();
boat.position.set(8.8, 0.05, 5.88);
scene.add(boat);
const topRing = [
[-0.64, -1.65],
[ 0.64, -1.65],
[ 0.82, 0.78],
[ 0.00, 1.82],
[-0.82, 0.78]
];
const hullVertices = [];
const hullIndices = [];
for (const [x, z] of topRing) {
hullVertices.push(x, 0.43, z);
}
for (const [x, z] of topRing) {
hullVertices.push(x * 0.68, -0.58, z * 0.9 - 0.08);
}
for (let i = 0; i < topRing.length; i++) {
const next = (i + 1) % topRing.length;
hullIndices.push(i, next, i + topRing.length);
hullIndices.push(next, next + topRing.length, i + topRing.length);
}
hullIndices.push(5, 6, 7, 5, 7, 8, 5, 8, 9);
const hullGeometry = new THREE.BufferGeometry();
hullGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(hullVertices, 3)
);
hullGeometry.setIndex(hullIndices);
hullGeometry.computeVertexNormals();
const hull = new THREE.Mesh(hullGeometry, mats.boat);
hull.castShadow = true;
hull.receiveShadow = true;
boat.add(hull);
const deckShape = new THREE.Shape();
deckShape.moveTo(-0.64, -1.65);
deckShape.lineTo(0.64, -1.65);
deckShape.lineTo(0.82, 0.78);
deckShape.lineTo(0, 1.82);
deckShape.lineTo(-0.82, 0.78);
deckShape.closePath();
const deck = new THREE.Mesh(
new THREE.ShapeGeometry(deckShape),
mats.woodLight
);
deck.rotation.x = Math.PI / 2;
deck.position.y = 0.44;
deck.receiveShadow = true;
boat.add(deck);
for (let z = -1.25; z < 1.2; z += 0.45) {
const halfWidth = z > 0.45 ? 0.82 * (1.82 - z) / 1.1 : 0.73;
box(halfWidth * 2, 0.018, 0.025, mats.wood, boat, 0, 0.465, z);
}
// Cabin and wheelhouse.
box(1.03, 0.68, 1.16, mats.boatTrim, boat, 0, 0.79, 0.24);
box(1.27, 0.12, 1.4, mats.cream, boat, 0, 1.18, 0.24);
box(0.72, 0.35, 0.035, mats.glass, boat, 0, 0.88, 0.835);
box(0.035, 0.35, 0.66, mats.glass, boat, 0.53, 0.87, 0.24);
box(0.035, 0.35, 0.66, mats.glass, boat, -0.53, 0.87, 0.24);
cylinder(0.035, 0.045, 2.1, mats.metal, boat, 0, 1.47, -0.8, 7);
box(0.7, 0.04, 0.04, mats.metal, boat, 0, 2.13, -0.8);
const flagShape = new THREE.Shape();
flagShape.moveTo(0, 0);
flagShape.lineTo(0.48, -0.12);
flagShape.lineTo(0, -0.28);
flagShape.closePath();
const flag = new THREE.Mesh(
new THREE.ShapeGeometry(flagShape),
new THREE.MeshBasicMaterial({
color: 0xdc6a45,
side: THREE.DoubleSide
})
);
flag.position.set(0.02, 2.48, -0.8);
boat.add(flag);
// Cream rub rail.
for (let i = 0; i < topRing.length; i++) {
const a = topRing[i];
const b = topRing[(i + 1) % topRing.length];
rodBetween(
new THREE.Vector3(a[0], 0.42, a[1]),
new THREE.Vector3(b[0], 0.42, b[1]),
0.045,
mats.boatTrim,
boat
);
}
for (const z of [-0.9, 0.6]) {
for (const x of [-0.78, 0.78]) {
const fender = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.17, 0),
mats.cream
);
fender.position.set(x, 0.26, z);
fender.scale.set(0.8, 1.25, 0.8);
fender.castShadow = true;
boat.add(fender);
}
}
// -------------------------------------------------------------------------
// Animated boarding passenger
// -------------------------------------------------------------------------
const passenger = new THREE.Group();
scene.add(passenger);
box(0.39, 0.58, 0.25, mats.shirt, passenger, 0, 1.01, 0);
box(0.31, 0.32, 0.14, mats.red, passenger, 0, 1.02, -0.19);
const head = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.19, 0),
mats.skin
);
head.position.set(0, 1.49, 0.015);
head.castShadow = true;
passenger.add(head);
box(0.31, 0.12, 0.3, material(0x443229), passenger, 0, 1.62, -0.015);
box(0.08, 0.07, 0.07, mats.skin, passenger, 0, 1.49, 0.19);
function makeLimb(x, y, mat, length, radius, parent) {
const pivot = new THREE.Group();
pivot.position.set(x, y, 0);
parent.add(pivot);
cylinder(radius, radius * 0.88, length, mat,
pivot, 0, -length / 2, 0, 6);
return pivot;
}
const leftLeg = makeLimb(-0.105, 0.74, mats.trousers, 0.57, 0.075, passenger);
const rightLeg = makeLimb(0.105, 0.74, mats.trousers, 0.57, 0.075, passenger);
const leftArm = makeLimb(-0.265, 1.22, mats.shirt, 0.48, 0.06, passenger);
const rightArm = makeLimb(0.265, 1.22, mats.shirt, 0.48, 0.06, passenger);
box(0.14, 0.09, 0.25, mats.metal, leftLeg, 0, -0.59, 0.055);
box(0.14, 0.09, 0.25, mats.metal, rightLeg, 0, -0.59, 0.055);
const boardingPath = [
new THREE.Vector3(8.8, 1.08, -1.15),
new THREE.Vector3(8.8, 1.08, 2.18),
new THREE.Vector3(8.8, 0.54, 3.25),
new THREE.Vector3(8.8, 0.54, 4.45),
new THREE.Vector3(8.8, 0.54, 5.35)
];
const pathLengths = [0];
for (let i = 1; i < boardingPath.length; i++) {
pathLengths.push(
pathLengths[i - 1] +
boardingPath[i].distanceTo(boardingPath[i - 1])
);
}
const totalBoardingLength = pathLengths[pathLengths.length - 1];
function sampleBoardingPath(distance) {
const d = THREE.MathUtils.clamp(distance, 0, totalBoardingLength);
for (let i = 1; i < boardingPath.length; i++) {
if (d <= pathLengths[i]) {
const segmentLength = pathLengths[i] - pathLengths[i - 1];
const t = (d - pathLengths[i - 1]) / segmentLength;
return boardingPath[i - 1].clone().lerp(boardingPath[i], t);
}
}
return boardingPath[boardingPath.length - 1].clone();
}
// Mooring lines stay attached as the boat gently bobs.
const ropeMaterial = new THREE.LineBasicMaterial({ color: 0x806747 });
const mooringLines = [];
for (const offset of [-0.75, 0.75]) {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(8.8 + offset, 0.63, 4.38),
new THREE.Vector3(8.8 + offset, 0.48, 4.38)
]);
const line = new THREE.Line(geometry, ropeMaterial);
scene.add(line);
mooringLines.push({ line, offset });
}
// -------------------------------------------------------------------------
// Clouds and birds
// -------------------------------------------------------------------------
const cloudMaterial = new THREE.MeshBasicMaterial({ color: 0xf2f1e8 });
function cloud(x, y, z, scale) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
scene.add(group);
const pieces = [
[-0.75, 0, 0, 0.7],
[0, 0.18, 0, 0.95],
[0.8, 0.02, 0.1, 0.72],
[0.3, -0.12, 0.35, 0.65]
];
for (const [px, py, pz, size] of pieces) {
const puff = new THREE.Mesh(
new THREE.DodecahedronGeometry(size, 0),
cloudMaterial
);
puff.position.set(px, py, pz);
puff.scale.y = 0.7;
group.add(puff);
}
}
cloud(-10, 11.2, -15, 1.15);
cloud(4, 13.4, -19, 0.9);
cloud(13, 10.4, -13, 0.75);
const birds = [];
const birdMaterial = new THREE.LineBasicMaterial({ color: 0x526a6e });
for (const [x, y, z] of [[-6, 8.6, -1], [-4.8, 8.2, -0.8], [11, 9.2, -3]]) {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-0.32, 0, 0),
new THREE.Vector3(0, 0.14, 0),
new THREE.Vector3(0.32, 0, 0)
]);
const bird = new THREE.Line(geometry, birdMaterial);
bird.position.set(x, y, z);
scene.add(bird);
birds.push(bird);
}
// -------------------------------------------------------------------------
// Camera controls implemented without addons
// -------------------------------------------------------------------------
const cameraState = {
yaw: 0.64,
elevation: 0.31,
radius: 24,
target: new THREE.Vector3(-0.4, 2.05, -0.2)
};
const initialCamera = {
yaw: cameraState.yaw,
elevation: cameraState.elevation,
radius: cameraState.radius
};
function updateCamera() {
const horizontal = Math.cos(cameraState.elevation) * cameraState.radius;
camera.position.set(
cameraState.target.x + Math.sin(cameraState.yaw) * horizontal,
cameraState.target.y + Math.sin(cameraState.elevation) * cameraState.radius,
cameraState.target.z + Math.cos(cameraState.yaw) * horizontal
);
camera.lookAt(cameraState.target);
}
updateCamera();
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.yaw -= dx * 0.006;
cameraState.elevation = THREE.MathUtils.clamp(
cameraState.elevation + dy * 0.0045,
0.12,
0.78
);
updateCamera();
});
canvas.addEventListener("pointerup", (event) => {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
});
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
15,
34
);
updateCamera();
}, { passive: false });
document.querySelector("#resetView").addEventListener("click", () => {
cameraState.yaw = initialCamera.yaw;
cameraState.elevation = initialCamera.elevation;
cameraState.radius = initialCamera.radius;
updateCamera();
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let elapsed = 0;
let previousStatus = "";
function smoothRange(value, start, end) {
const t = THREE.MathUtils.clamp((value - start) / (end - start), 0, 1);
return t * t * (3 - 2 * t);
}
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
const cycle = 10.5;
const phase = elapsed % cycle;
const boatBob = Math.sin(elapsed * 1.35) * 0.035;
boat.position.y = 0.05 + boatBob;
boat.rotation.z = Math.sin(elapsed * 0.78) * 0.012;
boat.rotation.x = Math.sin(elapsed * 1.02 + 0.8) * 0.006;
flag.rotation.y = Math.sin(elapsed * 3.2) * 0.12;
// Gate opens before the passenger approaches and closes after boarding.
const gateOpen = phase < 8.2
? smoothRange(phase, 0.12, 0.8)
: 1 - smoothRange(phase, 8.2, 9.15);
gate.rotation.y = -gateOpen * Math.PI * 0.5;
const passengerVisible = phase >= 0.62 && phase < 8.18;
passenger.visible = passengerVisible;
if (passengerVisible) {
const walkProgress = THREE.MathUtils.clamp(
(phase - 0.72) / (7.55 - 0.72),
0,
1
);
const position = sampleBoardingPath(
walkProgress * totalBoardingLength
);
if (position.z > 4.45) {
position.y += boatBob;
}
const walking = phase > 0.72 && phase < 7.55;
const stride = walking ? Math.sin(elapsed * 8.6) : 0;
passenger.position.copy(position);
passenger.position.y += walking
? Math.abs(Math.sin(elapsed * 8.6)) * 0.022
: 0;
passenger.rotation.y = 0;
leftLeg.rotation.x = stride * 0.52;
rightLeg.rotation.x = -stride * 0.52;
leftArm.rotation.x = -stride * 0.38;
rightArm.rotation.x = stride * 0.38;
}
// Keep the mooring endpoints attached to the boat.
for (const { line, offset } of mooringLines) {
const positions = line.geometry.attributes.position;
positions.setXYZ(
1,
8.8 + offset,
0.48 + boatBob,
4.38 + boat.position.z - 5.88
);
positions.needsUpdate = true;
line.geometry.computeBoundingSphere();
}
for (let i = 0; i < birds.length; i++) {
const bird = birds[i];
bird.position.y += Math.sin(elapsed * 1.3 + i) * 0.0015;
bird.rotation.z = Math.sin(elapsed * 2.1 + i) * 0.08;
bird.position.x += 0.0015;
if (bird.position.x > 16) bird.position.x = -15;
}
let status = "Boarding access active";
if (phase < 0.8) status = "Opening access gate";
else if (phase < 7.55) status = "Passenger boarding";
else if (phase < 8.2) status = "Boarding complete";
else status = "Promenade clear";
if (status !== previousStatus) {
document.querySelector("#statusText").textContent = status;
previousStatus = status;
}
renderer.render(scene, camera);
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
</script>
</body>
</html>
```