Prompt specification
Build or customize the Three.js 3D scene "Public Sculpture With Pedestrian Paths" 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: Public Sculpture With Pedestrian Paths
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/public-sculpture-with-pedestrian-paths-x3347
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: public sculpture with pedestrian paths. Build a small plaza around a perforated geometric sculpture. Let people pass through designed openings while preserving actual collision clearance and sight lines.
Working Three.js Starter (public-sculpture-with-pedestrian-paths-x3347):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Common Ground — Voxel Civic Plaza</title>
<style>
:root {
color-scheme: light;
--ink: #193b38;
--muted: #5e716c;
--paper: rgba(250, 248, 239, 0.9);
--line: rgba(25, 59, 56, 0.15);
--accent: #2f756c;
--warm: #d96f4b;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cfd9d4;
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;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--line);
background: var(--paper);
box-shadow: 0 12px 35px rgba(33, 57, 52, 0.12);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
.brand {
top: 22px;
left: 22px;
width: min(350px, calc(100vw - 44px));
padding: 18px 20px 16px;
border-radius: 16px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--warm);
content: "";
box-shadow: 13px 0 0 rgba(217, 111, 75, 0.35);
margin-right: 13px;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 34px);
line-height: 1;
letter-spacing: -0.045em;
}
.subtitle {
max-width: 290px;
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.metrics {
top: 22px;
right: 22px;
width: 225px;
padding: 16px;
border-radius: 16px;
}
.metrics-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 11px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.live {
display: inline-flex;
align-items: center;
gap: 6px;
color: var(--accent);
font-size: 9px;
letter-spacing: 0.08em;
}
.live::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: #4d9c73;
box-shadow: 0 0 0 4px rgba(77, 156, 115, 0.13);
content: "";
animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
50% { opacity: 0.45; }
}
.metric {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
padding: 9px 0;
border-top: 1px solid var(--line);
}
.metric span {
color: var(--muted);
font-size: 11px;
}
.metric strong {
font-size: 14px;
font-variant-numeric: tabular-nums;
}
.metric strong.good {
color: var(--accent);
}
.controls {
bottom: 22px;
left: 22px;
display: flex;
gap: 7px;
padding: 7px;
border-radius: 13px;
}
button {
border: 0;
border-radius: 9px;
padding: 10px 13px;
background: transparent;
color: var(--ink);
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 700;
transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}
button:hover {
background: rgba(47, 117, 108, 0.1);
}
button:active {
transform: translateY(1px);
}
button.active {
background: var(--ink);
color: #fffdf4;
}
.hint {
position: fixed;
z-index: 9;
right: 24px;
bottom: 23px;
color: rgba(25, 59, 56, 0.72);
font-size: 10px;
letter-spacing: 0.03em;
pointer-events: none;
}
.legend {
position: fixed;
z-index: 8;
left: 50%;
bottom: 25px;
display: flex;
gap: 14px;
transform: translateX(-50%);
color: rgba(25, 59, 56, 0.78);
font-size: 10px;
pointer-events: none;
}
.legend span {
display: flex;
align-items: center;
gap: 6px;
white-space: nowrap;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 2px;
background: #91b7ae;
box-shadow: inset 0 0 0 1px rgba(25, 59, 56, 0.12);
}
.swatch.coral {
background: var(--warm);
}
.swatch.green {
background: #63a47a;
}
@media (max-width: 760px) {
.brand {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.subtitle {
max-width: none;
}
.metrics {
top: auto;
right: 12px;
bottom: 76px;
width: 190px;
padding: 12px;
}
.metrics-title {
margin-bottom: 5px;
}
.metric {
padding: 6px 0;
}
.controls {
bottom: 12px;
left: 12px;
}
button {
padding: 9px 10px;
font-size: 10px;
}
.hint, .legend {
display: none;
}
}
</style>
</head>
<body>
<header class="panel brand">
<div class="eyebrow">Civic space study</div>
<h1>Common Ground</h1>
<p class="subtitle">
A voxel sculpture organized around two walkable passages. The routes pass
through actual empty space while keeping views open across the plaza.
</p>
</header>
<aside class="panel metrics" aria-live="polite">
<div class="metrics-title">
Clearance check
<span class="live">Live</span>
</div>
<div class="metric">
<span>Clear width</span>
<strong id="widthMetric">2.40 m</strong>
</div>
<div class="metric">
<span>Headroom</span>
<strong id="heightMetric">4.00 m</strong>
</div>
<div class="metric">
<span>Sight lines</span>
<strong id="sightMetric" class="good">Clear</strong>
</div>
<div class="metric">
<span>Pedestrians</span>
<strong id="walkerMetric">5 moving</strong>
</div>
</aside>
<nav class="panel controls" aria-label="Scene controls">
<button class="active" data-view="overview">Overview</button>
<button data-view="plan">Plan</button>
<button id="clearanceButton" class="active">Clearance</button>
</nav>
<div class="legend">
<span><i class="swatch"></i> pedestrian route</span>
<span><i class="swatch coral"></i> sculpture</span>
<span><i class="swatch green"></i> planting</span>
</div>
<div class="hint">
Drag to orbit · Wheel to zoom · Right-drag to pan · 1 / 2 / 3 for views
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, camera
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcfd9d4);
scene.fog = new THREE.Fog(0xcfd9d4, 30, 68);
const renderer = new THREE.WebGLRenderer({ antialias: true });
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;
renderer.domElement.id = "plaza-canvas";
document.body.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xfff9df, 0x667a72, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff2d8, 3.1);
sun.position.set(-12, 19, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -22;
sun.shadow.camera.right = 22;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -22;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
const obstacles = [];
function getMaterial(color, roughness = 0.82, metalness = 0) {
const key = `${color}_${roughness}_${metalness}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({ color, roughness, metalness })
);
}
return materialCache.get(key);
}
function addBox(
parent,
width,
height,
depth,
color,
x = 0,
y = 0,
z = 0,
options = {}
) {
let material;
if (options.emissive) {
material = new THREE.MeshStandardMaterial({
color,
roughness: 0.45,
emissive: options.emissive,
emissiveIntensity: options.emissiveIntensity ?? 1
});
} else {
material = getMaterial(color, options.roughness, options.metalness);
}
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = options.cast !== false;
mesh.receiveShadow = options.receive !== false;
parent.add(mesh);
return mesh;
}
function addCollider(
minX, maxX, minZ, maxZ, minY, maxY, label = "obstacle"
) {
obstacles.push({ minX, maxX, minZ, maxZ, minY, maxY, label });
}
function createInstances(items, castShadow = false) {
const mesh = new THREE.InstancedMesh(
unitBox,
getMaterial(0xffffff),
items.length
);
const dummy = new THREE.Object3D();
items.forEach((item, index) => {
dummy.position.set(item.x, item.y, item.z);
dummy.rotation.set(0, item.rotation ?? 0, 0);
dummy.scale.set(item.sx, item.sy, item.sz);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
mesh.setColorAt(index, new THREE.Color(item.color));
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
mesh.computeBoundingSphere();
scene.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Plaza paving
// -------------------------------------------------------------------------
addBox(scene, 68, 0.35, 68, 0x9eafa5, 0, -0.28, 0, {
cast: false
});
const paving = [];
for (let x = -15; x <= 15; x++) {
for (let z = -15; z <= 15; z++) {
const radial = x * x + z * z;
const hash = (x * 37 + z * 19 + 100) % 11;
let color;
if (Math.abs(x) <= 1 || Math.abs(z) <= 1) {
color = hash < 2 ? 0x9fc0b7 : 0x91b7ae;
} else if (radial < 48) {
color = hash < 2 ? 0xe8ddc6 : 0xded2bb;
} else {
color = hash < 3 ? 0xd5cbb7 : 0xc9c1ae;
}
paving.push({
x,
y: -0.02,
z,
sx: 0.965,
sy: 0.12,
sz: 0.965,
color
});
}
}
createInstances(paving);
// -------------------------------------------------------------------------
// Voxel sculpture: a chamfered monolith with two through-passages,
// a central upper void, and smaller upper side perforations.
// -------------------------------------------------------------------------
const CELL = 0.8;
const VISUAL_CELL = 0.76;
const occupied = new Set();
const key = (x, y, z) => `${x},${y},${z}`;
function isPortalVoid(ix, iy, iz) {
// North–south and east–west pedestrian passages.
if (iy <= 4 && (Math.abs(ix) <= 1 || Math.abs(iz) <= 1)) {
return true;
}
// Square light well above the passage intersection.
if (iy >= 5 && Math.abs(ix) <= 2 && Math.abs(iz) <= 2) {
return true;
}
// Smaller upper side perforations.
if (
iy === 5 &&
(
(Math.abs(ix) >= 4 && Math.abs(iz) <= 1) ||
(Math.abs(iz) >= 4 && Math.abs(ix) <= 1)
)
) {
return true;
}
return false;
}
for (let iy = 0; iy < 8; iy++) {
const radius = iy <= 5 ? 5 : iy === 6 ? 4 : 3;
for (let ix = -5; ix <= 5; ix++) {
for (let iz = -5; iz <= 5; iz++) {
if (Math.max(Math.abs(ix), Math.abs(iz)) > radius) continue;
if (Math.abs(ix) + Math.abs(iz) > 9) continue;
if (isPortalVoid(ix, iy, iz)) continue;
occupied.add(key(ix, iy, iz));
}
}
}
const sculptureVoxels = [];
for (const cellKey of occupied) {
const [ix, iy, iz] = cellKey.split(",").map(Number);
const x = ix * CELL;
const y = (iy + 0.5) * CELL;
const z = iz * CELL;
const nearPortal =
(iy <= 4 && (Math.abs(ix) <= 2 || Math.abs(iz) <= 2)) ||
(iy >= 5 && Math.abs(ix) <= 3 && Math.abs(iz) <= 3);
let color;
if (iy <= 1) {
color = 0x315f59;
} else if (nearPortal) {
color = (ix + iz + iy) % 2 === 0 ? 0xd96f4b : 0xc96343;
} else if ((ix - iz + iy * 2) % 9 === 0) {
color = 0x3c776f;
} else if ((ix + iz * 2 + iy) % 13 === 0) {
color = 0xc6a76d;
} else {
color = (ix + iz + iy) % 3 === 0 ? 0xd5c3a2 : 0xe0d0af;
}
sculptureVoxels.push({
x,
y,
z,
sx: VISUAL_CELL,
sy: VISUAL_CELL,
sz: VISUAL_CELL,
color
});
// Full-cell collision bounds are intentionally more conservative than
// the visible cubes. The actual passage remains 2.4 m wide.
addCollider(
x - CELL / 2,
x + CELL / 2,
z - CELL / 2,
z + CELL / 2,
iy * CELL,
(iy + 1) * CELL,
"sculpture voxel"
);
}
createInstances(sculptureVoxels, true);
// -------------------------------------------------------------------------
// Trees, seating, lamps, bollards
// -------------------------------------------------------------------------
function addTree(x, z, variant = 0) {
addBox(scene, 2.45, 0.48, 2.45, 0xb7aa91, x, 0.23, z);
addBox(scene, 2.14, 0.10, 2.14, 0x6e8066, x, 0.49, z);
addBox(scene, 0.46, 2.25, 0.46, 0x80684a, x, 1.57, z);
addCollider(
x - 1.23, x + 1.23,
z - 1.23, z + 1.23,
0, 0.54,
"planter"
);
addCollider(
x - 0.25, x + 0.25,
z - 0.25, z + 0.25,
0.48, 2.72,
"tree trunk"
);
const foliage = [
[0, 3.02, 0, 1.85, 1.35, 1.85],
[-0.72, 2.83, 0.12, 1.15, 1.05, 1.30],
[0.72, 2.88, -0.10, 1.15, 1.12, 1.25],
[0.12, 3.72, -0.08, 1.25, 0.85, 1.20],
[-0.10, 2.73, -0.80, 1.35, 1.00, 1.10],
[0.15, 2.77, 0.78, 1.30, 1.02, 1.05],
[-0.25, 3.44, 0.60, 0.85, 0.85, 0.85],
[0.38, 3.35, -0.62, 0.85, 0.90, 0.85]
];
foliage.forEach((block, index) => {
const green = index % 3 === 0 ? 0x72936d : index % 3 === 1 ? 0x628563 : 0x82a078;
addBox(
scene,
block[3], block[4], block[5],
green,
x + block[0], block[1], z + block[2]
);
});
}
addTree(-9.2, -8.5, 0);
addTree(9.1, -8.2, 1);
addTree(-9.4, 8.5, 2);
addTree(9.4, 8.4, 3);
function addBench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
for (let i = 0; i < 3; i++) {
addBox(group, 2.35, 0.13, 0.17, 0xa76e43, 0, 0.57, -0.24 + i * 0.24);
}
for (let i = 0; i < 3; i++) {
addBox(group, 2.35, 0.14, 0.12, 0xb87b4c, 0, 0.92 + i * 0.22, 0.31);
}
addBox(group, 0.16, 0.58, 0.55, 0x455650, -0.87, 0.28, 0);
addBox(group, 0.16, 0.58, 0.55, 0x455650, 0.87, 0.28, 0);
const rotated = Math.abs(Math.sin(rotation)) > 0.5;
const halfX = rotated ? 0.48 : 1.25;
const halfZ = rotated ? 1.25 : 0.48;
addCollider(
x - halfX, x + halfX,
z - halfZ, z + halfZ,
0, 1.5,
"bench"
);
}
addBench(-6.6, 4.6, 0);
addBench(6.6, -4.6, 0);
addBench(-4.8, -7.1, Math.PI / 2);
addBench(4.8, 7.1, Math.PI / 2);
function addLamp(x, z) {
addBox(scene, 0.18, 4.1, 0.18, 0x3e504c, x, 2.05, z);
addBox(scene, 0.58, 0.30, 0.58, 0x445b56, x, 4.12, z);
addBox(
scene, 0.43, 0.16, 0.43, 0xffe4a3,
x, 3.91, z,
{ emissive: 0xffc96b, emissiveIntensity: 1.7 }
);
addCollider(
x - 0.16, x + 0.16,
z - 0.16, z + 0.16,
0, 4.3,
"lamp"
);
}
addLamp(-10.3, -4.2);
addLamp(10.3, 4.2);
addLamp(-4.2, 10.3);
addLamp(4.2, -10.3);
function addBollard(x, z) {
addBox(scene, 0.30, 0.78, 0.30, 0x3f5c57, x, 0.38, z);
addBox(
scene, 0.33, 0.12, 0.33, 0xffd890,
x, 0.79, z,
{ emissive: 0xffbd5b, emissiveIntensity: 1.4 }
);
addCollider(
x - 0.18, x + 0.18,
z - 0.18, z + 0.18,
0, 0.86,
"bollard"
);
}
[
[-5.2, -5.2], [-5.2, 5.2],
[5.2, -5.2], [5.2, 5.2]
].forEach(([x, z]) => addBollard(x, z));
// Voxel direction markers lead pedestrians toward the two portals.
function addArrow(x, z, axis, direction) {
const color = 0x39756d;
if (axis === "z") {
addBox(scene, 0.16, 0.045, 0.72, color, x, 0.075, z - direction * 0.25);
addBox(scene, 0.16, 0.045, 0.35, color, x - 0.22, 0.075, z + direction * 0.10);
addBox(scene, 0.16, 0.045, 0.35, color, x + 0.22, 0.075, z + direction * 0.10);
} else {
addBox(scene, 0.72, 0.045, 0.16, color, x - direction * 0.25, 0.075, z);
addBox(scene, 0.35, 0.045, 0.16, color, x + direction * 0.10, 0.075, z - 0.22);
addBox(scene, 0.35, 0.045, 0.16, color, x + direction * 0.10, 0.075, z + 0.22);
}
}
addArrow(0, -6.5, "z", 1);
addArrow(0, 6.5, "z", -1);
addArrow(-6.5, 0, "x", 1);
addArrow(6.5, 0, "x", -1);
// -------------------------------------------------------------------------
// Clearance and sight-line overlay
// -------------------------------------------------------------------------
const overlay = new THREE.Group();
scene.add(overlay);
function addClearanceVolume(width, depth, x, z, color) {
const geometry = new THREE.BoxGeometry(width, 4, depth);
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.045,
depthWrite: false,
side: THREE.DoubleSide
});
const volume = new THREE.Mesh(geometry, material);
volume.position.set(x, 2, z);
volume.renderOrder = 2;
overlay.add(volume);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.46,
depthWrite: false
})
);
edges.position.copy(volume.position);
edges.renderOrder = 3;
overlay.add(edges);
}
addClearanceVolume(2.4, 8.8, 0, 0, 0x43ad89);
addClearanceVolume(8.8, 2.4, 0, 0, 0x43ad89);
function addSightLine(points, color) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map(([x, y, z]) => new THREE.Vector3(x, y, z))
);
const line = new THREE.Line(
geometry,
new THREE.LineDashedMaterial({
color,
dashSize: 0.28,
gapSize: 0.16,
transparent: true,
opacity: 0.65,
depthWrite: false
})
);
line.computeLineDistances();
overlay.add(line);
}
addSightLine([[-13, 1.65, 0], [13, 1.65, 0]], 0x238f70);
addSightLine([[0, 1.65, -13], [0, 1.65, 13]], 0x238f70);
// -------------------------------------------------------------------------
// Collision and clearance validation
// -------------------------------------------------------------------------
function pointInsideObstacle(x, y, z) {
return obstacles.some((box) =>
x >= box.minX && x <= box.maxX &&
y >= box.minY && y <= box.maxY &&
z >= box.minZ && z <= box.maxZ
);
}
function measureClearWidth(axis) {
const fixed = 2.8; // Just inside the passage entrance.
for (let offset = -1.20; offset <= 1.20; offset += 0.02) {
const x = axis === "z" ? offset : fixed;
const z = axis === "z" ? fixed : offset;
if (pointInsideObstacle(x, 1.65, z)) {
return Math.max(0, Math.abs(offset) * 2);
}
}
return 2.4;
}
function measureHeadroom(axis) {
const x = axis === "z" ? 0 : 2.8;
const z = axis === "z" ? 2.8 : 0;
for (let y = 0.04; y < 4.5; y += 0.01) {
if (pointInsideObstacle(x, y, z)) {
return Math.max(0, Math.floor((y - 0.01) * 100) / 100);
}
}
return 4;
}
function sightLineClear(axis) {
for (let distance = -13; distance <= 13; distance += 0.1) {
const x = axis === "x" ? distance : 0;
const z = axis === "z" ? distance : 0;
if (pointInsideObstacle(x, 1.65, z)) return false;
}
return true;
}
const widths = [
measureClearWidth("z"),
measureClearWidth("x")
];
const heights = [
measureHeadroom("z"),
measureHeadroom("x")
];
const minimumWidth = Math.min(...widths);
const minimumHeight = Math.min(...heights);
const sightLinesClear = sightLineClear("z") && sightLineClear("x");
document.getElementById("widthMetric").textContent =
`${minimumWidth.toFixed(2)} m`;
document.getElementById("heightMetric").textContent =
`${minimumHeight.toFixed(2)} m`;
document.getElementById("sightMetric").textContent =
sightLinesClear ? "Clear" : "Review";
// -------------------------------------------------------------------------
// Voxel pedestrians
// -------------------------------------------------------------------------
const walkers = [];
const PERSON_RADIUS = 0.27;
const PERSON_BOTTOM = 0.05;
const PERSON_TOP = 1.82;
function createPerson(color, skin, hair) {
const group = new THREE.Group();
addBox(group, 0.48, 0.62, 0.31, color, 0, 1.03, 0);
addBox(group, 0.42, 0.18, 0.30, 0x334a47, 0, 0.67, 0);
addBox(group, 0.34, 0.36, 0.34, skin, 0, 1.49, 0);
addBox(group, 0.36, 0.10, 0.36, hair, 0, 1.69, -0.015);
addBox(group, 0.055, 0.055, 0.035, 0x253431, -0.085, 1.52, 0.177);
addBox(group, 0.055, 0.055, 0.035, 0x253431, 0.085, 1.52, 0.177);
addBox(group, 0.055, 0.055, 0.055, skin, 0, 1.44, 0.19);
const legLeft = new THREE.Group();
const legRight = new THREE.Group();
legLeft.position.set(-0.13, 0.61, 0);
legRight.position.set(0.13, 0.61, 0);
group.add(legLeft, legRight);
addBox(legLeft, 0.17, 0.48, 0.19, 0x344d4a, 0, -0.25, 0);
addBox(legRight, 0.17, 0.48, 0.19, 0x344d4a, 0, -0.25, 0);
addBox(legLeft, 0.19, 0.12, 0.29, 0x253431, 0, -0.52, 0.04);
addBox(legRight, 0.19, 0.12, 0.29, 0x253431, 0, -0.52, 0.04);
const armLeft = new THREE.Group();
const armRight = new THREE.Group();
armLeft.position.set(-0.33, 1.24, 0);
armRight.position.set(0.33, 1.24, 0);
group.add(armLeft, armRight);
addBox(armLeft, 0.14, 0.49, 0.16, color, 0, -0.23, 0);
addBox(armRight, 0.14, 0.49, 0.16, color, 0, -0.23, 0);
addBox(armLeft, 0.14, 0.14, 0.15, skin, 0, -0.50, 0);
addBox(armRight, 0.14, 0.14, 0.15, skin, 0, -0.50, 0);
group.traverse((object) => {
if (object.isMesh) {
object.castShadow = true;
object.receiveShadow = true;
}
});
scene.add(group);
return { group, legLeft, legRight, armLeft, armRight };
}
function createWalker({
axis,
offset,
speed,
phase,
color,
skin,
hair,
scale = 1
}) {
const person = createPerson(color, skin, hair);
person.group.scale.setScalar(scale);
const walker = {
...person,
axis,
offset,
speed,
phase,
u: phase,
direction: 1,
pathStart: -12.8,
pathEnd: 12.8
};
walkers.push(walker);
placeWalker(walker, walker.u);
return walker;
}
function pathPosition(walker, u) {
const distance = THREE.MathUtils.lerp(
walker.pathStart,
walker.pathEnd,
u
);
return walker.axis === "z"
? { x: walker.offset, z: distance }
: { x: distance, z: walker.offset };
}
function placeWalker(walker, u) {
const position = pathPosition(walker, u);
walker.group.position.set(position.x, 0.04, position.z);
}
function horizontalCollision(x, z, radius) {
for (const box of obstacles) {
if (PERSON_TOP <= box.minY || PERSON_BOTTOM >= box.maxY) continue;
const closestX = THREE.MathUtils.clamp(x, box.minX, box.maxX);
const closestZ = THREE.MathUtils.clamp(z, box.minZ, box.maxZ);
const dx = x - closestX;
const dz = z - closestZ;
if (dx * dx + dz * dz < radius * radius) {
return true;
}
}
return false;
}
function personCollision(x, z, radius, ignoredWalker) {
for (const other of walkers) {
if (other === ignoredWalker) continue;
const dx = x - other.group.position.x;
const dz = z - other.group.position.z;
if (dx * dx + dz * dz < (radius * 2) ** 2) {
return true;
}
}
return false;
}
function canOccupy(walker, x, z) {
return (
!horizontalCollision(x, z, PERSON_RADIUS) &&
!personCollision(x, z, PERSON_RADIUS, walker)
);
}
createWalker({
axis: "z", offset: -0.62, speed: 0.92, phase: 0.12,
color: 0xd96f4b, skin: 0xc98f67, hair: 0x3b302a
});
createWalker({
axis: "z", offset: 0, speed: 1.05, phase: 0.43,
color: 0x3f7f76, skin: 0xe0ae83, hair: 0x5d3b27, scale: 1.03
});
createWalker({
axis: "z", offset: 0.62, speed: 0.83, phase: 0.69,
color: 0xd3a64d, skin: 0x8f6046, hair: 0x2d2925
});
createWalker({
axis: "x", offset: -0.62, speed: 1.00, phase: 0.28,
color: 0x637a9b, skin: 0xdca27c, hair: 0x47352c
});
createWalker({
axis: "x", offset: 0.62, speed: 0.88, phase: 0.76,
color: 0xa76887, skin: 0xb97855, hair: 0x352b28, scale: 0.98
});
document.getElementById("walkerMetric").textContent =
`${walkers.length} moving`;
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, touch pinch
// -------------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 1.6, 0),
radius: 22,
theta: 0.67,
phi: 0.78
};
function syncCamera() {
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);
camera.updateMatrixWorld();
}
function setView(view) {
document.querySelectorAll("[data-view]").forEach((button) => {
button.classList.toggle("active", button.dataset.view === view);
});
if (view === "plan") {
cameraState.target.set(0, 0, 0);
cameraState.radius = 29;
cameraState.theta = 0.01;
cameraState.phi = 0.18;
} else {
cameraState.target.set(0, 1.6, 0);
cameraState.radius = 22;
cameraState.theta = 0.67;
cameraState.phi = 0.78;
}
syncCamera();
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => setView(button.dataset.view));
});
const clearanceButton = document.getElementById("clearanceButton");
clearanceButton.addEventListener("click", () => {
overlay.visible = !overlay.visible;
clearanceButton.classList.toggle("active", overlay.visible);
});
window.addEventListener("keydown", (event) => {
if (event.key === "1") setView("overview");
if (event.key === "2") setView("plan");
if (event.key === "3") clearanceButton.click();
});
const canvas = renderer.domElement;
const pointers = new Map();
let pinchDistance = 0;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
mode: event.button === 2 ? "pan" : "orbit"
});
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
canvas.addEventListener("pointermove", (event) => {
const pointer = pointers.get(event.pointerId);
if (!pointer) return;
if (pointers.size === 1) {
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
if (pointer.mode === "pan") {
syncCamera();
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0);
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const scale = cameraState.radius * 0.0014;
cameraState.target
.addScaledVector(right, -dx * scale)
.addScaledVector(forward, dy * scale);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.18,
1.49
);
}
pointer.x = event.clientX;
pointer.y = event.clientY;
syncCamera();
} else if (pointers.size === 2) {
pointer.x = event.clientX;
pointer.y = event.clientY;
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0 && distance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (pinchDistance / distance),
7,
42
);
syncCamera();
}
pinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
pinchDistance = pointers.size === 2
? (() => {
const [a, b] = [...pointers.values()];
return Math.hypot(a.x - b.x, a.y - b.y);
})()
: 0;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
7,
42
);
syncCamera();
}, { passive: false });
canvas.addEventListener("dblclick", () => setView("overview"));
syncCamera();
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
for (const walker of walkers) {
const pathLength = walker.pathEnd - walker.pathStart;
const nextU = walker.u + walker.direction * walker.speed * delta / pathLength;
if (nextU > 1) {
walker.u = 2 - nextU;
walker.direction = -1;
} else if (nextU < 0) {
walker.u = -nextU;
walker.direction = 1;
} else {
walker.u = nextU;
}
const position = pathPosition(walker, walker.u);
// The actual pedestrian body is checked against the voxel collision
// volumes and other walkers before it can advance.
if (canOccupy(walker, position.x, position.z)) {
walker.group.position.x = position.x;
walker.group.position.z = position.z;
}
const stride = elapsed * walker.speed * 7.2 + walker.phase * 8;
const swing = Math.sin(stride) * 0.48;
walker.legLeft.rotation.x = swing;
walker.legRight.rotation.x = -swing;
walker.armLeft.rotation.x = -swing * 0.72;
walker.armRight.rotation.x = swing * 0.72;
walker.group.position.y =
0.04 + Math.abs(Math.sin(stride)) * 0.024;
if (walker.axis === "z") {
walker.group.rotation.y =
walker.direction > 0 ? 0 : Math.PI;
} else {
walker.group.rotation.y =
walker.direction > 0 ? Math.PI / 2 : -Math.PI / 2;
}
}
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
</script>
</body>
</html>
```