Prompt specification
Build or customize the Three.js 3D scene "Village Bridge Maintenance Assembly" 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: Village Bridge Maintenance Assembly
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/village-bridge-maintenance-assembly-x3187
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts shared funding for public facilities. Build a bridge used by several neighborhoods with unequal traffic. Compare equal and usage-based contribution rules while showing the same maintenance target and shared access. Voxel style.
Working Three.js Starter (village-bridge-maintenance-assembly-x3187):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Common Bridge — Shared Funding Explorer</title>
<style>
:root {
--ink: #21322e;
--muted: #687772;
--paper: #fffdf7;
--line: #dfe5dc;
--green: #2f7d5d;
--coral: #e76f51;
--blue: #4e8fba;
--gold: #e0ad3e;
--leaf: #68a875;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8eee5;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.soft-vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 44% 42%, transparent 35%, rgba(40, 57, 50, 0.07) 100%);
z-index: 2;
}
.header {
position: fixed;
top: 24px;
left: 28px;
z-index: 6;
width: min(570px, calc(100vw - 450px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: #486259;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 22px;
height: 4px;
border-radius: 5px;
background: var(--green);
}
h1 {
max-width: 540px;
margin: 0;
font-size: clamp(30px, 4vw, 52px);
line-height: 0.98;
letter-spacing: -0.045em;
}
.header p {
max-width: 490px;
margin: 13px 0 0;
color: #5e7169;
font-size: 14px;
line-height: 1.5;
}
.status-pill {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 14px;
padding: 8px 11px;
border: 1px solid rgba(73, 113, 92, 0.2);
border-radius: 999px;
background: rgba(255, 253, 247, 0.76);
box-shadow: 0 8px 24px rgba(44, 65, 55, 0.06);
color: #426557;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #48a66f;
box-shadow: 0 0 0 4px rgba(72, 166, 111, 0.14);
}
.panel {
position: fixed;
top: 18px;
right: 18px;
bottom: 18px;
z-index: 10;
width: 390px;
padding: 20px;
overflow-y: auto;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 22px;
background: rgba(255, 253, 247, 0.94);
box-shadow:
0 22px 70px rgba(46, 67, 57, 0.16),
inset 0 0 0 1px rgba(56, 77, 66, 0.04);
backdrop-filter: blur(18px);
scrollbar-width: thin;
scrollbar-color: #c9d3ca transparent;
}
.panel-kicker {
color: #789087;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.panel h2 {
margin: 6px 0 7px;
font-size: 23px;
line-height: 1.1;
letter-spacing: -0.03em;
}
.panel-intro {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.mode-switch {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 5px;
margin-top: 17px;
padding: 4px;
border: 1px solid #e0e6dd;
border-radius: 13px;
background: #edf1e9;
}
.mode-switch button {
min-height: 46px;
padding: 9px 10px;
border: 0;
border-radius: 9px;
background: transparent;
color: #6b7b75;
cursor: pointer;
font-size: 11px;
font-weight: 800;
transition: 160ms ease;
}
.mode-switch button[aria-pressed="true"] {
background: var(--paper);
color: var(--ink);
box-shadow: 0 4px 14px rgba(42, 63, 52, 0.1);
}
.mode-switch button:focus-visible,
.small-button:focus-visible {
outline: 3px solid rgba(47, 125, 93, 0.25);
outline-offset: 2px;
}
.mode-copy {
min-height: 42px;
margin: 10px 2px 0;
color: #687871;
font-size: 11px;
line-height: 1.45;
}
.target-card {
margin-top: 13px;
padding: 15px;
border-radius: 15px;
background: #edf4e9;
border: 1px solid #d8e6d5;
}
.target-top,
.section-heading,
.share-label,
.access-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.target-top span,
.section-heading span {
color: #66786e;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.same-badge {
padding: 4px 7px;
border-radius: 999px;
background: #d8ead9;
color: #397052;
font-size: 9px;
font-weight: 800;
white-space: nowrap;
}
.target-value {
margin-top: 7px;
font-size: 31px;
font-weight: 850;
letter-spacing: -0.045em;
}
.target-sub {
margin-top: 2px;
color: #718078;
font-size: 10px;
}
.funding-meter {
height: 7px;
margin-top: 11px;
overflow: hidden;
border-radius: 10px;
background: #d3dfd0;
}
.funding-meter > div {
width: 100%;
height: 100%;
border-radius: inherit;
background: #4b966a;
}
.section-heading {
margin-top: 18px;
margin-bottom: 8px;
}
.section-heading small {
color: #89968f;
font-size: 10px;
}
table {
width: 100%;
border-collapse: collapse;
overflow: hidden;
border: 1px solid #e1e6de;
border-radius: 12px;
font-size: 10px;
}
th {
padding: 8px 6px;
background: #f1f3ed;
color: #7b8982;
font-size: 8px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
td {
padding: 9px 6px;
border-top: 1px solid #e7ebe4;
text-align: right;
font-variant-numeric: tabular-nums;
}
td:first-child {
text-align: left;
font-weight: 750;
}
.district-cell {
display: flex;
align-items: center;
gap: 6px;
white-space: nowrap;
}
.district-dot {
width: 7px;
height: 7px;
flex: 0 0 auto;
border-radius: 2px;
background: var(--c);
}
.amount-cell {
border-radius: 5px;
transition: background 180ms ease, color 180ms ease;
}
.amount-cell.active {
background: #e2ecdf;
color: #245e45;
font-weight: 850;
}
.split-section {
margin-top: 14px;
padding-top: 12px;
border-top: 1px solid #e4e9e1;
}
.share-label {
margin-bottom: 5px;
color: #6f7d76;
font-size: 9px;
}
.share-label strong {
color: #3f5048;
font-size: 9px;
}
.share-row {
margin-bottom: 10px;
padding: 5px;
border: 1px solid transparent;
border-radius: 9px;
transition: 180ms ease;
}
.share-row.active {
border-color: #d5e3d4;
background: #f0f5ed;
}
.share-bar {
display: flex;
height: 12px;
overflow: hidden;
border-radius: 5px;
background: #e7ece4;
}
.share-bar span {
height: 100%;
border-right: 2px solid rgba(255, 253, 247, 0.86);
}
.share-bar span:last-child {
border-right: 0;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 6px 11px;
margin-top: 9px;
color: #78857f;
font-size: 8px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 4px;
}
.legend i {
width: 6px;
height: 6px;
border-radius: 2px;
background: var(--c);
}
.access-card {
margin-top: 12px;
padding: 12px 13px;
border: 1px solid #d6e3d6;
border-radius: 13px;
background: #f5f8f1;
}
.access-top strong {
color: #3c7655;
font-size: 10px;
letter-spacing: 0.06em;
}
.access-card p {
margin: 5px 0 0;
color: #748078;
font-size: 10px;
line-height: 1.45;
}
.tradeoff {
margin-top: 12px;
padding-left: 10px;
border-left: 3px solid #d9b45e;
color: #6d7771;
font-size: 10px;
line-height: 1.5;
}
.tradeoff strong {
color: #43544c;
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
min-width: 116px;
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.85);
border-radius: 10px;
background: rgba(255, 253, 247, 0.91);
box-shadow: 0 8px 24px rgba(39, 61, 50, 0.12);
transform: translate(-50%, -100%);
backdrop-filter: blur(8px);
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -5px;
width: 9px;
height: 9px;
border-right: 1px solid rgba(255, 255, 255, 0.85);
border-bottom: 1px solid rgba(255, 255, 255, 0.85);
background: rgba(255, 253, 247, 0.91);
transform: translateX(-50%) rotate(45deg);
}
.wl-title {
display: flex;
align-items: center;
gap: 6px;
font-size: 10px;
font-weight: 850;
}
.wl-title i {
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--c);
}
.wl-meta {
display: flex;
justify-content: space-between;
gap: 12px;
margin-top: 4px;
color: #78857f;
font-size: 8px;
}
.wl-meta strong {
color: #344a40;
font-size: 9px;
}
.bridge-label {
position: absolute;
min-width: 168px;
padding: 10px 12px;
border: 1px solid rgba(255, 255, 255, 0.92);
border-radius: 11px;
background: rgba(35, 64, 53, 0.9);
color: white;
box-shadow: 0 10px 26px rgba(30, 52, 43, 0.2);
transform: translate(-50%, -100%);
text-align: center;
backdrop-filter: blur(8px);
}
.bridge-label small {
display: block;
color: #c7ddd1;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.bridge-label strong {
display: block;
margin: 3px 0;
font-size: 12px;
}
.bridge-label span {
color: #bcd5c7;
font-size: 9px;
}
.scene-note {
position: fixed;
left: 26px;
bottom: 25px;
z-index: 8;
width: 278px;
padding: 12px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 14px;
background: rgba(255, 253, 247, 0.84);
box-shadow: 0 12px 35px rgba(40, 61, 51, 0.1);
backdrop-filter: blur(12px);
}
.control-row {
display: flex;
gap: 6px;
}
.small-button {
min-height: 30px;
padding: 6px 9px;
border: 1px solid #d8e0d7;
border-radius: 8px;
background: #fffdf8;
color: #4e6258;
cursor: pointer;
font-size: 9px;
font-weight: 750;
}
.small-button:hover {
border-color: #a9c3b1;
color: #285e46;
}
.control-hint {
margin: 9px 1px 0;
color: #7b8982;
font-size: 9px;
line-height: 1.4;
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #e8eee5;
color: #527060;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.header {
top: 15px;
left: 15px;
width: calc(100vw - 30px);
}
h1 {
max-width: 340px;
font-size: 31px;
}
.header p,
.status-pill {
display: none;
}
.panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 53vh;
padding: 16px;
border-radius: 18px;
}
.panel-intro,
.mode-copy,
.tradeoff {
display: none;
}
.scene-note {
top: 112px;
bottom: auto;
left: 15px;
width: 238px;
padding: 8px;
}
.control-hint {
display: none;
}
.world-label {
min-width: 95px;
padding: 6px 8px;
}
.wl-meta {
gap: 6px;
}
.bridge-label {
min-width: 138px;
padding: 8px 9px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="soft-vignette"></div>
<div id="labels" aria-hidden="true"></div>
<header class="header">
<div class="eyebrow">Common Ground / Public Finance</div>
<h1>One bridge.<br />Four ways to pay.</h1>
<p>
A shared public facility used by four neighborhoods with different levels of traffic.
Compare contribution rules without changing the bridge or its maintenance target.
</p>
<div class="status-pill">
<span class="status-dot"></span>
Shared access preserved
</div>
</header>
<aside class="panel" aria-label="Funding rule comparison">
<div class="panel-kicker">Funding model 01</div>
<h2>Who pays for the bridge?</h2>
<p class="panel-intro">
Both plans fully fund the same $120,000 maintenance target and keep the bridge open to every neighborhood.
</p>
<div class="mode-switch" role="group" aria-label="Choose contribution rule">
<button type="button" data-mode="equal" aria-pressed="false">Equal shares</button>
<button type="button" data-mode="usage" aria-pressed="true">Usage-based</button>
</div>
<p class="mode-copy" id="mode-copy" aria-live="polite"></p>
<div class="target-card">
<div class="target-top">
<span>Maintenance target</span>
<span class="same-badge">Identical in both plans</span>
</div>
<div class="target-value">$120,000</div>
<div class="target-sub">100% funded · repairs, inspection and safety</div>
<div class="funding-meter" aria-label="Funding target fully funded">
<div></div>
</div>
</div>
<div class="section-heading">
<span>Side-by-side comparison</span>
<small>100 trips / day</small>
</div>
<table aria-label="Neighborhood contributions under both funding rules">
<thead>
<tr>
<th>Neighborhood</th>
<th>Trips</th>
<th>Equal</th>
<th>Usage</th>
</tr>
</thead>
<tbody id="comparison-body"></tbody>
</table>
<div class="split-section">
<div class="share-row" id="equal-share-row">
<div class="share-label">
<span>Equal shares</span>
<strong>25% each</strong>
</div>
<div class="share-bar" id="equal-share-bar"></div>
</div>
<div class="share-row active" id="usage-share-row">
<div class="share-label">
<span>Usage-based shares</span>
<strong>Follow traffic</strong>
</div>
<div class="share-bar" id="usage-share-bar"></div>
</div>
<div class="legend" id="legend"></div>
</div>
<div class="access-card">
<div class="access-top">
<strong>OPEN TO ALL</strong>
<span class="same-badge">No tolls</span>
</div>
<p>
Every neighborhood keeps the same crossing rights in either model.
The rule changes only how the fixed cost is divided.
</p>
</div>
<div class="tradeoff" id="tradeoff"></div>
</aside>
<div class="scene-note">
<div class="control-row">
<button class="small-button" id="reset-view" type="button">Reset view</button>
<button class="small-button" id="traffic-toggle" type="button">Pause traffic</button>
<button class="small-button" id="zoom-out" type="button" aria-label="Zoom out">−</button>
<button class="small-button" id="zoom-in" type="button" aria-label="Zoom in">+</button>
</div>
<p class="control-hint">
Drag to orbit · Scroll to zoom · Keyboard: arrows, + / −, R
</p>
</div>
<div id="loading">Building shared bridge…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (selector) => document.querySelector(selector);
const $$ = (selector) => [...document.querySelectorAll(selector)];
const TARGET = 120000;
const TOTAL_TRIPS = 100;
const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const districts = [
{
id: "northbank",
name: "Northbank",
x: -16,
z: -9,
traffic: 42,
color: 0xe76f51,
css: "#e76f51",
cars: 7
},
{
id: "old-quarter",
name: "Old Quarter",
x: -16,
z: 9,
traffic: 28,
color: 0x4e8fba,
css: "#4e8fba",
cars: 5
},
{
id: "meadow",
name: "Meadow",
x: 16,
z: -9,
traffic: 18,
color: 0xe0ad3e,
css: "#e0ad3e",
cars: 3
},
{
id: "hillcrest",
name: "Hillcrest",
x: 16,
z: 9,
traffic: 12,
color: 0x68a875,
css: "#68a875",
cars: 2
}
];
let activeMode = "usage";
let trafficPaused = reduceMotion;
const money = new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
maximumFractionDigits: 0
});
function contribution(district, mode) {
return mode === "equal"
? TARGET / districts.length
: TARGET * district.traffic / TOTAL_TRIPS;
}
// ---------------------------------------------------------------------
// Renderer, camera, and lighting
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8eee5);
scene.fog = new THREE.Fog(0xe8eee5, 68, 135);
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.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Interactive voxel bridge funding scene");
renderer.domElement.tabIndex = 0;
$("#scene").appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-30, 30, 18, -18, 0.1, 220);
const orbit = {
yaw: 0.67,
pitch: 0.76,
zoom: 0.96,
targetZoom: 0.96,
targetX: window.innerWidth > 900 ? 4 : 0,
dragging: false,
pointerX: 0,
pointerY: 0
};
const hemi = new THREE.HemisphereLight(0xf9fff5, 0x829487, 2.2);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff4d8, 3.4);
sun.position.set(-18, 34, 19);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -32;
sun.shadow.camera.right = 32;
sun.shadow.camera.top = 26;
sun.shadow.camera.bottom = -26;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 90;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8d8eb, 0.7);
fill.position.set(20, 12, -18);
scene.add(fill);
// ---------------------------------------------------------------------
// Voxel construction helpers
// ---------------------------------------------------------------------
const materialCache = new Map();
function material(color, options = {}) {
const key = `${color}-${JSON.stringify(options)}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.84,
metalness: 0,
...options
})
);
}
return materialCache.get(key);
}
function box(
parent,
width,
height,
depth,
x,
y,
z,
color,
options = {},
castShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material(color, options)
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function seeded(seed) {
const x = Math.sin(seed * 999.17) * 43758.5453;
return x - Math.floor(x);
}
function addTree(parent, x, z, size = 1, seed = 1) {
box(parent, 0.28 * size, 1.25 * size, 0.28 * size,
x, 0.62 * size + 0.08, z, 0x8f6946);
box(parent, 1.15 * size, 0.95 * size, 1.15 * size,
x, 1.55 * size + 0.08, z, 0x5e9867);
box(parent, 0.72 * size, 0.62 * size, 0.72 * size,
x + 0.12 * size, 2.12 * size + 0.08, z - 0.08 * size,
seeded(seed) > 0.5 ? 0x72a876 : 0x659969);
}
function addHouse(parent, x, z, w, h, d, wall, roof, seed) {
const base = 0.15;
box(parent, w, h, d, x, base + h / 2, z, wall);
box(parent, w + 0.12, 0.28, d + 0.12, x, base + h + 0.14, z, roof);
const windowColor = 0xffe7a2;
const frontZ = z + d / 2 + 0.015;
box(parent, 0.38, 0.46, 0.05,
x - w * 0.22, base + h * 0.58, frontZ, windowColor,
{ emissive: 0xb77828, emissiveIntensity: 0.16 }, false);
box(parent, 0.38, 0.46, 0.05,
x + w * 0.22, base + h * 0.58, frontZ, windowColor,
{ emissive: 0xb77828, emissiveIntensity: 0.16 }, false);
box(parent, 0.34, 0.72, 0.05,
x, base + 0.36, z - d / 2 - 0.015, 0x6f5946,
{}, false);
if (seeded(seed) > 0.55) {
box(parent, 0.45, 0.65, 0.5,
x + w * 0.25, base + h + 0.55, z, 0x9a7655);
}
}
function addRoad(x1, z1, x2, z2, width = 2.8) {
if (Math.abs(z2 - z1) < 0.01) {
const length = Math.abs(x2 - x1) + width;
box(scene, length, 0.12, width,
(x1 + x2) / 2, 0.12, (z1 + z2) / 2, 0xc8bfa7, {}, false);
} else {
const length = Math.abs(z2 - z1) + width;
box(scene, width, 0.12, length,
(x1 + x2) / 2, 0.12, (z1 + z2) / 2, 0xc8bfa7, {}, false);
}
}
// ---------------------------------------------------------------------
// Terrain and river
// ---------------------------------------------------------------------
box(scene, 44, 2, 34, 0, -1, 0, 0xb9a887);
box(scene, 9.5, 0.18, 34, 0, 0.12, 0, 0x69aeb9, {
roughness: 0.32,
metalness: 0.05
}, false);
const grassColors = [0x9fc18c, 0xa9c897, 0x98ba84, 0xb0ca9b];
for (let x = -20; x <= 20; x += 3) {
for (let z = -15; z <= 15; z += 3) {
if (Math.abs(x) < 6) continue;
const color = grassColors[Math.floor(seeded(x * 7 + z * 13) * grassColors.length)];
box(scene, 2.85, 0.07, 2.85,
x, 0.055, z, color, {}, false);
}
}
// Riverbank voxels.
for (let z = -15; z <= 15; z += 2) {
box(scene, 0.8, 0.32, 1.82, -5.1, 0.14, z, 0xc5c7a5);
box(scene, 0.8, 0.32, 1.82, 5.1, 0.14, z, 0xc5c7a5);
}
// Water highlights.
for (let i = 0; i < 15; i++) {
const x = -3.6 + seeded(i + 8) * 7.2;
const z = -15 + seeded(i + 51) * 30;
box(scene, 0.8 + seeded(i + 2), 0.025, 0.18,
x, 0.225, z, 0x9acbd0, {}, false);
}
// Approach roads from the four districts.
for (const z of [-9, 9]) {
addRoad(-16, z, -13.8, z);
addRoad(-13.8, z, -13.8, 0);
addRoad(16, z, 13.8, z);
addRoad(13.8, z, 13.8, 0);
}
// ---------------------------------------------------------------------
// The shared bridge
// ---------------------------------------------------------------------
const bridge = new THREE.Group();
scene.add(bridge);
const deckColors = [0xc8bda8, 0xcfc4ad, 0xc3b9a5];
for (let i = 0; i < 10; i++) {
const x = -9 + i * 2;
box(bridge, 1.91, 0.55, 5.4,
x, 3.1, 0, deckColors[i % deckColors.length]);
box(bridge, 1.81, 0.09, 4.72,
x, 3.42, 0, 0x69706d);
box(bridge, 0.65, 0.035, 0.12,
x, 3.485, i % 2 === 0 ? -0.72 : 0.72, 0xf4e5b3, {}, false);
}
// Blocky piers and cross beams.
for (const x of [-4, 0, 4]) {
for (const z of [-1.75, 1.75]) {
box(bridge, 1.05, 2.85, 1.15, x, 1.43, z, 0xb5aa94);
}
box(bridge, 1.05, 0.42, 5.2, x, 2.75, 0, 0xa89e89);
}
// Railings.
for (const z of [-2.72, 2.72]) {
for (let x = -9; x <= 9; x += 2) {
box(bridge, 0.16, 1.08, 0.16, x, 4.0, z, 0xf0e7d2);
}
for (let x = -8; x <= 8; x += 2) {
box(bridge, 1.92, 0.18, 0.18, x, 4.47, z, 0xf0e7d2);
}
}
// Stepped voxel ramps.
const stepTops = [0.6, 1.2, 1.8, 2.4];
const westStepX = [-13.8, -12.6, -11.4, -10.2];
const eastStepX = [10.2, 11.4, 12.6, 13.8];
westStepX.forEach((x, i) => {
const h = stepTops[i];
box(bridge, 1.15, h, 5.15, x, h / 2, 0, 0xc5baa3);
box(bridge, 1.06, 0.08, 4.65, x, h + 0.04, 0, 0x747976);
});
eastStepX.forEach((x, i) => {
const h = stepTops[3 - i];
box(bridge, 1.15, h, 5.15, x, h / 2, 0, 0xc5baa3);
box(bridge, 1.06, 0.08, 4.65, x, h + 0.04, 0, 0x747976);
});
// Small maintenance crew and tools.
box(bridge, 0.34, 0.62, 0.34, 4.3, 3.91, 1.25, 0xf49a44);
box(bridge, 0.32, 0.32, 0.32, 4.3, 4.38, 1.25, 0xe5bd83);
box(bridge, 0.08, 0.85, 0.08, 4.68, 3.9, 1.25, 0x5b5148);
// Voxel boats.
function addBoat(x, z, color) {
const boat = new THREE.Group();
scene.add(boat);
box(boat, 1.35, 0.35, 2.9, x, 0.43, z, color);
box(boat, 0.9, 0.4, 1.0, x, 0.78, z, 0xe8dfc7);
box(boat, 0.09, 0.8, 0.09, x, 1.05, z, 0x5d655f);
}
addBoat(-1.5, 10, 0xe56c4f);
addBoat(2.1, -11, 0xe4b347);
// ---------------------------------------------------------------------
// Neighborhoods and physical contribution towers
// ---------------------------------------------------------------------
const labelLayer = $("#labels");
districts.forEach((district, districtIndex) => {
const group = new THREE.Group();
scene.add(group);
box(group, 8.2, 0.14, 7.2,
district.x, 0.07, district.z, 0xdce5c9, {}, false);
const wallSets = [
[0xf0d6ae, 0xd9956c, 0xe9c79c],
[0xefd9bd, 0xd6a47c, 0xe5c8a9],
[0xd9e7d2, 0x92b6a0, 0xe7dec1],
[0xe8d7ba, 0xb59a78, 0xe4caa3]
];
const roofSets = [
[0x9f5b4c, 0x805b50, 0xb46b54],
[0x567b8e, 0x6a6172, 0x476b7c],
[0xc08c45, 0x9f784d, 0xb98d47],
[0x688b5e, 0x587550, 0x779463]
];
const houseOffsets = [
[-2.25, -2.2],
[0.35, -2.35],
[2.05, -1.9],
[-1.75, 2.25],
[1.2, 2.15]
];
houseOffsets.forEach(([ox, oz], i) => {
const w = 1.35 + seeded(districtIndex * 17 + i) * 0.65;
const d = 1.3 + seeded(districtIndex * 23 + i) * 0.55;
const h = 1.25 + seeded(districtIndex * 31 + i) * 1.45;
addHouse(
group,
district.x + ox,
district.z + oz,
w,
h,
d,
wallSets[districtIndex][i % wallSets[districtIndex].length],
roofSets[districtIndex][i % roofSets[districtIndex].length],
districtIndex * 100 + i
);
});
addTree(group, district.x - 3.35, district.z + 2.65, 0.78, districtIndex + 40);
addTree(group, district.x + 3.35, district.z + 1.8, 0.9, districtIndex + 70);
// The stack's height represents the selected contribution.
const towerX = district.x;
const towerZ = district.z + 3.42;
box(group, 1.05, 0.18, 1.05,
towerX, 0.2, towerZ, 0x40564d);
district.stackBlocks = [];
for (let i = 0; i < 6; i++) {
const block = box(
group,
0.78,
1,
0.78,
towerX,
0.32,
towerZ,
district.color,
{ roughness: 0.72 }
);
block.scale.y = 0.001;
block.userData.targetScale = 0.001;
district.stackBlocks.push(block);
}
const label = document.createElement("div");
label.className = "world-label";
label.style.setProperty("--c", district.css);
label.innerHTML = `
<div class="wl-title">
<i></i>
${district.name}
</div>
<div class="wl-meta">
<span>${district.traffic} trips/day</span>
<strong class="label-amount"></strong>
</div>
`;
labelLayer.appendChild(label);
district.label = label;
district.labelAmount = label.querySelector(".label-amount");
district.labelPosition = new THREE.Vector3(district.x, 6.15, district.z);
});
// Bridge annotation.
const bridgeLabel = document.createElement("div");
bridgeLabel.className = "bridge-label";
bridgeLabel.innerHTML = `
<small>Shared public facility</small>
<strong>Cross-Canal Bridge</strong>
<span>$120K target · open to all four districts</span>
`;
labelLayer.appendChild(bridgeLabel);
const bridgeLabelPosition = new THREE.Vector3(0, 7.25, 0);
// ---------------------------------------------------------------------
// Traffic routes and voxel vehicles
// ---------------------------------------------------------------------
function makeRoute(z, lane, reverse = false) {
const points = [
[-16, 0.2, z],
[-13.8, 0.2, z],
[-13.8, 0.2, 0],
[-13.8, 0.72, 0],
[-12.6, 1.32, 0],
[-11.4, 1.92, 0],
[-10.2, 2.52, 0],
[-9, 3.54, 0],
[-9, 3.54, lane],
[9, 3.54, lane],
[9, 3.54, 0],
[10.2, 2.52, 0],
[11.4, 1.92, 0],
[12.6, 1.32, 0],
[13.8, 0.72, 0],
[13.8, 0.2, 0],
[13.8, 0.2, z],
[16, 0.2, z]
].map((p) => new THREE.Vector3(...p));
if (reverse) points.reverse();
const cumulative = [0];
for (let i = 1; i < points.length; i++) {
cumulative.push(cumulative[i - 1] + points[i].distanceTo(points[i - 1]));
}
return {
points,
cumulative,
length: cumulative[cumulative.length - 1]
};
}
function sampleRoute(route, t) {
const distance = ((t % 1) + 1) % 1 * route.length;
let index = 0;
while (
index < route.cumulative.length - 2 &&
distance > route.cumulative[index + 1]
) {
index++;
}
const start = route.points[index];
const end = route.points[index + 1];
const segmentLength = route.cumulative[index + 1] - route.cumulative[index];
const localT = (distance - route.cumulative[index]) / segmentLength;
return {
position: new THREE.Vector3().lerpVectors(start, end, localT),
tangent: new THREE.Vector3().subVectors(end, start).normalize()
};
}
function makeCar(color) {
const car = new THREE.Group();
box(car, 0.88, 0.35, 1.5, 0, 0.31, 0, color);
box(car, 0.68, 0.31, 0.78, 0, 0.62, -0.05, 0xe8eee8);
const wheel = 0x303735;
box(car, 0.16, 0.28, 0.32, -0.47, 0.14, 0.48, wheel);
box(car, 0.16, 0.28, 0.32, 0.47, 0.14, 0.48, wheel);
box(car, 0.16, 0.28, 0.32, -0.47, 0.14, -0.48, wheel);
box(car, 0.16, 0.28, 0.32, 0.47, 0.14, -0.48, wheel);
box(car, 0.5, 0.08, 0.08, 0, 0.51, 0.76, 0xffe7a0, {}, false);
return car;
}
const routes = [
makeRoute(-9, -0.72, false),
makeRoute(-9, 0.72, true),
makeRoute(9, 0.72, false),
makeRoute(9, -0.72, true)
];
const vehicles = [];
districts.forEach((district, routeIndex) => {
for (let i = 0; i < district.cars; i++) {
const car = makeCar(district.color);
scene.add(car);
vehicles.push({
mesh: car,
route: routes[routeIndex],
progress: (i / district.cars + seeded(i + routeIndex * 13) * 0.08) % 1,
speed: 0.028 + seeded(i * 5 + routeIndex) * 0.009
});
}
});
// ---------------------------------------------------------------------
// Comparison UI
// ---------------------------------------------------------------------
const comparisonBody = $("#comparison-body");
districts.forEach((district) => {
const row = document.createElement("tr");
row.innerHTML = `
<td>
<span class="district-cell">
<i class="district-dot" style="--c:${district.css}"></i>
${district.name}
</span>
</td>
<td>${district.traffic}</td>
<td class="amount-cell amount-equal">${money.format(contribution(district, "equal"))}</td>
<td class="amount-cell amount-usage">${money.format(contribution(district, "usage"))}</td>
`;
comparisonBody.appendChild(row);
});
function buildShareBar(id, values) {
const bar = $(id);
bar.innerHTML = "";
values.forEach((value, index) => {
const segment = document.createElement("span");
segment.style.width = `${value}%`;
segment.style.background = districts[index].css;
segment.title = `${districts[index].name}: ${value}%`;
bar.appendChild(segment);
});
}
buildShareBar("#equal-share-bar", districts.map(() => 25));
buildShareBar("#usage-share-bar", districts.map((d) => d.traffic));
$("#legend").innerHTML = districts
.map((d) => `<span><i style="--c:${d.css}"></i>${d.name}</span>`)
.join("");
function applyMode(mode) {
activeMode = mode;
$$(".mode-switch button").forEach((button) => {
button.setAttribute("aria-pressed", String(button.dataset.mode === mode));
});
const equalActive = mode === "equal";
$("#equal-share-row").classList.toggle("active", equalActive);
$("#usage-share-row").classList.toggle("active", !equalActive);
$$(".amount-cell").forEach((cell) => {
const isEqual = cell.classList.contains("amount-equal");
cell.classList.toggle("active", isEqual ? equalActive : !equalActive);
});
districts.forEach((district) => {
const amount = contribution(district, mode);
district.labelAmount.textContent = money.format(amount);
let remainingUnits = amount / 10000;
district.stackBlocks.forEach((block) => {
const visibleUnits = THREE.MathUtils.clamp(remainingUnits, 0, 1);
block.userData.targetScale = Math.max(0.001, visibleUnits * 0.44);
remainingUnits -= 1;
});
});
if (equalActive) {
$("#mode-copy").textContent =
"Each neighborhood contributes $30,000. The rule is simple, but lighter users receive the same subsidy as heavier users.";
$("#tradeoff").innerHTML =
"<strong>Trade-off:</strong> equal shares are easy to understand and administer, regardless of actual crossing frequency.";
} else {
$("#mode-copy").textContent =
"Contributions follow actual bridge use: 42%, 28%, 18% and 12% of daily trips. The total target does not change.";
$("#tradeoff").innerHTML =
"<strong>Trade-off:</strong> usage-based contributions track demand more closely, but require traffic measurement and ongoing administration.";
}
}
$$(".mode-switch button").forEach((button) => {
button.addEventListener("click", () => applyMode(button.dataset.mode));
});
applyMode(activeMode);
// ---------------------------------------------------------------------
// Custom camera controls — no addons used
// ---------------------------------------------------------------------
function resetCamera() {
orbit.yaw = 0.67;
orbit.pitch = 0.76;
orbit.targetZoom = 0.96;
orbit.targetX = window.innerWidth > 900 ? 4 : 0;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
orbit.dragging = true;
orbit.pointerX = event.clientX;
orbit.pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.focus({ preventScroll: true });
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!orbit.dragging) return;
const dx = event.clientX - orbit.pointerX;
const dy = event.clientY - orbit.pointerY;
orbit.pointerX = event.clientX;
orbit.pointerY = event.clientY;
orbit.yaw -= dx * 0.006;
orbit.pitch = THREE.MathUtils.clamp(orbit.pitch + dy * 0.004, 0.42, 1.18);
});
function endDrag(event) {
orbit.dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.targetZoom = THREE.MathUtils.clamp(
orbit.targetZoom * Math.exp(-event.deltaY * 0.001),
0.62,
1.75
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
const tag = document.activeElement?.tagName;
if (tag === "INPUT" || tag === "TEXTAREA") return;
if (event.key === "ArrowLeft") orbit.yaw += 0.12;
if (event.key === "ArrowRight") orbit.yaw -= 0.12;
if (event.key === "ArrowUp") orbit.pitch = Math.min(1.18, orbit.pitch + 0.08);
if (event.key === "ArrowDown") orbit.pitch = Math.max(0.42, orbit.pitch - 0.08);
if (event.key === "+" || event.key === "=") orbit.targetZoom = Math.min(1.75, orbit.targetZoom * 1.12);
if (event.key === "-" || event.key === "_") orbit.targetZoom = Math.max(0.62, orbit.targetZoom / 1.12);
if (event.key.toLowerCase() === "r") resetCamera();
});
$("#reset-view").addEventListener("click", resetCamera);
$("#zoom-in").addEventListener("click", () => {
orbit.targetZoom = Math.min(1.75, orbit.targetZoom * 1.15);
});
$("#zoom-out").addEventListener("click", () => {
orbit.targetZoom = Math.max(0.62, orbit.targetZoom / 1.15);
});
function updateTrafficButton() {
$("#traffic-toggle").textContent = trafficPaused ? "Resume traffic" : "Pause traffic";
}
$("#traffic-toggle").addEventListener("click", () => {
trafficPaused = !trafficPaused;
updateTrafficButton();
});
updateTrafficButton();
// ---------------------------------------------------------------------
// Resize and projected HTML labels
// ---------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setSize(width, height);
const viewSize = aspect < 1 ? 48 / aspect : 36;
camera.left = (-viewSize * aspect) / 2;
camera.right = (viewSize * aspect) / 2;
camera.top = viewSize / 2;
camera.bottom = -viewSize / 2;
camera.updateProjectionMatrix();
orbit.targetX = width > 900 ? 4 : 0;
}
window.addEventListener("resize", resize);
resize();
const projected = new THREE.Vector3();
function placeLabel(element, position) {
projected.copy(position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.08 &&
Math.abs(projected.y) < 1.08;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
// ---------------------------------------------------------------------
// Animation loop
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
// Smooth camera zoom.
const zoomDifference = orbit.targetZoom - orbit.zoom;
if (Math.abs(zoomDifference) > 0.0001) {
orbit.zoom += zoomDifference * 0.12;
camera.zoom = orbit.zoom;
camera.updateProjectionMatrix();
}
const cameraRadius = 58;
camera.position.set(
orbit.targetX + cameraRadius * Math.sin(orbit.yaw) * Math.cos(orbit.pitch),
1.5 + cameraRadius * Math.sin(orbit.pitch),
cameraRadius * Math.cos(orbit.yaw) * Math.cos(orbit.pitch)
);
camera.lookAt(orbit.targetX, 1.5, 0);
// Contribution tower transitions.
districts.forEach((district) => {
let currentBottom = 0.32;
district.stackBlocks.forEach((block) => {
const target = block.userData.targetScale;
block.scale.y += (target - block.scale.y) * 0.1;
const visibleHeight = Math.max(0.001, block.scale.y);
block.position.y = currentBottom + visibleHeight / 2;
currentBottom += visibleHeight;
});
});
// Traffic motion.
if (!trafficPaused) {
vehicles.forEach((vehicle) => {
vehicle.progress =
(vehicle.progress + dt * vehicle.speed) % 1;
const sample = sampleRoute(vehicle.route, vehicle.progress);
vehicle.mesh.position.copy(sample.position);
vehicle.mesh.rotation.y = Math.atan2(
sample.tangent.x,
sample.tangent.z
);
});
}
districts.forEach((district) => {
placeLabel(district.label, district.labelPosition);
});
placeLabel(bridgeLabel, bridgeLabelPosition);
renderer.render(scene, camera);
}
animate();
$("#loading").classList.add("hidden");
setTimeout(() => $("#loading").remove(), 400);
</script>
</body>
</html>
```