Prompt specification
Build or customize the Three.js 3D scene "Visitors moving between two cultural entrances" 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: Visitors moving between two cultural entrances
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/visitors-moving-between-two-cultural-entrances-x2662
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing Fortaleza's Dragão do Mar cultural complex. Create a compact referenced cultural-center vignette with stairs, walkway, and plaza. Animate visitors along both ground and elevated routes without merging their movement levels. Voxel style.
Working Three.js Starter (visitors-moving-between-two-cultural-entrances-x2662):
```html
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dragão do Mar — Fortaleza</title>
<style>
:root {
--navy: #123247;
--blue: #157ca3;
--cyan: #22c7d6;
--coral: #ee7657;
--cream: #f4ead5;
--glass: rgba(11, 35, 50, 0.88);
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: #b9dce5;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.panel {
position: fixed;
z-index: 5;
color: #f7fbff;
background: var(--glass);
border: 1px solid rgba(255,255,255,.14);
box-shadow: 0 12px 36px rgba(8, 30, 43, .18);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#title-card {
top: 18px;
left: 18px;
max-width: min(440px, calc(100vw - 36px));
padding: 18px 20px 16px;
border-radius: 16px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 6px;
color: #7ee3ec;
font-size: 11px;
font-weight: 800;
letter-spacing: .18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 4vw, 38px);
line-height: .98;
letter-spacing: -.035em;
}
#title-card p {
margin: 10px 0 0;
max-width: 380px;
color: rgba(244, 250, 255, .76);
font-size: 13px;
line-height: 1.45;
}
#controls {
top: 18px;
right: 18px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 7px;
padding: 8px;
border-radius: 14px;
}
button {
appearance: none;
border: 1px solid rgba(255,255,255,.14);
border-radius: 9px;
padding: 9px 11px;
color: #eef9ff;
background: rgba(255,255,255,.08);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition: background .15s, transform .15s, opacity .15s;
}
button:hover {
background: rgba(255,255,255,.16);
transform: translateY(-1px);
}
button[aria-pressed="false"] {
opacity: .45;
}
#legend {
left: 18px;
bottom: 18px;
width: min(330px, calc(100vw - 36px));
padding: 15px 16px;
border-radius: 14px;
pointer-events: none;
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
margin: 8px 0;
font-size: 13px;
}
.dot {
width: 11px;
height: 11px;
flex: 0 0 auto;
border-radius: 3px;
box-shadow: 0 0 0 3px rgba(255,255,255,.08);
}
.dot.ground { background: var(--coral); }
.dot.elevated { background: var(--cyan); }
.level-note {
margin-top: 11px;
padding-top: 10px;
border-top: 1px solid rgba(255,255,255,.13);
color: rgba(244,250,255,.72);
font-size: 11px;
line-height: 1.45;
}
#help {
right: 18px;
bottom: 18px;
max-width: 260px;
padding: 11px 13px;
border-radius: 12px;
color: rgba(245,251,255,.76);
font-size: 11px;
line-height: 1.5;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: #15384b;
background: #c9e4e8;
transition: opacity .45s ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
.loader {
text-align: center;
font-size: 12px;
font-weight: 800;
letter-spacing: .16em;
text-transform: uppercase;
}
.loader::after {
content: "";
display: block;
width: 42px;
height: 6px;
margin: 14px auto 0;
border-radius: 4px;
background: linear-gradient(90deg, #157ca3, #22c7d6, #ee7657);
animation: load 1s ease-in-out infinite alternate;
}
@keyframes load {
to { transform: scaleX(.35); opacity: .55; }
}
@media (max-width: 760px) {
#title-card {
top: 10px;
left: 10px;
padding: 14px 15px;
}
#title-card p { display: none; }
#controls {
top: 102px;
right: 10px;
max-width: calc(100vw - 20px);
}
#legend {
left: 10px;
bottom: 10px;
}
#help { display: none; }
}
</style>
</head>
<body>
<main id="scene" aria-label="Diorama tridimensional do complexo cultural Dragão do Mar"></main>
<section id="title-card" class="panel">
<div class="eyebrow">Fortaleza · Ceará · Brasil</div>
<h1>Dragão do Mar</h1>
<p>
Diorama voxel inspirado no complexo cultural à beira-mar, na Praça do Dragão:
museu, arquivo, biblioteca, praça, escadaria e mirante elevado.
</p>
</section>
<nav id="controls" class="panel" aria-label="Controles da cena">
<button id="ground-toggle" aria-pressed="true">Rota do chão</button>
<button id="elevated-toggle" aria-pressed="true">Rota elevada</button>
<button id="pause-toggle" aria-pressed="false">Pausar</button>
<button id="reset-camera">Vista inicial</button>
</nav>
<aside id="legend" class="panel">
<div class="legend-row">
<span class="dot ground"></span>
<span><strong>Nível 0</strong> · visitantes na praça e no passeio</span>
</div>
<div class="legend-row">
<span class="dot elevated"></span>
<span><strong>Nível 1</strong> · visitantes no mirante do telhado</span>
</div>
<div class="level-note">
Os dois percursos são independentes: cada visitante mantém sua altura,
sem transição ou mistura entre o chão e o nível elevado.
</div>
</aside>
<aside id="help" class="panel">
Arraste para orbitar · roda do mouse para zoom ·
botão direito ou Shift + arraste para mover · duplo clique para recentrar
</aside>
<div id="loading">
<div class="loader">Construindo o Dragão do Mar</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene, renderer, and lighting
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color("#b9dce5");
scene.fog = new THREE.Fog("#b9dce5", 42, 78);
const renderer = new THREE.WebGLRenderer({ antialias: true });
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;
document.querySelector("#scene").appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
140
);
const world = new THREE.Group();
scene.add(world);
const groundRouteGroup = new THREE.Group();
const elevatedRouteGroup = new THREE.Group();
const groundVisitorsGroup = new THREE.Group();
const elevatedVisitorsGroup = new THREE.Group();
world.add(
groundRouteGroup,
elevatedRouteGroup,
groundVisitorsGroup,
elevatedVisitorsGroup
);
const hemi = new THREE.HemisphereLight("#dff8ff", "#826d52", 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight("#fff2d4", 3.1);
sun.position.set(-14, 25, 17);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -27;
sun.shadow.camera.right = 27;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight("#8adbea", 0.8);
fill.position.set(17, 10, -15);
scene.add(fill);
// -------------------------------------------------------------------------
// Shared voxel construction helpers
// -------------------------------------------------------------------------
const materialCache = new Map();
function material(color, roughness = 0.84, metalness = 0) {
const key = `${color}|${roughness}|${metalness}`;
if (!materialCache.has(key)) {
materialCache.set(key, new THREE.MeshStandardMaterial({
color,
roughness,
metalness,
flatShading: true
}));
}
return materialCache.get(key);
}
function box(parent, size, position, color, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
options.material || material(color, options.roughness ?? 0.84)
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
if (options.rotation) mesh.rotation.set(...options.rotation);
parent.add(mesh);
return mesh;
}
function beamBetween(parent, a, b, thickness, color) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = box(
parent,
[length, thickness, thickness],
start.clone().add(end).multiplyScalar(0.5).toArray(),
color
);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(1, 0, 0),
direction.normalize()
);
return mesh;
}
function makeSign(parent, text, subtitle, position, width = 3, height = 0.8, bg = "#15384b") {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 224;
const ctx = canvas.getContext("2d");
ctx.fillStyle = bg;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = "rgba(255,255,255,.28)";
ctx.lineWidth = 8;
ctx.strokeRect(10, 10, canvas.width - 20, canvas.height - 20);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#f7fbff";
ctx.font = "800 55px system-ui, sans-serif";
ctx.fillText(text, canvas.width / 2, subtitle ? 89 : 112);
if (subtitle) {
ctx.fillStyle = "#8de4ea";
ctx.font = "700 25px system-ui, sans-serif";
ctx.fillText(subtitle, canvas.width / 2, 158);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(4, renderer.capabilities.getMaxAnisotropy());
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({ map: texture })
);
mesh.position.set(...position);
parent.add(mesh);
return mesh;
}
let seed = 8157;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function choose(array) {
return array[Math.floor(random() * array.length)];
}
// -------------------------------------------------------------------------
// Terrain, sea, promenade, and plaza
// -------------------------------------------------------------------------
box(world, [35, 1.2, 27], [0, -0.72, 0], "#d9c39c");
box(world, [27.3, 0.22, 26], [-3.35, -0.08, 0], "#d8d0ad");
// Atlantic-side water blocks.
box(world, [7.8, 0.2, 26], [13.85, -0.12, 0], "#167b9d", {
roughness: 0.48,
metalness: 0.08
});
box(world, [7.8, 0.035, 26], [13.85, 0.005, 0], "#238eaa", {
roughness: 0.5
});
const waveMeshes = [];
for (let x = 11.15; x < 16.8; x += 0.88) {
for (let z = -11.8; z <= 11.8; z += 0.92) {
if (random() > 0.68) {
const wave = box(
world,
[choose([0.35, 0.5, 0.68]), 0.055, 0.13],
[x + random() * 0.22, 0.055, z + random() * 0.18],
choose(["#62d1d7", "#83dfe1", "#b4eeee"]),
{ castShadow: false }
);
waveMeshes.push({ mesh: wave, phase: random() * Math.PI * 2 });
}
}
}
// Seawall and coastal promenade.
box(world, [0.38, 0.62, 26], [10.1, 0.23, 0], "#e8ddc5");
box(world, [0.16, 0.1, 26], [9.88, 0.57, 0], "#f6ecd8");
box(world, [1.3, 0.1, 25.3], [9.25, 0.06, 0], "#e8dfca");
for (let z = -11.5; z < 12; z += 1.15) {
box(world, [1.14, 0.025, 1.02], [9.25, 0.125, z], "#f4ead8", {
castShadow: false
});
}
// Plaza slab and individual voxel pavers.
box(world, [17.1, 0.16, 8.8], [-1.15, 0.08, 4.05], "#c8baa0");
const tileColors = ["#eadfc8", "#f1e7d2", "#dfd2b8", "#efe3ca"];
for (let ix = 0; ix < 15; ix++) {
for (let iz = 0; iz < 7; iz++) {
const x = -8.45 + ix * 1.08;
const z = 0.78 + iz * 1.08;
box(
world,
[1.01, 0.055, 1.01],
[x, 0.185, z],
tileColors[(ix + iz * 2) % tileColors.length],
{ castShadow: false }
);
}
}
// Connection from plaza to the waterfront.
box(world, [4.3, 0.1, 1.5], [7.05, 0.07, 4.1], "#e9dfc9");
for (let x = 5.1; x < 9.5; x += 0.85) {
box(world, [0.76, 0.04, 1.34], [x, 0.14, 4.1], "#f6ecd8", {
castShadow: false
});
}
// -------------------------------------------------------------------------
// Dragão do Mar cultural building
// -------------------------------------------------------------------------
const building = new THREE.Group();
world.add(building);
box(building, [15.3, 0.34, 8.25], [-2, 0.17, -3.3], "#f5ead5");
box(building, [14.1, 3.08, 7.45], [-2, 1.86, -3.3], "#f7f0e2");
box(building, [14.8, 0.22, 8.05], [-2, 3.48, -3.3], "#dce2dc");
// Blue glazed volumes for the museum, archive, and library.
box(building, [3.6, 2.18, 0.18], [-6.05, 1.77, 0.49], "#216a82");
box(building, [4.35, 2.42, 0.2], [-2, 1.9, 0.49], "#174f68");
box(building, [3.35, 2.18, 0.18], [2.22, 1.77, 0.49], "#216a82");
// Front columns and lintel.
for (const x of [-8.25, -4.15, 0.15, 4.2]) {
box(building, [0.32, 2.75, 0.34], [x, 1.74, 0.64], "#fff8e9");
}
box(building, [14.3, 0.32, 0.46], [-2, 3.16, 0.66], "#fff8e9");
// Pixel-like blue mosaic on the central facade.
const mosaicColors = [
"#0b4f6c", "#117b9c", "#1ca4b7", "#44c5ca", "#246d91"
];
for (let row = 0; row < 7; row++) {
for (let col = 0; col < 10; col++) {
if ((row === 3 && col > 3 && col < 7) || random() < 0.14) continue;
box(
building,
[0.37, 0.29, 0.09],
[-3.83 + col * 0.405, 0.72 + row * 0.345, 0.64],
choose(mosaicColors),
{ castShadow: false }
);
}
}
// Central entrance.
box(building, [1.45, 1.62, 0.16], [-2, 1.15, 0.74], "#0b3042");
box(building, [0.11, 1.62, 0.12], [-2, 1.15, 0.85], "#72bdc7");
box(building, [1.75, 0.14, 0.7], [-2, 0.3, 0.92], "#d4c6aa");
// Side windows.
for (const x of [-7.2, -5.2, 1.4, 3.0]) {
box(building, [0.75, 1.45, 0.09], [x, 1.8, 0.63], "#7ed2dc", {
roughness: 0.4
});
box(building, [0.08, 1.45, 0.11], [x, 1.8, 0.7], "#eaf4ec");
}
makeSign(building, "DRAGÃO DO MAR", "CULTURA · ARTE · MEMÓRIA",
[-2, 3.02, 0.72], 4.45, 0.72, "#14566c");
makeSign(building, "MUSEU", "ARTE", [-6.05, 0.67, 0.73], 2.25, 0.48, "#176f89");
makeSign(building, "ARQUIVO", "MEMÓRIA", [-2, 3.02, 0.83], 2.65, 0.56, "#176f89");
makeSign(building, "BIBLIOTECA", "LEITURA", [2.22, 0.67, 0.73], 2.35, 0.48, "#176f89");
// Voxel interpretation of the complex's whale-tail roof sculpture.
const tail = new THREE.Group();
tail.position.z = -3.3;
building.add(tail);
for (const side of [-1, 1]) {
for (let i = 0; i < 8; i++) {
const x = -2 + side * (0.43 + i * 0.72);
const y = 3.89 + i * 0.115;
const depth = 3.65 - i * 0.31;
box(tail, [0.76, 0.48, depth], [x, y, 0], "#fbf4e6");
box(tail, [0.72, 0.13, depth * 0.83], [x, y - 0.29, 0], "#2aa9ba");
}
}
box(tail, [1.12, 1.05, 2.6], [-2, 4.08, 0], "#f8f0df");
box(tail, [0.52, 1.65, 2.95], [-2, 4.08, 0.02], "#248fa9");
box(tail, [0.18, 1.75, 3.0], [-2, 4.12, 0.03], "#82d8dc");
// Roof-edge railings.
function railingLine(x1, z1, x2, z2) {
const distance = Math.hypot(x2 - x1, z2 - z1);
const count = Math.max(2, Math.ceil(distance / 1.35));
for (let i = 0; i <= count; i++) {
const t = i / count;
const x = THREE.MathUtils.lerp(x1, x2, t);
const z = THREE.MathUtils.lerp(z1, z2, t);
box(building, [0.1, 0.67, 0.1], [x, 3.93, z], "#e9f0e9");
}
beamBetween(building, [x1, 4.25, z1], [x2, 4.25, z2], 0.09, "#dce9e7");
}
railingLine(-9.25, 0.67, 5.25, 0.67);
railingLine(-9.25, -7.17, 5.25, -7.17);
railingLine(-9.25, -7.17, -9.25, 0.67);
railingLine(5.25, -7.17, 5.25, 0.67);
// -------------------------------------------------------------------------
// Stairs and elevated landing
// -------------------------------------------------------------------------
const stairs = new THREE.Group();
world.add(stairs);
const stairCount = 12;
for (let i = 0; i < stairCount; i++) {
const height = (i + 1) * 0.275;
const z = 3.05 - i * 0.325;
box(stairs, [2.05, height, 0.34], [7.5, height / 2, z], "#e9ddc5");
box(stairs, [1.86, 0.035, 0.22], [7.5, height + 0.018, z + 0.03], "#f8eedc", {
castShadow: false
});
}
// Elevated landing and bridge to the roof.
box(stairs, [3.9, 0.23, 1.05], [6.75, 3.43, -0.74], "#d9e2dc");
box(stairs, [3.9, 0.035, 0.19], [6.75, 3.57, -0.47], "#22c7d6", {
castShadow: false
});
// Sloping stair rails.
for (const x of [6.42, 8.58]) {
for (let i = 0; i <= 6; i++) {
const t = i / 6;
const z = THREE.MathUtils.lerp(3.05, -0.74, t);
const y = THREE.MathUtils.lerp(0.25, 3.58, t);
box(stairs, [0.09, 0.75, 0.09], [x, y + 0.36, z], "#ecf1e8");
}
beamBetween(
stairs,
[x, 0.92, 3.05],
[x, 4.28, -0.74],
0.09,
"#e5eee8"
);
}
makeSign(stairs, "NÍVEL +1", "MIRANTE", [7.5, 2.2, 2.9], 1.85, 0.6, "#126b7c");
// -------------------------------------------------------------------------
// Separate route geometry: ground and elevated levels
// -------------------------------------------------------------------------
const GROUND_Y = 0.235;
const ELEVATED_Y = 3.59;
const groundRoute = [
new THREE.Vector3(-8.7, GROUND_Y, 1.45),
new THREE.Vector3(5.45, GROUND_Y, 1.45),
new THREE.Vector3(5.45, GROUND_Y, 7.25),
new THREE.Vector3(-8.7, GROUND_Y, 7.25)
];
const elevatedRoute = [
new THREE.Vector3(4.25, ELEVATED_Y, -0.72),
new THREE.Vector3(4.25, ELEVATED_Y, -6.15),
new THREE.Vector3(-8.2, ELEVATED_Y, -6.15),
new THREE.Vector3(-8.2, ELEVATED_Y, -0.72)
];
function addRoute(parent, points, color, width = 0.22) {
for (let i = 0; i < points.length; i++) {
const a = points[i];
const b = points[(i + 1) % points.length];
const dx = b.x - a.x;
const dz = b.z - a.z;
const length = Math.hypot(dx, dz);
const segment = box(
parent,
[length, 0.035, width],
[(a.x + b.x) / 2, a.y, (a.z + b.z) / 2],
color,
{
castShadow: false,
material: new THREE.MeshStandardMaterial({
color,
roughness: 0.7,
emissive: color,
emissiveIntensity: 0.08
})
}
);
segment.rotation.y = Math.atan2(-dz, dx);
}
for (const point of points) {
box(parent, [0.42, 0.045, 0.42], [point.x, point.y + 0.002, point.z], color, {
castShadow: false
});
}
}
addRoute(groundRouteGroup, groundRoute, "#ee7657", 0.24);
addRoute(elevatedRouteGroup, elevatedRoute, "#22c7d6", 0.24);
// -------------------------------------------------------------------------
// Plaza fountain with a small block-built sea dragon
// -------------------------------------------------------------------------
const fountain = new THREE.Group();
fountain.position.set(-1.5, 0, 4.15);
world.add(fountain);
box(fountain, [4.25, 0.28, 3.05], [0, 0.34, 0], "#e9dec7");
box(fountain, [3.75, 0.12, 2.55], [0, 0.53, 0], "#2db4c5", {
roughness: 0.38
});
box(fountain, [3.15, 0.06, 1.95], [0, 0.61, 0], "#66d5d8", {
roughness: 0.3,
castShadow: false
});
// Dragon body, neck, head, fins, and stepped tail.
box(fountain, [0.95, 0.65, 1.35], [-0.18, 1.0, -0.18], "#147c99");
box(fountain, [0.48, 0.88, 0.5], [-0.18, 1.45, 0.47], "#168ca6");
box(fountain, [0.82, 0.55, 0.65], [-0.18, 1.93, 0.73], "#1595aa");
box(fountain, [0.56, 0.3, 0.38], [-0.18, 1.85, 1.12], "#39b5bf");
box(fountain, [0.1, 0.1, 0.1], [-0.42, 2.02, 1.31], "#102d3c");
box(fountain, [0.1, 0.1, 0.1], [0.05, 2.02, 1.31], "#102d3c");
box(fountain, [0.18, 0.55, 0.65], [-0.66, 1.1, 0.14], "#e56f56");
box(fountain, [0.18, 0.55, 0.65], [0.3, 1.1, 0.14], "#e56f56");
box(fountain, [0.14, 0.65, 0.75], [-0.18, 1.15, -0.78], "#73d5d6");
for (let i = 0; i < 4; i++) {
box(
fountain,
[0.42 - i * 0.07, 0.22, 0.32],
[-0.18, 0.84 - i * 0.06, -0.9 - i * 0.28],
i % 2 ? "#1595aa" : "#2db4c5"
);
}
box(fountain, [0.16, 0.42, 0.16], [-0.18, 2.31, 0.55], "#ee7657");
box(fountain, [0.16, 0.42, 0.16], [-0.48, 2.25, 0.62], "#ee7657");
// Pixelated fountain splashes.
for (const [x, y, z] of [
[-1.2, 1.35, 0.2], [-0.7, 1.5, -0.5], [0.6, 1.2, 0.6],
[1.1, 1.55, -0.3], [0.3, 1.8, -0.9]
]) {
box(fountain, [0.13, 0.13, 0.13], [x, y, z], "#a4ebea", {
castShadow: false
});
}
// -------------------------------------------------------------------------
// Furniture, trees, palms, and lamps
// -------------------------------------------------------------------------
function makeTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
world.add(tree);
box(tree, [0.28, 1.5, 0.28], [0, 0.75, 0], "#88694a");
box(tree, [1.35, 0.65, 1.25], [0, 1.8, 0], "#3d8767");
box(tree, [0.9, 0.7, 0.9], [-0.62, 1.55, 0.12], "#4b9b70");
box(tree, [0.85, 0.72, 0.82], [0.58, 1.62, -0.08], "#367b5e");
box(tree, [0.72, 0.65, 0.75], [0.03, 2.25, 0.02], "#65aa79");
box(tree, [1.45, 0.16, 1.35], [0, 1.5, 0], "#d2ae70");
}
function makePalm(x, z, scale = 1) {
const palm = new THREE.Group();
palm.position.set(x, 0, z);
palm.scale.setScalar(scale);
world.add(palm);
for (let i = 0; i < 5; i++) {
box(palm, [0.18, 0.55, 0.18], [0, 0.3 + i * 0.5, 0], "#9b7850");
}
box(palm, [1.7, 0.13, 0.38], [0, 2.65, 0], "#3b8d68");
box(palm, [0.38, 0.13, 1.65], [0, 2.63, 0], "#4aa16f");
box(palm, [1.25, 0.12, 0.35], [0.48, 2.8, 0.46], "#66ad75");
box(palm, [0.34, 0.12, 1.2], [-0.5, 2.78, -0.42], "#2f7d61");
}
function makeBench(x, z, rotation = 0) {
const bench = new THREE.Group();
bench.position.set(x, 0, z);
bench.rotation.y = rotation;
world.add(bench);
box(bench, [1.7, 0.14, 0.48], [0, 0.55, 0], "#9a6849");
box(bench, [1.7, 0.48, 0.12], [0, 0.9, -0.22], "#a97550");
box(bench, [0.16, 0.48, 0.38], [-0.63, 0.25, 0], "#435963");
box(bench, [0.16, 0.48, 0.38], [0.63, 0.25, 0], "#435963");
}
function makeLamp(x, z) {
box(world, [0.15, 2.3, 0.15], [x, 1.15, z], "#3a5662");
box(world, [0.42, 0.22, 0.42], [x, 2.33, z], "#f6df9b", {
roughness: 0.35,
material: new THREE.MeshStandardMaterial({
color: "#ffe4a4",
emissive: "#ffc96a",
emissiveIntensity: 0.38,
roughness: 0.4
})
});
box(world, [0.55, 0.1, 0.55], [x, 2.49, z], "#38515d");
}
makeTree(-12.2, -4.2, 1.15);
makeTree(-12.4, 7.9, 0.92);
makeTree(6.8, -8.7, 0.88);
makePalm(9.0, -8.9, 0.86);
makePalm(9.0, -1.8, 0.8);
makePalm(9.0, 6.2, 0.92);
makePalm(8.7, 10.0, 0.8);
makeBench(-6.4, 8.45, 0);
makeBench(2.9, 8.45, 0);
makeBench(-10.0, 3.5, Math.PI / 2);
makeLamp(-9.7, 0.0);
makeLamp(6.6, 8.6);
makeLamp(8.9, -4.9);
// Low cultural wayfinding markers.
box(world, [0.55, 0.75, 0.55], [-11.0, 0.38, 0.1], "#176f89");
makeSign(world, "PRAÇA", "CULTURAL", [-11.0, 0.52, 0.39], 1.3, 0.55, "#176f89");
// -------------------------------------------------------------------------
// Animated voxel visitors
// -------------------------------------------------------------------------
class Route {
constructor(points, closed = true) {
this.points = points.map(p => p.clone());
this.closed = closed;
this.segments = [];
this.length = 0;
const segmentCount = closed ? points.length : points.length - 1;
for (let i = 0; i < segmentCount; i++) {
const a = this.points[i];
const b = this.points[(i + 1) % this.points.length];
const length = a.distanceTo(b);
this.segments.push({ a, b, length, start: this.length });
this.length += length;
}
}
sample(distance) {
let d = distance;
if (this.closed) {
d = ((d % this.length) + this.length) % this.length;
} else {
d = Math.max(0, Math.min(this.length, d));
}
let segment = this.segments[this.segments.length - 1];
for (const candidate of this.segments) {
if (d <= candidate.start + candidate.length) {
segment = candidate;
break;
}
}
const local = segment.length === 0 ? 0 : (d - segment.start) / segment.length;
const point = segment.a.clone().lerp(segment.b, local);
const tangent = segment.b.clone().sub(segment.a).normalize();
return { point, tangent };
}
}
const groundPath = new Route(groundRoute, true);
const elevatedPath = new Route(elevatedRoute, true);
function makeVisitor(color, elevated, phase) {
const group = new THREE.Group();
const rig = new THREE.Group();
group.add(rig);
const skin = choose(["#d9a77c", "#a86c4f", "#efc7a1", "#7e4b36"]);
const shirt = color;
box(rig, [0.32, 0.42, 0.23], [0, 0.69, 0], shirt);
box(rig, [0.27, 0.27, 0.26], [0, 1.04, 0], skin);
box(rig, [0.29, 0.1, 0.28], [0, 1.19, -0.01], elevated ? "#143b50" : "#533c33");
if (elevated) {
box(rig, [0.34, 0.07, 0.31], [0, 1.25, -0.01], "#22c7d6");
}
const leftLegPivot = new THREE.Group();
const rightLegPivot = new THREE.Group();
leftLegPivot.position.set(-0.09, 0.49, 0);
rightLegPivot.position.set(0.09, 0.49, 0);
rig.add(leftLegPivot, rightLegPivot);
box(leftLegPivot, [0.12, 0.36, 0.13], [0, -0.18, 0], "#29465a");
box(rightLegPivot, [0.12, 0.36, 0.13], [0, -0.18, 0], "#29465a");
box(leftLegPivot, [0.14, 0.09, 0.22], [0, -0.37, 0.04], "#172e3c");
box(rightLegPivot, [0.14, 0.09, 0.22], [0, -0.37, 0.04], "#172e3c");
const leftArmPivot = new THREE.Group();
const rightArmPivot = new THREE.Group();
leftArmPivot.position.set(-0.22, 0.84, 0);
rightArmPivot.position.set(0.22, 0.84, 0);
rig.add(leftArmPivot, rightArmPivot);
box(leftArmPivot, [0.1, 0.31, 0.11], [0, -0.15, 0], shirt);
box(rightArmPivot, [0.1, 0.31, 0.11], [0, -0.15, 0], shirt);
box(leftArmPivot, [0.1, 0.11, 0.11], [0, -0.31, 0], skin);
box(rightArmPivot, [0.1, 0.11, 0.11], [0, -0.31, 0], skin);
// Tiny color marker identifies elevated visitors.
if (elevated) {
box(rig, [0.12, 0.12, 0.12], [0, 1.42, 0], "#22c7d6", {
castShadow: false
});
}
return {
group,
rig,
leftLegPivot,
rightLegPivot,
leftArmPivot,
rightArmPivot,
phase,
yaw: 0,
level: elevated ? "elevated" : "ground"
};
}
const visitors = [];
const groundColors = ["#e56f56", "#efaa45", "#416b83", "#8b5f89", "#f1d06b"];
const elevatedColors = ["#1ca9bb", "#2f768f", "#62c6cc", "#5064a0", "#d88364"];
for (let i = 0; i < 10; i++) {
const visitor = makeVisitor(
groundColors[i % groundColors.length],
false,
random() * Math.PI * 2
);
visitor.speed = 0.62 + random() * 0.28;
visitor.offset = random() * groundPath.length;
groundVisitorsGroup.add(visitor.group);
visitors.push(visitor);
}
for (let i = 0; i < 6; i++) {
const visitor = makeVisitor(
elevatedColors[i % elevatedColors.length],
true,
random() * Math.PI * 2
);
visitor.speed = 0.43 + random() * 0.2;
visitor.offset = random() * elevatedPath.length;
elevatedVisitorsGroup.add(visitor.group);
visitors.push(visitor);
}
function updateVisitor(visitor, delta, elapsed) {
const route = visitor.level === "ground" ? groundPath : elevatedPath;
const distance = visitor.offset + elapsed * visitor.speed;
const sample = route.sample(distance);
visitor.group.position.copy(sample.point);
const desiredYaw = Math.atan2(sample.tangent.x, sample.tangent.z);
const difference = Math.atan2(
Math.sin(desiredYaw - visitor.yaw),
Math.cos(desiredYaw - visitor.yaw)
);
visitor.yaw += difference * Math.min(1, delta * 8);
visitor.group.rotation.y = visitor.yaw;
const stride = Math.sin(elapsed * visitor.speed * 10 + visitor.phase);
visitor.leftLegPivot.rotation.x = stride * 0.52;
visitor.rightLegPivot.rotation.x = -stride * 0.52;
visitor.leftArmPivot.rotation.x = -stride * 0.42;
visitor.rightArmPivot.rotation.x = stride * 0.42;
visitor.rig.position.y = Math.abs(stride) * 0.018;
}
// -------------------------------------------------------------------------
// Camera controls implemented directly, without examples/addons
// -------------------------------------------------------------------------
const cameraState = {
theta: 0.72,
phi: 0.93,
radius: 34,
target: new THREE.Vector3(-0.7, 1.1, 0)
};
const initialCameraState = {
theta: 0.72,
phi: 0.93,
radius: 34,
target: new THREE.Vector3(-0.7, 1.1, 0)
};
function updateCamera() {
const { theta, phi, radius, target } = cameraState;
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + radius * sinPhi * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(target);
}
function resetCamera() {
cameraState.theta = initialCameraState.theta;
cameraState.phi = initialCameraState.phi;
cameraState.radius = initialCameraState.radius;
cameraState.target.copy(initialCameraState.target);
updateCamera();
}
const pointers = new Map();
let pinchDistance = 0;
let dragMode = "orbit";
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
dragMode = event.button === 2 || event.shiftKey ? "pan" : "orbit";
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (pinchDistance / Math.max(1, distance)),
18,
52
);
}
pinchDistance = distance;
updateCamera();
return;
}
if (dragMode === "orbit") {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.35,
1.35
);
} else {
const scale = cameraState.radius / 520;
const right = new THREE.Vector3(
Math.cos(cameraState.theta),
0,
-Math.sin(cameraState.theta)
);
const forward = new THREE.Vector3(
-Math.sin(cameraState.theta),
0,
-Math.cos(cameraState.theta)
);
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(forward, -dy * scale);
cameraState.target.x = THREE.MathUtils.clamp(cameraState.target.x, -9, 9);
cameraState.target.z = THREE.MathUtils.clamp(cameraState.target.z, -8, 8);
}
updateCamera();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
18,
52
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// UI controls
// -------------------------------------------------------------------------
const groundButton = document.querySelector("#ground-toggle");
const elevatedButton = document.querySelector("#elevated-toggle");
const pauseButton = document.querySelector("#pause-toggle");
let paused = false;
groundButton.addEventListener("click", () => {
const visible = !groundRouteGroup.visible;
groundRouteGroup.visible = visible;
groundVisitorsGroup.visible = visible;
groundButton.setAttribute("aria-pressed", String(visible));
});
elevatedButton.addEventListener("click", () => {
const visible = !elevatedRouteGroup.visible;
elevatedRouteGroup.visible = visible;
elevatedVisitorsGroup.visible = visible;
elevatedButton.setAttribute("aria-pressed", String(visible));
});
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.setAttribute("aria-pressed", String(paused));
pauseButton.textContent = paused ? "Continuar" : "Pausar";
});
document.querySelector("#reset-camera").addEventListener("click", resetCamera);
// -------------------------------------------------------------------------
// Resize and animation loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) elapsed += delta;
for (const visitor of visitors) {
updateVisitor(visitor, delta, elapsed);
}
for (const wave of waveMeshes) {
wave.mesh.position.y = 0.055 + Math.sin(elapsed * 1.5 + wave.phase) * 0.025;
}
renderer.render(scene, camera);
}
updateCamera();
renderer.render(scene, camera);
animate();
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
setTimeout(() => document.querySelector("#loading").remove(), 500);
});
</script>
</body>
</html>
```