Prompt specification
Build or customize the Three.js 3D scene "Community Resource Dashboard Diorama" 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: Community Resource Dashboard Diorama
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/community-resource-dashboard-diorama-x3975
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts resource meters, sensors, and measurement errors. Build an original neighborhood display linking physical water and energy flows to simple gauges. Distinguish direct observations from estimates and avoid invented real community data. Voxel style.
Working Three.js Starter (community-resource-dashboard-diorama-x3975):
```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 Resource Lab</title>
<style>
:root {
--ink: #112830;
--muted: #667b80;
--panel: rgba(248, 250, 245, 0.91);
--line: rgba(17, 40, 48, 0.14);
--water: #168bd0;
--energy: #f2a51b;
--error: #df5574;
--good: #138b71;
--shadow: 0 16px 42px rgba(24, 48, 55, 0.16);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce7e2;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button { font: inherit; }
#scene, #labels {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
#scene canvas:active { cursor: grabbing; }
#labels {
pointer-events: none;
overflow: hidden;
z-index: 3;
}
.panel {
position: fixed;
z-index: 5;
background: var(--panel);
border: 1px solid rgba(255, 255, 255, 0.72);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
header {
top: 18px;
left: 18px;
width: 340px;
padding: 18px 19px 16px;
border-radius: 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: #5c7377;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--good);
box-shadow: 0 0 0 3px rgba(19, 139, 113, 0.13);
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 34px);
line-height: 1;
letter-spacing: -0.045em;
}
.subtitle {
margin: 9px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.demo-strip {
display: flex;
align-items: center;
gap: 9px;
margin-top: 14px;
padding: 9px 10px;
border: 1px solid rgba(223, 85, 116, 0.22);
border-radius: 10px;
background: rgba(223, 85, 116, 0.07);
color: #8b4054;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.09em;
}
.demo-strip b {
padding: 3px 5px;
border-radius: 4px;
color: white;
background: var(--error);
font-size: 9px;
}
.toolbar {
top: 18px;
right: 18px;
display: flex;
gap: 7px;
padding: 7px;
border-radius: 14px;
}
.toolbar button {
min-height: 38px;
padding: 0 12px;
border: 0;
border-radius: 9px;
color: var(--ink);
background: transparent;
cursor: pointer;
font-size: 11px;
font-weight: 750;
transition: 160ms ease;
}
.toolbar button:hover {
background: rgba(17, 40, 48, 0.07);
}
.toolbar button.active {
color: white;
background: var(--ink);
}
.toolbar button span {
margin-left: 5px;
opacity: 0.65;
font-size: 9px;
letter-spacing: 0.08em;
}
.legend {
left: 18px;
bottom: 18px;
width: 310px;
padding: 16px 17px;
border-radius: 16px;
}
.legend h2, .inspector h2 {
margin: 0 0 12px;
font-size: 11px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 30px 1fr;
gap: 10px;
align-items: center;
margin: 10px 0;
color: #40585e;
font-size: 11px;
line-height: 1.35;
}
.symbol {
position: relative;
width: 25px;
height: 25px;
}
.symbol.solid {
border-radius: 4px;
background: var(--water);
box-shadow: inset -6px -6px rgba(0, 0, 0, 0.12);
}
.symbol.energy {
background: var(--energy);
box-shadow: inset -6px -6px rgba(0, 0, 0, 0.12);
}
.symbol.outline {
border: 2px dashed var(--error);
border-radius: 4px;
}
.symbol.error {
height: 2px;
margin-top: 11px;
background: var(--error);
}
.symbol.error::before,
.symbol.error::after {
content: "";
position: absolute;
top: -4px;
width: 2px;
height: 10px;
background: var(--error);
}
.symbol.error::before { left: 3px; }
.symbol.error::after { right: 3px; }
.legend-note {
margin: 12px 0 0;
padding-top: 11px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.inspector {
top: 84px;
right: 18px;
width: 318px;
max-height: calc(100vh - 102px);
overflow: auto;
padding: 17px;
border-radius: 17px;
}
.inspector .small {
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.resource-card {
width: 100%;
margin-top: 10px;
padding: 13px;
border: 1px solid var(--line);
border-radius: 12px;
color: var(--ink);
background: rgba(255, 255, 255, 0.52);
text-align: left;
cursor: pointer;
transition: 160ms ease;
}
.resource-card:hover {
transform: translateY(-1px);
border-color: rgba(17, 40, 48, 0.28);
background: white;
}
.resource-card .top {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
font-size: 11px;
font-weight: 800;
}
.chip {
padding: 4px 6px;
border-radius: 5px;
font-size: 8px;
letter-spacing: 0.1em;
}
.chip.water { color: #075f93; background: rgba(22, 139, 208, 0.13); }
.chip.energy { color: #8c5a00; background: rgba(242, 165, 27, 0.18); }
.card-values {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.card-values span {
display: block;
color: var(--muted);
font-size: 9px;
}
.card-values b {
display: block;
margin-top: 3px;
font-size: 17px;
letter-spacing: -0.03em;
}
.delta {
margin-top: 10px;
padding-top: 9px;
border-top: 1px solid var(--line);
color: #a13c56;
font-size: 10px;
font-weight: 750;
}
.detail-head {
display: flex;
justify-content: space-between;
gap: 10px;
align-items: flex-start;
margin-bottom: 13px;
}
.detail-head h3 {
margin: 4px 0 0;
font-size: 19px;
letter-spacing: -0.03em;
}
.detail-tag {
flex: 0 0 auto;
padding: 5px 7px;
border-radius: 6px;
color: #8b4054;
background: rgba(223, 85, 116, 0.11);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.1em;
}
.metric {
display: grid;
grid-template-columns: 1fr auto;
gap: 10px;
padding: 11px 0;
border-bottom: 1px solid var(--line);
}
.metric span {
color: var(--muted);
font-size: 10px;
}
.metric b {
font-size: 12px;
}
.uncertainty {
margin-top: 7px;
color: var(--muted);
font-size: 9px;
}
.callout {
margin-top: 14px;
padding: 12px;
border-left: 3px solid var(--error);
border-radius: 0 9px 9px 0;
background: rgba(223, 85, 116, 0.07);
color: #70485a;
font-size: 10px;
line-height: 1.55;
}
.back {
margin-bottom: 12px;
padding: 0;
border: 0;
color: var(--muted);
background: transparent;
cursor: pointer;
font-size: 10px;
}
.scene-label {
position: absolute;
left: 0;
top: 0;
padding: 6px 8px;
border-radius: 7px;
border: 1px solid rgba(255, 255, 255, 0.8);
box-shadow: 0 7px 20px rgba(16, 37, 43, 0.15);
color: white;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.07em;
white-space: nowrap;
pointer-events: auto;
cursor: pointer;
transform: translate(-50%, -50%);
transition: opacity 120ms ease;
}
.scene-label.direct {
background: rgba(17, 40, 48, 0.92);
}
.scene-label.direct.water { border-bottom: 3px solid var(--water); }
.scene-label.direct.energy { border-bottom: 3px solid var(--energy); }
.scene-label.estimate {
color: #8c3650;
border: 1px dashed var(--error);
background: rgba(255, 248, 249, 0.94);
}
.scene-label:hover { filter: brightness(1.06); }
.controls-hint {
position: fixed;
left: 50%;
bottom: 20px;
z-index: 4;
transform: translateX(-50%);
padding: 8px 12px;
border-radius: 20px;
color: rgba(255, 255, 255, 0.92);
background: rgba(17, 40, 48, 0.76);
box-shadow: 0 8px 24px rgba(16, 37, 43, 0.18);
font-size: 9px;
letter-spacing: 0.04em;
pointer-events: none;
}
@media (max-width: 800px) {
header {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 13px 15px;
}
header h1 { font-size: 23px; }
.subtitle { display: none; }
.demo-strip { margin-top: 9px; }
.toolbar {
top: 132px;
right: 10px;
}
.toolbar button {
padding: 0 9px;
font-size: 9px;
}
.legend {
display: none;
}
.inspector {
top: auto;
right: 10px;
bottom: 10px;
width: min(330px, calc(100vw - 20px));
max-height: 43vh;
}
.controls-hint { display: none; }
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive voxel neighborhood showing water and energy flows"></div>
<div id="labels"></div>
<header class="panel">
<div class="eyebrow">Resource systems lab</div>
<h1>Common Ground</h1>
<p class="subtitle">
An original voxel neighborhood connecting physical infrastructure to direct
readings, modeled estimates, and the gap between them.
</p>
<div class="demo-strip">
<b>DEMO</b>
FICTIONAL BLOCK · GENERATED VALUES · NOT REAL COMMUNITY DATA
</div>
</header>
<nav class="toolbar panel" aria-label="Scene controls">
<button id="flowToggle" class="active" aria-pressed="true">
Flows <span>ON</span>
</button>
<button id="errorToggle" class="active" aria-pressed="true">
Errors <span>ON</span>
</button>
<button id="resetView">Reset view</button>
</nav>
<section class="legend panel">
<h2>How to read the scene</h2>
<div class="legend-row">
<div class="symbol solid"></div>
<div><b>Solid sensor</b><br>Direct observation in this synthetic snapshot</div>
</div>
<div class="legend-row">
<div class="symbol outline"></div>
<div><b>Outline marker</b><br>Model estimate, not a measured value</div>
</div>
<div class="legend-row">
<div class="symbol error"></div>
<div><b>Error bracket</b><br>Estimate minus direct reading</div>
</div>
<div class="legend-row">
<div class="symbol energy"></div>
<div><b>Moving cubes</b><br>Schematic flow direction only, not measured speed</div>
</div>
<p class="legend-note">
The snapshot is frozen for comparison. Blue carries water; amber carries energy.
Every building and number belongs to a fictional teaching example.
</p>
</section>
<aside class="inspector panel" id="inspector"></aside>
<div class="controls-hint">
Drag to orbit · Scroll to zoom · Arrow keys rotate · + / − zoom · 0 resets
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Fictional demonstration data
// ------------------------------------------------------------
const data = {
water: {
id: "W-01",
resource: "water",
title: "Neighborhood inlet",
direct: 1.80,
estimate: 1.92,
uncertainty: 0.06,
unit: "m³",
max: 2.4,
location: "Water tower outlet"
},
energy: {
id: "E-01",
resource: "energy",
title: "Utility delivery meter",
direct: 4.60,
estimate: 5.00,
uncertainty: 0.18,
unit: "kWh",
max: 6.0,
location: "Utility cabinet"
},
waterBranch: {
id: "W-02",
resource: "water",
title: "Community-center branch",
direct: 0.76,
estimate: 0.81,
uncertainty: 0.04,
unit: "m³",
max: 1.1,
location: "Community center"
},
energyBranch: {
id: "E-02",
resource: "energy",
title: "East-home branch",
direct: 0.92,
estimate: 0.98,
uncertainty: 0.05,
unit: "kWh",
max: 1.3,
location: "East residence"
}
};
for (const item of Object.values(data)) {
item.difference = item.estimate - item.direct;
item.percent = item.difference / item.direct * 100;
}
// ------------------------------------------------------------
// Renderer, camera, lighting
// ------------------------------------------------------------
const sceneHost = document.getElementById("scene");
const labelHost = document.getElementById("labels");
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
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.05;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Voxel neighborhood. Drag to orbit, scroll to zoom, and click sensors for details."
);
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce7e2);
scene.fog = new THREE.Fog(0xdce7e2, 25, 44);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const controls = {
target: new THREE.Vector3(0, 1.0, 0),
theta: 0.73,
phi: 0.93,
radius: 22
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
updateCamera();
scene.add(new THREE.HemisphereLight(0xf7fff9, 0x65746c, 2.0));
const sun = new THREE.DirectionalLight(0xfff5df, 3.2);
sun.position.set(-8, 16, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const rim = new THREE.DirectionalLight(0xa8d9ff, 0.75);
rim.position.set(10, 7, -10);
scene.add(rim);
// ------------------------------------------------------------
// Materials and voxel helpers
// ------------------------------------------------------------
const materialCache = new Map();
function getMaterial(color, options = {}) {
const key = `${color}-${options.emissive || 0}-${options.opacity || 1}`;
if (!materialCache.has(key)) {
materialCache.set(key, new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.82,
metalness: options.metalness ?? 0.02,
emissive: options.emissive || 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 1,
transparent: (options.opacity ?? 1) < 1,
opacity: options.opacity ?? 1
}));
}
return materialCache.get(key);
}
function box(w, h, d, color, x, y, z, parent = scene, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
options.material || getMaterial(color, options)
);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function outlineCube(size, color = 0xdf5574, opacity = 0.8) {
const edges = new THREE.EdgesGeometry(new THREE.BoxGeometry(size, size, size));
const material = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
});
const line = new THREE.LineSegments(edges, material);
return line;
}
// ------------------------------------------------------------
// Diorama base, roads, parcels
// ------------------------------------------------------------
box(18.4, 0.65, 13.4, 0xaab7aa, 0, -0.42, 0);
box(17.9, 0.14, 12.9, 0xcbd8c8, 0, -0.04, 0);
// Main streets and pale sidewalks.
box(16.5, 0.035, 1.45, 0x697574, 0, 0.055, 1.15);
box(1.35, 0.038, 10.7, 0x697574, 2.2, 0.057, -0.3);
box(16.7, 0.05, 0.18, 0xe7e8dc, 0, 0.073, 0.36);
box(16.7, 0.05, 0.18, 0xe7e8dc, 0, 0.073, 1.94);
box(0.18, 0.052, 10.6, 0xe7e8dc, 1.46, 0.076, -0.3);
box(0.18, 0.052, 10.6, 0xe7e8dc, 2.94, 0.076, -0.3);
// Lane dashes.
for (let x = -7.5; x <= 7.5; x += 1.35) {
if (Math.abs(x - 2.2) > 0.9) {
box(0.56, 0.025, 0.07, 0xe8dda9, x, 0.09, 1.15);
}
}
for (let z = -4.9; z <= 4.6; z += 1.35) {
if (Math.abs(z - 1.15) > 0.7) {
box(0.07, 0.025, 0.56, 0xe8dda9, 2.2, 0.092, z);
}
}
// Small neighborhood parcels.
const parcelMaterial = { color: 0xb7c8ae };
for (const [x, z, w, d] of [
[-4.8, -2.4, 3.8, 3.5],
[5.3, -2.8, 3.8, 3.5],
[-4.8, 4.5, 3.8, 3.3],
[5.3, 4.4, 3.8, 3.3],
[0, -2.5, 4.6, 3.7],
[-6.9, -4.5, 3.0, 2.8],
[0, 4.6, 4.3, 2.8]
]) {
box(w, 0.045, d, parcelMaterial.color, x, 0.075, z);
}
// ------------------------------------------------------------
// Buildings
// ------------------------------------------------------------
function makeBuilding(x, z, w, d, h, bodyColor, roofColor) {
const g = new THREE.Group();
g.position.set(x, 0.1, z);
scene.add(g);
box(w, h, d, bodyColor, 0, h / 2, 0, g);
box(w + 0.22, 0.2, d + 0.22, roofColor, 0, h + 0.1, 0, g);
box(w * 0.35, 0.7, d * 0.42, bodyColor, -w * 0.18, h + 0.43, -d * 0.08, g);
// Front windows.
const windowCount = Math.max(2, Math.floor(w / 0.7));
for (let i = 0; i < windowCount; i++) {
const wx = -w / 2 + 0.55 + i * (w - 1.1) / Math.max(1, windowCount - 1);
box(0.38, 0.46, 0.045, 0x8cc7d5, wx, h * 0.56, d / 2 + 0.025, g, {
emissive: 0x173e49,
emissiveIntensity: 0.35
});
}
// Door and awning.
box(0.52, 0.9, 0.055, 0x486568, 0, 0.46, d / 2 + 0.035, g);
box(0.76, 0.08, 0.36, roofColor, 0, 1.0, d / 2 + 0.16, g);
// Side window blocks.
box(0.045, 0.46, 0.42, 0x8cc7d5, w / 2 + 0.025, h * 0.58, 0, g, {
emissive: 0x173e49,
emissiveIntensity: 0.28
});
return g;
}
makeBuilding(0, -2.45, 3.25, 2.5, 2.05, 0xd98572, 0x6e4650);
makeBuilding(-4.8, -2.45, 2.35, 2.15, 1.7, 0xdfc58f, 0x697d72);
makeBuilding(5.3, -2.85, 2.35, 2.15, 1.75, 0xb5c7ae, 0x586d69);
makeBuilding(-4.8, 4.5, 2.45, 2.15, 1.75, 0xd7b3a3, 0x6e5c73);
makeBuilding(5.3, 4.45, 2.4, 2.15, 1.8, 0xe0c78e, 0x63766e);
// Community-center sign block.
box(1.65, 0.32, 0.11, 0xf1e7cd, 0, 2.18, -1.16);
// ------------------------------------------------------------
// Voxel landscape
// ------------------------------------------------------------
function tree(x, z, scale = 1) {
const g = new THREE.Group();
g.position.set(x, 0.1, z);
g.scale.setScalar(scale);
scene.add(g);
box(0.18, 0.65, 0.18, 0x79604d, 0, 0.32, 0, g);
box(0.68, 0.5, 0.68, 0x5b8f67, 0, 0.78, 0, g);
box(0.48, 0.42, 0.48, 0x78a66d, 0.02, 1.17, 0, g);
box(0.25, 0.28, 0.25, 0x8bb377, 0, 1.48, 0, g);
}
[
[-7.9, 0.5, 0.8], [-7.7, 3.7, 0.9], [-2.9, -5.2, 0.75],
[3.5, -4.8, 0.8], [7.8, -3.6, 0.8], [7.8, 2.8, 0.75],
[3.4, 5.5, 0.8], [-2.8, 5.5, 0.7], [-0.8, 0.0, 0.65]
].forEach(p => tree(...p));
// Street lamps.
function lamp(x, z) {
box(0.11, 1.6, 0.11, 0x455b5b, x, 0.88, z);
box(0.34, 0.12, 0.34, 0xf4df9a, x, 1.72, z, scene, {
emissive: 0xffc95e,
emissiveIntensity: 0.55
});
}
lamp(-1.6, 0.08);
lamp(3.25, 0.08);
lamp(-3.0, 5.55);
lamp(6.3, 5.55);
// ------------------------------------------------------------
// Water tower and utility cabinet
// ------------------------------------------------------------
const tower = new THREE.Group();
tower.position.set(-6.9, 0.1, -4.5);
scene.add(tower);
for (const dx of [-0.5, 0.5]) {
for (const dz of [-0.5, 0.5]) {
box(0.16, 1.8, 0.16, 0x627b7e, dx, 0.9, dz, tower);
}
}
box(1.45, 1.05, 1.45, 0x74b9cd, 0, 2.25, 0, tower);
box(1.62, 0.16, 1.62, 0x3c7e93, 0, 2.84, 0, tower);
box(0.4, 0.22, 0.4, 0x48686c, 0, 3.03, 0, tower);
box(1.16, 0.16, 0.08, 0xa9d6df, 0, 2.28, 0.75, tower);
const utility = new THREE.Group();
utility.position.set(7.0, 0.1, 0.15);
scene.add(utility);
box(1.35, 0.25, 1.0, 0x8e9d96, 0, 0.13, 0, utility);
box(0.95, 1.35, 0.68, 0xe2a643, 0, 0.93, 0, utility);
box(0.62, 0.62, 0.05, 0x29484e, 0, 1.1, 0.365, utility);
box(0.37, 0.13, 0.07, 0x9de2bf, 0, 1.22, 0.405, utility, {
emissive: 0x4ecb91,
emissiveIntensity: 0.5
});
box(0.18, 0.42, 0.08, 0x39565a, 0, 0.65, 0.405, utility);
// Solar array.
const solar = new THREE.Group();
solar.position.set(-0.2, 0.1, 4.65);
scene.add(solar);
box(1.0, 0.7, 0.8, 0xb9c1b6, 0, 0.35, 0, solar);
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 3; col++) {
box(0.68, 0.09, 0.83, 0x315d77, -0.9 + col * 0.9, 0.8 + row * 0.16, 0, solar, {
metalness: 0.18,
roughness: 0.46
});
}
}
box(0.4, 0.58, 0.32, 0xf2a51b, 1.18, 0.32, 0.05, solar);
// ------------------------------------------------------------
// Flow networks
// ------------------------------------------------------------
const flowsGroup = new THREE.Group();
scene.add(flowsGroup);
const flowAnimations = [];
function addFlowRoute(points, color, particleCount = 6, speed = 1.4) {
const route = {
points: points.map(p => new THREE.Vector3(...p)),
lengths: [],
total: 0,
color,
speed,
particles: []
};
for (let i = 1; i < route.points.length; i++) {
const a = route.points[i - 1];
const b = route.points[i];
const length = a.distanceTo(b);
route.lengths.push(length);
route.total += length;
const mid = a.clone().lerp(b, 0.5);
const horizontal = Math.abs(b.x - a.x) > Math.abs(b.z - a.z);
if (horizontal) {
box(Math.abs(b.x - a.x) + 0.12, 0.11, 0.12, color,
mid.x, mid.y, mid.z, flowsGroup, { castShadow: false });
} else {
box(0.12, 0.11, Math.abs(b.z - a.z) + 0.12, color,
mid.x, mid.y, mid.z, flowsGroup, { castShadow: false });
}
}
for (let i = 0; i < particleCount; i++) {
const particle = box(0.22, 0.22, 0.22, color, 0, 0, 0, flowsGroup, {
emissive: color,
emissiveIntensity: 0.8,
castShadow: false
});
route.particles.push({
mesh: particle,
offset: route.total * i / particleCount
});
}
flowAnimations.push(route);
}
function sampleRoute(route, distance) {
let remaining = ((distance % route.total) + route.total) % route.total;
for (let i = 0; i < route.lengths.length; i++) {
if (remaining <= route.lengths[i]) {
const t = route.lengths[i] === 0 ? 0 : remaining / route.lengths[i];
return route.points[i].clone().lerp(route.points[i + 1], t);
}
remaining -= route.lengths[i];
}
return route.points[route.points.length - 1].clone();
}
// Water lines: tower to center and west branch.
addFlowRoute([
[-6.35, 0.19, -4.25],
[-6.35, 0.19, 1.72],
[-4.15, 0.19, 1.72],
[-4.15, 0.19, -0.62],
[0.15, 0.19, -0.62],
[0.15, 0.19, -1.12]
], 0x168bd0, 8, 1.15);
addFlowRoute([
[-4.15, 0.19, 1.72],
[-4.15, 0.19, 4.2],
[-3.55, 0.19, 4.2]
], 0x168bd0, 3, 1.15);
// Energy bus: solar/inverter to utility and buildings.
addFlowRoute([
[0.95, 0.23, 4.65],
[1.55, 0.23, 4.65],
[1.55, 0.23, 1.82],
[6.95, 0.23, 1.82],
[6.95, 0.23, 0.55]
], 0xf2a51b, 8, 1.45);
addFlowRoute([
[4.15, 0.23, 1.82],
[4.15, 0.23, -1.55],
[4.15, 0.23, -2.0]
], 0xf2a51b, 3, 1.35);
// ------------------------------------------------------------
// Sensors, estimate markers, and error brackets
// ------------------------------------------------------------
const sensorsGroup = new THREE.Group();
const errorsGroup = new THREE.Group();
scene.add(sensorsGroup, errorsGroup);
const pickables = [];
const markerItems = [];
function addMarker(text, position, kind, resource, info) {
const el = document.createElement("button");
el.className = `scene-label ${kind} ${resource}`;
el.textContent = text;
el.setAttribute("aria-label", text);
el.addEventListener("click", () => showDetail(info));
labelHost.appendChild(el);
markerItems.push({ el, position: position.clone() });
}
function makeDirectSensor(position, info) {
const group = new THREE.Group();
group.position.copy(position);
group.userData.selectable = true;
group.userData.info = info;
sensorsGroup.add(group);
const color = info.resource === "water" ? 0x168bd0 : 0xf2a51b;
box(0.13, 0.65, 0.13, 0x50696b, 0, 0.32, 0, group);
box(0.42, 0.43, 0.3, 0xe7eee8, 0, 0.78, 0, group);
box(0.27, 0.2, 0.045, color, 0, 0.83, 0.17, group, {
emissive: color,
emissiveIntensity: 0.65
});
box(0.09, 0.09, 0.09, color, 0, 1.08, 0, group, {
emissive: color,
emissiveIntensity: 0.9
});
pickables.push(group);
return group;
}
function makeEstimateAndError(position, info, label = true) {
const estimatePosition = position.clone().add(new THREE.Vector3(0, 0.95, 0));
const estimate = outlineCube(0.62, 0xdf5574, 0.9);
estimate.position.copy(estimatePosition);
estimate.userData.selectable = true;
estimate.userData.info = info;
errorsGroup.add(estimate);
pickables.push(estimate);
const lineGeometry = new THREE.BufferGeometry().setFromPoints([
position.clone().add(new THREE.Vector3(0, 0.85, 0)),
estimatePosition.clone().add(new THREE.Vector3(0, -0.36, 0))
]);
const lineMaterial = new THREE.LineDashedMaterial({
color: 0xdf5574,
dashSize: 0.13,
gapSize: 0.09,
transparent: true,
opacity: 0.9
});
const errorLine = new THREE.Line(lineGeometry, lineMaterial);
errorLine.computeLineDistances();
errorsGroup.add(errorLine);
if (label) {
const sign = info.percent >= 0 ? "+" : "";
addMarker(
`${info.id} ESTIMATE ${sign}${info.percent.toFixed(1)}%`,
estimatePosition.clone().add(new THREE.Vector3(0, 0.5, 0)),
"estimate",
info.resource,
info
);
}
}
const waterSensorPos = new THREE.Vector3(-6.35, 0.1, -4.1);
const energySensorPos = new THREE.Vector3(6.8, 0.1, 0.15);
const waterBranchPos = new THREE.Vector3(0.15, 0.1, -1.12);
const energyBranchPos = new THREE.Vector3(4.15, 0.1, -2.0);
makeDirectSensor(waterSensorPos, data.water);
makeDirectSensor(energySensorPos, data.energy);
makeDirectSensor(waterBranchPos, data.waterBranch);
makeDirectSensor(energyBranchPos, data.energyBranch);
makeEstimateAndError(waterSensorPos, data.water);
makeEstimateAndError(energySensorPos, data.energy);
makeEstimateAndError(waterBranchPos, data.waterBranch, false);
makeEstimateAndError(energyBranchPos, data.energyBranch, false);
addMarker(
"W-01 DIRECT",
waterSensorPos.clone().add(new THREE.Vector3(-0.55, 1.55, 0)),
"direct",
"water",
data.water
);
addMarker(
"E-01 DIRECT",
energySensorPos.clone().add(new THREE.Vector3(0.6, 1.55, 0)),
"direct",
"energy",
data.energy
);
addMarker(
"W-02 DIRECT",
waterBranchPos.clone().add(new THREE.Vector3(-0.55, 1.25, 0)),
"direct",
"water",
data.waterBranch
);
addMarker(
"E-02 DIRECT",
energyBranchPos.clone().add(new THREE.Vector3(0.65, 1.25, 0)),
"direct",
"energy",
data.energyBranch
);
// ------------------------------------------------------------
// In-world meter boards
// ------------------------------------------------------------
const meterCanvases = [];
function drawMeter(meter) {
const { ctx, canvas, item } = meter;
const w = canvas.width;
const h = canvas.height;
ctx.clearRect(0, 0, w, h);
ctx.fillStyle = "#102a33";
ctx.fillRect(0, 0, w, h);
ctx.fillStyle = item.resource === "water" ? "#47b9ee" : "#ffc34e";
ctx.fillRect(0, 0, 9, h);
ctx.fillStyle = "#eaf3ef";
ctx.font = "700 25px system-ui";
ctx.fillText(item.resource === "water" ? "WATER DELIVERY" : "ENERGY DELIVERY", 28, 43);
ctx.fillStyle = "#8ca5aa";
ctx.font = "700 13px system-ui";
ctx.fillText("FICTIONAL DEMO SNAPSHOT", 28, 65);
const left = 28;
const barWidth = 450;
const scale = barWidth / item.max;
function drawBar(label, value, color, y, dashed = false) {
ctx.fillStyle = "#91a9ad";
ctx.font = "600 14px system-ui";
ctx.fillText(label, left, y);
ctx.fillStyle = "#1d3b43";
ctx.fillRect(left, y + 11, barWidth, 25);
const width = Math.min(barWidth, value * scale);
ctx.fillStyle = color;
ctx.fillRect(left, y + 11, width, 25);
if (dashed) {
ctx.strokeStyle = "#ffd7e1";
ctx.lineWidth = 2;
ctx.setLineDash([8, 6]);
ctx.strokeRect(left, y + 11, width, 25);
ctx.setLineDash([]);
}
ctx.fillStyle = "#f3f8f5";
ctx.font = "700 14px system-ui";
ctx.textAlign = "right";
ctx.fillText(`${value.toFixed(2)} ${item.unit}`, w - 28, y + 29);
ctx.textAlign = "left";
}
drawBar("DIRECT OBSERVATION", item.direct, "#40b8ec", 94, false);
// Uncertainty band around the direct observation.
const uncertaintyWidth = Math.max(8, item.uncertainty * scale * 2);
const center = left + item.direct * scale;
ctx.fillStyle = "rgba(255,255,255,.38)";
ctx.fillRect(center - uncertaintyWidth / 2, 104, uncertaintyWidth, 39);
drawBar("MODEL ESTIMATE", item.estimate, "#d95c79", 166, true);
ctx.fillStyle = "#91a9ad";
ctx.font = "600 13px system-ui";
ctx.fillText(
`Observed uncertainty ±${item.uncertainty.toFixed(2)} ${item.unit}`,
left, 238
);
ctx.fillStyle = "#e97894";
ctx.font = "800 20px system-ui";
const sign = item.difference >= 0 ? "+" : "";
ctx.fillText(
`MODEL ERROR ${sign}${item.difference.toFixed(2)} ${item.unit} (${sign}${item.percent.toFixed(1)}%)`,
left, 276
);
ctx.fillStyle = "#718e94";
ctx.font = "600 12px system-ui";
ctx.fillText("Estimate minus direct reading · generated example", left, 302);
meter.texture.needsUpdate = true;
}
function makeMeter(position, item) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 320;
const ctx = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: true,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.position.copy(position);
sprite.scale.set(3.15, 1.97, 1);
sprite.userData.selectable = true;
sprite.userData.info = item;
scene.add(sprite);
pickables.push(sprite);
const meter = { canvas, ctx, item, texture };
meterCanvases.push(meter);
drawMeter(meter);
return meter;
}
makeMeter(new THREE.Vector3(-5.55, 3.25, -4.45), data.water);
makeMeter(new THREE.Vector3(6.2, 2.85, 0.15), data.energy);
// ------------------------------------------------------------
// Inspector UI
// ------------------------------------------------------------
const inspector = document.getElementById("inspector");
function overviewHTML() {
return `
<h2>Neighborhood overview</h2>
<p class="small">
Select a solid sensor or outline estimate in the scene to compare a
direct observation with a modeled result.
</p>
<button class="resource-card" data-select="water">
<div class="top">
<span>Water inlet</span>
<span class="chip water">WATER</span>
</div>
<div class="card-values">
<div><span>Direct</span><b>1.80 m³</b></div>
<div><span>Estimate</span><b>1.92 m³</b></div>
</div>
<div class="delta">Difference +0.12 m³ · +6.7%</div>
</button>
<button class="resource-card" data-select="energy">
<div class="top">
<span>Utility delivery</span>
<span class="chip energy">ENERGY</span>
</div>
<div class="card-values">
<div><span>Direct</span><b>4.60 kWh</b></div>
<div><span>Estimate</span><b>5.00 kWh</b></div>
</div>
<div class="delta">Difference +0.40 kWh · +8.7%</div>
</button>
<div class="callout">
<b>Not real utility data.</b> This is a fictional block made to
demonstrate measurement uncertainty and model error.
</div>
`;
}
function showOverview() {
inspector.innerHTML = overviewHTML();
inspector.querySelectorAll("[data-select]").forEach(button => {
button.addEventListener("click", () => showDetail(data[button.dataset.select]));
});
}
function showDetail(item) {
const sign = item.difference >= 0 ? "+" : "";
const interpretation = item.difference >= 0
? "The model is higher than the direct reading in this example."
: "The model is lower than the direct reading in this example.";
inspector.innerHTML = `
<button class="back" id="backButton">← All readings</button>
<div class="detail-head">
<div>
<span class="chip ${item.resource}">
${item.resource.toUpperCase()} · ${item.id}
</span>
<h3>${item.title}</h3>
</div>
<span class="detail-tag">${item.id === "W-01" || item.id === "E-01"
? "MAIN SENSOR" : "BRANCH SENSOR"}</span>
</div>
<p class="small">${item.location}</p>
<div class="metric">
<span>Direct observation</span>
<b>${item.direct.toFixed(2)} ${item.unit}</b>
</div>
<div class="uncertainty">
Displayed sensor uncertainty: ±${item.uncertainty.toFixed(2)} ${item.unit}
</div>
<div class="metric">
<span>Model estimate</span>
<b>${item.estimate.toFixed(2)} ${item.unit}</b>
</div>
<div class="metric">
<span>Estimate minus direct reading</span>
<b style="color:#a13c56">
${sign}${item.difference.toFixed(2)} ${item.unit}
</b>
</div>
<div class="uncertainty">
Relative model difference: ${sign}${item.percent.toFixed(1)}%
</div>
<div class="callout">
<b>Reading the error.</b> ${interpretation} Error is defined here as
estimate − direct reading. The moving flow cubes are schematic and
do not represent measured velocity.
</div>
<p class="small" style="margin-bottom:0">
<b>Synthetic demonstration:</b> this neighborhood does not exist,
and all sensor readings and estimates were generated only to show
how a direct observation can differ from a model.
</p>
`;
document.getElementById("backButton").addEventListener("click", showOverview);
}
showOverview();
// ------------------------------------------------------------
// Toolbar behavior
// ------------------------------------------------------------
const flowToggle = document.getElementById("flowToggle");
const errorToggle = document.getElementById("errorToggle");
flowToggle.addEventListener("click", () => {
flowsGroup.visible = !flowsGroup.visible;
flowToggle.classList.toggle("active", flowsGroup.visible);
flowToggle.setAttribute("aria-pressed", String(flowsGroup.visible));
flowToggle.querySelector("span").textContent = flowsGroup.visible ? "ON" : "OFF";
});
errorToggle.addEventListener("click", () => {
errorsGroup.visible = !errorsGroup.visible;
errorToggle.classList.toggle("active", errorsGroup.visible);
errorToggle.setAttribute("aria-pressed", String(errorsGroup.visible));
errorToggle.querySelector("span").textContent = errorsGroup.visible ? "ON" : "OFF";
});
function resetView() {
controls.theta = 0.73;
controls.phi = 0.93;
controls.radius = 22;
controls.target.set(0, 1.0, 0);
updateCamera();
}
document.getElementById("resetView").addEventListener("click", resetView);
// ------------------------------------------------------------
// Direct camera controls and picking
// ------------------------------------------------------------
let dragging = false;
let pointerMoved = false;
let lastX = 0;
let lastY = 0;
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
pointerMoved = false;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (Math.abs(dx) + Math.abs(dy) > 1) pointerMoved = true;
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(controls.phi - dy * 0.005, 0.38, 1.32);
updateCamera();
});
renderer.domElement.addEventListener("pointerup", event => {
dragging = false;
if (!pointerMoved) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickables, true);
if (hits.length) {
let object = hits[0].object;
while (object && !object.userData.selectable) object = object.parent;
if (object?.userData.info) showDetail(object.userData.info);
}
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
12,
31
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetView);
renderer.domElement.addEventListener("keydown", event => {
let handled = true;
switch (event.key) {
case "ArrowLeft": controls.theta -= 0.09; break;
case "ArrowRight": controls.theta += 0.09; break;
case "ArrowUp": controls.phi = Math.max(0.38, controls.phi - 0.07); break;
case "ArrowDown": controls.phi = Math.min(1.32, controls.phi + 0.07); break;
case "+":
case "=": controls.radius = Math.max(12, controls.radius - 1); break;
case "-": controls.radius = Math.min(31, controls.radius + 1); break;
case "0": resetView(); break;
default: handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const marker of markerItems) {
projected.copy(marker.position).project(camera);
const visible = projected.z > -1 && projected.z < 1;
marker.el.style.display = visible ? "block" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
marker.el.style.left = `${x}px`;
marker.el.style.top = `${y}px`;
marker.el.style.opacity =
projected.z > 0.92 ? String(Math.max(0, (1 - projected.z) / 0.08)) : "1";
}
}
}
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
for (const route of flowAnimations) {
for (const particle of route.particles) {
const position = sampleRoute(
route,
elapsed * route.speed + particle.offset
);
particle.mesh.position.copy(position);
particle.mesh.position.y += Math.sin(elapsed * 4 + particle.offset) * 0.025;
}
}
// A subtle LED pulse; values themselves remain a frozen comparison.
sensorsGroup.children.forEach((group, index) => {
const led = group.children[2];
if (led?.material?.emissiveIntensity !== undefined) {
led.material.emissiveIntensity = 0.55 + Math.sin(elapsed * 2.2 + index) * 0.12;
}
});
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```