Prompt specification
Build or customize the Three.js 3D scene "Two Supply Paths and a Local Reserve" 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: Two Supply Paths and a Local Reserve
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/two-supply-paths-and-a-local-reserve-x3961
Scene Description Prompt:
Two supply paths and a local reserve. Model a service point connected to two sources and a local storage tank. Show independent links and keep reserve capacity separate from supply rate. Please build this with Three.js from cdnjs in one self-contained HTML file, using stylized solid shapes.
Working Three.js Starter (two-supply-paths-and-a-local-reserve-x3961):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dual Supply and Local Reserve</title>
<style>
:root {
--ink: #172b36;
--muted: #627781;
--panel: rgba(249, 252, 252, 0.94);
--line: #d9e3e7;
--source-a: #247fd1;
--source-b: #8058d6;
--reserve: #ee9b27;
--good: #16876e;
--bad: #cf4d49;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8eff1;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage,
#labels {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#stage canvas:active {
cursor: grabbing;
}
#labels {
z-index: 3;
pointer-events: none;
overflow: hidden;
}
.world-label {
position: absolute;
min-width: 132px;
padding: 9px 11px;
border: 1px solid rgba(255, 255, 255, 0.86);
border-radius: 10px;
background: rgba(248, 251, 251, 0.91);
box-shadow: 0 8px 24px rgba(28, 50, 62, 0.13);
backdrop-filter: blur(8px);
transform: translate(-50%, -100%);
text-align: center;
transition: opacity 120ms ease;
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -7px;
width: 12px;
height: 12px;
border-right: 1px solid rgba(255, 255, 255, 0.86);
border-bottom: 1px solid rgba(255, 255, 255, 0.86);
background: rgba(248, 251, 251, 0.91);
transform: translateX(-50%) rotate(45deg);
}
.world-label strong {
display: block;
margin-bottom: 3px;
font-size: 11px;
line-height: 1.1;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.world-label span {
display: block;
color: var(--muted);
font-size: 12px;
font-weight: 650;
white-space: nowrap;
}
.world-label.a {
border-top: 3px solid var(--source-a);
}
.world-label.b {
border-top: 3px solid var(--source-b);
}
.world-label.reserve {
border-top: 3px solid var(--reserve);
}
.world-label.service {
border-top: 3px solid #264653;
}
.world-label.link {
min-width: 116px;
padding: 7px 10px;
}
.world-label.link strong {
margin: 0;
font-size: 9px;
}
.world-label.link span {
margin-top: 2px;
font-size: 11px;
}
#panel {
position: fixed;
z-index: 5;
top: 18px;
right: 18px;
width: 326px;
max-height: calc(100vh - 36px);
overflow: auto;
padding: 18px;
border: 1px solid rgba(255, 255, 255, 0.9);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(30, 53, 64, 0.18);
backdrop-filter: blur(13px);
}
.eyebrow {
margin: 0 0 5px;
color: #55707d;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 22px;
line-height: 1.08;
letter-spacing: -0.035em;
}
.subtitle {
margin: 8px 0 15px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.status {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 14px;
padding: 10px 11px;
border: 1px solid #cae5dd;
border-radius: 10px;
background: #eaf7f2;
color: var(--good);
font-size: 12px;
font-weight: 750;
}
.status::before {
content: "";
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 15%, transparent);
}
.status.warning {
border-color: #f1d8ac;
background: #fff6e6;
color: #a66b08;
}
.status.danger {
border-color: #efc5c3;
background: #fff0ef;
color: var(--bad);
}
.control {
margin-top: 13px;
}
.control-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 7px;
}
.control-row label {
color: #405963;
font-size: 12px;
font-weight: 750;
}
.control-row output {
font-variant-numeric: tabular-nums;
font-size: 12px;
font-weight: 800;
}
.dot {
display: inline-block;
width: 8px;
height: 8px;
margin-right: 6px;
border-radius: 50%;
vertical-align: 1px;
}
.dot.a {
background: var(--source-a);
}
.dot.b {
background: var(--source-b);
}
.dot.reserve {
background: var(--reserve);
}
input[type="range"] {
--fill: 50%;
width: 100%;
height: 6px;
margin: 0;
border-radius: 999px;
outline: none;
appearance: none;
background:
linear-gradient(
to right,
var(--accent) 0%,
var(--accent) var(--fill),
#dbe4e8 var(--fill),
#dbe4e8 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
border: 3px solid #fff;
border-radius: 50%;
appearance: none;
background: var(--accent);
box-shadow: 0 2px 7px rgba(24, 43, 54, 0.25);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid #fff;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 2px 7px rgba(24, 43, 54, 0.25);
}
#source-a {
--accent: var(--source-a);
}
#source-b {
--accent: var(--source-b);
}
#reserve-rate {
--accent: var(--reserve);
}
.reserve-box {
margin-top: 16px;
padding: 13px;
border: 1px solid #e6d6b9;
border-radius: 11px;
background: #fff9ef;
}
.reserve-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 9px;
}
.reserve-heading strong {
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.reserve-heading span {
color: #99610d;
font-size: 11px;
font-weight: 750;
}
.capacity-line {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-bottom: 8px;
color: #6c5a3a;
font-size: 11px;
}
.capacity-line b {
color: var(--ink);
font-size: 17px;
font-variant-numeric: tabular-nums;
}
.meter {
height: 8px;
overflow: hidden;
border-radius: 999px;
background: #eadfc9;
}
.meter-fill {
width: 73.33%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #f4b64c, #e68a17);
transition: width 150ms ease;
}
.capacity-note {
margin: 9px 0 0;
color: #826f4e;
font-size: 10px;
line-height: 1.4;
}
.network-readout {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px 14px;
margin-top: 15px;
padding-top: 14px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 11px;
}
.network-readout b {
color: var(--ink);
font-variant-numeric: tabular-nums;
}
.actions {
display: flex;
gap: 8px;
margin-top: 14px;
}
button {
flex: 1;
padding: 9px 10px;
border: 1px solid #d6e1e5;
border-radius: 9px;
background: #fff;
color: #36515d;
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
}
button:hover {
border-color: #afc2ca;
background: #f7fafb;
}
.help {
margin: 11px 0 0;
color: #7a8d95;
font-size: 10px;
line-height: 1.4;
}
#legend {
position: fixed;
z-index: 4;
bottom: 18px;
left: 18px;
display: flex;
flex-wrap: wrap;
gap: 7px 13px;
max-width: min(560px, calc(100vw - 390px));
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.88);
border-radius: 11px;
background: rgba(249, 252, 252, 0.88);
box-shadow: 0 8px 25px rgba(28, 50, 62, 0.1);
backdrop-filter: blur(8px);
color: #536a74;
font-size: 10px;
font-weight: 700;
}
.legend-item {
white-space: nowrap;
}
@media (max-width: 760px) {
#panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 43vh;
padding: 14px;
}
h1 {
font-size: 19px;
}
#legend {
top: 10px;
bottom: auto;
left: 10px;
max-width: calc(100vw - 20px);
}
.world-label.link {
display: none;
}
.world-label {
min-width: 105px;
padding: 7px 9px;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div id="labels">
<div class="world-label a" id="label-a">
<strong>Source A</strong>
<span id="label-a-value">55 m³/h</span>
</div>
<div class="world-label b" id="label-b">
<strong>Source B</strong>
<span id="label-b-value">45 m³/h</span>
</div>
<div class="world-label reserve" id="label-reserve">
<strong>Local Reserve</strong>
<span id="label-reserve-value">300 m³ capacity</span>
<span id="label-reserve-rate">0 m³/h discharge</span>
</div>
<div class="world-label service" id="label-service">
<strong>Service Point</strong>
<span>120 m³/h demand</span>
</div>
<div class="world-label link a" id="link-a">
<strong>Supply A · Independent</strong>
<span id="link-a-value">55 m³/h</span>
</div>
<div class="world-label link b" id="link-b">
<strong>Supply B · Independent</strong>
<span id="link-b-value">45 m³/h</span>
</div>
<div class="world-label link reserve" id="link-reserve">
<strong>Reserve Link</strong>
<span id="link-reserve-value">0 m³/h</span>
</div>
</div>
<aside id="panel">
<p class="eyebrow">Water Network Model</p>
<h1>Dual supply with local reserve</h1>
<p class="subtitle">
Two independent supply paths feed the service point. The storage tank
discharges only when the incoming sources cannot meet demand.
</p>
<div class="status" id="status">System balanced</div>
<div class="control">
<div class="control-row">
<label for="source-a">
<span class="dot a"></span>Source A supply rate
</label>
<output id="source-a-output">55 m³/h</output>
</div>
<input
id="source-a"
type="range"
min="0"
max="120"
step="1"
value="55"
aria-label="Source A supply rate"
>
</div>
<div class="control">
<div class="control-row">
<label for="source-b">
<span class="dot b"></span>Source B supply rate
</label>
<output id="source-b-output">45 m³/h</output>
</div>
<input
id="source-b"
type="range"
min="0"
max="120"
step="1"
value="45"
aria-label="Source B supply rate"
>
</div>
<div class="control">
<div class="control-row">
<label for="reserve-rate">
<span class="dot reserve"></span>Maximum reserve discharge
</label>
<output id="reserve-rate-output">30 m³/h</output>
</div>
<input
id="reserve-rate"
type="range"
min="0"
max="120"
step="1"
value="30"
aria-label="Maximum reserve discharge rate"
>
</div>
<div class="reserve-box">
<div class="reserve-heading">
<strong>Reserve Capacity</strong>
<span>Stored volume</span>
</div>
<div class="capacity-line">
<span><b id="reserve-volume">220</b> / 300 m³</span>
<span id="reserve-percent">73%</span>
</div>
<div class="meter">
<div class="meter-fill" id="reserve-meter"></div>
</div>
<p class="capacity-note">
Capacity is a stored-volume limit in m³. Discharge is a separate
transfer rate in m³/h.
</p>
</div>
<div class="network-readout">
<span>Total source supply</span>
<b id="total-supply">100 m³/h</b>
<span>Actual reserve discharge</span>
<b id="actual-reserve">20 m³/h</b>
<span>Unmet demand</span>
<b id="unmet-demand">0 m³/h</b>
</div>
<div class="actions">
<button id="reset-model" type="button">Reset model</button>
<button id="reset-view" type="button">Reset view</button>
</div>
<p class="help">
Drag to orbit, Shift-drag to pan, and use the wheel to zoom.
All geometry and flow indicators are rendered from solid Three.js shapes.
</p>
</aside>
<div id="legend">
<span class="legend-item"><span class="dot a"></span>Independent source A</span>
<span class="legend-item"><span class="dot b"></span>Independent source B</span>
<span class="legend-item"><span class="dot reserve"></span>Local reserve discharge</span>
<span class="legend-item">Arrows show active flow direction</span>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Application state
// ------------------------------------------------------------
const COLORS = {
ground: 0xdde7e9,
groundEdge: 0xc7d5d9,
concrete: 0xe7ecec,
service: 0xf7faf9,
roof: 0x273b45,
window: 0x91c7db,
sourceA: 0x247fd1,
sourceB: 0x8058d6,
reserve: 0xee9b27,
steel: 0x83969e,
darkSteel: 0x435861,
paleBlue: 0xcce3ee,
palePurple: 0xe0d8f2,
paleAmber: 0xf5e4c4
};
const state = {
sourceA: 55,
sourceB: 45,
reserveLimit: 30,
demand: 120,
capacity: 300,
volume: 220,
actualA: 55,
actualB: 45,
actualReserve: 20,
unmet: 0
};
const stage = document.querySelector("#stage");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8eff1);
scene.fog = new THREE.Fog(0xe8eff1, 35, 70);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
120
);
// Camera controls are implemented locally, without addons.
const cameraTarget = new THREE.Vector3(0, 1.1, 1.2);
const desiredCamera = {
theta: 0.56,
phi: 0.87,
radius: 31,
target: cameraTarget.clone()
};
const currentCamera = {
theta: desiredCamera.theta,
phi: desiredCamera.phi,
radius: desiredCamera.radius,
target: desiredCamera.target.clone()
};
function updateCamera(dt) {
const damping = 1 - Math.exp(-9 * dt);
currentCamera.theta +=
(desiredCamera.theta - currentCamera.theta) * damping;
currentCamera.phi +=
(desiredCamera.phi - currentCamera.phi) * damping;
currentCamera.radius +=
(desiredCamera.radius - currentCamera.radius) * damping;
currentCamera.target.lerp(desiredCamera.target, damping);
const spherical = new THREE.Spherical(
currentCamera.radius,
currentCamera.phi,
currentCamera.theta
);
camera.position.setFromSpherical(spherical).add(currentCamera.target);
camera.lookAt(currentCamera.target);
}
function resetView() {
desiredCamera.theta = 0.56;
desiredCamera.phi = 0.87;
desiredCamera.radius = 31;
desiredCamera.target.set(0, 1.1, 1.2);
}
let pointerDown = false;
let shiftDown = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerDown = true;
shiftDown = event.shiftKey;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerDown) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
if (shiftDown) {
const right = new THREE.Vector3();
const up = new THREE.Vector3();
camera.matrixWorld.extractBasis(right, up, new THREE.Vector3());
const panScale = currentCamera.radius * 0.0014;
desiredCamera.target.addScaledVector(right, -dx * panScale);
desiredCamera.target.addScaledVector(up, dy * panScale);
desiredCamera.target.x = THREE.MathUtils.clamp(
desiredCamera.target.x,
-10,
10
);
desiredCamera.target.z = THREE.MathUtils.clamp(
desiredCamera.target.z,
-8,
12
);
} else {
desiredCamera.theta -= dx * 0.006;
desiredCamera.phi = THREE.MathUtils.clamp(
desiredCamera.phi - dy * 0.005,
0.3,
1.35
);
}
});
function endPointer(event) {
pointerDown = false;
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredCamera.radius = THREE.MathUtils.clamp(
desiredCamera.radius * Math.exp(event.deltaY * 0.001),
13,
49
);
},
{ passive: false }
);
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xffffff, 0x78909a, 2.1));
const sun = new THREE.DirectionalLight(0xfff7e8, 3.2);
sun.position.set(-13, 22, 15);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 60;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbdd9ee, 1.2);
fill.position.set(18, 10, -18);
scene.add(fill);
// ------------------------------------------------------------
// Geometry helpers
// ------------------------------------------------------------
function material(color, roughness = 0.72, metalness = 0.04) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness
});
}
function addBox(
width,
height,
depth,
color,
x,
y,
z,
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
radius,
height,
color,
x,
y,
z,
segments = 24,
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, segments),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addSphere(
radius,
color,
x,
y,
z,
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(radius, 20, 12),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addHorizontalRing(
radius,
tube,
color,
x,
y,
z,
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.TorusGeometry(radius, tube, 8, 32),
material(color, 0.5, 0.2)
);
mesh.position.set(x, y, z);
mesh.rotation.x = Math.PI / 2;
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
const up = new THREE.Vector3(0, 1, 0);
function cylinderBetween(a, b, radius, color, parent = scene) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 12),
material(color, 0.48, 0.22)
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
up,
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Site and buildings
// ------------------------------------------------------------
addBox(32, 0.45, 29, COLORS.ground, 0, -0.28, 1.6);
addBox(32.4, 0.18, 29.4, COLORS.groundEdge, 0, -0.53, 1.6);
// Service-point platform.
addBox(6.2, 0.18, 5.1, 0xd4e0e3, 0, 0.02, 0.3);
// Service building.
addBox(4.2, 2.45, 3.2, COLORS.service, 0, 1.42, 0);
addBox(4.55, 0.23, 3.55, COLORS.roof, 0, 2.75, 0);
addBox(0.72, 1.65, 0.12, COLORS.darkSteel, 0, 1.02, 1.66);
addBox(0.56, 1.43, 0.08, 0x87afbd, 0, 1.06, 1.74);
for (const x of [-1.35, 1.35]) {
for (const y of [1.15, 1.85]) {
addBox(0.68, 0.43, 0.1, COLORS.window, x, y, 1.66);
}
}
// Roof service manifold.
addCylinder(0.52, 0.42, COLORS.darkSteel, 0, 3.08, 0);
addSphere(0.52, COLORS.service, 0, 3.31, 0).scale.y = 0.55;
// Emblem on the front of the service building.
const emblem = addCylinder(
0.48,
0.1,
COLORS.window,
0,
2.0,
1.7,
32
);
emblem.rotation.x = Math.PI / 2;
addBox(0.12, 0.48, 0.05, COLORS.service, 0, 2.0, 1.78);
addBox(0.34, 0.12, 0.05, COLORS.service, 0, 2.0, 1.78);
// Source A: storage-style source station.
addBox(6.0, 0.16, 5.2, COLORS.paleBlue, -10.5, 0.04, -6);
addCylinder(1.52, 2.5, 0xa7c3cf, -11.0, 1.46, -6);
const domeA = addSphere(1.52, 0xc7d8de, -11.0, 2.72, -6);
domeA.scale.y = 0.48;
addHorizontalRing(1.55, 0.07, 0x667d87, -11.0, 1.0, -6);
addHorizontalRing(1.55, 0.07, 0x667d87, -11.0, 2.05, -6);
addBox(1.45, 1.15, 1.45, COLORS.sourceA, -8.9, 0.79, -6);
addBox(1.7, 0.15, 1.7, COLORS.darkSteel, -8.9, 1.44, -6);
addCylinder(0.13, 1.8, COLORS.darkSteel, -12.1, 4.0, -6.6);
addCylinder(0.25, 0.18, COLORS.sourceA, -12.1, 4.93, -6.6);
// Source B: alternate industrial source building.
addBox(6.0, 0.16, 5.2, COLORS.palePurple, 10.5, 0.04, -6);
addBox(3.7, 2.25, 3.25, 0xb7a9ce, 11.0, 1.31, -6);
addBox(4.1, 0.23, 3.65, COLORS.darkSteel, 11.0, 2.54, -6);
addBox(1.0, 1.55, 0.1, COLORS.sourceB, 11.0, 1.12, -4.36);
addBox(1.5, 0.16, 0.15, COLORS.roof, 11.0, 1.0, -4.27);
for (const x of [10.0, 11.25]) {
addCylinder(0.34, 2.1, 0x8e80aa, x, 1.25, -7.9);
addCylinder(0.42, 0.18, COLORS.sourceB, x, 2.37, -7.9);
}
// Local storage tank.
addBox(5.2, 0.18, 5.2, COLORS.paleAmber, 0, 0.04, 10);
addCylinder(1.7, 3.35, 0xd9dfe0, 0, 2.0, 10, 32);
const tankDome = addSphere(1.7, 0xe8ecec, 0, 3.67, 10);
tankDome.scale.y = 0.4;
for (const y of [0.7, 1.7, 2.7, 3.45]) {
addHorizontalRing(1.73, 0.065, 0x6f8289, 0, y, 10);
}
for (const x of [-1.08, 1.08]) {
for (const z of [8.92, 11.08]) {
addBox(0.18, 0.85, 0.18, COLORS.darkSteel, x, 0.43, z);
}
}
// External reserve-level gauge: capacity is represented spatially and
// is intentionally separate from the discharge-rate control.
addBox(0.75, 2.65, 0.12, COLORS.darkSteel, 0, 2.05, 11.73);
const gaugeCells = [];
for (let i = 0; i < 10; i++) {
const cellMaterial = new THREE.MeshStandardMaterial({
color: i < 8 ? COLORS.reserve : 0x596970,
roughness: 0.55,
emissive: i < 8 ? 0x5b2b00 : 0x000000,
emissiveIntensity: i < 8 ? 0.08 : 0
});
const cell = new THREE.Mesh(
new THREE.BoxGeometry(0.46, 0.16, 0.08),
cellMaterial
);
cell.position.set(0, 0.95 + i * 0.245, 11.82);
cell.castShadow = true;
scene.add(cell);
gaugeCells.push(cell);
}
// ------------------------------------------------------------
// Independent pipe paths
// ------------------------------------------------------------
const flowGroups = [];
function createPipePath(points, color) {
const group = new THREE.Group();
scene.add(group);
for (let i = 0; i < points.length - 1; i++) {
cylinderBetween(
points[i],
points[i + 1],
0.14,
color,
group
);
}
for (let i = 1; i < points.length - 1; i++) {
addSphere(0.215, color, points[i].x, points[i].y, points[i].z, group);
}
// Pipe support feet.
for (let i = 1; i < points.length - 1; i += 2) {
const point = points[i];
addBox(
0.52,
0.12,
0.52,
COLORS.steel,
point.x,
0.18,
point.z,
group
);
cylinderBetween(
new THREE.Vector3(point.x, 0.2, point.z),
new THREE.Vector3(point.x, point.y - 0.1, point.z),
0.065,
COLORS.steel,
group
);
}
const lengths = [];
let totalLength = 0;
for (let i = 0; i < points.length - 1; i++) {
const length = points[i].distanceTo(points[i + 1]);
lengths.push(length);
totalLength += length;
}
const markerMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
emissive: color,
emissiveIntensity: 0.38,
roughness: 0.35,
metalness: 0.1
});
const markers = [];
for (let i = 0; i < 4; i++) {
const marker = new THREE.Mesh(
new THREE.ConeGeometry(0.19, 0.48, 10),
markerMaterial
);
marker.castShadow = true;
group.add(marker);
markers.push(marker);
}
const result = {
group,
points,
lengths,
totalLength,
markers,
phase: 0
};
flowGroups.push(result);
return result;
}
function samplePipe(path, normalizedPosition) {
let distance =
((normalizedPosition % 1) + 1) % 1 * path.totalLength;
for (let i = 0; i < path.lengths.length; i++) {
const length = path.lengths[i];
if (distance <= length || i === path.lengths.length - 1) {
const t = length === 0 ? 0 : distance / length;
const a = path.points[i];
const b = path.points[i + 1];
const position = new THREE.Vector3().lerpVectors(a, b, t);
const tangent = new THREE.Vector3().subVectors(b, a).normalize();
return { position, tangent };
}
distance -= length;
}
return {
position: path.points[0].clone(),
tangent: new THREE.Vector3(0, 1, 0)
};
}
const pipeA = createPipePath(
[
new THREE.Vector3(-9.15, 0.62, -6),
new THREE.Vector3(-7.4, 0.62, -6),
new THREE.Vector3(-7.4, 0.62, -2.7),
new THREE.Vector3(-4.7, 0.62, -2.7),
new THREE.Vector3(-4.7, 0.62, -1.65),
new THREE.Vector3(-2.15, 0.62, -1.0),
new THREE.Vector3(-2.15, 1.02, 0)
],
COLORS.sourceA
);
const pipeB = createPipePath(
[
new THREE.Vector3(9.15, 0.62, -6),
new THREE.Vector3(7.4, 0.62, -6),
new THREE.Vector3(7.4, 0.62, -2.7),
new THREE.Vector3(4.7, 0.62, -2.7),
new THREE.Vector3(4.7, 0.62, -1.65),
new THREE.Vector3(2.15, 0.62, -1.0),
new THREE.Vector3(2.15, 1.02, 0)
],
COLORS.sourceB
);
const pipeReserve = createPipePath(
[
new THREE.Vector3(0, 0.62, 8.3),
new THREE.Vector3(0, 0.62, 6.8),
new THREE.Vector3(0, 0.62, 4.7),
new THREE.Vector3(0, 0.62, 3.25),
new THREE.Vector3(0, 1.02, 1.65)
],
COLORS.reserve
);
// Colored service connection ports.
addSphere(0.31, COLORS.sourceA, -2.15, 1.02, 0);
addSphere(0.31, COLORS.sourceB, 2.15, 1.02, 0);
addSphere(0.31, COLORS.reserve, 0, 1.02, 1.65);
// Small operational details around the service point.
addBox(1.0, 0.75, 0.8, 0xaab9be, -3.65, 0.57, 2.35);
addBox(1.0, 0.75, 0.8, 0xaab9be, 3.65, 0.57, 2.35);
addCylinder(0.09, 2.8, COLORS.darkSteel, -3.65, 2.1, 2.35);
addCylinder(0.09, 2.8, COLORS.darkSteel, 3.65, 2.1, 2.35);
addBox(1.25, 0.12, 0.12, COLORS.darkSteel, -3.65, 3.45, 2.35);
addBox(1.25, 0.12, 0.12, COLORS.darkSteel, 3.65, 3.45, 2.35);
// ------------------------------------------------------------
// Labels
// ------------------------------------------------------------
const labelAnchors = [
{
element: document.querySelector("#label-a"),
position: new THREE.Vector3(-11, 4.55, -6)
},
{
element: document.querySelector("#label-b"),
position: new THREE.Vector3(11, 4.1, -6)
},
{
element: document.querySelector("#label-reserve"),
position: new THREE.Vector3(0, 5.05, 10)
},
{
element: document.querySelector("#label-service"),
position: new THREE.Vector3(0, 4.25, 0)
},
{
element: document.querySelector("#link-a"),
position: new THREE.Vector3(-7.0, 1.25, -4.0)
},
{
element: document.querySelector("#link-b"),
position: new THREE.Vector3(7.0, 1.25, -4.0)
},
{
element: document.querySelector("#link-reserve"),
position: new THREE.Vector3(1.45, 1.25, 5.45)
}
];
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labelAnchors) {
const projected = label.position.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.2 &&
projected.x < 1.2 &&
projected.y > -1.2 &&
projected.y < 1.2;
label.element.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
// ------------------------------------------------------------
// Simulation and controls
// ------------------------------------------------------------
const sourceAInput = document.querySelector("#source-a");
const sourceBInput = document.querySelector("#source-b");
const reserveRateInput = document.querySelector("#reserve-rate");
function updateRangeFill(input) {
const min = Number(input.min);
const max = Number(input.max);
const value = Number(input.value);
const percentage = ((value - min) / (max - min)) * 100;
input.style.setProperty("--fill", `${percentage}%`);
}
function updateSimulation(dt) {
const total = state.sourceA + state.sourceB;
if (total <= 0) {
state.actualA = 0;
state.actualB = 0;
} else if (total <= state.demand) {
state.actualA = state.sourceA;
state.actualB = state.sourceB;
} else {
// If the source setpoints exceed demand, share the service demand
// proportionally. Neither source path depends on the other.
state.actualA = state.demand * (state.sourceA / total);
state.actualB = state.demand * (state.sourceB / total);
}
const deficit = Math.max(
0,
state.demand - state.actualA - state.actualB
);
// One real second represents 0.002 simulated hours.
const simulatedHours = dt * 0.002;
const availableThisStep =
simulatedHours > 0 ? state.volume / simulatedHours : 0;
state.actualReserve = Math.min(
state.reserveLimit,
deficit,
availableThisStep
);
if (state.volume <= 0) {
state.actualReserve = 0;
}
state.volume = Math.max(
0,
state.volume - state.actualReserve * simulatedHours
);
state.unmet = Math.max(
0,
state.demand -
state.actualA -
state.actualB -
state.actualReserve
);
}
function updateUI() {
const aText = `${Math.round(state.actualA)} m³/h`;
const bText = `${Math.round(state.actualB)} m³/h`;
const reserveText = `${Math.round(state.actualReserve)} m³/h`;
document.querySelector("#source-a-output").textContent =
`${state.sourceA} m³/h`;
document.querySelector("#source-b-output").textContent =
`${state.sourceB} m³/h`;
document.querySelector("#reserve-rate-output").textContent =
`${state.reserveLimit} m³/h`;
document.querySelector("#total-supply").textContent =
`${Math.round(state.actualA + state.actualB)} m³/h`;
document.querySelector("#actual-reserve").textContent = reserveText;
document.querySelector("#unmet-demand").textContent =
`${Math.round(state.unmet)} m³/h`;
const percent = Math.round((state.volume / state.capacity) * 100);
document.querySelector("#reserve-volume").textContent =
Math.round(state.volume);
document.querySelector("#reserve-percent").textContent = `${percent}%`;
document.querySelector("#reserve-meter").style.width = `${percent}%`;
document.querySelector("#label-a-value").textContent = aText;
document.querySelector("#label-b-value").textContent = bText;
document.querySelector("#link-a-value").textContent = aText;
document.querySelector("#link-b-value").textContent = bText;
document.querySelector("#link-reserve-value").textContent = reserveText;
document.querySelector("#label-reserve-value").textContent =
`${state.capacity} m³ capacity`;
document.querySelector("#label-reserve-rate").textContent =
`${Math.round(state.actualReserve)} m³/h discharge`;
const status = document.querySelector("#status");
if (state.unmet > 0.5) {
status.className = "status danger";
status.textContent =
`Demand shortfall: ${Math.round(state.unmet)} m³/h`;
} else if (state.actualReserve > 0.5) {
status.className = "status warning";
status.textContent = "Reserve is supporting service demand";
} else {
status.className = "status";
status.textContent = "System balanced";
}
const filledCells = Math.ceil(
(state.volume / state.capacity) * gaugeCells.length
);
gaugeCells.forEach((cell, index) => {
const filled = index < filledCells;
cell.material.color.setHex(
filled ? COLORS.reserve : 0x596970
);
cell.material.emissive.setHex(
filled ? 0x5b2b00 : 0x000000
);
cell.material.emissiveIntensity = filled ? 0.08 : 0;
});
updateRangeFill(sourceAInput);
updateRangeFill(sourceBInput);
updateRangeFill(reserveRateInput);
}
sourceAInput.addEventListener("input", () => {
state.sourceA = Number(sourceAInput.value);
updateRangeFill(sourceAInput);
updateUI();
});
sourceBInput.addEventListener("input", () => {
state.sourceB = Number(sourceBInput.value);
updateRangeFill(sourceBInput);
updateUI();
});
reserveRateInput.addEventListener("input", () => {
state.reserveLimit = Number(reserveRateInput.value);
updateRangeFill(reserveRateInput);
updateUI();
});
document.querySelector("#reset-model").addEventListener("click", () => {
state.sourceA = 55;
state.sourceB = 45;
state.reserveLimit = 30;
state.volume = 220;
sourceAInput.value = "55";
sourceBInput.value = "45";
reserveRateInput.value = "30";
updateSimulation(0);
updateUI();
});
document.querySelector("#reset-view").addEventListener("click", resetView);
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
function updateFlow(path, rate, dt) {
const active = rate > 0.05;
path.phase += dt * (0.035 + rate * 0.0024);
path.markers.forEach((marker, index) => {
marker.visible = active;
if (!active) return;
const sample = samplePipe(
path,
path.phase + index / path.markers.length
);
marker.position.copy(sample.position);
marker.quaternion.setFromUnitVectors(up, sample.tangent);
});
}
let previousTime = performance.now();
function animate(now) {
const dt = Math.min((now - previousTime) / 1000, 0.1);
previousTime = now;
updateCamera(dt);
updateSimulation(dt);
updateFlow(pipeA, state.actualA, dt);
updateFlow(pipeB, state.actualB, dt);
updateFlow(pipeReserve, state.actualReserve, dt);
updateUI();
updateLabels();
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
updateSimulation(0);
updateUI();
updateCamera(1);
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```