Prompt specification
Build or customize the Three.js 3D scene "Water Meter and Independent Tank Gauge" 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: Water Meter and Independent Tank Gauge
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/water-meter-and-independent-tank-gauge-x3973
Scene Description Prompt:
A water-system cutaway compares a flow meter with a tank-level gauge, distinguishing rates, stored quantities, and units. Three.js from cdnjs, one HTML file.
Working Three.js Starter (water-meter-and-independent-tank-gauge-x3973):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Water-System Cutaway — Flow vs. Stored Quantity</title>
<style>
:root {
color-scheme: dark;
--bg: #07131c;
--panel: rgba(10, 25, 36, 0.86);
--line: rgba(159, 202, 221, 0.17);
--text: #edf7fb;
--muted: #8ea8b5;
--cyan: #59dcff;
--cyan-soft: rgba(89, 220, 255, 0.14);
--amber: #ffc66d;
--amber-soft: rgba(255, 198, 109, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
button,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
outline: none;
}
#scene.dragging {
cursor: grabbing;
}
.hero {
position: fixed;
z-index: 20;
top: 28px;
left: 30px;
width: min(530px, calc(100vw - 430px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 13px;
color: var(--cyan);
font: 700 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 22px;
height: 2px;
background: var(--cyan);
box-shadow: 0 0 14px var(--cyan);
}
h1 {
max-width: 520px;
margin: 0;
font-size: clamp(28px, 3.2vw, 48px);
line-height: 1.02;
letter-spacing: -0.045em;
text-wrap: balance;
}
.hero p {
max-width: 480px;
margin: 15px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.65;
}
.panel {
position: fixed;
z-index: 30;
top: 20px;
right: 20px;
bottom: 20px;
width: 348px;
padding: 20px;
overflow: auto;
border: 1px solid var(--line);
border-radius: 22px;
background:
linear-gradient(145deg, rgba(18, 41, 55, 0.92), rgba(7, 19, 29, 0.93)),
var(--panel);
box-shadow:
0 24px 70px rgba(0, 0, 0, 0.36),
inset 0 1px 0 rgba(255, 255, 255, 0.04);
backdrop-filter: blur(18px);
}
.panel::-webkit-scrollbar {
width: 6px;
}
.panel::-webkit-scrollbar-thumb {
border-radius: 10px;
background: rgba(139, 192, 211, 0.24);
}
.panel-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 7px;
}
.panel-title {
margin: 0;
font-size: 18px;
letter-spacing: -0.025em;
}
.live {
display: inline-flex;
align-items: center;
gap: 7px;
color: var(--cyan);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
}
.live::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 12px var(--cyan);
animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
50% {
opacity: 0.4;
}
}
.panel-intro {
margin: 0 0 18px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.instrument {
position: relative;
margin-top: 12px;
padding: 16px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 16px;
background: rgba(2, 13, 21, 0.4);
}
.instrument::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 3px;
background: var(--accent);
box-shadow: 0 0 18px var(--accent);
}
.instrument.flow {
--accent: var(--cyan);
--accent-soft: var(--cyan-soft);
}
.instrument.tank {
--accent: var(--amber);
--accent-soft: var(--amber-soft);
}
.instrument-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 13px;
}
.instrument-name {
color: var(--accent);
font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.quantity-type {
padding: 5px 7px;
border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent);
border-radius: 6px;
background: var(--accent-soft);
color: var(--accent);
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.readout {
display: flex;
align-items: baseline;
gap: 8px;
min-height: 46px;
}
.readout strong {
font-size: 34px;
font-weight: 650;
letter-spacing: -0.045em;
font-variant-numeric: tabular-nums;
}
.readout span {
color: var(--muted);
font: 600 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.conversion {
display: flex;
justify-content: space-between;
gap: 12px;
margin-top: 4px;
color: var(--muted);
font-size: 11px;
}
.conversion strong {
color: #c9d9e1;
font-weight: 600;
font-variant-numeric: tabular-nums;
}
.slider-wrap {
margin-top: 15px;
}
.slider-caption {
display: flex;
justify-content: space-between;
margin-bottom: 8px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.04em;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 0;
border-radius: 20px;
appearance: none;
background:
linear-gradient(
to right,
var(--accent) 0%,
var(--accent) var(--fill),
rgba(145, 179, 193, 0.16) var(--fill),
rgba(145, 179, 193, 0.16) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
border: 3px solid #0a1720;
border-radius: 50%;
appearance: none;
background: var(--accent);
box-shadow: 0 0 0 1px var(--accent), 0 0 14px var(--accent);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #0a1720;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 1px var(--accent), 0 0 14px var(--accent);
}
.meter-bars {
display: grid;
grid-template-columns: repeat(12, 1fr);
gap: 4px;
height: 22px;
margin-top: 14px;
align-items: end;
}
.meter-bars i {
display: block;
height: 100%;
border-radius: 2px;
background: rgba(89, 220, 255, 0.09);
transition: background 180ms ease, box-shadow 180ms ease;
}
.meter-bars i.on {
background: var(--cyan);
box-shadow: 0 0 8px rgba(89, 220, 255, 0.34);
}
.note {
margin-top: 14px;
padding: 13px 14px;
border: 1px solid rgba(255, 198, 109, 0.17);
border-radius: 13px;
background: rgba(255, 198, 109, 0.055);
color: #b9c7ce;
font-size: 11px;
line-height: 1.55;
}
.note strong {
color: var(--amber);
}
.toolbar {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
margin-top: 16px;
}
.toolbar button {
min-height: 36px;
padding: 7px 5px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.035);
color: #b7c9d2;
font-size: 10px;
cursor: pointer;
transition: 150ms ease;
}
.toolbar button:hover {
border-color: rgba(89, 220, 255, 0.4);
background: rgba(89, 220, 255, 0.08);
color: white;
}
.toolbar button.active {
border-color: rgba(89, 220, 255, 0.45);
color: var(--cyan);
}
.concept {
position: fixed;
z-index: 20;
left: 28px;
bottom: 24px;
width: min(790px, calc(100vw - 420px));
display: grid;
grid-template-columns: repeat(3, 1fr);
overflow: hidden;
border: 1px solid var(--line);
border-radius: 17px;
background: rgba(7, 20, 29, 0.8);
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(15px);
pointer-events: none;
}
.concept-item {
padding: 14px 16px;
border-right: 1px solid var(--line);
}
.concept-item:last-child {
border-right: 0;
}
.concept-item .name {
color: #dceaf0;
font-size: 11px;
font-weight: 700;
}
.concept-item .unit {
margin-left: 7px;
color: var(--cyan);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.concept-item p {
margin: 6px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.hint {
position: fixed;
z-index: 20;
right: 390px;
bottom: 29px;
color: rgba(170, 196, 207, 0.58);
font: 10px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.06em;
pointer-events: none;
}
.world-label {
position: fixed;
z-index: 8;
min-width: 170px;
padding: 10px 12px;
border: 1px solid rgba(120, 194, 220, 0.23);
border-left: 2px solid var(--cyan);
border-radius: 10px;
background: rgba(5, 18, 27, 0.86);
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.24);
transform: translate(-50%, -100%);
backdrop-filter: blur(12px);
pointer-events: none;
transition: opacity 120ms ease;
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 24px;
background: linear-gradient(var(--cyan), transparent);
}
.world-label.gauge {
border-left-color: var(--amber);
}
.world-label.gauge::after {
background: linear-gradient(var(--amber), transparent);
}
.world-label .label-name {
margin-bottom: 5px;
color: var(--muted);
font: 700 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.world-label strong {
display: block;
font-size: 17px;
letter-spacing: -0.02em;
font-variant-numeric: tabular-nums;
}
.world-label .label-detail {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
}
body.labels-hidden .world-label {
opacity: 0;
}
@media (max-width: 1050px) {
.concept {
width: calc(100vw - 410px);
}
.concept-item {
padding: 12px;
}
.hint {
display: none;
}
}
@media (max-width: 760px) {
.hero {
top: 16px;
left: 16px;
width: calc(100vw - 32px);
}
.hero h1 {
max-width: 360px;
font-size: 29px;
}
.hero p {
display: none;
}
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 42vh;
padding: 15px;
border-radius: 17px;
}
.panel-intro,
.note {
display: none;
}
.instrument {
padding: 13px;
}
.readout strong {
font-size: 28px;
}
.concept {
display: none;
}
.world-label {
min-width: 140px;
padding: 8px 9px;
transform: translate(-50%, -100%) scale(0.82);
}
.world-label strong {
font-size: 14px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive 3D water-system cutaway"></canvas>
<header class="hero">
<div class="eyebrow">Hydraulic systems / cutaway 07</div>
<h1>One system. Two different measurements.</h1>
<p>
A flow meter reports how quickly water moves through a pipe. A tank-level
gauge reports how much water is currently stored in the tank.
</p>
</header>
<aside class="panel">
<div class="panel-header">
<h2 class="panel-title">Live instrument compare</h2>
<span class="live">LIVE</span>
</div>
<p class="panel-intro">
Adjust either instrument. The geometry, readouts, and units update together.
</p>
<section class="instrument flow">
<div class="instrument-head">
<span class="instrument-name">01 / Flow meter</span>
<span class="quantity-type">Rate</span>
</div>
<div class="readout">
<strong id="flowValue">42.0</strong>
<span>L/min</span>
</div>
<div class="conversion">
<span>Equivalent flow rate</span>
<strong id="flowConverted">2.52 m³/h</strong>
</div>
<div class="meter-bars" id="meterBars" aria-hidden="true">
<i></i><i></i><i></i><i></i><i></i><i></i>
<i></i><i></i><i></i><i></i><i></i><i></i>
</div>
<div class="slider-wrap">
<div class="slider-caption">
<label for="flowSlider">Simulated pipe flow</label>
<span>0–120 L/min</span>
</div>
<input
id="flowSlider"
type="range"
min="0"
max="120"
step="0.5"
value="42"
/>
</div>
</section>
<section class="instrument tank">
<div class="instrument-head">
<span class="instrument-name">02 / Tank-level gauge</span>
<span class="quantity-type">Stored quantity</span>
</div>
<div class="readout">
<strong id="tankValue">1,728</strong>
<span>L</span>
</div>
<div class="conversion">
<span id="tankPercent">72% full</span>
<strong id="tankConverted">1.73 m³</strong>
</div>
<div class="slider-wrap">
<div class="slider-caption">
<label for="tankSlider">Stored volume</label>
<span>Capacity: 2,400 L</span>
</div>
<input
id="tankSlider"
type="range"
min="0"
max="2400"
step="10"
value="1728"
/>
</div>
</section>
<div class="note">
<strong>Important:</strong> liters measure a quantity. Liters per minute
measure a rate. A percentage only describes how full the tank is; it is
not the stored volume.
</div>
<div class="toolbar">
<button id="pauseButton" type="button">Pause</button>
<button id="labelsButton" class="active" type="button">Labels</button>
<button id="zoomInButton" type="button">Zoom +</button>
<button id="zoomOutButton" type="button">Zoom −</button>
<button id="resetViewButton" type="button">Reset view</button>
<button id="resetDataButton" type="button">Reset data</button>
<button id="resetAllButton" type="button">Reset all</button>
<button id="topViewButton" type="button">Top view</button>
</div>
</aside>
<div class="concept">
<div class="concept-item">
<span class="name">Rate</span>
<span class="unit">L/min</span>
<p>How quickly water moves through the pipe.</p>
</div>
<div class="concept-item">
<span class="name">Stored</span>
<span class="unit">L</span>
<p>How much water is currently held in the tank.</p>
</div>
<div class="concept-item">
<span class="name">Level</span>
<span class="unit">%</span>
<p>The fraction of the tank's total capacity in use.</p>
</div>
</div>
<div class="hint">DRAG TO ORBIT · SCROLL TO ZOOM</div>
<div class="world-label" id="label-tank">
<div class="label-name">Cutaway tank</div>
<strong>2,400 L</strong>
<span class="label-detail">Maximum stored capacity</span>
</div>
<div class="world-label gauge" id="label-gauge">
<div class="label-name">Tank-level gauge</div>
<strong id="gaugeWorldValue">1,728 L stored</strong>
<span class="label-detail">Liters = quantity in tank</span>
</div>
<div class="world-label" id="label-flow">
<div class="label-name">Flow meter</div>
<strong id="flowWorldValue">42.0 L/min</strong>
<span class="label-detail">Liters per minute = rate</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 CAPACITY_L = 2400;
const state = {
flow: 42,
volume: 1728,
paused: false
};
const canvas = document.querySelector("#scene");
const ui = {
flowSlider: document.querySelector("#flowSlider"),
tankSlider: document.querySelector("#tankSlider"),
flowValue: document.querySelector("#flowValue"),
flowConverted: document.querySelector("#flowConverted"),
tankValue: document.querySelector("#tankValue"),
tankConverted: document.querySelector("#tankConverted"),
tankPercent: document.querySelector("#tankPercent"),
gaugeWorldValue: document.querySelector("#gaugeWorldValue"),
flowWorldValue: document.querySelector("#flowWorldValue"),
meterBars: [...document.querySelectorAll("#meterBars i")],
pauseButton: document.querySelector("#pauseButton"),
labelsButton: document.querySelector("#labelsButton")
};
const integerFormatter = new Intl.NumberFormat("en-US", {
maximumFractionDigits: 0
});
// ---------------------------------------------------------------------
// Three.js scene
// ---------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131c);
scene.fog = new THREE.Fog(0x07131c, 11, 24);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Custom orbit state: no OrbitControls or other addon is used.
const cameraState = {
target: new THREE.Vector3(-0.25, 1.45, 0),
radius: 10,
theta: 0.67,
phi: 1.02
};
function applyCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y +
cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.target.set(-0.25, 1.45, 0);
cameraState.radius = window.innerWidth < 760 ? 12 : 10;
cameraState.theta = 0.67;
cameraState.phi = 1.02;
applyCamera();
}
applyCamera();
const hemisphere = new THREE.HemisphereLight(0xa9e7ff, 0x14202b, 1.8);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xe8f8ff, 3.1);
keyLight.position.set(-5, 8, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x51d8ff, 2.2);
rimLight.position.set(6, 4, -5);
scene.add(rimLight);
const meterLight = new THREE.PointLight(0x54dfff, 15, 6, 2);
meterLight.position.set(2.4, 1.2, 1.3);
scene.add(meterLight);
const warmLight = new THREE.PointLight(0xffbd62, 8, 4.5, 2);
warmLight.position.set(-1.4, 2.6, 1.6);
scene.add(warmLight);
// ---------------------------------------------------------------------
// Materials and geometry helpers
// ---------------------------------------------------------------------
const materials = {
frame: new THREE.MeshStandardMaterial({
color: 0x4d7280,
metalness: 0.78,
roughness: 0.3
}),
darkFrame: new THREE.MeshStandardMaterial({
color: 0x203946,
metalness: 0.72,
roughness: 0.36
}),
panel: new THREE.MeshStandardMaterial({
color: 0x102b38,
metalness: 0.35,
roughness: 0.58
}),
board: new THREE.MeshStandardMaterial({
color: 0x10232d,
metalness: 0.38,
roughness: 0.48
}),
glass: new THREE.MeshPhysicalMaterial({
color: 0xbcecff,
transparent: true,
opacity: 0.16,
transmission: 0.28,
roughness: 0.08,
metalness: 0,
thickness: 0.25,
depthWrite: false,
side: THREE.DoubleSide
}),
water: new THREE.MeshPhysicalMaterial({
color: 0x39bfea,
transparent: true,
opacity: 0.64,
transmission: 0.14,
roughness: 0.12,
metalness: 0,
thickness: 0.7,
ior: 1.33,
depthWrite: false
}),
waterSurface: new THREE.MeshPhysicalMaterial({
color: 0x6ce3ff,
transparent: true,
opacity: 0.78,
roughness: 0.16,
metalness: 0.05,
emissive: 0x0b6176,
emissiveIntensity: 0.22,
depthWrite: false
}),
cyan: new THREE.MeshStandardMaterial({
color: 0x59dcff,
emissive: 0x1388aa,
emissiveIntensity: 1.7,
metalness: 0.25,
roughness: 0.25
}),
amber: new THREE.MeshStandardMaterial({
color: 0xffc66d,
emissive: 0x9a5715,
emissiveIntensity: 0.8,
metalness: 0.45,
roughness: 0.3
}),
black: new THREE.MeshStandardMaterial({
color: 0x02090e,
roughness: 0.36,
metalness: 0.3
})
};
function addBox(parent, size, position, material) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinderBetween(
parent,
start,
end,
radius,
material,
openEnded = false
) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = b.clone().sub(a);
const midpoint = a.clone().add(b).multiplyScalar(0.5);
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radius,
radius,
direction.length(),
32,
1,
openEnded
),
material
);
mesh.position.copy(midpoint);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeTextSprite(text, color = "#b8cbd4", width = 0.68) {
const textCanvas = document.createElement("canvas");
textCanvas.width = 512;
textCanvas.height = 96;
const ctx = textCanvas.getContext("2d");
ctx.clearRect(0, 0, 512, 96);
ctx.font = "600 36px monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = color;
ctx.fillText(text, 256, 48);
const texture = new THREE.CanvasTexture(textCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(width, width * (96 / 512), 1);
sprite.renderOrder = 8;
return sprite;
}
// ---------------------------------------------------------------------
// Floor and platform
// ---------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0x081721,
metalness: 0.15,
roughness: 0.9
})
);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(18, 36, 0x2c5263, 0x173440);
grid.position.y = 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.26;
scene.add(grid);
addBox(
scene,
[9.2, 0.12, 3.4],
[0.15, 0.06, 0],
new THREE.MeshStandardMaterial({
color: 0x0d2632,
metalness: 0.5,
roughness: 0.62
})
);
// ---------------------------------------------------------------------
// Tank cutaway
// ---------------------------------------------------------------------
const tank = new THREE.Group();
tank.position.x = -2;
scene.add(tank);
// Back wall and bottom.
addBox(tank, [3.2, 2.75, 0.1], [0, 1.77, -1.1], materials.panel);
addBox(tank, [3.2, 0.12, 2.3], [0, 0.36, 0], materials.darkFrame);
// Transparent side walls and front face.
addBox(tank, [0.055, 2.75, 2.25], [-1.57, 1.77, 0], materials.glass);
addBox(tank, [0.055, 2.75, 2.25], [1.57, 1.77, 0], materials.glass);
addBox(tank, [3.08, 2.65, 0.035], [0, 1.77, 1.11], materials.glass);
// Structural frame.
for (const x of [-1.59, 1.59]) {
for (const z of [-1.1, 1.1]) {
addBox(tank, [0.09, 2.82, 0.09], [x, 1.78, z], materials.frame);
}
}
for (const z of [-1.1, 1.1]) {
addBox(tank, [3.25, 0.09, 0.09], [0, 3.16, z], materials.frame);
}
for (const x of [-1.59, 1.59]) {
addBox(tank, [0.09, 0.09, 2.25], [x, 3.16, 0], materials.frame);
}
// Tank water body and free surface.
const tankWater = new THREE.Mesh(
new THREE.BoxGeometry(3.0, 1, 2.04),
materials.water
);
tankWater.renderOrder = 2;
tank.add(tankWater);
const waterSurface = new THREE.Mesh(
new THREE.BoxGeometry(3.01, 0.025, 2.05),
materials.waterSurface
);
waterSurface.renderOrder = 3;
tank.add(waterSurface);
// Small internal baffle reinforces the cutaway/system reading.
addBox(tank, [0.07, 1.6, 1.85], [0.58, 1.25, 0], materials.darkFrame);
// ---------------------------------------------------------------------
// Main pipe and flow meter
// ---------------------------------------------------------------------
const pipeStart = [-0.42, 0.52, 0];
const pipeEnd = [4.3, 0.52, 0];
addCylinderBetween(
scene,
pipeStart,
pipeEnd,
0.235,
materials.glass,
true
);
addCylinderBetween(
scene,
pipeStart,
pipeEnd,
0.17,
materials.water
);
// Pipe support saddles.
for (const x of [0.35, 1.25, 3.75]) {
addBox(scene, [0.16, 0.35, 0.55], [x, 0.22, 0], materials.darkFrame);
addBox(scene, [0.16, 0.06, 0.7], [x, 0.41, 0], materials.frame);
}
// Flow meter housing.
addCylinderBetween(
scene,
[1.78, 0.52, 0],
[3.12, 0.52, 0],
0.4,
materials.glass,
true
);
addCylinderBetween(
scene,
[1.79, 0.52, 0],
[3.11, 0.52, 0],
0.31,
materials.water
);
for (const x of [1.78, 3.12]) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.405, 0.065, 12, 40),
materials.frame
);
ring.rotation.y = Math.PI / 2;
ring.position.set(x, 0.52, 0);
ring.castShadow = true;
scene.add(ring);
}
// Meter feet.
addBox(scene, [0.28, 0.22, 0.82], [2.02, 0.2, 0], materials.darkFrame);
addBox(scene, [0.28, 0.22, 0.82], [2.88, 0.2, 0], materials.darkFrame);
// Rotating impeller, aligned with the pipe's X axis.
const rotor = new THREE.Group();
rotor.position.set(2.45, 0.52, 0);
scene.add(rotor);
const hub = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.13, 0.28, 24),
materials.amber
);
hub.rotation.z = Math.PI / 2;
hub.castShadow = true;
rotor.add(hub);
for (let i = 0; i < 6; i++) {
const blade = addBox(
rotor,
[0.045, 0.48, 0.085],
[0, 0.22, 0],
materials.amber
);
blade.rotation.x = (i / 6) * Math.PI * 2;
}
// Direction arrows.
for (const x of [0.55, 1.2, 3.7]) {
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.085, 0.22, 16),
materials.cyan
);
arrow.rotation.z = -Math.PI / 2;
arrow.position.set(x, 0.52, 0.19);
scene.add(arrow);
}
// Animated water particles.
const particles = [];
const particleMaterial = new THREE.MeshBasicMaterial({
color: 0x91eeff,
transparent: true,
opacity: 0.9
});
for (let i = 0; i < 28; i++) {
const particle = new THREE.Mesh(
new THREE.SphereGeometry(0.045, 8, 8),
particleMaterial
);
particle.position.set(
-0.38 + (i / 28) * 4.58,
0.52,
Math.sin(i * 1.7) * 0.055
);
particle.userData.phase = i * 1.73;
scene.add(particle);
particles.push(particle);
}
// ---------------------------------------------------------------------
// Physical digital flow display
// ---------------------------------------------------------------------
addBox(scene, [1.03, 0.4, 0.11], [2.45, 1.05, 0.24], materials.black);
addCylinderBetween(
scene,
[2.45, 0.83, 0.1],
[2.45, 1.05, 0.18],
0.045,
materials.frame
);
const displayCanvas = document.createElement("canvas");
displayCanvas.width = 512;
displayCanvas.height = 160;
const displayContext = displayCanvas.getContext("2d");
const displayTexture = new THREE.CanvasTexture(displayCanvas);
displayTexture.colorSpace = THREE.SRGBColorSpace;
const display = new THREE.Mesh(
new THREE.PlaneGeometry(0.94, 0.3),
new THREE.MeshBasicMaterial({ map: displayTexture })
);
display.position.set(2.45, 1.05, 0.299);
scene.add(display);
function drawMeterDisplay() {
const ctx = displayContext;
ctx.clearRect(0, 0, 512, 160);
ctx.fillStyle = "#031016";
ctx.fillRect(0, 0, 512, 160);
ctx.strokeStyle = "rgba(89,220,255,0.22)";
ctx.lineWidth = 3;
ctx.strokeRect(7, 7, 498, 146);
ctx.textAlign = "right";
ctx.textBaseline = "middle";
ctx.fillStyle = "#68e4ff";
ctx.font = "700 84px monospace";
ctx.fillText(state.flow.toFixed(1), 350, 78);
ctx.textAlign = "left";
ctx.fillStyle = "#91aeba";
ctx.font = "600 27px monospace";
ctx.fillText("L/min", 365, 87);
ctx.textAlign = "center";
ctx.fillStyle = "#477382";
ctx.font = "600 17px monospace";
ctx.fillText("FLOW RATE", 256, 137);
displayTexture.needsUpdate = true;
}
// ---------------------------------------------------------------------
// Tank-level gauge and scale
// ---------------------------------------------------------------------
addBox(scene, [1.08, 2.86, 0.09], [0.28, 1.78, 0.57], materials.board);
// Tubing connections from tank to level gauge.
addCylinderBetween(
scene,
[-0.43, 0.49, 0],
[0.05, 0.49, 0.83],
0.07,
materials.frame
);
addCylinderBetween(
scene,
[-0.43, 3.04, 0],
[0.05, 3.04, 0.83],
0.07,
materials.frame
);
addCylinderBetween(
scene,
[0.05, 0.44, 0.83],
[0.05, 3.08, 0.83],
0.145,
materials.glass,
true
);
const gaugeWater = new THREE.Mesh(
new THREE.CylinderGeometry(0.085, 0.085, 1, 24),
materials.water
);
gaugeWater.position.x = 0.05;
gaugeWater.position.z = 0.83;
gaugeWater.renderOrder = 2;
scene.add(gaugeWater);
const gaugeMeniscus = new THREE.Mesh(
new THREE.SphereGeometry(0.087, 20, 12),
materials.waterSurface
);
gaugeMeniscus.position.set(0.05, 0.5, 0.83);
scene.add(gaugeMeniscus);
for (const y of [0.44, 3.08]) {
const cap = new THREE.Mesh(
new THREE.CylinderGeometry(0.17, 0.17, 0.09, 24),
materials.frame
);
cap.position.set(0.05, y, 0.83);
scene.add(cap);
}
const gaugeTicks = new THREE.Group();
scene.add(gaugeTicks);
for (let i = 0; i <= 12; i++) {
const y = 0.44 + (i / 12) * 2.64;
const major = i % 3 === 0;
addBox(
gaugeTicks,
[major ? 0.3 : 0.19, 0.017, 0.025],
[0.31, y, 0.86],
major ? materials.amber : materials.frame
);
if (major) {
const liters = i * 200;
const text = i === 12 ? "2400 L" : `${liters}`;
const label = makeTextSprite(
text,
i === 12 ? "#ffd08a" : "#91aeba",
i === 12 ? 0.76 : 0.55
);
label.position.set(0.75, y, 0.87);
gaugeTicks.add(label);
}
}
// ---------------------------------------------------------------------
// Readouts and synchronized geometry
// ---------------------------------------------------------------------
const WATER_BOTTOM = 0.46;
const TANK_USABLE_HEIGHT = 2.42;
const GAUGE_USABLE_HEIGHT = 2.56;
function updateSliderFill(input) {
const percent =
((Number(input.value) - Number(input.min)) /
(Number(input.max) - Number(input.min))) *
100;
input.style.setProperty("--fill", `${percent}%`);
}
function updateSystem() {
const flow = state.flow;
const volume = state.volume;
const fillFraction = volume / CAPACITY_L;
const levelPercent = fillFraction * 100;
// Tank water.
const tankHeight = Math.max(0.018, fillFraction * TANK_USABLE_HEIGHT);
tankWater.scale.y = tankHeight;
tankWater.position.y = WATER_BOTTOM + tankHeight / 2;
waterSurface.position.y = WATER_BOTTOM + tankHeight;
// Gauge water.
const gaugeHeight = Math.max(0.018, fillFraction * GAUGE_USABLE_HEIGHT);
gaugeWater.scale.y = gaugeHeight;
gaugeWater.position.y = 0.47 + gaugeHeight / 2;
gaugeMeniscus.position.y = 0.47 + gaugeHeight;
// HTML readouts.
ui.flowValue.textContent = flow.toFixed(1);
ui.flowConverted.textContent = `${(flow * 0.06).toFixed(2)} m³/h`;
ui.tankValue.textContent = integerFormatter.format(volume);
ui.tankConverted.textContent = `${(volume / 1000).toFixed(2)} m³`;
ui.tankPercent.textContent = `${Math.round(levelPercent)}% full`;
ui.gaugeWorldValue.textContent =
`${integerFormatter.format(volume)} L stored`;
ui.flowWorldValue.textContent = `${flow.toFixed(1)} L/min`;
// Mini flow display.
const activeBars = Math.round((flow / 120) * ui.meterBars.length);
ui.meterBars.forEach((bar, index) => {
bar.classList.toggle("on", index < activeBars);
});
updateSliderFill(ui.flowSlider);
updateSliderFill(ui.tankSlider);
drawMeterDisplay();
}
ui.flowSlider.addEventListener("input", (event) => {
state.flow = Number(event.target.value);
updateSystem();
});
ui.tankSlider.addEventListener("input", (event) => {
state.volume = Number(event.target.value);
updateSystem();
});
ui.pauseButton.addEventListener("click", () => {
state.paused = !state.paused;
ui.pauseButton.textContent = state.paused ? "Resume" : "Pause";
ui.pauseButton.classList.toggle("active", state.paused);
});
ui.labelsButton.addEventListener("click", () => {
document.body.classList.toggle("labels-hidden");
ui.labelsButton.classList.toggle(
"active",
!document.body.classList.contains("labels-hidden")
);
});
document.querySelector("#zoomInButton").addEventListener("click", () => {
cameraState.radius = Math.max(5.4, cameraState.radius - 0.8);
applyCamera();
});
document.querySelector("#zoomOutButton").addEventListener("click", () => {
cameraState.radius = Math.min(16, cameraState.radius + 0.8);
applyCamera();
});
document.querySelector("#resetViewButton").addEventListener("click", resetCamera);
document.querySelector("#topViewButton").addEventListener("click", () => {
cameraState.theta = 0.0;
cameraState.phi = 0.62;
cameraState.radius = 9.7;
applyCamera();
});
document.querySelector("#resetDataButton").addEventListener("click", () => {
state.flow = 42;
state.volume = 1728;
ui.flowSlider.value = state.flow;
ui.tankSlider.value = state.volume;
updateSystem();
});
document.querySelector("#resetAllButton").addEventListener("click", () => {
state.flow = 42;
state.volume = 1728;
state.paused = false;
ui.flowSlider.value = state.flow;
ui.tankSlider.value = state.volume;
ui.pauseButton.textContent = "Pause";
ui.pauseButton.classList.remove("active");
resetCamera();
updateSystem();
});
updateSystem();
// ---------------------------------------------------------------------
// Custom camera controls
// ---------------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi -= dy * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi,
0.34,
1.43
);
applyCamera();
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius *= Math.exp(event.deltaY * 0.001);
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius,
5.4,
16
);
applyCamera();
},
{ passive: false }
);
// ---------------------------------------------------------------------
// Projected HTML labels
// ---------------------------------------------------------------------
const labels = [
{
element: document.querySelector("#label-tank"),
anchor: new THREE.Vector3(-2.05, 3.46, 0)
},
{
element: document.querySelector("#label-gauge"),
anchor: new THREE.Vector3(0.28, 3.48, 0.76)
},
{
element: document.querySelector("#label-flow"),
anchor: new THREE.Vector3(2.45, 1.67, 0)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
projected.copy(label.anchor).project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
const visible = projected.z > -1 && projected.z < 1;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
label.element.style.visibility = visible ? "visible" : "hidden";
}
}
// ---------------------------------------------------------------------
// Resize and animation
// ---------------------------------------------------------------------
function onResize() {
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", onResize);
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!state.paused) {
elapsed += delta;
const speed = 0.18 + state.flow * 0.047;
for (const particle of particles) {
particle.position.x += speed * delta;
particle.position.y =
0.52 + Math.sin(elapsed * 3 + particle.userData.phase) * 0.045;
if (particle.position.x > 4.24) {
particle.position.x = -0.4;
}
}
rotor.rotation.x -= (0.2 + state.flow * 0.065) * delta;
waterSurface.position.y += Math.sin(elapsed * 1.7) * 0.0025;
gaugeMeniscus.position.y += Math.sin(elapsed * 1.9) * 0.0015;
}
particles.forEach((particle) => {
particle.visible = state.flow > 0;
});
updateLabels();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```