Prompt specification
Build or customize the Three.js 3D scene "Old San Juan wall and street 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: Old San Juan wall and street slice
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/old-san-juan-wall-and-street-slice-x2787
Scene Description Prompt:
Old San Juan wall and street slice. Build a bounded voxel scene with referenced colorful facades, a section of city wall, and coastal edge. Preserve the contrast between compact streets and open water views. Please build this with Three.js from cdnjs in one self-contained HTML file, using visible voxel blocks.
Working Three.js Starter (old-san-juan-wall-and-street-slice-x2787):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Old San Juan — Voxel Coastal Diorama</title>
<style>
:root {
--ink: #173f43;
--paper: rgba(255, 250, 238, 0.9);
--coral: #d96455;
--gold: #e2a83e;
--aqua: #3f9c98;
--blue: #4c6fa6;
--sand: #bba579;
--sea: #3f9fb0;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9e7e3;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
.title-card {
position: fixed;
top: 24px;
left: 24px;
z-index: 5;
width: min(360px, calc(100vw - 48px));
padding: 18px 20px 16px;
border: 1px solid rgba(23, 63, 67, 0.14);
border-radius: 5px;
background: var(--paper);
box-shadow: 0 12px 35px rgba(26, 70, 73, 0.13);
backdrop-filter: blur(9px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: #477478;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 3vw, 38px);
font-weight: 700;
line-height: 1;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 14px;
color: #547578;
font-size: 12px;
line-height: 1.45;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 13px;
padding-top: 12px;
border-top: 1px solid rgba(23, 63, 67, 0.12);
color: #315d60;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 5px;
}
.dot {
width: 8px;
height: 8px;
border-radius: 1px;
background: var(--coral);
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.dot.wall {
background: var(--sand);
}
.dot.sea {
background: var(--sea);
}
.controls {
position: fixed;
right: 22px;
bottom: 20px;
z-index: 5;
display: flex;
align-items: center;
gap: 12px;
padding: 9px 10px 9px 13px;
border: 1px solid rgba(23, 63, 67, 0.13);
border-radius: 4px;
background: rgba(255, 250, 238, 0.82);
color: #4e7072;
box-shadow: 0 8px 22px rgba(26, 70, 73, 0.1);
backdrop-filter: blur(8px);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.02em;
}
#reset {
border: 0;
border-radius: 3px;
padding: 7px 10px;
background: #214f52;
color: #fff9eb;
font: inherit;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
}
#reset:hover {
background: #173f43;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #d9e7e3;
color: #28585b;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 0.5s ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
.title-card {
top: 14px;
left: 14px;
width: min(315px, calc(100vw - 28px));
padding: 14px 15px;
}
.subtitle {
margin-bottom: 10px;
}
.controls {
right: 12px;
bottom: 12px;
}
.controls .desktop-hint {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<section class="title-card">
<div class="eyebrow">Puerto Rico · Voxel Study</div>
<h1>Old San Juan</h1>
<p class="subtitle">
A narrow colonial street, sun-washed facades, the old city wall, and an open
Caribbean edge.
</p>
<div class="legend">
<span><i class="dot"></i> Colorful facades</span>
<span><i class="dot wall"></i> City wall</span>
<span><i class="dot sea"></i> Open water</span>
</div>
</section>
<div class="controls">
<span class="desktop-hint">Drag to orbit · Scroll to zoom · Shift-drag to pan</span>
<button id="reset" type="button">Reset view</button>
</div>
<div id="loading">Building the coastal diorama…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#d9e7e3");
scene.fog = new THREE.Fog("#d9e7e3", 65, 110);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-20, 20, 14, -14, 0.1, 150);
const hemisphere = new THREE.HemisphereLight("#e5fbff", "#806a4d", 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff1d0", 3.25);
sun.position.set(-13, 27, 17);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -29;
sun.shadow.camera.right = 29;
sun.shadow.camera.top = 29;
sun.shadow.camera.bottom = -29;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 75;
sun.shadow.bias = -0.00045;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight("#8bd3dd", 0.55);
fill.position.set(22, 10, -18);
scene.add(fill);
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
const dummy = new THREE.Object3D();
const staticBlocks = [];
const glowBlocks = [];
const waterBlocks = [];
let seed = 739391;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
const toneCache = new Map();
function tone(hex, amount = 0) {
const key = `${hex}:${amount.toFixed(3)}`;
if (toneCache.has(key)) return toneCache.get(key);
const color = new THREE.Color(hex);
color.offsetHSL(0, 0, amount);
const result = `#${color.getHexString()}`;
toneCache.set(key, result);
return result;
}
function addBlock(x, y, z, sx, sy, sz, color) {
staticBlocks.push({ x, y, z, sx, sy, sz, color });
}
function addGlow(x, y, z, sx, sy, sz, color = "#ffd779") {
glowBlocks.push({ x, y, z, sx, sy, sz, color });
}
function addWater(x, y, z, sx, sy, sz, color, phase = random() * Math.PI * 2) {
waterBlocks.push({ x, y, z, sx, sy, sz, color, phase });
}
function createInstancedMesh(blocks, material, shadows = true) {
const mesh = new THREE.InstancedMesh(cubeGeometry, material, blocks.length);
blocks.forEach((block, index) => {
dummy.position.set(block.x, block.y, block.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(block.sx, block.sy, block.sz);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
mesh.setColorAt(index, new THREE.Color(block.color));
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = shadows;
mesh.receiveShadow = shadows;
mesh.computeBoundingSphere();
scene.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Bounded diorama base
// -------------------------------------------------------------------------
addBlock(0, -1.25, 0, 32.4, 1.2, 22.8, "#345b60");
addBlock(0, -1.86, 0, 32.55, 0.16, 22.95, "#294b50");
addBlock(-4.25, -0.34, 0, 23.9, 0.68, 22, "#c5aa79");
// Sand and stone edge along the land side of the base.
for (let x = -15.8; x < 7.6; x += 0.9) {
addBlock(x, 0.02, 10.95, 0.82, 0.16, 0.18, "#ddca98");
addBlock(x, 0.02, -10.95, 0.82, 0.16, 0.18, "#b99b6f");
}
// Studio floor receives the diorama's shadow.
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(180, 180),
new THREE.MeshStandardMaterial({
color: "#d9e7e3",
roughness: 1,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.96;
floor.receiveShadow = true;
scene.add(floor);
// -------------------------------------------------------------------------
// Compact cobbled street
// -------------------------------------------------------------------------
const cobbleColors = ["#817b73", "#8b8278", "#756f69", "#9a8d7e", "#77736e"];
for (let z = -9.55; z <= 10.25; z += 0.68) {
for (let x = -2.36; x <= 2.36; x += 0.68) {
addBlock(
x,
0.055,
z,
0.59,
0.11,
0.59,
tone(cobbleColors[Math.floor(random() * cobbleColors.length)], (random() - 0.5) * 0.08)
);
}
}
// Raised curb stones emphasize the narrowness of the street.
for (let z = -9.4; z <= 10.2; z += 0.76) {
addBlock(-2.61, 0.14, z, 0.18, 0.28, 0.68, "#b9ae96");
addBlock(2.61, 0.14, z, 0.18, 0.28, 0.68, "#b9ae96");
}
// Small drainage grates.
for (const z of [-5.6, 1.1, 6.7]) {
for (let i = 0; i < 4; i++) {
addBlock(-0.34 + i * 0.22, 0.13, z, 0.1, 0.07, 0.6, "#3e4a49");
}
}
// -------------------------------------------------------------------------
// Voxel masonry helpers
// -------------------------------------------------------------------------
function brickFaceX(plane, z0, z1, y0, y1, color) {
let row = 0;
for (let y = y0 + 0.36; y < y1 - 0.2; y += 0.72, row++) {
let p = z0 + (row % 2 ? 0.43 : 0.04);
while (p < z1 - 0.18) {
const length = Math.min(0.82, z1 - p);
if (length > 0.24) {
addBlock(
plane + 0.055,
y,
p + length / 2,
0.13,
0.63,
length - 0.055,
tone(color, (random() - 0.5) * 0.095)
);
}
p += 0.88;
}
}
}
function brickFaceZ(plane, x0, x1, y0, y1, color) {
let row = 0;
for (let y = y0 + 0.36; y < y1 - 0.2; y += 0.72, row++) {
let p = x0 + (row % 2 ? 0.43 : 0.04);
while (p < x1 - 0.18) {
const length = Math.min(0.82, x1 - p);
if (length > 0.24) {
addBlock(
p + length / 2,
y,
plane + 0.055,
length - 0.055,
0.63,
0.13,
tone(color, (random() - 0.5) * 0.095)
);
}
p += 0.88;
}
}
}
function addEastWindow(plane, z, y, accent, shutter = true) {
addBlock(plane + 0.17, y, z, 0.13, 1.12, 0.72, "#263d42");
addBlock(plane + 0.255, y, z - 0.42, 0.12, 1.31, 0.1, "#f0dfb9");
addBlock(plane + 0.255, y, z + 0.42, 0.12, 1.31, 0.1, "#f0dfb9");
addBlock(plane + 0.255, y + 0.61, z, 0.12, 0.1, 0.94, "#f0dfb9");
addBlock(plane + 0.255, y - 0.61, z, 0.12, 0.1, 0.94, "#f0dfb9");
addBlock(plane + 0.27, y, z, 0.13, 0.075, 0.82, "#d6c39d");
if (shutter) {
addBlock(plane + 0.24, y, z - 0.56, 0.14, 1.08, 0.21, accent);
addBlock(plane + 0.24, y, z + 0.56, 0.14, 1.08, 0.21, accent);
}
}
function addSouthWindow(plane, x, y, accent) {
addBlock(x, y, plane + 0.17, 0.72, 1.12, 0.13, "#263d42");
addBlock(x - 0.42, y, plane + 0.255, 0.1, 1.31, 0.12, "#f0dfb9");
addBlock(x + 0.42, y, plane + 0.255, 0.1, 1.31, 0.12, "#f0dfb9");
addBlock(x, y + 0.61, plane + 0.255, 0.94, 0.1, 0.12, "#f0dfb9");
addBlock(x, y - 0.61, plane + 0.255, 0.94, 0.1, 0.12, "#f0dfb9");
addBlock(x - 0.56, y, plane + 0.24, 0.21, 1.08, 0.14, accent);
addBlock(x + 0.56, y, plane + 0.24, 0.21, 1.08, 0.14, accent);
}
function addBalcony(plane, z, y, color = "#315356") {
addBlock(plane + 0.43, y - 0.72, z, 0.86, 0.13, 1.38, "#ddcfad");
addBlock(plane + 0.81, y - 0.37, z, 0.09, 0.09, 1.38, color);
addBlock(plane + 0.81, y - 0.35, z - 0.63, 0.09, 0.68, 0.09, color);
addBlock(plane + 0.81, y - 0.35, z + 0.63, 0.09, 0.68, 0.09, color);
}
function addEastDoor(plane, z, accent) {
addBlock(plane + 0.17, 1.04, z, 0.14, 1.98, 0.84, "#314344");
addBlock(plane + 0.26, 1.04, z - 0.49, 0.13, 2.18, 0.12, "#f0dfb9");
addBlock(plane + 0.26, 1.04, z + 0.49, 0.13, 2.18, 0.12, "#f0dfb9");
addBlock(plane + 0.26, 2.05, z, 0.13, 0.13, 1.08, "#f0dfb9");
addBlock(plane + 0.3, 0.13, z, 0.52, 0.26, 1.2, "#c2b59a");
addBlock(plane + 0.35, 2.27, z, 0.18, 0.28, 0.62, accent);
}
function addRoofDetails(x0, x1, z0, z1, height, color, chimney = true) {
const centerX = (x0 + x1) / 2;
const centerZ = (z0 + z1) / 2;
const depth = x1 - x0;
const width = z1 - z0;
// Flat roof deck and terracotta roof pixels.
addBlock(centerX, height + 0.035, centerZ, depth - 0.2, 0.15, width - 0.2, "#bd654c");
for (let x = x0 + 0.45; x < x1 - 0.35; x += 0.77) {
for (let z = z0 + 0.45; z < z1 - 0.35; z += 0.77) {
addBlock(
x,
height + 0.17,
z,
0.68,
0.12,
0.68,
tone("#b85f48", (random() - 0.5) * 0.11)
);
}
}
// Segmented parapet around the roof.
for (let z = z0 + 0.12; z < z1; z += 0.78) {
const length = Math.min(0.72, z1 - z);
addBlock(x0 + 0.09, height + 0.45, z + length / 2, 0.19, 0.6, length, "#eadbb5");
addBlock(x1 - 0.09, height + 0.45, z + length / 2, 0.19, 0.6, length, "#eadbb5");
}
for (let x = x0 + 0.15; x < x1; x += 0.78) {
const length = Math.min(0.72, x1 - x);
addBlock(x + length / 2, height + 0.45, z0 + 0.09, length, 0.6, 0.19, "#eadbb5");
addBlock(x + length / 2, height + 0.45, z1 - 0.09, length, 0.6, 0.19, "#eadbb5");
}
// Cream cornice.
for (let z = z0 + 0.2; z < z1; z += 0.82) {
const length = Math.min(0.77, z1 - z);
addBlock(x1 + 0.02, height - 0.11, z + length / 2, 0.22, 0.19, length, "#edddba");
}
if (chimney) {
addBlock(x0 + 0.9, height + 0.62, z0 + width * 0.58, 0.5, 1.0, 0.55, "#d7c6a3");
addBlock(x0 + 0.9, height + 1.16, z0 + width * 0.58, 0.62, 0.16, 0.67, "#eee0bd");
}
}
function buildBuilding({
x0,
x1,
z0,
z1,
height,
color,
accent,
balcony = true,
chimney = true
}) {
const centerX = (x0 + x1) / 2;
const centerZ = (z0 + z1) / 2;
const depth = x1 - x0;
const width = z1 - z0;
// Main masonry mass.
addBlock(
centerX,
height / 2 + 0.04,
centerZ,
depth - 0.04,
height,
width - 0.04,
tone(color, -0.035)
);
// Camera-facing east and south facades.
brickFaceX(x1, z0, z1, 0.12, height - 0.12, color);
brickFaceZ(z1, x0, x1, 0.12, height - 0.12, color);
addEastDoor(x1, centerZ, accent);
const windowZ = width > 3.05
? [z0 + 0.73, z1 - 0.73]
: [centerZ];
const levels = [1.68, 3.45, 5.22, 6.99];
levels.forEach((y, levelIndex) => {
if (y > height - 0.62) return;
for (const z of windowZ) {
if (levelIndex === 0 && Math.abs(z - centerZ) < 0.61) continue;
addEastWindow(x1, z, y, accent, (levelIndex + Math.round(z)) % 3 !== 0);
}
if (balcony && (levelIndex === 1 || levelIndex === 2)) {
addBalcony(x1, centerZ, y, accent);
}
});
// Windows on the visible south-facing end walls.
const southLevels = [1.75, 3.55, 5.35];
for (const y of southLevels) {
if (y > height - 0.65) continue;
const count = depth > 7 ? 3 : 2;
for (let i = 0; i < count; i++) {
const x = x0 + depth * ((i + 0.7) / (count + 0.4));
addSouthWindow(z1, x, y, accent);
}
}
addRoofDetails(x0, x1, z0, z1, height, color, chimney);
}
// -------------------------------------------------------------------------
// Colorful colonial facades lining the street
// -------------------------------------------------------------------------
const leftBuildings = [
{ x0: -9.2, x1: -2.8, z0: 6.45, z1: 9.95, height: 6.65, color: "#d96455", accent: "#436f67" },
{ x0: -11.8, x1: -2.8, z0: 3.28, z1: 6.58, height: 7.35, color: "#e2a83e", accent: "#7c4f48" },
{ x0: -10.2, x1: -2.8, z0: 0.25, z1: 3.38, height: 8.35, color: "#3f9c98", accent: "#e5c878" },
{ x0: -12.2, x1: -2.8, z0: -3.02, z1: 0.35, height: 6.95, color: "#4c6fa6", accent: "#b35b57" },
{ x0: -10.8, x1: -2.8, z0: -6.12, z1: -2.92, height: 8.05, color: "#b95d78", accent: "#3d7774" },
{ x0: -12.5, x1: -2.8, z0: -9.02, z1: -6.02, height: 6.75, color: "#e8d7a7", accent: "#4c7774" }
];
const rightBuildings = [
{ x0: 2.8, x1: 7.1, z0: 5.9, z1: 9.5, height: 7.25, color: "#d86d5d", accent: "#3b7771" },
{ x0: 2.8, x1: 7.25, z0: 2.35, z1: 5.95, height: 6.55, color: "#70ad8c", accent: "#e0b04b" },
{ x0: 2.8, x1: 7.05, z0: -1.48, z1: 2.42, height: 8.2, color: "#d7a13b", accent: "#536d99" }
];
for (const building of leftBuildings) {
buildBuilding({ ...building, balcony: true, chimney: true });
}
for (const building of rightBuildings) {
buildBuilding({ ...building, balcony: true, chimney: true });
}
// Striped awning on the golden facade.
for (let i = 0; i < 9; i++) {
addBlock(
-2.25,
2.52,
3.67 + i * 0.31,
0.98,
0.13,
0.29,
i % 2 ? "#f0dfb9" : "#b34f45"
);
addBlock(
-1.76,
2.36,
3.67 + i * 0.31,
0.08,
0.28,
0.29,
i % 2 ? "#f0dfb9" : "#b34f45"
);
}
// Rooftop water tank.
const tankX = -10.9;
const tankZ = -7.0;
for (const dx of [-0.34, 0.34]) {
for (const dz of [-0.34, 0.34]) {
addBlock(tankX + dx, 7.18, tankZ + dz, 0.12, 0.7, 0.12, "#76503c");
}
}
addBlock(tankX, 7.75, tankZ, 0.95, 0.8, 0.95, "#8b9994");
addBlock(tankX, 8.19, tankZ, 1.04, 0.12, 1.04, "#667a79");
// -------------------------------------------------------------------------
// City wall: rear section, coastal return, towers, gate, and crenellations
// -------------------------------------------------------------------------
const wallColors = ["#b8a17b", "#c4b087", "#aa9270", "#cdbb95"];
// Main rear wall.
for (let row = 0; row < 7; row++) {
const y = 0.4 + row * 0.81;
for (let x = -15.75; x < 6.75; x += 1.26) {
const gateOpening = Math.abs(x) < 1.48 && y < 3.5;
if (gateOpening) continue;
addBlock(
x,
y,
-10.15,
1.18,
0.73,
1.16,
tone(wallColors[Math.floor(random() * wallColors.length)], (random() - 0.5) * 0.08)
);
}
}
// Crenellations along the main wall.
for (let x = -15.45; x < 6.6; x += 1.5) {
addBlock(
x,
5.92,
-10.15,
0.77,
0.72,
1.18,
tone("#c7b38b", (random() - 0.5) * 0.07)
);
}
// Coastal return, visible against the water.
for (let row = 0; row < 6; row++) {
const y = 0.4 + row * 0.81;
for (let z = -9.42; z < -2.05; z += 1.2) {
addBlock(
7.08,
y,
z,
1.16,
0.73,
1.12,
tone(wallColors[Math.floor(random() * wallColors.length)], (random() - 0.5) * 0.08)
);
}
}
for (let z = -9.2; z < -2.1; z += 1.42) {
addBlock(7.08, 5.22, z, 1.18, 0.7, 0.77, "#c7b38b");
}
function buildTower(centerX, centerZ, size, height) {
const unit = size / 3;
for (let row = 0; row < height; row++) {
const y = 0.5 + row;
for (let ix = 0; ix < 3; ix++) {
for (let iz = 0; iz < 3; iz++) {
addBlock(
centerX - size / 2 + unit * (ix + 0.5),
y,
centerZ - size / 2 + unit * (iz + 0.5),
unit - 0.055,
0.92,
unit - 0.055,
tone(wallColors[Math.floor(random() * wallColors.length)], (random() - 0.5) * 0.09)
);
}
}
}
const top = height + 0.48;
for (let i = 0; i < 4; i++) {
const offset = -size / 2 + 0.4 + i * (size - 0.8) / 3;
addBlock(centerX + offset, top, centerZ - size / 2 + 0.25, 0.72, 0.82, 0.52, "#c8b58e");
addBlock(centerX + offset, top, centerZ + size / 2 - 0.25, 0.72, 0.82, 0.52, "#c8b58e");
}
addBlock(centerX - size / 2 + 0.25, top, centerZ, 0.52, 0.82, size, "#c8b58e");
addBlock(centerX + size / 2 - 0.25, top, centerZ, 0.52, 0.82, size, "#c8b58e");
}
buildTower(-14.75, -10.05, 3, 6);
buildTower(6.05, -9.93, 3.15, 7);
// Dark gate opening and stepped stone arch.
addBlock(0, 1.65, -10.18, 2.85, 3.25, 0.18, "#253b3d");
addBlock(-1.53, 1.66, -9.47, 0.35, 3.28, 0.38, "#d6c29a");
addBlock(1.53, 1.66, -9.47, 0.35, 3.28, 0.38, "#d6c29a");
addBlock(-1.18, 3.22, -9.47, 0.38, 0.38, 0.38, "#d6c29a");
addBlock(1.18, 3.22, -9.47, 0.38, 0.38, 0.38, "#d6c29a");
addBlock(-0.62, 3.61, -9.47, 0.38, 0.38, 0.38, "#d6c29a");
addBlock(0.62, 3.61, -9.47, 0.38, 0.38, 0.38, "#d6c29a");
addBlock(0, 3.97, -9.47, 0.55, 0.35, 0.38, "#d6c29a");
// -------------------------------------------------------------------------
// Caribbean water: visible individual voxel tiles
// -------------------------------------------------------------------------
const waterColors = ["#318ca5", "#3d9caf", "#4aaaba", "#57b8bf", "#2f83a0"];
for (let row = 0; row < 16; row++) {
for (let col = 0; col < 6; col++) {
const x = 8.35 + col * 1.3;
const z = -10.2 + row * 1.35;
const y = -0.15 + random() * 0.08;
const color = waterColors[Math.floor(random() * waterColors.length)];
addWater(
x,
y,
z,
1.19,
0.22 + random() * 0.08,
1.23,
tone(color, (random() - 0.5) * 0.035)
);
if (random() > 0.76) {
addBlock(
x + (random() - 0.5) * 0.35,
y + 0.18,
z + (random() - 0.5) * 0.35,
0.22 + random() * 0.42,
0.045,
0.12 + random() * 0.22,
"#a8dfdc"
);
}
}
}
// Shoreline foam pixels.
for (let z = -10; z < 10.6; z += 0.63) {
if (random() > 0.22) {
addBlock(
7.72,
-0.015,
z,
0.18,
0.07,
0.48 + random() * 0.3,
"#c8ece5"
);
}
}
// Low seawall beneath the right-hand buildings.
for (let z = -1.8; z < 10.2; z += 0.9) {
addBlock(7.48, 0.18, z, 0.38, 0.36, 0.81, "#b7a27d");
}
// -------------------------------------------------------------------------
// Street life and coastal accents
// -------------------------------------------------------------------------
function addPerson(x, z, shirt, skin = "#c78f68") {
addBlock(x - 0.13, 0.39, z, 0.17, 0.62, 0.19, "#31444b");
addBlock(x + 0.13, 0.39, z, 0.17, 0.62, 0.19, "#31444b");
addBlock(x, 0.99, z, 0.51, 0.65, 0.29, shirt);
addBlock(x, 1.48, z, 0.34, 0.34, 0.32, skin);
addBlock(x - 0.34, 0.98, z, 0.14, 0.48, 0.17, skin);
addBlock(x + 0.34, 0.98, z, 0.14, 0.48, 0.17, skin);
}
addPerson(1.35, 2.95, "#e7b64c");
addPerson(-1.45, -3.9, "#6b96b2", "#9a6648");
// Planters beside a doorway.
for (const z of [7.65, 8.5]) {
addBlock(-2.34, 0.25, z, 0.42, 0.5, 0.42, "#b76543");
addBlock(-2.34, 0.65, z, 0.5, 0.42, 0.5, "#3f7f58");
addBlock(-2.18, 0.83, z + 0.1, 0.28, 0.3, 0.28, "#5d9b63");
}
// Street lamps with glowing voxel lanterns.
for (const [x, z] of [[2.25, 6.35], [-2.25, -0.45]]) {
addBlock(x, 0.17, z, 0.42, 0.34, 0.42, "#435354");
addBlock(x, 1.47, z, 0.12, 2.65, 0.12, "#263f42");
addBlock(x, 2.82, z, 0.4, 0.43, 0.4, "#263f42");
addGlow(x, 2.82, z, 0.27, 0.3, 0.27);
addBlock(x, 3.1, z, 0.5, 0.12, 0.5, "#263f42");
}
// Small vintage car, entirely built from cubes.
const carX = 0.15;
const carZ = 6.2;
addBlock(carX, 0.5, carZ, 1.05, 0.48, 2.28, "#b84f43");
addBlock(carX, 0.82, carZ - 0.15, 0.91, 0.47, 1.25, "#d86755");
addBlock(carX, 1.12, carZ - 0.15, 0.88, 0.22, 1.03, "#f0d6a5");
addBlock(carX, 1.09, carZ - 0.16, 0.74, 0.42, 0.83, "#36545c");
addBlock(carX, 1.34, carZ - 0.15, 0.9, 0.12, 1.05, "#e4c28f");
for (const dx of [-0.57, 0.57]) {
for (const dz of [-0.72, 0.72]) {
addBlock(carX + dx, 0.38, carZ + dz, 0.23, 0.5, 0.44, "#26383c");
}
}
addBlock(carX - 0.28, 0.64, carZ + 1.16, 0.22, 0.17, 0.08, "#f5df9a");
addBlock(carX + 0.28, 0.64, carZ + 1.16, 0.22, 0.17, 0.08, "#f5df9a");
// Voxel sailboat in the open water.
const boatX = 11.75;
const boatZ = 4.9;
addBlock(boatX, 0.08, boatZ, 1.25, 0.34, 2.55, "#704b39");
addBlock(boatX, 0.31, boatZ + 0.22, 1.55, 0.28, 1.85, "#d89257");
addBlock(boatX, 0.54, boatZ - 0.36, 1.15, 0.48, 0.93, "#f0e2bd");
addBlock(boatX, 0.85, boatZ - 0.35, 1.25, 0.16, 1.05, "#c75b4c");
addBlock(boatX, 1.95, boatZ - 0.35, 0.12, 3.35, 0.12, "#e8d7ac");
// Stair-stepped triangular sail.
for (let row = 0; row < 6; row++) {
const width = 1.55 - row * 0.23;
addBlock(
boatX - 0.25 - width / 2,
0.85 + row * 0.43,
boatZ - 0.42,
width,
0.4,
0.1,
row % 2 ? "#f5e9c8" : "#fff3d2"
);
}
// -------------------------------------------------------------------------
// Render the voxel collections
// -------------------------------------------------------------------------
const staticMaterial = new THREE.MeshStandardMaterial({
color: "#ffffff",
roughness: 0.82,
metalness: 0.015
});
const voxelMesh = createInstancedMesh(staticBlocks, staticMaterial, true);
const glowMaterial = new THREE.MeshStandardMaterial({
color: "#ffe6a5",
emissive: "#ff9d3d",
emissiveIntensity: 1.55,
roughness: 0.45,
metalness: 0
});
const glowMesh = createInstancedMesh(glowBlocks, glowMaterial, false);
const waterMaterial = new THREE.MeshStandardMaterial({
color: "#ffffff",
roughness: 0.3,
metalness: 0.08
});
const waterMesh = createInstancedMesh(waterBlocks, waterMaterial, false);
waterMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, and touch pinch
// -------------------------------------------------------------------------
const defaultView = {
theta: 0.72,
phi: 0.82,
zoom: 1,
target: new THREE.Vector3(-0.35, 1.65, 0)
};
const current = {
theta: defaultView.theta,
phi: defaultView.phi,
zoom: defaultView.zoom,
target: defaultView.target.clone()
};
const desired = {
theta: defaultView.theta,
phi: defaultView.phi,
zoom: defaultView.zoom,
target: defaultView.target.clone()
};
function updateCamera(delta) {
const smoothing = 1 - Math.exp(-delta * 11);
current.theta += (desired.theta - current.theta) * smoothing;
current.phi += (desired.phi - current.phi) * smoothing;
current.zoom += (desired.zoom - current.zoom) * smoothing;
current.target.lerp(desired.target, smoothing);
const radius = 48;
const sinPhi = Math.sin(current.phi);
camera.position.set(
current.target.x + radius * sinPhi * Math.sin(current.theta),
current.target.y + radius * Math.cos(current.phi),
current.target.z + radius * sinPhi * Math.cos(current.theta)
);
camera.lookAt(current.target);
camera.zoom = current.zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
const halfHeight = Math.max(13.8, 21.4 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
const pointers = new Map();
let dragMode = null;
let previousX = 0;
let previousY = 0;
let previousPinch = 0;
function pointerDistance() {
const points = [...pointers.values()];
if (points.length < 2) return 0;
return Math.hypot(points[0].x - points[1].x, points[0].y - points[1].y);
}
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
previousPinch = pointerDistance();
dragMode = "pinch";
} else {
dragMode = event.shiftKey || event.button === 2 ? "pan" : "orbit";
previousX = event.clientX;
previousY = event.clientY;
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (dragMode === "pinch" && pointers.size >= 2) {
const distance = pointerDistance();
if (previousPinch > 0) {
desired.zoom = THREE.MathUtils.clamp(
desired.zoom * (distance / previousPinch),
0.62,
1.8
);
}
previousPinch = distance;
return;
}
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (dragMode === "orbit") {
desired.theta -= dx * 0.006;
desired.phi = THREE.MathUtils.clamp(desired.phi + dy * 0.005, 0.42, 1.35);
}
if (dragMode === "pan") {
const worldPerPixel =
((camera.top - camera.bottom) / camera.zoom) / renderer.domElement.clientHeight;
const direction = new THREE.Vector3();
camera.getWorldDirection(direction);
direction.y = 0;
direction.normalize();
const right = new THREE.Vector3().crossVectors(direction, camera.up).normalize();
desired.target.addScaledVector(right, -dx * worldPerPixel);
desired.target.addScaledVector(direction, -dy * worldPerPixel);
desired.target.x = THREE.MathUtils.clamp(desired.target.x, -10, 10);
desired.target.z = THREE.MathUtils.clamp(desired.target.z, -10, 10);
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 0) {
dragMode = null;
} else if (pointers.size === 1) {
const point = [...pointers.values()][0];
previousX = point.x;
previousY = point.y;
dragMode = "orbit";
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.zoom = THREE.MathUtils.clamp(
desired.zoom * Math.exp(-event.deltaY * 0.001),
0.62,
1.8
);
},
{ passive: false }
);
function resetView() {
desired.theta = defaultView.theta;
desired.phi = defaultView.phi;
desired.zoom = defaultView.zoom;
desired.target.copy(defaultView.target);
}
document.getElementById("reset").addEventListener("click", resetView);
renderer.domElement.addEventListener("dblclick", resetView);
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateCamera(delta);
// Gentle, block-by-block water motion.
waterBlocks.forEach((block, index) => {
dummy.position.set(
block.x,
block.y + Math.sin(elapsed * 0.82 + block.phase) * 0.035,
block.z
);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(block.sx, block.sy, block.sz);
dummy.updateMatrix();
waterMesh.setMatrixAt(index, dummy.matrix);
});
waterMesh.instanceMatrix.needsUpdate = true;
glowMaterial.emissiveIntensity = 1.48 + Math.sin(elapsed * 1.8) * 0.12;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 550);
});
</script>
</body>
</html>
```