Prompt specification
Build or customize the Three.js 3D scene "Alto da Sé hilltop square scene" 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: Alto da Sé hilltop square scene
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/alto-da-s-hilltop-square-scene-x2679
Scene Description Prompt:
Olinda's Alto da Sé in low-poly blocks: church silhouette, hilltop square, descending street, and distant skyline. Three.js from cdnjs, one HTML file.
Working Three.js Starter (alto-da-s-hilltop-square-scene-x2679):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Alto da Sé — Olinda</title>
<style>
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #9dc1cc;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.card {
position: fixed;
top: 24px;
left: 24px;
z-index: 10;
color: #fff9e9;
text-shadow: 0 2px 16px rgba(42, 40, 31, 0.35);
user-select: none;
pointer-events: none;
}
.eyebrow {
margin-bottom: 6px;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.25em;
opacity: 0.86;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(34px, 5vw, 64px);
font-weight: 500;
line-height: 0.95;
letter-spacing: -0.035em;
}
.subtitle {
margin-top: 10px;
font-size: 12px;
letter-spacing: 0.13em;
opacity: 0.9;
}
.hint {
position: fixed;
right: 22px;
bottom: 20px;
z-index: 10;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.25);
border-radius: 999px;
color: rgba(255, 255, 255, 0.9);
background: rgba(31, 43, 43, 0.24);
backdrop-filter: blur(8px);
font-size: 11px;
letter-spacing: 0.04em;
user-select: none;
pointer-events: none;
}
#reset {
position: fixed;
right: 22px;
top: 22px;
z-index: 20;
width: 42px;
height: 42px;
border: 1px solid rgba(255, 255, 255, 0.35);
border-radius: 50%;
color: white;
background: rgba(31, 43, 43, 0.26);
backdrop-filter: blur(8px);
cursor: pointer;
font-size: 20px;
transition: background 150ms ease, transform 150ms ease;
}
#reset:hover {
background: rgba(31, 43, 43, 0.5);
transform: rotate(-12deg);
}
@media (max-width: 600px) {
.card { top: 18px; left: 18px; }
.subtitle { max-width: 210px; line-height: 1.5; }
.hint { right: 12px; bottom: 12px; }
}
</style>
</head>
<body>
<div class="card">
<div class="eyebrow">OLINDA · PERNAMBUCO</div>
<h1>ALTO DA SÉ</h1>
<div class="subtitle">Church, hilltop square and the street descending to Recife</div>
</div>
<button id="reset" title="Reset view" aria-label="Reset view">↺</button>
<div class="hint">Drag to orbit · Scroll to zoom · Arrow keys to rotate</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 renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xd9c4ad, 67, 155);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
260
);
const standard = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
flatShading: true,
...options
});
const materials = {
cream: standard(0xf0dfb8),
creamLight: standard(0xffedc5),
ochre: standard(0xc78c46),
ochreLight: standard(0xe2ad60),
roof: standard(0xa94f36, { side: THREE.DoubleSide }),
roofDark: standard(0x793c32, { side: THREE.DoubleSide }),
stone: standard(0xb5aa8d),
stoneDark: standard(0x817a67),
paving: standard(0xc8b58e),
dark: standard(0x253d3c),
iron: standard(0x344441),
trunk: standard(0x705039),
leaf: standard(0x4f714b),
leafLight: standard(0x67834f),
leafDark: standard(0x365640),
water: standard(0x64b6bd, { roughness: 0.35 }),
ocean: standard(0x559da8, { roughness: 0.45 }),
glass: standard(0x8ac1c0, {
emissive: 0x315657,
emissiveIntensity: 0.22,
roughness: 0.4
})
};
const hemi = new THREE.HemisphereLight(0xb9d9e2, 0x76624b, 2.15);
scene.add(hemi);
const sunLight = new THREE.DirectionalLight(0xffdfad, 3.25);
sunLight.position.set(-28, 52, 34);
sunLight.castShadow = true;
sunLight.shadow.mapSize.set(2048, 2048);
sunLight.shadow.camera.left = -55;
sunLight.shadow.camera.right = 55;
sunLight.shadow.camera.top = 55;
sunLight.shadow.camera.bottom = -45;
sunLight.shadow.camera.near = 1;
sunLight.shadow.camera.far = 140;
sunLight.shadow.bias = -0.00035;
sunLight.shadow.normalBias = 0.035;
scene.add(sunLight);
const fillLight = new THREE.DirectionalLight(0x7fb9d0, 0.65);
fillLight.position.set(38, 22, -35);
scene.add(fillLight);
// -------------------------------------------------------------------------
// Small geometry helpers
// -------------------------------------------------------------------------
function box(width, height, depth, material, x, y, z, shadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = shadow;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function cylinder(rTop, rBottom, height, sides, material, x, y, z) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rTop, rBottom, height, sides),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function smoothstep(min, max, value) {
const t = THREE.MathUtils.clamp((value - min) / (max - min), 0, 1);
return t * t * (3 - 2 * t);
}
let seed = 1837;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
function terrainHeight(x, z) {
const front = 1 - smoothstep(7, 36, z);
const back = smoothstep(-62, -42, z);
const side = 1 - 0.87 * smoothstep(19, 60, Math.abs(x));
const ripple =
Math.sin(x * 0.22 + z * 0.11) * 0.16 +
Math.cos(z * 0.27 - x * 0.08) * 0.11;
return 10.2 * front * back * side + ripple * front * back;
}
function cylinderBetween(a, b, radius, material, sides = 6) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius * 0.85, radius, length, sides),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function gableGeometry(width, depth, baseY, ridgeY, zCenter) {
const half = width / 2;
const halfDepth = depth / 2;
const z0 = zCenter - halfDepth;
const z1 = zCenter + halfDepth;
const positions = [
-half, baseY, z0,
half, baseY, z0,
0, ridgeY, z0,
-half, baseY, z1,
half, baseY, z1,
0, ridgeY, z1
];
const indices = [
0, 1, 2,
3, 5, 4,
0, 3, 4, 0, 4, 2,
2, 4, 5, 2, 5, 1
];
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
'position',
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function addGable(width, depth, baseY, ridgeY, zCenter, material) {
const mesh = new THREE.Mesh(
gableGeometry(width, depth, baseY, ridgeY, zCenter),
material
);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function pyramidGeometry(width, depth, baseY, height, zCenter) {
const x = width / 2;
const z = depth / 2;
const positions = [
-x, baseY, zCenter - z,
x, baseY, zCenter - z,
x, baseY, zCenter + z,
-x, baseY, zCenter + z,
0, baseY + height, zCenter
];
const indices = [
0, 1, 4,
1, 2, 4,
2, 3, 4,
3, 0, 4,
3, 2, 1,
3, 1, 0
];
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
'position',
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function archShape(width, height) {
const radius = width / 2;
const spring = height - radius;
const shape = new THREE.Shape();
shape.moveTo(-radius, 0);
shape.lineTo(radius, 0);
shape.lineTo(radius, spring);
for (let i = 0; i <= 8; i++) {
const angle = (i / 8) * Math.PI;
shape.lineTo(
Math.cos(angle) * radius,
spring + Math.sin(angle) * radius
);
}
shape.closePath();
return shape;
}
function addArch(x, y, z, width, height, trim = false, rotationY = 0) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.rotation.y = rotationY;
if (trim) {
const border = new THREE.Mesh(
new THREE.ShapeGeometry(archShape(width + 0.38, height + 0.28)),
materials.ochreLight
);
border.position.z = 0.015;
border.castShadow = true;
group.add(border);
}
const opening = new THREE.Mesh(
new THREE.ShapeGeometry(archShape(width, height)),
materials.dark
);
opening.position.z = 0.055;
group.add(opening);
scene.add(group);
return group;
}
function addCross(x, y, z, scale = 1) {
box(0.16 * scale, 1.65 * scale, 0.16 * scale,
materials.iron, x, y + 0.55 * scale, z);
box(0.85 * scale, 0.15 * scale, 0.16 * scale,
materials.iron, x, y + 0.75 * scale, z);
}
// -------------------------------------------------------------------------
// Sky, sun and low-poly clouds
// -------------------------------------------------------------------------
const skyMaterial = new THREE.ShaderMaterial({
side: THREE.BackSide,
depthWrite: false,
uniforms: {
topColor: { value: new THREE.Color(0x73aec8) },
horizonColor: { value: new THREE.Color(0xf1c59c) }
},
vertexShader: `
varying float vHeight;
void main() {
vHeight = normalize(position).y;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`,
fragmentShader: `
uniform vec3 topColor;
uniform vec3 horizonColor;
varying float vHeight;
void main() {
float h = smoothstep(-0.08, 0.72, vHeight);
vec3 color = mix(horizonColor, topColor, h);
gl_FragColor = vec4(color, 1.0);
}
`
});
const sky = new THREE.Mesh(
new THREE.SphereGeometry(185, 24, 16),
skyMaterial
);
scene.add(sky);
const sun = new THREE.Mesh(
new THREE.SphereGeometry(5.4, 16, 12),
new THREE.MeshBasicMaterial({ color: 0xffd39a, fog: false })
);
sun.position.set(-38, 39, -93);
scene.add(sun);
const cloudMaterial = standard(0xf3e4ce, {
roughness: 1,
flatShading: true
});
function addCloud(x, y, z, scale) {
const group = new THREE.Group();
const pieces = [
[-2.1, 0, 0, 1.5],
[-0.6, 0.55, 0, 1.8],
[1.25, 0.15, 0, 1.4],
[2.6, -0.1, 0, 0.9]
];
for (const [px, py, pz, s] of pieces) {
const piece = new THREE.Mesh(
new THREE.IcosahedronGeometry(s, 0),
cloudMaterial
);
piece.position.set(px, py, pz);
group.add(piece);
}
group.position.set(x, y, z);
group.scale.setScalar(scale);
scene.add(group);
}
addCloud(-30, 28, -74, 2.1);
addCloud(31, 34, -91, 2.7);
addCloud(53, 24, -69, 1.8);
addCloud(-56, 22, -60, 1.5);
// -------------------------------------------------------------------------
// Faceted terrain
// -------------------------------------------------------------------------
const terrainPositions = [];
const terrainColors = [];
const terrainPalette = [
0x899567,
0x929b69,
0xa39a68,
0xb09b6b,
0x7f8c60
];
const terrainWidth = 130;
const terrainDepth = 128;
const terrainX = -65;
const terrainZ = -72;
const segmentsX = 45;
const segmentsZ = 50;
function terrainPoint(ix, iz) {
const x = terrainX + (ix / segmentsX) * terrainWidth;
const z = terrainZ + (iz / segmentsZ) * terrainDepth;
return [x, terrainHeight(x, z), z];
}
function addTerrainTriangle(a, b, c) {
const averageHeight = (a[1] + b[1] + c[1]) / 3;
let color;
if (averageHeight > 8.7) {
color = new THREE.Color(0xb4a171);
} else {
color = new THREE.Color(
terrainPalette[Math.floor(random() * terrainPalette.length)]
);
}
color.multiplyScalar(0.91 + random() * 0.16);
for (const point of [a, b, c]) {
terrainPositions.push(...point);
terrainColors.push(color.r, color.g, color.b);
}
}
for (let iz = 0; iz < segmentsZ; iz++) {
for (let ix = 0; ix < segmentsX; ix++) {
const p00 = terrainPoint(ix, iz);
const p10 = terrainPoint(ix + 1, iz);
const p01 = terrainPoint(ix, iz + 1);
const p11 = terrainPoint(ix + 1, iz + 1);
addTerrainTriangle(p00, p01, p10);
addTerrainTriangle(p10, p01, p11);
}
}
const terrainGeometry = new THREE.BufferGeometry();
terrainGeometry.setAttribute(
'position',
new THREE.Float32BufferAttribute(terrainPositions, 3)
);
terrainGeometry.setAttribute(
'color',
new THREE.Float32BufferAttribute(terrainColors, 3)
);
terrainGeometry.computeVertexNormals();
const terrain = new THREE.Mesh(
terrainGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 1,
flatShading: true
})
);
terrain.receiveShadow = true;
scene.add(terrain);
// Faceted upper terrace that visually supports the church.
const terrace = new THREE.Mesh(
new THREE.CylinderGeometry(23, 25, 1.7, 10),
standard(0x9c8c65)
);
terrace.position.set(0, 9.47, -14);
terrace.scale.set(1.18, 1, 0.86);
terrace.castShadow = true;
terrace.receiveShadow = true;
scene.add(terrace);
// -------------------------------------------------------------------------
// Paved hilltop square
// -------------------------------------------------------------------------
function createPavingTexture() {
const canvas = document.createElement('canvas');
canvas.width = 1024;
canvas.height = 512;
const context = canvas.getContext('2d');
context.fillStyle = '#80745f';
context.fillRect(0, 0, canvas.width, canvas.height);
const tileWidth = 64;
const tileHeight = 64;
const colors = ['#cabb94', '#d1c39d', '#bfad87', '#d9c9a2', '#c4b58d'];
for (let row = 0; row < 8; row++) {
const offset = row % 2 ? -tileWidth / 2 : 0;
for (let col = -1; col < 17; col++) {
const x = col * tileWidth + offset;
const y = row * tileHeight;
context.fillStyle = colors[Math.floor(random() * colors.length)];
context.fillRect(x + 2, y + 2, tileWidth - 4, tileHeight - 4);
}
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
const square = new THREE.Mesh(
new THREE.PlaneGeometry(31, 16),
new THREE.MeshStandardMaterial({
map: createPavingTexture(),
roughness: 1
})
);
square.rotation.x = -Math.PI / 2;
square.position.set(0, 10.55, 0.5);
square.receiveShadow = true;
scene.add(square);
box(31.4, 0.18, 0.28, materials.ochreLight, 0, 10.57, 8.45);
box(0.28, 0.18, 16.2, materials.ochreLight, -15.45, 10.57, 0.45);
box(0.28, 0.18, 16.2, materials.ochreLight, 15.45, 10.57, 0.45);
// -------------------------------------------------------------------------
// Igreja Nossa Senhora da Graça / Alto da Sé
// -------------------------------------------------------------------------
const churchBase = 10.58;
// Nave
box(12.3, 9, 20, materials.cream, 0, churchBase + 4.5, -22);
addGable(13, 20.8, churchBase + 9, churchBase + 14, -22, materials.roof);
// Central façade
box(10, 10.4, 3, materials.creamLight, 0, churchBase + 5.2, -10.5);
addGable(10.7, 3.5, churchBase + 10.4, churchBase + 14.1, -10.5, materials.roof);
// Twin towers
const towerXs = [-7.25, 7.25];
for (const x of towerXs) {
box(4.8, 12.4, 5, materials.creamLight, x, churchBase + 6.2, -9.6);
box(5.15, 0.48, 5.25, materials.ochreLight, x, churchBase + 12.25, -9.6);
const roof = new THREE.Mesh(
pyramidGeometry(6, 6, churchBase + 12.5, 3.5, -9.6),
materials.roofDark
);
roof.castShadow = true;
scene.add(roof);
addCross(x, churchBase + 16, -9.6, 0.82);
addArch(x, churchBase + 7.2, -7.075, 2.45, 4.1, true);
// Small bell in the opening.
const bell = cylinder(0.33, 0.52, 0.85, 6,
materials.ochre, x, churchBase + 9.1, -7.25);
bell.rotation.x = Math.PI;
}
// Main entrance and oculus.
addArch(0, churchBase + 0.08, -8.97, 2.9, 5.4, true);
box(0.16, 5.5, 0.15, materials.ochre, 0, churchBase + 2.7, -8.84);
const oculus = new THREE.Mesh(
new THREE.CircleGeometry(1.02, 12),
materials.dark
);
oculus.position.set(0, churchBase + 7.55, -8.95);
scene.add(oculus);
const oculusRing = new THREE.Mesh(
new THREE.TorusGeometry(1.13, 0.15, 5, 16),
materials.ochreLight
);
oculusRing.position.set(0, churchBase + 7.55, -8.91);
scene.add(oculusRing);
// Pilasters and cornices.
for (const x of [-4.5, 4.5]) {
box(0.42, 9.6, 0.32, materials.ochreLight, x, churchBase + 4.8, -8.88);
}
box(10.55, 0.35, 0.48, materials.ochreLight, 0, churchBase + 10.3, -8.87);
box(12.7, 0.36, 20.35, materials.roofDark, 0, churchBase + 9.03, -22);
// Side windows.
for (const z of [-15.5, -21.5, -27.5]) {
addArch(6.18, churchBase + 3.3, z, 1.35, 3.15, true, Math.PI / 2);
addArch(-6.18, churchBase + 3.3, z, 1.35, 3.15, true, -Math.PI / 2);
}
// Roof ridge and small finial.
box(0.18, 0.18, 20.8, materials.roofDark, 0, churchBase + 14.15, -22);
addCross(0, churchBase + 14.15, -22, 0.72);
// -------------------------------------------------------------------------
// Descending street
// -------------------------------------------------------------------------
const roadMaterial = standard(0x77786e);
const roadWallMaterial = standard(0x9e8160);
const curbMaterial = standard(0xc7b895);
function roadQuaternion(a, b) {
const direction = new THREE.Vector3().subVectors(b, a).normalize();
const across = new THREE.Vector3(-direction.z, 0, direction.x).normalize();
const up = new THREE.Vector3().crossVectors(across, direction).normalize();
const basis = new THREE.Matrix4().makeBasis(across, up, direction);
return {
quaternion: new THREE.Quaternion().setFromRotationMatrix(basis),
across,
up,
direction,
length: a.distanceTo(b)
};
}
function addRoadSegment(a, b, width = 7) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const { quaternion, across, up, length } = roadQuaternion(start, end);
const center = start.clone().add(end).multiplyScalar(0.5);
const road = new THREE.Mesh(
new THREE.BoxGeometry(width, 0.24, length),
roadMaterial
);
road.position.copy(center).addScaledVector(up, -0.12);
road.quaternion.copy(quaternion);
road.castShadow = true;
road.receiveShadow = true;
scene.add(road);
const wall = new THREE.Mesh(
new THREE.BoxGeometry(width + 0.55, 0.82, length + 0.08),
roadWallMaterial
);
wall.position.copy(center).addScaledVector(up, -0.65);
wall.quaternion.copy(quaternion);
wall.castShadow = true;
wall.receiveShadow = true;
scene.add(wall);
for (const side of [-1, 1]) {
const curb = new THREE.Mesh(
new THREE.BoxGeometry(0.22, 0.18, length),
curbMaterial
);
curb.position
.copy(center)
.addScaledVector(across, side * (width / 2 - 0.12))
.addScaledVector(up, 0.05);
curb.quaternion.copy(quaternion);
curb.castShadow = true;
curb.receiveShadow = true;
scene.add(curb);
}
const stoneCount = Math.max(2, Math.floor(length / 2.1));
for (let i = 1; i < stoneCount; i++) {
const t = i / stoneCount;
const p = start.clone().lerp(end, t).addScaledVector(up, 0.025);
const joint = new THREE.Mesh(
new THREE.BoxGeometry(width - 0.8, 0.035, 0.11),
standard(0x62665f)
);
joint.position.copy(p);
joint.quaternion.copy(quaternion);
joint.receiveShadow = true;
scene.add(joint);
}
}
const roadPoints = [
[0, 10.58, 8.8],
[-8, 7.85, 17],
[-6, 4.4, 25],
[7, 1.05, 33],
[10, 0.22, 43]
];
for (let i = 0; i < roadPoints.length - 1; i++) {
addRoadSegment(roadPoints[i], roadPoints[i + 1]);
}
// -------------------------------------------------------------------------
// Trees, palms, lamps, benches and people
// -------------------------------------------------------------------------
function addTree(x, z, baseY, scale = 1) {
const trunkHeight = 2.2 * scale;
cylinder(
0.22 * scale,
0.31 * scale,
trunkHeight,
6,
materials.trunk,
x,
baseY + trunkHeight / 2,
z
);
const crown = new THREE.Mesh(
new THREE.IcosahedronGeometry(1.75 * scale, 0),
materials.leaf
);
crown.position.set(x, baseY + trunkHeight + 0.95 * scale, z);
crown.scale.set(1, 1.15, 0.92);
crown.castShadow = true;
scene.add(crown);
const crown2 = new THREE.Mesh(
new THREE.IcosahedronGeometry(1.18 * scale, 0),
materials.leafLight
);
crown2.position.set(x + 0.62 * scale, baseY + trunkHeight + 0.72 * scale, z - 0.15);
crown2.castShadow = true;
scene.add(crown2);
}
function addPalm(x, z, baseY, height = 6.2) {
const points = [];
for (let i = 0; i <= 4; i++) {
const t = i / 4;
points.push(new THREE.Vector3(
x + Math.sin(t * 1.5) * 0.65,
baseY + t * height,
z + Math.sin(t * Math.PI) * 0.35
));
}
for (let i = 0; i < points.length - 1; i++) {
cylinderBetween(points[i], points[i + 1], 0.22 - i * 0.025,
materials.trunk, 6);
}
const top = points[points.length - 1];
const leafMaterial = standard(0x416c43, { side: THREE.DoubleSide });
for (let i = 0; i < 7; i++) {
const angle = (i / 7) * Math.PI * 2;
const length = 3.15 + random() * 0.65;
const width = 0.72;
const vertices = new Float32Array([
0, 0, 0,
length * 0.55, 0.18, -width,
length, -0.9, 0,
length * 0.55, 0.18, width
]);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
geometry.setIndex([0, 1, 2, 0, 2, 3]);
geometry.computeVertexNormals();
const leaf = new THREE.Mesh(geometry, leafMaterial);
leaf.position.copy(top);
leaf.rotation.y = angle;
leaf.castShadow = true;
scene.add(leaf);
}
}
function addLamp(x, z, baseY) {
cylinder(0.07, 0.11, 3.6, 6, materials.iron, x, baseY + 1.8, z);
box(0.55, 0.12, 0.55, materials.iron, x, baseY + 3.55, z);
box(0.39, 0.55, 0.39,
standard(0xffd98d, { emissive: 0xe5a64b, emissiveIntensity: 0.6 }),
x, baseY + 3.88, z);
box(0.56, 0.12, 0.56, materials.iron, x, baseY + 4.2, z);
}
function addBench(x, z, baseY, rotation = 0) {
const group = new THREE.Group();
const seat = new THREE.Mesh(
new THREE.BoxGeometry(2.7, 0.18, 0.65),
materials.trunk
);
seat.position.y = 0.72;
seat.castShadow = true;
group.add(seat);
const back = new THREE.Mesh(
new THREE.BoxGeometry(2.7, 0.78, 0.13),
materials.trunk
);
back.position.set(0, 1.12, -0.29);
back.castShadow = true;
group.add(back);
for (const px of [-1.02, 1.02]) {
const leg = new THREE.Mesh(
new THREE.BoxGeometry(0.16, 0.75, 0.55),
materials.iron
);
leg.position.set(px, 0.37, 0);
leg.castShadow = true;
group.add(leg);
}
group.position.set(x, baseY, z);
group.rotation.y = rotation;
scene.add(group);
}
function addPerson(x, z, baseY, color, rotation = 0) {
const group = new THREE.Group();
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.21, 0.28, 1.05, 5),
standard(color)
);
body.position.y = 0.63;
body.castShadow = true;
group.add(body);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.25, 6, 4),
standard(0x9a684b)
);
head.position.y = 1.37;
head.castShadow = true;
group.add(head);
group.position.set(x, baseY, z);
group.rotation.y = rotation;
scene.add(group);
}
// Fountain
const fountainBase = 10.58;
cylinder(2.25, 2.5, 0.55, 8, materials.stone,
6.2, fountainBase + 0.28, 2.2);
cylinder(1.75, 1.75, 0.13, 16, materials.water,
6.2, fountainBase + 0.61, 2.2);
cylinder(0.38, 0.58, 2.15, 8, materials.stone,
6.2, fountainBase + 1.48, 2.2);
cylinder(1.05, 0.7, 0.28, 8, materials.stone,
6.2, fountainBase + 2.57, 2.2);
cylinder(0.11, 0.16, 1.1, 6, materials.ochreLight,
6.2, fountainBase + 3.1, 2.2);
addTree(-12.4, 4.7, fountainBase, 0.9);
addTree(12.4, 4.7, fountainBase, 0.86);
addTree(-12.5, -4.5, fountainBase, 0.78);
addPalm(12.6, -4.6, fountainBase, 6.3);
addPalm(-3.8, 6.1, fountainBase, 5.7);
addBench(-7.3, 4.2, fountainBase, 0.08);
addBench(10.2, 5.6, fountainBase, -0.18);
addBench(3.8, -5.7, fountainBase, Math.PI);
addLamp(-11.3, 6.7, fountainBase);
addLamp(10.7, 6.9, fountainBase);
addLamp(-14.3, -1.2, fountainBase);
addLamp(14.2, -1.2, fountainBase);
const personColors = [0xb45142, 0x496d8d, 0xd4ad55, 0x756080, 0x527d68];
const peoplePositions = [
[-4.8, 1.7], [-2.2, 4.2], [1.7, 4.8], [4.3, -2.7],
[8.8, 0.1], [-8.7, -1.6], [10.8, 6.8], [-5.7, 6.5]
];
peoplePositions.forEach(([x, z], i) => {
addPerson(x, z, fountainBase, personColors[i % personColors.length], random() * Math.PI);
});
// -------------------------------------------------------------------------
// Lower colorful colonial houses
// -------------------------------------------------------------------------
function addHouse(x, z, width, depth, height, color, roofColor) {
const baseY = terrainHeight(x, z) + 0.05;
const wallMaterial = standard(color);
const roofMaterial = standard(roofColor, { side: THREE.DoubleSide });
box(width, height, depth, wallMaterial,
x, baseY + height / 2, z);
addGable(
width + 0.7,
depth + 0.7,
baseY + height,
baseY + height + Math.min(2.6, width * 0.38),
z,
roofMaterial
);
const windowSize = Math.min(0.8, width * 0.16);
const frontZ = z + depth / 2 + 0.025;
for (const side of [-1, 1]) {
box(
windowSize,
windowSize * 1.35,
0.06,
materials.dark,
x + side * width * 0.29,
baseY + height * 0.62,
frontZ
);
}
box(
width * 0.18,
height * 0.42,
0.07,
materials.ochre,
x,
baseY + height * 0.21,
frontZ + 0.015
);
box(
width + 0.18,
0.22,
depth + 0.15,
materials.ochreLight,
x,
baseY + height - 0.05,
z
);
}
const housePalette = [
[0xd9c18a, 0xa54d38],
[0xc87858, 0x813d35],
[0xe0b763, 0xa95338],
[0x86a8a1, 0x98523f],
[0xd5d0ad, 0x9c503b],
[0xb9856e, 0x76483b]
];
const houses = [
[-15, 12.5, 6.5, 6, 6.3],
[-23, 18, 7, 6.5, 7.2],
[-16, 24, 6.2, 5.7, 6],
[-24, 29, 7.4, 7, 7.5],
[-15, 35.5, 6.5, 6, 6.6],
[15.5, 16.5, 7.3, 6.4, 7],
[22.5, 22, 6.5, 6, 6.5],
[17, 29, 7.2, 6.5, 7.4],
[26, 35, 8, 6.7, 7.8],
[16, 42, 7.5, 6.5, 7],
[-25, 40, 7, 7, 7.3]
];
houses.forEach((house, i) => {
const colors = housePalette[i % housePalette.length];
addHouse(...house, ...colors);
});
addTree(-19, 14.5, terrainHeight(-19, 14.5), 1.05);
addTree(19, 18, terrainHeight(19, 18), 1.1);
addTree(-19, 31, terrainHeight(-19, 31), 1.0);
addTree(23, 29.5, terrainHeight(23, 29.5), 1.12);
addPalm(12.6, 38, terrainHeight(12.6, 38), 6.4);
addPalm(-21.5, 23, terrainHeight(-21.5, 23), 5.8);
// -------------------------------------------------------------------------
// Ocean and distant Recife skyline
// -------------------------------------------------------------------------
const ocean = new THREE.Mesh(
new THREE.PlaneGeometry(220, 95),
materials.ocean
);
ocean.rotation.x = -Math.PI / 2;
ocean.position.set(0, -1.65, -82);
ocean.receiveShadow = true;
scene.add(ocean);
box(106, 0.7, 15, standard(0xb2aa86), 0, -0.38, -69);
const skylineMaterials = [
standard(0x71868e),
standard(0x8fa0a1),
standard(0x657985),
standard(0xa4a9a2),
standard(0x788a91)
];
const windowMaterial = standard(0xb8d0c8, {
emissive: 0x547b7d,
emissiveIntensity: 0.18
});
for (let x = -53; x <= 53; x += 5.1) {
if (Math.abs(x) < 12) continue;
const width = 2.8 + random() * 2.5;
const depth = 3 + random() * 4;
const height = 5 + random() * 16;
const z = -66 - random() * 6.5;
const baseY = 0;
const building = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
skylineMaterials[Math.floor(random() * skylineMaterials.length)]
);
building.position.set(x, baseY + height / 2, z);
building.castShadow = true;
building.receiveShadow = true;
scene.add(building);
if (random() > 0.48) {
const topWidth = width * 0.58;
const topDepth = depth * 0.62;
const topHeight = 2 + random() * 4.5;
box(
topWidth,
topHeight,
topDepth,
building.material,
x,
baseY + height + topHeight / 2,
z
);
if (random() > 0.45) {
cylinder(
0.045,
0.065,
3.5 + random() * 2,
5,
materials.iron,
x,
baseY + height + topHeight + 1.7,
z
);
}
}
if (height > 12 && random() > 0.4) {
for (let floor = 2; floor < height - 1; floor += 2.4) {
box(
width * 0.72,
0.28,
0.035,
windowMaterial,
x,
floor,
z + depth / 2 + 0.025
);
}
}
}
// A few taller landmark forms for the distant silhouette.
box(4.2, 25, 4.8, skylineMaterials[2], 33, 12.5, -68);
box(3.2, 21, 4.2, skylineMaterials[0], 39.5, 10.5, -71);
cylinder(0.08, 0.12, 6, 6, materials.iron, 33, 28, -68);
box(5.2, 18, 4.5, skylineMaterials[3], -37, 9, -69);
// -------------------------------------------------------------------------
// Birds
// -------------------------------------------------------------------------
const birds = [];
function addBird(x, y, z, scale = 1) {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-0.65, 0, 0),
new THREE.Vector3(0, -0.28, 0),
new THREE.Vector3(0.65, 0, 0)
]);
const bird = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({ color: 0x4a5655 })
);
bird.position.set(x, y, z);
bird.scale.setScalar(scale);
scene.add(bird);
birds.push({ mesh: bird, baseX: x, phase: random() * Math.PI * 2 });
}
addBird(-13, 26, -35, 1.1);
addBird(-8, 28, -38, 0.8);
addBird(19, 24, -43, 0.9);
// -------------------------------------------------------------------------
// Custom camera controls: drag, pinch, wheel and keyboard
// -------------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 7.5, -10),
theta: 0.40,
phi: 1.03,
radius: 52,
desiredTheta: 0.40,
desiredPhi: 1.03,
desiredRadius: 52
};
const resetView = () => {
controls.desiredTheta = 0.40;
controls.desiredPhi = 1.03;
controls.desiredRadius = 52;
};
document.getElementById('reset').addEventListener('click', resetView);
const pointers = new Map();
let previousPinchDistance = 0;
renderer.domElement.addEventListener('pointerdown', event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
previousPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener('pointermove', event => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
controls.desiredTheta -= dx * 0.005;
controls.desiredPhi -= dy * 0.004;
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (previousPinchDistance > 0) {
controls.desiredRadius *=
previousPinchDistance / Math.max(1, distance);
}
previousPinchDistance = distance;
}
controls.desiredPhi = THREE.MathUtils.clamp(
controls.desiredPhi,
0.38,
1.43
);
controls.desiredRadius = THREE.MathUtils.clamp(
controls.desiredRadius,
25,
88
);
});
function removePointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = 0;
}
renderer.domElement.addEventListener('pointerup', removePointer);
renderer.domElement.addEventListener('pointercancel', removePointer);
renderer.domElement.addEventListener('lostpointercapture', removePointer);
renderer.domElement.addEventListener('wheel', event => {
event.preventDefault();
controls.desiredRadius *= Math.exp(event.deltaY * 0.001);
controls.desiredRadius = THREE.MathUtils.clamp(
controls.desiredRadius,
25,
88
);
}, { passive: false });
renderer.domElement.addEventListener('dblclick', resetView);
window.addEventListener('keydown', event => {
const key = event.key.toLowerCase();
if (key === 'arrowleft') controls.desiredTheta -= 0.12;
if (key === 'arrowright') controls.desiredTheta += 0.12;
if (key === 'arrowup') controls.desiredPhi -= 0.08;
if (key === 'arrowdown') controls.desiredPhi += 0.08;
if (key === '+' || key === '=') controls.desiredRadius -= 3;
if (key === '-') controls.desiredRadius += 3;
if (key === 'r') resetView();
controls.desiredPhi = THREE.MathUtils.clamp(
controls.desiredPhi,
0.38,
1.43
);
controls.desiredRadius = THREE.MathUtils.clamp(
controls.desiredRadius,
25,
88
);
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
controls.theta +=
(controls.desiredTheta - controls.theta) * (1 - Math.exp(-8 * delta));
controls.phi +=
(controls.desiredPhi - controls.phi) * (1 - Math.exp(-8 * delta));
controls.radius +=
(controls.desiredRadius - controls.radius) * (1 - Math.exp(-7 * delta));
const sinPhi = Math.sin(controls.phi);
const cosPhi = Math.cos(controls.phi);
camera.position.set(
controls.target.x +
controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * cosPhi,
controls.target.z +
controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
sky.position.copy(camera.position);
birds.forEach((bird, i) => {
bird.mesh.position.x =
bird.baseX + Math.sin(elapsed * 0.22 + bird.phase) * 2.2;
bird.mesh.position.y += Math.sin(elapsed * 1.8 + bird.phase) * 0.002;
bird.mesh.rotation.z =
Math.sin(elapsed * 2.2 + bird.phase) * 0.08;
});
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```