Prompt specification
Build or customize the Three.js 3D scene "Vendor cart beneath a Madrid arcade" 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: Vendor cart beneath a Madrid arcade
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/vendor-cart-beneath-a-madrid-arcade-x2846
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring Plaza Mayor in Madrid. Create a compact plaza-edge vignette with original vendor cart, seated visitors, and passing pedestrians. Keep the arcade route continuous beside the temporary activity. Voxel style.
Working Three.js Starter (vendor-cart-beneath-a-madrid-arcade-x2846):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Plaza Mayor — Voxel Vignette</title>
<style>
:root {
--ink: #24313a;
--paper: #fff9ec;
--accent: #b54d35;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cddde0;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.title-card {
position: fixed;
left: 24px;
bottom: 24px;
z-index: 3;
max-width: min(420px, calc(100vw - 48px));
padding: 16px 19px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 4px;
color: var(--ink);
background: rgba(255, 249, 236, 0.88);
box-shadow: 0 12px 32px rgba(37, 45, 48, 0.16);
backdrop-filter: blur(9px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 4px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(21px, 3vw, 31px);
line-height: 1;
letter-spacing: -0.04em;
}
.subtitle {
margin-top: 7px;
color: #617079;
font-size: 12px;
line-height: 1.45;
}
.controls {
position: fixed;
top: 18px;
right: 18px;
z-index: 4;
display: flex;
gap: 8px;
}
button {
min-height: 38px;
padding: 0 14px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 4px;
color: var(--ink);
background: rgba(255, 249, 236, 0.9);
box-shadow: 0 8px 22px rgba(37, 45, 48, 0.12);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
backdrop-filter: blur(8px);
}
button:hover {
background: #fffdf7;
}
button:active {
transform: translateY(1px);
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
color: #fff9ec;
background: #cddde0;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 0.35s ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 620px) {
.title-card {
left: 14px;
bottom: 14px;
padding: 13px 15px;
}
.subtitle {
max-width: 250px;
}
.controls {
top: 12px;
right: 12px;
}
button {
padding: 0 11px;
}
}
</style>
</head>
<body>
<div id="stage" aria-label="Interactive voxel scene of Madrid's Plaza Mayor"></div>
<div class="controls">
<button id="motion" type="button" aria-label="Pause or resume pedestrians">Pause motion</button>
<button id="reset" type="button">Reset view</button>
</div>
<section class="title-card">
<div class="eyebrow">Madrid · Plaza Mayor</div>
<h1>A corner of the plaza</h1>
<div class="subtitle">
Drag to orbit · Scroll to zoom · Double-click to reset
</div>
</section>
<div id="loading">Building the plaza…</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 direct camera controls
// -------------------------------------------------------------------------
const stage = document.querySelector("#stage");
const loading = document.querySelector("#loading");
const motionButton = document.querySelector("#motion");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcddde0);
scene.fog = new THREE.Fog(0xcddde0, 56, 92);
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, 15, -15, 0.1, 140);
const view = {
azimuth: 0.69,
elevation: 0.58,
zoom: 1,
radius: 42,
target: new THREE.Vector3(0, 4.1, -1.2),
};
function updateCamera() {
const horizontal = view.radius * Math.cos(view.elevation);
camera.position.set(
view.target.x + horizontal * Math.sin(view.azimuth),
view.target.y + view.radius * Math.sin(view.elevation),
view.target.z + horizontal * Math.cos(view.azimuth)
);
camera.lookAt(view.target);
camera.zoom = view.zoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const frustumHeight = Math.max(27, 35 / aspect);
camera.left = (-frustumHeight * aspect) / 2;
camera.right = (frustumHeight * aspect) / 2;
camera.top = frustumHeight / 2;
camera.bottom = -frustumHeight / 2;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
updateCamera();
}
window.addEventListener("resize", resize);
resize();
updateCamera();
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
view.azimuth -= dx * 0.006;
view.elevation = THREE.MathUtils.clamp(
view.elevation + dy * 0.0045,
0.28,
1.12
);
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.zoom = THREE.MathUtils.clamp(
view.zoom * Math.exp(-event.deltaY * 0.001),
0.68,
1.8
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
view.azimuth = 0.69;
view.elevation = 0.58;
view.zoom = 1;
updateCamera();
});
document.querySelector("#reset").addEventListener("click", () => {
view.azimuth = 0.69;
view.elevation = 0.58;
view.zoom = 1;
updateCamera();
});
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") view.azimuth += 0.06;
if (event.key === "ArrowRight") view.azimuth -= 0.06;
if (event.key === "ArrowUp") view.elevation += 0.04;
if (event.key === "ArrowDown") view.elevation -= 0.04;
if (event.key === "+") view.zoom *= 1.08;
if (event.key === "-") view.zoom /= 1.08;
view.elevation = THREE.MathUtils.clamp(view.elevation, 0.28, 1.12);
view.zoom = THREE.MathUtils.clamp(view.zoom, 0.68, 1.8);
updateCamera();
});
// -------------------------------------------------------------------------
// Materials and voxel primitives
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color) {
const key = String(color);
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
})
);
}
return materialCache.get(key);
}
function box(
parent,
size,
position,
color,
rotation = [0, 0, 0],
options = {}
) {
const mesh = new THREE.Mesh(
unitBox,
options.material || material(color)
);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.rotation.set(rotation[0], rotation[1], rotation[2]);
mesh.castShadow = options.cast !== false;
mesh.receiveShadow = options.receive !== false;
parent.add(mesh);
return mesh;
}
function group(parent, position = [0, 0, 0], rotationY = 0) {
const result = new THREE.Group();
result.position.set(position[0], position[1], position[2]);
result.rotation.y = rotationY;
parent.add(result);
return result;
}
function makeTextSign(
parent,
title,
subtitle,
width,
height,
position,
background = "#f5e8c9",
foreground = "#27383d"
) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 320;
const context = canvas.getContext("2d");
context.fillStyle = background;
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = foreground;
context.lineWidth = 15;
context.strokeRect(18, 18, canvas.width - 36, canvas.height - 36);
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = foreground;
context.font = "900 104px system-ui, sans-serif";
context.fillText(title, canvas.width / 2, 124);
context.font = "700 34px system-ui, sans-serif";
context.letterSpacing = "4px";
context.fillText(subtitle, canvas.width / 2, 235);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
const signMaterial = new THREE.MeshBasicMaterial({
map: texture,
side: THREE.DoubleSide,
});
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
signMaterial
);
sign.position.set(position[0], position[1], position[2]);
parent.add(sign);
return sign;
}
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xe9f4f5, 0x8d705b, 2.25);
scene.add(hemisphere);
const sunlight = new THREE.DirectionalLight(0xfff0d2, 3.6);
sunlight.position.set(-16, 27, 19);
sunlight.target.position.set(0, 2, -2);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(2048, 2048);
sunlight.shadow.camera.left = -27;
sunlight.shadow.camera.right = 27;
sunlight.shadow.camera.top = 25;
sunlight.shadow.camera.bottom = -25;
sunlight.shadow.camera.near = 2;
sunlight.shadow.camera.far = 80;
sunlight.shadow.bias = -0.0004;
sunlight.shadow.normalBias = 0.035;
scene.add(sunlight, sunlight.target);
// -------------------------------------------------------------------------
// Plaza paving
// -------------------------------------------------------------------------
const ground = group(scene);
box(ground, [34, 0.64, 26], [0, -0.34, 1.2], 0x796b60, [0, 0, 0], {
cast: false,
});
const pavingMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
});
function pavingField(x0, x1, z0, z1, sx, sz, palette, y = 0.025) {
const nx = Math.ceil((x1 - x0) / sx);
const nz = Math.ceil((z1 - z0) / sz);
const count = nx * nz;
const mesh = new THREE.InstancedMesh(unitBox, pavingMaterial, count);
const dummy = new THREE.Object3D();
let index = 0;
for (let ix = 0; ix < nx; ix++) {
for (let iz = 0; iz < nz; iz++) {
const x = x0 + (ix + 0.5) * sx;
const z = z0 + (iz + 0.5) * sz;
dummy.position.set(x, y, z);
dummy.scale.set(sx - 0.055, 0.05, sz - 0.055);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
mesh.setColorAt(
index,
new THREE.Color(palette[Math.floor(Math.random() * palette.length)])
);
index++;
}
}
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = false;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
pavingField(
-16.2,
16.2,
-11.3,
-5.7,
1.18,
1.18,
[0xb9ad95, 0xc3b79e, 0xafa58f, 0xc9bda4]
);
pavingField(
-16.2,
16.2,
-5.65,
13.6,
1.18,
1.18,
[0xc9bda5, 0xd0c4aa, 0xbfb49e, 0xd7cbb1, 0xb9b19f]
);
// A continuous, unobstructed curb defines the arcade route.
box(ground, [32.4, 0.13, 0.18], [0, 0.08, -5.63], 0xe1d3ae, [0, 0, 0], {
cast: false,
});
box(ground, [32.4, 0.13, 0.18], [0, 0.08, -11.25], 0xe1d3ae, [0, 0, 0], {
cast: false,
});
// -------------------------------------------------------------------------
// Continuous Plaza Mayor-style arcade
// -------------------------------------------------------------------------
const building = group(scene);
// Passage behind the columns.
box(building, [29, 7.2, 0.45], [0, 3.6, -11.45], 0x773d34);
box(building, [0.45, 7.2, 4.7], [-14.45, 3.6, -8.7], 0x864437);
box(building, [0.45, 7.2, 4.7], [14.45, 3.6, -8.7], 0x864437);
// Upper wall.
box(building, [29.1, 4.8, 2.65], [0, 7.7, -8.5], 0xa6533f);
box(building, [29.65, 0.28, 3.9], [0, 5.38, -8.15], 0xe0c38f);
box(building, [29.8, 0.34, 4.45], [0, 10.17, -8.65], 0xe0c38f);
box(building, [30.2, 0.62, 4.85], [0, 10.61, -8.75], 0x46555c);
const columnXs = [-14, -10, -6, -2, 2, 6, 10, 14];
const brickColors = [0xa6533f, 0xad5941, 0x9e4e3b];
columnXs.forEach((x, index) => {
const brick = brickColors[index % brickColors.length];
box(building, [1.06, 0.34, 1.4], [x, 0.18, -7.45], 0xd5b783);
box(building, [0.72, 5.62, 0.98], [x, 3.05, -7.45], brick);
box(building, [1.07, 0.37, 1.32], [x, 5.94, -7.45], 0xdcc28d);
// Pale quoins emphasize the voxel rhythm.
box(building, [0.12, 5.3, 0.12], [x - 0.26, 3.0, -6.93], 0xe1c896);
box(building, [0.12, 5.3, 0.12], [x + 0.26, 3.0, -6.93], 0xe1c896);
});
// Stepped, block-built arches.
const archCenters = [-12, -8, -4, 0, 4, 8, 12];
archCenters.forEach((cx, bayIndex) => {
const archBrick = brickColors[bayIndex % brickColors.length];
const archParts = [
{ x: -1.34, y: 3.52, w: 0.42, h: 0.68 },
{ x: 1.34, y: 3.52, w: 0.42, h: 0.68 },
{ x: -1.10, y: 4.02, w: 0.55, h: 0.52 },
{ x: 1.10, y: 4.02, w: 0.55, h: 0.52 },
{ x: -0.80, y: 4.43, w: 0.58, h: 0.43 },
{ x: 0.80, y: 4.43, w: 0.58, h: 0.43 },
{ x: -0.42, y: 4.75, w: 0.56, h: 0.38 },
{ x: 0.42, y: 4.75, w: 0.56, h: 0.38 },
];
archParts.forEach((part) => {
box(
building,
[part.w, part.h, 1.03],
[cx + part.x, part.y, -7.0],
archBrick
);
});
box(building, [0.48, 0.52, 1.12], [cx, 4.92, -6.98], 0xe2c991);
});
// Upper windows, shutters and little balconies.
archCenters.forEach((x, index) => {
const windowY = 7.63;
const shutter = index % 3 === 0 ? 0x4f6a63 : 0x526a6b;
box(building, [1.9, 2.45, 0.17], [x, windowY, -7.08], 0xe6cf99);
box(building, [1.55, 2.1, 0.12], [x, windowY, -6.96], 0x273b40);
box(building, [0.12, 2.13, 0.14], [x, windowY, -6.86], 0xd9bf86);
box(building, [0.58, 2.18, 0.15], [x - 1.18, windowY, -6.94], shutter);
box(building, [0.58, 2.18, 0.15], [x + 1.18, windowY, -6.94], shutter);
for (let s = -1; s <= 1; s++) {
box(building, [0.38, 0.055, 0.12], [x + s * 0.35, windowY + 0.58, -6.83], 0xcbb17d);
box(building, [0.38, 0.055, 0.12], [x + s * 0.35, windowY - 0.58, -6.83], 0xcbb17d);
}
box(building, [2.38, 0.16, 0.65], [x, windowY - 1.27, -6.72], 0xd7bd83);
box(building, [0.13, 0.64, 0.13], [x - 1.05, windowY - 0.94, -6.38], 0x4b5756);
box(building, [0.13, 0.64, 0.13], [x + 1.05, windowY - 0.94, -6.38], 0x4b5756);
box(building, [2.1, 0.09, 0.09], [x, windowY - 0.66, -6.38], 0x4b5756);
// Stepped stone pediment.
box(building, [2.3, 0.18, 0.42], [x, windowY + 1.31, -6.84], 0xe7d19c);
box(building, [1.55, 0.18, 0.44], [x, windowY + 1.48, -6.82], 0xe7d19c);
box(building, [0.76, 0.18, 0.46], [x, windowY + 1.65, -6.8], 0xe7d19c);
});
// Warm square lanterns between bays.
const lanternMaterial = new THREE.MeshStandardMaterial({
color: 0xffd98c,
emissive: 0xffa735,
emissiveIntensity: 2.2,
roughness: 0.7,
});
columnXs.slice(0, -1).forEach((x) => {
box(building, [0.19, 0.29, 0.18], [x + 2, 2.8, -6.78], 0x394749);
box(
building,
[0.31, 0.4, 0.25],
[x + 2, 2.8, -6.58],
0xffd98c,
[0, 0, 0],
{ material: lanternMaterial }
);
});
// Small roof dormers.
for (let x = -12; x <= 12; x += 4) {
if (x === 0) continue;
box(building, [1.25, 1.05, 1.0], [x, 11.22, -7.18], 0xd7bd83);
box(building, [0.78, 0.72, 0.12], [x, 11.2, -6.64], 0x31464b);
box(building, [1.48, 0.17, 1.15], [x, 11.79, -7.18], 0x405158);
}
// Central clock tower.
const clockTower = group(building);
box(clockTower, [4.05, 0.35, 3.55], [0, 10.78, -8.45], 0xd7bd83);
box(clockTower, [3.5, 3.95, 3.0], [0, 12.9, -8.45], 0xa9533e);
box(clockTower, [3.72, 0.22, 3.2], [0, 14.86, -8.45], 0xe3c994);
const roofLayers = [
[4.25, 0.45],
[3.65, 0.45],
[3.05, 0.45],
[2.45, 0.45],
[1.82, 0.42],
[1.2, 0.38],
];
roofLayers.forEach(([size, height], index) => {
box(
clockTower,
[size, height, size * 0.78],
[0, 15.08 + index * 0.43, -8.45],
index % 2 === 0 ? 0x43545a : 0x4c5d62
);
});
box(clockTower, [0.09, 1.55, 0.09], [0, 17.9, -8.45], 0x404b4d);
box(clockTower, [0.83, 0.43, 0.08], [0.4, 18.5, -8.45], 0xb54b37);
// Pixel clock face.
box(clockTower, [1.78, 1.78, 0.14], [0, 13.13, -6.88], 0xe7d19a);
box(clockTower, [1.51, 1.51, 0.1], [0, 13.13, -6.77], 0x24383d);
box(clockTower, [0.105, 0.7, 0.07], [-0.18, 13.32, -6.69], 0xf5df9c, [0, 0, -0.55]);
box(clockTower, [0.105, 0.55, 0.07], [0.19, 13.2, -6.68], 0xf5df9c, [0, 0, 0.78]);
box(clockTower, [0.09, 0.09, 0.09], [0, 13.13, -6.63], 0xf5df9c);
// End turrets.
[-14.15, 14.15].forEach((x) => {
const turret = group(building);
box(turret, [2.35, 3.35, 3.0], [x, 11.72, -8.65], 0xa4523f);
box(turret, [2.6, 0.22, 3.24], [x, 13.48, -8.65], 0xdcc28d);
box(turret, [2.05, 0.43, 2.6], [x, 13.79, -8.65], 0x46565b);
box(turret, [1.55, 0.43, 2.05], [x, 14.08, -8.65], 0x506166);
box(turret, [1.02, 0.38, 1.45], [x, 14.35, -8.65], 0x46565b);
box(turret, [0.08, 1.1, 0.08], [x, 15.04, -8.65], 0x424d4e);
});
// -------------------------------------------------------------------------
// Benches and voxel people
// -------------------------------------------------------------------------
function makeBench(position, rotationY = 0) {
const bench = group(scene, position, rotationY);
box(bench, [3.65, 0.23, 0.78], [0, 0.69, 0], 0x9a6844);
box(bench, [3.85, 0.18, 0.9], [0, 0.52, 0], 0x754735);
box(bench, [3.65, 0.72, 0.18], [0, 1.05, -0.34], 0x9a6844);
box(bench, [0.26, 0.6, 0.62], [-1.35, 0.3, 0], 0x394647);
box(bench, [0.26, 0.6, 0.62], [1.35, 0.3, 0], 0x394647);
box(bench, [0.18, 0.72, 0.18], [-1.55, 1.0, -0.4], 0x394647);
box(bench, [0.18, 0.72, 0.18], [1.55, 1.0, -0.4], 0x394647);
return bench;
}
function makePerson(options = {}) {
const {
shirt = 0xc65d43,
pants = 0x354a55,
skin = 0xd9a276,
hair = 0x4b352b,
hat = null,
seated = false,
scale = 1,
} = options;
const root = new THREE.Group();
root.scale.setScalar(scale);
scene.add(root);
const parts = { legs: [], arms: [] };
if (seated) {
box(root, [0.66, 0.28, 0.45], [0, 0.73, 0.12], pants);
const torso = box(root, [0.7, 0.83, 0.42], [0, 1.22, 0.03], shirt);
torso.rotation.x = -0.08;
box(root, [0.5, 0.5, 0.48], [0, 1.95, 0.07], skin);
box(root, [0.54, 0.18, 0.52], [0, 2.18, 0.05], hair);
box(root, [0.12, 0.12, 0.13], [0, 1.95, 0.34], skin);
[-0.18, 0.18].forEach((x) => {
box(root, [0.27, 0.28, 0.78], [x, 0.76, 0.47], pants);
box(root, [0.23, 0.59, 0.24], [x, 0.4, 0.78], pants);
box(root, [0.28, 0.16, 0.43], [x, 0.1, 0.88], 0x34393a);
});
[-1, 1].forEach((side) => {
const arm = group(root, [side * 0.48, 1.53, 0.02]);
box(arm, [0.2, 0.63, 0.23], [0, -0.25, 0.05], shirt);
box(arm, [0.19, 0.22, 0.2], [0, -0.59, 0.11], skin);
arm.rotation.x = -0.32;
arm.rotation.z = side * 0.08;
parts.arms.push(arm);
});
} else {
box(root, [0.66, 0.29, 0.43], [0, 1.01, 0], pants);
box(root, [0.72, 0.87, 0.44], [0, 1.48, 0], shirt);
box(root, [0.52, 0.51, 0.5], [0, 2.22, 0], skin);
box(root, [0.56, 0.18, 0.54], [0, 2.46, -0.02], hair);
box(root, [0.12, 0.13, 0.14], [0, 2.21, 0.3], skin);
[-1, 1].forEach((side) => {
const leg = group(root, [side * 0.2, 1.0, 0]);
box(leg, [0.26, 0.83, 0.28], [0, -0.43, 0], pants);
box(leg, [0.29, 0.18, 0.43], [0, -0.85, 0.08], 0x343a3c);
parts.legs.push(leg);
const arm = group(root, [side * 0.51, 1.81, 0]);
box(arm, [0.2, 0.72, 0.24], [0, -0.34, 0], shirt);
box(arm, [0.19, 0.22, 0.21], [0, -0.74, 0], skin);
parts.arms.push(arm);
});
}
if (hat) {
box(root, [0.66, 0.16, 0.66], [0, 2.52, 0], hat);
box(root, [0.68, 0.08, 0.35], [0, 2.44, 0.33], hat);
}
root.userData.parts = parts;
root.userData.seated = seated;
return root;
}
makeBench([4.25, 0.04, 1.3], 0);
makeBench([6.7, 0.04, -0.95], -Math.PI / 2);
const seatedReader = makePerson({
seated: true,
shirt: 0x607b76,
pants: 0x4b4440,
skin: 0xc78f68,
hair: 0x3a302d,
hat: 0xd7b273,
});
seatedReader.position.set(3.65, 0.06, 1.18);
seatedReader.rotation.y = 0.03;
// A small open book.
box(seatedReader, [0.48, 0.08, 0.35], [0, 1.38, 0.43], 0xf0dfba, [0.12, 0, 0]);
box(seatedReader, [0.025, 0.06, 0.36], [0, 1.43, 0.43], 0x9f6948);
const seatedFriend = makePerson({
seated: true,
shirt: 0xd18a53,
pants: 0x3d5260,
skin: 0xe0ae83,
hair: 0x81543a,
});
seatedFriend.position.set(4.82, 0.06, 1.18);
seatedFriend.rotation.y = -0.08;
const seatedVisitor = makePerson({
seated: true,
shirt: 0x9a5a70,
pants: 0x41444b,
skin: 0xb97f5b,
hair: 0x282a2b,
scale: 0.94,
});
seatedVisitor.position.set(6.62, 0.06, -1.15);
seatedVisitor.rotation.y = -Math.PI / 2;
// -------------------------------------------------------------------------
// Original temporary vendor cart: "BOCATOS"
// -------------------------------------------------------------------------
const stall = group(scene, [-0.7, 0.05, 1.45]);
const stallWood = 0x8f5938;
const stallDarkWood = 0x593b2d;
// Cart body and counter.
box(stall, [3.85, 0.28, 1.72], [0, 0.86, 0], stallDarkWood);
box(stall, [3.55, 0.94, 1.46], [0, 1.38, 0], stallWood);
box(stall, [4.2, 0.24, 1.92], [0, 1.96, 0], 0xc98b4d);
box(stall, [3.58, 0.12, 1.5], [0, 0.87, 0], 0x37494c);
// Vertical paneling.
for (let x = -1.45; x <= 1.46; x += 0.48) {
box(stall, [0.09, 0.72, 0.08], [x, 1.36, 0.77], 0xb87845);
}
// Pixel wheels, axle aligned across the cart.
function pixelWheel(parent, x, radius = 0.56) {
const wheel = group(parent, [x, 0.63, 0]);
const pieces = 8;
for (let i = 0; i < pieces; i++) {
const angle = (i / pieces) * Math.PI * 2;
const py = Math.sin(angle) * radius;
const pz = Math.cos(angle) * radius;
box(
wheel,
[0.22, 0.27, 0.27],
[0, py, pz],
0x30383a,
[angle, 0, 0]
);
}
box(wheel, [0.28, 0.22, 0.22], [0, 0, 0], 0xb49258);
box(wheel, [0.31, 0.09, 0.72], [0, 0, 0], 0x4b4740);
}
pixelWheel(stall, -1.86);
pixelWheel(stall, 1.86);
// Canopy posts.
[-2.0, 2.0].forEach((x) => {
box(stall, [0.13, 2.02, 0.13], [x, 3.0, -0.76], 0x4a4740);
box(stall, [0.13, 2.02, 0.13], [x, 3.0, 0.76], 0x4a4740);
});
// Striped canopy.
box(stall, [4.78, 0.16, 2.4], [0, 4.05, 0], 0xf0dfb8);
for (let i = 0; i < 10; i++) {
const x = -2.15 + i * 0.48;
box(
stall,
[0.48, 0.09, 2.44],
[x, 4.16, 0],
i % 2 === 0 ? 0xb84f3c : 0xf0dfb8
);
}
// Scalloped-looking square valance.
for (let i = 0; i < 10; i++) {
const x = -2.15 + i * 0.48;
box(
stall,
[0.46, 0.37, 0.12],
[x, 3.83, 1.15],
i % 2 === 0 ? 0xb84f3c : 0xf0dfb8
);
}
// Hanging original sign.
box(stall, [2.75, 0.91, 0.18], [0, 3.25, 1.19], 0x4c382d);
makeTextSign(
stall,
"BOCATOS",
"CAFÉ DE BOLSA · MADRID",
2.55,
0.73,
[0, 3.25, 1.295],
"#f1dfb6",
"#4b3029"
);
// Products displayed as little voxel parcels.
const productColors = [
0xc9573e,
0xe2a33d,
0x6f8a63,
0xe3c884,
0x845548,
0xd27a54,
];
for (let i = 0; i < 12; i++) {
const x = -1.55 + (i % 6) * 0.62;
const z = i < 6 ? -0.42 : 0.25;
const color = productColors[i % productColors.length];
box(stall, [0.38, 0.34, 0.36], [x, 2.25, z], color);
box(stall, [0.4, 0.07, 0.38], [x, 2.45, z], 0xf0d49b);
}
// Small brass bell.
box(stall, [0.08, 0.43, 0.08], [1.78, 3.65, 0.93], 0x806a3e);
box(stall, [0.31, 0.23, 0.31], [1.78, 3.37, 0.93], 0xc49a4d);
// Crates beside the cart.
box(stall, [0.75, 0.56, 0.67], [-2.52, 0.33, 0.1], 0x785037);
box(stall, [0.79, 0.1, 0.7], [-2.52, 0.65, 0.1], 0xa47547);
box(stall, [0.66, 0.42, 0.61], [-2.58, 0.94, 0.08], 0x8b623f);
// Menu easel.
const easel = group(stall, [2.65, 0, 0.65], -0.13);
box(easel, [0.12, 1.8, 0.12], [-0.42, 0.9, 0], 0x5c4433, [0, 0, -0.08]);
box(easel, [0.12, 1.8, 0.12], [0.42, 0.9, 0], 0x5c4433, [0, 0, 0.08]);
box(easel, [1.16, 1.0, 0.13], [0, 1.53, 0.05], 0x3f332d);
makeTextSign(
easel,
"HOY",
"CAFÉ 2€\nBOLLOS 2€",
1.02,
0.82,
[0, 1.53, 0.125],
"#e9d8ae",
"#49342b"
);
// Vendor behind the counter.
const vendor = makePerson({
shirt: 0x6a7e66,
pants: 0x4c4339,
skin: 0xc88f65,
hair: 0x3e3029,
hat: 0xe5c98f,
scale: 0.96,
});
stall.add(vendor);
vendor.position.set(0.65, 0.02, -0.93);
vendor.rotation.y = Math.PI;
vendor.userData.parts.arms[0].rotation.x = -0.65;
vendor.userData.parts.arms[1].rotation.x = -0.45;
// Customers in the plaza side, never in the arcade passage.
const customerA = makePerson({
shirt: 0xe1b353,
pants: 0x465d67,
skin: 0xe1ac81,
hair: 0x674530,
});
customerA.position.set(-3.15, 0.06, 3.22);
customerA.rotation.y = 0.2;
const customerB = makePerson({
shirt: 0x6b7798,
pants: 0x3e4348,
skin: 0x9f694d,
hair: 0x262526,
hat: 0xc87855,
});
customerB.position.set(1.2, 0.06, 3.45);
customerB.rotation.y = -0.36;
const customerC = makePerson({
shirt: 0xb65e4d,
pants: 0x3f4d54,
skin: 0xd4a078,
hair: 0x8a694e,
scale: 0.91,
});
customerC.position.set(2.1, 0.06, 0.6);
customerC.rotation.y = -0.9;
// Market string lights, contained on the plaza side of the arcade.
const lightString = group(scene, [-0.7, 0.05, 4.25]);
box(lightString, [0.13, 4.25, 0.13], [-3.4, 2.12, 0], 0x4d514d);
box(lightString, [0.13, 4.25, 0.13], [3.4, 2.12, 0], 0x4d514d);
box(lightString, [6.85, 0.055, 0.055], [0, 4.12, 0], 0x3f4746);
const bulbColors = [0xffd58a, 0xf0a36b, 0xffe8b1];
for (let i = 0; i < 9; i++) {
const x = -3.05 + i * 0.76;
const y = 4.02 - Math.sin((i / 8) * Math.PI) * 0.25;
box(lightString, [0.055, 0.2, 0.055], [x, y + 0.11, 0], 0x343b3d);
box(
lightString,
[0.17, 0.2, 0.17],
[x, y - 0.07, 0],
bulbColors[i % bulbColors.length],
[0, 0, 0],
{ material: lanternMaterial }
);
}
// -------------------------------------------------------------------------
// Voxel equestrian statue in the plaza
// -------------------------------------------------------------------------
const statue = group(scene, [-8.0, 0.05, 4.35], -0.18);
const bronze = 0x55736b;
const bronzeDark = 0x3e5b55;
box(statue, [2.8, 0.7, 2.8], [0, 0.35, 0], 0x9a8b72);
box(statue, [2.1, 0.62, 2.1], [0, 0.96, 0], 0xb3a186);
box(statue, [1.58, 0.24, 1.58], [0, 1.38, 0], 0xcab596);
const horse = group(statue, [0, 1.48, 0]);
box(horse, [1.95, 0.68, 0.58], [0, 1.5, 0], bronze);
box(horse, [0.82, 0.28, 0.65], [-0.3, 1.9, 0], bronzeDark);
[-0.58, 0.58].forEach((x) => {
[-0.2, 0.2].forEach((z) => {
box(horse, [0.25, 1.05, 0.25], [x, 0.83, z], bronzeDark);
box(horse, [0.35, 0.2, 0.38], [x, 0.28, z + 0.04], bronze);
});
});
box(horse, [0.44, 1.16, 0.46], [0.78, 2.03, 0], bronze, [0, 0, -0.22]);
box(horse, [0.9, 0.46, 0.47], [1.2, 2.46, 0], bronze);
box(horse, [0.46, 0.31, 0.42], [1.59, 2.4, 0], bronzeDark);
box(horse, [0.33, 0.45, 0.32], [-1.08, 1.73, 0], bronzeDark, [0, 0, 0.5]);
// Rider.
box(horse, [0.62, 0.78, 0.46], [-0.08, 2.57, 0], bronze);
box(horse, [0.42, 0.43, 0.42], [-0.02, 3.16, 0], bronze);
box(horse, [0.18, 0.75, 0.18], [-0.48, 2.65, 0], bronze, [0, 0, -0.4]);
box(horse, [0.18, 0.75, 0.18], [0.38, 2.65, 0], bronze, [0, 0, 0.45]);
box(horse, [0.19, 0.85, 0.19], [-0.08, 2.15, 0.25], bronzeDark, [0, 0, 0.22]);
box(horse, [0.19, 0.85, 0.19], [-0.08, 2.15, -0.25], bronzeDark, [0, 0, -0.22]);
// -------------------------------------------------------------------------
// Passing pedestrians along the continuous arcade route
// -------------------------------------------------------------------------
const walkers = [];
function addWalker(options) {
const walker = makePerson(options);
walker.rotation.y = options.direction > 0 ? Math.PI / 2 : -Math.PI / 2;
walker.userData.walk = {
offset: options.offset,
speed: options.speed,
direction: options.direction,
lane: options.lane,
phase: Math.random() * Math.PI * 2,
};
walkers.push(walker);
return walker;
}
addWalker({
shirt: 0x4e7180,
pants: 0x303b43,
skin: 0xc78f66,
hair: 0x322925,
hat: 0xd7b16b,
offset: 1.5,
speed: 0.72,
direction: 1,
lane: -9.0,
scale: 0.98,
});
addWalker({
shirt: 0xc16a4d,
pants: 0x41464b,
skin: 0xe0ac82,
hair: 0x72503b,
offset: 8.2,
speed: 0.64,
direction: 1,
lane: -8.35,
});
addWalker({
shirt: 0x7b8a66,
pants: 0x4d4b43,
skin: 0xa96f4e,
hair: 0x242728,
offset: 4.1,
speed: 0.8,
direction: -1,
lane: -9.45,
});
addWalker({
shirt: 0xd9b06d,
pants: 0x3e5360,
skin: 0xd7a37b,
hair: 0x785640,
offset: 16.5,
speed: 0.68,
direction: -1,
lane: -8.7,
scale: 0.92,
});
addWalker({
shirt: 0x746582,
pants: 0x35424b,
skin: 0xe3b08a,
hair: 0x9d7554,
offset: 22.8,
speed: 0.76,
direction: 1,
lane: -9.7,
});
// A shopper's tote.
const tote = box(
walkers[0],
[0.42, 0.55, 0.25],
[0.58, 1.16, 0],
0xd8c690
);
tote.rotation.z = -0.08;
// -------------------------------------------------------------------------
// Plaza edge details: lamps, bollards, small tables and pigeons
// -------------------------------------------------------------------------
function addLamp(x) {
const lamp = group(scene, [x, 0.05, -5.05]);
box(lamp, [0.48, 0.18, 0.48], [0, 0.1, 0], 0x3d4848);
box(lamp, [0.14, 3.15, 0.14], [0, 1.68, 0], 0x394546);
box(lamp, [0.55, 0.16, 0.55], [0, 3.31, 0], 0x3c4748);
box(
lamp,
[0.42, 0.63, 0.42],
[0, 3.67, 0],
0xffd98c,
[0, 0, 0],
{ material: lanternMaterial }
);
box(lamp, [0.6, 0.14, 0.6], [0, 4.06, 0], 0x394546);
}
[-11.5, -5.2, 5.2, 11.5].forEach(addLamp);
[-13, -9, -7, -3, 3, 7, 9, 13].forEach((x) => {
box(scene, [0.22, 0.73, 0.22], [x, 0.38, -5.08], 0x3f4b4b);
box(scene, [0.29, 0.11, 0.29], [x, 0.76, -5.08], 0x303b3c);
});
// A bistro table with two block chairs.
const table = group(scene, [7.0, 0.05, 4.25], -0.12);
box(table, [0.12, 1.25, 0.12], [0, 0.62, 0], 0x3e4849);
box(table, [1.45, 0.13, 1.45], [0, 1.28, 0], 0xb98550);
box(table, [1.1, 0.12, 1.1], [0, 0.08, 0], 0x3e4849);
[-1, 1].forEach((side) => {
const chair = group(table, [side * 1.0, 0, 0]);
box(chair, [0.75, 0.16, 0.72], [0, 0.62, 0], 0x6d7d69);
box(chair, [0.75, 0.85, 0.13], [0, 1.0, -0.32], 0x6d7d69);
box(chair, [0.12, 0.62, 0.12], [-0.26, 0.31, -0.24], 0x3d4748);
box(chair, [0.12, 0.62, 0.12], [0.26, 0.31, -0.24], 0x3d4748);
});
function pigeon(x, z, rotationY = 0) {
const bird = group(scene, [x, 0.08, z], rotationY);
box(bird, [0.43, 0.28, 0.3], [0, 0.2, 0], 0x85898a);
box(bird, [0.23, 0.24, 0.23], [0.21, 0.39, 0], 0x9fa2a0);
box(bird, [0.09, 0.08, 0.09], [0.34, 0.39, 0], 0xd6a44f);
box(bird, [0.34, 0.08, 0.16], [-0.15, 0.29, 0], 0x596366);
box(bird, [0.06, 0.2, 0.06], [-0.08, 0.03, 0.09], 0xd3a14c);
box(bird, [0.06, 0.2, 0.06], [0.08, 0.03, 0.09], 0xd3a14c);
}
pigeon(-5.2, 5.3, 0.8);
pigeon(-4.75, 5.45, -0.3);
pigeon(5.5, 6.1, 2.1);
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
let paused = false;
let simulationTime = 0;
let previousTime = performance.now();
motionButton.addEventListener("click", () => {
paused = !paused;
motionButton.textContent = paused ? "Resume motion" : "Pause motion";
});
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (!paused) simulationTime += delta;
walkers.forEach((walker) => {
const data = walker.userData.walk;
const routeLength = 28.6;
const travel = data.offset + simulationTime * data.speed;
const wrapped = ((travel % routeLength) + routeLength) % routeLength;
walker.position.x =
data.direction > 0 ? -14.3 + wrapped : 14.3 - wrapped;
walker.position.z = data.lane;
const stride = simulationTime * data.speed * 6.2 + data.phase;
walker.position.y = 0.06 + Math.abs(Math.sin(stride)) * 0.025;
const { legs, arms } = walker.userData.parts;
legs[0].rotation.x = Math.sin(stride) * 0.56;
legs[1].rotation.x = -Math.sin(stride) * 0.56;
arms[0].rotation.x = -Math.sin(stride) * 0.43;
arms[1].rotation.x = Math.sin(stride) * 0.43;
});
// Quiet idle movements for the seated group.
seatedReader.userData.parts.arms[0].rotation.x =
-0.5 + Math.sin(simulationTime * 0.8) * 0.035;
seatedFriend.userData.parts.arms[1].rotation.x =
-0.3 + Math.sin(simulationTime * 0.65 + 1.2) * 0.04;
seatedVisitor.rotation.z = Math.sin(simulationTime * 0.48) * 0.012;
// Vendor works behind the counter.
vendor.userData.parts.arms[0].rotation.x =
-0.65 + Math.sin(simulationTime * 1.6) * 0.09;
vendor.userData.parts.arms[1].rotation.x =
-0.45 + Math.sin(simulationTime * 1.6 + 1.4) * 0.08;
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
// Remove the loading veil once the first frame is ready.
requestAnimationFrame(() => {
loading.classList.add("hidden");
window.setTimeout(() => loading.remove(), 450);
});
</script>
</body>
</html>
```