Prompt specification
Build or customize the Three.js 3D scene "Sidi Bou Said lane and viewpoint 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: Sidi Bou Said lane and viewpoint slice
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/sidi-bou-said-lane-and-viewpoint-slice-x2955
Scene Description Prompt:
Make a low-poly Three.js scene in a self-contained HTML file using cdnjs: Sidi Bou Said lane and viewpoint slice. Build a bounded low-poly scene with referenced facade proportions, climbing lane, and small coastal viewpoint. Use simplified blue-and-white material blocks while varying building shapes.
Working Three.js Starter (sidi-bou-said-lane-and-viewpoint-slice-x2955):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Sidi Bou Said · Lane & Coastal Viewpoint — Low Poly</title>
<style>
:root{ --blue:#1b4f9c; --blue2:#2f74c6; --ink:#22333f; }
*{box-sizing:border-box}
html,body{margin:0;height:100%;background:#cfe6f3;overflow:hidden;
font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;color:var(--ink)}
canvas{display:block}
#hud{position:absolute;left:16px;top:16px;width:288px;background:rgba(255,255,255,.93);
border:1px solid rgba(27,79,156,.30);border-left:6px solid var(--blue);border-radius:3px;
padding:12px 14px 11px;box-shadow:0 10px 28px rgba(14,38,66,.20);pointer-events:none}
#hud h1{margin:0 0 2px;font-size:13px;letter-spacing:.10em;text-transform:uppercase;color:var(--blue)}
#hud .sub{font-size:11px;opacity:.72;margin-bottom:8px}
#hud table{width:100%;border-collapse:collapse;font-size:11px;line-height:1.5}
#hud td{padding:1.5px 0;vertical-align:top}
#hud td.k{width:52%;opacity:.78}
#hud .sw{display:inline-block;width:11px;height:11px;border:1px solid rgba(0,0,0,.18);
vertical-align:-1px;margin-right:6px;border-radius:1px}
#hint{position:absolute;left:16px;bottom:14px;font-size:11px;letter-spacing:.03em;
background:rgba(27,79,156,.88);color:#fff;padding:6px 12px;border-radius:3px;
box-shadow:0 6px 18px rgba(14,38,66,.22);pointer-events:none}
#hint b{font-weight:600;color:#cfe3ff}
#reset{position:absolute;right:16px;top:16px;font-size:11px;letter-spacing:.06em;
background:rgba(255,255,255,.9);border:1px solid rgba(27,79,156,.35);color:var(--blue);
padding:7px 12px;border-radius:3px;cursor:pointer;box-shadow:0 8px 20px rgba(14,38,66,.18)}
#reset:hover{background:#fff}
@media (max-width:640px){ #hud{width:210px;font-size:11px} #hud table{font-size:10px} }
</style>
</head>
<body>
<div id="hud">
<h1>Sidi Bou Said · Lane & Viewpoint</h1>
<div class="sub">Low-poly slice — Tunisia, Mediterranean coast</div>
<table>
<tr><td class="k">Lane width</td><td>2.5 m cobbled, stepped climb</td></tr>
<tr><td class="k">Facade mass</td><td>cubic, 4–7 m tall, flat roofs</td></tr>
<tr><td class="k">Doors</td><td>1.05 × 2.3 m, round-arched</td></tr>
<tr><td class="k">Windows</td><td>0.85 × 1.15 m + shutters</td></tr>
<tr><td class="k">Domes</td><td>Ø 1.9 m, cobalt</td></tr>
<tr><td class="k">Palette</td><td>
<span class="sw" style="background:#f6f3ec"></span>whitewash
<span class="sw" style="background:#1b4f9c"></span>cobalt
<span class="sw" style="background:#d9d2c2"></span>stone</td></tr>
</table>
</div>
<button id="reset">Reset View (R)</button>
<div id="hint"><b>Drag</b> orbit · <b>Wheel</b> zoom · <b>Right-drag / Shift-drag</b> pan · <b>Double-click</b> reset</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
/* ------------------------------------------------------------------ *
* Deterministic RNG + helpers
* ------------------------------------------------------------------ */
function mulberry32(a){return function(){a|=0;a=a+0x6D2B79F5|0;let t=Math.imul(a^a>>>15,1|a);t=t+Math.imul(t^t>>>7,61|t)^t;return((t^t>>>14)>>>0)/4294967296;};}
const rnd = mulberry32(20240611);
const R = (a,b)=>a+(b-a)*rnd();
const pick = arr=>arr[Math.floor(rnd()*arr.length)];
/* ------------------------------------------------------------------ *
* Renderer / scene / camera
* ------------------------------------------------------------------ */
const renderer = new THREE.WebGLRenderer({antialias:true});
renderer.setPixelRatio(Math.min(devicePixelRatio,2));
renderer.setSize(innerWidth,innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.06;
document.body.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xd9edf7, 78, 270);
const camera = new THREE.PerspectiveCamera(46, innerWidth/innerHeight, 0.4, 900);
/* ------------------------------------------------------------------ *
* Materials (blue & white blocks)
* ------------------------------------------------------------------ */
const M = {
wall: new THREE.MeshStandardMaterial({color:0xf7f4ec, roughness:0.94, flatShading:true}),
wall2: new THREE.MeshStandardMaterial({color:0xefe9dc, roughness:0.95, flatShading:true}),
wall3: new THREE.MeshStandardMaterial({color:0xf3eee3, roughness:0.93, flatShading:true}),
trim: new THREE.MeshStandardMaterial({color:0xffffff, roughness:0.85, flatShading:true}),
blue: new THREE.MeshStandardMaterial({color:0x1b4f9c, roughness:0.62, flatShading:true}),
blue2: new THREE.MeshStandardMaterial({color:0x2a6fbe, roughness:0.6, flatShading:true}),
blueD: new THREE.MeshStandardMaterial({color:0x123a78, roughness:0.55, flatShading:true}),
stone: new THREE.MeshStandardMaterial({color:0xded7c6, roughness:1, flatShading:true}),
stoneD: new THREE.MeshStandardMaterial({color:0xc7bda8, roughness:1, flatShading:true}),
sand: new THREE.MeshStandardMaterial({color:0xe4dbc6, roughness:1, flatShading:true}),
plinth: new THREE.MeshStandardMaterial({color:0xbdb198, roughness:1, flatShading:true}),
cobble: new THREE.MeshStandardMaterial({color:0xffffff, roughness:1, flatShading:true}),
green: new THREE.MeshStandardMaterial({color:0x5c8a63, roughness:1, flatShading:true}),
green2: new THREE.MeshStandardMaterial({color:0x47765a, roughness:1, flatShading:true}),
rock: new THREE.MeshStandardMaterial({color:0x9a9384, roughness:1, flatShading:true}),
distant:new THREE.MeshStandardMaterial({color:0xe9eee9, roughness:1, flatShading:true})
};
/* ------------------------------------------------------------------ *
* Geometry helpers
* ------------------------------------------------------------------ */
function mesh(geo, mat, parent, x=0, y=0, z=0){
const m = new THREE.Mesh(geo, mat);
m.position.set(x,y,z);
m.castShadow = true; m.receiveShadow = true;
(parent||scene).add(m);
return m;
}
function box(parent, w,h,d, mat, x=0,y=0,z=0){
return mesh(new THREE.BoxGeometry(w,h,d), mat, parent, x,y,z);
}
/* round-arched shape extruded along +Z (r = w/2) */
function archGeo(w,h,depth){
const r = w/2, s = new THREE.Shape();
s.moveTo(-r,0); s.lineTo(-r,h-r);
s.absarc(0,h-r,r,Math.PI,0,true);
s.lineTo(r,0); s.closePath();
return new THREE.ExtrudeGeometry(s,{depth:depth, bevelEnabled:false, curveSegments:8});
}
function domeOn(parent, x, y, z, r, blue=true){
mesh(new THREE.CylinderGeometry(r*0.82,r*0.88,0.42,12), M.trim, parent, x,y+0.21,z);
const d = mesh(new THREE.SphereGeometry(r,14,7,0,Math.PI*2,0,Math.PI/2), blue?M.blue:M.trim, parent, x,y+0.42,z);
d.rotation.y = R(0,1);
mesh(new THREE.CylinderGeometry(0.045,0.045,0.34,6), M.trim, parent, x,y+0.42+r+0.12,z);
mesh(new THREE.SphereGeometry(0.11,8,6), M.trim, parent, x,y+0.42+r+0.30,z);
}
/* ------------------------------------------------------------------ *
* Sky, sun, sea
* ------------------------------------------------------------------ */
(function sky(){
const c=document.createElement('canvas'); c.width=8; c.height=256;
const ctx=c.getContext('2d');
const g=ctx.createLinearGradient(0,0,0,256);
g.addColorStop(0.00,'#3f86c6'); g.addColorStop(0.42,'#9fd2ea');
g.addColorStop(0.72,'#dceff7'); g.addColorStop(1.00,'#f1e5cb');
ctx.fillStyle=g; ctx.fillRect(0,0,8,256);
const tex=new THREE.CanvasTexture(c); tex.colorSpace=THREE.SRGBColorSpace;
const sky=new THREE.Mesh(new THREE.SphereGeometry(520,24,16),
new THREE.MeshBasicMaterial({map:tex, side:THREE.BackSide, fog:false}));
scene.add(sky);
})();
const hemi = new THREE.HemisphereLight(0xbfe3f7, 0xd6c7a8, 1.05);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff3dd, 1.55);
sun.position.set(-26,34,-16);
sun.target.position.set(0,4,12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048,2048);
sun.shadow.camera.left=-34; sun.shadow.camera.right=34;
sun.shadow.camera.top=40; sun.shadow.camera.bottom=-40;
sun.shadow.camera.near=1; sun.shadow.camera.far=170;
sun.shadow.bias=-0.0009;
scene.add(sun); scene.add(sun.target);
/* low-poly sea */
(function sea(){
const g = new THREE.PlaneGeometry(420,420,54,54);
g.rotateX(-Math.PI/2);
const pos = g.attributes.position, col=[];
const c = new THREE.Color();
for(let i=0;i<pos.count;i++){
const x=pos.getX(i), z=pos.getZ(i);
const h = Math.sin(x*0.075)*0.30 + Math.sin(z*0.11 + x*0.045)*0.22 + Math.sin((x+z)*0.19)*0.07;
pos.setY(i,h);
const d = Math.min(1, Math.hypot(x, z+10)/95);
c.setHSL(0.53 - 0.03*d, 0.55 - 0.12*d, 0.55 - 0.16*d);
col.push(c.r,c.g,c.b);
}
g.setAttribute('color', new THREE.Float32BufferAttribute(col,3));
g.computeVertexNormals();
const m = new THREE.Mesh(g, new THREE.MeshStandardMaterial({
color:0xffffff, vertexColors:true, roughness:0.24, metalness:0.12, flatShading:true}));
m.position.y = -3.05; m.receiveShadow = true;
scene.add(m);
})();
/* ------------------------------------------------------------------ *
* Bounded land slab + terrace / stair / landing profile
* lane runs north (+Z) climbing from the sea at -Z
* ------------------------------------------------------------------ */
const PLATFORMS = [ {z0:-3.4, z1:6, y:0}, {z0:12, z1:18, y:3}, {z0:26, z1:34, y:6.5} ];
const STAIRS = [ {z0:6, z1:12, y0:0, y1:3}, {z0:18, z1:26, y0:3, y1:6.5} ];
const LANE_HALF = 1.25;
const X_EDGE = 11;
/* diorama plinth (the "cut" base of the slice) */
box(scene, 25.2, 6.2, 40.5, M.plinth, 0, -4.1, 16.0);
function buildPlatform(p){
const h = p.y + 1.2;
box(scene, X_EDGE*2, h, p.z1-p.z0, M.sand, 0, p.y-h/2, (p.z0+p.z1)/2);
// pale paving skin
box(scene, X_EDGE*2, 0.12, p.z1-p.z0, M.stone, 0, p.y+0.06, (p.z0+p.z1)/2);
}
function buildStairs(s){
const n = Math.round((s.y1-s.y0)/0.34);
const depth = (s.z1-s.z0)/n, rise = (s.y1-s.y0)/n;
for(let i=0;i<n;i++){
const zf = s.z0 + i*depth;
const top = s.y0 + (i+1)*rise;
const h = top + 1.2;
box(scene, X_EDGE*2, h, depth+0.02, M.sand, 0, top-h/2, zf+depth/2);
// lane tread
box(scene, LANE_HALF*2, 0.12, depth*0.95, M.stoneD, 0, top+0.06, zf+depth/2);
// cobalt nosing on the riser
box(scene, LANE_HALF*2, 0.13, 0.13, M.blue, 0, top-0.005, zf+0.065);
}
}
PLATFORMS.forEach(buildPlatform);
STAIRS.forEach(buildStairs);
/* cobbled lane on the flat landings */
function cobbles(x0,x1,z0,z1,yTop){
const sx=0.56, sz=0.62;
const cols=Math.max(1,Math.floor((x1-x0)/sx)), rows=Math.max(1,Math.floor((z1-z0)/sz));
const im=new THREE.InstancedMesh(new THREE.BoxGeometry(sx-0.055,0.11,sz-0.06), M.cobble, cols*rows);
im.castShadow=false; im.receiveShadow=true;
const mtx=new THREE.Matrix4(), q=new THREE.Quaternion(), sc=new THREE.Vector3(1,1,1), p=new THREE.Vector3();
const col=new THREE.Color(); let i=0;
for(let r=0;r<rows;r++){
for(let c=0;c<cols;c++){
let x = x0 + sx*(c+0.5) + (r%2 ? sx*0.5 : 0);
x = Math.min(x1-0.3, Math.max(x0+0.3, x));
const z = z0 + sz*(r+0.5);
p.set(x, yTop+0.055, z);
q.setFromAxisAngle(new THREE.Vector3(0,1,0), R(-0.035,0.035));
mtx.compose(p,q,sc); im.setMatrixAt(i,mtx);
col.setHSL(0.11, 0.16, R(0.72,0.86)); im.setColorAt(i,col); i++;
}
}
im.instanceMatrix.needsUpdate=true; if(im.instanceColor) im.instanceColor.needsUpdate=true;
scene.add(im);
}
PLATFORMS.forEach(p=>{
cobbles(-LANE_HALF, LANE_HALF, p.z0+0.05, p.z1-0.05, p.y+0.12);
// kerb stones along the lane
box(scene, 0.28,0.26,p.z1-p.z0, M.stoneD, LANE_HALF+0.14, p.y+0.13, (p.z0+p.z1)/2);
box(scene, 0.28,0.26,p.z1-p.z0, M.stoneD, -LANE_HALF-0.14, p.y+0.13, (p.z0+p.z1)/2);
});
/* ------------------------------------------------------------------ *
* Facade decoration
* ------------------------------------------------------------------ */
function windowAt(parent, x, y, arched){
const w = arched?0.80:0.85, h = arched?1.35:1.15;
const frame = arched
? mesh(archGeo(w+0.24,h+0.20,0.05), M.trim, parent, x,y,0.015)
: mesh(new THREE.BoxGeometry(w+0.24,h+0.22,0.05), M.trim, parent, x,y,0.015);
const glass = arched
? mesh(archGeo(w,h,0.07), M.blueD, parent, x,y+0.02,0.045)
: mesh(new THREE.BoxGeometry(w,h,0.07), M.blueD, parent, x,y+0.02,0.045);
if(arched){
for(const dx of [-0.2,0,0.2]) box(parent,0.055,h*0.95,0.05,M.trim,x+dx,y+0.02+h*0.47,0.075);
}else{
const open = rnd()>0.35;
for(const s of [-1,1]){
const sh = box(parent, w*0.44, h, 0.055, M.blue, x+s*(w*0.5+w*0.24), y+0.02+h/2, 0.07);
sh.rotation.y = open ? s*0.62 : 0;
}
box(parent,w,0.055,0.05,M.trim,x,y+0.02+h/2,0.075);
}
return frame;
}
function addFacade(g, faceX, zc, zSpan, yBase, h, facing, insetFace){
const f = new THREE.Group();
f.position.set(faceX, yBase, zc);
f.rotation.y = facing>0 ? Math.PI/2 : -Math.PI/2;
g.add(f);
const floorH = 3.15;
const nFloors = Math.max(1, Math.round(h/floorH));
/* round-arched cobalt door with a white surround */
const doorX = -zSpan*0.26 + R(-0.25,0.35);
mesh(archGeo(1.42,2.48,0.05), M.trim, f, doorX, 0, 0.015);
mesh(archGeo(1.05,2.30,0.08), M.blue, f, doorX, 0, 0.05);
box(f, 1.55,0.13,0.62, M.trim, doorX, 0.065, 0.36);
mesh(new THREE.SphereGeometry(0.055,8,6), M.trim, f, doorX+0.32, 1.05, 0.135);
/* ground floor window, opposite the door */
windowAt(f, zSpan*0.24, 0.95, rnd()>0.55);
/* upper floors */
for(let fl=1; fl<nFloors; fl++){
const y = fl*floorH + 0.25;
const n = 2 + (rnd()>0.6?1:0);
for(let k=0;k<n;k++){
const u = (k-(n-1)/2)*(zSpan*0.72/n);
windowAt(f, u, y, rnd()>0.45);
}
/* occasional projecting mashrabiya box */
if(rnd()>0.62){
const bx = box(f, 0.95, 0.95, 0.46, M.trim, R(-zSpan*0.25,zSpan*0.25), fl*floorH+0.55, 0.24);
for(let b=0;b<4;b++) box(f, 0.055, 0.85, 0.05, M.blueD, bx.position.x-0.33+b*0.22, fl*floorH+0.55, 0.48);
box(f, 1.02,0.08,0.52, M.blue, bx.position.x, fl*floorH+1.05, 0.24);
}
}
/* blue band under the cornice */
box(f, zSpan*0.98, 0.09, 0.06, M.blue2, 0, h-0.30, 0.05);
}
/* ------------------------------------------------------------------ *
* Buildings — cubic masses with varied shapes
* ------------------------------------------------------------------ */
function makeBuilding(o){
const g = new THREE.Group();
const w=o.x1-o.x0, d=o.z1-o.z0, cx=(o.x0+o.x1)/2, cz=(o.z0+o.z1)/2;
const base=o.base, h=o.h, style=o.style||'cube';
const wallA = o.mat || pick([M.wall,M.wall2,M.wall3]);
const facing = cx<0 ? 1 : -1; // +1 : facade normal points +x (toward lane)
const innerFace = cx<0 ? o.x1 : o.x0;
if(style==='stepped'){
const h1=h*0.55, h2=h-h1, ins=0.8;
box(g, w, h1, d, wallA, cx, base+h1/2, cz);
box(g, w+0.26, 0.20, d+0.26, M.trim, cx, base+h1+0.10, cz);
box(g, w-2*ins, h2, d-2*ins, pick([M.wall,M.wall2,M.wall3]), cx, base+h1+h2/2, cz);
const upFace = cx<0 ? o.x1-ins : o.x0+ins;
addFacade(g, innerFace, cz, d, base, h1, facing);
addFacade(g, upFace, cz, d-2*ins, base+h1+0.20, h2, facing);
box(g, w-2*ins+0.24, 0.18, d-2*ins+0.24, M.trim, cx, base+h+0.09, cz);
/* roof terrace parapet */
const pw=w-2*ins, pd=d-2*ins, ph=0.48, py=base+h+0.18;
box(g, pw,ph,0.16, M.trim, cx, py+ph/2, cz-pd/2+0.08);
box(g, pw,ph,0.16, M.trim, cx, py+ph/2, cz+pd/2-0.08);
box(g, 0.16,ph,pd, M.trim, cx-pw/2+0.08, py+ph/2, cz);
box(g, 0.16,ph,pd, M.trim, cx+pw/2-0.08, py+ph/2, cz);
if(rnd()>0.5) domeOn(g, cx+R(-0.6,0.6), py+ph, cz+R(-0.5,0.5), 0.85);
} else {
box(g, w, h, d, wallA, cx, base+h/2, cz);
box(g, w+0.28, 0.20, d+0.28, M.trim, cx, base+h+0.10, cz);
addFacade(g, innerFace, cz, d, base, h, facing);
if(style==='domed'){
domeOn(g, cx, base+h+0.20, cz, 0.98);
} else {
/* flat roof with parapet + a few roof boxes */
const ph=0.42, py=base+h+0.20;
box(g, w,ph,0.16, M.trim, cx, py+ph/2, cz-d/2+0.08);
box(g, w,ph,0.16, M.trim, cx, py+ph/2, cz+d/2-0.08);
box(g, 0.16,ph,d, M.trim, cx-w/2+0.08, py+ph/2, cz);
box(g, 0.16,ph,d, M.trim, cx+w/2-0.08, py+ph/2, cz);
const nb = 1+Math.floor(rnd()*3);
for(let i=0;i<nb;i++){
const bw=R(0.5,1.0), bh=R(0.45,0.9);
box(g, bw,bh,R(0.5,0.9), M.wall2, cx+R(-w*0.3,w*0.3), py+bh/2, cz+R(-d*0.3,d*0.3));
}
}
}
scene.add(g);
return g;
}
const BUILDINGS = [
/* viewpoint terrace (y = 0) */
{x0:-8.8, x1:-2.4, z0:-1.6, z1:5.2, base:0, h:6.4, style:'stepped'},
{x0: 2.4, x1: 8.6, z0:-1.1, z1:5.4, base:0, h:5.6, style:'domed'},
{x0:-10.9,x1:-8.8, z0: 0.4, z1:5.4, base:0, h:4.6, style:'cube'},
{x0: 8.6, x1:10.9, z0: 1.0, z1:5.4, base:0, h:4.3, style:'cube'},
/* upper landing (y = 3) */
{x0:-8.2, x1:-2.4, z0:12.1, z1:17.8, base:3, h:6.8, style:'domed'},
{x0: 2.4, x1: 8.3, z0:12.5, z1:17.6, base:3, h:7.3, style:'stepped'},
{x0:-10.9,x1:-8.2, z0:13.0, z1:17.8, base:3, h:4.4, style:'cube'},
{x0: 8.3, x1:10.9, z0:12.6, z1:17.6, base:3, h:5.0, style:'cube'},
/* top landing (y = 6.5) */
{x0:-7.8, x1:-2.4, z0:26.2, z1:31.5, base:6.5, h:6.0, style:'cube'},
{x0: 2.4, x1: 7.9, z0:26.0, z1:32.0, base:6.5, h:6.6, style:'stepped'},
{x0:-10.9,x1:-7.8, z0:27.0, z1:32.0, base:6.5, h:4.2, style:'cube'},
{x0: 7.9, x1:10.9, z0:27.5, z1:32.5, base:6.5, h:4.8, style:'cube'}
];
BUILDINGS.forEach(makeBuilding);
/* ------------------------------------------------------------------ *
* Domed gateway at the head of the lane
* ------------------------------------------------------------------ */
(function gateway(){
const g=new THREE.Group(); g.position.set(0,6.5,29.6);
const P=1.15;
box(g,P,4.2,P,M.wall, -1.25-P/2, 2.1, 0);
box(g,P,4.2,P,M.wall, 1.25+P/2, 2.1, 0);
box(g,4.3,0.42,1.2,M.trim,0,4.4,0);
box(g,4.3,0.16,1.32,M.blue,0,4.66,0);
domeOn(g,0,4.72,0,1.05);
/* blue-shuttered niches in the piers */
for(const s of [-1,1]) box(g,0.5,1.3,0.08,M.blue,s*1.25,1.9,0.6);
scene.add(g);
})();
/* ------------------------------------------------------------------ *
* Coastal viewpoint: parapet, railing, benches, lamps, pots
* ------------------------------------------------------------------ */
(function viewpoint(){
/* cliff parapet along the seaward edge */
box(scene, X_EDGE*2, 0.95, 0.36, M.trim, 0, 0.475, -3.22);
box(scene, X_EDGE*2, 0.10, 0.46, M.stone, 0, 0.95, -3.22);
/* cobalt railing */
const railY = 1.0;
box(scene, X_EDGE*2-0.4, 0.07, 0.09, M.blue, 0, railY+0.62, -3.22);
box(scene, X_EDGE*2-0.4, 0.05, 0.07, M.blue, 0, railY+0.30, -3.22);
for(let x=-X_EDGE+0.5; x<X_EDGE-0.3; x+=1.05){
box(scene,0.075,0.66,0.075,M.trim,x,railY+0.33,-3.22);
}
/* rocks below the cliff */
for(let i=0;i<14;i++){
const r=mesh(new THREE.IcosahedronGeometry(R(0.5,1.4),0), M.rock, scene,
R(-X_EDGE+1,X_EDGE-1), R(-1.6,-0.6), R(-5.6,-3.6));
r.scale.set(R(0.8,1.6),R(0.5,1.0),R(0.8,1.5));
r.rotation.set(R(0,3),R(0,3),R(0,3));
}
/* benches facing the sea */
function bench(x,z,rot){
const b=new THREE.Group(); b.position.set(x,0,z); b.rotation.y=rot;
box(b,1.7,0.12,0.52,M.blue,0,0.56,0);
box(b,1.7,0.10,0.10,M.blue,0,0.90,-0.22);
for(const s of [-1,1]) box(b,0.12,0.56,0.44,M.trim,s*0.72,0.28,0);
scene.add(b);
}
bench(-4.2,-1.6,0); bench(4.2,-1.6,0);
/* lamps along the lane + terrace */
function lamp(x,y,z){
mesh(new THREE.CylinderGeometry(0.055,0.075,2.6,7), M.blue, scene, x, y+1.3, z);
box(scene,0.30,0.34,0.30,M.trim,x,y+2.75,z);
box(scene,0.36,0.08,0.36,M.blue,x,y+2.96,z);
mesh(new THREE.SphereGeometry(0.09,8,6), M.trim, scene, x, y+3.05, z);
}
lamp(-1.85,0.12,3.2); lamp(1.85,0.12,14.0); lamp(-1.85,6.62,27.4);
/* potted plants */
function pot(x,y,z,s){
mesh(new THREE.CylinderGeometry(0.26*s,0.19*s,0.44*s,9), M.blue, scene, x, y+0.22*s, z);
const f=mesh(new THREE.IcosahedronGeometry(0.46*s,0), rnd()>0.5?M.green:M.green2, scene, x, y+0.66*s, z);
f.scale.set(1,0.85,1); f.rotation.set(R(0,3),R(0,3),R(0,3));
const f2=mesh(new THREE.IcosahedronGeometry(0.26*s,0), M.green2, scene, x+0.18*s, y+0.88*s, z-0.1*s);
f2.rotation.set(R(0,3),R(0,3),R(0,3));
}
pot(-2.9,0.12,1.2,1); pot(2.9,0.12,2.0,0.9); pot(-2.9,0.12,5.4,0.8);
pot(2.9,3.12,12.6,1); pot(-2.9,3.12,17.0,0.85); pot(2.9,6.62,26.4,0.95);
pot(-2.9,6.62,31.0,0.8);
/* bougainvillea spilling over a lane wall */
for(const [x,y,z,s] of [[-1.6,3.2,15.5,1.0],[1.7,6.8,28.4,0.9],[-1.7,0.3,2.6,0.8]]){
const c=mesh(new THREE.IcosahedronGeometry(0.55*s,0), M.green, scene, x, y+0.45*s, z);
c.scale.set(1.25,0.8,1.0); c.rotation.set(R(0,3),R(0,3),R(0,3));
const c2=mesh(new THREE.IcosahedronGeometry(0.34*s,0), M.green2, scene, x+0.35*s, y+0.1*s, z+0.2*s);
c2.rotation.set(R(0,3),R(0,3),R(0,3));
}
})();
/* ------------------------------------------------------------------ *
* Boats, lighthouse, distant town
* ------------------------------------------------------------------ */
(function props(){
/* low-poly fishing boats */
function boat(x,z,rot,s){
const b=new THREE.Group(); b.position.set(x,-3.0,z); b.rotation.y=rot; b.scale.setScalar(s);
const hull=box(b,1.9,0.55,4.2,M.blue,0,0,0);
hull.rotation.x=0.0;
box(b,1.7,0.5,1.6,M.trim,0,0.42,-0.4);
box(b,0.10,3.2,0.10,M.trim,0,1.8,0.3);
const sail=new THREE.Shape();
sail.moveTo(0,0); sail.lineTo(0,2.6); sail.lineTo(1.7,0.15); sail.closePath();
const sg=new THREE.ShapeGeometry(sail);
const sm=new THREE.Mesh(sg, new THREE.MeshStandardMaterial({color:0xfbf7ee,roughness:1,side:THREE.DoubleSide}));
sm.position.set(0.06,0.6,0.32); sm.rotation.y=Math.PI/2; b.add(sm);
scene.add(b);
}
boat(-14,-16,0.7,1); boat(11,-25,-0.4,0.8); boat(24,-11,2.1,1.15);
/* lighthouse on a rocky islet */
const isl=new THREE.Group(); isl.position.set(-31,-3.0,-20);
for(let i=0;i<7;i++){
const r=mesh(new THREE.IcosahedronGeometry(R(1.2,3.0),0), M.rock, isl, R(-4,4), R(-1,1.6), R(-3,3));
r.scale.set(1,0.55,1); r.rotation.set(R(0,3),R(0,3),R(0,3));
}
mesh(new THREE.CylinderGeometry(0.85,1.15,5.6,12), M.trim, isl, 0,4.4,0);
mesh(new THREE.CylinderGeometry(0.92,0.92,0.7,12), M.blue, isl, 0,4.6,0);
mesh(new THREE.CylinderGeometry(1.25,1.25,0.25,12), M.trim, isl, 0,7.3,0);
mesh(new THREE.CylinderGeometry(0.7,0.7,0.95,8), M.blue2, isl, 0,7.9,0);
mesh(new THREE.ConeGeometry(0.9,0.8,8), M.blue, isl, 0,8.7,0);
scene.add(isl);
/* distant headland across the water */
for(let i=0;i<6;i++){
const h=mesh(new THREE.ConeGeometry(R(6,14), R(4,9), 5), M.distant, scene, -70+i*26, -2, -105-R(0,25));
h.rotation.y=R(0,3);
}
/* the town continuing uphill behind the slice */
for(let i=0;i<8;i++){
const z=34+i*5.2, top=6.5+i*1.7;
box(scene, 34, top+7, 5.4, M.distant, 0, top-(top+7)/2, z+2.7);
}
for(let i=0;i<26;i++){
const i2=Math.floor(i/5);
const z=35+i2*5.2+R(0,3.6), top=6.5+i2*1.7;
const w=R(1.6,3.4), h=R(2.4,4.6);
box(scene, w, h, R(1.6,3.2), M.distant, R(-13,13), top+h/2, z);
}
for(let i=0;i<5;i++){
const i2=Math.floor(i/2);
domeOn(scene, R(-12,12), 6.5+i2*1.7+4.6, 36+i2*5.2+R(0,3), R(0.7,1.1));
}
})();
/* ------------------------------------------------------------------ *
* Custom camera controls (orbit / pan / zoom) — no addons
* ------------------------------------------------------------------ */
const HOME = { theta:-0.72, phi:1.06, radius:44, target:new THREE.Vector3(0,3.0,11) };
const cam = {
theta:HOME.theta, phi:HOME.phi, radius:HOME.radius,
target:HOME.target.clone(),
dTheta:HOME.theta, dPhi:HOME.phi, dRadius:HOME.radius, dTarget:HOME.target.clone()
};
const pointers=new Map();
let mode='orbit', lastX=0, lastY=0, pinchDist=0;
const el=renderer.domElement;
el.style.touchAction='none';
el.addEventListener('contextmenu', e=>e.preventDefault());
el.addEventListener('pointerdown', e=>{
el.setPointerCapture(e.pointerId);
pointers.set(e.pointerId,{x:e.clientX,y:e.clientY});
if(pointers.size===1){
mode = (e.button===2 || e.shiftKey) ? 'pan' : 'orbit';
lastX=e.clientX; lastY=e.clientY;
}else if(pointers.size===2){
const p=[...pointers.values()];
pinchDist=Math.hypot(p[0].x-p[1].x, p[0].y-p[1].y);
mode='pinch';
}
});
el.addEventListener('pointermove', e=>{
if(!pointers.has(e.pointerId)) return;
pointers.set(e.pointerId,{x:e.clientX,y:e.clientY});
if(mode==='pinch' && pointers.size===2){
const p=[...pointers.values()];
const d=Math.hypot(p[0].x-p[1].x,p[0].y-p[1].y);
if(pinchDist>0) cam.dRadius=THREE.MathUtils.clamp(cam.dRadius*(pinchDist/Math.max(d,1)),10,140);
pinchDist=d; return;
}
const dx=e.clientX-lastX, dy=e.clientY-lastY;
lastX=e.clientX; lastY=e.clientY;
if(mode==='orbit'){
cam.dTheta -= dx*0.005;
cam.dPhi = THREE.MathUtils.clamp(cam.dPhi - dy*0.004, 0.12, 1.46);
}else if(mode==='pan'){
const right=new THREE.Vector3().setFromMatrixColumn(camera.matrix,0);
const up=new THREE.Vector3().setFromMatrixColumn(camera.matrix,1);
const k=cam.dRadius*0.0016;
cam.dTarget.addScaledVector(right,-dx*k).addScaledVector(up,dy*k);
cam.dTarget.y=THREE.MathUtils.clamp(cam.dTarget.y,-2,16);
cam.dTarget.x=THREE.MathUtils.clamp(cam.dTarget.x,-30,30);
cam.dTarget.z=THREE.MathUtils.clamp(cam.dTarget.z,-30,50);
}
});
function endPointer(e){ pointers.delete(e.pointerId); if(pointers.size===0) mode='orbit'; }
el.addEventListener('pointerup',endPointer);
el.addEventListener('pointercancel',endPointer);
el.addEventListener('pointerleave',endPointer);
el.addEventListener('wheel', e=>{
e.preventDefault();
cam.dRadius=THREE.MathUtils.clamp(cam.dRadius*Math.exp(e.deltaY*0.0011),10,140);
},{passive:false});
el.addEventListener('dblclick', resetView);
function resetView(){
cam.dTheta=HOME.theta; cam.dPhi=HOME.phi; cam.dRadius=HOME.radius;
cam.dTarget.copy(HOME.target);
}
document.getElementById('reset').addEventListener('click',resetView);
addEventListener('keydown', e=>{ if(e.key==='r'||e.key==='R') resetView(); });
function updateCamera(){
cam.theta += (cam.dTheta-cam.theta)*0.12;
cam.phi += (cam.dPhi-cam.phi)*0.12;
cam.radius+= (cam.dRadius-cam.radius)*0.12;
cam.target.lerp(cam.dTarget,0.12);
const s=Math.sin(cam.phi);
camera.position.set(
cam.target.x + cam.radius*s*Math.sin(cam.theta),
cam.target.y + cam.radius*Math.cos(cam.phi),
cam.target.z + cam.radius*s*Math.cos(cam.theta)
);
camera.lookAt(cam.target);
}
updateCamera();
addEventListener('resize', ()=>{
camera.aspect=innerWidth/innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth,innerHeight);
});
/* ------------------------------------------------------------------ *
* Loop
* ------------------------------------------------------------------ */
function animate(){
requestAnimationFrame(animate);
updateCamera();
renderer.render(scene,camera);
}
animate();
</script>
</body>
</html>
```