Prompt specification
Build or customize the Three.js 3D scene "Coastal lane between harbor and homes" 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: Coastal lane between harbor and homes
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/coastal-lane-between-harbor-and-homes-x2395
Scene Description Prompt:
A low-poly nineteenth-century Lamu street fragment connecting harbor, trading lane, and domestic courtyards through referenced Swahili architecture. Three.js from cdnjs, one HTML file.
Working Three.js Starter (coastal-lane-between-harbor-and-homes-x2395):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Lamu — Harbor to Courtyard</title>
<style>
:root {
--ink: #f4ead6;
--muted: #c5b79d;
--glass: rgba(28, 24, 18, 0.78);
--line: rgba(244, 234, 214, 0.2);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9c2bd;
font-family: Georgia, "Times New Roman", serif;
}
canvas {
display: block;
touch-action: none;
outline: none;
}
#title {
position: fixed;
top: 24px;
left: 26px;
z-index: 3;
color: var(--ink);
text-shadow: 0 2px 12px rgba(0,0,0,.55);
pointer-events: none;
}
#title small {
display: block;
margin-bottom: 4px;
font: 600 10px/1.2 Arial, sans-serif;
letter-spacing: .25em;
text-transform: uppercase;
color: #e4c996;
}
#title h1 {
margin: 0;
font-size: clamp(24px, 4vw, 46px);
font-weight: 400;
letter-spacing: .04em;
}
#title p {
margin: 8px 0 0;
max-width: 430px;
color: var(--muted);
font: 12px/1.6 Arial, sans-serif;
}
#panel {
position: fixed;
right: 20px;
bottom: 20px;
z-index: 4;
width: min(330px, calc(100vw - 40px));
padding: 14px;
border: 1px solid var(--line);
border-radius: 4px;
background: var(--glass);
backdrop-filter: blur(10px);
color: var(--ink);
}
#views {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
}
button {
border: 1px solid var(--line);
border-radius: 3px;
padding: 9px 5px;
background: rgba(255,255,255,.04);
color: var(--ink);
cursor: pointer;
font: 10px/1 Arial, sans-serif;
letter-spacing: .12em;
text-transform: uppercase;
transition: background .2s, border-color .2s;
}
button:hover,
button.active {
background: rgba(225, 190, 128, .18);
border-color: #d4b477;
}
#hint {
margin: 11px 0 0;
color: var(--muted);
font: 10px/1.5 Arial, sans-serif;
}
#legend {
display: flex;
flex-wrap: wrap;
gap: 8px 14px;
margin-top: 10px;
padding-top: 10px;
border-top: 1px solid var(--line);
color: var(--muted);
font: 9px/1.4 Arial, sans-serif;
letter-spacing: .07em;
text-transform: uppercase;
}
#legend span::before {
content: "";
display: inline-block;
width: 6px;
height: 6px;
margin-right: 6px;
border-radius: 50%;
background: #dfb973;
}
#legend span:nth-child(2)::before { background: #b66f4e; }
#legend span:nth-child(3)::before { background: #668a72; }
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #25251f;
color: #e5c48d;
font: 11px/1 Arial, sans-serif;
letter-spacing: .25em;
text-transform: uppercase;
transition: opacity .6s;
}
#loading.done {
opacity: 0;
pointer-events: none;
}
@media (max-width: 640px) {
#title { top: 16px; left: 16px; }
#title p { display: none; }
#panel { right: 12px; bottom: 12px; width: calc(100vw - 24px); }
}
</style>
</head>
<body>
<div id="loading">Building the street fragment…</div>
<header id="title">
<small>Swahili coast · c. 1880</small>
<h1>Lamu: Harbor to Courtyard</h1>
<p>Coral-rag masonry, carved doors, screened windows, roof terraces, market awnings and lateen-rigged dhows.</p>
</header>
<aside id="panel">
<nav id="views">
<button class="active" data-view="overview">Overview</button>
<button data-view="harbor">Harbor</button>
<button data-view="lane">Trading lane</button>
<button data-view="court">Courtyards</button>
</nav>
<p id="hint">Drag to orbit · wheel or pinch to zoom · 1–4 for views</p>
<div id="legend">
<span>Harbor</span>
<span>Trading lane</span>
<span>Domestic court</span>
</div>
</aside>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = selector => document.querySelector(selector);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb9c2bd);
scene.fog = new THREE.FogExp2(0xb9c2bd, 0.0125);
const camera = new THREE.PerspectiveCamera(43, innerWidth / innerHeight, 0.1, 180);
const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: "high-performance" });
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xdbe4e0, 0x79644b, 2.1);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffdfae, 3.7);
sun.position.set(-18, 30, 17);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -32;
sun.shadow.camera.right = 32;
sun.shadow.camera.top = 34;
sun.shadow.camera.bottom = -34;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 85;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xa9c8d3, 0.65);
fill.position.set(20, 12, -22);
scene.add(fill);
let seed = 1879;
function rand() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
const range = (a, b) => a + (b - a) * rand();
function canvasTexture(draw, width = 256, height = 256) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
draw(canvas.getContext("2d"), width, height);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
const stoneTexture = canvasTexture((ctx, w, h) => {
ctx.fillStyle = "#766f60";
ctx.fillRect(0, 0, w, h);
const rows = 8;
const rh = h / rows;
const palette = ["#c9b998", "#bcae8d", "#d2c09a", "#b6a88c", "#c4b291", "#a9997e"];
for (let row = 0; row < rows; row++) {
let x = -range(0, 35);
while (x < w) {
const bw = range(27, 55);
ctx.fillStyle = palette[Math.floor(rand() * palette.length)];
ctx.fillRect(x + 2, row * rh + 2, bw - 4, rh - 4);
ctx.fillStyle = "rgba(255,255,255,.08)";
ctx.fillRect(x + 3, row * rh + 3, bw - 6, 2);
ctx.fillStyle = "rgba(58,48,38,.13)";
ctx.fillRect(x + 3, row * rh + rh - 5, bw - 6, 2);
x += bw;
}
}
for (let i = 0; i < 900; i++) {
ctx.fillStyle = rand() > 0.5 ? "rgba(255,255,255,.08)" : "rgba(40,35,28,.08)";
ctx.fillRect(rand() * w, rand() * h, 1.5, 1.5);
}
}, 512, 512);
stoneTexture.repeat.set(2.4, 2.2);
const stripeTexture = canvasTexture((ctx, w, h) => {
const colors = ["#b66f4e", "#e3d3ae", "#667b69", "#d5b467"];
const stripe = w / 8;
for (let i = 0; i < 8; i++) {
ctx.fillStyle = colors[i % colors.length];
ctx.fillRect(i * stripe, 0, stripe, h);
}
ctx.fillStyle = "rgba(70,45,30,.1)";
for (let i = 0; i < 600; i++) {
ctx.fillRect(rand() * w, rand() * h, 2, 1);
}
}, 256, 128);
const coral = new THREE.MeshStandardMaterial({
map: stoneTexture, roughness: 0.96, color: 0xf0dfb9
});
const coralDark = new THREE.MeshStandardMaterial({
map: stoneTexture, roughness: 1, color: 0xc2ae8a
});
const plaster = new THREE.MeshStandardMaterial({ color: 0xd6c39d, roughness: 1 });
const paleStone = new THREE.MeshStandardMaterial({ color: 0xb9aa8c, roughness: 1 });
const wood = new THREE.MeshStandardMaterial({ color: 0x5b3320, roughness: 0.88 });
const darkWood = new THREE.MeshStandardMaterial({ color: 0x2f1b12, roughness: 0.9 });
const brass = new THREE.MeshStandardMaterial({ color: 0xb28b3f, roughness: 0.38, metalness: 0.7 });
const ropeMat = new THREE.MeshStandardMaterial({ color: 0x9c8051, roughness: 1 });
const cloth = new THREE.MeshStandardMaterial({ map: stripeTexture, roughness: 1, side: THREE.DoubleSide });
const leaf = new THREE.MeshStandardMaterial({ color: 0x496c49, roughness: 1, flatShading: true });
const leafLight = new THREE.MeshStandardMaterial({ color: 0x718b55, roughness: 1, flatShading: true });
const soil = new THREE.MeshStandardMaterial({ color: 0x5b4936, roughness: 1 });
const ceramic = new THREE.MeshStandardMaterial({ color: 0x9c5639, roughness: 0.86 });
const ceramicDark = new THREE.MeshStandardMaterial({ color: 0x604334, roughness: 0.9 });
const lanternMat = new THREE.MeshStandardMaterial({
color: 0xf0b55e, emissive: 0xd77721, emissiveIntensity: 0.7, roughness: 0.8
});
function mesh(geometry, material, parent = scene) {
const m = new THREE.Mesh(geometry, material);
m.castShadow = true;
m.receiveShadow = true;
parent.add(m);
return m;
}
function box(w, h, d, material, x = 0, y = 0, z = 0, parent = scene) {
const m = mesh(new THREE.BoxGeometry(w, h, d), material, parent);
m.position.set(x, y, z);
return m;
}
function cylinderBetween(a, b, radius, material, parent = scene, segments = 6) {
const av = new THREE.Vector3(...a);
const bv = new THREE.Vector3(...b);
const direction = bv.clone().sub(av);
const m = mesh(
new THREE.CylinderGeometry(radius, radius, direction.length(), segments),
material,
parent
);
m.position.copy(av).add(bv).multiplyScalar(0.5);
m.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return m;
}
function addPot(x, y, z, scale = 1, material = ceramic, parent = scene) {
const points = [
new THREE.Vector2(0.12, 0),
new THREE.Vector2(0.31, 0.1),
new THREE.Vector2(0.42, 0.36),
new THREE.Vector2(0.36, 0.62),
new THREE.Vector2(0.22, 0.75),
new THREE.Vector2(0.27, 0.82)
];
const pot = mesh(new THREE.LatheGeometry(points, 10), material, parent);
pot.position.set(x, y, z);
pot.scale.setScalar(scale);
return pot;
}
function addBasket(x, y, z, scale = 1, parent = scene) {
const basket = mesh(
new THREE.CylinderGeometry(0.38, 0.28, 0.5, 9),
new THREE.MeshStandardMaterial({ color: 0x9a7545, roughness: 1 }),
parent
);
basket.position.set(x, y + 0.25, z);
basket.scale.setScalar(scale);
return basket;
}
function addArchDoor(parent, x, height = 2.35, width = 1.28) {
const g = new THREE.Group();
g.position.x = x;
parent.add(g);
const shape = new THREE.Shape();
const r = width / 2;
const spring = height - r;
shape.moveTo(-r, 0);
shape.lineTo(r, 0);
shape.lineTo(r, spring);
shape.absarc(0, spring, r, 0, Math.PI, false);
shape.lineTo(-r, 0);
const door = mesh(
new THREE.ExtrudeGeometry(shape, { depth: 0.12, bevelEnabled: false }),
darkWood,
g
);
door.position.z = 0.2;
const frame = mesh(
new THREE.TorusGeometry(r + 0.055, 0.075, 5, 14, Math.PI),
wood,
g
);
frame.position.set(0, spring, 0.27);
box(0.12, spring, 0.14, wood, -r - 0.04, spring / 2, 0.27, g);
box(0.12, spring, 0.14, wood, r + 0.04, spring / 2, 0.27, g);
for (const yy of [0.52, 1.25]) {
box(width - 0.28, 0.045, 0.035, brass, 0, yy, 0.34, g);
}
for (const yy of [0.22, 0.46, 0.72, 1.02, 1.35, 1.66]) {
for (const xx of [-0.35, 0.35]) {
const stud = mesh(new THREE.CylinderGeometry(0.035, 0.035, 0.035, 7), brass, g);
stud.rotation.x = Math.PI / 2;
stud.position.set(xx, yy, 0.36);
}
}
const handle = mesh(new THREE.TorusGeometry(0.11, 0.018, 5, 12), brass, g);
handle.position.set(width * 0.28, 0.88, 0.38);
return g;
}
function addWindow(parent, x, y, width = 0.72, height = 0.9, screened = false) {
box(width, height, 0.055, darkWood, x, y, 0.205, parent);
box(width + 0.16, 0.08, 0.16, paleStone, x, y + height / 2 + 0.04, 0.25, parent);
box(0.07, height + 0.12, 0.13, paleStone, x - width / 2 - 0.035, y, 0.25, parent);
box(0.07, height + 0.12, 0.13, paleStone, x + width / 2 + 0.035, y, 0.25, parent);
if (screened) {
for (let i = 1; i < 4; i++) {
box(0.035, height, 0.06, wood, x - width / 2 + width * i / 4, y, 0.25, parent);
}
for (let i = 1; i < 4; i++) {
box(width, 0.035, 0.06, wood, x, y - height / 2 + height * i / 4, 0.25, parent);
}
box(width + 0.42, 0.12, 0.65, wood, x, y + height / 2 + 0.18, 0.38, parent);
}
}
function addBaoBench(parent, x, z = 0.25) {
const seat = box(1.65, 0.13, 0.48, wood, x, 0.5, z, parent);
seat.rotation.x = -0.035;
box(0.18, 0.48, 0.42, darkWood, x - 0.62, 0.25, z, parent);
box(0.18, 0.48, 0.42, darkWood, x + 0.62, 0.25, z, parent);
for (const dx of [-0.42, 0, 0.42]) {
box(0.06, 0.45, 0.5, wood, x + dx, 0.5, z + 0.24, parent);
}
}
function addFacade(group, length, height, options = {}) {
box(length, height, 0.36, coral, 0, height / 2, 0, group);
box(length + 0.1, 0.32, 0.52, paleStone, 0, 0.16, 0.03, group);
box(length + 0.08, 0.18, 0.48, coralDark, 0, height - 0.08, 0.02, group);
const doorX = options.doorX ?? range(-length * 0.22, length * 0.22);
addArchDoor(group, doorX, options.doorHeight ?? 2.35, options.doorWidth ?? 1.28);
const lowerWindowX = doorX < 0 ? -length * 0.32 : length * 0.32;
addWindow(group, lowerWindowX, 1.65, 0.62, 0.86, false);
const upperXs = [-length * 0.28, length * 0.27];
upperXs.forEach((x, i) => {
addWindow(group, x, height - 1.35, 0.78, 0.92, i === 0);
});
addBaoBench(group, doorX + (doorX > 0 ? -1.42 : 1.42));
if (options.lantern) {
cylinderBetween([doorX + 0.9, height - 0.3, 0.35], [doorX + 0.9, height - 0.95, 0.35], 0.035, wood, group);
const lamp = mesh(new THREE.CylinderGeometry(0.12, 0.16, 0.3, 6), lanternMat, group);
lamp.position.set(doorX + 0.9, height - 1.08, 0.35);
}
}
function addBuilding(side, z, length, height, depth, options = {}) {
const facadeX = side * 4.05;
box(
depth, height, Math.max(0.6, length - 0.25), coral,
side * (4.05 + depth / 2), height / 2, z
);
const facade = new THREE.Group();
facade.position.set(facadeX, 0.04, z);
facade.rotation.y = side > 0 ? -Math.PI / 2 : Math.PI / 2;
scene.add(facade);
addFacade(facade, length, height, options);
const roofY = height + 0.2;
box(depth + 0.35, 0.28, length + 0.25, paleStone,
side * (4.05 + depth / 2), roofY, z);
box(0.22, 0.7, length + 0.25, coralDark,
side * 4.0, height + 0.53, z);
box(0.22, 0.58, length + 0.1, coralDark,
side * (4.05 + depth), height + 0.43, z);
for (const zz of [z - length / 2, z + length / 2]) {
box(depth + 0.25, 0.55, 0.2, coralDark,
side * (4.05 + depth / 2), height + 0.4, zz);
}
if (options.roofTank) {
const tank = mesh(new THREE.CylinderGeometry(0.42, 0.42, 0.72, 10), paleStone);
tank.position.set(side * (4.5 + depth * 0.55), height + 0.73, z + length * 0.22);
const rim = mesh(new THREE.TorusGeometry(0.42, 0.035, 5, 12), coralDark);
rim.rotation.x = Math.PI / 2;
rim.position.set(tank.position.x, height + 1.1, tank.position.z);
}
}
function addTree(x, z, scale = 1) {
const g = new THREE.Group();
g.position.set(x, 0, z);
g.scale.setScalar(scale);
scene.add(g);
cylinderBetween([0, 0, 0], [0.12, 2.4, 0.05], 0.17, wood, g, 7);
cylinderBetween([0.1, 1.35, 0], [-0.55, 2.25, 0.18], 0.08, wood, g, 6);
cylinderBetween([0.1, 1.8, 0], [0.72, 2.5, -0.12], 0.08, wood, g, 6);
const blobs = [
[0.1, 2.8, 0, 1.25],
[-0.65, 2.55, 0.18, 0.85],
[0.8, 2.7, -0.12, 0.88],
[0.05, 3.5, 0.03, 0.85]
];
blobs.forEach((b, i) => {
const crown = mesh(
new THREE.DodecahedronGeometry(b[3], 0),
i % 2 ? leafLight : leaf,
g
);
crown.position.set(b[0], b[1], b[2]);
crown.scale.set(1.15, 0.86, 1.04);
});
box(1.45, 0.08, 1.45, soil, 0, 0.04, 0, g);
}
function addPlant(x, z, scale = 1) {
addPot(x, 0, z, scale, ceramic);
for (let i = 0; i < 7; i++) {
const angle = i / 7 * Math.PI * 2;
const leafMesh = mesh(new THREE.ConeGeometry(0.12, 0.9, 4), i % 2 ? leaf : leafLight);
leafMesh.position.set(
x + Math.cos(angle) * 0.12,
0.95 * scale,
z + Math.sin(angle) * 0.12
);
leafMesh.rotation.z = Math.cos(angle) * 0.48;
leafMesh.rotation.x = Math.sin(angle) * 0.48;
leafMesh.scale.setScalar(scale);
}
}
function addPalm(x, z, scale = 1) {
const g = new THREE.Group();
g.position.set(x, 0, z);
g.scale.setScalar(scale);
scene.add(g);
for (let i = 0; i < 6; i++) {
const y0 = i * 0.62;
const bend = Math.pow(i / 6, 2) * 0.6;
cylinderBetween(
[bend * 0.25, y0, 0],
[bend * 0.4, y0 + 0.63, 0],
0.14 - i * 0.008,
wood,
g,
7
);
}
const crownY = 3.8;
for (let i = 0; i < 8; i++) {
const a = i / 8 * Math.PI * 2;
const len = 1.7;
const end = [Math.cos(a) * len, crownY - 0.38, Math.sin(a) * len];
cylinderBetween([0.32, crownY, 0], end, 0.045, leaf, g, 5);
const v = new THREE.Vector3(...end);
const p0 = new THREE.Vector3(0.32, crownY, 0);
const mid = p0.clone().lerp(v, 0.55);
mid.y -= 0.28;
const geo = new THREE.BufferGeometry();
geo.setAttribute("position", new THREE.Float32BufferAttribute([
p0.x, p0.y, p0.z,
mid.x, mid.y, mid.z,
v.x, v.y, v.z
], 3));
geo.computeVertexNormals();
const frond = mesh(geo, i % 2 ? leaf : leafLight, g);
frond.material.side = THREE.DoubleSide;
}
}
function addCourtyard(side, z) {
const facadeX = side * 4.05;
const courtCenterX = side * 7.25;
const length = 9.2;
const gate = new THREE.Group();
gate.position.set(facadeX, 0.03, z);
gate.rotation.y = side > 0 ? -Math.PI / 2 : Math.PI / 2;
scene.add(gate);
const opening = 2.65;
const wallHeight = 3.6;
const segment = (length - opening) / 2;
box(segment, wallHeight, 0.38, coral, -(opening + segment) / 2, wallHeight / 2, 0, gate);
box(segment, wallHeight, 0.38, coral, (opening + segment) / 2, wallHeight / 2, 0, gate);
box(opening, wallHeight - 1.3, 0.38, coral, 0, 1.3 + (wallHeight - 1.3) / 2, 0, gate);
const arch = mesh(
new THREE.TorusGeometry(opening / 2, 0.14, 5, 18, Math.PI),
paleStone,
gate
);
arch.position.set(0, 1.3, 0.24);
box(0.16, 1.3, 0.42, paleStone, -opening / 2, 0.65, 0.23, gate);
box(0.16, 1.3, 0.42, paleStone, opening / 2, 0.65, 0.23, gate);
box(7.1, 0.16, length, paleStone, courtCenterX, 0.02, z);
for (const zz of [z - length / 2, z + length / 2]) {
box(7, 2.9, 0.28, coral, courtCenterX, 1.45, zz);
}
box(0.3, 3.25, length, coral, side * 10.65, 1.62, z);
const rearX = side * 9.15;
box(2.25, 3.6, 5.6, coralDark, rearX, 1.8, z + 0.5);
box(2.5, 0.22, 5.9, paleStone, rearX, 3.7, z + 0.5);
box(0.2, 0.55, 5.9, coral, rearX + side * 1.05, 3.96, z + 0.5);
const rearDoor = box(0.08, 2.05, 1.15, darkWood, rearX - side * 1.15, 1.03, z - 0.9);
for (let i = 0; i < 4; i++) {
box(0.025, 1.85, 0.035, wood, rearX - side * 1.2, 1.03, z - 1.35 + i * 0.3);
}
addTree(side * 6.5, z - 1.1, 0.9);
addPot(side * 5.5, 0, z + 1.45, 1.1, ceramicDark);
addPlant(side * 8.4, z + 2.25, 0.8);
addPlant(side * 5.25, z - 2.65, 0.75);
// Timber pergola and climbing greenery.
for (const zz of [z + 1.4, z + 3.3]) {
cylinderBetween(
[side * 5.1, 0, zz],
[side * 5.1, 2.45, zz],
0.075,
wood
);
}
box(0.14, 0.14, 2.4, wood, side * 5.1, 2.43, z + 2.35);
for (let i = 0; i < 7; i++) {
const vine = mesh(new THREE.DodecahedronGeometry(0.24, 0), i % 2 ? leaf : leafLight);
vine.position.set(side * 5.1, 2.2 + range(-0.1, 0.18), z + 1.45 + i * 0.3);
}
// A line of laundry across the domestic court.
const laundryZ = z - 2.1;
cylinderBetween(
[side * 5.2, 2.8, laundryZ],
[side * 9.5, 2.8, laundryZ],
0.014,
ropeMat
);
const laundryColors = [0xd5c8aa, 0x9b5f46, 0x617663];
laundryColors.forEach((color, i) => {
const material = new THREE.MeshStandardMaterial({ color, roughness: 1, side: THREE.DoubleSide });
const clothPiece = mesh(new THREE.PlaneGeometry(0.65, 0.9), material);
clothPiece.position.set(side * (6.25 + i * 1.05), 2.3, laundryZ);
clothPiece.rotation.y = side > 0 ? Math.PI / 2 : -Math.PI / 2;
});
}
function addStall(side, z, rotation = 0) {
const x = side * 2.85;
const g = new THREE.Group();
g.position.set(x, 0, z);
g.rotation.y = rotation;
scene.add(g);
const canopy = box(2.35, 0.07, 3.0, cloth, 0, 2.65, 0, g);
canopy.rotation.z = side * 0.045;
for (const zz of [-1.25, 1.25]) {
cylinderBetween([side * 0.85, 0, zz], [side * 0.85, 2.55, zz], 0.045, wood, g);
cylinderBetween([-side * 0.95, 0, zz], [-side * 0.95, 2.55, zz], 0.045, wood, g);
}
box(1.55, 0.12, 2.35, wood, 0, 0.83, 0, g);
for (const zz of [-0.9, 0.9]) {
box(0.09, 0.8, 0.09, darkWood, -0.55, 0.4, zz, g);
box(0.09, 0.8, 0.09, darkWood, 0.55, 0.4, zz, g);
}
addBasket(0.45, 0.9, -0.55, 0.85, g);
addBasket(-0.45, 0.9, 0.48, 0.72, g);
for (let i = 0; i < 4; i++) {
const fruit = mesh(new THREE.DodecahedronGeometry(0.1, 0), i % 2 ? leafLight : ceramic);
fruit.position.set(range(-0.2, 0.2), 1.32, -0.55 + range(-0.2, 0.2));
fruit.scale.setScalar(range(0.75, 1.1));
}
const sack = mesh(new THREE.DodecahedronGeometry(0.42, 1), plaster, g);
sack.position.set(-0.85, 0.4, 1.05);
sack.scale.set(0.85, 1.2, 0.85);
const lamp = mesh(new THREE.CylinderGeometry(0.1, 0.14, 0.26, 6), lanternMat, g);
lamp.position.set(side * 0.55, 2.25, 1.22);
cylinderBetween([side * 0.55, 2.38, 1.22], [side * 0.55, 2.62, 1.22], 0.015, wood, g);
}
function addPerson(x, z, color = 0x765240, rotation = 0, scale = 1) {
const g = new THREE.Group();
g.position.set(x, 0, z);
g.rotation.y = rotation;
g.scale.setScalar(scale);
scene.add(g);
const garment = new THREE.MeshStandardMaterial({ color, roughness: 1 });
const skin = new THREE.MeshStandardMaterial({ color: 0x6f4935, roughness: 1 });
const body = mesh(new THREE.CylinderGeometry(0.18, 0.3, 0.75, 6), garment, g);
body.position.y = 1.04;
const head = mesh(new THREE.DodecahedronGeometry(0.19, 0), skin, g);
head.position.y = 1.58;
const wrap = mesh(new THREE.CylinderGeometry(0.205, 0.205, 0.13, 7), cloth, g);
wrap.position.y = 1.72;
cylinderBetween([-0.13, 0.76, 0], [-0.16, 0.16, 0.03], 0.075, skin, g, 5);
cylinderBetween([0.13, 0.76, 0], [0.16, 0.16, -0.02], 0.075, skin, g, 5);
cylinderBetween([-0.18, 1.35, 0], [-0.38, 0.92, 0.02], 0.065, garment, g, 5);
cylinderBetween([0.18, 1.35, 0], [0.39, 0.95, 0.08], 0.065, garment, g, 5);
box(0.22, 0.16, 0.38, darkWood, -0.15, 0.08, 0.05, g);
box(0.22, 0.16, 0.38, darkWood, 0.15, 0.08, 0.05, g);
}
function addDhow(x, z, rotation = 0, scale = 1) {
const g = new THREE.Group();
g.position.set(x, -0.62, z);
g.rotation.y = rotation;
g.scale.setScalar(scale);
scene.add(g);
const outline = new THREE.Shape();
outline.moveTo(0, 3.5);
outline.lineTo(1.05, 1.65);
outline.lineTo(1.12, -1.7);
outline.lineTo(0, -3.1);
outline.lineTo(-1.12, -1.7);
outline.lineTo(-1.05, 1.65);
outline.closePath();
const hull = mesh(
new THREE.ExtrudeGeometry(outline, {
depth: 0.72,
bevelEnabled: true,
bevelSize: 0.12,
bevelThickness: 0.08,
bevelSegments: 1,
steps: 1
}),
wood,
g
);
hull.rotation.x = -Math.PI / 2;
hull.position.y = -0.76;
const deck = mesh(new THREE.ShapeGeometry(outline), paleStone, g);
deck.rotation.x = -Math.PI / 2;
deck.position.y = 0.01;
const gunwale = mesh(
new THREE.ExtrudeGeometry(outline, {
depth: 0.08,
bevelEnabled: false
}),
darkWood,
g
);
gunwale.rotation.x = -Math.PI / 2;
gunwale.position.y = 0.06;
cylinderBetween([0, 0, 0.3], [0, 5.45, 0.3], 0.065, wood, g, 7);
const sailGeo = new THREE.BufferGeometry();
sailGeo.setAttribute("position", new THREE.Float32BufferAttribute([
0.15, 1.0, 0.2,
0.15, 5.55, 0.2,
-2.45, 1.15, 0.2
], 3));
sailGeo.computeVertexNormals();
const sailMat = new THREE.MeshStandardMaterial({
color: 0xd7c5a0,
roughness: 1,
side: THREE.DoubleSide
});
const sail = mesh(sailGeo, sailMat, g);
const yard = cylinderBetween([0.15, 5.55, 0.2], [-2.45, 1.15, 0.2], 0.045, wood, g, 6);
const ropeMaterial = new THREE.LineBasicMaterial({ color: 0x78664a });
const ropePoints = [
new THREE.Vector3(0, 5.45, 0.3), new THREE.Vector3(0, 0.1, 3.0)
];
const ropeGeo = new THREE.BufferGeometry().setFromPoints(ropePoints);
g.add(new THREE.Line(ropeGeo, ropeMaterial));
const ropePoints2 = [
new THREE.Vector3(0, 5.45, 0.3), new THREE.Vector3(0, 0.1, -2.8)
];
const ropeGeo2 = new THREE.BufferGeometry().setFromPoints(ropePoints2);
g.add(new THREE.Line(ropeGeo2, ropeMaterial));
box(1.3, 0.16, 0.8, cloth, 0, 0.15, -1.2, g);
box(0.65, 0.3, 0.55, ceramic, 0.45, 0.22, -0.8, g);
}
// Terrain and street.
box(22, 0.22, 35, paleStone, 0, -0.11, -5.5);
box(8.1, 0.2, 34, coralDark, 0, -0.05, -5.2);
box(24, 1.2, 7.2, coralDark, 0, -0.6, 12.1);
box(25, 0.2, 0.8, paleStone, 0, 0.05, 8.5);
// Irregular paving strips.
for (let z = -21; z < 9; z += 1.25) {
const seam = box(8.02, 0.012, 0.035, soil, 0, 0.058, z);
seam.material = new THREE.MeshBasicMaterial({ color: 0x8c806c });
}
addBuilding(-1, 5.1, 9.0, 6.6, 4.7, {
doorX: -1.7, lantern: true, roofTank: true
});
addBuilding(1, 6.3, 9.6, 7.4, 4.6, {
doorX: 1.6, lantern: true, roofTank: true
});
addBuilding(-1, -4.1, 8.8, 5.8, 4.3, {
doorX: 1.5, lantern: true
});
addBuilding(1, -3.8, 8.8, 6.2, 4.6, {
doorX: -1.3, lantern: true, roofTank: true
});
addCourtyard(-1, -15.0);
addCourtyard(1, -14.5);
addStall(-1, 3.4, -0.12);
addStall(1, 1.0, 0.08);
addStall(-1, -1.4, 0.05);
addStall(1, -6.2, -0.08);
// Small shop sign.
function makeSign(text) {
const texture = canvasTexture((ctx, w, h) => {
ctx.fillStyle = "#3e2719";
ctx.fillRect(0, 0, w, h);
ctx.strokeStyle = "#b28b3f";
ctx.lineWidth = 7;
ctx.strokeRect(8, 8, w - 16, h - 16);
ctx.fillStyle = "#e6d0a4";
ctx.font = "bold 34px Georgia";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, w / 2, h / 2);
}, 256, 96);
const material = new THREE.MeshStandardMaterial({ map: texture, roughness: 0.9 });
const sign = mesh(new THREE.PlaneGeometry(1.65, 0.62), material);
sign.position.set(3.78, 3.65, 2.6);
sign.rotation.y = -Math.PI / 2;
box(0.09, 0.78, 0.09, wood, 3.8, 3.65, 2.25);
box(0.09, 0.78, 0.09, wood, 3.8, 3.65, 2.95);
}
makeSign("SADA");
// A few jars and baskets along the trading lane.
for (let i = 0; i < 7; i++) {
const side = i % 2 ? 1 : -1;
addPot(side * range(3.1, 3.55), 0, range(-6.5, 6.5), range(0.55, 1.05), i % 3 ? ceramic : ceramicDark);
}
for (let i = 0; i < 5; i++) {
addBasket((i % 2 ? 1 : -1) * 3.15, 0, range(-7, 7), range(0.7, 1.1));
}
// Palm trees at the quay.
addPalm(-8.7, 11.0, 1.05);
addPalm(8.8, 10.2, 0.95);
addPalm(-11.0, 8.0, 0.8);
// Bollards and dock.
for (let x = -10; x <= 10; x += 4) {
const bollard = mesh(new THREE.CylinderGeometry(0.16, 0.21, 0.68, 8), darkWood);
bollard.position.set(x, 0.34, 15.15);
}
box(2.7, 0.3, 8, wood, 6.1, 0.06, 18.1);
for (let z = 15; z < 22; z += 1.4) {
box(2.6, 0.08, 0.13, darkWood, 6.1, 0.23, z);
}
for (const x of [5.05, 7.15]) {
for (let z = 15.5; z < 21.5; z += 2.5) {
cylinderBetween([x, -0.7, z], [x, 0.18, z], 0.09, wood);
}
}
// Ocean.
const waterGeometry = new THREE.PlaneGeometry(120, 120, 36, 36);
waterGeometry.rotateX(-Math.PI / 2);
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x477b7d,
roughness: 0.48,
metalness: 0.08,
flatShading: true
});
const water = mesh(waterGeometry, waterMaterial);
water.position.y = -1.05;
water.castShadow = false;
addDhow(4.3, 20.8, -0.32, 0.9);
addDhow(-4.8, 19.8, 0.38, 0.78);
addDhow(10.5, 23.8, -0.65, 0.68);
addDhow(-11.0, 25.0, 0.22, 0.62);
// People.
addPerson(-1.4, 5.0, 0x7d4935, 0.4, 1.02);
addPerson(1.5, 2.4, 0x53665b, -0.8, 0.96);
addPerson(-2.2, -2.2, 0x9b7147, 1.4, 0.92);
addPerson(2.3, -6.0, 0x704552, -0.4, 0.94);
addPerson(-3.2, 10.2, 0x66756c, 1.1, 1.04);
addPerson(2.4, 11.4, 0x9a5d3d, -0.7, 0.98);
addPerson(5.0, 14.3, 0x746451, 0.3, 0.95);
// Bales, crates and coils near the harbor.
for (let i = 0; i < 6; i++) {
const x = -7 + (i % 3) * 1.4;
const z = 9.3 + Math.floor(i / 3) * 1.2;
const bale = mesh(new THREE.DodecahedronGeometry(0.55, 0), i % 2 ? cloth : plaster);
bale.position.set(x, 0.46, z);
bale.scale.set(1.2, 0.7, 0.9);
}
for (let i = 0; i < 4; i++) {
const x = 7.2 + (i % 2) * 1.1;
const z = 9.2 + Math.floor(i / 2) * 1.1;
box(0.9, 0.65, 0.8, wood, x, 0.33, z);
box(0.96, 0.08, 0.08, darkWood, x, 0.48, z + 0.42);
}
// Custom camera controls.
const target = new THREE.Vector3(0, 2.2, -3.8);
const desiredTarget = target.clone();
const spherical = new THREE.Spherical(36, 1.02, 0.46);
const desiredSpherical = spherical.clone();
function updateCameraFromSpherical() {
const offset = new THREE.Vector3().setFromSpherical(spherical);
camera.position.copy(target).add(offset);
camera.lookAt(target);
}
updateCameraFromSpherical();
const pointers = new Map();
let lastX = 0, lastY = 0, pinchDistance = 0;
let transitioning = true;
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
lastX = event.clientX;
lastY = event.clientY;
transitioning = false;
if (pointers.size === 2) {
const p = [...pointers.values()];
pinchDistance = Math.hypot(p[0].x - p[1].x, p[0].y - p[1].y);
}
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
const p = [...pointers.values()];
const distance = Math.hypot(p[0].x - p[1].x, p[0].y - p[1].y);
if (pinchDistance > 0) {
desiredSpherical.radius *= pinchDistance / Math.max(1, distance);
desiredSpherical.radius = THREE.MathUtils.clamp(desiredSpherical.radius, 4.5, 68);
}
pinchDistance = distance;
} else {
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
desiredSpherical.theta -= dx * 0.005;
desiredSpherical.phi = THREE.MathUtils.clamp(desiredSpherical.phi - dy * 0.004, 0.28, 1.45);
lastX = event.clientX;
lastY = event.clientY;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
transitioning = false;
desiredSpherical.radius *= Math.exp(event.deltaY * 0.001);
desiredSpherical.radius = THREE.MathUtils.clamp(desiredSpherical.radius, 4.5, 68);
}, { passive: false });
const views = {
overview: { position: [17, 13.2, 27], target: [0, 2.1, -3.7] },
harbor: { position: [10, 6.6, 23], target: [0, 1.4, 10.5] },
lane: { position: [8.6, 5.5, 10.5], target: [0, 2.1, -1.5] },
court: { position: [13, 8.8, -6.5], target: [5.2, 1.5, -14.4] }
};
function setView(name) {
const view = views[name];
if (!view) return;
desiredTarget.set(...view.target);
const offset = new THREE.Vector3(...view.position).sub(desiredTarget);
desiredSpherical.setFromVector3(offset);
desiredSpherical.phi = THREE.MathUtils.clamp(desiredSpherical.phi, 0.28, 1.45);
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", () => setView(button.dataset.view));
});
addEventListener("keydown", event => {
const keys = { "1": "overview", "2": "harbor", "3": "lane", "4": "court" };
if (keys[event.key]) setView(keys[event.key]);
});
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
// Animation.
const clock = new THREE.Clock();
const waterPositions = waterGeometry.attributes.position;
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
if (transitioning) {
target.lerp(desiredTarget, 0.065);
spherical.radius += (desiredSpherical.radius - spherical.radius) * 0.065;
spherical.phi += (desiredSpherical.phi - spherical.phi) * 0.065;
spherical.theta += (desiredSpherical.theta - spherical.theta) * 0.065;
if (
target.distanceToSquared(desiredTarget) < 0.0001 &&
Math.abs(spherical.radius - desiredSpherical.radius) < 0.01
) transitioning = false;
}
updateCameraFromSpherical();
for (let i = 0; i < waterPositions.count; i++) {
const x = waterPositions.getX(i);
const z = waterPositions.getZ(i);
const y = Math.sin(x * 0.42 + elapsed * 0.7) * 0.075
+ Math.cos(z * 0.31 - elapsed * 0.55) * 0.055;
waterPositions.setY(i, y);
}
waterPositions.needsUpdate = true;
waterGeometry.computeVertexNormals();
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
$("#loading").classList.add("done");
setTimeout(() => $("#loading").remove(), 700);
});
</script>
</body>
</html>
```