Prompt specification
Build or customize the Three.js 3D scene "Montréal Old Port pier and urban edge" 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: Montréal Old Port pier and urban edge
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/montr-al-old-port-pier-and-urban-edge-x2763
Scene Description Prompt:
A voxel Montréal Old Port fragment linking pier, warehouse, waterfront path, and entrance to a historic street. Build one HTML file with Three.js from cdnjs.
Working Three.js Starter (montr-al-old-port-pier-and-urban-edge-x2763):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#14282c" />
<title>Montréal — Vieux-Port Fragment</title>
<style>
:root {
--ink: #13272b;
--paper: #f4ead6;
--muted: #b8cbc7;
--accent: #efb35f;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #bfd7da;
color: var(--paper);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas:active {
cursor: grabbing;
}
#hud {
position: fixed;
z-index: 10;
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 18px 20px 17px;
border: 1px solid rgba(244, 234, 214, 0.18);
border-radius: 4px;
background: rgba(16, 36, 40, 0.88);
box-shadow: 0 12px 40px rgba(9, 24, 29, 0.2);
backdrop-filter: blur(10px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
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(27px, 4vw, 42px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.025em;
}
.subtitle {
max-width: 320px;
margin: 12px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
#help {
position: fixed;
z-index: 10;
bottom: 21px;
left: 22px;
display: flex;
flex-wrap: wrap;
gap: 7px 12px;
max-width: calc(100vw - 44px);
color: rgba(19, 39, 43, 0.78);
font-size: 11px;
font-weight: 700;
pointer-events: none;
}
#help span {
padding: 7px 9px;
border: 1px solid rgba(19, 39, 43, 0.16);
border-radius: 3px;
background: rgba(244, 234, 214, 0.76);
backdrop-filter: blur(6px);
}
#coordinates {
position: fixed;
z-index: 10;
right: 22px;
bottom: 22px;
color: rgba(19, 39, 43, 0.62);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
pointer-events: none;
}
#hotspots {
position: fixed;
z-index: 8;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.hotspot {
position: absolute;
width: 18px;
height: 18px;
padding: 0;
border: 0;
border-radius: 50%;
background: transparent;
transform: translate(-50%, -50%);
cursor: pointer;
pointer-events: auto;
}
.hotspot::before {
position: absolute;
inset: 4px;
border: 2px solid white;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 2px 10px rgba(5, 20, 24, 0.4);
content: "";
}
.hotspot::after {
position: absolute;
inset: 0;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 50%;
animation: pulse 2.3s ease-out infinite;
content: "";
}
.hotspot .tag {
position: absolute;
top: 50%;
left: 26px;
padding: 6px 9px;
border: 1px solid rgba(255, 255, 255, 0.18);
border-radius: 3px;
background: rgba(16, 36, 40, 0.88);
box-shadow: 0 4px 14px rgba(9, 24, 29, 0.16);
color: var(--paper);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
line-height: 1;
white-space: nowrap;
text-transform: uppercase;
transform: translateY(-50%);
transition:
background 160ms ease,
color 160ms ease;
}
.hotspot:hover .tag,
.hotspot:focus-visible .tag {
background: var(--accent);
color: var(--ink);
}
.hotspot:focus-visible {
outline: 2px solid white;
outline-offset: 4px;
}
@keyframes pulse {
0% {
opacity: 0.8;
transform: scale(0.8);
}
80%,
100% {
opacity: 0;
transform: scale(1.8);
}
}
@media (max-width: 680px) {
#hud {
top: 14px;
left: 14px;
width: min(335px, calc(100vw - 28px));
padding: 14px 16px;
}
.subtitle {
display: none;
}
#help {
bottom: 13px;
left: 14px;
max-width: calc(100vw - 28px);
font-size: 9px;
}
#coordinates {
display: none;
}
.hotspot .tag {
left: 20px;
padding: 5px 7px;
font-size: 8px;
}
}
</style>
</head>
<body>
<header id="hud">
<div class="eyebrow">Montréal · Fragment 01</div>
<h1>Vieux-Port<br />Waterfront</h1>
<p class="subtitle">
A voxel study connecting the working pier, brick entrepôt, cobbled quay,
and the entrance to historic Rue Saint-Paul.
</p>
</header>
<div id="hotspots" aria-label="Scene locations"></div>
<div id="help">
<span>Drag · orbit</span>
<span>Shift-drag · pan</span>
<span>Wheel / pinch · zoom</span>
<span>Select a marker</span>
</div>
<div id="coordinates">45.5019° N 73.5554° W · Old Port</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(0xc5dcdf);
scene.fog = new THREE.Fog(0xc5dcdf, 75, 145);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel model of Montréal's Old Port"
);
document.body.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
240
);
const hemisphere = new THREE.HemisphereLight(0xdff4f4, 0x5b463c, 1.7);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffdfb0, 3.2);
sun.position.set(-26, 45, 28);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -48;
sun.shadow.camera.right = 48;
sun.shadow.camera.top = 48;
sun.shadow.camera.bottom = -48;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 120;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9bc9d7, 0.75);
fill.position.set(35, 20, -30);
scene.add(fill);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02
})
);
}
return materialCache.get(color);
}
function box(w, h, d, x, y, z, color, parent = scene) {
const mesh = new THREE.Mesh(unitBox, material(color));
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function instanceBoxes(entries, options = {}) {
const mesh = new THREE.InstancedMesh(
unitBox,
new THREE.MeshStandardMaterial({
color: options.color ?? 0xffffff,
vertexColors: true,
roughness: options.roughness ?? 0.86,
metalness: options.metalness ?? 0.02
}),
entries.length
);
const dummy = new THREE.Object3D();
entries.forEach((entry, index) => {
dummy.position.set(entry.x, entry.y, entry.z);
dummy.scale.set(entry.w, entry.h, entry.d);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
mesh.setColorAt(index, new THREE.Color(entry.c ?? 0xffffff));
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = options.castShadow ?? false;
mesh.receiveShadow = true;
mesh.frustumCulled = false;
(options.parent ?? scene).add(mesh);
return mesh;
}
function makeSign(text, width, height, options = {}) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const context = canvas.getContext("2d");
context.fillStyle = options.background ?? "#19363a";
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = options.border ?? "#d8b477";
context.lineWidth = 7;
context.strokeRect(10, 10, canvas.width - 20, canvas.height - 20);
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = options.foreground ?? "#f4ead6";
context.font = `700 ${options.fontSize ?? 54}px Arial, sans-serif`;
context.fillText(
text,
canvas.width / 2,
options.subtitle ? 105 : 132,
canvas.width - 80
);
if (options.subtitle) {
context.fillStyle = options.secondary ?? "#d8b477";
context.font = "700 27px Arial, sans-serif";
context.fillText(
options.subtitle,
canvas.width / 2,
190,
canvas.width - 80
);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(4, renderer.capabilities.getMaxAnisotropy());
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
side: THREE.DoubleSide,
toneMapped: false
})
);
return mesh;
}
// Deterministic randomness keeps the composition stable.
let randomSeed = 73421;
function random() {
randomSeed |= 0;
randomSeed = (randomSeed + 0x6d2b79f5) | 0;
let value = Math.imul(randomSeed ^ (randomSeed >>> 15), 1 | randomSeed);
value = (value + Math.imul(value ^ (value >>> 7), 61 | value)) ^ value;
return ((value ^ (value >>> 14)) >>> 0) / 4294967296;
}
// -------------------------------------------------------------------------
// Diorama base and waterfront
// -------------------------------------------------------------------------
box(190, 1, 190, 0, -4.4, 0, 0xa8c3c1);
box(58, 3.4, 31, 0, -1.7, -7, 0x29464b);
box(58, 0.32, 31, 0, -0.08, -7, 0x8b806d);
box(58, 1.2, 34, 0, -1.45, 25.5, 0x315f69);
box(58, 0.22, 0.3, 0, 0.13, 8.45, 0xd5c6a8);
const quayBlocks = [];
for (let x = -27; x <= 27; x += 2) {
quayBlocks.push({
x,
y: -0.68 + random() * 0.04,
z: 8.18,
w: 1.93,
h: 1.72,
d: 1.1,
c: random() > 0.5 ? 0x777b70 : 0x686f68
});
}
instanceBoxes(quayBlocks, { castShadow: true });
const waterGroups = [];
const waterColors = [0x4f9ba5, 0x46929e, 0x58a6ad, 0x3f8794];
for (let phase = 0; phase < 3; phase++) {
const tiles = [];
for (let x = -27; x <= 27; x += 2) {
for (let z = 9; z <= 41; z += 2) {
const color = new THREE.Color(
waterColors[Math.floor(random() * waterColors.length)]
);
color.offsetHSL(0, 0, (random() - 0.5) * 0.035);
tiles.push({
x,
y: -0.4 + random() * 0.045,
z,
w: 1.94,
h: 0.2,
d: 1.94,
c: color.getHex()
});
}
}
const water = instanceBoxes(tiles, {
roughness: 0.38,
metalness: 0.08
});
waterGroups.push({ mesh: water, phase: phase * 2.1 });
}
// Cobbled waterfront promenade.
const promenade = [];
for (let row = 0; row < 5; row++) {
for (let x = -27; x <= 27; x += 1.2) {
const shade = random();
promenade.push({
x: x + (random() - 0.5) * 0.08,
y: 0.08 + random() * 0.025,
z: 2.25 + row * 1.24,
w: 1.1,
h: 0.13,
d: 1.12,
c: shade > 0.66 ? 0xa9a18c : shade > 0.3 ? 0x989384 : 0xb4aa93
});
}
}
instanceBoxes(promenade);
// Cobbled lane into the historic street.
const streetCobbles = [];
for (let z = 4.5; z >= -20.5; z -= 1.12) {
for (let x = 17.05; x <= 20.55; x += 1.15) {
const shade = random();
streetCobbles.push({
x: x + (random() - 0.5) * 0.05,
y: 0.1,
z: z + (random() - 0.5) * 0.05,
w: 1.03,
h: 0.14,
d: 1.0,
c: shade > 0.6 ? 0x8d8d82 : shade > 0.28 ? 0x9b9889 : 0xaaa38f
});
}
}
instanceBoxes(streetCobbles);
// -------------------------------------------------------------------------
// Warehouse
// -------------------------------------------------------------------------
const warehouseX = -3;
const warehouseZ = -5.5;
const warehouseFront = 0.55;
box(21.6, 0.72, 12.6, warehouseX, 0.36, warehouseZ, 0x777568);
box(21, 8.3, 12, warehouseX, 4.15, warehouseZ, 0x9e4f40);
// Pixel-scale brick courses on the river-facing and eastern walls.
const brickEntries = [];
for (let y = 0.85; y < 8; y += 0.58) {
for (let x = -12.9; x <= 6.9; x += 1.25) {
brickEntries.push({
x,
y,
z: warehouseFront + 0.025,
w: 1.12,
h: 0.08,
d: 0.07,
c: random() > 0.48 ? 0xb2634f : 0x874237
});
}
}
for (let y = 0.85; y < 8; y += 0.58) {
for (let z = -10.85; z <= -0.1; z += 1.25) {
brickEntries.push({
x: 7.54,
y,
z,
w: 0.07,
h: 0.08,
d: 1.12,
c: random() > 0.48 ? 0xa95847 : 0x814036
});
}
}
instanceBoxes(brickEntries);
// Flat roof with stepped parapet.
box(21.8, 0.5, 12.8, warehouseX, 8.55, warehouseZ, 0x3f4b4b);
box(21.6, 0.55, 0.35, warehouseX, 8.93, 0.77, 0x66706a);
box(21.6, 0.55, 0.35, warehouseX, 8.93, -11.77, 0x66706a);
box(0.35, 0.55, 12.6, -13.32, 8.93, warehouseZ, 0x66706a);
box(0.35, 0.55, 12.6, 7.32, 8.93, warehouseZ, 0x66706a);
box(18.8, 0.35, 9.8, warehouseX, 8.93, warehouseZ, 0x485452);
box(2.2, 0.9, 2.2, -8.7, 9.4, -7.3, 0x69716d);
box(2.6, 0.22, 2.6, -8.7, 9.95, -7.3, 0x343f40);
// Loading doors.
[-5.2, -0.8].forEach((doorX) => {
box(4.2, 4.3, 0.28, doorX, 2.25, 0.72, 0x243f42);
box(0.18, 4.7, 0.22, doorX - 2.13, 2.35, 0.86, 0xd0b997);
box(0.18, 4.7, 0.22, doorX + 2.13, 2.35, 0.86, 0xd0b997);
box(4.45, 0.22, 0.25, doorX, 4.68, 0.86, 0xd0b997);
box(0.13, 4.1, 0.12, doorX, 2.25, 0.91, 0x66817d);
box(3.9, 0.15, 0.12, doorX, 1.1, 0.91, 0x66817d);
box(3.9, 0.15, 0.12, doorX, 3.35, 0.91, 0x66817d);
box(2.8, 0.72, 0.16, doorX, 4.98, 0.73, 0x41666c);
});
// Upper warehouse windows.
[-11, -7.5, -4, -0.5, 3, 5.5].forEach((windowX) => {
box(2.05, 2.12, 0.16, windowX, 6.25, 0.67, 0xd0b997);
box(1.62, 1.7, 0.16, windowX, 6.25, 0.79, 0x35565d);
box(0.12, 1.72, 0.14, windowX, 6.25, 0.9, 0xb8a684);
box(1.62, 0.12, 0.14, windowX, 6.25, 0.9, 0xb8a684);
});
const warehouseSign = makeSign(
"ENTREPÔT DU VIEUX-PORT",
13.5,
1.15,
{
background: "#263e40",
foreground: "#f0dfbd",
border: "#c59b5b",
fontSize: 50
}
);
warehouseSign.position.set(warehouseX, 7.52, 0.69);
scene.add(warehouseSign);
// Small loading canopy.
box(8.8, 0.22, 2.1, -3, 4.8, 1.45, 0x45595a);
[-6.8, 0.8].forEach((postX) => {
box(0.18, 4.5, 0.18, postX, 2.35, 2.1, 0x354a4b);
});
// -------------------------------------------------------------------------
// Pier, pilings, railings, crane, and cargo
// -------------------------------------------------------------------------
const pierX = -12;
const deckColors = [0x8c5c3f, 0x79503a, 0x986747, 0x704a36];
for (let z = 9.5; z < 29.5; z += 2) {
const index = Math.floor((z - 9.5) / 2);
box(6, 0.3, 1.92, pierX, 0.1, z, deckColors[index % deckColors.length]);
}
[-15, -9].forEach((postX) => {
[10, 14, 18, 22, 26, 30].forEach((postZ) => {
box(0.48, 5.2, 0.48, postX, -1.65, postZ, 0x4b352e);
box(0.72, 0.25, 0.72, postX, 0.82, postZ, 0x3d2d2a);
});
box(0.16, 0.16, 16.2, postX, 1.55, 21.5, 0x513a31);
box(0.14, 0.13, 16.2, postX, 0.88, 21.5, 0x513a31);
});
[13, 17, 21, 25, 29].forEach((z) => {
[-15, -9].forEach((x) => {
box(0.2, 1.55, 0.2, x, 0.95, z, 0x4d3831);
});
});
// Mooring bollards.
for (let x = -25; x <= 27; x += 4.5) {
box(0.42, 0.76, 0.42, x, 0.4, 7.55, 0x273b3e);
box(0.65, 0.18, 0.65, x, 0.82, 7.55, 0x273b3e);
}
// Dock crane.
box(3, 0.65, 3, -6.8, 0.32, 22.8, 0x4c5551);
box(0.85, 7.8, 0.85, -6.8, 4.2, 22.8, 0xb9873d);
box(0.65, 0.65, 12.6, -6.8, 8.25, 23.9, 0xc08d42);
box(2.8, 2.1, 2.3, -6.8, 1.55, 22.8, 0x59635d);
box(0.12, 4.5, 0.12, -6.8, 5.8, 28.2, 0x354244);
box(0.9, 0.35, 0.9, -6.8, 3.45, 28.2, 0x354244);
box(0.2, 2.6, 0.2, -6.8, 10.25, 20.2, 0x574a3c);
function addCrate(x, y, z, size, color = 0xa67345) {
const group = new THREE.Group();
group.position.set(x, y, z);
const body = new THREE.Mesh(unitBox, material(color));
body.scale.set(size, size, size);
body.position.y = size / 2;
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const slat = 0x6d4934;
box(size + 0.05, size * 0.1, 0.08, 0, size * 0.25, size / 2 + 0.02, slat, group);
box(size + 0.05, size * 0.1, 0.08, 0, size * 0.75, size / 2 + 0.02, slat, group);
box(0.08, size * 0.1, size + 0.05, size / 2 + 0.02, size * 0.25, 0, slat, group);
box(0.08, size * 0.1, size + 0.05, size / 2 + 0.02, size * 0.75, 0, slat, group);
scene.add(group);
return group;
}
addCrate(-13.2, 0.28, 12.1, 1.25, 0xa56f43);
addCrate(-11.6, 0.28, 12.4, 0.85, 0x8b593b);
addCrate(-12.8, 1.54, 12.1, 0.75, 0xb27a49);
addCrate(9.2, 0.05, -0.2, 1.8, 0xa87145);
addCrate(11.3, 0.05, 0.3, 1.3, 0x8a5a3d);
addCrate(9.7, 1.86, -0.2, 1.05, 0xb17a4c);
const pierSign = makeSign("PIER 32", 4.1, 1.05, {
background: "#264a50",
foreground: "#f5dfb4",
border: "#d4a65e",
fontSize: 66
});
pierSign.position.set(pierX, 1.35, 8.15);
scene.add(pierSign);
box(0.16, 1.7, 0.16, pierX - 1.7, 0.8, 8.15, 0x3d4b4b);
box(0.16, 1.7, 0.16, pierX + 1.7, 0.8, 8.15, 0x3d4b4b);
// -------------------------------------------------------------------------
// Historic street and gateway
// -------------------------------------------------------------------------
const facadeColors = [
0xc87356,
0xd8b873,
0x789487,
0xc49761,
0x8e7770,
0xb66d59
];
function addHistoricBuilding(x, z, width, depth, height, color) {
box(width, height, depth, x, height / 2, z, color);
box(width + 0.55, 0.65, depth + 0.55, x, height + 0.32, z, 0x485451);
box(width - 0.7, 0.75, depth - 0.7, x, height + 0.95, z, 0x394746);
const floors = height > 8 ? 3 : 2;
const floorHeight = height / floors;
// Windows on both long elevations.
[-1, 1].forEach((side) => {
const faceX = x + side * (width / 2 + 0.06);
for (let floor = 0; floor < floors; floor++) {
for (const offsetZ of [-depth * 0.23, depth * 0.23]) {
const windowY = floor * floorHeight + floorHeight * 0.58;
box(0.16, 1.65, 1.25, faceX, windowY, z + offsetZ, 0xd7c7a7);
box(
0.19,
1.3,
0.88,
faceX + side * 0.03,
windowY,
z + offsetZ,
0x35545c
);
box(
0.22,
0.09,
0.9,
faceX + side * 0.045,
windowY,
z + offsetZ,
0xa89879
);
}
}
});
// Windows facing the viewer.
for (let floor = 0; floor < floors; floor++) {
for (const offsetX of [-width * 0.24, width * 0.24]) {
const windowY = floor * floorHeight + floorHeight * 0.58;
box(1.1, 1.6, 0.15, x + offsetX, windowY, z + depth / 2 + 0.05, 0xd9c9a8);
box(0.8, 1.28, 0.16, x + offsetX, windowY, z + depth / 2 + 0.1, 0x3d5b61);
}
}
}
const buildingZ = [-6.5, -13, -19.5];
const heights = [8.4, 7.2, 9.1];
buildingZ.forEach((z, index) => {
addHistoricBuilding(
14.05,
z,
5.1,
5.25,
heights[index],
facadeColors[index]
);
addHistoricBuilding(
23.95,
z,
5.1,
5.25,
heights[(index + 2) % heights.length],
facadeColors[(index + 3) % facadeColors.length]
);
});
// Gateway marking the transition from quay to Rue Saint-Paul.
box(1.15, 4.7, 1.2, 16.45, 2.35, 0, 0xc2ad87);
box(1.15, 4.7, 1.2, 21.55, 2.35, 0, 0xc2ad87);
box(6.35, 1.05, 1.25, 19, 4.62, 0, 0xb59c78);
box(6.8, 0.22, 1.55, 19, 5.22, 0, 0xd1bd96);
const streetSign = makeSign(
"RUE SAINT-PAUL",
5.8,
0.88,
{
background: "#314b4a",
foreground: "#f0dfbd",
border: "#d0a35d",
fontSize: 58
}
);
streetSign.position.set(19, 4.64, 0.66);
scene.add(streetSign);
// -------------------------------------------------------------------------
// Furniture, trees, lamps, and people
// -------------------------------------------------------------------------
function addLamp(x, z) {
box(0.55, 0.25, 0.55, x, 0.12, z, 0x43504e);
box(0.16, 4.1, 0.16, x, 2.05, z, 0x2e4142);
box(0.72, 0.16, 0.72, x, 4.12, z, 0x2e4142);
const glow = new THREE.Mesh(
unitBox,
new THREE.MeshStandardMaterial({
color: 0xffd591,
emissive: 0xffb84d,
emissiveIntensity: 1.4,
roughness: 0.4
})
);
glow.scale.set(0.43, 0.5, 0.43);
glow.position.set(x, 3.78, z);
scene.add(glow);
}
[-19, -4, 10.5, 26].forEach((x) => addLamp(x, 6.65));
function addTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
box(1.8, 0.58, 1.8, 0, 0.29, 0, 0x8e8978, group);
box(1.52, 0.18, 1.52, 0, 0.62, 0, 0x555e4f, group);
box(0.42, 2.35, 0.42, 0, 1.65, 0, 0x6c4f39, group);
box(2.05, 1.35, 1.8, 0, 3.05, 0, 0x4f7357, group);
box(1.55, 1.05, 2.1, -0.15, 3.95, 0.05, 0x5b805d, group);
box(1.35, 0.8, 1.25, 0.4, 4.65, -0.15, 0x6e8e63, group);
scene.add(group);
}
addTree(9.3, 1.1, 0.88);
addTree(12.0, 1.3, 0.74);
addTree(-17.8, 1.2, 0.8);
function addBench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
box(2.8, 0.18, 0.7, 0, 0.72, 0, 0x9a6944, group);
box(2.8, 0.85, 0.16, 0, 1.17, -0.3, 0x9a6944, group);
box(0.18, 0.72, 0.65, -1.05, 0.36, 0, 0x36494a, group);
box(0.18, 0.72, 0.65, 1.05, 0.36, 0, 0x36494a, group);
scene.add(group);
}
addBench(6.7, 4.65, Math.PI / 2);
addBench(24.2, 4.65, -Math.PI / 2);
const people = [];
function addPerson(x, z, options = {}) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(options.scale ?? 1);
const coat = options.coat ?? 0xbe6048;
const trousers = options.trousers ?? 0x30444d;
const skin = options.skin ?? 0xc98d68;
box(0.2, 0.58, 0.24, -0.15, 0.31, 0, trousers, group);
box(0.2, 0.58, 0.24, 0.15, 0.31, 0, trousers, group);
box(0.56, 0.72, 0.34, 0, 0.94, 0, coat, group);
box(0.18, 0.62, 0.2, -0.39, 0.94, 0, coat, group);
box(0.18, 0.62, 0.2, 0.39, 0.94, 0, coat, group);
box(0.42, 0.42, 0.42, 0, 1.5, 0, skin, group);
box(0.47, 0.13, 0.47, 0, 1.76, 0, options.hat ?? 0x38484c, group);
if (options.bag) {
box(0.32, 0.4, 0.18, 0.45, 0.75, 0, 0x7b573e, group);
}
group.userData = {
phase: random() * Math.PI * 2,
axis: options.axis ?? null,
min: options.min ?? 0,
max: options.max ?? 0,
speed: options.speed ?? 0
};
scene.add(group);
people.push(group);
return group;
}
addPerson(-11.1, 17.5, {
coat: 0xd1a24c,
trousers: 0x3d5358,
hat: 0x283b40
});
addPerson(-13.0, 23.7, {
coat: 0x607c86,
trousers: 0x4a4644,
bag: true
});
addPerson(2.4, 4.5, {
coat: 0xb95d47,
trousers: 0x334d59,
axis: "x",
min: -8,
max: 8,
speed: 1.15
});
addPerson(19.1, -3.5, {
coat: 0x7c9274,
trousers: 0x4a4543,
scale: 0.95
});
addPerson(18.2, 4.1, {
coat: 0xe1b65b,
trousers: 0x40515c,
scale: 0.9
});
// -------------------------------------------------------------------------
// Boat, birds, and clouds
// -------------------------------------------------------------------------
const boat = new THREE.Group();
boat.position.set(9.5, -0.2, 23.5);
boat.rotation.y = -0.22;
box(4.8, 0.8, 7.2, 0, 0, 0, 0x934a3d, boat);
box(4.35, 0.35, 6.8, 0, 0.55, 0, 0xe0cba7, boat);
box(2.6, 1.55, 2.7, 0, 1.35, -0.55, 0xd9d1b8, boat);
box(2.15, 0.72, 0.12, 0, 1.55, 0.84, 0x41666c, boat);
box(0.16, 6.2, 0.16, 0, 3.6, 0.8, 0x5b493c, boat);
box(3.4, 0.14, 0.14, 0, 4.65, 0.8, 0x5b493c, boat);
box(0.13, 2.8, 2.1, 0.06, 3.25, 0.75, 0xf0e7cf, boat);
box(1.5, 0.1, 0.8, 0, 0.83, -2.4, 0x5b493c, boat);
scene.add(boat);
const birds = [];
function addBird(x, y, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
box(0.32, 0.25, 0.7, 0, 0, 0, 0xf4f0df, group);
box(0.24, 0.22, 0.25, 0, 0.08, 0.48, 0xf4f0df, group);
box(0.16, 0.12, 0.22, 0, 0.06, 0.66, 0xd6a64c, group);
const leftWing = box(0.82, 0.08, 0.28, -0.43, 0.04, 0, 0xe8e4d4, group);
const rightWing = box(0.82, 0.08, 0.28, 0.43, 0.04, 0, 0xe8e4d4, group);
group.userData = {
leftWing,
rightWing,
speed: 0.65 + random() * 0.4,
phase: random() * 10
};
scene.add(group);
birds.push(group);
}
addBird(-5, 9.5, 18, 0.85);
addBird(14, 11.2, 29, 0.65);
addBird(3, 8.4, 34, 0.55);
function addCloud(x, y, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
box(4.2, 1.2, 1.8, 0, 0, 0, 0xe7eee9, group);
box(2.7, 1.8, 1.9, -0.8, 0.5, 0, 0xf0f3ed, group);
box(2.5, 1.4, 1.7, 1.3, 0.3, 0, 0xf0f3ed, group);
scene.add(group);
}
addCloud(-22, 17, 30, 1.3);
addCloud(18, 20, 35, 1.1);
addCloud(-6, 22, 43, 0.85);
// Foam streaks on the river.
const foam = [];
for (let i = 0; i < 28; i++) {
const foamMesh = box(
0.6 + random() * 1.6,
0.045,
0.12 + random() * 0.12,
-27 + random() * 54,
-0.24,
10 + random() * 29,
0xd6ebe6
);
foamMesh.castShadow = false;
foam.push({
mesh: foamMesh,
speed: 0.18 + random() * 0.28
});
}
// Base plaque.
box(14.5, 1.05, 0.16, 0, -1.4, 8.55, 0x20393d);
const baseSign = makeSign("MONTRÉAL · VIEUX-PORT", 13.8, 0.82, {
background: "#20393d",
foreground: "#e8d6b4",
border: "#b78d54",
fontSize: 55
});
baseSign.position.set(0, -1.38, 8.65);
scene.add(baseSign);
// -------------------------------------------------------------------------
// Camera and direct controls — no Three.js examples/addons
// -------------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 2.2, 4),
azimuth: 0.66,
elevation: 0.60,
radius: 69
};
let cameraTween = null;
function updateCamera() {
const horizontal = Math.cos(cameraState.elevation) * cameraState.radius;
camera.position.set(
cameraState.target.x +
horizontal * Math.sin(cameraState.azimuth),
cameraState.target.y +
Math.sin(cameraState.elevation) * cameraState.radius,
cameraState.target.z +
horizontal * Math.cos(cameraState.azimuth)
);
camera.lookAt(cameraState.target);
camera.updateMatrixWorld();
}
updateCamera();
const pointers = new Map();
let pinchDistance = 0;
let shifted = false;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
shifted = event.shiftKey;
cameraTween = null;
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
canvas.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size >= 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0 && distance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (pinchDistance / distance),
20,
105
);
}
pinchDistance = distance;
return;
}
if (event.shiftKey || shifted) {
const scale = cameraState.radius * 0.00115;
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrixWorld, 0)
.setY(0)
.normalize();
const forward = new THREE.Vector3(
-Math.sin(cameraState.azimuth),
0,
-Math.cos(cameraState.azimuth)
);
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(forward, -dy * scale);
cameraState.target.x = THREE.MathUtils.clamp(
cameraState.target.x,
-30,
30
);
cameraState.target.z = THREE.MathUtils.clamp(
cameraState.target.z,
-24,
36
);
} else {
cameraState.azimuth -= dx * 0.006;
cameraState.elevation = THREE.MathUtils.clamp(
cameraState.elevation + dy * 0.005,
0.22,
1.25
);
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
shifted = false;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("lostpointercapture", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraTween = null;
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
20,
105
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "arrowleft") cameraState.azimuth += 0.1;
else if (key === "arrowright") cameraState.azimuth -= 0.1;
else if (key === "arrowup") {
cameraState.elevation = THREE.MathUtils.clamp(
cameraState.elevation + 0.08,
0.22,
1.25
);
} else if (key === "arrowdown") {
cameraState.elevation = THREE.MathUtils.clamp(
cameraState.elevation - 0.08,
0.22,
1.25
);
} else if (key === "+" || key === "=") {
cameraState.radius = Math.max(20, cameraState.radius * 0.9);
} else if (key === "-") {
cameraState.radius = Math.min(105, cameraState.radius * 1.1);
} else {
return;
}
cameraTween = null;
event.preventDefault();
});
// -------------------------------------------------------------------------
// Focusable hotspots
// -------------------------------------------------------------------------
const hotspotDefinitions = [
{
id: "pier",
label: "01 · Pier 32",
position: new THREE.Vector3(-12, 2.2, 18),
camera: {
target: new THREE.Vector3(-12, 1.2, 18),
azimuth: 0.48,
elevation: 0.48,
radius: 35
}
},
{
id: "warehouse",
label: "02 · Entrepôt",
position: new THREE.Vector3(-3, 8.9, -1),
camera: {
target: new THREE.Vector3(-3, 3.2, -2),
azimuth: 0.63,
elevation: 0.56,
radius: 36
}
},
{
id: "quay",
label: "03 · Waterfront",
position: new THREE.Vector3(8.5, 1.7, 5.1),
camera: {
target: new THREE.Vector3(7, 1.4, 4),
azimuth: 0.58,
elevation: 0.62,
radius: 43
}
},
{
id: "street",
label: "04 · Rue Saint-Paul",
position: new THREE.Vector3(19, 5.8, 0.5),
camera: {
target: new THREE.Vector3(19, 2.2, -3),
azimuth: 0.34,
elevation: 0.57,
radius: 36
}
}
];
const hotspotContainer = document.getElementById("hotspots");
const projected = new THREE.Vector3();
hotspotDefinitions.forEach((hotspot) => {
const button = document.createElement("button");
button.className = "hotspot";
button.setAttribute("aria-label", `Focus on ${hotspot.label}`);
button.innerHTML = `<span class="tag">${hotspot.label}</span>`;
button.addEventListener("click", () => {
cameraTween = {
start: performance.now(),
duration: 950,
from: {
target: cameraState.target.clone(),
azimuth: cameraState.azimuth,
elevation: cameraState.elevation,
radius: cameraState.radius
},
to: hotspot.camera
};
});
hotspotContainer.appendChild(button);
hotspot.button = button;
});
function updateHotspots() {
hotspotDefinitions.forEach((hotspot) => {
projected.copy(hotspot.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.05 &&
Math.abs(projected.y) < 1.05;
hotspot.button.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
hotspot.button.style.left = `${x}px`;
hotspot.button.style.top = `${y}px`;
});
}
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
if (cameraTween) {
const progress = THREE.MathUtils.clamp(
(performance.now() - cameraTween.start) / cameraTween.duration,
0,
1
);
const eased = 1 - Math.pow(1 - progress, 3);
const from = cameraTween.from;
const to = cameraTween.to;
cameraState.target.lerpVectors(from.target, to.target, eased);
cameraState.azimuth = THREE.MathUtils.lerp(
from.azimuth,
to.azimuth,
eased
);
cameraState.elevation = THREE.MathUtils.lerp(
from.elevation,
to.elevation,
eased
);
cameraState.radius = THREE.MathUtils.lerp(
from.radius,
to.radius,
eased
);
if (progress >= 1) cameraTween = null;
}
updateCamera();
waterGroups.forEach(({ mesh, phase }) => {
mesh.position.y = Math.sin(time * 0.7 + phase) * 0.035;
});
foam.forEach(({ mesh, speed }) => {
mesh.position.x += speed * delta;
if (mesh.position.x > 28) mesh.position.x = -28;
});
boat.position.y = -0.2 + Math.sin(time * 1.15) * 0.09;
boat.rotation.z = Math.sin(time * 0.75) * 0.012;
people.forEach((person) => {
const data = person.userData;
if (data.axis === "x") {
person.position.x += data.speed * delta;
person.rotation.y = -Math.PI / 2;
if (person.position.x > data.max) person.position.x = data.min;
if (person.position.x < data.min) person.position.x = data.max;
}
person.position.y = Math.abs(Math.sin(time * 5 + data.phase)) * 0.035;
});
birds.forEach((bird) => {
const data = bird.userData;
bird.position.x += data.speed * delta;
bird.position.y += Math.sin(time * 1.4 + data.phase) * 0.08;
if (bird.position.x > 25) bird.position.x = -25;
const flap = Math.sin(time * 8 + data.phase) * 0.48;
data.leftWing.rotation.z = flap;
data.rightWing.rotation.z = -flap;
});
updateHotspots();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
// -------------------------------------------------------------------------
// Resize
// -------------------------------------------------------------------------
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>
```