Prompt specification
Build or customize the Three.js 3D scene "Market-day routes through a Sorocaba square model" 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: Market-day routes through a Sorocaba square model
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/market-day-routes-through-a-sorocaba-square-model-x2720
Scene Description Prompt:
Place voxel market stalls in Sorocaba's Praça Fernando Prestes, keeping cathedral access and pedestrian crossings open. Three.js from cdnjs, standalone HTML.
Working Three.js Starter (market-day-routes-through-a-sorocaba-square-model-x2720):
```html
<!doctype html>
<html lang="pt-BR">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Praça Fernando Prestes — Mercado Voxel</title>
<style>
:root {
--ink: #263238;
--muted: #64747b;
--paper: rgba(255, 255, 255, 0.93);
--line: rgba(38, 50, 56, 0.12);
--orange: #e85d3f;
--blue: #287c8e;
--gold: #d6a23a;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c8dce0;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.95);
color: var(--ink);
padding: 9px 12px;
font: 650 12px/1 inherit;
cursor: pointer;
transition: transform .15s ease, background .15s ease;
}
button:hover {
transform: translateY(-1px);
background: #fff;
}
button.active {
color: #fff;
background: var(--blue);
border-color: var(--blue);
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.panel {
pointer-events: auto;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, .75);
box-shadow:
0 12px 32px rgba(35, 55, 61, .13),
0 2px 5px rgba(35, 55, 61, .06);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#title {
position: absolute;
top: 20px;
left: 20px;
width: min(390px, calc(100vw - 40px));
padding: 18px 20px 17px;
border-radius: 16px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: var(--orange);
font-size: 10px;
font-weight: 850;
letter-spacing: .15em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--orange);
box-shadow: 13px 0 0 #f4b942;
}
h1 {
margin: 0;
font-size: clamp(21px, 3vw, 30px);
line-height: 1.05;
letter-spacing: -.035em;
}
#title p {
margin: 8px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
#controls {
position: absolute;
top: 20px;
right: 20px;
display: flex;
gap: 7px;
padding: 8px;
border-radius: 14px;
}
#legend {
position: absolute;
left: 20px;
bottom: 20px;
width: 255px;
padding: 15px;
border-radius: 15px;
}
.section-title {
margin: 0 0 10px;
font-size: 10px;
font-weight: 850;
letter-spacing: .13em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin-top: 8px;
color: #526269;
font-size: 11px;
}
.swatch {
width: 13px;
height: 13px;
flex: 0 0 auto;
border-radius: 3px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08);
}
.swatch.stalls { background: #e85d3f; }
.swatch.access { background: #f1dfb9; }
.swatch.crossing { background: #fff; border: 2px solid #91a1a5; }
.swatch.cathedral { background: #d8c8a6; }
#mini-map {
position: relative;
height: 108px;
margin-top: 12px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 10px;
background:
repeating-linear-gradient(
90deg,
rgba(85, 111, 110, .08) 0 1px,
transparent 1px 13px
),
#dfe4d4;
}
.map-path {
position: absolute;
background: #f1dfb9;
}
.map-path.vertical {
width: 25%;
height: 100%;
left: 37.5%;
}
.map-path.horizontal {
height: 24%;
width: 100%;
top: 38%;
}
.map-church {
position: absolute;
top: 0;
left: 32%;
width: 36%;
height: 15%;
background: #d8c8a6;
border-bottom: 3px solid #9c8261;
}
.map-stall {
position: absolute;
width: 13%;
height: 14%;
border-radius: 2px;
background: var(--orange);
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08);
}
#info {
position: absolute;
right: 20px;
bottom: 20px;
width: min(300px, calc(100vw - 40px));
padding: 16px;
border-radius: 15px;
}
#info h2 {
margin: 0;
font-size: 17px;
letter-spacing: -.02em;
}
#info p {
margin: 7px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
#info .status {
display: inline-flex;
align-items: center;
gap: 6px;
margin-top: 11px;
padding: 6px 8px;
border-radius: 7px;
background: rgba(40, 124, 142, .1);
color: #226b79;
font-size: 10px;
font-weight: 750;
}
#info .status::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: #2c9b8f;
}
#hint {
position: absolute;
left: 50%;
bottom: 20px;
transform: translateX(-50%);
padding: 9px 13px;
border-radius: 999px;
background: rgba(30, 45, 50, .76);
color: #fff;
font-size: 10px;
white-space: nowrap;
box-shadow: 0 6px 20px rgba(0, 0, 0, .12);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #c8dce0;
color: #41545b;
transition: opacity .35s ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
.loader {
display: flex;
align-items: center;
gap: 12px;
font-size: 12px;
font-weight: 750;
}
.loader i {
width: 17px;
height: 17px;
border: 3px solid rgba(40, 124, 142, .22);
border-top-color: var(--blue);
border-radius: 50%;
animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 780px) {
#title {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
#title p { display: none; }
#controls {
top: 102px;
right: 12px;
flex-direction: column;
}
#legend {
left: 12px;
bottom: 12px;
width: 205px;
padding: 12px;
}
#legend .legend-row,
#mini-map { display: none; }
#info {
right: 12px;
bottom: 12px;
width: calc(100vw - 245px);
min-width: 130px;
}
#info p { display: none; }
#hint { display: none; }
}
</style>
</head>
<body>
<div id="loading">
<div class="loader"><i></i> Montando a praça…</div>
</div>
<div id="hud">
<section id="title" class="panel">
<div class="eyebrow">Mercado municipal · estudo espacial</div>
<h1>Praça Fernando Prestes</h1>
<p>
Barracas voxel organizadas em duas alas, mantendo livre o acesso
à catedral e as travessias de pedestres.
</p>
</section>
<nav id="controls" class="panel" aria-label="Controles da cena">
<button id="reset" title="Retornar à vista inicial">Vista inicial</button>
<button id="top" title="Vista superior">Planta</button>
<button id="labels" class="active" title="Mostrar ou ocultar rótulos">Rótulos</button>
</nav>
<section id="legend" class="panel">
<div class="section-title">Legenda do projeto</div>
<div class="legend-row">
<span class="swatch stalls"></span>
Barracas de mercado
</div>
<div class="legend-row">
<span class="swatch access"></span>
Eixos livres de circulação
</div>
<div class="legend-row">
<span class="swatch crossing"></span>
Travessias de pedestres
</div>
<div class="legend-row">
<span class="swatch cathedral"></span>
Referência da catedral
</div>
<div id="mini-map" aria-label="Mini planta esquemática">
<div class="map-path vertical"></div>
<div class="map-path horizontal"></div>
<div class="map-church"></div>
<span class="map-stall" style="left:17%;top:20%"></span>
<span class="map-stall" style="left:17%;top:38%"></span>
<span class="map-stall" style="left:17%;top:64%"></span>
<span class="map-stall" style="left:17%;top:80%"></span>
<span class="map-stall" style="left:70%;top:20%"></span>
<span class="map-stall" style="left:70%;top:38%"></span>
<span class="map-stall" style="left:70%;top:64%"></span>
<span class="map-stall" style="left:70%;top:80%"></span>
</div>
</section>
<section id="info" class="panel">
<div class="section-title">Barraca selecionada</div>
<h2 id="stall-title">Escolha uma barraca</h2>
<p id="stall-copy">
Clique em uma barraca no cenário para consultar sua ocupação.
</p>
<div class="status">Circulação preservada</div>
</section>
<div id="hint">
Arraste para orbitar · Shift + arraste para mover · Roda para zoom
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#c8dce0");
scene.fog = new THREE.Fog("#c8dce0", 65, 125);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
180
);
const world = new THREE.Group();
scene.add(world);
const hemi = new THREE.HemisphereLight("#e7f5ff", "#8d806b", 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight("#fff1d2", 3.2);
sun.position.set(-24, 38, 27);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -42;
sun.shadow.camera.right = 42;
sun.shadow.camera.top = 42;
sun.shadow.camera.bottom = -42;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 110;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materials = new Map();
const labels = [];
const hitTargets = [];
function material(color) {
if (!materials.has(color)) {
materials.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02
})
);
}
return materials.get(color);
}
function box(w, h, d, x, y, z, color, parent = world, castShadow = true) {
const mesh = new THREE.Mesh(
unitBox,
color && color.isMaterial ? color : material(color)
);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedLabelTexture(text, background = "#ffffff", foreground = "#263238") {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 150;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = background;
ctx.beginPath();
ctx.roundRect(4, 4, 632, 142, 28);
ctx.fill();
ctx.strokeStyle = "rgba(38,50,56,.12)";
ctx.lineWidth = 4;
ctx.stroke();
ctx.fillStyle = foreground;
ctx.font = "800 43px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 320, 76);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function worldLabel(
text,
x,
y,
z,
scale = 5,
background = "#ffffff",
foreground = "#263238",
parent = world
) {
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: roundedLabelTexture(text, background, foreground),
transparent: true,
depthWrite: false
})
);
sprite.position.set(x, y, z);
sprite.scale.set(scale, scale * 0.234, 1);
parent.add(sprite);
labels.push(sprite);
return sprite;
}
function groundText(text, x, z, width = 5, color = "#287c8e") {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 192;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = color;
ctx.font = "850 72px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 512, 96);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, width * 0.1875),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
opacity: 0.72
})
);
mesh.rotation.x = -Math.PI / 2;
mesh.position.set(x, 0.595, z);
world.add(mesh);
labels.push(mesh);
return mesh;
}
// ------------------------------------------------------------
// Ground, plaza, roads and protected circulation routes
// ------------------------------------------------------------
box(58, 1.2, 58, 0, -0.55, 0, "#8b7966");
box(57, 0.2, 57, 0, 0.12, 0, "#86a66b");
// Road bands: south, east and west.
box(58, 0.12, 7, 0, 0.27, 24, "#586266");
box(7, 0.12, 48, -24.5, 0.27, 0, "#586266");
box(7, 0.12, 48, 24.5, 0.27, 0, "#586266");
// Sidewalk edges.
box(48, 0.22, 1.5, 0, 0.35, 20.7, "#c7c3b8");
box(1.5, 0.22, 43, -22.6, 0.35, 0, "#c7c3b8");
box(1.5, 0.22, 43, 22.6, 0.35, 0, "#c7c3b8");
// Plaza pavers.
const tileGeometry = new THREE.BoxGeometry(1.94, 0.16, 1.94);
const tileCount = 22 * 20;
const tiles = new THREE.InstancedMesh(
tileGeometry,
material("#ffffff"),
tileCount
);
tiles.receiveShadow = true;
const matrix = new THREE.Matrix4();
const tileColors = ["#d5cdbd", "#d9d1c2", "#cfc8ba", "#ddd5c6"];
let tileIndex = 0;
for (let ix = 0; ix < 22; ix++) {
for (let iz = 0; iz < 20; iz++) {
const x = -21 + ix * 2;
const z = -19 + iz * 2;
matrix.makeTranslation(x, 0.39, z);
tiles.setMatrixAt(tileIndex, matrix);
const hash = (ix * 17 + iz * 31 + ix * iz * 3) % tileColors.length;
tiles.setColorAt(tileIndex, new THREE.Color(tileColors[hash]));
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
if (tiles.instanceColor) tiles.instanceColor.needsUpdate = true;
world.add(tiles);
// Main clear route: approximately 8 m wide.
box(8, 0.13, 40, 0, 0.505, 0, "#f1dfb9", world, false);
// East-west clear route: approximately 6 m wide.
box(44, 0.14, 6, 0, 0.515, 0, "#f1dfb9", world, false);
// Perimeter pedestrian loop.
box(2.5, 0.11, 39, -20.5, 0.51, 0, "#e5d6bb", world, false);
box(2.5, 0.11, 39, 20.5, 0.51, 0, "#e5d6bb", world, false);
box(39, 0.11, 2.5, 0, 0.51, -18.6, "#e5d6bb", world, false);
box(39, 0.11, 2.5, 0, 0.51, 18.6, "#e5d6bb", world, false);
// Fine boundary lines make the reserved corridors legible.
for (const x of [-4, 4]) {
for (let z = -12; z <= 17; z += 3.5) {
box(0.11, 0.035, 1.65, x, 0.592, z, "#d6a23a", world, false);
}
}
for (const z of [-3, 3]) {
for (let x = -18; x <= 18; x += 3.5) {
box(1.65, 0.035, 0.11, x, 0.602, z, "#d6a23a", world, false);
}
}
// Zebra crossing on the southern road.
for (let i = 0; i < 5; i++) {
box(7.2, 0.055, 0.72, 0, 0.36, 21.35 + i * 1.22, "#f7f5eb", world, false);
}
// Zebra crossings on the east and west roads.
for (let i = 0; i < 5; i++) {
box(0.72, 0.055, 7.2, 22.25 + i * 1.22, 0.36, 0, "#f7f5eb", world, false);
box(0.72, 0.055, 7.2, -22.25 - i * 1.22, 0.36, 0, "#f7f5eb", world, false);
}
// Road center dashes, interrupted around crossings.
for (let x = -26; x <= 26; x += 4.5) {
if (Math.abs(x) > 6) {
box(2.2, 0.045, 0.14, x, 0.36, 24, "#e6c864", world, false);
}
}
for (const x of [-24.5, 24.5]) {
for (let z = -19; z <= 19; z += 4.5) {
if (Math.abs(z) > 5) {
box(0.14, 0.045, 2.2, x, 0.36, z, "#e6c864", world, false);
}
}
}
groundText("ACESSO À CATEDRAL", 0, -11.2, 6.2, "#287c8e");
groundText("PRAÇA FERNANDO PRESTES", 0, 15.4, 7.2, "#8a7657");
// ------------------------------------------------------------
// Simplified voxel cathedral at the north end
// ------------------------------------------------------------
const cathedral = new THREE.Group();
world.add(cathedral);
box(9, 8, 9, 0, 4.55, -23, "#ded0b1", cathedral);
box(10, 1.2, 10, 0, 9, -23, "#a9553f", cathedral);
box(8, 1, 8, 0, 10, -23, "#bd6549", cathedral);
box(5.6, 0.8, 5.6, 0, 10.8, -23, "#c87353", cathedral);
box(7.5, 8.8, 1.2, 0, 4.95, -19.7, "#e6d8b9", cathedral);
for (const x of [-6.2, 6.2]) {
box(2.9, 12.3, 3, x, 6.7, -20.3, "#dfd0af", cathedral);
box(3.35, 0.55, 3.45, x, 12.9, -20.3, "#c5b28d", cathedral);
box(2.55, 0.9, 2.65, x, 13.55, -20.3, "#a9553f", cathedral);
box(1.75, 0.8, 1.85, x, 14.25, -20.3, "#bd6549", cathedral);
box(0.8, 2.15, 0.12, x, 9.8, -18.76, "#4f7480", cathedral);
box(0.8, 2.15, 0.12, x, 4.8, -18.76, "#4f7480", cathedral);
box(1.05, 0.18, 0.13, x, 9.8, -18.68, "#d8c49b", cathedral);
}
// Entrance and facade windows.
box(2.6, 4.1, 0.18, 0, 3.55, -19.02, "#4c514c", cathedral);
box(0.18, 4.1, 0.22, 0, 3.55, -18.9, "#88704f", cathedral);
for (const x of [-2.65, 2.65]) {
box(1.05, 2.35, 0.13, x, 7.35, -19.03, "#547985", cathedral);
box(0.12, 2.4, 0.16, x, 7.35, -18.93, "#d8c49b", cathedral);
}
box(2.1, 2.2, 0.14, 0, 9.25, -19.02, "#547985", cathedral);
// Voxel cross.
box(0.22, 2.6, 0.22, 0, 15.8, -20.3, "#e6bd58", cathedral);
box(1.25, 0.22, 0.22, 0, 16.1, -20.3, "#e6bd58", cathedral);
// Broad central steps preserve a clear visual and physical approach.
box(11, 0.28, 5.2, 0, 0.68, -17.25, "#cfc3a8", cathedral);
box(9, 0.52, 3.4, 0, 0.91, -18.25, "#d8cbb0", cathedral);
box(7, 0.76, 1.8, 0, 1.15, -19.05, "#e1d4b9", cathedral);
worldLabel("CATEDRAL", 0, 16.2, -20.3, 5.2, "#fffaf0", "#634d35");
// ------------------------------------------------------------
// Voxel market stalls
// ------------------------------------------------------------
const stallConfigs = [
{
name: "Frutas da estação",
type: "frutas",
accent: "#e85d3f",
goods: ["#e5483f", "#f2a541", "#e8c547"]
},
{
name: "Pães elasting",
type: "paes",
accent: "#b56b3d",
goods: ["#d99b55", "#f0c07a", "#a95d32"]
},
{
name: "Flores da praça",
type: "flores",
accent: "#c45472",
goods: ["#e95f88", "#f2a4bc", "#7aa65b"]
},
{
name: "Queijos e laticínios",
type: "queijos",
accent: "#d39a32",
goods: ["#f0d58c", "#e5b95e", "#fff0b0"]
},
{
name: "Flores e plantas",
type: "plantas",
accent: "#4d8b5a",
goods: ["#4f985a", "#7db56b", "#d47a99"]
},
{
name: "Artesanato local",
type: "artesanato",
accent: "#497f91",
goods: ["#e57c52", "#4d93a5", "#f0bf5c"]
},
{
name: "Café e doces",
type: "cafe",
accent: "#83523d",
goods: ["#5b3428", "#c99363", "#e6b54f"]
},
{
name: "Hortaliças",
type: "hortalicas",
accent: "#65934d",
goods: ["#5b9a45", "#8fbd54", "#e5b73f"]
}
];
function makeCrate(parent, x, z, color, width = 1.05) {
box(width, 0.32, 0.72, x, 0.99, z, "#8e6542", parent);
box(width + 0.08, 0.11, 0.79, x, 1.16, z, color, parent);
}
function populateStall(group, config) {
const goods = config.goods;
for (let i = 0; i < 3; i++) {
const x = -1.45 + i * 1.45;
makeCrate(group, x, 0.88, goods[i]);
if (config.type === "flores") {
for (let j = 0; j < 4; j++) {
const fx = x - 0.35 + j * 0.23;
box(0.05, 0.48, 0.05, fx, 1.48, 0.88, "#4f8a50", group);
box(0.2, 0.18, 0.2, fx, 1.78, 0.88, goods[j % goods.length], group);
}
} else if (config.type === "plantas") {
box(0.46, 0.42, 0.46, x, 1.42, 0.88, "#b77a4c", group);
box(0.8, 0.65, 0.68, x, 1.82, 0.88, goods[i], group);
box(0.5, 0.4, 0.5, x, 2.25, 0.88, goods[(i + 1) % goods.length], group);
} else if (config.type === "artesanato") {
box(0.34, 0.4, 0.34, x - 0.22, 1.42, 0.88, goods[i], group);
box(0.28, 0.3, 0.28, x + 0.22, 1.37, 0.88, goods[(i + 1) % goods.length], group);
} else if (config.type === "cafe") {
box(0.38, 0.44, 0.38, x - 0.22, 1.43, 0.88, goods[i], group);
box(0.34, 0.3, 0.34, x + 0.22, 1.4, 0.88, goods[(i + 1) % goods.length], group);
} else if (config.type === "paes") {
for (let j = 0; j < 3; j++) {
box(
0.22,
0.22,
0.56,
x - 0.32 + j * 0.32,
1.34,
0.88,
goods[(i + j) % goods.length],
group
);
}
} else {
for (let j = 0; j < 5; j++) {
box(
0.22,
0.22,
0.22,
x - 0.38 + j * 0.19,
1.35,
0.88,
goods[(i + j) % goods.length],
group
);
}
}
}
// Back shelf and small containers.
box(4.3, 0.14, 0.65, 0, 1.95, -1.5, "#7d563b", group);
for (let i = 0; i < 5; i++) {
box(
0.28,
0.38,
0.28,
-1.55 + i * 0.78,
2.2,
-1.5,
goods[i % goods.length],
group
);
}
}
function makeStall(config, x, z, rotationY, index) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotationY;
world.add(group);
// Compact 5.8 × 4.4 m footprint.
box(5.8, 0.11, 4.4, 0, 0.66, 0, "#b7aa94", group);
// Rear wall and work counter.
box(4.8, 1.65, 0.18, 0, 1.52, -1.82, "#dfd0b6", group);
box(4.65, 1.05, 0.72, 0, 1.2, 1.18, "#8f6240", group);
box(4.85, 0.16, 0.9, 0, 1.8, 1.18, "#c08b55", group);
// Uprights.
for (const px of [-2.25, 2.25]) {
for (const pz of [-1.7, 1.7]) {
box(0.18, 2.75, 0.18, px, 2.03, pz, "#765038", group);
}
}
// Striped voxel canopy.
const stripeWidth = 5.6 / 8;
for (let i = 0; i < 8; i++) {
const color = i % 2 === 0 ? config.accent : "#fff4df";
box(
stripeWidth + 0.015,
0.22,
4.25,
-2.8 + stripeWidth * (i + 0.5),
3.48,
0,
color,
group
);
// Front valance.
box(
stripeWidth + 0.015,
0.48,
0.14,
-2.8 + stripeWidth * (i + 0.5),
3.08,
2.12,
color,
group
);
}
// Selection outline.
const selection = new THREE.Group();
const outlineColor = "#ffd65a";
box(5.95, 0.07, 0.12, 0, 0.76, 2.27, outlineColor, selection, false);
box(5.95, 0.07, 0.12, 0, 0.76, -2.27, outlineColor, selection, false);
box(0.12, 0.07, 4.55, -2.96, 0.76, 0, outlineColor, selection, false);
box(0.12, 0.07, 4.55, 2.96, 0.76, 0, outlineColor, selection, false);
selection.visible = false;
group.add(selection);
populateStall(group, config);
const label = worldLabel(
config.name.toUpperCase(),
0,
4.65,
0,
4.7,
"#fffaf0",
"#3f484b",
group
);
label.userData.stallLabel = true;
// Invisible interaction volume.
const hit = new THREE.Mesh(
new THREE.BoxGeometry(5.8, 4.2, 4.4),
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
})
);
hit.position.y = 2.2;
hit.userData.stall = {
index,
config,
selection
};
group.add(hit);
hitTargets.push(hit);
return group;
}
const stallPositions = [
[-12, -12, Math.PI / 2],
[-12, -7, Math.PI / 2],
[-12, 7, Math.PI / 2],
[-12, 12, Math.PI / 2],
[ 12, -12, -Math.PI / 2],
[ 12, -7, -Math.PI / 2],
[ 12, 7, -Math.PI / 2],
[ 12, 12, -Math.PI / 2]
];
stallPositions.forEach((position, index) => {
makeStall(stallConfigs[index], ...position, index);
});
// ------------------------------------------------------------
// Street furniture, trees and lamps
// ------------------------------------------------------------
function tree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
world.add(group);
box(0.62, 2.5, 0.62, 0, 1.75, 0, "#765238", group);
box(3.4, 1.65, 3.2, 0, 3.55, 0, "#58844d", group);
box(2.55, 1.35, 2.5, 0, 4.65, 0, "#6f9d57", group);
box(1.6, 0.95, 1.6, 0.25, 5.55, -0.15, "#83aa62", group);
}
[
[-18.5, -15],
[-18.5, 14.5],
[18.5, -15],
[18.5, 14.5],
[-17.8, 17],
[17.8, 17]
].forEach(([x, z], i) => tree(x, z, 0.86 + (i % 3) * 0.08));
function bench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
world.add(group);
box(2.8, 0.18, 0.62, 0, 1.15, 0, "#9a6943", group);
box(2.8, 0.7, 0.16, 0, 1.55, -0.3, "#a87348", group);
box(0.18, 0.75, 0.5, -1.05, 0.85, 0, "#4c5653", group);
box(0.18, 0.75, 0.5, 1.05, 0.85, 0, "#4c5653", group);
}
bench(-7.1, 4.6, Math.PI / 2);
bench(7.1, -4.6, Math.PI / 2);
bench(-17.5, 3.8, 0);
bench(17.5, -3.8, 0);
function lamp(x, z) {
box(0.22, 4.7, 0.22, x, 2.85, z, "#465457");
box(0.8, 0.15, 0.8, x, 5.15, z, "#465457");
box(0.62, 0.55, 0.62, x, 4.85, z, "#ffe7a5");
box(0.76, 0.12, 0.76, x, 5.55, z, "#465457");
}
[
[-5.4, -14],
[5.4, -14],
[-5.4, 4.2],
[5.4, 4.2],
[-5.4, 16],
[5.4, 16]
].forEach(([x, z]) => lamp(x, z));
// ------------------------------------------------------------
// Voxel pedestrians following the protected circulation routes
// ------------------------------------------------------------
const walkers = [];
const shirtColors = ["#e85d3f", "#397d8b", "#e6b346", "#6a8f5a", "#785f91"];
function makePerson(index, vertical) {
const group = new THREE.Group();
const shirt = shirtColors[index % shirtColors.length];
box(0.52, 0.88, 0.35, 0, 1.23, 0, shirt, group);
box(0.45, 0.45, 0.45, 0, 1.9, 0, index % 3 ? "#d6a277" : "#9b6749", group);
box(0.18, 0.65, 0.2, -0.15, 0.57, 0, "#35454d", group);
box(0.18, 0.65, 0.2, 0.15, 0.57, 0, "#35454d", group);
box(0.15, 0.6, 0.17, -0.35, 1.18, 0, shirt, group);
box(0.15, 0.6, 0.17, 0.35, 1.18, 0, shirt, group);
group.position.y = 0.6;
world.add(group);
walkers.push({
group,
vertical,
phase: index * 4.7,
speed: 1.0 + (index % 4) * 0.14,
lane: vertical ? (index % 2 ? 1.25 : -1.25) : (index % 2 ? 1.25 : -1.25)
});
}
for (let i = 0; i < 8; i++) makePerson(i, i < 5);
// ------------------------------------------------------------
// Selection and hover interaction
// ------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const titleElement = document.getElementById("stall-title");
const copyElement = document.getElementById("stall-copy");
let selectedStall = null;
function setPointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function hitStall(event) {
setPointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(hitTargets, false);
return hits.length ? hits[0].object.userData.stall : null;
}
function selectStall(stall) {
if (selectedStall) selectedStall.selection.visible = false;
selectedStall = stall;
if (stall) {
stall.selection.visible = true;
titleElement.textContent = stall.config.name;
copyElement.textContent =
"Bancaca voltada para o corredor interno. O módulo permanece " +
"fora do eixo de acesso à catedral e das áreas de travessia.";
} else {
titleElement.textContent = "Escolha uma barraca";
copyElement.textContent =
"Clique em uma barraca no cenário para consultar sua ocupação.";
}
}
renderer.domElement.addEventListener("pointermove", event => {
if (event.buttons === 0) {
const stall = hitStall(event);
renderer.domElement.style.cursor = stall ? "pointer" : "grab";
}
});
renderer.domElement.addEventListener("pointerleave", () => {
if (!selectedStall) {
titleElement.textContent = "Escolha uma barraca";
copyElement.textContent =
"Clique em uma barraca no cenário para consultar sua ocupação.";
}
});
// ------------------------------------------------------------
// Direct camera controls — no addons or example modules
// ------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 1.5, -1.5),
yaw: 0.72,
pitch: 0.66,
distance: 52,
dragging: false,
panning: false,
pointerId: null,
lastX: 0,
lastY: 0,
moved: 0
};
function updateCamera() {
const horizontal = Math.cos(controls.pitch) * controls.distance;
camera.position.set(
controls.target.x + Math.sin(controls.yaw) * horizontal,
controls.target.y + Math.sin(controls.pitch) * controls.distance,
controls.target.z + Math.cos(controls.yaw) * horizontal
);
camera.lookAt(controls.target);
}
function resetCamera() {
controls.target.set(0, 1.5, -1.5);
controls.yaw = 0.72;
controls.pitch = 0.66;
controls.distance = 52;
updateCamera();
}
function topCamera() {
controls.target.set(0, 0, 0);
controls.yaw = 0;
controls.pitch = 1.48;
controls.distance = 49;
updateCamera();
}
function panCamera(dx, dy) {
const scale = controls.distance * 0.0016;
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
right.y = 0;
right.normalize();
const forward = controls.target.clone().sub(camera.position);
forward.y = 0;
forward.normalize();
controls.target.addScaledVector(right, -dx * scale);
controls.target.addScaledVector(forward, -dy * scale);
controls.target.x = THREE.MathUtils.clamp(controls.target.x, -24, 24);
controls.target.z = THREE.MathUtils.clamp(controls.target.z, -25, 24);
}
renderer.domElement.addEventListener("pointerdown", event => {
if (controls.pointerId !== null) return;
controls.pointerId = event.pointerId;
controls.dragging = true;
controls.panning = event.button === 2 || event.shiftKey;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
controls.moved = 0;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = controls.panning ? "move" : "grabbing";
});
renderer.domElement.addEventListener("pointermove", event => {
if (!controls.dragging || event.pointerId !== controls.pointerId) return;
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
controls.moved += Math.abs(dx) + Math.abs(dy);
if (controls.panning) {
panCamera(dx, dy);
} else {
controls.yaw -= dx * 0.006;
controls.pitch = THREE.MathUtils.clamp(
controls.pitch + dy * 0.0045,
0.2,
1.49
);
}
updateCamera();
});
function endPointer(event) {
if (event.pointerId !== controls.pointerId) return;
if (controls.moved < 6) {
selectStall(hitStall(event));
}
controls.dragging = false;
controls.panning = false;
controls.pointerId = null;
renderer.domElement.style.cursor = "grab";
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
controls.distance = THREE.MathUtils.clamp(
controls.distance * Math.exp(event.deltaY * 0.001),
18,
92
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", event => {
const key = event.key.toLowerCase();
if (key === "r") resetCamera();
if (key === "t") topCamera();
if (key === "arrowleft") controls.yaw += 0.08;
if (key === "arrowright") controls.yaw -= 0.08;
if (key === "arrowup") controls.pitch = Math.min(1.49, controls.pitch + 0.06);
if (key === "arrowdown") controls.pitch = Math.max(0.2, controls.pitch - 0.06);
if (key === "+" || key === "=") controls.distance = Math.max(18, controls.distance - 3);
if (key === "-") controls.distance = Math.min(92, controls.distance + 3);
updateCamera();
});
document.getElementById("reset").addEventListener("click", resetCamera);
document.getElementById("top").addEventListener("click", topCamera);
const labelsButton = document.getElementById("labels");
labelsButton.addEventListener("click", () => {
const visible = !labelsButton.classList.contains("active");
labelsButton.classList.toggle("active", visible);
labels.forEach(label => label.visible = visible);
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
walkers.forEach(walker => {
if (walker.vertical) {
const progress = (elapsed * walker.speed + walker.phase) % 31;
walker.group.position.z = -13 + progress;
walker.group.position.x = walker.lane;
walker.group.rotation.y = 0;
} else {
const progress = (elapsed * walker.speed + walker.phase) % 41;
walker.group.position.x = -20 + progress;
walker.group.position.z = walker.lane;
walker.group.rotation.y = -Math.PI / 2;
}
const bob = Math.sin(elapsed * 8 + walker.phase) * 0.025;
walker.group.position.y = 0.6 + bob;
});
renderer.render(scene, camera);
}
updateCamera();
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
setTimeout(() => document.getElementById("loading").remove(), 500);
});
</script>
</body>
</html>
```