Prompt specification
Build or customize the Three.js 3D scene "Jamestown street-to-waterfront urban 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: Jamestown street-to-waterfront urban slice
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/jamestown-street-to-waterfront-urban-slice-x2883
Scene Description Prompt:
With Three.js from cdnjs, make a single HTML voxel slice of Jamestown, Accra, connecting a lighthouse, residential lane, and working waterfront.
Working Three.js Starter (jamestown-street-to-waterfront-urban-slice-x2883):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#d7e4df">
<title>Jamestown, Accra — A Voxel Coast</title>
<style>
:root {
--ink: #163c42;
--muted: #567579;
--paper: rgba(250, 247, 236, 0.9);
--line: rgba(22, 60, 66, 0.18);
--accent: #e2694f;
--shadow: 0 18px 50px rgba(22, 60, 66, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c9dbd8;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#app,
#app canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
}
#app canvas {
cursor: grab;
touch-action: none;
}
#app canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
linear-gradient(180deg, rgba(255, 255, 255, 0.2), transparent 24%),
radial-gradient(circle at center, transparent 55%, rgba(22, 60, 66, 0.08));
z-index: 2;
}
header {
position: fixed;
z-index: 5;
top: 28px;
left: 32px;
width: min(440px, calc(100vw - 64px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 28px;
height: 2px;
background: var(--accent);
}
h1 {
margin: 0;
max-width: 420px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(38px, 6vw, 76px);
font-weight: 500;
line-height: 0.84;
letter-spacing: -0.055em;
text-transform: uppercase;
}
h1 span {
display: block;
margin-top: 12px;
color: var(--accent);
font-family: Inter, ui-sans-serif, system-ui, sans-serif;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.34em;
}
.story {
position: fixed;
z-index: 5;
left: 32px;
bottom: 30px;
width: min(350px, calc(100vw - 64px));
padding: 17px 19px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 4px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
.story strong {
display: block;
margin-bottom: 6px;
font-size: 11px;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.story p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.coordinates {
display: flex;
gap: 7px;
align-items: center;
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.coordinates i {
width: 6px;
height: 6px;
border-radius: 50%;
background: #55a999;
box-shadow: 0 0 0 3px rgba(85, 169, 153, 0.16);
}
nav {
position: fixed;
z-index: 6;
right: 28px;
bottom: 30px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 7px;
max-width: calc(100vw - 420px);
}
nav button {
appearance: none;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 3px;
padding: 11px 14px;
color: var(--ink);
background: rgba(250, 247, 236, 0.86);
box-shadow: 0 8px 24px rgba(22, 60, 66, 0.09);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
font: inherit;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
cursor: pointer;
transition:
color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
nav button:hover,
nav button.active {
color: #fffaf0;
background: var(--ink);
transform: translateY(-2px);
}
.hint {
position: fixed;
z-index: 5;
top: 30px;
right: 30px;
display: flex;
align-items: center;
gap: 10px;
color: rgba(22, 60, 66, 0.72);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
pointer-events: none;
}
.hint span {
display: grid;
width: 27px;
height: 27px;
place-items: center;
border: 1px solid rgba(22, 60, 66, 0.24);
border-radius: 50%;
font-size: 14px;
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
top: 0;
left: 0;
display: flex;
align-items: center;
gap: 8px;
color: var(--ink);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
white-space: nowrap;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.9);
transition: opacity 160ms ease;
}
.scene-label::before {
content: "";
width: 7px;
height: 7px;
border: 2px solid var(--paper);
border-radius: 50%;
background: var(--accent);
box-shadow: 0 2px 8px rgba(22, 60, 66, 0.3);
}
.scene-label::after {
content: "";
position: absolute;
top: 50%;
left: 3px;
width: 20px;
height: 1px;
background: rgba(22, 60, 66, 0.34);
z-index: -1;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #d3e1dc;
color: var(--ink);
transition: opacity 500ms ease;
}
#loading div {
text-align: center;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
#loading i {
display: block;
width: 44px;
height: 4px;
margin: 0 auto 15px;
background: var(--accent);
animation: pulse 900ms ease-in-out infinite alternate;
}
@keyframes pulse {
from { transform: scaleX(0.25); opacity: 0.45; }
to { transform: scaleX(1); opacity: 1; }
}
@media (max-width: 720px) {
header {
top: 20px;
left: 20px;
width: calc(100vw - 40px);
}
h1 {
font-size: clamp(34px, 12vw, 54px);
}
.hint {
display: none;
}
.story {
left: 16px;
bottom: 72px;
width: calc(100vw - 32px);
padding: 12px 14px;
}
.story p {
display: none;
}
.coordinates {
margin-top: 0;
padding-top: 8px;
}
nav {
right: 16px;
bottom: 16px;
left: 16px;
justify-content: center;
max-width: none;
}
nav button {
padding: 10px 11px;
font-size: 8px;
}
.scene-label {
font-size: 7px;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div class="vignette"></div>
<header>
<div class="eyebrow">A coastal neighborhood</div>
<h1>
Jamestown
<span>Accra · Ghana</span>
</h1>
</header>
<div class="hint"><span>↔</span> Drag to orbit · Scroll to zoom</div>
<div id="labels" aria-hidden="true">
<div class="scene-label" data-anchor="-3,6.8,-8">The lighthouse</div>
<div class="scene-label" data-anchor="7,3.6,-1">Residential lane</div>
<div class="scene-label" data-anchor="-10,2.1,6.2">Working waterfront</div>
</div>
<aside class="story">
<strong>Atlantic edge of old Accra</strong>
<p>
A lighthouse marks the old fort, colorful homes line a shaded lane,
and fishing crews work the quays along the coast.
</p>
<div class="coordinates">
<i></i>
5.55° N · 0.21° W · Coastal district
</div>
</aside>
<nav aria-label="Camera viewpoints">
<button class="active" data-view="all">Full slice</button>
<button data-view="lighthouse">Lighthouse</button>
<button data-view="lane">Living lane</button>
<button data-view="quay">Fish quay</button>
</nav>
<div id="loading">
<div><i></i>Building the coast</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 app = document.querySelector("#app");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#c9dbd8");
scene.fog = new THREE.Fog("#c9dbd8", 58, 105);
const camera = new THREE.OrthographicCamera(-25, 25, 15, -15, 0.1, 160);
const hemi = new THREE.HemisphereLight("#e9fbff", "#856b4f", 2.2);
scene.add(hemi);
const sun = new THREE.DirectionalLight("#fff1cf", 3.2);
sun.position.set(-18, 30, 18);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -32;
sun.shadow.camera.right = 32;
sun.shadow.camera.top = 30;
sun.shadow.camera.bottom = -30;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 80;
sun.shadow.bias = -0.0008;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight("#91cbd5", 0.85);
fill.position.set(20, 12, -18);
scene.add(fill);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materials = new Map();
const GROUND = 0.37;
function material(color, options = {}) {
const key = color + JSON.stringify(options);
if (!materials.has(key)) {
materials.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.84,
metalness: 0,
...options
})
);
}
return materials.get(key);
}
function box(
width,
height,
depth,
x,
y,
z,
color,
parent = scene,
castShadow = true,
receiveShadow = true
) {
const mat =
color && color.isMaterial
? color
: material(color);
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
function line(points, color = "#345c60", opacity = 1) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map((point) => new THREE.Vector3(...point))
);
const lineMaterial = new THREE.LineBasicMaterial({
color,
transparent: opacity < 1,
opacity
});
return new THREE.Line(geometry, lineMaterial);
}
let randomSeed = 1471;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
function choose(list) {
return list[Math.floor(random() * list.length)];
}
// ------------------------------------------------------------------
// Sea and irregular voxel shoreline
// ------------------------------------------------------------------
const waterMaterial = material("#438f9b", {
roughness: 0.38,
metalness: 0.12,
transparent: true,
opacity: 0.96
});
const water = new THREE.Mesh(
new THREE.PlaneGeometry(150, 150),
waterMaterial
);
water.rotation.x = -Math.PI / 2;
water.position.y = -0.39;
water.receiveShadow = true;
scene.add(water);
function coastline(z) {
return (
-6 +
0.85 * Math.sin(z * 0.55) +
0.35 * Math.sin(z * 1.7)
);
}
const landColumns = [];
const capBuckets = {
sand: [],
garden: [],
road: []
};
for (let x = -8; x <= 16; x++) {
for (let z = -12; z <= 12; z++) {
if (x < coastline(z)) continue;
landColumns.push({ x, z });
const isRoad =
x === 4 ||
x === 5 ||
(z === -8 && x <= 4) ||
(z === 5 && x <= 4);
if (isRoad) {
capBuckets.road.push({ x, z });
} else if (x < coastline(z) + 1.4) {
capBuckets.sand.push({ x, z });
} else {
capBuckets.garden.push({ x, z });
}
}
}
function makeInstancedBoxes(items, height, y, baseColors) {
const mesh = new THREE.InstancedMesh(
unitBox,
material("#ffffff"),
items.length
);
const dummy = new THREE.Object3D();
items.forEach((item, index) => {
dummy.position.set(item.x, y, item.z);
dummy.scale.set(1, height, 1);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
mesh.setColorAt(
index,
new THREE.Color(choose(baseColors))
);
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
makeInstancedBoxes(
landColumns,
1.8,
-0.65,
["#9e7654", "#a9805d", "#947052", "#b38b64"]
);
makeInstancedBoxes(
capBuckets.sand,
0.12,
0.31,
["#d8c291", "#cdb780", "#dfc99a"]
);
makeInstancedBoxes(
capBuckets.garden,
0.12,
0.31,
["#9ba77b", "#8d9b72", "#a7ad82", "#919d78"]
);
makeInstancedBoxes(
capBuckets.road,
0.12,
0.31,
["#c9b593", "#d0bd9e", "#c5af8b"]
);
// Short seawall blocks emphasize the cut edge of the district.
for (let z = -12; z <= 12; z++) {
const x = Math.floor(coastline(z)) - 0.35;
box(
0.65,
0.85,
0.98,
x,
-0.05,
z,
choose(["#ae9a79", "#9f8b6c", "#b9a580"]),
scene
);
}
// Animated block ripples.
const rippleCount = 320;
const rippleMaterial = material("#d2f0e9", {
transparent: true,
opacity: 0.45,
roughness: 0.6
});
const ripples = new THREE.InstancedMesh(
unitBox,
rippleMaterial,
rippleCount
);
const rippleData = [];
const rippleDummy = new THREE.Object3D();
for (let i = 0; i < rippleCount; i++) {
rippleData.push({
x: -28 + random() * 29,
z: -20 + random() * 40,
phase: random() * Math.PI * 2,
length: 0.25 + random() * 1.25,
width: 0.045 + random() * 0.055
});
}
ripples.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
ripples.receiveShadow = false;
ripples.castShadow = false;
scene.add(ripples);
// ------------------------------------------------------------------
// Lane details
// ------------------------------------------------------------------
for (let z = -11; z <= 11; z += 3) {
box(0.09, 0.025, 0.75, 5, 0.39, z, "#eee1b9", scene, false);
}
function streetLamp(x, z) {
box(0.11, 2.5, 0.11, x, GROUND + 1.25, z, "#41585a");
box(0.38, 0.12, 0.38, x, GROUND + 2.55, z, "#34494b");
box(
0.25,
0.18,
0.25,
x,
GROUND + 2.43,
z,
material("#f5d98d", {
emissive: "#c18d36",
emissiveIntensity: 0.35
})
);
}
streetLamp(3.55, -7);
streetLamp(6.45, 1);
streetLamp(3.55, 8);
// ------------------------------------------------------------------
// Lighthouse and fort courtyard
// ------------------------------------------------------------------
const lighthouse = new THREE.Group();
lighthouse.position.set(-3, GROUND, -8);
scene.add(lighthouse);
box(5.2, 0.15, 4.8, 0, 0.08, 0, "#b9ab91", lighthouse);
box(3.6, 0.45, 3.6, 0, 0.36, 0, "#d5c8ac", lighthouse);
box(2.7, 0.55, 2.7, 0, 0.86, 0, "#e7dfcc", lighthouse);
box(1.7, 3.75, 1.7, 0, 2.92, 0, "#f0eadb", lighthouse);
box(1.78, 0.28, 1.78, 0, 2.45, 0, "#d36550", lighthouse);
box(1.77, 0.22, 1.77, 0, 3.95, 0, "#d36550", lighthouse);
box(2.45, 0.24, 2.45, 0, 4.94, 0, "#c75947", lighthouse);
box(1.45, 1.0, 1.45, 0, 5.55, 0, "#91bfc0", lighthouse);
for (const x of [-0.65, 0, 0.65]) {
box(0.09, 1.02, 0.09, x, 5.55, -0.7, "#354d51", lighthouse);
box(0.09, 1.02, 0.09, x, 5.55, 0.7, "#354d51", lighthouse);
box(0.09, 1.02, 0.09, -0.7, 5.55, x, "#354d51", lighthouse);
box(0.09, 1.02, 0.09, 0.7, 5.55, x, "#354d51", lighthouse);
}
box(1.8, 0.24, 1.8, 0, 6.15, 0, "#bd4d40", lighthouse);
box(1.3, 0.22, 1.3, 0, 6.37, 0, "#b7463b", lighthouse);
box(0.75, 0.22, 0.75, 0, 6.59, 0, "#a83e35", lighthouse);
box(0.09, 0.62, 0.09, 0, 6.96, 0, "#425256", lighthouse);
// Lantern glow.
const lantern = new THREE.PointLight("#ffd887", 2.2, 8, 2);
lantern.position.set(0, 5.55, 0);
lighthouse.add(lantern);
// Tower windows.
for (const y of [1.7, 3.1]) {
box(0.58, 0.72, 0.08, 0, y, 0.88, "#314d55", lighthouse);
box(0.08, 0.72, 0.58, -0.88, y, 0, "#314d55", lighthouse);
}
// Gallery railing.
for (let i = -3; i <= 3; i++) {
const p = i * 0.34;
box(0.055, 0.42, 0.055, p, 5.18, 1.12, "#475457", lighthouse);
box(0.055, 0.42, 0.055, p, 5.18, -1.12, "#475457", lighthouse);
box(0.055, 0.42, 0.055, 1.12, 5.18, p, "#475457", lighthouse);
box(0.055, 0.42, 0.055, -1.12, 5.18, p, "#475457", lighthouse);
}
// Small flag.
box(0.055, 1.0, 0.055, 0.55, 7.33, 0, "#46585a", lighthouse);
box(
0.64,
0.34,
0.045,
0.85,
7.61,
0,
"#e36a50",
lighthouse
);
// Low fort wall fragments.
box(5.5, 0.65, 0.45, -0.1, 0.38, -2.55, "#b8aa8e", lighthouse);
box(0.45, 0.65, 2.7, -2.65, 0.38, -1.25, "#b8aa8e", lighthouse);
box(0.45, 0.65, 2.0, 2.65, 0.38, -1.5, "#b8aa8e", lighthouse);
// ------------------------------------------------------------------
// Residential buildings
// ------------------------------------------------------------------
function addWindow(parent, x, y, z, width, height, side = "z") {
if (side === "z") {
box(width, height, 0.075, x, y, z, "#294750", parent);
box(width + 0.12, 0.08, 0.12, x, y - height / 2, z + 0.02, "#eee4cf", parent);
box(0.045, height, 0.085, x, y, z + 0.02, "#c5bba5", parent);
} else {
box(0.075, height, width, x, y, z, "#294750", parent);
box(0.12, 0.08, width + 0.12, x + 0.02, y - height / 2, z, "#eee4cf", parent);
box(0.085, height, 0.045, x + 0.02, y, z, "#c5bba5", parent);
}
}
function makeHouse(x, z, width, depth, height, wallColor, accentColor) {
const group = new THREE.Group();
group.position.set(x, GROUND, z);
scene.add(group);
box(width + 0.16, 0.2, depth + 0.16, 0, 0.1, 0, "#aaa18e", group);
box(width, height, depth, 0, height / 2 + 0.15, 0, wallColor, group);
// Flat roof with a shallow parapet.
box(width + 0.28, 0.18, depth + 0.28, 0, height + 0.22, 0, accentColor, group);
box(width + 0.2, 0.28, 0.14, 0, height + 0.41, depth / 2, accentColor, group);
box(width + 0.2, 0.28, 0.14, 0, height + 0.41, -depth / 2, accentColor, group);
box(0.14, 0.28, depth + 0.2, width / 2, height + 0.41, 0, accentColor, group);
box(0.14, 0.28, depth + 0.2, -width / 2, height + 0.41, 0, accentColor, group);
// Door and steps.
box(0.62, 1.28, 0.08, -0.55, 0.82, depth / 2 + 0.02, "#34545b", group);
box(0.76, 0.08, 0.16, -0.55, 0.23, depth / 2 + 0.08, "#ddd0b6", group);
box(0.9, 0.08, 0.38, -0.55, 0.1, depth / 2 + 0.26, "#b8ac96", group);
// Windows on the street-facing and seaward sides.
addWindow(group, 0.75, 1.55, depth / 2 + 0.03, 0.65, 0.8, "z");
addWindow(group, -width / 2 - 0.03, 1.55, -0.35, 0.65, 0.8, "x");
if (height > 3.25) {
addWindow(group, 0.62, height - 0.65, depth / 2 + 0.03, 0.68, 0.72, "z");
addWindow(group, -width / 2 - 0.03, height - 0.65, 0.55, 0.7, 0.72, "x");
}
// Small balcony.
box(1.25, 0.11, 0.62, 0.77, 1.08, depth / 2 + 0.27, "#d7c9ae", group);
for (let i = 0; i < 5; i++) {
box(
0.045,
0.34,
0.045,
0.25 + i * 0.25,
1.25,
depth / 2 + 0.53,
"#536365",
group
);
}
box(1.2, 0.05, 0.05, 0.75, 1.42, depth / 2 + 0.53, "#536365", group);
// Awning over the entrance.
const awning = box(
1.0,
0.08,
0.75,
-0.55,
1.68,
depth / 2 + 0.32,
accentColor,
group
);
awning.rotation.x = -0.13;
// Rooftop water tank.
box(0.75, 0.65, 0.72, width * 0.2, height + 0.66, -depth * 0.16, "#4c6568", group);
box(0.88, 0.1, 0.85, width * 0.2, height + 1.02, -depth * 0.16, "#384d50", group);
// Air-conditioning unit.
box(
0.45,
0.5,
0.3,
-width * 0.26,
height - 0.35,
depth / 2 + 0.17,
"#d2d0c2",
group
);
}
makeHouse(9.0, -9.5, 3.2, 3.0, 3.25, "#d56e5e", "#e8a266");
makeHouse(13.1, -9.6, 3.0, 3.1, 3.65, "#e3b257", "#f0d18a");
makeHouse(9.1, -4.3, 3.4, 3.2, 4.0, "#64a39f", "#8cc2b7");
makeHouse(13.2, -4.2, 3.1, 3.1, 2.85, "#7798b4", "#aac3d5");
makeHouse(9.1, 0.9, 3.4, 3.3, 3.5, "#e39e57", "#f0c47b");
makeHouse(13.1, 0.8, 3.0, 3.0, 4.05, "#b86f86", "#d69aaa");
makeHouse(9.1, 8.4, 3.4, 3.2, 3.25, "#719a70", "#99b784");
makeHouse(13.1, 8.4, 3.0, 3.0, 2.8, "#d47952", "#e6a178");
// A smaller shop linking the lighthouse path to the lane.
makeHouse(0.4, -9.2, 2.8, 2.6, 2.45, "#d5b35c", "#edd285");
makeHouse(1.7, -5.1, 2.7, 2.4, 2.25, "#6fa5a1", "#a5ccc2");
// Laundry line across a narrow side passage.
const laundryLine = line(
[[6.3, 2.75, -6.5], [8.2, 2.72, -6.5]],
"#42595d",
0.8
);
scene.add(laundryLine);
const laundryColors = ["#f2e9d7", "#d66c56", "#6a9ea6", "#e6bb58"];
for (let i = 0; i < 4; i++) {
box(
0.38,
0.58,
0.045,
6.58 + i * 0.42,
2.4,
-6.5,
laundryColors[i],
scene
);
}
// ------------------------------------------------------------------
// Palms and plants
// ------------------------------------------------------------------
function makePalm(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, GROUND, z);
group.scale.setScalar(scale);
scene.add(group);
for (let i = 0; i < 7; i++) {
box(
0.22,
0.54,
0.22,
i * 0.025,
0.25 + i * 0.48,
0,
i % 2 ? "#9b7049" : "#aa7d51",
group
);
}
for (let i = 0; i < 8; i++) {
const leaf = new THREE.Group();
leaf.rotation.y = (i / 8) * Math.PI * 2;
leaf.position.set(0, 3.65, 0);
group.add(leaf);
const blade = box(
0.36,
0.11,
1.75,
0,
0,
0.92,
i % 2 ? "#4f865b" : "#619a63",
leaf
);
blade.rotation.x = 0.11;
const tip = box(
0.22,
0.08,
1.0,
0,
-0.04,
2.15,
"#76a967",
leaf
);
tip.rotation.x = 0.17;
}
box(0.32, 0.3, 0.32, 0, 3.62, 0, "#6f7548", group);
}
makePalm(7.0, -11.1, 1.05);
makePalm(15.6, -6.3, 1.15);
makePalm(7.0, 5.0, 0.95);
makePalm(15.5, 4.5, 1.0);
makePalm(-0.2, -11.0, 0.9);
makePalm(12.0, 11.2, 1.1);
function planter(x, z, color) {
box(0.65, 0.42, 0.65, x, GROUND + 0.21, z, color);
box(0.52, 0.35, 0.52, x, GROUND + 0.56, z, "#5d8b58");
}
planter(6.7, -3.1, "#c76d53");
planter(6.7, 3.5, "#618f8b");
planter(-0.8, 3.8, "#d8ad58");
// ------------------------------------------------------------------
// Working waterfront: piers, market, crates, nets and people
// ------------------------------------------------------------------
function makePier(startX, endX, z, width = 2.0) {
for (let x = startX; x <= endX; x += 0.95) {
box(
0.92,
0.24,
width,
x,
0.49,
z,
choose(["#8d6846", "#98714d", "#7f6043"]),
scene
);
}
for (let x = startX; x <= endX; x += 1.9) {
for (const side of [-1, 1]) {
box(
0.18,
1.55,
0.18,
x,
-0.12,
z + side * width * 0.36,
"#5e4c39",
scene
);
}
}
}
makePier(-13, -5.1, 6.25, 2.15);
makePier(-10.5, -5.0, 2.65, 1.65);
// Mooring posts and ropes.
for (const x of [-12.7, -10.4, -8.1]) {
box(0.23, 0.9, 0.23, x, 0.92, 5.35, "#554a39");
}
scene.add(
line(
[[-12.7, 1.25, 5.35], [-11.2, 0.15, 4.9], [-9.6, 0.45, 4.4]],
"#d1c3a0",
0.9
)
);
// Market warehouse.
const warehouse = new THREE.Group();
warehouse.position.set(-1.8, GROUND, 8.3);
scene.add(warehouse);
box(4.0, 2.25, 2.8, 0, 1.13, 0, "#d9cfb5", warehouse);
box(4.35, 0.2, 3.1, 0, 2.36, 0, "#5e9694", warehouse);
for (let x = -1.8; x <= 1.8; x += 0.3) {
box(0.055, 0.18, 3.12, x, 2.35, 0, "#81b0a8", warehouse);
}
// Open west-facing market counter.
box(1.0, 1.15, 2.25, -2.1, 0.58, 0, "#668b86", warehouse);
box(0.8, 0.16, 2.4, -2.15, 1.2, 0, "#d9b56d", warehouse);
// Sign.
box(0.08, 0.65, 1.6, -2.17, 1.95, 0.3, "#e36d50", warehouse);
function makeStall(x, z, canopyA, canopyB) {
const group = new THREE.Group();
group.position.set(x, GROUND, z);
scene.add(group);
for (const dx of [-1.0, 1.0]) {
for (const dz of [-0.72, 0.72]) {
box(0.09, 2.0, 0.09, dx, 1.0, dz, "#6b563f", group);
}
}
box(2.15, 0.8, 1.35, 0, 0.4, 0, "#98764d", group);
box(2.25, 0.13, 1.48, 0, 0.87, 0, "#d4c8ab", group);
for (let i = 0; i < 6; i++) {
box(
0.37,
0.12,
1.72,
-0.92 + i * 0.37,
2.05,
0,
i % 2 ? canopyA : canopyB,
group
);
}
// Fish-like silver forms on the counter.
for (let i = 0; i < 5; i++) {
const fish = box(
0.38,
0.08,
0.13,
-0.72 + i * 0.35,
0.99,
(i % 2 ? -0.12 : 0.12),
"#b9d0c8",
group
);
fish.rotation.y = (i % 2 ? 1 : -1) * 0.4;
}
}
makeStall(-4.2, 3.1, "#e16e51", "#efe3c7");
makeStall(-1.1, 3.5, "#5f9c99", "#efe3c7");
makeStall(-3.4, 6.8, "#d9aa50", "#e8dcc1");
function makeCrate(x, z, size = 0.55, color = "#9c744b") {
box(size, size, size, x, GROUND + size / 2, z, color);
box(size + 0.03, 0.045, size + 0.03, x, GROUND + size * 0.68, z, "#c39a68");
}
makeCrate(-4.7, 5.0);
makeCrate(-4.0, 5.0, 0.45, "#b38a59");
makeCrate(-3.4, 4.7, 0.62, "#826345");
makeCrate(0.4, 6.4);
makeCrate(1.05, 6.2, 0.45, "#b5895d");
makeCrate(-6.4, 4.1, 0.5, "#92714e");
// Barrels.
for (const [x, z] of [[-5.5, 7.5], [-0.2, 7.0], [1.2, 4.8]]) {
box(0.55, 0.75, 0.55, x, GROUND + 0.38, z, "#587e78");
box(0.59, 0.07, 0.59, x, GROUND + 0.22, z, "#3d5f5d");
box(0.59, 0.07, 0.59, x, GROUND + 0.55, z, "#3d5f5d");
}
// Fishing net draped at the end of the smaller pier.
const netPoints = [];
for (let y = 0; y <= 1.45; y += 0.24) {
netPoints.push([-9.7, y + 0.05, 2.7], [-8.1, y - 0.02, 2.7]);
}
for (let x = -9.7; x <= -8.1; x += 0.26) {
netPoints.push([x, 0.05, 2.7], [x, 1.45, 2.7]);
}
scene.add(line(netPoints, "#d5c7a4", 0.72));
// ------------------------------------------------------------------
// Boats
// ------------------------------------------------------------------
const boats = [];
function makeBoat(x, z, scale, hullColor, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, -0.31, z);
group.rotation.y = rotation;
group.scale.setScalar(scale);
scene.add(group);
box(2.25, 0.42, 1.0, -0.15, 0, 0, hullColor, group);
box(0.7, 0.4, 0.72, 1.15, 0, 0, hullColor, group);
box(0.38, 0.36, 0.38, 1.58, 0, 0, hullColor, group);
box(2.25, 0.08, 0.86, -0.2, 0.25, 0, "#d2c59f", group);
box(0.72, 0.62, 0.72, -0.58, 0.54, 0, "#e6ddc6", group);
box(0.47, 0.26, 0.74, -0.58, 0.72, 0, "#496b73", group);
box(0.06, 1.8, 0.06, 0.35, 1.12, 0, "#61513d", group);
box(0.85, 0.055, 0.055, 0.05, 1.6, 0, "#61513d", group);
box(0.38, 0.25, 0.04, 0.37, 1.88, 0, "#e36b4f", group);
group.userData.baseY = -0.31;
group.userData.phase = random() * Math.PI * 2;
boats.push(group);
}
makeBoat(-11.5, 8.1, 1.1, "#c95b48", -0.15);
makeBoat(-8.7, 0.2, 0.82, "#497f89", 0.25);
makeBoat(-15.2, 3.8, 0.9, "#d19a47", 0.08);
makeBoat(-12.0, -5.3, 0.72, "#6b9b86", -0.3);
// Small distant breakwater.
for (let x = -19; x <= -11; x += 1) {
box(
0.95,
0.55 + random() * 0.18,
1.1,
x,
-0.04,
-10.7,
choose(["#858e88", "#92968c", "#7c8984"])
);
}
// ------------------------------------------------------------------
// People
// ------------------------------------------------------------------
function makePerson(x, z, shirt, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, GROUND, z);
group.rotation.y = rotation;
scene.add(group);
box(0.24, 0.48, 0.25, -0.11, 0.25, 0, "#344d52", group);
box(0.24, 0.48, 0.25, 0.11, 0.25, 0, "#344d52", group);
box(0.42, 0.53, 0.27, 0, 0.75, 0, shirt, group);
box(0.12, 0.44, 0.15, -0.29, 0.72, 0, shirt, group);
box(0.12, 0.44, 0.15, 0.29, 0.72, 0, shirt, group);
box(0.27, 0.28, 0.27, 0, 1.18, 0, "#8b5e42", group);
box(0.29, 0.09, 0.29, 0, 1.31, 0, "#40342e", group);
}
makePerson(-9.9, 6.0, "#df6c50", 0.4);
makePerson(-7.7, 2.5, "#d8bd58", -0.6);
makePerson(-4.8, 4.4, "#598f93", 0.2);
makePerson(-1.2, 4.1, "#e7dfc6", 0.8);
makePerson(1.4, 5.4, "#d66e52", -0.2);
makePerson(3.0, 6.0, "#6e9d79", 0.6);
makePerson(6.5, -2.4, "#d99d52", 1.2);
makePerson(11.5, -6.2, "#6b9ea0", -0.4);
// ------------------------------------------------------------------
// Clouds and birds
// ------------------------------------------------------------------
const clouds = [];
function makeCloud(x, y, z, scale) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
scene.add(group);
box(2.5, 0.55, 0.9, 0, 0, 0, "#f3f1df", group, false, false);
box(1.2, 0.85, 0.8, -0.8, 0.18, 0, "#f3f1df", group, false, false);
box(1.6, 0.7, 0.8, 0.8, 0.1, 0, "#e8eee4", group, false, false);
group.userData.startX = x;
clouds.push(group);
}
makeCloud(-15, 9.5, -15, 1.1);
makeCloud(8, 11.5, -21, 0.8);
makeCloud(-24, 7.5, 5, 0.7);
const birdGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-0.22, 0, 0),
new THREE.Vector3(0, 0.12, 0),
new THREE.Vector3(0.22, 0, 0)
]);
const birds = [];
for (let i = 0; i < 6; i++) {
const bird = new THREE.Line(
birdGeometry,
new THREE.LineBasicMaterial({ color: "#47666a" })
);
bird.position.set(-12 + i * 2.4, 6.2 + (i % 2) * 0.6, -12 + i);
bird.userData.phase = i * 0.7;
scene.add(bird);
birds.push(bird);
}
// ------------------------------------------------------------------
// Custom camera controls: orbit, pan, wheel zoom and touch pinch
// ------------------------------------------------------------------
const controls = {
theta: -0.73,
phi: 0.82,
zoom: 1,
target: new THREE.Vector3(1, 0.3, 0),
radius: 48
};
const goal = {
theta: controls.theta,
phi: controls.phi,
zoom: controls.zoom,
target: controls.target.clone()
};
let transitioning = false;
const pointers = new Map();
function updateCamera() {
const horizontal = Math.sin(controls.phi) * controls.radius;
camera.position.set(
controls.target.x + horizontal * Math.sin(controls.theta),
controls.target.y + Math.cos(controls.phi) * controls.radius,
controls.target.z + horizontal * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
camera.zoom = controls.zoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(30, 39 / aspect);
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, 2));
}
window.addEventListener("resize", resize);
resize();
const canvas = renderer.domElement;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
button: event.button
});
transitioning = false;
});
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;
previous.x = event.clientX;
previous.y = event.clientY;
if (pointers.size === 1) {
if (event.shiftKey || previous.button === 2) {
const right = new THREE.Vector3();
const forward = new THREE.Vector3();
camera.matrixWorld.extractBasis(right, new THREE.Vector3(), forward);
right.y = 0;
forward.y = 0;
right.normalize();
forward.normalize();
const panScale = 0.018 / controls.zoom;
controls.target.addScaledVector(right, -dx * panScale);
controls.target.addScaledVector(forward, dy * panScale);
} else {
controls.theta -= dx * 0.0055;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.0045,
0.42,
1.28
);
}
} else if (pointers.size === 2) {
const points = [...pointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (canvas.userData.pinchDistance) {
const scale = canvas.userData.pinchDistance / distance;
controls.zoom = THREE.MathUtils.clamp(
controls.zoom * scale,
0.65,
3.6
);
}
canvas.userData.pinchDistance = distance;
}
goal.theta = controls.theta;
goal.phi = controls.phi;
goal.zoom = controls.zoom;
goal.target.copy(controls.target);
});
function removePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) canvas.userData.pinchDistance = 0;
}
canvas.addEventListener("pointerup", removePointer);
canvas.addEventListener("pointercancel", removePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
transitioning = false;
controls.zoom = THREE.MathUtils.clamp(
controls.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
3.6
);
goal.zoom = controls.zoom;
},
{ passive: false }
);
const views = {
all: {
theta: -0.73,
phi: 0.82,
zoom: 1,
target: new THREE.Vector3(1, 0.3, 0)
},
lighthouse: {
theta: -0.82,
phi: 0.78,
zoom: 2.15,
target: new THREE.Vector3(-3, 1.3, -8)
},
lane: {
theta: -0.65,
phi: 0.9,
zoom: 1.95,
target: new THREE.Vector3(7.5, 1.2, -0.8)
},
quay: {
theta: -0.95,
phi: 0.84,
zoom: 2.05,
target: new THREE.Vector3(-7.5, 0.5, 5.1)
}
};
function selectView(name) {
const view = views[name];
goal.theta = view.theta;
goal.phi = view.phi;
goal.zoom = view.zoom;
goal.target.copy(view.target);
transitioning = true;
document.querySelectorAll("[data-view]").forEach((button) => {
button.classList.toggle("active", button.dataset.view === name);
});
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => selectView(button.dataset.view));
});
canvas.addEventListener("dblclick", () => selectView("all"));
// ------------------------------------------------------------------
// Screen-space labels
// ------------------------------------------------------------------
const labelElements = [...document.querySelectorAll(".scene-label")];
const labelAnchors = labelElements.map((element) => {
const values = element.dataset.anchor.split(",").map(Number);
return {
element,
position: new THREE.Vector3(...values)
};
});
function updateLabels() {
for (const item of labelAnchors) {
const projected = item.position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
if (!visible) {
item.element.style.opacity = "0";
continue;
}
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
item.element.style.opacity = "1";
item.element.style.transform =
`translate(${x}px, ${y}px) translate(-2px, -50%)`;
}
}
// ------------------------------------------------------------------
// Animation
// ------------------------------------------------------------------
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
if (transitioning) {
const easing = 1 - Math.exp(-delta * 4.2);
controls.theta = THREE.MathUtils.lerp(controls.theta, goal.theta, easing);
controls.phi = THREE.MathUtils.lerp(controls.phi, goal.phi, easing);
controls.zoom = THREE.MathUtils.lerp(controls.zoom, goal.zoom, easing);
controls.target.lerp(goal.target, easing);
if (
Math.abs(controls.theta - goal.theta) < 0.001 &&
Math.abs(controls.phi - goal.phi) < 0.001 &&
Math.abs(controls.zoom - goal.zoom) < 0.001 &&
controls.target.distanceTo(goal.target) < 0.01
) {
transitioning = false;
}
}
updateCamera();
// Animated water tiles.
rippleData.forEach((ripple, index) => {
rippleDummy.position.set(
ripple.x,
-0.345 + Math.sin(elapsed * 1.3 + ripple.phase) * 0.025,
ripple.z
);
rippleDummy.scale.set(ripple.length, 0.028, ripple.width);
rippleDummy.rotation.y = Math.sin(elapsed * 0.22 + ripple.phase) * 0.08;
rippleDummy.updateMatrix();
ripples.setMatrixAt(index, rippleDummy.matrix);
});
ripples.instanceMatrix.needsUpdate = true;
// Boat bob and roll.
boats.forEach((boat) => {
boat.position.y =
boat.userData.baseY + Math.sin(elapsed * 1.45 + boat.userData.phase) * 0.045;
boat.rotation.z =
Math.sin(elapsed * 0.85 + boat.userData.phase) * 0.025;
});
clouds.forEach((cloud, index) => {
cloud.position.x =
cloud.userData.startX + Math.sin(elapsed * 0.035 + index) * 2.2;
});
birds.forEach((bird, index) => {
bird.position.x += delta * (0.28 + index * 0.018);
bird.position.y += Math.sin(elapsed * 2 + bird.userData.phase) * delta * 0.13;
bird.rotation.z = Math.sin(elapsed * 3 + bird.userData.phase) * 0.12;
});
updateLabels();
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
loading.style.opacity = "0";
setTimeout(() => loading.remove(), 520);
});
</script>
</body>
</html>
```