Prompt specification
Build or customize the Three.js 3D scene "Malecón bend and Havana street frontage" 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: Malecón bend and Havana street frontage
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/malec-n-bend-and-havana-street-frontage-x2743
Scene Description Prompt:
Build a voxel Havana Malecón bend with curved seawall, promenade, road, and neighboring facades. One HTML file using Three.js from cdnjs.
Working Three.js Starter (malec-n-bend-and-havana-street-frontage-x2743):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Havana Malecón — Voxel Diorama</title>
<style>
:root {
--ink: #102a36;
--cream: #fff6df;
--glass: rgba(255, 246, 223, 0.82);
--accent: #e4553d;
--line: rgba(16, 42, 54, 0.18);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #9bd5e1;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body.night {
--ink: #f6edd6;
--cream: #fff6df;
--glass: rgba(13, 28, 45, 0.78);
--line: rgba(255, 255, 255, 0.16);
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
linear-gradient(180deg, rgba(15, 42, 52, 0.06), transparent 30%),
radial-gradient(circle at center, transparent 48%, rgba(12, 33, 44, 0.17));
z-index: 2;
}
.brand {
position: fixed;
top: 26px;
left: 28px;
z-index: 5;
pointer-events: none;
text-shadow: 0 2px 18px rgba(255,255,255,.28);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 6px;
font-size: 10px;
font-weight: 800;
letter-spacing: .22em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 23px;
height: 3px;
background: var(--accent);
box-shadow: 7px 0 0 rgba(228,85,61,.35);
}
h1 {
margin: 0;
font-size: clamp(30px, 4.7vw, 64px);
line-height: .88;
letter-spacing: -.055em;
font-weight: 900;
}
.brand p {
margin: 10px 0 0;
font-size: 11px;
line-height: 1.5;
font-weight: 700;
letter-spacing: .12em;
text-transform: uppercase;
opacity: .75;
}
.toolbar {
position: fixed;
z-index: 6;
top: 24px;
right: 24px;
display: flex;
gap: 8px;
padding: 7px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--glass);
backdrop-filter: blur(13px);
box-shadow: 0 12px 40px rgba(14, 42, 52, .14);
}
button {
appearance: none;
border: 0;
border-radius: 9px;
padding: 10px 12px;
background: transparent;
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 850;
letter-spacing: .09em;
text-transform: uppercase;
cursor: pointer;
transition: background .2s, color .2s, transform .2s;
}
button:hover {
background: rgba(228, 85, 61, .12);
transform: translateY(-1px);
}
button.active {
background: var(--accent);
color: #fff9e9;
}
.help {
position: fixed;
z-index: 5;
left: 26px;
bottom: 24px;
display: flex;
align-items: center;
gap: 14px;
padding: 12px 15px;
border: 1px solid var(--line);
border-radius: 13px;
background: var(--glass);
backdrop-filter: blur(12px);
box-shadow: 0 12px 35px rgba(14, 42, 52, .12);
font-size: 10px;
font-weight: 750;
letter-spacing: .08em;
text-transform: uppercase;
}
.mouse {
position: relative;
width: 19px;
height: 28px;
border: 2px solid currentColor;
border-radius: 10px;
opacity: .75;
}
.mouse::after {
content: "";
position: absolute;
width: 2px;
height: 6px;
top: 4px;
left: 7px;
border-radius: 2px;
background: currentColor;
animation: scroll 1.6s infinite;
}
@keyframes scroll {
0%, 100% { transform: translateY(0); opacity: .4; }
50% { transform: translateY(5px); opacity: 1; }
}
.divider {
width: 1px;
height: 24px;
background: var(--line);
}
.loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #a7dce4;
color: #173642;
transition: opacity .7s, visibility .7s;
}
.loading.hidden {
opacity: 0;
visibility: hidden;
}
.loading div {
text-align: center;
font-size: 11px;
font-weight: 900;
letter-spacing: .25em;
text-transform: uppercase;
}
.loading span {
display: block;
width: 90px;
height: 4px;
margin: 15px auto 0;
background: rgba(23,54,66,.15);
overflow: hidden;
}
.loading span::after {
content: "";
display: block;
width: 45%;
height: 100%;
background: #e4553d;
animation: load 1s ease-in-out infinite alternate;
}
@keyframes load {
from { transform: translateX(-20%); }
to { transform: translateX(145%); }
}
@media (max-width: 700px) {
.brand { top: 18px; left: 18px; }
.brand p { display: none; }
.toolbar {
top: auto;
right: 14px;
bottom: 14px;
flex-wrap: wrap;
justify-content: center;
max-width: 230px;
}
.help { display: none; }
button { padding: 9px 10px; font-size: 9px; }
}
</style>
</head>
<body>
<canvas id="scene"></canvas>
<div class="vignette"></div>
<header class="brand">
<div class="eyebrow">La Habana · Cuba</div>
<h1>MALECÓN</h1>
<p>A voxel bend of sea, stone and pastel facades</p>
</header>
<nav class="toolbar" aria-label="Scene controls">
<button id="reset">Reset view</button>
<button id="promenade">Promenade</button>
<button id="night">Night</button>
<button id="orbit">Auto orbit</button>
</nav>
<div class="help">
<div class="mouse"></div>
<span>Drag to orbit</span>
<div class="divider"></div>
<span>Scroll to zoom</span>
<div class="divider"></div>
<span>Right-drag to pan</span>
</div>
<div class="loading" id="loading">
<div>
Building the Malecón
<span></span>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const loading = document.getElementById("loading");
const renderer = new THREE.WebGLRenderer({
canvas,
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;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x9bd7e3);
scene.fog = new THREE.Fog(0x9bd7e3, 57, 112);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
180
);
const hemi = new THREE.HemisphereLight(0xdffaff, 0x927b58, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffefd1, 3.4);
sun.position.set(-24, 38, 28);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -34;
sun.shadow.camera.right = 34;
sun.shadow.camera.top = 28;
sun.shadow.camera.bottom = -28;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 100;
sun.shadow.bias = -0.0004;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x6fc7dd, 0.55);
fill.position.set(24, 14, -22);
scene.add(fill);
let seed = 8127;
function random() {
seed |= 0;
seed = seed + 0x6D2B79F5 | 0;
let t = Math.imul(seed ^ seed >>> 15, 1 | seed);
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
return ((t ^ t >>> 14) >>> 0) / 4294967296;
}
const range = (a, b) => a + (b - a) * random();
const pick = array => array[Math.floor(random() * array.length)];
const standard = (color, extra = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
...extra
});
const basic = (color, extra = {}) =>
new THREE.MeshBasicMaterial({ color, ...extra });
const mats = {
water: standard(0x28a9b7, {
roughness: 0.28,
metalness: 0.12
}),
foam: standard(0xdffcf1, {
roughness: 0.5
}),
foamBlue: standard(0x91e0df, {
roughness: 0.55
}),
road: standard(0x3c4b50, { roughness: 0.96 }),
sidewalk: standard(0xc9bfa8),
promenade: standard(0xd9cfb8),
cream: standard(0xf2e4c1),
dark: standard(0x24373a),
wood: standard(0x8d5034),
trunk: standard(0x8e6546),
leaf: standard(0x397c57),
leafLight: standard(0x4c9b63),
white: standard(0xfff7df),
red: standard(0xcf4d3b),
yellow: standard(0xf2c95c),
tire: standard(0x172125),
glass: standard(0x193f50, {
roughness: 0.25,
metalness: 0.18,
emissive: 0x071820,
emissiveIntensity: 0.35
}),
lamp: standard(0xffe7a0, {
emissive: 0xffbd55,
emissiveIntensity: 0.35,
roughness: 0.35
}),
skin: standard(0xb97654),
skinLight: standard(0xd99b72)
};
const stoneColors = [
0xb7aa91,
0xc4b79c,
0xa99c85,
0xcdbfa2,
0xb0a38b
];
const facadeColors = [
0xe66f52,
0xf0bf55,
0x62abb2,
0x7799c5,
0xe5a1b3,
0xead9b4,
0xd5784e,
0x9eb88e
];
const trimColors = [
0xf5e8c9,
0xf7efd7,
0xe8d9b5
];
function box(w, h, d, material, x, y, z, parent = scene, cast = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function worldZ(x) {
return 1.4 * Math.sin(x * 0.18) + 0.015 * x * x;
}
function worldSlope(x) {
return 0.252 * Math.cos(x * 0.18) + 0.03 * x;
}
function coastAngle(x) {
return -Math.atan(worldSlope(x));
}
// Water
const sea = new THREE.Mesh(
new THREE.PlaneGeometry(110, 110),
mats.water
);
sea.rotation.x = -Math.PI / 2;
sea.position.set(0, -0.09, 18);
sea.receiveShadow = true;
scene.add(sea);
// Voxel land foundation
const landPositions = [];
for (let x = -21; x <= 21; x++) {
const edge = worldZ(x) + 0.5;
for (let z = -19; z < edge; z++) {
landPositions.push([x, z + 0.5]);
}
}
const landMaterial = standard(0xffffff);
const land = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1.2, 1),
landMaterial,
landPositions.length
);
const dummy = new THREE.Object3D();
const tint = new THREE.Color();
landPositions.forEach(([x, z], i) => {
dummy.position.set(x, 0.6, z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
land.setMatrixAt(i, dummy.matrix);
tint.setHex(pick([0xb5a78d, 0xbbae93, 0xafa188, 0xc1b499]));
land.setColorAt(i, tint);
});
land.instanceMatrix.needsUpdate = true;
land.instanceColor.needsUpdate = true;
land.receiveShadow = true;
scene.add(land);
// Curved masonry seawall
for (let x = -20; x < 20; x += 0.84) {
const z = worldZ(x);
const angle = coastAngle(x);
const length = 0.88;
const block = box(
length,
1.23,
1.18,
standard(pick(stoneColors)),
x,
0.68,
z
);
block.rotation.y = angle;
const cap = box(
length + 0.035,
0.23,
1.36,
standard(pick([0xc7b99c, 0xbbae91, 0xd0c3a8])),
x,
1.39,
z
);
cap.rotation.y = angle;
const waterline = box(
length + 0.02,
0.16,
1.23,
standard(0x667b6c),
x,
0.13,
z
);
waterline.rotation.y = angle;
if (Math.round((x + 20) / 0.84) % 7 === 0) {
const buttress = box(
0.48,
1.65,
1.5,
standard(0xb4a68a),
x,
0.85,
z + 0.38
);
buttress.rotation.y = angle;
}
}
// Promenade, road and sidewalk follow the bend
for (let x = -20; x < 20; x += 0.84) {
const z = worldZ(x);
const angle = coastAngle(x);
const length = 0.86;
const promenade = box(
length + 0.02,
0.2,
2.35,
standard(pick([0xd5cab1, 0xdcd1b9, 0xcfc5ad])),
x,
1.29,
z - 1.83
);
promenade.rotation.y = angle;
const road = box(
length + 0.03,
0.16,
2.68,
mats.road,
x,
1.27,
z - 4.48
);
road.rotation.y = angle;
const sidewalk = box(
length + 0.02,
0.21,
1.05,
standard(pick([0xc6bba5, 0xcdc1aa])),
x,
1.29,
z - 6.28
);
sidewalk.rotation.y = angle;
for (const offset of [-1.12, 1.12]) {
const line = box(
length + 0.03,
0.025,
0.055,
mats.cream,
x,
1.365,
z - 4.48 + offset
);
line.rotation.y = angle;
}
}
// Broken center line
for (let x = -19.5; x < 19.5; x += 1.75) {
const dash = box(
0.78,
0.035,
0.085,
standard(0xe9ddb7),
x,
1.375,
worldZ(x) - 4.48
);
dash.rotation.y = coastAngle(x);
}
function createBuilding(x, zOffset, width, depth, height, colorIndex, detailed = true) {
const group = new THREE.Group();
group.position.set(x, 0, worldZ(x) + zOffset);
group.rotation.y = coastAngle(x);
scene.add(group);
const color = facadeColors[colorIndex % facadeColors.length];
const trimColor = trimColors[colorIndex % trimColors.length];
const facadeMat = standard(color);
const trimMat = standard(trimColor);
const base = 1.39;
box(width, height, depth, facadeMat, 0, base + height / 2, 0, group);
box(width + 0.16, 0.48, depth + 0.16, trimMat, 0, base + 0.2, 0, group);
box(width + 0.28, 0.23, depth + 0.25, trimMat, 0, base + height, 0, group);
box(width + 0.12, 0.48, 0.22, trimMat, 0, base + height + 0.27, depth / 2, group);
// Corner pilasters
for (const side of [-1, 1]) {
box(
0.18,
height - 0.25,
0.18,
trimMat,
side * (width / 2 - 0.14),
base + height / 2,
depth / 2 + 0.07,
group
);
}
if (detailed) {
const stories = height > 6.7 ? 3 : 2;
const front = depth / 2 + 0.06;
for (let floor = 0; floor < stories; floor++) {
const windowY = base + 1.65 + floor * 2.12;
const windowXs = floor === 0
? [-width * 0.29, width * 0.29]
: [-width * 0.3, 0, width * 0.3];
windowXs.forEach((wx, index) => {
box(
1.0,
1.32,
0.14,
trimMat,
wx,
windowY,
front,
group
);
box(
0.73,
1.03,
0.15,
mats.glass,
wx,
windowY,
front + 0.085,
group
);
box(
0.05,
1.04,
0.17,
trimMat,
wx,
windowY,
front + 0.1,
group
);
if ((floor + index + colorIndex) % 2 === 0) {
box(
0.16,
1.12,
0.16,
facadeMat,
wx - 0.62,
windowY,
front + 0.09,
group
);
box(
0.16,
1.12,
0.16,
facadeMat,
wx + 0.62,
windowY,
front + 0.09,
group
);
}
});
if (floor > 0 && colorIndex % 2 === 0) {
const balconyY = base + 1.04 + floor * 2.12;
const balconyZ = front + 0.42;
box(2.5, 0.14, 0.92, trimMat, 0, balconyY, balconyZ, group);
box(2.5, 0.09, 0.09, mats.dark, 0, balconyY + 0.92, balconyZ + 0.39, group);
box(2.5, 0.08, 0.08, mats.dark, 0, balconyY + 0.48, balconyZ + 0.39, group);
for (let p = -1.1; p <= 1.11; p += 0.44) {
box(0.065, 0.92, 0.065, mats.dark, p, balconyY + 0.46, balconyZ + 0.39, group);
}
}
}
// Ground-floor doorway
box(1.3, 2.25, 0.18, trimMat, 0, base + 1.08, front + 0.02, group);
box(0.92, 1.95, 0.17, standard(0x4d4b3c), 0, base + 0.96, front + 0.13, group);
box(1.65, 0.16, 0.72, standard(0x8c4938), 0, base + 2.28, front + 0.29, group);
// Small decorative plaque
box(
0.75,
0.34,
0.12,
standard(colorIndex % 2 ? 0x315f68 : 0x9c4435),
width * 0.28,
base + 2.35,
front + 0.18,
group
);
}
// Rooftop tank or chimney
if (colorIndex % 3 !== 0) {
box(
0.8,
1.05,
0.72,
standard(0x73847d),
width * 0.22,
base + height + 0.75,
-depth * 0.12,
group
);
} else {
box(
0.5,
1.3,
0.5,
standard(0x9d6048),
-width * 0.25,
base + height + 0.78,
0,
group
);
}
return group;
}
// Main neighboring facades
let bx = -19.1;
let facadeIndex = 0;
while (bx < 18.6) {
const width = range(3.2, 4.3);
createBuilding(
bx + width / 2,
range(-9.25, -9.0),
width,
range(3.6, 4.25),
range(4.7, 7.9),
facadeIndex++,
true
);
bx += width + range(0.13, 0.3);
}
// A second, quieter row behind the promenade
[
[-14, 5.5, 7.2, 0xbca285],
[-6.5, 6.8, 8.3, 0x94aaa6],
[3.7, 5.9, 7.4, 0xc4aa8f],
[12.7, 6.4, 8.6, 0x9fa7aa]
].forEach(([x, w, h, color], i) => {
const g = new THREE.Group();
g.position.set(x, 0, -13.4 + (i % 2) * 0.6);
scene.add(g);
box(w, h, 4.4, standard(color), 0, 1.4 + h / 2, 0, g);
box(w + 0.3, 0.25, 4.7, standard(0xd0c2a5), 0, 1.4 + h, 0, g);
for (let row = 0; row < 3; row++) {
for (let col = -1; col <= 1; col++) {
box(
0.68,
0.9,
0.12,
mats.glass,
col * w * 0.25,
3.2 + row * 1.75,
2.25,
g
);
}
}
});
// Street lamps
const nightLights = [];
for (let x = -18; x <= 18; x += 3.6) {
const group = new THREE.Group();
group.position.set(x, 1.4, worldZ(x) - 2.72);
group.rotation.y = coastAngle(x);
scene.add(group);
box(0.13, 2.75, 0.13, mats.dark, 0, 1.38, 0, group);
box(0.72, 0.11, 0.12, mats.dark, 0.34, 2.76, 0, group);
box(0.42, 0.48, 0.42, mats.lamp, 0.67, 2.57, 0, group);
box(0.53, 0.09, 0.53, mats.dark, 0.67, 2.84, 0, group);
box(0.53, 0.08, 0.53, mats.dark, 0.67, 2.31, 0, group);
const light = new THREE.PointLight(0xffc56d, 0, 7, 2);
light.position.set(0.67, 2.5, 0);
group.add(light);
nightLights.push(light);
}
// Benches
for (let x = -16; x <= 16; x += 6.4) {
const group = new THREE.Group();
group.position.set(x, 1.4, worldZ(x) - 1.15);
group.rotation.y = coastAngle(x);
scene.add(group);
box(1.75, 0.14, 0.55, mats.wood, 0, 0.52, 0, group);
box(1.75, 0.58, 0.12, mats.wood, 0, 0.86, -0.24, group);
box(0.13, 0.55, 0.13, mats.dark, -0.65, 0.25, 0, group);
box(0.13, 0.55, 0.13, mats.dark, 0.65, 0.25, 0, group);
}
// Classic block cars
function createCar(x, lane, color, heading = 1) {
const group = new THREE.Group();
group.position.set(x, 1.35, worldZ(x) - 4.48 + lane);
group.rotation.y = coastAngle(x) + (heading < 0 ? Math.PI : 0);
scene.add(group);
const bodyMat = standard(color, { roughness: 0.5 });
box(2.65, 0.52, 1.28, bodyMat, 0, 0.48, 0, group);
box(1.4, 0.58, 1.1, bodyMat, -0.15, 0.94, 0, group);
box(0.08, 0.42, 0.9, mats.glass, 0.57, 1.0, 0, group);
box(0.72, 0.4, 0.92, mats.glass, -0.16, 1.02, 0, group);
box(0.18, 0.17, 1.31, mats.cream, 1.29, 0.55, 0, group);
box(0.16, 0.16, 1.31, mats.cream, -1.29, 0.55, 0, group);
for (const wx of [-0.86, 0.86]) {
for (const wz of [-0.67, 0.67]) {
box(0.56, 0.42, 0.22, mats.tire, wx, 0.25, wz, group);
}
}
box(0.08, 0.18, 0.25, mats.yellow, 1.34, 0.65, 0.38, group);
box(0.08, 0.18, 0.25, mats.yellow, 1.34, 0.65, -0.38, group);
}
[
[-16.5, 0.62, 0xe0b74e, 1],
[-9.2, -0.6, 0xc64f3e, 1],
[-2.7, 0.6, 0x70a7a7, -1],
[4.3, -0.58, 0xe4d7b1, 1],
[11.6, 0.6, 0x527b96, -1],
[17.2, -0.58, 0xd67d4e, 1]
].forEach(args => createCar(...args));
// Voxel palms
function createPalm(x) {
const group = new THREE.Group();
group.position.set(x, 1.4, worldZ(x) - 6.65);
group.rotation.y = range(0, Math.PI * 2);
scene.add(group);
for (let i = 0; i < 6; i++) {
box(
0.27 - i * 0.014,
0.72,
0.27 - i * 0.014,
mats.trunk,
Math.sin(i * 0.7) * 0.08,
0.35 + i * 0.67,
Math.cos(i * 0.5) * 0.05,
group
);
}
const crownY = 4.48;
for (let i = 0; i < 8; i++) {
const leaf = box(
range(1.8, 2.65),
0.18,
0.48,
i % 2 ? mats.leaf : mats.leafLight,
0,
crownY,
0,
group
);
leaf.rotation.y = i * Math.PI / 4;
leaf.rotation.z = i % 2 ? 0.12 : -0.1;
}
box(0.32, 0.32, 0.32, mats.wood, 0.22, crownY - 0.2, 0.18, group);
box(0.29, 0.29, 0.29, mats.wood, -0.18, crownY - 0.17, -0.15, group);
}
[-17, -10, -3.2, 4.2, 11.1, 17.4].forEach(createPalm);
// Tiny pedestrians
function createPerson(x, offset, shirtColor, lightSkin = false) {
const group = new THREE.Group();
group.position.set(x, 1.4, worldZ(x) + offset);
group.rotation.y = range(-0.5, 0.5);
scene.add(group);
const shirt = standard(shirtColor);
const skin = lightSkin ? mats.skinLight : mats.skin;
box(0.42, 0.64, 0.28, shirt, 0, 0.77, 0, group);
box(0.29, 0.29, 0.29, skin, 0, 1.27, 0, group);
box(0.14, 0.48, 0.16, mats.dark, -0.12, 0.25, 0, group);
box(0.14, 0.48, 0.16, mats.dark, 0.12, 0.25, 0, group);
box(0.12, 0.58, 0.13, skin, -0.28, 0.77, 0, group);
box(0.12, 0.58, 0.13, skin, 0.28, 0.77, 0, group);
}
[
[-14.1, -1.6, 0xe9e0ca, true],
[-11.4, -1.9, 0x397c9b, false],
[-5.1, -1.4, 0xd85f49, true],
[-0.8, -2.0, 0xe8c857, false],
[3.7, -1.65, 0x5b9a76, true],
[8.8, -1.9, 0xe8e0ca, false],
[13.7, -1.5, 0xcf654b, true]
].forEach(args => createPerson(...args));
// Animated voxel foam
const foamObjects = [];
for (let i = 0; i < 115; i++) {
const material = i % 4 === 0 ? mats.foamBlue : mats.foam;
const length = range(0.35, 1.8);
const wave = box(
length,
range(0.035, 0.09),
range(0.07, 0.18),
material,
0,
0,
0,
scene,
false
);
wave.rotation.y = range(-0.25, 0.25);
wave.castShadow = false;
wave.receiveShadow = false;
foamObjects.push({
mesh: wave,
x: range(-32, 32),
distance: range(1.6, 35),
speed: range(0.16, 0.52),
phase: range(0, Math.PI * 2)
});
}
// A few voxel clouds and a square sun
const sunBlock = new THREE.Mesh(
new THREE.BoxGeometry(4.2, 4.2, 1.2),
basic(0xffdf83, { fog: false })
);
sunBlock.position.set(-19, 24, -25);
scene.add(sunBlock);
function createCloud(x, y, z, scale) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
scene.add(group);
const cloudMat = basic(0xf5fbf3, { fog: true });
box(3.2, 0.8, 1.1, cloudMat, 0, 0, 0, group, false);
box(1.5, 1.0, 1.25, cloudMat, -1.25, 0.36, 0, group, false);
box(1.7, 1.3, 1.3, cloudMat, 0.15, 0.55, 0, group, false);
box(1.3, 0.8, 1.1, cloudMat, 1.5, 0.2, 0, group, false);
}
createCloud(-12, 15, -8, 1.0);
createCloud(11, 17, -14, 1.3);
createCloud(23, 13, -3, 0.8);
// Custom camera controls, implemented without Three.js addons
const desired = {
target: new THREE.Vector3(0, 2.2, -2.2),
radius: 51,
phi: 1.04,
theta: 0.68
};
const current = {
target: desired.target.clone(),
radius: desired.radius,
phi: desired.phi,
theta: desired.theta
};
let dragging = false;
let panning = false;
let lastX = 0;
let lastY = 0;
let autoOrbit = false;
const pressed = new Set();
function updateCamera(dt) {
if (autoOrbit) desired.theta += dt * 0.095;
const forward = new THREE.Vector3(
-Math.sin(desired.theta),
0,
-Math.cos(desired.theta)
);
const right = new THREE.Vector3(
Math.cos(desired.theta),
0,
-Math.sin(desired.theta)
);
const speed = desired.radius * 0.32 * dt;
if (pressed.has("w") || pressed.has("arrowup")) {
desired.target.addScaledVector(forward, speed);
}
if (pressed.has("s") || pressed.has("arrowdown")) {
desired.target.addScaledVector(forward, -speed);
}
if (pressed.has("d") || pressed.has("arrowright")) {
desired.target.addScaledVector(right, speed);
}
if (pressed.has("a") || pressed.has("arrowleft")) {
desired.target.addScaledVector(right, -speed);
}
const damping = 1 - Math.exp(-dt * 8);
current.target.lerp(desired.target, damping);
current.radius = THREE.MathUtils.lerp(current.radius, desired.radius, damping);
current.phi = THREE.MathUtils.lerp(current.phi, desired.phi, damping);
current.theta = THREE.MathUtils.lerp(current.theta, desired.theta, damping);
const sinPhi = Math.sin(current.phi);
camera.position.set(
current.target.x + current.radius * sinPhi * Math.sin(current.theta),
current.target.y + current.radius * Math.cos(current.phi),
current.target.z + current.radius * sinPhi * Math.cos(current.theta)
);
camera.lookAt(current.target);
}
canvas.addEventListener("pointerdown", event => {
dragging = true;
panning = event.button === 2 || event.shiftKey;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (panning) {
const scale = current.radius * 0.00145;
const right = new THREE.Vector3(
Math.cos(current.theta),
0,
-Math.sin(current.theta)
);
const forward = new THREE.Vector3(
-Math.sin(current.theta),
0,
-Math.cos(current.theta)
);
desired.target.addScaledVector(right, -dx * scale);
desired.target.addScaledVector(forward, dy * scale);
} else {
desired.theta -= dx * 0.006;
desired.phi = THREE.MathUtils.clamp(
desired.phi - dy * 0.005,
0.32,
1.43
);
}
});
function endDrag() {
dragging = false;
panning = false;
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("wheel", event => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
14,
82
);
}, { passive: false });
window.addEventListener("keydown", event => {
pressed.add(event.key.toLowerCase());
});
window.addEventListener("keyup", event => {
pressed.delete(event.key.toLowerCase());
});
window.addEventListener("blur", () => pressed.clear());
function resetView() {
desired.target.set(0, 2.2, -2.2);
desired.radius = 51;
desired.phi = 1.04;
desired.theta = 0.68;
}
function promenadeView() {
desired.target.set(1.5, 2.2, worldZ(1.5) - 1.4);
desired.radius = 17;
desired.phi = 1.29;
desired.theta = 0.25;
}
document.getElementById("reset").addEventListener("click", resetView);
document.getElementById("promenade").addEventListener("click", promenadeView);
const orbitButton = document.getElementById("orbit");
orbitButton.addEventListener("click", () => {
autoOrbit = !autoOrbit;
orbitButton.classList.toggle("active", autoOrbit);
});
const nightButton = document.getElementById("night");
let isNight = false;
nightButton.addEventListener("click", () => {
isNight = !isNight;
nightButton.classList.toggle("active", isNight);
document.body.classList.toggle("night", isNight);
if (isNight) {
scene.background.set(0x14243d);
scene.fog.color.set(0x14243d);
hemi.color.set(0x7896c4);
hemi.groundColor.set(0x24313e);
hemi.intensity = 0.78;
sun.color.set(0x9bb8ef);
sun.intensity = 0.58;
fill.color.set(0x477eac);
fill.intensity = 0.32;
mats.water.color.set(0x164f70);
mats.glass.emissive.set(0x2e91a8);
mats.glass.emissiveIntensity = 1.25;
mats.lamp.emissiveIntensity = 3.2;
nightLights.forEach(light => light.intensity = 26);
renderer.toneMappingExposure = 1.18;
} else {
scene.background.set(0x9bd7e3);
scene.fog.color.set(0x9bd7e3);
hemi.color.set(0xdffaff);
hemi.groundColor.set(0x927b58);
hemi.intensity = 2.25;
sun.color.set(0xffefd1);
sun.intensity = 3.4;
fill.color.set(0x6fc7dd);
fill.intensity = 0.55;
mats.water.color.set(0x28a9b7);
mats.glass.emissive.set(0x071820);
mats.glass.emissiveIntensity = 0.35;
mats.lamp.emissiveIntensity = 0.35;
nightLights.forEach(light => light.intensity = 0);
renderer.toneMappingExposure = 1.08;
}
});
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() {
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
foamObjects.forEach(item => {
item.x += item.speed * dt;
if (item.x > 33) item.x = -33;
item.mesh.position.x = item.x;
item.mesh.position.z = worldZ(item.x) + item.distance;
item.mesh.position.y =
-0.025 + Math.sin(elapsed * 1.4 + item.phase) * 0.025;
});
updateCamera(dt);
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
loading.classList.add("hidden");
});
</script>
</body>
</html>
```