Prompt specification
Build or customize the Three.js 3D scene "Trace household and visitor routes through a shared courtyard" 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: Trace household and visitor routes through a shared courtyard
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/trace-household-and-visitor-routes-through-a-shared-co-x2724
Scene Description Prompt:
Trace residents, visitors, and deliveries through a fictional voxel courtyard in Buenos Aires's La Boca, preserving private areas. Three.js from cdnjs, one HTML file.
Working Three.js Starter (trace-household-and-visitor-routes-through-a-shared-co-x2724):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="theme-color" content="#132a30">
<title>La Boca Courtyard Trace</title>
<style>
:root {
--ink: #132a30;
--muted: #61777a;
--paper: #f8f4e9;
--panel: rgba(248, 244, 233, 0.94);
--line: rgba(19, 42, 48, 0.13);
--resident: #31bfa5;
--visitor: #eab84f;
--delivery: #ed715d;
--shadow: 0 16px 45px rgba(19, 42, 48, 0.16);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8dfda;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, input { font: inherit; }
button {
color: inherit;
border: 0;
cursor: pointer;
}
button:focus-visible,
input:focus-visible {
outline: 3px solid rgba(49, 191, 165, 0.48);
outline-offset: 2px;
}
#stage,
#stage canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
#stage canvas { cursor: grab; }
.loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #d8dfda;
color: var(--ink);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.hud {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.panel,
.topbar,
.camera-dock,
.hint {
pointer-events: auto;
}
.topbar {
position: absolute;
top: 20px;
left: 22px;
right: 22px;
display: flex;
align-items: flex-start;
justify-content: space-between;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
text-shadow: 0 1px 0 rgba(255,255,255,.5);
}
.brand-mark {
width: 42px;
height: 42px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 3px;
transform: rotate(-2deg);
}
.brand-mark i {
display: block;
border-radius: 2px;
box-shadow: 0 3px 8px rgba(19,42,48,.13);
}
.brand-mark i:nth-child(1) { background: #ed715d; }
.brand-mark i:nth-child(2) { background: #eab84f; }
.brand-mark i:nth-child(3) { background: #4a91c4; }
.brand-mark i:nth-child(4) { background: #31bfa5; }
.brand h1 {
margin: 0;
font-size: 20px;
line-height: 1;
letter-spacing: 0.15em;
font-weight: 900;
}
.brand p {
margin: 6px 0 0;
color: #50686c;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.privacy-badge {
display: flex;
align-items: center;
gap: 9px;
padding: 10px 13px;
border: 1px solid rgba(19,42,48,.12);
border-radius: 999px;
background: rgba(248,244,233,.88);
box-shadow: 0 8px 25px rgba(19,42,48,.09);
backdrop-filter: blur(12px);
font-size: 11px;
font-weight: 850;
letter-spacing: 0.04em;
}
.privacy-badge span {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--resident);
box-shadow: 0 0 0 4px rgba(49,191,165,.15);
}
.control-panel {
position: absolute;
top: 88px;
left: 22px;
width: 306px;
padding: 20px;
border: 1px solid rgba(255,255,255,.58);
border-radius: 20px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
}
.eyebrow {
margin: 0 0 7px;
color: #718587;
font-size: 10px;
font-weight: 900;
letter-spacing: .15em;
text-transform: uppercase;
}
.control-panel h2 {
margin: 0;
font-size: 25px;
line-height: 1.05;
letter-spacing: -.035em;
}
.intro {
margin: 10px 0 18px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin: 17px 0 8px;
font-size: 10px;
font-weight: 900;
letter-spacing: .12em;
text-transform: uppercase;
}
.section-title button {
padding: 3px 6px;
border-radius: 6px;
background: transparent;
color: #5b7376;
font-size: 9px;
font-weight: 900;
letter-spacing: .08em;
text-transform: uppercase;
}
.section-title button:hover { background: rgba(19,42,48,.07); }
.roles {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.role-button {
position: relative;
min-width: 0;
padding: 11px 6px 10px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255,255,255,.42);
transition: transform .15s ease, background .15s ease, opacity .15s ease;
}
.role-button:hover { transform: translateY(-1px); }
.role-button.off {
opacity: .42;
background: transparent;
}
.role-button .dot {
display: block;
width: 10px;
height: 10px;
margin: 0 auto 7px;
border-radius: 3px;
background: var(--role);
box-shadow: 0 0 0 4px color-mix(in srgb, var(--role) 17%, transparent);
}
.role-button strong {
display: block;
overflow: hidden;
font-size: 10px;
text-overflow: ellipsis;
white-space: nowrap;
}
.role-button small {
display: block;
margin-top: 3px;
color: #718487;
font-size: 9px;
font-weight: 750;
}
.trace-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin: 13px 0 0;
padding-top: 13px;
border-top: 1px solid var(--line);
}
.trace-row label {
font-size: 11px;
font-weight: 850;
}
.toggle {
position: relative;
width: 40px;
height: 23px;
padding: 0;
border-radius: 999px;
background: #cbd3cf;
transition: background .18s ease;
}
.toggle::after {
content: "";
position: absolute;
top: 3px;
left: 3px;
width: 17px;
height: 17px;
border-radius: 50%;
background: white;
box-shadow: 0 2px 6px rgba(19,42,48,.2);
transition: transform .18s ease;
}
.toggle.on { background: var(--resident); }
.toggle.on::after { transform: translateX(17px); }
.timeline {
margin-top: 17px;
padding-top: 15px;
border-top: 1px solid var(--line);
}
.timeline-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.play {
width: 35px;
height: 35px;
border-radius: 11px;
background: var(--ink);
color: white;
font-size: 13px;
}
.clock {
margin-right: auto;
font-variant-numeric: tabular-nums;
font-size: 12px;
font-weight: 850;
}
.speeds {
display: flex;
gap: 3px;
padding: 3px;
border-radius: 9px;
background: rgba(19,42,48,.07);
}
.speed {
padding: 5px 7px;
border-radius: 6px;
background: transparent;
color: #657a7d;
font-size: 9px;
font-weight: 900;
}
.speed.active {
background: white;
color: var(--ink);
box-shadow: 0 2px 8px rgba(19,42,48,.09);
}
#timeline {
width: 100%;
height: 4px;
margin: 16px 0 7px;
border-radius: 999px;
accent-color: var(--ink);
cursor: pointer;
}
.timeline-labels {
display: flex;
justify-content: space-between;
color: #7b8e90;
font-size: 9px;
font-weight: 750;
}
.privacy-note {
display: flex;
align-items: flex-start;
gap: 8px;
margin-top: 15px;
padding: 10px;
border: 1px solid rgba(49,191,165,.22);
border-radius: 11px;
background: rgba(49,191,165,.08);
color: #3f6866;
font-size: 10px;
line-height: 1.45;
}
.privacy-note b {
color: #236c65;
font-size: 13px;
}
.selected-card {
position: absolute;
top: 88px;
right: 22px;
width: 292px;
padding: 18px;
border: 1px solid rgba(255,255,255,.58);
border-radius: 18px;
background: rgba(248,244,233,.93);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
}
.selected-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 10px;
}
.actor-role {
display: inline-flex;
align-items: center;
gap: 6px;
margin-bottom: 7px;
color: var(--actor-color, var(--resident));
font-size: 9px;
font-weight: 900;
letter-spacing: .12em;
text-transform: uppercase;
}
.actor-role::before {
content: "";
width: 7px;
height: 7px;
border-radius: 2px;
background: currentColor;
}
.selected-card h3 {
margin: 0;
font-size: 22px;
letter-spacing: -.03em;
}
.live-badge {
padding: 5px 7px;
border-radius: 7px;
background: rgba(19,42,48,.07);
color: #607578;
font-size: 8px;
font-weight: 900;
letter-spacing: .1em;
text-transform: uppercase;
}
.activity {
margin: 15px 0;
padding: 12px;
border-radius: 11px;
background: rgba(19,42,48,.055);
font-size: 12px;
font-weight: 760;
line-height: 1.45;
}
.detail-row {
display: grid;
grid-template-columns: 62px 1fr;
gap: 8px;
padding: 7px 0;
border-top: 1px solid var(--line);
font-size: 10px;
line-height: 1.4;
}
.detail-row span:first-child {
color: #788b8d;
font-weight: 800;
}
.progress {
height: 5px;
margin-top: 14px;
overflow: hidden;
border-radius: 99px;
background: rgba(19,42,48,.08);
}
.progress i {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: var(--actor-color, var(--resident));
}
.selected-card .follow {
width: 100%;
margin-top: 14px;
padding: 10px;
border-radius: 10px;
background: var(--ink);
color: white;
font-size: 10px;
font-weight: 900;
letter-spacing: .05em;
text-transform: uppercase;
}
.selected-card .follow:disabled {
cursor: not-allowed;
opacity: .38;
}
.camera-dock {
position: absolute;
bottom: 22px;
left: 50%;
display: flex;
align-items: center;
gap: 5px;
padding: 5px;
border: 1px solid rgba(255,255,255,.6);
border-radius: 13px;
background: rgba(248,244,233,.9);
box-shadow: 0 10px 30px rgba(19,42,48,.13);
backdrop-filter: blur(14px);
transform: translateX(-50%);
}
.camera-dock button {
height: 33px;
padding: 0 12px;
border-radius: 9px;
background: transparent;
font-size: 9px;
font-weight: 900;
letter-spacing: .06em;
text-transform: uppercase;
}
.camera-dock button:hover { background: rgba(19,42,48,.07); }
.camera-dock .zoom {
width: 33px;
padding: 0;
font-size: 16px;
}
.hint {
position: absolute;
bottom: 24px;
left: 22px;
max-width: 290px;
color: rgba(19,42,48,.68);
font-size: 9px;
font-weight: 850;
letter-spacing: .06em;
line-height: 1.55;
text-transform: uppercase;
text-shadow: 0 1px 0 rgba(255,255,255,.45);
}
.fictional {
position: absolute;
right: 23px;
bottom: 25px;
color: rgba(19,42,48,.55);
font-size: 9px;
font-weight: 850;
letter-spacing: .11em;
text-transform: uppercase;
}
#tooltip {
position: fixed;
z-index: 10;
display: none;
padding: 8px 10px;
border: 1px solid rgba(255,255,255,.45);
border-radius: 9px;
background: rgba(19,42,48,.92);
color: white;
box-shadow: 0 8px 20px rgba(19,42,48,.2);
font-size: 10px;
line-height: 1.35;
pointer-events: none;
}
#tooltip strong {
display: block;
font-size: 11px;
}
#tooltip span {
color: #b9cccb;
}
@media (max-width: 760px) {
.topbar { top: 12px; left: 12px; right: 12px; }
.brand-mark { width: 35px; height: 35px; }
.brand h1 { font-size: 16px; }
.brand p { font-size: 8px; }
.privacy-badge { padding: 8px 10px; font-size: 8px; }
.privacy-badge span { display: none; }
.control-panel {
top: 62px;
left: 12px;
width: min(278px, calc(100vw - 24px));
max-height: calc(100vh - 154px);
overflow: auto;
padding: 16px;
}
.control-panel h2 { font-size: 21px; }
.intro { display: none; }
.selected-card {
top: auto;
right: 12px;
bottom: 76px;
width: min(276px, calc(100vw - 24px));
max-height: 36vh;
overflow: auto;
padding: 14px;
}
.selected-card h3 { font-size: 18px; }
.selected-card .activity { margin: 10px 0; }
.camera-dock { bottom: 13px; }
.camera-dock button { padding: 0 9px; }
.hint, .fictional { display: none; }
}
</style>
</head>
<body>
<div id="stage" aria-label="Interactive voxel courtyard showing anonymized movement routes"></div>
<div class="loading" id="loading">Building the courtyard…</div>
<div class="hud">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"><i></i><i></i><i></i><i></i></div>
<div>
<h1>LA BOCA</h1>
<p>Courtyard trace · fictional block</p>
</div>
</div>
<div class="privacy-badge" title="No household interiors or private access paths are modeled">
<span></span>
Private areas protected
</div>
</header>
<section class="control-panel" aria-label="Movement controls">
<p class="eyebrow">Movement study / 01</p>
<h2>Public courtyard</h2>
<p class="intro">
Follow anonymized residents, guests, and deliveries through a fictional
voxel courtyard inspired by La Boca.
</p>
<div class="section-title">
<span>Visible groups</span>
<button id="showAll" type="button">Show all</button>
</div>
<div class="roles">
<button class="role-button" data-role="resident" style="--role:var(--resident)" type="button">
<span class="dot"></span>
<strong>Residents</strong>
<small>3 traces</small>
</button>
<button class="role-button" data-role="visitor" style="--role:var(--visitor)" type="button">
<span class="dot"></span>
<strong>Visitors</strong>
<small>2 traces</small>
</button>
<button class="role-button" data-role="delivery" style="--role:var(--delivery)" type="button">
<span class="dot"></span>
<strong>Deliveries</strong>
<small>2 traces</small>
</button>
</div>
<div class="trace-row">
<label for="traceToggle">Route trails</label>
<button class="toggle on" id="traceToggle" type="button" aria-label="Toggle route trails"></button>
</div>
<div class="timeline">
<div class="timeline-top">
<button class="play" id="playButton" type="button" aria-label="Pause simulation">Ⅱ</button>
<span class="clock" id="clock">00:18</span>
<div class="speeds" aria-label="Playback speed">
<button class="speed" data-speed="0.5" type="button">0.5×</button>
<button class="speed active" data-speed="1" type="button">1×</button>
<button class="speed" data-speed="2" type="button">2×</button>
</div>
</div>
<input id="timeline" type="range" min="0" max="120" step="0.1" value="18" aria-label="Simulation timeline">
<div class="timeline-labels"><span>00:00</span><span>02:00</span></div>
</div>
<div class="privacy-note">
<b>◆</b>
<span>Private dwellings are abstract façades. Traces stop at masked thresholds; no interior routes are recorded.</span>
</div>
</section>
<aside class="selected-card" id="selectedCard" aria-live="polite">
<div class="selected-head">
<div>
<div class="actor-role" id="actorRole">Resident</div>
<h3 id="actorName">Sofía</h3>
</div>
<span class="live-badge">Live trace</span>
</div>
<div class="activity" id="actorActivity">Crossing the public plaza</div>
<div class="detail-row">
<span>Route</span><span id="actorRoute">Masked dwelling → neighborhood café</span>
</div>
<div class="detail-row">
<span>Location</span><span id="actorLocation">Public courtyard</span>
</div>
<div class="detail-row">
<span>Privacy</span><span>Personal identity and private interior excluded</span>
</div>
<div class="progress"><i id="actorProgress"></i></div>
<button class="follow" id="followButton" type="button">Follow this trace</button>
</aside>
<div class="camera-dock" aria-label="Camera controls">
<button id="overviewButton" type="button">Overview</button>
<button class="zoom" id="zoomIn" type="button" aria-label="Zoom in">+</button>
<button class="zoom" id="zoomOut" type="button" aria-label="Zoom out">−</button>
</div>
<div class="hint">Drag to orbit · Shift-drag to pan · Scroll to zoom · Select a person</div>
<div class="fictional">Synthetic movement data · Buenos Aires motif</div>
</div>
<div id="tooltip"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8dfda);
scene.fog = new THREE.Fog(0xd8dfda, 48, 100);
const camera = new THREE.PerspectiveCamera(38, innerWidth / innerHeight, 0.1, 150);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
stage.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xfff7df, 0x829594, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff3d5, 3.2);
sun.position.set(-18, 32, 18);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -34;
sun.shadow.camera.right = 34;
sun.shadow.camera.top = 30;
sun.shadow.camera.bottom = -30;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 90;
sun.shadow.bias = -0.00035;
scene.add(sun);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color, options = {}) {
const key = [
color,
options.opacity ?? 1,
options.transparent ? 1 : 0,
options.metalness ?? 0,
options.roughness ?? 0.84,
options.emissive ?? 0
].join("|");
if (!materialCache.has(key)) {
materialCache.set(key, new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.84,
metalness: options.metalness ?? 0,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 1,
side: options.side ?? THREE.FrontSide,
depthWrite: options.depthWrite ?? true
}));
}
return materialCache.get(key);
}
function box(parent, w, h, d, color, x = 0, y = 0, z = 0, options = {}) {
const mesh = new THREE.Mesh(
unitBox,
options.material || material(color, options)
);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
parent.add(mesh);
return mesh;
}
function makeLabel(text, background = "#f8f4e9", foreground = "#132a30", width = 3) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = "rgba(19,42,48,.18)";
ctx.lineWidth = 8;
ctx.strokeRect(4, 4, canvas.width - 8, canvas.height - 8);
ctx.fillStyle = foreground;
ctx.font = "800 52px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 67);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
}));
sprite.scale.set(width, width / 4, 1);
return sprite;
}
// Ground and checkerboard tiles.
const world = new THREE.Group();
scene.add(world);
const distantGround = new THREE.Mesh(
new THREE.PlaneGeometry(180, 180),
material(0xc9d2ce)
);
distantGround.rotation.x = -Math.PI / 2;
distantGround.position.y = -1.02;
distantGround.receiveShadow = true;
world.add(distantGround);
box(world, 38, 0.9, 26, 0xb7c4bd, 0, -0.48, 0);
const tileGeometry = new THREE.BoxGeometry(1.94, 0.08, 1.94);
const tileA = material(0xe8dfcc);
const tileB = material(0xcbd2c7);
for (let ix = 0; ix < 18; ix++) {
for (let iz = 0; iz < 12; iz++) {
const tile = new THREE.Mesh(tileGeometry, (ix + iz) % 2 ? tileA : tileB);
tile.position.set(-17 + ix * 2, -0.005, -11 + iz * 2);
tile.receiveShadow = true;
world.add(tile);
}
}
// Private architecture is represented only by opaque exterior massing.
const privateGroup = new THREE.Group();
world.add(privateGroup);
function addPrivateBuilding(x, z, w, d, h, color, front = "south", seed = 0) {
box(privateGroup, w, h, d, color, x, h / 2 + 0.08, z);
box(privateGroup, w + 0.28, 0.28, d + 0.28, 0xf0e6ce, x, h + 0.18, z);
const floors = Math.max(1, Math.floor((h - 0.8) / 2.15));
const columns = Math.max(2, Math.floor(w / 1.65));
for (let floor = 0; floor < floors; floor++) {
const wy = 1.55 + floor * 2.12;
for (let col = 0; col < columns; col++) {
const offset = -w / 2 + ((col + 0.5) * w) / columns;
if (front === "south") {
const wx = x + offset;
const frontZ = z + d / 2 + 0.055;
box(privateGroup, 1.03, 1.14, 0.11, 0x203c46, wx, wy, frontZ);
box(privateGroup, 0.17, 1.22, 0.15, 0xf5e9d5, wx - 0.61, wy, frontZ + 0.035);
box(privateGroup, 0.17, 1.22, 0.15, 0xf5e9d5, wx + 0.61, wy, frontZ + 0.035);
if (floor > 0 && (floor + col + seed) % 3 === 0) {
box(privateGroup, 1.65, 0.13, 0.72, 0xf2dfbb, wx, wy - 0.76, frontZ + 0.31);
box(privateGroup, 1.65, 0.10, 0.10, 0x36545a, wx, wy - 0.32, frontZ + 0.61);
box(privateGroup, 0.10, 0.48, 0.10, 0x36545a, wx - 0.77, wy - 0.52, frontZ + 0.61);
box(privateGroup, 0.10, 0.48, 0.10, 0x36545a, wx + 0.77, wy - 0.52, frontZ + 0.61);
box(privateGroup, 0.25, 0.32, 0.25, 0x4a8b61, wx + 0.42, wy - 0.55, frontZ + 0.29);
}
} else {
const wz = z + offset;
const frontX = x + w / 2 + 0.055;
box(privateGroup, 0.11, 1.14, 1.03, 0x203c46, frontX, wy, wz);
box(privateGroup, 0.15, 1.22, 0.17, 0xf5e9d5, frontX + 0.035, wy, wz - 0.61);
box(privateGroup, 0.15, 1.22, 0.17, 0xf5e9d5, frontX + 0.035, wy, wz + 0.61);
if (floor > 0 && (floor + col + seed) % 3 === 0) {
box(privateGroup, 0.72, 0.13, 1.65, 0xf2dfbb, frontX + 0.31, wy - 0.76, wz);
box(privateGroup, 0.10, 0.10, 1.65, 0x36545a, frontX + 0.61, wy - 0.32, wz);
}
}
}
}
// Masked door mosaic: no occupant or dwelling information is exposed.
if (front === "south") {
const doorZ = z + d / 2 + 0.08;
box(privateGroup, 1.18, 1.75, 0.12, 0x19323b, x, 0.95, doorZ);
box(privateGroup, 1.42, 0.12, 0.42, 0xe7d8b9, x, 0.09, doorZ + 0.16);
const pixels = ["#36b99f", "#f2dfb8", "#294d55", "#e76d58"];
for (let i = 0; i < 9; i++) {
const px = x - 0.39 + (i % 3) * 0.39;
const py = 0.58 + Math.floor(i / 3) * 0.38;
box(privateGroup, 0.31, 0.31, 0.08, pixels[i % pixels.length], px, py, doorZ + 0.09);
}
} else {
const doorX = x + w / 2 + 0.08;
box(privateGroup, 0.12, 1.75, 1.18, 0x19323b, doorX, 0.95, z);
box(privateGroup, 0.42, 0.12, 1.42, 0xe7d8b9, doorX + 0.16, 0.09, z);
const pixels = ["#36b99f", "#f2dfb8", "#294d55", "#e76d58"];
for (let i = 0; i < 9; i++) {
const pz = z - 0.39 + (i % 3) * 0.39;
const py = 0.58 + Math.floor(i / 3) * 0.38;
box(privateGroup, 0.08, 0.31, 0.31, pixels[i % pixels.length], doorX + 0.09, py, pz);
}
}
}
addPrivateBuilding(-14, -10.5, 6, 4, 7.5, 0xd95b4b, "south", 0);
addPrivateBuilding(-7, -10.5, 6, 4, 6.2, 0xe2b845, "south", 1);
addPrivateBuilding(0, -10.5, 6, 4, 8.5, 0x427fa8, "south", 2);
addPrivateBuilding(7, -10.5, 6, 4, 7.0, 0x3d998d, "south", 1);
addPrivateBuilding(14, -10.5, 6, 4, 6.3, 0xde7956, "south", 0);
addPrivateBuilding(-16.8, -4.5, 4, 6, 7.2, 0x4e8da6, "east", 2);
addPrivateBuilding(-16.8, 3, 4, 6, 6.4, 0xd88b45, "east", 0);
addPrivateBuilding(-16.8, 9.2, 4, 5.6, 8.0, 0x687caf, "east", 1);
// Low street walls and the public gate.
box(world, 24, 1.15, 0.55, 0xd8b875, -4, 0.52, 11.75);
box(world, 3.4, 1.15, 0.55, 0xd8b875, 16.3, 0.52, 11.75);
box(world, 0.55, 1.15, 18.8, 0xd8b875, 17.75, 0.52, 0.5);
box(world, 0.55, 1.15, 5.0, 0xd8b875, 17.75, 0.52, 9.5);
box(world, 0.65, 3.1, 0.65, 0x315b61, 11.3, 1.5, 11.75);
box(world, 0.65, 3.1, 0.65, 0x315b61, 14.7, 1.5, 11.75);
box(world, 4.1, 0.45, 0.65, 0x315b61, 13, 2.85, 11.75);
const gateLabel = makeLabel("CAMINITO", "#f7edcf", "#24464b", 3.8);
gateLabel.position.set(13, 2.85, 11.95);
world.add(gateLabel);
// Fountain.
const fountain = new THREE.Group();
fountain.position.set(0, 0, 0);
world.add(fountain);
box(fountain, 5.2, 0.55, 5.2, 0xd6c6a4, 0, 0.30, 0);
box(fountain, 4.4, 0.48, 4.4, 0x5aa9b2, 0, 0.66, 0);
box(fountain, 3.5, 0.12, 3.5, 0x79c6cc, 0, 0.96, 0, {
transparent: true,
opacity: 0.84,
roughness: 0.28
});
box(fountain, 1.15, 1.35, 1.15, 0xe3d6b9, 0, 1.5, 0);
box(fountain, 1.65, 0.25, 1.65, 0xf1e5c9, 0, 2.18, 0);
box(fountain, 0.32, 1.0, 0.32, 0xa9e1dc, 0, 2.72, 0, {
transparent: true,
opacity: 0.85
});
// Neighborhood café.
const cafe = new THREE.Group();
cafe.position.set(-8, 0, 5);
world.add(cafe);
box(cafe, 4.3, 2.45, 3.0, 0xe06d57, 0, 1.25, 0);
box(cafe, 4.65, 0.25, 3.3, 0xf3dfb6, 0, 2.58, 0);
box(cafe, 3.8, 0.18, 0.7, 0x31565a, 0, 1.02, 1.57);
for (let i = 0; i < 6; i++) {
box(cafe, 0.76, 0.16, 1.25, i % 2 ? 0xf8edcf : 0xe76e59,
-1.9 + i * 0.76, 2.35, 1.72);
}
box(cafe, 4.7, 0.30, 0.24, 0xe06d57, 0, 2.15, 2.25);
const cafeLabel = makeLabel("CAFÉ", "#f5e8c8", "#9d483a", 2.1);
cafeLabel.position.set(-8, 3.15, 5.2);
world.add(cafeLabel);
// Voxel mural inspired by neighborhood color and football imagery.
const mural = new THREE.Group();
mural.position.set(10, 0, -7.25);
world.add(mural);
box(mural, 6.3, 3.6, 0.48, 0xe9ddc2, 0, 1.8, 0);
box(mural, 0.95, 0.95, 0.13, 0xeebc45, 1.45, 2.5, 0.29);
box(mural, 0.52, 0.52, 0.13, 0xef765d, -1.55, 2.35, 0.29);
box(mural, 0.72, 0.72, 0.13, 0x3ca998, -2.1, 1.2, 0.29);
box(mural, 0.56, 0.56, 0.13, 0x4b87b1, 0.1, 1.0, 0.29);
for (let i = 0; i < 8; i++) {
box(mural, 0.56, 0.22, 0.13, i % 2 ? 0x3a7f9d : 0x4ba995,
-2.2 + i * 0.62, 0.6 + Math.sin(i * 0.8) * 0.25, 0.29);
}
const muralLabel = makeLabel("LA BOCA", "#315b61", "#f8edcf", 3.25);
muralLabel.position.set(10, 4.05, -7.25);
world.add(muralLabel);
// Communal parcel lockers: deliveries do not enter private buildings.
const lockers = new THREE.Group();
lockers.position.set(16, 0, 5.2);
world.add(lockers);
box(lockers, 1.2, 2.0, 4.3, 0x476d70, 0, 1.0, 0);
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 3; col++) {
box(lockers, 0.12, 0.74, 1.12,
(row + col) % 2 ? 0xe4b94e : 0xe3715c,
-0.66, 0.56 + row * 0.87, -1.35 + col * 1.35);
}
}
const lockerLabel = makeLabel("PARCELAS", "#f5e8c8", "#315b61", 2.8);
lockerLabel.position.set(16, 2.6, 5.2);
world.add(lockerLabel);
// Trees, planters, benches, and lamps.
function addTree(x, z, scale = 1) {
const g = new THREE.Group();
g.position.set(x, 0, z);
g.scale.setScalar(scale);
world.add(g);
box(g, 0.38, 2.4, 0.38, 0x76573f, 0, 1.2, 0);
box(g, 2.2, 1.35, 2.0, 0x4b9161, 0, 3.0, 0);
box(g, 1.55, 1.1, 1.55, 0x5ca66b, -0.35, 3.9, 0.15);
box(g, 1.3, 0.95, 1.3, 0x397e55, 0.65, 3.65, -0.15);
box(g, 1.35, 0.85, 1.35, 0x70b671, 0.1, 4.55, 0.05);
box(g, 1.8, 0.35, 1.8, 0x8b7959, 0, 0.12, 0);
}
addTree(-13.2, 8.2, 0.86);
addTree(12.3, -0.9, 0.80);
addTree(3.6, -7.0, 0.72);
addTree(-13.2, -1.0, 0.72);
function addBench(x, z, rotation = 0) {
const g = new THREE.Group();
g.position.set(x, 0, z);
g.rotation.y = rotation;
world.add(g);
box(g, 2.4, 0.18, 0.65, 0x8d6047, 0, 0.62, 0);
box(g, 2.4, 0.65, 0.14, 0x8d6047, 0, 1.0, -0.31);
box(g, 0.16, 0.58, 0.48, 0x36585b, -0.84, 0.3, 0);
box(g, 0.16, 0.58, 0.48, 0x36585b, 0.84, 0.3, 0);
}
addBench(-10.5, 1.1, Math.PI / 2);
addBench(6.0, 8.3, 0);
addBench(8.0, -3.7, Math.PI / 2);
function addLamp(x, z) {
box(world, 0.16, 3.5, 0.16, 0x35575b, x, 1.75, z);
box(world, 0.62, 0.2, 0.62, 0xf1d99d, x, 3.45, z);
box(world, 0.38, 0.5, 0.38, 0xffedb8, x, 3.18, z, {
emissive: 0xffc65c,
emissiveIntensity: 0.45
});
}
addLamp(-15.1, 10.2);
addLamp(15.7, 8.8);
addLamp(-14.4, -7.8);
// A small voxel football on the plaza.
const ball = new THREE.Group();
ball.position.set(4.2, 0.35, 2.4);
ball.rotation.y = 0.5;
world.add(ball);
box(ball, 0.65, 0.65, 0.65, 0xf5f0df, 0, 0, 0);
box(ball, 0.22, 0.22, 0.68, 0x2d4146, 0, 0, 0);
box(ball, 0.68, 0.22, 0.22, 0x2d4146, 0, 0, 0);
// Soft ambient dust motes.
const dustPositions = new Float32Array(120 * 3);
for (let i = 0; i < 120; i++) {
dustPositions[i * 3] = (Math.random() - 0.5) * 40;
dustPositions[i * 3 + 1] = 1 + Math.random() * 12;
dustPositions[i * 3 + 2] = (Math.random() - 0.5) * 30;
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute("position", new THREE.BufferAttribute(dustPositions, 3));
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xfff3cf,
size: 0.065,
transparent: true,
opacity: 0.45,
depthWrite: false
})
);
scene.add(dust);
// Route construction and movement definitions.
const ROLES = {
resident: { label: "Resident", color: 0x31bfa5, css: "#31bfa5" },
visitor: { label: "Visitor", color: 0xeab84f, css: "#eab84f" },
delivery: { label: "Delivery", color: 0xed715d, css: "#ed715d" }
};
function buildRoute(coords) {
const points = coords.map(([x, z]) => new THREE.Vector3(x, 0, z));
const segments = [];
let total = 0;
for (let i = 0; i < points.length - 1; i++) {
const start = points[i];
const end = points[i + 1];
const length = start.distanceTo(end);
segments.push({ start, end, length, startDistance: total });
total += length;
}
return {
points,
segments,
total,
sample(distance, position, tangent) {
const d = ((distance % total) + total) % total;
let segment = segments[segments.length - 1];
for (const candidate of segments) {
if (d <= candidate.startDistance + candidate.length) {
segment = candidate;
break;
}
}
const local = segment.length > 0
? THREE.MathUtils.clamp((d - segment.startDistance) / segment.length, 0, 1)
: 0;
position.lerpVectors(segment.start, segment.end, local);
tangent.subVectors(segment.end, segment.start).normalize();
return segments.indexOf(segment);
}
};
}
const actorDefinitions = [
{
id: "sofia",
role: "resident",
name: "Sofía",
from: "Masked dwelling threshold",
to: "Neighborhood café",
speed: 1.65,
offset: 0.05,
skin: 0xc98763,
points: [
[-7, -8.25], [-5, -6], [-3.8, -3.6], [3.8, -3.6],
[6, 0], [5, 5], [1, 7], [-4.5, 6], [-7, -8.25]
],
labels: [
"Leaving a masked dwelling threshold",
"Crossing the public plaza",
"Passing the fountain",
"Approaching the café",
"Returning through the courtyard",
"Heading back to a masked home"
]
},
{
id: "mateo",
role: "resident",
name: "Mateo",
from: "Masked dwelling threshold",
to: "Mural court",
speed: 1.55,
offset: 0.39,
skin: 0x9c6448,
points: [
[-14.55, -4.5], [-11, -4], [-10, 0], [-7, 3], [0, 4],
[7, 1], [9, -4], [4, -6], [-7, -8.25], [-14.55, -4.5]
],
labels: [
"At a masked dwelling threshold",
"Walking along the west edge",
"Crossing between neighbors",
"Passing the central fountain",
"Moving toward the mural court",
"Returning by a different public path"
]
},
{
id: "valentina",
role: "resident",
name: "Valentina",
from: "Masked dwelling threshold",
to: "Courtyard garden",
speed: 1.72,
offset: 0.71,
skin: 0xe0ad83,
points: [
[2, -8.25], [4, -6], [8, -4], [11, 0], [9, 5],
[3, 7], [-3, 5], [-4, -2], [2, -8.25]
],
labels: [
"Leaving a masked dwelling threshold",
"Walking toward the east garden",
"Following the fountain path",
"Looping through the public garden",
"Returning toward home"
]
},
{
id: "mia",
role: "visitor",
name: "Mía",
from: "Public street gate",
to: "Neighborhood mural",
speed: 1.95,
offset: 0.18,
skin: 0xb87854,
points: [
[13, 10.2], [9, 8], [6, 4], [7, 0], [8, -4],
[10, -5.2], [13, -3], [16, 2], [13, 10.2]
],
labels: [
"Entering through the public gate",
"Walking around the central fountain",
"Following the mural route",
"Viewing the neighborhood artwork",
"Returning toward the public gate"
]
},
{
id: "tomas",
role: "visitor",
name: "Tomás",
from: "Public street gate",
to: "Café terrace",
speed: 1.72,
offset: 0.63,
skin: 0xd59b74,
points: [
[15, 10.2], [8, 8], [0, 8], [-5, 7], [-8, 7.4],
[-10, 4], [-6, 2], [0, 7], [15, 10.2]
],
labels: [
"Entering through the public gate",
"Approaching the café terrace",
"Waiting near the café",
"Taking a short courtyard loop",
"Returning to the public gate"
]
},
{
id: "verduleria",
role: "delivery",
name: "Verdulería",
from: "Public street gate",
to: "Café service point",
speed: 2.15,
offset: 0.33,
skin: 0x9d6749,
points: [
[14, 10.2], [8, 8.8], [0, 8.2], [-5, 8], [-8, 7.4],
[-9, 9], [4, 10], [14, 10.2]
],
labels: [
"Arriving at the public gate",
"Carrying goods through the courtyard",
"Approaching the café service point",
"Making the delivery at a public counter",
"Returning through the public courtyard"
]
},
{
id: "mercado",
role: "delivery",
name: "Mercado Sur",
from: "Public street gate",
to: "Communal parcel lockers",
speed: 2.4,
offset: 0.82,
skin: 0xb97850,
points: [
[15, 10.2], [14.5, 7], [14.5, 5.2], [15, 8], [15, 10.2]
],
labels: [
"Arriving at the public gate",
"Carrying a parcel to communal lockers",
"Depositing the parcel at a public service point",
"Returning to the street gate"
]
}
];
const actors = [];
const hitMeshes = [];
const routeGroup = new THREE.Group();
const peopleGroup = new THREE.Group();
scene.add(routeGroup, peopleGroup);
const MAX_TRAIL_POINTS = 100;
function createTrail(actor) {
const positions = new Float32Array(MAX_TRAIL_POINTS * 2 * 3);
const colors = new Float32Array(MAX_TRAIL_POINTS * 2 * 3);
const indices = new Uint16Array((MAX_TRAIL_POINTS - 1) * 6);
for (let i = 0; i < MAX_TRAIL_POINTS - 1; i++) {
const a = i * 2;
indices.set([a, a + 1, a + 2, a + 1, a + 3, a + 2], i * 6);
}
const geometry = new THREE.BufferGeometry();
const positionAttribute = new THREE.BufferAttribute(positions, 3);
const colorAttribute = new THREE.BufferAttribute(colors, 3);
positionAttribute.setUsage(THREE.DynamicDrawUsage);
colorAttribute.setUsage(THREE.DynamicDrawUsage);
geometry.setAttribute("position", positionAttribute);
geometry.setAttribute("color", colorAttribute);
geometry.setIndex(new THREE.BufferAttribute(indices, 1));
geometry.setDrawRange(0, 0);
const mesh = new THREE.Mesh(
geometry,
new THREE.MeshBasicMaterial({
vertexColors: true,
transparent: true,
opacity: 0.86,
depthWrite: false,
side: THREE.DoubleSide
})
);
mesh.frustumCulled = false;
mesh.renderOrder = 3;
routeGroup.add(mesh);
actor.trail = mesh;
actor.trailPoints = [];
actor.trailGeometry = geometry;
}
function createPerson(actor) {
const group = new THREE.Group();
const model = new THREE.Group();
group.add(model);
peopleGroup.add(group);
const roleColor = ROLES[actor.role].color;
const shadow = new THREE.Mesh(
new THREE.CircleGeometry(0.48, 20),
new THREE.MeshBasicMaterial({
color: 0x253f43,
transparent: true,
opacity: 0.18,
depthWrite: false
})
);
shadow.rotation.x = -Math.PI / 2;
shadow.position.y = 0.105;
group.add(shadow);
const body = box(model, 0.58, 0.72, 0.40, roleColor, 0, 1.05, 0);
const head = box(model, 0.43, 0.43, 0.42, actor.skin, 0, 1.63, 0);
const hair = box(model, 0.46, 0.12, 0.45, 0x47372f, 0, 1.83, -0.01);
box(model, 0.07, 0.07, 0.04, 0x23383e, -0.11, 1.66, 0.225);
box(model, 0.07, 0.07, 0.04, 0x23383e, 0.11, 1.66, 0.225);
const leftLeg = box(model, 0.20, 0.58, 0.23, 0x2c4954, -0.16, 0.43, 0);
const rightLeg = box(model, 0.20, 0.58, 0.23, 0x2c4954, 0.16, 0.43, 0);
const leftArm = box(model, 0.16, 0.58, 0.18, roleColor, -0.38, 1.02, 0);
const rightArm = box(model, 0.16, 0.58, 0.18, roleColor, 0.38, 1.02, 0);
box(model, 0.30, 0.09, 0.42, 0x20383e, -0.16, 0.12, 0.04);
box(model, 0.30, 0.09, 0.42, 0x20383e, 0.16, 0.12, 0.04);
if (actor.role === "visitor") {
box(model, 0.43, 0.53, 0.22, 0xe1b64d, 0, 1.10, -0.29);
box(model, 0.48, 0.12, 0.46, 0xf3dfb4, 0, 1.88, 0);
}
if (actor.role === "delivery") {
box(model, 0.63, 0.48, 0.47, 0xc88945, 0, 1.07, 0.43);
box(model, 0.12, 0.50, 0.49, 0xf2d59c, 0, 1.07, 0.43);
}
const ring = new THREE.Mesh(
new THREE.RingGeometry(0.52, 0.66, 28),
new THREE.MeshBasicMaterial({
color: roleColor,
transparent: true,
opacity: 0.28,
depthWrite: false,
side: THREE.DoubleSide
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.y = 0.12;
ring.renderOrder = 4;
group.add(ring);
const hit = new THREE.Mesh(
new THREE.SphereGeometry(0.72, 12, 10),
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false,
colorWrite: false
})
);
hit.position.y = 1.05;
hit.userData.actor = actor;
group.add(hit);
hitMeshes.push(hit);
actor.group = group;
actor.model = model;
actor.body = body;
actor.head = head;
actor.hair = hair;
actor.leftLeg = leftLeg;
actor.rightLeg = rightLeg;
actor.leftArm = leftArm;
actor.rightArm = rightArm;
actor.ring = ring;
}
for (const definition of actorDefinitions) {
const actor = {
...definition,
route: buildRoute(definition.points),
travel: 0,
progress: 0,
currentLabel: definition.labels[0]
};
const routePoints = actor.route.points.map(p => new THREE.Vector3(p.x, 0.16, p.z));
const routeGeometry = new THREE.BufferGeometry().setFromPoints(routePoints);
const routeLine = new THREE.Line(
routeGeometry,
new THREE.LineDashedMaterial({
color: ROLES[actor.role].color,
transparent: true,
opacity: 0.23,
dashSize: 0.34,
gapSize: 0.28,
depthWrite: false
})
);
routeLine.computeLineDistances();
routeLine.renderOrder = 2;
routeGroup.add(routeLine);
actor.routeLine = routeLine;
createPerson(actor);
createTrail(actor);
actors.push(actor);
}
// Application state.
const visibleRoles = new Set(["resident", "visitor", "delivery"]);
let tracesVisible = true;
let playing = true;
let playbackSpeed = 1;
let simulationTime = 18;
let selectedActor = actors[0];
let followingActor = null;
let lastSelectedUpdate = 0;
const tooltip = document.getElementById("tooltip");
const timeline = document.getElementById("timeline");
const clock = document.getElementById("clock");
const playButton = document.getElementById("playButton");
const traceToggle = document.getElementById("traceToggle");
const followButton = document.getElementById("followButton");
const roleButtons = [...document.querySelectorAll(".role-button")];
function updateVisibility() {
for (const actor of actors) {
const visible = visibleRoles.has(actor.role);
actor.group.visible = visible;
actor.routeLine.visible = visible && tracesVisible;
actor.trail.visible = visible && tracesVisible;
}
for (const button of roleButtons) {
const active = visibleRoles.has(button.dataset.role);
button.classList.toggle("off", !active);
button.setAttribute("aria-pressed", String(active));
}
followButton.disabled = !selectedActor || !selectedActor.group.visible;
}
function updateTrail(actor) {
if (!tracesVisible || !actor.group.visible) return;
if (actor.lastTravel !== null && actor.travel < actor.lastTravel - actor.route.total * 0.5) {
actor.trailPoints.length = 0;
}
if (
actor.trailPoints.length === 0 ||
actor.lastTravel === null ||
Math.abs(actor.travel - actor.lastTravel) > 0.20
) {
const point = new THREE.Vector3();
const tangent = new THREE.Vector3();
actor.route.sample(actor.travel, point, tangent);
point.y = 0.19;
actor.trailPoints.push(point);
if (actor.trailPoints.length > MAX_TRAIL_POINTS) {
actor.trailPoints.shift();
}
}
actor.lastTravel = actor.travel;
const points = actor.trailPoints;
const count = points.length;
const positionArray = actor.trailGeometry.attributes.position.array;
const colorArray = actor.trailGeometry.attributes.color.array;
const roleColor = new THREE.Color(ROLES[actor.role].color);
const background = new THREE.Color(0xd8dfda);
for (let i = 0; i < count; i++) {
const previous = points[Math.max(0, i - 1)];
const next = points[Math.min(count - 1, i + 1)];
const tx = next.x - previous.x;
const tz = next.z - previous.z;
const length = Math.hypot(tx, tz) || 1;
const nx = -tz / length * 0.105;
const nz = tx / length * 0.105;
const point = points[i];
const offset = i * 6;
positionArray[offset] = point.x + nx;
positionArray[offset + 1] = 0.19;
positionArray[offset + 2] = point.z + nz;
positionArray[offset + 3] = point.x - nx;
positionArray[offset + 4] = 0.19;
positionArray[offset + 5] = point.z - nz;
const strength = count <= 1 ? 1 : Math.pow(i / (count - 1), 0.72);
const color = background.clone().lerp(roleColor, strength);
colorArray[offset] = color.r;
colorArray[offset + 1] = color.g;
colorArray[offset + 2] = color.b;
colorArray[offset + 3] = color.r;
colorArray[offset + 4] = color.g;
colorArray[offset + 5] = color.b;
}
actor.trailGeometry.attributes.position.needsUpdate = true;
actor.trailGeometry.attributes.color.needsUpdate = true;
actor.trailGeometry.setDrawRange(0, Math.max(0, count - 1) * 6);
}
function clearTrails() {
for (const actor of actors) {
actor.trailPoints.length = 0;
actor.lastTravel = null;
actor.trailGeometry.setDrawRange(0, 0);
}
}
function selectActor(actor) {
selectedActor = actor;
if (!actor) return;
document.getElementById("selectedCard").style.setProperty(
"--actor-color",
ROLES[actor.role].css
);
document.getElementById("actorRole").textContent = ROLES[actor.role].label;
document.getElementById("actorName").textContent = actor.name;
document.getElementById("actorRoute").textContent = `${actor.from} → ${actor.to}`;
for (const other of actors) {
other.ring.material.opacity = other === actor ? 0.9 : 0.25;
other.ring.scale.setScalar(other === actor ? 1.18 : 1);
}
followButton.disabled = !actor.group.visible;
updateSelectedCard();
}
function updateSelectedCard() {
if (!selectedActor) return;
const actor = selectedActor;
document.getElementById("actorActivity").textContent = actor.currentLabel;
document.getElementById("actorLocation").textContent =
actor.group.visible ? "Public courtyard" : "Currently filtered from view";
document.getElementById("actorProgress").style.width = `${actor.progress * 100}%`;
}
roleButtons.forEach(button => {
button.addEventListener("click", () => {
const role = button.dataset.role;
if (visibleRoles.has(role)) visibleRoles.delete(role);
else visibleRoles.add(role);
updateVisibility();
});
});
document.getElementById("showAll").addEventListener("click", () => {
["resident", "visitor", "delivery"].forEach(role => visibleRoles.add(role));
updateVisibility();
});
traceToggle.addEventListener("click", () => {
tracesVisible = !tracesVisible;
traceToggle.classList.toggle("on", tracesVisible);
traceToggle.setAttribute("aria-pressed", String(tracesVisible));
updateVisibility();
});
playButton.addEventListener("click", () => {
playing = !playing;
playButton.textContent = playing ? "Ⅱ" : "▶";
playButton.setAttribute("aria-label", playing ? "Pause simulation" : "Play simulation");
});
document.querySelectorAll(".speed").forEach(button => {
button.addEventListener("click", () => {
playbackSpeed = Number(button.dataset.speed);
document.querySelectorAll(".speed").forEach(speedButton => {
speedButton.classList.toggle("active", speedButton === button);
});
});
});
timeline.addEventListener("input", () => {
simulationTime = Number(timeline.value);
clearTrails();
});
// Custom orbit / pan / zoom controls implemented without addons.
const cameraState = {
target: new THREE.Vector3(0, 1.0, 0),
radius: 49,
theta: 0.72,
phi: 0.72
};
const followOffset = new THREE.Vector3();
function overview() {
followingActor = null;
cameraState.target.set(0, 1.0, 0);
cameraState.radius = 49;
cameraState.theta = 0.72;
cameraState.phi = 0.72;
followButton.textContent = "Follow this trace";
}
followButton.addEventListener("click", () => {
if (!selectedActor || !selectedActor.group.visible) return;
if (followingActor === selectedActor) {
followingActor = null;
followButton.textContent = "Follow this trace";
} else {
followingActor = selectedActor;
followOffset.copy(cameraState.target).sub(selectedActor.group.position);
followButton.textContent = "Following selected trace";
}
});
document.getElementById("overviewButton").addEventListener("click", overview);
document.getElementById("zoomIn").addEventListener("click", () => {
cameraState.radius = Math.max(25, cameraState.radius * 0.86);
});
document.getElementById("zoomOut").addEventListener("click", () => {
cameraState.radius = Math.min(82, cameraState.radius * 1.16);
});
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
const canvas = renderer.domElement;
let pointerDown = false;
let pointerButton = 0;
let pointerStartX = 0;
let pointerStartY = 0;
let lastPointerX = 0;
let lastPointerY = 0;
let pointerTravel = 0;
function setPointer(event) {
pointer.x = event.clientX / innerWidth * 2 - 1;
pointer.y = -(event.clientY / innerHeight) * 2 + 1;
}
function actorUnderPointer(event) {
setPointer(event);
raycaster.setFromCamera(pointer, camera);
const availableHits = hitMeshes.filter(mesh => mesh.userData.actor.group.visible);
const hits = raycaster.intersectObjects(availableHits, false);
return hits.length ? hits[0].object.userData.actor : null;
}
canvas.addEventListener("pointerdown", event => {
pointerDown = true;
pointerButton = event.button;
pointerStartX = event.clientX;
pointerStartY = event.clientY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
pointerTravel = 0;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
tooltip.style.display = "none";
});
canvas.addEventListener("pointermove", event => {
if (pointerDown) {
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
pointerTravel += Math.abs(dx) + Math.abs(dy);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
if (pointerButton === 2 || event.shiftKey) {
camera.updateMatrixWorld();
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrixWorld, 0);
const screenUp = new THREE.Vector3().crossVectors(right, forward).normalize();
const scale = cameraState.radius * 0.00125;
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(screenUp, dy * scale);
followingActor = null;
followButton.textContent = "Follow this trace";
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(cameraState.phi - dy * 0.005, 0.34, 1.28);
}
return;
}
const actor = actorUnderPointer(event);
if (actor) {
tooltip.style.display = "block";
tooltip.style.left = `${Math.min(innerWidth - 190, event.clientX + 14)}px`;
tooltip.style.top = `${Math.min(innerHeight - 70, event.clientY + 14)}px`;
tooltip.innerHTML = `<strong>${actor.name}</strong><span>${ROLES[actor.role].label} · click to inspect</span>`;
canvas.style.cursor = "pointer";
} else {
tooltip.style.display = "none";
canvas.style.cursor = "grab";
}
});
canvas.addEventListener("pointerup", event => {
canvas.releasePointerCapture(event.pointerId);
pointerDown = false;
const dragDistance = Math.hypot(
event.clientX - pointerStartX,
event.clientY - pointerStartY
);
if (dragDistance < 6 && pointerTravel < 10) {
const actor = actorUnderPointer(event);
if (actor) selectActor(actor);
}
canvas.style.cursor = "grab";
});
canvas.addEventListener("pointercancel", () => {
pointerDown = false;
canvas.style.cursor = "grab";
});
canvas.addEventListener("pointerleave", () => {
if (!pointerDown) tooltip.style.display = "none";
});
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
25,
82
);
}, { passive: false });
function updateCamera() {
if (followingActor && followingActor.group.visible) {
const desired = followingActor.group.position.clone().add(followOffset);
desired.y = 1;
cameraState.target.lerp(desired, 0.075);
}
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z + cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
const samplePosition = new THREE.Vector3();
const sampleTangent = new THREE.Vector3();
function updateActors() {
for (const actor of actors) {
actor.travel = (
simulationTime * actor.speed +
actor.offset * actor.route.total
) % actor.route.total;
actor.progress = actor.travel / actor.route.total;
const segmentIndex = actor.route.sample(
actor.travel,
samplePosition,
sampleTangent
);
actor.group.position.set(samplePosition.x, 0, samplePosition.z);
actor.group.rotation.y = Math.atan2(sampleTangent.x, sampleTangent.z);
const walking = playing ? Math.sin(simulationTime * 8 + actor.offset * 20) : 0;
actor.leftLeg.rotation.x = walking * 0.34;
actor.rightLeg.rotation.x = -walking * 0.34;
actor.leftArm.rotation.x = -walking * 0.22;
actor.rightArm.rotation.x = walking * 0.22;
actor.model.position.y = Math.abs(walking) * 0.025;
actor.currentLabel = actor.labels[Math.min(segmentIndex, actor.labels.length - 1)];
updateTrail(actor);
}
}
function updateClock() {
const minutes = Math.floor(simulationTime / 60).toString().padStart(2, "0");
const seconds = Math.floor(simulationTime % 60).toString().padStart(2, "0");
clock.textContent = `${minutes}:${seconds}`;
if (document.activeElement !== timeline) {
timeline.value = simulationTime % 120;
}
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
addEventListener("resize", resize);
updateVisibility();
selectActor(actors[0]);
updateActors();
updateCamera();
updateClock();
loading.remove();
let previousTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (playing) simulationTime += delta * playbackSpeed;
updateActors();
updateCamera();
updateClock();
dust.rotation.y = now * 0.000018;
dust.position.y = Math.sin(now * 0.00022) * 0.12;
if (now - lastSelectedUpdate > 90) {
updateSelectedCard();
lastSelectedUpdate = now;
}
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```