Prompt specification
Build or customize the Three.js 3D scene "La Boca street and Riachuelo edge fragment" 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: La Boca street and Riachuelo edge fragment
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/la-boca-street-and-riachuelo-edge-fragment-x2723
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing La Boca in Buenos Aires. Build a bounded low-poly scene with referenced low-rise housing forms, a partial waterfront edge, and local activity. Do not combine distant landmarks into one impossible block. Low-poly.
Working Three.js Starter (la-boca-street-and-riachuelo-edge-fragment-x2723):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>La Boca — Low-Poly Buenos Aires</title>
<style>
:root {
color-scheme: dark;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #9ebfc7;
}
canvas {
position: fixed;
inset: 0;
display: block;
z-index: 0;
touch-action: none;
}
.title-card {
position: fixed;
z-index: 10;
top: 18px;
left: 18px;
max-width: min(390px, calc(100vw - 36px));
padding: 17px 20px 16px;
color: #fff3d6;
background: rgba(28, 30, 29, 0.88);
border-left: 5px solid #e6533f;
box-shadow: 0 12px 35px rgba(0, 0, 0, 0.22);
pointer-events: none;
backdrop-filter: blur(8px);
}
.eyebrow {
margin-bottom: 4px;
color: #f1b74c;
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(1.8rem, 4vw, 2.8rem);
line-height: 0.95;
letter-spacing: 0.055em;
text-transform: uppercase;
}
.subtitle {
margin: 10px 0 0;
color: #e5dfcf;
font-size: 0.85rem;
line-height: 1.45;
}
.controls {
position: fixed;
z-index: 10;
right: 18px;
bottom: 18px;
width: min(300px, calc(100vw - 36px));
padding: 13px 15px;
color: #f6eedc;
background: rgba(28, 30, 29, 0.84);
border: 1px solid rgba(255, 255, 255, 0.12);
box-shadow: 0 12px 35px rgba(0, 0, 0, 0.2);
backdrop-filter: blur(8px);
font-size: 0.78rem;
line-height: 1.5;
}
.controls strong {
color: #ffd074;
}
.controls p {
margin: 4px 0 10px;
}
button {
appearance: none;
border: 0;
border-radius: 4px;
padding: 8px 11px;
color: #262622;
background: #f3b84b;
font: inherit;
font-size: 0.76rem;
font-weight: 800;
cursor: pointer;
}
button:hover {
background: #ffd06d;
}
button:focus-visible {
outline: 3px solid #fff;
outline-offset: 2px;
}
.loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
color: #fff3d6;
background: #283536;
transition: opacity 0.45s ease;
}
.loading.hide {
opacity: 0;
pointer-events: none;
}
.loading span {
font-size: 0.8rem;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
@media (max-width: 650px) {
.title-card {
top: 10px;
left: 10px;
max-width: calc(100vw - 20px);
padding: 12px 14px;
}
.subtitle {
display: none;
}
.controls {
right: 10px;
bottom: 10px;
width: calc(100vw - 20px);
}
}
</style>
</head>
<body>
<section class="title-card">
<div class="eyebrow">Buenos Aires · Argentina</div>
<h1>La Boca</h1>
<p class="subtitle">
An interpretive low-poly study of Caminito’s colorful attached housing,
street life and a separate partial edge of the Riachuelo.
</p>
</section>
<aside class="controls">
<p>
<strong>Drag</strong> to orbit · <strong>Shift/right-drag</strong> to pan ·
<strong>Wheel/pinch</strong> to zoom
</p>
<button id="reset-view" type="button">Reset view</button>
</aside>
<div class="loading" id="loading"><span>Building La Boca…</span></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene and lighting
// ------------------------------------------------------------
const loading = document.querySelector("#loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x9ebfc7);
scene.fog = new THREE.Fog(0x9ebfc7, 105, 170);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
240
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.75));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xffe6bc, 0x52666a, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffdfad, 3.1);
sun.position.set(-32, 58, 34);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -62;
sun.shadow.camera.right = 62;
sun.shadow.camera.top = 48;
sun.shadow.camera.bottom = -48;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 140;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x91c7d4, 0.65);
fill.position.set(40, 22, -35);
scene.add(fill);
// ------------------------------------------------------------
// Shared materials and geometry helpers
// ------------------------------------------------------------
const material = (color, extra = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
flatShading: true,
...extra
});
const M = {
base: material(0x424a4b),
land: material(0x9b8b70),
concrete: material(0xc8c1ad),
promenade: material(0xd4cdbb),
asphalt: material(0x555858),
clay: material(0xa96543),
roof: material(0x4b5253),
roofEdge: material(0x343b3d),
cream: material(0xe5d8b4),
white: material(0xf1ead8),
dark: material(0x263033),
glass: material(0x334b54, { roughness: 0.32, metalness: 0.08 }),
wood: material(0x7c5038),
metal: material(0x596263, { roughness: 0.58, metalness: 0.24 }),
trunk: material(0x674635),
leaf: material(0x54794b),
red: material(0xc84938),
yellow: material(0xe2b84d),
blue: material(0x38789b),
green: material(0x3b8278)
};
function box(parent, w, h, d, mat, x = 0, y = 0, z = 0, cast = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(
parent,
radiusTop,
radiusBottom,
height,
segments,
mat,
x = 0,
y = 0,
z = 0
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function ico(parent, radius, detail, mat, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(
new THREE.IcosahedronGeometry(radius, detail),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
let randomSeed = 7319;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
// ------------------------------------------------------------
// Procedural mural and sign textures
// ------------------------------------------------------------
function makeMuralTexture(title, background, palette, tango = false) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 384;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
for (let i = 0; i < 15; i++) {
ctx.save();
ctx.globalAlpha = 0.72;
ctx.translate(random() * 512, random() * 384);
ctx.rotate((random() - 0.5) * 1.2);
const w = 35 + random() * 135;
const h = 18 + random() * 90;
ctx.fillStyle = palette[i % palette.length];
ctx.fillRect(-w / 2, -h / 2, w, h);
if (i % 3 === 0) {
ctx.strokeStyle = palette[(i + 1) % palette.length];
ctx.lineWidth = 5 + random() * 9;
ctx.beginPath();
ctx.moveTo(-w / 2, 0);
ctx.lineTo(w / 2, (random() - 0.5) * 35);
ctx.stroke();
}
ctx.restore();
}
if (tango) {
ctx.strokeStyle = palette[0];
ctx.fillStyle = palette[0];
ctx.lineWidth = 13;
ctx.lineCap = "round";
for (const offset of [-75, 70]) {
ctx.beginPath();
ctx.arc(256 + offset, 132, 19, 0, Math.PI * 2);
ctx.fill();
ctx.beginPath();
ctx.moveTo(256 + offset, 154);
ctx.lineTo(246 + offset, 230);
ctx.lineTo(205 + offset, 302);
ctx.moveTo(246 + offset, 230);
ctx.lineTo(304 + offset, 302);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(246 + offset, 178);
ctx.lineTo(256 + offset - offset * 0.58, 214);
ctx.stroke();
}
}
ctx.save();
ctx.translate(20, 315);
ctx.rotate(-0.035);
ctx.font = "900 62px Arial, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.lineWidth = 10;
ctx.strokeStyle = "rgba(20,20,20,0.8)";
ctx.strokeText(title, 236, 0);
ctx.fillStyle = "#fff1cf";
ctx.fillText(title, 236, 0);
ctx.restore();
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function makeSignTexture(text, background = "#f0dfb6", foreground = "#283538") {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 192;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = foreground;
ctx.lineWidth = 12;
ctx.strokeRect(12, 12, 744, 168);
ctx.fillStyle = foreground;
ctx.font = "900 78px Arial, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 384, 100);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
function addPlane(parent, texture, w, h, x, y, z, rotationY = 0) {
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(w, h),
new THREE.MeshBasicMaterial({
map: texture,
side: THREE.DoubleSide
})
);
mesh.position.set(x, y, z);
mesh.rotation.y = rotationY;
parent.add(mesh);
return mesh;
}
const facadeColors = [
0xc84d3d,
0xe27437,
0xe0b849,
0x397da1,
0x438d88,
0xc65d79,
0xddd0a5,
0x67865b,
0xbd633c
];
const facadeMaterialCache = new Map();
function getFacadeMaterial(color) {
if (!facadeMaterialCache.has(color)) {
facadeMaterialCache.set(color, material(color));
}
return facadeMaterialCache.get(color);
}
// ------------------------------------------------------------
// Bounded diorama base, land, street, promenade and water
// ------------------------------------------------------------
box(scene, 96, 1.4, 66, M.base, 0, -0.95, 0, false);
box(scene, 92, 0.5, 48, M.land, 0, -0.05, -9, false);
box(scene, 90, 0.12, 8, M.asphalt, 0, 0.25, -3, false);
box(scene, 90, 0.2, 2, M.concrete, 0, 0.27, -8.1, false);
box(scene, 90, 0.2, 0.9, M.concrete, 0, 0.27, 1.45, false);
box(scene, 90, 0.12, 1.5, M.asphalt, 0, 0.27, 11.55, false);
box(scene, 91, 0.28, 1.6, M.promenade, 0, 0.29, 13.25, false);
box(scene, 92, 1, 1.2, M.concrete, 0, -0.15, 14.7, false);
// Alternating painted curbs.
for (let x = -43; x < 44; x += 2.4) {
box(scene, 2.25, 0.16, 0.22, M.red, x, 0.39, -7.05, false);
box(scene, 2.25, 0.16, 0.22, M.cream, x + 1.2, 0.39, -7.05, false);
box(scene, 2.25, 0.16, 0.22, M.cream, x, 0.39, 1.0, false);
box(scene, 2.25, 0.16, 0.22, M.red, x + 1.2, 0.39, 1.0, false);
}
// Low boundary walls keep the study compact and bounded.
box(scene, 92, 0.8, 0.6, M.concrete, 0, 0.5, -32.3, false);
box(scene, 0.6, 0.8, 47.5, M.concrete, -45.7, 0.5, -9.2, false);
box(scene, 0.6, 0.8, 47.5, M.concrete, 45.7, 0.5, -9.2, false);
box(scene, 0.65, 1.1, 15.5, M.concrete, -45.7, 0.05, 23, false);
box(scene, 0.65, 1.1, 15.5, M.concrete, 45.7, 0.05, 23, false);
// Low-poly animated water.
const waterNX = 36;
const waterNZ = 12;
const waterWidth = 91;
const waterDepth = 15.4;
const waterPositions = [];
const waterColors = [];
const waterIndices = [];
const waterBase = [];
for (let iz = 0; iz <= waterNZ; iz++) {
for (let ix = 0; ix <= waterNX; ix++) {
const x = -waterWidth / 2 + (ix / waterNX) * waterWidth;
const z = 15.35 + (iz / waterNZ) * waterDepth;
const y = -0.08;
waterPositions.push(x, y, z);
waterBase.push(y);
const shade = new THREE.Color().setHSL(
0.53 + random() * 0.025,
0.39,
0.39 + random() * 0.07
);
waterColors.push(shade.r, shade.g, shade.b);
}
}
for (let iz = 0; iz < waterNZ; iz++) {
for (let ix = 0; ix < waterNX; ix++) {
const a = iz * (waterNX + 1) + ix;
const b = a + 1;
const c = a + waterNX + 1;
const d = c + 1;
if ((ix + iz) % 2) {
waterIndices.push(a, c, b, b, c, d);
} else {
waterIndices.push(a, c, d, a, d, b);
}
}
}
const waterGeometry = new THREE.BufferGeometry();
waterGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(waterPositions, 3)
);
waterGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(waterColors, 3)
);
waterGeometry.setIndex(waterIndices);
const waterMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.42,
metalness: 0.06,
transparent: true,
opacity: 0.9,
flatShading: true
});
const water = new THREE.Mesh(waterGeometry, waterMaterial);
water.receiveShadow = true;
scene.add(water);
// ------------------------------------------------------------
// Caminito-inspired attached low-rise housing
// ------------------------------------------------------------
function addWindow(parent, x, y, z, front, shutterMat, w = 1.25, h = 1.45) {
box(parent, w + 0.22, h + 0.22, 0.12, M.white, x, y, z);
box(
parent,
w,
h,
0.14,
M.glass,
x,
y,
z + front * 0.075
);
box(
parent,
0.055,
h,
0.15,
M.white,
x,
y,
z + front * 0.09
);
box(
parent,
w,
0.055,
0.15,
M.white,
x,
y,
z + front * 0.09
);
for (const side of [-1, 1]) {
box(
parent,
0.28,
h + 0.08,
0.1,
shutterMat,
x + side * (w / 2 + 0.24),
y,
z + front * 0.07
);
for (let slat = 0; slat < 4; slat++) {
box(
parent,
0.3,
0.035,
0.13,
M.cream,
x + side * (w / 2 + 0.24),
y - h * 0.3 + slat * h * 0.2,
z + front * 0.09
);
}
}
}
function makeBuilding({
x,
z,
width = 8,
depth = 10,
floors = 1,
color = facadeColors[0],
front = 1,
awningColor = facadeColors[3],
mural = null,
balcony = false
}) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
const height = floors === 2 ? 7.2 : 4.25;
const bodyMat = getFacadeMaterial(color);
const frontZ = front * (depth / 2);
box(group, width, height, depth, bodyMat, 0, height / 2 + 0.2, 0);
box(
group,
width + 0.12,
0.36,
depth + 0.12,
M.cream,
0,
0.38,
0
);
// Fine vertical corrugation gives the façades a metal-cladding rhythm.
const corrugationMat = material(
new THREE.Color(color).offsetHSL(0, 0, 0.055)
);
for (let rib = 0; rib < Math.floor(width / 1.15); rib++) {
const ribX = -width / 2 + 0.55 + rib * 1.15;
box(
group,
0.055,
height - 0.45,
0.045,
corrugationMat,
ribX,
height / 2 + 0.22,
frontZ + front * 0.045,
false
);
}
const floorLevels = floors === 2 ? [1.65, 4.75] : [1.65];
floorLevels.forEach((floorY, floorIndex) => {
addWindow(
group,
-width * 0.27,
floorY,
frontZ + front * 0.07,
front,
getFacadeMaterial(awningColor),
1.15,
1.35
);
addWindow(
group,
width * 0.27,
floorY,
frontZ + front * 0.07,
front,
getFacadeMaterial(M.blue),
1.15,
1.35
);
if (floorIndex === 1 && balcony) {
box(
group,
width * 0.63,
0.12,
1.15,
M.concrete,
0,
3.43,
frontZ + front * 0.5
);
box(
group,
width * 0.63,
0.07,
0.07,
M.dark,
0,
4.4,
frontZ + front * 1.02
);
for (let bar = 0; bar < 7; bar++) {
const barX = -width * 0.29 + (bar / 6) * width * 0.58;
box(
group,
0.045,
0.95,
0.045,
M.dark,
barX,
3.9,
frontZ + front * 1.02
);
}
}
});
// Street-facing doorway.
box(
group,
1.75,
2.7,
0.13,
M.white,
0,
1.55,
frontZ + front * 0.07
);
box(
group,
1.38,
2.42,
0.15,
M.dark,
0,
1.42,
frontZ + front * 0.09
);
// Small striped awning.
for (let stripe = 0; stripe < 6; stripe++) {
const awning = box(
group,
0.43,
0.09,
1.35,
stripe % 2 ? M.cream : awningColor,
-1.08 + stripe * 0.43,
2.94,
frontZ + front * 0.53
);
awning.rotation.x = front * -0.13;
}
// Low corrugated shed roof.
const roof = box(
group,
width + 0.35,
0.18,
depth + 0.45,
M.roof,
0,
height + 0.35,
0
);
roof.rotation.x = front * 0.045;
for (let ridge = 0; ridge < Math.floor(width / 0.75); ridge++) {
const ridgeMesh = box(
group,
0.075,
0.07,
depth + 0.48,
M.roofEdge,
-width / 2 + 0.45 + ridge * 0.75,
height + 0.49,
0
);
ridgeMesh.rotation.x = front * 0.045;
}
if (random() > 0.62) {
box(
group,
0.7,
1.1,
0.75,
M.cream,
width * 0.24,
height + 0.75,
-depth * 0.15
);
}
if (mural) {
const texture = makeMuralTexture(
mural.title,
mural.background,
mural.palette,
mural.tango
);
addPlane(
group,
texture,
Math.min(depth * 0.68, 6.2),
3.3,
width / 2 + 0.055,
height * 0.48,
0,
Math.PI / 2
);
}
return group;
}
const northBuildings = [
{ x: -37, width: 8.0, floors: 1, color: facadeColors[0] },
{ x: -28.6, width: 8.2, floors: 2, color: facadeColors[1], balcony: true },
{ x: -19.1, width: 8.7, floors: 1, color: facadeColors[3] },
{ x: -9.8, width: 8.1, floors: 2, color: facadeColors[4], balcony: true },
{ x: -0.6, width: 8.3, floors: 1, color: facadeColors[5] },
{ x: 9.1, width: 8.8, floors: 2, color: facadeColors[2], balcony: true },
{ x: 19.2, width: 8.5, floors: 1, color: facadeColors[6] },
{ x: 28.8, width: 8.8, floors: 2, color: facadeColors[7], balcony: true },
{
x: 38.5,
width: 7.4,
floors: 1,
color: facadeColors[8],
mural: {
title: "CAMINITO",
background: "#d4573f",
palette: ["#f1c94f", "#2b7893", "#f4e4bc", "#283f49"],
tango: true
}
}
];
northBuildings.forEach((data, index) => {
makeBuilding({
...data,
z: -14.6 + (index % 3) * 0.12,
depth: 10 + (index % 2) * 0.4,
front: 1,
awningColor: facadeColors[(index + 3) % facadeColors.length]
});
});
const southBuildings = [
{ x: -37, width: 8.1, floors: 1, color: facadeColors[2] },
{ x: -28.7, width: 8.3, floors: 2, color: facadeColors[3], balcony: true },
{ x: -19.5, width: 8.6, floors: 1, color: facadeColors[5] },
{ x: -10, width: 8.1, floors: 2, color: facadeColors[7], balcony: true },
{
x: -0.7,
width: 8.5,
floors: 1,
color: facadeColors[0],
mural: {
title: "LA BOCA",
background: "#277b92",
palette: ["#e9bd45", "#d95c45", "#f2e4c3", "#27363d"],
tango: true
}
}
];
southBuildings.forEach((data, index) => {
makeBuilding({
...data,
z: 6.0 + (index % 2) * 0.15,
depth: 10,
front: -1,
awningColor: facadeColors[(index + 5) % facadeColors.length]
});
});
// ------------------------------------------------------------
// Local street details
// ------------------------------------------------------------
function addStreetLamp(x, z) {
cylinder(scene, 0.075, 0.1, 4.4, 6, M.dark, x, 2.2, z);
box(scene, 0.12, 0.12, 1.0, M.dark, x, 4.3, z + 0.45);
box(scene, 0.36, 0.18, 0.65, M.yellow, x, 4.18, z + 0.85);
}
[-41, -29, -17, 4, 16, 40].forEach((x) => {
addStreetLamp(x, 1.55);
});
function addUtilityPole(x, z) {
cylinder(scene, 0.08, 0.12, 7.2, 6, M.wood, x, 3.6, z);
box(scene, 1.65, 0.09, 0.09, M.dark, x, 6.95, z);
for (const offset of [-0.55, 0, 0.55]) {
cylinder(scene, 0.035, 0.035, 0.25, 5, M.cream, x + offset, 7.08, z);
}
}
const poleXs = [-38, -22, -6, 10, 26, 42];
poleXs.forEach((x) => addUtilityPole(x, -9.0));
for (let i = 0; i < poleXs.length - 1; i++) {
for (const offset of [-0.55, 0, 0.55]) {
const x1 = poleXs[i] + offset;
const x2 = poleXs[i + 1] + offset;
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(x1, 7.2, -9),
new THREE.Vector3((x1 + x2) / 2, 6.6, -9),
new THREE.Vector3(x2, 7.2, -9)
]);
scene.add(
new THREE.Line(
geometry,
new THREE.LineBasicMaterial({ color: 0x303638 })
)
);
}
}
// Small neighborhood market stalls.
function addMarketStall(x, z, awningColor) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
for (const legX of [-1.7, 1.7]) {
for (const legZ of [-0.8, 0.8]) {
box(group, 0.09, 2.45, 0.09, M.wood, legX, 1.25, legZ);
}
}
box(group, 3.8, 0.65, 1.8, M.wood, 0, 1.0, 0);
for (let stripe = 0; stripe < 7; stripe++) {
box(
group,
0.55,
0.1,
2.8,
stripe % 2 ? M.cream : awningColor,
-1.65 + stripe * 0.55,
2.55,
0
);
}
const goods = [M.red, M.yellow, M.green, M.blue];
for (let item = 0; item < 12; item++) {
const crate = box(
group,
0.4,
0.28,
0.4,
goods[item % goods.length],
-1.45 + (item % 6) * 0.58,
1.47,
item < 6 ? -0.35 : 0.35
);
crate.rotation.y = (random() - 0.5) * 0.12;
}
return group;
}
addMarketStall(-33.4, -8.15, M.red);
addMarketStall(-25.6, -8.15, M.blue);
// Benches.
function addBench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
box(group, 2.4, 0.12, 0.65, M.wood, 0, 0.72, 0);
box(group, 2.4, 0.65, 0.1, M.wood, 0, 1.08, -0.28);
for (const legX of [-0.85, 0.85]) {
box(group, 0.11, 0.7, 0.11, M.dark, legX, 0.35, 0);
}
}
addBench(12.5, -7.8);
addBench(42, 11.9, Math.PI / 2);
// Sparse street trees, kept small to preserve the dense urban scale.
function addTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
cylinder(group, 0.18, 0.28, 3.2, 6, M.trunk, 0, 1.6, 0);
ico(group, 1.5, 0, M.leaf, 0, 3.6, 0);
ico(group, 0.95, 0, M.leaf, -0.65, 3.0, 0.2);
}
addTree(12.2, 10.6, 0.85);
addTree(42.1, 8.5, 0.9);
// ------------------------------------------------------------
// Low-poly people
// ------------------------------------------------------------
const animatedPeople = [];
const skinMaterials = [
material(0x9b6746),
material(0xc99064),
material(0x6f4935),
material(0xe1b08b)
];
const shirtMaterials = [
M.red,
M.yellow,
M.blue,
M.green,
material(0xeee1c5),
material(0x76508c)
];
const pantsMaterials = [
material(0x30383b),
material(0x46566a),
material(0x69503f),
material(0x2f4d56)
];
function makeLimb(parent, length, radius, mat, x, y, z) {
const pivot = new THREE.Group();
pivot.position.set(x, y, z);
parent.add(pivot);
cylinder(pivot, radius, radius * 0.88, length, 6, mat, 0, -length / 2, 0);
return pivot;
}
function createPerson({
x = 0,
z = 0,
scale = 1,
shirt = 0,
pants = 0,
skin = 0,
walking = false,
rotation = 0
} = {}) {
const group = new THREE.Group();
group.position.set(x, 0.2, z);
group.rotation.y = rotation;
group.scale.setScalar(scale);
scene.add(group);
const shirtMat = shirtMaterials[shirt % shirtMaterials.length];
const pantsMat = pantsMaterials[pants % pantsMaterials.length];
const skinMat = skinMaterials[skin % skinMaterials.length];
cylinder(group, 0.27, 0.42, 1.08, 7, shirtMat, 0, 1.27, 0);
cylinder(group, 0.12, 0.12, 0.22, 6, skinMat, 0, 1.92, 0);
const head = ico(group, 0.26, 1, skinMat, 0, 2.15, 0);
head.scale.set(0.92, 1.08, 0.92);
const hair = ico(
group,
0.275,
1,
material(0x30251f),
0,
2.25,
-0.025
);
hair.scale.set(0.92, 0.5, 0.92);
const leftLeg = makeLimb(group, 0.76, 0.13, pantsMat, -0.18, 0.82, 0);
const rightLeg = makeLimb(group, 0.76, 0.13, pantsMat, 0.18, 0.82, 0);
const leftArm = makeLimb(group, 0.68, 0.105, shirtMat, -0.42, 1.72, 0);
const rightArm = makeLimb(group, 0.68, 0.105, shirtMat, 0.42, 1.72, 0);
box(group, 0.24, 0.12, 0.38, M.dark, -0.18, 0.07, 0.07);
box(group, 0.24, 0.12, 0.38, M.dark, 0.18, 0.07, 0.07);
if (!walking) {
leftArm.rotation.z = -0.1;
rightArm.rotation.z = 0.1;
}
group.userData = { leftLeg, rightLeg, leftArm, rightArm };
return group;
}
// Tango couple on the pedestrian street.
const tango = new THREE.Group();
tango.position.set(-8.2, 0, -3.0);
scene.add(tango);
const tangoA = createPerson({
x: -0.7,
scale: 1.05,
shirt: 0,
pants: 0,
skin: 1,
rotation: Math.PI / 2
});
const tangoB = createPerson({
x: 0.7,
scale: 0.98,
shirt: 5,
pants: 3,
skin: 3,
rotation: -Math.PI / 2
});
tangoA.position.y = 0;
tangoB.position.y = 0;
tango.add(tangoA, tangoB);
tangoA.userData.leftArm.rotation.z = 1.25;
tangoA.userData.rightArm.rotation.z = 0.15;
tangoB.userData.rightArm.rotation.z = -1.25;
tangoB.userData.leftArm.rotation.z = -0.15;
// Market vendors and customers.
const vendor = createPerson({
x: -33.4,
z: -9.75,
scale: 0.93,
shirt: 4,
pants: 1,
skin: 2
});
const vendor2 = createPerson({
x: -25.6,
z: -9.75,
scale: 0.9,
shirt: 2,
pants: 0,
skin: 0
});
const customer = createPerson({
x: -31.8,
z: -6.4,
scale: 0.94,
shirt: 1,
pants: 2,
skin: 3
});
// Pedestrians moving gently along the street.
const walkers = [];
[
[-18.0, -4.8, 0.95, 1, 2, 0],
[-14.8, -2.8, 1.0, 4, 0, 3],
[-1.0, -5.4, 0.94, 2, 3, 1],
[4.3, -1.6, 1.02, 3, 1, 0],
[8.2, -5.3, 0.86, 1, 2, 3]
].forEach((data, index) => {
const person = createPerson({
x: data[0],
z: data[1],
scale: data[2],
shirt: data[3],
pants: data[4],
skin: data[5],
walking: true,
rotation: index % 2 ? Math.PI / 2 : -Math.PI / 2
});
walkers.push({
group: person,
baseX: data[0],
phase: index * 1.7
});
});
// A small neighborhood football pitch and goal.
box(scene, 30, 0.1, 9.8, M.clay, 25, 0.35, 6.0, false);
for (const z of [1.25, 10.75]) {
box(scene, 30, 0.03, 0.08, M.white, 25, 0.42, z, false);
}
for (const x of [10, 40]) {
box(scene, 0.08, 0.03, 9.5, M.white, x, 0.42, 6, false);
}
const goal = new THREE.Group();
goal.position.set(37.4, 0, 6);
scene.add(goal);
cylinder(goal, 0.07, 0.07, 2.35, 6, M.white, 0, 1.18, -1.65);
cylinder(goal, 0.07, 0.07, 2.35, 6, M.white, 0, 1.18, 1.65);
box(goal, 0.08, 0.08, 3.35, M.white, 0, 2.34, 0);
for (let i = 0; i <= 6; i++) {
const z = -1.65 + (i / 6) * 3.3;
box(goal, 0.025, 2.3, 0.025, M.cream, 0.04, 1.17, z, false);
}
for (let i = 0; i <= 4; i++) {
const y = (i / 4) * 2.3;
box(goal, 0.025, 0.025, 3.3, M.cream, 0.04, y, 0, false);
}
const footballers = [
createPerson({
x: 20.4,
z: 4.2,
scale: 0.75,
shirt: 2,
pants: 1,
skin: 1,
walking: true,
rotation: 0.7
}),
createPerson({
x: 26.7,
z: 7.4,
scale: 0.72,
shirt: 4,
pants: 0,
skin: 2,
walking: true,
rotation: -1.0
}),
createPerson({
x: 32.2,
z: 4.8,
scale: 0.78,
shirt: 0,
pants: 3,
skin: 3,
walking: true,
rotation: 2.4
}),
createPerson({
x: 36.2,
z: 6.0,
scale: 0.83,
shirt: 1,
pants: 2,
skin: 0,
rotation: -Math.PI / 2
})
];
const ball = ico(scene, 0.33, 1, M.white, 24, 0.83, 4.7);
ico(scene, 0.12, 0, M.dark, 24.12, 0.9, 4.68);
// ------------------------------------------------------------
// Waterfront: bollards, railings, fishing and boats
// ------------------------------------------------------------
for (let x = -42; x <= 42; x += 6) {
cylinder(scene, 0.15, 0.19, 0.75, 6, M.dark, x, 0.8, 13.55);
}
function addRailing(x1, x2) {
box(scene, x2 - x1, 0.07, 0.07, M.dark, (x1 + x2) / 2, 1.55, 14.8);
box(scene, x2 - x1, 0.045, 0.045, M.dark, (x1 + x2) / 2, 1.02, 14.8);
for (let x = x1; x <= x2; x += 4) {
box(scene, 0.06, 1.6, 0.06, M.dark, x, 0.9, 14.8);
}
}
addRailing(-42, -9);
addRailing(11, 42);
const fisher = createPerson({
x: -34,
z: 13.0,
scale: 0.95,
shirt: 5,
pants: 1,
skin: 2
});
const rod = box(
scene,
0.05,
2.4,
0.05,
M.dark,
-33.65,
1.8,
13.25
);
rod.rotation.z = -0.55;
rod.rotation.x = -0.2;
function makeBoat(x, z, color, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0.15, z);
group.rotation.y = rotation;
scene.add(group);
const hullGeometry = new THREE.BufferGeometry();
hullGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
2.2, 0.25, 0,
-1.9, 0.25, 0,
-1.45, 0.55, 0.75,
-1.45, 0.55, -0.75,
1.45, -0.35, 0,
-1.25, -0.35, 0
], 3)
);
hullGeometry.setIndex([
0, 1, 2,
0, 2, 3,
0, 3, 4,
1, 5, 2,
2, 5, 4,
3, 4, 5,
0, 3, 1
]);
hullGeometry.computeVertexNormals();
const hull = new THREE.Mesh(hullGeometry, getFacadeMaterial(color));
hull.castShadow = true;
group.add(hull);
box(group, 1.35, 0.9, 1.0, M.cream, -0.45, 0.9, 0);
box(group, 1.0, 0.35, 1.03, M.blue, -0.45, 1.1, 0);
cylinder(group, 0.045, 0.045, 1.8, 6, M.dark, 0.7, 1.15, 0);
box(group, 1.1, 0.06, 0.8, M.wood, -1.0, 0.62, 0);
return group;
}
const boats = [
makeBoat(-23.5, 21.5, 0x387d9a, 0.22),
makeBoat(14.8, 24.2, 0xc9543e, -0.55),
makeBoat(35.0, 19.2, 0xd3ae45, 0.8)
];
// Floating buoys.
const buoyMaterials = [M.red, M.yellow, M.green];
[-7, 5, 27].forEach((x, index) => {
cylinder(
scene,
0.24,
0.32,
0.55,
6,
buoyMaterials[index % 3],
x,
0.05,
18.5 + index * 3
);
});
// ------------------------------------------------------------
// Small readable neighborhood sign
// ------------------------------------------------------------
const signTexture = makeSignTexture("CAMINITO");
const signSprite = new THREE.Sprite(
new THREE.SpriteMaterial({ map: signTexture })
);
signSprite.position.set(8.5, 4.4, -8.7);
signSprite.scale.set(6.4, 1.6, 1);
scene.add(signSprite);
cylinder(scene, 0.065, 0.085, 3.7, 6, M.dark, 8.5, 1.85, -8.7);
// ------------------------------------------------------------
// Direct camera controls: orbit, pan and zoom
// ------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 2, 0),
distance: 91,
theta: 0.72,
phi: 0.83
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x +
controls.distance * sinPhi * Math.sin(controls.theta),
controls.target.y +
controls.distance * Math.cos(controls.phi),
controls.target.z +
controls.distance * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
function clampTarget() {
controls.target.x = THREE.MathUtils.clamp(
controls.target.x,
-38,
38
);
controls.target.z = THREE.MathUtils.clamp(
controls.target.z,
-25,
26
);
controls.target.y = THREE.MathUtils.clamp(
controls.target.y,
0.5,
9
);
}
function pan(dx, dy) {
const right = new THREE.Vector3();
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
right.setFromMatrixColumn(camera.matrix, 0);
right.y = 0;
forward.y = 0;
right.normalize();
forward.normalize();
const amount = controls.distance * 0.00115;
controls.target.addScaledVector(right, -dx * amount);
controls.target.addScaledVector(forward, -dy * amount);
clampTarget();
}
const pointers = new Map();
let dragMode = "orbit";
let lastX = 0;
let lastY = 0;
let pinchDistance = 0;
let pinchCenter = { x: 0, y: 0 };
const canvas = renderer.domElement;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
function pointerCenter() {
const values = [...pointers.values()];
if (values.length < 2) return { x: 0, y: 0 };
return {
x: (values[0].x + values[1].x) / 2,
y: (values[0].y + values[1].y) / 2
};
}
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
dragMode =
event.button === 2 || event.shiftKey ? "pan" : "orbit";
lastX = event.clientX;
lastY = event.clientY;
} else if (pointers.size === 2) {
pinchDistance = pointerDistance();
pinchCenter = pointerCenter();
}
});
canvas.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 === 2) {
const distance = pointerDistance();
const center = pointerCenter();
if (pinchDistance > 0 && distance > 0) {
controls.distance = THREE.MathUtils.clamp(
controls.distance * (pinchDistance / distance),
43,
126
);
}
pan(center.x - pinchCenter.x, center.y - pinchCenter.y);
pinchDistance = distance;
pinchCenter = center;
} else {
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (dragMode === "pan") {
pan(dx, dy);
} else {
controls.theta -= dx * 0.005;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.004,
0.34,
1.24
);
}
}
updateCamera();
});
function removePointer(event) {
pointers.delete(event.pointerId);
pinchDistance = 0;
}
canvas.addEventListener("pointerup", removePointer);
canvas.addEventListener("pointercancel", removePointer);
canvas.addEventListener("lostpointercapture", removePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.distance = THREE.MathUtils.clamp(
controls.distance * Math.exp(event.deltaY * 0.001),
43,
126
);
updateCamera();
},
{ passive: false }
);
function resetView() {
controls.target.set(0, 2, 0);
controls.distance = 91;
controls.theta = 0.72;
controls.phi = 0.83;
updateCamera();
}
document.querySelector("#reset-view").addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
const step = event.shiftKey ? 0.12 : 0.06;
if (event.key === "ArrowLeft") controls.theta += step;
else if (event.key === "ArrowRight") controls.theta -= step;
else if (event.key === "ArrowUp") controls.phi -= step;
else if (event.key === "ArrowDown") controls.phi += step;
else if (event.key === "+" || event.key === "=") {
controls.distance -= 4;
} else if (event.key === "-" || event.key === "_") {
controls.distance += 4;
} else if (event.key.toLowerCase() === "r") {
resetView();
return;
} else {
return;
}
controls.phi = THREE.MathUtils.clamp(controls.phi, 0.34, 1.24);
controls.distance = THREE.MathUtils.clamp(controls.distance, 43, 126);
updateCamera();
});
updateCamera();
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const time = clock.getElapsedTime();
// Gentle triangular water motion.
const positionAttribute = waterGeometry.getAttribute("position");
for (let i = 0; i < positionAttribute.count; i++) {
const x = positionAttribute.getX(i);
const z = positionAttribute.getZ(i);
const wave =
Math.sin(x * 0.22 + time * 1.15) * 0.045 +
Math.cos(z * 0.39 + time * 0.8) * 0.032;
positionAttribute.setY(i, waterBase[i] + wave);
}
positionAttribute.needsUpdate = true;
waterGeometry.computeVertexNormals();
// Tango movement.
tango.rotation.y = Math.sin(time * 1.35) * 0.035;
tangoA.userData.leftArm.rotation.z =
1.22 + Math.sin(time * 2.1) * 0.08;
tangoB.userData.rightArm.rotation.z =
-1.22 - Math.sin(time * 2.1) * 0.08;
tangoA.position.y = Math.sin(time * 2.1) * 0.035;
tangoB.position.y = -Math.sin(time * 2.1) * 0.035;
// Walkers.
walkers.forEach((walker, index) => {
const phase = time * 2.1 + walker.phase;
walker.group.position.x =
walker.baseX + Math.sin(time * 0.16 + walker.phase) * 1.35;
walker.group.userData.leftLeg.rotation.x = Math.sin(phase) * 0.48;
walker.group.userData.rightLeg.rotation.x = -Math.sin(phase) * 0.48;
walker.group.userData.leftArm.rotation.x = -Math.sin(phase) * 0.38;
walker.group.userData.rightArm.rotation.x = Math.sin(phase) * 0.38;
walker.group.position.y =
0.2 + Math.abs(Math.sin(phase)) * 0.025;
});
// Footballers.
footballers.forEach((player, index) => {
const phase = time * 3.4 + index * 1.4;
player.userData.leftLeg.rotation.x = Math.sin(phase) * 0.58;
player.userData.rightLeg.rotation.x = -Math.sin(phase) * 0.58;
player.userData.leftArm.rotation.x = -Math.sin(phase) * 0.55;
player.userData.rightArm.rotation.x = Math.sin(phase) * 0.55;
});
ball.position.x = 23.4 + Math.sin(time * 0.48) * 4.2;
ball.position.z = 4.8 + Math.cos(time * 0.48) * 1.7;
ball.position.y = 0.76 + Math.abs(Math.sin(time * 3.2)) * 0.15;
ball.rotation.x = time * 1.4;
ball.rotation.z = time * 0.9;
// Boat bobbing.
boats.forEach((boat, index) => {
boat.position.y =
0.12 + Math.sin(time * 1.15 + index * 1.7) * 0.055;
boat.rotation.z = Math.sin(time * 0.85 + index) * 0.018;
});
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.75));
});
requestAnimationFrame(() => {
loading.classList.add("hide");
setTimeout(() => loading.remove(), 500);
});
animate();
</script>
</body>
</html>
```