Prompt specification
Build or customize the Three.js 3D scene "Repair Service Added to a Local Economy" 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: Repair Service Added to a Local Economy
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/repair-service-added-to-a-local-economy-x3128
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts circular flows of work, goods, and resources in a local economy. Extend a neighborhood flow model with a repair shop. Compare material replacement and service payments before and after, keeping assumed repair success and labor requirements explicit. Low-poly.
Working Three.js Starter (repair-service-added-to-a-local-economy-x3128):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Neighborhood Repair Loop</title>
<style>
:root {
--ink: #183238;
--muted: #61747a;
--panel: rgba(251, 250, 245, 0.92);
--line: rgba(24, 50, 56, 0.12);
--work: #3b82c4;
--goods: #3f9d70;
--materials: #e6a23c;
--payments: #8b5cf6;
--accent: #e76f51;
--green: #24745f;
--shadow: 0 18px 45px rgba(36, 57, 55, 0.16);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #edf2ea;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
#stage {
position: fixed;
inset: 0;
z-index: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
#labels {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
overflow: hidden;
}
.node-label {
position: absolute;
left: 0;
top: 0;
display: flex;
align-items: center;
gap: 8px;
min-width: 132px;
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 10px;
background: rgba(255, 255, 255, 0.88);
box-shadow: 0 8px 22px rgba(40, 63, 59, 0.13);
backdrop-filter: blur(8px);
white-space: nowrap;
will-change: transform;
}
.node-label b {
display: block;
font-size: 11px;
line-height: 1.15;
letter-spacing: 0.015em;
}
.node-label small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
line-height: 1.2;
}
.node-dot {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--dot);
box-shadow: 0 0 0 4px color-mix(in srgb, var(--dot) 16%, transparent);
}
header {
position: fixed;
z-index: 6;
top: 22px;
left: 24px;
width: min(440px, calc(100vw - 48px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: #416761;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 23px;
height: 3px;
border-radius: 3px;
background: var(--accent);
content: "";
}
h1 {
margin: 0;
max-width: 420px;
font-size: clamp(27px, 3vw, 42px);
font-weight: 780;
letter-spacing: -0.045em;
line-height: 0.98;
}
.subtitle {
max-width: 390px;
margin: 11px 0 0;
color: #52686d;
font-size: 12px;
line-height: 1.5;
}
#resetView {
pointer-events: auto;
margin-top: 12px;
padding: 7px 11px;
border: 1px solid rgba(24, 50, 56, 0.15);
border-radius: 8px;
background: rgba(255, 255, 255, 0.78);
color: var(--ink);
cursor: pointer;
font-size: 10px;
font-weight: 750;
box-shadow: 0 5px 15px rgba(36, 57, 55, 0.08);
}
#resetView:hover { background: white; }
.panel {
position: fixed;
z-index: 7;
border: 1px solid rgba(255, 255, 255, 0.82);
border-radius: 16px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
}
#metrics {
top: 22px;
right: 22px;
width: 340px;
padding: 17px;
}
#assumptions {
left: 24px;
bottom: 24px;
width: 380px;
padding: 16px 17px;
}
.panel-kicker {
margin-bottom: 5px;
color: #738287;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.panel h2 {
margin: 0;
font-size: 17px;
letter-spacing: -0.025em;
}
.panel-intro {
margin: 7px 0 13px;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.scenario {
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: center;
gap: 9px;
margin: 12px 0;
}
.scenario-card {
padding: 10px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.58);
}
.scenario-card.after {
border-color: rgba(36, 116, 95, 0.24);
background: rgba(225, 243, 235, 0.68);
}
.scenario-card span {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
text-transform: uppercase;
letter-spacing: 0.08em;
}
.scenario-card strong {
font-size: 19px;
letter-spacing: -0.04em;
}
.scenario-arrow {
color: #93a09e;
font-size: 18px;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 10px;
}
th, td {
padding: 8px 3px;
border-bottom: 1px solid var(--line);
text-align: right;
}
th {
color: #7a898d;
font-size: 8px;
font-weight: 750;
text-transform: uppercase;
letter-spacing: 0.08em;
}
th:first-child, td:first-child { text-align: left; }
tbody td { font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 800; border-bottom: 0; }
.saving {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 10px;
padding: 10px 11px;
border-radius: 10px;
background: #e4f2e9;
color: #215e4e;
}
.saving.negative {
background: #fae7df;
color: #8c432d;
}
.saving span {
font-size: 9px;
font-weight: 750;
text-transform: uppercase;
letter-spacing: 0.07em;
}
.saving strong {
font-size: 16px;
white-space: nowrap;
}
.unit-row {
margin-top: 11px;
}
.unit-head {
display: flex;
justify-content: space-between;
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
}
.unit-head strong { color: var(--ink); }
.track {
height: 7px;
overflow: hidden;
border-radius: 99px;
background: #e2e5df;
}
.track i {
display: block;
height: 100%;
border-radius: inherit;
background: var(--accent);
transition: width 160ms ease;
}
.small-note {
margin: 10px 0 0;
color: #738287;
font-size: 9px;
line-height: 1.45;
}
.control-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px 12px;
margin-top: 12px;
}
.control {
display: grid;
grid-template-columns: 1fr 68px;
align-items: center;
gap: 7px;
}
.control.wide { grid-column: 1 / -1; }
.control label {
color: #53676c;
font-size: 9px;
line-height: 1.25;
}
.control input[type="number"] {
width: 68px;
padding: 6px 7px;
border: 1px solid rgba(24, 50, 56, 0.14);
border-radius: 7px;
background: rgba(255, 255, 255, 0.82);
color: var(--ink);
font-size: 10px;
text-align: right;
}
.range-wrap {
margin-top: 12px;
}
.range-head {
display: flex;
justify-content: space-between;
margin-bottom: 6px;
color: #53676c;
font-size: 10px;
}
#success {
width: 100%;
accent-color: var(--green);
}
#legend {
position: fixed;
z-index: 6;
left: 50%;
bottom: 24px;
transform: translateX(-50%);
display: flex;
gap: 16px;
padding: 9px 14px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 12px;
background: rgba(251, 250, 245, 0.84);
box-shadow: 0 10px 28px rgba(36, 57, 55, 0.12);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
color: #56696e;
font-size: 9px;
white-space: nowrap;
}
.legend-line {
width: 19px;
height: 3px;
border-radius: 4px;
background: var(--c);
box-shadow: 0 0 0 2px color-mix(in srgb, var(--c) 12%, transparent);
}
#nodeInfo {
position: fixed;
z-index: 8;
left: 50%;
bottom: 79px;
width: min(440px, calc(100vw - 32px));
padding: 11px 14px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 12px;
background: rgba(30, 49, 53, 0.9);
color: white;
box-shadow: var(--shadow);
transform: translate(-50%, 8px);
opacity: 0;
transition: opacity 160ms ease, transform 160ms ease;
pointer-events: none;
font-size: 10px;
line-height: 1.45;
}
#nodeInfo.visible {
opacity: 1;
transform: translate(-50%, 0);
}
#nodeInfo b {
display: block;
margin-bottom: 2px;
color: #fff4c8;
font-size: 11px;
}
.view-hint {
position: fixed;
z-index: 5;
right: 24px;
bottom: 25px;
color: rgba(48, 68, 70, 0.67);
font-size: 9px;
pointer-events: none;
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #edf2ea;
color: #49645f;
font-size: 12px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#loading.hidden { display: none; }
@media (max-width: 1000px) {
#metrics {
width: 300px;
}
#assumptions {
width: 340px;
}
#legend {
left: auto;
right: 22px;
transform: none;
}
.view-hint { display: none; }
}
@media (max-width: 720px) {
header {
top: 14px;
left: 14px;
}
h1 { font-size: 28px; }
.subtitle { max-width: 300px; }
#metrics {
top: auto;
right: 10px;
bottom: 10px;
width: 270px;
max-height: 46vh;
overflow: auto;
padding: 13px;
}
#assumptions {
left: 10px;
bottom: 10px;
width: calc(100vw - 300px);
min-width: 230px;
max-height: 46vh;
overflow: auto;
padding: 13px;
}
#legend { display: none; }
#nodeInfo { bottom: 15px; }
.control-grid { grid-template-columns: 1fr; }
.control.wide { grid-column: auto; }
}
@media (max-width: 520px) {
#assumptions {
top: 125px;
bottom: auto;
width: 205px;
max-height: 36vh;
}
#metrics {
width: 245px;
max-height: 39vh;
}
.subtitle { display: none; }
}
</style>
</head>
<body>
<div id="stage"></div>
<div id="labels"></div>
<header>
<div class="eyebrow">Local economy · circular flow model</div>
<h1>Neighborhood Repair Loop</h1>
<p class="subtitle">
Work, payments, goods, and materials circulate through a low-poly neighborhood.
The repair shop adds a local service loop before a new item is purchased.
</p>
<button id="resetView" type="button">Reset camera</button>
</header>
<aside id="metrics" class="panel">
<div class="panel-kicker">One broken item</div>
<h2>Expected local payments</h2>
<p class="panel-intro">
Before repair, the item is replaced. After repair, success and failure are
averaged using the stated success rate.
</p>
<div class="scenario">
<div class="scenario-card">
<span>Before · replace</span>
<strong id="beforeTotal">$120.00</strong>
</div>
<div class="scenario-arrow">→</div>
<div class="scenario-card after">
<span>After · try repair</span>
<strong id="afterTotal">$64.75</strong>
</div>
</div>
<table aria-label="Before and after payment comparison">
<thead>
<tr>
<th>Payment</th>
<th>Before</th>
<th>After</th>
</tr>
</thead>
<tbody>
<tr>
<td>Material replacement</td>
<td id="beforeReplacement">$120.00</td>
<td id="afterReplacement">$42.00</td>
</tr>
<tr>
<td>Service labor</td>
<td>$0.00</td>
<td id="afterLabor">$17.55</td>
</tr>
<tr>
<td>Repair parts</td>
<td>$0.00</td>
<td id="afterParts">$5.20</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Total payments</td>
<td id="beforeTotalRow">$120.00</td>
<td id="afterTotalRow">$64.75</td>
</tr>
</tfoot>
</table>
<div id="savingBox" class="saving">
<span id="savingLabel">Expected reduction</span>
<strong id="savingValue">$55.25</strong>
</div>
<div class="unit-row">
<div class="unit-head">
<span>New replacement units per broken item</span>
<strong id="unitValue">1.00 → 0.35</strong>
</div>
<div class="track">
<i id="unitBar" style="width:35%"></i>
</div>
</div>
<p class="small-note">
Combined service and parts payment: <b id="combinedService">$0.00 → $22.75</b>.
All modeled payments remain local; external production and disposal impacts are excluded.
</p>
</aside>
<aside id="assumptions" class="panel">
<div class="panel-kicker">Adjustable model</div>
<h2>Explicit assumptions</h2>
<div class="range-wrap">
<div class="range-head">
<label for="success">Assumed repair success</label>
<strong id="successReadout">65%</strong>
</div>
<input id="success" type="range" min="0" max="100" step="1" value="65">
</div>
<div class="control-grid">
<div class="control">
<label for="labor">Successful repair labor</label>
<input id="labor" type="number" min="0.25" step="0.25" value="1.5">
</div>
<div class="control">
<label for="wage">Local hourly wage</label>
<input id="wage" type="number" min="0" step="1" value="18">
</div>
<div class="control">
<label for="parts">Parts per success</label>
<input id="parts" type="number" min="0" step="1" value="8">
</div>
<div class="control">
<label for="replacement">New replacement price</label>
<input id="replacement" type="number" min="0" step="5" value="120">
</div>
</div>
<p class="small-note">
A successful repair uses <b id="laborNote">1.5 total labor hours</b>, including
0.25 diagnostic hours, plus $8 in parts. A failed attempt uses 0.25 diagnostic
labor hours and no billable parts, then triggers replacement. Labor and parts
are billed only on success. One repair attempt is modeled per item.
</p>
</aside>
<div id="legend" aria-label="Flow legend">
<div class="legend-item">
<span class="legend-line" style="--c:var(--work)"></span>
Work & demand
</div>
<div class="legend-item">
<span class="legend-line" style="--c:var(--goods)"></span>
Goods & repairs
</div>
<div class="legend-item">
<span class="legend-line" style="--c:var(--materials)"></span>
Materials & parts
</div>
<div class="legend-item">
<span class="legend-line" style="--c:var(--payments)"></span>
Payments & wages
</div>
</div>
<div id="nodeInfo"></div>
<div class="view-hint">Drag: orbit · Shift/right-drag: pan · Wheel: zoom · Click a building</div>
<div id="loading">Building neighborhood flow model…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const stage = document.getElementById("stage");
const labelsLayer = document.getElementById("labels");
const nodeInfo = document.getElementById("nodeInfo");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xedf2ea);
scene.fog = new THREE.Fog(0xedf2ea, 29, 56);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
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;
renderer.domElement.setAttribute("aria-label", "Interactive 3D neighborhood economy");
stage.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xf7fbff, 0x73826b, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff3d5, 3.3);
sun.position.set(-10, 19, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.0006;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xcce6f5, 1.0);
fill.position.set(13, 8, -12);
scene.add(fill);
const standard = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...options
});
const materials = {
plinth: standard(0x9eb5a0),
ground: standard(0xcbdcc0),
road: standard(0x9aa79b),
roadEdge: standard(0xe9ecdf),
plaza: standard(0xe8d8b7),
cream: standard(0xf6efdc),
wallLight: standard(0xf1dfbd),
wallWarm: standard(0xdca268),
wallTeal: standard(0x4e9587),
wallCoral: standard(0xd8795f),
wallBlue: standard(0x7da6b2),
roofDark: standard(0x40565b),
roofGreen: standard(0x4f7d66),
roofRed: standard(0xb65345),
window: standard(0xa7d9dc, {
emissive: 0x143f42,
emissiveIntensity: 0.14
}),
door: standard(0x3c555a),
wood: standard(0xa77b50),
trunk: standard(0x806243),
leaf1: standard(0x5d9565),
leaf2: standard(0x7cab70),
crate: standard(0xc89c62),
crateBand: standard(0x896544),
personBlue: standard(0x3b82c4),
personRed: standard(0xe36d50),
personYellow: standard(0xe7b64b),
dark: standard(0x263f44)
};
const pickables = [];
const nodeGroups = {};
const labelElements = new Map();
const labelSubs = new Map();
function addMesh(parent, geometry, material, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function box(parent, w, h, d, x, y, z, material) {
return addMesh(parent, new THREE.BoxGeometry(w, h, d), material, x, y, z);
}
function cylinder(parent, rTop, rBottom, h, x, y, z, material, sides = 8) {
return addMesh(
parent,
new THREE.CylinderGeometry(rTop, rBottom, h, sides),
material,
x, y, z
);
}
function patch(x, z, radius, material) {
const mesh = addMesh(
scene,
new THREE.CircleGeometry(radius, 24),
material,
x, 0.025, z
);
mesh.rotation.x = -Math.PI / 2;
mesh.castShadow = false;
return mesh;
}
// -------------------------------------------------------------------------
// Ground, roads, plaza, and vegetation
// -------------------------------------------------------------------------
const plinth = addMesh(
scene,
new THREE.CylinderGeometry(13.4, 13.8, 0.75, 64),
materials.plinth,
0, -0.48, 0
);
plinth.receiveShadow = true;
const ground = addMesh(
scene,
new THREE.CylinderGeometry(13.25, 13.25, 0.12, 64),
materials.ground,
0, -0.035, 0
);
ground.castShadow = false;
const roadRing = addMesh(
scene,
new THREE.TorusGeometry(9.25, 0.34, 4, 96),
materials.road,
0, 0.07, 0
);
roadRing.rotation.x = Math.PI / 2;
roadRing.castShadow = false;
const innerRoad = addMesh(
scene,
new THREE.TorusGeometry(5.25, 0.16, 4, 72),
materials.road,
0, 0.06, 0
);
innerRoad.rotation.x = Math.PI / 2;
innerRoad.castShadow = false;
for (let i = 0; i < 30; i++) {
const a = (i / 30) * Math.PI * 2;
const dash = box(
scene,
0.12, 0.035, 0.52,
Math.sin(a) * 9.25,
0.115,
Math.cos(a) * 9.25,
materials.roadEdge
);
dash.rotation.y = a;
dash.castShadow = false;
}
const plaza = addMesh(
scene,
new THREE.CylinderGeometry(2.15, 2.15, 0.12, 24),
materials.plaza,
0, 0.08, 0
);
plaza.castShadow = false;
// Benches and a small central tree.
box(scene, 1.7, 0.14, 0.42, -0.7, 0.48, 0.65, materials.wood);
box(scene, 0.14, 0.38, 0.42, -1.38, 0.3, 0.65, materials.dark);
box(scene, 0.14, 0.38, 0.42, -0.02, 0.3, 0.65, materials.dark);
cylinder(scene, 0.14, 0.19, 1.0, 0.55, 0.57, -0.35, materials.trunk, 6);
const centerCrown = addMesh(
scene,
new THREE.ConeGeometry(0.95, 1.8, 7),
materials.leaf2,
0.55, 1.75, -0.35
);
centerCrown.rotation.y = 0.3;
function makeTree(parent, x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
parent.add(tree);
cylinder(tree, 0.13, 0.18, 1.05, 0, 0.52, 0, materials.trunk, 6);
addMesh(
tree,
new THREE.ConeGeometry(0.78, 1.65, 7),
materials.leaf1,
0, 1.55, 0
);
addMesh(
tree,
new THREE.ConeGeometry(0.56, 1.2, 6),
materials.leaf2,
0.05, 2.25, 0
);
return tree;
}
for (let i = 0; i < 18; i++) {
const a = (i / 18) * Math.PI * 2 + 0.08;
const radius = 11.45 + (i % 3) * 0.18;
makeTree(
scene,
Math.sin(a) * radius,
Math.cos(a) * radius,
0.78 + (i % 4) * 0.08
);
}
// -------------------------------------------------------------------------
// Low-poly neighborhood buildings
// -------------------------------------------------------------------------
function makeHouse(parent, x, z, scale, wallMaterial, roofMaterial) {
const house = new THREE.Group();
house.position.set(x, 0, z);
house.scale.setScalar(scale);
parent.add(house);
box(house, 1.6, 1.5, 1.6, 0, 0.88, 0, wallMaterial);
const roof = addMesh(
house,
new THREE.ConeGeometry(1.28, 0.95, 4),
roofMaterial,
0, 1.96, 0
);
roof.rotation.y = Math.PI / 4;
box(house, 0.43, 0.88, 0.06, 0, 0.57, 0.83, materials.door);
box(house, 0.42, 0.46, 0.05, -0.48, 1.03, 0.82, materials.window);
box(house, 0.42, 0.46, 0.05, 0.48, 1.03, 0.82, materials.window);
box(house, 0.24, 0.62, 0.24, 0.48, 2.22, -0.22, materials.roofDark);
return house;
}
function makePerson(parent, x, z, material, scale = 1) {
const person = new THREE.Group();
person.position.set(x, 0, z);
person.scale.setScalar(scale);
parent.add(person);
cylinder(person, 0.17, 0.21, 0.63, 0, 0.68, 0, material, 5);
addMesh(
person,
new THREE.IcosahedronGeometry(0.21, 0),
materials.cream,
0, 1.12, 0
);
box(person, 0.1, 0.36, 0.12, -0.1, 0.24, 0, materials.dark);
box(person, 0.1, 0.36, 0.12, 0.1, 0.24, 0, materials.dark);
return person;
}
// Homes and workers.
const homes = new THREE.Group();
homes.position.set(-7, 0.08, -3.2);
scene.add(homes);
patch(-7, -3.2, 3.1, materials.plaza);
makeHouse(homes, -1.25, 0, 1, materials.wallLight, materials.roofRed);
makeHouse(homes, 1.12, -0.55, 0.84, materials.wallBlue, materials.roofDark);
makeHouse(homes, 0.65, 1.25, 0.72, materials.cream, materials.roofGreen);
makePerson(homes, -0.35, 1.2, materials.personBlue, 0.85);
makePerson(homes, 0.15, 1.35, materials.personRed, 0.72);
// Maker / workshop.
const maker = new THREE.Group();
maker.position.set(-1, 0.08, -7);
scene.add(maker);
patch(-1, -7, 2.7, materials.plaza);
box(maker, 3.8, 2.0, 2.4, 0, 1.12, 0, materials.wallWarm);
box(maker, 4.05, 0.2, 2.65, 0, 2.22, 0, materials.roofDark);
box(maker, 0.48, 1.35, 0.48, 1.2, 2.85, -0.42, materials.roofDark);
box(maker, 0.63, 0.16, 0.63, 1.2, 3.55, -0.42, materials.cream);
box(maker, 1.35, 1.4, 0.08, -0.55, 0.8, 1.23, materials.door);
box(maker, 0.78, 0.6, 0.06, 0.72, 1.35, 1.23, materials.window);
box(maker, 0.78, 0.6, 0.06, -1.45, 1.35, 1.23, materials.window);
makePerson(maker, 2.3, 0.5, materials.personYellow, 0.88);
// Market.
const market = new THREE.Group();
market.position.set(7, 0.08, -3.5);
scene.add(market);
patch(7, -3.5, 2.6, materials.plaza);
box(market, 3.1, 1.95, 2.3, 0, 1.1, 0, materials.wallCoral);
box(market, 3.35, 0.2, 2.55, 0, 2.17, 0, materials.cream);
box(market, 1.0, 1.25, 0.07, -0.5, 0.75, 1.18, materials.door);
box(market, 0.72, 0.62, 0.06, 0.76, 1.32, 1.18, materials.window);
for (let i = 0; i < 7; i++) {
const stripe = box(
market,
0.43, 0.12, 0.65,
-1.32 + i * 0.44,
1.53,
1.42,
i % 2 === 0 ? materials.cream : materials.roofGreen
);
stripe.rotation.x = -0.12;
}
box(market, 2.65, 0.11, 0.55, 0, 1.5, 1.36, materials.roofGreen);
makePerson(market, -1.9, 0.85, materials.personBlue, 0.82);
makePerson(market, 1.9, 0.75, materials.personRed, 0.75);
// Repair shop, including a low-poly gear sign.
const repair = new THREE.Group();
repair.position.set(3, 0.08, 5);
scene.add(repair);
patch(3, 5, 2.9, materials.plaza);
box(repair, 3.3, 2.25, 2.5, 0, 1.25, 0, materials.wallCoral);
box(repair, 3.55, 0.2, 2.75, 0, 2.48, 0, materials.wallTeal);
box(repair, 0.75, 1.28, 0.08, -1.0, 0.76, 1.29, materials.door);
box(repair, 0.62, 0.58, 0.06, 0.94, 1.55, 1.29, materials.window);
const repairGear = new THREE.Group();
repairGear.position.set(0.08, 1.35, 1.36);
repair.add(repairGear);
addMesh(
repairGear,
new THREE.TorusGeometry(0.69, 0.15, 6, 16),
materials.cream
);
for (let i = 0; i < 8; i++) {
const a = (i / 8) * Math.PI * 2;
const tooth = box(
repairGear,
0.25, 0.42, 0.23,
Math.cos(a) * 0.81,
Math.sin(a) * 0.81,
0,
materials.cream
);
tooth.rotation.z = -a;
}
const hub = cylinder(repairGear, 0.24, 0.24, 0.24, 0, 0, 0.04, materials.roofGreen, 8);
hub.rotation.x = Math.PI / 2;
const repairRing = addMesh(
repair,
new THREE.TorusGeometry(2.35, 0.055, 4, 48),
new THREE.MeshBasicMaterial({ color: 0xe76f51 }),
0, 0.14, 0
);
repairRing.rotation.x = Math.PI / 2;
repairRing.castShadow = false;
makePerson(repair, 1.75, 1.2, materials.personBlue, 0.82);
makePerson(repair, 2.1, 0.65, materials.personYellow, 0.72);
// Materials depot.
const depot = new THREE.Group();
depot.position.set(-6, 0.08, 5);
scene.add(depot);
patch(-6, 5, 2.7, materials.plaza);
box(depot, 2.55, 1.25, 2.0, -0.65, 0.75, -0.15, materials.wallBlue);
box(depot, 2.8, 0.16, 2.25, -0.65, 1.45, -0.15, materials.roofDark);
box(depot, 0.95, 1.05, 0.07, -0.65, 0.63, 0.88, materials.door);
function makeCrate(parent, x, y, z, scale = 1) {
const crate = new THREE.Group();
crate.position.set(x, y, z);
crate.scale.setScalar(scale);
parent.add(crate);
box(crate, 1.0, 0.78, 0.9, 0, 0.39, 0, materials.crate);
box(crate, 1.04, 0.12, 0.94, 0, 0.39, 0, materials.crateBand);
box(crate, 0.14, 0.82, 0.94, -0.33, 0.4, 0, materials.crateBand);
box(crate, 0.14, 0.82, 0.94, 0.33, 0.4, 0, materials.crateBand);
return crate;
}
makeCrate(depot, 0.95, 0, 0.3, 0.92);
makeCrate(depot, 1.35, 0, 0.65, 0.78);
makeCrate(depot, 1.05, 0.78, 0.4, 0.72);
makePerson(depot, -1.9, 0.9, materials.personRed, 0.75);
// -------------------------------------------------------------------------
// Node labels and picking
// -------------------------------------------------------------------------
const nodeDescriptions = {
homes: "Households provide labor and create demand. They receive wages, goods, and repaired products, then send service requests and payments back into local businesses.",
maker: "The maker turns local materials into goods and returns wage income to households. Its material demand is represented by the amber flow from the depot.",
market: "The market sells new goods and replacement units. A failed repair sends demand back to this node, replacing the item instead of extending its life.",
repair: "The repair shop converts local labor and parts into a repaired product. Success keeps the item in use; failure triggers the replacement branch and is explicitly included in expected payments.",
depot: "The materials depot supplies the maker with production inputs and the repair shop with repair parts. These amber flows close the neighborhood's resource loop."
};
function registerNode(key, group, anchor, color) {
nodeGroups[key] = group;
group.traverse(object => {
if (object.isMesh) {
object.userData.nodeKey = key;
pickables.push(object);
}
});
const element = document.createElement("div");
element.className = "node-label";
element.style.setProperty("--dot", color);
element.innerHTML = `
<span class="node-dot"></span>
<div>
<b>${key === "maker" ? "Maker & workshop" :
key === "market" ? "Local market" :
key === "repair" ? "Repair shop" :
key === "depot" ? "Materials depot" : "Homes & workers"}</b>
<small></small>
</div>
`;
labelsLayer.appendChild(element);
labelElements.set(key, { element, anchor });
labelSubs.set(key, element.querySelector("small"));
}
registerNode("homes", homes, new THREE.Vector3(-7, 3.65, -3.2), "#3b82c4");
registerNode("maker", maker, new THREE.Vector3(-1, 3.35, -7), "#dca268");
registerNode("market", market, new THREE.Vector3(7, 3.0, -3.5), "#d8795f");
registerNode("repair", repair, new THREE.Vector3(3, 3.35, 5), "#e76f51");
registerNode("depot", depot, new THREE.Vector3(-6, 2.65, 5), "#e6a23c");
labelSubs.get("homes").textContent = "labor + demand";
labelSubs.get("maker").textContent = "goods + jobs";
labelSubs.get("market").textContent = "new goods + sales";
labelSubs.get("depot").textContent = "parts + materials";
// -------------------------------------------------------------------------
// Animated circular flows
// -------------------------------------------------------------------------
const flowColors = {
work: 0x3b82c4,
goods: 0x3f9d70,
materials: 0xe6a23c,
payments: 0x8b5cf6
};
const flows = [];
const particleGeometry = new THREE.IcosahedronGeometry(0.13, 0);
const arrowGeometry = new THREE.ConeGeometry(0.18, 0.52, 6);
function addFlow(category, start, end, height, lateral = 0, count = 5, speed = 0.075) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const middle = a.clone().add(b).multiplyScalar(0.5);
middle.y = Math.max(a.y, b.y) + height;
middle.x += lateral;
middle.z -= lateral * 0.28;
const curve = new THREE.CatmullRomCurve3(
[a, middle, b],
false,
"catmullrom",
0.5
);
const flowMaterial = new THREE.MeshBasicMaterial({
color: flowColors[category],
transparent: true,
opacity: category === "materials" ? 0.72 : 0.84
});
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 44, category === "payments" ? 0.045 : 0.055, 5, false),
flowMaterial
);
tube.renderOrder = 1;
scene.add(tube);
const arrow = new THREE.Mesh(arrowGeometry, flowMaterial);
arrow.position.copy(curve.getPointAt(0.78));
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
curve.getTangentAt(0.78).normalize()
);
arrow.renderOrder = 2;
scene.add(arrow);
const particles = [];
for (let i = 0; i < count; i++) {
const particle = new THREE.Mesh(particleGeometry, flowMaterial);
particle.renderOrder = 3;
scene.add(particle);
particles.push(particle);
}
flows.push({ curve, particles, count, speed });
}
const H = [-7, 2.7, -3.2];
const W = [-1, 2.85, -7];
const M = [7, 2.75, -3.5];
const R = [3, 2.95, 5];
const D = [-6, 2.55, 5];
// Work and demand travel from households to local producers and services.
addFlow("work", H, W, 2.7, 0, 4, 0.070);
addFlow("work", H, M, 3.5, -0.8, 5, 0.068);
addFlow("work", H, R, 3.3, 0.9, 5, 0.075);
// Goods move forward; repaired products return to the same household system.
addFlow("goods", W, M, 2.6, 0, 5, 0.064);
addFlow("goods", M, H, 2.45, -0.7, 6, 0.061);
addFlow("goods", R, H, 2.75, 0.8, 5, 0.074);
// Materials and parts feed production and repair.
addFlow("materials", D, W, 3.2, 0.7, 4, 0.052);
addFlow("materials", D, R, 2.7, 0, 4, 0.057);
// Wage income returns to households, while the repair fee flows to the shop.
addFlow("payments", W, H, 4.0, -0.5, 4, 0.058);
addFlow("payments", M, H, 3.0, 0.8, 5, 0.061);
addFlow("payments", H, R, 4.35, -1.0, 5, 0.067);
// -------------------------------------------------------------------------
// Economic model and UI
// -------------------------------------------------------------------------
const ui = {
success: document.getElementById("success"),
labor: document.getElementById("labor"),
wage: document.getElementById("wage"),
parts: document.getElementById("parts"),
replacement: document.getElementById("replacement"),
successReadout: document.getElementById("successReadout"),
laborNote: document.getElementById("laborNote"),
beforeTotal: document.getElementById("beforeTotal"),
afterTotal: document.getElementById("afterTotal"),
beforeReplacement: document.getElementById("beforeReplacement"),
afterReplacement: document.getElementById("afterReplacement"),
afterLabor: document.getElementById("afterLabor"),
afterParts: document.getElementById("afterParts"),
beforeTotalRow: document.getElementById("beforeTotalRow"),
afterTotalRow: document.getElementById("afterTotalRow"),
savingBox: document.getElementById("savingBox"),
savingLabel: document.getElementById("savingLabel"),
savingValue: document.getElementById("savingValue"),
unitValue: document.getElementById("unitValue"),
unitBar: document.getElementById("unitBar"),
combinedService: document.getElementById("combinedService")
};
const money = value =>
"$" + Number(value).toLocaleString("en-US", {
minimumFractionDigits: 2,
maximumFractionDigits: 2
});
function positiveNumber(input, fallback) {
const value = Number(input.value);
return Number.isFinite(value) && value >= 0 ? value : fallback;
}
function updateModel() {
const successRate = Math.max(0, Math.min(100, Number(ui.success.value))) / 100;
const laborHours = positiveNumber(ui.labor, 1.5);
const wage = positiveNumber(ui.wage, 18);
const partsCost = positiveNumber(ui.parts, 8);
const replacementCost = positiveNumber(ui.replacement, 120);
const beforeReplacement = replacementCost;
const beforeLabor = 0;
const beforeParts = 0;
const beforeTotal = beforeReplacement + beforeLabor + beforeParts;
// Failed attempts consume only 0.25 diagnostic hours and are not billed.
const afterReplacement = (1 - successRate) * replacementCost;
const afterLabor = successRate * laborHours * wage;
const afterParts = successRate * partsCost;
const afterTotal = afterReplacement + afterLabor + afterParts;
const savings = beforeTotal - afterTotal;
const replacementUnits = 1 - successRate;
ui.successReadout.textContent = `${Math.round(successRate * 100)}%`;
ui.laborNote.textContent = `${laborHours.toFixed(2)} total labor hours`;
ui.beforeTotal.textContent = money(beforeTotal);
ui.afterTotal.textContent = money(afterTotal);
ui.beforeReplacement.textContent = money(beforeReplacement);
ui.afterReplacement.textContent = money(afterReplacement);
ui.afterLabor.textContent = money(afterLabor);
ui.afterParts.textContent = money(afterParts);
ui.beforeTotalRow.textContent = money(beforeTotal);
ui.afterTotalRow.textContent = money(afterTotal);
ui.savingValue.textContent = money(Math.abs(savings));
ui.savingBox.classList.toggle("negative", savings < 0);
ui.savingLabel.textContent =
savings >= 0 ? "Expected reduction" : "Expected increase";
ui.unitValue.textContent = `1.00 → ${replacementUnits.toFixed(2)}`;
ui.unitBar.style.width = `${replacementUnits * 100}%`;
ui.combinedService.textContent =
`${money(0)} → ${money(afterLabor + afterParts)}`;
const successfulCost = laborHours * wage + partsCost;
labelSubs.get("repair").textContent =
`${Math.round(successRate * 100)}% success · ${laborHours} h · ${money(successfulCost)}`;
}
[
ui.success, ui.labor, ui.wage, ui.parts, ui.replacement
].forEach(input => input.addEventListener("input", updateModel));
updateModel();
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, reset
// -------------------------------------------------------------------------
const cameraState = {
theta: 0.69,
phi: 0.98,
radius: 24,
target: new THREE.Vector3(0, 0.8, -0.5)
};
const spherical = new THREE.Spherical();
function applyCamera() {
spherical.set(cameraState.radius, cameraState.phi, cameraState.theta);
camera.position.setFromSpherical(spherical).add(cameraState.target);
camera.lookAt(cameraState.target);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraState.theta = 0.69;
cameraState.phi = 0.98;
cameraState.radius = 24;
cameraState.target.set(0, 0.8, -0.5);
applyCamera();
}
document.getElementById("resetView").addEventListener("click", resetCamera);
const canvas = renderer.domElement;
let drag = null;
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
drag = {
id: event.pointerId,
x: event.clientX,
y: event.clientY,
startX: event.clientX,
startY: event.clientY,
moved: 0,
pan: event.button === 2 || event.shiftKey
};
});
canvas.addEventListener("pointermove", event => {
if (!drag || drag.id !== event.pointerId) return;
const dx = event.clientX - drag.x;
const dy = event.clientY - drag.y;
drag.x = event.clientX;
drag.y = event.clientY;
drag.moved += Math.abs(dx) + Math.abs(dy);
if (drag.pan) {
const factor = cameraState.radius * 0.0011;
const right = new THREE.Vector3(
Math.cos(cameraState.theta),
0,
-Math.sin(cameraState.theta)
);
const forward = new THREE.Vector3(
-Math.sin(cameraState.theta),
0,
-Math.cos(cameraState.theta)
);
cameraState.target.addScaledVector(right, -dx * factor);
cameraState.target.addScaledVector(forward, dy * factor);
cameraState.target.x = THREE.MathUtils.clamp(cameraState.target.x, -5, 5);
cameraState.target.z = THREE.MathUtils.clamp(cameraState.target.z, -5, 5);
} else {
cameraState.theta -= dx * 0.0055;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.0045,
0.43,
1.36
);
}
applyCamera();
});
canvas.addEventListener("pointerup", event => {
if (!drag || drag.id !== event.pointerId) return;
const wasClick = drag.moved < 6 && !drag.pan;
drag = null;
if (wasClick) {
const rect = canvas.getBoundingClientRect();
const pointer = new THREE.Vector2(
((event.clientX - rect.left) / rect.width) * 2 - 1,
-((event.clientY - rect.top) / rect.height) * 2 + 1
);
const raycaster = new THREE.Raycaster();
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(pickables, false);
if (intersections.length) {
const key = intersections[0].object.userData.nodeKey;
showNodeInfo(key);
}
}
});
canvas.addEventListener("pointercancel", () => { drag = null; });
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
11,
34
);
applyCamera();
}, { passive: false });
canvas.addEventListener("dblclick", resetCamera);
let nodeInfoTimer;
function showNodeInfo(key) {
const title = {
homes: "Homes & workers",
maker: "Maker & workshop",
market: "Local market",
repair: "Repair shop",
depot: "Materials depot"
}[key];
nodeInfo.innerHTML = `<b>${title}</b>${nodeDescriptions[key]}`;
nodeInfo.classList.add("visible");
clearTimeout(nodeInfoTimer);
nodeInfoTimer = setTimeout(() => {
nodeInfo.classList.remove("visible");
}, 4600);
}
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
const width = innerWidth;
const height = innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(width, height);
}
addEventListener("resize", resize);
resize();
applyCamera();
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
flows.forEach(flow => {
flow.particles.forEach((particle, index) => {
const t = (index / flow.count + elapsed * flow.speed) % 1;
particle.position.copy(flow.curve.getPointAt(t));
});
});
repairGear.rotation.z = elapsed * 0.34;
const pulse = 1 + Math.sin(elapsed * 1.8) * 0.018;
repairRing.scale.set(pulse, pulse, pulse);
camera.updateMatrixWorld();
labelElements.forEach(({ element, anchor }) => {
const projected = anchor.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.opacity = visible ? "1" : "0";
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
element.style.transform =
`translate(${x}px, ${y}px) translate(-50%, -100%)`;
});
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
document.getElementById("loading").classList.add("hidden");
</script>
</body>
</html>
```