Prompt specification
Build or customize the Three.js 3D scene "São Luís tiled facade and window bay" 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: São Luís tiled facade and window bay
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/s-o-lu-s-tiled-facade-and-window-bay-x2705
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: São Luís tiled facade and window bay. Build one referenced tiled facade bay with window shutters and a narrow balcony. Use an original repeating tile motif inspired by local material character rather than copying a complete artwork. Return one self-contained HTML file.
Working Three.js Starter (s-o-lu-s-tiled-facade-and-window-bay-x2705):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#173e4b">
<title>Maré Azuleja — São Luís Facade Bay</title>
<style>
:root {
color-scheme: light;
--ink: #153c48;
--cream: #f5ead0;
--gold: #b78945;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 18% 12%, rgba(255, 242, 202, 0.95), transparent 30%),
linear-gradient(180deg, #a9d1d3 0%, #d9d8bc 48%, #e4c398 100%);
font-family: Georgia, "Times New Roman", serif;
}
canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.title-card {
position: fixed;
z-index: 2;
top: clamp(18px, 3vw, 38px);
left: clamp(18px, 3vw, 42px);
max-width: min(410px, calc(100vw - 36px));
padding: 19px 22px 17px;
color: var(--cream);
background: linear-gradient(135deg, rgba(15, 54, 65, 0.9), rgba(20, 69, 77, 0.72));
border: 1px solid rgba(245, 234, 208, 0.35);
box-shadow: 0 18px 48px rgba(31, 47, 46, 0.18);
backdrop-filter: blur(10px);
pointer-events: none;
}
.eyebrow {
margin: 0 0 7px;
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.28em;
text-transform: uppercase;
color: #e7c98f;
}
h1 {
margin: 0;
font-size: clamp(29px, 4vw, 45px);
font-weight: 400;
line-height: 0.98;
letter-spacing: 0.01em;
}
.subtitle {
margin: 12px 0 0;
max-width: 340px;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
line-height: 1.55;
color: rgba(245, 234, 208, 0.79);
}
.controls {
position: fixed;
z-index: 3;
right: clamp(16px, 2.5vw, 32px);
bottom: clamp(16px, 2.5vw, 30px);
display: flex;
align-items: center;
gap: 12px;
padding: 9px 10px 9px 15px;
border: 1px solid rgba(24, 66, 76, 0.22);
border-radius: 999px;
background: rgba(248, 239, 215, 0.78);
box-shadow: 0 10px 30px rgba(43, 48, 42, 0.13);
backdrop-filter: blur(9px);
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
color: var(--ink);
}
button {
appearance: none;
border: 0;
border-radius: 999px;
padding: 8px 13px;
color: #f6ead0;
background: var(--ink);
font: 700 10px/1 Arial, Helvetica, sans-serif;
letter-spacing: 0.12em;
text-transform: uppercase;
cursor: pointer;
transition: background 160ms ease, transform 160ms ease;
}
button:hover {
background: #245b68;
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid var(--gold);
outline-offset: 3px;
}
#loading {
position: fixed;
z-index: 5;
inset: 0;
display: grid;
place-items: center;
color: var(--ink);
background: #e4d4ad;
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
letter-spacing: 0.2em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 620px) {
.title-card {
padding: 15px 17px;
max-width: 290px;
}
.subtitle {
display: none;
}
.controls {
font-size: 0;
padding-left: 10px;
}
}
</style>
</head>
<body>
<div id="loading">Preparing the facade…</div>
<header class="title-card">
<p class="eyebrow">São Luís · Maranhão</p>
<h1>Maré Azuleja</h1>
<p class="subtitle">
An original geometric tile motif inspired by Atlantic colonial ceramics,
arranged around a shuttered window and a narrow iron balcony.
</p>
</header>
<div class="controls" aria-label="Scene controls">
<span>Drag to orbit · Scroll to zoom</span>
<button id="reset" type="button">Reset view</button>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const loading = document.getElementById("loading");
const resetButton = document.getElementById("reset");
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
} catch (error) {
loading.textContent = "WebGL is unavailable in this browser.";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0xbfd3cf, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Interactive three-dimensional tiled facade");
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xd7c59d, 15, 38);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
80
);
const target = new THREE.Vector3(0, 3.03, 0.12);
const cameraState = {
radius: window.innerWidth < 620 ? 12.2 : 9.5,
theta: 0.37,
phi: 1.34
};
const desiredState = { ...cameraState };
function updateCamera(instant = false) {
const amount = instant ? 1 : 0.085;
cameraState.radius = THREE.MathUtils.lerp(cameraState.radius, desiredState.radius, amount);
cameraState.theta = THREE.MathUtils.lerp(cameraState.theta, desiredState.theta, amount);
cameraState.phi = THREE.MathUtils.lerp(cameraState.phi, desiredState.phi, amount);
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
target.x + cameraState.radius * sinPhi * Math.sin(cameraState.theta),
target.y + cameraState.radius * Math.cos(cameraState.phi),
target.z + cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(target);
}
updateCamera(true);
const hemisphere = new THREE.HemisphereLight(0xffe8c0, 0x40515b, 1.8);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffd39a, 3.6);
sun.position.set(-5.5, 9.5, 7.5);
sun.target.position.set(0, 2.6, 0);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -9;
sun.shadow.camera.right = 9;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -3;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun, sun.target);
const facadeBounce = new THREE.DirectionalLight(0x8bc7d0, 0.65);
facadeBounce.position.set(7, 4, 5);
scene.add(facadeBounce);
const materials = {
stucco: new THREE.MeshStandardMaterial({
color: 0xd7c39b,
roughness: 0.92,
metalness: 0.01
}),
paleStone: new THREE.MeshStandardMaterial({
color: 0xc8b995,
roughness: 0.86
}),
darkStone: new THREE.MeshStandardMaterial({
color: 0x52696b,
roughness: 0.83
}),
cobalt: new THREE.MeshStandardMaterial({
color: 0x174f70,
roughness: 0.42,
metalness: 0.03
}),
teal: new THREE.MeshStandardMaterial({
color: 0x174d55,
roughness: 0.58
}),
tealLight: new THREE.MeshStandardMaterial({
color: 0x28636a,
roughness: 0.52
}),
iron: new THREE.MeshStandardMaterial({
color: 0x173a43,
roughness: 0.48,
metalness: 0.55
}),
brass: new THREE.MeshStandardMaterial({
color: 0xb88c47,
roughness: 0.38,
metalness: 0.68
}),
recess: new THREE.MeshStandardMaterial({
color: 0x14292c,
roughness: 0.82
}),
glass: new THREE.MeshStandardMaterial({
color: 0x213c3a,
roughness: 0.22,
metalness: 0.12,
emissive: 0x372016,
emissiveIntensity: 0.28
})
};
function addBox(parent, size, position, material, castShadow = true, receiveShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value = (1664525 * value + 1013904223) >>> 0;
return value / 4294967296;
};
}
const random = seededRandom(82741);
// Original ceramic motif: an eight-petal cobalt rosette, turquoise leaves,
// ochre accents, and a hand-painted-looking glazed border.
function makeTileTexture(variant) {
const canvas = document.createElement("canvas");
canvas.width = canvas.height = 256;
const ctx = canvas.getContext("2d");
const palettes = [
{
cream: "#eee2bf",
cobalt: "#15547c",
turquoise: "#318d91",
ochre: "#bd8741",
glaze: "rgba(255,255,255,0.22)"
},
{
cream: "#e8dbb8",
cobalt: "#174d73",
turquoise: "#3b8586",
ochre: "#c18e48",
glaze: "rgba(255,244,205,0.18)"
},
{
cream: "#f1e5c5",
cobalt: "#1d5b7b",
turquoise: "#2a7f88",
ochre: "#b67e3e",
glaze: "rgba(255,255,255,0.24)"
},
{
cream: "#eadbb9",
cobalt: "#184c71",
turquoise: "#459193",
ochre: "#c2914b",
glaze: "rgba(255,240,196,0.2)"
}
];
const p = palettes[variant % palettes.length];
ctx.fillStyle = "#aa9976";
ctx.fillRect(0, 0, 256, 256);
ctx.fillStyle = p.cream;
ctx.fillRect(4, 4, 248, 248);
ctx.strokeStyle = p.cobalt;
ctx.lineWidth = 7;
ctx.strokeRect(12, 12, 232, 232);
ctx.strokeStyle = p.ochre;
ctx.lineWidth = 2;
ctx.strokeRect(22, 22, 212, 212);
ctx.save();
ctx.translate(128, 128);
for (let i = 0; i < 8; i++) {
ctx.save();
ctx.rotate((i * Math.PI) / 4);
ctx.fillStyle = p.cobalt;
ctx.beginPath();
ctx.moveTo(0, -18);
ctx.bezierCurveTo(-22, -31, -18, -72, 0, -88);
ctx.bezierCurveTo(18, -72, 22, -31, 0, -18);
ctx.fill();
ctx.fillStyle = p.turquoise;
ctx.beginPath();
ctx.moveTo(0, -29);
ctx.bezierCurveTo(-8, -39, -8, -62, 0, -72);
ctx.bezierCurveTo(8, -62, 8, -39, 0, -29);
ctx.fill();
ctx.restore();
}
for (let i = 0; i < 4; i++) {
ctx.save();
ctx.rotate(Math.PI / 4 + (i * Math.PI) / 2);
ctx.fillStyle = p.ochre;
ctx.beginPath();
ctx.moveTo(0, -61);
ctx.lineTo(13, -79);
ctx.lineTo(0, -96);
ctx.lineTo(-13, -79);
ctx.closePath();
ctx.fill();
ctx.restore();
}
ctx.fillStyle = p.ochre;
ctx.beginPath();
ctx.arc(0, 0, 23, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = p.cobalt;
ctx.beginPath();
ctx.arc(0, 0, 11, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = p.cream;
ctx.beginPath();
ctx.arc(-4, -4, 3.5, 0, Math.PI * 2);
ctx.fill();
ctx.restore();
// Small glaze streaks and firing variation.
ctx.globalAlpha = 0.2;
ctx.strokeStyle = p.glaze;
ctx.lineWidth = 3;
ctx.beginPath();
ctx.moveTo(31, 45);
ctx.bezierCurveTo(21, 92, 38, 153, 27, 218);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(220, 39);
ctx.bezierCurveTo(211, 89, 230, 155, 218, 219);
ctx.stroke();
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
texture.minFilter = THREE.LinearMipmapLinearFilter;
texture.magFilter = THREE.LinearFilter;
return texture;
}
function makeMedallionTexture() {
const canvas = document.createElement("canvas");
canvas.width = canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 256, 256);
ctx.fillStyle = "#eadbb7";
ctx.beginPath();
ctx.arc(128, 128, 111, 0, Math.PI * 2);
ctx.fill();
ctx.strokeStyle = "#1b5273";
ctx.lineWidth = 13;
ctx.beginPath();
ctx.arc(128, 128, 101, 0, Math.PI * 2);
ctx.stroke();
ctx.strokeStyle = "#b88a45";
ctx.lineWidth = 4;
ctx.beginPath();
ctx.arc(128, 128, 86, 0, Math.PI * 2);
ctx.stroke();
ctx.save();
ctx.translate(128, 128);
for (let i = 0; i < 8; i++) {
ctx.rotate(Math.PI / 4);
ctx.fillStyle = i % 2 ? "#31898a" : "#19587b";
ctx.beginPath();
ctx.ellipse(0, -43, 14, 34, 0, 0, Math.PI * 2);
ctx.fill();
}
ctx.fillStyle = "#bc8943";
ctx.beginPath();
ctx.arc(0, 0, 24, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = "#eadbb7";
ctx.beginPath();
ctx.arc(0, 0, 9, 0, Math.PI * 2);
ctx.fill();
ctx.restore();
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
// Main wall and deep returns.
addBox(scene, [6.4, 6.4, 0.48], [0, 3.16, -0.24], materials.stucco);
addBox(scene, [0.22, 6.4, 1.28], [-3.12, 3.16, -0.64], materials.stucco);
addBox(scene, [0.22, 6.4, 1.28], [3.12, 3.16, -0.64], materials.stucco);
// Grout field behind the individually glazed tiles.
addBox(
scene,
[6.0, 5.7, 0.018],
[0, 3.15, 0.012],
new THREE.MeshStandardMaterial({ color: 0x9d8965, roughness: 0.92 }),
false,
true
);
const tileGeometry = new THREE.PlaneGeometry(0.238, 0.238);
const tileCells = [[], [], [], []];
const columns = 24;
const rows = 23;
const pitch = 0.25;
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const x = (column - (columns - 1) / 2) * pitch;
const y = 0.4 + row * pitch;
// Leave the central opening for the recessed window.
if (Math.abs(x) < 0.91 && y > 2.48 && y < 5.12) {
continue;
}
const variant = Math.floor(random() * 4);
tileCells[variant].push({
x,
y,
rotation: (random() - 0.5) * 0.012,
z: 0.031 + (random() - 0.5) * 0.006,
shade: 0.94 + random() * 0.08
});
}
}
tileCells.forEach((cells, variant) => {
const tileMaterial = new THREE.MeshStandardMaterial({
map: makeTileTexture(variant),
roughness: 0.31,
metalness: 0.025
});
const mesh = new THREE.InstancedMesh(tileGeometry, tileMaterial, cells.length);
const dummy = new THREE.Object3D();
const color = new THREE.Color();
cells.forEach((cell, index) => {
dummy.position.set(cell.x, cell.y, cell.z);
dummy.rotation.set(0, 0, cell.rotation);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
color.setRGB(cell.shade, cell.shade, cell.shade * 0.985);
mesh.setColorAt(index, color);
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.receiveShadow = true;
scene.add(mesh);
});
// Stucco borders, stone plinth, and layered cornice.
addBox(scene, [0.13, 5.82, 0.12], [-3.03, 3.15, 0.06], materials.paleStone);
addBox(scene, [0.13, 5.82, 0.12], [3.03, 3.15, 0.06], materials.paleStone);
addBox(scene, [6.18, 0.12, 0.12], [0, 6.02, 0.06], materials.paleStone);
addBox(scene, [6.48, 0.31, 0.72], [0, 0.17, 0.08], materials.paleStone);
addBox(scene, [6.48, 0.08, 0.76], [0, 0.36, 0.09], materials.darkStone);
addBox(scene, [6.7, 0.14, 0.76], [0, 6.26, 0.1], materials.paleStone);
addBox(scene, [6.48, 0.13, 0.62], [0, 6.11, 0.06], materials.paleStone);
addBox(scene, [6.24, 0.22, 0.44], [0, 6.46, -0.02], materials.stucco);
addBox(scene, [6.4, 0.13, 0.58], [0, 6.63, 0.0], materials.paleStone);
const dentilGeometry = new THREE.BoxGeometry(0.17, 0.15, 0.3);
const dentils = new THREE.InstancedMesh(dentilGeometry, materials.paleStone, 16);
const dummy = new THREE.Object3D();
for (let i = 0; i < 16; i++) {
dummy.position.set(-2.85 + i * 0.38, 6.01, 0.22);
dummy.updateMatrix();
dentils.setMatrixAt(i, dummy.matrix);
}
dentils.castShadow = true;
dentils.receiveShadow = true;
scene.add(dentils);
// Window recess and frame.
addBox(scene, [1.78, 2.49, 0.035], [0, 3.78, 0.05], materials.recess, false, false);
addBox(scene, [1.5, 2.25, 0.028], [0, 3.79, 0.076], materials.glass, false, false);
addBox(scene, [0.13, 2.62, 0.18], [-0.89, 3.78, 0.11], materials.teal);
addBox(scene, [0.13, 2.62, 0.18], [0.89, 3.78, 0.11], materials.teal);
addBox(scene, [1.9, 0.13, 0.19], [0, 5.02, 0.12], materials.teal);
addBox(scene, [1.9, 0.15, 0.22], [0, 2.54, 0.13], materials.teal);
addBox(scene, [0.065, 2.31, 0.12], [0, 3.79, 0.15], materials.tealLight);
addBox(scene, [1.48, 0.065, 0.12], [0, 3.79, 0.15], materials.tealLight);
// Warm interior slivers behind the glazing.
const curtainMaterial = new THREE.MeshStandardMaterial({
color: 0x8a4f35,
roughness: 0.92,
emissive: 0x3a1d0e,
emissiveIntensity: 0.16
});
addBox(scene, [0.25, 2.14, 0.025], [-0.56, 3.79, 0.095], curtainMaterial, false, false);
addBox(scene, [0.25, 2.14, 0.025], [0.56, 3.79, 0.095], curtainMaterial, false, false);
const interiorLight = new THREE.PointLight(0xffa657, 13, 3.1, 2);
interiorLight.position.set(0, 3.7, 0.68);
scene.add(interiorLight);
function makeShutter(side) {
const group = new THREE.Group();
const width = 0.74;
const height = 2.29;
const centerX = -side * width / 2;
group.position.set(side * 0.86, 3.78, 0.19);
group.rotation.y = side < 0 ? -0.4 : 0.29;
addBox(group, [width, height, 0.075], [centerX, 0, 0], materials.teal);
for (let i = 0; i < 11; i++) {
const slat = addBox(
group,
[width - 0.13, 0.095, 0.07],
[centerX, -0.94 + i * 0.188, 0.075],
materials.tealLight
);
slat.rotation.x = -0.18;
}
addBox(
group,
[0.075, height - 0.08, 0.105],
[centerX - side * (width / 2 - 0.038), 0, 0.047],
materials.tealLight
);
addBox(
group,
[0.075, height - 0.08, 0.105],
[centerX + side * (width / 2 - 0.038), 0, 0.047],
materials.tealLight
);
addBox(group, [width, 0.09, 0.105], [centerX, height / 2 - 0.045, 0.047], materials.tealLight);
addBox(group, [width, 0.09, 0.105], [centerX, -height / 2 + 0.045, 0.047], materials.tealLight);
const handleX = centerX - side * (width / 2 - 0.12);
addBox(group, [0.065, 0.22, 0.055], [handleX, -0.05, 0.14], materials.brass);
const handle = new THREE.Mesh(new THREE.SphereGeometry(0.055, 12, 8), materials.brass);
handle.position.set(handleX, -0.12, 0.17);
handle.castShadow = true;
group.add(handle);
for (const y of [-0.72, 0.72]) {
const hinge = new THREE.Mesh(new THREE.CylinderGeometry(0.035, 0.035, 0.2, 12), materials.brass);
hinge.position.set(0, y, -0.015);
hinge.castShadow = true;
group.add(hinge);
}
scene.add(group);
}
makeShutter(-1);
makeShutter(1);
// Small ceramic medallion above the window.
const medallion = new THREE.Mesh(
new THREE.PlaneGeometry(0.57, 0.57),
new THREE.MeshStandardMaterial({
map: makeMedallionTexture(),
transparent: true,
roughness: 0.34,
side: THREE.DoubleSide
})
);
medallion.position.set(0, 5.53, 0.11);
medallion.castShadow = true;
scene.add(medallion);
// Narrow stone balcony.
addBox(scene, [2.25, 0.14, 0.88], [0, 2.43, 0.4], materials.paleStone);
addBox(scene, [2.25, 0.075, 0.055], [0, 2.45, 0.855], materials.cobalt);
addBox(scene, [0.18, 0.38, 0.52], [-0.72, 2.18, 0.22], materials.paleStone);
addBox(scene, [0.18, 0.38, 0.52], [0.72, 2.18, 0.22], materials.paleStone);
const railBottom = 2.56;
const railTop = 3.17;
const railFrontZ = 0.82;
const railHalfWidth = 1.03;
function cylinderBetween(parent, radius, length, position, rotation, material) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 10),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.rotation.set(rotation[0], rotation[1], rotation[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
cylinderBetween(
scene,
0.035,
railHalfWidth * 2,
[0, railTop, railFrontZ],
[0, 0, Math.PI / 2],
materials.iron
);
cylinderBetween(
scene,
0.025,
railHalfWidth * 2,
[0, railBottom, railFrontZ],
[0, 0, Math.PI / 2],
materials.iron
);
for (let i = 0; i <= 10; i++) {
const x = -railHalfWidth + (i / 10) * railHalfWidth * 2;
cylinderBetween(
scene,
0.018,
railTop - railBottom,
[x, (railTop + railBottom) / 2, railFrontZ],
[0, 0, 0],
materials.iron
);
}
for (const side of [-1, 1]) {
cylinderBetween(
scene,
0.03,
0.79,
[side * railHalfWidth, railTop, 0.43],
[Math.PI / 2, 0, 0],
materials.iron
);
cylinderBetween(
scene,
0.022,
0.79,
[side * railHalfWidth, railBottom, 0.43],
[Math.PI / 2, 0, 0],
materials.iron
);
for (let i = 0; i < 4; i++) {
cylinderBetween(
scene,
0.015,
railTop - railBottom,
[side * railHalfWidth, (railTop + railBottom) / 2, 0.13 + i * 0.2],
[0, 0, 0],
materials.iron
);
}
}
const centerRing = new THREE.Mesh(new THREE.TorusGeometry(0.105, 0.018, 8, 32), materials.brass);
centerRing.position.set(0, 2.86, 0.84);
centerRing.castShadow = true;
scene.add(centerRing);
const centerDiamond = new THREE.Mesh(new THREE.OctahedronGeometry(0.065), materials.brass);
centerDiamond.position.set(0, 2.86, 0.86);
centerDiamond.scale.z = 0.35;
centerDiamond.castShadow = true;
scene.add(centerDiamond);
// A discreet drainpipe reinforces the facade's scale.
const drainMaterial = new THREE.MeshStandardMaterial({
color: 0x526267,
roughness: 0.55,
metalness: 0.4
});
cylinderBetween(scene, 0.045, 5.95, [2.77, 3.1, 0.24], [0, 0, 0], drainMaterial);
for (const y of [0.48, 2.15, 3.85, 5.7]) {
const clamp = new THREE.Mesh(new THREE.TorusGeometry(0.06, 0.013, 6, 12), drainMaterial);
clamp.position.set(2.77, y, 0.25);
clamp.rotation.y = Math.PI / 2;
scene.add(clamp);
}
// Quiet neighboring façades create an urban context without competing
// with the tiled bay.
function makeNeighbor(x, width, height, bodyColor, trimColor) {
const group = new THREE.Group();
const bodyMaterial = new THREE.MeshStandardMaterial({
color: bodyColor,
roughness: 0.92
});
const trimMaterial = new THREE.MeshStandardMaterial({
color: trimColor,
roughness: 0.82
});
addBox(group, [width, height, 2.8], [x, height / 2, -1.45], bodyMaterial);
addBox(group, [width + 0.2, 0.19, 3.0], [x, height - 0.03, -1.4], trimMaterial);
addBox(group, [width + 0.12, 0.28, 2.94], [x, 0.18, -1.4], trimMaterial);
const windowMaterial = new THREE.MeshStandardMaterial({
color: 0x304445,
roughness: 0.75
});
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 2; col++) {
const wx = x + (col - 0.5) * width * 0.43;
const wy = 1.7 + row * 1.85;
addBox(group, [0.7, 1.15, 0.035], [wx, wy, -0.025], windowMaterial, false, false);
addBox(group, [0.84, 0.09, 0.18], [wx, wy + 0.61, 0.015], trimMaterial);
addBox(group, [0.055, 1.13, 0.08], [wx, wy, 0.02], trimMaterial);
addBox(group, [0.7, 0.045, 0.08], [wx, wy, 0.02], trimMaterial);
}
}
scene.add(group);
}
makeNeighbor(-5.25, 3.25, 5.65, 0xa96f58, 0xd0a77e);
makeNeighbor(5.05, 3.45, 5.15, 0xc19a62, 0xe0c28c);
// Pavement and street.
const streetMaterial = new THREE.MeshStandardMaterial({
color: 0x77776d,
roughness: 0.96
});
const sidewalkMaterial = new THREE.MeshStandardMaterial({
color: 0xb7aa8d,
roughness: 0.94
});
const ground = new THREE.Mesh(new THREE.PlaneGeometry(80, 80), streetMaterial);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.12;
ground.receiveShadow = true;
scene.add(ground);
addBox(scene, [30, 0.18, 1.8], [0, -0.03, 0.9], sidewalkMaterial, false, true);
for (let x = -14; x <= 14; x += 1.8) {
addBox(
scene,
[0.018, 0.008, 1.72],
[x, 0.064, 0.9],
new THREE.MeshStandardMaterial({ color: 0x95896f, roughness: 1 }),
false,
false
);
}
const cobbleGeometry = new THREE.BoxGeometry(0.43, 0.075, 0.29);
const cobbleMaterial = new THREE.MeshStandardMaterial({
color: 0x8b897c,
roughness: 0.98
});
const cobbleCount = 32 * 9;
const cobbles = new THREE.InstancedMesh(cobbleGeometry, cobbleMaterial, cobbleCount);
const cobbleDummy = new THREE.Object3D();
const cobbleColor = new THREE.Color();
for (let row = 0; row < 9; row++) {
for (let column = 0; column < 32; column++) {
const index = row * 32 + column;
const x = (column - 15.5) * 0.47 + (row % 2) * 0.22;
const z = 1.95 + row * 0.34 + (random() - 0.5) * 0.025;
const shade = 0.78 + random() * 0.2;
cobbleDummy.position.set(x, -0.057 + random() * 0.008, z);
cobbleDummy.rotation.set(0, (random() - 0.5) * 0.055, 0);
cobbleDummy.scale.set(0.91 + random() * 0.13, 1, 0.9 + random() * 0.15);
cobbleDummy.updateMatrix();
cobbles.setMatrixAt(index, cobbleDummy.matrix);
cobbleColor.setRGB(shade, shade * 0.98, shade * 0.91);
cobbles.setColorAt(index, cobbleColor);
}
}
cobbles.instanceMatrix.needsUpdate = true;
if (cobbles.instanceColor) cobbles.instanceColor.needsUpdate = true;
cobbles.receiveShadow = true;
scene.add(cobbles);
// Direct, dependency-free camera controls.
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
desiredState.theta = THREE.MathUtils.clamp(
desiredState.theta - dx * 0.005,
-1.05,
1.05
);
desiredState.phi = THREE.MathUtils.clamp(
desiredState.phi + dy * 0.004,
0.88,
1.54
);
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredState.radius = THREE.MathUtils.clamp(
desiredState.radius * Math.exp(event.deltaY * 0.001),
5.7,
16
);
},
{ passive: false }
);
function resetView() {
desiredState.radius = window.innerWidth < 620 ? 12.2 : 9.5;
desiredState.theta = 0.37;
desiredState.phi = 1.34;
}
resetButton.addEventListener("click", resetView);
renderer.domElement.addEventListener("dblclick", resetView);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.fov = window.innerWidth < 620 ? 49 : 39;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
if (window.innerWidth < 620) {
camera.fov = 49;
camera.updateProjectionMatrix();
}
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const smoothing = 1 - Math.pow(0.001, delta);
cameraState.radius = THREE.MathUtils.lerp(
cameraState.radius,
desiredState.radius,
smoothing
);
cameraState.theta = THREE.MathUtils.lerp(
cameraState.theta,
desiredState.theta,
smoothing
);
cameraState.phi = THREE.MathUtils.lerp(
cameraState.phi,
desiredState.phi,
smoothing
);
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
target.x + cameraState.radius * sinPhi * Math.sin(cameraState.theta),
target.y + cameraState.radius * Math.cos(cameraState.phi),
target.z + cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(target);
renderer.render(scene, camera);
}
renderer.render(scene, camera);
requestAnimationFrame(() => loading.classList.add("hidden"));
animate();
</script>
</body>
</html>
```