Prompt specification
Build or customize the Three.js 3D scene "Liberdade neighborhood street slice" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Liberdade neighborhood street slice
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/liberdade-neighborhood-street-slice-x2711
Scene Description Prompt:
Create a standalone voxel scene in one HTML file using Three.js from cdnjs. Build a bounded voxel scene of a recognizable Liberdade street segment with repeated lanterns, varied storefronts, and a small gathering space. Avoid treating every storefront as identical.
Working Three.js Starter (liberdade-neighborhood-street-slice-x2711):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Liberdade — Voxel Street</title>
<style>
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9d8e4;
font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
#hud {
position: fixed;
left: 18px;
top: 18px;
z-index: 2;
max-width: min(360px, calc(100vw - 36px));
padding: 14px 16px;
color: #fff8e8;
background: rgba(28, 42, 43, .82);
border: 1px solid rgba(255, 238, 183, .38);
border-radius: 10px;
box-shadow: 0 8px 30px rgba(16, 28, 28, .22);
backdrop-filter: blur(8px);
pointer-events: none;
}
#hud h1 {
margin: 0 0 4px;
color: #ffd36a;
font-size: 18px;
letter-spacing: .08em;
text-transform: uppercase;
}
#hud p {
margin: 0;
font-size: 12px;
line-height: 1.5;
color: #f2ead6;
}
#hint {
margin-top: 9px !important;
color: #b8d9d2 !important;
font-size: 11px !important;
}
</style>
</head>
<body>
<div id="hud">
<h1>Liberdade</h1>
<p>A bounded voxel interpretation of São Paulo's lantern-lit cultural district.</p>
<p id="hint">Drag: orbit · Wheel: zoom · Shift/right-drag: pan · R: reset</p>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, camera, lighting
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#b9d8e4");
scene.fog = new THREE.Fog("#b9d8e4", 42, 78);
const camera = new THREE.PerspectiveCamera(38, innerWidth / innerHeight, 0.1, 140);
scene.add(new THREE.HemisphereLight("#dff4ff", "#806853", 2.25));
const sun = new THREE.DirectionalLight("#fff1cf", 3.15);
sun.position.set(-10, 21, 15);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -23;
sun.shadow.camera.right = 23;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight("#9bd8e8", 0.65);
fill.position.set(15, 9, -12);
scene.add(fill);
// ------------------------------------------------------------
// Shared helpers and materials
// ------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color, roughness = 0.82, metalness = 0, extra = {}) {
const key = [color, roughness, metalness, JSON.stringify(extra)].join("|");
if (!materialCache.has(key)) {
materialCache.set(key, new THREE.MeshStandardMaterial({
color, roughness, metalness, ...extra
}));
}
return materialCache.get(key);
}
const M = {
base: material("#344c4c"),
baseEdge: material("#203838"),
ground: material("#d7c8aa"),
road: material("#414a4d"),
roadPatch: material("#485154"),
curb: material("#d7d0bd"),
sidewalk: material("#c9c1ad"),
tileDark: material("#a9a18f"),
yellow: material("#e9bb38"),
white: material("#f4f0df"),
black: material("#20282a"),
glass: material("#375d68", 0.3, 0.15),
litGlass: material("#ffd781", 0.35, 0.05, {
emissive: "#c27d21", emissiveIntensity: 0.35
}),
red: material("#b8272f"),
redLight: material("#d53b35"),
gold: material("#e5b64c"),
navy: material("#24445f"),
teal: material("#287b78"),
cream: material("#f1e1bc"),
green: material("#397c55"),
leaf: material("#3d8f55"),
leafLight: material("#65a95e"),
wood: material("#835437"),
skin1: material("#d7a071"),
skin2: material("#9e6546"),
skin3: material("#f0bf91"),
hair: material("#302723"),
planter: material("#986a43")
};
function box(w, h, d, x, y, z, mat, parent = scene, cast = true, receive = true) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
function beamBetween(a, b, thickness, mat, parent = scene) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const mesh = new THREE.Mesh(unitBox, mat);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.scale.set(thickness, thickness, length);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
direction.normalize()
);
mesh.castShadow = false;
parent.add(mesh);
return mesh;
}
function textureFromCanvas(canvas) {
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.magFilter = THREE.NearestFilter;
texture.minFilter = THREE.NearestFilter;
texture.generateMipmaps = false;
return texture;
}
// Compact 5×7 pixel alphabet, rendered into canvas textures.
const FONT = {
A:["01110","10001","10001","11111","10001","10001","10001"],
B:["11110","10001","10001","11110","10001","10001","11110"],
C:["01111","10000","10000","10000","10000","10000","01111"],
D:["11110","10001","10001","10001","10001","10001","11110"],
E:["11111","10000","10000","11110","10000","10000","11111"],
F:["11111","10000","10000","11110","10000","10000","10000"],
G:["01111","10000","10000","10111","10001","10001","01111"],
H:["10001","10001","10001","11111","10001","10001","10001"],
I:["11111","00100","00100","00100","00100","00100","11111"],
J:["00111","00010","00010","00010","10010","10010","01100"],
K:["10001","10010","10100","11000","10100","10010","10001"],
L:["10000","10000","10000","10000","10000","10000","11111"],
M:["10001","11011","10101","10101","10001","10001","10001"],
N:["10001","11001","10101","10011","10001","10001","10001"],
O:["01110","10001","10001","10001","10001","10001","01110"],
P:["11110","10001","10001","11110","10000","10000","10000"],
Q:["01110","10001","10001","10001","10101","10010","01101"],
R:["11110","10001","10001","11110","10100","10010","10001"],
S:["01111","10000","10000","01110","00001","00001","11110"],
T:["11111","00100","00100","00100","00100","00100","00100"],
U:["10001","10001","10001","10001","10001","10001","01110"],
V:["10001","10001","10001","10001","10001","01010","00100"],
W:["10001","10001","10001","10101","10101","10101","01010"],
X:["10001","10001","01010","00100","01010","10001","10001"],
Y:["10001","10001","01010","00100","00100","00100","00100"],
Z:["11111","00001","00010","00100","01000","10000","11111"],
0:["01110","10001","10011","10101","11001","10001","01110"],
1:["00100","01100","00100","00100","00100","00100","01110"],
2:["01110","10001","00001","00010","00100","01000","11111"],
3:["11110","00001","00001","01110","00001","00001","11110"],
4:["00010","00110","01010","10010","11111","00010","00010"],
5:["11111","10000","10000","11110","00001","00001","11110"],
6:["01110","10000","10000","11110","10001","10001","01110"],
7:["11111","00001","00010","00100","01000","01000","01000"],
8:["01110","10001","10001","01110","10001","10001","01110"],
9:["01110","10001","10001","01111","00001","00001","01110"],
"?":["01110","10001","00010","00100","00100","00000","00100"],
" ":["00000","00000","00000","00000","00000","00000","00000"]
};
function pixelTexture(text, bg = "#ffffff", fg = "#111111") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.fillStyle = bg;
ctx.fillRect(0, 0, canvas.width, canvas.height);
const chars = text.toUpperCase().split("");
const cell = Math.max(4, Math.min(12, Math.floor(472 / (chars.length * 6))));
const totalWidth = chars.length * 6 * cell - cell;
let cursor = (512 - totalWidth) / 2;
const top = (128 - 7 * cell) / 2;
chars.forEach(char => {
const glyph = FONT[char] || FONT["?"];
glyph.forEach((row, y) => {
[...row].forEach((bit, x) => {
if (bit === "1") {
ctx.fillStyle = fg;
ctx.fillRect(cursor + x * cell, top + y * cell, cell, cell);
}
});
});
cursor += 6 * cell;
});
return textureFromCanvas(canvas);
}
function cjkTexture(glyph, bg = "#b4252d", fg = "#f4cf60") {
const canvas = document.createElement("canvas");
canvas.width = 160;
canvas.height = 200;
const ctx = canvas.getContext("2d");
ctx.fillStyle = bg;
ctx.fillRect(0, 0, 160, 200);
ctx.strokeStyle = fg;
ctx.lineWidth = 8;
ctx.strokeRect(9, 9, 142, 182);
ctx.fillStyle = fg;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = 'bold 112px "Noto Sans CJK SC", "Microsoft YaHei", sans-serif';
ctx.fillText(glyph, 80, 102);
return textureFromCanvas(canvas);
}
function signPanel(x, y, z, w, h, text, bg, fg, parent = scene) {
box(w + 0.08, h + 0.08, 0.13, x, y, z, material(bg), parent);
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(w, h),
new THREE.MeshBasicMaterial({ map: pixelTexture(text, bg, fg) })
);
mesh.position.set(x, y, z + 0.071);
parent.add(mesh);
}
function glyphPanel(x, y, z, w, h, glyph, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(w, h),
new THREE.MeshBasicMaterial({ map: cjkTexture(glyph) })
);
mesh.position.set(x, y, z);
parent.add(mesh);
}
function windowPanel(x, y, z, w, h, frameMat, lit = false) {
box(w + 0.12, h + 0.12, 0.13, x, y, z, frameMat);
box(w, h, 0.035, x, y, z + 0.085, lit ? M.litGlass : M.glass);
box(0.055, h, 0.05, x, y, z + 0.115, frameMat);
box(w, 0.055, 0.05, x, y, z + 0.115, frameMat);
box(w + 0.16, 0.09, 0.22, x, y - h / 2 - 0.06, z + 0.04, frameMat);
}
// ------------------------------------------------------------
// Bounded diorama base, road, sidewalks
// ------------------------------------------------------------
box(150, 0.2, 150, 0, -1.16, 0, M.ground, scene, false, true);
box(32, 1.1, 22, 0, -0.55, 0, M.base);
box(32.15, 0.18, 22.15, 0, -0.03, 0, M.baseEdge);
box(30.8, 0.14, 5.0, 0, 0.07, 1.45, M.road);
box(30.8, 0.28, 3.35, 0, 0.14, -2.75, M.sidewalk);
box(30.8, 0.28, 3.1, 0, 0.14, 5.35, M.sidewalk);
// Curbs.
box(30.8, 0.25, 0.16, 0, 0.14, -1.08, M.curb);
box(30.8, 0.25, 0.16, 0, 0.14, 3.96, M.curb);
// Sidewalk paving joints.
for (let x = -14.4; x <= 14.4; x += 1.2) {
box(0.025, 0.018, 3.18, x, 0.288, -2.75, M.tileDark, scene, false);
box(0.025, 0.018, 2.95, x, 0.288, 5.35, M.tileDark, scene, false);
}
box(30.6, 0.018, 0.025, 0, 0.289, -2.25, M.tileDark, scene, false);
box(30.6, 0.018, 0.025, 0, 0.289, 5.35, M.tileDark, scene, false);
// Road markings.
for (let x = -13; x <= 13; x += 2.6) {
box(1.25, 0.025, 0.095, x, 0.153, 1.42, M.yellow, scene, false);
}
// Zebra crossing.
for (let z = -0.65; z <= 3.45; z += 0.55) {
box(2.35, 0.028, 0.30, -11.5, 0.157, z, M.white, scene, false);
}
// Small road patches and drain covers.
for (const [x, z, w] of [[-7.4, .3, 1.4], [1.5, 2.8, 1.8], [9.5, .15, 1.2]]) {
box(w, 0.012, .65, x, .148, z, M.roadPatch, scene, false);
}
box(.55, .025, .38, 7.9, .165, 3.55, M.black);
box(.55, .025, .38, -8.4, .165, 3.55, M.black);
// ------------------------------------------------------------
// Varied storefront row
// ------------------------------------------------------------
const stores = [
{
name: "CHA", width: 3.1, height: 7.7,
body: "#4f8a72", trim: "#e3bb57", sign: "#145e4b", text: "#f5d778",
awning: "#28745d", awning2: "#e7d9b7", style: "tea", balcony: true
},
{
name: "PAO", width: 3.5, height: 8.9,
body: "#dd7950", trim: "#f1dfb7", sign: "#a83b2f", text: "#ffd66b",
awning: "#e84e3d", awning2: "#f5d786", style: "bakery", balcony: false
},
{
name: "DIM SUM", width: 2.9, height: 9.5,
body: "#9b426d", trim: "#f0bd53", sign: "#771a3e", text: "#ffd96e",
awning: "#7d2450", awning2: "#e0a843", style: "dimsum", balcony: true
},
{
name: "ARTES", width: 3.3, height: 7.9,
body: "#507bab", trim: "#eee6d2", sign: "#244777", text: "#ff876b",
awning: "#315d91", awning2: "#e7dcc4", style: "art", balcony: false
},
{
name: "CHURRASCO", width: 3.7, height: 8.5,
body: "#d0a239", trim: "#66543b", sign: "#91322c", text: "#f8df9b",
awning: "#a63b30", awning2: "#e3b24d", style: "grill", balcony: true
},
{
name: "SOUVENIR", width: 3.2, height: 9.2,
body: "#b74a48", trim: "#274b72", sign: "#203d68", text: "#ffd561",
awning: "#284c74", awning2: "#d24a42", style: "souvenir", balcony: false
},
{
name: "MERCADO", width: 3.4, height: 8.6,
body: "#80508f", trim: "#ead255", sign: "#472a61", text: "#ffe17b",
awning: "#6c3b7e", awning2: "#d9bd53", style: "market", balcony: true
}
];
function makeStore(config, x) {
const w = config.width;
const bodyMat = material(config.body);
const trimMat = material(config.trim);
const signMat = material(config.sign);
const awningMat = material(config.awning);
const awningAlt = material(config.awning2);
// Main narrow row-house.
box(w, config.height - .28, 4.4, x, .28 + (config.height - .28) / 2, -6.8, bodyMat);
box(w + .12, .16, 4.5, x, config.height + .08, -6.8, trimMat);
box(.12, config.height - .28, .18, x - w / 2, .28 + (config.height - .28) / 2, -4.55, trimMat);
box(.12, config.height - .28, .18, x + w / 2, .28 + (config.height - .28) / 2, -4.55, trimMat);
// Shop sign.
signPanel(x, 3.58, -4.48, w - .25, .68, config.name, config.sign, config.text);
// Door and broad display window.
const doorX = x + w / 2 - .53;
const displayW = w - 1.16;
const displayX = x - .30;
box(.92, 2.45, .13, doorX, 1.50, -4.51, trimMat);
box(.70, 2.17, .04, doorX, 1.49, -4.425, M.glass);
box(.06, .32, .07, doorX - .22, 1.48, -4.37, M.gold);
windowPanel(displayX, 1.48, -4.52, displayW, 1.88, trimMat, config.style === "tea");
// Different awning treatments.
const segmentCount = Math.ceil(w / .36);
for (let i = 0; i < segmentCount; i++) {
const segmentW = w / segmentCount;
const sx = x - w / 2 + (i + .5) * segmentW;
box(segmentW, .13, .95, sx, 2.98, -4.02, i % 2 ? awningAlt : awningMat);
if (config.style !== "art") {
box(segmentW, .20, .08, sx, 2.80, -3.53, i % 2 ? awningMat : awningAlt);
}
}
// Upper windows: layouts vary with width and building height.
const rows = config.height > 8.7 ? 2 : 1;
for (let row = 0; row < rows; row++) {
const wy = row === 0 ? 5.30 : 7.82;
const count = w > 3.4 ? 3 : 2;
for (let i = 0; i < count; i++) {
const offset = count === 3
? [-w * .28, 0, w * .28][i]
: [-w * .22, w * .22][i];
const lit = (row * 3 + i + Math.round(x)) % 4 === 0;
windowPanel(x + offset, wy, -4.56, .72, 1.03, trimMat, lit);
}
}
// Selected houses have projecting balconies.
if (config.balcony) {
const bw = w * .76;
box(bw, .13, .93, x, 4.45, -4.18, trimMat);
box(bw, .08, .08, x, 5.10, -3.74, trimMat);
box(bw, .06, .06, x, 4.78, -3.75, trimMat);
for (let i = 0; i < 6; i++) {
box(.055, .66, .055, x - bw / 2 + i * bw / 5, 4.77, -3.74, trimMat);
}
}
// Rooftop tank, terrace blocks, or antenna.
if (config.style === "tea" || config.style === "souvenir") {
box(.72, .80, .72, x + w * .19, config.height + .58, -6.9, M.navy);
box(.16, .26, .16, x + w * .19, config.height + 1.08, -6.9, M.black);
} else {
box(w * .42, .30, 1.0, x - w * .16, config.height + .30, -6.8, trimMat);
box(.06, 1.15, .06, x + w * .28, config.height + .73, -6.85, M.black);
box(.65, .05, .05, x + w * .28, config.height + 1.03, -6.85, M.black);
}
// Individual display details.
if (config.style === "tea") {
for (let i = 0; i < 5; i++) {
box(.24, .34, .23, displayX - .58 + i * .29, 2.17, -4.25,
material(["#b14d3d", "#d6ad4d", "#3d8070"][i % 3]));
box(.17, .07, .17, displayX - .58 + i * .29, 2.38, -4.25, M.gold);
}
} else if (config.style === "bakery") {
for (let i = 0; i < 6; i++) {
box(.24, .16, .22, displayX - .57 + i * .225, 1.02, -4.24, M.cream);
box(.20, .11, .18, displayX - .57 + i * .225, 1.70, -4.24, material("#c87932"));
}
} else if (config.style === "dimsum") {
for (let row = 0; row < 2; row++) {
box(displayW - .2, .10, .22, displayX, 1.07 + row * .69, -4.24, M.cream);
for (let i = 0; i < 4; i++) {
box(.24, .16, .18, displayX - .52 + i * .35, 1.21 + row * .69, -4.23, M.white);
}
}
for (let i = 0; i < 3; i++) {
box(.18, .13, .13, displayX - .38 + i * .36, 2.55, -4.18, M.white);
}
} else if (config.style === "art") {
const artColors = ["#e26f5a", "#3f9a82", "#edc34e", "#6f70a8"];
for (let i = 0; i < 4; i++) {
box(.42, .60, .07, displayX - .62 + i * .42, 1.56, -4.26, M.cream);
box(.29, .43, .04, displayX - .62 + i * .42, 1.56, -4.205, material(artColors[i]));
}
} else if (config.style === "grill") {
box(displayW - .2, .15, .30, displayX, 1.05, -4.20, M.black);
for (let i = 0; i < 5; i++) {
box(.045, .55, .04, displayX - .55 + i * .28, 1.35, -4.16, M.gold);
box(.18, .13, .13, displayX - .55 + i * .28, 1.60, -4.16, material("#9b3e2e"));
}
} else if (config.style === "souvenir") {
for (let i = 0; i < 4; i++) {
box(.28, .42, .18, displayX - .55 + i * .36, 1.38, -4.24,
material(["#d94c43", "#315f91", "#e6b947", "#3b9270"][i]));
}
} else if (config.style === "market") {
for (let i = 0; i < 4; i++) {
box(.32, .23, .28, displayX - .58 + i * .39, 1.08, -4.22, M.wood);
box(.22, .19, .21, displayX - .58 + i * .39, 1.26, -4.20,
material(["#d6a832", "#c64d32", "#4b944c", "#7ca543"][i]));
}
}
// Projecting Chinese-inspired signs on selected businesses.
if (config.style === "tea") {
glyphPanel(x - w / 2 + .22, 5.28, -4.02, .61, 1.35, "茶");
} else if (config.style === "dimsum") {
glyphPanel(x + w / 2 - .22, 5.22, -4.00, .61, 1.35, "福");
}
}
let cursorX = -14.4;
for (const config of stores) {
const x = cursorX + config.width / 2;
makeStore(config, x);
cursorX += config.width;
}
// Community/library building closing the block and framing the plaza.
box(4.55, 6.25, 4.4, 11.25, 3.405, -6.8, material("#bd6f4d"));
box(4.72, .18, 4.55, 11.25, 6.62, -6.8, material("#315f59"));
signPanel(11.25, 3.55, -4.48, 3.85, .68, "BIBLIOTECA", "#244b5a", "#f4d476");
box(1.08, 2.45, .13, 12.28, 1.50, -4.50, material("#e8c27a"));
box(.86, 2.17, .04, 12.28, 1.49, -4.41, M.glass);
windowPanel(10.18, 1.66, -4.52, 1.28, 1.72, material("#e8c27a"), true);
for (const x of [9.85, 12.75]) {
windowPanel(x, 5.08, -4.56, .92, 1.10, material("#e8c27a"), false);
}
glyphPanel(13.05, 5.10, -4.00, .55, 1.18, "文");
// ------------------------------------------------------------
// Small gathering plaza with Portuguese-style mosaic paving
// ------------------------------------------------------------
const mosaicColors = ["#264e68", "#eee1bd", "#c54838", "#d6a838", "#4a8960"];
for (let i = -4; i <= 4; i++) {
for (let j = -4; j <= 4; j++) {
if (Math.abs(i) + Math.abs(j) <= 5) {
const index = (i * 3 + j * 5 + 20) % mosaicColors.length;
box(.265, .035, .265, 11.02 + i * .27, .305, -2.77 + j * .27,
material(mosaicColors[index]), scene, false);
}
}
}
// Central table.
box(1.02, .13, 1.02, 11.02, 1.22, -2.77, M.cream);
box(.20, .83, .20, 11.02, .80, -2.77, M.black);
box(.66, .10, .66, 11.02, .36, -2.77, M.black);
box(.16, .23, .16, 10.73, 1.40, -2.58, M.red);
box(.13, .19, .13, 11.31, 1.38, -2.91, M.green);
function makeChair(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, .30, z);
group.rotation.y = rotation;
scene.add(group);
box(.50, .10, .48, 0, .43, 0, M.wood, group);
box(.50, .53, .08, 0, .74, -.22, M.wood, group);
box(.09, .40, .09, -.19, .20, -.18, M.black, group);
box(.09, .40, .09, .19, .20, -.18, M.black, group);
box(.09, .40, .09, -.19, .20, .18, M.black, group);
box(.09, .40, .09, .19, .20, .18, M.black, group);
}
function makePerson(x, z, shirt, skin, rotation = 0, seated = false) {
const group = new THREE.Group();
group.position.set(x, .31, z);
group.rotation.y = rotation;
scene.add(group);
if (seated) {
box(.42, .58, .28, 0, .93, 0, shirt, group);
box(.13, .48, .14, -.29, .91, 0, shirt, group);
box(.13, .48, .14, .29, .91, 0, shirt, group);
box(.16, .15, .43, -.12, .69, .20, M.navy, group);
box(.16, .15, .43, .12, .69, .20, M.navy, group);
box(.16, .36, .16, -.12, .47, .37, M.navy, group);
box(.16, .36, .16, .12, .47, .37, M.navy, group);
box(.30, .32, .29, 0, 1.43, 0, skin, group);
box(.32, .09, .30, 0, 1.60, -.015, M.hair, group);
} else {
box(.18, .57, .22, -.13, .48, 0, M.navy, group);
box(.18, .57, .22, .13, .48, 0, M.navy, group);
box(.21, .12, .32, -.13, .12, .05, M.black, group);
box(.21, .12, .32, .13, .12, .05, M.black, group);
box(.48, .64, .29, 0, 1.02, 0, shirt, group);
box(.13, .55, .17, -.31, 1.01, 0, shirt, group);
box(.13, .55, .17, .31, 1.01, 0, shirt, group);
box(.31, .33, .30, 0, 1.55, 0, skin, group);
box(.33, .10, .31, 0, 1.73, -.01, M.hair, group);
}
return group;
}
makeChair(10.19, -2.77, Math.PI / 2);
makeChair(11.85, -2.77, -Math.PI / 2);
makeChair(11.02, -1.94, Math.PI);
makeChair(11.02, -3.60, 0);
makePerson(10.19, -2.77, material("#d44842"), M.skin2, Math.PI / 2, true);
makePerson(11.85, -2.77, material("#347e83"), M.skin1, -Math.PI / 2, true);
makePerson(11.02, -1.94, material("#e1b83f"), M.skin3, Math.PI, true);
makePerson(11.02, -3.60, material("#66558d"), M.skin2, 0, true);
makePerson(12.88, -3.14, material("#43845f"), M.skin1, -.5);
makePerson(9.55, -3.45, material("#d7a33c"), M.skin3, .35);
makePerson(-7.55, -2.10, material("#d75b4d"), M.skin2, 1.2);
makePerson(2.70, -1.72, material("#346e9b"), M.skin1, -.7);
makePerson(-3.20, 5.10, material("#e0b548"), M.skin3, 1.0);
makePerson(6.20, 5.20, material("#9a4d78"), M.skin2, -.6);
// ------------------------------------------------------------
// Repeated overhead red lanterns
// ------------------------------------------------------------
const lanternPivots = [];
function makeLantern(x, y, z, phase) {
const pivot = new THREE.Group();
pivot.position.set(x, y, z);
scene.add(pivot);
box(.025, .30, .025, 0, -.15, 0, M.black, pivot, false);
box(.48, .07, .48, 0, -.33, 0, M.gold, pivot, false);
box(.43, .47, .43, 0, -.59, 0, M.redLight, pivot, false);
box(.49, .06, .49, 0, -.84, 0, M.gold, pivot, false);
box(.055, .23, .055, 0, -.98, 0, M.gold, pivot, false);
box(.08, .07, .08, 0, -1.12, 0, M.red, pivot, false);
lanternPivots.push({ pivot, phase });
}
function makeGarland(x) {
const points = [];
for (let i = 0; i <= 10; i++) {
const t = i / 10;
const z = -4.55 + t * 8.55;
const y = 5.42 - Math.sin(t * Math.PI) * .48;
points.push([x, y, z]);
}
for (let i = 0; i < points.length - 1; i++) {
beamBetween(points[i], points[i + 1], .025, M.black);
}
[.18, .50, .82].forEach((t, index) => {
const z = -4.55 + t * 8.55;
const y = 5.42 - Math.sin(t * Math.PI) * .48;
makeLantern(x, y, z, index + x);
});
// Near-side support pole and a small modern streetlight.
box(.13, 5.40, .13, x, 2.98, 4.02, M.black);
box(.15, .13, 1.05, x, 5.28, 3.63, M.black);
box(.55, .12, .32, x, 5.17, 3.22, M.black);
box(.40, .035, .20, x, 5.095, 3.22, M.litGlass, scene, false);
}
[-11.5, -6.0, 0, 6.0].forEach(makeGarland);
// Standalone lantern at the plaza edge.
box(.12, 4.10, .12, 13.35, 2.33, -1.55, M.black);
box(.12, .12, 1.05, 13.35, 4.32, -2.00, M.black);
makeLantern(13.35, 4.25, -2.45, 3.4);
// ------------------------------------------------------------
// Trees, planters, benches, bins and street furniture
// ------------------------------------------------------------
function makeTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, .28, z);
group.scale.setScalar(scale);
scene.add(group);
box(1.34, .34, 1.34, 0, .17, 0, M.planter, group);
box(1.08, .06, 1.08, 0, .37, 0, M.base, group);
box(.31, 1.72, .31, 0, 1.17, 0, M.wood, group);
const clusters = [
[-.42, 2.08, 0, .78], [.35, 2.12, .05, .84], [0, 2.48, -.08, .94],
[-.34, 2.72, .18, .64], [.37, 2.78, -.12, .64], [0, 2.98, .10, .65]
];
clusters.forEach((c, i) => {
box(c[3], .68, c[3], c[0], c[1], c[2], i % 2 ? M.leafLight : M.leaf, group);
});
}
makeTree(-14.1, 5.18, .95);
makeTree(14.0, 5.15, 1.0);
makeTree(-14.0, -2.75, .72);
function makeBench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, .29, z);
group.rotation.y = rotation;
scene.add(group);
box(1.75, .12, .46, 0, .43, 0, M.wood, group);
box(1.75, .42, .10, 0, .70, -.21, M.wood, group);
box(.12, .43, .38, -.68, .21, 0, M.black, group);
box(.12, .43, .38, .68, .21, 0, M.black, group);
}
makeBench(-7.0, 5.45);
makeBench(-7.0, 5.45, 0);
makeBench(13.3, -2.75, Math.PI / 2);
function makeBin(x, z) {
box(.50, .86, .50, x, .72, z, M.teal);
box(.58, .09, .58, x, 1.18, z, M.black);
box(.34, .12, .08, x, 1.03, z + .28, M.black);
}
makeBin(-8.05, 4.83);
makeBin(12.85, -1.72);
// Bollards protect the small plaza.
for (const x of [9.15, 12.85]) {
box(.13, .68, .13, x, .63, -1.28, M.black);
box(.15, .07, .15, x, .99, -1.28, M.gold);
}
// A simple voxel bicycle beside the bench.
const bike = new THREE.Group();
bike.position.set(-5.05, .30, 5.30);
bike.rotation.y = .15;
scene.add(bike);
box(.06, .58, .06, -.48, .31, 0, M.black, bike);
box(.06, .58, .06, .48, .31, 0, M.black, bike);
box(.52, .06, .06, -.18, .59, 0, M.teal, bike);
box(.42, .06, .06, .18, .59, 0, M.teal, bike);
box(.08, .42, .08, -.17, .35, 0, M.teal, bike);
box(.42, .06, .08, .20, .69, 0, M.teal, bike);
box(.08, .35, .08, .43, .64, 0, M.teal, bike);
// ------------------------------------------------------------
// Vehicles
// ------------------------------------------------------------
function makeCar(x, z, bodyColor, taxi = false, direction = 1) {
const group = new THREE.Group();
group.position.set(x, .16, z);
group.rotation.y = direction === -1 ? Math.PI : 0;
scene.add(group);
const bodyMat = material(bodyColor);
box(2.75, .62, 1.34, 0, .66, 0, bodyMat, group);
box(1.52, .58, 1.17, -.16, 1.19, 0, bodyMat, group);
box(1.22, .36, 1.20, -.17, 1.24, 0, M.glass, group);
box(1.60, .10, 1.23, -.16, 1.51, 0, bodyMat, group);
box(.57, .18, 1.09, 1.00, 1.06, 0, bodyMat, group);
box(.52, .16, 1.10, -1.00, 1.02, 0, bodyMat, group);
for (const wx of [-.88, .88]) {
for (const wz of [-.67, .67]) {
box(.47, .45, .20, wx, .40, wz, M.black, group);
box(.21, .21, .215, wx, .40, wz, M.cream, group);
}
}
box(.13, .18, .31, 1.38, .72, .42, M.white, group);
box(.13, .18, .31, 1.38, .72, -.42, M.white, group);
box(.10, .16, .28, -1.38, .70, .42, M.red, group);
box(.10, .16, .28, -1.38, .70, -.42, M.red, group);
if (taxi) {
box(.70, .25, .46, -.10, 1.75, 0, M.yellow, group);
box(.30, .12, .28, -.10, 1.90, 0, M.black, group);
box(1.80, .08, 1.36, -.10, .99, 0, M.black, group);
}
}
makeCar(4.35, .28, "#327f7d");
makeCar(-4.45, 2.64, "#d43e38", true, -1);
// ------------------------------------------------------------
// Additional details and bounded edge
// ------------------------------------------------------------
// Market crates outside the final shop.
for (let i = 0; i < 3; i++) {
box(.52, .34, .45, 7.90 + i * .60, .48, -3.35, M.wood);
box(.43, .24, .38, 7.90 + i * .60, .76, -3.35,
material(["#dfad35", "#ca4c36", "#4d914b"][i]));
}
// Newspaper boxes and utility cabinet.
box(.42, .65, .38, -10.05, .61, 4.76, M.blue);
box(.42, .65, .38, -10.65, .61, 4.76, M.red);
box(.66, 1.22, .48, -13.80, .90, -1.55, M.teal);
// Parked scooters, rendered as small blocky silhouettes.
for (const [x, z, color] of [[-9.4, 4.70, "#daaa3e"], [8.9, 4.72, "#3d7586"]]) {
box(.24, .28, .68, x, .49, z, material(color));
box(.22, .42, .22, x, .77, z + .26, material(color));
box(.08, .55, .08, x, .79, z + .44, M.black);
box(.62, .08, .08, x, 1.04, z + .44, M.black);
box(.22, .30, .22, x - .22, .31, z - .32, M.black);
box(.22, .30, .22, x + .22, .31, z - .32, M.black);
}
// Low framing wall and planted front edge.
box(31.8, .52, .28, 0, .13, 10.65, M.baseEdge);
box(30.6, .18, 1.40, 0, .12, 9.45, material("#59765a"));
for (let x = -14; x <= 14; x += 2) {
box(1.25, .18, .70, x, .27, 9.45, M.leaf);
}
// Small plaque on the front edge.
signPanel(0, .54, 10.82, 4.8, .55, "LIBERDADE", "#244b5a", "#f3cf66");
// ------------------------------------------------------------
// Direct camera controls: orbit, zoom, pan and keyboard
// ------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 2.25, -1.0),
theta: .72,
phi: .95,
radius: 34
};
const initial = {
target: controls.target.clone(),
theta: controls.theta,
phi: controls.phi,
radius: controls.radius
};
let dragging = false;
let panning = false;
let lastX = 0;
let lastY = 0;
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
panning = event.button === 2 || event.shiftKey;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.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 right = new THREE.Vector3(Math.cos(controls.theta), 0, -Math.sin(controls.theta));
const forward = new THREE.Vector3(Math.sin(controls.theta), 0, Math.cos(controls.theta));
const scale = controls.radius * .0013;
controls.target.addScaledVector(right, -dx * scale);
controls.target.addScaledVector(forward, -dy * scale);
controls.target.x = THREE.MathUtils.clamp(controls.target.x, -12, 12);
controls.target.z = THREE.MathUtils.clamp(controls.target.z, -8, 8);
} else {
controls.theta -= dx * .0055;
controls.phi = THREE.MathUtils.clamp(controls.phi - dy * .0045, .34, 1.36);
}
updateCamera();
});
function endDrag(event) {
dragging = false;
panning = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * .001),
19,
52
);
updateCamera();
}, { passive: false });
addEventListener("keydown", event => {
if (event.key.toLowerCase() === "r") {
controls.target.copy(initial.target);
controls.theta = initial.theta;
controls.phi = initial.phi;
controls.radius = initial.radius;
updateCamera();
}
if (event.key === "ArrowLeft") controls.theta -= .08;
if (event.key === "ArrowRight") controls.theta += .08;
if (event.key === "ArrowUp") controls.phi = Math.max(.34, controls.phi - .06);
if (event.key === "ArrowDown") controls.phi = Math.min(1.36, controls.phi + .06);
if (event.key === "+" || event.key === "=") controls.radius = Math.max(19, controls.radius - 2);
if (event.key === "-") controls.radius = Math.min(52, controls.radius + 2);
updateCamera();
});
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
});
updateCamera();
// ------------------------------------------------------------
// Render loop with a subtle lantern sway
// ------------------------------------------------------------
function animate(time) {
requestAnimationFrame(animate);
const t = time * .001;
lanternPivots.forEach(({ pivot, phase }) => {
pivot.rotation.z = Math.sin(t * .85 + phase) * .035;
pivot.rotation.x = Math.cos(t * .68 + phase) * .018;
});
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```